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