diff --git a/hal/src/peripherals/nvm/mod.rs b/hal/src/peripherals/nvm/mod.rs index e4082db3f19f..b41284b5739a 100644 --- a/hal/src/peripherals/nvm/mod.rs +++ b/hal/src/peripherals/nvm/mod.rs @@ -176,6 +176,12 @@ impl Nvm { Self { nvm } } + /// Releases the NvmCtrl resource + #[inline] + pub fn free(self) -> Nvmctrl { + self.nvm + } + /// Raw access to the registers. /// /// # Safety diff --git a/hal/src/peripherals/pwm/d11.rs b/hal/src/peripherals/pwm/d11.rs index 0b1b2bfb8497..49ef1c285475 100644 --- a/hal/src/peripherals/pwm/d11.rs +++ b/hal/src/peripherals/pwm/d11.rs @@ -57,6 +57,15 @@ impl $TYPE { } } + #[inline] + // Disables the TC, then releases it + pub fn free(self) -> crate::pac::$TC { + let count = self.tc.count16(); + count.ctrla().write(|w| w.swrst().set_bit()); + while count.ctrla().read().bits() & 1 != 0 {} + self.tc + } + pub fn set_period(&mut self, period: Hertz) { let params = TimerParams::new(period, self.clock_freq); diff --git a/hal/src/peripherals/pwm/d5x.rs b/hal/src/peripherals/pwm/d5x.rs index f101e3b494b2..30e4286a46cf 100644 --- a/hal/src/peripherals/pwm/d5x.rs +++ b/hal/src/peripherals/pwm/d5x.rs @@ -606,6 +606,14 @@ impl $TYPE { pinout, } } + + #[inline] + // Disables the TCC, then releases it + pub fn free(self) -> crate::pac::$TCC { + self.tcc.ctrla().write(|w| w.swrst().set_bit()); + while self.tcc.syncbusy().read().swrst().bit_is_set() {} + self.tcc + } } impl $crate::ehal_02::Pwm for $TYPE { diff --git a/hal/src/peripherals/timer/d11.rs b/hal/src/peripherals/timer/d11.rs index b484eabf417c..0f7658540857 100644 --- a/hal/src/peripherals/timer/d11.rs +++ b/hal/src/peripherals/timer/d11.rs @@ -129,6 +129,15 @@ impl TimerCounter<$TC> tc, } } + + #[inline] + // Disables the TC, then releases it + pub fn free(self) -> $TC { + let count = self.tc.count16(); + count.ctrla().write(|w| w.swrst().set_bit()); + while count.ctrla().read().bits() & 1 != 0 {} + self.tc + } } )+ } diff --git a/hal/src/peripherals/timer/d5x.rs b/hal/src/peripherals/timer/d5x.rs index 260f7e2f7b6a..a54c0e76ebf3 100644 --- a/hal/src/peripherals/timer/d5x.rs +++ b/hal/src/peripherals/timer/d5x.rs @@ -128,6 +128,15 @@ impl TimerCounter<$TC> tc, } } + + #[inline] + // Disables the TC, then releases it + pub fn free(self) -> $TC { + let count = self.tc.count_16(); + count.ctrla().write(|w| w.swrst().set_bit()); + while count.syncbusy().read().swrst().bit_is_set() {} + self.tc + } } )+ } diff --git a/hal/src/peripherals/trng.rs b/hal/src/peripherals/trng.rs index e6f76e14b32d..f4e7706d8037 100644 --- a/hal/src/peripherals/trng.rs +++ b/hal/src/peripherals/trng.rs @@ -13,6 +13,11 @@ impl Trng { Self(trng) } + /// Releases the Trng resource + pub fn free(self) -> pac::Trng { + self.0 + } + pub fn random(&self, buf: &mut [u8]) { for chunk in buf.chunks_mut(4) { chunk.copy_from_slice(&self.random_u32().to_le_bytes()[..chunk.len()]);