diff --git a/libraries/AP_HAL/GPIO.cpp b/libraries/AP_HAL/GPIO.cpp index 062a2c9a99..62e5ecec93 100644 --- a/libraries/AP_HAL/GPIO.cpp +++ b/libraries/AP_HAL/GPIO.cpp @@ -6,6 +6,15 @@ extern const AP_HAL::HAL& hal; +AP_HAL::PWMSource::~PWMSource() +{ + if (interrupt_attached) { + // Assume this is always successful + hal.gpio->detach_interrupt(_pin); + interrupt_attached = false; + } +} + bool AP_HAL::PWMSource::set_pin(int16_t new_pin, const char *subsystem) { if (new_pin == _pin) { diff --git a/libraries/AP_HAL/GPIO.h b/libraries/AP_HAL/GPIO.h index 5bbd446848..1e519e5b7c 100644 --- a/libraries/AP_HAL/GPIO.h +++ b/libraries/AP_HAL/GPIO.h @@ -19,6 +19,9 @@ public: class AP_HAL::PWMSource { public: + // Destructor detaches interrupt + ~PWMSource(); + bool set_pin(int16_t new_pin, const char *subsystem); int16_t pin() const { return _pin; } // returns pin this is attached to