diff --git a/src/board/esp32s3.rs b/src/board/esp32s3.rs index 1a1cda5..5e42792 100644 --- a/src/board/esp32s3.rs +++ b/src/board/esp32s3.rs @@ -18,6 +18,20 @@ use crate::hal::esp32s3 as mcu; pub use mcu::{I2cBus as DisplayI2c, SpiBus}; +// ── LED driver ────────────────────────────────────────────────────── + +pub struct SimpleLed(pub Output<'static>); + +impl super::traits::RgbLed for SimpleLed { + async fn set_rgb(&mut self, r: u8, g: u8, b: u8) { + if r > 0 || g > 0 || b > 0 { + self.0.set_high(); + } else { + self.0.set_low(); + } + } +} + // ── Concrete peripheral types ─────────────────────────────────────── type Nss = Output<'static>; diff --git a/src/board/heltec_v3.rs b/src/board/heltec_v3.rs index dd80339..a63bf21 100644 --- a/src/board/heltec_v3.rs +++ b/src/board/heltec_v3.rs @@ -11,7 +11,7 @@ use static_cell::StaticCell; use super::esp32s3; use super::traits::{BoardParts, LoRaBoard}; -use crate::driver::simple_led::SimpleLed; +use super::esp32s3::SimpleLed; use crate::hal::esp32s3 as mcu; pub use super::esp32s3::{ @@ -84,7 +84,7 @@ impl LoRaBoard for Board { // White LED on GPIO35 let led_pin = Output::new(p.GPIO35, Level::Low, OutputConfig::default()); - let led = Some(SimpleLed::new(led_pin)); + let led = Some(SimpleLed(led_pin)); BoardParts { radio, diff --git a/src/board/heltec_v3_uart.rs b/src/board/heltec_v3_uart.rs index f45d4fc..7edb4f6 100644 --- a/src/board/heltec_v3_uart.rs +++ b/src/board/heltec_v3_uart.rs @@ -10,7 +10,7 @@ use esp_hal::gpio::{Level, Output, OutputConfig}; use super::esp32s3; use super::traits::{BoardParts, LoRaBoard}; -use crate::driver::simple_led::SimpleLed; +use super::esp32s3::SimpleLed; use crate::hal::esp32s3 as mcu; pub use super::esp32s3::{ @@ -80,7 +80,7 @@ impl LoRaBoard for Board { // White LED on GPIO35 let led_pin = Output::new(p.GPIO35, Level::Low, OutputConfig::default()); - let led = Some(SimpleLed::new(led_pin)); + let led = Some(SimpleLed(led_pin)); BoardParts { radio, diff --git a/src/board/heltec_v4.rs b/src/board/heltec_v4.rs index cbfd85e..ce79f01 100644 --- a/src/board/heltec_v4.rs +++ b/src/board/heltec_v4.rs @@ -3,7 +3,7 @@ use static_cell::StaticCell; use super::esp32s3; use super::traits::{BoardParts, LoRaBoard}; -use crate::driver::simple_led::SimpleLed; +use super::esp32s3::SimpleLed; use crate::hal::esp32s3 as mcu; pub use super::esp32s3::{ @@ -77,7 +77,7 @@ impl LoRaBoard for Board { // Orange LED on GPIO35 let led_pin = Output::new(p.GPIO35, Level::Low, OutputConfig::default()); - let led = Some(SimpleLed::new(led_pin)); + let led = Some(SimpleLed(led_pin)); BoardParts { radio, diff --git a/src/board/wio_tracker_l1.rs b/src/board/wio_tracker_l1.rs index 486cb60..2c63cb8 100644 --- a/src/board/wio_tracker_l1.rs +++ b/src/board/wio_tracker_l1.rs @@ -20,7 +20,22 @@ type RadioSpiDevice = SpiDevice<'static, NoopRawMutex, mcu::SpiBus, Nss>; pub type RadioDriver = Sx126x; pub type UsbDriver = mcu::UsbNrfDriver; pub type DisplayI2c = mcu::I2cBus; -pub type LedDriver = (); + +// ── LED driver (green LED on P1.01) ───────────────────────────────── + +pub struct SimpleLed(pub Output<'static>); + +impl super::traits::RgbLed for SimpleLed { + async fn set_rgb(&mut self, r: u8, g: u8, b: u8) { + if r > 0 || g > 0 || b > 0 { + self.0.set_high(); + } else { + self.0.set_low(); + } + } +} + +pub type LedDriver = SimpleLed; pub type DisplayDriver = crate::driver::sh1106::Sh1106; @@ -67,7 +82,7 @@ impl LoRaBoard for Board { type CommParts = UsbParts; type DisplayParts = DisplayParts; type DisplayDriver = DisplayDriver; - type LedDriver = (); + type LedDriver = LedDriver; fn init() -> Self { let mut config = embassy_nrf::config::Config::default(); @@ -81,7 +96,7 @@ impl LoRaBoard for Board { mcu::mac_address() } - fn into_parts(self) -> BoardParts { + fn into_parts(self) -> BoardParts { let p = self.p; // ── SPI bus for SX1262 ────────────────────────────────── @@ -131,11 +146,15 @@ impl LoRaBoard for Board { ); let display = Some(DisplayParts { i2c }); + // Green LED on P1.01 + let led_pin = Output::new(p.P1_01, Level::Low, OutputDrive::Standard); + let led = Some(SimpleLed(led_pin)); + BoardParts { radio, host, display, - led: None, + led, mac: Self::mac_address(), } } diff --git a/src/driver/mod.rs b/src/driver/mod.rs index 39e3ec1..f895c6c 100644 --- a/src/driver/mod.rs +++ b/src/driver/mod.rs @@ -1,5 +1,2 @@ #[cfg(feature = "wio_tracker_l1")] pub mod sh1106; - -#[cfg(any(feature = "heltec_v3", feature = "heltec_v3_uart", feature = "heltec_v4"))] -pub mod simple_led; diff --git a/src/driver/simple_led.rs b/src/driver/simple_led.rs deleted file mode 100644 index ca97882..0000000 --- a/src/driver/simple_led.rs +++ /dev/null @@ -1,28 +0,0 @@ -//! Simple single-color LED driver (GPIO on/off). -//! -//! For boards with a plain LED (not addressable RGB). Any non-zero -//! RGB value turns the LED on; all zeros turns it off. - -use esp_hal::gpio::Output; - -use crate::board::RgbLed; - -pub struct SimpleLed { - pin: Output<'static>, -} - -impl SimpleLed { - pub fn new(pin: Output<'static>) -> Self { - Self { pin } - } -} - -impl RgbLed for SimpleLed { - async fn set_rgb(&mut self, r: u8, g: u8, b: u8) { - if r > 0 || g > 0 || b > 0 { - self.pin.set_high(); - } else { - self.pin.set_low(); - } - } -}