File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -277,9 +277,11 @@ impl ADC {
277
277
}
278
278
279
279
/// Convert a raw sample from the `Temperature` to deg C
280
- pub fn to_degrees_centigrade ( sample : u16 ) -> f32 {
281
- ( 130.0 - 30.0 ) / ( VtempCal130 :: get ( ) . read ( ) as f32 - VtempCal30 :: get ( ) . read ( ) as f32 )
282
- * ( sample as f32 - VtempCal30 :: get ( ) . read ( ) as f32 )
280
+ pub fn to_degrees_centigrade ( & self , sample : u16 ) -> f32 {
281
+ let sample = ( u32:: from ( sample) * self . calibrated_vdda ) / VDDA_CALIB_MV ;
282
+ ( VtempCal130 :: TEMP_DEGREES - VtempCal30 :: TEMP_DEGREES ) as f32
283
+ / ( VtempCal130 :: get ( ) . read ( ) - VtempCal30 :: get ( ) . read ( ) ) as f32
284
+ * ( sample - u32:: from ( VtempCal30 :: get ( ) . read ( ) ) ) as f32
283
285
+ 30.0
284
286
}
285
287
Original file line number Diff line number Diff line change @@ -93,25 +93,32 @@ impl VrefCal {
93
93
}
94
94
95
95
/// A temperature reading taken at 30°C stored at the factory
96
+ /// aka TS_CAL1
96
97
#[ derive( Debug ) ]
97
98
#[ repr( C ) ]
98
99
pub struct VtempCal30 ( u16 ) ;
99
100
define_ptr_type ! ( VtempCal30 , 0x1FFF_75A8 ) ;
100
101
101
102
impl VtempCal30 {
103
+ /// TS_CAL1_TEMP
104
+ pub const TEMP_DEGREES : u16 = 30 ;
102
105
/// Read calibration value
103
106
pub fn read ( & self ) -> u16 {
104
107
self . 0
105
108
}
106
109
}
107
110
108
111
/// A temperature reading taken at 130°C stored at the factory
112
+ /// aka TS_CAL2
109
113
#[ derive( Debug ) ]
110
114
#[ repr( C ) ]
111
115
pub struct VtempCal130 ( u16 ) ;
112
116
define_ptr_type ! ( VtempCal130 , 0x1FFF_75CA ) ;
113
117
114
118
impl VtempCal130 {
119
+ /// TS_CAL2_TEMP
120
+ /// TODO: this is 110 for L47x, 130 for L43x
121
+ pub const TEMP_DEGREES : u16 = 130 ;
115
122
/// Read calibration value
116
123
pub fn read ( & self ) -> u16 {
117
124
self . 0
You can’t perform that action at this time.
0 commit comments