Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions hal/src/peripherals/nvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions hal/src/peripherals/pwm/d11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions hal/src/peripherals/pwm/d5x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,14 @@ impl<I: PinId, M: PinMode> $TYPE<I, M> {
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<I: PinId, M: PinMode> $crate::ehal_02::Pwm for $TYPE<I, M> {
Expand Down
9 changes: 9 additions & 0 deletions hal/src/peripherals/timer/d11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
)+
}
Expand Down
9 changes: 9 additions & 0 deletions hal/src/peripherals/timer/d5x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
)+
}
Expand Down
5 changes: 5 additions & 0 deletions hal/src/peripherals/trng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
Expand Down