diff options
| author | Timo Kröger <[email protected]> | 2022-06-25 10:10:59 +0200 |
|---|---|---|
| committer | Timo Kröger <[email protected]> | 2022-08-26 15:44:58 +0200 |
| commit | 69d80c086d2f22f66aa25fafb55918cb1c5e3bdd (patch) | |
| tree | 0bf973222a790689263c5483582110f76e008ff9 /examples | |
| parent | 6ee29ff0bd4d8cbd2da547dfdf631332cda551d4 (diff) | |
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 9c390bdf0..0ef13354d 100644 --- a/examples/stm32wl/src/bin/lorawan.rs +++ b/examples/stm32wl/src/bin/lorawan.rs | |||
| @@ -9,7 +9,7 @@ use embassy_executor::Spawner; | |||
| 9 | use embassy_lora::stm32wl::*; | 9 | use embassy_lora::stm32wl::*; |
| 10 | use embassy_lora::LoraTimer; | 10 | use embassy_lora::LoraTimer; |
| 11 | use embassy_stm32::dma::NoDma; | 11 | use embassy_stm32::dma::NoDma; |
| 12 | use embassy_stm32::gpio::{Level, Output, Pin, Speed}; | 12 | use embassy_stm32::gpio::{AnyPin, Level, Output, Pin, Speed}; |
| 13 | use embassy_stm32::rng::Rng; | 13 | use embassy_stm32::rng::Rng; |
| 14 | use embassy_stm32::subghz::*; | 14 | use embassy_stm32::subghz::*; |
| 15 | use embassy_stm32::{interrupt, pac}; | 15 | use embassy_stm32::{interrupt, pac}; |
| @@ -17,6 +17,32 @@ use lorawan::default_crypto::DefaultFactory as Crypto; | |||
| 17 | use lorawan_device::async_device::{region, Device, JoinMode}; | 17 | use lorawan_device::async_device::{region, Device, JoinMode}; |
| 18 | use {defmt_rtt as _, panic_probe as _}; | 18 | use {defmt_rtt as _, panic_probe as _}; |
| 19 | 19 | ||
| 20 | struct RadioSwitch<'a> { | ||
| 21 | ctrl1: Output<'a, AnyPin>, | ||
| 22 | ctrl2: Output<'a, AnyPin>, | ||
| 23 | ctrl3: Output<'a, AnyPin>, | ||
| 24 | } | ||
| 25 | |||
| 26 | impl<'a> RadioSwitch<'a> { | ||
| 27 | fn new(ctrl1: Output<'a, AnyPin>, ctrl2: Output<'a, AnyPin>, ctrl3: Output<'a, AnyPin>) -> Self { | ||
| 28 | Self { ctrl1, ctrl2, ctrl3 } | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | impl<'a> embassy_lora::stm32wl::RadioSwitch for RadioSwitch<'a> { | ||
| 33 | fn set_rx(&mut self) { | ||
| 34 | self.ctrl1.set_high(); | ||
| 35 | self.ctrl2.set_low(); | ||
| 36 | self.ctrl3.set_high(); | ||
| 37 | } | ||
| 38 | |||
| 39 | fn set_tx(&mut self) { | ||
| 40 | self.ctrl1.set_low(); | ||
| 41 | self.ctrl2.set_high(); | ||
| 42 | self.ctrl3.set_high(); | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 20 | #[embassy_executor::main] | 46 | #[embassy_executor::main] |
| 21 | async fn main(_spawner: Spawner) { | 47 | async fn main(_spawner: Spawner) { |
| 22 | let mut config = embassy_stm32::Config::default(); | 48 | let mut config = embassy_stm32::Config::default(); |
