Paperd.Ink Library 0.0.5
Library for interacting with Paperd.Ink devices.
Loading...
Searching...
No Matches
GxEPD2_3C.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_3C_H_
13#define _GxEPD2_3C_H_
14// uncomment next line to use class GFX of library GFX_Root instead of Adafruit_GFX
15//#include <GFX.h>
16
17#ifndef ENABLE_GxEPD2_GFX
18// default is off
19#define ENABLE_GxEPD2_GFX 0
20#endif
21
22#if ENABLE_GxEPD2_GFX
23#include "GxEPD2_GFX.h"
24#define GxEPD2_GFX_BASE_CLASS GxEPD2_GFX
25#elif defined(_GFX_H_)
26#define GxEPD2_GFX_BASE_CLASS GFX
27#else
28#include <Adafruit_GFX.h>
29#define GxEPD2_GFX_BASE_CLASS Adafruit_GFX
30#endif
31
32#include "GxEPD2_EPD.h"
33#include "epd3c/GxEPD2_154c.h"
35#include "epd3c/GxEPD2_213c.h"
38#include "epd3c/GxEPD2_290c.h"
41#include "epd3c/GxEPD2_266c.h"
42#include "epd3c/GxEPD2_270c.h"
43#include "epd3c/GxEPD2_420c.h"
45#include "epd3c/GxEPD2_583c.h"
47#include "epd3c/GxEPD2_565c.h"
48#include "epd3c/GxEPD2_750c.h"
51#include "epd3c/GxEPD2_1248c.h"
52
53template<typename GxEPD2_Type, const uint16_t page_height>
54class GxEPD2_3C : public GxEPD2_GFX_BASE_CLASS
55{
56 public:
57 GxEPD2_Type epd2;
58#if ENABLE_GxEPD2_GFX
59 GxEPD2_3C(GxEPD2_Type epd2_instance) : GxEPD2_GFX_BASE_CLASS(epd2, GxEPD2_Type::WIDTH_VISIBLE, GxEPD2_Type::HEIGHT), epd2(epd2_instance)
60#else
61 GxEPD2_3C(GxEPD2_Type epd2_instance) : GxEPD2_GFX_BASE_CLASS(GxEPD2_Type::WIDTH_VISIBLE, GxEPD2_Type::HEIGHT), epd2(epd2_instance)
62#endif
63 {
64 _page_height = page_height;
65 _pages = (HEIGHT / _page_height) + ((HEIGHT % _page_height) > 0);
66 _mirror = false;
67 _using_partial_mode = false;
68 _current_page = 0;
70 }
71
72 uint16_t pages()
73 {
74 return _pages;
75 }
76
77 uint16_t pageHeight()
78 {
79 return _page_height;
80 }
81
82 bool mirror(bool m)
83 {
84 _swap_ (_mirror, m);
85 return m;
86 }
87
88 void drawPixel(int16_t x, int16_t y, uint16_t color)
89 {
90 if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) return;
91 if (_mirror) x = width() - x - 1;
92 // check rotation, move pixel around if necessary
93 switch (getRotation())
94 {
95 case 1:
96 _swap_(x, y);
97 x = WIDTH - x - 1;
98 break;
99 case 2:
100 x = WIDTH - x - 1;
101 y = HEIGHT - y - 1;
102 break;
103 case 3:
104 _swap_(x, y);
105 y = HEIGHT - y - 1;
106 break;
107 }
108 // transpose partial window to 0,0
109 x -= _pw_x;
110 y -= _pw_y;
111 // clip to (partial) window
112 if ((x < 0) || (x >= int16_t(_pw_w)) || (y < 0) || (y >= int16_t(_pw_h))) return;
113 // adjust for current page
114 y -= _current_page * _page_height;
115 // check if in current page
116 if ((y < 0) || (y >= int16_t(_page_height))) return;
117 uint16_t i = x / 8 + y * (_pw_w / 8);
118 _black_buffer[i] = (_black_buffer[i] | (1 << (7 - x % 8))); // white
119 _color_buffer[i] = (_color_buffer[i] | (1 << (7 - x % 8)));
120 if (color == GxEPD_WHITE) return;
121 else if (color == GxEPD_BLACK) _black_buffer[i] = (_black_buffer[i] & (0xFF ^ (1 << (7 - x % 8))));
122 else if ((color == GxEPD_RED) || (color == GxEPD_YELLOW)) _color_buffer[i] = (_color_buffer[i] & (0xFF ^ (1 << (7 - x % 8))));
123 }
124
125 void init(uint32_t serial_diag_bitrate = 0) // = 0 : disabled
126 {
127 epd2.init(serial_diag_bitrate);
128 _using_partial_mode = false;
129 _current_page = 0;
131 }
132
133 // init method with additional parameters:
134 // initial false for re-init after processor deep sleep wake up, if display power supply was kept
135 // only relevant for b/w displays with fast partial update
136 // reset_duration = 20 is default; a value of 2 may help with "clever" reset circuit of newer boards from Waveshare
137 // pulldown_rst_mode true for alternate RST handling to avoid feeding 5V through RST pin
138 void init(uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration = 20, bool pulldown_rst_mode = false)
139 {
140 epd2.init(serial_diag_bitrate, initial, reset_duration, pulldown_rst_mode);
141 _using_partial_mode = false;
142 _current_page = 0;
144 }
145
146 // init method with additional parameters:
147 // SPIClass& spi: either SPI or alternate HW SPI channel
148 // SPISettings spi_settings: e.g. for higher SPI speed selection
149 void init(uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration, bool pulldown_rst_mode, SPIClass& spi, SPISettings spi_settings)
150 {
151 epd2.selectSPI(spi, spi_settings);
152 epd2.init(serial_diag_bitrate, initial, reset_duration, pulldown_rst_mode);
153 _using_partial_mode = false;
154 _current_page = 0;
156 }
157
158 void fillScreen(uint16_t color) // 0x0 black, >0x0 white, to buffer
159 {
160 uint8_t black = 0xFF;
161 uint8_t red = 0xFF;
162 if (color == GxEPD_WHITE);
163 else if (color == GxEPD_BLACK) black = 0x00;
164 else if ((color == GxEPD_RED) || (color == GxEPD_YELLOW)) red = 0x00;
165 for (uint16_t x = 0; x < sizeof(_black_buffer); x++)
166 {
167 _black_buffer[x] = black;
168 _color_buffer[x] = red;
169 }
170 }
171
172 // display buffer content to screen, useful for full screen buffer
173 void display(bool partial_update_mode = false)
174 {
175 epd2.writeImage(_black_buffer, _color_buffer, 0, 0, GxEPD2_Type::WIDTH, _page_height);
176 epd2.refresh(partial_update_mode);
177 if (!partial_update_mode) epd2.powerOff();
178 }
179
180 // display part of buffer content to screen, useful for full screen buffer
181 // displayWindow, use parameters according to actual rotation.
182 // x and w should be multiple of 8, for rotation 0 or 2,
183 // y and h should be multiple of 8, for rotation 1 or 3,
184 // else window is increased as needed,
185 // this is an addressing limitation of the e-paper controllers
186 void displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
187 {
188 x = gx_uint16_min(x, width());
189 y = gx_uint16_min(y, height());
190 w = gx_uint16_min(w, width() - x);
191 h = gx_uint16_min(h, height() - y);
192 _rotate(x, y, w, h);
193 epd2.writeImagePart(_black_buffer, _color_buffer, x, y, GxEPD2_Type::WIDTH, _page_height, x, y, w, h);
194 epd2.refresh(x, y, w, h);
195 }
196
197 void displayWindowBW(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
198 {
199 x = gx_uint16_min(x, width());
200 y = gx_uint16_min(y, height());
201 w = gx_uint16_min(w, width() - x);
202 h = gx_uint16_min(h, height() - y);
203 _rotate(x, y, w, h);
204 epd2.writeImagePartNew(_black_buffer, x, y, GxEPD2_Type::WIDTH, _page_height, x, y, w, h);
205 epd2.refresh_bw(x, y, w, h);
206 epd2.writeImagePartPrevious(_black_buffer, x, y, GxEPD2_Type::WIDTH, _page_height, x, y, w, h);
207 }
208
210 {
211 _using_partial_mode = false;
212 _pw_x = 0;
213 _pw_y = 0;
214 _pw_w = GxEPD2_Type::WIDTH;
215 _pw_h = HEIGHT;
216 }
217
218 // setPartialWindow, use parameters according to actual rotation.
219 // x and w should be multiple of 8, for rotation 0 or 2,
220 // y and h should be multiple of 8, for rotation 1 or 3,
221 // else window is increased as needed,
222 // this is an addressing limitation of the e-paper controllers
223 void setPartialWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
224 {
225 if (!epd2.hasPartialUpdate) return;
226 _pw_x = gx_uint16_min(x, width());
227 _pw_y = gx_uint16_min(y, height());
228 _pw_w = gx_uint16_min(w, width() - _pw_x);
229 _pw_h = gx_uint16_min(h, height() - _pw_y);
230 _rotate(_pw_x, _pw_y, _pw_w, _pw_h);
231 _using_partial_mode = true;
232 // make _pw_x, _pw_w multiple of 8
233 _pw_w += _pw_x % 8;
234 if (_pw_w % 8 > 0) _pw_w += 8 - _pw_w % 8;
235 _pw_x -= _pw_x % 8;
236 }
237
239 {
241 _current_page = 0;
242 _second_phase = false;
243 epd2.setPaged(); // for GxEPD2_154c paged workaround
244 }
245
246 bool nextPage()
247 {
248 uint16_t page_ys = _current_page * _page_height;
249 if (_using_partial_mode)
250 {
251 //Serial.print(" nextPage("); Serial.print(_pw_x); Serial.print(", "); Serial.print(_pw_y); Serial.print(", ");
252 //Serial.print(_pw_w); Serial.print(", "); Serial.print(_pw_h); Serial.print(") P"); Serial.println(_current_page);
253 uint16_t page_ye = _current_page < int16_t(_pages - 1) ? page_ys + _page_height : HEIGHT;
254 uint16_t dest_ys = _pw_y + page_ys; // transposed
255 uint16_t dest_ye = gx_uint16_min(_pw_y + _pw_h, _pw_y + page_ye);
256 if (dest_ye > dest_ys)
257 {
258 //Serial.print("writeImage("); Serial.print(_pw_x); Serial.print(", "); Serial.print(dest_ys); Serial.print(", ");
259 //Serial.print(_pw_w); Serial.print(", "); Serial.print(dest_ye - dest_ys); Serial.println(")");
260 epd2.writeImage(_black_buffer, _color_buffer, _pw_x, dest_ys, _pw_w, dest_ye - dest_ys);
261 }
262 else
263 {
264 //Serial.print("writeImage("); Serial.print(_pw_x); Serial.print(", "); Serial.print(dest_ys); Serial.print(", ");
265 //Serial.print(_pw_w); Serial.print(", "); Serial.print(dest_ye - dest_ys); Serial.print(") skipped ");
266 //Serial.print(dest_ys); Serial.print(".."); Serial.println(dest_ye);
267 }
268 _current_page++;
269 if (_current_page == int16_t(_pages))
270 {
271 _current_page = 0;
272 if (!_second_phase)
273 {
274 epd2.refresh(_pw_x, _pw_y, _pw_w, _pw_h);
275 if (epd2.hasFastPartialUpdate)
276 {
277 _second_phase = true;
278 return true;
279 }
280 }
281 return false;
282 }
284 return true;
285 }
286 else // full update
287 {
288 epd2.writeImage(_black_buffer, _color_buffer, 0, page_ys, GxEPD2_Type::WIDTH, gx_uint16_min(_page_height, HEIGHT - page_ys));
289 _current_page++;
290 if (_current_page == int16_t(_pages))
291 {
292 _current_page = 0;
293 if ((epd2.panel == GxEPD2::GDEW0154Z04) && (_pages > 1))
294 {
295 if (!_second_phase)
296 {
297 epd2.refresh(false); // full update after first phase
298 _second_phase = true;
300 return true;
301 }
302 else epd2.refresh(true); // partial update after second phase
303 } else epd2.refresh(false); // full update after only phase
304 epd2.powerOff();
305 return false;
306 }
308 return true;
309 }
310 }
311
313 {
314 if (1 == _pages)
315 {
316 if (_using_partial_mode)
317 {
318 epd2.writeImageNew(_black_buffer, _pw_x, _pw_y, _pw_w, _pw_h);
319 epd2.refresh_bw(_pw_x, _pw_y, _pw_w, _pw_h);
320 epd2.writeImagePrevious(_black_buffer, _pw_x, _pw_y, _pw_w, _pw_h);
321 }
322 else // full update
323 {
324 epd2.writeImage(_black_buffer, 0, 0, GxEPD2_Type::WIDTH, HEIGHT);
325 epd2.refresh(false);
326 epd2.writeImagePrevious(_black_buffer, 0, 0, GxEPD2_Type::WIDTH, HEIGHT);
327 epd2.powerOff();
328 }
329 return false;
330 }
331 uint16_t page_ys = _current_page * _page_height;
332 if (_using_partial_mode)
333 {
334 //Serial.print(" nextPage("); Serial.print(_pw_x); Serial.print(", "); Serial.print(_pw_y); Serial.print(", ");
335 //Serial.print(_pw_w); Serial.print(", "); Serial.print(_pw_h); Serial.print(") P"); Serial.println(_current_page);
336 uint16_t page_ye = _current_page < (_pages - 1) ? page_ys + _page_height : HEIGHT;
337 uint16_t dest_ys = _pw_y + page_ys; // transposed
338 uint16_t dest_ye = gx_uint16_min(_pw_y + _pw_h, _pw_y + page_ye);
339 if (dest_ye > dest_ys)
340 {
341 //Serial.print("writeImage("); Serial.print(_pw_x); Serial.print(", "); Serial.print(dest_ys); Serial.print(", ");
342 //Serial.print(_pw_w); Serial.print(", "); Serial.print(dest_ye - dest_ys); Serial.println(")");
343 if (!_second_phase) epd2.writeImageNew(_black_buffer, _pw_x, dest_ys, _pw_w, dest_ye - dest_ys);
344 else epd2.writeImagePrevious(_black_buffer, _pw_x, dest_ys, _pw_w, dest_ye - dest_ys);
345 }
346 else
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.print(") skipped ");
350 //Serial.print(dest_ys); Serial.print(".."); Serial.println(dest_ye);
351 }
352 _current_page++;
353 if (_current_page == _pages)
354 {
355 _current_page = 0;
356 if (!_second_phase)
357 {
358 epd2.refresh_bw(_pw_x, _pw_y, _pw_w, _pw_h);
359 _second_phase = true;
361 return true;
362 }
363 return false;
364 }
366 return true;
367 }
368 else // full update
369 {
370 if (!_second_phase) epd2.writeImage(_black_buffer, 0, page_ys, GxEPD2_Type::WIDTH, gx_uint16_min(_page_height, HEIGHT - page_ys));
371 else epd2.writeImagePrevious(_black_buffer, 0, page_ys, GxEPD2_Type::WIDTH, gx_uint16_min(_page_height, HEIGHT - page_ys));
372 _current_page++;
373 if (_current_page == _pages)
374 {
375 _current_page = 0;
376 if (!_second_phase)
377 {
378 epd2.refresh(false); // full update after first phase
379 _second_phase = true;
381 return true;
382 }
383 epd2.powerOff();
384 return false;
385 }
387 return true;
388 }
389 }
390
391 // GxEPD style paged drawing; drawCallback() is called as many times as needed
392 void drawPaged(void (*drawCallback)(const void*), const void* pv)
393 {
394 if (_using_partial_mode)
395 {
396 for (_current_page = 0; _current_page < _pages; _current_page++)
397 {
398 uint16_t page_ys = _current_page * _page_height;
399 uint16_t page_ye = _current_page < (_pages - 1) ? page_ys + _page_height : HEIGHT;
400 uint16_t dest_ys = _pw_y + page_ys; // transposed
401 uint16_t dest_ye = gx_uint16_min(_pw_y + _pw_h, _pw_y + page_ye);
402 if (dest_ye > dest_ys)
403 {
405 drawCallback(pv);
406 epd2.writeImage(_black_buffer, _color_buffer, _pw_x, dest_ys, _pw_w, dest_ye - dest_ys);
407 }
408 }
409 epd2.refresh(_pw_x, _pw_y, _pw_w, _pw_h);
410 }
411 else // full update
412 {
413 epd2.setPaged(); // for GxEPD2_154c paged workaround
414 for (_current_page = 0; _current_page < _pages; _current_page++)
415 {
416 uint16_t page_ys = _current_page * _page_height;
418 drawCallback(pv);
419 epd2.writeImage(_black_buffer, _color_buffer, 0, page_ys, GxEPD2_Type::WIDTH, gx_uint16_min(_page_height, HEIGHT - page_ys));
420 }
421 if (epd2.panel == GxEPD2::GDEW0154Z04)
422 { // GxEPD2_154c paged workaround: write color part
423 for (_current_page = 0; _current_page < _pages; _current_page++)
424 {
425 uint16_t page_ys = _current_page * _page_height;
427 drawCallback(pv);
428 epd2.writeImage(_black_buffer, _color_buffer, 0, page_ys, GxEPD2_Type::WIDTH, gx_uint16_min(_page_height, HEIGHT - page_ys));
429 }
430 }
431 epd2.refresh(false); // full update
432 epd2.powerOff();
433 }
434 _current_page = 0;
435 }
436
437 void drawInvertedBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color)
438 {
439 // taken from Adafruit_GFX.cpp, modified
440 int16_t byteWidth = (w + 7) / 8; // Bitmap scanline pad = whole byte
441 uint8_t byte = 0;
442 for (int16_t j = 0; j < h; j++)
443 {
444 for (int16_t i = 0; i < w; i++ )
445 {
446 if (i & 7) byte <<= 1;
447 else
448 {
449#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
450 byte = pgm_read_byte(&bitmap[j * byteWidth + i / 8]);
451#else
452 byte = bitmap[j * byteWidth + i / 8];
453#endif
454 }
455 if (!(byte & 0x80))
456 {
457 drawPixel(x + i, y + j, color);
458 }
459 }
460 }
461 }
462
463 // Support for Bitmaps (Sprites) to Controller Buffer and to Screen
464 void clearScreen(uint8_t value = 0xFF) // init controller memory and screen (default white)
465 {
466 epd2.clearScreen(value);
467 }
468 void writeScreenBuffer(uint8_t value = 0xFF) // init controller memory (default white)
469 {
470 epd2.writeScreenBuffer(value);
471 }
472 // write to controller memory, without screen refresh; x and w should be multiple of 8
473 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)
474 {
475 epd2.writeImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
476 }
477 void writeImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
478 int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false)
479 {
480 epd2.writeImagePart(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
481 }
482 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)
483 {
484 epd2.writeImage(black, color, x, y, w, h, invert, mirror_y, pgm);
485 }
486 void writeImage(const uint8_t* black, const uint8_t* color, int16_t x, int16_t y, int16_t w, int16_t h)
487 {
488 epd2.writeImage(black, color, x, y, w, h, false, false, false);
489 }
490 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,
491 int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
492 {
493 epd2.writeImagePart(black, color, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
494 }
495 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,
496 int16_t x, int16_t y, int16_t w, int16_t h)
497 {
498 epd2.writeImagePart(black, color, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, false, false, false);
499 }
500 // write sprite of native data to controller memory, without screen refresh; x and w should be multiple of 8
501 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)
502 {
503 epd2.writeNative(data1, data2, x, y, w, h, invert, mirror_y, pgm);
504 }
505 // write to controller memory, with screen refresh; x and w should be multiple of 8
506 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)
507 {
508 epd2.drawImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
509 }
510 void drawImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
511 int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false)
512 {
513 epd2.drawImagePart(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
514 }
515 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)
516 {
517 epd2.drawImage(black, color, x, y, w, h, invert, mirror_y, pgm);
518 }
519 void drawImage(const uint8_t* black, const uint8_t* color, int16_t x, int16_t y, int16_t w, int16_t h)
520 {
521 epd2.drawImage(black, color, x, y, w, h, false, false, false);
522 }
523 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,
524 int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
525 {
526 epd2.drawImagePart(black, color, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
527 }
528 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,
529 int16_t x, int16_t y, int16_t w, int16_t h)
530 {
531 epd2.drawImagePart(black, color, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, false, false, false);
532 }
533 // write sprite of native data to controller memory, with screen refresh; x and w should be multiple of 8
534 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)
535 {
536 epd2.drawNative(data1, data2, x, y, w, h, invert, mirror_y, pgm);
537 }
538 void refresh(bool partial_update_mode = false) // screen refresh from controller memory to full screen
539 {
540 epd2.refresh(partial_update_mode);
541 if (!partial_update_mode) epd2.powerOff();
542 }
543 void refresh(int16_t x, int16_t y, int16_t w, int16_t h) // screen refresh from controller memory, partial screen
544 {
545 epd2.refresh(x, y, w, h);
546 }
547 // turns off generation of panel driving voltages, avoids screen fading over time
548 void powerOff()
549 {
550 epd2.powerOff();
551 }
552 // turns powerOff() and sets controller to deep sleep for minimum power use, ONLY if wakeable by RST (rst >= 0)
554 {
555 epd2.hibernate();
556 }
557 private:
558 template <typename T> static inline void
559 _swap_(T & a, T & b)
560 {
561 T t = a;
562 a = b;
563 b = t;
564 };
565 static inline uint16_t gx_uint16_min(uint16_t a, uint16_t b)
566 {
567 return (a < b ? a : b);
568 };
569 static inline uint16_t gx_uint16_max(uint16_t a, uint16_t b)
570 {
571 return (a > b ? a : b);
572 };
573 void _rotate(uint16_t& x, uint16_t& y, uint16_t& w, uint16_t& h)
574 {
575 switch (getRotation())
576 {
577 case 1:
578 _swap_(x, y);
579 _swap_(w, h);
580 x = WIDTH - x - w;
581 break;
582 case 2:
583 x = WIDTH - x - w;
584 y = HEIGHT - y - h;
585 break;
586 case 3:
587 _swap_(x, y);
588 _swap_(w, h);
589 y = HEIGHT - y - h;
590 break;
591 }
592 }
593 private:
594 uint8_t _black_buffer[(GxEPD2_Type::WIDTH / 8) * page_height];
595 uint8_t _color_buffer[(GxEPD2_Type::WIDTH / 8) * page_height];
596 bool _using_partial_mode, _second_phase, _mirror;
597 uint16_t _width_bytes, _pixel_bytes;
598 int16_t _current_page;
599 uint16_t _pages, _page_height;
600 uint16_t _pw_x, _pw_y, _pw_w, _pw_h;
601};
602
603#endif
#define GxEPD_RED
Definition GxEPD2.h:25
#define GxEPD_BLACK
Definition GxEPD2.h:19
#define GxEPD_YELLOW
Definition GxEPD2.h:26
#define GxEPD_WHITE
Definition GxEPD2.h:20
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_3C.h:506
void displayWindowBW(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
Definition GxEPD2_3C.h:197
void display(bool partial_update_mode=false)
Definition GxEPD2_3C.h:173
void init(uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration=20, bool pulldown_rst_mode=false)
Definition GxEPD2_3C.h:138
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_3C.h:501
void setPartialWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
Definition GxEPD2_3C.h:223
uint16_t pages()
Definition GxEPD2_3C.h:72
void refresh(int16_t x, int16_t y, int16_t w, int16_t h)
Definition GxEPD2_3C.h:543
uint16_t pageHeight()
Definition GxEPD2_3C.h:77
void init(uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration, bool pulldown_rst_mode, SPIClass &spi, SPISettings spi_settings)
Definition GxEPD2_3C.h:149
void hibernate()
Definition GxEPD2_3C.h:553
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_3C.h:473
void drawImage(const uint8_t *black, const uint8_t *color, int16_t x, int16_t y, int16_t w, int16_t h)
Definition GxEPD2_3C.h:519
void setFullWindow()
Definition GxEPD2_3C.h:209
void writeScreenBuffer(uint8_t value=0xFF)
Definition GxEPD2_3C.h:468
GxEPD2_3C(GxEPD2_Type epd2_instance)
Definition GxEPD2_3C.h:61
void clearScreen(uint8_t value=0xFF)
Definition GxEPD2_3C.h:464
void drawPixel(int16_t x, int16_t y, uint16_t color)
Definition GxEPD2_3C.h:88
GxEPD2_Type epd2
Definition GxEPD2_3C.h:57
bool nextPageBW()
Definition GxEPD2_3C.h:312
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_3C.h:528
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_3C.h:534
void drawInvertedBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color)
Definition GxEPD2_3C.h:437
void refresh(bool partial_update_mode=false)
Definition GxEPD2_3C.h:538
void powerOff()
Definition GxEPD2_3C.h:548
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_3C.h:490
void writeImage(const uint8_t *black, const uint8_t *color, int16_t x, int16_t y, int16_t w, int16_t h)
Definition GxEPD2_3C.h:486
void fillScreen(uint16_t color)
Definition GxEPD2_3C.h:158
void displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
Definition GxEPD2_3C.h:186
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_3C.h:482
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_3C.h:477
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_3C.h:510
bool nextPage()
Definition GxEPD2_3C.h:246
void firstPage()
Definition GxEPD2_3C.h:238
bool mirror(bool m)
Definition GxEPD2_3C.h:82
void init(uint32_t serial_diag_bitrate=0)
Definition GxEPD2_3C.h:125
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_3C.h:515
void drawPaged(void(*drawCallback)(const void *), const void *pv)
Definition GxEPD2_3C.h:392
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_3C.h:495
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_3C.h:523
@ GDEW0154Z04
Definition GxEPD2.h:80