Paperd.Ink Library 0.0.5
Library for interacting with Paperd.Ink devices.
Loading...
Searching...
No Matches
GxEPD2_BW.h
Go to the documentation of this file.
1// Display Library for SPI e-paper panels from Dalian Good Display and boards from Waveshare.
2// Requires HW SPI and Adafruit_GFX. Caution: these e-papers require 3.3V supply AND data lines!
3//
4// based on Demo Example from Good Display: http://www.e-paper-display.com/download_list/downloadcategoryid=34&isMode=false.html
5//
6// Author: Jean-Marc Zingg
7//
8// Version: see library.properties
9//
10// Library: https://github.com/ZinggJM/GxEPD2
11
12#ifndef _GxEPD2_BW_H_
13#define _GxEPD2_BW_H_
14
15// uncomment next line to use class GFX of library GFX_Root instead of Adafruit_GFX
16//#include <GFX.h>
17
18#ifndef ENABLE_GxEPD2_GFX
19// default is off
20#define ENABLE_GxEPD2_GFX 0
21#endif
22
23#if ENABLE_GxEPD2_GFX
24#include "GxEPD2_GFX.h"
25#define GxEPD2_GFX_BASE_CLASS GxEPD2_GFX
26#elif defined(_GFX_H_)
27#define GxEPD2_GFX_BASE_CLASS GFX
28#else
29#include <Adafruit_GFX.h>
30#define GxEPD2_GFX_BASE_CLASS Adafruit_GFX
31#endif
32
33#include "GxEPD2_EPD.h"
34#include "epd/GxEPD2_102.h"
35#include "epd/GxEPD2_150_BN.h"
36#include "epd/GxEPD2_154.h"
37#include "epd/GxEPD2_154_D67.h"
38#include "epd/GxEPD2_154_T8.h"
39#include "epd/GxEPD2_154_M09.h"
40#include "epd/GxEPD2_154_M10.h"
41#include "epd/GxEPD2_213.h"
42#include "epd/GxEPD2_213_B72.h"
43#include "epd/GxEPD2_213_B73.h"
44#include "epd/GxEPD2_213_B74.h"
45#include "epd/GxEPD2_213_flex.h"
46#include "epd/GxEPD2_213_M21.h"
47#include "epd/GxEPD2_213_T5D.h"
48#include "epd/GxEPD2_213_BN.h"
49#include "epd/GxEPD2_260.h"
50#include "epd/GxEPD2_266_BN.h"
51#include "epd/GxEPD2_260_M01.h"
52#include "epd/GxEPD2_290.h"
53#include "epd/GxEPD2_290_T5.h"
54#include "epd/GxEPD2_290_T5D.h"
55#include "epd/GxEPD2_290_I6FD.h"
56#include "epd/GxEPD2_290_M06.h"
57#include "epd/GxEPD2_290_T94.h"
59#include "epd/GxEPD2_290_BS.h"
60#include "epd/GxEPD2_270.h"
61#include "epd/GxEPD2_270_T91.h"
62#include "epd/GxEPD2_371.h"
63#include "epd/GxEPD2_370_TC1.h"
64#include "epd/GxEPD2_420.h"
65#include "epd/GxEPD2_420_M01.h"
66#include "epd/GxEPD2_583.h"
67#include "epd/GxEPD2_583_T8.h"
68#include "epd/GxEPD2_750.h"
69#include "epd/GxEPD2_750_T7.h"
70#include "epd/GxEPD2_1160_T91.h"
71#include "epd/GxEPD2_1248.h"
72#include "it8951/GxEPD2_it60.h"
76
77#ifndef GxEPD_BPP
78 #define GxEPD_BPP 1
79#endif
80
81template<typename GxEPD2_Type, const uint16_t page_height>
82class GxEPD2_BW : public GxEPD2_GFX_BASE_CLASS
83{
84 public:
85 GxEPD2_Type epd2;
86#if ENABLE_GxEPD2_GFX
87 GxEPD2_BW(GxEPD2_Type epd2_instance) : GxEPD2_GFX_BASE_CLASS(epd2, GxEPD2_Type::WIDTH, GxEPD2_Type::HEIGHT), epd2(epd2_instance)
88#else
89 GxEPD2_BW(GxEPD2_Type epd2_instance) : GxEPD2_GFX_BASE_CLASS(GxEPD2_Type::WIDTH, GxEPD2_Type::HEIGHT), epd2(epd2_instance)
90#endif
91 {
92 _page_height = page_height;
93 _pages = (HEIGHT / _page_height) + ((HEIGHT % _page_height) > 0);
94 _reverse = (epd2_instance.panel == GxEPD2::GDE0213B1);
95 _mirror = false;
96 _using_partial_mode = false;
97 _current_page = 0;
99 }
100
101 uint16_t pages()
102 {
103 return _pages;
104 }
105
106 uint16_t pageHeight()
107 {
108 return _page_height;
109 }
110
111 bool mirror(bool m)
112 {
113 _swap_ (_mirror, m);
114 return m;
115 }
116
117 void drawPixel(int16_t x, int16_t y, uint16_t color)
118 {
119 if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) return;
120 if (_mirror) x = width() - x - 1;
121 // check rotation, move pixel around if necessary
122 switch (getRotation())
123 {
124 case 1:
125 _swap_(x, y);
126 x = WIDTH - x - 1;
127 break;
128 case 2:
129 x = WIDTH - x - 1;
130 y = HEIGHT - y - 1;
131 break;
132 case 3:
133 _swap_(x, y);
134 y = HEIGHT - y - 1;
135 break;
136 }
137 // transpose partial window to 0,0
138 x -= _pw_x;
139 y -= _pw_y;
140 // clip to (partial) window
141 if ((x < 0) || (x >= int16_t(_pw_w)) || (y < 0) || (y >= int16_t(_pw_h))) return;
142 // adjust for current page
143 y -= _current_page * _page_height;
144 if (_reverse) y = _page_height - y - 1;
145 // check if in current page
146 if ((y < 0) || (y >= int16_t(_page_height))) return;
147 uint16_t i = x / 4 + y * (_pw_w / 4);
148 _buffer[i] = (_buffer[i] & (0xFF ^ (3 << 2 * (3 - x % 4))));
149 if (color > 0)
150 {
151 uint8_t brb = 0x03;
152 if (color != GxEPD_WHITE)
153 {
154 uint32_t brightness = (uint32_t(color & 0xF800) + uint32_t((color & 0x07E0) << 5) + uint32_t((color & 0x001F) << 11));
155 brb = uint8_t((brightness - 1) / 0xC000ul); // GxEPD_LIGHTGREY is one too high
156 }
157 _buffer[i] = (_buffer[i] | (brb << 2 * (3 - x % 4)));
158 }
159 }
160
161 void drawGreyPixel(int16_t x, int16_t y, uint8_t grey)
162 {
163 if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) return;
164 if (_mirror) x = width() - x - 1;
165 // check rotation, move pixel around if necessary
166 switch (getRotation())
167 {
168 case 1:
169 _swap_(x, y);
170 x = WIDTH - x - 1;
171 break;
172 case 2:
173 x = WIDTH - x - 1;
174 y = HEIGHT - y - 1;
175 break;
176 case 3:
177 _swap_(x, y);
178 y = HEIGHT - y - 1;
179 break;
180 }
181 // transpose partial window to 0,0
182 x -= _pw_x;
183 y -= _pw_y;
184 // clip to (partial) window
185 if ((x < 0) || (x >= _pw_w) || (y < 0) || (y >= _pw_h)) return;
186 // adjust for current page
187 y -= _current_page * _page_height;
188 // check if in current page
189 if ((y < 0) || (y >= _page_height)) return;
190 uint16_t i = x / 4 + y * (_pw_w / 4);
191 _buffer[i] = (_buffer[i] & (0xFF ^ (3 << 2 * (3 - x % 4))));
192 _buffer[i] = (_buffer[i] | ((grey >> 6) << 2 * (3 - x % 4)));
193 }
194
195 void init(uint32_t serial_diag_bitrate = 0) // = 0 : disabled
196 {
197 epd2.init(serial_diag_bitrate);
198 _using_partial_mode = false;
199 _current_page = 0;
201 }
202
203 // init method with additional parameters:
204 // initial false for re-init after processor deep sleep wake up, if display power supply was kept
205 // this can be used to avoid the repeated initial full refresh on displays with fast partial update
206 // NOTE: garbage will result on fast partial update displays, if initial full update is omitted after power loss
207 // reset_duration = 10 is default; a value of 2 may help with "clever" reset circuit of newer boards from Waveshare
208 // pulldown_rst_mode true for alternate RST handling to avoid feeding 5V through RST pin
209 void init(uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration = 10, bool pulldown_rst_mode = false)
210 {
211 epd2.init(serial_diag_bitrate, initial, reset_duration, pulldown_rst_mode);
212 _using_partial_mode = false;
213 _current_page = 0;
215 }
216
217 // init method with additional parameters:
218 // SPIClass& spi: either SPI or alternate HW SPI channel
219 // SPISettings spi_settings: e.g. for higher SPI speed selection
220 void init(uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration, bool pulldown_rst_mode, SPIClass& spi, SPISettings spi_settings)
221 {
222 epd2.selectSPI(spi, spi_settings);
223 epd2.init(serial_diag_bitrate, initial, reset_duration, pulldown_rst_mode);
224 _using_partial_mode = false;
225 _current_page = 0;
227 }
228
229 void fillScreen(uint16_t color) // 0x0 black, >0x0 white, to buffer
230 {
231 uint32_t brightness = (uint32_t(color & 0xF800) + uint32_t((color & 0x07E0) << 5) + uint32_t((color & 0x001F) << 11));
232 uint8_t brb = uint8_t((brightness - 1) / 0xC000ul); // GxEPD_LIGHTGREY is one too high
233 uint8_t data = brb * 0b01010101;
234 for (uint16_t x = 0; x < sizeof(_buffer); x++)
235 {
236 _buffer[x] = data;
237 }
238 }
239
240 // display buffer content to screen, useful for full screen buffer
241 void display(bool partial_update_mode = false)
242 {
243 if (partial_update_mode) epd2.writeImage(_buffer, 0, 0, WIDTH, _page_height);
244 else epd2.writeImageForFullRefresh(_buffer, 0, 0, WIDTH, _page_height);
245 epd2.refresh(partial_update_mode);
246 if (epd2.hasFastPartialUpdate)
247 {
248 epd2.writeImageAgain(_buffer, 0, 0, WIDTH, _page_height);
249 }
250 if (!partial_update_mode) epd2.powerOff();
251 }
252
253 // display part of buffer content to screen, useful for full screen buffer
254 // displayWindow, use parameters according to actual rotation.
255 // x and w should be multiple of 8, for rotation 0 or 2,
256 // y and h should be multiple of 8, for rotation 1 or 3,
257 // else window is increased as needed,
258 // this is an addressing limitation of the e-paper controllers
259 void displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
260 {
261 x = gx_uint16_min(x, width());
262 y = gx_uint16_min(y, height());
263 w = gx_uint16_min(w, width() - x);
264 h = gx_uint16_min(h, height() - y);
265 _rotate(x, y, w, h);
266 uint16_t y_part = _reverse ? HEIGHT - h - y : y;
267 epd2.writeImagePart(_buffer, x, y_part, WIDTH, _page_height, x, y, w, h);
268 epd2.refresh(x, y, w, h);
269 if (epd2.hasFastPartialUpdate)
270 {
271 epd2.writeImagePartAgain(_buffer, x, y_part, WIDTH, _page_height, x, y, w, h);
272 }
273 }
274
276 {
277 _using_partial_mode = false;
278 _pw_x = 0;
279 _pw_y = 0;
280 _pw_w = WIDTH;
281 _pw_h = HEIGHT;
282 }
283
284 // setPartialWindow, use parameters according to actual rotation.
285 // x and w should be multiple of 8, for rotation 0 or 2,
286 // y and h should be multiple of 8, for rotation 1 or 3,
287 // else window is increased as needed,
288 // this is an addressing limitation of the e-paper controllers
289 void setPartialWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
290 {
291 _pw_x = gx_uint16_min(x, width());
292 _pw_y = gx_uint16_min(y, height());
293 _pw_w = gx_uint16_min(w, width() - _pw_x);
294 _pw_h = gx_uint16_min(h, height() - _pw_y);
295 _rotate(_pw_x, _pw_y, _pw_w, _pw_h);
296 _using_partial_mode = true;
297 // make _pw_x, _pw_w multiple of 8
298 _pw_w += _pw_x % 8;
299 if (_pw_w % 8 > 0) _pw_w += 8 - _pw_w % 8;
300 _pw_x -= _pw_x % 8;
301 }
302
304 {
306 _current_page = 0;
307 _second_phase = false;
308 }
309
310 bool nextPage()
311 {
312 if (1 == _pages)
313 {
314 if (_using_partial_mode)
315 {
316 uint32_t offset = _reverse ? (HEIGHT - _pw_h) * _pw_w / 8 : 0;
317 epd2.writeImage(_buffer + offset, _pw_x, _pw_y, _pw_w, _pw_h);
318 epd2.refresh(_pw_x, _pw_y, _pw_w, _pw_h);
319 if (epd2.hasFastPartialUpdate)
320 {
321 epd2.writeImageAgain(_buffer + offset, _pw_x, _pw_y, _pw_w, _pw_h);
322 //epd2.refresh(_pw_x, _pw_y, _pw_w, _pw_h); // not needed
323 }
324 }
325 else // full update
326 {
327 epd2.writeImageForFullRefresh(_buffer, 0, 0, WIDTH, HEIGHT);
328 epd2.refresh(false);
329 if (epd2.hasFastPartialUpdate)
330 {
331 epd2.writeImageAgain(_buffer, 0, 0, WIDTH, HEIGHT);
332 //epd2.refresh(true); // not needed
333 }
334 epd2.powerOff();
335 }
336 return false;
337 }
338 uint16_t page_ys = _current_page * _page_height;
339 if (_using_partial_mode)
340 {
341 //Serial.print(" nextPage("); Serial.print(_pw_x); Serial.print(", "); Serial.print(_pw_y); Serial.print(", ");
342 //Serial.print(_pw_w); Serial.print(", "); Serial.print(_pw_h); Serial.print(") P"); Serial.println(_current_page);
343 uint16_t page_ye = _current_page < int16_t(_pages - 1) ? page_ys + _page_height : HEIGHT;
344 uint16_t dest_ys = _pw_y + page_ys; // transposed
345 uint16_t dest_ye = gx_uint16_min(_pw_y + _pw_h, _pw_y + page_ye);
346 if (dest_ye > dest_ys)
347 {
348 //Serial.print("writeImage("); Serial.print(_pw_x); Serial.print(", "); Serial.print(dest_ys); Serial.print(", ");
349 //Serial.print(_pw_w); Serial.print(", "); Serial.print(dest_ye - dest_ys); Serial.println(")");
350 uint32_t offset = _reverse ? (_page_height - (dest_ye - dest_ys)) * _pw_w / 8 : 0;
351 if (!_second_phase) epd2.writeImage(_buffer + offset, _pw_x, dest_ys, _pw_w, dest_ye - dest_ys);
352 else epd2.writeImageAgain(_buffer + offset, _pw_x, dest_ys, _pw_w, dest_ye - dest_ys);
353 }
354 else
355 {
356 //Serial.print("writeImage("); Serial.print(_pw_x); Serial.print(", "); Serial.print(dest_ys); Serial.print(", ");
357 //Serial.print(_pw_w); Serial.print(", "); Serial.print(dest_ye - dest_ys); Serial.print(") skipped ");
358 //Serial.print(dest_ys); Serial.print(".."); Serial.println(dest_ye);
359 }
360 _current_page++;
361 if (_current_page == int16_t(_pages))
362 {
363 _current_page = 0;
364 if (!_second_phase)
365 {
366 epd2.refresh(_pw_x, _pw_y, _pw_w, _pw_h);
367 if (epd2.hasFastPartialUpdate)
368 {
369 _second_phase = true;
371 return true;
372 }
373 }
374 return false;
375 }
377 return true;
378 }
379 else // full update
380 {
381 if (!_second_phase) epd2.writeImageForFullRefresh(_buffer, 0, page_ys, WIDTH, gx_uint16_min(_page_height, HEIGHT - page_ys));
382 else epd2.writeImageAgain(_buffer, 0, page_ys, WIDTH, gx_uint16_min(_page_height, HEIGHT - page_ys));
383 _current_page++;
384 if (_current_page == int16_t(_pages))
385 {
386 _current_page = 0;
387 if (epd2.hasFastPartialUpdate)
388 {
389 if (!_second_phase)
390 {
391 epd2.refresh(false); // full update after first phase
392 _second_phase = true;
394 return true;
395 }
396 //else epd2.refresh(true); // partial update after second phase
397 } else epd2.refresh(false); // full update after only phase
398 epd2.powerOff();
399 return false;
400 }
402 return true;
403 }
404 }
405
406 // GxEPD style paged drawing; drawCallback() is called as many times as needed
407 void drawPaged(void (*drawCallback)(const void*), const void* pv)
408 {
409 if (1 == _pages)
410 {
412 drawCallback(pv);
413 if (_using_partial_mode)
414 {
415 uint32_t offset = _reverse ? (HEIGHT - _pw_h) * _pw_w / 8 : 0;
416 epd2.writeImage(_buffer + offset, _pw_x, _pw_y, _pw_w, _pw_h);
417 epd2.refresh(_pw_x, _pw_y, _pw_w, _pw_h);
418 if (epd2.hasFastPartialUpdate)
419 {
420 epd2.writeImageAgain(_buffer + offset, _pw_x, _pw_y, _pw_w, _pw_h);
421 //epd2.refresh(_pw_x, _pw_y, _pw_w, _pw_h); // not needed
422 }
423 }
424 else // full update
425 {
426 epd2.writeImageForFullRefresh(_buffer, 0, 0, WIDTH, HEIGHT);
427 epd2.refresh(false);
428 if (epd2.hasFastPartialUpdate)
429 {
430 epd2.writeImageAgain(_buffer, 0, 0, WIDTH, HEIGHT);
431 //epd2.refresh(true); // not needed
432 epd2.powerOff();
433 }
434 }
435 return;
436 }
437 if (_using_partial_mode)
438 {
439 for (uint16_t phase = 1; phase <= 2; phase++)
440 {
441 for (_current_page = 0; _current_page < _pages; _current_page++)
442 {
443 uint16_t page_ys = _current_page * _page_height;
444 uint16_t page_ye = _current_page < (_pages - 1) ? page_ys + _page_height : HEIGHT;
445 uint16_t dest_ys = _pw_y + page_ys; // transposed
446 uint16_t dest_ye = gx_uint16_min(_pw_y + _pw_h, _pw_y + page_ye);
447 if (dest_ye > dest_ys)
448 {
450 drawCallback(pv);
451 uint32_t offset = _reverse ? (_page_height - (dest_ye - dest_ys)) * _pw_w / 8 : 0;
452 if (phase == 1) epd2.writeImage(_buffer + offset, _pw_x, dest_ys, _pw_w, dest_ye - dest_ys);
453 else epd2.writeImageAgain(_buffer + offset, _pw_x, dest_ys, _pw_w, dest_ye - dest_ys);
454 }
455 }
456 epd2.refresh(_pw_x, _pw_y, _pw_w, _pw_h);
457 if (!epd2.hasFastPartialUpdate) break;
458 // else make both controller buffers have equal content
459 }
460 }
461 else // full update
462 {
463 for (_current_page = 0; _current_page < _pages; _current_page++)
464 {
465 uint16_t page_ys = _current_page * _page_height;
467 drawCallback(pv);
468 epd2.writeImageForFullRefresh(_buffer, 0, page_ys, WIDTH, gx_uint16_min(_page_height, HEIGHT - page_ys));
469 }
470 epd2.refresh(false); // full update after first phase
471 if (epd2.hasFastPartialUpdate)
472 {
473 // make both controller buffers have equal content
474 for (_current_page = 0; _current_page < _pages; _current_page++)
475 {
476 uint16_t page_ys = _current_page * _page_height;
478 drawCallback(pv);
479 epd2.writeImageAgain(_buffer, 0, page_ys, WIDTH, gx_uint16_min(_page_height, HEIGHT - page_ys));
480 }
481 //epd2.refresh(true); // partial update after second phase // not needed
482 }
483 epd2.powerOff();
484 }
485 _current_page = 0;
486 }
487
488 void drawInvertedBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color)
489 {
490 // taken from Adafruit_GFX.cpp, modified
491 int16_t byteWidth = (w + 7) / 8; // Bitmap scanline pad = whole byte
492 uint8_t byte = 0;
493 for (int16_t j = 0; j < h; j++)
494 {
495 for (int16_t i = 0; i < w; i++ )
496 {
497 if (i & 7) byte <<= 1;
498 else
499 {
500#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
501 byte = pgm_read_byte(&bitmap[j * byteWidth + i / 8]);
502#else
503 byte = bitmap[j * byteWidth + i / 8];
504#endif
505 }
506 if (!(byte & 0x80))
507 {
508 drawPixel(x + i, y + j, color);
509 }
510 }
511 }
512 }
513
514 void drawGreyPixmap(const uint8_t pixmap[], int16_t depth, int16_t x, int16_t y, int16_t w, int16_t h)
515 {
516 switch (depth)
517 {
518 case 1:
519 {
520 int16_t byteWidth = (w + 7) / 8; // Bitmap scanline pad = whole byte
521 uint8_t byte = 0;
522 for (int16_t j = 0; j < h; j++)
523 {
524 for (int16_t i = 0; i < w; i++ )
525 {
526 if (i & 7) byte <<= 1;
527 else
528 {
529#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
530 byte = pgm_read_byte(&pixmap[j * byteWidth + i / 8]);
531#else
532 byte = pixmap[j * byteWidth + i / 8];
533#endif
534 }
535 uint16_t color = byte & 0x80 ? 0xFFFF : 0x0000;
536 drawPixel(x + i, y + j, color);
537 }
538 }
539 }
540 break;
541 case 2:
542 {
543 int16_t byteWidth = (w + 3) / 4; // Bitmap scanline pad = whole byte
544 uint8_t byte = 0;
545 for (int16_t j = 0; j < h; j++)
546 {
547 for (int16_t i = 0; i < w; i++ )
548 {
549 if (i & 3) byte <<= 2;
550 else
551 {
552#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
553 byte = pgm_read_byte(&pixmap[j * byteWidth + i / 4]);
554#else
555 byte = pixmap[j * byteWidth + i / 4];
556#endif
557 }
558 drawGreyPixel(x + i, y + j, byte & 0xC0);
559 }
560 }
561 }
562 break;
563 case 4:
564 {
565 int16_t byteWidth = (w + 1) / 2; // Bitmap scanline pad = whole byte
566 uint8_t byte = 0;
567 for (int16_t j = 0; j < h; j++)
568 {
569 for (int16_t i = 0; i < w; i++ )
570 {
571 if (i & 1) byte <<= 4;
572 else
573 {
574#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
575 byte = pgm_read_byte(&pixmap[j * byteWidth + i / 2]);
576#else
577 byte = pixmap[j * byteWidth + i / 2];
578#endif
579 }
580 uint8_t grey = byte & 0xF0;
581 if ((grey < 0xF0) && (grey >= 0xA0)) grey = 0x80; // light grey demo limit for 4bpp
582 else if ((grey < 0xF0) && (grey > 0x00)) grey = 0x40; // dark grey
583 drawGreyPixel(x + i, y + j, grey);
584 }
585 }
586 }
587 break;
588 case 8:
589 {
590 uint8_t byte = 0;
591 for (int16_t j = 0; j < h; j++)
592 {
593 for (int16_t i = 0; i < w; i++ )
594 {
595#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
596 byte = pgm_read_byte(&pixmap[j * w + i]);
597#else
598 byte = pixmap[j * w + i];
599#endif
600 drawGreyPixel(x + i, y + j, byte);
601 }
602 }
603 }
604 break;
605 }
606 }
607
608 // Support for Bitmaps (Sprites) to Controller Buffer and to Screen
609 void clearScreen(uint8_t value = 0xFF) // init controller memory and screen (default white)
610 {
611 epd2.clearScreen(value);
612 }
613 void writeScreenBuffer(uint8_t value = 0xFF) // init controller memory (default white)
614 {
615 epd2.writeScreenBuffer(value);
616 }
617 // write to controller memory, without screen refresh; x and w should be multiple of 8
618 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)
619 {
620 epd2.writeImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
621 }
622 void writeImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
623 int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false)
624 {
625 epd2.writeImagePart(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
626 }
627 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)
628 {
629 epd2.writeImage(black, color, x, y, w, h, invert, mirror_y, pgm);
630 }
631 void writeImage(const uint8_t* black, const uint8_t* color, int16_t x, int16_t y, int16_t w, int16_t h)
632 {
633 epd2.writeImage(black, color, x, y, w, h, false, false, false);
634 }
635 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,
636 int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
637 {
638 epd2.writeImagePart(black, color, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
639 }
640 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,
641 int16_t x, int16_t y, int16_t w, int16_t h)
642 {
643 epd2.writeImagePart(black, color, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, false, false, false);
644 }
645 // write sprite of native data to controller memory, without screen refresh; x and w should be multiple of 8
646 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)
647 {
648 epd2.writeNative(data1, data2, x, y, w, h, invert, mirror_y, pgm);
649 }
650 // write to controller memory, with screen refresh; x and w should be multiple of 8
651 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)
652 {
653 epd2.drawImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
654 }
655 void drawImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
656 int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false)
657 {
658 epd2.drawImagePart(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
659 }
660 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)
661 {
662 epd2.drawImage(black, color, x, y, w, h, invert, mirror_y, pgm);
663 }
664 void drawImage(const uint8_t* black, const uint8_t* color, int16_t x, int16_t y, int16_t w, int16_t h)
665 {
666 epd2.drawImage(black, color, x, y, w, h, false, false, false);
667 }
668 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,
669 int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
670 {
671 epd2.drawImagePart(black, color, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
672 }
673 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,
674 int16_t x, int16_t y, int16_t w, int16_t h)
675 {
676 epd2.drawImagePart(black, color, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, false, false, false);
677 }
678 // write sprite of native data to controller memory, with screen refresh; x and w should be multiple of 8
679 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)
680 {
681 epd2.drawNative(data1, data2, x, y, w, h, invert, mirror_y, pgm);
682 }
683 void refresh(bool partial_update_mode = false) // screen refresh from controller memory to full screen
684 {
685 epd2.refresh(partial_update_mode);
686 if (!partial_update_mode) epd2.powerOff();
687 }
688 void refresh(int16_t x, int16_t y, int16_t w, int16_t h) // screen refresh from controller memory, partial screen
689 {
690 epd2.refresh(x, y, w, h);
691 }
692 // turns off generation of panel driving voltages, avoids screen fading over time
693 void powerOff()
694 {
695 epd2.powerOff();
696 }
697 // turns powerOff() and sets controller to deep sleep for minimum power use, ONLY if wakeable by RST (rst >= 0)
699 {
700 epd2.hibernate();
701 }
702 private:
703 template <typename T> static inline void
704 _swap_(T & a, T & b)
705 {
706 T t = a;
707 a = b;
708 b = t;
709 };
710 static inline uint16_t gx_uint16_min(uint16_t a, uint16_t b)
711 {
712 return (a < b ? a : b);
713 };
714 static inline uint16_t gx_uint16_max(uint16_t a, uint16_t b)
715 {
716 return (a > b ? a : b);
717 };
718 void _rotate(uint16_t& x, uint16_t& y, uint16_t& w, uint16_t& h)
719 {
720 switch (getRotation())
721 {
722 case 1:
723 _swap_(x, y);
724 _swap_(w, h);
725 x = WIDTH - x - w;
726 break;
727 case 2:
728 x = WIDTH - x - w;
729 y = HEIGHT - y - h;
730 break;
731 case 3:
732 _swap_(x, y);
733 _swap_(w, h);
734 y = HEIGHT - y - h;
735 break;
736 }
737 }
738 private:
739 uint8_t _buffer[(GxEPD2_Type::WIDTH / (8/GxEPD_BPP)) * page_height];
740 bool _using_partial_mode, _second_phase, _mirror, _reverse;
741 uint16_t _width_bytes, _pixel_bytes;
742 int16_t _current_page;
743 uint16_t _pages, _page_height;
744 uint16_t _pw_x, _pw_y, _pw_w, _pw_h;
745};
746
747#endif
#define GxEPD_WHITE
Definition GxEPD2.h:20
#define GxEPD_BPP
Definition GxEPD2_420.h:18
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)
Definition GxEPD2_BW.h:640
bool mirror(bool m)
Definition GxEPD2_BW.h:111
void refresh(int16_t x, int16_t y, int16_t w, int16_t h)
Definition GxEPD2_BW.h:688
void powerOff()
Definition GxEPD2_BW.h:693
void init(uint32_t serial_diag_bitrate=0)
Definition GxEPD2_BW.h:195
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)
Definition GxEPD2_BW.h:679
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)
Definition GxEPD2_BW.h:635
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)
Definition GxEPD2_BW.h:622
void hibernate()
Definition GxEPD2_BW.h:698
GxEPD2_BW(GxEPD2_Type epd2_instance)
Definition GxEPD2_BW.h:89
void fillScreen(uint16_t color)
Definition GxEPD2_BW.h:229
void clearScreen(uint8_t value=0xFF)
Definition GxEPD2_BW.h:609
void init(uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration, bool pulldown_rst_mode, SPIClass &spi, SPISettings spi_settings)
Definition GxEPD2_BW.h:220
void drawGreyPixmap(const uint8_t pixmap[], int16_t depth, int16_t x, int16_t y, int16_t w, int16_t h)
Definition GxEPD2_BW.h:514
void drawPaged(void(*drawCallback)(const void *), const void *pv)
Definition GxEPD2_BW.h:407
void display(bool partial_update_mode=false)
Definition GxEPD2_BW.h:241
uint16_t pages()
Definition GxEPD2_BW.h:101
void init(uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration=10, bool pulldown_rst_mode=false)
Definition GxEPD2_BW.h:209
GxEPD2_Type epd2
Definition GxEPD2_BW.h:85
uint16_t pageHeight()
Definition GxEPD2_BW.h:106
void displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
Definition GxEPD2_BW.h:259
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)
Definition GxEPD2_BW.h:660
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)
Definition GxEPD2_BW.h:627
void setFullWindow()
Definition GxEPD2_BW.h:275
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)
Definition GxEPD2_BW.h:673
bool nextPage()
Definition GxEPD2_BW.h:310
void drawImage(const uint8_t *black, const uint8_t *color, int16_t x, int16_t y, int16_t w, int16_t h)
Definition GxEPD2_BW.h:664
void drawInvertedBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color)
Definition GxEPD2_BW.h:488
void drawPixel(int16_t x, int16_t y, uint16_t color)
Definition GxEPD2_BW.h:117
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)
Definition GxEPD2_BW.h:618
void writeImage(const uint8_t *black, const uint8_t *color, int16_t x, int16_t y, int16_t w, int16_t h)
Definition GxEPD2_BW.h:631
void writeScreenBuffer(uint8_t value=0xFF)
Definition GxEPD2_BW.h:613
void firstPage()
Definition GxEPD2_BW.h:303
void refresh(bool partial_update_mode=false)
Definition GxEPD2_BW.h:683
void drawGreyPixel(int16_t x, int16_t y, uint8_t grey)
Definition GxEPD2_BW.h:161
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)
Definition GxEPD2_BW.h:668
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)
Definition GxEPD2_BW.h:651
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)
Definition GxEPD2_BW.h:646
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)
Definition GxEPD2_BW.h:655
void setPartialWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
Definition GxEPD2_BW.h:289
@ GDE0213B1
Definition GxEPD2.h:45