more cleanup

This commit is contained in:
Laurence Bank
2024-09-22 20:01:56 +01:00
parent 0d28a94f7f
commit 2dcc6c67a4
4 changed files with 65 additions and 51 deletions
+3 -1
View File
@@ -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; i<iLen; i++) { // Arduino clobbers the data (duplex)
SPI.transfer(pData[i]);
}
digitalWrite(pBBEP->iCSPin, HIGH);
#endif
} /* bbepWriteData() */
+18
View File
@@ -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
//
+42 -35
View File
@@ -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; y<iMiddle; y++)
{
d = &pBBEP->ucScreen[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; y<iMiddle; y++) {
d = &pBBEP->ucScreen[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);
}
}
}
+2 -15
View File
@@ -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)