Skip to content

Commit 162ee40

Browse files
committed
rcc refactoring
1 parent 2b5bd2b commit 162ee40

File tree

7 files changed

+25
-8
lines changed

7 files changed

+25
-8
lines changed

src/analog/adc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ pub struct CalibrationFactor(pub u8);
113113
impl Adc {
114114
pub fn new(adc: ADC, rcc: &mut Rcc) -> Self {
115115
// Enable ADC clocks
116-
rcc.rb.apbenr2.modify(|_, w| w.adcen().set_bit());
116+
rcc.enable_adc();
117+
117118
adc.cr.modify(|_, w| w.advregen().set_bit());
118119

119120
Self {

src/crc.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ pub trait CrcExt {
3131

3232
impl CrcExt for CRC {
3333
fn constrain(self, rcc: &mut Rcc) -> Config {
34-
// Enable power to CRC unit
35-
rcc.rb.ahbenr.modify(|_, w| w.crcen().set_bit());
36-
// Reset CRC unit
37-
rcc.rb.ahbrstr.modify(|_, w| w.crcrst().set_bit());
38-
rcc.rb.ahbrstr.modify(|_, w| w.crcrst().clear_bit());
34+
rcc.enable_crc();
3935

4036
// Default values
4137
Config {

src/flash/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl WriteErase for UnlockedFlash {
189189

190190
let mut chunks = aligned_data.chunks_exact(mem::size_of::<Self::NativeType>());
191191

192-
while let Some(exact_chunk) = chunks.next() {
192+
for exact_chunk in &mut chunks {
193193
// Write chunks
194194
let native = &[Self::NativeType::from_ne_bytes(
195195
exact_chunk.try_into().unwrap(),

src/gpio.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,30 +177,35 @@ macro_rules! gpio {
177177
_mode: PhantomData<MODE>,
178178
}
179179

180+
#[allow(clippy::from_over_into)]
180181
impl Into<$PXi<Input<PullDown>>> for $PXi<DefaultMode> {
181182
fn into(self) -> $PXi<Input<PullDown>> {
182183
self.into_pull_down_input()
183184
}
184185
}
185186

187+
#[allow(clippy::from_over_into)]
186188
impl Into<$PXi<Input<PullUp>>> for $PXi<DefaultMode> {
187189
fn into(self) -> $PXi<Input<PullUp>> {
188190
self.into_pull_up_input()
189191
}
190192
}
191193

194+
#[allow(clippy::from_over_into)]
192195
impl Into<$PXi<Input<Floating>>> for $PXi<DefaultMode> {
193196
fn into(self) -> $PXi<Input<Floating>> {
194197
self.into_floating_input()
195198
}
196199
}
197200

201+
#[allow(clippy::from_over_into)]
198202
impl Into<$PXi<Output<OpenDrain>>> for $PXi<DefaultMode> {
199203
fn into(self) -> $PXi<Output<OpenDrain>> {
200204
self.into_open_drain_output()
201205
}
202206
}
203207

208+
#[allow(clippy::from_over_into)]
204209
impl Into<$PXi<Output<PushPull>>> for $PXi<DefaultMode> {
205210
fn into(self) -> $PXi<Output<PushPull>> {
206211
self.into_push_pull_output()

src/rcc/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,16 @@ impl Rcc {
315315
pub(crate) fn enable_power_control(&self) {
316316
self.rb.apbenr1.modify(|_, w| w.pwren().set_bit());
317317
}
318+
319+
pub(crate) fn enable_adc(&self) {
320+
self.rb.apbenr2.modify(|_, w| w.adcen().set_bit());
321+
}
322+
323+
pub(crate) fn enable_crc(&self) {
324+
self.rb.ahbenr.modify(|_, w| w.crcen().set_bit());
325+
self.rb.ahbrstr.modify(|_, w| w.crcrst().set_bit());
326+
self.rb.ahbrstr.modify(|_, w| w.crcrst().clear_bit());
327+
}
318328
}
319329

320330
/// Extension trait that constrains the `RCC` peripheral

src/serial/usart.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ macro_rules! uart_shared {
326326
});
327327
}
328328
}
329-
330329
}
331330
}
332331

src/time.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ impl Add for MicroSecond {
217217
}
218218
}
219219

220+
impl From<Second> for MicroSecond {
221+
fn from(period: Second) -> MicroSecond {
222+
MicroSecond(period.0 * 1_000_000)
223+
}
224+
}
225+
220226
impl From<Hertz> for MicroSecond {
221227
fn from(freq: Hertz) -> MicroSecond {
222228
assert!(freq.0 <= 1_000_000);

0 commit comments

Comments
 (0)