diff options
Diffstat (limited to 'stmhal/mphalport.c')
-rw-r--r-- | stmhal/mphalport.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/stmhal/mphalport.c b/stmhal/mphalport.c index 147a8682d2..3fd4395d60 100644 --- a/stmhal/mphalport.c +++ b/stmhal/mphalport.c @@ -118,3 +118,17 @@ void mp_hal_gpio_clock_enable(GPIO_TypeDef *gpio) { #endif } } + +bool mp_hal_gpio_set_af(const pin_obj_t *pin, GPIO_InitTypeDef *init, uint8_t fn, uint8_t unit) { + mp_hal_gpio_clock_enable(pin->gpio); + + const pin_af_obj_t *af = pin_find_af(pin, fn, unit); + if (af == NULL) { + return false; + } + init->Pin = pin->pin_mask; + init->Alternate = af->idx; + HAL_GPIO_Init(pin->gpio, init); + + return true; +} |