Paperd.Ink Library 0.0.5
Library for interacting with Paperd.Ink devices.
Loading...
Searching...
No Matches
GxEPD2_750c.cpp
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// Controller: IL0371 : http://www.e-paper-display.com/download_detail/downloadsId=536.html
6//
7// Author: Jean-Marc Zingg
8//
9// Version: see library.properties
10//
11// Library: https://github.com/ZinggJM/GxEPD2
12
13#include "GxEPD2_750c.h"
14
15GxEPD2_750c::GxEPD2_750c(int16_t cs, int16_t dc, int16_t rst, int16_t busy) :
16 GxEPD2_EPD(cs, dc, rst, busy, LOW, 40000000, WIDTH, HEIGHT, panel, hasColor, hasPartialUpdate, hasFastPartialUpdate)
17{
18}
19
20void GxEPD2_750c::clearScreen(uint8_t value)
21{
22 _initial_write = false; // initial full screen buffer clean done
23 if (value == 0xFF) value = 0x33; // white value for this controller
24 _Init_Part();
25 _writeCommand(0x91); // partial in
26 _setPartialRamArea(0, 0, WIDTH, HEIGHT);
27 _writeCommand(0x10);
29 for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(HEIGHT) / 2; i++)
30 {
31 _transfer(value);
32 }
34 _Update_Part();
35 _writeCommand(0x92); // partial out
36}
37
38void GxEPD2_750c::clearScreen(uint8_t black_value, uint8_t color_value)
39{
40 _initial_write = false; // initial full screen buffer clean done
41 _Init_Part();
42 _writeCommand(0x91); // partial in
43 _setPartialRamArea(0, 0, WIDTH, HEIGHT);
44 _writeCommand(0x10);
46 for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(HEIGHT) / 8; i++)
47 {
48 _send8pixel(~black_value, ~color_value);
49 }
51 _Update_Part();
52 _writeCommand(0x92); // partial out
53}
54
56{
57 _initial_write = false; // initial full screen buffer clean done
58 if (value == 0xFF) value = 0x33; // white value for this controller
59 _Init_Part();
60 _writeCommand(0x91); // partial in
61 _setPartialRamArea(0, 0, WIDTH, HEIGHT);
62 _writeCommand(0x10);
64 for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(HEIGHT) / 2; i++)
65 {
66 _transfer(value);
67 }
69 _writeCommand(0x92); // partial out
70}
71
72void GxEPD2_750c::writeScreenBuffer(uint8_t black_value, uint8_t color_value)
73{
74 _initial_write = false; // initial full screen buffer clean done
75 _Init_Part();
76 _writeCommand(0x91); // partial in
77 _setPartialRamArea(0, 0, WIDTH, HEIGHT);
78 _writeCommand(0x10);
80 for (uint32_t i = 0; uint32_t(WIDTH) * uint32_t(HEIGHT) / 8; i++)
81 {
82 _send8pixel(~black_value, ~color_value);
83 }
85 _writeCommand(0x92); // partial out
86}
87
88void GxEPD2_750c::writeImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
89{
90 writeImage(bitmap, NULL, x, y, w, h, invert, mirror_y, pgm);
91}
92
93void GxEPD2_750c::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)
94{
95 if (_initial_write) writeScreenBuffer(); // initial full screen buffer clean
96 delay(1); // yield() to avoid WDT on ESP8266 and ESP32
97 uint16_t wb = (w + 7) / 8; // width bytes, bitmaps are padded
98 x -= x % 8; // byte boundary
99 w = wb * 8; // byte boundary
100 int16_t x1 = x < 0 ? 0 : x; // limit
101 int16_t y1 = y < 0 ? 0 : y; // limit
102 int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit
103 int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit
104 int16_t dx = x1 - x;
105 int16_t dy = y1 - y;
106 w1 -= dx;
107 h1 -= dy;
108 if ((w1 <= 0) || (h1 <= 0)) return;
109 _Init_Part();
110 _writeCommand(0x91); // partial in
111 _setPartialRamArea(x1, y1, w1, h1);
112 _writeCommand(0x10);
114 for (int16_t i = 0; i < h1; i++)
115 {
116 for (int16_t j = 0; j < w1 / 8; j++)
117 {
118 uint8_t black_data = 0xFF;
119 uint8_t color_data = 0xFF;
120 if (black)
121 {
122 // use wb, h of bitmap for index!
123 uint16_t idx = mirror_y ? j + dx / 8 + uint16_t((h - 1 - (i + dy))) * wb : j + dx / 8 + uint16_t(i + dy) * wb;
124 if (pgm)
125 {
126#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
127 black_data = pgm_read_byte(&black[idx]);
128#else
129 black_data = black[idx];
130#endif
131 }
132 else
133 {
134 black_data = black[idx];
135 }
136 if (invert) black_data = ~black_data;
137 }
138 if (color)
139 {
140 // use wb, h of bitmap for index!
141 uint16_t idx = mirror_y ? j + dx / 8 + uint16_t((h - 1 - (i + dy))) * wb : j + dx / 8 + uint16_t(i + dy) * wb;
142 if (pgm)
143 {
144#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
145 color_data = pgm_read_byte(&color[idx]);
146#else
147 color_data = color[idx];
148#endif
149 }
150 else
151 {
152 color_data = color[idx];
153 }
154 if (invert) color_data = ~color_data;
155 }
156 _send8pixel(~black_data, ~color_data);
157 }
158 }
159 _endTransfer();
160 _writeCommand(0x92); // partial out
161 delay(1); // yield() to avoid WDT on ESP8266 and ESP32
162}
163
164void GxEPD2_750c::writeImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
165 int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
166{
167 writeImagePart(bitmap, NULL, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
168}
169
170void GxEPD2_750c::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,
171 int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
172{
173 if (_initial_write) writeScreenBuffer(); // initial full screen buffer clean
174 delay(1); // yield() to avoid WDT on ESP8266 and ESP32
175 if ((w_bitmap < 0) || (h_bitmap < 0) || (w < 0) || (h < 0)) return;
176 if ((x_part < 0) || (x_part >= w_bitmap)) return;
177 if ((y_part < 0) || (y_part >= h_bitmap)) return;
178 uint16_t wb_bitmap = (w_bitmap + 7) / 8; // width bytes, bitmaps are padded
179 x_part -= x_part % 8; // byte boundary
180 w = w_bitmap - x_part < w ? w_bitmap - x_part : w; // limit
181 h = h_bitmap - y_part < h ? h_bitmap - y_part : h; // limit
182 x -= x % 8; // byte boundary
183 w = 8 * ((w + 7) / 8); // byte boundary, bitmaps are padded
184 int16_t x1 = x < 0 ? 0 : x; // limit
185 int16_t y1 = y < 0 ? 0 : y; // limit
186 int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit
187 int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit
188 int16_t dx = x1 - x;
189 int16_t dy = y1 - y;
190 w1 -= dx;
191 h1 -= dy;
192 if ((w1 <= 0) || (h1 <= 0)) return;
193 if (!_using_partial_mode) _Init_Part();
194 _writeCommand(0x91); // partial in
195 _setPartialRamArea(x1, y1, w1, h1);
196 _writeCommand(0x10);
198 for (int16_t i = 0; i < h1; i++)
199 {
200 for (int16_t j = 0; j < w1 / 8; j++)
201 {
202 uint8_t black_data = 0xFF;
203 uint8_t color_data = 0xFF;
204 // use wb_bitmap, h_bitmap of bitmap for index!
205 uint16_t idx = mirror_y ? x_part / 8 + j + dx / 8 + uint16_t((h_bitmap - 1 - (y_part + i + dy))) * wb_bitmap : x_part / 8 + j + dx / 8 + uint16_t(y_part + i + dy) * wb_bitmap;
206 if (black)
207 {
208 if (pgm)
209 {
210#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
211 black_data = pgm_read_byte(&black[idx]);
212#else
213 black_data = black[idx];
214#endif
215 }
216 else
217 {
218 black_data = black[idx];
219 }
220 if (invert) black_data = ~black_data;
221 }
222 if (color)
223 {
224 if (pgm)
225 {
226#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
227 color_data = pgm_read_byte(&color[idx]);
228#else
229 color_data = color[idx];
230#endif
231 }
232 else
233 {
234 color_data = color[idx];
235 }
236 if (invert) color_data = ~color_data;
237 }
238 _send8pixel(~black_data, ~color_data);
239 }
240#if defined(ESP8266)
241 yield();
242#endif
243 }
244 _endTransfer();
245 _writeCommand(0x92); // partial out
246 delay(1); // yield() to avoid WDT on ESP8266 and ESP32
247}
248
249void GxEPD2_750c::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)
250{
251 if (data1)
252 {
253 if (_initial_write) writeScreenBuffer(); // initial full screen buffer clean
254 delay(1); // yield() to avoid WDT on ESP8266 and ESP32
255 uint16_t wb = (w + 1) / 2; // width bytes, bitmaps are padded
256 x -= x % 2; // byte boundary
257 w = wb * 2; // byte boundary
258 int16_t x1 = x < 0 ? 0 : x; // limit
259 int16_t y1 = y < 0 ? 0 : y; // limit
260 int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit
261 int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit
262 int16_t dx = x1 - x;
263 int16_t dy = y1 - y;
264 w1 -= dx;
265 h1 -= dy;
266 if ((w1 <= 0) || (h1 <= 0)) return;
267 _Init_Part();
268 _writeCommand(0x91); // partial in
269 _setPartialRamArea(x1, y1, w1, h1);
270 _writeCommand(0x10);
272 for (int16_t i = 0; i < h1; i++)
273 {
274 for (int16_t j = 0; j < w1 / 2; j++)
275 {
276 uint8_t data;
277 // use wb, h of bitmap for index!
278 uint16_t idx = mirror_y ? j + dx / 2 + uint16_t((h - 1 - (i + dy))) * wb : j + dx / 2 + uint16_t(i + dy) * wb;
279 if (pgm)
280 {
281#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
282 data = pgm_read_byte(&data1[idx]);
283#else
284 data = data1[idx];
285#endif
286 }
287 else
288 {
289 data = data1[idx];
290 }
291 if (invert) data = ~data;
292 _transfer(data);
293 }
294 }
295 _endTransfer();
296 _writeCommand(0x92); // partial out
297 delay(1); // yield() to avoid WDT on ESP8266 and ESP32
298 }
299}
300
301void GxEPD2_750c::drawImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
302{
303 writeImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
304 refresh(x, y, w, h);
305}
306
307void GxEPD2_750c::drawImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
308 int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
309{
310 writeImagePart(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
311 refresh(x, y, w, h);
312}
313
314void GxEPD2_750c::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)
315{
316 writeImage(black, color, x, y, w, h, invert, mirror_y, pgm);
317 refresh(x, y, w, h);
318}
319
320void GxEPD2_750c::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,
321 int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
322{
323 writeImagePart(black, color, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
324 refresh(x, y, w, h);
325}
326
327void GxEPD2_750c::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)
328{
329 writeNative(data1, data2, x, y, w, h, invert, mirror_y, pgm);
330 refresh(x, y, w, h);
331}
332
333void GxEPD2_750c::refresh(bool partial_update_mode)
334{
335 if (partial_update_mode) refresh(0, 0, WIDTH, HEIGHT);
336 else _Update_Full();
337}
338
339void GxEPD2_750c::refresh(int16_t x, int16_t y, int16_t w, int16_t h)
340{
341 // intersection with screen
342 int16_t w1 = x < 0 ? w + x : w; // reduce
343 int16_t h1 = y < 0 ? h + y : h; // reduce
344 int16_t x1 = x < 0 ? 0 : x; // limit
345 int16_t y1 = y < 0 ? 0 : y; // limit
346 w1 = x1 + w1 < int16_t(WIDTH) ? w1 : int16_t(WIDTH) - x1; // limit
347 h1 = y1 + h1 < int16_t(HEIGHT) ? h1 : int16_t(HEIGHT) - y1; // limit
348 if ((w1 <= 0) || (h1 <= 0)) return;
349 // make x1, w1 multiple of 8
350 w1 += x1 % 8;
351 if (w1 % 8 > 0) w1 += 8 - w1 % 8;
352 x1 -= x1 % 8;
353 _Init_Part();
354 _setPartialRamArea(x1, y1, w1, h1);
355 _Update_Part();
356}
357
359{
360 _PowerOff();
361}
362
364{
365 _PowerOff();
366 if (_rst >= 0)
367 {
368 // check if it supports this command!
369 _writeCommand(0x07); // deep sleep
370 _writeData(0xA5); // check code
371 _hibernating = true;
372 }
373}
374
375void GxEPD2_750c::_send8pixel(uint8_t black_data, uint8_t color_data)
376{
377 for (uint8_t j = 0; j < 8; j++)
378 {
379 uint8_t t = 0x00; // black
380 if (black_data & 0x80); // keep black
381 else if (color_data & 0x80) t = 0x04; //color
382 else t = 0x03; // white
383 t <<= 4;
384 black_data <<= 1;
385 color_data <<= 1;
386 j++;
387 if (black_data & 0x80); // keep black
388 else if (color_data & 0x80) t |= 0x04; //color
389 else t |= 0x03; // white
390 black_data <<= 1;
391 color_data <<= 1;
392 _transfer(t);
393 }
394}
395
396void GxEPD2_750c::_setPartialRamArea(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
397{
398 uint16_t xe = (x + w - 1) | 0x0007; // byte boundary inclusive (last byte)
399 uint16_t ye = y + h - 1;
400 x &= 0xFFF8; // byte boundary
401 xe |= 0x0007; // byte boundary
402 _writeCommand(0x90); // partial window
403 _writeData(x / 256);
404 _writeData(x % 256);
405 _writeData(xe / 256);
406 _writeData(xe % 256);
407 _writeData(y / 256);
408 _writeData(y % 256);
409 _writeData(ye / 256);
410 _writeData(ye % 256);
411 //_writeData(0x01); // distortion on full right half
412 _writeData(0x00); // distortion on right half
413}
414
415void GxEPD2_750c::_PowerOn()
416{
417 if (!_power_is_on)
418 {
419 _writeCommand(0x04);
420 _waitWhileBusy("_PowerOn", power_on_time);
421 }
422 _power_is_on = true;
423}
424
425void GxEPD2_750c::_PowerOff()
426{
427 _writeCommand(0x02); // power off
428 _waitWhileBusy("_PowerOff", power_off_time);
429 _power_is_on = false;
430}
431
432void GxEPD2_750c::_InitDisplay()
433{
434 if (_hibernating) _reset();
435 /**********************************release flash sleep**********************************/
436 _writeCommand(0X65); //FLASH CONTROL
437 _writeData(0x01);
438 _writeCommand(0xAB);
439 _writeCommand(0X65); //FLASH CONTROL
440 _writeData(0x00);
441 /**********************************release flash sleep**********************************/
442 _writeCommand(0x01);
443 _writeData (0x37); //POWER SETTING
444 _writeData (0x00);
445 //_writeCommand(0x04); //POWER ON
446 //_waitWhileBusy("PowerOn", power_on_time);
447 _writeCommand(0X00); //PANNEL SETTING
448 _writeData(0xCF);
449 _writeData(0x08);
450 _writeCommand(0x06); //boost
451 _writeData (0xc7);
452 _writeData (0xcc);
453 _writeData (0x28);
454 _writeCommand(0x30); //PLL setting
455 _writeData (0x3c);
456 _writeCommand(0X41); //TEMPERATURE SETTING
457 _writeData(0x00);
458 _writeCommand(0X50); //VCOM AND DATA INTERVAL SETTING
459 _writeData(0x77);
460 _writeCommand(0X60); //TCON SETTING
461 _writeData(0x22);
462 _writeCommand(0x61); //tres 640*384
463 _writeData (0x02); //source 640
464 _writeData (0x80);
465 _writeData (0x01); //gate 384
466 _writeData (0x80);
467 _writeCommand(0X82); //VDCS SETTING
468 _writeData(0x1E); //decide by LUT file
469 _writeCommand(0xe5); //FLASH MODE
470 _writeData(0x03);
471}
472
473void GxEPD2_750c::_Init_Full()
474{
475 _InitDisplay();
476 _PowerOn();
477}
478
479void GxEPD2_750c::_Init_Part()
480{
481 _InitDisplay();
482 _PowerOn();
483}
484
485void GxEPD2_750c::_Update_Full()
486{
487 _writeCommand(0x12); //display refresh
488 _waitWhileBusy("_Update_Full", full_refresh_time);
489}
490
491void GxEPD2_750c::_Update_Part()
492{
493 _writeCommand(0x12); //display refresh
494 _waitWhileBusy("_Update_Part", partial_refresh_time);
495}
void drawNative(const uint8_t *data1, const uint8_t *data2, int16_t x, int16_t y, int16_t w, int16_t h, bool invert=false, bool mirror_y=false, bool pgm=false)
void writeNative(const uint8_t *data1, const uint8_t *data2, int16_t x, int16_t y, int16_t w, int16_t h, bool invert=false, bool mirror_y=false, bool pgm=false)
static const uint16_t full_refresh_time
Definition GxEPD2_750c.h:31
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)
static const uint16_t partial_refresh_time
Definition GxEPD2_750c.h:32
static const uint16_t power_off_time
Definition GxEPD2_750c.h:30
static const uint16_t HEIGHT
Definition GxEPD2_750c.h:24
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)
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)
static const uint16_t power_on_time
Definition GxEPD2_750c.h:29
void writeScreenBuffer(uint8_t value=0x33)
GxEPD2_750c(int16_t cs, int16_t dc, int16_t rst, int16_t busy)
void clearScreen(uint8_t value=0x33)
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)
void refresh(bool partial_update_mode=false)
static const uint16_t WIDTH
Definition GxEPD2_750c.h:22
void _endTransfer()
void _writeCommand(uint8_t c)
void _writeData(uint8_t d)
bool _using_partial_mode
Definition GxEPD2_EPD.h:118
void _waitWhileBusy(const char *comment=0, uint16_t busy_time=5000)
bool _power_is_on
Definition GxEPD2_EPD.h:118
void _startTransfer()
void _transfer(uint8_t value)
void _reset()
bool _initial_write
Definition GxEPD2_EPD.h:117
int16_t _rst
Definition GxEPD2_EPD.h:112
bool _hibernating
Definition GxEPD2_EPD.h:118