Skip to content

Commit

Permalink
Fixed drawBMP to handle images larger than 256x256
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurence Bank authored and Laurence Bank committed Aug 10, 2024
1 parent c3889d6 commit cc1278b
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 22 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=OneBitDisplay
version=2.3.1
version=2.3.2
author=Larry Bank
maintainer=Larry Bank
sentence=OLED, LCD and e-paper library for 1-bit per pixel displays.
Expand Down
4 changes: 2 additions & 2 deletions src/OneBitDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void ONE_BIT_DISPLAY::setCursor(int x, int y)
_obd.iCursorY = y;
} /* setCursor() */

int ONE_BIT_DISPLAY::loadBMP(uint8_t *pBMP, int x, int y, int iFG, int iBG)
int ONE_BIT_DISPLAY::loadBMP(const uint8_t *pBMP, int x, int y, int iFG, int iBG)
{
return obdLoadBMP(&_obd, pBMP, x, y, iFG, iBG);
} /* loadBMP() */
Expand All @@ -224,7 +224,7 @@ int ONE_BIT_DISPLAY::drawEPDGFX(int x, int y, int cx, int cy, uint8_t *pPlane0,
return obdDrawEPDGFX(&_obd, x, y, cx, cy, pPlane0, pPlane1);
} /* drawEPDGFX() */

int ONE_BIT_DISPLAY::loadBMP3(uint8_t *pBMP, int x, int y)
int ONE_BIT_DISPLAY::loadBMP3(const uint8_t *pBMP, int x, int y)
{
return obdLoadBMP3(&_obd, pBMP, x, y);
} /* loadBMP3() */
Expand Down
9 changes: 5 additions & 4 deletions src/OneBitDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ enum {
EPD29R_128x296,
EPD29Y_128x296, // DEPG0290YN
EPD293_128x296,
EPD294_128x296, // Waveshare newer 2.9" 1-bit 128x296
EPD42R_400x300,
EPD42R2_400x300, // GDEQ042Z21
EPD213B_104x212,
Expand Down Expand Up @@ -374,8 +375,8 @@ class ONE_BIT_DISPLAY
void setCursor(int x, int y);
void setPower(bool bOn);
int drawEPDGFX(int x, int y, int cx, int cy, uint8_t *pPlane0, uint8_t *pPlane1);
int loadBMP(uint8_t *pBMP, int x, int y, int iFG, int iBG);
int loadBMP3(uint8_t *pBMP, int x, int y);
int loadBMP(const uint8_t *pBMP, int x, int y, int iFG, int iBG);
int loadBMP3(const uint8_t *pBMP, int x, int y);
int16_t getCursorX(void);
int16_t getCursorY(void);
void wake(void);
Expand Down Expand Up @@ -566,15 +567,15 @@ void obdSetContrast(OBDISP *pOBD, unsigned char ucContrast);
// Pass the pointer to the beginning of the BMP file
// First pass version assumes a full screen bitmap
//
int obdLoadBMP(OBDISP *pOBD, uint8_t *pBMP, int x, int y, int iFG, int iBG);
int obdLoadBMP(OBDISP *pOBD, const uint8_t *pBMP, int x, int y, int iFG, int iBG);
//
// load a 4-bpp Windows bitmap
// into memory for 3-color (BLACK/WHITE/RED)
// e-paper displays
// It does a 'best match' of the colors to
// B/W/R
//
int obdLoadBMP3(OBDISP *pOBD, uint8_t *pBMP, int dx, int dy);
int obdLoadBMP3(OBDISP *pOBD, const uint8_t *pBMP, int dx, int dy);
//
// Power up/down the display
// useful for low power situations
Expand Down
97 changes: 89 additions & 8 deletions src/obd.inl
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,27 @@ const uint8_t epd213b_init_sequence_full[] PROGMEM =
0x00 // end of table
}; /* epd213b_init_sequence_full[] */

