style: cargo fmt

This commit is contained in:
swaits committed 2026-04-16 13:25:19 -06:00
1 parent 649c29218c
commit f9582c0b94
19 files changed
+104 -48

No files matched your search

+1 -2
View File
@@ -118,8 +118,7 @@ fn main() {
}; };
if let Some(src) = memory_x { if let Some(src) = memory_x {
let out_dir = std::env::var("OUT_DIR").unwrap(); let out_dir = std::env::var("OUT_DIR").unwrap();
fs::copy(src, format!("{out_dir}/memory.x")) fs::copy(src, format!("{out_dir}/memory.x")).expect("failed to copy memory.x");
.expect("failed to copy memory.x");
println!("cargo:rustc-link-search={out_dir}"); println!("cargo:rustc-link-search={out_dir}");
} }
println!("cargo:rerun-if-changed=ld/nrf52840-memory.x"); println!("cargo:rerun-if-changed=ld/nrf52840-memory.x");
+15 -3
View File
@@ -35,14 +35,22 @@ pub struct RadioParts {
// SSD1306 display support is Heltec-specific. ESP32-S3 boards that use a // SSD1306 display support is Heltec-specific. ESP32-S3 boards that use a
// different controller (e.g. ThinkNode-M2 uses SH1106) provide their own // different controller (e.g. ThinkNode-M2 uses SH1106) provide their own
// DisplayParts / DisplayDriver / create_display directly. // DisplayParts / DisplayDriver / create_display directly.
#[cfg(any(feature = "heltec_v3", feature = "heltec_v3_uart", feature = "heltec_v4"))] #[cfg(any(
feature = "heltec_v3",
feature = "heltec_v3_uart",
feature = "heltec_v4"
))]
pub struct DisplayParts { pub struct DisplayParts {
pub i2c: DisplayI2c, pub i2c: DisplayI2c,
} }
// ── Display driver ────────────────────────────────────────────────── // ── Display driver ──────────────────────────────────────────────────
#[cfg(any(feature = "heltec_v3", feature = "heltec_v3_uart", feature = "heltec_v4"))] #[cfg(any(
feature = "heltec_v3",
feature = "heltec_v3_uart",
feature = "heltec_v4"
))]
pub type DisplayDriver = ssd1306::Ssd1306Async< pub type DisplayDriver = ssd1306::Ssd1306Async<
ssd1306::prelude::I2CInterface<DisplayI2c>, ssd1306::prelude::I2CInterface<DisplayI2c>,
ssd1306::size::DisplaySize128x64, ssd1306::size::DisplaySize128x64,
@@ -50,7 +58,11 @@ pub type DisplayDriver = ssd1306::Ssd1306Async<
>; >;
/// Construct and initialize an SSD1306 display from raw I2C. /// Construct and initialize an SSD1306 display from raw I2C.
#[cfg(any(feature = "heltec_v3", feature = "heltec_v3_uart", feature = "heltec_v4"))] #[cfg(any(
feature = "heltec_v3",
feature = "heltec_v3_uart",
feature = "heltec_v4"
))]
pub async fn create_display(i2c: DisplayI2c) -> Option<DisplayDriver> { pub async fn create_display(i2c: DisplayI2c) -> Option<DisplayDriver> {
use ssd1306::mode::DisplayConfigAsync; use ssd1306::mode::DisplayConfigAsync;
use ssd1306::prelude::{Brightness, DisplayRotation}; use ssd1306::prelude::{Brightness, DisplayRotation};
+1 -3
View File
@@ -14,9 +14,7 @@ use super::traits::{BoardParts, LoRaBoard};
use crate::driver::simple_led::SimpleLed; use crate::driver::simple_led::SimpleLed;
use crate::hal::esp32s3 as mcu; use crate::hal::esp32s3 as mcu;
pub use super::esp32s3::{ pub use super::esp32s3::{create_display, DisplayDriver, DisplayParts, RadioDriver, RadioParts};
create_display, DisplayDriver, DisplayParts, RadioDriver, RadioParts,
};
pub type UsbDriver = esp_hal::otg_fs::asynch::Driver<'static>; pub type UsbDriver = esp_hal::otg_fs::asynch::Driver<'static>;
pub type LedDriver = SimpleLed<Output<'static>>; pub type LedDriver = SimpleLed<Output<'static>>;
+1 -3
View File
@@ -13,9 +13,7 @@ use super::traits::{BoardParts, LoRaBoard};
use crate::driver::simple_led::SimpleLed; use crate::driver::simple_led::SimpleLed;
use crate::hal::esp32s3 as mcu; use crate::hal::esp32s3 as mcu;
pub use super::esp32s3::{ pub use super::esp32s3::{create_display, DisplayDriver, DisplayParts, RadioDriver, RadioParts};
create_display, DisplayDriver, DisplayParts, RadioDriver, RadioParts,
};
pub type UartDriver = esp_hal::uart::Uart<'static, esp_hal::Async>; pub type UartDriver = esp_hal::uart::Uart<'static, esp_hal::Async>;
pub type LedDriver = SimpleLed<Output<'static>>; pub type LedDriver = SimpleLed<Output<'static>>;
+1 -3
View File
@@ -6,9 +6,7 @@ use super::traits::{BoardParts, LoRaBoard};
use crate::driver::simple_led::SimpleLed; use crate::driver::simple_led::SimpleLed;
use crate::hal::esp32s3 as mcu; use crate::hal::esp32s3 as mcu;
pub use super::esp32s3::{ pub use super::esp32s3::{create_display, DisplayDriver, DisplayParts, RadioDriver, RadioParts};
create_display, DisplayDriver, DisplayParts, RadioDriver, RadioParts,
};
pub type UsbDriver = esp_hal::otg_fs::asynch::Driver<'static>; pub type UsbDriver = esp_hal::otg_fs::asynch::Driver<'static>;
+6 -1
View File
@@ -129,7 +129,12 @@ impl LoRaBoard for Board {
// ── Display (optional RAK1921 SSD1306 OLED on I2C) ───── // ── Display (optional RAK1921 SSD1306 OLED on I2C) ─────
let twim_buf = mcu::alloc_i2c_buffer(); let twim_buf = mcu::alloc_i2c_buffer();
let i2c = embassy_nrf::twim::Twim::new( let i2c = embassy_nrf::twim::Twim::new(
p.TWISPI0, mcu::Irqs, p.P0_13, p.P0_14, twim::Config::default(), twim_buf, p.TWISPI0,
mcu::Irqs,
p.P0_13,
p.P0_14,
twim::Config::default(),
twim_buf,
); );
let display = Some(DisplayParts { i2c }); let display = Some(DisplayParts { i2c });
+3 -1
View File
@@ -48,7 +48,9 @@ pub trait LoRaBoard: Sized {
fn mac_address() -> [u8; 6]; fn mac_address() -> [u8; 6];
/// Decompose initialized board into peripheral bundles for each task. /// Decompose initialized board into peripheral bundles for each task.
fn into_parts(self) -> BoardParts<Self::RadioParts, Self::CommParts, Self::DisplayParts, Self::LedDriver>; fn into_parts(
self,
) -> BoardParts<Self::RadioParts, Self::CommParts, Self::DisplayParts, Self::LedDriver>;
} }
/// Peripheral bundles for each firmware task, produced by [`LoRaBoard::into_parts`]. /// Peripheral bundles for each firmware task, produced by [`LoRaBoard::into_parts`].
+12 -3
View File
@@ -21,7 +21,8 @@ pub type LedDriver = crate::driver::simple_led::SimpleLed<Output<'static>>;
// Display types — never instantiated (no OLED on this board), but the // Display types — never instantiated (no OLED on this board), but the
// trait requires concrete associated types that satisfy the bounds. // trait requires concrete associated types that satisfy the bounds.
pub type DisplayI2c = embassy_rp::i2c::I2c<'static, embassy_rp::peripherals::I2C0, embassy_rp::i2c::Async>; pub type DisplayI2c =
embassy_rp::i2c::I2c<'static, embassy_rp::peripherals::I2C0, embassy_rp::i2c::Async>;
pub type DisplayDriver = ssd1306::Ssd1306Async< pub type DisplayDriver = ssd1306::Ssd1306Async<
ssd1306::prelude::I2CInterface<DisplayI2c>, ssd1306::prelude::I2CInterface<DisplayI2c>,
ssd1306::size::DisplaySize128x64, ssd1306::size::DisplaySize128x64,
@@ -78,7 +79,8 @@ impl LoRaBoard for Board {
let p = self.p; let p = self.p;
// ── MAC address from flash unique ID ─────────────────── // ── MAC address from flash unique ID ───────────────────
let mut flash = embassy_rp::flash::Flash::<_, _, { 2 * 1024 * 1024 }>::new_blocking(p.FLASH); let mut flash =
embassy_rp::flash::Flash::<_, _, { 2 * 1024 * 1024 }>::new_blocking(p.FLASH);
mcu::init_mac(&mut flash); mcu::init_mac(&mut flash);
// ── SPI1 bus for SX1262 ──────────────────────────────── // ── SPI1 bus for SX1262 ────────────────────────────────
@@ -92,7 +94,14 @@ impl LoRaBoard for Board {
let mut spi_cfg = spi::Config::default(); let mut spi_cfg = spi::Config::default();
spi_cfg.frequency = 1_000_000; spi_cfg.frequency = 1_000_000;
let spi = spi::Spi::new( let spi = spi::Spi::new(
p.SPI1, p.PIN_14, p.PIN_15, p.PIN_24, p.DMA_CH0, p.DMA_CH1, mcu::Irqs, spi_cfg, p.SPI1,
p.PIN_14,
p.PIN_15,
p.PIN_24,
p.DMA_CH0,
p.DMA_CH1,
mcu::Irqs,
spi_cfg,
); );
let spi_bus = mcu::share_spi_bus(spi); let spi_bus = mcu::share_spi_bus(spi);
+6 -1
View File
@@ -128,7 +128,12 @@ impl LoRaBoard for Board {
// ── Display (SH1106 OLED on I2C) ──────────────────────── // ── Display (SH1106 OLED on I2C) ────────────────────────
let twim_buf = mcu::alloc_i2c_buffer(); let twim_buf = mcu::alloc_i2c_buffer();
let i2c = embassy_nrf::twim::Twim::new( let i2c = embassy_nrf::twim::Twim::new(
p.TWISPI0, mcu::Irqs, p.P0_06, p.P0_05, twim::Config::default(), twim_buf, p.TWISPI0,
mcu::Irqs,
p.P0_06,
p.P0_05,
twim::Config::default(),
twim_buf,
); );
let display = Some(DisplayParts { i2c }); let display = Some(DisplayParts { i2c });
+5 -2
View File
@@ -563,8 +563,11 @@ mod render {
i + committed.saturating_sub(effective_bars) i + committed.saturating_sub(effective_bars)
} else { } else {
let start = count - RSSI_HISTORY_LEN; let start = count - RSSI_HISTORY_LEN;
let skip = let skip = RSSI_HISTORY_LEN.saturating_sub(if live {
RSSI_HISTORY_LEN.saturating_sub(if live { visible_bars - 1 } else { visible_bars }); visible_bars - 1
} else {
visible_bars
});
(start + skip + i) % RSSI_HISTORY_LEN (start + skip + i) % RSSI_HISTORY_LEN
}; };
let is_tx = tx_history[idx]; let is_tx = tx_history[idx];
+8 -1
View File
@@ -1,5 +1,12 @@
#[cfg(any(feature = "wio_tracker_l1", feature = "elecrow_thinknode_m2"))] #[cfg(any(feature = "wio_tracker_l1", feature = "elecrow_thinknode_m2"))]
pub mod sh1106; pub mod sh1106;
#[cfg(any(feature = "heltec_v3", feature = "heltec_v3_uart", feature = "heltec_v4", feature = "elecrow_thinknode_m2", feature = "wio_tracker_l1", feature = "waveshare_rp2040_lora"))] #[cfg(any(
feature = "heltec_v3",
feature = "heltec_v3_uart",
feature = "heltec_v4",
feature = "elecrow_thinknode_m2",
feature = "wio_tracker_l1",
feature = "waveshare_rp2040_lora"
))]
pub mod simple_led; pub mod simple_led;
+3 -4
View File
@@ -73,9 +73,9 @@ impl<I: I2c> Sh1106<I> {
for page in 0..PAGES { for page in 0..PAGES {
// Set page address and column start (with SH1106 2-column offset). // Set page address and column start (with SH1106 2-column offset).
self.cmd(&[ self.cmd(&[
0xB0 | page as u8, // page address 0xB0 | page as u8, // page address
COL_OFFSET & 0x0F, // column low nibble COL_OFFSET & 0x0F, // column low nibble
0x10 | (COL_OFFSET >> 4), // column high nibble 0x10 | (COL_OFFSET >> 4), // column high nibble
]) ])
.await?; .await?;
@@ -90,7 +90,6 @@ impl<I: I2c> Sh1106<I> {
pub async fn set_brightness(&mut self, value: u8) -> Result<(), I::Error> { pub async fn set_brightness(&mut self, value: u8) -> Result<(), I::Error> {
self.cmd(&[0x81, value]).await self.cmd(&[0x81, value]).await
} }
} }
impl<I: I2c> DrawTarget for Sh1106<I> { impl<I: I2c> DrawTarget for Sh1106<I> {
+6 -1
View File
@@ -3,7 +3,12 @@
//! Each submodule provides low-level bus and peripheral init for one MCU family. //! Each submodule provides low-level bus and peripheral init for one MCU family.
//! Board files call these with specific pins and construct higher-level drivers. //! Board files call these with specific pins and construct higher-level drivers.
#[cfg(any(feature = "heltec_v3", feature = "heltec_v3_uart", feature = "heltec_v4", feature = "elecrow_thinknode_m2"))] #[cfg(any(
feature = "heltec_v3",
feature = "heltec_v3_uart",
feature = "heltec_v4",
feature = "elecrow_thinknode_m2"
))]
pub mod esp32s3; pub mod esp32s3;
#[cfg(any(feature = "rak_wisblock_4631", feature = "wio_tracker_l1"))] #[cfg(any(feature = "rak_wisblock_4631", feature = "wio_tracker_l1"))]
+1 -3
View File
@@ -25,9 +25,7 @@ pub type UsbNrfDriver =
// ── SPI bus sharing ───────────────────────────────────────────────── // ── SPI bus sharing ─────────────────────────────────────────────────
/// Wrap an initialized SPI peripheral in a shared bus (StaticCell + Mutex). /// Wrap an initialized SPI peripheral in a shared bus (StaticCell + Mutex).
pub fn share_spi_bus( pub fn share_spi_bus(spi: SpiBus) -> &'static embassy_sync::mutex::Mutex<NoopRawMutex, SpiBus> {
spi: SpiBus,
) -> &'static embassy_sync::mutex::Mutex<NoopRawMutex, SpiBus> {
static SPI_BUS: StaticCell<embassy_sync::mutex::Mutex<NoopRawMutex, SpiBus>> = static SPI_BUS: StaticCell<embassy_sync::mutex::Mutex<NoopRawMutex, SpiBus>> =
StaticCell::new(); StaticCell::new();
SPI_BUS.init(embassy_sync::mutex::Mutex::new(spi)) SPI_BUS.init(embassy_sync::mutex::Mutex::new(spi))
+10 -8
View File
@@ -17,15 +17,14 @@ bind_interrupts!(pub struct Irqs {
// ── MCU-level types ──────────────────────────────────────────────── // ── MCU-level types ────────────────────────────────────────────────
pub type SpiBus = embassy_rp::spi::Spi<'static, embassy_rp::peripherals::SPI1, embassy_rp::spi::Async>; pub type SpiBus =
embassy_rp::spi::Spi<'static, embassy_rp::peripherals::SPI1, embassy_rp::spi::Async>;
pub type UsbRpDriver = embassy_rp::usb::Driver<'static, embassy_rp::peripherals::USB>; pub type UsbRpDriver = embassy_rp::usb::Driver<'static, embassy_rp::peripherals::USB>;
// ── SPI bus sharing ──────────────────────────────────────────────── // ── SPI bus sharing ────────────────────────────────────────────────
/// Wrap an initialized SPI peripheral in a shared bus (StaticCell + Mutex). /// Wrap an initialized SPI peripheral in a shared bus (StaticCell + Mutex).
pub fn share_spi_bus( pub fn share_spi_bus(spi: SpiBus) -> &'static embassy_sync::mutex::Mutex<NoopRawMutex, SpiBus> {
spi: SpiBus,
) -> &'static embassy_sync::mutex::Mutex<NoopRawMutex, SpiBus> {
static SPI_BUS: StaticCell<embassy_sync::mutex::Mutex<NoopRawMutex, SpiBus>> = static SPI_BUS: StaticCell<embassy_sync::mutex::Mutex<NoopRawMutex, SpiBus>> =
StaticCell::new(); StaticCell::new();
SPI_BUS.init(embassy_sync::mutex::Mutex::new(spi)) SPI_BUS.init(embassy_sync::mutex::Mutex::new(spi))
@@ -42,7 +41,12 @@ static mut MAC_REF: Option<&'static [u8; 6]> = None;
/// ///
/// Must be called once during board init before `mac_address()`. /// Must be called once during board init before `mac_address()`.
pub fn init_mac<const FLASH_SIZE: usize>( pub fn init_mac<const FLASH_SIZE: usize>(
flash: &mut embassy_rp::flash::Flash<'_, embassy_rp::peripherals::FLASH, embassy_rp::flash::Blocking, FLASH_SIZE>, flash: &mut embassy_rp::flash::Flash<
'_,
embassy_rp::peripherals::FLASH,
embassy_rp::flash::Blocking,
FLASH_SIZE,
>,
) { ) {
let mut uid = [0u8; 8]; let mut uid = [0u8; 8];
flash.blocking_unique_id(&mut uid).expect("flash unique ID"); flash.blocking_unique_id(&mut uid).expect("flash unique ID");
@@ -72,7 +76,5 @@ pub fn init_mac<const FLASH_SIZE: usize>(
pub fn mac_address() -> [u8; 6] { pub fn mac_address() -> [u8; 6] {
// SAFETY: MAC_REF is set once during init before the executor starts, // SAFETY: MAC_REF is set once during init before the executor starts,
// and only read (never written) after that. // and only read (never written) after that.
unsafe { unsafe { *MAC_REF.expect("init_mac() must be called before mac_address()") }
*MAC_REF.expect("init_mac() must be called before mac_address()")
}
} }
+1 -2
View File
@@ -44,8 +44,7 @@ impl CobsDecoder {
// End of COBS frame — decode and dispatch // End of COBS frame — decode and dispatch
if self.len > 0 { if self.len > 0 {
let mut decode_buf = [0u8; MAX_FRAME]; let mut decode_buf = [0u8; MAX_FRAME];
if let Some(decoded_len) = if let Some(decoded_len) = ucobs::decode(&self.buf[..self.len], &mut decode_buf)
ucobs::decode(&self.buf[..self.len], &mut decode_buf)
{ {
if let Some(cmd) = Command::from_bytes(&decode_buf[..decoded_len]) { if let Some(cmd) = Command::from_bytes(&decode_buf[..decoded_len]) {
on_command(cmd); on_command(cmd);
+7 -2
View File
@@ -6,8 +6,8 @@ use defmt::warn;
use embassy_executor::task; use embassy_executor::task;
use embedded_io_async::Write; use embedded_io_async::Write;
use crate::channel::{CommandChannel, DisplayCommand, DisplayCommandChannel, ResponseChannel};
use super::framing::{self, CobsDecoder, MAX_FRAME}; use super::framing::{self, CobsDecoder, MAX_FRAME};
use crate::channel::{CommandChannel, DisplayCommand, DisplayCommandChannel, ResponseChannel};
#[task] #[task]
pub async fn host_task( pub async fn host_task(
@@ -56,7 +56,12 @@ pub async fn host_task(
}); });
for cmd in cmds { for cmd in cmds {
framing::route_command( framing::route_command(
cmd, commands, responses, display_commands, has_display, mac, cmd,
commands,
responses,
display_commands,
has_display,
mac,
) )
.await; .await;
} }
+16 -3
View File
@@ -7,9 +7,9 @@ use embassy_usb::class::cdc_acm::{CdcAcmClass, Receiver, Sender, State};
use embassy_usb::Builder; use embassy_usb::Builder;
use static_cell::StaticCell; use static_cell::StaticCell;
use super::framing::{self, CobsDecoder, MAX_FRAME};
use crate::channel::{CommandChannel, DisplayCommand, DisplayCommandChannel, ResponseChannel}; use crate::channel::{CommandChannel, DisplayCommand, DisplayCommandChannel, ResponseChannel};
use crate::protocol::Command; use crate::protocol::Command;
use super::framing::{self, CobsDecoder, MAX_FRAME};
const MAX_PACKET: usize = 64; const MAX_PACKET: usize = 64;
@@ -59,7 +59,15 @@ pub async fn host_task(
join( join(
usb_dev.run(), usb_dev.run(),
protocol_loop(sender, receiver, commands, responses, display_commands, has_display, mac), protocol_loop(
sender,
receiver,
commands,
responses,
display_commands,
has_display,
mac,
),
) )
.await; .await;
} }
@@ -106,7 +114,12 @@ async fn protocol_loop<'d, D: embassy_usb_driver::Driver<'d>>(
}); });
for cmd in cmds { for cmd in cmds {
framing::route_command( framing::route_command(
cmd, commands, responses, display_commands, has_display, mac, cmd,
commands,
responses,
display_commands,
has_display,
mac,
) )
.await; .await;
} }
+1 -2
View File
@@ -80,8 +80,7 @@ async fn run(spawner: Spawner) {
let parts = board.into_parts(); let parts = board.into_parts();
spawner.spawn( spawner.spawn(
radio::radio_task(parts.radio, &COMMANDS, &RESPONSES, &STATUS) radio::radio_task(parts.radio, &COMMANDS, &RESPONSES, &STATUS).expect("spawn radio_task"),
.expect("spawn radio_task"),
); );
spawner.spawn( spawner.spawn(