From d669de7c71da522e12060c41488ebeb6d8151a93 Mon Sep 17 00:00:00 2001 From: Laurence Bank Date: Sun, 6 Oct 2024 19:21:35 +0100 Subject: [PATCH] fixes for AVR and rotated fonts --- examples/atmega_clock/atmega_clock.ino | 26 ++++++++++++++++---------- src/bb_ep.inl | 6 +++--- src/bb_ep_gfx.inl | 18 +++++++++++------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/examples/atmega_clock/atmega_clock.ino b/examples/atmega_clock/atmega_clock.ino index 0d4e87f..2313853 100644 --- a/examples/atmega_clock/atmega_clock.ino +++ b/examples/atmega_clock/atmega_clock.ino @@ -11,7 +11,8 @@ #include "Roboto_Black_38.h" #include "Roboto_Black_78.h" #include -BBEPAPER bbep(EPD42_400x300); +BBEPAPER bbep(EPD295_128x296); +//BBEPAPER bbep(EPD42B_400x300); static int iRunCount = 0; static int iSec, iMin, iHour, iWDay, iMDay, iMon; int iSleepTime; // number of microseconds to sleep in each wakeup phase @@ -23,12 +24,17 @@ int iSleepTime; // number of microseconds to sleep in each wakeup phase #define RTC_ADDR RTC_DS3231_ADDR #define RTC_START_REG 0 // Ugly solder job of Xiao ESP32-C6 and my e-paper adapter -#define PIN_SDA 4 -#define PIN_SCL 3 -#define POWER_PIN 5 -#define PIN_DC 14 +//#define PIN_SDA 4 +//#define PIN_SCL 3 +//#define POWER_PIN 5 +//#define PIN_DC 14 +//#define PIN_BUSY 16 +//#define PIN_RST 15 +// Arduino Pro mini clone +#define PIN_DC 15 #define PIN_BUSY 16 -#define PIN_RST 15 +#define PIN_RST 14 +#define PIN_CS 10 const char *szDays[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; const char *szMonths[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; @@ -140,7 +146,7 @@ void DrawPlane(int bInvert, int iPlane, char *string1, char *string2) iFG = BBEP_BLACK; iBG = BBEP_WHITE; } bbep.setPlane(iPlane); - bbep.fillRect(0,0, bbep.width(), bbep.height(), iBG); // clear both buffers to white for full update + bbep.fillScreen(iBG); // clear both buffers to white for full update bbep.setFont(Roboto_Black_78); bbep.setTextColor(iFG, iBG); bbep.drawString(string1, CENTER_X, 120); @@ -162,9 +168,9 @@ void loop() char szTemp[32] ,szTemp2[32]; int bPartial, iSleepTime, bInvert; - bbep.initIO(PIN_DC, PIN_RST, PIN_BUSY); + bbep.initIO(PIN_DC, PIN_RST, PIN_BUSY, PIN_CS, MOSI, SCK, 4000000); while (1) { - bInvert = 1; + bInvert = 0; if ((iRunCount & 1) == 0) { // get time and update bPartial = ((iRunCount & 0x1f) != 0); rtc_get_time(); @@ -174,7 +180,7 @@ void loop() // the SSD16xx remembers the old properly and just needs to know the new if (bPartial) { // inverted too, with the old time strings DrawPlane(bInvert, PLANE_1, szTemp, szTemp2); - bInvert = 0; + // bInvert = 0; } } // BBEP_CHIP_UC81xx // Print the current hour:minute diff --git a/src/bb_ep.inl b/src/bb_ep.inl index 1159ce0..6641d2e 100644 --- a/src/bb_ep.inl +++ b/src/bb_ep.inl @@ -1133,7 +1133,7 @@ void bbepSleep(BBEPDISP *pBBEP, int bDeep) void bbepStartWrite(BBEPDISP *pBBEP, int iPlane) { - uint8_t u8Cmd; + uint16_t u8Cmd; // AVR crashes w/odd number of bytes for stack vars if (!pBBEP) return; if (pBBEP->chip_type == BBEP_CHIP_UC81xx) { @@ -1147,7 +1147,7 @@ void bbepStartWrite(BBEPDISP *pBBEP, int iPlane) else u8Cmd = SSD1608_WRITE_ALTRAM; } - bbepWriteCmd(pBBEP, u8Cmd); + bbepWriteCmd(pBBEP, (uint8_t)u8Cmd); } /* bbepStartWrite() */ // @@ -1264,7 +1264,7 @@ int bbepRefresh(BBEPDISP *pBBEP, int iMode) bbepWriteCmd(pBBEP, UC8151_PTOU); // partial out (update the entire panel, not just the last memory window) bbepWriteCmd(pBBEP, UC8151_DRF); } else { - const uint8_t u8CMD[3] = {0xf7, 0xc7, 0xff}; // normal, fast, partial + const uint8_t u8CMD[4] = {0xf7, 0xc7, 0xff, 0}; // normal, fast, partial if (pBBEP->iFlags & BBEP_3COLOR) { iMode = REFRESH_FAST; } // 3-color = 0xc7 diff --git a/src/bb_ep_gfx.inl b/src/bb_ep_gfx.inl index fc4c0ce..9c33f89 100644 --- a/src/bb_ep_gfx.inl +++ b/src/bb_ep_gfx.inl @@ -638,9 +638,10 @@ void bbepSetTextWrap(BBEPDISP *pBBEP, int bWrap) // void bbepWriteStringCustom(BBEPDISP *pBBEP, BB_FONT *pFont, int x, int y, char *szMsg, int iColor, uint8_t iPlane) { - int rc, i, h, w, end_y, dx, dy, tx, ty, iSrcPitch, iPitch; - unsigned int c; - uint8_t *s, bInvert = 0; + int rc, i, h, w, j, end_y, dx, dy, tx, ty, iSrcPitch, iPitch; + signed int n; + unsigned int c, bInvert = 0; + uint8_t *s, uc0, uc1; BB_GLYPH *pGlyph; uint8_t *pBits, u8CMD1, u8CMD2, u8CMD, u8EndMask; uint8_t first, last; @@ -687,7 +688,9 @@ void bbepWriteStringCustom(BBEPDISP *pBBEP, BB_FONT *pFont, int x, int y, char * } else { // rotated w = pgm_read_word(&pGlyph->height); h = pgm_read_byte(&pGlyph->width); - dx = x + pgm_read_word(&pGlyph->yOffset); // offset from character UL to start drawing + n = pgm_read_word(&pGlyph->yOffset); // offset from character UL to start drawing + dx = x; + if (-n < w) dx -= (w+n); // since we draw from the baseline dy = y + pgm_read_word(&pGlyph->xOffset); } if ((dy + h) > pBBEP->native_height) { // trim it @@ -748,9 +751,10 @@ void bbepWriteStringCustom(BBEPDISP *pBBEP, BB_FONT *pFont, int x, int y, char * u8Cache[iSrcPitch-1] &= u8EndMask; // clean pixels beyond character width u8Cache[iSrcPitch] = 0; if (dx & 7) { // need to shift it over by 1-7 bits - uint8_t *s = u8Cache, uc1, uc0 = 0; // last shifted byte - uint8_t n = dx & 7; // shift amount - for (int j=0; j> n); *s++ = uc0;