Merge pull request #6239 from bmcdonnell-ionx/interrupt-in-pin-mode

Interrupt in pin mode
pull/6442/head
Cruz Monrreal 2018-03-23 12:00:36 -05:00 committed by GitHub
commit 801f27efcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 2 deletions

View File

@ -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);

View File

@ -66,6 +66,15 @@ public:
* @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)
@ -153,6 +162,8 @@ protected:
Callback<void()> _rise;
Callback<void()> _fall;
void irq_init(PinName pin);
};
} // namespace mbed