1 /** 2 ****************************************************************************** 3 * @file stm32f4xx_hal_adc.h 4 * @author MCD Application Team 5 * @brief Header file containing functions prototypes of ADC HAL library. 6 ****************************************************************************** 7 * @attention 8 * 9 * <h2><center>© Copyright (c) 2017 STMicroelectronics. 10 * All rights reserved.</center></h2> 11 * 12 * This software component is licensed by ST under BSD 3-Clause license, 13 * the "License"; You may not use this file except in compliance with the 14 * License. You may obtain a copy of the License at: 15 * opensource.org/licenses/BSD-3-Clause 16 * 17 ****************************************************************************** 18 */ 19 20 /* Define to prevent recursive inclusion -------------------------------------*/ 21 #ifndef __STM32F4xx_ADC_H 22 #define __STM32F4xx_ADC_H 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /* Includes ------------------------------------------------------------------*/ 29 #include "stm32f4xx_hal_def.h" 30 31 /** @addtogroup STM32F4xx_HAL_Driver 32 * @{ 33 */ 34 35 /** @addtogroup ADC 36 * @{ 37 */ 38 39 /* Exported types ------------------------------------------------------------*/ 40 /** @defgroup ADC_Exported_Types ADC Exported Types 41 * @{ 42 */ 43 44 /** 45 * @brief Structure definition of ADC and regular group initialization 46 * @note Parameters of this structure are shared within 2 scopes: 47 * - Scope entire ADC (affects regular and injected groups): ClockPrescaler, Resolution, ScanConvMode, DataAlign, ScanConvMode, EOCSelection, LowPowerAutoWait, LowPowerAutoPowerOff, ChannelsBank. 48 * - Scope regular group: ContinuousConvMode, NbrOfConversion, DiscontinuousConvMode, NbrOfDiscConversion, ExternalTrigConvEdge, ExternalTrigConv. 49 * @note The setting of these parameters with function HAL_ADC_Init() is conditioned to ADC state. 50 * ADC state can be either: 51 * - For all parameters: ADC disabled 52 * - For all parameters except 'Resolution', 'ScanConvMode', 'DiscontinuousConvMode', 'NbrOfDiscConversion' : ADC enabled without conversion on going on regular group. 53 * - For parameters 'ExternalTrigConv' and 'ExternalTrigConvEdge': ADC enabled, even with conversion on going. 54 * If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed 55 * without error reporting (as it can be the expected behaviour in case of intended action to update another parameter (which fulfills the ADC state condition) on the fly). 56 */ 57 typedef struct 58 { 59 uint32_t ClockPrescaler; /*!< Select ADC clock prescaler. The clock is common for 60 all the ADCs. 61 This parameter can be a value of @ref ADC_ClockPrescaler */ 62 uint32_t Resolution; /*!< Configures the ADC resolution. 63 This parameter can be a value of @ref ADC_Resolution */ 64 uint32_t DataAlign; /*!< Specifies ADC data alignment to right (MSB on register bit 11 and LSB on register bit 0) (default setting) 65 or to left (if regular group: MSB on register bit 15 and LSB on register bit 4, if injected group (MSB kept as signed value due to potential negative value after offset application): MSB on register bit 14 and LSB on register bit 3). 66 This parameter can be a value of @ref ADC_Data_align */ 67 uint32_t ScanConvMode; /*!< Configures the sequencer of regular and injected groups. 68 This parameter can be associated to parameter 'DiscontinuousConvMode' to have main sequence subdivided in successive parts. 69 If disabled: Conversion is performed in single mode (one channel converted, the one defined in rank 1). 70 Parameters 'NbrOfConversion' and 'InjectedNbrOfConversion' are discarded (equivalent to set to 1). 71 If enabled: Conversions are performed in sequence mode (multiple ranks defined by 'NbrOfConversion'/'InjectedNbrOfConversion' and each channel rank). 72 Scan direction is upward: from rank1 to rank 'n'. 73 This parameter can be set to ENABLE or DISABLE */ 74 uint32_t EOCSelection; /*!< Specifies what EOC (End Of Conversion) flag is used for conversion by polling and interruption: end of conversion of each rank or complete sequence. 75 This parameter can be a value of @ref ADC_EOCSelection. 76 Note: For injected group, end of conversion (flag&IT) is raised only at the end of the sequence. 77 Therefore, if end of conversion is set to end of each conversion, injected group should not be used with interruption (HAL_ADCEx_InjectedStart_IT) 78 or polling (HAL_ADCEx_InjectedStart and HAL_ADCEx_InjectedPollForConversion). By the way, polling is still possible since driver will use an estimated timing for end of injected conversion. 79 Note: If overrun feature is intended to be used, use ADC in mode 'interruption' (function HAL_ADC_Start_IT() ) with parameter EOCSelection set to end of each conversion or in mode 'transfer by DMA' (function HAL_ADC_Start_DMA()). 80 If overrun feature is intended to be bypassed, use ADC in mode 'polling' or 'interruption' with parameter EOCSelection must be set to end of sequence */ 81 FunctionalState ContinuousConvMode; /*!< Specifies whether the conversion is performed in single mode (one conversion) or continuous mode for regular group, 82 after the selected trigger occurred (software start or external trigger). 83 This parameter can be set to ENABLE or DISABLE. */ 84 uint32_t NbrOfConversion; /*!< Specifies the number of ranks that will be converted within the regular group sequencer. 85 To use regular group sequencer and convert several ranks, parameter 'ScanConvMode' must be enabled. 86 This parameter must be a number between Min_Data = 1 and Max_Data = 16. */ 87 FunctionalState DiscontinuousConvMode; /*!< Specifies whether the conversions sequence of regular group is performed in Complete-sequence/Discontinuous-sequence (main sequence subdivided in successive parts). 88 Discontinuous mode is used only if sequencer is enabled (parameter 'ScanConvMode'). If sequencer is disabled, this parameter is discarded. 89 Discontinuous mode can be enabled only if continuous mode is disabled. If continuous mode is enabled, this parameter setting is discarded. 90 This parameter can be set to ENABLE or DISABLE. */ 91 uint32_t NbrOfDiscConversion; /*!< Specifies the number of discontinuous conversions in which the main sequence of regular group (parameter NbrOfConversion) will be subdivided. 92 If parameter 'DiscontinuousConvMode' is disabled, this parameter is discarded. 93 This parameter must be a number between Min_Data = 1 and Max_Data = 8. */ 94 uint32_t ExternalTrigConv; /*!< Selects the external event used to trigger the conversion start of regular group. 95 If set to ADC_SOFTWARE_START, external triggers are disabled. 96 If set to external trigger source, triggering is on event rising edge by default. 97 This parameter can be a value of @ref ADC_External_trigger_Source_Regular */ 98 uint32_t ExternalTrigConvEdge; /*!< Selects the external trigger edge of regular group. 99 If trigger is set to ADC_SOFTWARE_START, this parameter is discarded. 100 This parameter can be a value of @ref ADC_External_trigger_edge_Regular */ 101 FunctionalState DMAContinuousRequests; /*!< Specifies whether the DMA requests are performed in one shot mode (DMA transfer stop when number of conversions is reached) 102 or in Continuous mode (DMA transfer unlimited, whatever number of conversions). 103 Note: In continuous mode, DMA must be configured in circular mode. Otherwise an overrun will be triggered when DMA buffer maximum pointer is reached. 104 Note: This parameter must be modified when no conversion is on going on both regular and injected groups (ADC disabled, or ADC enabled without continuous mode or external trigger that could launch a conversion). 105 This parameter can be set to ENABLE or DISABLE. */ 106 }ADC_InitTypeDef; 107 108 109 110 /** 111 * @brief Structure definition of ADC channel for regular group 112 * @note The setting of these parameters with function HAL_ADC_ConfigChannel() is conditioned to ADC state. 113 * ADC can be either disabled or enabled without conversion on going on regular group. 114 */ 115 typedef struct 116 { 117 uint32_t Channel; /*!< Specifies the channel to configure into ADC regular group. 118 This parameter can be a value of @ref ADC_channels */ 119 uint32_t Rank; /*!< Specifies the rank in the regular group sequencer. 120 This parameter must be a number between Min_Data = 1 and Max_Data = 16 */ 121 uint32_t SamplingTime; /*!< Sampling time value to be set for the selected channel. 122 Unit: ADC clock cycles 123 Conversion time is the addition of sampling time and processing time (12 ADC clock cycles at ADC resolution 12 bits, 11 cycles at 10 bits, 9 cycles at 8 bits, 7 cycles at 6 bits). 124 This parameter can be a value of @ref ADC_sampling_times 125 Caution: This parameter updates the parameter property of the channel, that can be used into regular and/or injected groups. 126 If this same channel has been previously configured in the other group (regular/injected), it will be updated to last setting. 127 Note: In case of usage of internal measurement channels (VrefInt/Vbat/TempSensor), 128 sampling time constraints must be respected (sampling time can be adjusted in function of ADC clock frequency and sampling time setting) 129 Refer to device datasheet for timings values, parameters TS_vrefint, TS_temp (values rough order: 4us min). */ 130 uint32_t Offset; /*!< Reserved for future use, can be set to 0 */ 131 }ADC_ChannelConfTypeDef; 132 133 /** 134 * @brief ADC Configuration multi-mode structure definition 135 */ 136 typedef struct 137 { 138 uint32_t WatchdogMode; /*!< Configures the ADC analog watchdog mode. 139 This parameter can be a value of @ref ADC_analog_watchdog_selection */ 140 uint32_t HighThreshold; /*!< Configures the ADC analog watchdog High threshold value. 141 This parameter must be a 12-bit value. */ 142 uint32_t LowThreshold; /*!< Configures the ADC analog watchdog High threshold value. 143 This parameter must be a 12-bit value. */ 144 uint32_t Channel; /*!< Configures ADC channel for the analog watchdog. 145 This parameter has an effect only if watchdog mode is configured on single channel 146 This parameter can be a value of @ref ADC_channels */ 147 FunctionalState ITMode; /*!< Specifies whether the analog watchdog is configured 148 is interrupt mode or in polling mode. 149 This parameter can be set to ENABLE or DISABLE */ 150 uint32_t WatchdogNumber; /*!< Reserved for future use, can be set to 0 */ 151 }ADC_AnalogWDGConfTypeDef; 152 153 /** 154 * @brief HAL ADC state machine: ADC states definition (bitfields) 155 */ 156 /* States of ADC global scope */ 157 #define HAL_ADC_STATE_RESET 0x00000000U /*!< ADC not yet initialized or disabled */ 158 #define HAL_ADC_STATE_READY 0x00000001U /*!< ADC peripheral ready for use */ 159 #define HAL_ADC_STATE_BUSY_INTERNAL 0x00000002U /*!< ADC is busy to internal process (initialization, calibration) */ 160 #define HAL_ADC_STATE_TIMEOUT 0x00000004U /*!< TimeOut occurrence */ 161 162 /* States of ADC errors */ 163 #define HAL_ADC_STATE_ERROR_INTERNAL 0x00000010U /*!< Internal error occurrence */ 164 #define HAL_ADC_STATE_ERROR_CONFIG 0x00000020U /*!< Configuration error occurrence */ 165 #define HAL_ADC_STATE_ERROR_DMA 0x00000040U /*!< DMA error occurrence */ 166 167 /* States of ADC group regular */ 168 #define HAL_ADC_STATE_REG_BUSY 0x00000100U /*!< A conversion on group regular is ongoing or can occur (either by continuous mode, 169 external trigger, low power auto power-on (if feature available), multimode ADC master control (if feature available)) */ 170 #define HAL_ADC_STATE_REG_EOC 0x00000200U /*!< Conversion data available on group regular */ 171 #define HAL_ADC_STATE_REG_OVR 0x00000400U /*!< Overrun occurrence */ 172 173 /* States of ADC group injected */ 174 #define HAL_ADC_STATE_INJ_BUSY 0x00001000U /*!< A conversion on group injected is ongoing or can occur (either by auto-injection mode, 175 external trigger, low power auto power-on (if feature available), multimode ADC master control (if feature available)) */ 176 #define HAL_ADC_STATE_INJ_EOC 0x00002000U /*!< Conversion data available on group injected */ 177 178 /* States of ADC analog watchdogs */ 179 #define HAL_ADC_STATE_AWD1 0x00010000U /*!< Out-of-window occurrence of analog watchdog 1 */ 180 #define HAL_ADC_STATE_AWD2 0x00020000U /*!< Not available on STM32F4 device: Out-of-window occurrence of analog watchdog 2 */ 181 #define HAL_ADC_STATE_AWD3 0x00040000U /*!< Not available on STM32F4 device: Out-of-window occurrence of analog watchdog 3 */ 182 183 /* States of ADC multi-mode */ 184 #define HAL_ADC_STATE_MULTIMODE_SLAVE 0x00100000U /*!< Not available on STM32F4 device: ADC in multimode slave state, controlled by another ADC master ( */ 185 186 187 /** 188 * @brief ADC handle Structure definition 189 */ 190 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 191 typedef struct __ADC_HandleTypeDef 192 #else 193 typedef struct 194 #endif 195 { 196 ADC_TypeDef *Instance; /*!< Register base address */ 197 198 ADC_InitTypeDef Init; /*!< ADC required parameters */ 199 200 __IO uint32_t NbrOfCurrentConversionRank; /*!< ADC number of current conversion rank */ 201 202 DMA_HandleTypeDef *DMA_Handle; /*!< Pointer DMA Handler */ 203 204 HAL_LockTypeDef Lock; /*!< ADC locking object */ 205 206 __IO uint32_t State; /*!< ADC communication state */ 207 208 __IO uint32_t ErrorCode; /*!< ADC Error code */ 209 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 210 void (* ConvCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC conversion complete callback */ 211 void (* ConvHalfCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC conversion DMA half-transfer callback */ 212 void (* LevelOutOfWindowCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC analog watchdog 1 callback */ 213 void (* ErrorCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC error callback */ 214 void (* InjectedConvCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC group injected conversion complete callback */ 215 void (* MspInitCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC Msp Init callback */ 216 void (* MspDeInitCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC Msp DeInit callback */ 217 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 218 }ADC_HandleTypeDef; 219 220 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 221 /** 222 * @brief HAL ADC Callback ID enumeration definition 223 */ 224 typedef enum 225 { 226 HAL_ADC_CONVERSION_COMPLETE_CB_ID = 0x00U, /*!< ADC conversion complete callback ID */ 227 HAL_ADC_CONVERSION_HALF_CB_ID = 0x01U, /*!< ADC conversion DMA half-transfer callback ID */ 228 HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID = 0x02U, /*!< ADC analog watchdog 1 callback ID */ 229 HAL_ADC_ERROR_CB_ID = 0x03U, /*!< ADC error callback ID */ 230 HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID = 0x04U, /*!< ADC group injected conversion complete callback ID */ 231 HAL_ADC_MSPINIT_CB_ID = 0x05U, /*!< ADC Msp Init callback ID */ 232 HAL_ADC_MSPDEINIT_CB_ID = 0x06U /*!< ADC Msp DeInit callback ID */ 233 } HAL_ADC_CallbackIDTypeDef; 234 235 /** 236 * @brief HAL ADC Callback pointer definition 237 */ 238 typedef void (*pADC_CallbackTypeDef)(ADC_HandleTypeDef *hadc); /*!< pointer to a ADC callback function */ 239 240 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 241 242 /** 243 * @} 244 */ 245 246 /* Exported constants --------------------------------------------------------*/ 247 /** @defgroup ADC_Exported_Constants ADC Exported Constants 248 * @{ 249 */ 250 251 /** @defgroup ADC_Error_Code ADC Error Code 252 * @{ 253 */ 254 #define HAL_ADC_ERROR_NONE 0x00U /*!< No error */ 255 #define HAL_ADC_ERROR_INTERNAL 0x01U /*!< ADC IP internal error: if problem of clocking, 256 enable/disable, erroneous state */ 257 #define HAL_ADC_ERROR_OVR 0x02U /*!< Overrun error */ 258 #define HAL_ADC_ERROR_DMA 0x04U /*!< DMA transfer error */ 259 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 260 #define HAL_ADC_ERROR_INVALID_CALLBACK (0x10U) /*!< Invalid Callback error */ 261 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 262 /** 263 * @} 264 */ 265 266 267 /** @defgroup ADC_ClockPrescaler ADC Clock Prescaler 268 * @{ 269 */ 270 #define ADC_CLOCK_SYNC_PCLK_DIV2 0x00000000U 271 #define ADC_CLOCK_SYNC_PCLK_DIV4 ((uint32_t)ADC_CCR_ADCPRE_0) 272 #define ADC_CLOCK_SYNC_PCLK_DIV6 ((uint32_t)ADC_CCR_ADCPRE_1) 273 #define ADC_CLOCK_SYNC_PCLK_DIV8 ((uint32_t)ADC_CCR_ADCPRE) 274 /** 275 * @} 276 */ 277 278 /** @defgroup ADC_delay_between_2_sampling_phases ADC Delay Between 2 Sampling Phases 279 * @{ 280 */ 281 #define ADC_TWOSAMPLINGDELAY_5CYCLES 0x00000000U 282 #define ADC_TWOSAMPLINGDELAY_6CYCLES ((uint32_t)ADC_CCR_DELAY_0) 283 #define ADC_TWOSAMPLINGDELAY_7CYCLES ((uint32_t)ADC_CCR_DELAY_1) 284 #define ADC_TWOSAMPLINGDELAY_8CYCLES ((uint32_t)(ADC_CCR_DELAY_1 | ADC_CCR_DELAY_0)) 285 #define ADC_TWOSAMPLINGDELAY_9CYCLES ((uint32_t)ADC_CCR_DELAY_2) 286 #define ADC_TWOSAMPLINGDELAY_10CYCLES ((uint32_t)(ADC_CCR_DELAY_2 | ADC_CCR_DELAY_0)) 287 #define ADC_TWOSAMPLINGDELAY_11CYCLES ((uint32_t)(ADC_CCR_DELAY_2 | ADC_CCR_DELAY_1)) 288 #define ADC_TWOSAMPLINGDELAY_12CYCLES ((uint32_t)(ADC_CCR_DELAY_2 | ADC_CCR_DELAY_1 | ADC_CCR_DELAY_0)) 289 #define ADC_TWOSAMPLINGDELAY_13CYCLES ((uint32_t)ADC_CCR_DELAY_3) 290 #define ADC_TWOSAMPLINGDELAY_14CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_0)) 291 #define ADC_TWOSAMPLINGDELAY_15CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_1)) 292 #define ADC_TWOSAMPLINGDELAY_16CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_1 | ADC_CCR_DELAY_0)) 293 #define ADC_TWOSAMPLINGDELAY_17CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_2)) 294 #define ADC_TWOSAMPLINGDELAY_18CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_2 | ADC_CCR_DELAY_0)) 295 #define ADC_TWOSAMPLINGDELAY_19CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_2 | ADC_CCR_DELAY_1)) 296 #define ADC_TWOSAMPLINGDELAY_20CYCLES ((uint32_t)ADC_CCR_DELAY) 297 /** 298 * @} 299 */ 300 301 /** @defgroup ADC_Resolution ADC Resolution 302 * @{ 303 */ 304 #define ADC_RESOLUTION_12B 0x00000000U 305 #define ADC_RESOLUTION_10B ((uint32_t)ADC_CR1_RES_0) 306 #define ADC_RESOLUTION_8B ((uint32_t)ADC_CR1_RES_1) 307 #define ADC_RESOLUTION_6B ((uint32_t)ADC_CR1_RES) 308 /** 309 * @} 310 */ 311 312 /** @defgroup ADC_External_trigger_edge_Regular ADC External Trigger Edge Regular 313 * @{ 314 */ 315 #define ADC_EXTERNALTRIGCONVEDGE_NONE 0x00000000U 316 #define ADC_EXTERNALTRIGCONVEDGE_RISING ((uint32_t)ADC_CR2_EXTEN_0) 317 #define ADC_EXTERNALTRIGCONVEDGE_FALLING ((uint32_t)ADC_CR2_EXTEN_1) 318 #define ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING ((uint32_t)ADC_CR2_EXTEN) 319 /** 320 * @} 321 */ 322 323 /** @defgroup ADC_External_trigger_Source_Regular ADC External Trigger Source Regular 324 * @{ 325 */ 326 /* Note: Parameter ADC_SOFTWARE_START is a software parameter used for */ 327 /* compatibility with other STM32 devices. */ 328 #define ADC_EXTERNALTRIGCONV_T1_CC1 0x00000000U 329 #define ADC_EXTERNALTRIGCONV_T1_CC2 ((uint32_t)ADC_CR2_EXTSEL_0) 330 #define ADC_EXTERNALTRIGCONV_T1_CC3 ((uint32_t)ADC_CR2_EXTSEL_1) 331 #define ADC_EXTERNALTRIGCONV_T2_CC2 ((uint32_t)(ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0)) 332 #define ADC_EXTERNALTRIGCONV_T2_CC3 ((uint32_t)ADC_CR2_EXTSEL_2) 333 #define ADC_EXTERNALTRIGCONV_T2_CC4 ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_0)) 334 #define ADC_EXTERNALTRIGCONV_T2_TRGO ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1)) 335 #define ADC_EXTERNALTRIGCONV_T3_CC1 ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0)) 336 #define ADC_EXTERNALTRIGCONV_T3_TRGO ((uint32_t)ADC_CR2_EXTSEL_3) 337 #define ADC_EXTERNALTRIGCONV_T4_CC4 ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_0)) 338 #define ADC_EXTERNALTRIGCONV_T5_CC1 ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_1)) 339 #define ADC_EXTERNALTRIGCONV_T5_CC2 ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0)) 340 #define ADC_EXTERNALTRIGCONV_T5_CC3 ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2)) 341 #define ADC_EXTERNALTRIGCONV_T8_CC1 ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_0)) 342 #define ADC_EXTERNALTRIGCONV_T8_TRGO ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1)) 343 #define ADC_EXTERNALTRIGCONV_Ext_IT11 ((uint32_t)ADC_CR2_EXTSEL) 344 #define ADC_SOFTWARE_START ((uint32_t)ADC_CR2_EXTSEL + 1U) 345 /** 346 * @} 347 */ 348 349 /** @defgroup ADC_Data_align ADC Data Align 350 * @{ 351 */ 352 #define ADC_DATAALIGN_RIGHT 0x00000000U 353 #define ADC_DATAALIGN_LEFT ((uint32_t)ADC_CR2_ALIGN) 354 /** 355 * @} 356 */ 357 358 /** @defgroup ADC_channels ADC Common Channels 359 * @{ 360 */ 361 #define ADC_CHANNEL_0 0x00000000U 362 #define ADC_CHANNEL_1 ((uint32_t)ADC_CR1_AWDCH_0) 363 #define ADC_CHANNEL_2 ((uint32_t)ADC_CR1_AWDCH_1) 364 #define ADC_CHANNEL_3 ((uint32_t)(ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0)) 365 #define ADC_CHANNEL_4 ((uint32_t)ADC_CR1_AWDCH_2) 366 #define ADC_CHANNEL_5 ((uint32_t)(ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_0)) 367 #define ADC_CHANNEL_6 ((uint32_t)(ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1)) 368 #define ADC_CHANNEL_7 ((uint32_t)(ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0)) 369 #define ADC_CHANNEL_8 ((uint32_t)ADC_CR1_AWDCH_3) 370 #define ADC_CHANNEL_9 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_0)) 371 #define ADC_CHANNEL_10 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_1)) 372 #define ADC_CHANNEL_11 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0)) 373 #define ADC_CHANNEL_12 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2)) 374 #define ADC_CHANNEL_13 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_0)) 375 #define ADC_CHANNEL_14 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1)) 376 #define ADC_CHANNEL_15 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0)) 377 #define ADC_CHANNEL_16 ((uint32_t)ADC_CR1_AWDCH_4) 378 #define ADC_CHANNEL_17 ((uint32_t)(ADC_CR1_AWDCH_4 | ADC_CR1_AWDCH_0)) 379 #define ADC_CHANNEL_18 ((uint32_t)(ADC_CR1_AWDCH_4 | ADC_CR1_AWDCH_1)) 380 381 #define ADC_CHANNEL_VREFINT ((uint32_t)ADC_CHANNEL_17) 382 #define ADC_CHANNEL_VBAT ((uint32_t)ADC_CHANNEL_18) 383 /** 384 * @} 385 */ 386 387 /** @defgroup ADC_sampling_times ADC Sampling Times 388 * @{ 389 */ 390 #define ADC_SAMPLETIME_3CYCLES 0x00000000U 391 #define ADC_SAMPLETIME_15CYCLES ((uint32_t)ADC_SMPR1_SMP10_0) 392 #define ADC_SAMPLETIME_28CYCLES ((uint32_t)ADC_SMPR1_SMP10_1) 393 #define ADC_SAMPLETIME_56CYCLES ((uint32_t)(ADC_SMPR1_SMP10_1 | ADC_SMPR1_SMP10_0)) 394 #define ADC_SAMPLETIME_84CYCLES ((uint32_t)ADC_SMPR1_SMP10_2) 395 #define ADC_SAMPLETIME_112CYCLES ((uint32_t)(ADC_SMPR1_SMP10_2 | ADC_SMPR1_SMP10_0)) 396 #define ADC_SAMPLETIME_144CYCLES ((uint32_t)(ADC_SMPR1_SMP10_2 | ADC_SMPR1_SMP10_1)) 397 #define ADC_SAMPLETIME_480CYCLES ((uint32_t)ADC_SMPR1_SMP10) 398 /** 399 * @} 400 */ 401 402 /** @defgroup ADC_EOCSelection ADC EOC Selection 403 * @{ 404 */ 405 #define ADC_EOC_SEQ_CONV 0x00000000U 406 #define ADC_EOC_SINGLE_CONV 0x00000001U 407 #define ADC_EOC_SINGLE_SEQ_CONV 0x00000002U /*!< reserved for future use */ 408 /** 409 * @} 410 */ 411 412 /** @defgroup ADC_Event_type ADC Event Type 413 * @{ 414 */ 415 #define ADC_AWD_EVENT ((uint32_t)ADC_FLAG_AWD) 416 #define ADC_OVR_EVENT ((uint32_t)ADC_FLAG_OVR) 417 /** 418 * @} 419 */ 420 421 /** @defgroup ADC_analog_watchdog_selection ADC Analog Watchdog Selection 422 * @{ 423 */ 424 #define ADC_ANALOGWATCHDOG_SINGLE_REG ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_AWDEN)) 425 #define ADC_ANALOGWATCHDOG_SINGLE_INJEC ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_JAWDEN)) 426 #define ADC_ANALOGWATCHDOG_SINGLE_REGINJEC ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_AWDEN | ADC_CR1_JAWDEN)) 427 #define ADC_ANALOGWATCHDOG_ALL_REG ((uint32_t)ADC_CR1_AWDEN) 428 #define ADC_ANALOGWATCHDOG_ALL_INJEC ((uint32_t)ADC_CR1_JAWDEN) 429 #define ADC_ANALOGWATCHDOG_ALL_REGINJEC ((uint32_t)(ADC_CR1_AWDEN | ADC_CR1_JAWDEN)) 430 #define ADC_ANALOGWATCHDOG_NONE 0x00000000U 431 /** 432 * @} 433 */ 434 435 /** @defgroup ADC_interrupts_definition ADC Interrupts Definition 436 * @{ 437 */ 438 #define ADC_IT_EOC ((uint32_t)ADC_CR1_EOCIE) 439 #define ADC_IT_AWD ((uint32_t)ADC_CR1_AWDIE) 440 #define ADC_IT_JEOC ((uint32_t)ADC_CR1_JEOCIE) 441 #define ADC_IT_OVR ((uint32_t)ADC_CR1_OVRIE) 442 /** 443 * @} 444 */ 445 446 /** @defgroup ADC_flags_definition ADC Flags Definition 447 * @{ 448 */ 449 #define ADC_FLAG_AWD ((uint32_t)ADC_SR_AWD) 450 #define ADC_FLAG_EOC ((uint32_t)ADC_SR_EOC) 451 #define ADC_FLAG_JEOC ((uint32_t)ADC_SR_JEOC) 452 #define ADC_FLAG_JSTRT ((uint32_t)ADC_SR_JSTRT) 453 #define ADC_FLAG_STRT ((uint32_t)ADC_SR_STRT) 454 #define ADC_FLAG_OVR ((uint32_t)ADC_SR_OVR) 455 /** 456 * @} 457 */ 458 459 /** @defgroup ADC_channels_type ADC Channels Type 460 * @{ 461 */ 462 #define ADC_ALL_CHANNELS 0x00000001U 463 #define ADC_REGULAR_CHANNELS 0x00000002U /*!< reserved for future use */ 464 #define ADC_INJECTED_CHANNELS 0x00000003U /*!< reserved for future use */ 465 /** 466 * @} 467 */ 468 469 /** 470 * @} 471 */ 472 473 /* Exported macro ------------------------------------------------------------*/ 474 /** @defgroup ADC_Exported_Macros ADC Exported Macros 475 * @{ 476 */ 477 478 /** @brief Reset ADC handle state 479 * @param __HANDLE__ ADC handle 480 * @retval None 481 */ 482 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 483 #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) \ 484 do{ \ 485 (__HANDLE__)->State = HAL_ADC_STATE_RESET; \ 486 (__HANDLE__)->MspInitCallback = NULL; \ 487 (__HANDLE__)->MspDeInitCallback = NULL; \ 488 } while(0) 489 #else 490 #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) \ 491 ((__HANDLE__)->State = HAL_ADC_STATE_RESET) 492 #endif 493 494 /** 495 * @brief Enable the ADC peripheral. 496 * @param __HANDLE__ ADC handle 497 * @retval None 498 */ 499 #define __HAL_ADC_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR2 |= ADC_CR2_ADON) 500 501 /** 502 * @brief Disable the ADC peripheral. 503 * @param __HANDLE__ ADC handle 504 * @retval None 505 */ 506 #define __HAL_ADC_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR2 &= ~ADC_CR2_ADON) 507 508 /** 509 * @brief Enable the ADC end of conversion interrupt. 510 * @param __HANDLE__ specifies the ADC Handle. 511 * @param __INTERRUPT__ ADC Interrupt. 512 * @retval None 513 */ 514 #define __HAL_ADC_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR1) |= (__INTERRUPT__)) 515 516 /** 517 * @brief Disable the ADC end of conversion interrupt. 518 * @param __HANDLE__ specifies the ADC Handle. 519 * @param __INTERRUPT__ ADC interrupt. 520 * @retval None 521 */ 522 #define __HAL_ADC_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR1) &= ~(__INTERRUPT__)) 523 524 /** @brief Check if the specified ADC interrupt source is enabled or disabled. 525 * @param __HANDLE__ specifies the ADC Handle. 526 * @param __INTERRUPT__ specifies the ADC interrupt source to check. 527 * @retval The new state of __IT__ (TRUE or FALSE). 528 */ 529 #define __HAL_ADC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR1 & (__INTERRUPT__)) == (__INTERRUPT__)) 530 531 /** 532 * @brief Clear the ADC's pending flags. 533 * @param __HANDLE__ specifies the ADC Handle. 534 * @param __FLAG__ ADC flag. 535 * @retval None 536 */ 537 #define __HAL_ADC_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR) = ~(__FLAG__)) 538 539 /** 540 * @brief Get the selected ADC's flag status. 541 * @param __HANDLE__ specifies the ADC Handle. 542 * @param __FLAG__ ADC flag. 543 * @retval None 544 */ 545 #define __HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__)) 546 547 /** 548 * @} 549 */ 550 551 /* Include ADC HAL Extension module */ 552 #include "stm32f4xx_hal_adc_ex.h" 553 554 /* Exported functions --------------------------------------------------------*/ 555 /** @addtogroup ADC_Exported_Functions 556 * @{ 557 */ 558 559 /** @addtogroup ADC_Exported_Functions_Group1 560 * @{ 561 */ 562 /* Initialization/de-initialization functions ***********************************/ 563 HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc); 564 HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef *hadc); 565 void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc); 566 void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc); 567 568 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 569 /* Callbacks Register/UnRegister functions ***********************************/ 570 HAL_StatusTypeDef HAL_ADC_RegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID, pADC_CallbackTypeDef pCallback); 571 HAL_StatusTypeDef HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID); 572 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 573 /** 574 * @} 575 */ 576 577 /** @addtogroup ADC_Exported_Functions_Group2 578 * @{ 579 */ 580 /* I/O operation functions ******************************************************/ 581 HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc); 582 HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc); 583 HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout); 584 585 HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout); 586 587 HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc); 588 HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc); 589 590 void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc); 591 592 HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length); 593 HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc); 594 595 uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc); 596 597 void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc); 598 void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc); 599 void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc); 600 void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc); 601 /** 602 * @} 603 */ 604 605 /** @addtogroup ADC_Exported_Functions_Group3 606 * @{ 607 */ 608 /* Peripheral Control functions *************************************************/ 609 HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig); 610 HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig); 611 /** 612 * @} 613 */ 614 615 /** @addtogroup ADC_Exported_Functions_Group4 616 * @{ 617 */ 618 /* Peripheral State functions ***************************************************/ 619 uint32_t HAL_ADC_GetState(ADC_HandleTypeDef* hadc); 620 uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc); 621 /** 622 * @} 623 */ 624 625 /** 626 * @} 627 */ 628 /* Private types -------------------------------------------------------------*/ 629 /* Private variables ---------------------------------------------------------*/ 630 /* Private constants ---------------------------------------------------------*/ 631 /** @defgroup ADC_Private_Constants ADC Private Constants 632 * @{ 633 */ 634 /* Delay for ADC stabilization time. */ 635 /* Maximum delay is 1us (refer to device datasheet, parameter tSTAB). */ 636 /* Unit: us */ 637 #define ADC_STAB_DELAY_US 3U 638 /* Delay for temperature sensor stabilization time. */ 639 /* Maximum delay is 10us (refer to device datasheet, parameter tSTART). */ 640 /* Unit: us */ 641 #define ADC_TEMPSENSOR_DELAY_US 10U 642 /** 643 * @} 644 */ 645 646 /* Private macro ------------------------------------------------------------*/ 647 648 /** @defgroup ADC_Private_Macros ADC Private Macros 649 * @{ 650 */ 651 /* Macro reserved for internal HAL driver usage, not intended to be used in 652 code of final user */ 653 654 /** 655 * @brief Verification of ADC state: enabled or disabled 656 * @param __HANDLE__ ADC handle 657 * @retval SET (ADC enabled) or RESET (ADC disabled) 658 */ 659 #define ADC_IS_ENABLE(__HANDLE__) \ 660 ((( ((__HANDLE__)->Instance->SR & ADC_SR_ADONS) == ADC_SR_ADONS ) \ 661 ) ? SET : RESET) 662 663 /** 664 * @brief Test if conversion trigger of regular group is software start 665 * or external trigger. 666 * @param __HANDLE__ ADC handle 667 * @retval SET (software start) or RESET (external trigger) 668 */ 669 #define ADC_IS_SOFTWARE_START_REGULAR(__HANDLE__) \ 670 (((__HANDLE__)->Instance->CR2 & ADC_CR2_EXTEN) == RESET) 671 672 /** 673 * @brief Test if conversion trigger of injected group is software start 674 * or external trigger. 675 * @param __HANDLE__ ADC handle 676 * @retval SET (software start) or RESET (external trigger) 677 */ 678 #define ADC_IS_SOFTWARE_START_INJECTED(__HANDLE__) \ 679 (((__HANDLE__)->Instance->CR2 & ADC_CR2_JEXTEN) == RESET) 680 681 /** 682 * @brief Simultaneously clears and sets specific bits of the handle State 683 * @note: ADC_STATE_CLR_SET() macro is merely aliased to generic macro MODIFY_REG(), 684 * the first parameter is the ADC handle State, the second parameter is the 685 * bit field to clear, the third and last parameter is the bit field to set. 686 * @retval None 687 */ 688 #define ADC_STATE_CLR_SET MODIFY_REG 689 690 /** 691 * @brief Clear ADC error code (set it to error code: "no error") 692 * @param __HANDLE__ ADC handle 693 * @retval None 694 */ 695 #define ADC_CLEAR_ERRORCODE(__HANDLE__) \ 696 ((__HANDLE__)->ErrorCode = HAL_ADC_ERROR_NONE) 697 698 699 #define IS_ADC_CLOCKPRESCALER(ADC_CLOCK) (((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV2) || \ 700 ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV4) || \ 701 ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV6) || \ 702 ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV8)) 703 #define IS_ADC_SAMPLING_DELAY(DELAY) (((DELAY) == ADC_TWOSAMPLINGDELAY_5CYCLES) || \ 704 ((DELAY) == ADC_TWOSAMPLINGDELAY_6CYCLES) || \ 705 ((DELAY) == ADC_TWOSAMPLINGDELAY_7CYCLES) || \ 706 ((DELAY) == ADC_TWOSAMPLINGDELAY_8CYCLES) || \ 707 ((DELAY) == ADC_TWOSAMPLINGDELAY_9CYCLES) || \ 708 ((DELAY) == ADC_TWOSAMPLINGDELAY_10CYCLES) || \ 709 ((DELAY) == ADC_TWOSAMPLINGDELAY_11CYCLES) || \ 710 ((DELAY) == ADC_TWOSAMPLINGDELAY_12CYCLES) || \ 711 ((DELAY) == ADC_TWOSAMPLINGDELAY_13CYCLES) || \ 712 ((DELAY) == ADC_TWOSAMPLINGDELAY_14CYCLES) || \ 713 ((DELAY) == ADC_TWOSAMPLINGDELAY_15CYCLES) || \ 714 ((DELAY) == ADC_TWOSAMPLINGDELAY_16CYCLES) || \ 715 ((DELAY) == ADC_TWOSAMPLINGDELAY_17CYCLES) || \ 716 ((DELAY) == ADC_TWOSAMPLINGDELAY_18CYCLES) || \ 717 ((DELAY) == ADC_TWOSAMPLINGDELAY_19CYCLES) || \ 718 ((DELAY) == ADC_TWOSAMPLINGDELAY_20CYCLES)) 719 #define IS_ADC_RESOLUTION(RESOLUTION) (((RESOLUTION) == ADC_RESOLUTION_12B) || \ 720 ((RESOLUTION) == ADC_RESOLUTION_10B) || \ 721 ((RESOLUTION) == ADC_RESOLUTION_8B) || \ 722 ((RESOLUTION) == ADC_RESOLUTION_6B)) 723 #define IS_ADC_EXT_TRIG_EDGE(EDGE) (((EDGE) == ADC_EXTERNALTRIGCONVEDGE_NONE) || \ 724 ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISING) || \ 725 ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_FALLING) || \ 726 ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING)) 727 #define IS_ADC_EXT_TRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC1) || \ 728 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC2) || \ 729 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC3) || \ 730 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC2) || \ 731 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC3) || \ 732 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC4) || \ 733 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_TRGO) || \ 734 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_CC1) || \ 735 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO) || \ 736 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T4_CC4) || \ 737 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T5_CC1) || \ 738 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T5_CC2) || \ 739 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T5_CC3) || \ 740 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T8_CC1) || \ 741 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T8_TRGO) || \ 742 ((REGTRIG) == ADC_EXTERNALTRIGCONV_Ext_IT11)|| \ 743 ((REGTRIG) == ADC_SOFTWARE_START)) 744 #define IS_ADC_DATA_ALIGN(ALIGN) (((ALIGN) == ADC_DATAALIGN_RIGHT) || \ 745 ((ALIGN) == ADC_DATAALIGN_LEFT)) 746 #define IS_ADC_SAMPLE_TIME(TIME) (((TIME) == ADC_SAMPLETIME_3CYCLES) || \ 747 ((TIME) == ADC_SAMPLETIME_15CYCLES) || \ 748 ((TIME) == ADC_SAMPLETIME_28CYCLES) || \ 749 ((TIME) == ADC_SAMPLETIME_56CYCLES) || \ 750 ((TIME) == ADC_SAMPLETIME_84CYCLES) || \ 751 ((TIME) == ADC_SAMPLETIME_112CYCLES) || \ 752 ((TIME) == ADC_SAMPLETIME_144CYCLES) || \ 753 ((TIME) == ADC_SAMPLETIME_480CYCLES)) 754 #define IS_ADC_EOCSelection(EOCSelection) (((EOCSelection) == ADC_EOC_SINGLE_CONV) || \ 755 ((EOCSelection) == ADC_EOC_SEQ_CONV) || \ 756 ((EOCSelection) == ADC_EOC_SINGLE_SEQ_CONV)) 757 #define IS_ADC_EVENT_TYPE(EVENT) (((EVENT) == ADC_AWD_EVENT) || \ 758 ((EVENT) == ADC_OVR_EVENT)) 759 #define IS_ADC_ANALOG_WATCHDOG(WATCHDOG) (((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_REG) || \ 760 ((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_INJEC) || \ 761 ((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_REGINJEC) || \ 762 ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_REG) || \ 763 ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_INJEC) || \ 764 ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_REGINJEC) || \ 765 ((WATCHDOG) == ADC_ANALOGWATCHDOG_NONE)) 766 #define IS_ADC_CHANNELS_TYPE(CHANNEL_TYPE) (((CHANNEL_TYPE) == ADC_ALL_CHANNELS) || \ 767 ((CHANNEL_TYPE) == ADC_REGULAR_CHANNELS) || \ 768 ((CHANNEL_TYPE) == ADC_INJECTED_CHANNELS)) 769 #define IS_ADC_THRESHOLD(THRESHOLD) ((THRESHOLD) <= 0xFFFU) 770 771 #define IS_ADC_REGULAR_LENGTH(LENGTH) (((LENGTH) >= 1U) && ((LENGTH) <= 16U)) 772 #define IS_ADC_REGULAR_RANK(RANK) (((RANK) >= 1U) && ((RANK) <= (16U))) 773 #define IS_ADC_REGULAR_DISC_NUMBER(NUMBER) (((NUMBER) >= 1U) && ((NUMBER) <= 8U)) 774 #define IS_ADC_RANGE(RESOLUTION, ADC_VALUE) \ 775 ((((RESOLUTION) == ADC_RESOLUTION_12B) && ((ADC_VALUE) <= 0x0FFFU)) || \ 776 (((RESOLUTION) == ADC_RESOLUTION_10B) && ((ADC_VALUE) <= 0x03FFU)) || \ 777 (((RESOLUTION) == ADC_RESOLUTION_8B) && ((ADC_VALUE) <= 0x00FFU)) || \ 778 (((RESOLUTION) == ADC_RESOLUTION_6B) && ((ADC_VALUE) <= 0x003FU))) 779 780 /** 781 * @brief Set ADC Regular channel sequence length. 782 * @param _NbrOfConversion_ Regular channel sequence length. 783 * @retval None 784 */ 785 #define ADC_SQR1(_NbrOfConversion_) (((_NbrOfConversion_) - (uint8_t)1U) << 20U) 786 787 /** 788 * @brief Set the ADC's sample time for channel numbers between 10 and 18. 789 * @param _SAMPLETIME_ Sample time parameter. 790 * @param _CHANNELNB_ Channel number. 791 * @retval None 792 */ 793 #define ADC_SMPR1(_SAMPLETIME_, _CHANNELNB_) ((_SAMPLETIME_) << (3U * (((uint32_t)((uint16_t)(_CHANNELNB_))) - 10U))) 794 795 /** 796 * @brief Set the ADC's sample time for channel numbers between 0 and 9. 797 * @param _SAMPLETIME_ Sample time parameter. 798 * @param _CHANNELNB_ Channel number. 799 * @retval None 800 */ 801 #define ADC_SMPR2(_SAMPLETIME_, _CHANNELNB_) ((_SAMPLETIME_) << (3U * ((uint32_t)((uint16_t)(_CHANNELNB_))))) 802 803 /** 804 * @brief Set the selected regular channel rank for rank between 1 and 6. 805 * @param _CHANNELNB_ Channel number. 806 * @param _RANKNB_ Rank number. 807 * @retval None 808 */ 809 #define ADC_SQR3_RK(_CHANNELNB_, _RANKNB_) (((uint32_t)((uint16_t)(_CHANNELNB_))) << (5U * ((_RANKNB_) - 1U))) 810 811 /** 812 * @brief Set the selected regular channel rank for rank between 7 and 12. 813 * @param _CHANNELNB_ Channel number. 814 * @param _RANKNB_ Rank number. 815 * @retval None 816 */ 817 #define ADC_SQR2_RK(_CHANNELNB_, _RANKNB_) (((uint32_t)((uint16_t)(_CHANNELNB_))) << (5U * ((_RANKNB_) - 7U))) 818 819 /** 820 * @brief Set the selected regular channel rank for rank between 13 and 16. 821 * @param _CHANNELNB_ Channel number. 822 * @param _RANKNB_ Rank number. 823 * @retval None 824 */ 825 #define ADC_SQR1_RK(_CHANNELNB_, _RANKNB_) (((uint32_t)((uint16_t)(_CHANNELNB_))) << (5U * ((_RANKNB_) - 13U))) 826 827 /** 828 * @brief Enable ADC continuous conversion mode. 829 * @param _CONTINUOUS_MODE_ Continuous mode. 830 * @retval None 831 */ 832 #define ADC_CR2_CONTINUOUS(_CONTINUOUS_MODE_) ((_CONTINUOUS_MODE_) << 1U) 833 834 /** 835 * @brief Configures the number of discontinuous conversions for the regular group channels. 836 * @param _NBR_DISCONTINUOUSCONV_ Number of discontinuous conversions. 837 * @retval None 838 */ 839 #define ADC_CR1_DISCONTINUOUS(_NBR_DISCONTINUOUSCONV_) (((_NBR_DISCONTINUOUSCONV_) - 1U) << ADC_CR1_DISCNUM_Pos) 840 841 /** 842 * @brief Enable ADC scan mode. 843 * @param _SCANCONV_MODE_ Scan conversion mode. 844 * @retval None 845 */ 846 #define ADC_CR1_SCANCONV(_SCANCONV_MODE_) ((_SCANCONV_MODE_) << 8U) 847 848 /** 849 * @brief Enable the ADC end of conversion selection. 850 * @param _EOCSelection_MODE_ End of conversion selection mode. 851 * @retval None 852 */ 853 #define ADC_CR2_EOCSelection(_EOCSelection_MODE_) ((_EOCSelection_MODE_) << 10U) 854 855 /** 856 * @brief Enable the ADC DMA continuous request. 857 * @param _DMAContReq_MODE_ DMA continuous request mode. 858 * @retval None 859 */ 860 #define ADC_CR2_DMAContReq(_DMAContReq_MODE_) ((_DMAContReq_MODE_) << 9U) 861 862 /** 863 * @brief Return resolution bits in CR1 register. 864 * @param __HANDLE__ ADC handle 865 * @retval None 866 */ 867 #define ADC_GET_RESOLUTION(__HANDLE__) (((__HANDLE__)->Instance->CR1) & ADC_CR1_RES) 868 869 /** 870 * @} 871 */ 872 873 /* Private functions ---------------------------------------------------------*/ 874 /** @defgroup ADC_Private_Functions ADC Private Functions 875 * @{ 876 */ 877 878 /** 879 * @} 880 */ 881 882 /** 883 * @} 884 */ 885 886 /** 887 * @} 888 */ 889 890 #ifdef __cplusplus 891 } 892 #endif 893 894 #endif /*__STM32F4xx_ADC_H */ 895 896 897 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 898