EPD_5in65f.c (9250B)
1 /***************************************************************************** 2 * | File : EPD_5in65f.c 3 * | Author : Waveshare team 4 * | Function : 5.65inch e-paper 5 * | Info : 6 *---------------- 7 * | This version: V1.0 8 * | Date : 2020-07-07 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_5in65f.h" 32 33 34 /****************************************************************************** 35 function: 36 hardware reset 37 ******************************************************************************/ 38 static void EPD_5IN65F_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(1); 44 DEV_Digital_Write(EPD_RST_PIN, 1); 45 DEV_Delay_ms(200); 46 } 47 48 /****************************************************************************** 49 function: 50 send Command 51 ******************************************************************************/ 52 static void EPD_5IN65F_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: 62 send data 63 ******************************************************************************/ 64 static void EPD_5IN65F_SendData(UBYTE Data) 65 { 66 DEV_Digital_Write(EPD_DC_PIN, 1); 67 DEV_Digital_Write(EPD_CS_PIN, 0); 68 DEV_SPI_WriteByte(Data); 69 DEV_Digital_Write(EPD_CS_PIN, 1); 70 } 71 72 /****************************************************************************** 73 function: 74 io busy 75 ******************************************************************************/ 76 static void EPD_5IN65F_BusyHigh(void)// If BUSYN=0 then waiting 77 { 78 while(!(DEV_Digital_Read(EPD_BUSY_PIN))); 79 } 80 81 static void EPD_5IN65F_BusyLow(void)// If BUSYN=1 then waiting 82 { 83 while(DEV_Digital_Read(EPD_BUSY_PIN)); 84 } 85 86 /****************************************************************************** 87 function: 88 module init 89 ******************************************************************************/ 90 void EPD_5IN65F_Init(void) 91 { 92 EPD_5IN65F_Reset(); 93 EPD_5IN65F_BusyHigh(); 94 EPD_5IN65F_SendCommand(0x00); 95 EPD_5IN65F_SendData(0xEF); 96 EPD_5IN65F_SendData(0x08); 97 EPD_5IN65F_SendCommand(0x01); 98 EPD_5IN65F_SendData(0x37); 99 EPD_5IN65F_SendData(0x00); 100 EPD_5IN65F_SendData(0x23); 101 EPD_5IN65F_SendData(0x23); 102 EPD_5IN65F_SendCommand(0x03); 103 EPD_5IN65F_SendData(0x00); 104 EPD_5IN65F_SendCommand(0x06); 105 EPD_5IN65F_SendData(0xC7); 106 EPD_5IN65F_SendData(0xC7); 107 EPD_5IN65F_SendData(0x1D); 108 EPD_5IN65F_SendCommand(0x30); 109 EPD_5IN65F_SendData(0x3C); 110 EPD_5IN65F_SendCommand(0x40); 111 EPD_5IN65F_SendData(0x00); 112 EPD_5IN65F_SendCommand(0x50); 113 EPD_5IN65F_SendData(0x37); 114 EPD_5IN65F_SendCommand(0x60); 115 EPD_5IN65F_SendData(0x22); 116 EPD_5IN65F_SendCommand(0x61); 117 EPD_5IN65F_SendData(0x02); 118 EPD_5IN65F_SendData(0x58); 119 EPD_5IN65F_SendData(0x01); 120 EPD_5IN65F_SendData(0xC0); 121 EPD_5IN65F_SendCommand(0xE3); 122 EPD_5IN65F_SendData(0xAA); 123 124 DEV_Delay_ms(100); 125 EPD_5IN65F_SendCommand(0x50); 126 EPD_5IN65F_SendData(0x37); 127 } 128 129 /****************************************************************************** 130 function: 131 clear display 132 ******************************************************************************/ 133 void EPD_5IN65F_Clear(UBYTE color) 134 { 135 EPD_5IN65F_SendCommand(0x61);//Set Resolution setting 136 EPD_5IN65F_SendData(0x02); 137 EPD_5IN65F_SendData(0x58); 138 EPD_5IN65F_SendData(0x01); 139 EPD_5IN65F_SendData(0xC0); 140 EPD_5IN65F_SendCommand(0x10); 141 for(int i=0; i<EPD_5IN65F_HEIGHT; i++) { 142 for(int j=0; j<EPD_5IN65F_WIDTH/2; j++) 143 EPD_5IN65F_SendData((color<<4)|color); 144 } 145 EPD_5IN65F_SendCommand(0x04);//0x04 146 EPD_5IN65F_BusyHigh(); 147 EPD_5IN65F_SendCommand(0x12);//0x12 148 EPD_5IN65F_BusyHigh(); 149 EPD_5IN65F_SendCommand(0x02); //0x02 150 EPD_5IN65F_BusyLow(); 151 DEV_Delay_ms(500); 152 } 153 154 /****************************************************************************** 155 function: 156 show 7 kind of color block 157 ******************************************************************************/ 158 void EPD_5IN65F_Show7Block(void) 159 { 160 unsigned long i,j,k; 161 unsigned char const Color_seven[8] = 162 {EPD_5IN65F_BLACK,EPD_5IN65F_BLUE,EPD_5IN65F_GREEN,EPD_5IN65F_ORANGE, 163 EPD_5IN65F_RED,EPD_5IN65F_YELLOW,EPD_5IN65F_WHITE,EPD_5IN65F_WHITE}; 164 EPD_5IN65F_SendCommand(0x61);//Set Resolution setting 165 EPD_5IN65F_SendData(0x02); 166 EPD_5IN65F_SendData(0x58); 167 EPD_5IN65F_SendData(0x01); 168 EPD_5IN65F_SendData(0xC0); 169 EPD_5IN65F_SendCommand(0x10); 170 for(i=0; i<224; i++) { 171 for(k = 0 ; k < 4; k ++) { 172 for(j = 0 ; j < 75; j ++) { 173 EPD_5IN65F_SendData((Color_seven[k]<<4) |Color_seven[k]); 174 } 175 } 176 } 177 for(i=0; i<224; i++) { 178 for(k = 4 ; k < 8; k ++) { 179 for(j = 0 ; j < 75; j ++) { 180 EPD_5IN65F_SendData((Color_seven[k]<<4) |Color_seven[k]); 181 } 182 } 183 } 184 EPD_5IN65F_SendCommand(0x04);//0x04 185 EPD_5IN65F_BusyHigh(); 186 EPD_5IN65F_SendCommand(0x12);//0x12 187 EPD_5IN65F_BusyHigh(); 188 EPD_5IN65F_SendCommand(0x02); //0x02 189 EPD_5IN65F_BusyLow(); 190 DEV_Delay_ms(200); 191 } 192 193 /****************************************************************************** 194 function: 195 refresh display 196 ******************************************************************************/ 197 void EPD_5IN65F_Display(const UBYTE *image) 198 { 199 unsigned long i, j; 200 // UBYTE k = 0; 201 EPD_5IN65F_SendCommand(0x61);//Set Resolution setting 202 EPD_5IN65F_SendData(0x02); 203 EPD_5IN65F_SendData(0x58); 204 EPD_5IN65F_SendData(0x01); 205 EPD_5IN65F_SendData(0xC0); 206 EPD_5IN65F_SendCommand(0x10); 207 for(i=0; i<EPD_5IN65F_HEIGHT; i++) { 208 for(j=0; j<EPD_5IN65F_WIDTH/2; j++) { 209 EPD_5IN65F_SendData(image[j+((EPD_5IN65F_WIDTH/2)*i)]); 210 // printf("0x%x, ", image[j+((EPD_5IN65F_WIDTH/2)*i)]); 211 // k++; 212 // if(k == 16) { 213 // printf("\n"); 214 // k = 0; 215 // } 216 } 217 } 218 EPD_5IN65F_SendCommand(0x04);//0x04 219 EPD_5IN65F_BusyHigh(); 220 EPD_5IN65F_SendCommand(0x12);//0x12 221 EPD_5IN65F_BusyHigh(); 222 EPD_5IN65F_SendCommand(0x02); //0x02 223 EPD_5IN65F_BusyLow(); 224 DEV_Delay_ms(200); 225 } 226 227 void EPD_5IN65F_Display_part(const UBYTE *image, UWORD xstart, UWORD ystart, 228 UWORD image_width, UWORD image_heigh) 229 { 230 unsigned long i, j; 231 // UBYTE k = 0; 232 EPD_5IN65F_SendCommand(0x61);//Set Resolution setting 233 EPD_5IN65F_SendData(0x02); 234 EPD_5IN65F_SendData(0x58); 235 EPD_5IN65F_SendData(0x01); 236 EPD_5IN65F_SendData(0xC0); 237 EPD_5IN65F_SendCommand(0x10); 238 for(i=0; i<EPD_5IN65F_HEIGHT; i++) { 239 for(j=0; j< EPD_5IN65F_WIDTH/2; j++) { 240 if(i<image_heigh+ystart && i>=ystart && j<(image_width+xstart)/2 && j>=xstart/2) { 241 EPD_5IN65F_SendData(image[(j-xstart/2) + (image_width/2*(i-ystart))]); 242 // printf("0x%x, ", image[j+((EPD_5IN65F_WIDTH/2)*i)]); 243 // k++; 244 // if(k == 16) { 245 // printf("\r\n"); 246 // k = 0; 247 // } 248 } 249 else { 250 EPD_5IN65F_SendData(0x11); 251 } 252 } 253 } 254 EPD_5IN65F_SendCommand(0x04);//0x04 255 EPD_5IN65F_BusyHigh(); 256 EPD_5IN65F_SendCommand(0x12);//0x12 257 EPD_5IN65F_BusyHigh(); 258 EPD_5IN65F_SendCommand(0x02); //0x02 259 EPD_5IN65F_BusyLow(); 260 DEV_Delay_ms(200); 261 262 } 263 264 /****************************************************************************** 265 function: 266 Sleep 267 ******************************************************************************/ 268 void EPD_5IN65F_Sleep(void) 269 { 270 DEV_Delay_ms(100); 271 EPD_5IN65F_SendCommand(0x07); 272 EPD_5IN65F_SendData(0xA5); 273 DEV_Delay_ms(100); 274 DEV_Digital_Write(EPD_RST_PIN, 0); // Reset 275 } 276