Skip to content

Commit 853c451

Browse files
authored
bsp: add RfSwitch::steal
1 parent e73fdc2 commit 853c451

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Added
99
- Added `Rtc::alarm_{a,b}` to get the alarm value.
1010
- Added `impl From<Alarm> for chrono::NaiveTime`.
11+
- Added `RfSwitch::steal()` to all BSPs.
1112

1213
## [0.5.0] - 2022-05-08
1314
### Added

lora-e5-bsp/src/lib.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,47 @@ impl RfSwitch {
5050
}
5151
}
5252

53+
/// Steal the RF switch from whatever is currently using it.
54+
///
55+
/// # Safety
56+
///
57+
/// 1. Ensure that the code stealing the RF switch has exclusive access.
58+
/// Singleton checks are bypassed with this method.
59+
/// 2. You must set up the RF switch pins.
60+
/// No setup will occur when using this method.
61+
///
62+
/// # Example
63+
///
64+
/// ```no_run
65+
/// use lora_e5_bsp::{
66+
/// hal::{
67+
/// cortex_m,
68+
/// gpio::{pins, Output, PortA},
69+
/// pac,
70+
/// },
71+
/// RfSwitch,
72+
/// };
73+
///
74+
/// let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
75+
///
76+
/// let pa: PortA = PortA::split(dp.GPIOA, &mut dp.RCC);
77+
/// cortex_m::interrupt::free(|cs| {
78+
/// let _: Output<pins::A4> = Output::default(pa.a4, cs);
79+
/// let _: Output<pins::A5> = Output::default(pa.a5, cs);
80+
/// });
81+
///
82+
/// // safety:
83+
/// // 1. we have exclusive access to the underlying pins
84+
/// // 2. the pins have been setup
85+
/// let rfs: RfSwitch = unsafe { RfSwitch::steal() };
86+
/// ```
87+
pub unsafe fn steal() -> Self {
88+
RfSwitch {
89+
a4: Output::steal(),
90+
a5: Output::steal(),
91+
}
92+
}
93+
5394
/// Set the RF switch to receive.
5495
///
5596
/// # Example

nucleo-wl55jc-bsp/src/lib.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,49 @@ impl RfSwitch {
5353
}
5454
}
5555

56+
/// Steal the RF switch from whatever is currently using it.
57+
///
58+
/// # Safety
59+
///
60+
/// 1. Ensure that the code stealing the RF switch has exclusive access.
61+
/// Singleton checks are bypassed with this method.
62+
/// 2. You must set up the RF switch pins.
63+
/// No setup will occur when using this method.
64+
///
65+
/// # Example
66+
///
67+
/// ```no_run
68+
/// use nucleo_wl55jc_bsp::{
69+
/// hal::{
70+
/// cortex_m,
71+
/// gpio::{pins, Output, PortC},
72+
/// pac,
73+
/// },
74+
/// RfSwitch,
75+
/// };
76+
///
77+
/// let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
78+
///
79+
/// let pc: PortC = PortC::split(dp.GPIOC, &mut dp.RCC);
80+
/// cortex_m::interrupt::free(|cs| {
81+
/// let _: Output<pins::C3> = Output::default(pc.c3, cs);
82+
/// let _: Output<pins::C4> = Output::default(pc.c4, cs);
83+
/// let _: Output<pins::C5> = Output::default(pc.c5, cs);
84+
/// });
85+
///
86+
/// // safety:
87+
/// // 1. we have exclusive access to the underlying pins
88+
/// // 2. the pins have been setup
89+
/// let rfs: RfSwitch = unsafe { RfSwitch::steal() };
90+
/// ```
91+
pub unsafe fn steal() -> Self {
92+
RfSwitch {
93+
fe_ctrl1: Output::steal(),
94+
fe_ctrl2: Output::steal(),
95+
fe_ctrl3: Output::steal(),
96+
}
97+
}
98+
5699
/// Set the RF switch to receive.
57100
///
58101
/// # Example

0 commit comments

Comments
 (0)