MG32F10x Standard Peripherals Firmware Library

mg32f10x_adc.h
浏览该文件的文档.
1
10 /* Define to prevent recursive inclusion -------------------------------------*/
11 #ifndef __MG32F10x_ADC_H
12 #define __MG32F10x_ADC_H
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 /* Includes ------------------------------------------------------------------*/
19 #include "mg32f10x.h"
20
29 /* Exported types ------------------------------------------------------------*/
30
35 typedef struct
36 {
37 FunctionalState ADC_ScanConvMode;
41 FunctionalState ADC_ContinuousConvMode;
45 uint32_t ADC_ExternalTrigConv;
49 uint32_t ADC_DataAlign;
52 uint8_t ADC_NbrOfChannel;
55 } ADC_InitTypeDef;
56
57 /* Exported constants --------------------------------------------------------*/
58
67 #define ADC_ExternalTrigConv_T1_CC1 ((uint32_t)0x00000000)
68 #define ADC_ExternalTrigConv_T1_CC2 ((uint32_t)0x00020000)
69 #define ADC_ExternalTrigConv_T1_CC3 ((uint32_t)0x00040000)
70 #define ADC_ExternalTrigConv_T2_CC2 ((uint32_t)0x00060000)
71 #define ADC_ExternalTrigConv_T3_TRGO ((uint32_t)0x00080000)
72 #define ADC_ExternalTrigConv_T4_CC4 ((uint32_t)0x000A0000)
73 #define ADC_ExternalTrigConv_Ext_IT11 ((uint32_t)0x000C0000)
74 #define ADC_ExternalTrigConv_None ((uint32_t)0x000E0000)
75
76 #define IS_ADC_EXT_TRIG(REGTRIG) (((REGTRIG) == ADC_ExternalTrigConv_T1_CC1) || \
77 ((REGTRIG) == ADC_ExternalTrigConv_T1_CC2) || \
78 ((REGTRIG) == ADC_ExternalTrigConv_T1_CC3) || \
79 ((REGTRIG) == ADC_ExternalTrigConv_T2_CC2) || \
80 ((REGTRIG) == ADC_ExternalTrigConv_T3_TRGO) || \
81 ((REGTRIG) == ADC_ExternalTrigConv_T4_CC4) || \
82 ((REGTRIG) == ADC_ExternalTrigConv_Ext_IT11) || \
83 ((REGTRIG) == ADC_ExternalTrigConv_None))
84
92 #define ADC_DataAlign_Right ((uint32_t)0x00000000)
93 #define ADC_DataAlign_Left ((uint32_t)0x00000800)
94 #define IS_ADC_DATA_ALIGN(ALIGN) (((ALIGN) == ADC_DataAlign_Right) || \
95 ((ALIGN) == ADC_DataAlign_Left))
96
104 #define ADC_Channel_0 ((uint8_t)0x00)
105 #define ADC_Channel_1 ((uint8_t)0x01)
106 #define ADC_Channel_2 ((uint8_t)0x02)
107 #define ADC_Channel_3 ((uint8_t)0x03)
108 #define ADC_Channel_4 ((uint8_t)0x04)
109 #define ADC_Channel_5 ((uint8_t)0x05)
110 #define ADC_Channel_6 ((uint8_t)0x06)
111 #define ADC_Channel_7 ((uint8_t)0x07)
112 #define ADC_Channel_8 ((uint8_t)0x08)
113 #define ADC_Channel_9 ((uint8_t)0x09)
114 #define ADC_Channel_10 ((uint8_t)0x0A)
115 #define ADC_Channel_11 ((uint8_t)0x0B)
116 #define ADC_Channel_12 ((uint8_t)0x0C)
117 #define ADC_Channel_13 ((uint8_t)0x0D)
118 #define ADC_Channel_14 ((uint8_t)0x0E)
119 #define ADC_Channel_15 ((uint8_t)0x0F)
120 #define ADC_Channel_16 ((uint8_t)0x10)
121 #define ADC_Channel_17 ((uint8_t)0x11)
122
123 #define ADC_Channel_TempSensor ((uint8_t)ADC_Channel_16)
124 #define ADC_Channel_Vrefint ((uint8_t)ADC_Channel_17)
125
126 #define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) == ADC_Channel_0) || ((CHANNEL) == ADC_Channel_1) || \
127 ((CHANNEL) == ADC_Channel_2) || ((CHANNEL) == ADC_Channel_3) || \
128 ((CHANNEL) == ADC_Channel_4) || ((CHANNEL) == ADC_Channel_5) || \
129 ((CHANNEL) == ADC_Channel_6) || ((CHANNEL) == ADC_Channel_7) || \
130 ((CHANNEL) == ADC_Channel_8) || ((CHANNEL) == ADC_Channel_9) || \
131 ((CHANNEL) == ADC_Channel_10) || ((CHANNEL) == ADC_Channel_11) || \
132 ((CHANNEL) == ADC_Channel_12) || ((CHANNEL) == ADC_Channel_13) || \
133 ((CHANNEL) == ADC_Channel_14) || ((CHANNEL) == ADC_Channel_15) || \
134 ((CHANNEL) == ADC_Channel_16) || ((CHANNEL) == ADC_Channel_17))
135
143 #define ADC_SampleTime_1Cycles5 ((uint8_t)0x00)
144 #define ADC_SampleTime_7Cycles5 ((uint8_t)0x01)
145 #define ADC_SampleTime_13Cycles5 ((uint8_t)0x02)
146 #define ADC_SampleTime_28Cycles5 ((uint8_t)0x03)
147 #define ADC_SampleTime_41Cycles5 ((uint8_t)0x04)
148 #define ADC_SampleTime_55Cycles5 ((uint8_t)0x05)
149 #define ADC_SampleTime_71Cycles5 ((uint8_t)0x06)
150 #define ADC_SampleTime_239Cycles5 ((uint8_t)0x07)
151 #define IS_ADC_SAMPLE_TIME(TIME) (((TIME) == ADC_SampleTime_1Cycles5) || \
152 ((TIME) == ADC_SampleTime_7Cycles5) || \
153 ((TIME) == ADC_SampleTime_13Cycles5) || \
154 ((TIME) == ADC_SampleTime_28Cycles5) || \
155 ((TIME) == ADC_SampleTime_41Cycles5) || \
156 ((TIME) == ADC_SampleTime_55Cycles5) || \
157 ((TIME) == ADC_SampleTime_71Cycles5) || \
158 ((TIME) == ADC_SampleTime_239Cycles5))
159
167 #define ADC_ExternalTrigInjecConv_T1_TRGO ((uint32_t)0x00000000)
168 #define ADC_ExternalTrigInjecConv_T1_CC4 ((uint32_t)0x00001000)
169 #define ADC_ExternalTrigInjecConv_T2_TRGO ((uint32_t)0x00002000)
170 #define ADC_ExternalTrigInjecConv_T2_CC1 ((uint32_t)0x00003000)
171 #define ADC_ExternalTrigInjecConv_T3_CC4 ((uint32_t)0x00004000)
172 #define ADC_ExternalTrigInjecConv_T4_TRGO ((uint32_t)0x00005000)
173 #define ADC_ExternalTrigInjecConv_Ext_IT15 ((uint32_t)0x00006000)
174 #define ADC_ExternalTrigInjecConv_None ((uint32_t)0x00007000)
175
176 #define IS_ADC_EXT_INJEC_TRIG(INJTRIG) (((INJTRIG) == ADC_ExternalTrigInjecConv_T1_TRGO) || \
177 ((INJTRIG) == ADC_ExternalTrigInjecConv_T1_CC4) || \
178 ((INJTRIG) == ADC_ExternalTrigInjecConv_T2_TRGO) || \
179 ((INJTRIG) == ADC_ExternalTrigInjecConv_T2_CC1) || \
180 ((INJTRIG) == ADC_ExternalTrigInjecConv_T3_CC4) || \
181 ((INJTRIG) == ADC_ExternalTrigInjecConv_T4_TRGO) || \
182 ((INJTRIG) == ADC_ExternalTrigInjecConv_Ext_IT15) || \
183 ((INJTRIG) == ADC_ExternalTrigInjecConv_None))
184
192 #define ADC_InjectedChannel_1 ((uint8_t)0x14)
193 #define ADC_InjectedChannel_2 ((uint8_t)0x18)
194 #define ADC_InjectedChannel_3 ((uint8_t)0x1C)
195 #define ADC_InjectedChannel_4 ((uint8_t)0x20)
196 #define IS_ADC_INJECTED_CHANNEL(CHANNEL) (((CHANNEL) == ADC_InjectedChannel_1) || \
197 ((CHANNEL) == ADC_InjectedChannel_2) || \
198 ((CHANNEL) == ADC_InjectedChannel_3) || \
199 ((CHANNEL) == ADC_InjectedChannel_4))
200
208 #define ADC_AnalogWatchdog_SingleRegEnable ((uint32_t)0x00800200)
209 #define ADC_AnalogWatchdog_SingleInjecEnable ((uint32_t)0x00400200)
210 #define ADC_AnalogWatchdog_SingleRegOrInjecEnable ((uint32_t)0x00C00200)
211 #define ADC_AnalogWatchdog_AllRegEnable ((uint32_t)0x00800000)
212 #define ADC_AnalogWatchdog_AllInjecEnable ((uint32_t)0x00400000)
213 #define ADC_AnalogWatchdog_AllRegAllInjecEnable ((uint32_t)0x00C00000)
214 #define ADC_AnalogWatchdog_None ((uint32_t)0x00000000)
215
216 #define IS_ADC_ANALOG_WATCHDOG(WATCHDOG) (((WATCHDOG) == ADC_AnalogWatchdog_SingleRegEnable) || \
217 ((WATCHDOG) == ADC_AnalogWatchdog_SingleInjecEnable) || \
218 ((WATCHDOG) == ADC_AnalogWatchdog_SingleRegOrInjecEnable) || \
219 ((WATCHDOG) == ADC_AnalogWatchdog_AllRegEnable) || \
220 ((WATCHDOG) == ADC_AnalogWatchdog_AllInjecEnable) || \
221 ((WATCHDOG) == ADC_AnalogWatchdog_AllRegAllInjecEnable) || \
222 ((WATCHDOG) == ADC_AnalogWatchdog_None))
223
231 #define ADC_IT_EOC ((uint16_t)0x0220)
232 #define ADC_IT_AWD ((uint16_t)0x0140)
233 #define ADC_IT_JEOC ((uint16_t)0x0480)
234 #define ADC_IT_OVF ((uint16_t)0x4001)
235 #define ADC_IT_EMP ((uint16_t)0x2002)
236
237 #define IS_ADC_IT(IT) ((((IT) & (uint16_t)0x981C) == 0x00) && ((IT) != 0x00))
238
239 #define IS_ADC_GET_IT(IT) (((IT) == ADC_IT_EOC) || ((IT) == ADC_IT_AWD) || \
240 ((IT) == ADC_IT_JEOC)|| ((IT) == ADC_IT_OVF) || \
241 ((IT) == ADC_IT_EMP))
242
250 #define ADC_FLAG_AWD ((uint8_t)0x01)
251 #define ADC_FLAG_EOC ((uint8_t)0x02)
252 #define ADC_FLAG_JEOC ((uint8_t)0x04)
253 #define ADC_FLAG_JSTRT ((uint8_t)0x08)
254 #define ADC_FLAG_STRT ((uint8_t)0x10)
255 #define ADC_FLAG_EMP ((uint8_t)0x20)
256 #define ADC_FLAG_OVF ((uint8_t)0x40)
257 #define IS_ADC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint8_t)0xE0) == 0x00) && ((FLAG) != 0x00))
258 #define IS_ADC_GET_FLAG(FLAG) (((FLAG) == ADC_FLAG_AWD) || ((FLAG) == ADC_FLAG_EOC) || \
259 ((FLAG) == ADC_FLAG_JEOC) || ((FLAG)== ADC_FLAG_JSTRT) || \
260 ((FLAG) == ADC_FLAG_STRT) || ((FLAG) == ADC_FLAG_EMP) || \
261 ((FLAG) == ADC_FLAG_OVF))
262
273 #define IS_ADC_THRESHOLD(THRESHOLD) ((THRESHOLD) <= 0xFFF)
274
283 #define IS_ADC_OFFSET(OFFSET) ((OFFSET) <= 0xFFF)
284
293 #define IS_ADC_INJECTED_LENGTH(LENGTH) (((LENGTH) >= 0x1) && ((LENGTH) <= 0x4))
294
303 #define IS_ADC_INJECTED_RANK(RANK) (((RANK) >= 0x1) && ((RANK) <= 0x4))
304
314 #define IS_ADC_REGULAR_LENGTH(LENGTH) (((LENGTH) >= 0x1) && ((LENGTH) <= 0x10))
315
323 #define IS_ADC_REGULAR_RANK(RANK) (((RANK) >= 0x1) && ((RANK) <= 0x10))
324
333 #define IS_ADC_REGULAR_DISC_NUMBER(NUMBER) (((NUMBER) >= 0x1) && ((NUMBER) <= 0x8))
334
343 /* Exported macro ------------------------------------------------------------*/
344 /* Exported functions --------------------------------------------------------*/
345
346 void ADC_DeInit(void);
347 void ADC_Init(ADC_InitTypeDef* ADC_InitStruct);
348 void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct);
349 void ADC_Cmd(FunctionalState NewState);
350 void ADC_DMACmd(FunctionalState NewState);
351 void ADC_InjectedDMACmd(FunctionalState NewState);
352 void ADC_ITConfig(uint16_t ADC_IT, FunctionalState NewState);
353 void ADC_ResetCalibration(void);
354 FlagStatus ADC_GetResetCalibrationStatus(void);
355 void ADC_StartCalibration(void);
356 FlagStatus ADC_GetCalibrationStatus(void);
357 void ADC_SoftwareStartConvCmd(FunctionalState NewState);
358 FlagStatus ADC_GetSoftwareStartConvStatus(void);
359 void ADC_DiscModeChannelCountConfig(uint8_t Number);
360 void ADC_DiscModeCmd(FunctionalState NewState);
361 void ADC_RegularChannelConfig(uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime);
362 void ADC_ExternalTrigConvCmd(FunctionalState NewState);
363 uint16_t ADC_GetConversionValue(void);
364 void ADC_AutoInjectedConvCmd(FunctionalState NewState);
365 void ADC_InjectedDiscModeCmd(FunctionalState NewState);
366 void ADC_ExternalTrigInjectedConvConfig(uint32_t ADC_ExternalTrigInjecConv);
367 void ADC_ExternalTrigInjectedConvCmd(FunctionalState NewState);
368 void ADC_SoftwareStartInjectedConvCmd(FunctionalState NewState);
369 FlagStatus ADC_GetSoftwareStartInjectedConvCmdStatus(void);
370 void ADC_InjectedChannelConfig(uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime);
371 void ADC_InjectedSequencerLengthConfig(uint8_t Length);
372 void ADC_SetInjectedOffset(uint8_t ADC_InjectedChannel, uint16_t Offset);
373 uint16_t ADC_GetInjectedConversionValue(uint8_t ADC_InjectedChannel);
374 void ADC_AnalogWatchdogCmd(uint32_t ADC_AnalogWatchdog);
375 void ADC_AnalogWatchdogThresholdsConfig(uint16_t HighThreshold, uint16_t LowThreshold);
376 void ADC_AnalogWatchdogSingleChannelConfig(uint8_t ADC_Channel);
377 void ADC_TempSensorVrefintCmd(FunctionalState NewState);
378 FlagStatus ADC_GetFlagStatus(uint8_t ADC_FLAG);
379 void ADC_ClearFlag(uint8_t ADC_FLAG);
380 ITStatus ADC_GetITStatus(uint16_t ADC_IT);
381 void ADC_ClearITPendingBit(uint16_t ADC_IT);
382
383 uint16_t ADC_GetADValue(uint16_t data);
384
393 #ifdef __cplusplus
394 }
395 #endif
396
397 #endif /*__MG32F10x_ADC_H */
ADC_Init
void ADC_Init(ADC_InitTypeDef *ADC_InitStruct)
Initializes the ADC peripheral according to the specified parameters in the ADC_InitStruct.
Definition: mg32f10x_adc.c:152
ADC_ExternalTrigInjectedConvCmd
void ADC_ExternalTrigInjectedConvCmd(FunctionalState NewState)
Enables or disables the ADC injected channels conversion through external trigger
Definition: mg32f10x_adc.c:726
ADC_ResetCalibration
void ADC_ResetCalibration(void)
Resets the selected ADC calibration registers.
Definition: mg32f10x_adc.c:331
ADC_GetFlagStatus
FlagStatus ADC_GetFlagStatus(uint8_t ADC_FLAG)
Checks whether the specified ADC flag is set or not.
Definition: mg32f10x_adc.c:1076
ADC_TempSensorVrefintCmd
void ADC_TempSensorVrefintCmd(FunctionalState NewState)
Enables or disables the temperature sensor and Vrefint channel.
Definition: mg32f10x_adc.c:1049
ADC_AutoInjectedConvCmd
void ADC_AutoInjectedConvCmd(FunctionalState NewState)
Enables or disables the selected ADC automatic injected group conversion after regular one.
Definition: mg32f10x_adc.c:648
ADC_ClearITPendingBit
void ADC_ClearITPendingBit(uint16_t ADC_IT)
Clears the ADC's interrupt pending bits.
Definition: mg32f10x_adc.c:1161
ADC_InjectedDiscModeCmd
void ADC_InjectedDiscModeCmd(FunctionalState NewState)
Enables or disables the discontinuous mode for injected group channel for the ADC
Definition: mg32f10x_adc.c:672
ADC_DeInit
void ADC_DeInit(void)
Deinitializes the ADC peripheral registers to their default reset values.
Definition: mg32f10x_adc.c:139
ADC_DiscModeCmd
void ADC_DiscModeCmd(FunctionalState NewState)
Enables or disables the discontinuous mode on regular group channel for the ADC
Definition: mg32f10x_adc.c:469
ADC_InitTypeDef
ADC Init structure definition
Definition: mg32f10x_adc.h:35
ADC_GetITStatus
ITStatus ADC_GetITStatus(uint16_t ADC_IT)
Checks whether the specified ADC interrupt has occurred or not.
Definition: mg32f10x_adc.c:1126
ADC_SoftwareStartConvCmd
void ADC_SoftwareStartConvCmd(FunctionalState NewState)
Enables or disables the selected ADC software start conversion .
Definition: mg32f10x_adc.c:397
ADC_ITConfig
void ADC_ITConfig(uint16_t ADC_IT, FunctionalState NewState)
Enables or disables the specified ADC interrupts.
Definition: mg32f10x_adc.c:305
ADC_AnalogWatchdogSingleChannelConfig
void ADC_AnalogWatchdogSingleChannelConfig(uint8_t ADC_Channel)
Configures the analog watchdog guarded single channel
Definition: mg32f10x_adc.c:1028
ADC_InjectedSequencerLengthConfig
void ADC_InjectedSequencerLengthConfig(uint8_t Length)
Configures the sequencer length for injected channels
Definition: mg32f10x_adc.c:886
ADC_GetADValue
uint16_t ADC_GetADValue(uint16_t data)
Adjust the ADC conversion result.
Definition: mg32f10x_adc.c:1178
ADC_StartCalibration
void ADC_StartCalibration(void)
Starts the selected ADC calibration process.
Definition: mg32f10x_adc.c:363
ADC_ExternalTrigInjectedConvConfig
void ADC_ExternalTrigInjectedConvConfig(uint32_t ADC_ExternalTrigInjecConv)
Configures the ADC external trigger for injected channels conversion.
Definition: mg32f10x_adc.c:703
ADC_GetInjectedConversionValue
uint16_t ADC_GetInjectedConversionValue(uint8_t ADC_InjectedChannel)
Returns the ADC injected channel conversion result
Definition: mg32f10x_adc.c:941
ADC_ExternalTrigConvCmd
void ADC_ExternalTrigConvCmd(FunctionalState NewState)
Enables or disables the ADC conversion through external trigger.
Definition: mg32f10x_adc.c:615
ADC_GetConversionValue
uint16_t ADC_GetConversionValue(void)
Returns the last ADC conversion result data for regular channel.
Definition: mg32f10x_adc.c:635
ADC_InitTypeDef::ADC_ScanConvMode
FunctionalState ADC_ScanConvMode
Definition: mg32f10x_adc.h:37
ADC_InitTypeDef::ADC_ExternalTrigConv
uint32_t ADC_ExternalTrigConv
Definition: mg32f10x_adc.h:45
ADC_InitTypeDef::ADC_ContinuousConvMode
FunctionalState ADC_ContinuousConvMode
Definition: mg32f10x_adc.h:41
ADC_RegularChannelConfig
void ADC_RegularChannelConfig(uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime)
Configures for the selected ADC regular channel its corresponding rank in the sequencer and its sampl...
Definition: mg32f10x_adc.c:521
ADC_InitTypeDef::ADC_NbrOfChannel
uint8_t ADC_NbrOfChannel
Definition: mg32f10x_adc.h:52
ADC_AnalogWatchdogThresholdsConfig
void ADC_AnalogWatchdogThresholdsConfig(uint16_t HighThreshold, uint16_t LowThreshold)
Configures the high and low thresholds of the analog watchdog.
Definition: mg32f10x_adc.c:992
ADC_DMACmd
void ADC_DMACmd(FunctionalState NewState)
Enables or disables the ADC DMA request.
Definition: mg32f10x_adc.c:254
ADC_SoftwareStartInjectedConvCmd
void ADC_SoftwareStartInjectedConvCmd(FunctionalState NewState)
Enables or disables the selected ADC start of the injected channels conversion.
Definition: mg32f10x_adc.c:749
ADC_StructInit
void ADC_StructInit(ADC_InitTypeDef *ADC_InitStruct)
Fills each ADC_InitStruct member with its default value.
Definition: mg32f10x_adc.c:211
ADC_InitTypeDef::ADC_DataAlign
uint32_t ADC_DataAlign
Definition: mg32f10x_adc.h:49
ADC_InjectedDMACmd
void ADC_InjectedDMACmd(FunctionalState NewState)
Enables or disables the ADC injected group DMA request.
Definition: mg32f10x_adc.c:276
ADC_Cmd
void ADC_Cmd(FunctionalState NewState)
Enables or disables the ADC peripheral.
Definition: mg32f10x_adc.c:232
ADC_SetInjectedOffset
void ADC_SetInjectedOffset(uint8_t ADC_InjectedChannel, uint16_t Offset)
Set the injected channels conversion value offset
Definition: mg32f10x_adc.c:916
ADC_GetResetCalibrationStatus
FlagStatus ADC_GetResetCalibrationStatus(void)
Gets the selected ADC reset calibration registers status.
Definition: mg32f10x_adc.c:341
ADC_ClearFlag
void ADC_ClearFlag(uint8_t ADC_FLAG)
Clears the ADC's pending flags.
Definition: mg32f10x_adc.c:1107
ADC_InjectedChannelConfig
void ADC_InjectedChannelConfig(uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime)
Configures for the selected ADC injected channel its corresponding rank in the sequencer and its samp...
Definition: mg32f10x_adc.c:825
ADC_AnalogWatchdogCmd
void ADC_AnalogWatchdogCmd(uint32_t ADC_AnalogWatchdog)
Enables or disables the analog watchdog on single/all regular or injected channels
Definition: mg32f10x_adc.c:969
ADC_GetSoftwareStartInjectedConvCmdStatus
FlagStatus ADC_GetSoftwareStartInjectedConvCmdStatus(void)
Gets the selected ADC Software start injected conversion Status.
Definition: mg32f10x_adc.c:771
ADC_GetSoftwareStartConvStatus
FlagStatus ADC_GetSoftwareStartConvStatus(void)
Gets the selected ADC Software start conversion Status.
Definition: mg32f10x_adc.c:419
ADC_GetCalibrationStatus
FlagStatus ADC_GetCalibrationStatus(void)
Gets the selected ADC calibration status.
Definition: mg32f10x_adc.c:373
ADC_DiscModeChannelCountConfig
void ADC_DiscModeChannelCountConfig(uint8_t Number)
Configures the discontinuous mode for the selected ADC regular group channel.
Definition: mg32f10x_adc.c:444