diff options
| author | f_punk <[email protected]> | 2021-09-02 12:02:31 +0200 |
|---|---|---|
| committer | f_punk <[email protected]> | 2021-09-02 12:02:31 +0200 |
| commit | 34c66fa78d700fa5ca324dd043dc0861694ea693 (patch) | |
| tree | 44deb75285cbc264f02aef88a2809e33660b6ee0 /embassy-nrf/src/timer.rs | |
| parent | 1cef7134d42e581c86102df733f1420d86b20861 (diff) | |
removed type aliases
NotAwaitable as default generic param
added awaitable_timer example
Diffstat (limited to 'embassy-nrf/src/timer.rs')
| -rw-r--r-- | embassy-nrf/src/timer.rs | 19 |
1 files changed, 9 insertions, 10 deletions
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 {} | |||
| 97 | impl TimerType for Awaitable {} | 97 | impl TimerType for Awaitable {} |
| 98 | impl TimerType for NotAwaitable {} | 98 | impl TimerType for NotAwaitable {} |
| 99 | 99 | ||
| 100 | pub type AwaitableTimer<'d, T> = Timer<'d, T, Awaitable>; | 100 | pub struct Timer<'d, T: Instance, I: TimerType = NotAwaitable> { |
| 101 | pub type NotAwaitableTimer<'d, T> = Timer<'d, T, NotAwaitable>; | ||
| 102 | |||
| 103 | pub struct Timer<'d, T: Instance, I: TimerType> { | ||
| 104 | phantom: PhantomData<(&'d mut T, I)>, | 101 | phantom: PhantomData<(&'d mut T, I)>, |
| 105 | } | 102 | } |
| 106 | 103 | ||
| 107 | impl<'d, T: Instance> Timer<'d, T, Awaitable> { | 104 | impl<'d, T: Instance> Timer<'d, T, Awaitable> { |
| 108 | pub fn new( | 105 | pub fn new_awaitable( |
| 109 | timer: impl Unborrow<Target = T> + 'd, | 106 | timer: impl Unborrow<Target = T> + 'd, |
| 110 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 107 | irq: impl Unborrow<Target = T::Interrupt> + 'd, |
| 111 | ) -> Self { | 108 | ) -> Self { |
| @@ -119,6 +116,10 @@ impl<'d, T: Instance> Timer<'d, T, Awaitable> { | |||
| 119 | } | 116 | } |
| 120 | } | 117 | } |
| 121 | impl<'d, T: Instance> Timer<'d, T, NotAwaitable> { | 118 | impl<'d, T: Instance> Timer<'d, T, NotAwaitable> { |
| 119 | /// Create a `Timer` without an interrupt, meaning `Cc::wait` won't work. | ||
| 120 | /// | ||
| 121 | /// This can be useful for triggering tasks via PPI | ||
| 122 | /// `Uarte` uses this internally. | ||
| 122 | pub fn new(timer: impl Unborrow<Target = T> + 'd) -> Self { | 123 | pub fn new(timer: impl Unborrow<Target = T> + 'd) -> Self { |
| 123 | Self::new_irqless(timer) | 124 | Self::new_irqless(timer) |
| 124 | } | 125 | } |
| @@ -127,7 +128,7 @@ impl<'d, T: Instance> Timer<'d, T, NotAwaitable> { | |||
| 127 | impl<'d, T: Instance, I: TimerType> Timer<'d, T, I> { | 128 | impl<'d, T: Instance, I: TimerType> Timer<'d, T, I> { |
| 128 | /// Create a `Timer` without an interrupt, meaning `Cc::wait` won't work. | 129 | /// Create a `Timer` without an interrupt, meaning `Cc::wait` won't work. |
| 129 | /// | 130 | /// |
| 130 | /// This is used by `Uarte` internally. | 131 | /// This is used by the public constructors. |
| 131 | fn new_irqless(_timer: impl Unborrow<Target = T> + 'd) -> Self { | 132 | fn new_irqless(_timer: impl Unborrow<Target = T> + 'd) -> Self { |
| 132 | let regs = T::regs(); | 133 | let regs = T::regs(); |
| 133 | 134 | ||
| @@ -242,7 +243,6 @@ impl<'d, T: Instance, I: TimerType> Timer<'d, T, I> { | |||
| 242 | Cc { | 243 | Cc { |
| 243 | n, | 244 | n, |
| 244 | phantom: PhantomData, | 245 | phantom: PhantomData, |
| 245 | phantom2: PhantomData, | ||
| 246 | } | 246 | } |
| 247 | } | 247 | } |
| 248 | } | 248 | } |
| @@ -254,10 +254,9 @@ impl<'d, T: Instance, I: TimerType> Timer<'d, T, I> { | |||
| 254 | /// | 254 | /// |
| 255 | /// The timer will fire the register's COMPARE event when its counter reaches the value stored in the register. | 255 | /// The timer will fire the register's COMPARE event when its counter reaches the value stored in the register. |
| 256 | /// When the register's CAPTURE task is triggered, the timer will store the current value of its counter in the register | 256 | /// When the register's CAPTURE task is triggered, the timer will store the current value of its counter in the register |
| 257 | pub struct Cc<'a, T: Instance, I: TimerType> { | 257 | pub struct Cc<'a, T: Instance, I: TimerType = NotAwaitable> { |
| 258 | n: usize, | 258 | n: usize, |
| 259 | phantom: PhantomData<&'a mut T>, | 259 | phantom: PhantomData<(&'a mut T, I)>, |
| 260 | phantom2: PhantomData<I>, | ||
| 261 | } | 260 | } |
| 262 | 261 | ||
| 263 | impl<'a, T: Instance> Cc<'a, T, Awaitable> { | 262 | impl<'a, T: Instance> Cc<'a, T, Awaitable> { |
