diff --git a/libraries/AP_HAL_ChibiOS/GPIO.cpp b/libraries/AP_HAL_ChibiOS/GPIO.cpp index 15812c9b33fbdb..d2218a21ab2a81 100644 --- a/libraries/AP_HAL_ChibiOS/GPIO.cpp +++ b/libraries/AP_HAL_ChibiOS/GPIO.cpp @@ -241,17 +241,16 @@ uint8_t GPIO::read(uint8_t pin) if (g) { return palReadLine(g->pal_line); } +#if HAL_WITH_IO_MCU + if (AP_BoardConfig::io_enabled() && iomcu.valid_GPIO_pin(pin)) { + return iomcu.read_virtual_GPIO(pin); + } +#endif return 0; } void GPIO::write(uint8_t pin, uint8_t value) { -#if HAL_WITH_IO_MCU - if (AP_BoardConfig::io_enabled() && iomcu.valid_GPIO_pin(pin)) { - iomcu.write_GPIO(pin, value); - return; - } -#endif struct gpio_entry *g = gpio_by_pin_num(pin); if (g) { if (g->is_input) { @@ -263,36 +262,42 @@ void GPIO::write(uint8_t pin, uint8_t value) } else { palSetLine(g->pal_line); } + return; + } +#if HAL_WITH_IO_MCU + if (AP_BoardConfig::io_enabled() && iomcu.valid_GPIO_pin(pin)) { + iomcu.write_GPIO(pin, value); } +#endif } void GPIO::toggle(uint8_t pin) { + struct gpio_entry *g = gpio_by_pin_num(pin); + if (g) { + palToggleLine(g->pal_line); + return; + } #if HAL_WITH_IO_MCU if (AP_BoardConfig::io_enabled() && iomcu.valid_GPIO_pin(pin)) { iomcu.toggle_GPIO(pin); - return; } #endif - struct gpio_entry *g = gpio_by_pin_num(pin); - if (g) { - palToggleLine(g->pal_line); - } } /* Alternative interface: */ AP_HAL::DigitalSource* GPIO::channel(uint16_t pin) { + struct gpio_entry *g = gpio_by_pin_num(pin); + if (g != nullptr) { + return NEW_NOTHROW DigitalSource(g->pal_line); + } #if HAL_WITH_IO_MCU if (AP_BoardConfig::io_enabled() && iomcu.valid_GPIO_pin(pin)) { return NEW_NOTHROW IOMCU_DigitalSource(pin); } #endif - struct gpio_entry *g = gpio_by_pin_num(pin); - if (!g) { - return nullptr; - } - return NEW_NOTHROW DigitalSource(g->pal_line); + return nullptr; } extern const AP_HAL::HAL& hal; @@ -526,12 +531,15 @@ bool GPIO::wait_pin(uint8_t pin, INTERRUPT_TRIGGER_TYPE mode, uint32_t timeout_u // check if a pin number is valid bool GPIO::valid_pin(uint8_t pin) const { + if (gpio_by_pin_num(pin) != nullptr) { + return true; + } #if HAL_WITH_IO_MCU if (AP_BoardConfig::io_enabled() && iomcu.valid_GPIO_pin(pin)) { return true; } #endif - return gpio_by_pin_num(pin) != nullptr; + return false; } // return servo channel associated with GPIO pin. Returns true on success and fills in servo_ch argument diff --git a/libraries/AP_HAL_ChibiOS/RCOutput.cpp b/libraries/AP_HAL_ChibiOS/RCOutput.cpp index 0fcc96e04c4c05..da2b34fa3621b8 100644 --- a/libraries/AP_HAL_ChibiOS/RCOutput.cpp +++ b/libraries/AP_HAL_ChibiOS/RCOutput.cpp @@ -1263,9 +1263,13 @@ bool RCOutput::get_output_mode_banner(char banner_msg[], uint8_t banner_msg_len) if (iomcu_enabled) { uint8_t iomcu_mask; const output_mode iomcu_mode = iomcu.get_output_mode(iomcu_mask); + const uint8_t gpio_mask = iomcu.get_GPIO_mask(); for (uint8_t i = 0; i < chan_offset; i++ ) { - if (iomcu_mask & 1U<