Skip to content

Commit 35308c1

Browse files
overload InterruptIn constructor to allow PinMode control
1 parent 3d1174a commit 35308c1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

drivers/InterruptIn.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,20 @@ InterruptIn::InterruptIn(PinName pin) : gpio(),
2424
_rise(NULL),
2525
_fall(NULL) {
2626
// No lock needed in the constructor
27-
2827
gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
2928
gpio_init_in(&gpio, pin);
3029
}
3130

31+
InterruptIn::InterruptIn(PinName pin, PinMode mode) :
32+
gpio(),
33+
gpio_irq(),
34+
_rise(NULL),
35+
_fall(NULL) {
36+
// No lock needed in the constructor
37+
gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
38+
gpio_init_in_ex(&gpio, pin, mode);
39+
}
40+
3241
InterruptIn::~InterruptIn() {
3342
// No lock needed in the destructor
3443
gpio_irq_free(&gpio_irq);

drivers/InterruptIn.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ class InterruptIn : private NonCopyable<InterruptIn> {
6666
* @param pin InterruptIn pin to connect to
6767
*/
6868
InterruptIn(PinName pin);
69+
/** Create an InterruptIn connected to the specified pin,
70+
* and the pin configured to the specified mode.
71+
*
72+
* @param pin InterruptIn pin to connect to
73+
*/
74+
InterruptIn(PinName pin, PinMode mode);
6975
virtual ~InterruptIn();
7076

7177
/** Read the input, represented as 0 or 1 (int)

0 commit comments

Comments
 (0)