Skip to content

Commit 2dc7af4

Browse files
committed
Improved profiles which use all of the built-in LUTs of the gen2/Xiao panels
1 parent c397130 commit 2dc7af4

File tree

3 files changed

+50
-19
lines changed

3 files changed

+50
-19
lines changed

lib/bb_epaper/src/bb_ep.inl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ BBEP_GRAY3, BBEP_GRAY2, BBEP_GRAY1, BBEP_GRAY0, BBEP_GRAY3, BBEP_GRAY2, BBEP_GRA
4949
BBEP_GRAY3, BBEP_GRAY2, BBEP_GRAY1, BBEP_GRAY0, BBEP_GRAY3, BBEP_GRAY2, BBEP_GRAY1, BBEP_GRAY0
5050
};
5151

52+
// 2-bit grayscale mode (some swapped)
53+
const uint8_t u8Colors_4gray_v2[16] = {
54+
BBEP_GRAY3, BBEP_GRAY1, BBEP_GRAY2, BBEP_GRAY0, BBEP_GRAY3, BBEP_GRAY1, BBEP_GRAY2, BBEP_GRAY0,
55+
BBEP_GRAY3, BBEP_GRAY2, BBEP_GRAY1, BBEP_GRAY0, BBEP_GRAY3, BBEP_GRAY1, BBEP_GRAY2, BBEP_GRAY0
56+
};
57+
5258
// the 4-color mode
5359
const uint8_t u8Colors_4clr[16] = { // black white red yellow
5460
BBEP_BLACK, BBEP_WHITE, BBEP_RED, BBEP_YELLOW, BBEP_BLACK, BBEP_WHITE, BBEP_RED, BBEP_YELLOW,
@@ -646,7 +652,7 @@ const uint8_t epd75_init_sequence_partial[] PROGMEM = {
646652
};
647653
const uint8_t epd75_init_fast_gen2[] PROGMEM = {
648654
0x02, 0x00, 0x1f, // panel setting
649-
0x03, 0x50, 0x10, 0x07,
655+
0x03, 0x50, 0x21, 0x07,
650656
0x01, 0x04, // power on
651657
BUSY_WAIT,
652658
0x05, 0x06, 0x27, 0x27, 0x18, 0x17,
@@ -656,14 +662,17 @@ const uint8_t epd75_init_fast_gen2[] PROGMEM = {
656662
};
657663

658664
const uint8_t epd75_init_partial_gen2[] PROGMEM = {
665+
0x01, 0x04, // power on
666+
BUSY_WAIT,
667+
0x02, 0xe0, 0x02,
668+
0x02, 0xe5, 0x5a,
659669
0x02, 0x00, 0x1f, // panel setting
660-
// 0x03, 0x50, 0x10, 0x07,
670+
0x03, 0x50, 0x21, 0x07,
661671
0x01, 0x04, // power on
662672
BUSY_WAIT,
663673
0x05, 0x06, 0x27, 0x27, 0x18, 0x17,
664674
0x02, 0xe0, 0x02,
665675
0x02, 0xe5, 0x6e,
666-
0x03, 0x50, 0xa9, 0x07,
667676
0
668677
};
669678

@@ -2095,8 +2104,8 @@ const EPD_PANEL panelDefs[] PROGMEM = {
20952104
{240, 416, 0, epd37_init_sequence_full, NULL, epd37_init_sequence_part, 0, BBEP_CHIP_UC81xx, u8Colors_2clr}, // EP37_240x416
20962105
{104, 212, 0, epd213_inky_init_sequence_full, NULL, NULL, 0, BBEP_CHIP_UC81xx, u8Colors_2clr}, // EP213_104x212, older InkyPHAT black and white
20972106
{800, 480, 0, epd75_init_sequence_full, epd75_init_sequence_fast, epd75_init_sequence_partial, 0, BBEP_CHIP_UC81xx, u8Colors_2clr}, // EP75_800x480
2098-
{800, 480, 0, epd75_init_sequence_full, epd75_init_fast_gen2, epd75_init_sequence_partial, 0, BBEP_CHIP_UC81xx, u8Colors_2clr}, // EP75_800x480_GEN2
2099-
{800, 480, 0, epd75_gray_init, NULL, NULL, BBEP_4GRAY, BBEP_CHIP_UC81xx, u8Colors_4gray}, // EP75_800x480_4GRAY_GEN2
2107+
{800, 480, 0, epd75_init_sequence_full, epd75_init_fast_gen2, epd75_init_partial_gen2, 0, BBEP_CHIP_UC81xx, u8Colors_2clr}, // EP75_800x480_GEN2
2108+
{800, 480, 0, epd75_gray_init, NULL, NULL, BBEP_4GRAY, BBEP_CHIP_UC81xx, u8Colors_4gray_v2}, // EP75_800x480_4GRAY_GEN2
21002109
{800, 480, 0, epd75_old_gray_init, NULL, NULL, BBEP_4GRAY, BBEP_CHIP_UC81xx, u8Colors_4gray}, // EP75_800x480_4GRAY
21012110
{800, 480, 0, epd75_old_gray_init2, NULL, NULL, BBEP_4GRAY, BBEP_CHIP_UC81xx, u8Colors_4gray}, // EP75_800x480_4GRAY_V2
21022111
{128, 296, 0, epd29_init_sequence_full, epd29_init_sequence_fast, epd29_init_sequence_part, 0, BBEP_CHIP_UC81xx, u8Colors_2clr}, // Badger 2040

src/bl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ void bl_init(void)
262262

263263
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
264264

265-
// uncomment this to hardcode WiFi credentials (useful for testing wifi errors, etc.)
265+
// uncdcomment this to hardcode WiFi credentials (useful for testing wifi errors, etc.)
266266
// #define HARDCODED_WIFI
267267
#ifdef HARDCODED_WIFI
268268
WifiCredentials hardcodedCreds = {.ssid = "ssid-goes-here", .pswd = "password-goes-here"};

src/display.cpp

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
#include "bb_epaper.h"
1111

1212
const DISPLAY_PROFILE dpList[4] = { // 1-bit and 2-bit display types for each profile
13-
{EP75_800x480, EP75_800x480_4GRAY_GEN2/*EP75_800x480_4GRAY*/}, // default (for original EPD)
13+
{EP75_800x480, EP75_800x480_4GRAY}, // default (for original EPD)
1414
{EP75_800x480_GEN2, EP75_800x480_4GRAY_GEN2}, // a = uses built-in fast + 4-gray
15-
{EP75_800x480, EP75_800x480_4GRAY_V2}, // b
16-
{EP75_800x480_GEN2, EP75_800x480_4GRAY_GEN2}, // c
15+
{EP75_800x480, EP75_800x480_4GRAY_V2}, // b = darker grays
1716
};
1817
BBEPAPER bbep(EP75_800x480);
1918
// Counts the number of partial updates to know when to do a full update
@@ -366,6 +365,15 @@ void ReduceBpp(int iDestBpp, int iPixelType, uint8_t *pPalette, uint8_t *pSrc, u
366365
*d++ = u8;
367366
}
368367
} /* ReduceBpp() */
368+
enum {
369+
PNG_1_BIT = 0,
370+
PNG_1_BIT_INVERTED,
371+
PNG_2_BIT_0,
372+
PNG_2_BIT_1,
373+
PNG_2_BIT_BOTH,
374+
PNG_2_BIT_INVERTED,
375+
};
376+
369377
/**
370378
* @brief Callback function for each line of PNG decoded
371379
* @param PNGDRAW structure containing the current line and relevant info
@@ -376,6 +384,7 @@ int png_draw(PNGDRAW *pDraw)
376384
int x;
377385
uint8_t ucBppChanged = 0, ucInvert = 0;
378386
uint8_t uc, ucMask, src, *s, *d, *pTemp = bbep.getCache(); // get some scratch memory (not from the stack)
387+
int iPlane = *(int *)pDraw->pUser;
379388

380389
if (pDraw->iPixelType == PNG_PIXEL_INDEXED || pDraw->iBpp > 2) {
381390
if (pDraw->iBpp == 1) { // 1-bit output, just see which color is brighter
@@ -395,8 +404,9 @@ int png_draw(PNGDRAW *pDraw)
395404
}
396405
s = (ucBppChanged) ? pTemp : (uint8_t *)pDraw->pPixels;
397406
d = pTemp;
398-
if (!pDraw->pUser) {
407+
if (iPlane == PNG_1_BIT || iPlane == PNG_1_BIT_INVERTED) {
399408
// 1-bit output, decode the single plane and write it
409+
if (iPlane == PNG_1_BIT_INVERTED) ucInvert = ~ucInvert; // to do PLANE_FALSE_DIFF
400410
for (x=0; x<pDraw->iWidth; x+= 8) {
401411
d[0] = s[0] ^ ucInvert;
402412
d++; s++;
@@ -405,8 +415,10 @@ int png_draw(PNGDRAW *pDraw)
405415
src = *s++;
406416
src ^= ucInvert;
407417
uc = 0; // suppress warning/error
408-
if (*(int *)pDraw->pUser > 1) { // draw 2bpp data as 1-bit to use for partial update
409-
ucInvert = ~ucInvert; // the invert rule is backwards for grayscale data
418+
if (iPlane == PNG_2_BIT_BOTH || iPlane == PNG_2_BIT_INVERTED) { // draw 2bpp data as 1-bit to use for partial update
419+
if (iPlane == PNG_2_BIT_BOTH) {
420+
ucInvert = ~ucInvert; // the invert rule is backwards for grayscale data
421+
}
410422
src = ~src;
411423
for (x=0; x<pDraw->iWidth; x++) {
412424
uc <<= 1;
@@ -423,7 +435,7 @@ int png_draw(PNGDRAW *pDraw)
423435
}
424436
} // for x
425437
} else { // normal 0/1 split plane
426-
ucMask = (*(int *)pDraw->pUser == 0) ? 0x40 : 0x80; // lower or upper source bit
438+
ucMask = (iPlane == PNG_2_BIT_0) ? 0x40 : 0x80; // lower or upper source bit
427439
for (x=0; x<pDraw->iWidth; x++) {
428440
uc <<= 1;
429441
if (src & ucMask) {
@@ -516,10 +528,9 @@ int i, iColors;
516528
* @param size of the PNG file
517529
* @return refresh mode based on image type and presence of old image
518530
*/
519-
520531
int png_to_epd(const uint8_t *pPNG, int iDataSize)
521532
{
522-
int iPlane, rc = -1;
533+
int iPlane = PNG_1_BIT, rc = -1;
523534
PNG *png = new PNG();
524535

525536
if (!png) return PNG_MEM_ERROR; // not enough memory for the decoder instance
@@ -539,26 +550,37 @@ PNG *png = new PNG();
539550
bbep.startWrite(PLANE_0); // start writing image data to plane 0
540551
png->openRAM((uint8_t *)pPNG, iDataSize, png_draw);
541552
if (png->getBpp() == 1 || png->getBpp() > 2) {
542-
png->decode(NULL, 0);
553+
iPlane = PNG_1_BIT;
554+
png->decode(&iPlane, 0);
543555
} else { // convert the 2-bit image to 1-bit output
544556
Log_info("%s [%d]: Current png only has 2 unique colors!\n", __FILE__, __LINE__);
545-
iPlane = 2;
557+
iPlane = PNG_2_BIT_BOTH;
546558
if (png->decode(&iPlane, 0) != PNG_SUCCESS) {
547559
Log_info("%s [%d]: Error decoding image = %d\n", __FILE__, __LINE__, png->getLastError());
548560
}
549561
}
550562
png->close();
563+
if (iTempProfile != 0) { // need to write the inverted plane to do PLANE_FALSE_DIFF
564+
bbep.startWrite(PLANE_1); // start writing image data to plane 1
565+
png->openRAM((uint8_t *)pPNG, iDataSize, png_draw);
566+
if (iPlane == PNG_1_BIT) {
567+
iPlane = PNG_1_BIT_INVERTED; // inverted 1-bit to second memory plane
568+
} else { // convert the 2-bit image to 1-bit output
569+
iPlane = PNG_2_BIT_INVERTED; // inverted 2-bit -> 1-bit to second plane
570+
}
571+
png->decode(&iPlane, 0);
572+
} // temp profile needs the second plane written
551573
} else { // 2-bpp
552574
bbep.setPanelType(dpList[iTempProfile].TwoBit);
553575
rc = REFRESH_FULL; // 4gray mode must be full refresh
554576
iUpdateCount = 0; // grayscale mode resets the partial update counter
555577
bbep.startWrite(PLANE_0); // start writing image data to plane 0
556-
iPlane = 0;
578+
iPlane = PNG_2_BIT_0;
557579
Log_info("%s [%d]: decoding 4-gray plane 0\r\n", __FILE__, __LINE__);
558580
png->openRAM((uint8_t *)pPNG, iDataSize, png_draw);
559581
png->decode(&iPlane, 0); // tell PNGDraw to use bits for plane 0
560582
png->close(); // start over for plane 1
561-
iPlane = 1;
583+
iPlane = PNG_2_BIT_1;
562584
Log_info("%s [%d]: decoding 4-gray plane 1\r\n", __FILE__, __LINE__);
563585
png->openRAM((uint8_t *)pPNG, iDataSize, png_draw);
564586
bbep.startWrite(PLANE_1); // start writing image data to plane 1

0 commit comments

Comments
 (0)