aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-nrf/src')
-rw-r--r--embassy-nrf/src/gpiote.rs18
-rw-r--r--embassy-nrf/src/timer.rs19
2 files changed, 35 insertions, 2 deletions
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs
index d169b49f9..43e43f0bf 100644
--- a/embassy-nrf/src/gpiote.rs
+++ b/embassy-nrf/src/gpiote.rs
@@ -193,6 +193,15 @@ pub struct InputChannel<'d> {
193 pin: Input<'d>, 193 pin: Input<'d>,
194} 194}
195 195
196impl InputChannel<'static> {
197 /// Persist the channel's configuration for the rest of the program's lifetime. This method
198 /// should be preferred over [`core::mem::forget()`] because the `'static` bound prevents
199 /// accidental reuse of the underlying peripheral.
200 pub fn persist(self) {
201 core::mem::forget(self);
202 }
203}
204
196impl<'d> Drop for InputChannel<'d> { 205impl<'d> Drop for InputChannel<'d> {
197 fn drop(&mut self) { 206 fn drop(&mut self) {
198 let g = regs(); 207 let g = regs();
@@ -263,6 +272,15 @@ pub struct OutputChannel<'d> {
263 _pin: Output<'d>, 272 _pin: Output<'d>,
264} 273}
265 274
275impl OutputChannel<'static> {
276 /// Persist the channel's configuration for the rest of the program's lifetime. This method
277 /// should be preferred over [`core::mem::forget()`] because the `'static` bound prevents
278 /// accidental reuse of the underlying peripheral.
279 pub fn persist(self) {
280 core::mem::forget(self);
281 }
282}
283
266impl<'d> Drop for OutputChannel<'d> { 284impl<'d> Drop for OutputChannel<'d> {
267 fn drop(&mut self) { 285 fn drop(&mut self) {
268 let g = regs(); 286 let g = regs();
diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs
index de2875765..5d6afe49b 100644
--- a/embassy-nrf/src/timer.rs
+++ b/embassy-nrf/src/timer.rs
@@ -104,7 +104,7 @@ impl<'d, T: Instance> Timer<'d, T> {
104 Self::new_inner(timer, true) 104 Self::new_inner(timer, true)
105 } 105 }
106 106
107 fn new_inner(timer: Peri<'d, T>, _is_counter: bool) -> Self { 107 fn new_inner(timer: Peri<'d, T>, is_counter: bool) -> Self {
108 let regs = T::regs(); 108 let regs = T::regs();
109 109
110 let this = Self { _p: timer }; 110 let this = Self { _p: timer };
@@ -114,7 +114,7 @@ impl<'d, T: Instance> Timer<'d, T> {
114 this.stop(); 114 this.stop();
115 115
116 regs.mode().write(|w| { 116 regs.mode().write(|w| {
117 w.set_mode(match _is_counter { 117 w.set_mode(match is_counter {
118 #[cfg(not(feature = "_nrf51"))] 118 #[cfg(not(feature = "_nrf51"))]
119 true => vals::Mode::LOW_POWER_COUNTER, 119 true => vals::Mode::LOW_POWER_COUNTER,
120 #[cfg(feature = "_nrf51")] 120 #[cfg(feature = "_nrf51")]
@@ -218,6 +218,21 @@ impl<'d, T: Instance> Timer<'d, T> {
218 } 218 }
219} 219}
220 220
221impl<T: Instance> Timer<'static, T> {
222 /// Persist the timer's configuration for the rest of the program's lifetime. This method
223 /// should be preferred over [`core::mem::forget()`] because the `'static` bound prevents
224 /// accidental reuse of the underlying peripheral.
225 pub fn persist(self) {
226 core::mem::forget(self);
227 }
228}
229
230impl<'d, T: Instance> Drop for Timer<'d, T> {
231 fn drop(&mut self) {
232 self.stop();
233 }
234}
235
221/// A representation of a timer's Capture/Compare (CC) register. 236/// A representation of a timer's Capture/Compare (CC) register.
222/// 237///
223/// A CC register holds a 32-bit value. 238/// A CC register holds a 32-bit value.