const uint8_t epd294_init_sequence_full[] PROGMEM =
{
// 0x02, 0x74, 0x54,
// 0x02, 0x7e, 0x3b,
// 0x03, 0x2b, 0x04, 0x63,
// 0x05, 0x0c, 0x8f, 0x8f, 0x8f, 0x3f,
0x04, 0x01, 0x27, 0x01, 0x00,
0x02, 0x11, 0x03,
0x03, 0x44, 0x00, 0x0f,
0x05, 0x45, 0x00, 0x00, 0x27, 0x01,
0x03, 0x21, 0x00, 0x80,
0x02, 0x3c, 0xc0,
0x02, 0x18, 0x80,
0x02, 0x22, 0xb1,
0x01, 0x20,
BUSY_WAIT,
0x02, 0x4e, 0x00,
0x03, 0x4f, 0x00, 0x00,
0x00 // end of table
}; /* epd294_init_sequence_full[] */

const uint8_t epd293_init_sequence_full[] PROGMEM =
{
// 0x01, SSD1608_SW_RESET,
Expand Down Expand Up @@ -1411,6 +1432,28 @@ const uint8_t epd213_lut[] PROGMEM =
};
#endif

static const uint8_t epd294_lut_partial[] PROGMEM = {
0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x80,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x40,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0A,0x0,0x0,0x0,0x0,0x0,0x2,
0x1,0x0,0x0,0x0,0x0,0x0,0x0,
0x1,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x22,0x22,0x22,0x22,0x22,0x22,0x0,0x0,0x0,
//0x22,0x17,0x41,0xB0,0x32,0x36,
};

static const uint8_t epd293_lut_partial[] PROGMEM = {
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down Expand Up @@ -1681,6 +1724,19 @@ void obdSPIInit(OBDISP *pOBD, int iType, int iDC, int iCS, int iReset, int iMOSI
return; // nothing else to do yet
}
#endif // __AVR__
else if (iType == EPD294_128x296)
{
pOBD->native_width = pOBD->width = 128;
pOBD->native_height = pOBD->height = 296;
pOBD->busy_idle = LOW;
pOBD->can_flip = 0;
//pOBD->x_offset = 2; // column byte offset
pOBD->chip_type = OBD_CHIP_SSD16xx;
pOBD->iFlags |= OBD_HAS_FAST_UPDATE;
pOBD->pInitFull = epd294_init_sequence_full;
pOBD->type = EPD293_128x296; // same for the rest
return; // nothing else to do yet
}
else if (iType == EPD42B_400x300)
{
pOBD->native_width = pOBD->width = 400;
Expand Down Expand Up @@ -3523,6 +3579,23 @@ uint8_t *pBuffer;
} // 270
} /* EPDWriteImage4bpp() */
#endif // !WIMPY_MCU
const uint8_t epd294_init_sequence_part[] =
{
0x0b, 0x37, 0,0,0,0,0,0x40,0,0,0,0,
0x04, 0x01, 0x27, 0x01, 0x00,
0x02, 0x11, 0x03,
0x03, 0x44, 0x00, 0x0f,
0x05, 0x45, 0x00, 0x00, 0x27, 0x01,
0x03, 0x21, 0x00, 0x80,
0x02, 0x3c, 0xc0,
0x02, 0x22, 0xc0,
0x01, 0x20,
BUSY_WAIT,
0x02, 0x4e, 0x00,
0x03, 0x4f, 0x00, 0x00,
0x00 // end of sequence
}; /* epd294_init_sequence_part */

const uint8_t epd293_init_sequence_part[] =
{
// 0x01, SSD1608_SW_RESET,
Expand All @@ -3545,7 +3618,7 @@ const uint8_t epd293_init_sequence_part[] =
0x02, 0x4e, 0x00,
0x03, 0x4f, 0x00, 0x00,
0x00 // end of table
}; /* epd293_init_sequence_full[] */
}; /* epd293_init_sequence_part[] */

