Make vref units explicit
This commit is contained in:
parent
b1f0d6320e
commit
42434c75bc
@ -153,7 +153,7 @@ impl Prescaler {
|
|||||||
|
|
||||||
pub struct Adc<'d, T: Instance> {
|
pub struct Adc<'d, T: Instance> {
|
||||||
sample_time: SampleTime,
|
sample_time: SampleTime,
|
||||||
vref: u32,
|
vref_mv: u32,
|
||||||
resolution: Resolution,
|
resolution: Resolution,
|
||||||
phantom: PhantomData<&'d mut T>,
|
phantom: PhantomData<&'d mut T>,
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ where
|
|||||||
Self {
|
Self {
|
||||||
sample_time: Default::default(),
|
sample_time: Default::default(),
|
||||||
resolution: Resolution::default(),
|
resolution: Resolution::default(),
|
||||||
vref: VREF_DEFAULT_MV,
|
vref_mv: VREF_DEFAULT_MV,
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,13 +199,13 @@ where
|
|||||||
/// Set VREF value in millivolts. This value is used for [to_millivolts()] sample conversion.
|
/// Set VREF value in millivolts. This value is used for [to_millivolts()] sample conversion.
|
||||||
///
|
///
|
||||||
/// Use this if you have a known precise VREF (VDDA) pin reference voltage.
|
/// Use this if you have a known precise VREF (VDDA) pin reference voltage.
|
||||||
pub fn set_vref(&mut self, vref: u32) {
|
pub fn set_vref_mv(&mut self, vref_mv: u32) {
|
||||||
self.vref = vref;
|
self.vref_mv = vref_mv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a measurement to millivolts
|
/// Convert a measurement to millivolts
|
||||||
pub fn to_millivolts(&self, sample: u16) -> u16 {
|
pub fn to_millivolts(&self, sample: u16) -> u16 {
|
||||||
((u32::from(sample) * self.vref) / self.resolution.to_max_count()) as u16
|
((u32::from(sample) * self.vref_mv) / self.resolution.to_max_count()) as u16
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Perform a single conversion.
|
/// Perform a single conversion.
|
||||||
|
@ -205,7 +205,7 @@ pub use sample_time::SampleTime;
|
|||||||
|
|
||||||
pub struct Adc<'d, T: Instance> {
|
pub struct Adc<'d, T: Instance> {
|
||||||
sample_time: SampleTime,
|
sample_time: SampleTime,
|
||||||
vref: u32,
|
vref_mv: u32,
|
||||||
resolution: Resolution,
|
resolution: Resolution,
|
||||||
phantom: PhantomData<&'d mut T>,
|
phantom: PhantomData<&'d mut T>,
|
||||||
}
|
}
|
||||||
@ -244,7 +244,7 @@ impl<'d, T: Instance> Adc<'d, T> {
|
|||||||
Self {
|
Self {
|
||||||
sample_time: Default::default(),
|
sample_time: Default::default(),
|
||||||
resolution: Resolution::default(),
|
resolution: Resolution::default(),
|
||||||
vref: VREF_DEFAULT_MV,
|
vref_mv: VREF_DEFAULT_MV,
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,7 +307,7 @@ impl<'d, T: Instance> Adc<'d, T> {
|
|||||||
|
|
||||||
self.sample_time = old_sample_time;
|
self.sample_time = old_sample_time;
|
||||||
|
|
||||||
self.vref = (VREF_CALIB_MV * u32::from(vrefint_cal)) / u32::from(vrefint_samp);
|
self.vref_mv = (VREF_CALIB_MV * u32::from(vrefint_cal)) / u32::from(vrefint_samp);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_sample_time(&mut self, sample_time: SampleTime) {
|
pub fn set_sample_time(&mut self, sample_time: SampleTime) {
|
||||||
@ -321,13 +321,13 @@ impl<'d, T: Instance> Adc<'d, T> {
|
|||||||
/// Set VREF value in millivolts. This value is used for [to_millivolts()] sample conversion.
|
/// Set VREF value in millivolts. This value is used for [to_millivolts()] sample conversion.
|
||||||
///
|
///
|
||||||
/// Use this if you have a known precise VREF (VDDA) pin reference voltage.
|
/// Use this if you have a known precise VREF (VDDA) pin reference voltage.
|
||||||
pub fn set_vref(&mut self, vref: u32) {
|
pub fn set_vref_mv(&mut self, vref_mv: u32) {
|
||||||
self.vref = vref;
|
self.vref_mv = vref_mv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a measurement to millivolts
|
/// Convert a measurement to millivolts
|
||||||
pub fn to_millivolts(&self, sample: u16) -> u16 {
|
pub fn to_millivolts(&self, sample: u16) -> u16 {
|
||||||
((u32::from(sample) * self.vref) / self.resolution.to_max_count()) as u16
|
((u32::from(sample) * self.vref_mv) / self.resolution.to_max_count()) as u16
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -322,7 +322,7 @@ impl Prescaler {
|
|||||||
|
|
||||||
pub struct Adc<'d, T: Instance> {
|
pub struct Adc<'d, T: Instance> {
|
||||||
sample_time: SampleTime,
|
sample_time: SampleTime,
|
||||||
vref: u32,
|
vref_mv: u32,
|
||||||
resolution: Resolution,
|
resolution: Resolution,
|
||||||
phantom: PhantomData<&'d mut T>,
|
phantom: PhantomData<&'d mut T>,
|
||||||
}
|
}
|
||||||
@ -360,7 +360,7 @@ impl<'d, T: Instance + crate::rcc::RccPeripheral> Adc<'d, T> {
|
|||||||
|
|
||||||
let mut s = Self {
|
let mut s = Self {
|
||||||
sample_time: Default::default(),
|
sample_time: Default::default(),
|
||||||
vref: VREF_DEFAULT_MV,
|
vref_mv: VREF_DEFAULT_MV,
|
||||||
resolution: Resolution::default(),
|
resolution: Resolution::default(),
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
};
|
};
|
||||||
@ -470,13 +470,13 @@ impl<'d, T: Instance + crate::rcc::RccPeripheral> Adc<'d, T> {
|
|||||||
/// Set VREF value in millivolts. This value is used for [to_millivolts()] sample conversion.
|
/// Set VREF value in millivolts. This value is used for [to_millivolts()] sample conversion.
|
||||||
///
|
///
|
||||||
/// Use this if you have a known precise VREF (VDDA) pin reference voltage.
|
/// Use this if you have a known precise VREF (VDDA) pin reference voltage.
|
||||||
pub fn set_vref(&mut self, vref: u32) {
|
pub fn set_vref_mv(&mut self, vref_mv: u32) {
|
||||||
self.vref = vref;
|
self.vref_mv = vref_mv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a measurement to millivolts
|
/// Convert a measurement to millivolts
|
||||||
pub fn to_millivolts(&self, sample: u16) -> u16 {
|
pub fn to_millivolts(&self, sample: u16) -> u16 {
|
||||||
((u32::from(sample) * self.vref) / self.resolution.to_max_count()) as u16
|
((u32::from(sample) * self.vref_mv) / self.resolution.to_max_count()) as u16
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Perform a single conversion.
|
/// Perform a single conversion.
|
||||||
|
Loading…
Reference in New Issue
Block a user