diff options
| author | Robin Mueller <[email protected]> | 2025-09-20 22:07:02 +0200 |
|---|---|---|
| committer | Robin Mueller <[email protected]> | 2025-09-23 11:37:46 +0200 |
| commit | 76d47ea1fa84b0940f3d9e3d830aa0b182f280b8 (patch) | |
| tree | 55ded09e4e813847c390d8083b70cac7185a21ca /embassy-nrf | |
| parent | de5dd10a5832b330465d93399b3a9cb761e24029 (diff) | |
add missing timer API
Diffstat (limited to 'embassy-nrf')
| -rw-r--r-- | embassy-nrf/CHANGELOG.md | 2 | ||||
| -rw-r--r-- | 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 | |||
| 14 | - added: basic RTC driver | 14 | - added: basic RTC driver |
| 15 | - changed: add persist() method for gpio, gpiote, timer and ppi | 15 | - changed: add persist() method for gpio, gpiote, timer and ppi |
| 16 | - changed: impl Drop for Timer | 16 | - changed: impl Drop for Timer |
| 17 | - added: expose `regs` for timer driver | ||
| 18 | - added: timer driver CC `clear_events` method | ||
| 17 | 19 | ||
| 18 | ## 0.7.0 - 2025-08-26 | 20 | ## 0.7.0 - 2025-08-26 |
| 19 | 21 | ||
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 { | |||
| 81 | /// | 81 | /// |
| 82 | /// It has either 4 or 6 Capture/Compare registers, which can be used to capture the current state of the counter | 82 | /// It has either 4 or 6 Capture/Compare registers, which can be used to capture the current state of the counter |
| 83 | /// or trigger an event when the counter reaches a certain value. | 83 | /// or trigger an event when the counter reaches a certain value. |
| 84 | |||
| 85 | /// Timer driver. | ||
| 86 | pub struct Timer<'d, T: Instance> { | 84 | pub struct Timer<'d, T: Instance> { |
| 87 | _p: Peri<'d, T>, | 85 | _p: Peri<'d, T>, |
| 88 | } | 86 | } |
| @@ -145,6 +143,13 @@ impl<'d, T: Instance> Timer<'d, T> { | |||
| 145 | this | 143 | this |
| 146 | } | 144 | } |
| 147 | 145 | ||
| 146 | /// Direct access to the register block. | ||
| 147 | #[cfg(feature = "unstable-pac")] | ||
| 148 | #[inline] | ||
| 149 | pub fn regs(&mut self) -> pac::timer::Timer { | ||
| 150 | T::regs() | ||
| 151 | } | ||
| 152 | |||
| 148 | /// Starts the timer. | 153 | /// Starts the timer. |
| 149 | pub fn start(&self) { | 154 | pub fn start(&self) { |
| 150 | T::regs().tasks_start().write_value(1) | 155 | T::regs().tasks_start().write_value(1) |
| @@ -248,7 +253,7 @@ pub struct Cc<'d, T: Instance> { | |||
| 248 | impl<'d, T: Instance> Cc<'d, T> { | 253 | impl<'d, T: Instance> Cc<'d, T> { |
| 249 | /// Get the current value stored in the register. | 254 | /// Get the current value stored in the register. |
| 250 | pub fn read(&self) -> u32 { | 255 | pub fn read(&self) -> u32 { |
| 251 | return T::regs().cc(self.n).read(); | 256 | T::regs().cc(self.n).read() |
| 252 | } | 257 | } |
| 253 | 258 | ||
| 254 | /// Set the value stored in the register. | 259 | /// Set the value stored in the register. |
| @@ -278,6 +283,12 @@ impl<'d, T: Instance> Cc<'d, T> { | |||
| 278 | Event::from_reg(T::regs().events_compare(self.n)) | 283 | Event::from_reg(T::regs().events_compare(self.n)) |
| 279 | } | 284 | } |
| 280 | 285 | ||
| 286 | /// Clear the COMPARE event for this CC register. | ||
| 287 | #[inline] | ||
| 288 | pub fn clear_events(&self) { | ||
| 289 | T::regs().events_compare(self.n).write_value(0); | ||
| 290 | } | ||
| 291 | |||
| 281 | /// Enable the shortcut between this CC register's COMPARE event and the timer's CLEAR task. | 292 | /// Enable the shortcut between this CC register's COMPARE event and the timer's CLEAR task. |
| 282 | /// | 293 | /// |
| 283 | /// This means that when the COMPARE event is fired, the CLEAR task will be triggered. | 294 | /// This means that when the COMPARE event is fired, the CLEAR task will be triggered. |
