feat: RGB LED support — blinks green on RX, red on TX
- Added RgbLed trait with impl on () for boards without LED - Added WS2812 driver (driver/ws2812.rs) using ESP32-S3 RMT peripheral - 80MHz clock, 12.5ns resolution, 24-bit GRB encoding - Zero extra crate dependencies - Heltec V3/V3-UART/V4: WS2812B on GPIO38 via RMT channel 0 - RAK WisBlock/Wio Tracker: type LedDriver = (), led = None (no-op) - Display task: green blink on RX packet, red blink on TX packet - LED auto-off on timer tick (~1s), off when display is off/reset - LoRaBoard trait gains type LedDriver: RgbLed associated type - BoardParts gains led: Option<L> field
This commit is contained in:
1 parent
2b9e236f32
commit
5ac4b73739
11 files changed
+157
-20
No files matched your search
+17
-4
@@ -1,14 +1,23 @@
|
||||
//! Board abstraction trait.
|
||||
//!
|
||||
//! Every board must implement [`LoRaBoard`] with concrete associated types
|
||||
//! for its radio, host communication, and display peripherals. The compiler
|
||||
//! enforces completeness — missing types or methods are compile errors.
|
||||
//! for its radio, host communication, display, and LED peripherals. The
|
||||
//! compiler enforces completeness — missing types or methods are compile errors.
|
||||
//!
|
||||
//! See `src/board/PORTING.md` for a step-by-step guide to adding a new board.
|
||||
|
||||
use embedded_graphics::draw_target::DrawTarget;
|
||||
use embedded_graphics::pixelcolor::BinaryColor;
|
||||
|
||||
/// Async RGB LED control. Boards without an LED use `()` which is a no-op.
|
||||
pub trait RgbLed {
|
||||
fn set_rgb(&mut self, r: u8, g: u8, b: u8) -> impl core::future::Future<Output = ()>;
|
||||
}
|
||||
|
||||
impl RgbLed for () {
|
||||
async fn set_rgb(&mut self, _r: u8, _g: u8, _b: u8) {}
|
||||
}
|
||||
|
||||
/// Compile-time contract for a DongLoRa board.
|
||||
pub trait LoRaBoard: Sized {
|
||||
/// Human-readable board name (shown on display splash screen).
|
||||
@@ -29,6 +38,9 @@ pub trait LoRaBoard: Sized {
|
||||
/// Concrete display driver type (must implement DrawTarget for rendering).
|
||||
type DisplayDriver: DrawTarget<Color = BinaryColor>;
|
||||
|
||||
/// RGB LED driver. Boards without an LED use `()`.
|
||||
type LedDriver: RgbLed;
|
||||
|
||||
/// Initialize the board hardware.
|
||||
fn init() -> Self;
|
||||
|
||||
@@ -36,13 +48,14 @@ pub trait LoRaBoard: Sized {
|
||||
fn mac_address() -> [u8; 6];
|
||||
|
||||
/// Decompose initialized board into peripheral bundles for each task.
|
||||
fn into_parts(self) -> BoardParts<Self::RadioParts, Self::CommParts, Self::DisplayParts>;
|
||||
fn into_parts(self) -> BoardParts<Self::RadioParts, Self::CommParts, Self::DisplayParts, Self::LedDriver>;
|
||||
}
|
||||
|
||||
/// Peripheral bundles for each firmware task, produced by [`LoRaBoard::into_parts`].
|
||||
pub struct BoardParts<R, C, D> {
|
||||
pub struct BoardParts<R, C, D, L> {
|
||||
pub radio: R,
|
||||
pub host: C,
|
||||
pub display: Option<D>,
|
||||
pub led: Option<L>,
|
||||
pub mac: [u8; 6],
|
||||
}
|
||||
Reference in new issue
Block a user