Skip to content

Commit

Permalink
Added Sharp LCD partial update feature (displayLines)
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurence Bank authored and Laurence Bank committed Jul 8, 2024
1 parent 1aa7cb8 commit c3889d6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
5 changes: 5 additions & 0 deletions src/OneBitDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ void ONE_BIT_DISPLAY::pushImage(int x, int y, int w, int h, uint16_t *pixels)
(void)x; (void)y; (void)w; (void)h; (void)pixels;
}

void ONE_BIT_DISPLAY::displayLines(int iStartLine, int iLineCount)
{
obdWriteLCDLines(&_obd, iStartLine, iLineCount);
} /* displayLines() */

int ONE_BIT_DISPLAY::displayFast(int x, int y, int cx, int cy) {
if (_obd.type >= EPD42_400x300 && _obd.iFlags & OBD_HAS_FAST_UPDATE) {
obdDumpFast(&_obd, x, y, cx, cy);
Expand Down
7 changes: 3 additions & 4 deletions src/OneBitDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ class ONE_BIT_DISPLAY
uint32_t capabilities();
void setContrast(uint8_t ucContrast);
int display(bool bRefresh = true, bool bWait = true);
void displayLines(int iStartLine, int iLineCount);
int displayFast();
int displayFast(int x, int y, int w, int h);
int displayPartial(int x, int y, int w, int h, uint8_t *pBuffer = NULL);
Expand Down Expand Up @@ -525,11 +526,9 @@ int obdCopy(OBDISP *pOBD, int iFlags, uint8_t *pDestination);
//
void obdDumpWindow(OBDISP *pOBDSrc, OBDISP *pOBDDest, int srcx, int srcy, int destx, int desty, int width, int height);
//
// Write a single line to a Sharp memory LCD
// You must provide the exact number of bytes needed for a complete line
// e.g. for the 144x168 display, pSrc must provide 144 pixels (18 bytes)
// Write one of more lines to a Sharp memory LCD
//
void obdWriteLCDLine(OBDISP *pOBD, uint8_t *pSrc, int iLine);
void obdWriteLCDLines(OBDISP *pOBD, int iStart, int iCount);
//
// Initializes the display controller into "page mode" on I2C
// If SDAPin and SCLPin are not -1, then bit bang I2C on those pins
Expand Down
50 changes: 26 additions & 24 deletions src/obd.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1214,24 +1214,20 @@ int iPitch;
} /* obdDumpWindow() */

//
// Write a single line to a Sharp memory LCD
// You must provide the exact number of bytes needed for a complete line
// e.g. for the 144x168 display, pSrc must provide 144 pixels (18 bytes)
// Write a subset of lines to a Sharp memory LCD
//
void obdWriteLCDLine(OBDISP *pOBD, uint8_t *pSrc, int iLine)
void obdWriteLCDLines(OBDISP *pOBD, int iStart, int iCount)
{
int x;
uint8_t c, ucInvert, *d, ucStart;
uint8_t ucLineBuf[54]; // 400 pixels is max supported width = 50 bytes + 4
int x, y, j;
uint8_t uc, c, ucMask, *s, *d, ucStart;
uint8_t ucLineBuf[56]; // 400 pixels is max supported width = 50 bytes + 4
int iPitch = pOBD->width / 8;
static int iVCOM = 0;

// if (pOBD == NULL || pSrc == NULL || pOBD->chip_type != OBD_CHIP_SHARP)
// return; // invalid request
if (iLine < 0 || iLine >= pOBD->height)
return;
if (pOBD == NULL || pOBD->chip_type != OBD_CHIP_SHARP || pOBD->ucScreen == NULL || iStart < 0 || iStart > pOBD->native_height-1 || iStart+iCount < 0 || iStart+iCount > pOBD->native_height-1) {
return; // invalid request
}

ucInvert = (pOBD->invert) ? 0x00 : 0xff;
digitalWrite(pOBD->iCSPin, HIGH); // active high

ucStart = 0x80; // write command
Expand All @@ -1241,21 +1237,27 @@ void obdWriteLCDLine(OBDISP *pOBD, uint8_t *pSrc, int iLine)
ucLineBuf[0] = ucStart;
RawWriteData(pOBD, ucLineBuf, 1); // write command(01) + vcom(02)

d = &ucLineBuf[1];
ucLineBuf[0] = pgm_read_byte(&ucMirror[iLine+1]); // current line number
for (x=0; x<iPitch; x++)
{
c = pSrc[0] ^ ucInvert; // we need to brute-force invert it
*d++ = pgm_read_byte(&ucMirror[c]);
pSrc++;
} // for x
// write this line to the display
ucLineBuf[iPitch+1] = 0; // end of line
RawWriteData(pOBD, ucLineBuf, iPitch+2);
for (y=iStart; y<iStart+iCount; y++) {
d = &ucLineBuf[1];
ucMask = 1 << (y & 7);
s = &pOBD->ucScreen[(y >> 3) * pOBD->native_width];
ucLineBuf[0] = pgm_read_byte(&ucMirror[y+1]); // current line number
for (x=0; x<iPitch; x++) {
uc = 0xff;
for (j=7; j>=0; j--) {
c = *s++;
if (c & ucMask) uc ^= (1 << j);
}
*d++ = uc;
} // for x
// write this line to the display
ucLineBuf[iPitch+1] = 0; // end of line
RawWriteData(pOBD, ucLineBuf, iPitch+2);
} // for y
ucLineBuf[0] = 0;
RawWriteData(pOBD, ucLineBuf, 1); // final transfer
digitalWrite(pOBD->iCSPin, LOW); // de-activate
} /* obdWriteLCDLine() */
} /* obdWriteLCDLines() */

//
// Turn the display on or off
Expand Down

0 comments on commit c3889d6

Please sign in to comment.