Skip to content

Commit c53a1e8

Browse files
attie-argentumcarlescufi
authored andcommitted
samples: drivers: adc: Revise handling of configurable inputs
All drivers that require input_positive to be set should be given it. Some parts may require an offset, so abstract this away too. Signed-off-by: Attie Grande <[email protected]>
1 parent d45a9a1 commit c53a1e8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

samples/drivers/adc/src/main.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
#define ADC_REFERENCE ADC_REF_INTERNAL
3434
#define ADC_ACQUISITION_TIME ADC_ACQ_TIME_DEFAULT
3535

36+
#ifdef CONFIG_ADC_NRFX_SAADC
37+
#define ADC_INPUT_POS_OFFSET SAADC_CH_PSELP_PSELP_AnalogInput0
38+
#else
39+
#define ADC_INPUT_POS_OFFSET 0
40+
#endif
41+
3642
/* Get the numbers of up to two channels */
3743
static uint8_t channel_ids[ADC_NUM_CHANNELS] = {
3844
DT_IO_CHANNELS_INPUT_BY_IDX(DT_PATH(zephyr_user), 0),
@@ -76,9 +82,8 @@ void main(void)
7682
*/
7783
for (uint8_t i = 0; i < ADC_NUM_CHANNELS; i++) {
7884
channel_cfg.channel_id = channel_ids[i];
79-
#ifdef CONFIG_ADC_NRFX_SAADC
80-
channel_cfg.input_positive = SAADC_CH_PSELP_PSELP_AnalogInput0
81-
+ channel_ids[i];
85+
#ifdef CONFIG_ADC_CONFIGURABLE_INPUTS
86+
channel_cfg.input_positive = ADC_INPUT_POS_OFFSET + channel_ids[i];
8287
#endif
8388

8489
adc_channel_setup(dev_adc, &channel_cfg);

0 commit comments

Comments
 (0)