EPD_5in83.c (10314B)
1 /***************************************************************************** 2 * | File : EPD_5in83.c 3 * | Author : Waveshare team 4 * | Function : 5.83inch e-paper 5 * | Info : 6 *---------------- 7 * | This version: V3.0 8 * | Date : 2019-06-13 9 * | Info : 10 * ----------------------------------------------------------------------------- 11 * V3.0(2019-06-13): 12 * 1.Change: 13 * EPD_Reset() => EPD_5IN83_Reset() 14 * EPD_SendCommand() => EPD_5IN83_SendCommand() 15 * EPD_SendData() => EPD_5IN83_SendData() 16 * EPD_WaitUntilIdle() => EPD_5IN83_ReadBusy() 17 * EPD_SetFullReg() => EPD_5IN83_SetFullReg() 18 * EPD_SetPartReg() => EPD_5IN83_SetPartReg() 19 * EPD_TurnOnDisplay() => EPD_5IN83_TurnOnDisplay() 20 * EPD_Init() => EPD_5IN83_Init() 21 * EPD_Clear() => EPD_5IN83_Clear() 22 * EPD_Display() => EPD_5IN83_Display() 23 * EPD_Sleep() => EPD_5IN83_Sleep() 24 * 2.remove commands define: 25 * #define PANEL_SETTING 0x00 26 * #define POWER_SETTING 0x01 27 * #define POWER_OFF 0x02 28 * #define POWER_OFF_SEQUENCE_SETTING 0x03 29 * #define POWER_ON 0x04 30 * #define POWER_ON_MEASURE 0x05 31 * #define BOOSTER_SOFT_START 0x06 32 * #define DEEP_SLEEP 0x07 33 * #define DATA_START_TRANSMISSION_1 0x10 34 * #define DATA_STOP 0x11 35 * #define DISPLAY_REFRESH 0x12 36 * #define DATA_START_TRANSMISSION_2 0x13 37 * #define VCOM_LUT 0x20 38 * #define W2W_LUT 0x21 39 * #define B2W_LUT 0x22 40 * #define W2B_LUT 0x23 41 * #define B2B_LUT 0x24 42 * #define PLL_CONTROL 0x30 43 * #define TEMPERATURE_SENSOR_CALIBRATION 0x40 44 * #define TEMPERATURE_SENSOR_SELECTION 0x41 45 * #define TEMPERATURE_SENSOR_WRITE 0x42 46 * #define TEMPERATURE_SENSOR_READ 0x43 47 * #define VCOM_AND_DATA_INTERVAL_SETTING 0x50 48 * #define LOW_POWER_DETECTION 0x51 49 * #define TCON_SETTING 0x60 50 * #define RESOLUTION_SETTING 0x61 51 * #define GET_STATUS 0x71 52 * #define AUTO_MEASURE_VCOM 0x80 53 * #define READ_VCOM_VALUE 0x81 54 * #define VCM_DC_SETTING 0x82 55 * #define PARTIAL_WINDOW 0x90 56 * #define PARTIAL_IN 0x91 57 * #define PARTIAL_OUT 0x92 58 * #define PROGRAM_MODE 0xA0 59 * #define ACTIVE_PROGRAM 0xA1 60 * #define READ_OTP_DATA 0xA2 61 * #define POWER_SAVING 0xE3 62 * ----------------------------------------------------------------------------- 63 * V2.0(2018-11-09): 64 * 1.Remove:ImageBuff[EPD_HEIGHT * EPD_WIDTH / 8] 65 * 2.Change:EPD_Display(UBYTE *Image) 66 * Need to pass parameters: pointer to cached data 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_5in83.h" 88 #include "Debug.h" 89 90 /****************************************************************************** 91 function : Software reset 92 parameter: 93 ******************************************************************************/ 94 static void EPD_5IN83_Reset(void) 95 { 96 DEV_Digital_Write(EPD_RST_PIN, 1); 97 DEV_Delay_ms(200); 98 DEV_Digital_Write(EPD_RST_PIN, 0); 99 DEV_Delay_ms(200); 100 DEV_Digital_Write(EPD_RST_PIN, 1); 101 DEV_Delay_ms(200); 102 } 103 104 /****************************************************************************** 105 function : send command 106 parameter: 107 Reg : Command register 108 ******************************************************************************/ 109 static void EPD_5IN83_SendCommand(UBYTE Reg) 110 { 111 DEV_Digital_Write(EPD_DC_PIN, 0); 112 DEV_Digital_Write(EPD_CS_PIN, 0); 113 DEV_SPI_WriteByte(Reg); 114 DEV_Digital_Write(EPD_CS_PIN, 1); 115 } 116 117 /****************************************************************************** 118 function : send data 119 parameter: 120 Data : Write data 121 ******************************************************************************/ 122 static void EPD_5IN83_SendData(UBYTE Data) 123 { 124 DEV_Digital_Write(EPD_DC_PIN, 1); 125 DEV_Digital_Write(EPD_CS_PIN, 0); 126 DEV_SPI_WriteByte(Data); 127 DEV_Digital_Write(EPD_CS_PIN, 1); 128 } 129 130 /****************************************************************************** 131 function : Wait until the busy_pin goes LOW 132 parameter: 133 ******************************************************************************/ 134 static void EPD_5IN83_ReadBusy(void) 135 { 136 Debug("e-Paper busy\r\n"); 137 while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) { //LOW: idle, HIGH: busy 138 DEV_Delay_ms(100); 139 } 140 Debug("e-Paper busy release\r\n"); 141 } 142 143 /****************************************************************************** 144 function : Turn On Display 145 parameter: 146 ******************************************************************************/ 147 static void EPD_5IN83_TurnOnDisplay(void) 148 { 149 EPD_5IN83_SendCommand(0x12); // DISPLAY_REFRESH 150 DEV_Delay_ms(100); 151 EPD_5IN83_ReadBusy(); 152 } 153 154 /****************************************************************************** 155 function : Initialize the e-Paper register 156 parameter: 157 ******************************************************************************/ 158 void EPD_5IN83_Init(void) 159 { 160 EPD_5IN83_Reset(); 161 162 EPD_5IN83_SendCommand(0x01); // POWER_SETTING 163 EPD_5IN83_SendData(0x37); 164 EPD_5IN83_SendData(0x00); 165 166 EPD_5IN83_SendCommand(0x00); // PANEL_SETTING 167 EPD_5IN83_SendData(0xCF); 168 EPD_5IN83_SendData(0x08); 169 170 EPD_5IN83_SendCommand(0x06); // BOOSTER_SOFT_START 171 EPD_5IN83_SendData(0xc7); 172 EPD_5IN83_SendData(0xcc); 173 EPD_5IN83_SendData(0x28); 174 175 EPD_5IN83_SendCommand(0x04); // POWER_ON 176 EPD_5IN83_ReadBusy(); 177 178 EPD_5IN83_SendCommand(0x30); // PLL_CONTROL 179 EPD_5IN83_SendData(0x3c); 180 181 EPD_5IN83_SendCommand(0x41); // TEMPERATURE_CALIBRATION 182 EPD_5IN83_SendData(0x00); 183 184 EPD_5IN83_SendCommand(0x50); // VCOM_AND_DATA_INTERVAL_SETTING 185 EPD_5IN83_SendData(0x77); 186 187 EPD_5IN83_SendCommand(0x60); // TCON_SETTING 188 EPD_5IN83_SendData(0x22); 189 190 EPD_5IN83_SendCommand(0x61); // TCON_RESOLUTION 191 EPD_5IN83_SendData(EPD_5IN83_WIDTH >> 8); // source 600 192 EPD_5IN83_SendData(EPD_5IN83_WIDTH & 0xff); 193 EPD_5IN83_SendData(EPD_5IN83_HEIGHT >> 8); // gate 448 194 EPD_5IN83_SendData(EPD_5IN83_HEIGHT & 0xff); 195 196 EPD_5IN83_SendCommand(0x82); // VCM_DC_SETTING 197 EPD_5IN83_SendData(0x1E); // decide by LUT file 198 199 EPD_5IN83_SendCommand(0xe5); // FLASH MODE 200 EPD_5IN83_SendData(0x03); 201 } 202 203 /****************************************************************************** 204 function : Clear screen 205 parameter: 206 ******************************************************************************/ 207 void EPD_5IN83_Clear(void) 208 { 209 UWORD Width, Height; 210 Width = (EPD_5IN83_WIDTH % 8 == 0)? (EPD_5IN83_WIDTH / 8 ): (EPD_5IN83_WIDTH / 8 + 1); 211 Height = EPD_5IN83_HEIGHT; 212 213 EPD_5IN83_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_5IN83_SendData(0x33); 218 } 219 } 220 } 221 EPD_5IN83_TurnOnDisplay(); 222 } 223 224 /****************************************************************************** 225 function : Sends the image buffer in RAM to e-Paper and displays 226 parameter: 227 ******************************************************************************/ 228 void EPD_5IN83_Display(UBYTE *Image) 229 { 230 UBYTE Data_Black, Data; 231 UWORD Width, Height; 232 Width = (EPD_5IN83_WIDTH % 8 == 0)? (EPD_5IN83_WIDTH / 8 ): (EPD_5IN83_WIDTH / 8 + 1); 233 Height = EPD_5IN83_HEIGHT; 234 235 EPD_5IN83_SendCommand(0x10); 236 for (UWORD j = 0; j < Height; j++) { 237 for (UWORD i = 0; i < Width; i++) { 238 Data_Black = ~Image[i + j * Width]; 239 for(UBYTE k = 0; k < 8; k++) { 240 if(Data_Black & 0x80) 241 Data = 0x00; 242 else 243 Data = 0x03; 244 Data <<= 4; 245 Data_Black <<= 1; 246 k++; 247 if(Data_Black & 0x80) 248 Data |= 0x00; 249 else 250 Data |= 0x03; 251 Data_Black <<= 1; 252 EPD_5IN83_SendData(Data); 253 } 254 } 255 } 256 EPD_5IN83_TurnOnDisplay(); 257 } 258 259 /****************************************************************************** 260 function : Enter sleep mode 261 parameter: 262 ******************************************************************************/ 263 void EPD_5IN83_Sleep(void) 264 { 265 EPD_5IN83_SendCommand(0x02); // POWER_OFF 266 EPD_5IN83_ReadBusy(); 267 EPD_5IN83_SendCommand(0x07); // DEEP_SLEEP 268 EPD_5IN83_SendData(0XA5); 269 } 270