diff --git a/CHANGELOG.md b/CHANGELOG.md index f7287f32..e9310c36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Allow `Serial` reconfiguration by references to the `Tx` and `Rx` parts. - Allow `Serial` release after splitting. - `Spi::is_busy()` +- Allow to stop an incomplete DMA transfer. ## [v0.9.0] - 2022-03-02 diff --git a/src/dma.rs b/src/dma.rs index b94ad9d3..3910d492 100644 --- a/src/dma.rs +++ b/src/dma.rs @@ -302,9 +302,16 @@ macro_rules! dma { !self.payload.channel.in_progress() } - pub fn wait(mut self) -> (BUFFER, RxDma) { + /// Waits for the transfer to complete, + /// then stops it and returns the underlying buffer and RxDma. + pub fn wait(self) -> (BUFFER, RxDma) { while !self.is_done() {} + self.stop() + } + + /// Stops the transfer and returns the underlying buffer and RxDma. + pub fn stop(mut self) -> (BUFFER, RxDma) { atomic::compiler_fence(Ordering::Acquire); self.payload.stop(); @@ -340,9 +347,16 @@ macro_rules! dma { !self.payload.channel.in_progress() } - pub fn wait(mut self) -> (BUFFER, TxDma) { + /// Waits for the transfer to complete, + /// then stops it and returns the underlying buffer and TxDma. + pub fn wait(self) -> (BUFFER, TxDma) { while !self.is_done() {} + self.stop() + } + + /// Stops the transfer and returns the underlying buffer and TxDma. + pub fn stop(mut self) -> (BUFFER, TxDma) { atomic::compiler_fence(Ordering::Acquire); self.payload.stop(); @@ -378,9 +392,16 @@ macro_rules! dma { !self.payload.rxchannel.in_progress() } - pub fn wait(mut self) -> (BUFFER, RxTxDma) { + /// Waits for the transfer to complete, + /// then stops it and returns the underlying buffer and RxTxDma. + pub fn wait(self) -> (BUFFER, RxTxDma) { while !self.is_done() {} + self.stop() + } + + /// Stops the transfer and returns the underlying buffer and RxTxDma. + pub fn stop(mut self) -> (BUFFER, RxTxDma) { atomic::compiler_fence(Ordering::Acquire); self.payload.stop();