drivers/adc: stm32: Update setup_channels() for G4 series

G4 series have specific LL ADC API that discriminate ADC1 and ADC5
channels. Take this into account in adc_stm32_setup_channels().

Additionally, fix this function to use LL defines as argument of macro
__LL_ADC_CHANNEL_TO_DECIMAL_NB, as good practice.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
This commit is contained in:
Erwan Gouriou 2022-03-16 11:00:53 +01:00 committed by Marti Bolivar
commit d66c1d9b54

View file

@ -804,14 +804,32 @@ static void adc_stm32_setup_speed(const struct device *dev, uint8_t id,
static void adc_stm32_setup_channels(const struct device *dev, uint8_t channel_id)
{
const struct adc_stm32_cfg *config = dev->config;
#ifdef CONFIG_SOC_SERIES_STM32G4X
ADC_TypeDef *adc = config->base;
if (config->has_temp_channel) {
#if DT_NODE_HAS_STATUS(DT_NODELABEL(adc1), okay)
if ((__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_CHANNEL_TEMPSENSOR_ADC1) == channel_id)
&& (adc == ADC1)) {
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_TEMPSENSOR);
}
#endif
#if DT_NODE_HAS_STATUS(DT_NODELABEL(adc5), okay)
if ((__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_CHANNEL_TEMPSENSOR_ADC5) == channel_id)
&& (adc == ADC5)) {
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_TEMPSENSOR);
}
#endif
}
#else
if (config->has_temp_channel &&
__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_TEMPSENSOR) == channel_id) {
__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_CHANNEL_TEMPSENSOR) == channel_id) {
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_TEMPSENSOR);
}
#endif /* CONFIG_SOC_SERIES_STM32G4X */
if (config->has_vref_channel &&
__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_VREFINT) == channel_id) {
__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_CHANNEL_VREFINT) == channel_id) {
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_VREFINT);
}
}