Skip to content

Commit 2b401a5

Browse files
committed
rcc: Add core clocks definitions
1 parent 2b4cad8 commit 2b401a5

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

src/rcc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
mod core_clocks;
12
mod reset_reason;

src/rcc/core_clocks.rs

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
//! Structure to represent frozen core clock frequencies
2+
3+
use crate::time::Hertz;
4+
5+
/// Frozen core clock frequencies
6+
///
7+
/// The existence of this value indicates that the core clock
8+
/// configuration can no longer be changed
9+
#[derive(Clone, Copy)]
10+
pub struct CoreClocks {
11+
pub(super) hclk: Hertz,
12+
pub(super) pclk1: Hertz,
13+
pub(super) pclk2: Hertz,
14+
pub(super) pclk3: Hertz,
15+
pub(super) ppre1: u8,
16+
pub(super) ppre2: u8,
17+
pub(super) ppre3: u8,
18+
pub(super) csi_ck: Option<Hertz>,
19+
pub(super) hsi_ck: Option<Hertz>,
20+
pub(super) hsi48_ck: Option<Hertz>,
21+
pub(super) lsi_ck: Option<Hertz>,
22+
pub(super) per_ck: Option<Hertz>,
23+
pub(super) hse_ck: Option<Hertz>,
24+
pub(super) lse_ck: Option<Hertz>,
25+
pub(super) audio_ck: Option<Hertz>,
26+
pub(super) mco1_ck: Option<Hertz>,
27+
pub(super) mco2_ck: Option<Hertz>,
28+
pub(super) pll1_p_ck: Option<Hertz>,
29+
pub(super) pll1_q_ck: Option<Hertz>,
30+
pub(super) pll1_r_ck: Option<Hertz>,
31+
pub(super) pll2_p_ck: Option<Hertz>,
32+
pub(super) pll2_q_ck: Option<Hertz>,
33+
pub(super) pll2_r_ck: Option<Hertz>,
34+
pub(super) timx_ker_ck: Hertz,
35+
pub(super) timy_ker_ck: Hertz,
36+
pub(super) sys_ck: Hertz,
37+
}
38+
39+
/// Getters for pclk and ppre
40+
macro_rules! pclk_ppre_getter {
41+
($(($pclk:ident, $ppre:ident),)+) => {
42+
$(
43+
/// Returns the frequency of the APBn
44+
pub fn $pclk(&self) -> Hertz {
45+
self.$pclk
46+
}
47+
/// Returns the prescaler of the APBn
48+
pub fn $ppre(&self) -> u8 {
49+
self.$ppre
50+
}
51+
)+
52+
};
53+
}
54+
55+
/// Getters for optional clocks
56+
macro_rules! optional_ck_getter {
57+
($($opt_ck:ident: $doc:expr,)+) => {
58+
$(
59+
/// Returns `Some(frequency)` if
60+
#[doc=$doc]
61+
/// is running, otherwise `None`
62+
pub fn $opt_ck(&self) -> Option<Hertz> {
63+
self.$opt_ck
64+
}
65+
)+
66+
};
67+
}
68+
69+
/// Getters for pll clocks
70+
macro_rules! pll_getter {
71+
($($pll_ck:ident,)+) => {
72+
$(
73+
/// Returns `Some(frequency)` if the PLLx output is running,
74+
/// otherwise `None`
75+
pub fn $pll_ck(&self) -> Option<Hertz> {
76+
self.$pll_ck
77+
}
78+
)+
79+
};
80+
}
81+
82+
#[allow(dead_code)]
83+
impl CoreClocks {
84+
/// Returns the frequency of AHB1,2,3 busses
85+
pub fn hclk(&self) -> Hertz {
86+
self.hclk
87+
}
88+
89+
pclk_ppre_getter! {
90+
(pclk1, ppre1),
91+
(pclk2, ppre2),
92+
(pclk3, ppre3),
93+
}
94+
95+
optional_ck_getter! {
96+
csi_ck: "csi_ck",
97+
hsi_ck: "hsi_ck",
98+
hsi48_ck: "hsi48_ck",
99+
per_ck: "per_ck",
100+
hse_ck: "hse_ck",
101+
lse_ck: "lse_ck",
102+
lsi_ck: "lsi_ck",
103+
audio_ck: "audio_ck",
104+
}
105+
106+
/// Returns `Some(frequency)` if the MCO1 output is running, otherwise
107+
/// `None`
108+
pub fn mco1_ck(&self) -> Option<Hertz> {
109+
self.mco1_ck
110+
}
111+
112+
/// Returns `Some(frequency)` if the MCO2 output is running, otherwise
113+
/// `None`
114+
pub fn mco2_ck(&self) -> Option<Hertz> {
115+
self.mco2_ck
116+
}
117+
118+
pll_getter! {
119+
pll1_p_ck,
120+
pll1_q_ck,
121+
pll1_r_ck,
122+
pll2_p_ck,
123+
pll2_q_ck,
124+
pll2_r_ck,
125+
}
126+
127+
/// Returns the input frequency to the SCGU
128+
pub fn sys_ck(&self) -> Hertz {
129+
self.sys_ck
130+
}
131+
132+
/// Returns the input frequency to the SCGU - ALIAS
133+
pub fn sysclk(&self) -> Hertz {
134+
self.sys_ck
135+
}
136+
137+
/// Returns the CK_INT frequency for timers on APB1
138+
pub fn timx_ker_ck(&self) -> Hertz {
139+
self.timx_ker_ck
140+
}
141+
142+
/// Returns the CK_INT frequency for timers on APB2
143+
pub fn timy_ker_ck(&self) -> Hertz {
144+
self.timy_ker_ck
145+
}
146+
}

0 commit comments

Comments
 (0)