Skip to content

Commit d45a9a1

Browse files
attie-argentumcarlescufi
authored andcommitted
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 <[email protected]>
1 parent f86f6e0 commit d45a9a1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

drivers/adc/adc_sam0.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,15 @@ static int start_read(const struct device *dev,
387387

388388
wait_synchronization(adc);
389389

390-
if (sequence->channels != 1U) {
390+
if ((sequence->channels == 0)
391+
|| ((sequence->channels & (sequence->channels - 1)) != 0)) {
392+
/* The caller is expected to identify a single input channel, which will
393+
* typically be the positive input, though no check is made for this...
394+
*
395+
* While ensuring that the channels bitfield matches the positive input
396+
* might be sensible, this will likely break users before this revision
397+
* was put in place.
398+
*/
391399
LOG_ERR("Channel scanning is not supported");
392400
return -ENOTSUP;
393401
}

0 commit comments

Comments
 (0)