diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 3c97878f599..1436ca8623e 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Peripheral driver constructors don't take `InterruptHandler`s anymore. Use `set_interrupt_handler` to explicitly set the interrupt handler now. (#1819) - Use the peripheral ref pattern for `OneShotTimer` and `PeriodicTimer` (#1855) - +- DMA: don't require `Sealed` to implement `ReadBuffer` and `WriteBuffer` (#1921) - Allow DMA to/from psram for esp32s3 (#1827) - 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) diff --git a/esp-hal/src/dma/mod.rs b/esp-hal/src/dma/mod.rs index 535c3533589..c66f2551e2b 100644 --- a/esp-hal/src/dma/mod.rs +++ b/esp-hal/src/dma/mod.rs @@ -79,7 +79,13 @@ impl crate::private::Sealed for &[W] where W: Word {} impl crate::private::Sealed for &mut [W] where W: Word {} /// Trait for buffers that can be given to DMA for reading. -pub trait ReadBuffer: crate::private::Sealed { +/// +/// # Safety +/// +/// Once the `read_buffer` method has been called, it is unsafe to call any +/// `&mut self` methods on this object as long as the returned value is in use +/// (by DMA). +pub unsafe trait ReadBuffer { /// Provide a buffer usable for DMA reads. /// /// The return value is: @@ -94,7 +100,7 @@ pub trait ReadBuffer: crate::private::Sealed { unsafe fn read_buffer(&self) -> (*const u8, usize); } -impl ReadBuffer for [W; S] +unsafe impl ReadBuffer for [W; S] where W: Word, { @@ -103,7 +109,7 @@ where } } -impl ReadBuffer for &[W; S] +unsafe impl ReadBuffer for &[W; S] where W: Word, { @@ -112,7 +118,7 @@ where } } -impl ReadBuffer for &mut [W; S] +unsafe impl ReadBuffer for &mut [W; S] where W: Word, { @@ -121,7 +127,7 @@ where } } -impl ReadBuffer for &[W] +unsafe impl ReadBuffer for &[W] where W: Word, { @@ -130,7 +136,7 @@ where } } -impl ReadBuffer for &mut [W] +unsafe impl ReadBuffer for &mut [W] where W: Word, { @@ -140,7 +146,13 @@ where } /// Trait for buffers that can be given to DMA for writing. -pub trait WriteBuffer: crate::private::Sealed { +/// +/// # Safety +/// +/// Once the `write_buffer` method has been called, it is unsafe to call any +/// `&mut self` methods, except for `write_buffer`, on this object as long as +/// the returned value is in use (by DMA). +pub unsafe trait WriteBuffer { /// Provide a buffer usable for DMA writes. /// /// The return value is: @@ -156,7 +168,7 @@ pub trait WriteBuffer: crate::private::Sealed { unsafe fn write_buffer(&mut self) -> (*mut u8, usize); } -impl WriteBuffer for [W; S] +unsafe impl WriteBuffer for [W; S] where W: Word, { @@ -165,7 +177,7 @@ where } } -impl WriteBuffer for &mut [W; S] +unsafe impl WriteBuffer for &mut [W; S] where W: Word, { @@ -174,7 +186,7 @@ where } } -impl WriteBuffer for &mut [W] +unsafe impl WriteBuffer for &mut [W] where W: Word, {