refactor: LoRaBoard trait with full associated types + BoardParts
- LoRaBoard trait now has associated types: RadioParts, CommParts, DisplayParts, DisplayDriver - into_parts() is on the trait (enforced by compiler, not implicit convention) - BoardParts<R, C, D> struct replaces tuple return from into_parts() - mac_address() stays on trait, MAC also in BoardParts for convenience - Removed mac field from DisplayParts (display task calls Board::mac_address()) - DisplayDriver associated type requires DrawTarget<Color = BinaryColor>
This commit is contained in:
1 parent
7a54c4dff3
commit
ecc451affe
8 files changed
+134
-98
No files matched your search
+18
-13
@@ -1,17 +1,15 @@
|
||||
use esp_hal::gpio::{Level, Output, OutputConfig};
|
||||
|
||||
use super::esp32s3;
|
||||
use super::traits::LoRaBoard;
|
||||
use super::traits::{BoardParts, LoRaBoard};
|
||||
use crate::hal::esp32s3 as mcu;
|
||||
|
||||
#[allow(unused_imports)] // Re-exported for other modules (display, radio, uart tasks)
|
||||
#[allow(unused_imports)] // Re-exported for other modules (display, radio, host tasks)
|
||||
pub use super::esp32s3::{
|
||||
create_display, DisplayDriver, DisplayI2c, DisplayParts, RadioDriver, RadioParts, UartDriver,
|
||||
UartParts,
|
||||
};
|
||||
|
||||
// ── Board init ──────────────────────────────────────────────────────
|
||||
|
||||
pub struct Board {
|
||||
p: esp_hal::peripherals::Peripherals,
|
||||
}
|
||||
@@ -20,6 +18,11 @@ impl LoRaBoard for Board {
|
||||
const NAME: &'static str = "Heltec V3";
|
||||
const TX_POWER_RANGE: (i8, i8) = (-9, 22);
|
||||
|
||||
type RadioParts = RadioParts;
|
||||
type CommParts = UartParts;
|
||||
type DisplayParts = DisplayParts;
|
||||
type DisplayDriver = DisplayDriver;
|
||||
|
||||
fn init() -> Self {
|
||||
let p = esp_hal::init(esp_hal::Config::default());
|
||||
Self { p }
|
||||
@@ -28,21 +31,19 @@ impl LoRaBoard for Board {
|
||||
fn mac_address() -> [u8; 6] {
|
||||
mcu::mac_address()
|
||||
}
|
||||
}
|
||||
|
||||
impl Board {
|
||||
pub fn into_parts(self) -> (RadioParts, UartParts, Option<DisplayParts>) {
|
||||
fn into_parts(self) -> BoardParts<RadioParts, UartParts, DisplayParts> {
|
||||
let p = self.p;
|
||||
|
||||
mcu::start_timer(p.TIMG0);
|
||||
|
||||
// Vext power: GPIO36, active LOW to enable peripherals
|
||||
let vext = Output::new(p.GPIO36, Level::Low, OutputConfig::default());
|
||||
core::mem::forget(vext); // hold pin low permanently; drop would reset it
|
||||
core::mem::forget(vext);
|
||||
|
||||
let spi_bus = mcu::init_spi(p.SPI2, p.DMA_CH0, p.GPIO9, p.GPIO10, p.GPIO11);
|
||||
let radio = esp32s3::init_radio(spi_bus, p.GPIO8, p.GPIO12, p.GPIO14, p.GPIO13);
|
||||
let uart = UartParts {
|
||||
let host = UartParts {
|
||||
driver: mcu::init_uart(p.UART0, p.GPIO43, p.GPIO44),
|
||||
};
|
||||
|
||||
@@ -51,12 +52,16 @@ impl Board {
|
||||
esp_hal::delay::Delay::new().delay_millis(10);
|
||||
display_rst.set_high();
|
||||
esp_hal::delay::Delay::new().delay_millis(10);
|
||||
core::mem::forget(display_rst); // hold reset high permanently
|
||||
core::mem::forget(display_rst);
|
||||
|
||||
let i2c = mcu::init_i2c(p.I2C0, p.GPIO17, p.GPIO18);
|
||||
let mac = Self::mac_address();
|
||||
let display = Some(DisplayParts { i2c, mac });
|
||||
let display = Some(DisplayParts { i2c });
|
||||
|
||||
(radio, uart, display)
|
||||
BoardParts {
|
||||
radio,
|
||||
host,
|
||||
display,
|
||||
mac: Self::mac_address(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user