From 76d47ea1fa84b0940f3d9e3d830aa0b182f280b8 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 20 Sep 2025 22:07:02 +0200 Subject: add missing timer API --- embassy-nrf/CHANGELOG.md | 2 ++ embassy-nrf/src/timer.rs | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/embassy-nrf/CHANGELOG.md b/embassy-nrf/CHANGELOG.md index 0fedf9360..825d9d713 100644 --- a/embassy-nrf/CHANGELOG.md +++ b/embassy-nrf/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - added: basic RTC driver - changed: add persist() method for gpio, gpiote, timer and ppi - changed: impl Drop for Timer +- added: expose `regs` for timer driver +- added: timer driver CC `clear_events` method ## 0.7.0 - 2025-08-26 diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs index 5d6afe49b..1d1f77ea8 100644 --- a/embassy-nrf/src/timer.rs +++ b/embassy-nrf/src/timer.rs @@ -81,8 +81,6 @@ pub enum Frequency { /// /// It has either 4 or 6 Capture/Compare registers, which can be used to capture the current state of the counter /// or trigger an event when the counter reaches a certain value. - -/// Timer driver. pub struct Timer<'d, T: Instance> { _p: Peri<'d, T>, } @@ -145,6 +143,13 @@ impl<'d, T: Instance> Timer<'d, T> { this } + /// Direct access to the register block. + #[cfg(feature = "unstable-pac")] + #[inline] + pub fn regs(&mut self) -> pac::timer::Timer { + T::regs() + } + /// Starts the timer. pub fn start(&self) { T::regs().tasks_start().write_value(1) @@ -248,7 +253,7 @@ pub struct Cc<'d, T: Instance> { impl<'d, T: Instance> Cc<'d, T> { /// Get the current value stored in the register. pub fn read(&self) -> u32 { - return T::regs().cc(self.n).read(); + T::regs().cc(self.n).read() } /// Set the value stored in the register. @@ -278,6 +283,12 @@ impl<'d, T: Instance> Cc<'d, T> { Event::from_reg(T::regs().events_compare(self.n)) } + /// Clear the COMPARE event for this CC register. + #[inline] + pub fn clear_events(&self) { + T::regs().events_compare(self.n).write_value(0); + } + /// Enable the shortcut between this CC register's COMPARE event and the timer's CLEAR task. /// /// This means that when the COMPARE event is fired, the CLEAR task will be triggered. -- cgit