diff options
| -rw-r--r-- | embassy-nrf/src/gpiote.rs | 18 | ||||
| -rw-r--r-- | embassy-nrf/src/timer.rs | 9 |
2 files changed, 27 insertions, 0 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 | ||
| 196 | impl 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 | |||
| 196 | impl<'d> Drop for InputChannel<'d> { | 205 | impl<'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 | ||
| 275 | impl 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 | |||
| 266 | impl<'d> Drop for OutputChannel<'d> { | 284 | impl<'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 b6a77bd2e..5d6afe49b 100644 --- a/embassy-nrf/src/timer.rs +++ b/embassy-nrf/src/timer.rs | |||
| @@ -218,6 +218,15 @@ 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 | |||
| 221 | impl<'d, T: Instance> Drop for Timer<'d, T> { | 230 | impl<'d, T: Instance> Drop for Timer<'d, T> { |
| 222 | fn drop(&mut self) { | 231 | fn drop(&mut self) { |
| 223 | self.stop(); | 232 | self.stop(); |
