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, Output<'t>, Delay>; type RadioImpl<'t> = LoRa< Sx126x, GenericSx126xInterfaceVariant, 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( spi_instance: Peri<'static, T>, irq_binding: impl Binding> + '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; }