aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/timer.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-07-23 15:13:47 +0200
committerDario Nieuwenhuis <[email protected]>2022-07-23 15:13:47 +0200
commit709df0dc1dfff577fb79bbc2f67ea84670072456 (patch)
tree4a54aee47c0d3881b9e0bc809e075728cee8eeae /embassy-nrf/src/timer.rs
parent19d1ef0e29fdd0bf0407cbe37c388e8a87e7ddfe (diff)
nrf: replace PhantomData usages with PeripheralRef.
Diffstat (limited to 'embassy-nrf/src/timer.rs')
-rw-r--r--embassy-nrf/src/timer.rs28
1 files changed, 18 insertions, 10 deletions
diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs
index d7a7c4d70..8deecdc03 100644
--- a/embassy-nrf/src/timer.rs
+++ b/embassy-nrf/src/timer.rs
@@ -5,7 +5,7 @@ use core::task::Poll;
5 5
6use embassy::waitqueue::AtomicWaker; 6use embassy::waitqueue::AtomicWaker;
7use embassy_hal_common::drop::OnDrop; 7use embassy_hal_common::drop::OnDrop;
8use embassy_hal_common::into_ref; 8use embassy_hal_common::{into_ref, PeripheralRef};
9use futures::future::poll_fn; 9use futures::future::poll_fn;
10 10
11use crate::interrupt::{Interrupt, InterruptExt}; 11use crate::interrupt::{Interrupt, InterruptExt};
@@ -95,7 +95,8 @@ impl TimerType for Awaitable {}
95impl TimerType for NotAwaitable {} 95impl TimerType for NotAwaitable {}
96 96
97pub struct Timer<'d, T: Instance, I: TimerType = NotAwaitable> { 97pub struct Timer<'d, T: Instance, I: TimerType = NotAwaitable> {
98 phantom: PhantomData<(&'d mut T, I)>, 98 _p: PeripheralRef<'d, T>,
99 _i: PhantomData<I>,
99} 100}
100 101
101impl<'d, T: Instance> Timer<'d, T, Awaitable> { 102impl<'d, T: Instance> Timer<'d, T, Awaitable> {
@@ -123,10 +124,15 @@ impl<'d, T: Instance, I: TimerType> Timer<'d, T, I> {
123 /// Create a `Timer` without an interrupt, meaning `Cc::wait` won't work. 124 /// Create a `Timer` without an interrupt, meaning `Cc::wait` won't work.
124 /// 125 ///
125 /// This is used by the public constructors. 126 /// This is used by the public constructors.
126 fn new_irqless(_timer: impl Peripheral<P = T> + 'd) -> Self { 127 fn new_irqless(timer: impl Peripheral<P = T> + 'd) -> Self {
128 into_ref!(timer);
129
127 let regs = T::regs(); 130 let regs = T::regs();
128 131
129 let mut this = Self { phantom: PhantomData }; 132 let mut this = Self {
133 _p: timer,
134 _i: PhantomData,
135 };
130 136
131 // Stop the timer before doing anything else, 137 // Stop the timer before doing anything else,
132 // since changing BITMODE while running can cause 'unpredictable behaviour' according to the specification. 138 // since changing BITMODE while running can cause 'unpredictable behaviour' according to the specification.
@@ -230,7 +236,8 @@ impl<'d, T: Instance, I: TimerType> Timer<'d, T, I> {
230 } 236 }
231 Cc { 237 Cc {
232 n, 238 n,
233 phantom: PhantomData, 239 _p: self._p.reborrow(),
240 _i: PhantomData,
234 } 241 }
235 } 242 }
236} 243}
@@ -242,12 +249,13 @@ impl<'d, T: Instance, I: TimerType> Timer<'d, T, I> {
242/// 249///
243/// The timer will fire the register's COMPARE event when its counter reaches the value stored in the register. 250/// The timer will fire the register's COMPARE event when its counter reaches the value stored in the register.
244/// When the register's CAPTURE task is triggered, the timer will store the current value of its counter in the register 251/// When the register's CAPTURE task is triggered, the timer will store the current value of its counter in the register
245pub struct Cc<'a, T: Instance, I: TimerType = NotAwaitable> { 252pub struct Cc<'d, T: Instance, I: TimerType = NotAwaitable> {
246 n: usize, 253 n: usize,
247 phantom: PhantomData<(&'a mut T, I)>, 254 _p: PeripheralRef<'d, T>,
255 _i: PhantomData<I>,
248} 256}
249 257
250impl<'a, T: Instance> Cc<'a, T, Awaitable> { 258impl<'d, T: Instance> Cc<'d, T, Awaitable> {
251 /// Wait until the timer's counter reaches the value stored in this register. 259 /// Wait until the timer's counter reaches the value stored in this register.
252 /// 260 ///
253 /// This requires a mutable reference so that this task's waker cannot be overwritten by a second call to `wait`. 261 /// This requires a mutable reference so that this task's waker cannot be overwritten by a second call to `wait`.
@@ -281,9 +289,9 @@ impl<'a, T: Instance> Cc<'a, T, Awaitable> {
281 on_drop.defuse(); 289 on_drop.defuse();
282 } 290 }
283} 291}
284impl<'a, T: Instance> Cc<'a, T, NotAwaitable> {} 292impl<'d, T: Instance> Cc<'d, T, NotAwaitable> {}
285 293
286impl<'a, T: Instance, I: TimerType> Cc<'a, T, I> { 294impl<'d, T: Instance, I: TimerType> Cc<'d, T, I> {
287 /// Get the current value stored in the register. 295 /// Get the current value stored in the register.
288 pub fn read(&self) -> u32 { 296 pub fn read(&self) -> u32 {
289 T::regs().cc[self.n].read().cc().bits() 297 T::regs().cc[self.n].read().cc().bits()