1 #include "EPD_3in7_U.h"
5 static const UBYTE EPD_3in7_U_lut_R20_GC
[] =
7 0x05,0x01,0x01,0x01,0x01,0x01,0x01,
8 0x01,0x12,0x1C,0x01,0x01,0x01,0x01,
9 0x01,0x20,0x20,0x20,0x01,0x01,0x01,
10 0x01,0x08,0x12,0x05,0x05,0x01,0x02,
11 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
12 0x01,0x00,0x00,0x00,0x00,0x01,0x01
14 static const UBYTE EPD_3in7_U_lut_R21_GC
[] =
16 0x05,0x41,0x81,0x01,0x01,0x01,0x01,
17 0x01,0x52,0x1C,0x01,0x01,0x01,0x01,
18 0x01,0x20,0xA0,0x60,0x01,0x01,0x01,
19 0x01,0x88,0x12,0x85,0x05,0x01,0x02,
20 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
21 0x01,0x00,0x00,0x00,0x00,0x01,0x01
23 static const UBYTE EPD_3in7_U_lut_R22_GC
[] =
25 0x05,0x41,0x81,0x01,0x01,0x01,0x01,
26 0x01,0x52,0x1C,0x01,0x01,0x01,0x01,
27 0x01,0x20,0xA0,0x60,0x01,0x01,0x01,
28 0x01,0x88,0x12,0x85,0x05,0x01,0x02,
29 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
30 0x01,0x00,0x00,0x00,0x00,0x01,0x01
32 static const UBYTE EPD_3in7_U_lut_R23_GC
[] =
34 0x05,0x41,0x81,0x01,0x01,0x01,0x01,
35 0x01,0x12,0x9C,0x01,0x01,0x01,0x01,
36 0x01,0x60,0xA0,0x20,0x01,0x01,0x01,
37 0x01,0x08,0x52,0x05,0x45,0x01,0x02,
38 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
39 0x01,0x00,0x00,0x00,0x00,0x01,0x01
41 static const UBYTE EPD_3in7_U_lut_R24_GC
[] =
43 0x05,0x41,0x81,0x01,0x01,0x01,0x01,
44 0x01,0x12,0x9C,0x01,0x01,0x01,0x01,
45 0x01,0x60,0xA0,0x20,0x01,0x01,0x01,
46 0x01,0x08,0x52,0x05,0x45,0x01,0x02,
47 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
48 0x01,0x00,0x00,0x00,0x00,0x01,0x01
53 static const UBYTE EPD_3in7_U_lut_R20_DU
[] =
55 0x01,0x16,0x16,0x01,0x01,0x01,0x01,
56 0x01,0x00,0x00,0x00,0x00,0x01,0x00,
57 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
58 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
59 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
60 0x00,0x00,0x00,0x00,0x00,0x00,0x00
62 static const UBYTE EPD_3in7_U_lut_R21_DU
[] =
64 0x01,0x96,0x16,0x81,0x01,0x01,0x01,
65 0x01,0x00,0x00,0x00,0x00,0x01,0x00,
66 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
67 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
68 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
69 0x00,0x00,0x00,0x00,0x00,0x00,0x00
71 static const UBYTE EPD_3in7_U_lut_R22_DU
[] =
73 0x01,0x96,0x16,0x81,0x01,0x01,0x01,
74 0x01,0x00,0x00,0x00,0x00,0x01,0x00,
75 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
76 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
77 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
78 0x00,0x00,0x00,0x00,0x00,0x00,0x00
80 static const UBYTE EPD_3in7_U_lut_R23_DU
[] =
82 0x01,0x96,0x56,0x01,0x01,0x01,0x01,
83 0x01,0x00,0x00,0x00,0x00,0x01,0x00,
84 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
85 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
86 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
87 0x00,0x00,0x00,0x00,0x00,0x00,0x00
89 static const UBYTE EPD_3in7_U_lut_R24_DU
[] =
91 0x01,0x96,0x56,0x01,0x01,0x01,0x01,
92 0x01,0x00,0x00,0x00,0x00,0x01,0x00,
93 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
94 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
95 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
96 0x00,0x00,0x00,0x00,0x00,0x00,0x00
100 static const UBYTE EPD_3in7_U_lut_vcom
[] =
102 0x05,0x14,0x14,0x01,0x01,0x01,0x01,
103 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
104 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
105 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
106 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
107 0x01,0x00,0x00,0x00,0x00,0x01,0x01
110 static const UBYTE EPD_3in7_U_lut_ww
[] =
112 0x05,0x54,0x94,0x01,0x01,0x01,0x01,
113 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
114 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
115 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
116 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
117 0x01,0x00,0x00,0x00,0x00,0x01,0x01
120 static const UBYTE EPD_3in7_U_lut_bw
[] =
122 0x05,0x54,0x94,0x01,0x01,0x01,0x01,
123 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
124 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
125 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
126 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
127 0x01,0x00,0x00,0x00,0x00,0x01,0x01
130 static const UBYTE EPD_3in7_U_lut_wb
[] =
132 0x05,0x54,0x94,0x01,0x01,0x01,0x01,
133 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
134 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
135 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
136 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
137 0x01,0x00,0x00,0x00,0x00,0x01,0x01
140 static const UBYTE EPD_3in7_U_lut_bb
[] =
142 0x05,0x54,0x94,0x01,0x01,0x01,0x01,
143 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
144 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
145 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
146 0x01,0x00,0x00,0x00,0x00,0x01,0x01,
147 0x01,0x00,0x00,0x00,0x00,0x01,0x01
150 unsigned char EPD_3in7_U_Flag
= 0;
152 /******************************************************************************
153 function : Software reset
155 ******************************************************************************/
156 void EPD_3in7_U_Reset(void)
158 DEV_Digital_Write(EPD_RST_PIN
, 1);
160 DEV_Digital_Write(EPD_RST_PIN
, 0);
162 DEV_Digital_Write(EPD_RST_PIN
, 1);
166 /******************************************************************************
167 function : send command
169 Reg : Command register
170 ******************************************************************************/
171 void EPD_3in7_U_SendCommand(UBYTE Reg
)
173 DEV_Digital_Write(EPD_DC_PIN
, 0);
174 DEV_Digital_Write(EPD_CS_PIN
, 0);
175 DEV_SPI_WriteByte(Reg
);
176 DEV_Digital_Write(EPD_CS_PIN
, 1);
179 /******************************************************************************
183 ******************************************************************************/
184 void EPD_3in7_U_SendData(UBYTE Data
)
186 DEV_Digital_Write(EPD_DC_PIN
, 1);
187 DEV_Digital_Write(EPD_CS_PIN
, 0);
188 DEV_SPI_WriteByte(Data
);
189 DEV_Digital_Write(EPD_CS_PIN
, 1);
192 /******************************************************************************
195 ******************************************************************************/
196 void EPD_3in7_U_ReadBusy(void)
198 EPD_Busy_WaitUntil(1,0);
199 // Debug("e-Paper busy\r\n");
202 // busy = DEV_Digital_Read(EPD_BUSY_PIN);
204 // DEV_Delay_ms(200);
205 // Debug("e-Paper busy release\r\n");
212 void EPD_3in7_U_lut(void)
215 EPD_3in7_U_SendCommand(0x20); // vcom
216 for(count
= 0; count
< 42 ; count
++)
218 EPD_3in7_U_SendData(EPD_3in7_U_lut_vcom
[count
]);
221 EPD_3in7_U_SendCommand(0x21); // ww --
222 for(count
= 0; count
< 42 ; count
++)
224 EPD_3in7_U_SendData(EPD_3in7_U_lut_ww
[count
]);
227 EPD_3in7_U_SendCommand(0x22); // bw r
228 for(count
= 0; count
< 42 ; count
++)
230 EPD_3in7_U_SendData(EPD_3in7_U_lut_bw
[count
]);
233 EPD_3in7_U_SendCommand(0x23); // wb w
234 for(count
= 0; count
< 42 ; count
++)
236 EPD_3in7_U_SendData(EPD_3in7_U_lut_bb
[count
]);
239 EPD_3in7_U_SendCommand(0x24); // bb b
240 for(count
= 0; count
< 42 ; count
++)
242 EPD_3in7_U_SendData(EPD_3in7_U_lut_wb
[count
]);
250 void EPD_3in7_U_refresh(void)
252 EPD_3in7_U_SendCommand(0x17);
253 EPD_3in7_U_SendData(0xA5);
254 EPD_3in7_U_ReadBusy();
259 void EPD_3in7_U_lut_GC(void)
262 EPD_3in7_U_SendCommand(0x20); // vcom
263 for(count
= 0; count
< 56 ; count
++)
265 EPD_3in7_U_SendData(EPD_3in7_U_lut_R20_GC
[count
]);
268 EPD_3in7_U_SendCommand(0x21); // red not use
269 for(count
= 0; count
< 42 ; count
++)
271 EPD_3in7_U_SendData(EPD_3in7_U_lut_R21_GC
[count
]);
274 EPD_3in7_U_SendCommand(0x24); // bb b
275 for(count
= 0; count
< 42 ; count
++)
277 EPD_3in7_U_SendData(EPD_3in7_U_lut_R24_GC
[count
]);
280 if(EPD_3in7_U_Flag
== 0)
282 EPD_3in7_U_SendCommand(0x22); // bw r
283 for(count
= 0; count
< 56 ; count
++)
285 EPD_3in7_U_SendData(EPD_3in7_U_lut_R22_GC
[count
]);
288 EPD_3in7_U_SendCommand(0x23); // wb w
289 for(count
= 0; count
< 42 ; count
++)
291 EPD_3in7_U_SendData(EPD_3in7_U_lut_R23_GC
[count
]);
299 EPD_3in7_U_SendCommand(0x22); // bw r
300 for(count
= 0; count
< 56 ; count
++)
302 EPD_3in7_U_SendData(EPD_3in7_U_lut_R23_GC
[count
]);
305 EPD_3in7_U_SendCommand(0x23); // wb w
306 for(count
= 0; count
< 42 ; count
++)
308 EPD_3in7_U_SendData(EPD_3in7_U_lut_R22_GC
[count
]);
316 void EPD_3in7_U_lut_DU(void)
319 EPD_3in7_U_SendCommand(0x20); // vcom
320 for(count
= 0; count
< 56 ; count
++)
322 EPD_3in7_U_SendData(EPD_3in7_U_lut_R20_DU
[count
]);
325 EPD_3in7_U_SendCommand(0x21); // red not use
326 for(count
= 0; count
< 42 ; count
++)
328 EPD_3in7_U_SendData(EPD_3in7_U_lut_R21_DU
[count
]);
331 EPD_3in7_U_SendCommand(0x24); // bb b
332 for(count
= 0; count
< 42 ; count
++)
334 EPD_3in7_U_SendData(EPD_3in7_U_lut_R24_DU
[count
]);
337 if(EPD_3in7_U_Flag
== 0)
339 EPD_3in7_U_SendCommand(0x22); // bw r
340 for(count
= 0; count
< 56 ; count
++)
342 EPD_3in7_U_SendData(EPD_3in7_U_lut_R22_DU
[count
]);
345 EPD_3in7_U_SendCommand(0x23); // wb w
346 for(count
= 0; count
< 42 ; count
++)
348 EPD_3in7_U_SendData(EPD_3in7_U_lut_R23_DU
[count
]);
356 EPD_3in7_U_SendCommand(0x22); // bw r
357 for(count
= 0; count
< 56 ; count
++)
359 EPD_3in7_U_SendData(EPD_3in7_U_lut_R23_DU
[count
]);
362 EPD_3in7_U_SendCommand(0x23); // wb w
363 for(count
= 0; count
< 42 ; count
++)
365 EPD_3in7_U_SendData(EPD_3in7_U_lut_R22_DU
[count
]);
377 /******************************************************************************
378 function : Initialize the e-Paper register
380 ******************************************************************************/
381 void EPD_3in7_U_Init(UBYTE mode
)
386 EPD_3in7_U_SendCommand(0x00); // panel setting PSR
387 EPD_3in7_U_SendData(0xFF); // RES1 RES0 REG KW/R UD SHL SHD_N RST_N
388 EPD_3in7_U_SendData(0x01); // x x x VCMZ TS_AUTO TIGE NORG VC_LUTZ
390 EPD_3in7_U_SendCommand(0x01); // POWER SETTING PWR
391 EPD_3in7_U_SendData(0x03); // x x x x x x VDS_EN VDG_EN
392 EPD_3in7_U_SendData(0x10); // x x x VCOM_SLWE VGH[3:0] VGH=20V, VGL=-20V
393 EPD_3in7_U_SendData(0x3F); // x x VSH[5:0] VSH = 15V
394 EPD_3in7_U_SendData(0x3F); // x x VSL[5:0] VSL=-15V
395 EPD_3in7_U_SendData(0x03); // OPTEN VDHR[6:0] VHDR=6.4V
396 // T_VDS_OFF[1:0] 00=1 frame; 01=2 frame; 10=3 frame; 11=4 frame
397 EPD_3in7_U_SendCommand(0x06); // booster soft start BTST
398 EPD_3in7_U_SendData(0x37); // BT_PHA[7:0]
399 EPD_3in7_U_SendData(0x3D); // BT_PHB[7:0]
400 EPD_3in7_U_SendData(0x3D); // x x BT_PHC[5:0]
402 EPD_3in7_U_SendCommand(0x60); // TCON setting TCON
403 EPD_3in7_U_SendData(0x22); // S2G[3:0] G2S[3:0] non-overlap = 12
405 EPD_3in7_U_SendCommand(0x82); // VCOM_DC setting VDCS
406 EPD_3in7_U_SendData(0x07); // x VDCS[6:0] VCOM_DC value= -1.9v 00~3f,0x12=-1.9v
408 EPD_3in7_U_SendCommand(0x30);
409 EPD_3in7_U_SendData(0x09);
411 EPD_3in7_U_SendCommand(0xe3); // power saving PWS
412 EPD_3in7_U_SendData(0x88); // VCOM_W[3:0] SD_W[3:0]
414 EPD_3in7_U_SendCommand(0x61); // resoultion setting
415 EPD_3in7_U_SendData(0xf0); // HRES[7:3] 0 0 0
416 EPD_3in7_U_SendData(0x01); // x x x x x x x VRES[8]
417 EPD_3in7_U_SendData(0xA0); // VRES[7:0]
419 EPD_3in7_U_SendCommand(0x50);
420 EPD_3in7_U_SendData(0xB7);
422 EPD_3in7_U_display_NUM(EPD_3in7_U_WHITE
);
424 EPD_3in7_U_refresh();
426 EPD_3in7_U_SendCommand(0x50);
427 EPD_3in7_U_SendData(0x17);
431 void EPD_3in7_U_display(UBYTE
*Image
, UBYTE
*Image2
)
434 EPD_3in7_U_SendCommand(0x13); //Transfer new data
435 for(i
=0;i
<(EPD_3in7_U_WIDTH
*EPD_3in7_U_HEIGHT
/8);i
++)
437 EPD_3in7_U_SendData(*Image
);
442 EPD_3in7_U_refresh();
445 void EPD_3in7_U_display_NUM(UBYTE NUM
)
450 EPD_3in7_U_SendCommand(0x13); //Transfer new data
452 for(column
=0; column
<EPD_3in7_U_HEIGHT
; column
++)
454 for(row
=0; row
<EPD_3in7_U_WIDTH
/8; row
++)
458 case EPD_3in7_U_WHITE
:
459 EPD_3in7_U_SendData(0xFF);
462 case EPD_3in7_U_BLACK
:
463 EPD_3in7_U_SendData(0x00);
466 case EPD_3in7_U_Source_Line
:
467 EPD_3in7_U_SendData(0xAA);
470 case EPD_3in7_U_Gate_Line
:
472 EPD_3in7_U_SendData(0xff); //An odd number of Gate line
474 EPD_3in7_U_SendData(0x00); //The even line Gate
477 case EPD_3in7_U_Chessboard
:
478 if(row
>=(EPD_3in7_U_WIDTH
/8/2)&&column
>=(EPD_3in7_U_HEIGHT
/2))
479 EPD_3in7_U_SendData(0xff);
480 else if(row
<(EPD_3in7_U_WIDTH
/8/2)&&column
<(EPD_3in7_U_HEIGHT
/2))
481 EPD_3in7_U_SendData(0xff);
483 EPD_3in7_U_SendData(0x00);
486 case EPD_3in7_U_LEFT_BLACK_RIGHT_WHITE
:
487 if(row
>=(EPD_3in7_U_WIDTH
/8/2))
488 EPD_3in7_U_SendData(0xff);
490 EPD_3in7_U_SendData(0x00);
493 case EPD_3in7_U_UP_BLACK_DOWN_WHITE
:
494 if(column
>=(EPD_3in7_U_HEIGHT
/2))
495 EPD_3in7_U_SendData(0xFF);
497 EPD_3in7_U_SendData(0x00);
500 case EPD_3in7_U_Frame
:
501 if(column
==0||column
==(EPD_3in7_U_HEIGHT
-1))
502 EPD_3in7_U_SendData(0x00);
504 EPD_3in7_U_SendData(0x7F);
505 else if(row
==(EPD_3in7_U_WIDTH
/8-1))
506 EPD_3in7_U_SendData(0xFE);
508 EPD_3in7_U_SendData(0xFF);
511 case EPD_3in7_U_Crosstalk
:
512 if((row
>=(EPD_3in7_U_WIDTH
/8/3)&&row
<=(EPD_3in7_U_WIDTH
/8/3*2)&&column
<=(EPD_3in7_U_HEIGHT
/3))||(row
>=(EPD_3in7_U_WIDTH
/8/3)&&row
<=(EPD_3in7_U_WIDTH
/8/3*2)&&column
>=(EPD_3in7_U_HEIGHT
/3*2)))
513 EPD_3in7_U_SendData(0x00);
515 EPD_3in7_U_SendData(0xFF);
518 case EPD_3in7_U_Image
:
519 //EPD_3in7_U_SendData(gImage_1[pcnt++]);
529 /******************************************************************************
530 function : Clear screen
532 ******************************************************************************/
533 void EPD_3in7_U_Clear(void)
536 EPD_3in7_U_SendCommand(0x13); //Transfer new data
537 for(i
=0;i
<(EPD_3in7_U_WIDTH
*EPD_3in7_U_HEIGHT
/8);i
++)
539 EPD_3in7_U_SendData(0xFF);
542 EPD_3in7_U_refresh();
545 /******************************************************************************
546 function : Enter sleep mode
548 ******************************************************************************/
549 void EPD_3in7_U_sleep(void)
551 EPD_3in7_U_SendCommand(0X07); //deep sleep
552 EPD_3in7_U_SendData(0xA5);