-
Notifications
You must be signed in to change notification settings - Fork 246
/
Copy pathGxEPD2_3C.h
680 lines (651 loc) · 24.9 KB
/
GxEPD2_3C.h
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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
// Display Library for SPI e-paper panels from Dalian Good Display and boards from Waveshare.
// Requires HW SPI and Adafruit_GFX. Caution: the e-paper panels require 3.3V supply AND data lines!
//
// Display Library based on Demo Example from Good Display: https://www.good-display.com/companyfile/32/
//
// Author: Jean-Marc Zingg
//
// Version: see library.properties
//
// Library: https://github.com/ZinggJM/GxEPD2
#ifndef _GxEPD2_3C_H_
#define _GxEPD2_3C_H_
// uncomment next line to use class GFX of library GFX_Root instead of Adafruit_GFX
//#include <GFX.h>
#ifndef ENABLE_GxEPD2_GFX
// default is off
#define ENABLE_GxEPD2_GFX 0
#endif
#if ENABLE_GxEPD2_GFX
#include "GxEPD2_GFX.h"
#define GxEPD2_GFX_BASE_CLASS GxEPD2_GFX
#elif defined(_GFX_H_)
#define GxEPD2_GFX_BASE_CLASS GFX
#else
#include <Adafruit_GFX.h>
#define GxEPD2_GFX_BASE_CLASS Adafruit_GFX
#endif
#include "GxEPD2_EPD.h"
// for __has_include see https://en.cppreference.com/w/cpp/preprocessor/include
// see also https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005finclude.html
// #if !defined(__has_include) || __has_include("epd/GxEPD2_102.h") is not portable!
#if defined __has_include
# if __has_include("GxEPD2.h")
# // __has_include can be used
# else
# // __has_include doesn't work for us, include anyway
# undef __has_include
# define __has_include(x) true
# endif
#else
# // no __has_include, include anyway
# define __has_include(x) true
#endif
#if __has_include("epd3c/GxEPD2_154c.h")
#include "epd3c/GxEPD2_154c.h"
#endif
#if __has_include("epd3c/GxEPD2_154_Z90c.h")
#include "epd3c/GxEPD2_154_Z90c.h"
#endif
#if __has_include("epd3c/GxEPD2_213c.h")
#include "epd3c/GxEPD2_213c.h"
#endif
#if __has_include("epd3c/GxEPD2_213_Z19c.h")
#include "epd3c/GxEPD2_213_Z19c.h"
#endif
#if __has_include("epd3c/GxEPD2_213_Z98c.h")
#include "epd3c/GxEPD2_213_Z98c.h"
#endif
#if __has_include("epd3c/GxEPD2_290c.h")
#include "epd3c/GxEPD2_290c.h"
#endif
#if __has_include("epd3c/GxEPD2_290_Z13c.h")
#include "epd3c/GxEPD2_290_Z13c.h"
#endif
#if __has_include("epd3c/GxEPD2_290_C90c.h")
#include "epd3c/GxEPD2_290_C90c.h"
#endif
#if __has_include("epd3c/GxEPD2_266c.h")
#include "epd3c/GxEPD2_266c.h"
#endif
#if __has_include("epd3c/GxEPD2_150_BN.h")
#include "epd3c/GxEPD2_270c.h"
#endif
#if __has_include("epd3c/GxEPD2_420c.h")
#include "epd3c/GxEPD2_420c.h"
#endif
#if __has_include("epd3c/GxEPD2_420c_Z21.h")
#include "epd3c/GxEPD2_420c_Z21.h"
#endif
#if __has_include("gdey3c/GxEPD2_420c_GDEY042Z98.h")
#include "gdey3c/GxEPD2_420c_GDEY042Z98.h"
#endif
#if __has_include("gdey3c/GxEPD2_579c_GDEY0579Z93.h")
#include "gdey3c/GxEPD2_579c_GDEY0579Z93.h"
#endif
#if __has_include("epd3c/GxEPD2_583c.h")
#include "epd3c/GxEPD2_583c.h"
#endif
#if __has_include("gdeq3c/GxEPD2_583c_GDEQ0583Z31.h")
#include "gdeq3c/GxEPD2_583c_GDEQ0583Z31.h"
#endif
#if __has_include("epd3c/GxEPD2_583c_Z83.h")
#include "epd3c/GxEPD2_583c_Z83.h"
#endif
#if __has_include("epd7c/GxEPD2_565c.h")
#include "epd7c/GxEPD2_565c.h"
#endif
#if __has_include("epd3c/GxEPD2_750c.h")
#include "epd3c/GxEPD2_750c.h"
#endif
#if __has_include("epd3c/GxEPD2_750c_Z08.h")
#include "epd3c/GxEPD2_750c_Z08.h"
#endif
#if __has_include("epd3c/GxEPD2_750c_Z90.h")
#include "epd3c/GxEPD2_750c_Z90.h"
#endif
#if __has_include("gdey3c/GxEPD2_1160c_GDEY116Z91.h")
#include "gdey3c/GxEPD2_1160c_GDEY116Z91.h"
#endif
#if __has_include("epd3c/GxEPD2_1248c.h")
#include "epd3c/GxEPD2_1248c.h"
#endif
#if __has_include("gdem3c/GxEPD2_1330c_GDEM133Z91.h")
#include "gdem3c/GxEPD2_1330c_GDEM133Z91.h"
#endif
template<typename GxEPD2_Type, const uint16_t page_height>
class GxEPD2_3C : public GxEPD2_GFX_BASE_CLASS
{
public:
GxEPD2_Type epd2;
#if ENABLE_GxEPD2_GFX
GxEPD2_3C(GxEPD2_Type epd2_instance) : GxEPD2_GFX_BASE_CLASS(epd2, GxEPD2_Type::WIDTH_VISIBLE, GxEPD2_Type::HEIGHT), epd2(epd2_instance)
#else
GxEPD2_3C(GxEPD2_Type epd2_instance) : GxEPD2_GFX_BASE_CLASS(GxEPD2_Type::WIDTH_VISIBLE, GxEPD2_Type::HEIGHT), epd2(epd2_instance)
#endif
{
_page_height = page_height;
_pages = (HEIGHT / _page_height) + ((HEIGHT % _page_height) > 0);
_mirror = false;
_using_partial_mode = false;
_current_page = 0;
setFullWindow();
}
uint16_t pages()
{
return _pages;
}
uint16_t pageHeight()
{
return _page_height;
}
bool mirror(bool m)
{
_swap_ (_mirror, m);
return m;
}
void drawPixel(int16_t x, int16_t y, uint16_t color)
{
if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) return;
if (_mirror) x = width() - x - 1;
// check rotation, move pixel around if necessary
switch (getRotation())
{
case 1:
_swap_(x, y);
x = WIDTH - x - 1;
break;
case 2:
x = WIDTH - x - 1;
y = HEIGHT - y - 1;
break;
case 3:
_swap_(x, y);
y = HEIGHT - y - 1;
break;
}
// transpose partial window to 0,0
x -= _pw_x;
y -= _pw_y;
// clip to (partial) window
if ((x < 0) || (x >= int16_t(_pw_w)) || (y < 0) || (y >= int16_t(_pw_h))) return;
// adjust for current page
y -= _current_page * _page_height;
// check if in current page
if ((y < 0) || (y >= int16_t(_page_height))) return;
uint16_t i = x / 8 + y * (_pw_w / 8);
_black_buffer[i] = (_black_buffer[i] | (1 << (7 - x % 8))); // white
_color_buffer[i] = (_color_buffer[i] | (1 << (7 - x % 8)));
if (color == GxEPD_WHITE) return;
else if (color == GxEPD_BLACK) _black_buffer[i] = (_black_buffer[i] & (0xFF ^ (1 << (7 - x % 8))));
else if ((color == GxEPD_RED) || (color == GxEPD_YELLOW)) _color_buffer[i] = (_color_buffer[i] & (0xFF ^ (1 << (7 - x % 8))));
}
void init(uint32_t serial_diag_bitrate = 0) // = 0 : disabled
{
epd2.init(serial_diag_bitrate);
_using_partial_mode = false;
_current_page = 0;
setFullWindow();
}
// init method with additional parameters:
// initial false for re-init after processor deep sleep wake up, if display power supply was kept
// only relevant for b/w displays with fast partial update
// reset_duration = 20 is default; a value of 2 may help with "clever" reset circuit of newer boards from Waveshare
// pulldown_rst_mode true for alternate RST handling to avoid feeding 5V through RST pin
void init(uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration = 20, bool pulldown_rst_mode = false)
{
epd2.init(serial_diag_bitrate, initial, reset_duration, pulldown_rst_mode);
_using_partial_mode = false;
_current_page = 0;
setFullWindow();
}
// init method with additional parameters:
// SPIClass& spi: either SPI or alternate HW SPI channel
// SPISettings spi_settings: e.g. for higher SPI speed selection
void init(uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration, bool pulldown_rst_mode, SPIClass& spi, SPISettings spi_settings)
{
epd2.selectSPI(spi, spi_settings);
epd2.init(serial_diag_bitrate, initial, reset_duration, pulldown_rst_mode);
_using_partial_mode = false;
_current_page = 0;
setFullWindow();
}
// release SPI and control pins
void end()
{
epd2.end();
}
void fillScreen(uint16_t color) // 0x0 black, >0x0 white, to buffer
{
uint8_t black = 0xFF;
uint8_t red = 0xFF;
if (color == GxEPD_WHITE);
else if (color == GxEPD_BLACK) black = 0x00;
else if ((color == GxEPD_RED) || (color == GxEPD_YELLOW)) red = 0x00;
for (uint16_t x = 0; x < sizeof(_black_buffer); x++)
{
_black_buffer[x] = black;
_color_buffer[x] = red;
}
}
// display buffer content to screen, useful for full screen buffer
void display(bool partial_update_mode = false)
{
epd2.writeImage(_black_buffer, _color_buffer, 0, 0, GxEPD2_Type::WIDTH, _page_height);
epd2.refresh(partial_update_mode);
if (!partial_update_mode) epd2.powerOff();
}
// display part of buffer content to screen, useful for full screen buffer
// displayWindow, use parameters according to actual rotation.
// x and w should be multiple of 8, for rotation 0 or 2,
// y and h should be multiple of 8, for rotation 1 or 3,
// else window is increased as needed,
// this is an addressing limitation of the e-paper controllers
void displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
{
x = gx_uint16_min(x, width());
y = gx_uint16_min(y, height());
w = gx_uint16_min(w, width() - x);
h = gx_uint16_min(h, height() - y);
_rotate(x, y, w, h);
epd2.writeImagePart(_black_buffer, _color_buffer, x, y, GxEPD2_Type::WIDTH, _page_height, x, y, w, h);
epd2.refresh(x, y, w, h);
}
void displayWindowBW(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
{
x = gx_uint16_min(x, width());
y = gx_uint16_min(y, height());
w = gx_uint16_min(w, width() - x);
h = gx_uint16_min(h, height() - y);
_rotate(x, y, w, h);
epd2.writeImagePartNew(_black_buffer, x, y, GxEPD2_Type::WIDTH, _page_height, x, y, w, h);
epd2.refresh_bw(x, y, w, h);
epd2.writeImagePartPrevious(_black_buffer, x, y, GxEPD2_Type::WIDTH, _page_height, x, y, w, h);
}
void setFullWindow()
{
_using_partial_mode = false;
_pw_x = 0;
_pw_y = 0;
_pw_w = GxEPD2_Type::WIDTH;
_pw_h = HEIGHT;
}
// setPartialWindow, use parameters according to actual rotation.
// x and w should be multiple of 8, for rotation 0 or 2,
// y and h should be multiple of 8, for rotation 1 or 3,
// else window is increased as needed,
// this is an addressing limitation of the e-paper controllers
void setPartialWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
{
if (!epd2.hasPartialUpdate) return;
_pw_x = gx_uint16_min(x, width());
_pw_y = gx_uint16_min(y, height());
_pw_w = gx_uint16_min(w, width() - _pw_x);
_pw_h = gx_uint16_min(h, height() - _pw_y);
_rotate(_pw_x, _pw_y, _pw_w, _pw_h);
_using_partial_mode = true;
// make _pw_x, _pw_w multiple of 8
_pw_w += _pw_x % 8;
if (_pw_w % 8 > 0) _pw_w += 8 - _pw_w % 8;
_pw_x -= _pw_x % 8;
}
void firstPage()
{
fillScreen(GxEPD_WHITE);
_current_page = 0;
_second_phase = false;
epd2.setPaged(); // for GxEPD2_154c paged workaround
}
bool nextPage()
{
uint16_t page_ys = _current_page * _page_height;
if (_using_partial_mode)
{
//Serial.print(" nextPage("); Serial.print(_pw_x); Serial.print(", "); Serial.print(_pw_y); Serial.print(", ");
//Serial.print(_pw_w); Serial.print(", "); Serial.print(_pw_h); Serial.print(") P"); Serial.println(_current_page);
uint16_t page_ye = _current_page < int16_t(_pages - 1) ? page_ys + _page_height : HEIGHT;
uint16_t dest_ys = _pw_y + page_ys; // transposed
uint16_t dest_ye = gx_uint16_min(_pw_y + _pw_h, _pw_y + page_ye);
if (dest_ye > dest_ys)
{
//Serial.print("writeImage("); Serial.print(_pw_x); Serial.print(", "); Serial.print(dest_ys); Serial.print(", ");
//Serial.print(_pw_w); Serial.print(", "); Serial.print(dest_ye - dest_ys); Serial.println(")");
epd2.writeImage(_black_buffer, _color_buffer, _pw_x, dest_ys, _pw_w, dest_ye - dest_ys);
}
else
{
//Serial.print("writeImage("); Serial.print(_pw_x); Serial.print(", "); Serial.print(dest_ys); Serial.print(", ");
//Serial.print(_pw_w); Serial.print(", "); Serial.print(dest_ye - dest_ys); Serial.print(") skipped ");
//Serial.print(dest_ys); Serial.print(".."); Serial.println(dest_ye);
}
_current_page++;
if (_current_page == int16_t(_pages))
{
_current_page = 0;
if (!_second_phase)
{
epd2.refresh(_pw_x, _pw_y, _pw_w, _pw_h);
if (epd2.hasFastPartialUpdate)
{
_second_phase = true;
return true;
}
}
return false;
}
fillScreen(GxEPD_WHITE);
return true;
}
else // full update
{
epd2.writeImage(_black_buffer, _color_buffer, 0, page_ys, GxEPD2_Type::WIDTH, gx_uint16_min(_page_height, HEIGHT - page_ys));
_current_page++;
if (_current_page == int16_t(_pages))
{
_current_page = 0;
if ((epd2.panel == GxEPD2::GDEW0154Z04) && (_pages > 1))
{
if (!_second_phase)
{
epd2.refresh(false); // full update after first phase
_second_phase = true;
fillScreen(GxEPD_WHITE);
return true;
}
else epd2.refresh(true); // partial update after second phase
} else epd2.refresh(false); // full update after only phase
epd2.powerOff();
return false;
}
fillScreen(GxEPD_WHITE);
return true;
}
}
bool nextPageBW()
{
if (1 == _pages)
{
if (_using_partial_mode)
{
epd2.writeImageNew(_black_buffer, _pw_x, _pw_y, _pw_w, _pw_h);
epd2.refresh_bw(_pw_x, _pw_y, _pw_w, _pw_h);
epd2.writeImagePrevious(_black_buffer, _pw_x, _pw_y, _pw_w, _pw_h);
}
else // full update
{
epd2.writeImage(_black_buffer, 0, 0, GxEPD2_Type::WIDTH, HEIGHT);
epd2.refresh(false);
epd2.writeImagePrevious(_black_buffer, 0, 0, GxEPD2_Type::WIDTH, HEIGHT);
epd2.powerOff();
}
return false;
}
uint16_t page_ys = _current_page * _page_height;
if (_using_partial_mode)
{
//Serial.print(" nextPage("); Serial.print(_pw_x); Serial.print(", "); Serial.print(_pw_y); Serial.print(", ");
//Serial.print(_pw_w); Serial.print(", "); Serial.print(_pw_h); Serial.print(") P"); Serial.println(_current_page);
uint16_t page_ye = _current_page < (_pages - 1) ? page_ys + _page_height : HEIGHT;
uint16_t dest_ys = _pw_y + page_ys; // transposed
uint16_t dest_ye = gx_uint16_min(_pw_y + _pw_h, _pw_y + page_ye);
if (dest_ye > dest_ys)
{
//Serial.print("writeImage("); Serial.print(_pw_x); Serial.print(", "); Serial.print(dest_ys); Serial.print(", ");
//Serial.print(_pw_w); Serial.print(", "); Serial.print(dest_ye - dest_ys); Serial.println(")");
if (!_second_phase) epd2.writeImageNew(_black_buffer, _pw_x, dest_ys, _pw_w, dest_ye - dest_ys);
else epd2.writeImagePrevious(_black_buffer, _pw_x, dest_ys, _pw_w, dest_ye - dest_ys);
}
else
{
//Serial.print("writeImage("); Serial.print(_pw_x); Serial.print(", "); Serial.print(dest_ys); Serial.print(", ");
//Serial.print(_pw_w); Serial.print(", "); Serial.print(dest_ye - dest_ys); Serial.print(") skipped ");
//Serial.print(dest_ys); Serial.print(".."); Serial.println(dest_ye);
}
_current_page++;
if (_current_page == _pages)
{
_current_page = 0;
if (!_second_phase)
{
epd2.refresh_bw(_pw_x, _pw_y, _pw_w, _pw_h);
_second_phase = true;
fillScreen(GxEPD_WHITE);
return true;
}
return false;
}
fillScreen(GxEPD_WHITE);
return true;
}
else // full update
{
if (!_second_phase) epd2.writeImage(_black_buffer, 0, page_ys, GxEPD2_Type::WIDTH, gx_uint16_min(_page_height, HEIGHT - page_ys));
else epd2.writeImagePrevious(_black_buffer, 0, page_ys, GxEPD2_Type::WIDTH, gx_uint16_min(_page_height, HEIGHT - page_ys));
_current_page++;
if (_current_page == _pages)
{
_current_page = 0;
if (!_second_phase)
{
epd2.refresh(false); // full update after first phase
_second_phase = true;
fillScreen(GxEPD_WHITE);
return true;
}
epd2.powerOff();
return false;
}
fillScreen(GxEPD_WHITE);
return true;
}
}
// GxEPD style paged drawing; drawCallback() is called as many times as needed
void drawPaged(void (*drawCallback)(const void*), const void* pv)
{
if (_using_partial_mode)
{
for (_current_page = 0; _current_page < _pages; _current_page++)
{
uint16_t page_ys = _current_page * _page_height;
uint16_t page_ye = _current_page < (_pages - 1) ? page_ys + _page_height : HEIGHT;
uint16_t dest_ys = _pw_y + page_ys; // transposed
uint16_t dest_ye = gx_uint16_min(_pw_y + _pw_h, _pw_y + page_ye);
if (dest_ye > dest_ys)
{
fillScreen(GxEPD_WHITE);
drawCallback(pv);
epd2.writeImage(_black_buffer, _color_buffer, _pw_x, dest_ys, _pw_w, dest_ye - dest_ys);
}
}
epd2.refresh(_pw_x, _pw_y, _pw_w, _pw_h);
}
else // full update
{
epd2.setPaged(); // for GxEPD2_154c paged workaround
for (_current_page = 0; _current_page < _pages; _current_page++)
{
uint16_t page_ys = _current_page * _page_height;
fillScreen(GxEPD_WHITE);
drawCallback(pv);
epd2.writeImage(_black_buffer, _color_buffer, 0, page_ys, GxEPD2_Type::WIDTH, gx_uint16_min(_page_height, HEIGHT - page_ys));
}
if (epd2.panel == GxEPD2::GDEW0154Z04)
{ // GxEPD2_154c paged workaround: write color part
for (_current_page = 0; _current_page < _pages; _current_page++)
{
uint16_t page_ys = _current_page * _page_height;
fillScreen(GxEPD_WHITE);
drawCallback(pv);
epd2.writeImage(_black_buffer, _color_buffer, 0, page_ys, GxEPD2_Type::WIDTH, gx_uint16_min(_page_height, HEIGHT - page_ys));
}
}
epd2.refresh(false); // full update
epd2.powerOff();
}
_current_page = 0;
}
void drawInvertedBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color)
{
// taken from Adafruit_GFX.cpp, modified
int16_t byteWidth = (w + 7) / 8; // Bitmap scanline pad = whole byte
uint8_t byte = 0;
for (int16_t j = 0; j < h; j++)
{
for (int16_t i = 0; i < w; i++ )
{
if (i & 7) byte <<= 1;
else
{
#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
byte = pgm_read_byte(&bitmap[j * byteWidth + i / 8]);
#else
byte = bitmap[j * byteWidth + i / 8];
#endif
}
if (!(byte & 0x80))
{
drawPixel(x + i, y + j, color);
}
}
}
}
// Support for Bitmaps (Sprites) to Controller Buffer and to Screen
void clearScreen(uint8_t value = 0xFF) // init controller memory and screen (default white)
{
epd2.clearScreen(value);
}
void writeScreenBuffer(uint8_t value = 0xFF) // init controller memory (default white)
{
epd2.writeScreenBuffer(value);
}
// write to controller memory, without screen refresh; x and w should be multiple of 8
void writeImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false)
{
epd2.writeImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
}
void writeImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false)
{
epd2.writeImagePart(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
}
void writeImage(const uint8_t* black, const uint8_t* color, int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
epd2.writeImage(black, color, x, y, w, h, invert, mirror_y, pgm);
}
void writeImage(const uint8_t* black, const uint8_t* color, int16_t x, int16_t y, int16_t w, int16_t h)
{
epd2.writeImage(black, color, x, y, w, h, false, false, false);
}
void writeImagePart(const uint8_t* black, const uint8_t* color, int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
epd2.writeImagePart(black, color, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
}
void writeImagePart(const uint8_t* black, const uint8_t* color, int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h)
{
epd2.writeImagePart(black, color, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, false, false, false);
}
// write sprite of native data to controller memory, without screen refresh; x and w should be multiple of 8
void writeNative(const uint8_t* data1, const uint8_t* data2, int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
epd2.writeNative(data1, data2, x, y, w, h, invert, mirror_y, pgm);
}
// write to controller memory, with screen refresh; x and w should be multiple of 8
void drawImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false)
{
epd2.drawImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
}
void drawImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false)
{
epd2.drawImagePart(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
}
void drawImage(const uint8_t* black, const uint8_t* color, int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
epd2.drawImage(black, color, x, y, w, h, invert, mirror_y, pgm);
}
void drawImage(const uint8_t* black, const uint8_t* color, int16_t x, int16_t y, int16_t w, int16_t h)
{
epd2.drawImage(black, color, x, y, w, h, false, false, false);
}
void drawImagePart(const uint8_t* black, const uint8_t* color, int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
epd2.drawImagePart(black, color, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
}
void drawImagePart(const uint8_t* black, const uint8_t* color, int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h)
{
epd2.drawImagePart(black, color, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, false, false, false);
}
// write sprite of native data to controller memory, with screen refresh; x and w should be multiple of 8
void drawNative(const uint8_t* data1, const uint8_t* data2, int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
epd2.drawNative(data1, data2, x, y, w, h, invert, mirror_y, pgm);
}
void refresh(bool partial_update_mode = false) // screen refresh from controller memory to full screen
{
epd2.refresh(partial_update_mode);
if (!partial_update_mode) epd2.powerOff();
}
void refresh(int16_t x, int16_t y, int16_t w, int16_t h) // screen refresh from controller memory, partial screen
{
epd2.refresh(x, y, w, h);
}
// turns off generation of panel driving voltages, avoids screen fading over time
void powerOff()
{
epd2.powerOff();
}
// turns powerOff() and sets controller to deep sleep for minimum power use, ONLY if wakeable by RST (rst >= 0)
void hibernate()
{
epd2.hibernate();
}
private:
template <typename T> static inline void
_swap_(T & a, T & b)
{
T t = a;
a = b;
b = t;
};
static inline uint16_t gx_uint16_min(uint16_t a, uint16_t b)
{
return (a < b ? a : b);
};
static inline uint16_t gx_uint16_max(uint16_t a, uint16_t b)
{
return (a > b ? a : b);
};
void _rotate(uint16_t& x, uint16_t& y, uint16_t& w, uint16_t& h)
{
switch (getRotation())
{
case 1:
_swap_(x, y);
_swap_(w, h);
x = WIDTH - x - w;
break;
case 2:
x = WIDTH - x - w;
y = HEIGHT - y - h;
break;
case 3:
_swap_(x, y);
_swap_(w, h);
y = HEIGHT - y - h;
break;
}
}
private:
uint8_t _black_buffer[(GxEPD2_Type::WIDTH / 8) * page_height];
uint8_t _color_buffer[(GxEPD2_Type::WIDTH / 8) * page_height];
bool _using_partial_mode, _second_phase, _mirror;
uint16_t _width_bytes, _pixel_bytes;
int16_t _current_page;
uint16_t _pages, _page_height;
uint16_t _pw_x, _pw_y, _pw_w, _pw_h;
};
#endif