Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/stm32: Make ADC Resolution Definition uniform #20971

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions cpu/stm32/include/periph/c0/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ extern "C" {
*/
#define STM32_BOOTLOADER_ADDR (0x1FFF0000)

/**
* @brief Override ADC resolution values
* @{
*/
#define HAVE_ADC_RES_T
typedef enum {
ADC_RES_6BIT = (ADC_CFGR1_RES), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (ADC_CFGR1_RES_1), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (ADC_CFGR1_RES_0), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */
} adc_res_t;
/** @} */

/**
* @name Constants for internal VBAT ADC line
* @{
Expand Down
12 changes: 6 additions & 6 deletions cpu/stm32/include/periph/f0/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ extern "C" {
*/
#define HAVE_ADC_RES_T
typedef enum {
ADC_RES_6BIT = (0x3 << 3), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (0x2 << 3), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (0x1 << 3), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x0 << 3), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0xfe), /**< not applicable */
ADC_RES_16BIT = (0xff) /**< not applicable */
ADC_RES_6BIT = (ADC_CFGR1_RES), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (ADC_CFGR1_RES_1), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (ADC_CFGR1_RES_0), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */
} adc_res_t;
/** @} */

Expand Down
12 changes: 6 additions & 6 deletions cpu/stm32/include/periph/f2/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ extern "C" {
*/
#define HAVE_ADC_RES_T
typedef enum {
ADC_RES_6BIT = 0x03000000, /**< ADC resolution: 6 bit */
ADC_RES_8BIT = 0x02000000, /**< ADC resolution: 8 bit */
ADC_RES_10BIT = 0x01000000, /**< ADC resolution: 10 bit */
ADC_RES_12BIT = 0x00000000, /**< ADC resolution: 12 bit */
ADC_RES_14BIT = 1, /**< ADC resolution: 14 bit (not supported) */
ADC_RES_16BIT = 2 /**< ADC resolution: 16 bit (not supported)*/
ADC_RES_6BIT = (ADC_CR1_RES), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (ADC_CR1_RES_1), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (ADC_CR1_RES_0), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported)*/
} adc_res_t;
/** @} */

Expand Down
12 changes: 6 additions & 6 deletions cpu/stm32/include/periph/f3/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ extern "C" {
*/
#define HAVE_ADC_RES_T
typedef enum {
ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (ADC_CFGR_RES_1), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (ADC_CFGR_RES_0), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x0), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0x1), /**< not applicable */
ADC_RES_16BIT = (0x2) /**< not applicable */
ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (ADC_CFGR_RES_1), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (ADC_CFGR_RES_0), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */
} adc_res_t;
/** @} */

