aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Tran <[email protected]>2025-09-21 23:01:11 -0500
committerMatthew Tran <[email protected]>2025-09-21 23:01:11 -0500
commitd463a57879c0e02c188f63ab99c40d6ab91ea54e (patch)
tree66f2329c08b4eed652dba04c48456425cba3819b
parentc692a97b654adc50f997852a360ce3277cb73db4 (diff)
nrf: add persist() method for gpiote and timer
-rw-r--r--embassy-nrf/src/gpiote.rs18
-rw-r--r--embassy-nrf/src/timer.rs9
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
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 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
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
221impl<'d, T: Instance> Drop for Timer<'d, T> { 230impl<'d, T: Instance> Drop for Timer<'d, T> {
222 fn drop(&mut self) { 231 fn drop(&mut self) {
223 self.stop(); 232 self.stop();