Retire SquareLine: hand-coded gauge screen (oil quadrant dropped), LVGL lock, updates on change only; LVGL pool in PSRAM, millis tick, log off; 16 MB flash + OTA partitions; docs and wiki

This commit is contained in:
2026-09-27 18:50:44 +02:00
parent bde1f57f62
commit de6752d558
43 changed files with 439 additions and 19804 deletions
+28 -19
View File
@@ -29,10 +29,10 @@ Serial goes through the onboard **CH343 USB-UART chip on UART0**, so the port ap
### Tasks and cores
- **Core 1**: `lvglTask()` calls `DisplayInit::update()` every 5 ms (LVGL tick + handler). The Arduino `loop()` also runs on Core 1 (`ARDUINO_RUNNING_CORE=1`) and is where all UI updates happen: it polls `UARTReceiver` and writes labels/icons.
- **Core 0**: the UART receiver task (byte-level framing state machine) and the Wi-Fi/ESP-NOW receive callback. Both hand complete frames to `UARTReceiver::processFrame()`, which validates, dedupes DATA frames on `packet_id`, and caches CONFIG frames. Neither touches LVGL. Shared data is guarded by `g_data_mutex` inside `uart_receiver.cpp`.
- **Core 1**: `lvglTask()` calls `DisplayInit::update()` every 5 ms (`lv_timer_handler()` under the LVGL lock; the tick comes from `millis()` via `LV_TICK_CUSTOM`). The Arduino `loop()` also runs on Core 1 (`ARDUINO_RUNNING_CORE=1`) and drives the screen: every 200 ms it calls `GaugeScreen::update()` and `DebugMonitor::tick()`.
- **Core 0**: the UART receiver task (byte-level framing state machine) and the Wi-Fi/ESP-NOW receive callback. Both hand complete frames to `UARTReceiver::processFrame()`, which validates, dedupes DATA frames on `packet_id`, and caches CONFIG frames. Neither touches LVGL (the debug flag is only *recorded* there). Shared data is guarded by `g_data_mutex` inside `uart_receiver.cpp`.
There is **no LVGL port lock** in this project (unlike Controller A). Keep every LVGL call in `loop()` or `lvglTask()`; if you add a task that must update the UI, add a mutex around `lv_*` calls first.
**LVGL lock** (added 2026-09-27, same rule as Controller A's `lvgl_port_lock()`): `DisplayInit::lock(timeout_ms)` / `unlock()`, a recursive mutex. `lvglTask` holds it while rendering; every `lv_*` call anywhere else must hold it too. Before it existed, `loop()` wrote labels while the higher-priority LVGL task could preempt mid-call - the bug class that froze A.
### Modules
@@ -40,19 +40,27 @@ There is **no LVGL port lock** in this project (unlike Controller A). Keep every
src/
main.cpp # setup(), loop(): UI update from received data, warning thresholds
modules/
display_init.cpp/.h # LovyanGFX LGFX class (ST7789VW), LVGL init, circular mask, backlight PWM
display_init.cpp/.h # LovyanGFX LGFX class (ST7789VW), LVGL init + lock, backlight PWM
gauge_screen.cpp/.h # THE screen, hand-coded LVGL: coolant, gearbox oil, gear (pulses while shifting), battery
uart_receiver.cpp # Link receiver: UART1 framing task + processFrame() shared with ESP-NOW; dedupe, stats, config cache
espnow_receiver.cpp # ESP-NOW leg: STA mode, channel hopping while silent, feeds processFrame()
gauge_outputs.cpp # Patrol gauges: tach on IO7 (LEDC ch2), coolant PWM on IO8 (LEDC ch4), NVS-cached config
debug_monitor.cpp # shows/hides LVGL perf+mem monitors, mirrors A's debug_enabled flag
gauge_outputs.cpp # Patrol gauges: tach on IO7 (hardware-timer ISR), coolant PWM on IO8 (LEDC ch4), NVS-cached config
debug_monitor.cpp # shows/hides LVGL perf+mem monitors from A's debug_enabled flag (recorded by the receiver, applied in loop)
assets/
assets.h # LV_FONT_DECLARE / LV_IMG_DECLARE for the files below
fonts/ # Ubuntu Light 35 (values) and Ubuntu Bold 110 (gear) - plain LVGL font arrays
images/ # 3 status icons x normal/red - plain LVGL image arrays
include/
config/lv_conf.h # LVGL 8.4.0 config (RGB565, dark theme, arc/label/led/meter widgets)
config/lv_conf.h # LVGL 8.4.0 config (RGB565, dark theme, 128 KB pool in PSRAM, millis() tick, log off)
modules/uart_receiver.h, espnow_receiver.h, gauge_outputs.h, debug_monitor.h
protocol/automotive_data.h # SHARED packet contract — copied from Controller A, must match its version
ui/ # SquareLine Studio exports (ui.c/h, screens/, components/, fonts/)
```
**DisplayInit** — `init()`, `update()`, `setBrightness(0–255)`, `getBrightness()`. Default brightness 128. `DISPLAY_RADIUS 120` defines the circular mask.
**UI**: the single screen is hand-coded in `src/modules/gauge_screen.cpp` (SquareLine Studio was retired on 2026-09-27; `include/ui/` is gone - do not reintroduce a UI generator). The font and icon arrays it uses were kept from the old export, symbol names unchanged, under `src/assets/`. The engine-oil quadrant was dropped the same day: this engine has no oil temperature sensor.
**DisplayInit** — `init()`, `update()`, `lock(timeout_ms)` / `unlock()`, `setBrightness(0–255)`, `getBrightness()`. Default brightness 128. `DISPLAY_RADIUS 120` defines the circular mask.
**GaugeScreen** — `init()` builds and loads the screen once; `update(data, link_ok)` at 5 Hz writes a label, colour or icon **only when it changed** (`lv_label_set_text()` and style setters invalidate even for identical values, and every redraw is SPI time). Gear label: engaged gear, or the target gear pulsing while `target != engaged`, red on the mismatch alert; icons red from A's alert bits; everything N/A when the link is lost.
**UARTReceiver** — `init()`, `processFrame(frame, len, source)`, `getLatestData()`, `getStats()` (applied / per-transport / duplicate / config counts, checksum / framing / version errors, last times), `isConnected()`, `isSourceAlive(source)`, `getConfig()` + `getConfigSeq()`. Link lost after 1000 ms without an applied DATA frame on any transport.
@@ -60,7 +68,7 @@ include/
**GaugeOutputs** — `init()`, `applyConfig(cfg, persist)`, `update(data, link_ok)` at 5 Hz, `printStatus()`. Tach = `rpm × ppr / 60 × (1 + trim)` at 50 % duty on LEDC channel 2 (timer 1); coolant = `slope × T + offset` 8-bit duty at `temp_pwm_hz` on channel 4 (timer 2). Channels 0/1 (timer 0) belong to the LovyanGFX backlight — never reuse them. Both outputs low when the link is down, the value is invalid, the output is disabled, or T is below `temp_min_c`; A's override forces fixed values. Last config cached in NVS namespace `gaugecfg`.
**DebugMonitor** — `init()`, `setVisible(bool)`, `isVisible()`. Driven by the `debug_enabled` byte in each packet, so Controller A's debug toggle controls B's overlays.
**DebugMonitor** — `init()`, `setVisible(bool)` (records only; called from the receiver), `tick()` (applies under the LVGL lock; called from loop), `isVisible()`. Driven by the `debug_enabled` byte in each packet, so Controller A's debug toggle controls B's overlays.
### UART packet (shared with Controller A)
@@ -80,7 +88,7 @@ Alert thresholds live on A; B turns icons red from the `alerts` bits only. The g
| 43 / 44 | UART0 → CH343 USB bridge (debug console) — not available for the link |
| IO1 | UART1 RX from Controller A (left header, pin 4) |
| IO2 | UART1 TX — unused, link is receive-only |
| IO7 | Tachometer pulse output (GaugeOutputs, LEDC ch 2) |
| IO7 | Tachometer pulse output (GaugeOutputs, hardware-timer ISR, phase-continuous) |
| IO8 | Coolant gauge PWM output (GaugeOutputs, LEDC ch 4) |
**Header pinout** (USB-C at top): left 5V · GND · 3V3 · IO1 · IO2 · IO3 · IO4 · IO5; right IO14 · IO13 · IO12 · IO11 · IO10 · IO9 · IO8 · IO7. Free for new features: IO4, IO5, IO9–IO14 (IO3 is a strapping pin, avoid). Gauge driver design and calibration notes: `wiki/pages/patrol-gauge-outputs.md`.
@@ -91,22 +99,23 @@ Pins are set in `src/modules/display_init.cpp` and `platformio.ini` (`-DUART_RX_
- `espressif32@^6.0.0`, Arduino framework, board `esp32-s3-devkitc-1` with `board_build.arduino.memory_type = qio_opi`, `psram_type = opi`
- `-DARDUINO_RUNNING_CORE=1`, `-DBOARD_HAS_PSRAM`, `-DDISPLAY_WIDTH=240 -DDISPLAY_HEIGHT=240`
- `build_src_filter` pulls `include/ui/*` and `include/display/*` into the build
- `build_src_filter` pulls `src/modules/*` and `src/assets/*` into the build
- Flash declared as **16 MB** with `default_16MB.csv` (two 6.5 MB OTA app slots, NVS at 0x9000 as before) - the generic devkitc-1 profile assumed 8 MB
- Libraries: `lovyan03/LovyanGFX@^1.1.0`, `lvgl/lvgl@^8.4.0`
## SquareLine Studio
## Screen rules
- Export to **`include/ui/`**, never to `src/` (it would overwrite `main.cpp`).
- Access widgets through the exported `ui_*` / `uic_*` pointers; always NULL-check before use.
- Manual edits inside `include/ui/` are lost on the next export — put logic in `main.cpp`.
- Init order: `DisplayInit::init()` → `ui_init()` → create `lvglTask`. Do not overwrite label text in `loop()` unless intended.
- Colour depth must stay `LV_COLOR_DEPTH 16` (SquareLine exports RGB565).
- Init order: `DisplayInit::init()` → `GaugeScreen::init()` → create `lvglTask`.
- Hold `DisplayInit::lock()` around every `lv_*` call outside `lvglTask`; never call LVGL from the receiver task or the ESP-NOW callback.
- Write a label or style only when the value changed (`setText()` / `setIcon()` in `gauge_screen.cpp` do this).
- Screens are built once and kept; do not delete and rebuild them on the fly (dangling pointers froze Controller A).
- Colour depth stays `LV_COLOR_DEPTH 16` (the icon arrays are RGB565 with alpha).
## Troubleshooting
- **Blank display**: confirm the pin table above (backlight GPIO 20 is the usual culprit), try `cfg.freq_write = 40000000`, toggle `cfg.invert`. A direct LovyanGFX `fillScreen()` before LVGL init separates hardware from LVGL problems.
- **`lv_tick_inc() is not called`**: the tick handler lives in `DisplayInit::update()`; make sure `lvglTask` is running.
- **Out of memory**: raise `LV_MEM_SIZE` in `include/config/lv_conf.h` or move buffers to PSRAM.
- **Out of memory**: LVGL's 128 KB pool is already in PSRAM (`LV_MEM_POOL_ALLOC` in `lv_conf.h`); raise `LV_MEM_SIZE` there. The two 240×40 draw buffers must stay in internal RAM (SPI DMA).
- **No packets**: common ground? A's CAN toggle must be ON (its link auto-starts with CAN). `ver=` counting up in the `[Link]` stats line = the two repos run different `PACKET_VERSION`s; framing errors with bytes arriving = baud or wiring. ESP-NOW `silent` with UART `alive` = B still hopping or A's radio on another channel.
- **Gauge outputs stay low**: check `[Gauges]` status line — `no-rpm` means A has no valid rpm (no CAN); use `cfg override rpm 2000` on A's console to test the tach without the car.
- **Last resort**: Waveshare demo `https://files.waveshare.com/wiki/ESP32-S3-LCD-1.3/ESP32-S3-LCD-1.3-Demo.zip` and schematic `https://files.waveshare.com/wiki/ESP32-S3-LCD-1.3/ESP32S3_1.3inch.pdf`.