From 66dd5925cfffca8a2f21513359a2c9b37b4cf83e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 29 Dec 2019 19:08:56 +1100 Subject: [PATCH] HAL_ChibiOS: added support for alternative pin configs --- libraries/AP_HAL_ChibiOS/GPIO.cpp | 39 +++++ libraries/AP_HAL_ChibiOS/GPIO.h | 3 + .../hwdef/scripts/chibios_hwdef.py | 157 ++++++++++++++---- 3 files changed, 164 insertions(+), 35 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/GPIO.cpp b/libraries/AP_HAL_ChibiOS/GPIO.cpp index a9b927c942..ad6326dca3 100644 --- a/libraries/AP_HAL_ChibiOS/GPIO.cpp +++ b/libraries/AP_HAL_ChibiOS/GPIO.cpp @@ -67,7 +67,46 @@ void GPIO::init() g->enabled = g->pwm_num > pwm_count; } } +#ifdef HAL_PIN_ALT_CONFIG + setup_alt_config(); +#endif +} + +#ifdef HAL_PIN_ALT_CONFIG +/* + alternative config table, selected using BRD_ALT_CONFIG + */ +static const struct alt_config { + uint8_t alternate; + uint16_t mode; + ioline_t line; +} alternate_config[] HAL_PIN_ALT_CONFIG; + +/* + change pin configuration based on ALT() lines in hwdef.dat + */ +void GPIO::setup_alt_config(void) +{ + AP_BoardConfig *bc = AP::boardConfig(); + if (!bc) { + return; + } + const uint8_t alt = bc->get_alt_config(); + if (alt == 0) { + // use defaults + return; + } + for (uint8_t i=0; i