EPD_7in5.c (10235B)
1 /***************************************************************************** 2 * | File : EPD_7IN5.c 3 * | Author : Waveshare team 4 * | Function : 7.5inch 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_7IN5_Reset() 14 * EPD_SendCommand() => EPD_7IN5_SendCommand() 15 * EPD_SendData() => EPD_7IN5_SendData() 16 * EPD_WaitUntilIdle() => EPD_7IN5_ReadBusy() 17 * EPD_SetFullReg() => EPD_7IN5_SetFullReg() 18 * EPD_SetPartReg() => EPD_7IN5_SetPartReg() 19 * EPD_TurnOnDisplay() => EPD_7IN5_TurnOnDisplay() 20 * EPD_Init() => EPD_7IN5_Init() 21 * EPD_Clear() => EPD_7IN5_Clear() 22 * EPD_Display() => EPD_7IN5_Display() 23 * EPD_Sleep() => EPD_7IN5_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_7in5.h" 88 #include "Debug.h" 89 90 /****************************************************************************** 91 function : Software reset 92 parameter: 93 ******************************************************************************/ 94 static void EPD_7IN5_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_7IN5_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_7IN5_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 void EPD_7IN5_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 /****************************************************************************** 145 function : Turn On Display 146 parameter: 147 ******************************************************************************/ 148 static void EPD_7IN5_TurnOnDisplay(void) 149 { 150 EPD_7IN5_SendCommand(0x12); // DISPLAY_REFRESH 151 DEV_Delay_ms(100); 152 EPD_7IN5_ReadBusy(); 153 } 154 155 /****************************************************************************** 156 function : Initialize the e-Paper register 157 parameter: 158 ******************************************************************************/ 159 void EPD_7IN5_Init(void) 160 { 161 EPD_7IN5_Reset(); 162 163 EPD_7IN5_SendCommand(0x01); // POWER_SETTING 164 EPD_7IN5_SendData(0x37); 165 EPD_7IN5_SendData(0x00); 166 167 EPD_7IN5_SendCommand(0x00); // PANEL_SETTING 168 EPD_7IN5_SendData(0xCF); 169 EPD_7IN5_SendData(0x08); 170 171 EPD_7IN5_SendCommand(0x06); // BOOSTER_SOFT_START 172 EPD_7IN5_SendData(0xc7); 173 EPD_7IN5_SendData(0xcc); 174 EPD_7IN5_SendData(0x28); 175 176 EPD_7IN5_SendCommand(0x04); // POWER_ON 177 EPD_7IN5_ReadBusy(); 178 179 EPD_7IN5_SendCommand(0x30); // PLL_CONTROL 180 EPD_7IN5_SendData(0x3c); 181 182 EPD_7IN5_SendCommand(0x41); // TEMPERATURE_CALIBRATION 183 EPD_7IN5_SendData(0x00); 184 185 EPD_7IN5_SendCommand(0x50); // VCOM_AND_DATA_INTERVAL_SETTING 186 EPD_7IN5_SendData(0x77); 187 188 EPD_7IN5_SendCommand(0x60); // TCON_SETTING 189 EPD_7IN5_SendData(0x22); 190 191 EPD_7IN5_SendCommand(0x61); // TCON_RESOLUTION 192 EPD_7IN5_SendData(EPD_7IN5_WIDTH >> 8); // source 640 193 EPD_7IN5_SendData(EPD_7IN5_WIDTH & 0xff); 194 EPD_7IN5_SendData(EPD_7IN5_HEIGHT >> 8); // gate 384 195 EPD_7IN5_SendData(EPD_7IN5_HEIGHT & 0xff); 196 197 EPD_7IN5_SendCommand(0x82); // VCM_DC_SETTING 198 EPD_7IN5_SendData(0x1E); // decide by LUT file 199 200 EPD_7IN5_SendCommand(0xe5); // FLASH MODE 201 EPD_7IN5_SendData(0x03); 202 203 } 204 205 /****************************************************************************** 206 function : Clear screen 207 parameter: 208 ******************************************************************************/ 209 void EPD_7IN5_Clear(void) 210 { 211 UWORD Width, Height; 212 Width = (EPD_7IN5_WIDTH % 8 == 0)? (EPD_7IN5_WIDTH / 8 ): (EPD_7IN5_WIDTH / 8 + 1); 213 Height = EPD_7IN5_HEIGHT; 214 215 EPD_7IN5_SendCommand(0x10); 216 for (UWORD j = 0; j < Height; j++) { 217 for (UWORD i = 0; i < Width; i++) { 218 for(UBYTE k = 0; k < 4; k++) { 219 EPD_7IN5_SendData(0x33); 220 } 221 } 222 } 223 EPD_7IN5_TurnOnDisplay(); 224 } 225 226 /****************************************************************************** 227 function : Sends the image buffer in RAM to e-Paper and displays 228 parameter: 229 ******************************************************************************/ 230 void EPD_7IN5_Display(UBYTE *Image) 231 { 232 UBYTE Data_Black, Data; 233 UWORD Width, Height; 234 Width = (EPD_7IN5_WIDTH % 8 == 0)? (EPD_7IN5_WIDTH / 8 ): (EPD_7IN5_WIDTH / 8 + 1); 235 Height = EPD_7IN5_HEIGHT; 236 237 EPD_7IN5_SendCommand(0x10); 238 for (UWORD j = 0; j < Height; j++) { 239 for (UWORD i = 0; i < Width; i++) { 240 Data_Black = ~Image[i + j * Width]; 241 for(UBYTE k = 0; k < 8; k++) { 242 if(Data_Black & 0x80) 243 Data = 0x00; 244 else 245 Data = 0x03; 246 Data <<= 4; 247 Data_Black <<= 1; 248 k++; 249 if(Data_Black & 0x80) 250 Data |= 0x00; 251 else 252 Data |= 0x03; 253 Data_Black <<= 1; 254 EPD_7IN5_SendData(Data); 255 } 256 } 257 } 258 EPD_7IN5_TurnOnDisplay(); 259 } 260 261 /****************************************************************************** 262 function : Enter sleep mode 263 parameter: 264 ******************************************************************************/ 265 void EPD_7IN5_Sleep(void) 266 { 267 EPD_7IN5_SendCommand(0x02); // POWER_OFF 268 EPD_7IN5_ReadBusy(); 269 EPD_7IN5_SendCommand(0x07); // DEEP_SLEEP 270 EPD_7IN5_SendData(0XA5);; 271 }