e7fb5fb38f
- RLCD device.properties: DefaultDark (focus UI visible), fontSize 18
(+28% vs 14: small 10->14, default 14->18, large 18->24, icons 16->20/36->48)
- ST7305 driver: honor invertColor config (was ignored), call
esp_lcd_panel_invert_color after init
- DisplayDevice: add supportsInvertColor + set/get, and
supportsMonochromeThreshold/set/get (ST7305 only)
- EspLcdDisplay: implement invert via panelHandle, and mono threshold via
global g_mono_threshold shared with esp_lvgl_port
- DisplaySettings: new fields invertColor (default true to preserve current
inverted look) and monochromeThreshold (default 60 best for DefaultDark per
user testing, range 20-230)
- Lvgl.cpp: apply invert + threshold at boot from settings
- Display app: add Invert colors switch (if supportsInvertColor) + Mono
threshold slider with live preview and persistence
- esp_lvgl_port_disp.c (components override for hash mismatch): fix B/W
conversion
BEFORE: blue >16 only -> crushed colors, no gray handling
AFTER: proper luminance Y=0.299R+0.587G+0.114B with adjustable threshold
(default 60), no Bayer dithering dots. Crisp text on reflective
- Launcher/button/list wrappers reverted to stock DefaultDark (no white
focus hacks) per user request - focus UI now uses default outline which
survives luminance threshold
Verified on waveshare-esp32-s3-rlcd /dev/cu.usbmodem1101:
- Build 2877200 bytes, flash hash verified
- Invert toggle works, threshold slider live (60 best per test)
- Font bump visible, focus UI visible for button navigation
- No dithering dots
Docs: LVGL mono https://docs.lvgl.io/9.2/porting/display.html#monochrome-displays
Themes: https://docs.lvgl.io/9.2/details/common-widget-features/styles/themes.html
Co-authored-by: Hermes Agent <hermes@noreply>
159 lines
4.8 KiB
C++
159 lines
4.8 KiB
C++
#include "EspLcdDisplay.h"
|
|
#include "EspLcdDisplayDriver.h"
|
|
|
|
#include <Tactility/Logger.h>
|
|
#include <tactility/check.h>
|
|
#include <Tactility/hal/touch/TouchDevice.h>
|
|
#include <cassert>
|
|
#include <esp_lcd_panel_ops.h>
|
|
#include <esp_lvgl_port_disp.h>
|
|
|
|
static const auto LOGGER = tt::Logger("EspLcdDisplay");
|
|
|
|
EspLcdDisplay::~EspLcdDisplay() {
|
|
check(
|
|
displayDriver == nullptr || displayDriver.use_count() < 2, // 1 reference is held by this class
|
|
"DisplayDriver is still in use. This will cause memory access violations."
|
|
);
|
|
}
|
|
|
|
bool EspLcdDisplay::start() {
|
|
if (!createIoHandle(ioHandle)) {
|
|
LOGGER.error("Failed to create IO handle");
|
|
return false;
|
|
}
|
|
|
|
if (!createPanelHandle(ioHandle, panelHandle)) {
|
|
LOGGER.error("Failed to create panel handle");
|
|
esp_lcd_panel_io_del(ioHandle);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool EspLcdDisplay::stop() {
|
|
if (lvglDisplay != nullptr) {
|
|
stopLvgl();
|
|
lvglDisplay = nullptr;
|
|
}
|
|
|
|
if (panelHandle != nullptr && esp_lcd_panel_del(panelHandle) != ESP_OK) {
|
|
return false;
|
|
}
|
|
|
|
if (ioHandle != nullptr && esp_lcd_panel_io_del(ioHandle) != ESP_OK) {
|
|
return false;
|
|
}
|
|
|
|
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
|
|
LOGGER.warn("DisplayDriver is still in use.");
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool EspLcdDisplay::startLvgl() {
|
|
assert(lvglDisplay == nullptr);
|
|
|
|
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
|
|
LOGGER.warn("DisplayDriver is still in use.");
|
|
}
|
|
|
|
auto lvgl_port_config = getLvglPortDisplayConfig(ioHandle, panelHandle);
|
|
|
|
if (isRgbPanel()) {
|
|
auto rgb_config = getLvglPortDisplayRgbConfig(ioHandle, panelHandle);
|
|
lvglDisplay = lvgl_port_add_disp_rgb(&lvgl_port_config , &rgb_config);
|
|
} else {
|
|
lvglDisplay = lvgl_port_add_disp(&lvgl_port_config );
|
|
}
|
|
|
|
auto touch_device = getTouchDevice();
|
|
if (touch_device != nullptr && touch_device->supportsLvgl()) {
|
|
touch_device->startLvgl(lvglDisplay);
|
|
}
|
|
|
|
return lvglDisplay != nullptr;
|
|
}
|
|
|
|
bool EspLcdDisplay::stopLvgl() {
|
|
if (lvglDisplay == nullptr) {
|
|
return false;
|
|
}
|
|
|
|
auto touch_device = getTouchDevice();
|
|
if (touch_device != nullptr) {
|
|
touch_device->stopLvgl();
|
|
}
|
|
|
|
lvgl_port_remove_disp(lvglDisplay);
|
|
lvglDisplay = nullptr;
|
|
return true;
|
|
}
|
|
|
|
std::shared_ptr<tt::hal::display::DisplayDriver> EspLcdDisplay::getDisplayDriver() {
|
|
assert(lvglDisplay == nullptr); // Still attached to LVGL context. Call stopLvgl() first.
|
|
if (displayDriver == nullptr) {
|
|
auto lvgl_port_config = getLvglPortDisplayConfig(ioHandle, panelHandle);
|
|
|
|
tt::hal::display::ColorFormat color_format;
|
|
if (lvgl_port_config.color_format == LV_COLOR_FORMAT_I1) {
|
|
color_format = tt::hal::display::ColorFormat::Monochrome;
|
|
} else if (lvgl_port_config.color_format == LV_COLOR_FORMAT_RGB565) {
|
|
if (rgbElementOrder == LCD_RGB_ELEMENT_ORDER_RGB) {
|
|
if (lvgl_port_config.flags.swap_bytes) {
|
|
color_format = tt::hal::display::ColorFormat::RGB565Swapped;
|
|
} else {
|
|
color_format = tt::hal::display::ColorFormat::RGB565;
|
|
}
|
|
} else {
|
|
if (lvgl_port_config.flags.swap_bytes) {
|
|
color_format = tt::hal::display::ColorFormat::BGR565Swapped;
|
|
} else {
|
|
color_format = tt::hal::display::ColorFormat::BGR565;
|
|
}
|
|
}
|
|
} else if (lvgl_port_config.color_format == LV_COLOR_FORMAT_RGB888) {
|
|
color_format = tt::hal::display::ColorFormat::RGB888;
|
|
} else {
|
|
check(false, "unsupported driver");
|
|
}
|
|
|
|
displayDriver = std::make_shared<EspLcdDisplayDriver>(
|
|
panelHandle,
|
|
lvgl_port_config.hres,
|
|
lvgl_port_config.vres,
|
|
color_format
|
|
);
|
|
}
|
|
return displayDriver;
|
|
}
|
|
|
|
void EspLcdDisplay::setInvertColor(bool invert) {
|
|
currentInvertColor = invert;
|
|
if (panelHandle != nullptr) {
|
|
esp_err_t err = esp_lcd_panel_invert_color(panelHandle, invert);
|
|
if (err != ESP_OK) {
|
|
LOGGER.warn("Failed to invert color: {}", esp_err_to_name(err));
|
|
}
|
|
}
|
|
}
|
|
|
|
bool EspLcdDisplay::supportsMonochromeThreshold() const {
|
|
// Generic EspLcdDisplay doesn't know - subclasses override
|
|
return false;
|
|
}
|
|
|
|
void EspLcdDisplay::setMonochromeThreshold(uint8_t threshold) {
|
|
// Defined in esp_lvgl_port component
|
|
extern uint8_t g_mono_threshold;
|
|
if (threshold == 0) threshold = 1; // avoid 0 meaning default
|
|
g_mono_threshold = threshold;
|
|
}
|
|
|
|
uint8_t EspLcdDisplay::getMonochromeThreshold() const {
|
|
extern uint8_t g_mono_threshold;
|
|
return g_mono_threshold ? g_mono_threshold : 60;
|
|
}
|