Restore single-param InterruptIn ctor, to maintain binary compatibility (for Wi-Fi drivers).

Revert "simplify InterruptIn - default parameter instead of multiple constructors"; add comment.

This reverts commit d28dbf6702.
pull/6239/head
Brendan McDonnell 2018-03-21 10:14:47 -04:00
parent 087b4281f6
commit 895e19ae0f
2 changed files with 27 additions and 4 deletions

View File

@ -19,16 +19,33 @@
namespace mbed { 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
irq_init(pin);
gpio_init_in(&gpio, pin);
}
InterruptIn::InterruptIn(PinName pin, PinMode mode) : InterruptIn::InterruptIn(PinName pin, PinMode mode) :
gpio(), gpio(),
gpio_irq(), gpio_irq(),
_rise(NULL), _rise(NULL),
_fall(NULL) { _fall(NULL) {
// No lock needed in the constructor // No lock needed in the constructor
gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this); irq_init(pin);
gpio_init_in_ex(&gpio, pin, mode); 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() { InterruptIn::~InterruptIn() {
// No lock needed in the destructor // No lock needed in the destructor
gpio_irq_free(&gpio_irq); gpio_irq_free(&gpio_irq);

View File

@ -61,14 +61,18 @@ class InterruptIn : private NonCopyable<InterruptIn> {
public: public:
/** Create an InterruptIn connected to the specified pin
*
* @param pin InterruptIn pin to connect to
*/
InterruptIn(PinName pin);
/** Create an InterruptIn connected to the specified pin, /** Create an InterruptIn connected to the specified pin,
* with the pin configured to the specified mode. * and the pin configured to the specified mode.
* *
* @param pin InterruptIn pin to connect to * @param pin InterruptIn pin to connect to
* @param mode The mode to set the pin to (PullUp/PullDown/etc.) * @param mode The mode to set the pin to (PullUp/PullDown/etc.)
*/ */
InterruptIn(PinName pin, PinMode mode = PullDefault); InterruptIn(PinName pin, PinMode mode);
virtual ~InterruptIn(); virtual ~InterruptIn();
/** Read the input, represented as 0 or 1 (int) /** Read the input, represented as 0 or 1 (int)
@ -156,6 +160,8 @@ protected:
Callback<void()> _rise; Callback<void()> _rise;
Callback<void()> _fall; Callback<void()> _fall;
void irq_init(PinName pin);
}; };
} // namespace mbed } // namespace mbed