From d302d3c90a208d988e611cc6f4a56d03b6223b28 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 20 Jul 2021 14:19:40 +1000 Subject: [PATCH] HAL_ChibiOS: implement valid_pin() --- libraries/AP_HAL_ChibiOS/GPIO.cpp | 6 ++++++ libraries/AP_HAL_ChibiOS/GPIO.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/libraries/AP_HAL_ChibiOS/GPIO.cpp b/libraries/AP_HAL_ChibiOS/GPIO.cpp index 7481b8f2e8..39be31eb3b 100644 --- a/libraries/AP_HAL_ChibiOS/GPIO.cpp +++ b/libraries/AP_HAL_ChibiOS/GPIO.cpp @@ -440,6 +440,12 @@ bool GPIO::wait_pin(uint8_t pin, INTERRUPT_TRIGGER_TYPE mode, uint32_t timeout_u return msg == MSG_OK; } +// check if a pin number is valid +bool GPIO::valid_pin(uint8_t pin) const +{ + return gpio_by_pin_num(pin) != nullptr; +} + #ifndef IOMCU_FW /* timer to setup interrupt quotas for a 100ms period from diff --git a/libraries/AP_HAL_ChibiOS/GPIO.h b/libraries/AP_HAL_ChibiOS/GPIO.h index a198bdd75a..1b9949ee8a 100644 --- a/libraries/AP_HAL_ChibiOS/GPIO.h +++ b/libraries/AP_HAL_ChibiOS/GPIO.h @@ -78,6 +78,9 @@ public: void timer_tick(void) override; #endif + // check if a pin number is valid + bool valid_pin(uint8_t pin) const override; + /* resolve an ioline to take account of alternative configurations */