1cba9f30bc
Firmware / build (push) Successful in 10m49s
- ReverseLight: isolated output DO0 (CH422G OC0 -> PC817 -> NPN sink) drives the reverse-lamp relay while the lever is in R on a live bus with ignition on; 10 Hz decision confirmed over 200 ms, written through the panel library's expander object so the backlight cannot undo it; `reverse status|on|off|force` console, default ON (NVS `revlight_en`). Wiki page reverse-lights-output with the wiring. - Sport screen: BMW-style power + torque gauges (lv_meter on a dial-face image, image needle); PNG sources in assets/, tools/png2lvgl.py converter. - Vehicle: final drive ratio + tyre circumference -> road speed, hp from torque; Settings > Vehicle page; `vehicle` console. - Bench simulation (`sim` console) overlays torque / rpm / shaft on the snapshot. - EcuIdent: KWP 1A 86 / 1A 80 read once, stored in NVS, shown on Settings > Vehicle, passive ECU CHANGED? check; `ecu` console. - Ignition fallback from the 0x1D2 lever byte on buses without 0x3B4 (Patrol 2). - Engine data: per-DDE `2C 10` identifier profiles (Patrol 1 vs Patrol 2 rail 00C2 / boost 003A / battery 002F); DiagProbe liveConfigure(). - Wiki: Patrol 2 captures, vehicles page, obd identifier table per DDE, logs.
128 lines
4.7 KiB
C++
128 lines
4.7 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;
|
|
static esp_expander::Base* g_expander = 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);
|
|
}
|
|
|
|
esp_expander::Base* expander() { return g_expander; }
|
|
|
|
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;
|
|
g_expander = board->getIO_Expander() ? board->getIO_Expander()->getBase() : nullptr;
|
|
return {board, backlight};
|
|
}
|
|
|
|
} // namespace DisplayInit
|