diff options
| author | s-ol <s+removethis@s-ol.nu> | 2026-03-30 16:58:14 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2026-03-30 16:58:14 +0000 |
| commit | e249f617177c228c6f961c02a2640e88c328ff61 (patch) | |
| tree | 50b0766c4cf34f0fff14da2ce72c8b00976ba1e2 /src/bin/example/radio.rs | |
| parent | initial commit (diff) | |
| download | t144-meshcore-example-main.tar.gz t144-meshcore-example-main.zip | |
Diffstat (limited to 'src/bin/example/radio.rs')
| -rw-r--r-- | src/bin/example/radio.rs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/bin/example/radio.rs b/src/bin/example/radio.rs new file mode 100644 index 0000000..db677ee --- /dev/null +++ b/src/bin/example/radio.rs @@ -0,0 +1,70 @@ +use embassy_nrf::gpio::{AnyPin, Input, Level, Output, OutputDrive, Pull}; +use embassy_nrf::{interrupt::typelevel::Binding, spim, Peri}; +use embassy_time::Delay; +use embedded_hal_bus::spi::ExclusiveDevice; + +use lora_phy::iv::GenericSx126xInterfaceVariant; +use lora_phy::sx126x::{Config, Sx1262, Sx126x, TcxoCtrlVoltage}; +use lora_phy::LoRa; + +type SPIDevice<'t> = ExclusiveDevice<spim::Spim<'t>, Output<'t>, Delay>; + +type RadioImpl<'t> = LoRa< + Sx126x<SPIDevice<'t>, GenericSx126xInterfaceVariant<Output<'t>, Input<'t>>, Sx1262>, + Delay, +>; + +pub struct Radio(RadioImpl<'static>); + +pub struct Pins<'t> { + pub sck: Peri<'t, AnyPin>, + pub miso: Peri<'t, AnyPin>, + pub mosi: Peri<'t, AnyPin>, + pub cs: Peri<'t, AnyPin>, + pub rst: Peri<'t, AnyPin>, + pub dio1: Peri<'t, AnyPin>, + pub busy: Peri<'t, AnyPin>, +} + +pub async fn init<T: spim::Instance>( + spi_instance: Peri<'static, T>, + irq_binding: impl Binding<T::Interrupt, spim::InterruptHandler<T>> + 'static, + pins: Pins<'static>, +) -> Radio { + let out_rst = Output::new(pins.rst, Level::High, OutputDrive::Standard); + let out_cs = Output::new(pins.cs, Level::High, OutputDrive::Standard); + + let in_dio1 = Input::new(pins.dio1, Pull::None); + let in_busy = Input::new(pins.busy, Pull::None); + + let mut spi_config = spim::Config::default(); + spi_config.frequency = spim::Frequency::M8; + let spi_bus = spim::Spim::new( + spi_instance, + irq_binding, + pins.sck, + pins.miso, + pins.mosi, + spi_config, + ); + let spi_dev = ExclusiveDevice::new(spi_bus, out_cs, Delay).unwrap(); + + let iv = GenericSx126xInterfaceVariant::new(out_rst, in_dio1, in_busy, None, None).unwrap(); + let config = Config { + chip: Sx1262, + tcxo_ctrl: Some(TcxoCtrlVoltage::Ctrl1V8), + use_dcdc: true, + rx_boost: true, + }; + + let lora: RadioImpl = LoRa::new(Sx126x::new(spi_dev, iv, config), false, Delay) + .await + .unwrap(); + + Radio(lora) +} + +#[embassy_executor::task] +pub async fn task(mut radio: Radio) { + t114_meshcore_example::radio_task(&mut radio.0).await; +} |
