drivers: adc: adc_sam0: Fix interpretation of channels

Previously this was expected to be equal to 1 at all times. This doesn't
play well with the sample or other users (e.g: adc_shell). Instead, we
should count the number of active channels in the bitfield, and ensure
that only one is identified.

Signed-off-by: Attie Grande <attie.grande@argentum-systems.co.uk>
This commit is contained in:
Attie Grande 2021-12-17 13:35:26 +00:00 committed by Carles Cufí
commit d45a9a11b7

View file

@ -387,7 +387,15 @@ static int start_read(const struct device *dev,
wait_synchronization(adc);
if (sequence->channels != 1U) {
if ((sequence->channels == 0)
|| ((sequence->channels & (sequence->channels - 1)) != 0)) {
/* The caller is expected to identify a single input channel, which will
* typically be the positive input, though no check is made for this...
*
* While ensuring that the channels bitfield matches the positive input
* might be sensible, this will likely break users before this revision
* was put in place.
*/
LOG_ERR("Channel scanning is not supported");
return -ENOTSUP;
}