AP_HAL: GPIO: PWMSource: add destructor to detach interurupt

This commit is contained in:
Iampete1 2023-02-20 22:36:47 +00:00 committed by Andrew Tridgell
parent 54a9239e62
commit 36498cb4a0
2 changed files with 12 additions and 0 deletions

View File

@ -6,6 +6,15 @@
extern const AP_HAL::HAL& hal; 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) bool AP_HAL::PWMSource::set_pin(int16_t new_pin, const char *subsystem)
{ {
if (new_pin == _pin) { if (new_pin == _pin) {

View File

@ -19,6 +19,9 @@ public:
class AP_HAL::PWMSource { class AP_HAL::PWMSource {
public: public:
// Destructor detaches interrupt
~PWMSource();
bool set_pin(int16_t new_pin, const char *subsystem); bool set_pin(int16_t new_pin, const char *subsystem);
int16_t pin() const { return _pin; } // returns pin this is attached to int16_t pin() const { return _pin; } // returns pin this is attached to