refactor(esp32-s3-lcd-43): remove IO expander and use LovyanGFX backlight

This commit is contained in:
2026-02-17 02:13:30 -08:00
parent 246bfe0cb9
commit 2907dac33d
2 changed files with 44 additions and 78 deletions

View File

@@ -1,51 +1,19 @@
// boards/esp32-s3-lcd-43/DisplayDriverGFX.cpp
#include <Arduino.h> #include <Arduino.h>
#include <Wire.h>
#include <ESP_IOExpander_Library.h>
#include "LovyanPins.h" #include "LovyanPins.h"
#include "board_config.h" #include "board_config.h"
#include "DisplayDriverGFX.h" #include "DisplayDriverGFX.h"
// ── Globals ── // ── Globals ──
static LGFX* _gfx = nullptr; static LGFX* _gfx = nullptr;
static ESP_IOExpander* _expander = nullptr;
// ── Forward declarations ── // ── Forward declarations ──
static void initExpander();
static void initDisplay(); static void initDisplay();
// ── Dimensions ── // ── Dimensions ──
static constexpr int DISP_W = 800; static constexpr int DISP_W = 800;
static constexpr int DISP_H = 480; static constexpr int DISP_H = 480;
// ── Expander initialization (from Westcott) ──
static void initExpander() {
Serial.println("IO expander init...");
// Initialize I2C for expander (port 0)
Wire.begin(TOUCH_SDA, TOUCH_SCL);
_expander = new ESP_IOExpander_CH422G(
(i2c_port_t)I2C_NUM_0,
ESP_IO_EXPANDER_I2C_CH422G_ADDRESS
);
_expander->init();
_expander->begin();
// Set all pins to output
_expander->multiPinMode(TP_RST | LCD_BL | LCD_RST | SD_CS | USB_SEL, OUTPUT);
// Reset sequence for LCD
_expander->digitalWrite(LCD_RST, LOW);
delay(50);
_expander->digitalWrite(LCD_RST, HIGH);
delay(150);
// Turn on backlight
_expander->digitalWrite(LCD_BL, HIGH);
Serial.println("IO expander ready");
}
// ── Display initialization ── // ── Display initialization ──
static void initDisplay() { static void initDisplay() {
Serial.println("LovyanGFX init..."); Serial.println("LovyanGFX init...");
@@ -67,13 +35,13 @@ DisplayDriverGFX& DisplayDriverGFX::instance() {
// ── IDisplayDriver implementation ── // ── IDisplayDriver implementation ──
void DisplayDriverGFX::begin() { void DisplayDriverGFX::begin() {
initExpander();
initDisplay(); initDisplay();
} }
void DisplayDriverGFX::setBacklight(bool on) { void DisplayDriverGFX::setBacklight(bool on) {
if (_expander) { if (_gfx) {
_expander->digitalWrite(LCD_BL, on ? HIGH : LOW); // LovyanGFX handles backlight via setBrightness
_gfx->setBrightness(on ? 255 : 0);
} }
} }

View File

@@ -7,7 +7,6 @@ description = "Install shared (platform-independent) libraries"
run = """ run = """
arduino-cli lib install "ArduinoJson@7.4.1" arduino-cli lib install "ArduinoJson@7.4.1"
arduino-cli lib install "NTPClient@3.2.1" arduino-cli lib install "NTPClient@3.2.1"
arduino-cli lib install "ESP32_IO_Expander@0.0.4"
echo "[OK] Shared libraries installed" echo "[OK] Shared libraries installed"
""" """
@@ -78,13 +77,12 @@ description = "Compile ESP32-32E sketch"
depends = ["install-libs"] depends = ["install-libs"]
run = """ run = """
arduino-cli compile \ arduino-cli compile \
--fqbn "esp32:esp32:waveshare_esp32_s3_touch_lcd_43:PSRAM=enabled,FlashSize=16M,USBMode=hwcdc,PartitionScheme=app3M_fat9M_16MB" \ --fqbn "esp32:esp32@2.0.11:esp32:FlashSize=4M,PartitionScheme=default" \
--libraries ./libraries \ --libraries ./libraries \
--libraries ./vendor/esp32-s3-lcd-43 \ --libraries ./vendor/esp32-32e/TFT_eSPI \
--build-property "compiler.cpp.extra_flags=-DDEBUG_MODE -DBOARD_HAS_PSRAM" \ --build-property "compiler.cpp.extra_flags=-DDEBUG_MODE -DBOARD_HAS_PSRAM" \
--build-property "build.extra_flags=-DCONFIG_ESP32S3_OLD_I2C_LEGACY_DEVICE_COMPAT_MODE=1" \
--warnings default \ --warnings default \
./boards/esp32-s3-lcd-43 ./boards/esp32-32e
""" """
[tasks.upload-32e] [tasks.upload-32e]
@@ -105,7 +103,7 @@ arduino-cli monitor --port "${PORT:-/dev/ttyUSB0}" --config baudrate=115200
# ── ESP32-S3-LCD-4.3 ──────────────────────────────────── # ── ESP32-S3-LCD-4.3 ────────────────────────────────────
[tasks.compile-s3-43] [tasks.compile-s3-43]
description = "Compile ESP32-S3-LCD-4.3 sketch" description = "Compile ESP32-S3-LCD-4.3 sketch (Core 2.x)"
depends = ["install-libs"] depends = ["install-libs"]
run = """ run = """
arduino-cli compile \ arduino-cli compile \