fixes for AVR and rotated fonts

This commit is contained in:
Laurence Bank
2024-10-06 19:21:35 +01:00
parent ceecd49208
commit d669de7c71
3 changed files with 30 additions and 20 deletions
+16 -10
View File
@@ -11,7 +11,8 @@
#include "Roboto_Black_38.h"
#include "Roboto_Black_78.h"
#include <bb_epaper.h>
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
+3 -3
View File
@@ -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
+11 -7
View File
@@ -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<w+7; j+= 8) {
s = u8Cache;
uc0 = 0; // last shifted byte
n = dx & 7; // shift amount
for (j=0; j<w+7; j+= 8) {
uc1 = *s;
uc0 |= (uc1 >> n);
*s++ = uc0;