From 709df0dc1dfff577fb79bbc2f67ea84670072456 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sat, 23 Jul 2022 15:13:47 +0200 Subject: nrf: replace PhantomData usages with PeripheralRef. --- embassy-nrf/src/timer.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'embassy-nrf/src/timer.rs') 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; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::drop::OnDrop; -use embassy_hal_common::into_ref; +use embassy_hal_common::{into_ref, PeripheralRef}; use futures::future::poll_fn; use crate::interrupt::{Interrupt, InterruptExt}; @@ -95,7 +95,8 @@ impl TimerType for Awaitable {} impl TimerType for NotAwaitable {} pub struct Timer<'d, T: Instance, I: TimerType = NotAwaitable> { - phantom: PhantomData<(&'d mut T, I)>, + _p: PeripheralRef<'d, T>, + _i: PhantomData, } impl<'d, T: Instance> Timer<'d, T, Awaitable> { @@ -123,10 +124,15 @@ impl<'d, T: Instance, I: TimerType> Timer<'d, T, I> { /// Create a `Timer` without an interrupt, meaning `Cc::wait` won't work. /// /// This is used by the public constructors. - fn new_irqless(_timer: impl Peripheral

+ 'd) -> Self { + fn new_irqless(timer: impl Peripheral

+ 'd) -> Self { + into_ref!(timer); + let regs = T::regs(); - let mut this = Self { phantom: PhantomData }; + let mut this = Self { + _p: timer, + _i: PhantomData, + }; // Stop the timer before doing anything else, // 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> { } Cc { n, - phantom: PhantomData, + _p: self._p.reborrow(), + _i: PhantomData, } } } @@ -242,12 +249,13 @@ impl<'d, T: Instance, I: TimerType> Timer<'d, T, I> { /// /// The timer will fire the register's COMPARE event when its counter reaches the value stored in the register. /// When the register's CAPTURE task is triggered, the timer will store the current value of its counter in the register -pub struct Cc<'a, T: Instance, I: TimerType = NotAwaitable> { +pub struct Cc<'d, T: Instance, I: TimerType = NotAwaitable> { n: usize, - phantom: PhantomData<(&'a mut T, I)>, + _p: PeripheralRef<'d, T>, + _i: PhantomData, } -impl<'a, T: Instance> Cc<'a, T, Awaitable> { +impl<'d, T: Instance> Cc<'d, T, Awaitable> { /// Wait until the timer's counter reaches the value stored in this register. /// /// 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> { on_drop.defuse(); } } -impl<'a, T: Instance> Cc<'a, T, NotAwaitable> {} +impl<'d, T: Instance> Cc<'d, T, NotAwaitable> {} -impl<'a, T: Instance, I: TimerType> Cc<'a, T, I> { +impl<'d, T: Instance, I: TimerType> Cc<'d, T, I> { /// Get the current value stored in the register. pub fn read(&self) -> u32 { T::regs().cc[self.n].read().cc().bits() -- cgit