From 9dcb3991d288ab4c6ba27f614ac0ed0f50d02b34 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 17 Jan 2023 15:42:29 +0100 Subject: [PATCH] cpu/sam0_common: move adc_res_t to common code --- cpu/sam0_common/include/periph_cpu_common.h | 18 ++++++++++++++++++ cpu/sam0_common/periph/adc.c | 6 ++---- cpu/samd21/include/periph_cpu.h | 12 ------------ cpu/samd5x/include/periph_cpu.h | 12 ------------ cpu/saml1x/include/periph_cpu.h | 12 ------------ cpu/saml21/include/periph_cpu.h | 12 ------------ 6 files changed, 20 insertions(+), 52 deletions(-) diff --git a/cpu/sam0_common/include/periph_cpu_common.h b/cpu/sam0_common/include/periph_cpu_common.h index 0828128101..ed97e365a1 100644 --- a/cpu/sam0_common/include/periph_cpu_common.h +++ b/cpu/sam0_common/include/periph_cpu_common.h @@ -807,6 +807,24 @@ typedef struct { #define ADC_REFSEL_AREFC_PIN GPIO_PIN(PA, 6) #endif +#ifndef DOXYGEN +#define HAVE_ADC_RES_T +typedef enum { + ADC_RES_6BIT = 0xff, /**< not supported */ +#if defined(ADC_CTRLB_RESSEL) + ADC_RES_8BIT = ADC_CTRLB_RESSEL_8BIT_Val, /**< ADC resolution: 8 bit */ + ADC_RES_10BIT = ADC_CTRLB_RESSEL_10BIT_Val, /**< ADC resolution: 10 bit */ + ADC_RES_12BIT = ADC_CTRLB_RESSEL_12BIT_Val, /**< ADC resolution: 12 bit */ +#elif defined(ADC_CTRLC_RESSEL) + ADC_RES_8BIT = ADC_CTRLC_RESSEL_8BIT_Val, /**< ADC resolution: 8 bit */ + ADC_RES_10BIT = ADC_CTRLC_RESSEL_10BIT_Val, /**< ADC resolution: 10 bit */ + ADC_RES_12BIT = ADC_CTRLC_RESSEL_12BIT_Val, /**< ADC resolution: 12 bit */ +#endif + ADC_RES_14BIT = 0xfe, /**< not supported */ + ADC_RES_16BIT = 0xfd /**< not supported */ +} adc_res_t; +#endif /* DOXYGEN */ + /** * @name Ethernet peripheral parameters * @{ diff --git a/cpu/sam0_common/periph/adc.c b/cpu/sam0_common/periph/adc.c index 81f3a03215..3c906842b0 100644 --- a/cpu/sam0_common/periph/adc.c +++ b/cpu/sam0_common/periph/adc.c @@ -203,12 +203,10 @@ static int _adc_configure(Adc *dev, adc_res_t res) /* Set ADC resolution */ #ifdef ADC_CTRLC_RESSEL /* Reset resolution bits in CTRLC */ - dev->CTRLC.reg &= ~ADC_CTRLC_RESSEL_Msk; - dev->CTRLC.reg |= res; + dev->CTRLC.bit.RESSEL = res; #else /* Reset resolution bits in CTRLB */ - dev->CTRLB.reg &= ~ADC_CTRLB_RESSEL_Msk; - dev->CTRLB.reg |= res; + dev->CTRLB.bit.RESSEL = res; #endif /* Set Voltage Reference */ diff --git a/cpu/samd21/include/periph_cpu.h b/cpu/samd21/include/periph_cpu.h index c66d0f389c..42260ccc8e 100644 --- a/cpu/samd21/include/periph_cpu.h +++ b/cpu/samd21/include/periph_cpu.h @@ -99,18 +99,6 @@ static inline int _sercom_id(SercomUsart *sercom) return ((((uint32_t)sercom) >> 10) & 0x7) - 2; } -#ifndef DOXYGEN -#define HAVE_ADC_RES_T -typedef enum { - ADC_RES_6BIT = 0xff, /**< not supported */ - ADC_RES_8BIT = ADC_CTRLB_RESSEL_8BIT, /**< ADC resolution: 8 bit */ - ADC_RES_10BIT = ADC_CTRLB_RESSEL_10BIT, /**< ADC resolution: 10 bit */ - ADC_RES_12BIT = ADC_CTRLB_RESSEL_12BIT, /**< ADC resolution: 12 bit */ - ADC_RES_14BIT = 0xfe, /**< not supported */ - ADC_RES_16BIT = 0xfd /**< not supported */ -} adc_res_t; -#endif /* ndef DOXYGEN */ - /** * @brief Pins that can be used for ADC input */ diff --git a/cpu/samd5x/include/periph_cpu.h b/cpu/samd5x/include/periph_cpu.h index 3607eb0f46..e6ff957d00 100644 --- a/cpu/samd5x/include/periph_cpu.h +++ b/cpu/samd5x/include/periph_cpu.h @@ -83,18 +83,6 @@ enum { */ #define SPI_HWCS(x) (UINT_MAX - 1) -#ifndef DOXYGEN -#define HAVE_ADC_RES_T -typedef enum { - ADC_RES_6BIT = 0xff, /**< not supported */ - ADC_RES_8BIT = ADC_CTRLB_RESSEL_8BIT, /**< ADC resolution: 8 bit */ - ADC_RES_10BIT = ADC_CTRLB_RESSEL_10BIT, /**< ADC resolution: 10 bit */ - ADC_RES_12BIT = ADC_CTRLB_RESSEL_12BIT, /**< ADC resolution: 12 bit */ - ADC_RES_14BIT = 0xfe, /**< not supported */ - ADC_RES_16BIT = 0xfd /**< not supported */ -} adc_res_t; -#endif /* DOXYGEN */ - /** * @brief Pins that can be used for ADC input */ diff --git a/cpu/saml1x/include/periph_cpu.h b/cpu/saml1x/include/periph_cpu.h index ced0503b3a..81e8b10353 100644 --- a/cpu/saml1x/include/periph_cpu.h +++ b/cpu/saml1x/include/periph_cpu.h @@ -43,18 +43,6 @@ enum { }; /** @} */ -#ifndef DOXYGEN -#define HAVE_ADC_RES_T -typedef enum { - ADC_RES_6BIT = 0xff, /**< not supported */ - ADC_RES_8BIT = ADC_CTRLC_RESSEL_8BIT, /**< ADC resolution: 8 bit */ - ADC_RES_10BIT = ADC_CTRLC_RESSEL_10BIT, /**< ADC resolution: 10 bit */ - ADC_RES_12BIT = ADC_CTRLC_RESSEL_12BIT, /**< ADC resolution: 12 bit */ - ADC_RES_14BIT = 0xfe, /**< not supported */ - ADC_RES_16BIT = 0xfd /**< not supported */ -} adc_res_t; -#endif /* ndef DOXYGEN */ - /** * @brief Pins that can be used for ADC input */ diff --git a/cpu/saml21/include/periph_cpu.h b/cpu/saml21/include/periph_cpu.h index 22e6dbd503..6225d7ecd0 100644 --- a/cpu/saml21/include/periph_cpu.h +++ b/cpu/saml21/include/periph_cpu.h @@ -74,18 +74,6 @@ enum { }; /** @} */ -#ifndef DOXYGEN -#define HAVE_ADC_RES_T -typedef enum { - ADC_RES_6BIT = 0xff, /**< not supported */ - ADC_RES_8BIT = ADC_CTRLC_RESSEL_8BIT, /**< ADC resolution: 8 bit */ - ADC_RES_10BIT = ADC_CTRLC_RESSEL_10BIT, /**< ADC resolution: 10 bit */ - ADC_RES_12BIT = ADC_CTRLC_RESSEL_12BIT, /**< ADC resolution: 12 bit */ - ADC_RES_14BIT = 0xfe, /**< not supported */ - ADC_RES_16BIT = 0xfd /**< not supported */ -} adc_res_t; -#endif /* ndef DOXYGEN */ - /** * @brief Pins that can be used for ADC input */