8
8
9
9
use panic_halt as _;
10
10
11
- use stm32f1xx_hal:: {
12
- prelude:: * ,
13
- pac
14
- } ;
11
+ use core:: mem:: MaybeUninit ;
15
12
use cortex_m_rt:: entry;
16
13
use pac:: interrupt;
17
- use core:: mem:: MaybeUninit ;
18
14
use stm32f1xx_hal:: gpio:: * ;
15
+ use stm32f1xx_hal:: { pac, prelude:: * } ;
19
16
20
17
// These two are owned by the ISR. main() may only access them during the initialization phase,
21
18
// where the interrupt is not yet enabled (i.e. no concurrent accesses can occur).
22
19
// After enabling the interrupt, main() may not have any references to these objects any more.
23
20
// 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 ( ) ;
26
25
27
26
#[ interrupt]
28
27
fn 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 ( ) } ;
31
30
32
31
if int_pin. check_interrupt ( ) {
33
32
led. toggle ( ) . unwrap ( ) ;
@@ -50,17 +49,19 @@ fn main() -> ! {
50
49
let mut gpioc = p. GPIOC . split ( & mut rcc. apb2 ) ;
51
50
let mut afio = p. AFIO . constrain ( & mut rcc. apb2 ) ;
52
51
53
- let led = unsafe { & mut * LED . as_mut_ptr ( ) } ;
52
+ let led = unsafe { & mut * LED . as_mut_ptr ( ) } ;
54
53
* led = gpioc. pc13 . into_push_pull_output ( & mut gpioc. crh ) ;
55
54
56
- let int_pin = unsafe { & mut * INT_PIN . as_mut_ptr ( ) } ;
55
+ let int_pin = unsafe { & mut * INT_PIN . as_mut_ptr ( ) } ;
57
56
* int_pin = gpioa. pa7 . into_floating_input ( & mut gpioa. crl ) ;
58
57
int_pin. make_interrupt_source ( & mut afio) ;
59
58
int_pin. trigger_on_edge ( & p. EXTI , Edge :: RISING_FALLING ) ;
60
59
int_pin. enable_interrupt ( & p. EXTI ) ;
61
60
} // initialization ends here
62
61
63
- unsafe { pac:: NVIC :: unmask ( pac:: Interrupt :: EXTI9_5 ) ; }
62
+ unsafe {
63
+ pac:: NVIC :: unmask ( pac:: Interrupt :: EXTI9_5 ) ;
64
+ }
64
65
65
66
loop { }
66
67
}
0 commit comments