Skip to content

Commit 3f0f994

Browse files
committed
join Rcc::freeze and freeze_raw
1 parent b5aa244 commit 3f0f994

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1515
Add `RInto` trait and `Rmp` peripheral wrapper, add `remap` for peripherals. [#514] [#520]
1616
Remove `RemapStruct`s. [#462] [#506] [#509]
1717
- Use independent `Spi` and `SpiSlave` structures instead of `OP` generic [#462]
18-
- Include `Clocks` in `Rcc`. Take `&mut Rcc/RCC` where possible [#498] [#536]
18+
- Include `Clocks` in `Rcc`. Take `&mut Rcc/RCC` where possible, `freeze` takes `Config` or `RawConfig` [#498] [#536]
1919
- Update to `stm32f1` v0.16.0 [#503] [#534]
2020
- `Spi` now takes `Option<PIN>` for `SCK`, `MISO`, `MOSI` [#514],
2121
add `SPIx::NoSck`, etc. [#537]

examples/adc_temperature.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn main() -> ! {
2424

2525
/*
2626
// Alternative configuration using dividers and multipliers directly
27-
let rcc = p.RCC.freeze_raw(
27+
let rcc = p.RCC.freeze(
2828
rcc::RawConfig {
2929
hse: Some(8_000_000),
3030
pllmul: Some(7),

src/rcc.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ pub trait RccExt {
2222
fn constrain(self) -> Rcc;
2323

2424
/// Constrains the `RCC` peripheral and apply clock configuration
25-
fn freeze(self, rcc_cfg: Config, acr: &mut ACR) -> Rcc;
26-
27-
/// Constrains the `RCC` peripheral and apply clock configuration
28-
fn freeze_raw(self, rcc_cfg: RawConfig, acr: &mut ACR) -> Rcc;
25+
fn freeze(self, rcc_cfg: impl Into<RawConfig>, acr: &mut ACR) -> Rcc;
2926
}
3027

3128
impl RccExt for RCC {
@@ -36,13 +33,9 @@ impl RccExt for RCC {
3633
}
3734
}
3835

39-
fn freeze(self, rcc_cfg: Config, acr: &mut ACR) -> Rcc {
36+
fn freeze(self, rcc_cfg: impl Into<RawConfig>, acr: &mut ACR) -> Rcc {
4037
self.constrain().freeze(rcc_cfg, acr)
4138
}
42-
43-
fn freeze_raw(self, rcc_cfg: RawConfig, acr: &mut ACR) -> Rcc {
44-
self.constrain().freeze_raw(rcc_cfg, acr)
45-
}
4639
}
4740

4841
/// Constrained RCC peripheral
@@ -214,13 +207,8 @@ impl Rcc {
214207
/// let clocks = rcc.cfgr.freeze(&mut flash.acr);
215208
/// ```
216209
#[inline(always)]
217-
pub fn freeze(self, config: Config, acr: &mut ACR) -> Self {
218-
let cfg = RawConfig::from_cfgr(config);
219-
self.freeze_raw(cfg, acr)
220-
}
221-
222-
#[inline(always)]
223-
pub fn freeze_raw(self, cfg: RawConfig, acr: &mut ACR) -> Self {
210+
pub fn freeze(self, cfg: impl Into<RawConfig>, acr: &mut ACR) -> Self {
211+
let cfg = cfg.into();
224212
let clocks = cfg.get_clocks();
225213
// adjust flash wait states
226214
#[cfg(any(feature = "stm32f103", feature = "connectivity"))]
@@ -631,6 +619,13 @@ pub type UsbPre = rcc::cfgr::USBPRE;
631619
pub type UsbPre = rcc::cfgr::OTGFSPRE;
632620
pub type AdcPre = rcc::cfgr::ADCPRE;
633621

622+
impl From<Config> for RawConfig {
623+
#[inline(always)]
624+
fn from(cfgr: Config) -> Self {
625+
Self::from_cfgr(cfgr)
626+
}
627+
}
628+
634629
impl RawConfig {
635630
pub const fn from_cfgr(cfgr: Config) -> Self {
636631
let hse = cfgr.hse;

0 commit comments

Comments
 (0)