From 2dcc6c67a49e17b8dc1cf07d810c26a35a54fa27 Mon Sep 17 00:00:00 2001 From: Laurence Bank Date: Sun, 22 Sep 2024 20:01:56 +0100 Subject: [PATCH] more cleanup --- src/arduino_io.inl | 4 ++- src/bb_ep.inl | 18 +++++++++++ src/bb_ep_gfx.inl | 77 +++++++++++++++++++++++++--------------------- src/bb_epaper.cpp | 17 ++-------- 4 files changed, 65 insertions(+), 51 deletions(-) diff --git a/src/arduino_io.inl b/src/arduino_io.inl index 33ee18d..24a8609 100644 --- a/src/arduino_io.inl +++ b/src/arduino_io.inl @@ -123,7 +123,9 @@ void bbepWriteData(BBEPDISP *pBBEP, uint8_t *pData, int iLen) SPI.transferBytes(pData, NULL, iLen); #else digitalWrite(pBBEP->iCSPin, LOW); - SPI.transfer(pData, iLen); + for (int i=0; iiCSPin, HIGH); #endif } /* bbepWriteData() */ diff --git a/src/bb_ep.inl b/src/bb_ep.inl index 704955e..00c8b0f 100644 --- a/src/bb_ep.inl +++ b/src/bb_ep.inl @@ -1055,6 +1055,24 @@ void bbepSleep(BBEPDISP *pBBEP, int bDeep) pBBEP->is_awake = 0; } /* bbepSleep() */ +void bbepStartWrite(BBEPDISP *pBBEP, int iPlane) +{ +uint8_t u8Cmd; + + if (pBBEP->chip_type == BBEP_CHIP_UC81xx) { + if (iPlane == PLANE_0) + u8Cmd = UC8151_DTM2; + else + u8Cmd = UC8151_DTM1; + } else { // SSD16xx + if (iPlane == PLANE_0) + u8Cmd = SSD1608_WRITE_RAM; + else + u8Cmd = SSD1608_WRITE_ALTRAM; + } + bbepWriteCmd(pBBEP, u8Cmd); +} /* bbepStartWrite() */ + // // More efficient means of sending commands, data and busy-pauses // diff --git a/src/bb_ep_gfx.inl b/src/bb_ep_gfx.inl index 4695cba..89597e3 100644 --- a/src/bb_ep_gfx.inl +++ b/src/bb_ep_gfx.inl @@ -1314,8 +1314,8 @@ void bbepRectangle(BBEPDISP *pBBEP, int x1, int y1, int x2, int y2, uint8_t ucCo } } - if (pBBEP == NULL || pBBEP->ucScreen == NULL) - return; // only works with a back buffer + if (pBBEP == NULL) + return; // invalid - must have BBEPDISP structure if (x1 < 0 || y1 < 0 || x2 < 0 || y2 < 0 || x1 >= pBBEP->width || y1 >= pBBEP->height || x2 >= pBBEP->width || y2 >= pBBEP->height) return; // invalid coordinates @@ -1336,41 +1336,48 @@ void bbepRectangle(BBEPDISP *pBBEP, int x1, int y1, int x2, int y2, uint8_t ucCo } if (bFilled) { - int x, y, iMiddle; - iMiddle = (y2 >> 3) - (y1 >> 3); - ucMask = 0xff << (y1 & 7); - if (iMiddle == 0) // top and bottom lines are in the same row - ucMask &= (0xff >> (7-(y2 & 7))); - d = &pBBEP->ucScreen[iRedOffset + (y1 >> 3)*iPitch + x1]; - // Draw top - for (x = x1; x <= x2; x++) - { - if (ucColor) - *d |= ucMask; - else - *d &= ~ucMask; - d++; - } - if (iMiddle > 1) // need to draw middle part - { - ucMask = (ucColor) ? 0xff : 0x00; - for (y=1; yucScreen[iRedOffset + (y1 >> 3)*iPitch + x1 + (y*iPitch)]; - for (x = x1; x <= x2; x++) - *d++ = ucMask; - } - } - if (iMiddle >= 1) // need to draw bottom part - { - ucMask = 0xff >> (7-(y2 & 7)); - d = &pBBEP->ucScreen[iRedOffset + (y2 >> 3)*iPitch + x1]; - for (x = x1; x <= x2; x++) - { + if (pBBEP->ucScreen) { // has a buffer to fill + int x, y, iMiddle; + iMiddle = (y2 >> 3) - (y1 >> 3); + ucMask = 0xff << (y1 & 7); + if (iMiddle == 0) // top and bottom lines are in the same row + ucMask &= (0xff >> (7-(y2 & 7))); + d = &pBBEP->ucScreen[iRedOffset + (y1 >> 3)*iPitch + x1]; + // Draw top + for (x = x1; x <= x2; x++) { if (ucColor) - *d++ |= ucMask; + *d |= ucMask; else - *d++ &= ~ucMask; + *d &= ~ucMask; + d++; + } + if (iMiddle > 1) { // need to draw middle part + ucMask = (ucColor) ? 0xff : 0x00; + for (y=1; yucScreen[iRedOffset + (y1 >> 3)*iPitch + x1 + (y*iPitch)]; + for (x = x1; x <= x2; x++) + *d++ = ucMask; + } + } + if (iMiddle >= 1) { // need to draw bottom part + ucMask = 0xff >> (7-(y2 & 7)); + d = &pBBEP->ucScreen[iRedOffset + (y2 >> 3)*iPitch + x1]; + for (x = x1; x <= x2; x++) { + if (ucColor) + *d++ |= ucMask; + else + *d++ &= ~ucMask; + } + } + } else { // no buffer + int cx, cy, iPitch; + cx = x2-x1+1; + iPitch = (cx+7)/8; + memset(u8Cache, (ucColor == BBEP_WHITE) ? 0xff:0x00, iPitch); + bbepSetAddrWindow(pBBEP, x1, y1, cx, (y2-y1+1)); + bbepStartWrite(pBBEP, pBBEP->iPlane); + for (cy = y1; cy <= y2; cy++) { // one line at a time + bbepWriteData(pBBEP, u8Cache, iPitch); } } } diff --git a/src/bb_epaper.cpp b/src/bb_epaper.cpp index 4bf4b31..6c6aa08 100644 --- a/src/bb_epaper.cpp +++ b/src/bb_epaper.cpp @@ -130,7 +130,7 @@ uint32_t BBEPAPER::capabilities(void) void BBEPAPER::setRotation(int iRotation) { -// obdSetRotation(&_bbep, iRotation); + bbepSetRotation(&_bbep, iRotation); } /* setRotation() */ int BBEPAPER::getRotation(void) @@ -459,20 +459,7 @@ void BBEPAPER::drawSprite(const uint8_t *pSprite, int cx, int cy, int iPitch, in } void BBEPAPER::startWrite(int iPlane) { -uint8_t u8Cmd; - - if (_bbep.chip_type == BBEP_CHIP_UC81xx) { - if (iPlane == PLANE_0) - u8Cmd = UC8151_DTM2; - else - u8Cmd = UC8151_DTM1; - } else { // SSD16xx - if (iPlane == PLANE_0) - u8Cmd = SSD1608_WRITE_RAM; - else - u8Cmd = SSD1608_WRITE_ALTRAM; - } - bbepWriteCmd(&_bbep, u8Cmd); + bbepStartWrite(&_bbep, iPlane); } /* startWrite() */ void BBEPAPER::writeData(uint8_t *pData, int iLen)