EPD_5in83b_HD.c (7418B)
1 /***************************************************************************** 2 * | File : EPD_5in83b_HD.c 3 * | Author : Waveshare team 4 * | Function : Electronic paper driver 5 * | Info : 6 *---------------- 7 * | This version: V1.0 8 * | Date : 2020-07-04 9 * | Info : 10 ****************************************************************************** 11 # Permission is hereby granted, free of charge, to any person obtaining a copy 12 # of this software and associated documnetation files(the "Software"), to deal 13 # in the Software without restriction, including without limitation the rights 14 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 # copies of the Software, and to permit persons to whom the Software is 16 # furished to do so, subject to the following conditions: 17 # 18 # The above copyright notice and this permission notice shall be included in 19 # all copies or substantial portions of the Software. 20 # 21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 # THE SOFTWARE. 28 # 29 ******************************************************************************/ 30 #include "EPD_5in83b_HD.h" 31 #include "Debug.h" 32 33 /****************************************************************************** 34 function : Software reset 35 parameter: 36 ******************************************************************************/ 37 static void EPD_5IN83B_HD_Reset(void) 38 { 39 DEV_Digital_Write(EPD_RST_PIN, 1); 40 DEV_Delay_ms(200); 41 DEV_Digital_Write(EPD_RST_PIN, 0); 42 DEV_Delay_ms(1); 43 DEV_Digital_Write(EPD_RST_PIN, 1); 44 DEV_Delay_ms(200); 45 } 46 47 /****************************************************************************** 48 function : send command 49 parameter: 50 Reg : Command register 51 ******************************************************************************/ 52 static void EPD_5IN83B_HD_SendCommand(UBYTE Reg) 53 { 54 DEV_Digital_Write(EPD_DC_PIN, 0); 55 DEV_Digital_Write(EPD_CS_PIN, 0); 56 DEV_SPI_WriteByte(Reg); 57 DEV_Digital_Write(EPD_CS_PIN, 1); 58 } 59 60 /****************************************************************************** 61 function : send data 62 parameter: 63 Data : Write data 64 ******************************************************************************/ 65 static void EPD_5IN83B_HD_SendData(UBYTE Data) 66 { 67 68 DEV_Digital_Write(EPD_CS_PIN, 0); 69 DEV_Digital_Write(EPD_DC_PIN, 1); 70 DEV_SPI_WriteByte(Data); 71 DEV_Digital_Write(EPD_CS_PIN, 1); 72 } 73 74 /****************************************************************************** 75 function : Wait until the busy_pin goes LOW 76 parameter: 77 ******************************************************************************/ 78 void EPD_5IN83B_HD_WaitUntilIdle(void) 79 { 80 Debug("e-Paper busy\r\n"); 81 UBYTE busy; 82 do 83 { 84 EPD_5IN83B_HD_SendCommand(0x71); 85 busy = DEV_Digital_Read(EPD_BUSY_PIN); 86 busy =!(busy & 0x01); 87 } 88 while(busy); 89 DEV_Delay_ms(200); 90 Debug("e-Paper busy release\r\n"); 91 } 92 93 /****************************************************************************** 94 function : Turn On Display 95 parameter: 96 ******************************************************************************/ 97 static void EPD_5IN83B_HD_TurnOnDisplay(void) 98 { 99 EPD_5IN83B_HD_SendCommand(0x12); //DISPLAY REFRESH 100 DEV_Delay_ms(100); //!!!The delay here is necessary, 200uS at least!!! 101 EPD_5IN83B_HD_WaitUntilIdle(); //waiting for the electronic paper IC to release the idle signal 102 } 103 104 /****************************************************************************** 105 function : Initialize the e-Paper register 106 parameter: 107 ******************************************************************************/ 108 UBYTE EPD_5IN83B_HD_Init(void) 109 { 110 EPD_5IN83B_HD_Reset(); 111 112 EPD_5IN83B_HD_SendCommand(0x01); //POWER SETTING 113 EPD_5IN83B_HD_SendData (0x07); 114 EPD_5IN83B_HD_SendData (0x07); //VGH=20V,VGL=-20V 115 EPD_5IN83B_HD_SendData (0x3f); //VDH=15V 116 EPD_5IN83B_HD_SendData (0x3f); //VDL=-15V 117 118 EPD_5IN83B_HD_SendCommand(0x04); //POWER ON 119 DEV_Delay_ms(100); 120 EPD_5IN83B_HD_WaitUntilIdle(); //waiting for the electronic paper IC to release the idle signal 121 122 EPD_5IN83B_HD_SendCommand(0X00); //PANNEL SETTING 123 EPD_5IN83B_HD_SendData(0x0F); //KW-3f KWR-2F BWROTP 0f BWOTP 1f 124 125 EPD_5IN83B_HD_SendCommand(0x61); //tres 126 EPD_5IN83B_HD_SendData (0x02); //source 648 127 EPD_5IN83B_HD_SendData (0x88); 128 EPD_5IN83B_HD_SendData (0x01); //gate 480 129 EPD_5IN83B_HD_SendData (0xe0); 130 131 EPD_5IN83B_HD_SendCommand(0X15); 132 EPD_5IN83B_HD_SendData(0x00); 133 134 EPD_5IN83B_HD_SendCommand(0X50); //VCOM AND DATA INTERVAL SETTING 135 EPD_5IN83B_HD_SendData(0x11); 136 EPD_5IN83B_HD_SendData(0x07); 137 138 EPD_5IN83B_HD_SendCommand(0X60); //TCON SETTING 139 EPD_5IN83B_HD_SendData(0x22); 140 141 return 0; 142 } 143 144 /****************************************************************************** 145 function : Clear screen 146 parameter: 147 ******************************************************************************/ 148 void EPD_5IN83B_HD_Clear(void) 149 { 150 UWORD Width, Height; 151 Width =(EPD_5IN83B_HD_WIDTH % 8 == 0)?(EPD_5IN83B_HD_WIDTH / 8 ):(EPD_5IN83B_HD_WIDTH / 8 + 1); 152 Height = EPD_5IN83B_HD_HEIGHT; 153 UWORD i; 154 EPD_5IN83B_HD_SendCommand(0x10); 155 for(i=0; i<Width*Height; i++) { 156 EPD_5IN83B_HD_SendData(0xff); 157 158 } 159 EPD_5IN83B_HD_SendCommand(0x13); 160 for(i=0; i<Width*Height; i++) { 161 EPD_5IN83B_HD_SendData(0x00); 162 163 } 164 EPD_5IN83B_HD_TurnOnDisplay(); 165 } 166 167 /****************************************************************************** 168 function : Sends the image buffer in RAM to e-Paper and displays 169 parameter: 170 ******************************************************************************/ 171 void EPD_5IN83B_HD_Display(const UBYTE *blackimage, const UBYTE *ryimage) 172 { 173 UDOUBLE Width, Height; 174 Width =(EPD_5IN83B_HD_WIDTH % 8 == 0)?(EPD_5IN83B_HD_WIDTH / 8 ):(EPD_5IN83B_HD_WIDTH / 8 + 1); 175 Height = EPD_5IN83B_HD_HEIGHT; 176 //send black data 177 EPD_5IN83B_HD_SendCommand(0x10); 178 for (UDOUBLE j = 0; j < Height; j++) { 179 for (UDOUBLE i = 0; i < Width; i++) { 180 EPD_5IN83B_HD_SendData(blackimage[i + j * Width]); 181 } 182 } 183 184 //send red data 185 EPD_5IN83B_HD_SendCommand(0x13); 186 for (UDOUBLE j = 0; j < Height; j++) { 187 for (UDOUBLE i = 0; i < Width; i++) { 188 EPD_5IN83B_HD_SendData(~ryimage[i + j * Width]); 189 } 190 } 191 EPD_5IN83B_HD_TurnOnDisplay(); 192 } 193 194 /****************************************************************************** 195 function : Enter sleep mode 196 parameter: 197 ******************************************************************************/ 198 void EPD_5IN83B_HD_Sleep(void) 199 { 200 EPD_5IN83B_HD_SendCommand(0X02); //power off 201 EPD_5IN83B_HD_WaitUntilIdle(); //waiting for the electronic paper IC to release the idle signal 202 EPD_5IN83B_HD_SendCommand(0X07); //deep sleep 203 EPD_5IN83B_HD_SendData(0xA5); 204 }