mirror of https://github.com/ARMmbed/mbed-os.git
InterruptIn: callback to NULL clean-up
As we can check if callback was attached, we use NULL assigment.pull/5062/head
parent
e0bc631a0a
commit
d3cc0038d3
|
@ -19,17 +19,12 @@
|
||||||
|
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
static void donothing() {}
|
|
||||||
|
|
||||||
InterruptIn::InterruptIn(PinName pin) : gpio(),
|
InterruptIn::InterruptIn(PinName pin) : gpio(),
|
||||||
gpio_irq(),
|
gpio_irq(),
|
||||||
_rise(),
|
_rise(NULL),
|
||||||
_fall() {
|
_fall(NULL) {
|
||||||
// No lock needed in the constructor
|
// No lock needed in the constructor
|
||||||
|
|
||||||
_rise = donothing;
|
|
||||||
_fall = donothing;
|
|
||||||
|
|
||||||
gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
|
gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
|
||||||
gpio_init_in(&gpio, pin);
|
gpio_init_in(&gpio, pin);
|
||||||
}
|
}
|
||||||
|
@ -56,7 +51,7 @@ void InterruptIn::rise(Callback<void()> func) {
|
||||||
_rise = func;
|
_rise = func;
|
||||||
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
|
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
|
||||||
} else {
|
} else {
|
||||||
_rise = donothing;
|
_rise = NULL;
|
||||||
gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
|
gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
|
||||||
}
|
}
|
||||||
core_util_critical_section_exit();
|
core_util_critical_section_exit();
|
||||||
|
@ -68,7 +63,7 @@ void InterruptIn::fall(Callback<void()> func) {
|
||||||
_fall = func;
|
_fall = func;
|
||||||
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
|
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
|
||||||
} else {
|
} else {
|
||||||
_fall = donothing;
|
_fall = NULL;
|
||||||
gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
|
gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
|
||||||
}
|
}
|
||||||
core_util_critical_section_exit();
|
core_util_critical_section_exit();
|
||||||
|
@ -77,8 +72,16 @@ void InterruptIn::fall(Callback<void()> func) {
|
||||||
void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) {
|
void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) {
|
||||||
InterruptIn *handler = (InterruptIn*)id;
|
InterruptIn *handler = (InterruptIn*)id;
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case IRQ_RISE: handler->_rise(); break;
|
case IRQ_RISE:
|
||||||
case IRQ_FALL: handler->_fall(); break;
|
if (handler->_rise) {
|
||||||
|
handler->_rise();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case IRQ_FALL:
|
||||||
|
if (handler->_fall) {
|
||||||
|
handler->_fall();
|
||||||
|
}
|
||||||
|
break;
|
||||||
case IRQ_NONE: break;
|
case IRQ_NONE: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue