mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-18 02:53:52 +01:00
cpu/stm32: make ADC resolution uniform
This commit is contained in:
parent
4f676cd318
commit
1d3939d882
@ -31,6 +31,21 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
#define STM32_BOOTLOADER_ADDR (0x1FFF0000)
|
#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
|
* @name Constants for internal VBAT ADC line
|
||||||
* @{
|
* @{
|
||||||
|
|||||||
@ -53,12 +53,12 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
#define HAVE_ADC_RES_T
|
#define HAVE_ADC_RES_T
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ADC_RES_6BIT = (0x3 << 3), /**< ADC resolution: 6 bit */
|
ADC_RES_6BIT = (ADC_CFGR1_RES), /**< ADC resolution: 6 bit */
|
||||||
ADC_RES_8BIT = (0x2 << 3), /**< ADC resolution: 8 bit */
|
ADC_RES_8BIT = (ADC_CFGR1_RES_1), /**< ADC resolution: 8 bit */
|
||||||
ADC_RES_10BIT = (0x1 << 3), /**< ADC resolution: 10 bit */
|
ADC_RES_10BIT = (ADC_CFGR1_RES_0), /**< ADC resolution: 10 bit */
|
||||||
ADC_RES_12BIT = (0x0 << 3), /**< ADC resolution: 12 bit */
|
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
|
||||||
ADC_RES_14BIT = (0xfe), /**< not applicable */
|
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */
|
||||||
ADC_RES_16BIT = (0xff) /**< not applicable */
|
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */
|
||||||
} adc_res_t;
|
} adc_res_t;
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|||||||
@ -54,12 +54,12 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
#define HAVE_ADC_RES_T
|
#define HAVE_ADC_RES_T
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ADC_RES_6BIT = 0x03000000, /**< ADC resolution: 6 bit */
|
ADC_RES_6BIT = (ADC_CR1_RES), /**< ADC resolution: 6 bit */
|
||||||
ADC_RES_8BIT = 0x02000000, /**< ADC resolution: 8 bit */
|
ADC_RES_8BIT = (ADC_CR1_RES_1), /**< ADC resolution: 8 bit */
|
||||||
ADC_RES_10BIT = 0x01000000, /**< ADC resolution: 10 bit */
|
ADC_RES_10BIT = (ADC_CR1_RES_0), /**< ADC resolution: 10 bit */
|
||||||
ADC_RES_12BIT = 0x00000000, /**< ADC resolution: 12 bit */
|
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
|
||||||
ADC_RES_14BIT = 1, /**< ADC resolution: 14 bit (not supported) */
|
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */
|
||||||
ADC_RES_16BIT = 2 /**< ADC resolution: 16 bit (not supported)*/
|
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported)*/
|
||||||
} adc_res_t;
|
} adc_res_t;
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|||||||
@ -61,12 +61,12 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
#define HAVE_ADC_RES_T
|
#define HAVE_ADC_RES_T
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */
|
ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */
|
||||||
ADC_RES_8BIT = (ADC_CFGR_RES_1), /**< ADC resolution: 8 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_10BIT = (ADC_CFGR_RES_0), /**< ADC resolution: 10 bit */
|
||||||
ADC_RES_12BIT = (0x0), /**< ADC resolution: 12 bit */
|
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
|
||||||
ADC_RES_14BIT = (0x1), /**< not applicable */
|
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */
|
||||||
ADC_RES_16BIT = (0x2) /**< not applicable */
|
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */
|
||||||
} adc_res_t;
|
} adc_res_t;
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|||||||
@ -56,17 +56,17 @@ extern "C" {
|
|||||||
#define GET_RDP(x) ((x & 0xFF00) >> 8)
|
#define GET_RDP(x) ((x & 0xFF00) >> 8)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Override the ADC resolution configuration
|
* @brief Override ADC resolution values
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#define HAVE_ADC_RES_T
|
#define HAVE_ADC_RES_T
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ADC_RES_6BIT = 0x03000000, /**< ADC resolution: 6 bit */
|
ADC_RES_6BIT = (ADC_CR1_RES), /**< ADC resolution: 6 bit */
|
||||||
ADC_RES_8BIT = 0x02000000, /**< ADC resolution: 8 bit */
|
ADC_RES_8BIT = (ADC_CR1_RES_1), /**< ADC resolution: 8 bit */
|
||||||
ADC_RES_10BIT = 0x01000000, /**< ADC resolution: 10 bit */
|
ADC_RES_10BIT = (ADC_CR1_RES_0), /**< ADC resolution: 10 bit */
|
||||||
ADC_RES_12BIT = 0x00000000, /**< ADC resolution: 12 bit */
|
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
|
||||||
ADC_RES_14BIT = 1, /**< ADC resolution: 14 bit (not supported) */
|
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */
|
||||||
ADC_RES_16BIT = 2 /**< ADC resolution: 16 bit (not supported)*/
|
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */
|
||||||
} adc_res_t;
|
} adc_res_t;
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|||||||
@ -44,17 +44,17 @@ extern "C" {
|
|||||||
#define ADC_DEVS (3U)
|
#define ADC_DEVS (3U)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Override the ADC resolution configuration
|
* @brief Override ADC resolution values
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#define HAVE_ADC_RES_T
|
#define HAVE_ADC_RES_T
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ADC_RES_6BIT = 0x03000000, /**< ADC resolution: 6 bit */
|
ADC_RES_6BIT = (ADC_CR1_RES), /**< ADC resolution: 6 bit */
|
||||||
ADC_RES_8BIT = 0x02000000, /**< ADC resolution: 8 bit */
|
ADC_RES_8BIT = (ADC_CR1_RES_1), /**< ADC resolution: 8 bit */
|
||||||
ADC_RES_10BIT = 0x01000000, /**< ADC resolution: 10 bit */
|
ADC_RES_10BIT = (ADC_CR1_RES_0), /**< ADC resolution: 10 bit */
|
||||||
ADC_RES_12BIT = 0x00000000, /**< ADC resolution: 12 bit */
|
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
|
||||||
ADC_RES_14BIT = 1, /**< ADC resolution: 14 bit (not supported) */
|
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */
|
||||||
ADC_RES_16BIT = 2 /**< ADC resolution: 16 bit (not supported)*/
|
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */
|
||||||
} adc_res_t;
|
} adc_res_t;
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|||||||
@ -32,6 +32,21 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
#define STM32_BOOTLOADER_ADDR (0x1FFF0000)
|
#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
|
* @name Constants for internal VBAT ADC line
|
||||||
* @{
|
* @{
|
||||||
|
|||||||
@ -40,12 +40,12 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
#define HAVE_ADC_RES_T
|
#define HAVE_ADC_RES_T
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ADC_RES_6BIT = (0x3 << 3), /**< ADC resolution: 6 bit */
|
ADC_RES_6BIT = (ADC_CFGR1_RES), /**< ADC resolution: 6 bit */
|
||||||
ADC_RES_8BIT = (0x2 << 3), /**< ADC resolution: 8 bit */
|
ADC_RES_8BIT = (ADC_CFGR1_RES_1), /**< ADC resolution: 8 bit */
|
||||||
ADC_RES_10BIT = (0x1 << 3), /**< ADC resolution: 10 bit */
|
ADC_RES_10BIT = (ADC_CFGR1_RES_0), /**< ADC resolution: 10 bit */
|
||||||
ADC_RES_12BIT = (0x0 << 3), /**< ADC resolution: 12 bit */
|
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
|
||||||
ADC_RES_14BIT = (0xfe), /**< not applicable */
|
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported)*/
|
||||||
ADC_RES_16BIT = (0xff) /**< not applicable */
|
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported)*/
|
||||||
} adc_res_t;
|
} adc_res_t;
|
||||||
/** @} */
|
/** @} */
|
||||||
#endif /* ndef DOXYGEN */
|
#endif /* ndef DOXYGEN */
|
||||||
|
|||||||
@ -45,12 +45,12 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
#define HAVE_ADC_RES_T
|
#define HAVE_ADC_RES_T
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ADC_RES_6BIT = (ADC_CR1_RES_0 | ADC_CR1_RES_1), /**< ADC resolution: 6 bit */
|
ADC_RES_6BIT = (ADC_CR1_RES), /**< ADC resolution: 6 bit */
|
||||||
ADC_RES_8BIT = (ADC_CR1_RES_1), /**< ADC resolution: 8 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_10BIT = (ADC_CR1_RES_0), /**< ADC resolution: 10 bit */
|
||||||
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
|
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
|
||||||
ADC_RES_14BIT = (0xfe), /**< not applicable */
|
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported)*/
|
||||||
ADC_RES_16BIT = (0xff) /**< not applicable */
|
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported)*/
|
||||||
} adc_res_t;
|
} adc_res_t;
|
||||||
/** @} */
|
/** @} */
|
||||||
#endif /* ndef DOXYGEN */
|
#endif /* ndef DOXYGEN */
|
||||||
|
|||||||
@ -61,12 +61,12 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
#define HAVE_ADC_RES_T
|
#define HAVE_ADC_RES_T
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */
|
ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */
|
||||||
ADC_RES_8BIT = (ADC_CFGR_RES_1), /**< ADC resolution: 8 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_10BIT = (ADC_CFGR_RES_0), /**< ADC resolution: 10 bit */
|
||||||
ADC_RES_12BIT = (0x0), /**< ADC resolution: 12 bit */
|
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
|
||||||
ADC_RES_14BIT = (0x1), /**< not applicable */
|
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */
|
||||||
ADC_RES_16BIT = (0x2) /**< not applicable */
|
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */
|
||||||
} adc_res_t;
|
} adc_res_t;
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|||||||
@ -58,12 +58,12 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
#define HAVE_ADC_RES_T
|
#define HAVE_ADC_RES_T
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */
|
ADC_RES_6BIT = (ADC_CFGR_RES), /**< ADC resolution: 6 bit */
|
||||||
ADC_RES_8BIT = (ADC_CFGR_RES_1), /**< ADC resolution: 8 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_10BIT = (ADC_CFGR_RES_0), /**< ADC resolution: 10 bit */
|
||||||
ADC_RES_12BIT = (0x0), /**< ADC resolution: 12 bit */
|
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
|
||||||
ADC_RES_14BIT = (0x1), /**< not applicable */
|
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */
|
||||||
ADC_RES_16BIT = (0x2) /**< not applicable */
|
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */
|
||||||
} adc_res_t;
|
} adc_res_t;
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|||||||
@ -42,12 +42,12 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
#define HAVE_ADC_RES_T
|
#define HAVE_ADC_RES_T
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ADC_RES_6BIT = (ADC_CFGR1_RES), /**< ADC resolution: 6 bit */
|
ADC_RES_6BIT = (ADC_CFGR1_RES), /**< ADC resolution: 6 bit */
|
||||||
ADC_RES_8BIT = (ADC_CFGR1_RES_1), /**< ADC resolution: 8 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_10BIT = (ADC_CFGR1_RES_0), /**< ADC resolution: 10 bit */
|
||||||
ADC_RES_12BIT = (0x0), /**< ADC resolution: 12 bit */
|
ADC_RES_12BIT = (0x00), /**< ADC resolution: 12 bit */
|
||||||
ADC_RES_14BIT = (0x1), /**< not applicable */
|
ADC_RES_14BIT = (0xfe), /**< ADC resolution: 14 bit (not supported) */
|
||||||
ADC_RES_16BIT = (0x2) /**< not applicable */
|
ADC_RES_16BIT = (0xff) /**< ADC resolution: 16 bit (not supported) */
|
||||||
} adc_res_t;
|
} adc_res_t;
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|||||||
@ -201,7 +201,7 @@ int32_t adc_sample(adc_t line, adc_res_t res)
|
|||||||
int sample;
|
int sample;
|
||||||
|
|
||||||
/* check if resolution is applicable */
|
/* check if resolution is applicable */
|
||||||
if (res > 0xf0) {
|
if ((res & ADC_CFGR1_RES) != res) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -109,7 +109,7 @@ int32_t adc_sample(adc_t line, adc_res_t res)
|
|||||||
int sample;
|
int sample;
|
||||||
|
|
||||||
/* check if resolution is applicable */
|
/* check if resolution is applicable */
|
||||||
if (res < 0xff) {
|
if ((res & ADC_CR1_RES) != res) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -207,7 +207,7 @@ int32_t adc_sample(adc_t line, adc_res_t res)
|
|||||||
int sample;
|
int sample;
|
||||||
|
|
||||||
/* Check if resolution is applicable */
|
/* Check if resolution is applicable */
|
||||||
if (res & 0x3) {
|
if ((res & ADC_CFGR_RES) != res) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -129,7 +129,7 @@ int32_t adc_sample(adc_t line, adc_res_t res)
|
|||||||
int sample;
|
int sample;
|
||||||
|
|
||||||
/* check if resolution is applicable */
|
/* check if resolution is applicable */
|
||||||
if (res & 0xff) {
|
if ((res & ADC_CR1_RES) != res) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -118,10 +118,7 @@ int32_t adc_sample(adc_t line, adc_res_t res)
|
|||||||
int sample;
|
int sample;
|
||||||
|
|
||||||
/* check if resolution is applicable */
|
/* check if resolution is applicable */
|
||||||
if ( (res != ADC_RES_6BIT) &&
|
if ((res & ADC_CFGR1_RES) != res) {
|
||||||
(res != ADC_RES_8BIT) &&
|
|
||||||
(res != ADC_RES_10BIT) &&
|
|
||||||
(res != ADC_RES_12BIT)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -145,10 +145,7 @@ int32_t adc_sample(adc_t line, adc_res_t res)
|
|||||||
int sample;
|
int sample;
|
||||||
|
|
||||||
/* check if resolution is applicable */
|
/* check if resolution is applicable */
|
||||||
if ( (res != ADC_RES_6BIT) &&
|
if ((res & ADC_CR1_RES) != res) {
|
||||||
(res != ADC_RES_8BIT) &&
|
|
||||||
(res != ADC_RES_10BIT) &&
|
|
||||||
(res != ADC_RES_12BIT)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -221,7 +221,7 @@ int32_t adc_sample(adc_t line, adc_res_t res)
|
|||||||
int sample;
|
int sample;
|
||||||
|
|
||||||
/* check if resolution is applicable */
|
/* check if resolution is applicable */
|
||||||
if (res & 0x3) {
|
if ((res & ADC_CFGR_RES) != res) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -168,7 +168,7 @@ int32_t adc_sample(adc_t line, adc_res_t res)
|
|||||||
int sample;
|
int sample;
|
||||||
|
|
||||||
/* check if resolution is applicable */
|
/* check if resolution is applicable */
|
||||||
if (res & 0x3) {
|
if ((res & ADC_CFGR1_RES) != res) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user