@@ -91,7 +91,7 @@ pub enum AdcSampleTime {
9191
9292#[ cfg( feature = "device-selected" ) ]
9393impl AdcSampleTime {
94- fn write_bits ( & self , adc : & mut stm32:: ADC ) {
94+ fn write_bits ( self , adc : & mut stm32:: ADC ) {
9595 unsafe {
9696 adc. smpr . write ( |w| {
9797 w. smpr ( ) . bits ( match self {
@@ -139,7 +139,7 @@ pub enum AdcAlign {
139139
140140#[ cfg( feature = "device-selected" ) ]
141141impl AdcAlign {
142- fn write_bits ( & self , adc : & mut stm32:: ADC ) {
142+ fn write_bits ( self , adc : & mut stm32:: ADC ) {
143143 adc. cfgr1 . write ( |w| {
144144 w. align ( ) . bit ( match self {
145145 AdcAlign :: Left => true ,
@@ -170,7 +170,7 @@ pub enum AdcPrecision {
170170
171171#[ cfg( feature = "device-selected" ) ]
172172impl AdcPrecision {
173- fn write_bits ( & self , adc : & mut stm32:: ADC ) {
173+ fn write_bits ( self , adc : & mut stm32:: ADC ) {
174174 unsafe {
175175 adc. cfgr1 . write ( |w| {
176176 w. res ( ) . bits ( match self {
@@ -226,11 +226,11 @@ adc_pins!(
226226 gpioc:: PC5 <Analog > => 15_u8 ,
227227) ;
228228
229- #[ derive( Debug ) ]
229+ #[ derive( Debug , Default ) ]
230230/// Internal temperature sensor (ADC Channel 16)
231231pub struct VTemp ;
232232
233- #[ derive( Debug ) ]
233+ #[ derive( Debug , Default ) ]
234234/// Internal voltage reference (ADC Channel 17)
235235pub struct VRef ;
236236
@@ -244,7 +244,7 @@ adc_pins!(
244244impl VTemp {
245245 /// Init a new VTemp
246246 pub fn new ( ) -> Self {
247- VTemp { }
247+ VTemp :: default ( )
248248 }
249249
250250 /// Enable the internal temperature sense, this has a wake up time
@@ -270,8 +270,8 @@ impl VTemp {
270270 let vtemp30_cal = i32:: from ( unsafe { ptr:: read ( VTEMPCAL30 ) } ) * 100 ;
271271 let vtemp110_cal = i32:: from ( unsafe { ptr:: read ( VTEMPCAL110 ) } ) * 100 ;
272272
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;
275275 temperature *= ( 110 - 30 ) * 100 ;
276276 temperature /= vtemp110_cal - vtemp30_cal;
277277 temperature += 3000 ;
@@ -318,7 +318,7 @@ impl VTemp {
318318impl VRef {
319319 /// Init a new VRef
320320 pub fn new ( ) -> Self {
321- VRef { }
321+ VRef :: default ( )
322322 }
323323
324324 /// Enable the internal voltage reference, remember to disable when not in use.
@@ -356,12 +356,12 @@ impl VRef {
356356
357357 adc. restore_cfg ( prev_cfg) ;
358358
359- ( ( VDD_CALIB as u32 ) * vrefint_cal / vref_val) as u16
359+ ( u32 :: from ( VDD_CALIB ) * vrefint_cal / vref_val) as u16
360360 }
361361}
362362
363363#[ cfg( feature = "stm32f042" ) ]
364- #[ derive( Debug ) ]
364+ #[ derive( Debug , Default ) ]
365365/// Battery reference voltage (ADC Channel 18)
366366pub struct VBat ;
367367
@@ -374,7 +374,7 @@ adc_pins!(
374374impl VBat {
375375 /// Init a new VBat
376376 pub fn new ( ) -> Self {
377- VBat { }
377+ VBat :: default ( )
378378 }
379379
380380 /// Enable the internal VBat sense, remember to disable when not in use
@@ -483,7 +483,7 @@ impl Adc {
483483 match self . align {
484484 AdcAlign :: Left => u16:: max_value ( ) ,
485485 AdcAlign :: LeftAsRM => match self . precision {
486- AdcPrecision :: B_6 => u8:: max_value ( ) as u16 ,
486+ AdcPrecision :: B_6 => u16 :: from ( u8:: max_value ( ) ) ,
487487 _ => u16:: max_value ( ) ,
488488 } ,
489489 AdcAlign :: Right => match self . precision {
@@ -497,9 +497,9 @@ impl Adc {
497497
498498 /// Read the value of a channel and converts the result to milli-volts
499499 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 ) ) ;
501501 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 ( ) ) ;
503503
504504 ( v * vdda / max_samp) as u16
505505 }
0 commit comments