lora: Use a trait for RF frontend switching
The Seeed Studio Lora-E5 module only has two control pins. With the `RadioSwitch` trait the user can implement any method required by the module/board to control the TX/RX direction of the radio frontend.
This commit is contained in:
@ -9,7 +9,7 @@ use embassy_executor::Spawner;
|
||||
use embassy_lora::stm32wl::*;
|
||||
use embassy_lora::LoraTimer;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::gpio::{Level, Output, Pin, Speed};
|
||||
use embassy_stm32::gpio::{AnyPin, Level, Output, Pin, Speed};
|
||||
use embassy_stm32::rng::Rng;
|
||||
use embassy_stm32::subghz::*;
|
||||
use embassy_stm32::{interrupt, pac};
|
||||
@ -17,6 +17,32 @@ use lorawan::default_crypto::DefaultFactory as Crypto;
|
||||
use lorawan_device::async_device::{region, Device, JoinMode};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
struct RadioSwitch<'a> {
|
||||
ctrl1: Output<'a, AnyPin>,
|
||||
ctrl2: Output<'a, AnyPin>,
|
||||
ctrl3: Output<'a, AnyPin>,
|
||||
}
|
||||
|
||||
impl<'a> RadioSwitch<'a> {
|
||||
fn new(ctrl1: Output<'a, AnyPin>, ctrl2: Output<'a, AnyPin>, ctrl3: Output<'a, AnyPin>) -> Self {
|
||||
Self { ctrl1, ctrl2, ctrl3 }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> embassy_lora::stm32wl::RadioSwitch for RadioSwitch<'a> {
|
||||
fn set_rx(&mut self) {
|
||||
self.ctrl1.set_high();
|
||||
self.ctrl2.set_low();
|
||||
self.ctrl3.set_high();
|
||||
}
|
||||
|
||||
fn set_tx(&mut self) {
|
||||
self.ctrl1.set_low();
|
||||
self.ctrl2.set_high();
|
||||
self.ctrl3.set_high();
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let mut config = embassy_stm32::Config::default();
|
||||
|
Reference in New Issue
Block a user