From 37c7757c57c5038c3ec76e1b0d78396e38ff8743 Mon Sep 17 00:00:00 2001 From: xoviat Date: Sat, 6 Dec 2025 16:57:18 -0600 Subject: low-power: rework stoppableperipheral traits --- embassy-stm32/src/dma/mod.rs | 40 ++++++++++++++++++---------------------- 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::*; pub(crate) mod ringbuffer; pub mod word; -use embassy_hal_internal::{Peri, PeripheralType, impl_peripheral}; +use embassy_hal_internal::{PeripheralType, impl_peripheral}; use crate::interrupt; use crate::rcc::StoppablePeripheral; @@ -47,18 +47,9 @@ pub type Request = u8; #[cfg(not(any(dma_v2, bdma_v2, gpdma, dmamux)))] pub type Request = (); -impl<'a> StoppablePeripheral for Peri<'a, AnyChannel> { - #[cfg(feature = "low-power")] - fn stop_mode(&self) -> crate::rcc::StopMode { - self.stop_mode - } -} - -pub(crate) trait SealedChannel { +pub(crate) trait SealedChannel: StoppablePeripheral { #[cfg(not(stm32n6))] fn id(&self) -> u8; - #[cfg(feature = "low-power")] - fn stop_mode(&self) -> crate::rcc::StopMode; } #[cfg(not(stm32n6))] @@ -74,16 +65,19 @@ pub trait Channel: SealedChannel + PeripheralType + Into + 'static { #[cfg(not(stm32n6))] macro_rules! dma_channel_impl { ($channel_peri:ident, $index:expr, $stop_mode:ident) => { - impl crate::dma::SealedChannel for crate::peripherals::$channel_peri { - fn id(&self) -> u8 { - $index - } - + impl crate::rcc::StoppablePeripheral for crate::peripherals::$channel_peri { #[cfg(feature = "low-power")] fn stop_mode(&self) -> crate::rcc::StopMode { crate::rcc::StopMode::$stop_mode } } + + impl crate::dma::SealedChannel for crate::peripherals::$channel_peri { + fn id(&self) -> u8 { + $index + } + } + impl crate::dma::ChannelInterrupt for crate::peripherals::$channel_peri { unsafe fn on_irq() { crate::dma::AnyChannel { @@ -102,7 +96,7 @@ macro_rules! dma_channel_impl { Self { id: crate::dma::SealedChannel::id(&val), #[cfg(feature = "low-power")] - stop_mode: crate::dma::SealedChannel::stop_mode(&val), + stop_mode: crate::rcc::StoppablePeripheral::stop_mode(&val), } } } @@ -123,16 +117,18 @@ impl AnyChannel { } } +impl StoppablePeripheral for AnyChannel { + #[cfg(feature = "low-power")] + fn stop_mode(&self) -> crate::rcc::StopMode { + self.stop_mode + } +} + impl SealedChannel for AnyChannel { #[cfg(not(stm32n6))] fn id(&self) -> u8 { self.id } - - #[cfg(feature = "low-power")] - fn stop_mode(&self) -> crate::rcc::StopMode { - self.stop_mode - } } impl Channel for AnyChannel {} 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::*; #[cfg(any(mco, mco1, mco2))] mod mco; use critical_section::CriticalSection; +use embassy_hal_internal::{Peri, PeripheralType}; #[cfg(any(mco, mco1, mco2))] pub use mco::*; @@ -381,12 +382,19 @@ pub(crate) trait StoppablePeripheral { } #[cfg(feature = "low-power")] -impl<'a> StoppablePeripheral for StopMode { +impl StoppablePeripheral for StopMode { fn stop_mode(&self) -> StopMode { *self } } +impl<'a, T: StoppablePeripheral + PeripheralType> StoppablePeripheral for Peri<'a, T> { + #[cfg(feature = "low-power")] + fn stop_mode(&self) -> StopMode { + T::stop_mode(&self) + } +} + pub(crate) struct BusyPeripheral { peripheral: T, } -- cgit