@@ -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
0 commit comments