Expand Down
14 changes: 7 additions & 7 deletions cpu/stm32/include/periph/f4/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ extern "C" {
#define GET_RDP(x) ((x & 0xFF00) >> 8)

/**
* @brief Override the ADC resolution configuration
* @brief Override ADC resolution values
* @{
*/
#define HAVE_ADC_RES_T
typedef enum {
ADC_RES_6BIT = 0x03000000, /**< ADC resolution: 6 bit */
ADC_RES_8BIT = 0x02000000, /**< ADC resolution: 8 bit */
ADC_RES_10BIT = 0x01000000, /**< ADC resolution: 10 bit */
ADC_RES_12BIT = 0x00000000, /**< ADC resolution: 12 bit */
ADC_RES_14BIT = 1, /**< ADC resolution: 14 bit (not supported) */
ADC_RES_16BIT = 2 /**< ADC resolution: 16 bit (not supported)*/
ADC_RES_6BIT = (ADC_CR1_RES), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (ADC_CR1_RES_1), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (ADC_CR1_RES_0), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */
} adc_res_t;
/** @} */

Expand Down
14 changes: 7 additions & 7 deletions cpu/stm32/include/periph/f7/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ extern "C" {
#define ADC_DEVS (3U)

/**
* @brief Override the ADC resolution configuration
* @brief Override ADC resolution values
* @{
*/
#define HAVE_ADC_RES_T
typedef enum {
ADC_RES_6BIT = 0x03000000, /**< ADC resolution: 6 bit */
ADC_RES_8BIT = 0x02000000, /**< ADC resolution: 8 bit */
ADC_RES_10BIT = 0x01000000, /**< ADC resolution: 10 bit */
ADC_RES_12BIT = 0x00000000, /**< ADC resolution: 12 bit */
ADC_RES_14BIT = 1, /**< ADC resolution: 14 bit (not supported) */
ADC_RES_16BIT = 2 /**< ADC resolution: 16 bit (not supported)*/
ADC_RES_6BIT = (ADC_CR1_RES), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (ADC_CR1_RES_1), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (ADC_CR1_RES_0), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */
} adc_res_t;
/** @} */

Expand Down
15 changes: 15 additions & 0 deletions cpu/stm32/include/periph/g0/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ extern "C" {
*/
#define STM32_BOOTLOADER_ADDR (0x1FFF0000)

/**
* @brief Override ADC resolution values
* @{
*/
#define HAVE_ADC_RES_T
typedef enum {
ADC_RES_6BIT = (ADC_CFGR1_RES), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (ADC_CFGR1_RES_1), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (ADC_CFGR1_RES_0), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */
} adc_res_t;
/** @} */

/**
* @name Constants for internal VBAT ADC line
* @{
Expand Down
12 changes: 6 additions & 6 deletions cpu/stm32/include/periph/l0/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ extern "C" {
*/
#define HAVE_ADC_RES_T
typedef enum {
ADC_RES_6BIT = (0x3 << 3), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (0x2 << 3), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (0x1 << 3), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x0 << 3), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0xfe), /**< not applicable */
ADC_RES_16BIT = (0xff) /**< not applicable */
ADC_RES_6BIT = (ADC_CFGR1_RES), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (ADC_CFGR1_RES_1), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (ADC_CFGR1_RES_0), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported)*/
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported)*/
} adc_res_t;
/** @} */
#endif /* ndef DOXYGEN */
Expand Down
12 changes: 6 additions & 6 deletions cpu/stm32/include/periph/l1/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ extern "C" {
*/
#define HAVE_ADC_RES_T
typedef enum {
ADC_RES_6BIT = (ADC_CR1_RES_0 | ADC_CR1_RES_1), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (ADC_CR1_RES_1), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (ADC_CR1_RES_0), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0xfe), /**< not applicable */
ADC_RES_16BIT = (0xff) /**< not applicable */
ADC_RES_6BIT = (ADC_CR1_RES), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (ADC_CR1_RES_1), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (ADC_CR1_RES_0), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported)*/
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported)*/
} adc_res_t;
/** @} */
#endif /* ndef DOXYGEN */
Expand Down
12 changes: 6 additions & 6 deletions cpu/stm32/include/periph/l4/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ extern "C" {
*/
#define HAVE_ADC_RES_T
typedef enum {
ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (ADC_CFGR_RES_1), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (ADC_CFGR_RES_0), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x0), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0x1), /**< not applicable */
ADC_RES_16BIT = (0x2) /**< not applicable */
ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (ADC_CFGR_RES_1), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (ADC_CFGR_RES_0), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */
} adc_res_t;
/** @} */

Expand Down
12 changes: 6 additions & 6 deletions cpu/stm32/include/periph/wb/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ extern "C" {
*/
#define HAVE_ADC_RES_T
typedef enum {
ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (ADC_CFGR_RES_1), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (ADC_CFGR_RES_0), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x0), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0x1), /**< not applicable */
ADC_RES_16BIT = (0x2) /**< not applicable */
ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (ADC_CFGR_RES_1), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (ADC_CFGR_RES_0), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */
} adc_res_t;
/** @} */

Expand Down
12 changes: 6 additions & 6 deletions cpu/stm32/include/periph/wl/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ extern "C" {
*/
#define HAVE_ADC_RES_T
typedef enum {
ADC_RES_6BIT = (ADC_CFGR1_RES), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (ADC_CFGR1_RES_1), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (ADC_CFGR1_RES_0), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x0), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0x1), /**< not applicable */
ADC_RES_16BIT = (0x2) /**< not applicable */
ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */
ADC_RES_8BIT = (ADC_CFGR_RES_1), /**< ADC resolution: 8 bit */
ADC_RES_10BIT = (ADC_CFGR_RES_0), /**< ADC resolution: 10 bit */
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */
} adc_res_t;
/** @} */

