提交 | 用户 | age
|
483170
|
1 |
/** |
Q |
2 |
****************************************************************************** |
|
3 |
* @file stm32f0xx_hal_adc_ex.h |
|
4 |
* @author MCD Application Team |
|
5 |
* @brief Header file of ADC HAL Extension module. |
|
6 |
****************************************************************************** |
|
7 |
* @attention |
|
8 |
* |
|
9 |
* <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
|
10 |
* |
|
11 |
* Redistribution and use in source and binary forms, with or without modification, |
|
12 |
* are permitted provided that the following conditions are met: |
|
13 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
14 |
* this list of conditions and the following disclaimer. |
|
15 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
16 |
* this list of conditions and the following disclaimer in the documentation |
|
17 |
* and/or other materials provided with the distribution. |
|
18 |
* 3. Neither the name of STMicroelectronics nor the names of its contributors |
|
19 |
* may be used to endorse or promote products derived from this software |
|
20 |
* without specific prior written permission. |
|
21 |
* |
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
23 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
24 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
25 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
|
26 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
27 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
28 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
29 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
30 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
31 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 |
* |
|
33 |
****************************************************************************** |
|
34 |
*/ |
|
35 |
|
|
36 |
/* Define to prevent recursive inclusion -------------------------------------*/ |
|
37 |
#ifndef __STM32F0xx_HAL_ADC_EX_H |
|
38 |
#define __STM32F0xx_HAL_ADC_EX_H |
|
39 |
|
|
40 |
#ifdef __cplusplus |
|
41 |
extern "C" { |
|
42 |
#endif |
|
43 |
|
|
44 |
/* Includes ------------------------------------------------------------------*/ |
|
45 |
#include "stm32f0xx_hal_def.h" |
|
46 |
|
|
47 |
/** @addtogroup STM32F0xx_HAL_Driver |
|
48 |
* @{ |
|
49 |
*/ |
|
50 |
|
|
51 |
/** @addtogroup ADCEx |
|
52 |
* @{ |
|
53 |
*/ |
|
54 |
|
|
55 |
/* Exported types ------------------------------------------------------------*/ |
|
56 |
/* Exported constants --------------------------------------------------------*/ |
|
57 |
|
|
58 |
/** @defgroup ADC_Exported_Constants ADC Exported Constants |
|
59 |
* @{ |
|
60 |
*/ |
|
61 |
|
|
62 |
#if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) |
|
63 |
#define ADC_CCR_ALL (ADC_CCR_VBATEN | ADC_CCR_TSEN | ADC_CCR_VREFEN) |
|
64 |
#else |
|
65 |
#define ADC_CCR_ALL (ADC_CCR_TSEN | ADC_CCR_VREFEN) |
|
66 |
#endif |
|
67 |
|
|
68 |
/** @defgroup ADC_External_trigger_source_Regular ADC External trigger source Regular |
|
69 |
* @{ |
|
70 |
*/ |
|
71 |
/* List of external triggers with generic trigger name, sorted by trigger */ |
|
72 |
/* name: */ |
|
73 |
|
|
74 |
/* External triggers of regular group for ADC1 */ |
|
75 |
#define ADC_EXTERNALTRIGCONV_T1_TRGO ADC1_2_EXTERNALTRIG_T1_TRGO |
|
76 |
#define ADC_EXTERNALTRIGCONV_T1_CC4 ADC1_2_EXTERNALTRIG_T1_CC4 |
|
77 |
#define ADC_EXTERNALTRIGCONV_T3_TRGO ADC1_2_EXTERNALTRIG_T3_TRGO |
|
78 |
#define ADC_SOFTWARE_START (ADC_CFGR1_EXTSEL + 1U) |
|
79 |
|
|
80 |
#if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) |
|
81 |
#define ADC_EXTERNALTRIGCONV_T2_TRGO ADC1_2_EXTERNALTRIG_T2_TRGO |
|
82 |
#endif |
|
83 |
|
|
84 |
#if !defined(STM32F030x6) && !defined(STM32F070x6) && !defined(STM32F042x6) |
|
85 |
#define ADC_EXTERNALTRIGCONV_T15_TRGO ADC1_2_EXTERNALTRIG_T15_TRGO |
|
86 |
#endif |
|
87 |
|
|
88 |
/** |
|
89 |
* @} |
|
90 |
*/ |
|
91 |
|
|
92 |
|
|
93 |
/** @defgroup ADC_channels ADC channels |
|
94 |
* @{ |
|
95 |
*/ |
|
96 |
/* Note: Depending on devices, some channels may not be available on package */ |
|
97 |
/* pins. Refer to device datasheet for channels availability. */ |
|
98 |
/* Note: Channels are used by bitfields for setting of channel selection */ |
|
99 |
/* (register ADC_CHSELR) and used by number for setting of analog */ |
|
100 |
/* watchdog channel (bits AWDCH in register ADC_CFGR1). */ |
|
101 |
/* Channels are defined with decimal numbers and converted them to */ |
|
102 |
/* bitfields when needed. */ |
|
103 |
#define ADC_CHANNEL_0 ( 0x00000000U) |
|
104 |
#define ADC_CHANNEL_1 ( 0x00000001U) |
|
105 |
#define ADC_CHANNEL_2 ( 0x00000002U) |
|
106 |
#define ADC_CHANNEL_3 ( 0x00000003U) |
|
107 |
#define ADC_CHANNEL_4 ( 0x00000004U) |
|
108 |
#define ADC_CHANNEL_5 ( 0x00000005U) |
|
109 |
#define ADC_CHANNEL_6 ( 0x00000006U) |
|
110 |
#define ADC_CHANNEL_7 ( 0x00000007U) |
|
111 |
#define ADC_CHANNEL_8 ( 0x00000008U) |
|
112 |
#define ADC_CHANNEL_9 ( 0x00000009U) |
|
113 |
#define ADC_CHANNEL_10 ( 0x0000000AU) |
|
114 |
#define ADC_CHANNEL_11 ( 0x0000000BU) |
|
115 |
#define ADC_CHANNEL_12 ( 0x0000000CU) |
|
116 |
#define ADC_CHANNEL_13 ( 0x0000000DU) |
|
117 |
#define ADC_CHANNEL_14 ( 0x0000000EU) |
|
118 |
#define ADC_CHANNEL_15 ( 0x0000000FU) |
|
119 |
#define ADC_CHANNEL_16 ( 0x00000010U) |
|
120 |
#define ADC_CHANNEL_17 ( 0x00000011U) |
|
121 |
|
|
122 |
#define ADC_CHANNEL_TEMPSENSOR ADC_CHANNEL_16 |
|
123 |
#define ADC_CHANNEL_VREFINT ADC_CHANNEL_17 |
|
124 |
|
|
125 |
#if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) |
|
126 |
#define ADC_CHANNEL_18 ( 0x00000012U) |
|
127 |
#define ADC_CHANNEL_VBAT ADC_CHANNEL_18 |
|
128 |
#endif |
|
129 |
|
|
130 |
/** |
|
131 |
* @} |
|
132 |
*/ |
|
133 |
|
|
134 |
/** |
|
135 |
* @} |
|
136 |
*/ |
|
137 |
|
|
138 |
/* Exported macro ------------------------------------------------------------*/ |
|
139 |
|
|
140 |
|
|
141 |
/* Private macros ------------------------------------------------------------*/ |
|
142 |
|
|
143 |
/** @defgroup ADCEx_Private_Macros ADCEx Private Macros |
|
144 |
* @{ |
|
145 |
*/ |
|
146 |
/* Macro reserved for internal HAL driver usage, not intended to be used in */ |
|
147 |
/* code of final user. */ |
|
148 |
|
|
149 |
/** |
|
150 |
* @brief Test if the selected ADC channel is an internal channel |
|
151 |
* VrefInt/TempSensor/Vbat |
|
152 |
* Note: On STM32F0, availability of internal channel Vbat depends on |
|
153 |
* devices lines. |
|
154 |
* @param __CHANNEL__ ADC channel |
|
155 |
* @retval None |
|
156 |
*/ |
|
157 |
#if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) |
|
158 |
#define ADC_IS_CHANNEL_INTERNAL(__CHANNEL__) \ |
|
159 |
(((__CHANNEL__) == ADC_CHANNEL_TEMPSENSOR) || \ |
|
160 |
((__CHANNEL__) == ADC_CHANNEL_VREFINT) || \ |
|
161 |
((__CHANNEL__) == ADC_CHANNEL_VBAT) \ |
|
162 |
) |
|
163 |
#else |
|
164 |
#define ADC_IS_CHANNEL_INTERNAL(__CHANNEL__) \ |
|
165 |
(((__CHANNEL__) == ADC_CHANNEL_TEMPSENSOR) || \ |
|
166 |
((__CHANNEL__) == ADC_CHANNEL_VREFINT) \ |
|
167 |
) |
|
168 |
#endif |
|
169 |
|
|
170 |
/** |
|
171 |
* @brief Select the internal measurement path to be enabled/disabled |
|
172 |
* corresponding to the selected ADC internal channel |
|
173 |
* VrefInt/TempSensor/Vbat. |
|
174 |
* Note: On STM32F0, availability of internal channel Vbat depends on |
|
175 |
* devices lines. |
|
176 |
* @param __CHANNEL__ ADC channel |
|
177 |
* @retval Bit of register ADC_CCR |
|
178 |
*/ |
|
179 |
#if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) |
|
180 |
#define ADC_CHANNEL_INTERNAL_PATH(__CHANNEL__) \ |
|
181 |
(( (__CHANNEL__) == ADC_CHANNEL_TEMPSENSOR \ |
|
182 |
)? \ |
|
183 |
(ADC_CCR_TSEN) \ |
|
184 |
: \ |
|
185 |
( \ |
|
186 |
( (__CHANNEL__) == ADC_CHANNEL_VREFINT \ |
|
187 |
)? \ |
|
188 |
(ADC_CCR_VREFEN) \ |
|
189 |
: \ |
|
190 |
(ADC_CCR_VBATEN) \ |
|
191 |
) \ |
|
192 |
) |
|
193 |
#else |
|
194 |
#define ADC_CHANNEL_INTERNAL_PATH(__CHANNEL__) \ |
|
195 |
(( (__CHANNEL__) == ADC_CHANNEL_TEMPSENSOR \ |
|
196 |
)? \ |
|
197 |
(ADC_CCR_TSEN) \ |
|
198 |
: \ |
|
199 |
(ADC_CCR_VREFEN) \ |
|
200 |
) |
|
201 |
#endif |
|
202 |
|
|
203 |
|
|
204 |
#if defined (STM32F030x6) || defined (STM32F070x6) |
|
205 |
#define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_TRGO) || \ |
|
206 |
((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC4) || \ |
|
207 |
((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO) || \ |
|
208 |
((REGTRIG) == ADC_SOFTWARE_START)) |
|
209 |
#elif defined (STM32F042x6) |
|
210 |
#define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_TRGO) || \ |
|
211 |
((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC4) || \ |
|
212 |
((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_TRGO) || \ |
|
213 |
((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO) || \ |
|
214 |
((REGTRIG) == ADC_SOFTWARE_START)) |
|
215 |
|
|
216 |
#elif defined (STM32F030xC) || defined (STM32F070xB) || defined (STM32F030x8) |
|
217 |
#define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_TRGO) || \ |
|
218 |
((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC4) || \ |
|
219 |
((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO) || \ |
|
220 |
((REGTRIG) == ADC_EXTERNALTRIGCONV_T15_TRGO) || \ |
|
221 |
((REGTRIG) == ADC_SOFTWARE_START)) |
|
222 |
#else |
|
223 |
#define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_TRGO) || \ |
|
224 |
((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC4) || \ |
|
225 |
((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_TRGO) || \ |
|
226 |
((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO) || \ |
|
227 |
((REGTRIG) == ADC_EXTERNALTRIGCONV_T15_TRGO) || \ |
|
228 |
((REGTRIG) == ADC_SOFTWARE_START)) |
|
229 |
#endif |
|
230 |
|
|
231 |
#if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) |
|
232 |
#define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) == ADC_CHANNEL_0) || \ |
|
233 |
((CHANNEL) == ADC_CHANNEL_1) || \ |
|
234 |
((CHANNEL) == ADC_CHANNEL_2) || \ |
|
235 |
((CHANNEL) == ADC_CHANNEL_3) || \ |
|
236 |
((CHANNEL) == ADC_CHANNEL_4) || \ |
|
237 |
((CHANNEL) == ADC_CHANNEL_5) || \ |
|
238 |
((CHANNEL) == ADC_CHANNEL_6) || \ |
|
239 |
((CHANNEL) == ADC_CHANNEL_7) || \ |
|
240 |
((CHANNEL) == ADC_CHANNEL_8) || \ |
|
241 |
((CHANNEL) == ADC_CHANNEL_9) || \ |
|
242 |
((CHANNEL) == ADC_CHANNEL_10) || \ |
|
243 |
((CHANNEL) == ADC_CHANNEL_11) || \ |
|
244 |
((CHANNEL) == ADC_CHANNEL_12) || \ |
|
245 |
((CHANNEL) == ADC_CHANNEL_13) || \ |
|
246 |
((CHANNEL) == ADC_CHANNEL_14) || \ |
|
247 |
((CHANNEL) == ADC_CHANNEL_15) || \ |
|
248 |
((CHANNEL) == ADC_CHANNEL_TEMPSENSOR) || \ |
|
249 |
((CHANNEL) == ADC_CHANNEL_VREFINT) || \ |
|
250 |
((CHANNEL) == ADC_CHANNEL_VBAT) ) |
|
251 |
#else |
|
252 |
#define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) == ADC_CHANNEL_0) || \ |
|
253 |
((CHANNEL) == ADC_CHANNEL_1) || \ |
|
254 |
((CHANNEL) == ADC_CHANNEL_2) || \ |
|
255 |
((CHANNEL) == ADC_CHANNEL_3) || \ |
|
256 |
((CHANNEL) == ADC_CHANNEL_4) || \ |
|
257 |
((CHANNEL) == ADC_CHANNEL_5) || \ |
|
258 |
((CHANNEL) == ADC_CHANNEL_6) || \ |
|
259 |
((CHANNEL) == ADC_CHANNEL_7) || \ |
|
260 |
((CHANNEL) == ADC_CHANNEL_8) || \ |
|
261 |
((CHANNEL) == ADC_CHANNEL_9) || \ |
|
262 |
((CHANNEL) == ADC_CHANNEL_10) || \ |
|
263 |
((CHANNEL) == ADC_CHANNEL_11) || \ |
|
264 |
((CHANNEL) == ADC_CHANNEL_12) || \ |
|
265 |
((CHANNEL) == ADC_CHANNEL_13) || \ |
|
266 |
((CHANNEL) == ADC_CHANNEL_14) || \ |
|
267 |
((CHANNEL) == ADC_CHANNEL_15) || \ |
|
268 |
((CHANNEL) == ADC_CHANNEL_TEMPSENSOR) || \ |
|
269 |
((CHANNEL) == ADC_CHANNEL_VREFINT) ) |
|
270 |
#endif |
|
271 |
|
|
272 |
/** |
|
273 |
* @} |
|
274 |
*/ |
|
275 |
|
|
276 |
|
|
277 |
/* Exported functions --------------------------------------------------------*/ |
|
278 |
/** @addtogroup ADCEx_Exported_Functions |
|
279 |
* @{ |
|
280 |
*/ |
|
281 |
|
|
282 |
/* IO operation functions *****************************************************/ |
|
283 |
/** @addtogroup ADCEx_Exported_Functions_Group1 |
|
284 |
* @{ |
|
285 |
*/ |
|
286 |
|
|
287 |
/* ADC calibration */ |
|
288 |
HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc); |
|
289 |
/** |
|
290 |
* @} |
|
291 |
*/ |
|
292 |
|
|
293 |
|
|
294 |
/** |
|
295 |
* @} |
|
296 |
*/ |
|
297 |
|
|
298 |
|
|
299 |
/** |
|
300 |
* @} |
|
301 |
*/ |
|
302 |
|
|
303 |
/** |
|
304 |
* @} |
|
305 |
*/ |
|
306 |
|
|
307 |
#ifdef __cplusplus |
|
308 |
} |
|
309 |
#endif |
|
310 |
|
|
311 |
#endif /* __STM32F0xx_HAL_ADC_EX_H */ |
|
312 |
|
|
313 |
|
|
314 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
|
315 |
|