1 /*****************************************************************************
3 * | Author : Waveshare team
4 * | Function : 7.5inch e-paper
10 * -----------------------------------------------------------------------------
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 * -----------------------------------------------------------------------------
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
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:
75 # The above copyright notice and this permission notice shall be included in
76 # all copies or substantial portions of the Software.
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
86 ******************************************************************************/
90 /******************************************************************************
91 function : Software reset
93 ******************************************************************************/
94 static void EPD_7IN5_Reset(void)
96 DEV_Digital_Write(EPD_RST_PIN
, 1);
98 DEV_Digital_Write(EPD_RST_PIN
, 0);
100 DEV_Digital_Write(EPD_RST_PIN
, 1);
104 /******************************************************************************
105 function : send command
107 Reg : Command register
108 ******************************************************************************/
109 static void EPD_7IN5_SendCommand(UBYTE Reg
)
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);
117 /******************************************************************************
121 ******************************************************************************/
122 static void EPD_7IN5_SendData(UBYTE Data
)
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);
130 /******************************************************************************
131 function : Wait until the busy_pin goes LOW
133 ******************************************************************************/
134 void EPD_7IN5_ReadBusy(void)
136 EPD_Busy_WaitUntil(1,0);
137 // unsigned char count = 200;
138 // Debug("e-Paper busy\r\n");
139 // while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) { //LOW: idle, HIGH: busy
142 // Debug("error: e-Paper busy timeout!!!\r\n");
146 // DEV_Delay_ms(100);
148 // Debug("e-Paper busy release\r\n");
152 /******************************************************************************
153 function : Turn On Display
155 ******************************************************************************/
156 static void EPD_7IN5_TurnOnDisplay(void)
158 EPD_7IN5_SendCommand(0x12); // DISPLAY_REFRESH
163 /******************************************************************************
164 function : Initialize the e-Paper register
166 ******************************************************************************/
167 void EPD_7IN5_Init(UBYTE mode
)
171 EPD_7IN5_SendCommand(0x01); // POWER_SETTING
172 EPD_7IN5_SendData(0x37);
173 EPD_7IN5_SendData(0x00);
175 EPD_7IN5_SendCommand(0x00); // PANEL_SETTING
176 EPD_7IN5_SendData(0xCF);
177 EPD_7IN5_SendData(0x08);
179 EPD_7IN5_SendCommand(0x06); // BOOSTER_SOFT_START
180 EPD_7IN5_SendData(0xc7);
181 EPD_7IN5_SendData(0xcc);
182 EPD_7IN5_SendData(0x28);
184 EPD_7IN5_SendCommand(0x04); // POWER_ON
187 EPD_7IN5_SendCommand(0x30); // PLL_CONTROL
188 EPD_7IN5_SendData(0x3c);
190 EPD_7IN5_SendCommand(0x41); // TEMPERATURE_CALIBRATION
191 EPD_7IN5_SendData(0x00);
193 EPD_7IN5_SendCommand(0x50); // VCOM_AND_DATA_INTERVAL_SETTING
194 EPD_7IN5_SendData(0x77);
196 EPD_7IN5_SendCommand(0x60); // TCON_SETTING
197 EPD_7IN5_SendData(0x22);
199 EPD_7IN5_SendCommand(0x61); // TCON_RESOLUTION
200 EPD_7IN5_SendData(EPD_7IN5_WIDTH
>> 8); // source 640
201 EPD_7IN5_SendData(EPD_7IN5_WIDTH
& 0xff);
202 EPD_7IN5_SendData(EPD_7IN5_HEIGHT
>> 8); // gate 384
203 EPD_7IN5_SendData(EPD_7IN5_HEIGHT
& 0xff);
205 EPD_7IN5_SendCommand(0x82); // VCM_DC_SETTING
206 EPD_7IN5_SendData(0x1E); // decide by LUT file
208 EPD_7IN5_SendCommand(0xe5); // FLASH MODE
209 EPD_7IN5_SendData(0x03);
213 /******************************************************************************
214 function : Clear screen
216 ******************************************************************************/
217 void EPD_7IN5_Clear(void)
220 Width
= (EPD_7IN5_WIDTH
% 8 == 0)? (EPD_7IN5_WIDTH
/ 8 ): (EPD_7IN5_WIDTH
/ 8 + 1);
221 Height
= EPD_7IN5_HEIGHT
;
223 EPD_7IN5_SendCommand(0x10);
224 for (UWORD j
= 0; j
< Height
; j
++) {
225 for (UWORD i
= 0; i
< Width
; i
++) {
226 for(UBYTE k
= 0; k
< 4; k
++) {
227 EPD_7IN5_SendData(0x33);
231 EPD_7IN5_TurnOnDisplay();
234 /******************************************************************************
235 function : Sends the image buffer in RAM to e-Paper and displays
237 ******************************************************************************/
238 void EPD_7IN5_Display(UBYTE
*Image
, UBYTE
*Image2
)
240 UBYTE Data_Black
, Data
;
242 Width
= (EPD_7IN5_WIDTH
% 8 == 0)? (EPD_7IN5_WIDTH
/ 8 ): (EPD_7IN5_WIDTH
/ 8 + 1);
243 Height
= EPD_7IN5_HEIGHT
;
245 EPD_7IN5_SendCommand(0x10);
246 for (UWORD j
= 0; j
< Height
; j
++) {
247 for (UWORD i
= 0; i
< Width
; i
++) {
248 Data_Black
= ~Image
[i
+ j
* Width
];
249 for(UBYTE k
= 0; k
< 8; k
++) {
250 if(Data_Black
& 0x80)
257 if(Data_Black
& 0x80)
262 EPD_7IN5_SendData(Data
);
266 EPD_7IN5_TurnOnDisplay();
269 /******************************************************************************
270 function : Enter sleep mode
272 ******************************************************************************/
273 void EPD_7IN5_Sleep(void)
275 EPD_7IN5_SendCommand(0x02); // POWER_OFF
277 EPD_7IN5_SendCommand(0x07); // DEEP_SLEEP
278 EPD_7IN5_SendData(0XA5);;