34b3fc7ec0
Firmware / build (push) Successful in 4m1s
include/ui (SquareLine export: ui_init, placeholder screen, helpers, theme manager, project metadata) is no longer used - every screen is hand-coded. The one live line, the dark default LVGL theme, moves to display_init.cpp. Build filter and include path drop include/ui. Comments, CLAUDE.md and the stale README sections (features, layout, partitions) updated. Verified on the board (USB, dev): Wi-Fi on/forget/scan/join, dark keyboard and dialogs, update check + install of v0.1.5 from the screen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
124 lines
4.5 KiB
C++
124 lines
4.5 KiB
C++
/*
|
|
* Display Initialization Module Implementation
|
|
*/
|
|
|
|
#include "display_init.h"
|
|
#include "display/lvgl_v8_port.h"
|
|
#include "driveline_screen.h"
|
|
#include "config/ota_config.h" // FW_VERSION
|
|
|
|
namespace DisplayInit {
|
|
|
|
static Backlight* g_backlight = nullptr;
|
|
|
|
/**
|
|
* Firmware version, bottom-right on every screen. Lives on lv_layer_top(), which
|
|
* sits above all screens and survives screen switches. Labels aren't
|
|
* clickable, so it never steals touches or swipes from the screen below.
|
|
* Call with the LVGL lock held.
|
|
*/
|
|
static void createVersionLabel() {
|
|
lv_obj_t* lbl = lv_label_create(lv_layer_top());
|
|
lv_label_set_text(lbl, "A " FW_VERSION);
|
|
lv_obj_set_style_text_font(lbl, &lv_font_montserrat_14, 0);
|
|
lv_obj_set_style_text_color(lbl, lv_color_hex(0x808080), 0);
|
|
lv_obj_align(lbl, LV_ALIGN_BOTTOM_RIGHT, -8, -4);
|
|
}
|
|
|
|
void setBacklight(bool on) {
|
|
if (g_backlight == nullptr) return;
|
|
if (on) g_backlight->on();
|
|
else g_backlight->off();
|
|
}
|
|
|
|
// ============================================================================
|
|
// PUBLIC API IMPLEMENTATION
|
|
// ============================================================================
|
|
|
|
DisplayObjects init() {
|
|
Serial.println("[DisplayInit] Starting display initialization...");
|
|
|
|
// Step 1-3: Create and initialize board
|
|
Serial.println("[DisplayInit] Step 1: Creating Board object...");
|
|
Board *board = new Board();
|
|
|
|
Serial.println("[DisplayInit] Step 2: Calling board->init()...");
|
|
board->init();
|
|
Serial.println("[DisplayInit] Step 3: Board init completed");
|
|
|
|
// Step 4-5: Configure framebuffers (if avoid-tearing mode is enabled)
|
|
#if LVGL_PORT_AVOID_TEARING_MODE
|
|
Serial.println("[DisplayInit] Step 4: Configuring LCD frame buffers...");
|
|
auto lcd = board->getLCD();
|
|
lcd->configFrameBufferNumber(LVGL_PORT_DISP_BUFFER_NUM);
|
|
|
|
#if ESP_PANEL_DRIVERS_BUS_ENABLE_RGB && CONFIG_IDF_TARGET_ESP32S3
|
|
auto lcd_bus = lcd->getBus();
|
|
if (lcd_bus->getBasicAttributes().type == ESP_PANEL_BUS_TYPE_RGB) {
|
|
Serial.println("[DisplayInit] Step 5: Configuring bounce buffer...");
|
|
static_cast<BusRGB *>(lcd_bus)->configRGB_BounceBufferSize(lcd->getFrameWidth() * 10);
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
// Step 6: Get backlight object (before board->begin() to control it manually)
|
|
Serial.println("[DisplayInit] Step 6: Getting backlight control...");
|
|
auto backlight = board->getBacklight();
|
|
|
|
// Step 7-8: Start the board
|
|
Serial.println("[DisplayInit] Step 7: Calling board->begin()...");
|
|
if (!board->begin()) {
|
|
Serial.println("[DisplayInit] ERROR: board->begin() failed!");
|
|
Serial.println("[DisplayInit] System halted.");
|
|
while (1) {
|
|
delay(1000);
|
|
}
|
|
}
|
|
Serial.println("[DisplayInit] Step 8: Board initialized successfully!");
|
|
|
|
// Step 9: Turn OFF backlight to prevent white flash
|
|
Serial.println("[DisplayInit] Step 9: Turning off backlight to prevent white flash...");
|
|
if (backlight != nullptr) {
|
|
backlight->off();
|
|
}
|
|
|
|
// Step 10-11: Initialize LVGL
|
|
Serial.println("[DisplayInit] Step 10: Initializing LVGL...");
|
|
Serial.flush();
|
|
lvgl_port_init(board->getLCD(), board->getTouch());
|
|
Serial.println("[DisplayInit] Step 11: LVGL initialized successfully!");
|
|
Serial.flush();
|
|
|
|
// Step 12-13: Theme + boot screen
|
|
Serial.println("[DisplayInit] Step 12: Loading UI...");
|
|
lvgl_port_lock(-1);
|
|
// Dark default theme, blue primary. The hand-coded screens override most
|
|
// styles, but the keyboard, dialogs, text areas, switches and sliders take
|
|
// their base look from it.
|
|
lv_disp_t* disp = lv_disp_get_default();
|
|
lv_disp_set_theme(disp, lv_theme_default_init(disp, lv_palette_main(LV_PALETTE_BLUE),
|
|
lv_palette_main(LV_PALETTE_RED), true, LV_FONT_DEFAULT));
|
|
// Boot screen, loaded while the backlight is still off so there's no flash.
|
|
DrivelineScreen::show();
|
|
createVersionLabel();
|
|
lvgl_port_unlock();
|
|
Serial.println("[DisplayInit] Step 13: UI loaded");
|
|
|
|
// Small delay to ensure UI is rendered
|
|
delay(100);
|
|
|
|
// Step 14: NOW turn on backlight - UI is ready!
|
|
Serial.println("[DisplayInit] Step 14: Turning on backlight...");
|
|
if (backlight != nullptr) {
|
|
backlight->on();
|
|
}
|
|
Serial.println("[DisplayInit] Backlight on - no white flash!");
|
|
Serial.println("[DisplayInit] Display initialization complete!");
|
|
|
|
// Return board and backlight objects for later use
|
|
g_backlight = backlight;
|
|
return {board, backlight};
|
|
}
|
|
|
|
} // namespace DisplayInit
|