diff options
author | Timo Kröger <timokroeger93@gmail.com> | 2022-06-25 10:10:59 +0200 |
---|---|---|
committer | Timo Kröger <timokroeger93@gmail.com> | 2022-08-26 15:44:58 +0200 |
commit | 69d80c086d2f22f66aa25fafb55918cb1c5e3bdd (patch) | |
tree | 0bf973222a790689263c5483582110f76e008ff9 /embassy-lora/src/stm32wl/mod.rs | |
parent | 6ee29ff0bd4d8cbd2da547dfdf631332cda551d4 (diff) | |
download | embassy-69d80c086d2f22f66aa25fafb55918cb1c5e3bdd.zip |
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.
Diffstat (limited to 'embassy-lora/src/stm32wl/mod.rs')
-rw-r--r-- | embassy-lora/src/stm32wl/mod.rs | 42 |
1 files changed, 7 insertions, 35 deletions
diff --git a/embassy-lora/src/stm32wl/mod.rs b/embassy-lora/src/stm32wl/mod.rs index 5e1773d5..7502dc37 100644 --- a/embassy-lora/src/stm32wl/mod.rs +++ b/embassy-lora/src/stm32wl/mod.rs @@ -4,7 +4,6 @@ use core::task::Poll; use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; use embassy_stm32::dma::NoDma; -use embassy_stm32::gpio::{AnyPin, Output}; use embassy_stm32::interrupt::{Interrupt, InterruptExt, SUBGHZ_RADIO}; use embassy_stm32::subghz::{ CalibrateImage, CfgIrq, CodingRate, Error, HeaderType, Irq, LoRaBandwidth, LoRaModParams, LoRaPacketParams, @@ -100,7 +99,7 @@ impl<'d, RS: RadioSwitch> SubGhzRadio<'d, RS> { async fn do_tx(&mut self, config: TxConfig, buf: &[u8]) -> Result<u32, RadioError> { //trace!("TX Request: {}", config); trace!("TX START"); - self.switch.set_tx_lp(); + self.switch.set_tx(); self.configure()?; self.radio @@ -236,15 +235,15 @@ impl<'d, RS: RadioSwitch> SubGhzRadio<'d, RS> { } } -impl PhyRxTx for SubGhzRadio<'static> { +impl<RS: RadioSwitch> PhyRxTx for SubGhzRadio<'static, RS> { type PhyError = RadioError; - type TxFuture<'m> = impl Future<Output = Result<u32, Self::PhyError>> + 'm; + type TxFuture<'m> = impl Future<Output = Result<u32, Self::PhyError>> + 'm where RS: 'm; fn tx<'m>(&'m mut self, config: TxConfig, buf: &'m [u8]) -> Self::TxFuture<'m> { async move { self.do_tx(config, buf).await } } - type RxFuture<'m> = impl Future<Output = Result<(usize, RxQuality), Self::PhyError>> + 'm; + type RxFuture<'m> = impl Future<Output = Result<(usize, RxQuality), Self::PhyError>> + 'm where RS: 'm; fn rx<'m>(&'m mut self, config: RfConfig, buf: &'m mut [u8]) -> Self::RxFuture<'m> { async move { self.do_rx(config, buf).await } } @@ -265,36 +264,9 @@ impl<'d, RS> Timings for SubGhzRadio<'d, RS> { } } -/// Represents the radio switch found on STM32WL based boards, used to control the radio for transmission or reception. -pub struct RadioSwitch<'d> { - ctrl1: Output<'d, AnyPin>, - ctrl2: Output<'d, AnyPin>, - ctrl3: Output<'d, AnyPin>, -} - -impl<'d> RadioSwitch<'d> { - pub fn new(ctrl1: Output<'d, AnyPin>, ctrl2: Output<'d, AnyPin>, ctrl3: Output<'d, AnyPin>) -> Self { - Self { ctrl1, ctrl2, ctrl3 } - } - - pub(crate) fn set_rx(&mut self) { - self.ctrl1.set_high(); - self.ctrl2.set_low(); - self.ctrl3.set_high(); - } - - pub(crate) fn set_tx_lp(&mut self) { - self.ctrl1.set_high(); - self.ctrl2.set_high(); - self.ctrl3.set_high(); - } - - #[allow(dead_code)] - pub(crate) fn set_tx_hp(&mut self) { - self.ctrl2.set_high(); - self.ctrl1.set_low(); - self.ctrl3.set_high(); - } +pub trait RadioSwitch { + fn set_rx(&mut self); + fn set_tx(&mut self); } fn convert_spreading_factor(sf: SpreadingFactor) -> SF { |