fix: 对不支持weak的bsp, luat_http_client_onevent报重复定义了
[LuatOS.git] / components / epaper / EPD_2in7.c
blob029c64750bbf5d8ff0b6f8c85800dc88399989db
1 /*****************************************************************************
2 * | File : EPD_2in7.c
3 * | Author : Waveshare team
4 * | Function : 2.7inch e-paper
5 * | Info :
6 *----------------
7 * | This version: V3.1
8 * | Date : 2019-10-10
9 * | Info :
10 * -----------------------------------------------------------------------------
11 * V3.1(2019-10-10):
12 * 1. Add 4 grayscale display
13 * Add EPD_2in7_gray_lut_vcom[]
14 * Add EPD_2in7_gray_lut_ww[]
15 * Add EPD_2in7_gray_lut_bw[]
16 * Add EPD_2in7_gray_lut_wb[]
17 * Add EPD_2in7_gray_lut_bb[]
18 * Add EPD_2in7_gray_SetLut()
19 * Add EPD_2IN7_Init_4Gray()
20 * Add EPD_2IN7_4GrayDisplay()
21 * V3.0(2019-06-12):
22 * 1.Change:
23 * lut_vcom_dc[] => EPD_2in7_lut_vcom_dc[]
24 * lut_ww[] => EPD_2in7_lut_ww[]
25 * lut_bw[] => EPD_2in7_lut_bw[]
26 * lut_bb[] => EPD_2in7_lut_bb[]
27 * lut_wb[] => EPD_2in7_lut_wb[]
28 * EPD_Reset() => EPD_2in7_Reset()
29 * EPD_SendCommand() => EPD_2in7_SendCommand()
30 * EPD_SendData() => EPD_2in7_SendData()
31 * EPD_WaitUntilIdle() => EPD_2in7_ReadBusy()
32 * EPD_SetLut() => EPD_2in7_SetLut()
33 * EPD_Init() => EPD_2in7_Init()
34 * EPD_Clear() => EPD_2in7_Clear()
35 * EPD_Display() => EPD_2in7_Display()
36 * EPD_Sleep() => EPD_2in7_Sleep()
37 * 2.remove commands define:
38 * #define PANEL_SETTING 0x00
39 * #define POWER_SETTING 0x01
40 * #define POWER_OFF 0x02
41 * #define POWER_OFF_SEQUENCE_SETTING 0x03
42 * #define POWER_ON 0x04
43 * #define POWER_ON_MEASURE 0x05
44 * #define BOOSTER_SOFT_START 0x06
45 * #define DEEP_SLEEP 0x07
46 * #define DATA_START_TRANSMISSION_1 0x10
47 * #define DATA_STOP 0x11
48 * #define DISPLAY_REFRESH 0x12
49 * #define DATA_START_TRANSMISSION_2 0x13
50 * #define PLL_CONTROL 0x30
51 * #define TEMPERATURE_SENSOR_COMMAND 0x40
52 * #define TEMPERATURE_SENSOR_CALIBRATION 0x41
53 * #define TEMPERATURE_SENSOR_WRITE 0x42
54 * #define TEMPERATURE_SENSOR_READ 0x43
55 * #define VCOM_AND_DATA_INTERVAL_SETTING 0x50
56 * #define LOW_POWER_DETECTION 0x51
57 * #define TCON_SETTING 0x60
58 * #define TCON_RESOLUTION 0x61
59 * #define SOURCE_AND_GATE_START_SETTING 0x62
60 * #define GET_STATUS 0x71
61 * #define AUTO_MEASURE_VCOM 0x80
62 * #define VCOM_VALUE 0x81
63 * #define VCM_DC_SETTING_REGISTER 0x82
64 * #define PROGRAM_MODE 0xA0
65 * #define ACTIVE_PROGRAM 0xA1
66 * #define READ_OTP_DATA 0xA2
67 * -----------------------------------------------------------------------------
68 * V2.0(2018-11-06):
69 * 1.Remove:ImageBuff[EPD_HEIGHT * EPD_WIDTH / 8]
70 * 2.Change:EPD_Display(UBYTE *Image)
71 * Need to pass parameters: pointer to cached data
73 # Permission is hereby granted, free of charge, to any person obtaining a copy
74 # of this software and associated documnetation files (the "Software"), to deal
75 # in the Software without restriction, including without limitation the rights
76 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
77 # copies of the Software, and to permit persons to whom the Software is
78 # furished to do so, subject to the following conditions:
80 # The above copyright notice and this permission notice shall be included in
81 # all copies or substantial portions of the Software.
83 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
84 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
85 # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
86 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
87 # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
88 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
89 # THE SOFTWARE.
91 ******************************************************************************/
92 #include "EPD_2in7.h"
93 #include "Debug.h"
95 static const unsigned char EPD_2in7_lut_vcom_dc[] = {
96 0x00 ,0x00,
97 0x00 ,0x08 ,0x00 ,0x00 ,0x00 ,0x02,
98 0x60 ,0x28 ,0x28 ,0x00 ,0x00 ,0x01,
99 0x00 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
100 0x00 ,0x12 ,0x12 ,0x00 ,0x00 ,0x01,
101 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
102 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
103 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00
105 static const unsigned char EPD_2in7_lut_ww[] = {
106 0x40 ,0x08 ,0x00 ,0x00 ,0x00 ,0x02,
107 0x90 ,0x28 ,0x28 ,0x00 ,0x00 ,0x01,
108 0x40 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
109 0xA0 ,0x12 ,0x12 ,0x00 ,0x00 ,0x01,
110 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
111 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
112 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
114 static const unsigned char EPD_2in7_lut_bw[] = {
115 0x40 ,0x08 ,0x00 ,0x00 ,0x00 ,0x02,
116 0x90 ,0x28 ,0x28 ,0x00 ,0x00 ,0x01,
117 0x40 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
118 0xA0 ,0x12 ,0x12 ,0x00 ,0x00 ,0x01,
119 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
120 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
121 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
123 static const unsigned char EPD_2in7_lut_bb[] = {
124 0x80 ,0x08 ,0x00 ,0x00 ,0x00 ,0x02,
125 0x90 ,0x28 ,0x28 ,0x00 ,0x00 ,0x01,
126 0x80 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
127 0x50 ,0x12 ,0x12 ,0x00 ,0x00 ,0x01,
128 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
129 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
130 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
132 static const unsigned char EPD_2in7_lut_wb[] = {
133 0x80 ,0x08 ,0x00 ,0x00 ,0x00 ,0x02,
134 0x90 ,0x28 ,0x28 ,0x00 ,0x00 ,0x01,
135 0x80 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
136 0x50 ,0x12 ,0x12 ,0x00 ,0x00 ,0x01,
137 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
138 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
139 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
142 //////////////////////////////////////full screen update LUT////////////////////////////////////////////
143 //0~3 gray
144 static const unsigned char EPD_2in7_gray_lut_vcom[] =
146 0x00 ,0x00,
147 0x00 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
148 0x60 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
149 0x00 ,0x14 ,0x00 ,0x00 ,0x00 ,0x01,
150 0x00 ,0x13 ,0x0A ,0x01 ,0x00 ,0x01,
151 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
152 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
153 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
155 //R21
156 static const unsigned char EPD_2in7_gray_lut_ww[] ={
157 0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
158 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
159 0x10 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
160 0xA0 ,0x13 ,0x01 ,0x00 ,0x00 ,0x01,
161 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
162 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
163 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
165 //R22H r
166 static const unsigned char EPD_2in7_gray_lut_bw[] ={
167 0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
168 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
169 0x00 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
170 0x99 ,0x0C ,0x01 ,0x03 ,0x04 ,0x01,
171 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
172 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
173 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
175 //R23H w
176 static const unsigned char EPD_2in7_gray_lut_wb[] ={
177 0x40 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
178 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
179 0x00 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
180 0x99 ,0x0B ,0x04 ,0x04 ,0x01 ,0x01,
181 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
182 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
183 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
185 //R24H b
186 static const unsigned char EPD_2in7_gray_lut_bb[] ={
187 0x80 ,0x0A ,0x00 ,0x00 ,0x00 ,0x01,
188 0x90 ,0x14 ,0x14 ,0x00 ,0x00 ,0x01,
189 0x20 ,0x14 ,0x0A ,0x00 ,0x00 ,0x01,
190 0x50 ,0x13 ,0x01 ,0x00 ,0x00 ,0x01,
191 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
192 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
193 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
196 /******************************************************************************
197 function : Software reset
198 parameter:
199 ******************************************************************************/
200 static void EPD_2in7_Reset(void)
202 DEV_Digital_Write(EPD_RST_PIN, 1);
203 DEV_Delay_ms(200);
204 DEV_Digital_Write(EPD_RST_PIN, 0);
205 DEV_Delay_ms(2);
206 DEV_Digital_Write(EPD_RST_PIN, 1);
207 DEV_Delay_ms(200);
210 /******************************************************************************
211 function : send command
212 parameter:
213 Reg : Command register
214 ******************************************************************************/
215 static void EPD_2in7_SendCommand(UBYTE Reg)
217 DEV_Digital_Write(EPD_DC_PIN, 0);
218 DEV_Digital_Write(EPD_CS_PIN, 0);
219 DEV_SPI_WriteByte(Reg);
220 DEV_Digital_Write(EPD_CS_PIN, 1);
223 /******************************************************************************
224 function : send data
225 parameter:
226 Data : Write data
227 ******************************************************************************/
228 static void EPD_2in7_SendData(UBYTE Data)
230 DEV_Digital_Write(EPD_DC_PIN, 1);
231 DEV_Digital_Write(EPD_CS_PIN, 0);
232 DEV_SPI_WriteByte(Data);
233 DEV_Digital_Write(EPD_CS_PIN, 1);
236 /******************************************************************************
237 function : Wait until the busy_pin goes LOW
238 parameter:
239 ******************************************************************************/
240 static void EPD_2in7_ReadBusy(void)
242 EPD_Busy_WaitUntil(1,1);
243 // unsigned char count = 100;
244 // Debug("e-Paper busy\r\n");
245 // UBYTE busy;
246 // do {
247 // EPD_2in7_SendCommand(0x71);
248 // busy = DEV_Digital_Read(EPD_BUSY_PIN);
249 // busy =!(busy & 0x01);
250 // if(!(count--))
251 // {
252 // Debug("error: e-Paper busy timeout!!!\r\n");
253 // break;
254 // }
255 // else
256 // DEV_Delay_ms(100);
257 // } while(busy);
258 // DEV_Delay_ms(200);
259 // Debug("e-Paper busy release\r\n");
262 /******************************************************************************
263 function : set the look-up tables
264 parameter:
265 ******************************************************************************/
266 static void EPD_2in7_SetLut(void)
268 unsigned int count;
269 EPD_2in7_SendCommand(0x20); //vcom
270 for(count = 0; count < 44; count++) {
271 EPD_2in7_SendData(EPD_2in7_lut_vcom_dc[count]);
274 EPD_2in7_SendCommand(0x21); //ww --
275 for(count = 0; count < 42; count++) {
276 EPD_2in7_SendData(EPD_2in7_lut_ww[count]);
279 EPD_2in7_SendCommand(0x22); //bw r
280 for(count = 0; count < 42; count++) {
281 EPD_2in7_SendData(EPD_2in7_lut_bw[count]);
284 EPD_2in7_SendCommand(0x23); //wb w
285 for(count = 0; count < 42; count++) {
286 EPD_2in7_SendData(EPD_2in7_lut_bb[count]);
289 EPD_2in7_SendCommand(0x24); //bb b
290 for(count = 0; count < 42; count++) {
291 EPD_2in7_SendData(EPD_2in7_lut_wb[count]);
295 void EPD_2in7_gray_SetLut(void)
297 unsigned int count;
298 EPD_2in7_SendCommand(0x20); //vcom
299 for(count=0;count<44;count++)
300 {EPD_2in7_SendData(EPD_2in7_gray_lut_vcom[count]);}
302 EPD_2in7_SendCommand(0x21); //red not use
303 for(count=0;count<42;count++)
304 {EPD_2in7_SendData(EPD_2in7_gray_lut_ww[count]);}
306 EPD_2in7_SendCommand(0x22); //bw r
307 for(count=0;count<42;count++)
308 {EPD_2in7_SendData(EPD_2in7_gray_lut_bw[count]);}
310 EPD_2in7_SendCommand(0x23); //wb w
311 for(count=0;count<42;count++)
312 {EPD_2in7_SendData(EPD_2in7_gray_lut_wb[count]);}
314 EPD_2in7_SendCommand(0x24); //bb b
315 for(count=0;count<42;count++)
316 {EPD_2in7_SendData(EPD_2in7_gray_lut_bb[count]);}
318 EPD_2in7_SendCommand(0x25); //vcom
319 for(count=0;count<42;count++)
320 {EPD_2in7_SendData(EPD_2in7_gray_lut_ww[count]);}
324 /******************************************************************************
325 function : Initialize the e-Paper register
326 parameter:
327 ******************************************************************************/
328 void EPD_2IN7_Init(UBYTE mode)
330 EPD_2in7_Reset();
332 EPD_2in7_SendCommand(0x01); // POWER_SETTING
333 EPD_2in7_SendData(0x03); // VDS_EN, VDG_EN
334 EPD_2in7_SendData(0x00); // VCOM_HV, VGHL_LV[1], VGHL_LV[0]
335 EPD_2in7_SendData(0x2b); // VDH
336 EPD_2in7_SendData(0x2b); // VDL
337 EPD_2in7_SendData(0x09); // VDHR
339 EPD_2in7_SendCommand(0x06); // BOOSTER_SOFT_START
340 EPD_2in7_SendData(0x07);
341 EPD_2in7_SendData(0x07);
342 EPD_2in7_SendData(0x17);
344 // Power optimization
345 EPD_2in7_SendCommand(0xF8);
346 EPD_2in7_SendData(0x60);
347 EPD_2in7_SendData(0xA5);
349 // Power optimization
350 EPD_2in7_SendCommand(0xF8);
351 EPD_2in7_SendData(0x89);
352 EPD_2in7_SendData(0xA5);
354 // Power optimization
355 EPD_2in7_SendCommand(0xF8);
356 EPD_2in7_SendData(0x90);
357 EPD_2in7_SendData(0x00);
359 // Power optimization
360 EPD_2in7_SendCommand(0xF8);
361 EPD_2in7_SendData(0x93);
362 EPD_2in7_SendData(0x2A);
364 // Power optimization
365 EPD_2in7_SendCommand(0xF8);
366 EPD_2in7_SendData(0xA0);
367 EPD_2in7_SendData(0xA5);
369 // Power optimization
370 EPD_2in7_SendCommand(0xF8);
371 EPD_2in7_SendData(0xA1);
372 EPD_2in7_SendData(0x00);
374 // Power optimization
375 EPD_2in7_SendCommand(0xF8);
376 EPD_2in7_SendData(0x73);
377 EPD_2in7_SendData(0x41);
379 EPD_2in7_SendCommand(0x16); // PARTIAL_DISPLAY_REFRESH
380 EPD_2in7_SendData(0x00);
382 EPD_2in7_SendCommand(0x04); // POWER_ON
383 EPD_2in7_ReadBusy();
385 EPD_2in7_SendCommand(0x00); // PANEL_SETTING
386 EPD_2in7_SendData(0xAF); // KW-BF KWR-AF BWROTP 0f
387 EPD_2in7_SendCommand(0x30); // PLL_CONTROL
388 EPD_2in7_SendData(0x3A); // 3A 100HZ 29 150Hz 39 200HZ 31 171HZ
389 EPD_2in7_SendCommand(0x82); // VCM_DC_SETTING_REGISTER
390 EPD_2in7_SendData(0x12);
392 EPD_2in7_SetLut();
395 void EPD_2IN7_Init_4Gray(void)
397 EPD_2in7_Reset();
398 EPD_2in7_SendCommand(0x01); //POWER SETTING
399 EPD_2in7_SendData (0x03);
400 EPD_2in7_SendData (0x00);
401 EPD_2in7_SendData (0x2b);
402 EPD_2in7_SendData (0x2b);
405 EPD_2in7_SendCommand(0x06); //booster soft start
406 EPD_2in7_SendData (0x07); //A
407 EPD_2in7_SendData (0x07); //B
408 EPD_2in7_SendData (0x17); //C
410 EPD_2in7_SendCommand(0xF8); //boost??
411 EPD_2in7_SendData (0x60);
412 EPD_2in7_SendData (0xA5);
414 EPD_2in7_SendCommand(0xF8); //boost??
415 EPD_2in7_SendData (0x89);
416 EPD_2in7_SendData (0xA5);
418 EPD_2in7_SendCommand(0xF8); //boost??
419 EPD_2in7_SendData (0x90);
420 EPD_2in7_SendData (0x00);
422 EPD_2in7_SendCommand(0xF8); //boost??
423 EPD_2in7_SendData (0x93);
424 EPD_2in7_SendData (0x2A);
426 EPD_2in7_SendCommand(0xF8); //boost??
427 EPD_2in7_SendData (0xa0);
428 EPD_2in7_SendData (0xa5);
430 EPD_2in7_SendCommand(0xF8); //boost??
431 EPD_2in7_SendData (0xa1);
432 EPD_2in7_SendData (0x00);
434 EPD_2in7_SendCommand(0xF8); //boost??
435 EPD_2in7_SendData (0x73);
436 EPD_2in7_SendData (0x41);
438 EPD_2in7_SendCommand(0x16);
439 EPD_2in7_SendData(0x00);
441 EPD_2in7_SendCommand(0x04);
442 EPD_2in7_ReadBusy();
444 EPD_2in7_SendCommand(0x00); //panel setting
445 EPD_2in7_SendData(0xbf); //KW-BF KWR-AF BWROTP 0f
447 EPD_2in7_SendCommand(0x30); //PLL setting
448 EPD_2in7_SendData (0x90); //100hz
450 EPD_2in7_SendCommand(0x61); //resolution setting
451 EPD_2in7_SendData (0x00); //176
452 EPD_2in7_SendData (0xb0);
453 EPD_2in7_SendData (0x01); //264
454 EPD_2in7_SendData (0x08);
456 EPD_2in7_SendCommand(0x82); //vcom_DC setting
457 EPD_2in7_SendData (0x12);
459 EPD_2in7_SendCommand(0X50); //VCOM AND DATA INTERVAL SETTING
460 EPD_2in7_SendData(0x97);
465 /******************************************************************************
466 function : Clear screen
467 parameter:
468 ******************************************************************************/
469 void EPD_2IN7_Clear(void)
471 UWORD Width, Height;
472 Width = (EPD_2IN7_WIDTH % 8 == 0)? (EPD_2IN7_WIDTH / 8 ): (EPD_2IN7_WIDTH / 8 + 1);
473 Height = EPD_2IN7_HEIGHT;
475 EPD_2in7_SendCommand(0x10);
476 for (UWORD j = 0; j < Height; j++) {
477 for (UWORD i = 0; i < Width; i++) {
478 EPD_2in7_SendData(0XFF);
482 EPD_2in7_SendCommand(0x13);
483 for (UWORD j = 0; j < Height; j++) {
484 for (UWORD i = 0; i < Width; i++) {
485 EPD_2in7_SendData(0XFF);
489 EPD_2in7_SendCommand(0x12);
490 EPD_2in7_ReadBusy();
493 /******************************************************************************
494 function : Sends the image buffer in RAM to e-Paper and displays
495 parameter:
496 ******************************************************************************/
497 void EPD_2IN7_Display(const UBYTE *Image, UBYTE *Image2)
499 UWORD Width, Height;
500 Width = (EPD_2IN7_WIDTH % 8 == 0)? (EPD_2IN7_WIDTH / 8 ): (EPD_2IN7_WIDTH / 8 + 1);
501 Height = EPD_2IN7_HEIGHT;
503 EPD_2in7_SendCommand(0x10);
504 for (UWORD j = 0; j < Height; j++) {
505 for (UWORD i = 0; i < Width; i++) {
506 EPD_2in7_SendData(0XFF);
510 EPD_2in7_SendCommand(0x13);
511 for (UWORD j = 0; j < Height; j++) {
512 for (UWORD i = 0; i < Width; i++) {
513 EPD_2in7_SendData(Image[i + j * Width]);
516 EPD_2in7_SendCommand(0x12);
517 EPD_2in7_ReadBusy();
520 void EPD_2IN7_4GrayDisplay(const UBYTE *Image)
522 UDOUBLE i,j,k;
523 UBYTE temp1,temp2,temp3;
525 EPD_2in7_SendCommand(0x10);
526 for(i=0;i<5808;i++) //5808*4 46464
528 temp3=0;
529 for(j=0;j<2;j++)
531 temp1 = Image[i*2+j];
532 for(k=0;k<2;k++)
534 temp2 = temp1&0xC0 ;
535 if(temp2 == 0xC0)
536 temp3 |= 0x01;//white
537 else if(temp2 == 0x00)
538 temp3 |= 0x00; //black
539 else if(temp2 == 0x80)
540 temp3 |= 0x01; //gray1
541 else //0x40
542 temp3 |= 0x00; //gray2
543 temp3 <<= 1;
545 temp1 <<= 2;
546 temp2 = temp1&0xC0 ;
547 if(temp2 == 0xC0) //white
548 temp3 |= 0x01;
549 else if(temp2 == 0x00) //black
550 temp3 |= 0x00;
551 else if(temp2 == 0x80)
552 temp3 |= 0x01; //gray1
553 else //0x40
554 temp3 |= 0x00; //gray2
555 if(j!=1 || k!=1)
556 temp3 <<= 1;
558 temp1 <<= 2;
562 EPD_2in7_SendData(temp3);
564 // new data
565 EPD_2in7_SendCommand(0x13);
566 for(i=0;i<5808;i++) //5808*4 46464
568 temp3=0;
569 for(j=0;j<2;j++)
571 temp1 = Image[i*2+j];
572 for(k=0;k<2;k++)
574 temp2 = temp1&0xC0 ;
575 if(temp2 == 0xC0)
576 temp3 |= 0x01;//white
577 else if(temp2 == 0x00)
578 temp3 |= 0x00; //black
579 else if(temp2 == 0x80)
580 temp3 |= 0x00; //gray1
581 else //0x40
582 temp3 |= 0x01; //gray2
583 temp3 <<= 1;
585 temp1 <<= 2;
586 temp2 = temp1&0xC0 ;
587 if(temp2 == 0xC0) //white
588 temp3 |= 0x01;
589 else if(temp2 == 0x00) //black
590 temp3 |= 0x00;
591 else if(temp2 == 0x80)
592 temp3 |= 0x00; //gray1
593 else //0x40
594 temp3 |= 0x01; //gray2
595 if(j!=1 || k!=1)
596 temp3 <<= 1;
598 temp1 <<= 2;
602 EPD_2in7_SendData(temp3);
605 EPD_2in7_gray_SetLut();
606 EPD_2in7_SendCommand(0x12);
607 DEV_Delay_ms(200);
608 EPD_2in7_ReadBusy();
612 /******************************************************************************
613 function : Enter sleep mode
614 parameter:
615 ******************************************************************************/
616 void EPD_2IN7_Sleep(void)
618 EPD_2in7_SendCommand(0X50);
619 EPD_2in7_SendData(0xf7);
620 EPD_2in7_SendCommand(0X02); //power off
621 EPD_2in7_SendCommand(0X07); //deep sleep
622 EPD_2in7_SendData(0xA5);