diff options
| author | James Munns <[email protected]> | 2025-12-05 15:22:38 +0100 |
|---|---|---|
| committer | James Munns <[email protected]> | 2025-12-05 15:22:38 +0100 |
| commit | fa54dd5849a083b286b2a3f1928428c8704d3d70 (patch) | |
| tree | 56f6e4f4ad5233d357a7ef5fefb38083f32d0562 /embassy-mcxa/src/dma.rs | |
| parent | 1ce2083f9a0fcf1cfbb10de0fb3ed44b460a5cc7 (diff) | |
Create separate ring buffered RX receiver to encapsulate unsafe
Diffstat (limited to 'embassy-mcxa/src/dma.rs')
| -rw-r--r-- | embassy-mcxa/src/dma.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/embassy-mcxa/src/dma.rs b/embassy-mcxa/src/dma.rs index 7d1588516..d563c2e29 100644 --- a/embassy-mcxa/src/dma.rs +++ b/embassy-mcxa/src/dma.rs | |||
| @@ -2170,7 +2170,14 @@ impl<'a, W: Word> RingBuffer<'a, W> { | |||
| 2170 | /// Stop the DMA transfer and consume the ring buffer. | 2170 | /// Stop the DMA transfer and consume the ring buffer. |
| 2171 | /// | 2171 | /// |
| 2172 | /// Returns any remaining unread data count. | 2172 | /// Returns any remaining unread data count. |
| 2173 | pub fn stop(self) -> usize { | 2173 | pub fn stop(mut self) -> usize { |
| 2174 | let res = self.teardown(); | ||
| 2175 | drop(self); | ||
| 2176 | res | ||
| 2177 | } | ||
| 2178 | |||
| 2179 | /// Stop the DMA transfer. Intended to be called by `stop()` or `Drop`. | ||
| 2180 | fn teardown(&mut self) -> usize { | ||
| 2174 | let available = self.available(); | 2181 | let available = self.available(); |
| 2175 | 2182 | ||
| 2176 | // Disable the channel | 2183 | // Disable the channel |
| @@ -2187,6 +2194,12 @@ impl<'a, W: Word> RingBuffer<'a, W> { | |||
| 2187 | } | 2194 | } |
| 2188 | } | 2195 | } |
| 2189 | 2196 | ||
| 2197 | impl<'a, W: Word> Drop for RingBuffer<'a, W> { | ||
| 2198 | fn drop(&mut self) { | ||
| 2199 | self.teardown(); | ||
| 2200 | } | ||
| 2201 | } | ||
| 2202 | |||
| 2190 | impl<C: Channel> DmaChannel<C> { | 2203 | impl<C: Channel> DmaChannel<C> { |
| 2191 | /// Set up a circular DMA transfer for continuous peripheral-to-memory reception. | 2204 | /// Set up a circular DMA transfer for continuous peripheral-to-memory reception. |
| 2192 | /// | 2205 | /// |
