Skip to content

Commit ec30a0d

Browse files
committed
pull out the framebuffer writing code
1 parent 5cfc439 commit ec30a0d

File tree

2 files changed

+58
-62
lines changed

2 files changed

+58
-62
lines changed

src/Adafruit_EPD.cpp

Lines changed: 53 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,46 @@ 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) {
286+
// write image
287+
writeRAMCommand(EPDlocation);
288+
dcHigh();
289+
for (uint16_t i = 0; i < buffer1_size; i++) {
290+
SPItransfer(buffer[i]);
291+
}
292+
csHigh();
293+
return;
294+
}
295+
296+
void Adafruit_EPD::writeSRAMFramebufferToEPD(uint16_t SRAM_buffer_addr, uint32_t buffer_size,
297+
uint8_t EPDlocation) {
298+
uint8_t c;
299+
300+
// use SRAM
301+
sram.csLow();
302+
// send read command
303+
SPItransfer(MCPSRAM_READ);
304+
// send address
305+
SPItransfer(SRAM_buffer_addr >> 8);
306+
SPItransfer(SRAM_buffer_addr & 0xFF);
307+
308+
// first data byte from SRAM will be transfered in at the same time
309+
// as the EPD command is transferred out
310+
c = writeRAMCommand(EPDlocation);
311+
312+
dcHigh();
313+
for (uint16_t i = 0; i < buffer_size; i++) {
314+
c = SPItransfer(c);
315+
// Serial.print("0x"); Serial.print((byte)c, HEX); Serial.print(", ");
316+
// if (i % 32 == 31) Serial.println();
317+
}
318+
csHigh();
319+
sram.csHigh();
320+
}
321+
322+
323+
284324
/**************************************************************************/
285325
/*!
286326
@brief Transfer the data stored in the buffer(s) to the display
@@ -303,72 +343,23 @@ void Adafruit_EPD::display(bool sleep) {
303343
setRAMAddress(0, 0);
304344

305345
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();
346+
writeSRAMFramebufferToEPD(buffer1_addr, buffer1_size, 0);
325347
} 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();
333-
}
334-
335-
if (buffer2_size == 0) {
336-
update();
337-
return;
348+
writeRAMFramebufferToEPD(buffer1, buffer1_size, 0);
338349
}
339350

340-
// oh there's another buffer eh?
341-
delay(2);
342-
343-
// Set X & Y ram counters
344-
setRAMAddress(0, 0);
345-
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]);
351+
if (buffer2_size != 0) {
352+
// oh there's another buffer eh?
353+
delay(2);
354+
355+
// Set X & Y ram counters
356+
setRAMAddress(0, 0);
357+
358+
if (use_sram) {
359+
writeSRAMFramebufferToEPD(buffer2_addr, buffer2_size, 1);
360+
} else {
361+
writeRAMFramebufferToEPD(buffer2, buffer2_size, 1);
370362
}
371-
csHigh();
372363
}
373364

374365
#ifdef EPD_DEBUG

src/Adafruit_EPD.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ class Adafruit_EPD : public Adafruit_GFX {
7373
void display(bool sleep = false);
7474

7575
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);
80+
7681
/**************************************************************************/
7782
/*!
7883
@brief Send the specific command to start writing to EPD display RAM

0 commit comments

Comments
 (0)