fix: 对不支持weak的bsp, luat_http_client_onevent报重复定义了
[LuatOS.git] / components / epaper / EPD_3in7_U.c
blob94a23f77dfd7699037996db28a0eeb73b06a1607
1 #include "EPD_3in7_U.h"
2 #include "Debug.h"
4 //GC 0.9S
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
13 };
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
22 };
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
52 // DU 0.3s
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
61 };
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
70 };
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
99 //
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
154 parameter:
155 ******************************************************************************/
156 void EPD_3in7_U_Reset(void)
158 DEV_Digital_Write(EPD_RST_PIN, 1);
159 DEV_Delay_ms(200);
160 DEV_Digital_Write(EPD_RST_PIN, 0);
161 DEV_Delay_ms(2);
162 DEV_Digital_Write(EPD_RST_PIN, 1);
163 DEV_Delay_ms(200);
166 /******************************************************************************
167 function : send command
168 parameter:
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 /******************************************************************************
180 function : send data
181 parameter:
182 Data : Write data
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 /******************************************************************************
193 function : Read Busy
194 parameter:
195 ******************************************************************************/
196 void EPD_3in7_U_ReadBusy(void)
198 EPD_Busy_WaitUntil(1,0);
199 // Debug("e-Paper busy\r\n");
200 // UBYTE busy;
201 // do {
202 // busy = DEV_Digital_Read(EPD_BUSY_PIN);
203 // } while(!busy);
204 // DEV_Delay_ms(200);
205 // Debug("e-Paper busy release\r\n");
209 * @brief
212 void EPD_3in7_U_lut(void)
214 UBYTE count;
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]);
247 * @brief
250 void EPD_3in7_U_refresh(void)
252 EPD_3in7_U_SendCommand(0x17);
253 EPD_3in7_U_SendData(0xA5);
254 EPD_3in7_U_ReadBusy();
255 DEV_Delay_ms(200);
258 // LUT download
259 void EPD_3in7_U_lut_GC(void)
261 UBYTE count;
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]);
294 EPD_3in7_U_Flag = 1;
297 else
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]);
311 EPD_3in7_U_Flag = 0;
315 // LUT download
316 void EPD_3in7_U_lut_DU(void)
318 UBYTE count;
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]);
351 EPD_3in7_U_Flag = 1;
354 else
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]);
368 EPD_3in7_U_Flag = 0;
377 /******************************************************************************
378 function : Initialize the e-Paper register
379 parameter:
380 ******************************************************************************/
381 void EPD_3in7_U_Init(UBYTE mode)
383 EPD_3in7_U_Flag = 0;
384 EPD_3in7_U_Reset();
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);
421 // add for luatos
422 EPD_3in7_U_display_NUM(EPD_3in7_U_WHITE);
423 EPD_3in7_U_lut_GC();
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)
433 UWORD i;
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);
438 Image++;
440 // add for luatos
441 EPD_3in7_U_lut_GC();
442 EPD_3in7_U_refresh();
445 void EPD_3in7_U_display_NUM(UBYTE NUM)
447 UWORD row, column;
448 // UWORD pcnt = 0;
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++)
456 switch (NUM)
458 case EPD_3in7_U_WHITE:
459 EPD_3in7_U_SendData(0xFF);
460 break;
462 case EPD_3in7_U_BLACK:
463 EPD_3in7_U_SendData(0x00);
464 break;
466 case EPD_3in7_U_Source_Line:
467 EPD_3in7_U_SendData(0xAA);
468 break;
470 case EPD_3in7_U_Gate_Line:
471 if(column%2)
472 EPD_3in7_U_SendData(0xff); //An odd number of Gate line
473 else
474 EPD_3in7_U_SendData(0x00); //The even line Gate
475 break;
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);
482 else
483 EPD_3in7_U_SendData(0x00);
484 break;
486 case EPD_3in7_U_LEFT_BLACK_RIGHT_WHITE:
487 if(row>=(EPD_3in7_U_WIDTH/8/2))
488 EPD_3in7_U_SendData(0xff);
489 else
490 EPD_3in7_U_SendData(0x00);
491 break;
493 case EPD_3in7_U_UP_BLACK_DOWN_WHITE:
494 if(column>=(EPD_3in7_U_HEIGHT/2))
495 EPD_3in7_U_SendData(0xFF);
496 else
497 EPD_3in7_U_SendData(0x00);
498 break;
500 case EPD_3in7_U_Frame:
501 if(column==0||column==(EPD_3in7_U_HEIGHT-1))
502 EPD_3in7_U_SendData(0x00);
503 else if(row==0)
504 EPD_3in7_U_SendData(0x7F);
505 else if(row==(EPD_3in7_U_WIDTH/8-1))
506 EPD_3in7_U_SendData(0xFE);
507 else
508 EPD_3in7_U_SendData(0xFF);
509 break;
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);
514 else
515 EPD_3in7_U_SendData(0xFF);
516 break;
518 case EPD_3in7_U_Image:
519 //EPD_3in7_U_SendData(gImage_1[pcnt++]);
520 break;
522 default:
523 break;
529 /******************************************************************************
530 function : Clear screen
531 parameter:
532 ******************************************************************************/
533 void EPD_3in7_U_Clear(void)
535 UWORD i;
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);
541 EPD_3in7_U_lut_GC();
542 EPD_3in7_U_refresh();
545 /******************************************************************************
546 function : Enter sleep mode
547 parameter:
548 ******************************************************************************/
549 void EPD_3in7_U_sleep(void)
551 EPD_3in7_U_SendCommand(0X07); //deep sleep
552 EPD_3in7_U_SendData(0xA5);