2021-06-02 16:34:37 +02:00
|
|
|
#![macro_use]
|
|
|
|
|
|
|
|
use crate::peripherals;
|
2021-05-27 09:50:11 +02:00
|
|
|
use crate::time::Hertz;
|
|
|
|
use core::mem::MaybeUninit;
|
|
|
|
|
|
|
|
/// Frozen clock frequencies
|
|
|
|
///
|
|
|
|
/// The existence of this value indicates that the clock configuration can no longer be changed
|
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
pub struct Clocks {
|
|
|
|
pub sys_clk: Hertz,
|
|
|
|
pub ahb_clk: Hertz,
|
|
|
|
pub apb1_clk: Hertz,
|
|
|
|
pub apb1_tim_clk: Hertz,
|
|
|
|
pub apb2_clk: Hertz,
|
|
|
|
pub apb2_tim_clk: Hertz,
|
|
|
|
pub apb1_pre: u8,
|
|
|
|
pub apb2_pre: u8,
|
|
|
|
}
|
|
|
|
|
|
|
|
static mut CLOCK_FREQS: MaybeUninit<Clocks> = MaybeUninit::uninit();
|
|
|
|
|
|
|
|
/// Sets the clock frequencies
|
|
|
|
///
|
|
|
|
/// Safety: Sets a mutable global.
|
|
|
|
pub unsafe fn set_freqs(freqs: Clocks) {
|
|
|
|
CLOCK_FREQS.as_mut_ptr().write(freqs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Safety: Reads a mutable global.
|
|
|
|
pub unsafe fn get_freqs() -> &'static Clocks {
|
|
|
|
&*CLOCK_FREQS.as_ptr()
|
|
|
|
}
|
|
|
|
|
2021-05-25 13:30:42 +02:00
|
|
|
cfg_if::cfg_if! {
|
2021-05-25 04:17:24 +02:00
|
|
|
if #[cfg(rcc_h7)] {
|
2021-05-25 13:30:42 +02:00
|
|
|
mod h7;
|
|
|
|
pub use h7::*;
|
2021-05-25 04:17:24 +02:00
|
|
|
} else if #[cfg(rcc_l0)] {
|
2021-05-25 13:30:42 +02:00
|
|
|
mod l0;
|
|
|
|
pub use l0::*;
|
|
|
|
} else {
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct Config {}
|
2021-05-26 21:46:57 +02:00
|
|
|
pub unsafe fn init(_config: Config) {
|
2021-05-25 17:09:01 +02:00
|
|
|
}
|
2021-05-25 13:30:42 +02:00
|
|
|
}
|
|
|
|
}
|
2021-06-02 16:34:37 +02:00
|
|
|
|
|
|
|
pub(crate) mod sealed {
|
|
|
|
pub trait RccPeripheral {
|
|
|
|
fn reset();
|
|
|
|
fn enable();
|
|
|
|
fn disable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait RccPeripheral: sealed::RccPeripheral + 'static {}
|
|
|
|
|
|
|
|
crate::pac::peripheral_rcc!(
|
|
|
|
($inst:ident, $enable:ident, $reset:ident, $perien:ident, $perirst:ident) => {
|
|
|
|
impl sealed::RccPeripheral for peripherals::$inst {
|
|
|
|
fn enable() {
|
|
|
|
unsafe {
|
|
|
|
crate::pac::RCC.$enable().modify(|w| w.$perien(true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn disable() {
|
|
|
|
unsafe {
|
|
|
|
crate::pac::RCC.$enable().modify(|w| w.$perien(false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn reset() {
|
|
|
|
unsafe {
|
|
|
|
crate::pac::RCC.$reset().modify(|w| w.$perirst(true));
|
|
|
|
crate::pac::RCC.$reset().modify(|w| w.$perirst(false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RccPeripheral for peripherals::$inst {}
|
|
|
|
};
|
|
|
|
);
|