@@ -11,15 +11,14 @@ use cortex_m::interrupt::Mutex;
11
11
use cortex_m:: peripheral:: NVIC ;
12
12
use cortex_m_rt:: entry;
13
13
use stm32l0xx_hal:: {
14
- exti:: TriggerEdge ,
14
+ exti:: { TriggerEdge , line :: { GpioLine , ExtiLine } } ,
15
15
gpio:: * ,
16
16
pac:: { self , interrupt, Interrupt , EXTI } ,
17
17
prelude:: * ,
18
18
rcc:: Config ,
19
19
syscfg:: SYSCFG ,
20
20
} ;
21
21
22
- static INT : Mutex < RefCell < Option < EXTI > > > = Mutex :: new ( RefCell :: new ( None ) ) ;
23
22
static LED : Mutex < RefCell < Option < gpiob:: PB6 < Output < PushPull > > > > > = Mutex :: new ( RefCell :: new ( None ) ) ;
24
23
25
24
#[ entry]
@@ -42,13 +41,13 @@ fn main() -> ! {
42
41
let mut syscfg = SYSCFG :: new ( dp. SYSCFG , & mut rcc) ;
43
42
44
43
// Configure the external interrupt on the falling edge for the pin 0.
45
- let exti = dp. EXTI ;
46
- exti. listen ( & mut syscfg, button. port ( ) , button. pin_number ( ) , TriggerEdge :: Falling ) ;
44
+ let line = GpioLine :: from_raw_line ( button. pin_number ( ) ) . unwrap ( ) ;
45
+ let mut exti = dp. EXTI ;
46
+ exti. listen_gpio ( & mut syscfg, button. port ( ) , line, TriggerEdge :: Falling ) ;
47
47
48
48
// Store the external interrupt and LED in mutex reffcells to make them
49
49
// available from the interrupt.
50
50
cortex_m:: interrupt:: free ( |cs| {
51
- * INT . borrow ( cs) . borrow_mut ( ) = Some ( exti) ;
52
51
* LED . borrow ( cs) . borrow_mut ( ) = Some ( led) ;
53
52
} ) ;
54
53
@@ -66,19 +65,17 @@ fn EXTI2_3() {
66
65
static mut STATE : bool = false ;
67
66
68
67
cortex_m:: interrupt:: free ( |cs| {
69
- if let Some ( ref mut exti) = INT . borrow ( cs) . borrow_mut ( ) . deref_mut ( ) {
70
- // Clear the interrupt flag.
71
- exti. clear_irq ( 2 ) ;
72
-
73
- // Change the LED state on each interrupt.
74
- if let Some ( ref mut led) = LED . borrow ( cs) . borrow_mut ( ) . deref_mut ( ) {
75
- if * STATE {
76
- led. set_low ( ) . unwrap ( ) ;
77
- * STATE = false ;
78
- } else {
79
- led. set_high ( ) . unwrap ( ) ;
80
- * STATE = true ;
81
- }
68
+ // Clear the interrupt flag.
69
+ EXTI :: unpend ( GpioLine :: from_raw_line ( 2 ) . unwrap ( ) ) ;
70
+
71
+ // Change the LED state on each interrupt.
72
+ if let Some ( ref mut led) = LED . borrow ( cs) . borrow_mut ( ) . deref_mut ( ) {
73
+ if * STATE {
74
+ led. set_low ( ) . unwrap ( ) ;
75
+ * STATE = false ;
76
+ } else {
77
+ led. set_high ( ) . unwrap ( ) ;
78
+ * STATE = true ;
82
79
}
83
80
}
84
81
} ) ;
0 commit comments