Skip to content

Commit c3889d6

Browse files
Laurence BankLaurence Bank
authored andcommitted
Added Sharp LCD partial update feature (displayLines)
1 parent 1aa7cb8 commit c3889d6

3 files changed

Lines changed: 34 additions & 28 deletions

File tree

src/OneBitDisplay.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,11 @@ void ONE_BIT_DISPLAY::pushImage(int x, int y, int w, int h, uint16_t *pixels)
572572
(void)x; (void)y; (void)w; (void)h; (void)pixels;
573573
}
574574

575+
void ONE_BIT_DISPLAY::displayLines(int iStartLine, int iLineCount)
576+
{
577+
obdWriteLCDLines(&_obd, iStartLine, iLineCount);
578+
} /* displayLines() */
579+
575580
int ONE_BIT_DISPLAY::displayFast(int x, int y, int cx, int cy) {
576581
if (_obd.type >= EPD42_400x300 && _obd.iFlags & OBD_HAS_FAST_UPDATE) {
577582
obdDumpFast(&_obd, x, y, cx, cy);

src/OneBitDisplay.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ class ONE_BIT_DISPLAY
346346
uint32_t capabilities();
347347
void setContrast(uint8_t ucContrast);
348348
int display(bool bRefresh = true, bool bWait = true);
349+
void displayLines(int iStartLine, int iLineCount);
349350
int displayFast();
350351
int displayFast(int x, int y, int w, int h);
351352
int displayPartial(int x, int y, int w, int h, uint8_t *pBuffer = NULL);
@@ -525,11 +526,9 @@ int obdCopy(OBDISP *pOBD, int iFlags, uint8_t *pDestination);
525526
//
526527
void obdDumpWindow(OBDISP *pOBDSrc, OBDISP *pOBDDest, int srcx, int srcy, int destx, int desty, int width, int height);
527528
//
528-
// Write a single line to a Sharp memory LCD
529-
// You must provide the exact number of bytes needed for a complete line
530-
// e.g. for the 144x168 display, pSrc must provide 144 pixels (18 bytes)
529+
// Write one of more lines to a Sharp memory LCD
531530
//
532-
void obdWriteLCDLine(OBDISP *pOBD, uint8_t *pSrc, int iLine);
531+
void obdWriteLCDLines(OBDISP *pOBD, int iStart, int iCount);
533532
//
534533
// Initializes the display controller into "page mode" on I2C
535534
// If SDAPin and SCLPin are not -1, then bit bang I2C on those pins

src/obd.inl

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,24 +1214,20 @@ int iPitch;
12141214
} /* obdDumpWindow() */
12151215

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

1229-
// if (pOBD == NULL || pSrc == NULL || pOBD->chip_type != OBD_CHIP_SHARP)
1230-
// return; // invalid request
1231-
if (iLine < 0 || iLine >= pOBD->height)
1232-
return;
1227+
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) {
1228+
return; // invalid request
1229+
}
12331230

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

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

1244-
d = &ucLineBuf[1];
1245-
ucLineBuf[0] = pgm_read_byte(&ucMirror[iLine+1]); // current line number
1246-
for (x=0; x<iPitch; x++)
1247-
{
1248-
c = pSrc[0] ^ ucInvert; // we need to brute-force invert it
1249-
*d++ = pgm_read_byte(&ucMirror[c]);
1250-
pSrc++;
1251-
} // for x
1252-
// write this line to the display
1253-
ucLineBuf[iPitch+1] = 0; // end of line
1254-
RawWriteData(pOBD, ucLineBuf, iPitch+2);
1240+
for (y=iStart; y<iStart+iCount; y++) {
1241+
d = &ucLineBuf[1];
1242+
ucMask = 1 << (y & 7);
1243+
s = &pOBD->ucScreen[(y >> 3) * pOBD->native_width];
1244+
ucLineBuf[0] = pgm_read_byte(&ucMirror[y+1]); // current line number
1245+
for (x=0; x<iPitch; x++) {
1246+
uc = 0xff;
1247+
for (j=7; j>=0; j--) {
1248+
c = *s++;
1249+
if (c & ucMask) uc ^= (1 << j);
1250+
}
1251+
*d++ = uc;
1252+
} // for x
1253+
// write this line to the display
1254+
ucLineBuf[iPitch+1] = 0; // end of line
1255+
RawWriteData(pOBD, ucLineBuf, iPitch+2);
1256+
} // for y
12551257
ucLineBuf[0] = 0;
12561258
RawWriteData(pOBD, ucLineBuf, 1); // final transfer
12571259
digitalWrite(pOBD->iCSPin, LOW); // de-activate
1258-
} /* obdWriteLCDLine() */
1260+
} /* obdWriteLCDLines() */
12591261

12601262
//
12611263
// Turn the display on or off

0 commit comments

Comments
 (0)