Skip to content

Commit a272fa0

Browse files
committed
clippy
1 parent 3e93493 commit a272fa0

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

src/analog/adc.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub struct Adc {
106106
sample_time: SampleTime,
107107
align: Align,
108108
precision: Precision,
109-
vdda_mv: Option<u32>,
109+
vref: Option<u32>,
110110
}
111111

112112
/// Contains the calibration factors for the ADC which can be reused with [`Adc::set_calibration()`]
@@ -125,7 +125,7 @@ impl Adc {
125125
sample_time: SampleTime::T_2,
126126
align: Align::Right,
127127
precision: Precision::B_12,
128-
vdda_mv: None,
128+
vref: None,
129129
}
130130
}
131131

@@ -232,9 +232,11 @@ impl Adc {
232232
&mut self,
233233
pin: &mut PIN,
234234
) -> nb::Result<u16, ()> {
235-
let vdda_mv = if let Some(vdda_mv) = self.vdda_mv {
236-
vdda_mv
235+
let vref = if let Some(vref) = &self.vref {
236+
*vref
237237
} else {
238+
let vref_cal: u32 = unsafe { ptr::read_volatile(0x1FFF_75AA as *const u16) as u32 };
239+
238240
let mut vref = VRef::new();
239241
let vref_val: u32 = if vref.enabled(self) {
240242
self.read(&mut vref)?
@@ -245,20 +247,13 @@ impl Adc {
245247
vref_val
246248
};
247249

248-
let vref_cal: u32 = unsafe {
249-
// DS12766 3.13.2
250-
ptr::read_volatile(0x1FFF_75AA as *const u16) as u32
251-
};
252-
253-
// RM0454 14.9 Calculating the actual VDDA voltage using the internal reference voltage
254-
// V_DDA = 3 V x VREFINT_CAL / VREFINT_DATA
255-
let vdda_mv = vref_cal * 3_000_u32 / vref_val;
256-
self.vdda_mv = Some(vdda_mv);
257-
vdda_mv
250+
let vref = (3_000_u32 * vref_cal) / vref_val;
251+
self.vref = Some(vref);
252+
vref
258253
};
259254

260255
self.read(pin).map(|raw: u32| {
261-
let adc_mv = (vdda_mv * raw) >> 12;
256+
let adc_mv = (vref as u32 * raw) >> 16;
262257
adc_mv as u16
263258
})
264259
}

src/gpio.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,9 @@ macro_rules! gpio {
453453
let _ = &(*$GPIOX::ptr()).pupdr.modify(|r, w| {
454454
w.bits(r.bits() & !(0b11 << offset))
455455
});
456-
&(*$GPIOX::ptr()).moder.modify(|r, w| {
456+
let _ = &(*$GPIOX::ptr()).moder.modify(|r, w| {
457457
w.bits(r.bits() & !(0b11 << offset))
458-
})
458+
});
459459
};
460460
let offset = ($i % 4) * 8;
461461
let mask = $Pxn << offset;
@@ -483,9 +483,9 @@ macro_rules! gpio {
483483
pub fn set_speed(self, speed: Speed) -> Self {
484484
let offset = 2 * $i;
485485
unsafe {
486-
&(*$GPIOX::ptr()).ospeedr.modify(|r, w| {
486+
let _ = &(*$GPIOX::ptr()).ospeedr.modify(|r, w| {
487487
w.bits((r.bits() & !(0b11 << offset)) | ((speed as u32) << offset))
488-
})
488+
});
489489
};
490490
self
491491
}

0 commit comments

Comments
 (0)