const uint8_t epd293_lut[] =
{
Expand All @@ -3563,13 +3636,21 @@ void EPD293_Begin(OBDISP *pOBD, int x, int y, int w, int h, int bPartial)
(void)w;
(void)h;
if (bPartial) {
EPDSendCMDSequence(pOBD, epd293_init_sequence_part);
// send LUT
obdWriteCommand(pOBD, 0x32);
memcpy_P(u8Cache, epd293_lut_partial, sizeof(epd293_lut_partial));
RawWriteData(pOBD, u8Cache, sizeof(epd293_lut_partial));
if (pOBD->pInitFull == epd294_init_sequence_full) { // 294
// send LUT
obdWriteCommand(pOBD, 0x32);
memcpy_P(u8Cache, epd294_lut_partial, sizeof(epd294_lut_partial));
RawWriteData(pOBD, u8Cache, sizeof(epd294_lut_partial));
EPDSendCMDSequence(pOBD, epd294_init_sequence_part);
} else {
EPDSendCMDSequence(pOBD, epd293_init_sequence_part);
// send LUT
obdWriteCommand(pOBD, 0x32);
memcpy_P(u8Cache, epd293_lut_partial, sizeof(epd293_lut_partial));
RawWriteData(pOBD, u8Cache, sizeof(epd293_lut_partial));
}
} else {
EPDSendCMDSequence(pOBD, epd293_init_sequence_full);
EPDSendCMDSequence(pOBD, pOBD->pInitFull);
}
} /* EPD293_Begin() */

Expand Down Expand Up @@ -4412,7 +4493,7 @@ int i, tx, ty;
}
RawWriteData(pOBD, uc, 4);
// set ram counter to start of this region
EPD_CMD2(pOBD, SSD1608_SET_RAMXCOUNT, tx);
EPD_CMD2(pOBD, SSD1608_SET_RAMXCOUNT, tx+pOBD->x_offset);
uc[0] = ty;
uc[1] = (ty>>8);
obdWriteCommand(pOBD, SSD1608_SET_RAMYCOUNT);
Expand Down
14 changes: 7 additions & 7 deletions src/obd_gfx.inl
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ static void obdCachedWrite(OBDISP *pOBD, uint8_t *pData, uint8_t u8Len, int bRen
obdCachedFlush(pOBD, bRender); // write the old data
}
memcpy(&u8Cache[u8End], pData, u8Len);
u8End += u8Len;
u8End = u8End + u8Len;

} /* obdCachedWrite() */
//
Expand Down Expand Up @@ -1104,12 +1104,12 @@ uint8_t i;
// draw the 1's bits as the FG color and leave
// the background (0 pixels) unchanged - aka transparent.
//
int obdLoadBMP(OBDISP *pOBD, uint8_t *pBMP, int dx, int dy, int iFG, int iBG)
int obdLoadBMP(OBDISP *pOBD, const uint8_t *pBMP, int dx, int dy, int iFG, int iBG)
{
int16_t i16, cx, cy;
int iOffBits; // offset to bitmap data
int iPitch;
uint8_t x, y, b=0, *s, *d=NULL;
int x, y, iPitch;
uint8_t b=0, *s, *d=NULL;
uint8_t ucFill, dst_mask=0, src_mask;
uint8_t bFlipped = 0;

Expand Down Expand Up @@ -1162,7 +1162,7 @@ uint8_t bFlipped = 0;
if ((y & 7) == 0)
memset(u8Cache, ucFill, sizeof(u8Cache));
}
s = &pBMP[iOffBits + (y*iPitch)];
s = (uint8_t *)&pBMP[iOffBits + (y*iPitch)];
src_mask = 0;
if (!pOBD->ucScreen) // direct to display
{
Expand Down Expand Up @@ -1220,7 +1220,7 @@ uint8_t bFlipped = 0;
// Pass the pointer to the beginning of the BMP file
// First pass version assumes a full screen bitmap
//
int obdLoadBMP3(OBDISP *pOBD, uint8_t *pBMP, int dx, int dy)
int obdLoadBMP3(OBDISP *pOBD, const uint8_t *pBMP, int dx, int dy)
{
int16_t i16, cx, cy, bpp;
int x, y, iOffBits; // offset to bitmap data
Expand Down Expand Up @@ -1288,7 +1288,7 @@ uint8_t ucColorMap[16];
{
dst_mask = 1 << ((y+dy) & 7);
d = &pOBD->ucScreen[(((y+dy)>>3)*iDestPitch)+dx];
s = &pBMP[iOffBits+(y*iPitch)];
s = (uint8_t *)&pBMP[iOffBits+(y*iPitch)];
for (x=0; x<cx; x+=2) // work with pixel pairs
{
b = pgm_read_byte(s++);
Expand Down

0 comments on commit cc1278b

Please sign in to comment.