Device-abstraction refactor: HAL + per-board folders + responsive UI
Replaces the build-flag-driven #ifdef sprawl (~30 blocks across 6 files)
with a small HAL in firmware/src/hal/ and per-board folders under
firmware/src/boards/. Shared code (main.cpp, ui.cpp, splash.cpp) no
longer contains a single `#ifdef BOARD_*` — optional features are
guarded by BoardCaps (runtime) and BOARD_HAS_* macros (compile-time,
inside the board's own files).
Why: lets community contributors port to new ESP32 + AMOLED + touch
combos by dropping in a boards/<name>/ folder + a PlatformIO env,
without touching shared files. See docs/porting/adding-a-board.md.
Highlights:
- New HAL: display_hal, touch_hal, input_hal, power_hal, imu_hal,
board_caps. Each board provides display.cpp, touch.cpp, input.cpp,
power.cpp, imu.cpp, caps.cpp, board_init.cpp + private hardware
drivers (e.g. io_expander.{h,cpp} on AMOLED-1.8).
- PlatformIO build_src_filter selects each board's folder per env.
- ui.cpp picks fonts and layout from board_caps() via compute_layout()
with screen-height breakpoints (>= 460 → large, else compact).
- splash.cpp computes CELL = min(W,H)/20 — responsive instead of two
hardcoded values.
- idle.cpp (from #24) rewired through display_hal + power_hal — no
longer depends on the deleted display_cfg.h / power.h.
- power_hal gains power_hal_is_vbus_in() for idle's
IDLE_SLEEP_WHEN_CHARGING gate.
- boards/template/ + docs/porting/{adding-a-board,hal-contract,
capability-flags}.md to bootstrap new ports.
- display_cfg.h, power.{h,cpp}, imu.{h,cpp}, io_expander.{h,cpp}
deleted from src/ root (moved into boards/<name>/ or hal/).
Verification: both `pio run -e waveshare_amoled_216` and
`pio run -e waveshare_amoled_18` succeed unchanged.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
f3ed2425bf
commit
20351212b2
@@ -1,8 +1,8 @@
|
||||
#include <Arduino.h>
|
||||
#include "idle.h"
|
||||
#include "idle_cfg.h"
|
||||
#include "display_cfg.h" // declares `extern Arduino_CO5300 *gfx;`
|
||||
#include "power.h"
|
||||
#include "hal/display_hal.h"
|
||||
#include "hal/power_hal.h"
|
||||
|
||||
enum IdleState {
|
||||
STATE_AWAKE,
|
||||
@@ -19,7 +19,7 @@ static uint8_t fade_from = DISPLAY_DEFAULT_BRIGHTNESS;
|
||||
static uint8_t fade_to = 0;
|
||||
|
||||
static void apply_brightness(uint8_t b) {
|
||||
gfx->setBrightness(b);
|
||||
display_hal_set_brightness(b);
|
||||
}
|
||||
|
||||
static void begin_fade(uint8_t to, uint32_t now) {
|
||||
@@ -72,7 +72,7 @@ void idle_tick(void) {
|
||||
|
||||
// While on USB power (if configured), don't sleep — and wake from sleep
|
||||
// when power comes back. Treats USB-in as continuous activity.
|
||||
if (!IDLE_SLEEP_WHEN_CHARGING && power_is_vbus_in()) {
|
||||
if (!IDLE_SLEEP_WHEN_CHARGING && power_hal_is_vbus_in()) {
|
||||
last_activity_ms = now;
|
||||
if (state == STATE_ASLEEP || state == STATE_FADING_OUT) {
|
||||
begin_fade(DISPLAY_DEFAULT_BRIGHTNESS, now);
|
||||
|
||||
Reference in New Issue
Block a user