diff --git a/CHANGELOG.md b/CHANGELOG.md index c63bf3b0..399b2eb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). Add `RInto` trait and `Rmp` peripheral wrapper, add `remap` for peripherals. [#514] [#520] Remove `RemapStruct`s. [#462] [#506] [#509] - Use independent `Spi` and `SpiSlave` structures instead of `OP` generic [#462] -- Include `Clocks` in `Rcc`. Take `&mut Rcc/RCC` where possible [#498] [#536] +- Include `Clocks` in `Rcc`. Take `&mut Rcc/RCC` where possible, `freeze` takes `Config` or `RawConfig` [#498] [#536] - Update to `stm32f1` v0.16.0 [#503] [#534] - `Spi` now takes `Option` for `SCK`, `MISO`, `MOSI` [#514], add `SPIx::NoSck`, etc. [#537] diff --git a/examples/adc_temperature.rs b/examples/adc_temperature.rs index 7465e409..2bdc28df 100644 --- a/examples/adc_temperature.rs +++ b/examples/adc_temperature.rs @@ -24,7 +24,7 @@ fn main() -> ! { /* // Alternative configuration using dividers and multipliers directly - let rcc = p.RCC.freeze_raw( + let rcc = p.RCC.freeze( rcc::RawConfig { hse: Some(8_000_000), pllmul: Some(7), diff --git a/src/rcc.rs b/src/rcc.rs index 32ebc691..0e3c3b09 100644 --- a/src/rcc.rs +++ b/src/rcc.rs @@ -22,10 +22,7 @@ pub trait RccExt { fn constrain(self) -> Rcc; /// Constrains the `RCC` peripheral and apply clock configuration - fn freeze(self, rcc_cfg: Config, acr: &mut ACR) -> Rcc; - - /// Constrains the `RCC` peripheral and apply clock configuration - fn freeze_raw(self, rcc_cfg: RawConfig, acr: &mut ACR) -> Rcc; + fn freeze(self, rcc_cfg: impl Into, acr: &mut ACR) -> Rcc; } impl RccExt for RCC { @@ -36,13 +33,9 @@ impl RccExt for RCC { } } - fn freeze(self, rcc_cfg: Config, acr: &mut ACR) -> Rcc { + fn freeze(self, rcc_cfg: impl Into, acr: &mut ACR) -> Rcc { self.constrain().freeze(rcc_cfg, acr) } - - fn freeze_raw(self, rcc_cfg: RawConfig, acr: &mut ACR) -> Rcc { - self.constrain().freeze_raw(rcc_cfg, acr) - } } /// Constrained RCC peripheral @@ -214,13 +207,8 @@ impl Rcc { /// let clocks = rcc.cfgr.freeze(&mut flash.acr); /// ``` #[inline(always)] - pub fn freeze(self, config: Config, acr: &mut ACR) -> Self { - let cfg = RawConfig::from_cfgr(config); - self.freeze_raw(cfg, acr) - } - - #[inline(always)] - pub fn freeze_raw(self, cfg: RawConfig, acr: &mut ACR) -> Self { + pub fn freeze(self, cfg: impl Into, acr: &mut ACR) -> Self { + let cfg = cfg.into(); let clocks = cfg.get_clocks(); // adjust flash wait states #[cfg(any(feature = "stm32f103", feature = "connectivity"))] @@ -631,6 +619,13 @@ pub type UsbPre = rcc::cfgr::USBPRE; pub type UsbPre = rcc::cfgr::OTGFSPRE; pub type AdcPre = rcc::cfgr::ADCPRE; +impl From for RawConfig { + #[inline(always)] + fn from(cfgr: Config) -> Self { + Self::from_cfgr(cfgr) + } +} + impl RawConfig { pub const fn from_cfgr(cfgr: Config) -> Self { let hse = cfgr.hse;