From 7d2e10335d31163b7ddb8ef33bb9425b16e0a73a Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Wed, 27 Nov 2019 21:00:06 +0100 Subject: [PATCH 1/2] sam0: remove duplicate `_done()` call --- cpu/sam0_common/periph/adc.c | 1 - 1 file changed, 1 deletion(-) diff --git a/cpu/sam0_common/periph/adc.c b/cpu/sam0_common/periph/adc.c index db97790480..74e7a7de22 100644 --- a/cpu/sam0_common/periph/adc.c +++ b/cpu/sam0_common/periph/adc.c @@ -87,7 +87,6 @@ static int _adc_configure(adc_res_t res) _adc_poweroff(); if (ADC->CTRLA.reg & ADC_CTRLA_SWRST || ADC->CTRLA.reg & ADC_CTRLA_ENABLE ) { - _done(); DEBUG("adc: not ready\n"); return -1; } From 83215befd97e3eadc1002c72fd31449fd04c4f2d Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Wed, 27 Nov 2019 21:01:32 +0100 Subject: [PATCH 2/2] sam0: change ADC periph to return -1 on wrong resolution The common ADC API dictates that a sample call must return -1 on an incorrect resolution. The sam0 ADC implementation instead threw an assertion failure. --- cpu/sam0_common/periph/adc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cpu/sam0_common/periph/adc.c b/cpu/sam0_common/periph/adc.c index 74e7a7de22..7760a2b935 100644 --- a/cpu/sam0_common/periph/adc.c +++ b/cpu/sam0_common/periph/adc.c @@ -82,8 +82,10 @@ static int _adc_configure(adc_res_t res) /* Individual comparison necessary because ADC Resolution Bits are not * numerically in order and 16Bit (averaging - not currently supported) * falls between 12bit and 10bit. See datasheet for details */ - assert((res == ADC_RES_8BIT) || (res == ADC_RES_10BIT) || - (res == ADC_RES_12BIT)); + if (!((res == ADC_RES_8BIT) || (res == ADC_RES_10BIT) || + (res == ADC_RES_12BIT))){ + return -1; + } _adc_poweroff(); if (ADC->CTRLA.reg & ADC_CTRLA_SWRST || ADC->CTRLA.reg & ADC_CTRLA_ENABLE ) {