drivers/adc: stm32: Use bitfield for multiple channels detection

For multiple channels detection, channels variable was compared with
the output of find_lsb_set which actually is a decimal number.
Since channel is a bitfield the comparison was not behaving as
expected (detecting several channels while only one channel was used).

Rework the code to use the already existing bitfield "index" for
the test.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
This commit is contained in:
Erwan Gouriou 2021-01-29 13:45:11 +01:00 committed by Anas Nashif
commit 6a012301e6

View file

@ -319,15 +319,15 @@ static int start_read(const struct device *dev,
}
uint32_t channels = sequence->channels;
if (channels > find_lsb_set(channels)) {
uint8_t index = find_lsb_set(channels) - 1;
if (channels > BIT(index)) {
LOG_ERR("Only single channel supported");
return -ENOTSUP;
}
data->buffer = sequence->buffer;
uint8_t index;
index = find_lsb_set(channels) - 1;
uint32_t channel = __LL_ADC_DECIMAL_NB_TO_CHANNEL(index);
#if defined(CONFIG_SOC_SERIES_STM32H7X)
/*