From bb0e4283f97d5cdd3bb6a5c1ece3ab5465ecf033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20B=C3=B8ndergaard?= Date: Sun, 16 Jan 2022 19:19:39 +0100 Subject: [PATCH 1/2] drivers: adc: adc_sam0: Allow all ADC channels to be used MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In struct adc_sequence the channels member is a bitset specifying which channels to cover by the scan. The sam0 driver only supports one channel to be scanned at a time, but the check made until now did not regard .channels as a bitset but a number and thus only accepting a value of 1 aka channel 0 With this fix it is now checked whether more bits are set Signed-off-by: Kim Bøndergaard --- drivers/adc/adc_sam0.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/adc/adc_sam0.c b/drivers/adc/adc_sam0.c index 014692d96b493..e664f2e50c0dc 100644 --- a/drivers/adc/adc_sam0.c +++ b/drivers/adc/adc_sam0.c @@ -392,7 +392,8 @@ 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)) { LOG_ERR("Channel scanning is not supported"); return -ENOTSUP; } From 989f680235238b1d980fc0c1659abc5d45729f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20B=C3=B8ndergaard?= Date: Sun, 16 Jan 2022 19:52:16 +0100 Subject: [PATCH 2/2] sample: drivers: adc: Honnor CONFIG_ADC_CONFIGURABLE_INPUTS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some adc drivers, like adc_sam0, doesn't look at channel_id when setting up the adc channel, but rely on the input_positive and input_negative members. With this change the sample project also supports e.g. samd21 based boards using other pins than AIN[0]. This is exemplified by adding arduino_zero overlay using AIN[10] Signed-off-by: Kim Bøndergaard --- samples/drivers/adc/boards/arduino_zero.overlay | 16 ++++++++++++++++ samples/drivers/adc/src/main.c | 9 ++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 samples/drivers/adc/boards/arduino_zero.overlay diff --git a/samples/drivers/adc/boards/arduino_zero.overlay b/samples/drivers/adc/boards/arduino_zero.overlay new file mode 100644 index 0000000000000..c3b7012755ea0 --- /dev/null +++ b/samples/drivers/adc/boards/arduino_zero.overlay @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2022 Kim Bøndergaard + */ + +/ { + zephyr,user { + /* J106.6 (A5) aka D21G18, pin PB02_AIN10 */ + io-channels = <&adc 10>; + }; +}; + +&adc { + status = "okay"; +}; diff --git a/samples/drivers/adc/src/main.c b/samples/drivers/adc/src/main.c index 338f892eed84a..76b554c793de8 100644 --- a/samples/drivers/adc/src/main.c +++ b/samples/drivers/adc/src/main.c @@ -49,7 +49,11 @@ struct adc_channel_cfg channel_cfg = { .acquisition_time = ADC_ACQUISITION_TIME, /* channel ID will be overwritten below */ .channel_id = 0, - .differential = 0 + .differential = 0, +#ifdef CONFIG_ADC_CONFIGURABLE_INPUTS + .input_negative = 0, + .input_positive = 0, +#endif }; struct adc_sequence sequence = { @@ -80,6 +84,9 @@ void main(void) channel_cfg.input_positive = SAADC_CH_PSELP_PSELP_AnalogInput0 + channel_ids[i]; #endif +#ifdef CONFIG_ADC_CONFIGURABLE_INPUTS + channel_cfg.input_positive = channel_ids[i]; +#endif adc_channel_setup(dev_adc, &channel_cfg);