From d463a57879c0e02c188f63ab99c40d6ab91ea54e Mon Sep 17 00:00:00 2001 From: Matthew Tran <0e4ef622@gmail.com> Date: Sun, 21 Sep 2025 23:01:11 -0500 Subject: nrf: add persist() method for gpiote and timer --- embassy-nrf/src/gpiote.rs | 18 ++++++++++++++++++ embassy-nrf/src/timer.rs | 9 +++++++++ 2 files changed, 27 insertions(+) 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> { pin: Input<'d>, } +impl InputChannel<'static> { + /// Persist the channel's configuration for the rest of the program's lifetime. This method + /// should be preferred over [`core::mem::forget()`] because the `'static` bound prevents + /// accidental reuse of the underlying peripheral. + pub fn persist(self) { + core::mem::forget(self); + } +} + impl<'d> Drop for InputChannel<'d> { fn drop(&mut self) { let g = regs(); @@ -263,6 +272,15 @@ pub struct OutputChannel<'d> { _pin: Output<'d>, } +impl OutputChannel<'static> { + /// Persist the channel's configuration for the rest of the program's lifetime. This method + /// should be preferred over [`core::mem::forget()`] because the `'static` bound prevents + /// accidental reuse of the underlying peripheral. + pub fn persist(self) { + core::mem::forget(self); + } +} + impl<'d> Drop for OutputChannel<'d> { fn drop(&mut self) { 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> { } } +impl Timer<'static, T> { + /// Persist the timer's configuration for the rest of the program's lifetime. This method + /// should be preferred over [`core::mem::forget()`] because the `'static` bound prevents + /// accidental reuse of the underlying peripheral. + pub fn persist(self) { + core::mem::forget(self); + } +} + impl<'d, T: Instance> Drop for Timer<'d, T> { fn drop(&mut self) { self.stop(); -- cgit