-
Notifications
You must be signed in to change notification settings - Fork 0
/
GDEW0097T50_lib.cpp
457 lines (382 loc) · 12.1 KB
/
GDEW0097T50_lib.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
#include "GDEW0097T50_lib.h"
unsigned char oldData[2024];
unsigned char oldDataP[256];
unsigned char oldDataA[256];
unsigned char oldDataB[256];
unsigned char oldDataC[256];
unsigned char oldDataD[256];
unsigned char oldDataE[256];
unsigned char partFlag=1;
//SPI write byte
void SPI_Write(unsigned char value)
{
SPI.transfer(value);
}
//SPI write command
void EPD_W21_WriteCMD(unsigned char command)
{
EPD_W21_CS_0;
EPD_W21_DC_0; // D/C# 0:command 1:data
SPI_Write(command);
EPD_W21_CS_1;
}
//SPI write data
void EPD_W21_WriteDATA(unsigned char datas)
{
EPD_W21_CS_0;
EPD_W21_DC_1; // D/C# 0:command 1:data
SPI_Write(datas);
EPD_W21_CS_1;
}
//Busy function
void lcd_chkstatus(void)
{
while(1)
{ //=0 BUSY
if(isEPD_W21_BUSY==1) break;
ESP.wdtFeed(); // Feed dog to prevent system reset
}
}
void EPD_lut(unsigned char LUTsel)
{
unsigned char tempfull,temppartial;
EPD_W21_WriteCMD(0x40);
lcd_chkstatus();
tempfull =25;
if((128>tempfull)&&(tempfull>54))
tempfull = 53 ;
else if(tempfull>128)
tempfull = 1;
temppartial = tempfull+60;
if(temppartial>128)
temppartial = 127;
if(LUTsel==0)
{
EPD_W21_WriteCMD(0xE0);
EPD_W21_WriteDATA(0x02);
EPD_W21_WriteCMD(0xE5);
EPD_W21_WriteDATA(tempfull); // define the Temperature value////
}
else if(LUTsel==1)
{
EPD_W21_WriteCMD(0xe0);
EPD_W21_WriteDATA (0x02);
EPD_W21_WriteCMD(0xe5);
EPD_W21_WriteDATA (temppartial);
}
}
//JD79651
void EPD_Init(void)
{
EPD_W21_RST_0; // Module reset
delay(10); // At least 10ms delay
EPD_W21_RST_1;
delay(10); // At least 10ms delay
lcd_chkstatus();
/******FiTi init****************/
EPD_W21_WriteCMD(0x4D); // FITIinternal code
EPD_W21_WriteDATA (0xAA);
EPD_W21_WriteCMD(0x87); // FITIinternal code
EPD_W21_WriteDATA (0x28);
EPD_W21_WriteCMD(0x88); // FITIinternal code
EPD_W21_WriteDATA (0x80);
EPD_W21_WriteCMD(0x90); // FITIinternal code
EPD_W21_WriteDATA (0x02);
EPD_W21_WriteCMD(0x91); // FITIinternal code
EPD_W21_WriteDATA (0x8d);
EPD_W21_WriteCMD(0xAA); // FITIinternal code
EPD_W21_WriteDATA (0x0f);
EPD_lut(0);
EPD_W21_WriteCMD(0xE8);
EPD_W21_WriteDATA (0xA8); // A
EPD_W21_WriteCMD(0x26);
EPD_W21_WriteDATA (0x0f); // A
EPD_W21_WriteCMD(0x04);
lcd_chkstatus();
EPD_W21_WriteCMD(0x00); // panel setting
EPD_W21_WriteDATA(0x1f); // KW-BF KWR-AF BWROTP 0f BWOTP 1f
EPD_W21_WriteCMD(0X50);
EPD_W21_WriteDATA(0x97);
}
void EPD_Init_Part(void)
{
EPD_W21_RST_0; // Module reset
delay(10); // At least 10ms delay
EPD_W21_RST_1;
delay(10); // At least 10ms delay
lcd_chkstatus();
EPD_W21_WriteCMD(0x4D); // FITIinternal code
EPD_W21_WriteDATA (0xAA);
EPD_W21_WriteCMD(0x87); // FITIinternal code
EPD_W21_WriteDATA (0x28);
EPD_W21_WriteCMD(0x88); // FITIinternal code
EPD_W21_WriteDATA (0x80);
EPD_W21_WriteCMD(0x90); // FITIinternal code
EPD_W21_WriteDATA (0x02);
EPD_W21_WriteCMD(0x91); // FITIinternal code
EPD_W21_WriteDATA (0x8d);
EPD_W21_WriteCMD(0xAA); // FITIinternal code
EPD_W21_WriteDATA (0x0f);
EPD_lut(1);
EPD_W21_WriteCMD(0xE8);
EPD_W21_WriteDATA (0xA8); // A
EPD_W21_WriteCMD(0x26);
EPD_W21_WriteDATA (0x0f); // A
EPD_W21_WriteCMD(0x04);
lcd_chkstatus();
EPD_W21_WriteCMD(0x00); // panel setting
EPD_W21_WriteDATA(0x1f); // KW-BF KWR-AF BWROTP 0f BWOTP 1f
EPD_W21_WriteCMD(0X50);
EPD_W21_WriteDATA(0xf7);
}
void EPD_DeepSleep(void)
{
EPD_W21_WriteCMD(0X50); // VCOM AND DATA INTERVAL SETTING
EPD_W21_WriteDATA(0xf7); // WBmode:VBDF 17|D7 VBDW 97 VBDB 57 WBRmode:VBDF F7 VBDW 77 VBDB 37 VBDR B7
EPD_W21_WriteCMD(0X02); // power off
lcd_chkstatus(); // waiting for the electronic paper IC to release the idle signal
delay(100);
EPD_W21_WriteCMD(0X07); // deep sleep
EPD_W21_WriteDATA(0xA5);
}
//Full screen refresh update function
void EPD_Update(void)
{
//Refresh
EPD_W21_WriteCMD(0x12); // DISPLAY REFRESH
delay(1); // !!!The delay here is necessary, 200uS at least!!!
lcd_chkstatus(); // waiting for the electronic paper IC to release the idle signal
}
void EPD_WhiteScreen_ALL(const unsigned char *datas)
{
unsigned int i;
//Write Data
EPD_W21_WriteCMD(0x10); // Transfer old data
for(i=0;i<EPD_ARRAY;i++)
{
EPD_W21_WriteDATA(0xFF); // Transfer the actual displayed data
}
EPD_W21_WriteCMD(0x13); // Transfer new data
for(i=0;i<EPD_ARRAY;i++)
{
EPD_W21_WriteDATA(pgm_read_byte(&datas[i])); // Transfer the actual displayed data
}
EPD_Update();
}
void EPD_WhiteScreen_White(void)
{
unsigned int i;
//Write Data
EPD_W21_WriteCMD(0x10); // Transfer old data
for(i=0;i<EPD_ARRAY;i++)
{
EPD_W21_WriteDATA(0xFF);
}
EPD_W21_WriteCMD(0x13); // Transfer new data
for(i=0;i<EPD_ARRAY;i++)
{
EPD_W21_WriteDATA(0xFF); // Transfer the actual displayed data
oldData[i]=0xFF;
}
EPD_Update();
}
//Partial refresh of background display, this function is necessary, please do not delete it!!!
void EPD_SetRAMValue_BaseMap( const unsigned char * datas)
{
unsigned int i;
EPD_W21_WriteCMD(0x10); // write old data
for(i=0;i<EPD_ARRAY;i++)
{
EPD_W21_WriteDATA(0xFF);
}
EPD_W21_WriteCMD(0x13); // write new data
for(i=0;i<EPD_ARRAY;i++)
{
EPD_W21_WriteDATA(pgm_read_byte(&datas[i]));
oldData[i]=pgm_read_byte(&datas[i]);
}
EPD_Update();
}
void EPD_Dis_Part(unsigned int x_start,unsigned int y_start,const unsigned char * datas,unsigned int PART_COLUMN,unsigned int PART_LINE)
{
unsigned int i;
x_start=x_start-x_start%8;
EPD_Init_Part();
EPD_W21_WriteCMD(0x91); // This command makes the display enter partial mode
EPD_W21_WriteCMD(0x90); // resolution setting
EPD_W21_WriteCMD(0x14); // resolution setting
EPD_W21_WriteDATA (x_start); // x-start
EPD_W21_WriteDATA (y_start/256);
EPD_W21_WriteDATA (y_start%256); // y-start
EPD_W21_WriteDATA(PART_LINE); // w
EPD_W21_WriteDATA((PART_COLUMN)/256); // l-MSB
EPD_W21_WriteDATA((PART_COLUMN)%256); // l-LSB
if(partFlag==1)
{
partFlag=0;
for(i=0;i<PART_COLUMN*PART_LINE/8;i++)
EPD_W21_WriteDATA(0xFF);
}
else
{
for(i=0;i<PART_COLUMN*PART_LINE/8;i++)
EPD_W21_WriteDATA(oldData[i]);
}
EPD_W21_WriteCMD(0x15); // resolution setting
EPD_W21_WriteDATA (x_start); // x-start
EPD_W21_WriteDATA (y_start/256);
EPD_W21_WriteDATA (y_start%256); // y-start
EPD_W21_WriteDATA(PART_LINE); //w
EPD_W21_WriteDATA((PART_COLUMN)/256); // l-MSB
EPD_W21_WriteDATA((PART_COLUMN)%256); // l-LSB
for(i=0;i<PART_COLUMN*PART_LINE/8;i++)
{
EPD_W21_WriteDATA(pgm_read_byte(&datas[i]));
oldData[i]=pgm_read_byte(&datas[i]);
}
//Refresh
EPD_W21_WriteCMD(0x16); // DISPLAY REFRESH
EPD_W21_WriteDATA (x_start); // x-start
EPD_W21_WriteDATA (y_start/256);
EPD_W21_WriteDATA (y_start%256); // y-start
EPD_W21_WriteDATA(PART_LINE); // w
EPD_W21_WriteDATA((PART_COLUMN)/256); // l-MSB
EPD_W21_WriteDATA((PART_COLUMN)%256); // l-LSB
delay(1); // !!!The delay here is necessary, 200uS at least!!!
lcd_chkstatus(); // waiting for the electronic paper IC to release the idle signal
}
// Full screen partial refresh display
void EPD_Dis_PartAll(const unsigned char * datas)
{
unsigned int i;
EPD_Init_Part();
// Write Data
EPD_W21_WriteCMD(0x10); // Transfer old data
for(i=0;i<EPD_ARRAY;i++)
{
EPD_W21_WriteDATA(oldData[i]); // Transfer the actual displayed data
}
EPD_W21_WriteCMD(0x13); // Transfer new data
for(i=0;i<EPD_ARRAY;i++)
{
EPD_W21_WriteDATA(pgm_read_byte(&datas[i])); // Transfer the actual displayed data
oldData[i]=pgm_read_byte(&datas[i]);
}
EPD_Update();
}
//Partial refresh write address and data
void EPD_Dis_Part_RAM(unsigned int x_start,unsigned int y_start,
const unsigned char * datas_A,const unsigned char * datas_B,
const unsigned char * datas_C,const unsigned char * datas_D,const unsigned char * datas_E,
unsigned char num,unsigned int PART_COLUMN,unsigned int PART_LINE)
{
unsigned int i;
x_start=x_start-x_start%8;
EPD_Init_Part();
EPD_W21_WriteCMD(0x91); // This command makes the display enter partial mode
EPD_W21_WriteCMD(0x90); // resolution setting
EPD_W21_WriteCMD(0x14); // resolution setting
EPD_W21_WriteDATA (x_start); // x-start
EPD_W21_WriteDATA (y_start/256);
EPD_W21_WriteDATA (y_start%256); // y-start
EPD_W21_WriteDATA(PART_LINE); // w
EPD_W21_WriteDATA((PART_COLUMN*num)/256); // l-MSB
EPD_W21_WriteDATA((PART_COLUMN*num)%256); // l-LSB
if(partFlag==1)
{
partFlag=0;
for(i=0;i<PART_COLUMN*PART_LINE*num/8;i++)
EPD_W21_WriteDATA(0xFF);
}
else
{
for(i=0;i<PART_COLUMN*PART_LINE/8;i++)
EPD_W21_WriteDATA(oldDataA[i]);
for(i=0;i<PART_COLUMN*PART_LINE/8;i++)
EPD_W21_WriteDATA(oldDataB[i]);
for(i=0;i<PART_COLUMN*PART_LINE/8;i++)
EPD_W21_WriteDATA(oldDataC[i]);
for(i=0;i<PART_COLUMN*PART_LINE/8;i++)
EPD_W21_WriteDATA(oldDataD[i]);
for(i=0;i<PART_COLUMN*PART_LINE/8;i++)
EPD_W21_WriteDATA(oldDataE[i]);
}
EPD_W21_WriteCMD(0x15); // writes New data to SRAM.
EPD_W21_WriteDATA (x_start); // x-start
EPD_W21_WriteDATA (y_start/256);
EPD_W21_WriteDATA (y_start%256); // y-start
EPD_W21_WriteDATA(PART_LINE); // w
EPD_W21_WriteDATA((PART_COLUMN*num)/256); // l-MSB
EPD_W21_WriteDATA((PART_COLUMN*num)%256); // l-LSB
for(i=0;i<PART_COLUMN*PART_LINE/8;i++)
{
EPD_W21_WriteDATA(pgm_read_byte(&datas_A[i]));
oldDataA[i]=pgm_read_byte(&datas_A[i]);
}
for(i=0;i<PART_COLUMN*PART_LINE/8;i++)
{
EPD_W21_WriteDATA(pgm_read_byte(&datas_B[i]));
oldDataB[i]=pgm_read_byte(&datas_B[i]);
}
for(i=0;i<PART_COLUMN*PART_LINE/8;i++)
{
EPD_W21_WriteDATA(pgm_read_byte(&datas_C[i]));
oldDataC[i]=pgm_read_byte(&datas_C[i]);
}
for(i=0;i<PART_COLUMN*PART_LINE/8;i++)
{
EPD_W21_WriteDATA(pgm_read_byte(&datas_D[i]));
oldDataD[i]=pgm_read_byte(&datas_D[i]);
}
for(i=0;i<PART_COLUMN*PART_LINE/8;i++)
{
EPD_W21_WriteDATA(pgm_read_byte(&datas_E[i]));
oldDataE[i]=pgm_read_byte(&datas_E[i]);
}
//Refresh
EPD_W21_WriteCMD(0x16); // DISPLAY REFRESH
EPD_W21_WriteDATA (x_start); // x-start
EPD_W21_WriteDATA (y_start/256);
EPD_W21_WriteDATA (y_start%256); // y-start
EPD_W21_WriteDATA(PART_LINE); // w
EPD_W21_WriteDATA((PART_COLUMN*num)/256); // l-MSB
EPD_W21_WriteDATA((PART_COLUMN*num)%256); // l-LSB
delay(1); // !!!The delay here is necessary, 200uS at least!!!
lcd_chkstatus(); // waiting for the electronic paper IC to release the idle signal
}
//Display rotation 180 degrees initialization
void EPD_Init_180(void)
{
EPD_W21_RST_0; // Module reset
delay(10);//At least 10ms delay
EPD_W21_RST_1;
delay(10);//At least 10ms delay
lcd_chkstatus();
/******FiTi init****************/
EPD_W21_WriteCMD(0x4D); //FITIinternal code
EPD_W21_WriteDATA (0xAA);
EPD_W21_WriteCMD(0x87); //FITIinternal code
EPD_W21_WriteDATA (0x28);
EPD_W21_WriteCMD(0x88); //FITIinternal code
EPD_W21_WriteDATA (0x80);
EPD_W21_WriteCMD(0x90); //FITIinternal code
EPD_W21_WriteDATA (0x02);
EPD_W21_WriteCMD(0x91); //FITIinternal code
EPD_W21_WriteDATA (0x8d);
EPD_W21_WriteCMD(0xAA); //FITIinternal code
EPD_W21_WriteDATA (0x0f);
EPD_lut(0);
EPD_W21_WriteCMD(0xE8);
EPD_W21_WriteDATA (0xA8); //A
EPD_W21_WriteCMD(0x26);
EPD_W21_WriteDATA (0x0f); //A
EPD_W21_WriteCMD(0x04);
lcd_chkstatus();
EPD_W21_WriteCMD(0x00);
EPD_W21_WriteDATA(0x13); //180 mirror
EPD_W21_WriteCMD(0X50);
EPD_W21_WriteDATA(0x97);
}
/*
That's all folks!
*/