Skip to content

Commit cc1278b

Browse files
Laurence BankLaurence Bank
authored andcommitted
Fixed drawBMP to handle images larger than 256x256
1 parent c3889d6 commit cc1278b

5 files changed

Lines changed: 104 additions & 22 deletions

File tree

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=OneBitDisplay
2-
version=2.3.1
2+
version=2.3.2
33
author=Larry Bank
44
maintainer=Larry Bank
55
sentence=OLED, LCD and e-paper library for 1-bit per pixel displays.

src/OneBitDisplay.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ void ONE_BIT_DISPLAY::setCursor(int x, int y)
214214
_obd.iCursorY = y;
215215
} /* setCursor() */
216216

217-
int ONE_BIT_DISPLAY::loadBMP(uint8_t *pBMP, int x, int y, int iFG, int iBG)
217+
int ONE_BIT_DISPLAY::loadBMP(const uint8_t *pBMP, int x, int y, int iFG, int iBG)
218218
{
219219
return obdLoadBMP(&_obd, pBMP, x, y, iFG, iBG);
220220
} /* loadBMP() */
@@ -224,7 +224,7 @@ int ONE_BIT_DISPLAY::drawEPDGFX(int x, int y, int cx, int cy, uint8_t *pPlane0,
224224
return obdDrawEPDGFX(&_obd, x, y, cx, cy, pPlane0, pPlane1);
225225
} /* drawEPDGFX() */
226226

227-
int ONE_BIT_DISPLAY::loadBMP3(uint8_t *pBMP, int x, int y)
227+
int ONE_BIT_DISPLAY::loadBMP3(const uint8_t *pBMP, int x, int y)
228228
{
229229
return obdLoadBMP3(&_obd, pBMP, x, y);
230230
} /* loadBMP3() */

src/OneBitDisplay.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ enum {
109109
EPD29R_128x296,
110110
EPD29Y_128x296, // DEPG0290YN
111111
EPD293_128x296,
112+
EPD294_128x296, // Waveshare newer 2.9" 1-bit 128x296
112113
EPD42R_400x300,
113114
EPD42R2_400x300, // GDEQ042Z21
114115
EPD213B_104x212,
@@ -374,8 +375,8 @@ class ONE_BIT_DISPLAY
374375
void setCursor(int x, int y);
375376
void setPower(bool bOn);
376377
int drawEPDGFX(int x, int y, int cx, int cy, uint8_t *pPlane0, uint8_t *pPlane1);
377-
int loadBMP(uint8_t *pBMP, int x, int y, int iFG, int iBG);
378-
int loadBMP3(uint8_t *pBMP, int x, int y);
378+
int loadBMP(const uint8_t *pBMP, int x, int y, int iFG, int iBG);
379+
int loadBMP3(const uint8_t *pBMP, int x, int y);
379380
int16_t getCursorX(void);
380381
int16_t getCursorY(void);
381382
void wake(void);
@@ -566,15 +567,15 @@ void obdSetContrast(OBDISP *pOBD, unsigned char ucContrast);
566567
// Pass the pointer to the beginning of the BMP file
567568
// First pass version assumes a full screen bitmap
568569
//
569-
int obdLoadBMP(OBDISP *pOBD, uint8_t *pBMP, int x, int y, int iFG, int iBG);
570+
int obdLoadBMP(OBDISP *pOBD, const uint8_t *pBMP, int x, int y, int iFG, int iBG);
570571
//
571572
// load a 4-bpp Windows bitmap
572573
// into memory for 3-color (BLACK/WHITE/RED)
573574
// e-paper displays
574575
// It does a 'best match' of the colors to
575576
// B/W/R
576577
//
577-
int obdLoadBMP3(OBDISP *pOBD, uint8_t *pBMP, int dx, int dy);
578+
int obdLoadBMP3(OBDISP *pOBD, const uint8_t *pBMP, int dx, int dy);
578579
//
579580
// Power up/down the display
580581
// useful for low power situations

src/obd.inl

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,27 @@ const uint8_t epd213b_init_sequence_full[] PROGMEM =
791791
0x00 // end of table
792792
}; /* epd213b_init_sequence_full[] */
793793

