001

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

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