@@ -91,7 +91,7 @@ pub enum AdcSampleTime {
91
91
92
92
#[ cfg( feature = "device-selected" ) ]
93
93
impl AdcSampleTime {
94
- fn write_bits ( & self , adc : & mut stm32:: ADC ) {
94
+ fn write_bits ( self , adc : & mut stm32:: ADC ) {
95
95
unsafe {
96
96
adc. smpr . write ( |w| {
97
97
w. smpr ( ) . bits ( match self {
@@ -139,7 +139,7 @@ pub enum AdcAlign {
139
139
140
140
#[ cfg( feature = "device-selected" ) ]
141
141
impl AdcAlign {
142
- fn write_bits ( & self , adc : & mut stm32:: ADC ) {
142
+ fn write_bits ( self , adc : & mut stm32:: ADC ) {
143
143
adc. cfgr1 . write ( |w| {
144
144
w. align ( ) . bit ( match self {
145
145
AdcAlign :: Left => true ,
@@ -170,7 +170,7 @@ pub enum AdcPrecision {
170
170
171
171
#[ cfg( feature = "device-selected" ) ]
172
172
impl AdcPrecision {
173
- fn write_bits ( & self , adc : & mut stm32:: ADC ) {
173
+ fn write_bits ( self , adc : & mut stm32:: ADC ) {
174
174
unsafe {
175
175
adc. cfgr1 . write ( |w| {
176
176
w. res ( ) . bits ( match self {
@@ -226,11 +226,11 @@ adc_pins!(
226
226
gpioc:: PC5 <Analog > => 15_u8 ,
227
227
) ;
228
228
229
- #[ derive( Debug ) ]
229
+ #[ derive( Debug , Default ) ]
230
230
/// Internal temperature sensor (ADC Channel 16)
231
231
pub struct VTemp ;
232
232
233
- #[ derive( Debug ) ]
233
+ #[ derive( Debug , Default ) ]
234
234
/// Internal voltage reference (ADC Channel 17)
235
235
pub struct VRef ;
236
236
@@ -244,7 +244,7 @@ adc_pins!(
244
244
impl VTemp {
245
245
/// Init a new VTemp
246
246
pub fn new ( ) -> Self {
247
- VTemp { }
247
+ VTemp :: default ( )
248
248
}
249
249
250
250
/// Enable the internal temperature sense, this has a wake up time
@@ -270,8 +270,8 @@ impl VTemp {
270
270
let vtemp30_cal = i32:: from ( unsafe { ptr:: read ( VTEMPCAL30 ) } ) * 100 ;
271
271
let vtemp110_cal = i32:: from ( unsafe { ptr:: read ( VTEMPCAL110 ) } ) * 100 ;
272
272
273
- let mut temperature: i32 = ( vtemp as i32 ) * 100 ;
274
- temperature = ( temperature * ( vdda as i32 ) / ( VDD_CALIB as i32 ) ) - vtemp30_cal;
273
+ let mut temperature = i32 :: from ( vtemp) * 100 ;
274
+ temperature = ( temperature * ( i32:: from ( vdda ) / i32 :: from ( VDD_CALIB ) ) ) - vtemp30_cal;
275
275
temperature *= ( 110 - 30 ) * 100 ;
276
276
temperature /= vtemp110_cal - vtemp30_cal;
277
277
temperature += 3000 ;
@@ -318,7 +318,7 @@ impl VTemp {
318
318
impl VRef {
319
319
/// Init a new VRef
320
320
pub fn new ( ) -> Self {
321
- VRef { }
321
+ VRef :: default ( )
322
322
}
323
323
324
324
/// Enable the internal voltage reference, remember to disable when not in use.
@@ -356,12 +356,12 @@ impl VRef {
356
356
357
357
adc. restore_cfg ( prev_cfg) ;
358
358
359
- ( ( VDD_CALIB as u32 ) * vrefint_cal / vref_val) as u16
359
+ ( u32 :: from ( VDD_CALIB ) * vrefint_cal / vref_val) as u16
360
360
}
361
361
}
362
362
363
363
#[ cfg( feature = "stm32f042" ) ]
364
- #[ derive( Debug ) ]
364
+ #[ derive( Debug , Default ) ]
365
365
/// Battery reference voltage (ADC Channel 18)
366
366
pub struct VBat ;
367
367
@@ -374,7 +374,7 @@ adc_pins!(
374
374
impl VBat {
375
375
/// Init a new VBat
376
376
pub fn new ( ) -> Self {
377
- VBat { }
377
+ VBat :: default ( )
378
378
}
379
379
380
380
/// Enable the internal VBat sense, remember to disable when not in use
@@ -483,7 +483,7 @@ impl Adc {
483
483
match self . align {
484
484
AdcAlign :: Left => u16:: max_value ( ) ,
485
485
AdcAlign :: LeftAsRM => match self . precision {
486
- AdcPrecision :: B_6 => u8:: max_value ( ) as u16 ,
486
+ AdcPrecision :: B_6 => u16 :: from ( u8:: max_value ( ) ) ,
487
487
_ => u16:: max_value ( ) ,
488
488
} ,
489
489
AdcAlign :: Right => match self . precision {
@@ -497,9 +497,9 @@ impl Adc {
497
497
498
498
/// Read the value of a channel and converts the result to milli-volts
499
499
pub fn read_abs_mv < PIN : Channel < Adc , ID = u8 > > ( & mut self , pin : & mut PIN ) -> u16 {
500
- let vdda = VRef :: read_vdda ( self ) as u32 ;
500
+ let vdda = u32 :: from ( VRef :: read_vdda ( self ) ) ;
501
501
let v: u32 = self . read ( pin) . unwrap ( ) ;
502
- let max_samp = self . max_sample ( ) as u32 ;
502
+ let max_samp = u32 :: from ( self . max_sample ( ) ) ;
503
503
504
504
( v * vdda / max_samp) as u16
505
505
}
0 commit comments