pub struct Calibration {
pub ts_cal1: u16,
pub ts_cal2: u16,
pub vrefint_cal: u16,
}Expand description
Factory and datasheet ADC calibration parameters for the current chip.
Read once via Calibration::read and reuse to convert raw ADC counts into calibrated VDDA
voltages, channel millivolts, and millidegrees Celsius.
Fields§
§ts_cal1: u16Temperature sensor calibration value at TS_CAL1_TEMP_C.
ts_cal2: u16Temperature sensor calibration value at TS_CAL2_TEMP_C.
vrefint_cal: u16Internal voltage reference calibration value measured at VREF_CALIB_MV.
Implementations§
Source§impl Calibration
impl Calibration
Sourcepub fn vdda_mv(&self, vrefint_data: u32, resolution: Resolution) -> u32
pub fn vdda_mv(&self, vrefint_data: u32, resolution: Resolution) -> u32
Calculate actual VDDA voltage in millivolts from a VrefInt sample taken at resolution.
Returns VREF_DEFAULT_MV if vrefint_data is 0.
Sourcepub fn calculate_vdda_mv(&self, vrefint_data: u32) -> u32
pub fn calculate_vdda_mv(&self, vrefint_data: u32) -> u32
Calculate actual VDDA voltage in millivolts assuming vrefint_data matches
VREF_CALIB_BITS resolution.
Prefer Calibration::vdda_mv when sampling at an explicit Resolution (such as
12-bit ADC4 on STM32U5 where factory calibration is 14-bit).
Sourcepub fn sample_to_mv(
&self,
sample: u32,
sample_resolution: Resolution,
vrefint_data: u32,
vrefint_resolution: Resolution,
) -> u32
pub fn sample_to_mv( &self, sample: u32, sample_resolution: Resolution, vrefint_data: u32, vrefint_resolution: Resolution, ) -> u32
Convert a raw channel sample to millivolts using a VrefInt reading for VDDA compensation.
Sourcepub fn temperature_millicelsius(
&self,
ts_data: u32,
ts_resolution: Resolution,
vrefint_data: u32,
vrefint_resolution: Resolution,
) -> i32
pub fn temperature_millicelsius( &self, ts_data: u32, ts_resolution: Resolution, vrefint_data: u32, vrefint_resolution: Resolution, ) -> i32
Convert a temperature sensor reading at ts_resolution to millidegrees Celsius, using a
VrefInt sample at vrefint_resolution for VDDA compensation.
Sourcepub fn temperature_millicelsius_with_vdda(
&self,
ts_data: u32,
ts_resolution: Resolution,
vdda_mv: u32,
) -> i32
pub fn temperature_millicelsius_with_vdda( &self, ts_data: u32, ts_resolution: Resolution, vdda_mv: u32, ) -> i32
Convert a temperature sensor reading at ts_resolution to millidegrees Celsius using a
known vdda_mv.
Sourcepub fn convert_to_millicelsius(&self, ts_data: u32, vrefint_data: u32) -> i32
pub fn convert_to_millicelsius(&self, ts_data: u32, vrefint_data: u32) -> i32
Convert a temperature sensor reading to millidegrees Celsius assuming both ts_data and
vrefint_data match factory calibration bit widths.
Prefer Calibration::temperature_millicelsius when sampling at an explicit Resolution.