3
3
4
4
#define BUSY_WAIT 500
5
5
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
-
22
6
/* *************************************************************************/
23
7
/* !
24
8
@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,
101
85
void Adafruit_UC8151D::busy_wait (void ) {
102
86
if (_busy_pin >= 0 ) {
103
87
do {
104
- EPD_command (UC8151D_FLG);
88
+ // EPD_command(UC8151D_FLG);
105
89
delay (10 );
106
90
} while (!digitalRead (_busy_pin));
107
91
} else {
@@ -120,6 +104,9 @@ void Adafruit_UC8151D::begin(bool reset) {
120
104
setBlackBuffer (1 , true ); // black defaults to inverted
121
105
setColorBuffer (0 , true ); // red defaults to inverted
122
106
107
+ Serial.printf (" Buffer1 %04x: " , &buffer1);
108
+ Serial.printf (" Buffer2 %04x: " , &buffer2);
109
+
123
110
powerDown ();
124
111
}
125
112
@@ -150,7 +137,7 @@ void Adafruit_UC8151D::powerUp() {
150
137
hardwareReset ();
151
138
delay (10 );
152
139
153
- const uint8_t *init_code = uc8151d_default_init_code ;
140
+ const uint8_t *init_code = uc8151d_monofull_init_code ;
154
141
155
142
if (_epd_init_code != NULL ) {
156
143
init_code = _epd_init_code;
@@ -209,3 +196,167 @@ uint8_t Adafruit_UC8151D::writeRAMCommand(uint8_t index) {
209
196
*/
210
197
/* *************************************************************************/
211
198
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