EPD_7in5bc.c (12670B)
1 /***************************************************************************** 2 * | File : EPD_7IN5BC.h 3 * | Author : Waveshare team 4 * | Function : 7.5inch e-paper b&c 5 * | Info : 6 * | This version: V3.0 7 * | Date : 2019-06-13 8 * | Info : 9 * ----------------------------------------------------------------------------- 10 * V3.0(2019-06-13): 11 * 1.Change: 12 * EPD_Reset() => EPD_7IN5BC_Reset() 13 * EPD_SendCommand() => EPD_7IN5BC_SendCommand() 14 * EPD_SendData() => EPD_7IN5BC_SendData() 15 * EPD_WaitUntilIdle() => EPD_7IN5BC_ReadBusy() 16 * EPD_Init() => EPD_7IN5BC_Init() 17 * EPD_Clear() => EPD_7IN5BC_Clear() 18 * EPD_Display() => EPD_7IN5BC_Display() 19 * EPD_Sleep() => EPD_7IN5BC_Sleep() 20 * 2.Remove: 21 * #define PANEL_SETTING 0x00 22 * #define POWER_SETTING 0x01 23 * #define POWER_OFF 0x02 24 * #define POWER_OFF_SEQUENCE_SETTING 0x03 25 * #define POWER_ON 0x04 26 * #define POWER_ON_MEASURE 0x05 27 * #define BOOSTER_SOFT_START 0x06 28 * #define DEEP_SLEEP 0x07 29 * #define DATA_START_TRANSMISSION_1 0x10 30 * #define DATA_STOP 0x11 31 * #define DISPLAY_REFRESH 0x12 32 * #define IMAGE_PROCESS 0x13 33 * #define LUT_FOR_VCOM 0x20 34 * #define LUT_BLUE 0x21 35 * #define LUT_WHITE 0x22 36 * #define LUT_GRAY_1 0x23 37 * #define LUT_GRAY_2 0x24 38 * #define LUT_RED_0 0x25 39 * #define LUT_RED_1 0x26 40 * #define LUT_RED_2 0x27 41 * #define LUT_RED_3 0x28 42 * #define LUT_XON 0x29 43 * #define PLL_CONTROL 0x30 44 * #define TEMPERATURE_SENSOR_COMMAND 0x40 45 * #define TEMPERATURE_CALIBRATION 0x41 46 * #define TEMPERATURE_SENSOR_WRITE 0x42 47 * #define TEMPERATURE_SENSOR_READ 0x43 48 * #define VCOM_AND_DATA_INTERVAL_SETTING 0x50 49 * #define LOW_POWER_DETECTION 0x51 50 * #define TCON_SETTING 0x60 51 * #define TCON_RESOLUTION 0x61 52 * #define SPI_FLASH_CONTROL 0x65 53 * #define REVISION 0x70 54 * #define GET_STATUS 0x71 55 * #define AUTO_MEASUREMENT_VCOM 0x80 56 * #define READ_VCOM_VALUE 0x81 57 * #define VCM_DC_SETTING 0x82 58 * 3.add: 59 * EPD_7IN5BC_DisplayHalfScreen() 60 * ----------------------------------------------------------------------------- 61 * V2.0(2018-11-09): 62 * 1.Remove:ImageBuff[EPD_HEIGHT * EPD_WIDTH / 8] 63 * 2.Change:EPD_Display(UBYTE *Image) 64 * Need to pass parameters: pointer to cached data 65 # 66 # Permission is hereby granted, free of charge, to any person obtaining a copy 67 # of this software and associated documnetation files (the "Software"), to deal 68 # in the Software without restriction, including without limitation the rights 69 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 70 # copies of the Software, and to permit persons to whom the Software is 71 # furished to do so, subject to the following conditions: 72 # 73 # The above copyright notice and this permission notice shall be included in 74 # all copies or substantial portions of the Software. 75 # 76 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 77 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 78 # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 79 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 80 # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 81 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 82 # THE SOFTWARE. 83 # 84 ******************************************************************************/ 85 #include "EPD_7in5bc.h" 86 #include "Debug.h" 87 88 /****************************************************************************** 89 function : Software reset 90 parameter: 91 ******************************************************************************/ 92 static void EPD_7IN5BC_Reset(void) 93 { 94 DEV_Digital_Write(EPD_RST_PIN, 1); 95 DEV_Delay_ms(200); 96 DEV_Digital_Write(EPD_RST_PIN, 0); 97 DEV_Delay_ms(10); 98 DEV_Digital_Write(EPD_RST_PIN, 1); 99 DEV_Delay_ms(200); 100 } 101 102 /****************************************************************************** 103 function : send command 104 parameter: 105 Reg : Command register 106 ******************************************************************************/ 107 static void EPD_7IN5BC_SendCommand(UBYTE Reg) 108 { 109 DEV_Digital_Write(EPD_DC_PIN, 0); 110 DEV_Digital_Write(EPD_CS_PIN, 0); 111 DEV_SPI_WriteByte(Reg); 112 DEV_Digital_Write(EPD_CS_PIN, 1); 113 } 114 115 /****************************************************************************** 116 function : send data 117 parameter: 118 Data : Write data 119 ******************************************************************************/ 120 static void EPD_7IN5BC_SendData(UBYTE Data) 121 { 122 DEV_Digital_Write(EPD_DC_PIN, 1); 123 DEV_Digital_Write(EPD_CS_PIN, 0); 124 DEV_SPI_WriteByte(Data); 125 DEV_Digital_Write(EPD_CS_PIN, 1); 126 } 127 128 /****************************************************************************** 129 function : Wait until the busy_pin goes LOW 130 parameter: 131 ******************************************************************************/ 132 void EPD_7IN5BC_ReadBusy(void) 133 { 134 UBYTE busy; 135 Debug("e-Paper busy\r\n"); 136 do { 137 EPD_7IN5BC_SendCommand(0x71); 138 busy = DEV_Digital_Read(EPD_BUSY_PIN); 139 busy =!(busy & 0x01); 140 } while(busy); 141 Debug("e-Paper busy release\r\n"); 142 } 143 144 /****************************************************************************** 145 function : Turn On Display 146 parameter: 147 ******************************************************************************/ 148 static void EPD_7IN5BC_TurnOnDisplay(void) 149 { 150 EPD_7IN5BC_SendCommand(0x04); // POWER ON 151 EPD_7IN5BC_ReadBusy(); 152 EPD_7IN5BC_SendCommand(0x12); // display refresh 153 DEV_Delay_ms(100); 154 EPD_7IN5BC_ReadBusy(); 155 } 156 157 /****************************************************************************** 158 function : Initialize the e-Paper register 159 parameter: 160 ******************************************************************************/ 161 void EPD_7IN5BC_Init(void) 162 { 163 EPD_7IN5BC_Reset(); 164 165 EPD_7IN5BC_SendCommand(0x01); // POWER_SETTING 166 EPD_7IN5BC_SendData(0x37); 167 EPD_7IN5BC_SendData(0x00); 168 169 EPD_7IN5BC_SendCommand(0x00); // PANEL_SETTING 170 EPD_7IN5BC_SendData(0xCF); 171 EPD_7IN5BC_SendData(0x08); 172 173 EPD_7IN5BC_SendCommand(0x30); // PLL_CONTROL 174 EPD_7IN5BC_SendData(0x3A); // PLL: 0-15:0x3C, 15+:0x3A 175 176 EPD_7IN5BC_SendCommand(0x82); // VCM_DC_SETTING 177 EPD_7IN5BC_SendData(0x28); //all temperature range 178 179 EPD_7IN5BC_SendCommand(0x06); // BOOSTER_SOFT_START 180 EPD_7IN5BC_SendData (0xc7); 181 EPD_7IN5BC_SendData (0xcc); 182 EPD_7IN5BC_SendData (0x15); 183 184 EPD_7IN5BC_SendCommand(0x50); // VCOM AND DATA INTERVAL SETTING 185 EPD_7IN5BC_SendData(0x77); 186 187 EPD_7IN5BC_SendCommand(0x60); // TCON_SETTING 188 EPD_7IN5BC_SendData(0x22); 189 190 EPD_7IN5BC_SendCommand(0x65); // FLASH CONTROL 191 EPD_7IN5BC_SendData(0x00); 192 193 EPD_7IN5BC_SendCommand(0x61); // TCON_RESOLUTION 194 EPD_7IN5BC_SendData(EPD_7IN5BC_WIDTH >> 8); // source 640 195 EPD_7IN5BC_SendData(EPD_7IN5BC_WIDTH & 0xff); 196 EPD_7IN5BC_SendData(EPD_7IN5BC_HEIGHT >> 8); // gate 384 197 EPD_7IN5BC_SendData(EPD_7IN5BC_HEIGHT & 0xff); 198 199 EPD_7IN5BC_SendCommand(0xe5); // FLASH MODE 200 EPD_7IN5BC_SendData(0x03); 201 } 202 203 /****************************************************************************** 204 function : Clear screen 205 parameter: 206 ******************************************************************************/ 207 void EPD_7IN5BC_Clear(void) 208 { 209 UWORD Width, Height; 210 Width = (EPD_7IN5BC_WIDTH % 8 == 0)? (EPD_7IN5BC_WIDTH / 8): (EPD_7IN5BC_WIDTH / 8 + 1); 211 Height = EPD_7IN5BC_HEIGHT; 212 213 EPD_7IN5BC_SendCommand(0x10); 214 for (UWORD j = 0; j < Height; j++) { 215 for (UWORD i = 0; i < Width; i++) { 216 for(UBYTE k = 0; k < 4; k++) { 217 EPD_7IN5BC_SendData(0x33); 218 } 219 } 220 } 221 222 EPD_7IN5BC_TurnOnDisplay(); 223 } 224 225 /****************************************************************************** 226 function : Sends the image buffer in RAM to e-Paper and displays 227 parameter: 228 ******************************************************************************/ 229 void EPD_7IN5BC_Display(const UBYTE *blackimage, const UBYTE *ryimage) 230 { 231 UBYTE Data_Black, Data_RY, Data; 232 UDOUBLE i, j, Width, Height; 233 Width = (EPD_7IN5BC_WIDTH % 8 == 0)? (EPD_7IN5BC_WIDTH / 8 ): (EPD_7IN5BC_WIDTH / 8 + 1); 234 Height = EPD_7IN5BC_HEIGHT; 235 236 EPD_7IN5BC_SendCommand(0x10); 237 for (j = 0; j < Height; j++) { 238 for (i = 0; i < Width; i++) { 239 Data_Black = blackimage[i + j * Width]; 240 Data_RY = ryimage[i + j * Width]; // red or yellow 241 for(UBYTE k = 0; k < 8; k++) { 242 if ((Data_RY & 0x80) == 0x00) { 243 Data = 0x04; //red 244 } else if ((Data_Black & 0x80) == 0x00) { 245 Data = 0x00; //black 246 } else { 247 Data = 0x03; //white 248 } 249 Data = (Data << 4) & 0xFF; 250 Data_Black = (Data_Black << 1) & 0xFF; 251 Data_RY = (Data_RY << 1) & 0xFF; 252 k += 1; 253 254 if((Data_RY & 0x80) == 0x00) { 255 Data |= 0x04; //red 256 } else if ((Data_Black & 0x80) == 0x00) { 257 Data |= 0x00; //black 258 } else { 259 Data |= 0x03; //white 260 } 261 Data_Black = (Data_Black << 1) & 0xFF; 262 Data_RY = (Data_RY << 1) & 0xFF; 263 EPD_7IN5BC_SendData(Data); 264 } 265 } 266 } 267 268 EPD_7IN5BC_TurnOnDisplay(); 269 } 270 271 void EPD_7IN5BC_DisplayHalfScreen(const UBYTE *blackimage, const UBYTE *ryimage) 272 { 273 UBYTE Data_Black, Data_RY, Data; 274 UDOUBLE i, j, Width, Height; 275 Width = (EPD_7IN5BC_WIDTH % 8 == 0)? (EPD_7IN5BC_WIDTH / 8 ): (EPD_7IN5BC_WIDTH / 8 + 1); 276 Height = EPD_7IN5BC_HEIGHT; 277 278 EPD_7IN5BC_SendCommand(0x10); 279 for (j = 0; j < Height / 2; j++) { 280 for (i = 0; i < Width; i++) { 281 Data_Black = blackimage[i + j * Width]; 282 Data_RY = ryimage[i + j * Width]; // red or yellow 283 for(UBYTE k = 0; k < 8; k++) { 284 if ((Data_RY & 0x80) == 0x00) { 285 Data = 0x04; //red 286 } else if ((Data_Black & 0x80) == 0x00) { 287 Data = 0x00; //black 288 } else { 289 Data = 0x03; //white 290 } 291 Data = (Data << 4) & 0xFF; 292 Data_Black = (Data_Black << 1) & 0xFF; 293 Data_RY = (Data_RY << 1) & 0xFF; 294 k += 1; 295 296 if((Data_RY & 0x80) == 0x00) { 297 Data |= 0x04; //red 298 } else if ((Data_Black & 0x80) == 0x00) { 299 Data |= 0x00; //black 300 } else { 301 Data |= 0x03; //white 302 } 303 Data_Black = (Data_Black << 1) & 0xFF; 304 Data_RY = (Data_RY << 1) & 0xFF; 305 EPD_7IN5BC_SendData(Data); 306 } 307 } 308 } 309 310 for (j = 0; j < Height / 2; j++) { 311 for (i = 0; i < Width; i++) { 312 for(UBYTE k = 0; k < 4; k++) { 313 EPD_7IN5BC_SendData(Data); 314 } 315 } 316 } 317 318 EPD_7IN5BC_TurnOnDisplay(); 319 } 320 321 /****************************************************************************** 322 function : Enter sleep mode 323 parameter: 324 ******************************************************************************/ 325 void EPD_7IN5BC_Sleep(void) 326 { 327 EPD_7IN5BC_SendCommand(0x02); // POWER_OFF 328 EPD_7IN5BC_ReadBusy(); 329 EPD_7IN5BC_SendCommand(0x07); // DEEP_SLEEP 330 EPD_7IN5BC_SendData(0XA5); 331 }