fix: 对不支持weak的bsp, luat_http_client_onevent报重复定义了
[LuatOS.git] / components / epaper / EPD_4in2.c
blob3b988f7780396e69797f193ac5d2061edbee6aa6
1 /*****************************************************************************
2 * | File : EPD_4in2.c
3 * | Author : Waveshare team
4 * | Function : 4.2inch e-paper
5 * | Info :
6 *----------------
7 * | This version: V3.1
8 * | Date : 2019-11-14
9 * | Info :
10 * -----------------------------------------------------------------------------
11 * V3.1(2019-11-14):
12 * 1.Add 4 grayscale drive and display program
13 * Add EPD_4IN2_4Gray_lut_vcom[]
14 * Add EPD_4IN2_4Gray_lut_ww[]
15 * Add EPD_4IN2_4Gray_lut_bw[]
16 * Add EPD_4IN2_4Gray_lut_wb
17 * Add EPD_4IN2_4Gray_lut_bb
18 * Add EPD_4IN2_Partial_SetLut()
19 * Add EPD_4IN2_4Gray_lut()
20 * Add EPD_4IN2_Init_4Gray()
21 * Add EPD_4IN2_4GrayDisplay(....)
22 * 2.Add partial refresh display
23 * Add EPD_4IN2_Partial_lut_vcom1[]
24 * Add EPD_4IN2_Partial_lut_ww1[]
25 * Add EPD_4IN2_Partial_lut_bw1[]
26 * Add EPD_4IN2_Partial_lut_wb1[]
27 * Add EPD_4IN2_Partial_lut_bb1[]
28 * Add EPD_4IN2_Partial_SetLut()
29 * Add EPD_4IN2_PartialDisplay(...)
30 * Poor display, no display function by default
32 * V3.0(2019-06-13):
33 * 1.Change:
34 * lut_vcomDC[] => EPD_4IN2_lut_vcomDC[]
35 * lut_ww[] => EPD_4IN2_lut_ww[]
36 * lut_bw[] => EPD_4IN2_lut_bw[]
37 * lut_wb[] => EPD_4IN2_lut_wb[]
38 * lut_bb[] => EPD_4IN2_lut_bb[]
39 * EPD_Reset() => EPD_4IN2_Reset()
40 * EPD_SendCommand() => EPD_4IN2_SendCommand()
41 * EPD_SendData() => EPD_4IN2_SendData()
42 * EPD_WaitUntilIdle() => EPD_4IN2_ReadBusy()
43 * EPD_SetFullReg() => EPD_4IN2_SetFullReg()
44 * EPD_SetPartReg() => EPD_4IN2_SetPartReg()
45 * EPD_TurnOnDisplay() => EPD_4IN2_TurnOnDisplay()
46 * EPD_Init() => EPD_4IN2_Init()
47 * EPD_Clear() => EPD_4IN2_Clear()
48 * EPD_Display() => EPD_4IN2_Display()
49 * EPD_Sleep() => EPD_4IN2_Sleep()
50 * 2.remove commands define:
51 * #define PANEL_SETTING 0x00
52 * #define POWER_SETTING 0x01
53 * #define POWER_OFF 0x02
54 * #define POWER_OFF_SEQUENCE_SETTING 0x03
55 * #define POWER_ON 0x04
56 * #define POWER_ON_MEASURE 0x05
57 * #define BOOSTER_SOFT_START 0x06
58 * #define DEEP_SLEEP 0x07
59 * #define DATA_START_TRANSMISSION_1 0x10
60 * #define DATA_STOP 0x11
61 * #define DISPLAY_REFRESH 0x12
62 * #define DATA_START_TRANSMISSION_2 0x13
63 * #define VCOM_LUT 0x20
64 * #define W2W_LUT 0x21
65 * #define B2W_LUT 0x22
66 * #define W2B_LUT 0x23
67 * #define B2B_LUT 0x24
68 * #define PLL_CONTROL 0x30
69 * #define TEMPERATURE_SENSOR_CALIBRATION 0x40
70 * #define TEMPERATURE_SENSOR_SELECTION 0x41
71 * #define TEMPERATURE_SENSOR_WRITE 0x42
72 * #define TEMPERATURE_SENSOR_READ 0x43
73 * #define VCOM_AND_DATA_INTERVAL_SETTING 0x50
74 * #define LOW_POWER_DETECTION 0x51
75 * #define TCON_SETTING 0x60
76 * #define RESOLUTION_SETTING 0x61
77 * #define GET_STATUS 0x71
78 * #define AUTO_MEASURE_VCOM 0x80
79 * #define READ_VCOM_VALUE 0x81
80 * #define VCM_DC_SETTING 0x82
81 * #define PARTIAL_WINDOW 0x90
82 * #define PARTIAL_IN 0x91
83 * #define PARTIAL_OUT 0x92
84 * #define PROGRAM_MODE 0xA0
85 * #define ACTIVE_PROGRAM 0xA1
86 * #define READ_OTP_DATA 0xA2
87 * #define POWER_SAVING 0xE3
88 * V2.0(2018-10-30):
89 * 1.Remove:ImageBuff[EPD_HEIGHT * EPD_WIDTH / 8]
90 * 2.Change:EPD_Display(UBYTE *Image)
91 * Need to pass parameters: pointer to cached data
93 # Permission is hereby granted, free of charge, to any person obtaining a copy
94 # of this software and associated documnetation files (the "Software"), to deal
95 # in the Software without restriction, including without limitation the rights
96 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
97 # copies of the Software, and to permit persons to whom the Software is
98 # furished to do so, subject to the following conditions:
100 # The above copyright notice and this permission notice shall be included in
101 # all copies or substantial portions of the Software.
103 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
104 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
105 # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
106 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
107 # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
108 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
109 # THE SOFTWARE.
111 ******************************************************************************/
112 #include "EPD_4in2.h"
113 #include "Debug.h"
115 static const unsigned char EPD_4IN2_lut_vcom0[] = {
116 0x00, 0x17, 0x00, 0x00, 0x00, 0x02,
117 0x00, 0x17, 0x17, 0x00, 0x00, 0x02,
118 0x00, 0x0A, 0x01, 0x00, 0x00, 0x01,
119 0x00, 0x0E, 0x0E, 0x00, 0x00, 0x02,
120 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
121 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
122 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
124 static const unsigned char EPD_4IN2_lut_ww[] = {
125 0x40, 0x17, 0x00, 0x00, 0x00, 0x02,
126 0x90, 0x17, 0x17, 0x00, 0x00, 0x02,
127 0x40, 0x0A, 0x01, 0x00, 0x00, 0x01,
128 0xA0, 0x0E, 0x0E, 0x00, 0x00, 0x02,
129 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
130 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
131 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
133 static const unsigned char EPD_4IN2_lut_bw[] = {
134 0x40, 0x17, 0x00, 0x00, 0x00, 0x02,
135 0x90, 0x17, 0x17, 0x00, 0x00, 0x02,
136 0x40, 0x0A, 0x01, 0x00, 0x00, 0x01,
137 0xA0, 0x0E, 0x0E, 0x00, 0x00, 0x02,
138 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
139 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
140 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
142 static const unsigned char EPD_4IN2_lut_wb[] = {
143 0x80, 0x17, 0x00, 0x00, 0x00, 0x02,
144 0x90, 0x17, 0x17, 0x00, 0x00, 0x02,
145 0x80, 0x0A, 0x01, 0x00, 0x00, 0x01,
146 0x50, 0x0E, 0x0E, 0x00, 0x00, 0x02,
147 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
148 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
149 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
151 static const unsigned char EPD_4IN2_lut_bb[] = {
152 0x80, 0x17, 0x00, 0x00, 0x00, 0x02,
153 0x90, 0x17, 0x17, 0x00, 0x00, 0x02,
154 0x80, 0x0A, 0x01, 0x00, 0x00, 0x01,
155 0x50, 0x0E, 0x0E, 0x00, 0x00, 0x02,
156 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
157 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
158 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
161 /******************************partial screen update LUT*********************************/
162 const unsigned char EPD_4IN2_Partial_lut_vcom1[] = {
163 0x00 ,0x19 ,0x01 ,0x00 ,0x00 ,0x01,
164 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
165 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
166 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
167 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
168 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
169 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
170 0x00 ,0x00,
173 const unsigned char EPD_4IN2_Partial_lut_ww1[] = {
174 0x00 ,0x19 ,0x01 ,0x00 ,0x00 ,0x01,
175 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
176 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
177 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
178 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
179 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
180 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
183 const unsigned char EPD_4IN2_Partial_lut_bw1[] = {
184 0x80 ,0x19 ,0x01 ,0x00 ,0x00 ,0x01,
185 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
186 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
187 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
188 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
189 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
190 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
193 const unsigned char EPD_4IN2_Partial_lut_wb1[] = {
194 0x40 ,0x19 ,0x01 ,0x00 ,0x00 ,0x01,
195 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
196 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
197 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
198 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
199 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
200 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
203 const unsigned char EPD_4IN2_Partial_lut_bb1[] = {
204 0x00 ,0x19 ,0x01 ,0x00 ,0x00 ,0x01,
205 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
206 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
207 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
208 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
209 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
210 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
213 /******************************gray*********************************/
214 //0~3 gray
215 const unsigned char EPD_4IN2_4Gray_lut_vcom[] = {
216 0x00 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
217 0x60 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
218 0x00 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
219 0x00 ,0x13 ,0x0A ,0x01 ,0x00 ,0x01,
220 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
221 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
222 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00
225 //R21
226 const unsigned char EPD_4IN2_4Gray_lut_ww[] = {
227 0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
228 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
229 0x10 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
230 0xA0 ,0x13 ,0x01 ,0x00 ,0x00 ,0x01,
231 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
232 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
233 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
235 //R22H r
236 const unsigned char EPD_4IN2_4Gray_lut_bw[] = {
237 0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
238 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
239 0x00 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
240 0x99 ,0x0C ,0x01 ,0x03 ,0x04 ,0x01,
241 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
242 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
243 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
245 //R23H w
246 const unsigned char EPD_4IN2_4Gray_lut_wb[] = {
247 0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
248 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
249 0x00 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
250 0x99 ,0x0B ,0x04 ,0x04 ,0x01 ,0x01,
251 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
252 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
253 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
255 //R24H b
256 const unsigned char EPD_4IN2_4Gray_lut_bb[] = {
257 0x80 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
258 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
259 0x20 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
260 0x50 ,0x13 ,0x01 ,0x00 ,0x00 ,0x01,
261 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
262 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
263 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
267 /******************************************************************************
268 function : Software reset
269 parameter:
270 ******************************************************************************/
271 static void EPD_4IN2_Reset(void)
273 DEV_Digital_Write(EPD_RST_PIN, 1);
274 DEV_Delay_ms(200);
275 DEV_Digital_Write(EPD_RST_PIN, 0);
276 DEV_Delay_ms(2);
277 DEV_Digital_Write(EPD_RST_PIN, 1);
278 DEV_Delay_ms(200);
281 /******************************************************************************
282 function : send command
283 parameter:
284 Reg : Command register
285 ******************************************************************************/
286 static void EPD_4IN2_SendCommand(UBYTE Reg)
288 DEV_Digital_Write(EPD_DC_PIN, 0);
289 DEV_Digital_Write(EPD_CS_PIN, 0);
290 DEV_SPI_WriteByte(Reg);
291 DEV_Digital_Write(EPD_CS_PIN, 1);
294 /******************************************************************************
295 function : send data
296 parameter:
297 Data : Write data
298 ******************************************************************************/
299 static void EPD_4IN2_SendData(UBYTE Data)
301 DEV_Digital_Write(EPD_DC_PIN, 1);
302 DEV_Digital_Write(EPD_CS_PIN, 0);
303 DEV_SPI_WriteByte(Data);
304 DEV_Digital_Write(EPD_CS_PIN, 1);
307 /******************************************************************************
308 function : Wait until the busy_pin goes LOW
309 parameter:
310 ******************************************************************************/
311 void EPD_4IN2_ReadBusy(void)
313 EPD_Busy_WaitUntil(1,1);
314 // unsigned char count = 200;
315 // Debug("e-Paper busy\r\n");
316 // EPD_4IN2_SendCommand(0x71);
317 // while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) { //LOW: idle, HIGH: busy
318 // EPD_4IN2_SendCommand(0x71);
319 // if(!(count--))
320 // {
321 // Debug("error: e-Paper busy timeout!!!\r\n");
322 // break;
323 // }
324 // else
325 // DEV_Delay_ms(100);
326 // }
327 // Debug("e-Paper busy release\r\n");
330 /******************************************************************************
331 function : Turn On Display
332 parameter:
333 ******************************************************************************/
334 static void EPD_4IN2_TurnOnDisplay(void)
336 EPD_4IN2_SendCommand(0x12);
337 DEV_Delay_ms(100);
338 EPD_4IN2_ReadBusy();
341 /******************************************************************************
342 function : set the look-up tables
343 parameter:
344 ******************************************************************************/
345 static void EPD_4IN2_SetLut(void)
347 UWORD count;
348 EPD_4IN2_SendCommand(0x20); //g vcom
349 for(count=0; count<44; count++) {
350 EPD_4IN2_SendData(EPD_4IN2_lut_vcom0[count]);
353 EPD_4IN2_SendCommand(0x21);
354 for(count=0; count<42; count++) {
355 EPD_4IN2_SendData(EPD_4IN2_lut_ww[count]);
358 EPD_4IN2_SendCommand(0x22);
359 for(count=0; count<42; count++) {
360 EPD_4IN2_SendData(EPD_4IN2_lut_bw[count]);
363 EPD_4IN2_SendCommand(0x23);
364 for(count=0; count<42; count++) {
365 EPD_4IN2_SendData(EPD_4IN2_lut_wb[count]);
368 EPD_4IN2_SendCommand(0x24);
369 for(count=0; count<42; count++) {
370 EPD_4IN2_SendData(EPD_4IN2_lut_bb[count]);
374 static void EPD_4IN2_Partial_SetLut(void)
376 unsigned int count;
377 EPD_4IN2_SendCommand(0x20);
378 for(count=0; count<44; count++) {
379 EPD_4IN2_SendData(EPD_4IN2_Partial_lut_vcom1[count]);
382 EPD_4IN2_SendCommand(0x21);
383 for(count=0; count<42; count++) {
384 EPD_4IN2_SendData(EPD_4IN2_Partial_lut_ww1[count]);
387 EPD_4IN2_SendCommand(0x22);
388 for(count=0; count<42; count++) {
389 EPD_4IN2_SendData(EPD_4IN2_Partial_lut_bw1[count]);
392 EPD_4IN2_SendCommand(0x23);
393 for(count=0; count<42; count++) {
394 EPD_4IN2_SendData(EPD_4IN2_Partial_lut_wb1[count]);
397 EPD_4IN2_SendCommand(0x24);
398 for(count=0; count<42; count++) {
399 EPD_4IN2_SendData(EPD_4IN2_Partial_lut_bb1[count]);
403 //LUT download
404 static void EPD_4IN2_4Gray_lut(void)
406 unsigned int count;
408 EPD_4IN2_SendCommand(0x20); //vcom
409 for(count=0; count<42; count++) {
410 EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_vcom[count]);
413 EPD_4IN2_SendCommand(0x21); //red not use
414 for(count=0; count<42; count++) {
415 EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_ww[count]);
418 EPD_4IN2_SendCommand(0x22); //bw r
419 for(count=0; count<42; count++) {
420 EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_bw[count]);
423 EPD_4IN2_SendCommand(0x23); //wb w
424 for(count=0; count<42; count++) {
425 EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_wb[count]);
428 EPD_4IN2_SendCommand(0x24); //bb b
429 for(count=0; count<42; count++) {
430 EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_bb[count]);
433 EPD_4IN2_SendCommand(0x25); //vcom
434 for(count=0; count<42; count++) {
435 EPD_4IN2_SendData(EPD_4IN2_4Gray_lut_ww[count]);
439 /******************************************************************************
440 function : Initialize the e-Paper register
441 parameter:
442 ******************************************************************************/
443 void EPD_4IN2_Init(UBYTE mode)
445 EPD_4IN2_Reset();
447 EPD_4IN2_SendCommand(0x01); // POWER SETTING
448 EPD_4IN2_SendData(0x03);
449 EPD_4IN2_SendData(0x00);
450 EPD_4IN2_SendData(0x2b);
451 EPD_4IN2_SendData(0x2b);
453 EPD_4IN2_SendCommand(0x06); // boost soft start
454 EPD_4IN2_SendData(0x17); //A
455 EPD_4IN2_SendData(0x17); //B
456 EPD_4IN2_SendData(0x17); //C
458 EPD_4IN2_SendCommand(0x04); // POWER_ON
459 EPD_4IN2_ReadBusy();
461 EPD_4IN2_SendCommand(0x00); // panel setting
462 EPD_4IN2_SendData(0xbf); // KW-BF KWR-AF BWROTP 0f BWOTP 1f
463 EPD_4IN2_SendData(0x0d);
465 EPD_4IN2_SendCommand(0x30); // PLL setting
466 EPD_4IN2_SendData(0x3C); // 3A 100HZ 29 150Hz 39 200HZ 31 171HZ
468 EPD_4IN2_SendCommand(0x61); // resolution setting
469 EPD_4IN2_SendData(0x01);
470 EPD_4IN2_SendData(0x90); //128
471 EPD_4IN2_SendData(0x01); //
472 EPD_4IN2_SendData(0x2c);
474 EPD_4IN2_SendCommand(0x82); // vcom_DC setting
475 EPD_4IN2_SendData(0x28);
477 EPD_4IN2_SendCommand(0X50); // VCOM AND DATA INTERVAL SETTING
478 EPD_4IN2_SendData(0x97); // 97white border 77black border VBDF 17|D7 VBDW 97 VBDB 57 VBDF F7 VBDW 77 VBDB 37 VBDR B7
480 EPD_4IN2_SetLut();
483 void EPD_4IN2_Init_4Gray(void)
485 EPD_4IN2_Reset();
486 EPD_4IN2_SendCommand(0x01); //POWER SETTING
487 EPD_4IN2_SendData (0x03);
488 EPD_4IN2_SendData (0x00); //VGH=20V,VGL=-20V
489 EPD_4IN2_SendData (0x2b); //VDH=15V
490 EPD_4IN2_SendData (0x2b); //VDL=-15V
491 EPD_4IN2_SendData (0x13);
493 EPD_4IN2_SendCommand(0x06); //booster soft start
494 EPD_4IN2_SendData (0x17); //A
495 EPD_4IN2_SendData (0x17); //B
496 EPD_4IN2_SendData (0x17); //C
498 EPD_4IN2_SendCommand(0x04);
499 EPD_4IN2_ReadBusy();
501 EPD_4IN2_SendCommand(0x00); //panel setting
502 EPD_4IN2_SendData(0x3f); //KW-3f KWR-2F BWROTP 0f BWOTP 1f
504 EPD_4IN2_SendCommand(0x30); //PLL setting
505 EPD_4IN2_SendData (0x3c); //100hz
507 EPD_4IN2_SendCommand(0x61); //resolution setting
508 EPD_4IN2_SendData (0x01); //400
509 EPD_4IN2_SendData (0x90);
510 EPD_4IN2_SendData (0x01); //300
511 EPD_4IN2_SendData (0x2c);
513 EPD_4IN2_SendCommand(0x82); //vcom_DC setting
514 EPD_4IN2_SendData (0x12);
516 EPD_4IN2_SendCommand(0X50); //VCOM AND DATA INTERVAL SETTING
517 EPD_4IN2_SendData(0x97);
519 /******************************************************************************
520 function : Clear screen
521 parameter:
522 ******************************************************************************/
523 void EPD_4IN2_Clear(void)
525 UWORD Width, Height;
526 Width = (EPD_4IN2_WIDTH % 8 == 0)? (EPD_4IN2_WIDTH / 8 ): (EPD_4IN2_WIDTH / 8 + 1);
527 Height = EPD_4IN2_HEIGHT;
529 EPD_4IN2_SendCommand(0x10);
530 for (UWORD j = 0; j < Height; j++) {
531 for (UWORD i = 0; i < Width; i++) {
532 EPD_4IN2_SendData(0xFF);
536 EPD_4IN2_SendCommand(0x13);
537 for (UWORD j = 0; j < Height; j++) {
538 for (UWORD i = 0; i < Width; i++) {
539 EPD_4IN2_SendData(0xFF);
542 EPD_4IN2_SendCommand(0x12); //DISPLAY REFRESH
543 DEV_Delay_ms(10);
544 EPD_4IN2_TurnOnDisplay();
547 /******************************************************************************
548 function : Sends the image buffer in RAM to e-Paper and displays
549 parameter:
550 ******************************************************************************/
551 void EPD_4IN2_Display(UBYTE *Image, UBYTE *Image2)
553 UWORD Width, Height;
554 Width = (EPD_4IN2_WIDTH % 8 == 0)? (EPD_4IN2_WIDTH / 8 ): (EPD_4IN2_WIDTH / 8 + 1);
555 Height = EPD_4IN2_HEIGHT;
557 EPD_4IN2_SendCommand(0x13);
558 for (UWORD j = 0; j < Height; j++) {
559 for (UWORD i = 0; i < Width; i++) {
560 EPD_4IN2_SendData(Image[i + j * Width]);
564 EPD_4IN2_TurnOnDisplay();
567 void EPD_4IN2_PartialDisplay(UWORD X_start,UWORD Y_start,UWORD X_end,UWORD Y_end, UBYTE *Image)
569 UWORD Width;
570 Width = (EPD_4IN2_WIDTH % 8 == 0)? (EPD_4IN2_WIDTH / 8 ): (EPD_4IN2_WIDTH / 8 + 1);
572 X_start = (X_start % 8 == 0)? (X_start): (X_start/8*8+8);
573 X_end = (X_end % 8 == 0)? (X_end): (X_end/8*8+8);
575 EPD_4IN2_SendCommand(0X50);
576 EPD_4IN2_SendData(0xf7);
577 DEV_Delay_ms(100);
579 EPD_4IN2_SendCommand(0x82); //vcom_DC setting
580 EPD_4IN2_SendData (0x08);
581 EPD_4IN2_SendCommand(0X50);
582 EPD_4IN2_SendData(0x47);
583 EPD_4IN2_Partial_SetLut();
584 EPD_4IN2_SendCommand(0x91); //This command makes the display enter partial mode
585 EPD_4IN2_SendCommand(0x90); //resolution setting
586 EPD_4IN2_SendData ((X_start)/256);
587 EPD_4IN2_SendData ((X_start)%256); //x-start
589 EPD_4IN2_SendData ((X_end )/256);
590 EPD_4IN2_SendData ((X_end )%256-1); //x-end
592 EPD_4IN2_SendData (Y_start/256);
593 EPD_4IN2_SendData (Y_start%256); //y-start
595 EPD_4IN2_SendData (Y_end/256);
596 EPD_4IN2_SendData (Y_end%256-1); //y-end
597 EPD_4IN2_SendData (0x28);
599 EPD_4IN2_SendCommand(0x10); //writes Old data to SRAM for programming
600 for (UWORD j = 0; j < Y_end - Y_start; j++) {
601 for (UWORD i = 0; i < (X_end - X_start)/8; i++) {
602 EPD_4IN2_SendData(Image[(Y_start + j)*Width + X_start/8 + i]);
605 EPD_4IN2_SendCommand(0x13); //writes New data to SRAM.
606 for (UWORD j = 0; j < Y_end - Y_start; j++) {
607 for (UWORD i = 0; i < (X_end - X_start)/8; i++) {
608 EPD_4IN2_SendData(~Image[(Y_start + j)*Width + X_start/8 + i]);
612 EPD_4IN2_SendCommand(0x12); //DISPLAY REFRESH
613 DEV_Delay_ms(10); //The delay here is necessary, 200uS at least!!!
614 EPD_4IN2_TurnOnDisplay();
617 void EPD_4IN2_4GrayDisplay(const UBYTE *Image)
619 UDOUBLE i,j,k;
620 UBYTE temp1,temp2,temp3;
621 /****Color display description****
622 white gray1 gray2 black
623 0x10| 01 01 00 00
624 0x13| 01 00 01 00
625 *********************************/
626 EPD_4IN2_SendCommand(0x10);
628 for(i=0; i<15000; i++) { //5808*4 46464
629 temp3=0;
630 for(j=0; j<2; j++) {
631 temp1 = Image[i*2+j];
632 for(k=0; k<2; k++) {
633 temp2 = temp1&0xC0 ;
634 if(temp2 == 0xC0)
635 temp3 |= 0x01;//white
636 else if(temp2 == 0x00)
637 temp3 |= 0x00; //black
638 else if(temp2 == 0x80)
639 temp3 |= 0x01; //gray1
640 else //0x40
641 temp3 |= 0x00; //gray2
642 temp3 <<= 1;
644 temp1 <<= 2;
645 temp2 = temp1&0xC0 ;
646 if(temp2 == 0xC0) //white
647 temp3 |= 0x01;
648 else if(temp2 == 0x00) //black
649 temp3 |= 0x00;
650 else if(temp2 == 0x80)
651 temp3 |= 0x01; //gray1
652 else //0x40
653 temp3 |= 0x00; //gray2
654 if(j!=1 || k!=1)
655 temp3 <<= 1;
657 temp1 <<= 2;
661 EPD_4IN2_SendData(temp3);
663 // new data
664 EPD_4IN2_SendCommand(0x13);
665 for(i=0; i<15000; i++) { //5808*4 46464
666 temp3=0;
667 for(j=0; j<2; j++) {
668 temp1 = Image[i*2+j];
669 for(k=0; k<2; k++) {
670 temp2 = temp1&0xC0 ;
671 if(temp2 == 0xC0)
672 temp3 |= 0x01;//white
673 else if(temp2 == 0x00)
674 temp3 |= 0x00; //black
675 else if(temp2 == 0x80)
676 temp3 |= 0x00; //gray1
677 else //0x40
678 temp3 |= 0x01; //gray2
679 temp3 <<= 1;
681 temp1 <<= 2;
682 temp2 = temp1&0xC0 ;
683 if(temp2 == 0xC0) //white
684 temp3 |= 0x01;
685 else if(temp2 == 0x00) //black
686 temp3 |= 0x00;
687 else if(temp2 == 0x80)
688 temp3 |= 0x00; //gray1
689 else //0x40
690 temp3 |= 0x01; //gray2
691 if(j!=1 || k!=1)
692 temp3 <<= 1;
694 temp1 <<= 2;
698 EPD_4IN2_SendData(temp3);
701 EPD_4IN2_4Gray_lut();
702 EPD_4IN2_TurnOnDisplay();
704 /******************************************************************************
705 function : Enter sleep mode
706 parameter:
707 ******************************************************************************/
708 void EPD_4IN2_Sleep(void)
710 EPD_4IN2_SendCommand(0x02); // POWER_OFF
711 EPD_4IN2_ReadBusy();
712 EPD_4IN2_SendCommand(0x07); // DEEP_SLEEP
713 EPD_4IN2_SendData(0XA5);