From bbbc91f0a46caf65c5528039a4d4b7edd4dbb936 Mon Sep 17 00:00:00 2001 From: fuchsi <fuchsi@hemio.de> Date: Sun, 10 Nov 2019 22:22:38 +0100 Subject: [PATCH] fix(gpio): use ADC mode when both IN and ADC modes are set --- epicardium/modules/gpio.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/epicardium/modules/gpio.c b/epicardium/modules/gpio.c index a923812f..4af356ee 100644 --- a/epicardium/modules/gpio.c +++ b/epicardium/modules/gpio.c @@ -48,7 +48,16 @@ int epic_gpio_set_pin_mode(uint8_t pin, uint8_t mode) gpio_cfg_t *cfg = &gpio_configs[pin]; - if (mode & EPIC_GPIO_MODE_IN) { + if (mode & EPIC_GPIO_MODE_ADC) { + if (s_adc_channels[pin] == -1) { + LOG_WARN("gpio", "ADC not available on pin %d", pin); + return -EINVAL; + } + cfg->func = GPIO_FUNC_ALT1; + if (mode & EPIC_GPIO_MODE_OUT) { + return -EINVAL; + } + } else if (mode & EPIC_GPIO_MODE_IN) { cfg->func = GPIO_FUNC_IN; if (mode & EPIC_GPIO_MODE_OUT) { return -EINVAL; @@ -58,15 +67,6 @@ int epic_gpio_set_pin_mode(uint8_t pin, uint8_t mode) if (mode & EPIC_GPIO_MODE_IN) { return -EINVAL; } - } else if (mode & EPIC_GPIO_MODE_ADC) { - if (s_adc_channels[pin] == -1) { - LOG_WARN("gpio", "ADC not available on pin %d", pin); - return -EINVAL; - } - cfg->func = GPIO_FUNC_ALT1; - if (mode & EPIC_GPIO_MODE_OUT) { - return -EINVAL; - } } else { return -EINVAL; } -- GitLab