Skip to content

Commit 6177c01

Browse files
Merge pull request #5062 from 0xc0170/fix_interruptin_callback
InterruptIn: Use NULL callback by default
2 parents 323dc93 + d3cc003 commit 6177c01

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

drivers/InterruptIn.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,12 @@
1919

2020
namespace mbed {
2121

22-
static void donothing() {}
23-
2422
InterruptIn::InterruptIn(PinName pin) : gpio(),
2523
gpio_irq(),
26-
_rise(),
27-
_fall() {
24+
_rise(NULL),
25+
_fall(NULL) {
2826
// No lock needed in the constructor
2927

30-
_rise = donothing;
31-
_fall = donothing;
32-
3328
gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
3429
gpio_init_in(&gpio, pin);
3530
}
@@ -56,7 +51,7 @@ void InterruptIn::rise(Callback<void()> func) {
5651
_rise = func;
5752
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
5853
} else {
59-
_rise = donothing;
54+
_rise = NULL;
6055
gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
6156
}
6257
core_util_critical_section_exit();
@@ -68,7 +63,7 @@ void InterruptIn::fall(Callback<void()> func) {
6863
_fall = func;
6964
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
7065
} else {
71-
_fall = donothing;
66+
_fall = NULL;
7267
gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
7368
}
7469
core_util_critical_section_exit();
@@ -77,8 +72,16 @@ void InterruptIn::fall(Callback<void()> func) {
7772
void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) {
7873
InterruptIn *handler = (InterruptIn*)id;
7974
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;
8285
case IRQ_NONE: break;
8386
}
8487
}

0 commit comments

Comments
 (0)