1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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;
}
|