Add Clock type per RCC family

This commit is contained in:
Ulf Lilleengen 2021-06-11 17:45:07 +02:00
parent 952f525af5
commit 2c63393c9e
2 changed files with 40 additions and 10 deletions

View File

@ -1,6 +1,6 @@
use crate::pac; use crate::pac;
use crate::peripherals::{self, CRS, RCC, SYSCFG}; use crate::peripherals::{self, CRS, RCC, SYSCFG};
use crate::rcc::{get_freqs, set_freqs, Clocks}; use crate::rcc::{get_freqs, set_freqs};
use crate::time::Hertz; use crate::time::Hertz;
use crate::time::U32Ext; use crate::time::U32Ext;
use core::marker::PhantomData; use core::marker::PhantomData;
@ -12,6 +12,14 @@ use pac::rcc::vals::{Hpre, Msirange, Plldiv, Pllmul, Pllsrc, Ppre, Sw};
/// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC, /// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC,
/// and with the addition of the init function to configure a system clock. /// and with the addition of the init function to configure a system clock.
#[derive(Clone, Copy)]
pub struct Clocks {
pub sys: Hertz,
pub ahb: Hertz,
pub apb1: Hertz,
pub apb2: Hertz,
}
/// System clock mux source /// System clock mux source
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub enum ClockSrc { pub enum ClockSrc {

View File

@ -1,20 +1,11 @@
#![macro_use] #![macro_use]
use crate::peripherals; use crate::peripherals;
use crate::time::Hertz;
use core::mem::MaybeUninit; use core::mem::MaybeUninit;
/// Frozen clock frequencies /// Frozen clock frequencies
/// ///
/// The existence of this value indicates that the clock configuration can no longer be changed /// The existence of this value indicates that the clock configuration can no longer be changed
#[derive(Clone, Copy)]
pub struct Clocks {
pub sys: Hertz,
pub ahb: Hertz,
pub apb1: Hertz,
pub apb2: Hertz,
}
static mut CLOCK_FREQS: MaybeUninit<Clocks> = MaybeUninit::uninit(); static mut CLOCK_FREQS: MaybeUninit<Clocks> = MaybeUninit::uninit();
/// Sets the clock frequencies /// Sets the clock frequencies
@ -36,6 +27,37 @@ cfg_if::cfg_if! {
} else if #[cfg(rcc_l0)] { } else if #[cfg(rcc_l0)] {
mod l0; mod l0;
pub use l0::*; pub use l0::*;
} else if #[cfg(rcc_l4)] {
// TODO: Implement
use crate::time::Hertz;
#[derive(Clone, Copy)]
pub struct Clocks {
pub apb1: Hertz,
pub apb2: Hertz,
pub ahb2: Hertz,
}
#[derive(Default)]
pub struct Config {}
pub unsafe fn init(_config: Config) {
}
} else if #[cfg(rcc_f4)] {
// TODO: Implement
use crate::time::Hertz;
#[derive(Clone, Copy)]
pub struct Clocks {
pub apb1: Hertz,
pub apb2: Hertz,
pub ahb2: Hertz,
}
#[derive(Default)]
pub struct Config {}
pub unsafe fn init(_config: Config) {
}
} else { } else {
#[derive(Default)] #[derive(Default)]
pub struct Config {} pub struct Config {}