From 34c66fa78d700fa5ca324dd043dc0861694ea693 Mon Sep 17 00:00:00 2001 From: f_punk Date: Thu, 2 Sep 2021 12:02:31 +0200 Subject: removed type aliases NotAwaitable as default generic param added awaitable_timer example --- embassy-nrf/src/timer.rs | 19 +++++++++---------- 1 file changed, 9 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 14a2f7b35..638fd8229 100644 --- a/embassy-nrf/src/timer.rs +++ b/embassy-nrf/src/timer.rs @@ -97,15 +97,12 @@ impl sealed::TimerType for NotAwaitable {} impl TimerType for Awaitable {} impl TimerType for NotAwaitable {} -pub type AwaitableTimer<'d, T> = Timer<'d, T, Awaitable>; -pub type NotAwaitableTimer<'d, T> = Timer<'d, T, NotAwaitable>; - -pub struct Timer<'d, T: Instance, I: TimerType> { +pub struct Timer<'d, T: Instance, I: TimerType = NotAwaitable> { phantom: PhantomData<(&'d mut T, I)>, } impl<'d, T: Instance> Timer<'d, T, Awaitable> { - pub fn new( + pub fn new_awaitable( timer: impl Unborrow + 'd, irq: impl Unborrow + 'd, ) -> Self { @@ -119,6 +116,10 @@ impl<'d, T: Instance> Timer<'d, T, Awaitable> { } } impl<'d, T: Instance> Timer<'d, T, NotAwaitable> { + /// Create a `Timer` without an interrupt, meaning `Cc::wait` won't work. + /// + /// This can be useful for triggering tasks via PPI + /// `Uarte` uses this internally. pub fn new(timer: impl Unborrow + 'd) -> Self { Self::new_irqless(timer) } @@ -127,7 +128,7 @@ impl<'d, T: Instance> Timer<'d, T, NotAwaitable> { 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 `Uarte` internally. + /// This is used by the public constructors. fn new_irqless(_timer: impl Unborrow + 'd) -> Self { let regs = T::regs(); @@ -242,7 +243,6 @@ impl<'d, T: Instance, I: TimerType> Timer<'d, T, I> { Cc { n, phantom: PhantomData, - phantom2: PhantomData, } } } @@ -254,10 +254,9 @@ 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> { +pub struct Cc<'a, T: Instance, I: TimerType = NotAwaitable> { n: usize, - phantom: PhantomData<&'a mut T>, - phantom2: PhantomData, + phantom: PhantomData<(&'a mut T, I)>, } impl<'a, T: Instance> Cc<'a, T, Awaitable> { -- cgit