Skip to content

Commit 989f680

Browse files
committed
sample: drivers: adc: Honnor CONFIG_ADC_CONFIGURABLE_INPUTS
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 <[email protected]>
1 parent bb0e428 commit 989f680

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (c) 2022 Kim Bøndergaard <[email protected]>
5+
*/
6+
7+
/ {
8+
zephyr,user {
9+
/* J106.6 (A5) aka D21G18, pin PB02_AIN10 */
10+
io-channels = <&adc 10>;
11+
};
12+
};
13+
14+
&adc {
15+
status = "okay";
16+
};

samples/drivers/adc/src/main.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ struct adc_channel_cfg channel_cfg = {
4949
.acquisition_time = ADC_ACQUISITION_TIME,
5050
/* channel ID will be overwritten below */
5151
.channel_id = 0,
52-
.differential = 0
52+
.differential = 0,
53+
#ifdef CONFIG_ADC_CONFIGURABLE_INPUTS
54+
.input_negative = 0,
55+
.input_positive = 0,
56+
#endif
5357
};
5458

5559
struct adc_sequence sequence = {
@@ -80,6 +84,9 @@ void main(void)
8084
channel_cfg.input_positive = SAADC_CH_PSELP_PSELP_AnalogInput0
8185
+ channel_ids[i];
8286
#endif
87+
#ifdef CONFIG_ADC_CONFIGURABLE_INPUTS
88+
channel_cfg.input_positive = channel_ids[i];
89+
#endif
8390

8491
adc_channel_setup(dev_adc, &channel_cfg);
8592

0 commit comments

Comments
 (0)