diff options
| -rw-r--r-- | embassy-stm32/src/adc/v2.rs | 10 | ||||
| -rw-r--r-- | embassy-stm32/src/adc/v3.rs | 12 | ||||
| -rw-r--r-- | embassy-stm32/src/adc/v4.rs | 10 |
3 files changed, 16 insertions, 16 deletions
diff --git a/embassy-stm32/src/adc/v2.rs b/embassy-stm32/src/adc/v2.rs index 9244e5d8b..25b7ba967 100644 --- a/embassy-stm32/src/adc/v2.rs +++ b/embassy-stm32/src/adc/v2.rs | |||
| @@ -153,7 +153,7 @@ impl Prescaler { | |||
| 153 | 153 | ||
| 154 | pub struct Adc<'d, T: Instance> { | 154 | pub struct Adc<'d, T: Instance> { |
| 155 | sample_time: SampleTime, | 155 | sample_time: SampleTime, |
| 156 | vref: u32, | 156 | vref_mv: u32, |
| 157 | resolution: Resolution, | 157 | resolution: Resolution, |
| 158 | phantom: PhantomData<&'d mut T>, | 158 | phantom: PhantomData<&'d mut T>, |
| 159 | } | 159 | } |
| @@ -183,7 +183,7 @@ where | |||
| 183 | Self { | 183 | Self { |
| 184 | sample_time: Default::default(), | 184 | sample_time: Default::default(), |
| 185 | resolution: Resolution::default(), | 185 | resolution: Resolution::default(), |
| 186 | vref: VREF_DEFAULT_MV, | 186 | vref_mv: VREF_DEFAULT_MV, |
| 187 | phantom: PhantomData, | 187 | phantom: PhantomData, |
| 188 | } | 188 | } |
| 189 | } | 189 | } |
| @@ -199,13 +199,13 @@ where | |||
| 199 | /// Set VREF value in millivolts. This value is used for [to_millivolts()] sample conversion. | 199 | /// Set VREF value in millivolts. This value is used for [to_millivolts()] sample conversion. |
| 200 | /// | 200 | /// |
| 201 | /// Use this if you have a known precise VREF (VDDA) pin reference voltage. | 201 | /// Use this if you have a known precise VREF (VDDA) pin reference voltage. |
| 202 | pub fn set_vref(&mut self, vref: u32) { | 202 | pub fn set_vref_mv(&mut self, vref_mv: u32) { |
| 203 | self.vref = vref; | 203 | self.vref_mv = vref_mv; |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | /// Convert a measurement to millivolts | 206 | /// Convert a measurement to millivolts |
| 207 | pub fn to_millivolts(&self, sample: u16) -> u16 { | 207 | pub fn to_millivolts(&self, sample: u16) -> u16 { |
| 208 | ((u32::from(sample) * self.vref) / self.resolution.to_max_count()) as u16 | 208 | ((u32::from(sample) * self.vref_mv) / self.resolution.to_max_count()) as u16 |
| 209 | } | 209 | } |
| 210 | 210 | ||
| 211 | /// Perform a single conversion. | 211 | /// Perform a single conversion. |
diff --git a/embassy-stm32/src/adc/v3.rs b/embassy-stm32/src/adc/v3.rs index d8cac0724..0f1090888 100644 --- a/embassy-stm32/src/adc/v3.rs +++ b/embassy-stm32/src/adc/v3.rs | |||
| @@ -205,7 +205,7 @@ pub use sample_time::SampleTime; | |||
| 205 | 205 | ||
| 206 | pub struct Adc<'d, T: Instance> { | 206 | pub struct Adc<'d, T: Instance> { |
| 207 | sample_time: SampleTime, | 207 | sample_time: SampleTime, |
| 208 | vref: u32, | 208 | vref_mv: u32, |
| 209 | resolution: Resolution, | 209 | resolution: Resolution, |
| 210 | phantom: PhantomData<&'d mut T>, | 210 | phantom: PhantomData<&'d mut T>, |
| 211 | } | 211 | } |
| @@ -244,7 +244,7 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 244 | Self { | 244 | Self { |
| 245 | sample_time: Default::default(), | 245 | sample_time: Default::default(), |
| 246 | resolution: Resolution::default(), | 246 | resolution: Resolution::default(), |
| 247 | vref: VREF_DEFAULT_MV, | 247 | vref_mv: VREF_DEFAULT_MV, |
| 248 | phantom: PhantomData, | 248 | phantom: PhantomData, |
| 249 | } | 249 | } |
| 250 | } | 250 | } |
| @@ -307,7 +307,7 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 307 | 307 | ||
| 308 | self.sample_time = old_sample_time; | 308 | self.sample_time = old_sample_time; |
| 309 | 309 | ||
| 310 | self.vref = (VREF_CALIB_MV * u32::from(vrefint_cal)) / u32::from(vrefint_samp); | 310 | self.vref_mv = (VREF_CALIB_MV * u32::from(vrefint_cal)) / u32::from(vrefint_samp); |
| 311 | } | 311 | } |
| 312 | 312 | ||
| 313 | pub fn set_sample_time(&mut self, sample_time: SampleTime) { | 313 | pub fn set_sample_time(&mut self, sample_time: SampleTime) { |
| @@ -321,13 +321,13 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 321 | /// Set VREF value in millivolts. This value is used for [to_millivolts()] sample conversion. | 321 | /// Set VREF value in millivolts. This value is used for [to_millivolts()] sample conversion. |
| 322 | /// | 322 | /// |
| 323 | /// Use this if you have a known precise VREF (VDDA) pin reference voltage. | 323 | /// Use this if you have a known precise VREF (VDDA) pin reference voltage. |
| 324 | pub fn set_vref(&mut self, vref: u32) { | 324 | pub fn set_vref_mv(&mut self, vref_mv: u32) { |
| 325 | self.vref = vref; | 325 | self.vref_mv = vref_mv; |
| 326 | } | 326 | } |
| 327 | 327 | ||
| 328 | /// Convert a measurement to millivolts | 328 | /// Convert a measurement to millivolts |
| 329 | pub fn to_millivolts(&self, sample: u16) -> u16 { | 329 | pub fn to_millivolts(&self, sample: u16) -> u16 { |
| 330 | ((u32::from(sample) * self.vref) / self.resolution.to_max_count()) as u16 | 330 | ((u32::from(sample) * self.vref_mv) / self.resolution.to_max_count()) as u16 |
| 331 | } | 331 | } |
| 332 | 332 | ||
| 333 | /* | 333 | /* |
diff --git a/embassy-stm32/src/adc/v4.rs b/embassy-stm32/src/adc/v4.rs index cc210a6d0..d356d7b66 100644 --- a/embassy-stm32/src/adc/v4.rs +++ b/embassy-stm32/src/adc/v4.rs | |||
| @@ -322,7 +322,7 @@ impl Prescaler { | |||
| 322 | 322 | ||
| 323 | pub struct Adc<'d, T: Instance> { | 323 | pub struct Adc<'d, T: Instance> { |
| 324 | sample_time: SampleTime, | 324 | sample_time: SampleTime, |
| 325 | vref: u32, | 325 | vref_mv: u32, |
| 326 | resolution: Resolution, | 326 | resolution: Resolution, |
| 327 | phantom: PhantomData<&'d mut T>, | 327 | phantom: PhantomData<&'d mut T>, |
| 328 | } | 328 | } |
| @@ -360,7 +360,7 @@ impl<'d, T: Instance + crate::rcc::RccPeripheral> Adc<'d, T> { | |||
| 360 | 360 | ||
| 361 | let mut s = Self { | 361 | let mut s = Self { |
| 362 | sample_time: Default::default(), | 362 | sample_time: Default::default(), |
| 363 | vref: VREF_DEFAULT_MV, | 363 | vref_mv: VREF_DEFAULT_MV, |
| 364 | resolution: Resolution::default(), | 364 | resolution: Resolution::default(), |
| 365 | phantom: PhantomData, | 365 | phantom: PhantomData, |
| 366 | }; | 366 | }; |
| @@ -470,13 +470,13 @@ impl<'d, T: Instance + crate::rcc::RccPeripheral> Adc<'d, T> { | |||
| 470 | /// Set VREF value in millivolts. This value is used for [to_millivolts()] sample conversion. | 470 | /// Set VREF value in millivolts. This value is used for [to_millivolts()] sample conversion. |
| 471 | /// | 471 | /// |
| 472 | /// Use this if you have a known precise VREF (VDDA) pin reference voltage. | 472 | /// Use this if you have a known precise VREF (VDDA) pin reference voltage. |
| 473 | pub fn set_vref(&mut self, vref: u32) { | 473 | pub fn set_vref_mv(&mut self, vref_mv: u32) { |
| 474 | self.vref = vref; | 474 | self.vref_mv = vref_mv; |
| 475 | } | 475 | } |
| 476 | 476 | ||
| 477 | /// Convert a measurement to millivolts | 477 | /// Convert a measurement to millivolts |
| 478 | pub fn to_millivolts(&self, sample: u16) -> u16 { | 478 | pub fn to_millivolts(&self, sample: u16) -> u16 { |
| 479 | ((u32::from(sample) * self.vref) / self.resolution.to_max_count()) as u16 | 479 | ((u32::from(sample) * self.vref_mv) / self.resolution.to_max_count()) as u16 |
| 480 | } | 480 | } |
| 481 | 481 | ||
| 482 | /// Perform a single conversion. | 482 | /// Perform a single conversion. |
