diff options
| author | xoviat <[email protected]> | 2025-12-06 16:57:18 -0600 |
|---|---|---|
| committer | xoviat <[email protected]> | 2025-12-06 16:57:18 -0600 |
| commit | 37c7757c57c5038c3ec76e1b0d78396e38ff8743 (patch) | |
| tree | 53b254020e84f0986eac559fe3a47e874331e66f /embassy-stm32 | |
| parent | 997ad131325a30f79ef5bf407200830ce488302e (diff) | |
low-power: rework stoppableperipheral traits
Diffstat (limited to 'embassy-stm32')
| -rw-r--r-- | embassy-stm32/src/dma/mod.rs | 40 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/mod.rs | 10 |
2 files changed, 27 insertions, 23 deletions
diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs index efb324fa6..90feab167 100644 --- a/embassy-stm32/src/dma/mod.rs +++ b/embassy-stm32/src/dma/mod.rs | |||
| @@ -25,7 +25,7 @@ pub(crate) use util::*; | |||
| 25 | pub(crate) mod ringbuffer; | 25 | pub(crate) mod ringbuffer; |
| 26 | pub mod word; | 26 | pub mod word; |
| 27 | 27 | ||
| 28 | use embassy_hal_internal::{Peri, PeripheralType, impl_peripheral}; | 28 | use embassy_hal_internal::{PeripheralType, impl_peripheral}; |
| 29 | 29 | ||
| 30 | use crate::interrupt; | 30 | use crate::interrupt; |
| 31 | use crate::rcc::StoppablePeripheral; | 31 | use crate::rcc::StoppablePeripheral; |
| @@ -47,18 +47,9 @@ pub type Request = u8; | |||
| 47 | #[cfg(not(any(dma_v2, bdma_v2, gpdma, dmamux)))] | 47 | #[cfg(not(any(dma_v2, bdma_v2, gpdma, dmamux)))] |
| 48 | pub type Request = (); | 48 | pub type Request = (); |
| 49 | 49 | ||
| 50 | impl<'a> StoppablePeripheral for Peri<'a, AnyChannel> { | 50 | pub(crate) trait SealedChannel: StoppablePeripheral { |
| 51 | #[cfg(feature = "low-power")] | ||
| 52 | fn stop_mode(&self) -> crate::rcc::StopMode { | ||
| 53 | self.stop_mode | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | pub(crate) trait SealedChannel { | ||
| 58 | #[cfg(not(stm32n6))] | 51 | #[cfg(not(stm32n6))] |
| 59 | fn id(&self) -> u8; | 52 | fn id(&self) -> u8; |
| 60 | #[cfg(feature = "low-power")] | ||
| 61 | fn stop_mode(&self) -> crate::rcc::StopMode; | ||
| 62 | } | 53 | } |
| 63 | 54 | ||
| 64 | #[cfg(not(stm32n6))] | 55 | #[cfg(not(stm32n6))] |
| @@ -74,16 +65,19 @@ pub trait Channel: SealedChannel + PeripheralType + Into<AnyChannel> + 'static { | |||
| 74 | #[cfg(not(stm32n6))] | 65 | #[cfg(not(stm32n6))] |
| 75 | macro_rules! dma_channel_impl { | 66 | macro_rules! dma_channel_impl { |
| 76 | ($channel_peri:ident, $index:expr, $stop_mode:ident) => { | 67 | ($channel_peri:ident, $index:expr, $stop_mode:ident) => { |
| 77 | impl crate::dma::SealedChannel for crate::peripherals::$channel_peri { | 68 | impl crate::rcc::StoppablePeripheral for crate::peripherals::$channel_peri { |
| 78 | fn id(&self) -> u8 { | ||
| 79 | $index | ||
| 80 | } | ||
| 81 | |||
| 82 | #[cfg(feature = "low-power")] | 69 | #[cfg(feature = "low-power")] |
| 83 | fn stop_mode(&self) -> crate::rcc::StopMode { | 70 | fn stop_mode(&self) -> crate::rcc::StopMode { |
| 84 | crate::rcc::StopMode::$stop_mode | 71 | crate::rcc::StopMode::$stop_mode |
| 85 | } | 72 | } |
| 86 | } | 73 | } |
| 74 | |||
| 75 | impl crate::dma::SealedChannel for crate::peripherals::$channel_peri { | ||
| 76 | fn id(&self) -> u8 { | ||
| 77 | $index | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 87 | impl crate::dma::ChannelInterrupt for crate::peripherals::$channel_peri { | 81 | impl crate::dma::ChannelInterrupt for crate::peripherals::$channel_peri { |
| 88 | unsafe fn on_irq() { | 82 | unsafe fn on_irq() { |
| 89 | crate::dma::AnyChannel { | 83 | crate::dma::AnyChannel { |
| @@ -102,7 +96,7 @@ macro_rules! dma_channel_impl { | |||
| 102 | Self { | 96 | Self { |
| 103 | id: crate::dma::SealedChannel::id(&val), | 97 | id: crate::dma::SealedChannel::id(&val), |
| 104 | #[cfg(feature = "low-power")] | 98 | #[cfg(feature = "low-power")] |
| 105 | stop_mode: crate::dma::SealedChannel::stop_mode(&val), | 99 | stop_mode: crate::rcc::StoppablePeripheral::stop_mode(&val), |
| 106 | } | 100 | } |
| 107 | } | 101 | } |
| 108 | } | 102 | } |
| @@ -123,16 +117,18 @@ impl AnyChannel { | |||
| 123 | } | 117 | } |
| 124 | } | 118 | } |
| 125 | 119 | ||
| 120 | impl StoppablePeripheral for AnyChannel { | ||
| 121 | #[cfg(feature = "low-power")] | ||
| 122 | fn stop_mode(&self) -> crate::rcc::StopMode { | ||
| 123 | self.stop_mode | ||
| 124 | } | ||
| 125 | } | ||
| 126 | |||
| 126 | impl SealedChannel for AnyChannel { | 127 | impl SealedChannel for AnyChannel { |
| 127 | #[cfg(not(stm32n6))] | 128 | #[cfg(not(stm32n6))] |
| 128 | fn id(&self) -> u8 { | 129 | fn id(&self) -> u8 { |
| 129 | self.id | 130 | self.id |
| 130 | } | 131 | } |
| 131 | |||
| 132 | #[cfg(feature = "low-power")] | ||
| 133 | fn stop_mode(&self) -> crate::rcc::StopMode { | ||
| 134 | self.stop_mode | ||
| 135 | } | ||
| 136 | } | 132 | } |
| 137 | impl Channel for AnyChannel {} | 133 | impl Channel for AnyChannel {} |
| 138 | 134 | ||
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index 5890e68f4..a33ec5d7d 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs | |||
| @@ -12,6 +12,7 @@ pub use bd::*; | |||
| 12 | #[cfg(any(mco, mco1, mco2))] | 12 | #[cfg(any(mco, mco1, mco2))] |
| 13 | mod mco; | 13 | mod mco; |
| 14 | use critical_section::CriticalSection; | 14 | use critical_section::CriticalSection; |
| 15 | use embassy_hal_internal::{Peri, PeripheralType}; | ||
| 15 | #[cfg(any(mco, mco1, mco2))] | 16 | #[cfg(any(mco, mco1, mco2))] |
| 16 | pub use mco::*; | 17 | pub use mco::*; |
| 17 | 18 | ||
| @@ -381,12 +382,19 @@ pub(crate) trait StoppablePeripheral { | |||
| 381 | } | 382 | } |
| 382 | 383 | ||
| 383 | #[cfg(feature = "low-power")] | 384 | #[cfg(feature = "low-power")] |
| 384 | impl<'a> StoppablePeripheral for StopMode { | 385 | impl StoppablePeripheral for StopMode { |
| 385 | fn stop_mode(&self) -> StopMode { | 386 | fn stop_mode(&self) -> StopMode { |
| 386 | *self | 387 | *self |
| 387 | } | 388 | } |
| 388 | } | 389 | } |
| 389 | 390 | ||
| 391 | impl<'a, T: StoppablePeripheral + PeripheralType> StoppablePeripheral for Peri<'a, T> { | ||
| 392 | #[cfg(feature = "low-power")] | ||
| 393 | fn stop_mode(&self) -> StopMode { | ||
| 394 | T::stop_mode(&self) | ||
| 395 | } | ||
| 396 | } | ||
| 397 | |||
| 390 | pub(crate) struct BusyPeripheral<T: StoppablePeripheral> { | 398 | pub(crate) struct BusyPeripheral<T: StoppablePeripheral> { |
| 391 | peripheral: T, | 399 | peripheral: T, |
| 392 | } | 400 | } |
