Skip to content

Commit 1547f22

Browse files
astrotherealprof
authored andcommitted
adc: reuse signature::VrefCal (#90)
1 parent eb34e8f commit 1547f22

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/adc.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
44
#![deny(missing_docs)]
55

6-
/// This is the address the VREF calibration value is stored in at the factory
7-
const VREFCAL: *const u16 = 0x1FFF_7A2A as *const u16;
86
/// This is the test voltage, in millivolts of the calibration done at the factory
97
const VDDA_CALIB: u32 = 3300;
108

@@ -28,13 +26,9 @@ use embedded_hal::adc::{
2826
use crate::{
2927
stm32,
3028
gpio::*,
29+
signature::VrefCal,
3130
};
3231

33-
/// Fetches the vref calibration value stored at the factory
34-
fn get_vref_cal() -> u32 {
35-
unsafe { u32::from(ptr::read(VREFCAL)) }
36-
}
37-
3832
/// Vref internal signal, used for calibration
3933
pub struct Vref;
4034

@@ -687,10 +681,10 @@ macro_rules! adc {
687681
self.enable_temperature_and_vref();
688682
}
689683

690-
let vref_cal = get_vref_cal();
684+
let vref_cal = VrefCal::get().read();
691685
let vref_samp = self.read(&mut Vref).unwrap(); //This can't actually fail, it's just in a result to satisfy hal trait
692686

693-
self.calibrated_vdda = (VDDA_CALIB * vref_cal) / u32::from(vref_samp);
687+
self.calibrated_vdda = (VDDA_CALIB * u32::from(vref_cal)) / u32::from(vref_samp);
694688
if !vref_en {
695689
self.disable_temperature_and_vref();
696690
}

0 commit comments

Comments
 (0)