STM32F479xx HAL User Manual
stm32f4xx_hal_adc.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_hal_adc.h
00004   * @author  MCD Application Team
00005   * @brief   Header file containing functions prototypes of ADC HAL library.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
00010   * All rights reserved.</center></h2>
00011   *
00012   * This software component is licensed by ST under BSD 3-Clause license,
00013   * the "License"; You may not use this file except in compliance with the
00014   * License. You may obtain a copy of the License at:
00015   *                        opensource.org/licenses/BSD-3-Clause
00016   *
00017   ******************************************************************************
00018   */
00019 
00020 /* Define to prevent recursive inclusion -------------------------------------*/
00021 #ifndef __STM32F4xx_ADC_H
00022 #define __STM32F4xx_ADC_H
00023 
00024 #ifdef __cplusplus
00025  extern "C" {
00026 #endif
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "stm32f4xx_hal_def.h"
00030 
00031 /* Include low level driver */
00032 #include "stm32f4xx_ll_adc.h"
00033 
00034 /** @addtogroup STM32F4xx_HAL_Driver
00035   * @{
00036   */
00037 
00038 /** @addtogroup ADC
00039   * @{
00040   */ 
00041 
00042 /* Exported types ------------------------------------------------------------*/
00043 /** @defgroup ADC_Exported_Types ADC Exported Types
00044   * @{
00045   */
00046 
00047 /** 
00048   * @brief  Structure definition of ADC and regular group initialization 
00049   * @note   Parameters of this structure are shared within 2 scopes:
00050   *          - Scope entire ADC (affects regular and injected groups): ClockPrescaler, Resolution, ScanConvMode, DataAlign, ScanConvMode, EOCSelection, LowPowerAutoWait, LowPowerAutoPowerOff, ChannelsBank.
00051   *          - Scope regular group: ContinuousConvMode, NbrOfConversion, DiscontinuousConvMode, NbrOfDiscConversion, ExternalTrigConvEdge, ExternalTrigConv.
00052   * @note   The setting of these parameters with function HAL_ADC_Init() is conditioned to ADC state.
00053   *         ADC state can be either:
00054   *          - For all parameters: ADC disabled
00055   *          - For all parameters except 'Resolution', 'ScanConvMode', 'DiscontinuousConvMode', 'NbrOfDiscConversion' : ADC enabled without conversion on going on regular group.
00056   *          - For parameters 'ExternalTrigConv' and 'ExternalTrigConvEdge': ADC enabled, even with conversion on going.
00057   *         If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed
00058   *         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).
00059   */
00060 typedef struct
00061 {
00062   uint32_t ClockPrescaler;               /*!< Select ADC clock prescaler. The clock is common for 
00063                                               all the ADCs.
00064                                               This parameter can be a value of @ref ADC_ClockPrescaler */
00065   uint32_t Resolution;                   /*!< Configures the ADC resolution.
00066                                               This parameter can be a value of @ref ADC_Resolution */
00067   uint32_t DataAlign;                    /*!< Specifies ADC data alignment to right (MSB on register bit 11 and LSB on register bit 0) (default setting)
00068                                               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).
00069                                               This parameter can be a value of @ref ADC_Data_align */
00070   uint32_t ScanConvMode;                 /*!< Configures the sequencer of regular and injected groups.
00071                                               This parameter can be associated to parameter 'DiscontinuousConvMode' to have main sequence subdivided in successive parts.
00072                                               If disabled: Conversion is performed in single mode (one channel converted, the one defined in rank 1).
00073                                                            Parameters 'NbrOfConversion' and 'InjectedNbrOfConversion' are discarded (equivalent to set to 1).
00074                                               If enabled:  Conversions are performed in sequence mode (multiple ranks defined by 'NbrOfConversion'/'InjectedNbrOfConversion' and each channel rank).
00075                                                            Scan direction is upward: from rank1 to rank 'n'.
00076                                               This parameter can be set to ENABLE or DISABLE */
00077   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.
00078                                               This parameter can be a value of @ref ADC_EOCSelection.
00079                                               Note: For injected group, end of conversion (flag&IT) is raised only at the end of the sequence.
00080                                                     Therefore, if end of conversion is set to end of each conversion, injected group should not be used with interruption (HAL_ADCEx_InjectedStart_IT)
00081                                                     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.
00082                                               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()).
00083                                                     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 */
00084   FunctionalState ContinuousConvMode;    /*!< Specifies whether the conversion is performed in single mode (one conversion) or continuous mode for regular group,
00085                                               after the selected trigger occurred (software start or external trigger).
00086                                               This parameter can be set to ENABLE or DISABLE. */
00087   uint32_t NbrOfConversion;              /*!< Specifies the number of ranks that will be converted within the regular group sequencer.
00088                                               To use regular group sequencer and convert several ranks, parameter 'ScanConvMode' must be enabled.
00089                                               This parameter must be a number between Min_Data = 1 and Max_Data = 16. */
00090   FunctionalState DiscontinuousConvMode; /*!< Specifies whether the conversions sequence of regular group is performed in Complete-sequence/Discontinuous-sequence (main sequence subdivided in successive parts).
00091                                               Discontinuous mode is used only if sequencer is enabled (parameter 'ScanConvMode'). If sequencer is disabled, this parameter is discarded.
00092                                               Discontinuous mode can be enabled only if continuous mode is disabled. If continuous mode is enabled, this parameter setting is discarded.
00093                                               This parameter can be set to ENABLE or DISABLE. */
00094   uint32_t NbrOfDiscConversion;          /*!< Specifies the number of discontinuous conversions in which the  main sequence of regular group (parameter NbrOfConversion) will be subdivided.
00095                                               If parameter 'DiscontinuousConvMode' is disabled, this parameter is discarded.
00096                                               This parameter must be a number between Min_Data = 1 and Max_Data = 8. */
00097   uint32_t ExternalTrigConv;             /*!< Selects the external event used to trigger the conversion start of regular group.
00098                                               If set to ADC_SOFTWARE_START, external triggers are disabled.
00099                                               If set to external trigger source, triggering is on event rising edge by default.
00100                                               This parameter can be a value of @ref ADC_External_trigger_Source_Regular */
00101   uint32_t ExternalTrigConvEdge;         /*!< Selects the external trigger edge of regular group.
00102                                               If trigger is set to ADC_SOFTWARE_START, this parameter is discarded.
00103                                               This parameter can be a value of @ref ADC_External_trigger_edge_Regular */
00104   FunctionalState DMAContinuousRequests; /*!< Specifies whether the DMA requests are performed in one shot mode (DMA transfer stop when number of conversions is reached)
00105                                                                                           or in Continuous mode (DMA transfer unlimited, whatever number of conversions).
00106                                                                                           Note: In continuous mode, DMA must be configured in circular mode. Otherwise an overrun will be triggered when DMA buffer maximum pointer is reached.
00107                                                                                           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).
00108                                                                                           This parameter can be set to ENABLE or DISABLE. */
00109 }ADC_InitTypeDef;
00110 
00111 
00112 
00113 /** 
00114   * @brief  Structure definition of ADC channel for regular group   
00115   * @note   The setting of these parameters with function HAL_ADC_ConfigChannel() is conditioned to ADC state.
00116   *         ADC can be either disabled or enabled without conversion on going on regular group.
00117   */ 
00118 typedef struct 
00119 {
00120   uint32_t Channel;                /*!< Specifies the channel to configure into ADC regular group.
00121                                         This parameter can be a value of @ref ADC_channels */
00122   uint32_t Rank;                   /*!< Specifies the rank in the regular group sequencer.
00123                                         This parameter must be a number between Min_Data = 1 and Max_Data = 16 */
00124   uint32_t SamplingTime;           /*!< Sampling time value to be set for the selected channel.
00125                                         Unit: ADC clock cycles
00126                                         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).
00127                                         This parameter can be a value of @ref ADC_sampling_times
00128                                         Caution: This parameter updates the parameter property of the channel, that can be used into regular and/or injected groups.
00129                                                  If this same channel has been previously configured in the other group (regular/injected), it will be updated to last setting.
00130                                         Note: In case of usage of internal measurement channels (VrefInt/Vbat/TempSensor),
00131                                               sampling time constraints must be respected (sampling time can be adjusted in function of ADC clock frequency and sampling time setting)
00132                                               Refer to device datasheet for timings values, parameters TS_vrefint, TS_temp (values rough order: 4us min). */
00133   uint32_t Offset;                 /*!< Reserved for future use, can be set to 0 */
00134 }ADC_ChannelConfTypeDef;
00135 
00136 /** 
00137   * @brief ADC Configuration multi-mode structure definition  
00138   */ 
00139 typedef struct
00140 {
00141   uint32_t WatchdogMode;      /*!< Configures the ADC analog watchdog mode.
00142                                    This parameter can be a value of @ref ADC_analog_watchdog_selection */
00143   uint32_t HighThreshold;     /*!< Configures the ADC analog watchdog High threshold value.
00144                                    This parameter must be a 12-bit value. */     
00145   uint32_t LowThreshold;      /*!< Configures the ADC analog watchdog High threshold value.
00146                                    This parameter must be a 12-bit value. */
00147   uint32_t Channel;           /*!< Configures ADC channel for the analog watchdog. 
00148                                    This parameter has an effect only if watchdog mode is configured on single channel 
00149                                    This parameter can be a value of @ref ADC_channels */      
00150   FunctionalState ITMode;     /*!< Specifies whether the analog watchdog is configured
00151                                    is interrupt mode or in polling mode.
00152                                    This parameter can be set to ENABLE or DISABLE */
00153   uint32_t WatchdogNumber;    /*!< Reserved for future use, can be set to 0 */
00154 }ADC_AnalogWDGConfTypeDef;
00155 
00156 /** 
00157   * @brief  HAL ADC state machine: ADC states definition (bitfields)
00158   */ 
00159 /* States of ADC global scope */
00160 #define HAL_ADC_STATE_RESET             0x00000000U    /*!< ADC not yet initialized or disabled */
00161 #define HAL_ADC_STATE_READY             0x00000001U    /*!< ADC peripheral ready for use */
00162 #define HAL_ADC_STATE_BUSY_INTERNAL     0x00000002U    /*!< ADC is busy to internal process (initialization, calibration) */
00163 #define HAL_ADC_STATE_TIMEOUT           0x00000004U    /*!< TimeOut occurrence */
00164 
00165 /* States of ADC errors */
00166 #define HAL_ADC_STATE_ERROR_INTERNAL    0x00000010U    /*!< Internal error occurrence */
00167 #define HAL_ADC_STATE_ERROR_CONFIG      0x00000020U    /*!< Configuration error occurrence */
00168 #define HAL_ADC_STATE_ERROR_DMA         0x00000040U    /*!< DMA error occurrence */
00169 
00170 /* States of ADC group regular */
00171 #define HAL_ADC_STATE_REG_BUSY          0x00000100U    /*!< A conversion on group regular is ongoing or can occur (either by continuous mode,
00172                                                             external trigger, low power auto power-on (if feature available), multimode ADC master control (if feature available)) */
00173 #define HAL_ADC_STATE_REG_EOC           0x00000200U    /*!< Conversion data available on group regular */
00174 #define HAL_ADC_STATE_REG_OVR           0x00000400U    /*!< Overrun occurrence */
00175 
00176 /* States of ADC group injected */
00177 #define HAL_ADC_STATE_INJ_BUSY          0x00001000U    /*!< A conversion on group injected is ongoing or can occur (either by auto-injection mode,
00178                                                             external trigger, low power auto power-on (if feature available), multimode ADC master control (if feature available)) */
00179 #define HAL_ADC_STATE_INJ_EOC           0x00002000U    /*!< Conversion data available on group injected */
00180 
00181 /* States of ADC analog watchdogs */
00182 #define HAL_ADC_STATE_AWD1              0x00010000U    /*!< Out-of-window occurrence of analog watchdog 1 */
00183 #define HAL_ADC_STATE_AWD2              0x00020000U    /*!< Not available on STM32F4 device: Out-of-window occurrence of analog watchdog 2 */
00184 #define HAL_ADC_STATE_AWD3              0x00040000U    /*!< Not available on STM32F4 device: Out-of-window occurrence of analog watchdog 3 */
00185 
00186 /* States of ADC multi-mode */
00187 #define HAL_ADC_STATE_MULTIMODE_SLAVE   0x00100000U    /*!< Not available on STM32F4 device: ADC in multimode slave state, controlled by another ADC master ( */
00188 
00189 
00190 /** 
00191   * @brief  ADC handle Structure definition
00192   */ 
00193 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
00194 typedef struct __ADC_HandleTypeDef
00195 #else
00196 typedef struct
00197 #endif
00198 {
00199   ADC_TypeDef                   *Instance;                   /*!< Register base address */
00200 
00201   ADC_InitTypeDef               Init;                        /*!< ADC required parameters */
00202 
00203   __IO uint32_t                 NbrOfCurrentConversionRank;  /*!< ADC number of current conversion rank */
00204 
00205   DMA_HandleTypeDef             *DMA_Handle;                 /*!< Pointer DMA Handler */
00206 
00207   HAL_LockTypeDef               Lock;                        /*!< ADC locking object */
00208 
00209   __IO uint32_t                 State;                       /*!< ADC communication state */
00210 
00211   __IO uint32_t                 ErrorCode;                   /*!< ADC Error code */
00212 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
00213   void (* ConvCpltCallback)(struct __ADC_HandleTypeDef *hadc);              /*!< ADC conversion complete callback */
00214   void (* ConvHalfCpltCallback)(struct __ADC_HandleTypeDef *hadc);          /*!< ADC conversion DMA half-transfer callback */
00215   void (* LevelOutOfWindowCallback)(struct __ADC_HandleTypeDef *hadc);      /*!< ADC analog watchdog 1 callback */
00216   void (* ErrorCallback)(struct __ADC_HandleTypeDef *hadc);                 /*!< ADC error callback */
00217   void (* InjectedConvCpltCallback)(struct __ADC_HandleTypeDef *hadc);      /*!< ADC group injected conversion complete callback */
00218   void (* MspInitCallback)(struct __ADC_HandleTypeDef *hadc);               /*!< ADC Msp Init callback */
00219   void (* MspDeInitCallback)(struct __ADC_HandleTypeDef *hadc);             /*!< ADC Msp DeInit callback */
00220 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
00221 }ADC_HandleTypeDef;
00222 
00223 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
00224 /**
00225   * @brief  HAL ADC Callback ID enumeration definition
00226   */
00227 typedef enum
00228 {
00229   HAL_ADC_CONVERSION_COMPLETE_CB_ID     = 0x00U,  /*!< ADC conversion complete callback ID */
00230   HAL_ADC_CONVERSION_HALF_CB_ID         = 0x01U,  /*!< ADC conversion DMA half-transfer callback ID */
00231   HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID   = 0x02U,  /*!< ADC analog watchdog 1 callback ID */
00232   HAL_ADC_ERROR_CB_ID                   = 0x03U,  /*!< ADC error callback ID */
00233   HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID = 0x04U,  /*!< ADC group injected conversion complete callback ID */
00234   HAL_ADC_MSPINIT_CB_ID                 = 0x05U,  /*!< ADC Msp Init callback ID          */
00235   HAL_ADC_MSPDEINIT_CB_ID               = 0x06U   /*!< ADC Msp DeInit callback ID        */
00236 } HAL_ADC_CallbackIDTypeDef;
00237 
00238 /**
00239   * @brief  HAL ADC Callback pointer definition
00240   */
00241 typedef  void (*pADC_CallbackTypeDef)(ADC_HandleTypeDef *hadc); /*!< pointer to a ADC callback function */
00242 
00243 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
00244 
00245 /**
00246   * @}
00247   */
00248 
00249 /* Exported constants --------------------------------------------------------*/
00250 /** @defgroup ADC_Exported_Constants ADC Exported Constants
00251   * @{
00252   */
00253 
00254 /** @defgroup ADC_Error_Code ADC Error Code
00255   * @{
00256   */
00257 #define HAL_ADC_ERROR_NONE        0x00U   /*!< No error                                              */
00258 #define HAL_ADC_ERROR_INTERNAL    0x01U   /*!< ADC IP internal error: if problem of clocking, 
00259                                                enable/disable, erroneous state                       */
00260 #define HAL_ADC_ERROR_OVR         0x02U   /*!< Overrun error                                         */
00261 #define HAL_ADC_ERROR_DMA         0x04U   /*!< DMA transfer error                                    */
00262 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
00263 #define HAL_ADC_ERROR_INVALID_CALLBACK  (0x10U)   /*!< Invalid Callback error */
00264 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
00265 /**
00266   * @}
00267   */
00268 
00269 
00270 /** @defgroup ADC_ClockPrescaler  ADC Clock Prescaler
00271   * @{
00272   */ 
00273 #define ADC_CLOCK_SYNC_PCLK_DIV2    0x00000000U
00274 #define ADC_CLOCK_SYNC_PCLK_DIV4    ((uint32_t)ADC_CCR_ADCPRE_0)
00275 #define ADC_CLOCK_SYNC_PCLK_DIV6    ((uint32_t)ADC_CCR_ADCPRE_1)
00276 #define ADC_CLOCK_SYNC_PCLK_DIV8    ((uint32_t)ADC_CCR_ADCPRE)
00277 /**
00278   * @}
00279   */ 
00280 
00281 /** @defgroup ADC_delay_between_2_sampling_phases ADC Delay Between 2 Sampling Phases
00282   * @{
00283   */ 
00284 #define ADC_TWOSAMPLINGDELAY_5CYCLES    0x00000000U
00285 #define ADC_TWOSAMPLINGDELAY_6CYCLES    ((uint32_t)ADC_CCR_DELAY_0)
00286 #define ADC_TWOSAMPLINGDELAY_7CYCLES    ((uint32_t)ADC_CCR_DELAY_1)
00287 #define ADC_TWOSAMPLINGDELAY_8CYCLES    ((uint32_t)(ADC_CCR_DELAY_1 | ADC_CCR_DELAY_0))
00288 #define ADC_TWOSAMPLINGDELAY_9CYCLES    ((uint32_t)ADC_CCR_DELAY_2)
00289 #define ADC_TWOSAMPLINGDELAY_10CYCLES   ((uint32_t)(ADC_CCR_DELAY_2 | ADC_CCR_DELAY_0))
00290 #define ADC_TWOSAMPLINGDELAY_11CYCLES   ((uint32_t)(ADC_CCR_DELAY_2 | ADC_CCR_DELAY_1))
00291 #define ADC_TWOSAMPLINGDELAY_12CYCLES   ((uint32_t)(ADC_CCR_DELAY_2 | ADC_CCR_DELAY_1 | ADC_CCR_DELAY_0))
00292 #define ADC_TWOSAMPLINGDELAY_13CYCLES   ((uint32_t)ADC_CCR_DELAY_3)
00293 #define ADC_TWOSAMPLINGDELAY_14CYCLES   ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_0))
00294 #define ADC_TWOSAMPLINGDELAY_15CYCLES   ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_1))
00295 #define ADC_TWOSAMPLINGDELAY_16CYCLES   ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_1 | ADC_CCR_DELAY_0))
00296 #define ADC_TWOSAMPLINGDELAY_17CYCLES   ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_2))
00297 #define ADC_TWOSAMPLINGDELAY_18CYCLES   ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_2 | ADC_CCR_DELAY_0))
00298 #define ADC_TWOSAMPLINGDELAY_19CYCLES   ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_2 | ADC_CCR_DELAY_1))
00299 #define ADC_TWOSAMPLINGDELAY_20CYCLES   ((uint32_t)ADC_CCR_DELAY)
00300 /**
00301   * @}
00302   */ 
00303 
00304 /** @defgroup ADC_Resolution ADC Resolution
00305   * @{
00306   */ 
00307 #define ADC_RESOLUTION_12B  0x00000000U
00308 #define ADC_RESOLUTION_10B  ((uint32_t)ADC_CR1_RES_0)
00309 #define ADC_RESOLUTION_8B   ((uint32_t)ADC_CR1_RES_1)
00310 #define ADC_RESOLUTION_6B   ((uint32_t)ADC_CR1_RES)
00311 /**
00312   * @}
00313   */ 
00314 
00315 /** @defgroup ADC_External_trigger_edge_Regular ADC External Trigger Edge Regular
00316   * @{
00317   */ 
00318 #define ADC_EXTERNALTRIGCONVEDGE_NONE           0x00000000U
00319 #define ADC_EXTERNALTRIGCONVEDGE_RISING         ((uint32_t)ADC_CR2_EXTEN_0)
00320 #define ADC_EXTERNALTRIGCONVEDGE_FALLING        ((uint32_t)ADC_CR2_EXTEN_1)
00321 #define ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING  ((uint32_t)ADC_CR2_EXTEN)
00322 /**
00323   * @}
00324   */ 
00325 
00326 /** @defgroup ADC_External_trigger_Source_Regular ADC External Trigger Source Regular
00327   * @{
00328   */
00329 /* Note: Parameter ADC_SOFTWARE_START is a software parameter used for        */
00330 /*       compatibility with other STM32 devices.                              */
00331 #define ADC_EXTERNALTRIGCONV_T1_CC1    0x00000000U
00332 #define ADC_EXTERNALTRIGCONV_T1_CC2    ((uint32_t)ADC_CR2_EXTSEL_0)
00333 #define ADC_EXTERNALTRIGCONV_T1_CC3    ((uint32_t)ADC_CR2_EXTSEL_1)
00334 #define ADC_EXTERNALTRIGCONV_T2_CC2    ((uint32_t)(ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))
00335 #define ADC_EXTERNALTRIGCONV_T2_CC3    ((uint32_t)ADC_CR2_EXTSEL_2)
00336 #define ADC_EXTERNALTRIGCONV_T2_CC4    ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_0))
00337 #define ADC_EXTERNALTRIGCONV_T2_TRGO   ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1))
00338 #define ADC_EXTERNALTRIGCONV_T3_CC1    ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))
00339 #define ADC_EXTERNALTRIGCONV_T3_TRGO   ((uint32_t)ADC_CR2_EXTSEL_3)
00340 #define ADC_EXTERNALTRIGCONV_T4_CC4    ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_0))
00341 #define ADC_EXTERNALTRIGCONV_T5_CC1    ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_1))
00342 #define ADC_EXTERNALTRIGCONV_T5_CC2    ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))
00343 #define ADC_EXTERNALTRIGCONV_T5_CC3    ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2))
00344 #define ADC_EXTERNALTRIGCONV_T8_CC1    ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_0))
00345 #define ADC_EXTERNALTRIGCONV_T8_TRGO   ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1))
00346 #define ADC_EXTERNALTRIGCONV_Ext_IT11  ((uint32_t)ADC_CR2_EXTSEL)
00347 #define ADC_SOFTWARE_START             ((uint32_t)ADC_CR2_EXTSEL + 1U)
00348 /**
00349   * @}
00350   */ 
00351 
00352 /** @defgroup ADC_Data_align ADC Data Align
00353   * @{
00354   */ 
00355 #define ADC_DATAALIGN_RIGHT      0x00000000U
00356 #define ADC_DATAALIGN_LEFT       ((uint32_t)ADC_CR2_ALIGN)
00357 /**
00358   * @}
00359   */ 
00360 
00361 /** @defgroup ADC_channels  ADC Common Channels
00362   * @{
00363   */ 
00364 #define ADC_CHANNEL_0           0x00000000U
00365 #define ADC_CHANNEL_1           ((uint32_t)ADC_CR1_AWDCH_0)
00366 #define ADC_CHANNEL_2           ((uint32_t)ADC_CR1_AWDCH_1)
00367 #define ADC_CHANNEL_3           ((uint32_t)(ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0))
00368 #define ADC_CHANNEL_4           ((uint32_t)ADC_CR1_AWDCH_2)
00369 #define ADC_CHANNEL_5           ((uint32_t)(ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_0))
00370 #define ADC_CHANNEL_6           ((uint32_t)(ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1))
00371 #define ADC_CHANNEL_7           ((uint32_t)(ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0))
00372 #define ADC_CHANNEL_8           ((uint32_t)ADC_CR1_AWDCH_3)
00373 #define ADC_CHANNEL_9           ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_0))
00374 #define ADC_CHANNEL_10          ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_1))
00375 #define ADC_CHANNEL_11          ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0))
00376 #define ADC_CHANNEL_12          ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2))
00377 #define ADC_CHANNEL_13          ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_0))
00378 #define ADC_CHANNEL_14          ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1))
00379 #define ADC_CHANNEL_15          ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0))
00380 #define ADC_CHANNEL_16          ((uint32_t)ADC_CR1_AWDCH_4)
00381 #define ADC_CHANNEL_17          ((uint32_t)(ADC_CR1_AWDCH_4 | ADC_CR1_AWDCH_0))
00382 #define ADC_CHANNEL_18          ((uint32_t)(ADC_CR1_AWDCH_4 | ADC_CR1_AWDCH_1))
00383 
00384 #define ADC_CHANNEL_VREFINT     ((uint32_t)ADC_CHANNEL_17)
00385 #define ADC_CHANNEL_VBAT        ((uint32_t)ADC_CHANNEL_18)
00386 /**
00387   * @}
00388   */ 
00389 
00390 /** @defgroup ADC_sampling_times  ADC Sampling Times
00391   * @{
00392   */ 
00393 #define ADC_SAMPLETIME_3CYCLES    0x00000000U
00394 #define ADC_SAMPLETIME_15CYCLES   ((uint32_t)ADC_SMPR1_SMP10_0)
00395 #define ADC_SAMPLETIME_28CYCLES   ((uint32_t)ADC_SMPR1_SMP10_1)
00396 #define ADC_SAMPLETIME_56CYCLES   ((uint32_t)(ADC_SMPR1_SMP10_1 | ADC_SMPR1_SMP10_0))
00397 #define ADC_SAMPLETIME_84CYCLES   ((uint32_t)ADC_SMPR1_SMP10_2)
00398 #define ADC_SAMPLETIME_112CYCLES  ((uint32_t)(ADC_SMPR1_SMP10_2 | ADC_SMPR1_SMP10_0))
00399 #define ADC_SAMPLETIME_144CYCLES  ((uint32_t)(ADC_SMPR1_SMP10_2 | ADC_SMPR1_SMP10_1))
00400 #define ADC_SAMPLETIME_480CYCLES  ((uint32_t)ADC_SMPR1_SMP10)
00401 /**
00402   * @}
00403   */ 
00404 
00405   /** @defgroup ADC_EOCSelection ADC EOC Selection
00406   * @{
00407   */ 
00408 #define ADC_EOC_SEQ_CONV              0x00000000U
00409 #define ADC_EOC_SINGLE_CONV           0x00000001U
00410 #define ADC_EOC_SINGLE_SEQ_CONV       0x00000002U  /*!< reserved for future use */
00411 /**
00412   * @}
00413   */ 
00414 
00415 /** @defgroup ADC_Event_type ADC Event Type
00416   * @{
00417   */ 
00418 #define ADC_AWD_EVENT             ((uint32_t)ADC_FLAG_AWD)
00419 #define ADC_OVR_EVENT             ((uint32_t)ADC_FLAG_OVR)
00420 /**
00421   * @}
00422   */
00423 
00424 /** @defgroup ADC_analog_watchdog_selection ADC Analog Watchdog Selection
00425   * @{
00426   */ 
00427 #define ADC_ANALOGWATCHDOG_SINGLE_REG         ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_AWDEN))
00428 #define ADC_ANALOGWATCHDOG_SINGLE_INJEC       ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_JAWDEN))
00429 #define ADC_ANALOGWATCHDOG_SINGLE_REGINJEC    ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_AWDEN | ADC_CR1_JAWDEN))
00430 #define ADC_ANALOGWATCHDOG_ALL_REG            ((uint32_t)ADC_CR1_AWDEN)
00431 #define ADC_ANALOGWATCHDOG_ALL_INJEC          ((uint32_t)ADC_CR1_JAWDEN)
00432 #define ADC_ANALOGWATCHDOG_ALL_REGINJEC       ((uint32_t)(ADC_CR1_AWDEN | ADC_CR1_JAWDEN))
00433 #define ADC_ANALOGWATCHDOG_NONE               0x00000000U
00434 /**
00435   * @}
00436   */ 
00437     
00438 /** @defgroup ADC_interrupts_definition ADC Interrupts Definition
00439   * @{
00440   */ 
00441 #define ADC_IT_EOC      ((uint32_t)ADC_CR1_EOCIE)
00442 #define ADC_IT_AWD      ((uint32_t)ADC_CR1_AWDIE)
00443 #define ADC_IT_JEOC     ((uint32_t)ADC_CR1_JEOCIE)
00444 #define ADC_IT_OVR      ((uint32_t)ADC_CR1_OVRIE)
00445 /**
00446   * @}
00447   */ 
00448     
00449 /** @defgroup ADC_flags_definition ADC Flags Definition
00450   * @{
00451   */ 
00452 #define ADC_FLAG_AWD    ((uint32_t)ADC_SR_AWD)
00453 #define ADC_FLAG_EOC    ((uint32_t)ADC_SR_EOC)
00454 #define ADC_FLAG_JEOC   ((uint32_t)ADC_SR_JEOC)
00455 #define ADC_FLAG_JSTRT  ((uint32_t)ADC_SR_JSTRT)
00456 #define ADC_FLAG_STRT   ((uint32_t)ADC_SR_STRT)
00457 #define ADC_FLAG_OVR    ((uint32_t)ADC_SR_OVR)
00458 /**
00459   * @}
00460   */ 
00461 
00462 /** @defgroup ADC_channels_type ADC Channels Type
00463   * @{
00464   */ 
00465 #define ADC_ALL_CHANNELS      0x00000001U
00466 #define ADC_REGULAR_CHANNELS  0x00000002U /*!< reserved for future use */
00467 #define ADC_INJECTED_CHANNELS 0x00000003U /*!< reserved for future use */
00468 /**
00469   * @}
00470   */
00471 
00472 /**
00473   * @}
00474   */ 
00475 
00476 /* Exported macro ------------------------------------------------------------*/
00477 /** @defgroup ADC_Exported_Macros ADC Exported Macros
00478   * @{
00479   */
00480 
00481 /** @brief Reset ADC handle state
00482   * @param  __HANDLE__ ADC handle
00483   * @retval None
00484   */
00485 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
00486 #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__)                               \
00487   do{                                                                          \
00488      (__HANDLE__)->State = HAL_ADC_STATE_RESET;                               \
00489      (__HANDLE__)->MspInitCallback = NULL;                                     \
00490      (__HANDLE__)->MspDeInitCallback = NULL;                                   \
00491     } while(0)
00492 #else
00493 #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__)                               \
00494   ((__HANDLE__)->State = HAL_ADC_STATE_RESET)
00495 #endif
00496 
00497 /**
00498   * @brief  Enable the ADC peripheral.
00499   * @param  __HANDLE__ ADC handle
00500   * @retval None
00501   */
00502 #define __HAL_ADC_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR2 |=  ADC_CR2_ADON)
00503 
00504 /**
00505   * @brief  Disable the ADC peripheral.
00506   * @param  __HANDLE__ ADC handle
00507   * @retval None
00508   */
00509 #define __HAL_ADC_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR2 &=  ~ADC_CR2_ADON)
00510 
00511 /**
00512   * @brief  Enable the ADC end of conversion interrupt.
00513   * @param  __HANDLE__ specifies the ADC Handle.
00514   * @param  __INTERRUPT__ ADC Interrupt.
00515   * @retval None
00516   */
00517 #define __HAL_ADC_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR1) |= (__INTERRUPT__))
00518 
00519 /**
00520   * @brief  Disable the ADC end of conversion interrupt.
00521   * @param  __HANDLE__ specifies the ADC Handle.
00522   * @param  __INTERRUPT__ ADC interrupt.
00523   * @retval None
00524   */
00525 #define __HAL_ADC_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR1) &= ~(__INTERRUPT__))
00526 
00527 /** @brief  Check if the specified ADC interrupt source is enabled or disabled.
00528   * @param  __HANDLE__ specifies the ADC Handle.
00529   * @param  __INTERRUPT__ specifies the ADC interrupt source to check.
00530   * @retval The new state of __IT__ (TRUE or FALSE).
00531   */
00532 #define __HAL_ADC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)  (((__HANDLE__)->Instance->CR1 & (__INTERRUPT__)) == (__INTERRUPT__))
00533 
00534 /**
00535   * @brief  Clear the ADC's pending flags.
00536   * @param  __HANDLE__ specifies the ADC Handle.
00537   * @param  __FLAG__ ADC flag.
00538   * @retval None
00539   */
00540 #define __HAL_ADC_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR) = ~(__FLAG__))
00541 
00542 /**
00543   * @brief  Get the selected ADC's flag status.
00544   * @param  __HANDLE__ specifies the ADC Handle.
00545   * @param  __FLAG__ ADC flag.
00546   * @retval None
00547   */
00548 #define __HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
00549 
00550 /**
00551   * @}
00552   */
00553 
00554 /* Include ADC HAL Extension module */
00555 #include "stm32f4xx_hal_adc_ex.h"
00556 
00557 /* Exported functions --------------------------------------------------------*/
00558 /** @addtogroup ADC_Exported_Functions
00559   * @{
00560   */
00561 
00562 /** @addtogroup ADC_Exported_Functions_Group1
00563   * @{
00564   */
00565 /* Initialization/de-initialization functions ***********************************/
00566 HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc);
00567 HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef *hadc);
00568 void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc);
00569 void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc);
00570 
00571 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
00572 /* Callbacks Register/UnRegister functions  ***********************************/
00573 HAL_StatusTypeDef HAL_ADC_RegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID, pADC_CallbackTypeDef pCallback);
00574 HAL_StatusTypeDef HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID);
00575 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
00576 /**
00577   * @}
00578   */
00579 
00580 /** @addtogroup ADC_Exported_Functions_Group2
00581   * @{
00582   */
00583 /* I/O operation functions ******************************************************/
00584 HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc);
00585 HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc);
00586 HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout);
00587 
00588 HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout);
00589 
00590 HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc);
00591 HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc);
00592 
00593 void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc);
00594 
00595 HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length);
00596 HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc);
00597 
00598 uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc);
00599 
00600 void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc);
00601 void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc);
00602 void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc);
00603 void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc);
00604 /**
00605   * @}
00606   */
00607 
00608 /** @addtogroup ADC_Exported_Functions_Group3
00609   * @{
00610   */
00611 /* Peripheral Control functions *************************************************/
00612 HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig);
00613 HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig);
00614 /**
00615   * @}
00616   */
00617 
00618 /** @addtogroup ADC_Exported_Functions_Group4
00619   * @{
00620   */
00621 /* Peripheral State functions ***************************************************/
00622 uint32_t HAL_ADC_GetState(ADC_HandleTypeDef* hadc);
00623 uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc);
00624 /**
00625   * @}
00626   */
00627 
00628 /**
00629   * @}
00630   */
00631 /* Private types -------------------------------------------------------------*/
00632 /* Private variables ---------------------------------------------------------*/
00633 /* Private constants ---------------------------------------------------------*/
00634 /** @defgroup ADC_Private_Constants ADC Private Constants
00635   * @{
00636   */
00637 /* Delay for ADC stabilization time.                                        */
00638 /* Maximum delay is 1us (refer to device datasheet, parameter tSTAB).       */
00639 /* Unit: us                                                                 */
00640 #define ADC_STAB_DELAY_US               3U
00641 /* Delay for temperature sensor stabilization time.                         */
00642 /* Maximum delay is 10us (refer to device datasheet, parameter tSTART).     */
00643 /* Unit: us                                                                 */
00644 #define ADC_TEMPSENSOR_DELAY_US         10U
00645 /**
00646   * @}
00647   */
00648 
00649 /* Private macro ------------------------------------------------------------*/
00650 
00651 /** @defgroup ADC_Private_Macros ADC Private Macros
00652   * @{
00653   */
00654 /* Macro reserved for internal HAL driver usage, not intended to be used in
00655    code of final user */
00656 
00657 /**
00658   * @brief Verification of ADC state: enabled or disabled
00659   * @param __HANDLE__ ADC handle
00660   * @retval SET (ADC enabled) or RESET (ADC disabled)
00661   */
00662 #define ADC_IS_ENABLE(__HANDLE__)                                              \
00663   ((( ((__HANDLE__)->Instance->SR & ADC_SR_ADONS) == ADC_SR_ADONS )            \
00664   ) ? SET : RESET)
00665 
00666 /**
00667   * @brief Test if conversion trigger of regular group is software start
00668   *        or external trigger.
00669   * @param __HANDLE__ ADC handle
00670   * @retval SET (software start) or RESET (external trigger)
00671   */
00672 #define ADC_IS_SOFTWARE_START_REGULAR(__HANDLE__)                              \
00673   (((__HANDLE__)->Instance->CR2 & ADC_CR2_EXTEN) == RESET)
00674 
00675 /**
00676   * @brief Test if conversion trigger of injected group is software start
00677   *        or external trigger.
00678   * @param __HANDLE__ ADC handle
00679   * @retval SET (software start) or RESET (external trigger)
00680   */
00681 #define ADC_IS_SOFTWARE_START_INJECTED(__HANDLE__)                             \
00682   (((__HANDLE__)->Instance->CR2 & ADC_CR2_JEXTEN) == RESET)
00683 
00684 /**
00685   * @brief Simultaneously clears and sets specific bits of the handle State
00686   * @note: ADC_STATE_CLR_SET() macro is merely aliased to generic macro MODIFY_REG(),
00687   *        the first parameter is the ADC handle State, the second parameter is the
00688   *        bit field to clear, the third and last parameter is the bit field to set.
00689   * @retval None
00690   */
00691 #define ADC_STATE_CLR_SET MODIFY_REG
00692 
00693 /**
00694   * @brief Clear ADC error code (set it to error code: "no error")
00695   * @param __HANDLE__ ADC handle
00696   * @retval None
00697   */
00698 #define ADC_CLEAR_ERRORCODE(__HANDLE__)                                        \
00699   ((__HANDLE__)->ErrorCode = HAL_ADC_ERROR_NONE)
00700 
00701     
00702 #define IS_ADC_CLOCKPRESCALER(ADC_CLOCK)     (((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV2) || \
00703                                               ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV4) || \
00704                                               ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV6) || \
00705                                               ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV8))
00706 #define IS_ADC_SAMPLING_DELAY(DELAY) (((DELAY) == ADC_TWOSAMPLINGDELAY_5CYCLES)  || \
00707                                       ((DELAY) == ADC_TWOSAMPLINGDELAY_6CYCLES)  || \
00708                                       ((DELAY) == ADC_TWOSAMPLINGDELAY_7CYCLES)  || \
00709                                       ((DELAY) == ADC_TWOSAMPLINGDELAY_8CYCLES)  || \
00710                                       ((DELAY) == ADC_TWOSAMPLINGDELAY_9CYCLES)  || \
00711                                       ((DELAY) == ADC_TWOSAMPLINGDELAY_10CYCLES) || \
00712                                       ((DELAY) == ADC_TWOSAMPLINGDELAY_11CYCLES) || \
00713                                       ((DELAY) == ADC_TWOSAMPLINGDELAY_12CYCLES) || \
00714                                       ((DELAY) == ADC_TWOSAMPLINGDELAY_13CYCLES) || \
00715                                       ((DELAY) == ADC_TWOSAMPLINGDELAY_14CYCLES) || \
00716                                       ((DELAY) == ADC_TWOSAMPLINGDELAY_15CYCLES) || \
00717                                       ((DELAY) == ADC_TWOSAMPLINGDELAY_16CYCLES) || \
00718                                       ((DELAY) == ADC_TWOSAMPLINGDELAY_17CYCLES) || \
00719                                       ((DELAY) == ADC_TWOSAMPLINGDELAY_18CYCLES) || \
00720                                       ((DELAY) == ADC_TWOSAMPLINGDELAY_19CYCLES) || \
00721                                       ((DELAY) == ADC_TWOSAMPLINGDELAY_20CYCLES))
00722 #define IS_ADC_RESOLUTION(RESOLUTION) (((RESOLUTION) == ADC_RESOLUTION_12B) || \
00723                                        ((RESOLUTION) == ADC_RESOLUTION_10B) || \
00724                                        ((RESOLUTION) == ADC_RESOLUTION_8B)  || \
00725                                        ((RESOLUTION) == ADC_RESOLUTION_6B))
00726 #define IS_ADC_EXT_TRIG_EDGE(EDGE) (((EDGE) == ADC_EXTERNALTRIGCONVEDGE_NONE)    || \
00727                                     ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISING)  || \
00728                                     ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_FALLING) || \
00729                                     ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING))
00730 #define IS_ADC_EXT_TRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC1)  || \
00731                                   ((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC2)  || \
00732                                   ((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC3)  || \
00733                                   ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC2)  || \
00734                                   ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC3)  || \
00735                                   ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC4)  || \
00736                                   ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_TRGO) || \
00737                                   ((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_CC1)  || \
00738                                   ((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO) || \
00739                                   ((REGTRIG) == ADC_EXTERNALTRIGCONV_T4_CC4)  || \
00740                                   ((REGTRIG) == ADC_EXTERNALTRIGCONV_T5_CC1)  || \
00741                                   ((REGTRIG) == ADC_EXTERNALTRIGCONV_T5_CC2)  || \
00742                                   ((REGTRIG) == ADC_EXTERNALTRIGCONV_T5_CC3)  || \
00743                                   ((REGTRIG) == ADC_EXTERNALTRIGCONV_T8_CC1)  || \
00744                                   ((REGTRIG) == ADC_EXTERNALTRIGCONV_T8_TRGO) || \
00745                                   ((REGTRIG) == ADC_EXTERNALTRIGCONV_Ext_IT11)|| \
00746                                   ((REGTRIG) == ADC_SOFTWARE_START))
00747 #define IS_ADC_DATA_ALIGN(ALIGN) (((ALIGN) == ADC_DATAALIGN_RIGHT) || \
00748                                   ((ALIGN) == ADC_DATAALIGN_LEFT))
00749 #define IS_ADC_SAMPLE_TIME(TIME) (((TIME) == ADC_SAMPLETIME_3CYCLES)   || \
00750                                   ((TIME) == ADC_SAMPLETIME_15CYCLES)  || \
00751                                   ((TIME) == ADC_SAMPLETIME_28CYCLES)  || \
00752                                   ((TIME) == ADC_SAMPLETIME_56CYCLES)  || \
00753                                   ((TIME) == ADC_SAMPLETIME_84CYCLES)  || \
00754                                   ((TIME) == ADC_SAMPLETIME_112CYCLES) || \
00755                                   ((TIME) == ADC_SAMPLETIME_144CYCLES) || \
00756                                   ((TIME) == ADC_SAMPLETIME_480CYCLES))
00757 #define IS_ADC_EOCSelection(EOCSelection) (((EOCSelection) == ADC_EOC_SINGLE_CONV)   || \
00758                                            ((EOCSelection) == ADC_EOC_SEQ_CONV)  || \
00759                                            ((EOCSelection) == ADC_EOC_SINGLE_SEQ_CONV))
00760 #define IS_ADC_EVENT_TYPE(EVENT) (((EVENT) == ADC_AWD_EVENT) || \
00761                                   ((EVENT) == ADC_OVR_EVENT))
00762 #define IS_ADC_ANALOG_WATCHDOG(WATCHDOG) (((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_REG)        || \
00763                                           ((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_INJEC)      || \
00764                                           ((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_REGINJEC)   || \
00765                                           ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_REG)           || \
00766                                           ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_INJEC)         || \
00767                                           ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_REGINJEC)      || \
00768                                           ((WATCHDOG) == ADC_ANALOGWATCHDOG_NONE))
00769 #define IS_ADC_CHANNELS_TYPE(CHANNEL_TYPE) (((CHANNEL_TYPE) == ADC_ALL_CHANNELS) || \
00770                                             ((CHANNEL_TYPE) == ADC_REGULAR_CHANNELS) || \
00771                                             ((CHANNEL_TYPE) == ADC_INJECTED_CHANNELS))
00772 #define IS_ADC_THRESHOLD(THRESHOLD) ((THRESHOLD) <= 0xFFFU)
00773 
00774 #define IS_ADC_REGULAR_LENGTH(LENGTH) (((LENGTH) >= 1U) && ((LENGTH) <= 16U))
00775 #define IS_ADC_REGULAR_RANK(RANK) (((RANK) >= 1U) && ((RANK) <= (16U)))
00776 #define IS_ADC_REGULAR_DISC_NUMBER(NUMBER) (((NUMBER) >= 1U) && ((NUMBER) <= 8U))
00777 #define IS_ADC_RANGE(RESOLUTION, ADC_VALUE)                                     \
00778    ((((RESOLUTION) == ADC_RESOLUTION_12B) && ((ADC_VALUE) <= 0x0FFFU)) || \
00779     (((RESOLUTION) == ADC_RESOLUTION_10B) && ((ADC_VALUE) <= 0x03FFU)) || \
00780     (((RESOLUTION) == ADC_RESOLUTION_8B)  && ((ADC_VALUE) <= 0x00FFU)) || \
00781     (((RESOLUTION) == ADC_RESOLUTION_6B)  && ((ADC_VALUE) <= 0x003FU)))
00782 
00783 /**
00784   * @brief  Set ADC Regular channel sequence length.
00785   * @param  _NbrOfConversion_ Regular channel sequence length. 
00786   * @retval None
00787   */
00788 #define ADC_SQR1(_NbrOfConversion_) (((_NbrOfConversion_) - (uint8_t)1U) << 20U)
00789 
00790 /**
00791   * @brief  Set the ADC's sample time for channel numbers between 10 and 18.
00792   * @param  _SAMPLETIME_ Sample time parameter.
00793   * @param  _CHANNELNB_ Channel number.  
00794   * @retval None
00795   */
00796 #define ADC_SMPR1(_SAMPLETIME_, _CHANNELNB_) ((_SAMPLETIME_) << (3U * (((uint32_t)((uint16_t)(_CHANNELNB_))) - 10U)))
00797 
00798 /**
00799   * @brief  Set the ADC's sample time for channel numbers between 0 and 9.
00800   * @param  _SAMPLETIME_ Sample time parameter.
00801   * @param  _CHANNELNB_ Channel number.  
00802   * @retval None
00803   */
00804 #define ADC_SMPR2(_SAMPLETIME_, _CHANNELNB_) ((_SAMPLETIME_) << (3U * ((uint32_t)((uint16_t)(_CHANNELNB_)))))
00805 
00806 /**
00807   * @brief  Set the selected regular channel rank for rank between 1 and 6.
00808   * @param  _CHANNELNB_ Channel number.
00809   * @param  _RANKNB_ Rank number.    
00810   * @retval None
00811   */
00812 #define ADC_SQR3_RK(_CHANNELNB_, _RANKNB_) (((uint32_t)((uint16_t)(_CHANNELNB_))) << (5U * ((_RANKNB_) - 1U)))
00813 
00814 /**
00815   * @brief  Set the selected regular channel rank for rank between 7 and 12.
00816   * @param  _CHANNELNB_ Channel number.
00817   * @param  _RANKNB_ Rank number.    
00818   * @retval None
00819   */
00820 #define ADC_SQR2_RK(_CHANNELNB_, _RANKNB_) (((uint32_t)((uint16_t)(_CHANNELNB_))) << (5U * ((_RANKNB_) - 7U)))
00821 
00822 /**
00823   * @brief  Set the selected regular channel rank for rank between 13 and 16.
00824   * @param  _CHANNELNB_ Channel number.
00825   * @param  _RANKNB_ Rank number.    
00826   * @retval None
00827   */
00828 #define ADC_SQR1_RK(_CHANNELNB_, _RANKNB_) (((uint32_t)((uint16_t)(_CHANNELNB_))) << (5U * ((_RANKNB_) - 13U)))
00829 
00830 /**
00831   * @brief  Enable ADC continuous conversion mode.
00832   * @param  _CONTINUOUS_MODE_ Continuous mode.
00833   * @retval None
00834   */
00835 #define ADC_CR2_CONTINUOUS(_CONTINUOUS_MODE_) ((_CONTINUOUS_MODE_) << 1U)
00836 
00837 /**
00838   * @brief  Configures the number of discontinuous conversions for the regular group channels.
00839   * @param  _NBR_DISCONTINUOUSCONV_ Number of discontinuous conversions.
00840   * @retval None
00841   */
00842 #define ADC_CR1_DISCONTINUOUS(_NBR_DISCONTINUOUSCONV_) (((_NBR_DISCONTINUOUSCONV_) - 1U) << ADC_CR1_DISCNUM_Pos)
00843 
00844 /**
00845   * @brief  Enable ADC scan mode.
00846   * @param  _SCANCONV_MODE_ Scan conversion mode.
00847   * @retval None
00848   */
00849 #define ADC_CR1_SCANCONV(_SCANCONV_MODE_) ((_SCANCONV_MODE_) << 8U)
00850 
00851 /**
00852   * @brief  Enable the ADC end of conversion selection.
00853   * @param  _EOCSelection_MODE_ End of conversion selection mode.
00854   * @retval None
00855   */
00856 #define ADC_CR2_EOCSelection(_EOCSelection_MODE_) ((_EOCSelection_MODE_) << 10U)
00857 
00858 /**
00859   * @brief  Enable the ADC DMA continuous request.
00860   * @param  _DMAContReq_MODE_ DMA continuous request mode.
00861   * @retval None
00862   */
00863 #define ADC_CR2_DMAContReq(_DMAContReq_MODE_) ((_DMAContReq_MODE_) << 9U)
00864 
00865 /**
00866   * @brief Return resolution bits in CR1 register.
00867   * @param __HANDLE__ ADC handle
00868   * @retval None
00869   */
00870 #define ADC_GET_RESOLUTION(__HANDLE__) (((__HANDLE__)->Instance->CR1) & ADC_CR1_RES)
00871 
00872 /**
00873   * @}
00874   */
00875 
00876 /* Private functions ---------------------------------------------------------*/
00877 /** @defgroup ADC_Private_Functions ADC Private Functions
00878   * @{
00879   */
00880 
00881 /**
00882   * @}
00883   */
00884 
00885 /**
00886   * @}
00887   */ 
00888 
00889 /**
00890   * @}
00891   */
00892 
00893 #ifdef __cplusplus
00894 }
00895 #endif
00896 
00897 #endif /*__STM32F4xx_ADC_H */
00898 
00899 
00900 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/