Commit 66dceba5 authored by Patrick Günzel's avatar Patrick Günzel Committed by Benjamin Cabé
Browse files

driver: adjust res when oversampling

The SAM0 ADC has an internal register to divide the accumulated results
of oversampling the ADC by the amount of samples collected. This value
has to be set by the driver and was missing.

Signed-off-by: default avatarPatrick Günzel <patrick.guenzel@kinexon.com>
parent ba5971e7
Loading
Loading
Loading
Loading
+6 −2
Changes for drivers/adc/adc_sam0.c: 6 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -177,7 +177,6 @@ static int adc_sam0_channel_setup(const struct device *dev,
#endif
	}


	uint32_t inputctrl = 0;

	switch (channel_cfg->gain) {
@@ -255,7 +254,6 @@ static int adc_sam0_channel_setup(const struct device *dev,
		break;
	}


	return 0;
}

@@ -325,6 +323,12 @@ static int start_read(const struct device *dev,
	}

	adc->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM(sequence->oversampling);
	if (sequence->oversampling < 4) {
		adc->AVGCTRL.reg |= ADC_AVGCTRL_ADJRES(sequence->oversampling);
	} else {
		adc->AVGCTRL.reg |= ADC_AVGCTRL_ADJRES(4);
	}

	/* AVGCTRL is not synchronized */

#ifdef CONFIG_SOC_SERIES_SAMD20