diff --git a/embassy-rp/src/dma.rs b/embassy-rp/src/dma.rs index 526c8382..acf33822 100644 --- a/embassy-rp/src/dma.rs +++ b/embassy-rp/src/dma.rs @@ -40,14 +40,14 @@ pub(crate) unsafe fn init() { pub unsafe fn read<'a, C: Channel, W: Word>( ch: impl Peripheral

+ 'a, from: *const W, - to: *mut W, - len: usize, + to: *mut [W], dreq: u8, ) -> Transfer<'a, C> { + let (to_ptr, len) = crate::dma::slice_ptr_parts(to); copy_inner( ch, from as *const u32, - to as *mut u32, + to_ptr as *mut u32, len, W::size(), false, @@ -58,14 +58,14 @@ pub unsafe fn read<'a, C: Channel, W: Word>( pub unsafe fn write<'a, C: Channel, W: Word>( ch: impl Peripheral

+ 'a, - from: *const W, + from: *const [W], to: *mut W, - len: usize, dreq: u8, ) -> Transfer<'a, C> { + let (from_ptr, len) = crate::dma::slice_ptr_parts(from); copy_inner( ch, - from as *const u32, + from_ptr as *const u32, to as *mut u32, len, W::size(), diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs index c5d9647d..74f0b04d 100644 --- a/embassy-rp/src/spi.rs +++ b/embassy-rp/src/spi.rs @@ -325,7 +325,6 @@ impl<'d, T: Instance> Spi<'d, T, Async> { } pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> { - let (from_ptr, len) = crate::dma::slice_ptr_parts(buffer); let ch = self.tx_dma.as_mut().unwrap(); let transfer = unsafe { self.inner.regs().dmacr().modify(|reg| { @@ -333,20 +332,13 @@ impl<'d, T: Instance> Spi<'d, T, Async> { }); // If we don't assign future to a variable, the data register pointer // is held across an await and makes the future non-Send. - crate::dma::write( - ch, - from_ptr as *const u32, - self.inner.regs().dr().ptr() as *mut _, - len, - T::TX_DREQ, - ) + crate::dma::write(ch, buffer, self.inner.regs().dr().ptr() as *mut _, T::TX_DREQ) }; transfer.await; Ok(()) } pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { - let (to_ptr, len) = crate::dma::slice_ptr_parts_mut(buffer); let ch = self.rx_dma.as_mut().unwrap(); let transfer = unsafe { self.inner.regs().dmacr().modify(|reg| { @@ -354,13 +346,7 @@ impl<'d, T: Instance> Spi<'d, T, Async> { }); // If we don't assign future to a variable, the data register pointer // is held across an await and makes the future non-Send. - crate::dma::read( - ch, - self.inner.regs().dr().ptr() as *const _, - to_ptr as *mut u32, - len, - T::RX_DREQ, - ) + crate::dma::read(ch, self.inner.regs().dr().ptr() as *const _, buffer, T::RX_DREQ) }; transfer.await; Ok(()) @@ -375,8 +361,8 @@ impl<'d, T: Instance> Spi<'d, T, Async> { } async fn transfer_inner(&mut self, rx_ptr: *mut [u8], tx_ptr: *const [u8]) -> Result<(), Error> { - let (from_ptr, from_len) = crate::dma::slice_ptr_parts(tx_ptr); - let (to_ptr, to_len) = crate::dma::slice_ptr_parts_mut(rx_ptr); + let (_, from_len) = crate::dma::slice_ptr_parts(tx_ptr); + let (_, to_len) = crate::dma::slice_ptr_parts_mut(rx_ptr); assert_eq!(from_len, to_len); let tx_ch = self.tx_dma.as_mut().unwrap(); let tx_transfer = unsafe { @@ -385,13 +371,7 @@ impl<'d, T: Instance> Spi<'d, T, Async> { }); // If we don't assign future to a variable, the data register pointer // is held across an await and makes the future non-Send. - crate::dma::write( - tx_ch, - from_ptr as *const u32, - self.inner.regs().dr().ptr() as *mut _, - from_len, - T::TX_DREQ, - ) + crate::dma::write(tx_ch, tx_ptr, self.inner.regs().dr().ptr() as *mut _, T::TX_DREQ) }; let rx_ch = self.rx_dma.as_mut().unwrap(); let rx_transfer = unsafe { @@ -400,13 +380,7 @@ impl<'d, T: Instance> Spi<'d, T, Async> { }); // If we don't assign future to a variable, the data register pointer // is held across an await and makes the future non-Send. - crate::dma::read( - rx_ch, - self.inner.regs().dr().ptr() as *const _, - to_ptr as *mut u32, - to_len, - T::RX_DREQ, - ) + crate::dma::read(rx_ch, self.inner.regs().dr().ptr() as *const _, rx_ptr, T::RX_DREQ) }; join(tx_transfer, rx_transfer).await; Ok(()) diff --git a/embassy-rp/src/uart.rs b/embassy-rp/src/uart.rs index 87d5fbd4..987b716b 100644 --- a/embassy-rp/src/uart.rs +++ b/embassy-rp/src/uart.rs @@ -120,7 +120,6 @@ impl<'d, T: Instance, M: Mode> UartTx<'d, T, M> { impl<'d, T: Instance> UartTx<'d, T, Async> { pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> { - let (from_ptr, len) = crate::dma::slice_ptr_parts(buffer); let ch = self.tx_dma.as_mut().unwrap(); let transfer = unsafe { T::regs().uartdmacr().modify(|reg| { @@ -128,13 +127,7 @@ impl<'d, T: Instance> UartTx<'d, T, Async> { }); // If we don't assign future to a variable, the data register pointer // is held across an await and makes the future non-Send. - crate::dma::write( - ch, - from_ptr as *const u32, - T::regs().uartdr().ptr() as *mut _, - len, - T::TX_DREQ, - ) + crate::dma::write(ch, buffer, T::regs().uartdr().ptr() as *mut _, T::TX_DREQ) }; transfer.await; Ok(()) @@ -180,7 +173,6 @@ impl<'d, T: Instance, M: Mode> UartRx<'d, T, M> { impl<'d, T: Instance> UartRx<'d, T, Async> { pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { - let (to_ptr, len) = crate::dma::slice_ptr_parts_mut(buffer); let ch = self.rx_dma.as_mut().unwrap(); let transfer = unsafe { T::regs().uartdmacr().modify(|reg| { @@ -188,13 +180,7 @@ impl<'d, T: Instance> UartRx<'d, T, Async> { }); // If we don't assign future to a variable, the data register pointer // is held across an await and makes the future non-Send. - crate::dma::read( - ch, - T::regs().uartdr().ptr() as *const _, - to_ptr as *mut u32, - len, - T::RX_DREQ, - ) + crate::dma::read(ch, T::regs().uartdr().ptr() as *const _, buffer, T::RX_DREQ) }; transfer.await; Ok(())