Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions drivers/adc/adc_sam0.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ static int adc_sam0_channel_setup(const struct device *dev,
adc->SAMPCTRL.reg = sampctrl;
wait_synchronization(adc);


uint8_t refctrl;

switch (channel_cfg->reference) {
Expand All @@ -142,14 +141,14 @@ static int adc_sam0_channel_setup(const struct device *dev,
/* Enable the internal bandgap reference */
ADC_BGEN = 1;
break;
case ADC_REF_VDD_1_2:
refctrl = ADC_REFCTRL_REFSEL_VDD_1_2 | ADC_REFCTRL_REFCOMP;
break;
#ifdef ADC_REFCTRL_REFSEL_VDD_1
case ADC_REF_VDD_1:
refctrl = ADC_REFCTRL_REFSEL_VDD_1 | ADC_REFCTRL_REFCOMP;
break;
#endif
case ADC_REF_VDD_1_2:
refctrl = ADC_REFCTRL_REFSEL_VDD_1_2 | ADC_REFCTRL_REFCOMP;
break;
case ADC_REF_EXTERNAL0:
refctrl = ADC_REFCTRL_REFSEL_AREFA;
break;
Expand Down
27 changes: 20 additions & 7 deletions soc/arm/atmel_sam0/common/adc_fixup_sam0.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
#endif
#endif /* MCLK */

/*
* All SAM0 define the internal voltage reference as 1.0V by default.
*/
#ifndef ADC_REFCTRL_REFSEL_INTERNAL
# ifdef ADC_REFCTRL_REFSEL_INTREF
# define ADC_REFCTRL_REFSEL_INTERNAL ADC_REFCTRL_REFSEL_INTREF
Expand All @@ -114,18 +117,28 @@
# endif
#endif

/*
* Some SAM0 devices can use VDDANA as a direct reference. For the devices
* that not offer this option, the internal 1.0V reference will be used.
*/
#ifndef ADC_REFCTRL_REFSEL_VDD_1
# if defined(ADC0_BANDGAP)
# define ADC_REFCTRL_REFSEL_VDD_1 ADC_REFCTRL_REFSEL_INTVCC1
# elif defined(ADC_REFCTRL_REFSEL_INTVCC2)
# define ADC_REFCTRL_REFSEL_VDD_1 ADC_REFCTRL_REFSEL_INTVCC2
# endif
#endif

/*
* SAMD/E5x define ADC[0-1]_BANDGAP symbol. Only those devices use INTVCC0 to
* implement VDDANA / 2.
*/
#ifndef ADC_REFCTRL_REFSEL_VDD_1_2
# ifdef ADC_REFCTRL_REFSEL_INTVCC0
# ifdef ADC0_BANDGAP
# define ADC_REFCTRL_REFSEL_VDD_1_2 ADC_REFCTRL_REFSEL_INTVCC0
# else
# define ADC_REFCTRL_REFSEL_VDD_1_2 ADC_REFCTRL_REFSEL_INTVCC1
# endif
#endif

#ifndef ADC_REFCTRL_REFSEL_VDD_1
# ifdef ADC_REFCTRL_REFSEL_INTVCC1
# define ADC_REFCTRL_REFSEL_VDD_1 ADC_REFCTRL_REFSEL_INTVCC1
# endif
#endif

#endif /* _ATMEL_SAM0_ADC_FIXUP_H_ */