From 5f0dc148edceb874135703ddc9017371db5f3f48 Mon Sep 17 00:00:00 2001 From: liebman Date: Mon, 26 Aug 2024 06:10:56 -0700 Subject: [PATCH] parl_io: use ReadBuffer/WriteBuffer for async DMA (#1996) * parl_io: use ReadBuffer/WriteBuffer for async DMA * CHANGELOG --- esp-hal/CHANGELOG.md | 1 + esp-hal/src/parl_io.rs | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 61c074ebf64..319fdca4011 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - DMA buffers now don't require a static lifetime. Make sure to never `mem::forget` an in-progress DMA transfer (consider using `#[deny(clippy::mem_forget)]`) (#1837) - SHA driver now use specific structs for the hashing algorithm instead of a parameter. (#1908) - Remove `fn free(self)` in HMAC which goes against esp-hal API guidelines (#1972) +- PARL_IO use ReadBuffer and WriteBuffer for Async DMA (#1996) ### Fixed diff --git a/esp-hal/src/parl_io.rs b/esp-hal/src/parl_io.rs index 72cfdd3ddc8..2d99381066a 100644 --- a/esp-hal/src/parl_io.rs +++ b/esp-hal/src/parl_io.rs @@ -1669,7 +1669,7 @@ pub mod asynch { use super::{private::Instance, Error, ParlIoRx, ParlIoTx, MAX_DMA_SIZE}; use crate::{ - dma::{asynch::DmaRxFuture, DmaChannel, ParlIoPeripheral}, + dma::{asynch::DmaRxFuture, DmaChannel, ParlIoPeripheral, ReadBuffer, WriteBuffer}, peripherals::Interrupt, }; @@ -1731,8 +1731,11 @@ pub mod asynch { /// Perform a DMA write. /// /// The maximum amount of data to be sent is 32736 bytes. - pub async fn write_dma_async(&mut self, words: &mut [u8]) -> Result<(), Error> { - let (ptr, len) = (words.as_ptr(), words.len()); + pub async fn write_dma_async<'t, TXBUF>(&mut self, words: &'t TXBUF) -> Result<(), Error> + where + TXBUF: ReadBuffer, + { + let (ptr, len) = unsafe { words.read_buffer() }; if len > MAX_DMA_SIZE { return Err(Error::MaxDmaTransferSizeExceeded); @@ -1754,8 +1757,14 @@ pub mod asynch { /// Perform a DMA write. /// /// The maximum amount of data to be sent is 32736 bytes. - pub async fn read_dma_async(&mut self, words: &mut [u8]) -> Result<(), Error> { - let (ptr, len) = (words.as_mut_ptr(), words.len()); + pub async fn read_dma_async<'t, RXBUF>( + &'t mut self, + words: &'t mut RXBUF, + ) -> Result<(), Error> + where + RXBUF: WriteBuffer, + { + let (ptr, len) = unsafe { words.write_buffer() }; if !Instance::is_suc_eof_generated_externally() && len > MAX_DMA_SIZE { return Err(Error::MaxDmaTransferSizeExceeded);