Skip to content

Interrupt in pin mode #6239

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 7 commits into from
Mar 23, 2018
Merged
Show file tree
Hide file tree
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
21 changes: 19 additions & 2 deletions drivers/InterruptIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,33 @@

namespace mbed {

// Note: This single-parameter constructor exists to maintain binary
// compatibility.
// If not for that, we could simplify by having only the 2-param
// constructor, with a default value for the PinMode.
InterruptIn::InterruptIn(PinName pin) : gpio(),
gpio_irq(),
_rise(NULL),
_fall(NULL) {
// No lock needed in the constructor

gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
irq_init(pin);
gpio_init_in(&gpio, pin);
}

InterruptIn::InterruptIn(PinName pin, PinMode mode) :
gpio(),
gpio_irq(),
_rise(NULL),
_fall(NULL) {
// No lock needed in the constructor
irq_init(pin);
gpio_init_in_ex(&gpio, pin, mode);
}

void InterruptIn::irq_init(PinName pin) {
gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
}

InterruptIn::~InterruptIn() {
// No lock needed in the destructor
gpio_irq_free(&gpio_irq);
Expand Down
11 changes: 11 additions & 0 deletions drivers/InterruptIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ class InterruptIn : private NonCopyable<InterruptIn> {
* @param pin InterruptIn pin to connect to
*/
InterruptIn(PinName pin);

/** Create an InterruptIn connected to the specified pin,
* and the pin configured to the specified mode.
*
* @param pin InterruptIn pin to connect to
* @param mode The mode to set the pin to (PullUp/PullDown/etc.)
*/
InterruptIn(PinName pin, PinMode mode);

virtual ~InterruptIn();

/** Read the input, represented as 0 or 1 (int)
Expand Down Expand Up @@ -153,6 +162,8 @@ class InterruptIn : private NonCopyable<InterruptIn> {

Callback<void()> _rise;
Callback<void()> _fall;

void irq_init(PinName pin);
};

} // namespace mbed
Expand Down