embassy-stm32

Crates

git

Versions

stm32l496qe

Flavors

Skip to main content

Calibration

Struct Calibration 

Source
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: u16

Temperature sensor calibration value at TS_CAL1_TEMP_C.

§ts_cal2: u16

Temperature sensor calibration value at TS_CAL2_TEMP_C.

§vrefint_cal: u16

Internal voltage reference calibration value measured at VREF_CALIB_MV.

Implementations§

Source§

impl Calibration

Source

pub fn read() -> Self

Read factory calibration values from flash/signature registers.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Calibration

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Calibration

Source§

impl Debug for Calibration

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Format for Calibration

Source§

fn format(&self, f: Formatter<'_>)

Writes the defmt representation of self to fmt.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, I> Binding<I, NoHandler<I>> for T
where T: Copy, I: Interrupt,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.