794+
const uint8_t epd294_init_sequence_full[] PROGMEM =
795+
{
796+
// 0x02, 0x74, 0x54,
797+
// 0x02, 0x7e, 0x3b,
798+
// 0x03, 0x2b, 0x04, 0x63,
799+
// 0x05, 0x0c, 0x8f, 0x8f, 0x8f, 0x3f,
800+
0x04, 0x01, 0x27, 0x01, 0x00,
801+
0x02, 0x11, 0x03,
802+
0x03, 0x44, 0x00, 0x0f,
803+
0x05, 0x45, 0x00, 0x00, 0x27, 0x01,
804+
0x03, 0x21, 0x00, 0x80,
805+
0x02, 0x3c, 0xc0,
806+
0x02, 0x18, 0x80,
807+
0x02, 0x22, 0xb1,
808+
0x01, 0x20,
809+
BUSY_WAIT,
810+
0x02, 0x4e, 0x00,
811+
0x03, 0x4f, 0x00, 0x00,
812+
0x00 // end of table
813+
}; /* epd294_init_sequence_full[] */
814+
794815
const uint8_t epd293_init_sequence_full[] PROGMEM =
795816
{
796817
// 0x01, SSD1608_SW_RESET,
@@ -1411,6 +1432,28 @@ const uint8_t epd213_lut[] PROGMEM =
14111432
};
14121433
#endif
14131434

1435+
static const uint8_t epd294_lut_partial[] PROGMEM = {
1436+
0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
1437+
0x80,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
1438+
0x40,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
1439+
0x0,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
1440+
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
1441+
0x0A,0x0,0x0,0x0,0x0,0x0,0x2,
1442+
0x1,0x0,0x0,0x0,0x0,0x0,0x0,
1443+
0x1,0x0,0x0,0x0,0x0,0x0,0x0,
1444+
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
1445+
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
1446+
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
1447+
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
1448+
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
1449+
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
1450+
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
1451+
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
1452+
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
1453+
0x22,0x22,0x22,0x22,0x22,0x22,0x0,0x0,0x0,
1454+
//0x22,0x17,0x41,0xB0,0x32,0x36,
1455+
};
1456+
14141457
static const uint8_t epd293_lut_partial[] PROGMEM = {
14151458
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
14161459
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -1681,6 +1724,19 @@ void obdSPIInit(OBDISP *pOBD, int iType, int iDC, int iCS, int iReset, int iMOSI
16811724
return; // nothing else to do yet
16821725
}
16831726
#endif // __AVR__
1727+
else if (iType == EPD294_128x296)
1728+
{
1729+
pOBD->native_width = pOBD->width = 128;
1730+
pOBD->native_height = pOBD->height = 296;
1731+
pOBD->busy_idle = LOW;
1732+
pOBD->can_flip = 0;
1733+
//pOBD->x_offset = 2; // column byte offset
1734+
pOBD->chip_type = OBD_CHIP_SSD16xx;
1735+
pOBD->iFlags |= OBD_HAS_FAST_UPDATE;
1736+
pOBD->pInitFull = epd294_init_sequence_full;
1737+
pOBD->type = EPD293_128x296; // same for the rest
1738+
return; // nothing else to do yet
1739+
}
16841740
else if (iType == EPD42B_400x300)
16851741
{
16861742
pOBD->native_width = pOBD->width = 400;
@@ -3523,6 +3579,23 @@ uint8_t *pBuffer;
35233579
} // 270
35243580
} /* EPDWriteImage4bpp() */
35253581
#endif // !WIMPY_MCU
3582+
const uint8_t epd294_init_sequence_part[] =
3583+
{
3584+
0x0b, 0x37, 0,0,0,0,0,0x40,0,0,0,0,
3585+
0x04, 0x01, 0x27, 0x01, 0x00,
3586+
0x02, 0x11, 0x03,
3587+
0x03, 0x44, 0x00, 0x0f,
3588+
0x05, 0x45, 0x00, 0x00, 0x27, 0x01,
3589+
0x03, 0x21, 0x00, 0x80,
3590+
0x02, 0x3c, 0xc0,
3591+
0x02, 0x22, 0xc0,
3592+
0x01, 0x20,
3593+
BUSY_WAIT,
3594+
0x02, 0x4e, 0x00,
3595+
0x03, 0x4f, 0x00, 0x00,
3596+
0x00 // end of sequence
3597+
}; /* epd294_init_sequence_part */
3598+
35263599
const uint8_t epd293_init_sequence_part[] =
35273600
{
35283601
// 0x01, SSD1608_SW_RESET,
@@ -3545,7 +3618,7 @@ const uint8_t epd293_init_sequence_part[] =
35453618
0x02, 0x4e, 0x00,
35463619
0x03, 0x4f, 0x00, 0x00,
35473620
0x00 // end of table
3548-
}; /* epd293_init_sequence_full[] */
3621+
}; /* epd293_init_sequence_part[] */
35493622

