diff --git a/libraries/AP_IOMCU/AP_IOMCU.cpp b/libraries/AP_IOMCU/AP_IOMCU.cpp index 96c1c04549..8107f737af 100644 --- a/libraries/AP_IOMCU/AP_IOMCU.cpp +++ b/libraries/AP_IOMCU/AP_IOMCU.cpp @@ -1360,6 +1360,12 @@ void AP_IOMCU::set_GPIO_mask(uint8_t mask) trigger_event(IOEVENT_GPIO); } +// Get GPIO mask of channels setup for output +uint8_t AP_IOMCU::get_GPIO_mask() const +{ + return GPIO.channel_mask; +} + // write to a output pin void AP_IOMCU::write_GPIO(uint8_t pin, bool value) { @@ -1377,6 +1383,17 @@ void AP_IOMCU::write_GPIO(uint8_t pin, bool value) trigger_event(IOEVENT_GPIO); } +// Read the last output value send to the GPIO pin +// This is not a real read of the actual pin +// This allows callers to check for state change +uint8_t AP_IOMCU::read_virtual_GPIO(uint8_t pin) const +{ + if (!convert_pin_number(pin)) { + return 0; + } + return (GPIO.output_mask & (1U << pin)) != 0; +} + // toggle a output pin void AP_IOMCU::toggle_GPIO(uint8_t pin) { diff --git a/libraries/AP_IOMCU/AP_IOMCU.h b/libraries/AP_IOMCU/AP_IOMCU.h index 5199c5fb3d..5092bf26fa 100644 --- a/libraries/AP_IOMCU/AP_IOMCU.h +++ b/libraries/AP_IOMCU/AP_IOMCU.h @@ -157,9 +157,17 @@ public: // set GPIO mask of channels setup for output void set_GPIO_mask(uint8_t mask); + // Get GPIO mask of channels setup for output + uint8_t get_GPIO_mask() const; + // write to a output pin void write_GPIO(uint8_t pin, bool value); + // Read the last output value send to the GPIO pin + // This is not a real read of the actual pin + // This allows callers to check for state change + uint8_t read_virtual_GPIO(uint8_t pin) const; + // toggle a output pin void toggle_GPIO(uint8_t pin);