Expand Down
2 changes: 1 addition & 1 deletion cpu/stm32/periph/adc_f0_g0_c0.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int32_t adc_sample(adc_t line, adc_res_t res)
int sample;

/* check if resolution is applicable */
if (res > 0xf0) {
if ((res & ADC_CFGR_RES) != res) {
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion cpu/stm32/periph/adc_f2.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ int32_t adc_sample(adc_t line, adc_res_t res)
int sample;

/* check if resolution is applicable */
if (res < 0xff) {
if ((res & ADC_CR1_RES) != res) {
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion cpu/stm32/periph/adc_f3.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ int32_t adc_sample(adc_t line, adc_res_t res)
int sample;

/* Check if resolution is applicable */
if (res & 0x3) {
if ((res & ADC_CFGR_RES) != res) {
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion cpu/stm32/periph/adc_f4_f7.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ int32_t adc_sample(adc_t line, adc_res_t res)
int sample;

/* check if resolution is applicable */
if (res & 0xff) {
if ((res & ADC_CR1_RES) != res) {
return -1;
}

Expand Down
5 changes: 1 addition & 4 deletions cpu/stm32/periph/adc_l0.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
{
if ((ADC1->CR & ADC_CR_ADEN) != 0) {
ADC1->CR |= ADC_CR_ADDIS;
while(ADC1->CR & ADC_CR_ADEN) {} /* Wait for ADC disabled */

Check warning on line 49 in cpu/stm32/periph/adc_l0.c

View workflow job for this annotation

GitHub Actions / static-tests

keyword 'while' not followed by a single space
}

if ((ADC1->CR & ADC_CR_ADEN) == 0) {
/* Then, start a calibration */
ADC1->CR |= ADC_CR_ADCAL;
while(ADC1->CR & ADC_CR_ADCAL) {} /* Wait for the end of calibration */

Check warning on line 55 in cpu/stm32/periph/adc_l0.c

View workflow job for this annotation

GitHub Actions / static-tests

keyword 'while' not followed by a single space
}

/* Clear flag */
Expand All @@ -70,7 +70,7 @@
/* Disable ADC */
if ((ADC1->CR & ADC_CR_ADEN) != 0) {
ADC1->CR |= ADC_CR_ADDIS;
while(ADC1->CR & ADC_CR_ADEN) {} /* Wait for ADC disabled */

Check warning on line 73 in cpu/stm32/periph/adc_l0.c

View workflow job for this annotation

GitHub Actions / static-tests

keyword 'while' not followed by a single space
/* Disable Voltage regulator */
ADC1->CR = 0;
ADC1->ISR = 0;
Expand Down Expand Up @@ -118,10 +118,7 @@
int sample;

/* check if resolution is applicable */
if ( (res != ADC_RES_6BIT) &&
(res != ADC_RES_8BIT) &&
(res != ADC_RES_10BIT) &&
(res != ADC_RES_12BIT)) {
if ((res & ADC_CFGR1_RES) != res) {
return -1;
}

Expand Down
5 changes: 1 addition & 4 deletions cpu/stm32/periph/adc_l1.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@

/* configure the pin */
if ((adc_config[line].pin != GPIO_UNDEF))
gpio_init_analog(adc_config[line].pin);

Check warning on line 106 in cpu/stm32/periph/adc_l1.c

View workflow job for this annotation

GitHub Actions / static-tests

full block {} expected in the control structure

/* set ADC clock prescaler */
ADC->CCR &= ~ADC_CCR_ADCPRE;
Expand Down Expand Up @@ -147,10 +147,7 @@
int sample;

/* check if resolution is applicable */
if ( (res != ADC_RES_6BIT) &&
(res != ADC_RES_8BIT) &&
(res != ADC_RES_10BIT) &&
(res != ADC_RES_12BIT)) {
if ((res & ADC_CR1_RES) != res) {
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion cpu/stm32/periph/adc_l4_wb.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ int32_t adc_sample(adc_t line, adc_res_t res)
int sample;

/* check if resolution is applicable */
if (res & 0x3) {
if ((res & ADC_CFGR_RES) != res) {
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion cpu/stm32/periph/adc_wl.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int32_t adc_sample(adc_t line, adc_res_t res)
int sample;

/* check if resolution is applicable */
if (res & 0x3) {
if ((res & ADC_CFGR_RES) != res) {
return -1;
}

Expand Down
Loading