diff options
| author | xoviat <[email protected]> | 2025-11-25 16:53:26 -0600 |
|---|---|---|
| committer | xoviat <[email protected]> | 2025-11-25 16:53:26 -0600 |
| commit | 0847f4ca4657ea2174fc160f96a69f4c916d146e (patch) | |
| tree | c0d2a2bed6c9a5b2007fe9f312fb5d1de5eab2de /embassy-stm32/src/dma/mod.rs | |
| parent | 5298671b0c132f58f3f76273bcd35656dc6e6d3d (diff) | |
stm32: extract busychannel into common api
Diffstat (limited to 'embassy-stm32/src/dma/mod.rs')
| -rw-r--r-- | embassy-stm32/src/dma/mod.rs | 50 |
1 files changed, 9 insertions, 41 deletions
diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs index 4becc2d87..efb324fa6 100644 --- a/embassy-stm32/src/dma/mod.rs +++ b/embassy-stm32/src/dma/mod.rs | |||
| @@ -3,14 +3,12 @@ | |||
| 3 | 3 | ||
| 4 | #[cfg(any(bdma, dma))] | 4 | #[cfg(any(bdma, dma))] |
| 5 | mod dma_bdma; | 5 | mod dma_bdma; |
| 6 | use core::ops; | ||
| 7 | 6 | ||
| 8 | #[cfg(any(bdma, dma))] | 7 | #[cfg(any(bdma, dma))] |
| 9 | pub use dma_bdma::*; | 8 | pub use dma_bdma::*; |
| 10 | 9 | ||
| 11 | #[cfg(gpdma)] | 10 | #[cfg(gpdma)] |
| 12 | pub(crate) mod gpdma; | 11 | pub(crate) mod gpdma; |
| 13 | use embassy_hal_internal::Peri; | ||
| 14 | #[cfg(gpdma)] | 12 | #[cfg(gpdma)] |
| 15 | pub use gpdma::ringbuffered::*; | 13 | pub use gpdma::ringbuffered::*; |
| 16 | #[cfg(gpdma)] | 14 | #[cfg(gpdma)] |
| @@ -27,9 +25,10 @@ pub(crate) use util::*; | |||
| 27 | pub(crate) mod ringbuffer; | 25 | pub(crate) mod ringbuffer; |
| 28 | pub mod word; | 26 | pub mod word; |
| 29 | 27 | ||
| 30 | use embassy_hal_internal::{PeripheralType, impl_peripheral}; | 28 | use embassy_hal_internal::{Peri, PeripheralType, impl_peripheral}; |
| 31 | 29 | ||
| 32 | use crate::interrupt; | 30 | use crate::interrupt; |
| 31 | use crate::rcc::StoppablePeripheral; | ||
| 33 | 32 | ||
| 34 | /// The direction of a DMA transfer. | 33 | /// The direction of a DMA transfer. |
| 35 | #[derive(Debug, Copy, Clone, PartialEq, Eq)] | 34 | #[derive(Debug, Copy, Clone, PartialEq, Eq)] |
| @@ -48,6 +47,13 @@ pub type Request = u8; | |||
| 48 | #[cfg(not(any(dma_v2, bdma_v2, gpdma, dmamux)))] | 47 | #[cfg(not(any(dma_v2, bdma_v2, gpdma, dmamux)))] |
| 49 | pub type Request = (); | 48 | pub type Request = (); |
| 50 | 49 | ||
| 50 | impl<'a> StoppablePeripheral for Peri<'a, AnyChannel> { | ||
| 51 | #[cfg(feature = "low-power")] | ||
| 52 | fn stop_mode(&self) -> crate::rcc::StopMode { | ||
| 53 | self.stop_mode | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 51 | pub(crate) trait SealedChannel { | 57 | pub(crate) trait SealedChannel { |
| 52 | #[cfg(not(stm32n6))] | 58 | #[cfg(not(stm32n6))] |
| 53 | fn id(&self) -> u8; | 59 | fn id(&self) -> u8; |
| @@ -103,44 +109,6 @@ macro_rules! dma_channel_impl { | |||
| 103 | }; | 109 | }; |
| 104 | } | 110 | } |
| 105 | 111 | ||
| 106 | pub(crate) struct BusyChannel<'a> { | ||
| 107 | channel: Peri<'a, AnyChannel>, | ||
| 108 | } | ||
| 109 | |||
| 110 | impl<'a> BusyChannel<'a> { | ||
| 111 | pub fn new(channel: Peri<'a, AnyChannel>) -> Self { | ||
| 112 | #[cfg(feature = "low-power")] | ||
| 113 | critical_section::with(|cs| { | ||
| 114 | crate::rcc::increment_stop_refcount(cs, channel.stop_mode); | ||
| 115 | }); | ||
| 116 | |||
| 117 | Self { channel } | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | impl<'a> Drop for BusyChannel<'a> { | ||
| 122 | fn drop(&mut self) { | ||
| 123 | #[cfg(feature = "low-power")] | ||
| 124 | critical_section::with(|cs| { | ||
| 125 | crate::rcc::decrement_stop_refcount(cs, self.stop_mode); | ||
| 126 | }); | ||
| 127 | } | ||
| 128 | } | ||
| 129 | |||
| 130 | impl<'a> ops::Deref for BusyChannel<'a> { | ||
| 131 | type Target = Peri<'a, AnyChannel>; | ||
| 132 | |||
| 133 | fn deref(&self) -> &Self::Target { | ||
| 134 | &self.channel | ||
| 135 | } | ||
| 136 | } | ||
| 137 | |||
| 138 | impl<'a> ops::DerefMut for BusyChannel<'a> { | ||
| 139 | fn deref_mut(&mut self) -> &mut Self::Target { | ||
| 140 | &mut self.channel | ||
| 141 | } | ||
| 142 | } | ||
| 143 | |||
| 144 | /// Type-erased DMA channel. | 112 | /// Type-erased DMA channel. |
| 145 | pub struct AnyChannel { | 113 | pub struct AnyChannel { |
| 146 | pub(crate) id: u8, | 114 | pub(crate) id: u8, |
