Merge branch 'dev' into feature/lilygo-t3-stm32

This commit is contained in:
fdlamotte authored and GitHub committed 2026-11-10 08:22:52 -04:00
commit f40e13a425
178 files changed
+5207 -1141

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
#include "AutoDetectDisplay.h"
#include <MeshCore.h>
int AutoDetectDisplay::getDisplayStatus(TwoWire& wire, uint8_t addr) {
int status = -1;
for(int i = 0; i < 4; i++){
// request display status
wire.beginTransmission(addr);
wire.write((uint8_t)0x00);
// ensure response received
if (wire.endTransmission() != 0) return -1; // expect success
if (wire.requestFrom((int)addr, 1) == 0) return -1; // expect at least 1 byte
// ensure two consecutive reads are the same
int previous = status;
status = wire.read() & 0x0F;
if(status == previous){
break;
}
}
return status;
}
bool AutoDetectDisplay::begin() {
// request status from display address
int status = getDisplayStatus(Wire, DISPLAY_ADDRESS);
MESH_DEBUG_PRINTLN("AutoDetectDisplay: status=0x%02X", status);
// detect SH1106
if(status == 0x00 || status == 0x08){
MESH_DEBUG_PRINTLN("AutoDetectDisplay: SH1106 detected");
_impl = &_sh1106;
return _sh1106.begin();
}
// fallback to SSD1306
MESH_DEBUG_PRINTLN("AutoDetectDisplay: falling back to SSD1306");
_impl = &_ssd1306;
return _ssd1306.begin();
}
+32
View File
@@ -0,0 +1,32 @@
#pragma once
#include "DisplayDriver.h"
#include "SSD1306Display.h"
#include "SH1106Display.h"
// Auto detects SH1106 display at runtime, otherwise falls back to using SSD1306
class AutoDetectDisplay : public DisplayDriver {
DisplayDriver* _impl;
SSD1306Display _ssd1306;
SH1106Display _sh1106;
int getDisplayStatus(TwoWire& wire, uint8_t addr);
public:
AutoDetectDisplay() : DisplayDriver(128, 64), _impl(&_ssd1306) { }
bool begin();
bool isOn() override { return _impl->isOn(); }
void turnOn() override { _impl->turnOn(); }
void turnOff() override { _impl->turnOff(); }
void clear() override { _impl->clear(); }
void startFrame(ColorVal bkg = UIColor::window_bkg) override { _impl->startFrame(bkg); }
void setTextSize(int sz) override { _impl->setTextSize(sz); }
void setColor(ColorVal c) override { _impl->setColor(c); }
void setCursor(int x, int y) override { _impl->setCursor(x, y); }
void print(const char* str) override { _impl->print(str); }
void fillRect(int x, int y, int w, int h) override { _impl->fillRect(x, y, w, h); }
void drawRect(int x, int y, int w, int h) override { _impl->drawRect(x, y, w, h); }
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override { _impl->drawXbm(x, y, bits, w, h); }
uint16_t getTextWidth(const char* str) override { return _impl->getTextWidth(str); }
void endFrame() override { _impl->endFrame(); }
};
+2
View File
@@ -25,7 +25,9 @@ public:
virtual bool isEink() { return false; } // default to non-eink, override in eink drivers
virtual void forceFullRefresh() {} // next refresh will be full for eink
virtual void turnOn() = 0;
virtual void turnOn(int max_partial) { turnOn(); }
virtual void turnOff() = 0;
virtual void turnOff(bool blank) { turnOff(); }
virtual void clear() = 0;
virtual void startFrame(ColorVal bkg = UIColor::window_bkg) = 0;
virtual void setTextSize(int sz) = 0;
+48 -26
View File
@@ -1,11 +1,6 @@
#include "GxEPDDisplay.h"
#ifdef EXP_PIN_BACKLIGHT
#include <PCA9557.h>
extern PCA9557 expander;
#endif
#ifndef DISPLAY_ROTATION
#define DISPLAY_ROTATION 3
#endif
@@ -52,7 +47,7 @@ bool GxEPDDisplay::begin() {
}
display.setPartialWindow(0, 0, display.width(), display.height());
resetPartialRefreshCounter();
_partial_refresh_count = 0;
#if DISP_BACKLIGHT
digitalWrite(DISP_BACKLIGHT, LOW);
@@ -65,29 +60,55 @@ bool GxEPDDisplay::begin() {
void GxEPDDisplay::turnOn() {
if (!_init) begin();
#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN)
digitalWrite(DISP_BACKLIGHT, HIGH);
#elif defined(EXP_PIN_BACKLIGHT) && !defined(BACKLIGHT_BTN)
expander.digitalWrite(EXP_PIN_BACKLIGHT, HIGH);
#endif
if (!_isOn) {
_isOn = true;
}
}
void GxEPDDisplay::turnOff() {
#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN)
digitalWrite(DISP_BACKLIGHT, LOW);
#elif defined(EXP_PIN_BACKLIGHT) && !defined(BACKLIGHT_BTN)
expander.digitalWrite(EXP_PIN_BACKLIGHT, LOW);
#endif
void GxEPDDisplay::turnOn(int max_partial) {
setMaxPartialRefresh(max_partial);
turnOn();
}
// 24x24 sleep icon, MSB-first (matches GxEPDDisplay::drawXbm)
static const uint8_t sleep_icon_24x24[] = {
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0xe0, 0x0e, 0x03, 0xc0, 0x18,
0x0f, 0x80, 0x70, 0x1f, 0x80, 0xff, 0x3f, 0x80, 0xff, 0x3f, 0x00, 0x00,
0x7f, 0x3f, 0x00, 0x7f, 0x3f, 0x00, 0xff, 0x0e, 0x00, 0xff, 0x1c, 0x7c,
0xff, 0xbf, 0x7c, 0xff, 0xbf, 0x38, 0xff, 0xc0, 0x7c, 0xff, 0xe0, 0x7c,
0xff, 0xf0, 0x00, 0x7f, 0xfc, 0x00, 0x7f, 0xff, 0xf8, 0x3f, 0xff, 0xf0,
0x1f, 0xff, 0xf0, 0x0f, 0xff, 0xe0, 0x07, 0xff, 0x80, 0x01, 0xff, 0x00
};
void GxEPDDisplay::drawSleepIcon() {
const int W = 24, H = 24;
int x = (int)(display.width() / scale_x) - W; // top-right, logical coordinates
int y = 0;
display.fillRect((x - 5) * scale_x - 1, y * scale_y, (W+5) * scale_x + 2, (H-2) * scale_y + 1, GxEPD_WHITE);
_curr_color = GxEPD_BLACK;
drawXbm(x, y, sleep_icon_24x24, W, H);
display.display(true);
}
void GxEPDDisplay::turnOff(bool blank) {
if (blank) {
blankScreen();
} else {
drawSleepIcon();
}
_isOn = false;
last_display_crc_value=0;
}
void GxEPDDisplay::blankScreen() {
// do full refresh before powering off to clear screen
// no full refresh needed at wakeup
display.clearScreen(0xFF); // Clears microcontroller side RAM
display.writeScreenBuffer(0xFF); // Forces 0xFF (White) into the display controller's history registers
resetPartialRefreshCounter();
last_display_crc_value=0;
_partial_refresh_count = 0;
last_display_crc_value = 0;
// we can hibernate as screen has been cleaned
display.hibernate();
}
@@ -101,15 +122,18 @@ void GxEPDDisplay::startFrame(ColorVal bkg) {
display.fillScreen(bkg);
display.setTextColor(_curr_color = UIColor::primary_txt);
display_crc.reset();
if (_cycles_before_full_refresh != 0) {
display.setPartialWindow(0, 0, display.width(), display.height());
} else {
if (_force_full_refresh
|| (_max_partial_refresh > 0
&& _partial_refresh_count >= _max_partial_refresh)) {
// forces a full wipe of the screen ...
display.clearScreen(0xFF); // Clears microcontroller side RAM
display.writeScreenBuffer(0xFF); // Forces 0xFF (White) into the display controller's history registers
// we'll need a partial refresh after that (whatever crc value is)
last_display_crc_value = 0;
resetPartialRefreshCounter();
_partial_refresh_count = 0;
_force_full_refresh = false;
} else {
display.setPartialWindow(0, 0, display.width(), display.height());
}
}
@@ -216,9 +240,7 @@ void GxEPDDisplay::endFrame() {
uint32_t crc = display_crc.finalize();
if (crc != last_display_crc_value) {
display.display(true);
if (_cycles_before_full_refresh > 0) {
_cycles_before_full_refresh--;
}
_partial_refresh_count++;
}
last_display_crc_value = crc;
}
+10 -11
View File
@@ -16,12 +16,6 @@
#include "DisplayDriver.h"
#ifndef EINK_MAX_PARTIAL_REFRESH
// 60 to prevent ghosting when refreshing every minute ...
// set to -1 to disable the counter
#define EINK_MAX_PARTIAL_REFRESH -1
#endif
class GxEPDDisplay : public DisplayDriver {
#if defined(EINK_DISPLAY_MODEL)
@@ -42,8 +36,9 @@ class GxEPDDisplay : public DisplayDriver {
uint16_t _curr_color;
CRC32 display_crc;
int last_display_crc_value = 0;
int _cycles_before_full_refresh;
int max_partial_refresh = EINK_MAX_PARTIAL_REFRESH; // so this can be changed by an option after
bool _force_full_refresh = false;
int _partial_refresh_count = 0;
int _max_partial_refresh = 0;
public:
#if defined(EINK_DISPLAY_MODEL)
@@ -56,10 +51,13 @@ public:
bool isOn() override { return _isOn; }
bool isEink() override { return true; }
void forceFullRefresh() override { _cycles_before_full_refresh = 0; };
void resetPartialRefreshCounter() { _cycles_before_full_refresh = max_partial_refresh; };
void forceFullRefresh() override { _force_full_refresh = true; }
void turnOn(int max_partial) override;
void turnOn() override;
void turnOff() override;
void turnOff(bool blank) override;
void turnOff() override { turnOff(false); }
virtual void blankScreen();
virtual void setMaxPartialRefresh(int count) {_max_partial_refresh = count; }
void clear() override;
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override;
@@ -69,6 +67,7 @@ public:
void fillRect(int x, int y, int w, int h) override;
void drawRect(int x, int y, int w, int h) override;
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override;
void drawSleepIcon();
uint16_t getTextWidth(const char* str) override;
void endFrame() override;
};
+9 -9
View File
@@ -10,15 +10,15 @@ bool SH1106Display::i2c_probe(TwoWire &wire, uint8_t addr)
}
// Color scheme
ColorVal UIColor::window_bkg = SH110X_BLACK;
ColorVal UIColor::title_bkg = SH110X_BLACK;
ColorVal UIColor::title_txt = SH110X_WHITE;
ColorVal UIColor::primary_txt = SH110X_WHITE;
ColorVal UIColor::secondary_txt = SH110X_WHITE;
ColorVal UIColor::warning_txt = SH110X_WHITE;
ColorVal UIColor::popup_bkg = SH110X_BLACK;
ColorVal UIColor::popup_txt = SH110X_WHITE;
ColorVal UIColor::corp_blue = SH110X_WHITE;
__attribute__((weak)) ColorVal UIColor::window_bkg = SH110X_BLACK;
__attribute__((weak)) ColorVal UIColor::title_bkg = SH110X_BLACK;
__attribute__((weak)) ColorVal UIColor::title_txt = SH110X_WHITE;
__attribute__((weak)) ColorVal UIColor::primary_txt = SH110X_WHITE;
__attribute__((weak)) ColorVal UIColor::secondary_txt = SH110X_WHITE;
__attribute__((weak)) ColorVal UIColor::warning_txt = SH110X_WHITE;
__attribute__((weak)) ColorVal UIColor::popup_bkg = SH110X_BLACK;
__attribute__((weak)) ColorVal UIColor::popup_txt = SH110X_WHITE;
__attribute__((weak)) ColorVal UIColor::corp_blue = SH110X_WHITE;
bool SH1106Display::begin()
{