@@ -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