Skip to content

Commit aa3e7d1

Browse files
committed
L47x and L48x use 110C as the calibration temp, rest use 130
Rename the calibration structs to Low/High instead of 30/130 for clarity * 130 makes no sense when L47 uses 110 and Call30 and Cal30 could also be easily mistaken at a glance High constant is conditional on the device product feature
1 parent 767e2c0 commit aa3e7d1

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/adc.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
},
1616
pac,
1717
rcc::{AHB2, CCIPR},
18-
signature::{VrefCal, VtempCal130, VtempCal30, VDDA_CALIB_MV},
18+
signature::{VrefCal, VtempCalHigh, VtempCalLow, VDDA_CALIB_MV},
1919
};
2020

2121
use pac::{ADC1, ADC_COMMON};
@@ -279,12 +279,14 @@ impl ADC {
279279
/// Convert a raw sample from the `Temperature` to deg C
280280
pub fn to_degrees_centigrade(&self, sample: u16) -> f32 {
281281
let sample = (u32::from(sample) * self.calibrated_vdda) / VDDA_CALIB_MV;
282-
(VtempCal130::TEMP_DEGREES - VtempCal30::TEMP_DEGREES) as f32
282+
(VtempCalHigh::TEMP_DEGREES - VtempCalLow::TEMP_DEGREES) as f32
283283
// as signed because RM0351 doesn't specify against this being an
284284
// inverse relation (which would result in a negative differential)
285-
/ (VtempCal130::get().read() as i32 - VtempCal30::get().read() as i32) as f32
285+
/ (VtempCalHigh::get().read() as i32 - VtempCalLow::get().read() as i32) as f32
286286
// this can definitely be negative so must be done as a signed value
287-
* (sample as i32 - VtempCal30::get().read() as i32) as f32
287+
* (sample as i32 - VtempCalLow::get().read() as i32) as f32
288+
// while it would make sense for this to be `VtempCalLow::TEMP_DEGREES` (which is 30*C),
289+
// the RM specifically uses 30*C so this will too
288290
+ 30.0
289291
}
290292

src/signature.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ impl VrefCal {
9696
/// aka TS_CAL1 in reference manual
9797
#[derive(Debug)]
9898
#[repr(C)]
99-
pub struct VtempCal30(u16);
100-
define_ptr_type!(VtempCal30, 0x1FFF_75A8);
99+
pub struct VtempCalLow(u16);
100+
define_ptr_type!(VtempCalLow, 0x1FFF_75A8);
101101

102-
impl VtempCal30 {
102+
impl VtempCalLow {
103103
/// aka TS_CAL1_TEMP in reference manual
104104
pub const TEMP_DEGREES: u16 = 30;
105105
/// Read calibration value
@@ -112,13 +112,16 @@ impl VtempCal30 {
112112
/// aka TS_CAL2 in reference manual
113113
#[derive(Debug)]
114114
#[repr(C)]
115-
pub struct VtempCal130(u16);
116-
define_ptr_type!(VtempCal130, 0x1FFF_75CA);
115+
pub struct VtempCalHigh(u16);
116+
define_ptr_type!(VtempCalHigh, 0x1FFF_75CA);
117117

118-
impl VtempCal130 {
118+
impl VtempCalHigh {
119119
/// aka TS_CAL2_TEMP in reference manual
120120
/// Feature gate Required: this is 110 for L47x/L48x, 130 for other L4s according to
121121
/// https://github.com/STMicroelectronics/STM32CubeL4/blob/5e1553e07706491bd11f4edd304e093b6e4b83a4/Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_ll_adc.h#L352-L356
122+
#[cfg(feature = "private_product_L47_L48")]
123+
pub const TEMP_DEGREES: u16 = 110;
124+
#[cfg(not(feature = "private_product_L47_L48"))]
122125
pub const TEMP_DEGREES: u16 = 130;
123126
/// Read calibration value
124127
pub fn read(&self) -> u16 {

0 commit comments

Comments
 (0)