From 99a01b867e037b9000a9f010a7e249fc7953f9f5 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Sun, 29 Mar 2026 22:29:03 -0600 Subject: [PATCH] fix: .expect() on board init unwraps, document forget() and fixed LoRa params MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Board init: all .unwrap() → .expect() with diagnostic messages. Vext/reset forget(): documented why pin must stay in output state. Fixed LoRa params (PREAMBLE_LEN, CRC_ON, etc.): documented as intentionally non-configurable. Watch capacity: documented that display sees latest state only. --- src/board/heltec_v3.rs | 8 ++++---- src/board/heltec_v4.rs | 10 +++++----- src/board/rak_wisblock_4631.rs | 2 +- src/channel.rs | 4 +++- src/radio/task.rs | 6 +++++- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/board/heltec_v3.rs b/src/board/heltec_v3.rs index 9de603a5..9d107540 100644 --- a/src/board/heltec_v3.rs +++ b/src/board/heltec_v3.rs @@ -65,7 +65,7 @@ impl Board { // ── Vext power: GPIO21, active LOW to enable OLED ────────── let vext = Output::new(p.GPIO21, Level::Low); - core::mem::forget(vext); + core::mem::forget(vext); // hold pin low permanently; drop would reset it // ── DMA for SPI ──────────────────────────────────────────── let dma = Dma::new(p.DMA); @@ -83,8 +83,8 @@ impl Board { .with_dma(dma_ch); let (rx_buf, rx_desc, tx_buf, tx_desc) = esp_hal::dma_buffers!(256); - let dma_rx = esp_hal::dma::DmaRxBuf::new(rx_desc, rx_buf).unwrap(); - let dma_tx = esp_hal::dma::DmaTxBuf::new(tx_desc, tx_buf).unwrap(); + let dma_rx = esp_hal::dma::DmaRxBuf::new(rx_desc, rx_buf).expect("DMA RX buf"); + let dma_tx = esp_hal::dma::DmaTxBuf::new(tx_desc, tx_buf).expect("DMA TX buf"); let spi = spi.with_buffers(dma_rx, dma_tx).into_async(); @@ -100,7 +100,7 @@ impl Board { let dio1 = Input::new(p.GPIO14, Pull::Down); let busy = Input::new(p.GPIO13, Pull::Down); - let iv = GenericSx126xInterfaceVariant::new(reset, dio1, busy, None, None).unwrap(); + let iv = GenericSx126xInterfaceVariant::new(reset, dio1, busy, None, None).expect("SX1262 interface init"); let sx_config = sx126x::Config { chip: Sx1262, diff --git a/src/board/heltec_v4.rs b/src/board/heltec_v4.rs index 1d33ad55..37f0ea11 100644 --- a/src/board/heltec_v4.rs +++ b/src/board/heltec_v4.rs @@ -66,7 +66,7 @@ impl Board { // ── Vext power: GPIO36 ───────────────────────────────────── // V4 datasheet says "pull low to enable Vext" let vext = Output::new(p.GPIO36, Level::Low); - core::mem::forget(vext); + core::mem::forget(vext); // hold pin low permanently; drop would reset it // ── DMA for SPI ──────────────────────────────────────────── let dma = Dma::new(p.DMA); @@ -84,8 +84,8 @@ impl Board { .with_dma(dma_ch); let (rx_buf, rx_desc, tx_buf, tx_desc) = esp_hal::dma_buffers!(256); - let dma_rx = esp_hal::dma::DmaRxBuf::new(rx_desc, rx_buf).unwrap(); - let dma_tx = esp_hal::dma::DmaTxBuf::new(tx_desc, tx_buf).unwrap(); + let dma_rx = esp_hal::dma::DmaRxBuf::new(rx_desc, rx_buf).expect("DMA RX buf"); + let dma_tx = esp_hal::dma::DmaTxBuf::new(tx_desc, tx_buf).expect("DMA TX buf"); let spi = spi.with_buffers(dma_rx, dma_tx).into_async(); @@ -101,7 +101,7 @@ impl Board { let dio1 = Input::new(p.GPIO14, Pull::Down); let busy = Input::new(p.GPIO13, Pull::Down); - let iv = GenericSx126xInterfaceVariant::new(reset, dio1, busy, None, None).unwrap(); + let iv = GenericSx126xInterfaceVariant::new(reset, dio1, busy, None, None).expect("SX1262 interface init"); let sx_config = sx126x::Config { chip: Sx1262, @@ -136,7 +136,7 @@ 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); + core::mem::forget(display_rst); // hold reset high permanently let i2c = I2c::new(p.I2C0, I2cConfig::default()) .with_sda(p.GPIO17) diff --git a/src/board/rak_wisblock_4631.rs b/src/board/rak_wisblock_4631.rs index d1f1c6f5..62d31134 100644 --- a/src/board/rak_wisblock_4631.rs +++ b/src/board/rak_wisblock_4631.rs @@ -84,7 +84,7 @@ impl Board { let dio1 = Input::new(AnyPin::from(p.P1_15), Pull::Down); let busy = Input::new(AnyPin::from(p.P1_14), Pull::Down); - let iv = GenericSx126xInterfaceVariant::new(reset, dio1, busy, None, None).unwrap(); + let iv = GenericSx126xInterfaceVariant::new(reset, dio1, busy, None, None).expect("SX1262 interface init"); let sx_config = sx126x::Config { chip: Sx1262, diff --git a/src/channel.rs b/src/channel.rs index f2d93306..fb6efb25 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -30,7 +30,9 @@ pub type CommandChannel = Channel; /// Radio-to-host response channel (depth 32: buffer RX packets while USB writes). pub type ResponseChannel = Channel; -/// Observable radio status for the display task (2 slots: latest + previous). +/// Observable radio status for the display task (2 receivers max). +/// Display always sees the latest state — intermediate updates may be +/// skipped, which is fine for a status display. pub type StatusWatch = Watch; /// Current radio state exposed to observers (e.g. display). diff --git a/src/radio/task.rs b/src/radio/task.rs index 75ba00ca..d0743a44 100644 --- a/src/radio/task.rs +++ b/src/radio/task.rs @@ -33,7 +33,11 @@ const POWER_RANGE: (i8, i8) = TX_POWER_RANGE; type Radio = LoRa; -// ── LoRa radio parameters ─────────────────────────────────────────── +// ── Fixed LoRa radio parameters ───────────────────────────────────── +// +// These are intentionally not host-configurable. They are sensible +// defaults for a general-purpose LoRa pipe. Making them configurable +// would add protocol complexity for marginal benefit. /// Preamble length in symbols. 8 is the LoRa default. const PREAMBLE_LEN: u16 = 8;