Skip to content

Commit 5b7734c

Browse files
nandojvembolivar-nordic
authored andcommitted
drivers: adc: sam0: Fix adc_reference implementation
The current sam0 adc driver not implement correctly the adc_reference enum values. This try homonize adc input referece by tracking VDDANA at ADC_REF_VDD_1. The ADC_REF_VDD_1_2 were fixed with correct INTVCCx channel selection. Fixes #45443 Signed-off-by: Gerson Fernando Budke <[email protected]>
1 parent 9d5bd09 commit 5b7734c

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

drivers/adc/adc_sam0.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ static int adc_sam0_channel_setup(const struct device *dev,
133133
adc->SAMPCTRL.reg = sampctrl;
134134
wait_synchronization(adc);
135135

136-
137136
uint8_t refctrl;
138137

139138
switch (channel_cfg->reference) {
@@ -142,14 +141,14 @@ static int adc_sam0_channel_setup(const struct device *dev,
142141
/* Enable the internal bandgap reference */
143142
ADC_BGEN = 1;
144143
break;
145-
case ADC_REF_VDD_1_2:
146-
refctrl = ADC_REFCTRL_REFSEL_VDD_1_2 | ADC_REFCTRL_REFCOMP;
147-
break;
148144
#ifdef ADC_REFCTRL_REFSEL_VDD_1
149145
case ADC_REF_VDD_1:
150146
refctrl = ADC_REFCTRL_REFSEL_VDD_1 | ADC_REFCTRL_REFCOMP;
151147
break;
152148
#endif
149+
case ADC_REF_VDD_1_2:
150+
refctrl = ADC_REFCTRL_REFSEL_VDD_1_2 | ADC_REFCTRL_REFCOMP;
151+
break;
153152
case ADC_REF_EXTERNAL0:
154153
refctrl = ADC_REFCTRL_REFSEL_AREFA;
155154
break;

soc/arm/atmel_sam0/common/adc_fixup_sam0.h

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@
106106
#endif
107107
#endif /* MCLK */
108108

109+
/*
110+
* All SAM0 define the internal voltage reference as 1.0V by default.
111+
*/
109112
#ifndef ADC_REFCTRL_REFSEL_INTERNAL
110113
# ifdef ADC_REFCTRL_REFSEL_INTREF
111114
# define ADC_REFCTRL_REFSEL_INTERNAL ADC_REFCTRL_REFSEL_INTREF
@@ -114,18 +117,28 @@
114117
# endif
115118
#endif
116119

120+
/*
121+
* Some SAM0 devices can use VDDANA as a direct reference. For the devices
122+
* that not offer this option, the internal 1.0V reference will be used.
123+
*/
124+
#ifndef ADC_REFCTRL_REFSEL_VDD_1
125+
# if defined(ADC0_BANDGAP)
126+
# define ADC_REFCTRL_REFSEL_VDD_1 ADC_REFCTRL_REFSEL_INTVCC1
127+
# elif defined(ADC_REFCTRL_REFSEL_INTVCC2)
128+
# define ADC_REFCTRL_REFSEL_VDD_1 ADC_REFCTRL_REFSEL_INTVCC2
129+
# endif
130+
#endif
131+
132+
/*
133+
* SAMD/E5x define ADC[0-1]_BANDGAP symbol. Only those devices use INTVCC0 to
134+
* implement VDDANA / 2.
135+
*/
117136
#ifndef ADC_REFCTRL_REFSEL_VDD_1_2
118-
# ifdef ADC_REFCTRL_REFSEL_INTVCC0
137+
# ifdef ADC0_BANDGAP
119138
# define ADC_REFCTRL_REFSEL_VDD_1_2 ADC_REFCTRL_REFSEL_INTVCC0
120139
# else
121140
# define ADC_REFCTRL_REFSEL_VDD_1_2 ADC_REFCTRL_REFSEL_INTVCC1
122141
# endif
123142
#endif
124143

125-
#ifndef ADC_REFCTRL_REFSEL_VDD_1
126-
# ifdef ADC_REFCTRL_REFSEL_INTVCC1
127-
# define ADC_REFCTRL_REFSEL_VDD_1 ADC_REFCTRL_REFSEL_INTVCC1
128-
# endif
129-
#endif
130-
131144
#endif /* _ATMEL_SAM0_ADC_FIXUP_H_ */

0 commit comments

Comments
 (0)