@@ -270,8 +270,8 @@ adc_pins!(ADC4,
270270 gpiod:: PD12 <Analog > => 9 ,
271271 gpiod:: PD13 <Analog > => 10 ,
272272 gpiod:: PD14 <Analog > => 11 ,
273- gpiob :: PD8 <Analog > => 12 ,
274- gpiob :: PD9 <Analog > => 13 ,
273+ gpiod :: PD8 <Analog > => 12 ,
274+ gpiod :: PD9 <Analog > => 13 ,
275275) ;
276276
277277// Abstract implementation of ADC functionality
@@ -287,24 +287,30 @@ macro_rules! adc_hal {
287287 /// Init a new ADC
288288 ///
289289 /// Enables the clock, performs a calibration and enables the ADC
290+ ///
291+ /// # Panics
292+ /// If one of the following occurs:
293+ /// * the clocksetting is not well defined.
294+ /// * the clock was already enabled with a different setting
295+ ///
290296 pub fn $adcx(
291297 rb: $ADC,
292298 adc_common : & mut $ADC_COMMON,
293299 ahb: & mut AHB ,
294300 ckmode: CKMODE ,
295301 clocks: Clocks ,
296- ) -> Option < Self > {
302+ ) -> Self {
297303 let mut this_adc = Self {
298304 rb,
299305 clocks,
300306 ckmode,
301307 operation_mode: None ,
302308 } ;
303309 if !( this_adc. clocks_welldefined( clocks) ) {
304- return None ;
310+ panic! ( "Clock settings not well defined" ) ;
305311 }
306312 if !( this_adc. enable_clock( ahb, adc_common) ) {
307- return None ;
313+ panic! ( "Clock already enabled with a different setting" ) ;
308314 }
309315 this_adc. set_align( Align :: default ( ) ) ;
310316 this_adc. calibrate( ) ;
@@ -313,13 +319,19 @@ macro_rules! adc_hal {
313319 // bit is cleared by hardware
314320 this_adc. wait_adc_clk_cycles( 4 ) ;
315321 this_adc. enable( ) ;
316- Some ( this_adc)
322+
323+ this_adc
317324 }
318325
319326 /// Software can use CKMODE::SYNCDIV1 only if
320327 /// hclk and sysclk are the same. (see reference manual 15.3.3)
321328 fn clocks_welldefined( & self , clocks: Clocks ) -> bool {
322- !( self . ckmode == CKMODE :: SYNCDIV1 && !( clocks. hclk( ) . 0 == clocks. sysclk( ) . 0 ) )
329+ if ( self . ckmode == CKMODE :: SYNCDIV1 )
330+ {
331+ clocks. hclk( ) . 0 == clocks. sysclk( ) . 0
332+ } else {
333+ true
334+ }
323335 }
324336
325337 /// sets up adc in one shot mode for a single channel
0 commit comments