diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-03-26 16:01:37 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2025-03-27 15:18:06 +0100 |
| commit | d41eeeae79388f219bf6a84e2f7bde9f6b532516 (patch) | |
| tree | 678b6fc732216e529dc38e6f65b72a309917ac32 /embassy-rp/src/dma.rs | |
| parent | 9edf5b7f049f95742b60b041e4443967d8a6b708 (diff) | |
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'embassy-rp/src/dma.rs')
| -rw-r--r-- | embassy-rp/src/dma.rs | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/embassy-rp/src/dma.rs b/embassy-rp/src/dma.rs index 2edcfdf5b..d31d1e159 100644 --- a/embassy-rp/src/dma.rs +++ b/embassy-rp/src/dma.rs | |||
| @@ -4,7 +4,7 @@ use core::pin::Pin; | |||
| 4 | use core::sync::atomic::{compiler_fence, Ordering}; | 4 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 5 | use core::task::{Context, Poll}; | 5 | use core::task::{Context, Poll}; |
| 6 | 6 | ||
| 7 | use embassy_hal_internal::{impl_peripheral, into_ref, Peripheral, PeripheralRef}; | 7 | use embassy_hal_internal::{impl_peripheral, Peri, PeripheralType}; |
| 8 | use embassy_sync::waitqueue::AtomicWaker; | 8 | use embassy_sync::waitqueue::AtomicWaker; |
| 9 | use pac::dma::vals::DataSize; | 9 | use pac::dma::vals::DataSize; |
| 10 | 10 | ||
| @@ -42,7 +42,7 @@ pub(crate) unsafe fn init() { | |||
| 42 | /// | 42 | /// |
| 43 | /// SAFETY: Slice must point to a valid location reachable by DMA. | 43 | /// SAFETY: Slice must point to a valid location reachable by DMA. |
| 44 | pub unsafe fn read<'a, C: Channel, W: Word>( | 44 | pub unsafe fn read<'a, C: Channel, W: Word>( |
| 45 | ch: impl Peripheral<P = C> + 'a, | 45 | ch: Peri<'a, C>, |
| 46 | from: *const W, | 46 | from: *const W, |
| 47 | to: *mut [W], | 47 | to: *mut [W], |
| 48 | dreq: vals::TreqSel, | 48 | dreq: vals::TreqSel, |
| @@ -63,7 +63,7 @@ pub unsafe fn read<'a, C: Channel, W: Word>( | |||
| 63 | /// | 63 | /// |
| 64 | /// SAFETY: Slice must point to a valid location reachable by DMA. | 64 | /// SAFETY: Slice must point to a valid location reachable by DMA. |
| 65 | pub unsafe fn write<'a, C: Channel, W: Word>( | 65 | pub unsafe fn write<'a, C: Channel, W: Word>( |
| 66 | ch: impl Peripheral<P = C> + 'a, | 66 | ch: Peri<'a, C>, |
| 67 | from: *const [W], | 67 | from: *const [W], |
| 68 | to: *mut W, | 68 | to: *mut W, |
| 69 | dreq: vals::TreqSel, | 69 | dreq: vals::TreqSel, |
| @@ -87,7 +87,7 @@ static mut DUMMY: u32 = 0; | |||
| 87 | /// | 87 | /// |
| 88 | /// SAFETY: Slice must point to a valid location reachable by DMA. | 88 | /// SAFETY: Slice must point to a valid location reachable by DMA. |
| 89 | pub unsafe fn write_repeated<'a, C: Channel, W: Word>( | 89 | pub unsafe fn write_repeated<'a, C: Channel, W: Word>( |
| 90 | ch: impl Peripheral<P = C> + 'a, | 90 | ch: Peri<'a, C>, |
| 91 | to: *mut W, | 91 | to: *mut W, |
| 92 | len: usize, | 92 | len: usize, |
| 93 | dreq: vals::TreqSel, | 93 | dreq: vals::TreqSel, |
| @@ -107,11 +107,7 @@ pub unsafe fn write_repeated<'a, C: Channel, W: Word>( | |||
| 107 | /// DMA copy between slices. | 107 | /// DMA copy between slices. |
| 108 | /// | 108 | /// |
| 109 | /// SAFETY: Slices must point to locations reachable by DMA. | 109 | /// SAFETY: Slices must point to locations reachable by DMA. |
| 110 | pub unsafe fn copy<'a, C: Channel, W: Word>( | 110 | pub unsafe fn copy<'a, C: Channel, W: Word>(ch: Peri<'a, C>, from: &[W], to: &mut [W]) -> Transfer<'a, C> { |
| 111 | ch: impl Peripheral<P = C> + 'a, | ||
| 112 | from: &[W], | ||
| 113 | to: &mut [W], | ||
| 114 | ) -> Transfer<'a, C> { | ||
| 115 | let from_len = from.len(); | 111 | let from_len = from.len(); |
| 116 | let to_len = to.len(); | 112 | let to_len = to.len(); |
| 117 | assert_eq!(from_len, to_len); | 113 | assert_eq!(from_len, to_len); |
| @@ -128,7 +124,7 @@ pub unsafe fn copy<'a, C: Channel, W: Word>( | |||
| 128 | } | 124 | } |
| 129 | 125 | ||
| 130 | fn copy_inner<'a, C: Channel>( | 126 | fn copy_inner<'a, C: Channel>( |
| 131 | ch: impl Peripheral<P = C> + 'a, | 127 | ch: Peri<'a, C>, |
| 132 | from: *const u32, | 128 | from: *const u32, |
| 133 | to: *mut u32, | 129 | to: *mut u32, |
| 134 | len: usize, | 130 | len: usize, |
| @@ -137,8 +133,6 @@ fn copy_inner<'a, C: Channel>( | |||
| 137 | incr_write: bool, | 133 | incr_write: bool, |
| 138 | dreq: vals::TreqSel, | 134 | dreq: vals::TreqSel, |
| 139 | ) -> Transfer<'a, C> { | 135 | ) -> Transfer<'a, C> { |
| 140 | into_ref!(ch); | ||
| 141 | |||
| 142 | let p = ch.regs(); | 136 | let p = ch.regs(); |
| 143 | 137 | ||
| 144 | p.read_addr().write_value(from as u32); | 138 | p.read_addr().write_value(from as u32); |
| @@ -171,13 +165,11 @@ fn copy_inner<'a, C: Channel>( | |||
| 171 | /// DMA transfer driver. | 165 | /// DMA transfer driver. |
| 172 | #[must_use = "futures do nothing unless you `.await` or poll them"] | 166 | #[must_use = "futures do nothing unless you `.await` or poll them"] |
| 173 | pub struct Transfer<'a, C: Channel> { | 167 | pub struct Transfer<'a, C: Channel> { |
| 174 | channel: PeripheralRef<'a, C>, | 168 | channel: Peri<'a, C>, |
| 175 | } | 169 | } |
| 176 | 170 | ||
| 177 | impl<'a, C: Channel> Transfer<'a, C> { | 171 | impl<'a, C: Channel> Transfer<'a, C> { |
| 178 | pub(crate) fn new(channel: impl Peripheral<P = C> + 'a) -> Self { | 172 | pub(crate) fn new(channel: Peri<'a, C>) -> Self { |
| 179 | into_ref!(channel); | ||
| 180 | |||
| 181 | Self { channel } | 173 | Self { channel } |
| 182 | } | 174 | } |
| 183 | } | 175 | } |
| @@ -219,7 +211,7 @@ trait SealedWord {} | |||
| 219 | 211 | ||
| 220 | /// DMA channel interface. | 212 | /// DMA channel interface. |
| 221 | #[allow(private_bounds)] | 213 | #[allow(private_bounds)] |
| 222 | pub trait Channel: Peripheral<P = Self> + SealedChannel + Into<AnyChannel> + Sized + 'static { | 214 | pub trait Channel: PeripheralType + SealedChannel + Into<AnyChannel> + Sized + 'static { |
| 223 | /// Channel number. | 215 | /// Channel number. |
| 224 | fn number(&self) -> u8; | 216 | fn number(&self) -> u8; |
| 225 | 217 | ||
| @@ -227,11 +219,6 @@ pub trait Channel: Peripheral<P = Self> + SealedChannel + Into<AnyChannel> + Siz | |||
| 227 | fn regs(&self) -> pac::dma::Channel { | 219 | fn regs(&self) -> pac::dma::Channel { |
| 228 | pac::DMA.ch(self.number() as _) | 220 | pac::DMA.ch(self.number() as _) |
| 229 | } | 221 | } |
| 230 | |||
| 231 | /// Convert into type-erased [AnyChannel]. | ||
| 232 | fn degrade(self) -> AnyChannel { | ||
| 233 | AnyChannel { number: self.number() } | ||
| 234 | } | ||
| 235 | } | 222 | } |
| 236 | 223 | ||
| 237 | /// DMA word. | 224 | /// DMA word. |
| @@ -287,7 +274,7 @@ macro_rules! channel { | |||
| 287 | 274 | ||
| 288 | impl From<peripherals::$name> for crate::dma::AnyChannel { | 275 | impl From<peripherals::$name> for crate::dma::AnyChannel { |
| 289 | fn from(val: peripherals::$name) -> Self { | 276 | fn from(val: peripherals::$name) -> Self { |
| 290 | crate::dma::Channel::degrade(val) | 277 | Self { number: val.number() } |
| 291 | } | 278 | } |
| 292 | } | 279 | } |
| 293 | }; | 280 | }; |
