33
44#include "wm_hal.h"
55
6- #ifdef __cplusplus
7- extern "C" {
8- #endif
9-
106typedef struct
117{
12- uint32_t channel ; /* ADC_CHANNEL_0 : channel 0
13- * ADC_CHANNEL_1 : channel 1
14- * ADC_CHANNEL_2 : channel 2
15- * ADC_CHANNEL_3 : channel 3
16- * ADC_CHANNEL_0_1 : channel 0 and channel 1 differential input
17- * ADC_CHANNEL_2_3 : channel 2 and channel 3 differential input */
18-
19- uint32_t freq ; /* 307hz ~ 2khz */
20-
21- uint32_t cmp_val ; /* compare value */
22-
23- uint32_t cmp_pol ; /* CMP_POL_0 : when adc_result >= cmp_val interrupt
24- * CMP_POL_1 : whrn adc_result < cmp_val interrtup */
25-
8+ uint32_t channel ; /* ADC_CHANNEL_0 ~ channel 0
9+ * ADC_CHANNEL_1 ~ channel 1
10+ * ADC_CHANNEL_2 ~ channel 2
11+ * ADC_CHANNEL_3 ~ channel 3
12+ * ADC_CHANNEL_0_1 : channel 0 and channel 1 differential input
13+ * ADC_CHANNEL_2_3 : channel 2 and channel 3 differential input */
14+
15+ uint32_t freq ; /* 307hz ~ 2khz */
16+
17+ uint32_t cmp_val ; /* compare value */
18+
19+ uint32_t cmp_pol ; /* CMP_POL_0 : when adc_result >= cmp_val interrupt
20+ * CMP_POL_1 : whrn adc_result < cmp_val interrtup */
21+
2622}ADC_InitTypeDef ;
2723
2824typedef struct __ADC_HandleTypeDef
2925{
30- ADC_TypeDef * Instance ;
31-
32- ADC_InitTypeDef Init ;
33-
34- HAL_LockTypeDef Lock ;
35-
36- int offset ;
37-
26+ ADC_TypeDef * Instance ;
27+ ADC_InitTypeDef Init ;
28+ HAL_LockTypeDef Lock ;
29+ int offset ;
30+
3831}ADC_HandleTypeDef ;
3932
4033
4134#define ADC ((ADC_TypeDef *)ADC_BASE)
4235
43- #define ADC_CHANNEL_0 ADC_ANA_CR_CH_0
44- #define ADC_CHANNEL_1 ADC_ANA_CR_CH_1
45- #define ADC_CHANNEL_2 ADC_ANA_CR_CH_2
46- #define ADC_CHANNEL_3 ADC_ANA_CR_CH_3
47- #define ADC_CHANNEL_0_1 ADC_ANA_CR_CH_8
48- #define ADC_CHANNEL_2_3 ADC_ANA_CR_CH_9
49- #define ADC_CHANNEL_TEMP ADC_ANA_CR_CH_TEMP
50- #define ADC_CHANNEL_OFFSET ADC_ANA_CR_CH_OFFSET
36+ #define ADC_CHANNEL_0 ADC_ANA_CR_CH_0
37+ #define ADC_CHANNEL_1 ADC_ANA_CR_CH_1
38+ #define ADC_CHANNEL_2 ADC_ANA_CR_CH_2
39+ #define ADC_CHANNEL_3 ADC_ANA_CR_CH_3
40+ #define ADC_CHANNEL_0_1 ADC_ANA_CR_CH_8
41+ #define ADC_CHANNEL_2_3 ADC_ANA_CR_CH_9
42+ #define ADC_CHANNEL_TEMP ADC_ANA_CR_CH_TEMP
43+ #define ADC_CHANNEL_OFFSET ADC_ANA_CR_CH_OFFSET
5144
52- #define ADC_FREQ_MIN 307
53- #define ADC_FREQ_MAX 2000
45+ #define ADC_FREQ_MIN 307
46+ #define ADC_FREQ_MAX 2000
5447
55- #define CMP_POL_0 0x0UL
56- #define CMP_POL_1 ADC_ADC_CR_CMPPOL
48+ #define CMP_POL_0 0x0UL
49+ #define CMP_POL_1 ADC_ADC_CR_CMPPOL
5750
5851#define HAL_ADC_STATE_RESET 0x00000000U
5952#define HAL_ADC_STATE_READY 0x00000001U
@@ -67,26 +60,26 @@ typedef struct __ADC_HandleTypeDef
6760 ((CHANNEL) == ADC_CHANNEL_1) || \
6861 ((CHANNEL) == ADC_CHANNEL_2) || \
6962 ((CHANNEL) == ADC_CHANNEL_3) || \
70- ((CHANNEL) == ADC_CHANNEL_0_1) || \
63+ ((CHANNEL) == ADC_CHANNEL_0_1) || \
7164 ((CHANNEL) == ADC_CHANNEL_2_3) )
72-
73- #define IS_ADC_CMP_POL (POL ) (((POL) == CMP_POL_0) || \
74- ((POL) == CMP_POL_1))
75-
65+
66+ #define IS_ADC_CMP_POL (POL ) (((POL) == CMP_POL_0) || \
67+ ((POL) == CMP_POL_1))
68+
7669#define IS_ADC_FREQUENCY (FREQ ) (((FREQ) >= ADC_FREQ_MIN) && ((FREQ) <= ADC_FREQ_MAX))
7770
78- #define __HAL_ADC_ENABLE (__HANDLE__ ) (MODIFY_REG((__HANDLE__)->Instance->ANA_CR, ADC_ANA_CR_CH | ADC_ANA_CR_PD | ADC_ANA_CR_RST | ADC_ANA_CR_LDOEN, \
79- (__HANDLE__)->Init.channel | ADC_ANA_CR_RST | ADC_ANA_CR_LDOEN))
80-
81- #define __HAL_ADC_DISABLE (__HANDLE__ ) (MODIFY_REG((__HANDLE__)->Instance->ANA_CR, ADC_ANA_CR_PD | ADC_ANA_CR_RST | ADC_ANA_CR_LDOEN, \
82- ADC_ANA_CR_PD))
71+ #define __HAL_ADC_ENABLE (__HANDLE__ ) (MODIFY_REG((__HANDLE__)->Instance->ANA_CR, ADC_ANA_CR_CH | ADC_ANA_CR_PD | ADC_ANA_CR_RST | ADC_ANA_CR_LDOEN, \
72+ (__HANDLE__)->Init.channel | ADC_ANA_CR_RST | ADC_ANA_CR_LDOEN))
73+
74+ #define __HAL_ADC_DISABLE (__HANDLE__ ) (MODIFY_REG((__HANDLE__)->Instance->ANA_CR, ADC_ANA_CR_PD | ADC_ANA_CR_RST | ADC_ANA_CR_LDOEN, \
75+ ADC_ANA_CR_PD))
8376
84- #define __HAL_ADC_CLEAR_FLAG (__HANDLE__ , __FLAG__ ) \
85- (WRITE_REG((__HANDLE__)->Instance->IF, (__FLAG__)))
86-
87- #define __HAL_ADC_INT_ENABLE (__HANDLE__ , __FLAG__ ) (SET_BIT((__HANDLE__)->Instance->ADC_CR, __FLAG__))
77+ #define __HAL_ADC_CLEAR_FLAG (__HANDLE__ , __FLAG__ ) \
78+ (WRITE_REG((__HANDLE__)->Instance->IF, (__FLAG__)))
79+
80+ #define __HAL_ADC_INT_ENABLE (__HANDLE__ , __FLAG__ ) (SET_BIT((__HANDLE__)->Instance->ADC_CR, __FLAG__))
8881
89- #define __HAL_ADC_INT_DISABLE (__HANDLE__ , __FLAG__ ) (CLEAR_BIT((__HANDLE__)->Instance->ADC_CR, __FLAG__))
82+ #define __HAL_ADC_INT_DISABLE (__HANDLE__ , __FLAG__ ) (CLEAR_BIT((__HANDLE__)->Instance->ADC_CR, __FLAG__))
9083
9184#define __HAL_ADC_GET_IT_SOURCE (__HANDLE__ , __INTERRUPT__ ) \
9285 (((__HANDLE__)->Instance->ADC_CR & (__INTERRUPT__)) == (__INTERRUPT__))
@@ -96,28 +89,31 @@ typedef struct __ADC_HandleTypeDef
9689
9790
9891
92+ #ifdef __cplusplus
93+ extern "C" {
94+ #endif
9995HAL_StatusTypeDef HAL_ADC_Init (ADC_HandleTypeDef * hadc );
10096HAL_StatusTypeDef HAL_ADC_DeInit (ADC_HandleTypeDef * hadc );
10197void HAL_ADC_MspInit (ADC_HandleTypeDef * hadc );
10298void HAL_ADC_MspDeInit (ADC_HandleTypeDef * hadc );
10399
104100
105- // AD转换功能以查询方式实现所对应的开始、停止、查询是否转换完成、获取转换结果
101+ // AD转换功能以查询方式实现所对应的开始、停止、查询是否转换完成、获取转换结果
106102HAL_StatusTypeDef HAL_ADC_Start (ADC_HandleTypeDef * hadc );
107103HAL_StatusTypeDef HAL_ADC_Stop (ADC_HandleTypeDef * hadc );
108- HAL_StatusTypeDef HAL_ADC_PollForConversion (ADC_HandleTypeDef * hadc );
109- int HAL_ADC_GetValue (ADC_HandleTypeDef * hadc );
104+ HAL_StatusTypeDef HAL_ADC_PollForConversion (ADC_HandleTypeDef * hadc );
105+ int HAL_ADC_GetValue (ADC_HandleTypeDef * hadc );
110106
111- // 该接口调用了以上接口,实现了一个完整的查询转换过程,并返回结果,可以直接调用该接口获取转换结果,返回值单位mv
112- int HAL_ADC_GET_INPUT_VOLTAGE (ADC_HandleTypeDef * hadc );
107+ // 该接口调用了以上接口,实现了一个完整的查询转换过程,并返回结果,可以直接调用该接口获取转换结果,返回值单位mv
108+ int HAL_ADC_GET_INPUT_VOLTAGE (ADC_HandleTypeDef * hadc );
113109
114- // AD转换功能以中断方式实现所对应的开始、停止、中断回调函数
110+ // AD转换功能以中断方式实现所对应的开始、停止、中断回调函数
115111HAL_StatusTypeDef HAL_ADC_Start_IT (ADC_HandleTypeDef * hadc );
116112HAL_StatusTypeDef HAL_ADC_Stop_IT (ADC_HandleTypeDef * hadc );
117113void HAL_ADC_ConvCpltCallback (ADC_HandleTypeDef * hadc );
118114
119- // AD比较功能以中断方式实现所对应的开始、停止、中断回调函数
120- HAL_StatusTypeDef HAL_ADC_Start_Compare_IT (ADC_HandleTypeDef * hadc );
115+ // AD比较功能以中断方式实现所对应的开始、停止、中断回调函数
116+ HAL_StatusTypeDef HAL_ADC_Start_Compare_IT (ADC_HandleTypeDef * hadc );
121117HAL_StatusTypeDef HAL_ADC_Stop_Compare_IT (ADC_HandleTypeDef * hadc );
122118void HAL_ADC_CompareCallback (ADC_HandleTypeDef * hadc );
123119
0 commit comments