aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/rcc/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-stm32/src/rcc/mod.rs')
-rw-r--r--embassy-stm32/src/rcc/mod.rs22
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))]
13mod mco; 13mod mco;
14use critical_section::CriticalSection; 14use critical_section::CriticalSection;
15use embassy_hal_internal::{Peri, PeripheralType};
15#[cfg(any(mco, mco1, mco2))] 16#[cfg(any(mco, mco1, mco2))]
16pub use mco::*; 17pub 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)]
176pub enum StopMode { 177pub 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")]
384impl<'a> StoppablePeripheral for StopMode { 385impl 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
391impl<'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
390pub(crate) struct BusyPeripheral<T: StoppablePeripheral> { 398pub(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`?
507pub 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