aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTimo Kröger <[email protected]>2022-06-25 10:10:59 +0200
committerTimo Kröger <[email protected]>2022-08-26 15:44:58 +0200
commit69d80c086d2f22f66aa25fafb55918cb1c5e3bdd (patch)
tree0bf973222a790689263c5483582110f76e008ff9 /examples
parent6ee29ff0bd4d8cbd2da547dfdf631332cda551d4 (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.rs28
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;
9use embassy_lora::stm32wl::*; 9use embassy_lora::stm32wl::*;
10use embassy_lora::LoraTimer; 10use embassy_lora::LoraTimer;
11use embassy_stm32::dma::NoDma; 11use embassy_stm32::dma::NoDma;
12use embassy_stm32::gpio::{Level, Output, Pin, Speed}; 12use embassy_stm32::gpio::{AnyPin, Level, Output, Pin, Speed};
13use embassy_stm32::rng::Rng; 13use embassy_stm32::rng::Rng;
14use embassy_stm32::subghz::*; 14use embassy_stm32::subghz::*;
15use embassy_stm32::{interrupt, pac}; 15use embassy_stm32::{interrupt, pac};
@@ -17,6 +17,32 @@ use lorawan::default_crypto::DefaultFactory as Crypto;
17use lorawan_device::async_device::{region, Device, JoinMode}; 17use lorawan_device::async_device::{region, Device, JoinMode};
18use {defmt_rtt as _, panic_probe as _}; 18use {defmt_rtt as _, panic_probe as _};
19 19
20struct RadioSwitch<'a> {
21 ctrl1: Output<'a, AnyPin>,
22 ctrl2: Output<'a, AnyPin>,
23 ctrl3: Output<'a, AnyPin>,
24}
25
26impl<'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
32impl<'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]
21async fn main(_spawner: Spawner) { 47async fn main(_spawner: Spawner) {
22 let mut config = embassy_stm32::Config::default(); 48 let mut config = embassy_stm32::Config::default();