Skip to content

Commit 19a89da

Browse files
committed
colorful!
1 parent a9cdd17 commit 19a89da

File tree

4 files changed

+194
-44
lines changed

4 files changed

+194
-44
lines changed

src/Adafruit_EPD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ void Adafruit_EPD::writeRAMFramebufferToEPD(uint8_t *framebuffer,
290290
dcHigh();
291291
// Serial.printf("Writing from RAM location %04x: \n", &framebuffer);
292292

293-
for (uint16_t i = 0; i < framebuffer_size; i++) {
293+
for (uint32_t i = 0; i < framebuffer_size; i++) {
294294
uint8_t d = framebuffer[i];
295295
if (invertdata)
296296
d = ~d;

src/Adafruit_EPD.h

Lines changed: 3 additions & 3 deletions
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

@@ -155,8 +155,8 @@ class Adafruit_EPD : public Adafruit_GFX {
155155

156156
uint8_t layer_colors[EPD_NUM_COLORS];
157157

158-
uint16_t buffer1_size; ///< size of the primary buffer
159-
uint16_t buffer2_size; ///< size of the secondary buffer
158+
uint32_t buffer1_size; ///< size of the primary buffer
159+
uint32_t buffer2_size; ///< size of the secondary buffer
160160
uint8_t *buffer1; ///< the pointer to the primary buffer if using on-chip ram
161161
uint8_t
162162
*buffer2; ///< the pointer to the secondary buffer if using on-chip ram

src/drivers/Adafruit_ACeP.cpp

Lines changed: 174 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Adafruit_ACEP::Adafruit_ACEP(int width, int height, int8_t DC, int8_t RST,
8282
if ((height % 8) != 0) {
8383
height += 8 - (height % 8);
8484
}
85-
buffer1_size = (uint16_t)width * (uint16_t)height / 2;
85+
buffer1_size = width * height / 2;
8686
buffer2_size = 0;
8787

8888
if (SRCS >= 0) {
@@ -99,41 +99,25 @@ Adafruit_ACEP::Adafruit_ACEP(int width, int height, int8_t DC, int8_t RST,
9999

100100
/**************************************************************************/
101101
/*!
102-
@brief wait for busy signal to end
102+
@brief clear all data buffers
103103
*/
104104
/**************************************************************************/
105-
void Adafruit_ACEP::busy_wait(void) {
106-
if (_busy_pin >= 0) {
107-
while (!digitalRead(_busy_pin)) { // wait for busy high
108-
delay(10);
109-
}
105+
void Adafruit_ACEP::clearBuffer() {
106+
if (use_sram) {
107+
sram.erase(colorbuffer_addr, buffer1_size, 0x11);
110108
} else {
111-
delay(BUSY_WAIT);
109+
memset(color_buffer, 0x11, buffer1_size);
112110
}
113111
}
114112

115113
/**************************************************************************/
116114
/*!
117-
@brief begin communication with and set up the display.
118-
@param reset if true the reset pin will be toggled.
115+
@brief clear all data buffers
119116
*/
120117
/**************************************************************************/
121-
void Adafruit_ACEP::begin(bool reset) {
122-
Adafruit_EPD::begin(reset);
123-
124-
delay(100);
125-
//powerDown();
126-
}
127-
128-
/**************************************************************************/
129-
/*!
130-
@brief signal the display to update
131-
*/
132-
/**************************************************************************/
133-
void Adafruit_ACEP::update() {
134-
118+
void Adafruit_ACEP::deGhost() {
135119
uint8_t buf[4];
136-
/***************** clear data first */
120+
137121
buf[0] = 0x02;
138122
buf[1] = 0x58;
139123
buf[2] = 0x01;
@@ -163,27 +147,169 @@ void Adafruit_ACEP::update() {
163147
} else {
164148
delay(BUSY_WAIT);
165149
}
150+
}
151+
152+
153+
/**************************************************************************/
154+
/*!
155+
@brief clear the display twice to remove any spooky ghost images
156+
*/
157+
/**************************************************************************/
158+
void Adafruit_ACEP::clearDisplay() {
159+
clearBuffer();
160+
display();
161+
}
166162

163+
/**************************************************************************/
164+
/*!
165+
@brief draw a single pixel on the screen
166+
@param x the x axis position
167+
@param y the y axis position
168+
@param color the color of the pixel
169+
*/
170+
/**************************************************************************/
171+
void Adafruit_ACEP::drawPixel(int16_t x, int16_t y, uint16_t color) {
172+
if ((x < 0) || (x >= width()) || (y < 0) || (y >= height()))
173+
return;
174+
175+
uint8_t *pBuf;
176+
177+
// deal with non-8-bit heights
178+
uint16_t _HEIGHT = HEIGHT;
179+
if (_HEIGHT % 8 != 0) {
180+
_HEIGHT += 8 - (_HEIGHT % 8);
181+
}
182+
183+
// check rotation, move pixel around if necessary
184+
switch (getRotation()) {
185+
case 1:
186+
EPD_swap(x, y);
187+
x = WIDTH - x - 1;
188+
break;
189+
case 2:
190+
x = WIDTH - x - 1;
191+
y = _HEIGHT - y - 1;
192+
break;
193+
case 3:
194+
EPD_swap(x, y);
195+
y = _HEIGHT - y - 1;
196+
break;
197+
}
198+
uint32_t addr = ((uint32_t)x + (uint32_t)y*WIDTH)/2;
199+
bool lower_nibble = x % 2;
200+
uint8_t color_c;
201+
202+
if (use_sram) {
203+
color_c = sram.read8(colorbuffer_addr + addr);
204+
pBuf = &color_c;
205+
} else {
206+
pBuf = color_buffer + addr;
207+
}
208+
209+
if (lower_nibble) {
210+
*pBuf &= 0xF0; // save higher nib
211+
*pBuf |= (color & 0xF);
212+
} else {
213+
*pBuf &= 0x0F; // save lower nib
214+
*pBuf |= (color & 0xF) << 4;
215+
}
216+
217+
if (use_sram) {
218+
sram.write8(colorbuffer_addr + addr, *pBuf);
219+
}
220+
}
221+
222+
223+
/**************************************************************************/
224+
/*!
225+
@brief wait for busy signal to end
226+
*/
227+
/**************************************************************************/
228+
void Adafruit_ACEP::busy_wait(void) {
229+
if (_busy_pin >= 0) {
230+
while (!digitalRead(_busy_pin)) { // wait for busy high
231+
delay(10);
232+
}
233+
} else {
234+
delay(BUSY_WAIT);
235+
}
236+
}
237+
238+
/**************************************************************************/
239+
/*!
240+
@brief begin communication with and set up the display.
241+
@param reset if true the reset pin will be toggled.
242+
*/
243+
/**************************************************************************/
244+
void Adafruit_ACEP::begin(bool reset) {
245+
Adafruit_EPD::begin(reset);
246+
delay(100);
247+
}
248+
249+
250+
/**************************************************************************/
251+
/*!
252+
@brief Transfer the data stored in the buffer(s) to the display
253+
*/
254+
/**************************************************************************/
255+
void Adafruit_ACEP::display(bool sleep) {
256+
uint8_t c;
257+
258+
#ifdef EPD_DEBUG
259+
Serial.println(" Powering Up");
260+
#endif
261+
262+
powerUp();
263+
264+
#ifdef EPD_DEBUG
265+
Serial.println(" De Ghosting");
266+
#endif
267+
268+
deGhost();
167269
delay(500);
168270

169-
// actual data
170-
// setresolution, write data
171-
buf[0] = 0x02;
172-
buf[1] = 0x58;
173-
buf[2] = 0x01;
174-
buf[3] = 0xC0;
175-
EPD_command(ACEP_RESOLUTION, buf, 4);
176-
EPD_command(ACEP_DTM);
177271

178-
remaining = (600UL * 448UL / 2);
179-
while (remaining) {
180-
uint8_t block[256];
181-
uint32_t numbytes = min(remaining, sizeof(block));
182-
memset(block, 0x44, numbytes);
183-
EPD_data(block, numbytes);
184-
remaining -= numbytes;
272+
#ifdef EPD_DEBUG
273+
Serial.println(" Powering Up");
274+
#endif
275+
276+
277+
powerUp();
278+
279+
#ifdef EPD_DEBUG
280+
Serial.println(" Write frame buffer");
281+
#endif
282+
283+
if (use_sram) {
284+
writeSRAMFramebufferToEPD(buffer1_addr, buffer1_size, 0);
285+
} else {
286+
writeRAMFramebufferToEPD(buffer1, buffer1_size, 0);
185287
}
186288

289+
#ifdef EPD_DEBUG
290+
Serial.println(" Update");
291+
#endif
292+
update();
293+
partialsSinceLastFullUpdate = 0;
294+
295+
if (sleep) {
296+
#ifdef EPD_DEBUG
297+
Serial.println(" Powering Down");
298+
#endif
299+
powerDown();
300+
}
301+
}
302+
303+
304+
/**************************************************************************/
305+
/*!
306+
@brief signal the display to update
307+
*/
308+
/**************************************************************************/
309+
void Adafruit_ACEP::update(void) {
310+
311+
uint8_t buf[4];
312+
187313
EPD_command(ACEP_POWER_ON);
188314
busy_wait();
189315
EPD_command(ACEP_DISPLAY_REFRESH);
@@ -215,6 +341,14 @@ void Adafruit_ACEP::powerUp() {
215341
init_code = _epd_init_code;
216342
}
217343
EPD_commandList(init_code);
344+
345+
// set resolution
346+
buf[0] = 0x02;
347+
buf[1] = 0x58;
348+
buf[2] = 0x01;
349+
buf[3] = 0xC0;
350+
EPD_command(ACEP_RESOLUTION, buf, 4);
351+
218352
delay(100);
219353
}
220354

src/drivers/Adafruit_ACeP.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
#define ACEP_RESOLUTION 0x61
2121
#define ACEP_PWS 0xE3
2222

23+
#define ACEP_COLOR_BLACK 0x0 /// 000
24+
#define ACEP_COLOR_WHITE 0x1 /// 001
25+
#define ACEP_COLOR_GREEN 0x2 /// 010
26+
#define ACEP_COLOR_BLUE 0x3 /// 011
27+
#define ACEP_COLOR_RED 0x4 /// 100
28+
#define ACEP_COLOR_YELLOW 0x5 /// 101
29+
#define ACEP_COLOR_ORANGE 0x6 /// 110
30+
31+
2332
/**************************************************************************/
2433
/*!
2534
@brief Class for interfacing with ACEP EPD drivers
@@ -37,6 +46,13 @@ class Adafruit_ACEP : public Adafruit_EPD {
3746
void powerUp();
3847
void powerDown();
3948
void update();
49+
void display(bool sleep=true);
50+
51+
void clearBuffer();
52+
void clearDisplay();
53+
void deGhost();
54+
void drawPixel(int16_t x, int16_t y, uint16_t color);
55+
4056

4157
protected:
4258
uint8_t writeRAMCommand(uint8_t index);

0 commit comments

Comments
 (0)