diff --git a/libraries/AP_IOMCU/AP_IOMCU.cpp b/libraries/AP_IOMCU/AP_IOMCU.cpp index 786fbe6fde..25ea203058 100644 --- a/libraries/AP_IOMCU/AP_IOMCU.cpp +++ b/libraries/AP_IOMCU/AP_IOMCU.cpp @@ -1064,10 +1064,16 @@ void AP_IOMCU::check_iomcu_reset(void) last_rc_protocols = 0; } -// Check if pin number is valid for GPIO +// Check if pin number is valid and configured for GPIO bool AP_IOMCU::valid_GPIO_pin(uint8_t pin) const { - return convert_pin_number(pin); + // sanity check pin number + if (!convert_pin_number(pin)) { + return false; + } + + // check pin is enabled as GPIO + return ((GPIO.channel_mask & (1U << pin)) != 0); } // convert external pin numbers 101 to 108 to internal 0 to 7 diff --git a/libraries/AP_IOMCU/AP_IOMCU.h b/libraries/AP_IOMCU/AP_IOMCU.h index a4f0f962c2..81eeef0b78 100644 --- a/libraries/AP_IOMCU/AP_IOMCU.h +++ b/libraries/AP_IOMCU/AP_IOMCU.h @@ -107,7 +107,7 @@ public: bool setup_mixing(RCMapper *rcmap, int8_t override_chan, float mixing_gain, uint16_t manual_rc_mask); - // Check if pin number is valid for GPIO + // Check if pin number is valid and configured for GPIO bool valid_GPIO_pin(uint8_t pin) const; // convert external pin numbers 101 to 108 to internal 0 to 7