Paperd.Ink Library 0.0.5
Library for interacting with Paperd.Ink devices.
Loading...
Searching...
No Matches
GxEPD2_583_T8.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: the e-paper panels require 3.3V supply AND data lines!
3//
4// based on Demo Example from Good Display:
5// Panel: GDEW0583T8 : http://www.e-paper-display.com/products_detail/productId=509.html
6// Controller: GD7965 : http://www.e-paper-display.com/download_detail/downloadsId=821.html
7//
8// Author: Jean-Marc Zingg
9//
10// Version: see library.properties
11//
12// Library: https://github.com/ZinggJM/GxEPD2
13
14#include "GxEPD2_583_T8.h"
15
16GxEPD2_583_T8::GxEPD2_583_T8(int16_t cs, int16_t dc, int16_t rst, int16_t busy) :
17 GxEPD2_EPD(cs, dc, rst, busy, LOW, 10000000, WIDTH, HEIGHT, panel, hasColor, hasPartialUpdate, hasFastPartialUpdate)
18{
19}
20
21void GxEPD2_583_T8::clearScreen(uint8_t value)
22{
23 writeScreenBuffer(value);
24 refresh(true);
25 writeScreenBuffer(value);
26}
27
29{
30 _initial_write = false; // initial full screen buffer clean done
31 if (!_using_partial_mode) _Init_Part();
32 _writeCommand(0x13); // set current
34 for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(HEIGHT) / 8; i++)
35 {
36 _transfer(value);
37 }
40 {
41 _writeCommand(0x10); // preset previous
43 for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(HEIGHT) / 8; i++)
44 {
45 _transfer(0xFF); // 0xFF is white
46 }
48 }
49}
50
51void GxEPD2_583_T8::writeImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
52{
53 if (_initial_write) writeScreenBuffer(); // initial full screen buffer clean
54 delay(1); // yield() to avoid WDT on ESP8266 and ESP32
55 uint16_t wb = (w + 7) / 8; // width bytes, bitmaps are padded
56 x -= x % 8; // byte boundary
57 w = wb * 8; // byte boundary
58 int16_t x1 = x < 0 ? 0 : x; // limit
59 int16_t y1 = y < 0 ? 0 : y; // limit
60 int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit
61 int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit
62 int16_t dx = x1 - x;
63 int16_t dy = y1 - y;
64 w1 -= dx;
65 h1 -= dy;
66 if ((w1 <= 0) || (h1 <= 0)) return;
67 if (!_using_partial_mode) _Init_Part();
68 _writeCommand(0x91); // partial in
69 _setPartialRamArea(x1, y1, w1, h1);
70 _writeCommand(0x13);
72 for (int16_t i = 0; i < h1; i++)
73 {
74 for (int16_t j = 0; j < w1 / 8; j++)
75 {
76 uint8_t data;
77 // use wb, h of bitmap for index!
78 uint16_t idx = mirror_y ? j + dx / 8 + uint16_t((h - 1 - (i + dy))) * wb : j + dx / 8 + uint16_t(i + dy) * wb;
79 if (pgm)
80 {
81#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
82 data = pgm_read_byte(&bitmap[idx]);
83#else
84 data = bitmap[idx];
85#endif
86 }
87 else
88 {
89 data = bitmap[idx];
90 }
91 if (invert) data = ~data;
92 _transfer(data);
93 }
94 }
96 _writeCommand(0x92); // partial out
97 delay(1); // yield() to avoid WDT on ESP8266 and ESP32
98}
99
100void GxEPD2_583_T8::writeImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
101 int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
102{
103 if (_initial_write) writeScreenBuffer(); // initial full screen buffer clean
104 delay(1); // yield() to avoid WDT on ESP8266 and ESP32
105 if ((w_bitmap < 0) || (h_bitmap < 0) || (w < 0) || (h < 0)) return;
106 if ((x_part < 0) || (x_part >= w_bitmap)) return;
107 if ((y_part < 0) || (y_part >= h_bitmap)) return;
108 uint16_t wb_bitmap = (w_bitmap + 7) / 8; // width bytes, bitmaps are padded
109 x_part -= x_part % 8; // byte boundary
110 w = w_bitmap - x_part < w ? w_bitmap - x_part : w; // limit
111 h = h_bitmap - y_part < h ? h_bitmap - y_part : h; // limit
112 x -= x % 8; // byte boundary
113 w = 8 * ((w + 7) / 8); // byte boundary, bitmaps are padded
114 int16_t x1 = x < 0 ? 0 : x; // limit
115 int16_t y1 = y < 0 ? 0 : y; // limit
116 int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit
117 int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit
118 int16_t dx = x1 - x;
119 int16_t dy = y1 - y;
120 w1 -= dx;
121 h1 -= dy;
122 if ((w1 <= 0) || (h1 <= 0)) return;
123 if (!_using_partial_mode) _Init_Part();
124 _writeCommand(0x91); // partial in
125 _setPartialRamArea(x1, y1, w1, h1);
126 _writeCommand(0x13);
128 for (int16_t i = 0; i < h1; i++)
129 {
130 for (int16_t j = 0; j < w1 / 8; j++)
131 {
132 uint8_t data;
133 // use wb_bitmap, h_bitmap of bitmap for index!
134 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;
135 if (pgm)
136 {
137#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
138 data = pgm_read_byte(&bitmap[idx]);
139#else
140 data = bitmap[idx];
141#endif
142 }
143 else
144 {
145 data = bitmap[idx];
146 }
147 if (invert) data = ~data;
148 _transfer(data);
149 }
150 }
151 _endTransfer();
152 _writeCommand(0x92); // partial out
153 delay(1); // yield() to avoid WDT on ESP8266 and ESP32
154}
155
156void GxEPD2_583_T8::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)
157{
158 if (black)
159 {
160 writeImage(black, x, y, w, h, invert, mirror_y, pgm);
161 }
162}
163
164void GxEPD2_583_T8::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,
165 int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
166{
167 if (black)
168 {
169 writeImagePart(black, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
170 }
171}
172
173void GxEPD2_583_T8::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)
174{
175 if (data1)
176 {
177 writeImage(data1, x, y, w, h, invert, mirror_y, pgm);
178 }
179}
180
181void GxEPD2_583_T8::drawImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
182{
183 writeImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
184 refresh(x, y, w, h);
185 writeImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
186}
187
188void GxEPD2_583_T8::drawImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
189 int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
190{
191 writeImagePart(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
192 refresh(x, y, w, h);
193 writeImagePart(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
194}
195
196void GxEPD2_583_T8::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)
197{
198 writeImage(black, color, x, y, w, h, invert, mirror_y, pgm);
199 refresh(x, y, w, h);
200 writeImage(black, color, x, y, w, h, invert, mirror_y, pgm);
201}
202
203void GxEPD2_583_T8::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,
204 int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
205{
206 writeImagePart(black, color, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
207 refresh(x, y, w, h);
208 writeImagePart(black, color, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
209}
210
211void GxEPD2_583_T8::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)
212{
213 writeNative(data1, data2, x, y, w, h, invert, mirror_y, pgm);
214 refresh(x, y, w, h);
215 writeNative(data1, data2, x, y, w, h, invert, mirror_y, pgm);
216}
217
218void GxEPD2_583_T8::refresh(bool partial_update_mode)
219{
220 if (partial_update_mode) refresh(0, 0, WIDTH, HEIGHT);
221 else
222 {
223 if (_using_partial_mode) _Init_Full();
224 _Update_Full();
225 _initial_refresh = false; // initial full update done
226 }
227}
228
229void GxEPD2_583_T8::refresh(int16_t x, int16_t y, int16_t w, int16_t h)
230{
231 if (_initial_refresh) return refresh(false); // initial update needs be full update
232 // intersection with screen
233 int16_t w1 = x < 0 ? w + x : w; // reduce
234 int16_t h1 = y < 0 ? h + y : h; // reduce
235 int16_t x1 = x < 0 ? 0 : x; // limit
236 int16_t y1 = y < 0 ? 0 : y; // limit
237 w1 = x1 + w1 < int16_t(WIDTH) ? w1 : int16_t(WIDTH) - x1; // limit
238 h1 = y1 + h1 < int16_t(HEIGHT) ? h1 : int16_t(HEIGHT) - y1; // limit
239 if ((w1 <= 0) || (h1 <= 0)) return;
240 // make x1, w1 multiple of 8
241 w1 += x1 % 8;
242 if (w1 % 8 > 0) w1 += 8 - w1 % 8;
243 x1 -= x1 % 8;
244 if (!_using_partial_mode) _Init_Part();
245 if (usePartialUpdateWindow) _writeCommand(0x91); // partial in
246 _setPartialRamArea(x1, y1, w1, h1);
247 _Update_Part();
248 if (usePartialUpdateWindow) _writeCommand(0x92); // partial out
249}
250
252{
253 _PowerOff();
254}
255
257{
258 _PowerOff();
259 if (_rst >= 0)
260 {
261 _writeCommand(0x07); // deep sleep
262 _writeData(0xA5); // check code
263 _hibernating = true;
264 }
265}
266
267void GxEPD2_583_T8::_setPartialRamArea(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
268{
269 uint16_t xe = (x + w - 1) | 0x0007; // byte boundary inclusive (last byte)
270 uint16_t ye = y + h - 1;
271 x &= 0xFFF8; // byte boundary
272 _writeCommand(0x90); // partial window
273 _writeData(x / 256);
274 _writeData(x % 256);
275 _writeData(xe / 256);
276 _writeData(xe % 256);
277 _writeData(y / 256);
278 _writeData(y % 256);
279 _writeData(ye / 256);
280 _writeData(ye % 256);
281 //_writeData(0x01); // don't see any difference
282 _writeData(0x00); // don't see any difference
283}
284
285void GxEPD2_583_T8::_PowerOn()
286{
287 if (!_power_is_on)
288 {
289 _writeCommand(0x04);
290 _waitWhileBusy("_PowerOn", power_on_time);
291 }
292 _power_is_on = true;
293}
294
295void GxEPD2_583_T8::_PowerOff()
296{
297 if (_power_is_on)
298 {
299 _writeCommand(0x02); // power off
300 _waitWhileBusy("_PowerOff", power_off_time);
301 }
302 _power_is_on = false;
303 _using_partial_mode = false;
304}
305
306void GxEPD2_583_T8::_InitDisplay()
307{
308 if (_hibernating) _reset();
309 _writeCommand(0x01); // POWER SETTING
310 _writeData (0x07);
311 _writeData (0x07); // VGH=20V,VGL=-20V
312 _writeData (0x3f); // VDH=15V
313 _writeData (0x3f); // VDL=-15V
314 _writeCommand(0x00); //PANEL SETTING
315 _writeData(0x1f); //KW: 3f, KWR: 2F, BWROTP: 0f, BWOTP: 1f
316 _writeCommand(0x61); //tres
317 _writeData (WIDTH / 256);
318 _writeData (WIDTH % 256);
319 _writeData (HEIGHT / 256);
320 _writeData (HEIGHT % 256);
321 _writeCommand(0x15);
322 _writeData(0x00);
323 _writeCommand(0x50); //VCOM AND DATA INTERVAL SETTING
324 _writeData(0x29); // LUTKW, N2OCP: copy new to old
325 _writeData(0x07);
326 _writeCommand(0x60); //TCON SETTING
327 _writeData(0x22);
328}
329
330// experimental partial screen update LUTs with balanced charge
331// LUTs are filled with zeroes
332
333#define T1 30 // charge balance pre-phase
334#define T2 5 // optional extension
335#define T3 30 // color change phase (b/w)
336#define T4 5 // optional extension for one color
337
338const unsigned char GxEPD2_583_T8::lut_20_LUTC_partial[] PROGMEM =
339{
340 0x00, T1, T2, T3, T4, 1, // 00 00 00 00
341};
342
343const unsigned char GxEPD2_583_T8::lut_21_LUTWW_partial[] PROGMEM =
344{ // 10 w
345 0x00, T1, T2, T3, T4, 1, // 00 00 00 00
346};
347
348const unsigned char GxEPD2_583_T8::lut_22_LUTKW_partial[] PROGMEM =
349{ // 10 w
350 //0x48, T1, T2, T3, T4, 1, // 01 00 10 00
351 0x5A, T1, T2, T3, T4, 1, // 01 01 10 10 more white
352};
353
354const unsigned char GxEPD2_583_T8::lut_23_LUTWK_partial[] PROGMEM =
355{ // 01 b
356 0x84, T1, T2, T3, T4, 1, // 10 00 01 00
357 //0xA5, T1, T2, T3, T4, 1, // 10 10 01 01 more black
358};
359
360const unsigned char GxEPD2_583_T8::lut_24_LUTKK_partial[] PROGMEM =
361{ // 01 b
362 0x00, T1, T2, T3, T4, 1, // 00 00 00 00
363};
364
365const unsigned char GxEPD2_583_T8::lut_25_LUTBD_partial[] PROGMEM =
366{
367 0x00, T1, T2, T3, T4, 1, // 00 00 00 00
368};
369
370void GxEPD2_583_T8::_Init_Full()
371{
372 _InitDisplay();
373 _writeCommand(0x00); // panel setting
374 _writeData(0x1f); // full update LUT from OTP
375 _PowerOn();
376 _using_partial_mode = false;
377}
378
379void GxEPD2_583_T8::_Init_Part()
380{
381 _InitDisplay();
382 _writeCommand(0x00); //panel setting
383 _writeData(hasFastPartialUpdate ? 0x3f : 0x1f); // partial update LUT from registers
384 _writeCommand(0x82); // vcom_DC setting
385 //_writeData (0x2C); // -2.3V same value as in OTP
386 _writeData (0x26); // -2.0V
387 //_writeData (0x1C); // -1.5V
388 _writeCommand(0x50); // VCOM AND DATA INTERVAL SETTING
389 _writeData(0x39); // LUTBD, N2OCP: copy new to old
390 _writeData(0x07);
391 _writeCommand(0x20);
392 _writeDataPGM(lut_20_LUTC_partial, sizeof(lut_20_LUTC_partial), 42 - sizeof(lut_20_LUTC_partial));
393 _writeCommand(0x21);
394 _writeDataPGM(lut_21_LUTWW_partial, sizeof(lut_21_LUTWW_partial), 42 - sizeof(lut_21_LUTWW_partial));
395 _writeCommand(0x22);
396 _writeDataPGM(lut_22_LUTKW_partial, sizeof(lut_22_LUTKW_partial), 42 - sizeof(lut_22_LUTKW_partial));
397 _writeCommand(0x23);
398 _writeDataPGM(lut_23_LUTWK_partial, sizeof(lut_23_LUTWK_partial), 42 - sizeof(lut_23_LUTWK_partial));
399 _writeCommand(0x24);
400 _writeDataPGM(lut_24_LUTKK_partial, sizeof(lut_24_LUTKK_partial), 42 - sizeof(lut_24_LUTKK_partial));
401 _writeCommand(0x25);
402 _writeDataPGM(lut_25_LUTBD_partial, sizeof(lut_25_LUTBD_partial), 42 - sizeof(lut_25_LUTBD_partial));
403 _PowerOn();
404 _using_partial_mode = true;
405}
406
407void GxEPD2_583_T8::_Update_Full()
408{
409 _writeCommand(0x12); //display refresh
410 _waitWhileBusy("_Update_Full", full_refresh_time);
411}
412
413void GxEPD2_583_T8::_Update_Part()
414{
415 _writeCommand(0x12); //display refresh
416 _waitWhileBusy("_Update_Part", partial_refresh_time);
417}
#define T2
#define T3
const unsigned char GxEPD2_583_T8::lut_20_LUTC_partial[] PROGMEM
#define T4
#define T1
static const uint16_t power_off_time
void writeScreenBuffer(uint8_t value=0xFF)
static const bool hasFastPartialUpdate
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 power_on_time
void clearScreen(uint8_t value=0xFF)
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)
static const uint16_t full_refresh_time
static const uint16_t partial_refresh_time
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)
GxEPD2_583_T8(int16_t cs, int16_t dc, int16_t rst, int16_t busy)
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)
static const uint16_t WIDTH
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 bool usePartialUpdateWindow
void refresh(bool partial_update_mode=false)
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 HEIGHT
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
bool _initial_refresh
Definition GxEPD2_EPD.h:117
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
void _writeDataPGM(const uint8_t *data, uint16_t n, int16_t fill_with_zeroes=0)