Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sat Jun 03 00:22:44 2017 +0000
Revision:
46:b156ef445742
Parent:
18:6a4db94011d3
Final code for internal battlebot competition.

Who changed what in which revision?

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