diff options
Diffstat (limited to 'embassy-nrf/src/timer.rs')
| -rw-r--r-- | embassy-nrf/src/timer.rs | 19 |
1 files changed, 17 insertions, 2 deletions
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 | ||
| 221 | impl<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 | |||
| 230 | impl<'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. |
