Skip to content

Commit 09c3e97

Browse files
committed
work in progress
1 parent ec30a0d commit 09c3e97

File tree

6 files changed

+297
-41
lines changed

6 files changed

+297
-41
lines changed

src/Adafruit_EPD.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,20 +281,33 @@ void Adafruit_EPD::drawPixel(int16_t x, int16_t y, uint16_t color) {
281281
}
282282
}
283283

284-
void Adafruit_EPD::writeRAMFramebufferToEPD(uint8_t *buffer, uint32_t buffer_size,
285-
uint8_t EPDlocation) {
284+
void Adafruit_EPD::writeRAMFramebufferToEPD(uint8_t *framebuffer, uint32_t framebuffer_size,
285+
uint8_t EPDlocation, bool invertdata) {
286286
// write image
287287
writeRAMCommand(EPDlocation);
288288
dcHigh();
289-
for (uint16_t i = 0; i < buffer1_size; i++) {
290-
SPItransfer(buffer[i]);
289+
//Serial.printf("Writing from RAM location %04x: \n", &framebuffer);
290+
291+
for (uint16_t i = 0; i < framebuffer_size; i++) {
292+
uint8_t d = framebuffer[i];
293+
if (invertdata)
294+
d = ~d;
295+
296+
/*
297+
Serial.printf("%02x", d);
298+
if ((i+1) % (WIDTH/8) == 0)
299+
Serial.println();
300+
*/
301+
302+
SPItransfer(d);
291303
}
304+
// Serial.println();
292305
csHigh();
293306
return;
294307
}
295308

296309
void Adafruit_EPD::writeSRAMFramebufferToEPD(uint16_t SRAM_buffer_addr, uint32_t buffer_size,
297-
uint8_t EPDlocation) {
310+
uint8_t EPDlocation, bool invertdata) {
298311
uint8_t c;
299312

300313
// use SRAM
@@ -366,6 +379,7 @@ void Adafruit_EPD::display(bool sleep) {
366379
Serial.println(" Update");
367380
#endif
368381
update();
382+
partialsSinceLastFullUpdate = 0;
369383

370384
if (sleep) {
371385
#ifdef EPD_DEBUG

src/Adafruit_EPD.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ enum {
4343
EPD_NUM_COLORS
4444
};
4545

46+
typedef enum {
47+
THINKINK_MONO,
48+
THINKINK_TRICOLOR,
49+
THINKINK_GRAYSCALE4,
50+
THINKINK_MONO_PARTIAL,
51+
} thinkinkmode_t;
52+
4653
#define EPD_swap(a, b) \
4754
{ \
4855
int16_t t = a; \
@@ -72,11 +79,13 @@ class Adafruit_EPD : public Adafruit_GFX {
7279
void setColorBuffer(int8_t index, bool inverted);
7380
void display(bool sleep = false);
7481

82+
thinkinkmode_t getMode(void) { return inkmode; }
83+
7584
protected:
76-
void writeRAMFramebufferToEPD(uint8_t *buffer,
77-
uint32_t buffer_size, uint8_t EPDlocation);
78-
void writeSRAMFramebufferToEPD(uint16_t SRAM_buffer_addr,
79-
uint32_t buffer_size, uint8_t EPDlocation);
85+
void writeRAMFramebufferToEPD(uint8_t *buffer, uint32_t buffer_size,
86+
uint8_t EPDlocation, bool invertdata=false);
87+
void writeSRAMFramebufferToEPD(uint16_t SRAM_buffer_addr, uint32_t buffer_size,
88+
uint8_t EPDlocation, bool invertdata=false);
8089

8190
/**************************************************************************/
8291
/*!
@@ -169,6 +178,10 @@ class Adafruit_EPD : public Adafruit_GFX {
169178

170179
bool use_sram; ///< true if we are using an SRAM chip as a framebuffer
171180

181+
thinkinkmode_t inkmode; // Ink mode passed to begin()
182+
183+
uint8_t partialsSinceLastFullUpdate = 0;
184+
172185
#if defined(BUSIO_USE_FAST_PINIO)
173186
BusIO_PortReg *csPort, *dcPort;
174187
BusIO_PortMask csPinMask, dcPinMask;

src/Adafruit_ThinkInk.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33

44
#include "Adafruit_EPD.h"
55

6-
typedef enum {
7-
THINKINK_MONO,
8-
THINKINK_TRICOLOR,
9-
THINKINK_GRAYSCALE4,
10-
} thinkinkmode_t;
11-
126
#include "panels/ThinkInk_154_Tricolor_RW.h"
137
#include "panels/ThinkInk_154_Tricolor_Z17.h"
148
#include "panels/ThinkInk_213_Tricolor_RW.h"

src/drivers/Adafruit_UC8151D.cpp

Lines changed: 169 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,6 @@
33

44
#define BUSY_WAIT 500
55

6-
const unsigned char LUT_DATA[30] = {
7-
0x02, 0x02, 0x01, 0x11, 0x12, 0x12, 0x22, 0x22, 0x66, 0x69,
8-
0x69, 0x59, 0x58, 0x99, 0x99, 0x88, 0x00, 0x00, 0x00, 0x00,
9-
0xF8, 0xB4, 0x13, 0x51, 0x35, 0x51, 0x51, 0x19, 0x01, 0x00};
10-
11-
// clang-format off
12-
13-
const uint8_t uc8151d_default_init_code[] {
14-
UC8151D_PON, 0,
15-
0xFF, 10,
16-
UC8151D_PSR, 1, 0x1F,
17-
UC8151D_CDI, 1, 0x97,
18-
0xFE};
19-
20-
// clang-format on
21-
226
/**************************************************************************/
237
/*!
248
@brief constructor if using external SRAM chip and software SPI
@@ -101,7 +85,7 @@ Adafruit_UC8151D::Adafruit_UC8151D(int width, int height, int8_t DC, int8_t RST,
10185
void Adafruit_UC8151D::busy_wait(void) {
10286
if (_busy_pin >= 0) {
10387
do {
104-
EPD_command(UC8151D_FLG);
88+
//EPD_command(UC8151D_FLG);
10589
delay(10);
10690
} while (!digitalRead(_busy_pin));
10791
} else {
@@ -120,6 +104,9 @@ void Adafruit_UC8151D::begin(bool reset) {
120104
setBlackBuffer(1, true); // black defaults to inverted
121105
setColorBuffer(0, true); // red defaults to inverted
122106

107+
Serial.printf("Buffer1 %04x: ", &buffer1);
108+
Serial.printf("Buffer2 %04x: ", &buffer2);
109+
123110
powerDown();
124111
}
125112

@@ -150,7 +137,7 @@ void Adafruit_UC8151D::powerUp() {
150137
hardwareReset();
151138
delay(10);
152139

153-
const uint8_t *init_code = uc8151d_default_init_code;
140+
const uint8_t *init_code = uc8151d_monofull_init_code;
154141

155142
if (_epd_init_code != NULL) {
156143
init_code = _epd_init_code;
@@ -209,3 +196,167 @@ uint8_t Adafruit_UC8151D::writeRAMCommand(uint8_t index) {
209196
*/
210197
/**************************************************************************/
211198
void Adafruit_UC8151D::setRAMAddress(uint16_t x, uint16_t y) {}
199+
200+
201+
202+
/**************************************************************************/
203+
/*!
204+
@brief Transfer the data stored in the buffer(s) to the display
205+
*/
206+
/**************************************************************************/
207+
void Adafruit_UC8151D::displayPartial(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
208+
uint8_t buf[7];
209+
uint8_t c;
210+
211+
212+
// check rotation, move window around if necessary
213+
switch (getRotation()) {
214+
case 0:
215+
EPD_swap(x1, y1);
216+
EPD_swap(x2, y2);
217+
y1 = WIDTH - y1;
218+
y2 = WIDTH - y2;
219+
break;
220+
case 1:
221+
break;
222+
case 2:
223+
EPD_swap(x1, y1);
224+
EPD_swap(x2, y2);
225+
x1 = HEIGHT - x1;
226+
x2 = HEIGHT - x2;
227+
break;
228+
case 3:
229+
y1 = WIDTH - y1;
230+
y2 = WIDTH - y2;
231+
x1 = HEIGHT - x1;
232+
x2 = HEIGHT - x2;
233+
}
234+
if (x1 > x2)
235+
EPD_swap(x1, x2);
236+
if (y1 > y2)
237+
EPD_swap(y1, y2);
238+
239+
/*
240+
Serial.print("x: ");
241+
Serial.print(x1);
242+
Serial.print(" -> ");
243+
Serial.println(x2);
244+
Serial.print("y: ");
245+
Serial.print(y1);
246+
Serial.print(" -> ");
247+
Serial.println(y2);
248+
*/
249+
250+
// x1 and x2 must be on byte boundaries
251+
x1 -= x1 % 8; // round down;
252+
x2 = (x2 + 7) & ~0b111; // round up
253+
254+
255+
// backup & change init to the partial code
256+
const uint8_t *init_code_backup = _epd_init_code;
257+
const uint8_t *lut_code_backup = _epd_lut_code;
258+
_epd_init_code = _epd_partial_init_code;
259+
_epd_lut_code = _epd_partial_lut_code;
260+
261+
#ifdef EPD_DEBUG
262+
Serial.println(" Powering Up Partial");
263+
#endif
264+
265+
powerUp();
266+
267+
Serial.print("Partials since last full update: ");
268+
Serial.println(partialsSinceLastFullUpdate);
269+
270+
// This command makes the display enter partial mode
271+
EPD_command(UC8151D_PTIN);
272+
273+
buf[0] = x1;
274+
buf[1] = x2-1;
275+
buf[2] = y1 >> 8;
276+
buf[3] = y1 & 0xFF;
277+
buf[4] = (y2-1) >> 8;
278+
buf[5] = (y2-1) & 0xFF;
279+
buf[6] = 0x28;
280+
281+
EPD_command(UC8151D_PTL, buf, 7); //resolution setting
282+
283+
Serial.printf("Buffer=1 %04x: ", &buffer1);
284+
Serial.printf("Buffer=2 %04x: ", &buffer2);
285+
286+
// buffer 1 has the old data from the last update
287+
if (use_sram) {
288+
if (partialsSinceLastFullUpdate == 0) {
289+
// first partial update
290+
Serial.println("Erasing SRAM buffer 1");
291+
sram.erase(buffer1_addr, buffer1_size, 0xFF);
292+
}
293+
writeSRAMFramebufferToEPD(buffer1_addr, buffer1_size, 0, true);
294+
} else {
295+
if (partialsSinceLastFullUpdate == 0) {
296+
// first partial update
297+
Serial.println("Erasing RAM buffer 1");
298+
memset(buffer1, 0xFF, buffer1_size);
299+
}
300+
301+
/*
302+
Serial.println("Buffer 1)");
303+
for (uint16_t i = 0; i < buffer1_size; i++) {
304+
uint8_t d = buffer1[i];
305+
Serial.printf("%02x", d);
306+
if ((i+1) % (WIDTH/8) == 0)
307+
Serial.println();
308+
}
309+
Serial.println();
310+
*/
311+
312+
writeRAMFramebufferToEPD(buffer1, buffer1_size, 0, true);
313+
}
314+
315+
delay(2);
316+
317+
// buffer 2 has the new data, that we're updating
318+
if (use_sram) {
319+
writeSRAMFramebufferToEPD(buffer2_addr, buffer2_size, 1, true);
320+
} else {
321+
writeRAMFramebufferToEPD(buffer2, buffer2_size, 1, true);
322+
}
323+
324+
325+
#ifdef EPD_DEBUG
326+
Serial.println(" Update");
327+
#endif
328+
update();
329+
330+
if (use_sram) {
331+
Serial.println("MEME FIX");
332+
while (1);
333+
} else {
334+
Serial.println("Partial, saving old data to secondary buffer");
335+
memcpy(buffer1, buffer2, buffer1_size); // buffer1 has the backup
336+
337+
/*
338+
Serial.println("Buffer 1");
339+
for (uint16_t i = 0; i < buffer1_size; i++) {
340+
uint8_t d = buffer1[i];
341+
Serial.printf("%02x", d);
342+
if ((i+1) % (WIDTH/8) == 0)
343+
Serial.println();
344+
}
345+
Serial.println();
346+
Serial.println("Buffer 2");
347+
for (uint16_t i = 0; i < buffer2_size; i++) {
348+
uint8_t d = buffer2[i];
349+
Serial.printf("%02x", d);
350+
if ((i+1) % (WIDTH/8) == 0)
351+
Serial.println();
352+
}
353+
*/
354+
Serial.println();
355+
}
356+
357+
partialsSinceLastFullUpdate++;
358+
359+
// change init back
360+
_epd_lut_code = lut_code_backup;
361+
_epd_init_code = init_code_backup;
362+
}

0 commit comments

Comments
 (0)