Skip to content

Commit 280763b

Browse files
authored
Merge pull request #39 from adafruit/partial_uc
Partial uc
2 parents 5cfc439 + c9b5740 commit 280763b

File tree

6 files changed

+322
-111
lines changed

6 files changed

+322
-111
lines changed

src/Adafruit_EPD.cpp

Lines changed: 81 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,61 @@ void Adafruit_EPD::drawPixel(int16_t x, int16_t y, uint16_t color) {
281281
}
282282
}
283283

284+
void Adafruit_EPD::writeRAMFramebufferToEPD(uint8_t *framebuffer,
285+
uint32_t framebuffer_size,
286+
uint8_t EPDlocation,
287+
bool invertdata) {
288+
// write image
289+
writeRAMCommand(EPDlocation);
290+
dcHigh();
291+
// Serial.printf("Writing from RAM location %04x: \n", &framebuffer);
292+
293+
for (uint16_t i = 0; i < framebuffer_size; i++) {
294+
uint8_t d = framebuffer[i];
295+
if (invertdata)
296+
d = ~d;
297+
298+
/*
299+
Serial.printf("%02x", d);
300+
if ((i+1) % (WIDTH/8) == 0)
301+
Serial.println();
302+
*/
303+
304+
SPItransfer(d);
305+
}
306+
// Serial.println();
307+
csHigh();
308+
return;
309+
}
310+
311+
void Adafruit_EPD::writeSRAMFramebufferToEPD(uint16_t SRAM_buffer_addr,
312+
uint32_t buffer_size,
313+
uint8_t EPDlocation,
314+
bool invertdata) {
315+
uint8_t c;
316+
317+
// use SRAM
318+
sram.csLow();
319+
// send read command
320+
SPItransfer(MCPSRAM_READ);
321+
// send address
322+
SPItransfer(SRAM_buffer_addr >> 8);
323+
SPItransfer(SRAM_buffer_addr & 0xFF);
324+
325+
// first data byte from SRAM will be transfered in at the same time
326+
// as the EPD command is transferred out
327+
c = writeRAMCommand(EPDlocation);
328+
329+
dcHigh();
330+
for (uint16_t i = 0; i < buffer_size; i++) {
331+
c = SPItransfer(c);
332+
// Serial.print("0x"); Serial.print((byte)c, HEX); Serial.print(", ");
333+
// if (i % 32 == 31) Serial.println();
334+
}
335+
csHigh();
336+
sram.csHigh();
337+
}
338+
284339
/**************************************************************************/
285340
/*!
286341
@brief Transfer the data stored in the buffer(s) to the display
@@ -303,78 +358,30 @@ void Adafruit_EPD::display(bool sleep) {
303358
setRAMAddress(0, 0);
304359

305360
if (use_sram) {
306-
sram.csLow();
307-
// send read command
308-
SPItransfer(MCPSRAM_READ);
309-
// send address
310-
SPItransfer(buffer1_addr >> 8);
311-
SPItransfer(buffer1_addr & 0xFF);
312-
313-
// first data byte from SRAM will be transfered in at the same time
314-
// as the EPD command is transferred out
315-
c = writeRAMCommand(0);
316-
317-
dcHigh();
318-
for (uint16_t i = 0; i < buffer1_size; i++) {
319-
c = SPItransfer(c);
320-
// Serial.print("0x"); Serial.print((byte)c, HEX); Serial.print(", ");
321-
// if (i % 32 == 31) Serial.println();
322-
}
323-
csHigh();
324-
sram.csHigh();
361+
writeSRAMFramebufferToEPD(buffer1_addr, buffer1_size, 0);
325362
} else {
326-
// write image
327-
writeRAMCommand(0);
328-
dcHigh();
329-
for (uint16_t i = 0; i < buffer1_size; i++) {
330-
SPItransfer(buffer1[i]);
331-
}
332-
csHigh();
363+
writeRAMFramebufferToEPD(buffer1, buffer1_size, 0);
333364
}
334365

335-
if (buffer2_size == 0) {
336-
update();
337-
return;
338-
}
339-
340-
// oh there's another buffer eh?
341-
delay(2);
366+
if (buffer2_size != 0) {
367+
// oh there's another buffer eh?
368+
delay(2);
342369

343-
// Set X & Y ram counters
344-
setRAMAddress(0, 0);
370+
// Set X & Y ram counters
371+
setRAMAddress(0, 0);
345372

346-
if (use_sram) {
347-
sram.csLow();
348-
// send read command
349-
SPItransfer(MCPSRAM_READ);
350-
// send address
351-
SPItransfer(buffer2_addr >> 8);
352-
SPItransfer(buffer2_addr & 0xFF);
353-
354-
// first data byte from SRAM will be transfered in at the same time
355-
// as the EPD command is transferred out
356-
c = writeRAMCommand(1);
357-
358-
dcHigh();
359-
for (uint16_t i = 0; i < buffer2_size; i++) {
360-
c = SPItransfer(c);
361-
}
362-
csHigh();
363-
sram.csHigh();
364-
} else {
365-
writeRAMCommand(1);
366-
dcHigh();
367-
368-
for (uint16_t i = 0; i < buffer2_size; i++) {
369-
SPItransfer(buffer2[i]);
373+
if (use_sram) {
374+
writeSRAMFramebufferToEPD(buffer2_addr, buffer2_size, 1);
375+
} else {
376+
writeRAMFramebufferToEPD(buffer2, buffer2_size, 1);
370377
}
371-
csHigh();
372378
}
373379

374380
#ifdef EPD_DEBUG
375381
Serial.println(" Update");
376382
#endif
377383
update();
384+
partialsSinceLastFullUpdate = 0;
378385

379386
if (sleep) {
380387
#ifdef EPD_DEBUG
@@ -441,33 +448,29 @@ void Adafruit_EPD::setColorBuffer(int8_t index, bool inverted) {
441448
/**************************************************************************/
442449
void Adafruit_EPD::clearBuffer() {
443450
if (use_sram) {
444-
if (buffer1_size != 0) {
445-
if (blackInverted) {
446-
sram.erase(buffer1_addr, buffer1_size, 0xFF);
447-
} else {
448-
sram.erase(buffer1_addr, buffer1_size, 0x00);
449-
}
451+
if (blackInverted) {
452+
sram.erase(blackbuffer_addr, buffer1_size, 0xFF);
453+
} else {
454+
sram.erase(blackbuffer_addr, buffer1_size, 0x00);
450455
}
451-
if (buffer2_size != 0) {
452-
if (colorInverted) {
453-
sram.erase(buffer2_addr, buffer2_size, 0xFF);
454-
} else {
455-
sram.erase(buffer2_addr, buffer2_size, 0x00);
456-
}
456+
if (colorInverted) {
457+
sram.erase(colorbuffer_addr, buffer2_size, 0xFF);
458+
} else {
459+
sram.erase(colorbuffer_addr, buffer2_size, 0x00);
457460
}
458461
} else {
459-
if (buffer1) {
462+
if (black_buffer) {
460463
if (blackInverted) {
461-
memset(buffer1, 0xFF, buffer1_size);
464+
memset(black_buffer, 0xFF, buffer1_size);
462465
} else {
463-
memset(buffer1, 0x00, buffer1_size);
466+
memset(black_buffer, 0x00, buffer1_size);
464467
}
465468
}
466-
if (buffer2) {
469+
if (color_buffer) {
467470
if (colorInverted) {
468-
memset(buffer2, 0xFF, buffer2_size);
471+
memset(color_buffer, 0xFF, buffer2_size);
469472
} else {
470-
memset(buffer2, 0x00, buffer2_size);
473+
memset(color_buffer, 0x00, buffer2_size);
471474
}
472475
}
473476
}

src/Adafruit_EPD.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#ifndef _ADAFRUIT_EPD_H_
2121
#define _ADAFRUIT_EPD_H_
2222

23-
#define EPD_DEBUG
23+
//#define EPD_DEBUG
2424

2525
#define RAMBUFSIZE 64 ///< size of the ram buffer
2626

@@ -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,7 +79,15 @@ 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:
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,
88+
uint32_t buffer_size, uint8_t EPDlocation,
89+
bool invertdata = false);
90+
7691
/**************************************************************************/
7792
/*!
7893
@brief Send the specific command to start writing to EPD display RAM
@@ -164,6 +179,10 @@ class Adafruit_EPD : public Adafruit_GFX {
164179

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

182+
thinkinkmode_t inkmode; // Ink mode passed to begin()
183+
184+
uint8_t partialsSinceLastFullUpdate = 0;
185+
167186
#if defined(BUSIO_USE_FAST_PINIO)
168187
BusIO_PortReg *csPort, *dcPort;
169188
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"

0 commit comments

Comments
 (0)