88
99use panic_halt as _;
1010
11- use stm32f1xx_hal:: {
12- prelude:: * ,
13- pac
14- } ;
11+ use core:: mem:: MaybeUninit ;
1512use cortex_m_rt:: entry;
1613use pac:: interrupt;
17- use core:: mem:: MaybeUninit ;
1814use stm32f1xx_hal:: gpio:: * ;
15+ use stm32f1xx_hal:: { pac, prelude:: * } ;
1916
2017// These two are owned by the ISR. main() may only access them during the initialization phase,
2118// where the interrupt is not yet enabled (i.e. no concurrent accesses can occur).
2219// After enabling the interrupt, main() may not have any references to these objects any more.
2320// For the sake of minimalism, we do not use RTFM here, which would be the better way.
24- static mut LED : MaybeUninit < stm32f1xx_hal:: gpio:: gpioc:: PC13 < Output < PushPull > > > = MaybeUninit :: uninit ( ) ;
25- static mut INT_PIN : MaybeUninit < stm32f1xx_hal:: gpio:: gpioa:: PA7 < Input < Floating > > > = MaybeUninit :: uninit ( ) ;
21+ static mut LED : MaybeUninit < stm32f1xx_hal:: gpio:: gpioc:: PC13 < Output < PushPull > > > =
22+ MaybeUninit :: uninit ( ) ;
23+ static mut INT_PIN : MaybeUninit < stm32f1xx_hal:: gpio:: gpioa:: PA7 < Input < Floating > > > =
24+ MaybeUninit :: uninit ( ) ;
2625
2726#[ interrupt]
2827fn EXTI9_5 ( ) {
29- let led = unsafe { & mut * LED . as_mut_ptr ( ) } ;
30- let int_pin = unsafe { & mut * INT_PIN . as_mut_ptr ( ) } ;
28+ let led = unsafe { & mut * LED . as_mut_ptr ( ) } ;
29+ let int_pin = unsafe { & mut * INT_PIN . as_mut_ptr ( ) } ;
3130
3231 if int_pin. check_interrupt ( ) {
3332 led. toggle ( ) . unwrap ( ) ;
@@ -50,17 +49,19 @@ fn main() -> ! {
5049 let mut gpioc = p. GPIOC . split ( & mut rcc. apb2 ) ;
5150 let mut afio = p. AFIO . constrain ( & mut rcc. apb2 ) ;
5251
53- let led = unsafe { & mut * LED . as_mut_ptr ( ) } ;
52+ let led = unsafe { & mut * LED . as_mut_ptr ( ) } ;
5453 * led = gpioc. pc13 . into_push_pull_output ( & mut gpioc. crh ) ;
5554
56- let int_pin = unsafe { & mut * INT_PIN . as_mut_ptr ( ) } ;
55+ let int_pin = unsafe { & mut * INT_PIN . as_mut_ptr ( ) } ;
5756 * int_pin = gpioa. pa7 . into_floating_input ( & mut gpioa. crl ) ;
5857 int_pin. make_interrupt_source ( & mut afio) ;
5958 int_pin. trigger_on_edge ( & p. EXTI , Edge :: RISING_FALLING ) ;
6059 int_pin. enable_interrupt ( & p. EXTI ) ;
6160 } // initialization ends here
6261
63- unsafe { pac:: NVIC :: unmask ( pac:: Interrupt :: EXTI9_5 ) ; }
62+ unsafe {
63+ pac:: NVIC :: unmask ( pac:: Interrupt :: EXTI9_5 ) ;
64+ }
6465
6566 loop { }
6667}
0 commit comments