Skip to content

Commit 801f27e

Browse files
authored
Merge pull request #6239 from bmcdonnell-ionx/interrupt-in-pin-mode
Interrupt in pin mode
2 parents 6dc0c9d + 8d2214f commit 801f27e

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

drivers/InterruptIn.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,33 @@
1919

2020
namespace mbed {
2121

22+
// Note: This single-parameter constructor exists to maintain binary
23+
// compatibility.
24+
// If not for that, we could simplify by having only the 2-param
25+
// constructor, with a default value for the PinMode.
2226
InterruptIn::InterruptIn(PinName pin) : gpio(),
2327
gpio_irq(),
2428
_rise(NULL),
2529
_fall(NULL) {
2630
// No lock needed in the constructor
27-
28-
gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
31+
irq_init(pin);
2932
gpio_init_in(&gpio, pin);
3033
}
3134

35+
InterruptIn::InterruptIn(PinName pin, PinMode mode) :
36+
gpio(),
37+
gpio_irq(),
38+
_rise(NULL),
39+
_fall(NULL) {
40+
// No lock needed in the constructor
41+
irq_init(pin);
42+
gpio_init_in_ex(&gpio, pin, mode);
43+
}
44+
45+
void InterruptIn::irq_init(PinName pin) {
46+
gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
47+
}
48+
3249
InterruptIn::~InterruptIn() {
3350
// No lock needed in the destructor
3451
gpio_irq_free(&gpio_irq);

drivers/InterruptIn.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ class InterruptIn : private NonCopyable<InterruptIn> {
6666
* @param pin InterruptIn pin to connect to
6767
*/
6868
InterruptIn(PinName pin);
69+
70+
/** Create an InterruptIn connected to the specified pin,
71+
* and the pin configured to the specified mode.
72+
*
73+
* @param pin InterruptIn pin to connect to
74+
* @param mode The mode to set the pin to (PullUp/PullDown/etc.)
75+
*/
76+
InterruptIn(PinName pin, PinMode mode);
77+
6978
virtual ~InterruptIn();
7079

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

154163
Callback<void()> _rise;
155164
Callback<void()> _fall;
165+
166+
void irq_init(PinName pin);
156167
};
157168

158169
} // namespace mbed

0 commit comments

Comments
 (0)