aboutsummaryrefslogtreecommitdiff
path: root/embassy-lora
diff options
context:
space:
mode:
authorxoviat <[email protected]>2023-05-24 18:09:04 -0500
committerxoviat <[email protected]>2023-05-24 18:09:04 -0500
commitb6ba1ea53ada2f503ae89de66490957723a21866 (patch)
tree759273f8160ab66b8793044a456342fd6ee5a573 /embassy-lora
parent316be179af500fdf31606f085adf77c6879a396d (diff)
stm32: move lora to bind_interrupts
Diffstat (limited to 'embassy-lora')
-rw-r--r--embassy-lora/src/iv.rs36
1 files changed, 21 insertions, 15 deletions
diff --git a/embassy-lora/src/iv.rs b/embassy-lora/src/iv.rs
index f81134405..d515bc365 100644
--- a/embassy-lora/src/iv.rs
+++ b/embassy-lora/src/iv.rs
@@ -1,7 +1,9 @@
1#[cfg(feature = "stm32wl")] 1#[cfg(feature = "stm32wl")]
2use embassy_stm32::interrupt;
3#[cfg(feature = "stm32wl")]
2use embassy_stm32::interrupt::*; 4use embassy_stm32::interrupt::*;
3#[cfg(feature = "stm32wl")] 5#[cfg(feature = "stm32wl")]
4use embassy_stm32::{pac, PeripheralRef}; 6use embassy_stm32::pac;
5#[cfg(feature = "stm32wl")] 7#[cfg(feature = "stm32wl")]
6use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; 8use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
7#[cfg(feature = "stm32wl")] 9#[cfg(feature = "stm32wl")]
@@ -13,47 +15,51 @@ use lora_phy::mod_params::RadioError::*;
13use lora_phy::mod_params::{BoardType, RadioError}; 15use lora_phy::mod_params::{BoardType, RadioError};
14use lora_phy::mod_traits::InterfaceVariant; 16use lora_phy::mod_traits::InterfaceVariant;
15 17
18/// Interrupt handler.
19#[cfg(feature = "stm32wl")]
20pub struct InterruptHandler {}
21
22#[cfg(feature = "stm32wl")]
23impl interrupt::Handler<interrupt::SUBGHZ_RADIO> for InterruptHandler {
24 unsafe fn on_interrupt() {
25 unsafe { SUBGHZ_RADIO::steal() }.disable();
26 IRQ_SIGNAL.signal(());
27 }
28}
29
16#[cfg(feature = "stm32wl")] 30#[cfg(feature = "stm32wl")]
17static IRQ_SIGNAL: Signal<CriticalSectionRawMutex, ()> = Signal::new(); 31static IRQ_SIGNAL: Signal<CriticalSectionRawMutex, ()> = Signal::new();
18 32
19#[cfg(feature = "stm32wl")] 33#[cfg(feature = "stm32wl")]
20/// Base for the InterfaceVariant implementation for an stm32wl/sx1262 combination 34/// Base for the InterfaceVariant implementation for an stm32wl/sx1262 combination
21pub struct Stm32wlInterfaceVariant<'a, CTRL> { 35pub struct Stm32wlInterfaceVariant<CTRL> {
22 board_type: BoardType, 36 board_type: BoardType,
23 irq: PeripheralRef<'a, SUBGHZ_RADIO>,
24 rf_switch_rx: Option<CTRL>, 37 rf_switch_rx: Option<CTRL>,
25 rf_switch_tx: Option<CTRL>, 38 rf_switch_tx: Option<CTRL>,
26} 39}
27 40
28#[cfg(feature = "stm32wl")] 41#[cfg(feature = "stm32wl")]
29impl<'a, CTRL> Stm32wlInterfaceVariant<'a, CTRL> 42impl<'a, CTRL> Stm32wlInterfaceVariant<CTRL>
30where 43where
31 CTRL: OutputPin, 44 CTRL: OutputPin,
32{ 45{
33 /// Create an InterfaceVariant instance for an stm32wl/sx1262 combination 46 /// Create an InterfaceVariant instance for an stm32wl/sx1262 combination
34 pub fn new( 47 pub fn new(
35 irq: PeripheralRef<'a, SUBGHZ_RADIO>, 48 _irq: impl interrupt::Binding<interrupt::SUBGHZ_RADIO, InterruptHandler>,
36 rf_switch_rx: Option<CTRL>, 49 rf_switch_rx: Option<CTRL>,
37 rf_switch_tx: Option<CTRL>, 50 rf_switch_tx: Option<CTRL>,
38 ) -> Result<Self, RadioError> { 51 ) -> Result<Self, RadioError> {
39 irq.disable(); 52 unsafe { interrupt::SUBGHZ_RADIO::steal() }.disable();
40 irq.set_handler(Self::on_interrupt);
41 Ok(Self { 53 Ok(Self {
42 board_type: BoardType::Stm32wlSx1262, // updated when associated with a specific LoRa board 54 board_type: BoardType::Stm32wlSx1262, // updated when associated with a specific LoRa board
43 irq,
44 rf_switch_rx, 55 rf_switch_rx,
45 rf_switch_tx, 56 rf_switch_tx,
46 }) 57 })
47 } 58 }
48
49 fn on_interrupt(_: *mut ()) {
50 unsafe { SUBGHZ_RADIO::steal() }.disable();
51 IRQ_SIGNAL.signal(());
52 }
53} 59}
54 60
55#[cfg(feature = "stm32wl")] 61#[cfg(feature = "stm32wl")]
56impl<CTRL> InterfaceVariant for Stm32wlInterfaceVariant<'_, CTRL> 62impl<CTRL> InterfaceVariant for Stm32wlInterfaceVariant<CTRL>
57where 63where
58 CTRL: OutputPin, 64 CTRL: OutputPin,
59{ 65{
@@ -89,7 +95,7 @@ where
89 } 95 }
90 96
91 async fn await_irq(&mut self) -> Result<(), RadioError> { 97 async fn await_irq(&mut self) -> Result<(), RadioError> {
92 self.irq.enable(); 98 unsafe { interrupt::SUBGHZ_RADIO::steal() }.enable();
93 IRQ_SIGNAL.wait().await; 99 IRQ_SIGNAL.wait().await;
94 Ok(()) 100 Ok(())
95 } 101 }