Skip to content

InterruptIn: Use NULL callback by default #5062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions drivers/InterruptIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@

namespace mbed {

static void donothing() {}

InterruptIn::InterruptIn(PinName pin) : gpio(),
gpio_irq(),
_rise(),
_fall() {
_rise(NULL),
_fall(NULL) {
// No lock needed in the constructor

_rise = donothing;
_fall = donothing;

gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
gpio_init_in(&gpio, pin);
}
Expand All @@ -56,7 +51,7 @@ void InterruptIn::rise(Callback<void()> func) {
_rise = func;
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
} else {
_rise = donothing;
_rise = NULL;
gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
}
core_util_critical_section_exit();
Expand All @@ -68,7 +63,7 @@ void InterruptIn::fall(Callback<void()> func) {
_fall = func;
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
} else {
_fall = donothing;
_fall = NULL;
gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
}
core_util_critical_section_exit();
Expand All @@ -77,8 +72,16 @@ void InterruptIn::fall(Callback<void()> func) {
void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) {
InterruptIn *handler = (InterruptIn*)id;
switch (event) {
case IRQ_RISE: handler->_rise(); break;
case IRQ_FALL: handler->_fall(); break;
case IRQ_RISE:
if (handler->_rise) {
handler->_rise();
}
break;
case IRQ_FALL:
if (handler->_fall) {
handler->_fall();
}
break;
case IRQ_NONE: break;
}
}
Expand Down