refactor: LoRaBoard trait for compile-time board completeness verification
Every board's Board struct now implements the LoRaBoard trait, which enforces that NAME, TX_POWER_RANGE, init(), and mac_address() are all provided. Missing any of these is a compile error — no "good intentions" needed. The trait verifies metadata and initialization. Tasks use the board's concrete types directly (Embassy tasks must be concrete). Board-specific type aliases (RadioDriver, UsbDriver, DisplayI2c) and struct definitions (RadioParts, UsbParts, DisplayParts) remain in each board file. - New: src/board/traits.rs (LoRaBoard trait definition) - Modified: all 3 board files (implement trait, remove standalone constants) - Modified: main.rs (import trait for init) - Modified: radio/task.rs (use Board::TX_POWER_RANGE via trait) - Modified: display/task.rs (use Board::NAME via trait) - Modified: build.rs (exclude traits.rs from board discovery) - Removed: embedded-hal-async direct dep (not needed for trait approach)
This commit is contained in:
11 files changed
+107
-55
No files matched your search
+2
-1
@@ -24,6 +24,7 @@ mod usb;
|
||||
|
||||
use embassy_executor::Spawner;
|
||||
|
||||
use crate::board::LoRaBoard;
|
||||
use crate::channel::{CommandChannel, DisplayCommandChannel, ResponseChannel, StatusWatch};
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
@@ -55,7 +56,7 @@ cfg_if::cfg_if! {
|
||||
}
|
||||
|
||||
async fn run(spawner: Spawner) {
|
||||
let board = board::Board::init();
|
||||
let board = <board::Board as LoRaBoard>::init();
|
||||
let (radio, usb, display) = board.into_parts();
|
||||
|
||||
let has_display = display.is_some();
|
||||
|
||||
Reference in new issue
Block a user