19
19
20
20
namespace mbed {
21
21
22
- static void donothing () {}
23
-
24
22
InterruptIn::InterruptIn (PinName pin) : gpio(),
25
23
gpio_irq (),
26
- _rise(),
27
- _fall() {
24
+ _rise(NULL ),
25
+ _fall(NULL ) {
28
26
// No lock needed in the constructor
29
27
30
- _rise = donothing;
31
- _fall = donothing;
32
-
33
28
gpio_irq_init (&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t )this );
34
29
gpio_init_in (&gpio, pin);
35
30
}
@@ -56,7 +51,7 @@ void InterruptIn::rise(Callback<void()> func) {
56
51
_rise = func;
57
52
gpio_irq_set (&gpio_irq, IRQ_RISE, 1 );
58
53
} else {
59
- _rise = donothing ;
54
+ _rise = NULL ;
60
55
gpio_irq_set (&gpio_irq, IRQ_RISE, 0 );
61
56
}
62
57
core_util_critical_section_exit ();
@@ -68,7 +63,7 @@ void InterruptIn::fall(Callback<void()> func) {
68
63
_fall = func;
69
64
gpio_irq_set (&gpio_irq, IRQ_FALL, 1 );
70
65
} else {
71
- _fall = donothing ;
66
+ _fall = NULL ;
72
67
gpio_irq_set (&gpio_irq, IRQ_FALL, 0 );
73
68
}
74
69
core_util_critical_section_exit ();
@@ -77,8 +72,16 @@ void InterruptIn::fall(Callback<void()> func) {
77
72
void InterruptIn::_irq_handler (uint32_t id, gpio_irq_event event) {
78
73
InterruptIn *handler = (InterruptIn*)id;
79
74
switch (event) {
80
- case IRQ_RISE: handler->_rise (); break ;
81
- case IRQ_FALL: handler->_fall (); break ;
75
+ case IRQ_RISE:
76
+ if (handler->_rise ) {
77
+ handler->_rise ();
78
+ }
79
+ break ;
80
+ case IRQ_FALL:
81
+ if (handler->_fall ) {
82
+ handler->_fall ();
83
+ }
84
+ break ;
82
85
case IRQ_NONE: break ;
83
86
}
84
87
}
0 commit comments