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 /examples | |
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 'examples')
-rw-r--r-- | examples/stm32wl/src/bin/lorawan.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/examples/stm32wl/src/bin/lorawan.rs b/examples/stm32wl/src/bin/lorawan.rs index 9c390bdf..0ef13354 100644 --- a/examples/stm32wl/src/bin/lorawan.rs +++ b/examples/stm32wl/src/bin/lorawan.rs @@ -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(); |