diff options
| author | Mathias <[email protected]> | 2022-08-18 20:30:50 +0200 |
|---|---|---|
| committer | Mathias <[email protected]> | 2022-08-18 20:30:50 +0200 |
| commit | 55a63a5417ccfd2ca2792215920de14519a3d27b (patch) | |
| tree | 5fb7b7b971969ce32d2e841a1af4ffb8cbbeeb3b | |
| parent | 3bbfc11f45149c5624e2ff6370f8e71b956402af (diff) | |
Attempt to implement future for DMA transfer
| -rw-r--r-- | embassy-rp/src/dma.rs | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/embassy-rp/src/dma.rs b/embassy-rp/src/dma.rs index bf15e1f4e..ec09a7699 100644 --- a/embassy-rp/src/dma.rs +++ b/embassy-rp/src/dma.rs | |||
| @@ -1,8 +1,9 @@ | |||
| 1 | use core::pin::Pin; | 1 | use core::pin::Pin; |
| 2 | use core::sync::atomic::{compiler_fence, Ordering}; | 2 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 3 | use core::task::{Context, Poll}; | 3 | use core::task::{Context, Poll, Waker}; |
| 4 | 4 | ||
| 5 | use embassy_hal_common::{impl_peripheral, into_ref, Peripheral, PeripheralRef}; | 5 | use embassy_hal_common::{impl_peripheral, into_ref, Peripheral, PeripheralRef}; |
| 6 | use embassy_util::waitqueue::AtomicWaker; | ||
| 6 | use futures::Future; | 7 | use futures::Future; |
| 7 | 8 | ||
| 8 | use crate::pac::dma::vals; | 9 | use crate::pac::dma::vals; |
| @@ -60,15 +61,41 @@ impl<'a, C: Channel> Unpin for Transfer<'a, C> {} | |||
| 60 | impl<'a, C: Channel> Future for Transfer<'a, C> { | 61 | impl<'a, C: Channel> Future for Transfer<'a, C> { |
| 61 | type Output = (); | 62 | type Output = (); |
| 62 | fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | 63 | fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { |
| 63 | // self.channel.set_waker(cx.waker()); | 64 | self.channel.set_waker(cx.waker()); |
| 64 | // if self.channel.is_running() { | 65 | |
| 65 | // Poll::Pending | 66 | if self.channel.is_running() { |
| 66 | // } else { | 67 | Poll::Pending |
| 67 | Poll::Ready(()) | 68 | } else { |
| 68 | // } | 69 | Poll::Ready(()) |
| 70 | } | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | struct ChannelState { | ||
| 75 | waker: AtomicWaker, | ||
| 76 | } | ||
| 77 | |||
| 78 | impl ChannelState { | ||
| 79 | const fn new() -> Self { | ||
| 80 | Self { | ||
| 81 | waker: AtomicWaker::new(), | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | struct State { | ||
| 87 | channels: [ChannelState; 12], | ||
| 88 | } | ||
| 89 | |||
| 90 | impl State { | ||
| 91 | const fn new() -> Self { | ||
| 92 | const CH: ChannelState = ChannelState::new(); | ||
| 93 | Self { channels: [CH; 12] } | ||
| 69 | } | 94 | } |
| 70 | } | 95 | } |
| 71 | 96 | ||
| 97 | static STATE: State = State::new(); | ||
| 98 | |||
| 72 | pub struct NoDma; | 99 | pub struct NoDma; |
| 73 | 100 | ||
| 74 | impl_peripheral!(NoDma); | 101 | impl_peripheral!(NoDma); |
| @@ -86,6 +113,14 @@ pub trait Channel: Peripheral<P = Self> + sealed::Channel + Into<AnyChannel> + S | |||
| 86 | pac::DMA.ch(self.number() as _) | 113 | pac::DMA.ch(self.number() as _) |
| 87 | } | 114 | } |
| 88 | 115 | ||
| 116 | fn is_running(&self) -> bool { | ||
| 117 | self.regs().ctrl_trig().read().en() | ||
| 118 | } | ||
| 119 | |||
| 120 | fn set_waker(&self, waker: &Waker) { | ||
| 121 | STATE.channels[self.number() as usize].waker.register(waker); | ||
| 122 | } | ||
| 123 | |||
| 89 | fn degrade(self) -> AnyChannel { | 124 | fn degrade(self) -> AnyChannel { |
| 90 | AnyChannel { number: self.number() } | 125 | AnyChannel { number: self.number() } |
| 91 | } | 126 | } |
