Use builder

This commit is contained in:
Ulf Lilleengen 2021-05-27 10:01:40 +02:00
parent a41a812345
commit 3669eba561
2 changed files with 3 additions and 45 deletions

View File

@ -46,8 +46,9 @@ pub struct Config {
} }
impl Config { impl Config {
pub fn new(rcc: rcc::Config) -> Self { pub fn rcc(mut self, rcc: rcc::Config) -> Self {
Self { rcc } self.rcc = rcc;
self
} }
} }

View File

@ -224,49 +224,6 @@ impl Config {
self.apb2_pre = pre; self.apb2_pre = pre;
self self
} }
#[inline]
pub fn hsi16() -> Config {
Config {
mux: ClockSrc::HSI16,
ahb_pre: AHBPrescaler::NotDivided,
apb1_pre: APBPrescaler::NotDivided,
apb2_pre: APBPrescaler::NotDivided,
}
}
#[inline]
pub fn msi(range: MSIRange) -> Config {
Config {
mux: ClockSrc::MSI(range),
ahb_pre: AHBPrescaler::NotDivided,
apb1_pre: APBPrescaler::NotDivided,
apb2_pre: APBPrescaler::NotDivided,
}
}
#[inline]
pub fn pll(pll_src: PLLSource, pll_mul: PLLMul, pll_div: PLLDiv) -> Config {
Config {
mux: ClockSrc::PLL(pll_src, pll_mul, pll_div),
ahb_pre: AHBPrescaler::NotDivided,
apb1_pre: APBPrescaler::NotDivided,
apb2_pre: APBPrescaler::NotDivided,
}
}
#[inline]
pub fn hse<T>(freq: T) -> Config
where
T: Into<Hertz>,
{
Config {
mux: ClockSrc::HSE(freq.into()),
ahb_pre: AHBPrescaler::NotDivided,
apb1_pre: APBPrescaler::NotDivided,
apb2_pre: APBPrescaler::NotDivided,
}
}
} }
/// RCC peripheral /// RCC peripheral