Paperd.Ink Library 0.0.5
Library for interacting with Paperd.Ink devices.
Loading...
Searching...
No Matches
GxEPD2_750c_Z08.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: http://www.e-paper-display.com/download_detail/downloadsId=808.html
5// Panel: GDEW075Z08 : http://www.e-paper-display.com/products_detail/productId=457.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_750c_Z08.h"
15
16GxEPD2_750c_Z08::GxEPD2_750c_Z08(int16_t cs, int16_t dc, int16_t rst, int16_t busy) :
17 GxEPD2_EPD(cs, dc, rst, busy, LOW, 20000000, WIDTH, HEIGHT, panel, hasColor, hasPartialUpdate, hasFastPartialUpdate)
18{
19}
20
22{
23 clearScreen(value, 0xFF);
24}
25
26void GxEPD2_750c_Z08::clearScreen(uint8_t black_value, uint8_t color_value)
27{
28 _initial_write = false; // initial full screen buffer clean done
29 _Init_Part();
30 _writeCommand(0x91); // partial in
31 _setPartialRamArea(0, 0, WIDTH, HEIGHT);
32 _writeCommand(0x10);
34 for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(HEIGHT) / 8; i++)
35 {
36 _transfer(black_value);
37 }
39 _writeCommand(0x13);
41 for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(HEIGHT) / 8; i++)
42 {
43 _transfer(~color_value);
44 }
46 _Update_Part();
47 _writeCommand(0x92); // partial out
48}
49
51{
52 writeScreenBuffer(value, 0xFF);
53}
54
55void GxEPD2_750c_Z08::writeScreenBuffer(uint8_t black_value, uint8_t color_value)
56{
57 _initial_write = false; // initial full screen buffer clean done
58 _Init_Part();
59 _writeCommand(0x91); // partial in
60 _setPartialRamArea(0, 0, WIDTH, HEIGHT);
61 _writeCommand(0x10);
63 for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(HEIGHT) / 8; i++)
64 {
65 _transfer(black_value);
66 }
68 _writeCommand(0x13);
70 for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(HEIGHT) / 8; i++)
71 {
72 _transfer(~color_value);
73 }
75 _writeCommand(0x92); // partial out
76}
77
78void GxEPD2_750c_Z08::writeImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
79{
80 writeImage(bitmap, NULL, x, y, w, h, invert, mirror_y, pgm);
81}
82
83void GxEPD2_750c_Z08::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)
84{
85 if (_initial_write) writeScreenBuffer(); // initial full screen buffer clean
86 delay(1); // yield() to avoid WDT on ESP8266 and ESP32
87 uint16_t wb = (w + 7) / 8; // width bytes, bitmaps are padded
88 x -= x % 8; // byte boundary
89 w = wb * 8; // byte boundary
90 int16_t x1 = x < 0 ? 0 : x; // limit
91 int16_t y1 = y < 0 ? 0 : y; // limit
92 int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit
93 int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit
94 int16_t dx = x1 - x;
95 int16_t dy = y1 - y;
96 w1 -= dx;
97 h1 -= dy;
98 if ((w1 <= 0) || (h1 <= 0)) return;
99 _Init_Part();
100 _writeCommand(0x91); // partial in
101 _setPartialRamArea(x1, y1, w1, h1);
102 _writeCommand(0x10);
104 for (int16_t i = 0; i < h1; i++)
105 {
106 for (int16_t j = 0; j < w1 / 8; j++)
107 {
108 uint8_t data = 0xFF;
109 if (black)
110 {
111 // use wb, h of bitmap for index!
112 uint16_t idx = mirror_y ? j + dx / 8 + uint16_t((h - 1 - (i + dy))) * wb : j + dx / 8 + uint16_t(i + dy) * wb;
113 if (pgm)
114 {
115#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
116 data = pgm_read_byte(&black[idx]);
117#else
118 data = black[idx];
119#endif
120 }
121 else
122 {
123 data = black[idx];
124 }
125 if (invert) data = ~data;
126 }
127 _transfer(data);
128 }
129 }
130 _endTransfer();
131 _writeCommand(0x13);
133 for (int16_t i = 0; i < h1; i++)
134 {
135 for (int16_t j = 0; j < w1 / 8; j++)
136 {
137 uint8_t data = 0xFF;
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 data = pgm_read_byte(&color[idx]);
146#else
147 data = color[idx];
148#endif
149 }
150 else
151 {
152 data = color[idx];
153 }
154 if (invert) data = ~data;
155 }
156 _transfer(~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_Z08::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_Z08::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 data;
203 // use wb_bitmap, h_bitmap of bitmap for index!
204 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;
205 if (pgm)
206 {
207#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
208 data = pgm_read_byte(&black[idx]);
209#else
210 data = black[idx];
211#endif
212 }
213 else
214 {
215 data = black[idx];
216 }
217 if (invert) data = ~data;
218 _transfer(data);
219 }
220 }
221 _endTransfer();
222 _writeCommand(0x13);
224 for (int16_t i = 0; i < h1; i++)
225 {
226 for (int16_t j = 0; j < w1 / 8; j++)
227 {
228 uint8_t data = 0xFF;
229 if (color)
230 {
231 // use wb_bitmap, h_bitmap of bitmap for index!
232 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;
233 if (pgm)
234 {
235#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
236 data = pgm_read_byte(&color[idx]);
237#else
238 data = color[idx];
239#endif
240 }
241 else
242 {
243 data = color[idx];
244 }
245 if (invert) data = ~data;
246 }
247 _transfer(~data);
248 }
249 }
250 _endTransfer();
251 _writeCommand(0x92); // partial out
252 delay(1); // yield() to avoid WDT on ESP8266 and ESP32
253}
254
255void GxEPD2_750c_Z08::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)
256{
257 if (data1)
258 {
259 writeImage(data1, x, y, w, h, invert, mirror_y, pgm);
260 }
261}
262
263void GxEPD2_750c_Z08::drawImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
264{
265 writeImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
266 refresh(x, y, w, h);
267}
268
269void GxEPD2_750c_Z08::drawImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
270 int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
271{
272 writeImagePart(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
273 refresh(x, y, w, h);
274}
275
276void GxEPD2_750c_Z08::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)
277{
278 writeImage(black, color, x, y, w, h, invert, mirror_y, pgm);
279 refresh(x, y, w, h);
280}
281
282void GxEPD2_750c_Z08::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,
283 int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
284{
285 writeImagePart(black, color, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
286 refresh(x, y, w, h);
287}
288
289void GxEPD2_750c_Z08::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)
290{
291 writeNative(data1, data2, x, y, w, h, invert, mirror_y, pgm);
292 refresh(x, y, w, h);
293}
294
295void GxEPD2_750c_Z08::refresh(bool partial_update_mode)
296{
297 if (partial_update_mode) refresh(0, 0, WIDTH, HEIGHT);
298 else _Update_Full();
299}
300
301void GxEPD2_750c_Z08::refresh(int16_t x, int16_t y, int16_t w, int16_t h)
302{
303 // intersection with screen
304 int16_t w1 = x < 0 ? w + x : w; // reduce
305 int16_t h1 = y < 0 ? h + y : h; // reduce
306 int16_t x1 = x < 0 ? 0 : x; // limit
307 int16_t y1 = y < 0 ? 0 : y; // limit
308 w1 = x1 + w1 < int16_t(WIDTH) ? w1 : int16_t(WIDTH) - x1; // limit
309 h1 = y1 + h1 < int16_t(HEIGHT) ? h1 : int16_t(HEIGHT) - y1; // limit
310 if ((w1 <= 0) || (h1 <= 0)) return;
311 // make x1, w1 multiple of 8
312 w1 += x1 % 8;
313 if (w1 % 8 > 0) w1 += 8 - w1 % 8;
314 x1 -= x1 % 8;
315 _Init_Part();
316 if (usePartialUpdate) _writeCommand(0x91); // partial in
317 _setPartialRamArea(x1, y1, w1, h1);
318 _Update_Part();
319 if (usePartialUpdate) _writeCommand(0x92); // partial out
320}
321
323{
324 _PowerOff();
325}
326
328{
329 _PowerOff();
330 if (_rst >= 0)
331 {
332 _writeCommand(0x07); // deep sleep
333 _writeData(0xA5); // check code
334 _hibernating = true;
335 }
336}
337
338void GxEPD2_750c_Z08::_setPartialRamArea(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
339{
340 uint16_t xe = (x + w - 1) | 0x0007; // byte boundary inclusive (last byte)
341 uint16_t ye = y + h - 1;
342 x &= 0xFFF8; // byte boundary
343 xe |= 0x0007; // byte boundary
344 _writeCommand(0x90); // partial window
345 _writeData(x / 256);
346 _writeData(x % 256);
347 _writeData(xe / 256);
348 _writeData(xe % 256);
349 _writeData(y / 256);
350 _writeData(y % 256);
351 _writeData(ye / 256);
352 _writeData(ye % 256);
353 _writeData(0x00);
354}
355
356void GxEPD2_750c_Z08::_PowerOn()
357{
358 if (!_power_is_on)
359 {
360 _writeCommand(0x04);
361 _waitWhileBusy("_PowerOn", power_on_time);
362 }
363 _power_is_on = true;
364}
365
366void GxEPD2_750c_Z08::_PowerOff()
367{
368 _writeCommand(0x02); // power off
369 _waitWhileBusy("_PowerOff", power_off_time);
370 _power_is_on = false;
371}
372
373void GxEPD2_750c_Z08::_InitDisplay()
374{
375 if (_hibernating) _reset();
376 _writeCommand(0x01); // POWER SETTING
377 _writeData (0x07);
378 _writeData (0x07); // VGH=20V,VGL=-20V
379 _writeData (0x3f); // VDH=15V
380 _writeData (0x3f); // VDL=-15V
381 _writeCommand(0x00); //PANEL SETTING
382 _writeData(0x0f); //KW: 3f, KWR: 2F, BWROTP: 0f, BWOTP: 1f
383 _writeCommand(0x61); //tres
384 _writeData (WIDTH / 256); //source 800
385 _writeData (WIDTH % 256);
386 _writeData (HEIGHT / 256); //gate 480
387 _writeData (HEIGHT % 256);
388 _writeCommand(0x15);
389 _writeData(0x00);
390 _writeCommand(0x50); //VCOM AND DATA INTERVAL SETTING
391 _writeData(0x11);
392 _writeData(0x07);
393 _writeCommand(0x60); //TCON SETTING
394 _writeData(0x22);
395}
396
397void GxEPD2_750c_Z08::_Init_Full()
398{
399 _InitDisplay();
400 _PowerOn();
401}
402
403void GxEPD2_750c_Z08::_Init_Part()
404{
405 _InitDisplay();
406 _PowerOn();
407}
408
409void GxEPD2_750c_Z08::_Update_Full()
410{
411 _writeCommand(0x12); //display refresh
412 _waitWhileBusy("_Update_Full", full_refresh_time);
413}
414
415void GxEPD2_750c_Z08::_Update_Part()
416{
417 _writeCommand(0x12); //display refresh
418 _waitWhileBusy("_Update_Part", partial_refresh_time);
419}
static const uint16_t partial_refresh_time
void writeScreenBuffer(uint8_t value=0xFF)
static const uint16_t WIDTH
static const uint16_t HEIGHT
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)
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 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 full_refresh_time
static const uint16_t power_off_time
void refresh(bool partial_update_mode=false)
GxEPD2_750c_Z08(int16_t cs, int16_t dc, int16_t rst, int16_t busy)
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 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)
void clearScreen(uint8_t value=0xFF)
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 bool usePartialUpdate
static const uint16_t power_on_time
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