From 36498cb4a0a01cf621671d6b9f7867abbeaf8fc8 Mon Sep 17 00:00:00 2001 From: Iampete1 Date: Mon, 20 Feb 2023 22:36:47 +0000 Subject: [PATCH] AP_HAL: GPIO: PWMSource: add destructor to detach interurupt --- libraries/AP_HAL/GPIO.cpp | 9 +++++++++ libraries/AP_HAL/GPIO.h | 3 +++ 2 files changed, 12 insertions(+) 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