diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 33dcbeb59..0514cd5f4 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Introduce traits for the DMA buffer objects (#1976) +- Introduce traits for the DMA buffer objects (#1976, #2213) - Implement `embedded-hal` output pin traits for `NoPin` (#2019, #2133) - Added `esp_hal::init` to simplify HAL initialisation (#1970, #1999) - Added GpioPin::degrade to create ErasePins easily. Same for AnyPin by accident. (#2075) diff --git a/esp-hal/src/dma/mod.rs b/esp-hal/src/dma/mod.rs index 264615e74..bc84d401c 100644 --- a/esp-hal/src/dma/mod.rs +++ b/esp-hal/src/dma/mod.rs @@ -1962,7 +1962,12 @@ pub struct Preparation { /// [DmaTxBuffer] is a DMA descriptor + memory combo that can be used for /// transmitting data from a DMA channel to a peripheral's FIFO. -pub trait DmaTxBuffer { +/// +/// # Safety +/// +/// The implementing type must keep all its descriptors and the buffers they +/// point to valid while the buffer is being transferred. +pub unsafe trait DmaTxBuffer { /// Prepares the buffer for an imminent transfer and returns /// information required to use this buffer. /// @@ -1983,7 +1988,12 @@ pub trait DmaTxBuffer { /// Note: Implementations of this trait may only support having a single EOF bit /// which resides in the last descriptor. There will be a separate trait in /// future to support multiple EOFs. -pub trait DmaRxBuffer { +/// +/// # Safety +/// +/// The implementing type must keep all its descriptors and the buffers they +/// point to valid while the buffer is being transferred. +pub unsafe trait DmaRxBuffer { /// Prepares the buffer for an imminent transfer and returns /// information required to use this buffer. /// @@ -2224,7 +2234,7 @@ impl DmaTxBuf { } } -impl DmaTxBuffer for DmaTxBuf { +unsafe impl DmaTxBuffer for DmaTxBuf { fn prepare(&mut self) -> Preparation { for desc in self.descriptors.iter_mut() { // Give ownership to the DMA @@ -2463,7 +2473,7 @@ impl DmaRxBuf { } } -impl DmaRxBuffer for DmaRxBuf { +unsafe impl DmaRxBuffer for DmaRxBuf { fn prepare(&mut self) -> Preparation { for desc in self.descriptors.iter_mut() { // Give ownership to the DMA @@ -2664,7 +2674,7 @@ impl DmaRxTxBuf { } } -impl DmaTxBuffer for DmaRxTxBuf { +unsafe impl DmaTxBuffer for DmaRxTxBuf { fn prepare(&mut self) -> Preparation { for desc in self.tx_descriptors.iter_mut() { // Give ownership to the DMA @@ -2686,7 +2696,7 @@ impl DmaTxBuffer for DmaRxTxBuf { } } -impl DmaRxBuffer for DmaRxTxBuf { +unsafe impl DmaRxBuffer for DmaRxTxBuf { fn prepare(&mut self) -> Preparation { for desc in self.rx_descriptors.iter_mut() { // Give ownership to the DMA