diff --git a/embassy-rp/src/dma.rs b/embassy-rp/src/dma.rs index 531ed8020..cfaa6dd34 100644 --- a/embassy-rp/src/dma.rs +++ b/embassy-rp/src/dma.rs @@ -5,26 +5,45 @@ use core::task::{Context, Poll, Waker}; use embassy_hal_common::{impl_peripheral, into_ref, Peripheral, PeripheralRef}; use embassy_util::waitqueue::AtomicWaker; use futures::Future; +use pac::dma::vals::DataSize; use crate::pac::dma::vals; use crate::{pac, peripherals}; -pub fn copy<'a, C: Channel, W: Word>(ch: impl Peripheral
+ 'a, from: &[W], to: &mut [W]) -> Transfer<'a, C> { - assert!(from.len() == to.len()); +pub(crate) fn read<'a, C: Channel, W: Word>(ch: impl Peripheral
+ 'a, from: *const W, to: *mut [W]) -> Transfer<'a, C> { + let (ptr, len) = crate::dma::slice_ptr_parts_mut(to); + copy(ch, from as *const u32, ptr as *mut u32, len, W::size()) +} +pub(crate) fn write<'a, C: Channel, W: Word>( + ch: impl Peripheral
+ 'a, + from: *const [W], + to: *mut W, +) -> Transfer<'a, C> { + let (from_ptr, len) = crate::dma::slice_ptr_parts(from); + copy(ch, from_ptr as *const u32, to as *mut u32, len, W::size()) +} + +fn copy<'a, C: Channel>( + ch: impl Peripheral
+ 'a,
+ from: *const u32,
+ to: *mut u32,
+ len: usize,
+ data_size: DataSize,
+) -> Transfer<'a, C> {
into_ref!(ch);
unsafe {
let p = ch.regs();
- p.read_addr().write_value(from.as_ptr() as u32);
- p.write_addr().write_value(to.as_mut_ptr() as u32);
- p.trans_count().write_value(from.len() as u32);
+ p.read_addr().write_value(from as u32);
+ p.write_addr().write_value(to as u32);
+ p.trans_count().write_value(len as u32);
compiler_fence(Ordering::SeqCst);
p.ctrl_trig().write(|w| {
- w.set_data_size(W::size());
+ w.set_data_size(data_size);
w.set_incr_read(true);
w.set_incr_write(true);
w.set_chain_to(ch.number());
@@ -60,7 +79,7 @@ impl<'a, C: Channel> Drop for Transfer<'a, C> {
impl<'a, C: Channel> Unpin for Transfer<'a, C> {}
impl<'a, C: Channel> Future for Transfer<'a, C> {
type Output = ();
- fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll + sealed::Channel + Into