2424
2525#ifndef __BB_EP__
2626#define __BB_EP__
27+ #pragma GCC optimize("O2")
2728
2829// For measuring the performance of each stage of updates
2930// #define SHOW_TIME
@@ -173,7 +174,7 @@ int bbepSetCustomMatrix(FASTEPDSTATE *pState, const uint8_t *pMatrix, size_t mat
173174// width, height, bus_speed, flags, data[8], bus_width, ioPWR, ioSPV, ioCKV, ioSPH, ioOE, ioLE,
174175// ioCL, ioPWR_Good, ioSDA, ioSCL, ioShiftSTR/Wakeup, ioShiftMask/vcom, ioDCDummy, graymatrix, sizeof(graymatrix), iLinePadding
175176const BBPANELDEF panelDefs[] = {
176- {0 }, // BB_PANEL_NONE
177+ {0 , 0 , 0 , 0 ,{ 0 }, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , NULL , 0 , 0 }, // BB_PANEL_NONE
177178 {960 , 540 , 20000000 , BB_PANEL_FLAG_NONE, {6 ,14 ,7 ,12 ,9 ,11 ,8 ,10 }, 8 , 46 , 17 , 18 , 13 , 45 , 15 ,
178179 16 , BB_NOT_USED, BB_NOT_USED, BB_NOT_USED, BB_NOT_USED, BB_NOT_USED, 47 , u8M5Matrix, sizeof (u8M5Matrix), 0 }, // BB_PANEL_M5PAPERS3
179180
@@ -189,7 +190,7 @@ const BBPANELDEF panelDefs[] = {
189190 {0 , 0 , 20000000 , BB_PANEL_FLAG_NONE, {9 ,10 ,11 ,12 ,13 ,14 ,21 ,47 ,5 ,6 ,7 ,15 ,16 ,17 ,18 ,8 }, 16 , 11 , 45 , 48 , 41 , 8 , 42 ,
190191 4 , 14 , 39 , 40 , BB_NOT_USED, 0 , 46 , u8GrayMatrix, sizeof (u8GrayMatrix), 16 }, // BB_PANEL_EPDIY_V7_16
191192
192- {0 , 0 , 20000000 , BB_PANEL_FLAG_NONE, {5 ,6 ,7 ,15 ,16 ,17 ,18 ,8 }, 8 , 11 , 45 , 48 , 41 , 9 , 42 ,
193+ {0 , 0 , 26666666 , BB_PANEL_FLAG_NONE, {5 ,6 ,7 ,15 ,16 ,17 ,18 ,8 }, 8 , 11 , 45 , 48 , 41 , 9 , 42 ,
193194 4 , 14 , 39 , 40 , BB_NOT_USED, 0 , 0 , u8M5Matrix, sizeof (u8M5Matrix), 0 }, // BB_PANEL_V7_RAW
194195 // D8 15 D0 D7 STV,CKV,XSTL,OE,XLE
195196 {1872 , 1404 , 20000000 , BB_PANEL_FLAG_MIRROR_X, {8 ,18 ,17 ,16 ,15 ,7 ,6 ,5 ,47 ,21 ,14 ,13 ,12 ,11 ,10 ,9 }, 16 , 11 , 41 , 42 , 45 , 8 , 48 ,
@@ -232,7 +233,7 @@ uint8_t Inkplate5V2ExtIO(uint8_t iOp, uint8_t iPin, uint8_t iVal);
232233// List of predefined callback functions for the panels supported by bb_epdiy
233234// BB_EINK_POWER, BB_IO_INIT, BB_ROW_CONTROL
234235const BBPANELPROCS panelProcs[] = {
235- {0 }, // BB_PANEL_NONE
236+ {NULL , NULL , NULL , NULL , NULL }, // BB_PANEL_NONE
236237 {PaperS3EinkPower, PaperS3IOInit, PaperS3RowControl, NULL , NULL }, // BB_PANEL_M5PAPERS3
237238 {EPDiyV7EinkPower, EPDiyV7IOInit, EPDiyV7RowControl, EPDiyV7IODeInit, EPDiyV7ExtIO}, // BB_PANEL_EPDIY_V7
238239 {Inkplate6PlusEinkPower, Inkplate6PlusIOInit, Inkplate6PlusRowControl, NULL , NULL }, // BB_PANEL_INKPLATE6PLUS
@@ -247,6 +248,7 @@ const BBPANELPROCS panelProcs[] = {
247248uint8_t ioRegs[24 ]; // MCP23017 copy of I/O register state so that we can just write new bits
248249static uint16_t LUTW_16[256 ];
249250static uint16_t LUTB_16[256 ];
251+ static uint16_t LUTBW_16[256 ];
250252// Lookup tables for grayscale mode
251253static uint32_t *pGrayLower = NULL , *pGrayUpper = NULL ;
252254volatile bool dma_is_done = true ;
@@ -272,8 +274,8 @@ static esp_lcd_i80_bus_config_t s3_bus_config = {
272274 .data_gpio_nums = {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
273275 .bus_width = 0 ,
274276 .max_transfer_bytes = MAX_TX_SIZE,
275- // .psram_trans_align = 0, // 0 = use default values
276- // .sram_trans_align = 0,
277+ .psram_trans_align = 0 , // 0 = use default values
278+ .sram_trans_align = 0 ,
277279};
278280static esp_lcd_panel_io_i80_config_t s3_io_config = {
279281 .cs_gpio_num = 0 ,
@@ -779,9 +781,9 @@ uint8_t u8Value = 0; // I/O bits for the PCA9535
779781 } else { // power off
780782 gpio_set_level ((gpio_num_t )pState->panelDef .ioOE , 0 ); // OE off
781783 gpio_set_level ((gpio_num_t )10 , 0 ); // EP_MODE/GMOD off
782- gpio_set_level ((gpio_num_t )14 , 1 ); // WAKEUP on
783- gpio_set_level ((gpio_num_t )11 , 1 ); // PWRUP on
784- gpio_set_level ((gpio_num_t )12 , 1 ); // VCOM CTRL on
784+ gpio_set_level ((gpio_num_t )12 , 0 ); // VCOM CTRL off
785+ gpio_set_level ((gpio_num_t )11 , 0 ); // PWRUP off
786+ gpio_set_level ((gpio_num_t )14 , 0 ); // WAKEUP off
785787 vTaskDelay (1 ); // only leave WAKEUP on
786788 gpio_set_level ((gpio_num_t )14 , 0 );// now turn everything off
787789 pState->pwr_on = 0 ;
@@ -1325,28 +1327,34 @@ int bbepSetPanelSize(FASTEPDSTATE *pState, int width, int height, int flags, int
13251327 } // for j
13261328 // Create the lookup tables for 1-bit mode. Allow for inverted and mirrored
13271329 for (int i=0 ; i<256 ; i++) {
1328- uint16_t b, w, u16W, u16B;
1329- u16W = u16B = 0 ;
1330+ uint16_t b, w, bw, u16W, u16B, u16BW ;
1331+ u16W = u16B = u16BW = 0 ;
13301332 for (int j=0 ; j<8 ; j++) {
13311333 // a 1 means do nothing and 0 means move towards black or white (depending on the LUT)
13321334 if (pState->iFlags & BB_PANEL_FLAG_MIRROR_X) {
13331335 if (!(i & (1 <<(7 -j)))) {
13341336 w = 2 ; b = 1 ;
1337+ bw = 1 ;
13351338 } else {
13361339 w = 3 ; b = 3 ;
1340+ bw = 2 ;
13371341 }
13381342 } else {
13391343 if (!(i & (0x80 >>(7 -j)))) {
13401344 w = 2 ; b = 1 ;
1345+ bw = 1 ;
13411346 } else {
13421347 w = 3 ; b = 3 ;
1348+ bw = 2 ;
13431349 }
13441350 }
13451351 u16W |= (w << (j * 2 ));
13461352 u16B |= (b << (j * 2 ));
1353+ u16BW |= (bw << (j * 2 ));
13471354 } // for j
13481355 LUTW_16[i] = __builtin_bswap16 (u16W);
13491356 LUTB_16[i] = __builtin_bswap16 (u16B);
1357+ LUTBW_16[i] = __builtin_bswap16 (u16BW);
13501358 } // for i
13511359return BBEP_SUCCESS;
13521360} /* setPanelSize() */
@@ -1903,25 +1911,29 @@ int bbepPartialUpdate(FASTEPDSTATE *pState, bool bKeepOn, int iStartLine, int iE
19031911 pCur += (pState->native_width / 8 ) - 1 ;
19041912 pPrev += (pState->native_width / 8 ) - 1 ;
19051913 for (n = 0 ; n < pState->native_width / 16 ; n++) {
1906- cur = *pCur--; prev = *pPrev--;
1914+ cur = *pCur--; prev = *pPrev;
1915+ *pPrev-- = cur; // new->old
19071916 diffw = prev & ~cur;
19081917 diffb = ~prev & cur;
19091918 *(uint16_t *)&d[0 ] = LUTW_16[diffw] & LUTB_16[diffb];
19101919
1911- cur = *pCur--; prev = *pPrev--;
1920+ cur = *pCur--; prev = *pPrev;
1921+ *pPrev-- = cur; // new->old
19121922 diffw = prev & ~cur;
19131923 diffb = ~prev & cur;
19141924 *(uint16_t *)&d[2 ] = LUTW_16[diffw] & LUTB_16[diffb];
19151925 d += 4 ;
19161926 }
19171927 } else {
19181928 for (n = 0 ; n < pState->native_width / 16 ; n++) {
1919- cur = *pCur++; prev = *pPrev++;
1929+ cur = *pCur++; prev = *pPrev;
1930+ *pPrev++ = cur; // new->old
19201931 diffw = prev & ~cur;
19211932 diffb = ~prev & cur;
19221933 *(uint16_t *)&d[0 ] = LUTW_16[diffw] & LUTB_16[diffb];
19231934
1924- cur = *pCur++; prev = *pPrev++;
1935+ cur = *pCur++; prev = *pPrev;
1936+ *pPrev++ = cur; // new->old
19251937 diffw = prev & ~cur;
19261938 diffb = ~prev & cur;
19271939 *(uint16_t *)&d[2 ] = LUTW_16[diffw] & LUTB_16[diffb];
@@ -1967,16 +1979,13 @@ int bbepPartialUpdate(FASTEPDSTATE *pState, bool bKeepOn, int iStartLine, int iE
19671979 dp += iDelta;
19681980 iDMAOff ^= (pState->native_width /4 );
19691981 }
1970- // delayMicroseconds(230);
19711982 } // for each pass
19721983
19731984// This clear to neutral step is necessary; do not remove
19741985 bbepClear (pState, BB_CLEAR_NEUTRAL, 1 , NULL );
19751986 if (!bKeepOn) {
19761987 bbepEinkPower (pState, 0 );
19771988 }
1978- int offset = iStartLine * (pState->native_width /8 );
1979- memcpy (&pState->pPrevious [offset], &pState->pCurrent [offset], (pState->native_width /8 ) * (iEndLine - iStartLine+1 ));
19801989
19811990#ifdef SHOW_TIME
19821991 l = millis () - l;
0 commit comments