diff options
Diffstat (limited to 'embassy-stm32/src/rcc/mod.rs')
| -rw-r--r-- | embassy-stm32/src/rcc/mod.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index 1dd634cfe..2a9a1595a 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 | ||
| @@ -172,7 +173,7 @@ pub(crate) struct RccInfo { | |||
| 172 | /// E.g. if `StopMode::Stop1` is selected, the peripheral prevents the chip from entering Stop1 mode. | 173 | /// E.g. if `StopMode::Stop1` is selected, the peripheral prevents the chip from entering Stop1 mode. |
| 173 | #[cfg(feature = "low-power")] | 174 | #[cfg(feature = "low-power")] |
| 174 | #[allow(dead_code)] | 175 | #[allow(dead_code)] |
| 175 | #[derive(Debug, Clone, Copy, PartialEq, Default)] | 176 | #[derive(Debug, Clone, Copy, PartialEq, Default, defmt::Format)] |
| 176 | pub enum StopMode { | 177 | pub enum StopMode { |
| 177 | #[default] | 178 | #[default] |
| 178 | /// Peripheral prevents chip from entering Stop1 or executor will enter Stop1 | 179 | /// Peripheral prevents chip from entering Stop1 or executor will enter Stop1 |
| @@ -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 | } |
| @@ -490,6 +498,16 @@ pub fn enable_and_reset<T: RccPeripheral>() { | |||
| 490 | T::RCC_INFO.enable_and_reset(); | 498 | T::RCC_INFO.enable_and_reset(); |
| 491 | } | 499 | } |
| 492 | 500 | ||
| 501 | /// Enables and resets peripheral `T` without incrementing the stop refcount. | ||
| 502 | /// | ||
| 503 | /// # Safety | ||
| 504 | /// | ||
| 505 | /// Peripheral must not be in use. | ||
| 506 | // TODO: should this be `unsafe`? | ||
| 507 | pub fn enable_and_reset_without_stop<T: RccPeripheral>() { | ||
| 508 | T::RCC_INFO.enable_and_reset_without_stop(); | ||
| 509 | } | ||
| 510 | |||
| 493 | /// Disables peripheral `T`. | 511 | /// Disables peripheral `T`. |
| 494 | /// | 512 | /// |
| 495 | /// # Safety | 513 | /// # Safety |
