1 /** 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 * Copyright (c) 2016 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 19 /* Define to prevent recursive inclusion -------------------------------------*/ 20 #ifndef __STM32F0xx_HAL_ADC_EX_H 21 #define __STM32F0xx_HAL_ADC_EX_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32f0xx_hal_def.h" 29 30 /** @addtogroup STM32F0xx_HAL_Driver 31 * @{ 32 */ 33 34 /** @addtogroup ADCEx 35 * @{ 36 */ 37 38 /* Exported types ------------------------------------------------------------*/ 39 /* Exported constants --------------------------------------------------------*/ 40 41 /** @defgroup ADC_Exported_Constants ADC Exported Constants 42 * @{ 43 */ 44 45 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) 46 #define ADC_CCR_ALL (ADC_CCR_VBATEN | ADC_CCR_TSEN | ADC_CCR_VREFEN) 47 #else 48 #define ADC_CCR_ALL (ADC_CCR_TSEN | ADC_CCR_VREFEN) 49 #endif 50 51 /** @defgroup ADC_External_trigger_source_Regular ADC External trigger source Regular 52 * @{ 53 */ 54 /* List of external triggers with generic trigger name, sorted by trigger */ 55 /* name: */ 56 57 /* External triggers of regular group for ADC1 */ 58 #define ADC_EXTERNALTRIGCONV_T1_TRGO ADC1_2_EXTERNALTRIG_T1_TRGO 59 #define ADC_EXTERNALTRIGCONV_T1_CC4 ADC1_2_EXTERNALTRIG_T1_CC4 60 #define ADC_EXTERNALTRIGCONV_T3_TRGO ADC1_2_EXTERNALTRIG_T3_TRGO 61 #define ADC_SOFTWARE_START (ADC_CFGR1_EXTSEL + 1U) 62 63 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) 64 #define ADC_EXTERNALTRIGCONV_T2_TRGO ADC1_2_EXTERNALTRIG_T2_TRGO 65 #endif 66 67 #if !defined(STM32F030x6) && !defined(STM32F070x6) && !defined(STM32F042x6) 68 #define ADC_EXTERNALTRIGCONV_T15_TRGO ADC1_2_EXTERNALTRIG_T15_TRGO 69 #endif 70 71 /** 72 * @} 73 */ 74 75 76 /** @defgroup ADC_channels ADC channels 77 * @{ 78 */ 79 /* Note: Depending on devices, some channels may not be available on package */ 80 /* pins. Refer to device datasheet for channels availability. */ 81 /* Note: Channels are used by bitfields for setting of channel selection */ 82 /* (register ADC_CHSELR) and used by number for setting of analog */ 83 /* watchdog channel (bits AWDCH in register ADC_CFGR1). */ 84 /* Channels are defined with decimal numbers and converted them to */ 85 /* bitfields when needed. */ 86 #define ADC_CHANNEL_0 ( 0x00000000U) 87 #define ADC_CHANNEL_1 ( 0x00000001U) 88 #define ADC_CHANNEL_2 ( 0x00000002U) 89 #define ADC_CHANNEL_3 ( 0x00000003U) 90 #define ADC_CHANNEL_4 ( 0x00000004U) 91 #define ADC_CHANNEL_5 ( 0x00000005U) 92 #define ADC_CHANNEL_6 ( 0x00000006U) 93 #define ADC_CHANNEL_7 ( 0x00000007U) 94 #define ADC_CHANNEL_8 ( 0x00000008U) 95 #define ADC_CHANNEL_9 ( 0x00000009U) 96 #define ADC_CHANNEL_10 ( 0x0000000AU) 97 #define ADC_CHANNEL_11 ( 0x0000000BU) 98 #define ADC_CHANNEL_12 ( 0x0000000CU) 99 #define ADC_CHANNEL_13 ( 0x0000000DU) 100 #define ADC_CHANNEL_14 ( 0x0000000EU) 101 #define ADC_CHANNEL_15 ( 0x0000000FU) 102 #define ADC_CHANNEL_16 ( 0x00000010U) 103 #define ADC_CHANNEL_17 ( 0x00000011U) 104 105 #define ADC_CHANNEL_TEMPSENSOR ADC_CHANNEL_16 106 #define ADC_CHANNEL_VREFINT ADC_CHANNEL_17 107 108 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) 109 #define ADC_CHANNEL_18 ( 0x00000012U) 110 #define ADC_CHANNEL_VBAT ADC_CHANNEL_18 111 #endif 112 113 /** 114 * @} 115 */ 116 117 /** 118 * @} 119 */ 120 121 /* Exported macro ------------------------------------------------------------*/ 122 123 124 /* Private macros ------------------------------------------------------------*/ 125 126 /** @defgroup ADCEx_Private_Macros ADCEx Private Macros 127 * @{ 128 */ 129 /* Macro reserved for internal HAL driver usage, not intended to be used in */ 130 /* code of final user. */ 131 132 /** 133 * @brief Test if the selected ADC channel is an internal channel 134 * VrefInt/TempSensor/Vbat 135 * Note: On STM32F0, availability of internal channel Vbat depends on 136 * devices lines. 137 * @param __CHANNEL__ ADC channel 138 * @retval None 139 */ 140 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) 141 #define ADC_IS_CHANNEL_INTERNAL(__CHANNEL__) \ 142 (((__CHANNEL__) == ADC_CHANNEL_TEMPSENSOR) || \ 143 ((__CHANNEL__) == ADC_CHANNEL_VREFINT) || \ 144 ((__CHANNEL__) == ADC_CHANNEL_VBAT) \ 145 ) 146 #else 147 #define ADC_IS_CHANNEL_INTERNAL(__CHANNEL__) \ 148 (((__CHANNEL__) == ADC_CHANNEL_TEMPSENSOR) || \ 149 ((__CHANNEL__) == ADC_CHANNEL_VREFINT) \ 150 ) 151 #endif 152 153 /** 154 * @brief Select the internal measurement path to be enabled/disabled 155 * corresponding to the selected ADC internal channel 156 * VrefInt/TempSensor/Vbat. 157 * Note: On STM32F0, availability of internal channel Vbat depends on 158 * devices lines. 159 * @param __CHANNEL__ ADC channel 160 * @retval Bit of register ADC_CCR 161 */ 162 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) 163 #define ADC_CHANNEL_INTERNAL_PATH(__CHANNEL__) \ 164 (( (__CHANNEL__) == ADC_CHANNEL_TEMPSENSOR \ 165 )? \ 166 (ADC_CCR_TSEN) \ 167 : \ 168 ( \ 169 ( (__CHANNEL__) == ADC_CHANNEL_VREFINT \ 170 )? \ 171 (ADC_CCR_VREFEN) \ 172 : \ 173 (ADC_CCR_VBATEN) \ 174 ) \ 175 ) 176 #else 177 #define ADC_CHANNEL_INTERNAL_PATH(__CHANNEL__) \ 178 (( (__CHANNEL__) == ADC_CHANNEL_TEMPSENSOR \ 179 )? \ 180 (ADC_CCR_TSEN) \ 181 : \ 182 (ADC_CCR_VREFEN) \ 183 ) 184 #endif 185 186 187 #if defined (STM32F030x6) || defined (STM32F070x6) 188 #define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_TRGO) || \ 189 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC4) || \ 190 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO) || \ 191 ((REGTRIG) == ADC_SOFTWARE_START)) 192 #elif defined (STM32F042x6) 193 #define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_TRGO) || \ 194 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC4) || \ 195 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_TRGO) || \ 196 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO) || \ 197 ((REGTRIG) == ADC_SOFTWARE_START)) 198 199 #elif defined (STM32F030xC) || defined (STM32F070xB) || defined (STM32F030x8) 200 #define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_TRGO) || \ 201 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC4) || \ 202 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO) || \ 203 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T15_TRGO) || \ 204 ((REGTRIG) == ADC_SOFTWARE_START)) 205 #else 206 #define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_TRGO) || \ 207 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC4) || \ 208 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_TRGO) || \ 209 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO) || \ 210 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T15_TRGO) || \ 211 ((REGTRIG) == ADC_SOFTWARE_START)) 212 #endif 213 214 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) 215 #define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) == ADC_CHANNEL_0) || \ 216 ((CHANNEL) == ADC_CHANNEL_1) || \ 217 ((CHANNEL) == ADC_CHANNEL_2) || \ 218 ((CHANNEL) == ADC_CHANNEL_3) || \ 219 ((CHANNEL) == ADC_CHANNEL_4) || \ 220 ((CHANNEL) == ADC_CHANNEL_5) || \ 221 ((CHANNEL) == ADC_CHANNEL_6) || \ 222 ((CHANNEL) == ADC_CHANNEL_7) || \ 223 ((CHANNEL) == ADC_CHANNEL_8) || \ 224 ((CHANNEL) == ADC_CHANNEL_9) || \ 225 ((CHANNEL) == ADC_CHANNEL_10) || \ 226 ((CHANNEL) == ADC_CHANNEL_11) || \ 227 ((CHANNEL) == ADC_CHANNEL_12) || \ 228 ((CHANNEL) == ADC_CHANNEL_13) || \ 229 ((CHANNEL) == ADC_CHANNEL_14) || \ 230 ((CHANNEL) == ADC_CHANNEL_15) || \ 231 ((CHANNEL) == ADC_CHANNEL_TEMPSENSOR) || \ 232 ((CHANNEL) == ADC_CHANNEL_VREFINT) || \ 233 ((CHANNEL) == ADC_CHANNEL_VBAT) ) 234 #else 235 #define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) == ADC_CHANNEL_0) || \ 236 ((CHANNEL) == ADC_CHANNEL_1) || \ 237 ((CHANNEL) == ADC_CHANNEL_2) || \ 238 ((CHANNEL) == ADC_CHANNEL_3) || \ 239 ((CHANNEL) == ADC_CHANNEL_4) || \ 240 ((CHANNEL) == ADC_CHANNEL_5) || \ 241 ((CHANNEL) == ADC_CHANNEL_6) || \ 242 ((CHANNEL) == ADC_CHANNEL_7) || \ 243 ((CHANNEL) == ADC_CHANNEL_8) || \ 244 ((CHANNEL) == ADC_CHANNEL_9) || \ 245 ((CHANNEL) == ADC_CHANNEL_10) || \ 246 ((CHANNEL) == ADC_CHANNEL_11) || \ 247 ((CHANNEL) == ADC_CHANNEL_12) || \ 248 ((CHANNEL) == ADC_CHANNEL_13) || \ 249 ((CHANNEL) == ADC_CHANNEL_14) || \ 250 ((CHANNEL) == ADC_CHANNEL_15) || \ 251 ((CHANNEL) == ADC_CHANNEL_TEMPSENSOR) || \ 252 ((CHANNEL) == ADC_CHANNEL_VREFINT) ) 253 #endif 254 255 /** 256 * @} 257 */ 258 259 260 /* Exported functions --------------------------------------------------------*/ 261 /** @addtogroup ADCEx_Exported_Functions 262 * @{ 263 */ 264 265 /* IO operation functions *****************************************************/ 266 /** @addtogroup ADCEx_Exported_Functions_Group1 267 * @{ 268 */ 269 270 /* ADC calibration */ 271 HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc); 272 /** 273 * @} 274 */ 275 276 277 /** 278 * @} 279 */ 280 281 282 /** 283 * @} 284 */ 285 286 /** 287 * @} 288 */ 289 290 #ifdef __cplusplus 291 } 292 #endif 293 294 #endif /* __STM32F0xx_HAL_ADC_EX_H */ 295 296 297