EPD_1in54.c (11583B)
1 /***************************************************************************** 2 * | File : EPD_1in54.C 3 * | Author : Waveshare team 4 * | Function : 1.54inch e-paper 5 * | Info : 6 *---------------- 7 * | This version: V3.0 8 * | Date : 2019-06-12 9 * | Info : 10 * ----------------------------------------------------------------------------- 11 * V3.0(2019-06-12): 12 * 1.Change: 13 * lut_full_update[] => EPD_1IN54_lut_full_update[] 14 * lut_partial_update[] => EPD_1IN54_lut_partial_update[] 15 * EPD_Reset() => EPD_1IN54_Reset() 16 * EPD_SendCommand() => EPD_1IN54_SendCommand() 17 * EPD_SendData() => EPD_1IN54_SendData() 18 * EPD_WaitUntilIdle() => EPD_1IN54_ReadBusy() 19 * EPD_SetLut() => EPD_1IN54_SetLut() 20 * EPD_SetWindow() => EPD_1IN54_SetWindow() 21 * EPD_SetCursor() => EPD_1IN54_SetCursor() 22 * EPD_TurnOnDisplay() => EPD_1IN54_TurnOnDisplay() 23 * EPD_Init() => EPD_1IN54_Init() 24 * EPD_Clear() => EPD_1IN54_Clear() 25 * EPD_Display() => EPD_1IN54_Display() 26 * EPD_Sleep() => EPD_1IN54_Sleep() 27 * 2.remove commands define: 28 * #define PANEL_SETTING 0x00 29 * #define POWER_SETTING 0x01 30 * #define POWER_OFF 0x02 31 * #define POWER_OFF_SEQUENCE_SETTING 0x03 32 * #define POWER_ON 0x04 33 * #define POWER_ON_MEASURE 0x05 34 * #define BOOSTER_SOFT_START 0x06 35 * #define DEEP_SLEEP 0x07 36 * #define DATA_START_TRANSMISSION_1 0x10 37 * #define DATA_STOP 0x11 38 * #define DISPLAY_REFRESH 0x12 39 * #define DATA_START_TRANSMISSION_2 0x13 40 * #define PLL_CONTROL 0x30 41 * #define TEMPERATURE_SENSOR_COMMAND 0x40 42 * #define TEMPERATURE_SENSOR_CALIBRATION 0x41 43 * #define TEMPERATURE_SENSOR_WRITE 0x42 44 * #define TEMPERATURE_SENSOR_READ 0x43 45 * #define VCOM_AND_DATA_INTERVAL_SETTING 0x50 46 * #define LOW_POWER_DETECTION 0x51 47 * #define TCON_SETTING 0x60 48 * #define TCON_RESOLUTION 0x61 49 * #define SOURCE_AND_GATE_START_SETTING 0x62 50 * #define GET_STATUS 0x71 51 * #define AUTO_MEASURE_VCOM 0x80 52 * #define VCOM_VALUE 0x81 53 * #define VCM_DC_SETTING_REGISTER 0x82 54 * #define PROGRAM_MODE 0xA0 55 * #define ACTIVE_PROGRAM 0xA1 56 * #define READ_OTP_DATA 0xA2 57 * ----------------------------------------------------------------------------- 58 * V2.0(2018-10-30): 59 * 1.Remove:ImageBuff[EPD_1IN54_HEIGHT * EPD_1IN54_WIDTH / 8] 60 * 2.Change:EPD_Display(UBYTE *Image) 61 * Need to pass parameters: pointer to cached data 62 * 3.Change: 63 * EPD_RST -> EPD_RST_PIN 64 * EPD_DC -> EPD_DC_PIN 65 * EPD_CS -> EPD_CS_PIN 66 * EPD_BUSY -> EPD_BUSY_PIN 67 # 68 # Permission is hereby granted, free of charge, to any person obtaining a copy 69 # of this software and associated documnetation files (the "Software"), to deal 70 # in the Software without restriction, including without limitation the rights 71 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 72 # copies of the Software, and to permit persons to whom the Software is 73 # furished to do so, subject to the following conditions: 74 # 75 # The above copyright notice and this permission notice shall be included in 76 # all copies or substantial portions of the Software. 77 # 78 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 79 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 80 # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 81 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 82 # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 83 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 84 # THE SOFTWARE. 85 # 86 ******************************************************************************/ 87 #include "EPD_1in54.h" 88 #include "Debug.h" 89 90 static const unsigned char EPD_1IN54_lut_full_update[] = { 91 0x02, 0x02, 0x01, 0x11, 0x12, 0x12, 0x22, 0x22, 92 0x66, 0x69, 0x69, 0x59, 0x58, 0x99, 0x99, 0x88, 93 0x00, 0x00, 0x00, 0x00, 0xF8, 0xB4, 0x13, 0x51, 94 0x35, 0x51, 0x51, 0x19, 0x01, 0x00 95 }; 96 97 static const unsigned char EPD_1IN54_lut_partial_update[] = { 98 0x10, 0x18, 0x18, 0x08, 0x18, 0x18, 0x08, 0x00, 99 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 100 0x00, 0x00, 0x00, 0x00, 0x13, 0x14, 0x44, 0x12, 101 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 102 }; 103 104 /****************************************************************************** 105 function : Software reset 106 parameter: 107 ******************************************************************************/ 108 static void EPD_1IN54_Reset(void) 109 { 110 DEV_Digital_Write(EPD_RST_PIN, 1); 111 DEV_Delay_ms(200); 112 DEV_Digital_Write(EPD_RST_PIN, 0); 113 DEV_Delay_ms(10); 114 DEV_Digital_Write(EPD_RST_PIN, 1); 115 DEV_Delay_ms(200); 116 } 117 118 /****************************************************************************** 119 function : send command 120 parameter: 121 Reg : Command register 122 ******************************************************************************/ 123 static void EPD_1IN54_SendCommand(UBYTE Reg) 124 { 125 DEV_Digital_Write(EPD_DC_PIN, 0); 126 DEV_Digital_Write(EPD_CS_PIN, 0); 127 DEV_SPI_WriteByte(Reg); 128 DEV_Digital_Write(EPD_CS_PIN, 1); 129 } 130 131 /****************************************************************************** 132 function : send data 133 parameter: 134 Data : Write data 135 ******************************************************************************/ 136 static void EPD_1IN54_SendData(UBYTE Data) 137 { 138 DEV_Digital_Write(EPD_DC_PIN, 1); 139 DEV_Digital_Write(EPD_CS_PIN, 0); 140 DEV_SPI_WriteByte(Data); 141 DEV_Digital_Write(EPD_CS_PIN, 1); 142 } 143 144 /****************************************************************************** 145 function : Wait until the busy_pin goes LOW 146 parameter: 147 ******************************************************************************/ 148 void EPD_1IN54_ReadBusy(void) 149 { 150 Debug("e-Paper busy\r\n"); 151 while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) { //LOW: idle, HIGH: busy 152 DEV_Delay_ms(100); 153 } 154 Debug("e-Paper busy release\r\n"); 155 } 156 157 /****************************************************************************** 158 function : Setting the display window 159 parameter: 160 ******************************************************************************/ 161 static void EPD_1IN54_SetWindow(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend) 162 { 163 EPD_1IN54_SendCommand(0x44); // SET_RAM_X_ADDRESS_START_END_POSITION 164 EPD_1IN54_SendData((Xstart >> 3) & 0xFF); 165 EPD_1IN54_SendData((Xend >> 3) & 0xFF); 166 167 EPD_1IN54_SendCommand(0x45); // SET_RAM_Y_ADDRESS_START_END_POSITION 168 EPD_1IN54_SendData(Ystart & 0xFF); 169 EPD_1IN54_SendData((Ystart >> 8) & 0xFF); 170 EPD_1IN54_SendData(Yend & 0xFF); 171 EPD_1IN54_SendData((Yend >> 8) & 0xFF); 172 } 173 174 /****************************************************************************** 175 function : Set Cursor 176 parameter: 177 ******************************************************************************/ 178 static void EPD_1IN54_SetCursor(UWORD Xstart, UWORD Ystart) 179 { 180 EPD_1IN54_SendCommand(0x4E); // SET_RAM_X_ADDRESS_COUNTER 181 EPD_1IN54_SendData((Xstart >> 3) & 0xFF); 182 183 EPD_1IN54_SendCommand(0x4F); // SET_RAM_Y_ADDRESS_COUNTER 184 EPD_1IN54_SendData(Ystart & 0xFF); 185 EPD_1IN54_SendData((Ystart >> 8) & 0xFF); 186 } 187 188 /****************************************************************************** 189 function : Turn On Display 190 parameter: 191 ******************************************************************************/ 192 static void EPD_1IN54_TurnOnDisplay(void) 193 { 194 EPD_1IN54_SendCommand(0x22); // DISPLAY_UPDATE_CONTROL_2 195 EPD_1IN54_SendData(0xC4); 196 EPD_1IN54_SendCommand(0x20); // MASTER_ACTIVATION 197 EPD_1IN54_SendCommand(0xFF); // TERMINATE_FRAME_READ_WRITE 198 199 EPD_1IN54_ReadBusy(); 200 } 201 202 /****************************************************************************** 203 function : Initialize the e-Paper register 204 parameter: 205 ******************************************************************************/ 206 void EPD_1IN54_Init(UBYTE Mode) 207 { 208 EPD_1IN54_Reset(); 209 210 EPD_1IN54_SendCommand(0x01); // DRIVER_OUTPUT_CONTROL 211 EPD_1IN54_SendData((EPD_1IN54_HEIGHT - 1) & 0xFF); 212 EPD_1IN54_SendData(((EPD_1IN54_HEIGHT - 1) >> 8) & 0xFF); 213 EPD_1IN54_SendData(0x00); // GD = 0; SM = 0; TB = 0; 214 215 EPD_1IN54_SendCommand(0x0C); // BOOSTER_SOFT_START_CONTROL 216 EPD_1IN54_SendData(0xD7); 217 EPD_1IN54_SendData(0xD6); 218 EPD_1IN54_SendData(0x9D); 219 220 EPD_1IN54_SendCommand(0x2C); // WRITE_VCOM_REGISTER 221 EPD_1IN54_SendData(0xA8); // VCOM 7C 222 223 EPD_1IN54_SendCommand(0x3A); // SET_DUMMY_LINE_PERIOD 224 EPD_1IN54_SendData(0x1A); // 4 dummy lines per gate 225 226 EPD_1IN54_SendCommand(0x3B); // SET_GATE_TIME 227 EPD_1IN54_SendData(0x08); // 2us per line 228 229 EPD_1IN54_SendCommand(0x11); 230 EPD_1IN54_SendData(0x03); 231 232 //set the look-up table register 233 EPD_1IN54_SendCommand(0x32); 234 if(Mode == EPD_1IN54_FULL){ 235 for (UWORD i = 0; i < 30; i++) { 236 EPD_1IN54_SendData(EPD_1IN54_lut_full_update[i]); 237 } 238 }else if(Mode == EPD_1IN54_PART){ 239 for (UWORD i = 0; i < 30; i++) { 240 EPD_1IN54_SendData(EPD_1IN54_lut_partial_update[i]); 241 } 242 }else{ 243 Debug("error, the Mode is EPD_1IN54_FULL or EPD_1IN54_PART"); 244 } 245 246 } 247 248 /****************************************************************************** 249 function : Clear screen 250 parameter: 251 ******************************************************************************/ 252 void EPD_1IN54_Clear(void) 253 { 254 UWORD Width, Height; 255 Width = (EPD_1IN54_WIDTH % 8 == 0)? (EPD_1IN54_WIDTH / 8 ): (EPD_1IN54_WIDTH / 8 + 1); 256 Height = EPD_1IN54_HEIGHT; 257 EPD_1IN54_SetWindow(0, 0, EPD_1IN54_WIDTH, EPD_1IN54_HEIGHT); 258 for (UWORD j = 0; j < Height; j++) { 259 EPD_1IN54_SetCursor(0, j); 260 EPD_1IN54_SendCommand(0x24); 261 for (UWORD i = 0; i < Width; i++) { 262 EPD_1IN54_SendData(0XFF); 263 } 264 } 265 EPD_1IN54_TurnOnDisplay(); 266 } 267 268 /****************************************************************************** 269 function : Sends the image buffer in RAM to e-Paper and displays 270 parameter: 271 ******************************************************************************/ 272 void EPD_1IN54_Display(UBYTE *Image) 273 { 274 UWORD Width, Height; 275 Width = (EPD_1IN54_WIDTH % 8 == 0)? (EPD_1IN54_WIDTH / 8 ): (EPD_1IN54_WIDTH / 8 + 1); 276 Height = EPD_1IN54_HEIGHT; 277 278 UDOUBLE Addr = 0; 279 // UDOUBLE Offset = ImageName; 280 EPD_1IN54_SetWindow(0, 0, EPD_1IN54_WIDTH, EPD_1IN54_HEIGHT); 281 for (UWORD j = 0; j < Height; j++) { 282 EPD_1IN54_SetCursor(0, j); 283 EPD_1IN54_SendCommand(0x24); 284 for (UWORD i = 0; i < Width; i++) { 285 Addr = i + j * Width; 286 EPD_1IN54_SendData(Image[Addr]); 287 } 288 } 289 EPD_1IN54_TurnOnDisplay(); 290 } 291 292 /****************************************************************************** 293 function : Enter sleep mode 294 parameter: 295 ******************************************************************************/ 296 void EPD_1IN54_Sleep(void) 297 { 298 EPD_1IN54_SendCommand(0x10); 299 EPD_1IN54_SendData(0x01); 300 }