EPD_7in5_HD.c (9656B)
1 /***************************************************************************** 2 * | File : EPD_7in5_HD.c 3 * | Author : Waveshare team 4 * | Function : Electronic paper driver 5 * | Info : 6 *---------------- 7 * | This version: V1.0 8 * | Date : 2020-04-25 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_HD.h" 32 #include "Debug.h" 33 34 /****************************************************************************** 35 function : Software reset 36 parameter: 37 ******************************************************************************/ 38 static void EPD_7IN5_HD_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_7IN5_HD_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_7IN5_HD_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_7IN5_HD_WaitUntilIdle(void) 79 { 80 Debug("e-Paper busy\r\n"); 81 do{ 82 DEV_Delay_ms(10); 83 }while(DEV_Digital_Read(EPD_BUSY_PIN) == 1); 84 DEV_Delay_ms(200); 85 Debug("e-Paper busy release\r\n"); 86 87 } 88 89 90 /****************************************************************************** 91 function : Initialize the e-Paper register 92 parameter: 93 ******************************************************************************/ 94 void EPD_7IN5_HD_Init(void) 95 { 96 EPD_7IN5_HD_Reset(); 97 98 // EPD_7IN5_HD_WaitUntilIdle(); 99 // EPD_7IN5_HD_SendCommand(0x12); //SWRESET 100 // EPD_7IN5_HD_WaitUntilIdle(); 101 102 // EPD_7IN5_HD_SendCommand(0x46); // Auto Write Red RAM 103 // EPD_7IN5_HD_SendData(0xf7); 104 // EPD_7IN5_HD_WaitUntilIdle(); 105 // EPD_7IN5_HD_SendCommand(0x47); // Auto Write B/W RAM 106 // EPD_7IN5_HD_SendData(0xf7); 107 // EPD_7IN5_HD_WaitUntilIdle(); 108 109 110 // EPD_7IN5_HD_SendCommand(0x0C); // Soft start setting 111 // EPD_7IN5_HD_SendData(0xAE); 112 // EPD_7IN5_HD_SendData(0xC7); 113 // EPD_7IN5_HD_SendData(0xC3); 114 // EPD_7IN5_HD_SendData(0xC0); 115 // EPD_7IN5_HD_SendData(0x40); 116 117 118 // EPD_7IN5_HD_SendCommand(0x01); // Set MUX as 527 119 // EPD_7IN5_HD_SendData(0xAF); 120 // EPD_7IN5_HD_SendData(0x02); 121 // EPD_7IN5_HD_SendData(0x01);//0x01 122 123 124 // EPD_7IN5_HD_SendCommand(0x11); // Data entry mode 125 // EPD_7IN5_HD_SendData(0x01); 126 127 // EPD_7IN5_HD_SendCommand(0x44); 128 // EPD_7IN5_HD_SendData(0x00); // RAM x address start at 0 129 // EPD_7IN5_HD_SendData(0x00); 130 // EPD_7IN5_HD_SendData(0x6F); 131 // EPD_7IN5_HD_SendData(0x03); 132 // EPD_7IN5_HD_SendCommand(0x45); 133 // EPD_7IN5_HD_SendData(0xFF); 134 // EPD_7IN5_HD_SendData(0x03); 135 // EPD_7IN5_HD_SendData(0x00); 136 // EPD_7IN5_HD_SendData(0x00); 137 138 139 // EPD_7IN5_HD_SendCommand(0x3C); // VBD 140 // EPD_7IN5_HD_SendData(0x05); // LUT1, for white 141 142 // EPD_7IN5_HD_SendCommand(0x18); 143 // EPD_7IN5_HD_SendData(0X80); 144 145 146 // EPD_7IN5_HD_SendCommand(0x22); 147 // EPD_7IN5_HD_SendData(0XB1); //Load Temperature and waveform setting. 148 // EPD_7IN5_HD_SendCommand(0x20); 149 // EPD_7IN5_HD_WaitUntilIdle(); 150 151 // EPD_7IN5_HD_SendCommand(0x4E); // set RAM x address count to 0; 152 // EPD_7IN5_HD_SendData(0x00); 153 // EPD_7IN5_HD_SendData(0x00); 154 // EPD_7IN5_HD_SendCommand(0x4F); 155 // EPD_7IN5_HD_SendData(0x00); 156 // EPD_7IN5_HD_SendData(0x00); 157 // return 0; 158 159 EPD_7IN5_HD_SendCommand(0x46); // Auto Write RAM 160 EPD_7IN5_HD_SendData(0xF7); 161 EPD_7IN5_HD_WaitUntilIdle(); 162 EPD_7IN5_HD_SendCommand(0x47); // Auto Write RAM 163 EPD_7IN5_HD_SendData(0xF7); 164 EPD_7IN5_HD_WaitUntilIdle(); 165 166 167 EPD_7IN5_HD_SendCommand(0x0C); // Soft start setting 168 EPD_7IN5_HD_SendData(0xAE); 169 EPD_7IN5_HD_SendData(0xC7); 170 EPD_7IN5_HD_SendData(0xC3); 171 EPD_7IN5_HD_SendData(0xC0); 172 EPD_7IN5_HD_SendData(0x40); 173 174 175 176 177 EPD_7IN5_HD_SendCommand(0x01); // Set MUX as 527 178 EPD_7IN5_HD_SendData(0x0F); 179 EPD_7IN5_HD_SendData(0x02); 180 EPD_7IN5_HD_SendData(0x00); 181 182 EPD_7IN5_HD_SendCommand(0x11); // Data entry mode 183 EPD_7IN5_HD_SendData(0x01); 184 EPD_7IN5_HD_SendCommand(0x44); 185 EPD_7IN5_HD_SendData(0x00); // RAM x address start at 0 186 EPD_7IN5_HD_SendData(0x00); 187 EPD_7IN5_HD_SendData(0x6F); // RAM x address end at 36Fh -> 879 188 EPD_7IN5_HD_SendData(0x03); 189 EPD_7IN5_HD_SendCommand(0x45); 190 EPD_7IN5_HD_SendData(0x0F); // RAM y address start at 20Fh; 191 EPD_7IN5_HD_SendData(0x02); 192 EPD_7IN5_HD_SendData(0x00); // RAM y address end at 00h; 193 EPD_7IN5_HD_SendData(0x00); 194 195 EPD_7IN5_HD_SendCommand(0x3C); // VBD 196 EPD_7IN5_HD_SendData(0x01); // LUT1, for white 197 198 EPD_7IN5_HD_SendCommand(0x18); 199 EPD_7IN5_HD_SendData(0X80); 200 EPD_7IN5_HD_SendCommand(0x22); 201 EPD_7IN5_HD_SendData(0XB1); 202 EPD_7IN5_HD_SendCommand(0x20); 203 204 205 } 206 207 /****************************************************************************** 208 function : Clear screen 209 parameter: 210 ******************************************************************************/ 211 void EPD_7IN5_HD_Clear(void) 212 { 213 // UDOUBLE Width, Height; 214 // Width =(EPD_7IN5_HD_WIDTH % 8 == 0)?(EPD_7IN5_HD_WIDTH / 8 ):(EPD_7IN5_HD_WIDTH / 8 + 1); 215 // Height = EPD_7IN5_HD_HEIGHT; 216 217 // EPD_7IN5_HD_SendCommand(0x4F); 218 // EPD_7IN5_HD_SendData(0x00); 219 // EPD_7IN5_HD_SendData(0x00); 220 // EPD_7IN5_HD_SendCommand(0x24); 221 // UDOUBLE i; 222 // for(i=0; i<58080; i++) { 223 // EPD_7IN5_HD_SendData(0xff); 224 // } 225 226 // EPD_7IN5_HD_SendCommand(0x26); 227 // for(i=0; i<Height*Width; i++){ 228 // EPD_7IN5_HD_SendData(0xff); 229 // } 230 // EPD_7IN5_HD_SendCommand(0x22); 231 // EPD_7IN5_HD_SendData(0xF7);//Load LUT from MCU(0x32) 232 // EPD_7IN5_HD_SendCommand(0x20); 233 // DEV_Delay_ms(10); 234 235 236 // EPD_7IN5_HD_WaitUntilIdle(); 237 } 238 239 /****************************************************************************** 240 function : Sends the image buffer in RAM to e-Paper and displays 241 parameter: 242 ******************************************************************************/ 243 void EPD_7IN5_HD_Display(const UBYTE *blackimage) 244 { 245 UDOUBLE Width, Height; 246 Width =(EPD_7IN5_HD_WIDTH % 8 == 0)?(EPD_7IN5_HD_WIDTH / 8 ):(EPD_7IN5_HD_WIDTH / 8 + 1); 247 Height = EPD_7IN5_HD_HEIGHT; 248 249 EPD_7IN5_HD_SendCommand(0x4F); 250 EPD_7IN5_HD_SendData(0x00); 251 EPD_7IN5_HD_SendData(0x00); 252 EPD_7IN5_HD_SendCommand(0x24); 253 254 UDOUBLE i; 255 for (UDOUBLE j = 0; j < Height; j++) { 256 for (UDOUBLE i = 0; i < Width; i++) { 257 EPD_7IN5_HD_SendData(blackimage[i + j * Width]); 258 } 259 } 260 261 EPD_7IN5_HD_SendCommand(0x26); 262 for(i=0; i<Height*Width; i++) { 263 EPD_7IN5_HD_SendData(0xff); 264 } 265 EPD_7IN5_HD_SendCommand(0x22); 266 EPD_7IN5_HD_SendData(0xF7);//Load LUT from MCU(0x32) 267 EPD_7IN5_HD_SendCommand(0x20); 268 DEV_Delay_ms(10); 269 EPD_7IN5_HD_WaitUntilIdle(); 270 } 271 272 /****************************************************************************** 273 function : Enter sleep mode 274 parameter: 275 ******************************************************************************/ 276 void EPD_7IN5_HD_Sleep(void) 277 { 278 EPD_7IN5_HD_SendCommand(0x10); 279 EPD_7IN5_HD_SendData(0x01); 280 }