35503623
const uint8_t epd293_lut[] =
35513624
{
@@ -3563,13 +3636,21 @@ void EPD293_Begin(OBDISP *pOBD, int x, int y, int w, int h, int bPartial)
35633636
(void)w;
35643637
(void)h;
35653638
if (bPartial) {
3566-
EPDSendCMDSequence(pOBD, epd293_init_sequence_part);
3567-
// send LUT
3568-
obdWriteCommand(pOBD, 0x32);
3569-
memcpy_P(u8Cache, epd293_lut_partial, sizeof(epd293_lut_partial));
3570-
RawWriteData(pOBD, u8Cache, sizeof(epd293_lut_partial));
3639+
if (pOBD->pInitFull == epd294_init_sequence_full) { // 294
3640+
// send LUT
3641+
obdWriteCommand(pOBD, 0x32);
3642+
memcpy_P(u8Cache, epd294_lut_partial, sizeof(epd294_lut_partial));
3643+
RawWriteData(pOBD, u8Cache, sizeof(epd294_lut_partial));
3644+
EPDSendCMDSequence(pOBD, epd294_init_sequence_part);
3645+
} else {
3646+
EPDSendCMDSequence(pOBD, epd293_init_sequence_part);
3647+
// send LUT
3648+
obdWriteCommand(pOBD, 0x32);
3649+
memcpy_P(u8Cache, epd293_lut_partial, sizeof(epd293_lut_partial));
3650+
RawWriteData(pOBD, u8Cache, sizeof(epd293_lut_partial));
3651+
}
35713652
} else {
3572-
EPDSendCMDSequence(pOBD, epd293_init_sequence_full);
3653+
EPDSendCMDSequence(pOBD, pOBD->pInitFull);
35733654
}
35743655
} /* EPD293_Begin() */
35753656

@@ -4412,7 +4493,7 @@ int i, tx, ty;
44124493
}
44134494
RawWriteData(pOBD, uc, 4);
44144495
// set ram counter to start of this region
4415-
EPD_CMD2(pOBD, SSD1608_SET_RAMXCOUNT, tx);
4496+
EPD_CMD2(pOBD, SSD1608_SET_RAMXCOUNT, tx+pOBD->x_offset);
44164497
uc[0] = ty;
44174498
uc[1] = (ty>>8);
44184499
obdWriteCommand(pOBD, SSD1608_SET_RAMYCOUNT);

src/obd_gfx.inl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ static void obdCachedWrite(OBDISP *pOBD, uint8_t *pData, uint8_t u8Len, int bRen
572572
obdCachedFlush(pOBD, bRender); // write the old data
573573
}
574574
memcpy(&u8Cache[u8End], pData, u8Len);
575-
u8End += u8Len;
575+
u8End = u8End + u8Len;
576576

577577
} /* obdCachedWrite() */
578578
//
@@ -1104,12 +1104,12 @@ uint8_t i;
11041104
// draw the 1's bits as the FG color and leave
11051105
// the background (0 pixels) unchanged - aka transparent.
11061106
//
1107-
int obdLoadBMP(OBDISP *pOBD, uint8_t *pBMP, int dx, int dy, int iFG, int iBG)
1107+
int obdLoadBMP(OBDISP *pOBD, const uint8_t *pBMP, int dx, int dy, int iFG, int iBG)
11081108
{
11091109
int16_t i16, cx, cy;
11101110
int iOffBits; // offset to bitmap data
1111-
int iPitch;
1112-
uint8_t x, y, b=0, *s, *d=NULL;
1111+
int x, y, iPitch;
1112+
uint8_t b=0, *s, *d=NULL;
11131113
uint8_t ucFill, dst_mask=0, src_mask;
11141114
uint8_t bFlipped = 0;
11151115

@@ -1162,7 +1162,7 @@ uint8_t bFlipped = 0;
11621162
if ((y & 7) == 0)
11631163
memset(u8Cache, ucFill, sizeof(u8Cache));
11641164
}
1165-
s = &pBMP[iOffBits + (y*iPitch)];
1165+
s = (uint8_t *)&pBMP[iOffBits + (y*iPitch)];
11661166
src_mask = 0;
11671167
if (!pOBD->ucScreen) // direct to display
11681168
{
@@ -1220,7 +1220,7 @@ uint8_t bFlipped = 0;
12201220
// Pass the pointer to the beginning of the BMP file
12211221
// First pass version assumes a full screen bitmap
12221222
//
1223-
int obdLoadBMP3(OBDISP *pOBD, uint8_t *pBMP, int dx, int dy)
1223+
int obdLoadBMP3(OBDISP *pOBD, const uint8_t *pBMP, int dx, int dy)
12241224
{
12251225
int16_t i16, cx, cy, bpp;
12261226
int x, y, iOffBits; // offset to bitmap data
@@ -1288,7 +1288,7 @@ uint8_t ucColorMap[16];
12881288
{
12891289
dst_mask = 1 << ((y+dy) & 7);
12901290
d = &pOBD->ucScreen[(((y+dy)>>3)*iDestPitch)+dx];
1291-
s = &pBMP[iOffBits+(y*iPitch)];
1291+
s = (uint8_t *)&pBMP[iOffBits+(y*iPitch)];
12921292
for (x=0; x<cx; x+=2) // work with pixel pairs
12931293
{
12941294
b = pgm_read_byte(s++);

0 commit comments

Comments
 (0)