Skip to content

Commit 1075535

Browse files
Make RCC::freeze and dependencies inlinable
1 parent c969c7c commit 1075535

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/rcc.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pub struct Config {
9393
}
9494

9595
impl Default for Config {
96+
#[inline]
9697
fn default() -> Config {
9798
Config {
9899
mux: ClockSrc::MSI(MSIRange::default()),
@@ -104,26 +105,31 @@ impl Default for Config {
104105
}
105106

106107
impl Config {
108+
#[inline]
107109
pub fn clock_src(mut self, mux: ClockSrc) -> Self {
108110
self.mux = mux;
109111
self
110112
}
111113

114+
#[inline]
112115
pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self {
113116
self.ahb_pre = pre;
114117
self
115118
}
116119

120+
#[inline]
117121
pub fn apb1_pre(mut self, pre: APBPrescaler) -> Self {
118122
self.apb1_pre = pre;
119123
self
120124
}
121125

126+
#[inline]
122127
pub fn apb2_pre(mut self, pre: APBPrescaler) -> Self {
123128
self.apb2_pre = pre;
124129
self
125130
}
126131

132+
#[inline]
127133
pub fn hsi16() -> Config {
128134
Config {
129135
mux: ClockSrc::HSI16,
@@ -133,6 +139,7 @@ impl Config {
133139
}
134140
}
135141

142+
#[inline]
136143
pub fn msi(range: MSIRange) -> Config {
137144
Config {
138145
mux: ClockSrc::MSI(range),
@@ -142,6 +149,7 @@ impl Config {
142149
}
143150
}
144151

152+
#[inline]
145153
pub fn pll(pll_src: PLLSource, pll_mul: PLLMul, pll_div: PLLDiv) -> Config {
146154
Config {
147155
mux: ClockSrc::PLL(pll_src, pll_mul, pll_div),
@@ -151,6 +159,7 @@ impl Config {
151159
}
152160
}
153161

162+
#[inline]
154163
pub fn hse<T>(freq: T) -> Config
155164
where
156165
T: Into<Hertz>,
@@ -176,6 +185,10 @@ pub trait RccExt {
176185
}
177186

178187
impl RccExt for RCC {
188+
// `cfgr` is almost always a constant, so make sure it can be constant-propagated properly by
189+
// marking this function and all `Config` constructors and setters as `#[inline]`.
190+
// This saves ~900 Bytes for the `pwr.rs` example.
191+
#[inline]
179192
fn freeze(self, cfgr: Config) -> Rcc {
180193
let (sys_clk, sw_bits) = match cfgr.mux {
181194
ClockSrc::MSI(range) => {

0 commit comments

Comments
 (0)