aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-rp/src/dma.rs12
-rw-r--r--embassy-rp/src/spi.rs38
-rw-r--r--embassy-rp/src/uart.rs18
3 files changed, 14 insertions, 54 deletions
diff --git a/embassy-rp/src/dma.rs b/embassy-rp/src/dma.rs
index 526c83822..acf338225 100644
--- a/embassy-rp/src/dma.rs
+++ b/embassy-rp/src/dma.rs
@@ -40,14 +40,14 @@ pub(crate) unsafe fn init() {
40pub unsafe fn read<'a, C: Channel, W: Word>( 40pub unsafe fn read<'a, C: Channel, W: Word>(
41 ch: impl Peripheral<P = C> + 'a, 41 ch: impl Peripheral<P = C> + 'a,
42 from: *const W, 42 from: *const W,
43 to: *mut W, 43 to: *mut [W],
44 len: usize,
45 dreq: u8, 44 dreq: u8,
46) -> Transfer<'a, C> { 45) -> Transfer<'a, C> {
46 let (to_ptr, len) = crate::dma::slice_ptr_parts(to);
47 copy_inner( 47 copy_inner(
48 ch, 48 ch,
49 from as *const u32, 49 from as *const u32,
50 to as *mut u32, 50 to_ptr as *mut u32,
51 len, 51 len,
52 W::size(), 52 W::size(),
53 false, 53 false,
@@ -58,14 +58,14 @@ pub unsafe fn read<'a, C: Channel, W: Word>(
58 58
59pub unsafe fn write<'a, C: Channel, W: Word>( 59pub unsafe fn write<'a, C: Channel, W: Word>(
60 ch: impl Peripheral<P = C> + 'a, 60 ch: impl Peripheral<P = C> + 'a,
61 from: *const W, 61 from: *const [W],
62 to: *mut W, 62 to: *mut W,
63 len: usize,
64 dreq: u8, 63 dreq: u8,
65) -> Transfer<'a, C> { 64) -> Transfer<'a, C> {
65 let (from_ptr, len) = crate::dma::slice_ptr_parts(from);
66 copy_inner( 66 copy_inner(
67 ch, 67 ch,
68 from as *const u32, 68 from_ptr as *const u32,
69 to as *mut u32, 69 to as *mut u32,
70 len, 70 len,
71 W::size(), 71 W::size(),
diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs
index c5d9647db..74f0b04de 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> {
325 } 325 }
326 326
327 pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> { 327 pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> {
328 let (from_ptr, len) = crate::dma::slice_ptr_parts(buffer);
329 let ch = self.tx_dma.as_mut().unwrap(); 328 let ch = self.tx_dma.as_mut().unwrap();
330 let transfer = unsafe { 329 let transfer = unsafe {
331 self.inner.regs().dmacr().modify(|reg| { 330 self.inner.regs().dmacr().modify(|reg| {
@@ -333,20 +332,13 @@ impl<'d, T: Instance> Spi<'d, T, Async> {
333 }); 332 });
334 // If we don't assign future to a variable, the data register pointer 333 // If we don't assign future to a variable, the data register pointer
335 // is held across an await and makes the future non-Send. 334 // is held across an await and makes the future non-Send.
336 crate::dma::write( 335 crate::dma::write(ch, buffer, self.inner.regs().dr().ptr() as *mut _, T::TX_DREQ)
337 ch,
338 from_ptr as *const u32,
339 self.inner.regs().dr().ptr() as *mut _,
340 len,
341 T::TX_DREQ,
342 )
343 }; 336 };
344 transfer.await; 337 transfer.await;
345 Ok(()) 338 Ok(())
346 } 339 }
347 340
348 pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { 341 pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> {
349 let (to_ptr, len) = crate::dma::slice_ptr_parts_mut(buffer);
350 let ch = self.rx_dma.as_mut().unwrap(); 342 let ch = self.rx_dma.as_mut().unwrap();
351 let transfer = unsafe { 343 let transfer = unsafe {
352 self.inner.regs().dmacr().modify(|reg| { 344 self.inner.regs().dmacr().modify(|reg| {
@@ -354,13 +346,7 @@ impl<'d, T: Instance> Spi<'d, T, Async> {
354 }); 346 });
355 // If we don't assign future to a variable, the data register pointer 347 // If we don't assign future to a variable, the data register pointer
356 // is held across an await and makes the future non-Send. 348 // is held across an await and makes the future non-Send.
357 crate::dma::read( 349 crate::dma::read(ch, self.inner.regs().dr().ptr() as *const _, buffer, T::RX_DREQ)
358 ch,
359 self.inner.regs().dr().ptr() as *const _,
360 to_ptr as *mut u32,
361 len,
362 T::RX_DREQ,
363 )
364 }; 350 };
365 transfer.await; 351 transfer.await;
366 Ok(()) 352 Ok(())
@@ -375,8 +361,8 @@ impl<'d, T: Instance> Spi<'d, T, Async> {
375 } 361 }
376 362
377 async fn transfer_inner(&mut self, rx_ptr: *mut [u8], tx_ptr: *const [u8]) -> Result<(), Error> { 363 async fn transfer_inner(&mut self, rx_ptr: *mut [u8], tx_ptr: *const [u8]) -> Result<(), Error> {
378 let (from_ptr, from_len) = crate::dma::slice_ptr_parts(tx_ptr); 364 let (_, from_len) = crate::dma::slice_ptr_parts(tx_ptr);
379 let (to_ptr, to_len) = crate::dma::slice_ptr_parts_mut(rx_ptr); 365 let (_, to_len) = crate::dma::slice_ptr_parts_mut(rx_ptr);
380 assert_eq!(from_len, to_len); 366 assert_eq!(from_len, to_len);
381 let tx_ch = self.tx_dma.as_mut().unwrap(); 367 let tx_ch = self.tx_dma.as_mut().unwrap();
382 let tx_transfer = unsafe { 368 let tx_transfer = unsafe {
@@ -385,13 +371,7 @@ impl<'d, T: Instance> Spi<'d, T, Async> {
385 }); 371 });
386 // If we don't assign future to a variable, the data register pointer 372 // If we don't assign future to a variable, the data register pointer
387 // is held across an await and makes the future non-Send. 373 // is held across an await and makes the future non-Send.
388 crate::dma::write( 374 crate::dma::write(tx_ch, tx_ptr, self.inner.regs().dr().ptr() as *mut _, T::TX_DREQ)
389 tx_ch,
390 from_ptr as *const u32,
391 self.inner.regs().dr().ptr() as *mut _,
392 from_len,
393 T::TX_DREQ,
394 )
395 }; 375 };
396 let rx_ch = self.rx_dma.as_mut().unwrap(); 376 let rx_ch = self.rx_dma.as_mut().unwrap();
397 let rx_transfer = unsafe { 377 let rx_transfer = unsafe {
@@ -400,13 +380,7 @@ impl<'d, T: Instance> Spi<'d, T, Async> {
400 }); 380 });
401 // If we don't assign future to a variable, the data register pointer 381 // If we don't assign future to a variable, the data register pointer
402 // is held across an await and makes the future non-Send. 382 // is held across an await and makes the future non-Send.
403 crate::dma::read( 383 crate::dma::read(rx_ch, self.inner.regs().dr().ptr() as *const _, rx_ptr, T::RX_DREQ)
404 rx_ch,
405 self.inner.regs().dr().ptr() as *const _,
406 to_ptr as *mut u32,
407 to_len,
408 T::RX_DREQ,
409 )
410 }; 384 };
411 join(tx_transfer, rx_transfer).await; 385 join(tx_transfer, rx_transfer).await;
412 Ok(()) 386 Ok(())
diff --git a/embassy-rp/src/uart.rs b/embassy-rp/src/uart.rs
index 87d5fbd46..987b716b4 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> {
120 120
121impl<'d, T: Instance> UartTx<'d, T, Async> { 121impl<'d, T: Instance> UartTx<'d, T, Async> {
122 pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> { 122 pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> {
123 let (from_ptr, len) = crate::dma::slice_ptr_parts(buffer);
124 let ch = self.tx_dma.as_mut().unwrap(); 123 let ch = self.tx_dma.as_mut().unwrap();
125 let transfer = unsafe { 124 let transfer = unsafe {
126 T::regs().uartdmacr().modify(|reg| { 125 T::regs().uartdmacr().modify(|reg| {
@@ -128,13 +127,7 @@ impl<'d, T: Instance> UartTx<'d, T, Async> {
128 }); 127 });
129 // If we don't assign future to a variable, the data register pointer 128 // If we don't assign future to a variable, the data register pointer
130 // is held across an await and makes the future non-Send. 129 // is held across an await and makes the future non-Send.
131 crate::dma::write( 130 crate::dma::write(ch, buffer, T::regs().uartdr().ptr() as *mut _, T::TX_DREQ)
132 ch,
133 from_ptr as *const u32,
134 T::regs().uartdr().ptr() as *mut _,
135 len,
136 T::TX_DREQ,
137 )
138 }; 131 };
139 transfer.await; 132 transfer.await;
140 Ok(()) 133 Ok(())
@@ -180,7 +173,6 @@ impl<'d, T: Instance, M: Mode> UartRx<'d, T, M> {
180 173
181impl<'d, T: Instance> UartRx<'d, T, Async> { 174impl<'d, T: Instance> UartRx<'d, T, Async> {
182 pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { 175 pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> {
183 let (to_ptr, len) = crate::dma::slice_ptr_parts_mut(buffer);
184 let ch = self.rx_dma.as_mut().unwrap(); 176 let ch = self.rx_dma.as_mut().unwrap();
185 let transfer = unsafe { 177 let transfer = unsafe {
186 T::regs().uartdmacr().modify(|reg| { 178 T::regs().uartdmacr().modify(|reg| {
@@ -188,13 +180,7 @@ impl<'d, T: Instance> UartRx<'d, T, Async> {
188 }); 180 });
189 // If we don't assign future to a variable, the data register pointer 181 // If we don't assign future to a variable, the data register pointer
190 // is held across an await and makes the future non-Send. 182 // is held across an await and makes the future non-Send.
191 crate::dma::read( 183 crate::dma::read(ch, T::regs().uartdr().ptr() as *const _, buffer, T::RX_DREQ)
192 ch,
193 T::regs().uartdr().ptr() as *const _,
194 to_ptr as *mut u32,
195 len,
196 T::RX_DREQ,
197 )
198 }; 184 };
199 transfer.await; 185 transfer.await;
200 Ok(()) 186 Ok(())