File tree Expand file tree Collapse file tree 2 files changed +7
-10
lines changed Expand file tree Collapse file tree 2 files changed +7
-10
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
15
15
- Update ` remap_pins() ` and remove critical section
16
16
- Updated ` stm32f0 ` peripheral access crate from 0.13 to 0.14
17
17
- Address a few clippy lints
18
+ - Fix ` VTemp::convert_temp() `
18
19
19
20
### Added
20
21
Original file line number Diff line number Diff line change @@ -270,19 +270,15 @@ impl VTemp {
270
270
}
271
271
272
272
fn convert_temp ( vtemp : u16 , vdda : u16 ) -> i16 {
273
- let vtemp30_cal = i32:: from ( unsafe { ptr:: read ( VTEMPCAL30 ) } ) * 100 ;
274
- let vtemp110_cal = i32:: from ( unsafe { ptr:: read ( VTEMPCAL110 ) } ) * 100 ;
275
-
276
- let mut temperature = i32:: from ( vtemp) * 100 ;
277
- temperature = ( temperature * ( i32:: from ( vdda) / i32:: from ( VDD_CALIB ) ) ) - vtemp30_cal;
278
- temperature *= ( 110 - 30 ) * 100 ;
279
- temperature /= vtemp110_cal - vtemp30_cal;
280
- temperature += 3000 ;
281
- temperature as i16
273
+ let vtemp30_cal = unsafe { ptr:: read ( VTEMPCAL30 ) } as i32 ;
274
+ let vtemp110_cal = unsafe { ptr:: read ( VTEMPCAL110 ) } as i32 ;
275
+ let raw_temp_comp = vtemp as u32 * vdda as u32 / VDD_CALIB as u32 ;
276
+ ( ( raw_temp_comp as i32 - vtemp30_cal) * 10 * ( 110 - 30 ) / ( vtemp110_cal - vtemp30_cal)
277
+ + 300 ) as i16
282
278
}
283
279
284
280
/// Read the value of the internal temperature sensor and return the
285
- /// result in 100ths of a degree centigrade.
281
+ /// result in 10ths of a degree centigrade.
286
282
///
287
283
/// Given a delay reference it will attempt to restrict to the
288
284
/// minimum delay needed to ensure a 10 us t<sub>START</sub> value.
You can’t perform that action at this time.
0 commit comments