The upstream merge switched SH1106Display::begin() to probe-then-init. On the T-Beam S3 Supreme the OLED bus can NAK a cold address probe, so begin() bailed before display.begin() ever ran, and UITask::begin()'s unconditional turnOn() then drove Adafruit_GrayOLED with a null bus device: bogus gpio_set_level(227) followed by a LoadProhibited boot loop. Restore the proven S3 Supreme bring-up order (Adafruit init with reset sequence first, then settle the bus and verify), and track begin() success so turnOn/turnOff/clear are safe no-ops when the display never initialised - a failed or absent display now boots headless instead of crash-looping. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
120 lines
2.9 KiB
C++
120 lines
2.9 KiB
C++
#include "SH1106Display.h"
|
|
#include <Adafruit_GrayOLED.h>
|
|
#include "Adafruit_SH110X.h"
|
|
|
|
bool SH1106Display::i2c_probe(TwoWire &wire, uint8_t addr)
|
|
{
|
|
wire.beginTransmission(addr);
|
|
uint8_t error = wire.endTransmission();
|
|
return (error == 0);
|
|
}
|
|
|
|
// 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;
|
|
|
|
bool SH1106Display::begin()
|
|
{
|
|
#if defined(ESP32) && defined(TBEAM_SUPREME_SX1262) && defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
|
|
// The S3 Supreme OLED bus NAKs cold address probes on some boards, so run the
|
|
// Adafruit init (with its reset sequence) first, then settle the bus before
|
|
// verifying the display responds.
|
|
_began = display.begin(DISPLAY_ADDRESS, true);
|
|
Wire.begin(PIN_BOARD_SDA, PIN_BOARD_SCL);
|
|
Wire.setClock(100000);
|
|
_began = _began && i2c_probe(Wire, DISPLAY_ADDRESS);
|
|
#else
|
|
// Wire must already be initialised by board.begin() before this is called.
|
|
// Boards with non-standard SH1106 addresses should define DISPLAY_ADDRESS
|
|
// in their variant/platformio configuration.
|
|
_began = i2c_probe(Wire, DISPLAY_ADDRESS) && display.begin(DISPLAY_ADDRESS, true);
|
|
#endif
|
|
return _began;
|
|
}
|
|
|
|
void SH1106Display::turnOn()
|
|
{
|
|
if (!_began) return; // display.begin() never ran; oled_command would crash on a null bus device
|
|
display.oled_command(SH110X_DISPLAYON);
|
|
_isOn = true;
|
|
}
|
|
|
|
void SH1106Display::turnOff()
|
|
{
|
|
if (!_began) return;
|
|
display.oled_command(SH110X_DISPLAYOFF);
|
|
_isOn = false;
|
|
}
|
|
|
|
void SH1106Display::clear()
|
|
{
|
|
if (!_began) return;
|
|
display.clearDisplay();
|
|
display.display();
|
|
}
|
|
|
|
void SH1106Display::startFrame(ColorVal bkg)
|
|
{
|
|
display.clearDisplay(); // TODO: apply 'bkg'
|
|
_color = SH110X_WHITE;
|
|
display.setTextColor(_color);
|
|
display.setTextSize(1);
|
|
display.cp437(true); // Use full 256 char 'Code Page 437' font
|
|
}
|
|
|
|
void SH1106Display::setTextSize(int sz)
|
|
{
|
|
display.setTextSize(sz);
|
|
}
|
|
|
|
void SH1106Display::setColor(ColorVal c)
|
|
{
|
|
_color = c;
|
|
display.setTextColor(_color);
|
|
}
|
|
|
|
void SH1106Display::setCursor(int x, int y)
|
|
{
|
|
display.setCursor(x, y);
|
|
}
|
|
|
|
void SH1106Display::print(const char *str)
|
|
{
|
|
display.print(str);
|
|
}
|
|
|
|
void SH1106Display::fillRect(int x, int y, int w, int h)
|
|
{
|
|
display.fillRect(x, y, w, h, _color);
|
|
}
|
|
|
|
void SH1106Display::drawRect(int x, int y, int w, int h)
|
|
{
|
|
display.drawRect(x, y, w, h, _color);
|
|
}
|
|
|
|
void SH1106Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h)
|
|
{
|
|
display.drawBitmap(x, y, bits, w, h, _color);
|
|
}
|
|
|
|
uint16_t SH1106Display::getTextWidth(const char *str)
|
|
{
|
|
int16_t x1, y1;
|
|
uint16_t w, h;
|
|
display.getTextBounds(str, 0, 0, &x1, &y1, &w, &h);
|
|
return w;
|
|
}
|
|
|
|
void SH1106Display::endFrame()
|
|
{
|
|
display.display();
|
|
}
|