.

Dependents:   RTC

Committer:
jhon309
Date:
Thu Aug 13 00:20:09 2015 +0000
Revision:
0:88e313c910d0
RTC Example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jhon309 0:88e313c910d0 1 /**
jhon309 0:88e313c910d0 2 ******************************************************************************
jhon309 0:88e313c910d0 3 * @file stm32f0xx_hal_adc.h
jhon309 0:88e313c910d0 4 * @author MCD Application Team
jhon309 0:88e313c910d0 5 * @version V1.2.0
jhon309 0:88e313c910d0 6 * @date 11-December-2014
jhon309 0:88e313c910d0 7 * @brief Header file containing functions prototypes of ADC HAL library.
jhon309 0:88e313c910d0 8 ******************************************************************************
jhon309 0:88e313c910d0 9 * @attention
jhon309 0:88e313c910d0 10 *
jhon309 0:88e313c910d0 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
jhon309 0:88e313c910d0 12 *
jhon309 0:88e313c910d0 13 * Redistribution and use in source and binary forms, with or without modification,
jhon309 0:88e313c910d0 14 * are permitted provided that the following conditions are met:
jhon309 0:88e313c910d0 15 * 1. Redistributions of source code must retain the above copyright notice,
jhon309 0:88e313c910d0 16 * this list of conditions and the following disclaimer.
jhon309 0:88e313c910d0 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
jhon309 0:88e313c910d0 18 * this list of conditions and the following disclaimer in the documentation
jhon309 0:88e313c910d0 19 * and/or other materials provided with the distribution.
jhon309 0:88e313c910d0 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
jhon309 0:88e313c910d0 21 * may be used to endorse or promote products derived from this software
jhon309 0:88e313c910d0 22 * without specific prior written permission.
jhon309 0:88e313c910d0 23 *
jhon309 0:88e313c910d0 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
jhon309 0:88e313c910d0 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
jhon309 0:88e313c910d0 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
jhon309 0:88e313c910d0 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
jhon309 0:88e313c910d0 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
jhon309 0:88e313c910d0 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
jhon309 0:88e313c910d0 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
jhon309 0:88e313c910d0 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
jhon309 0:88e313c910d0 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
jhon309 0:88e313c910d0 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
jhon309 0:88e313c910d0 34 *
jhon309 0:88e313c910d0 35 ******************************************************************************
jhon309 0:88e313c910d0 36 */
jhon309 0:88e313c910d0 37
jhon309 0:88e313c910d0 38 /* Define to prevent recursive inclusion -------------------------------------*/
jhon309 0:88e313c910d0 39 #ifndef __STM32F0xx_HAL_ADC_H
jhon309 0:88e313c910d0 40 #define __STM32F0xx_HAL_ADC_H
jhon309 0:88e313c910d0 41
jhon309 0:88e313c910d0 42 #ifdef __cplusplus
jhon309 0:88e313c910d0 43 extern "C" {
jhon309 0:88e313c910d0 44 #endif
jhon309 0:88e313c910d0 45
jhon309 0:88e313c910d0 46 /* Includes ------------------------------------------------------------------*/
jhon309 0:88e313c910d0 47 #include "stm32f0xx_hal_def.h"
jhon309 0:88e313c910d0 48
jhon309 0:88e313c910d0 49 /** @addtogroup STM32F0xx_HAL_Driver
jhon309 0:88e313c910d0 50 * @{
jhon309 0:88e313c910d0 51 */
jhon309 0:88e313c910d0 52
jhon309 0:88e313c910d0 53 /** @addtogroup ADC
jhon309 0:88e313c910d0 54 * @{
jhon309 0:88e313c910d0 55 */
jhon309 0:88e313c910d0 56
jhon309 0:88e313c910d0 57 /* Exported types ------------------------------------------------------------*/
jhon309 0:88e313c910d0 58 /** @defgroup ADC_Exported_Types ADC Exported Types
jhon309 0:88e313c910d0 59 * @{
jhon309 0:88e313c910d0 60 */
jhon309 0:88e313c910d0 61
jhon309 0:88e313c910d0 62 /**
jhon309 0:88e313c910d0 63 * @brief Structure definition of ADC initialization and regular group
jhon309 0:88e313c910d0 64 * @note The setting of these parameters with function HAL_ADC_Init() is conditioned to ADC state.
jhon309 0:88e313c910d0 65 * ADC state can be either:
jhon309 0:88e313c910d0 66 * - For all parameters: ADC disabled (this is the only possible ADC state to modify parameter 'ClockPrescaler')
jhon309 0:88e313c910d0 67 * - For all parameters except 'ClockPrescaler': ADC enabled without conversion on going on regular group.
jhon309 0:88e313c910d0 68 * If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed
jhon309 0:88e313c910d0 69 * 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).
jhon309 0:88e313c910d0 70 */
jhon309 0:88e313c910d0 71 typedef struct
jhon309 0:88e313c910d0 72 {
jhon309 0:88e313c910d0 73 uint32_t ClockPrescaler; /*!< Select ADC clock source (synchronous clock derived from APB clock or asynchronous clock derived from ADC dedicated HSI RC oscillator 14MHz) and clock prescaler.
jhon309 0:88e313c910d0 74 This parameter can be a value of @ref ADC_ClockPrescaler
jhon309 0:88e313c910d0 75 Note: In case of usage of the ADC dedicated HSI RC oscillator, it must be preliminarily enabled at RCC top level.
jhon309 0:88e313c910d0 76 Note: This parameter can be modified only if the ADC is disabled */
jhon309 0:88e313c910d0 77 uint32_t Resolution; /*!< Configures the ADC resolution.
jhon309 0:88e313c910d0 78 This parameter can be a value of @ref ADC_Resolution */
jhon309 0:88e313c910d0 79 uint32_t DataAlign; /*!< Specifies whether the ADC data alignment is left or right.
jhon309 0:88e313c910d0 80 This parameter can be a value of @ref ADC_Data_align */
jhon309 0:88e313c910d0 81 uint32_t ScanConvMode; /*!< Configures the sequencer of regular group.
jhon309 0:88e313c910d0 82 This parameter can be associated to parameter 'DiscontinuousConvMode' to have main sequence subdivided in successive parts.
jhon309 0:88e313c910d0 83 Sequencer is automatically enabled if several channels are set (sequencer cannot be disabled, as it can be the case on other STM32 devices):
jhon309 0:88e313c910d0 84 If only 1 channel is set: Conversion is performed in single mode.
jhon309 0:88e313c910d0 85 If several channels are set: Conversions are performed in sequence mode (ranks defined by each channel number: channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
jhon309 0:88e313c910d0 86 Scan direction can be set to forward (from channel 0 to channel 18) or backward (from channel 18 to channel 0).
jhon309 0:88e313c910d0 87 This parameter can be a value of @ref ADC_Scan_mode */
jhon309 0:88e313c910d0 88 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.
jhon309 0:88e313c910d0 89 This parameter can be a value of @ref ADC_EOCSelection. */
jhon309 0:88e313c910d0 90 uint32_t LowPowerAutoWait; /*!< Selects the dynamic low power Auto Delay: new conversion start only when the previous
jhon309 0:88e313c910d0 91 conversion (for regular group) or previous sequence (for injected group) has been treated by user software.
jhon309 0:88e313c910d0 92 This feature automatically adapts the speed of ADC to the speed of the system that reads the data. Moreover, this avoids risk of overrun for low frequency applications.
jhon309 0:88e313c910d0 93 This parameter can be set to ENABLE or DISABLE.
jhon309 0:88e313c910d0 94 Note: Do not use with interruption or DMA (HAL_ADC_Start_IT(), HAL_ADC_Start_DMA()) since they have to clear immediately the EOC flag to free the IRQ vector sequencer.
jhon309 0:88e313c910d0 95 Do use with polling: 1. Start conversion with HAL_ADC_Start(), 2. Later on, when conversion data is needed: use HAL_ADC_PollForConversion() to ensure that conversion is completed
jhon309 0:88e313c910d0 96 and use HAL_ADC_GetValue() to retrieve conversion result and trig another conversion. */
jhon309 0:88e313c910d0 97 uint32_t LowPowerAutoPowerOff; /*!< Selects the auto-off mode: the ADC automatically powers-off after a conversion and automatically wakes-up when a new conversion is triggered (with startup time between trigger and start of sampling).
jhon309 0:88e313c910d0 98 This feature can be combined with automatic wait mode (parameter 'LowPowerAutoWait').
jhon309 0:88e313c910d0 99 This parameter can be set to ENABLE or DISABLE.
jhon309 0:88e313c910d0 100 Note: If enabled, this feature also turns off the ADC dedicated 14 MHz RC oscillator (HSI14) */
jhon309 0:88e313c910d0 101 uint32_t ContinuousConvMode; /*!< Specifies whether the conversion is performed in single mode (one conversion) or continuous mode for regular group,
jhon309 0:88e313c910d0 102 after the selected trigger occurred (software start or external trigger).
jhon309 0:88e313c910d0 103 This parameter can be set to ENABLE or DISABLE. */
jhon309 0:88e313c910d0 104 uint32_t DiscontinuousConvMode; /*!< Specifies whether the conversions sequence of regular group is performed in Complete-sequence/Discontinuous-sequence (main sequence subdivided in successive parts).
jhon309 0:88e313c910d0 105 Discontinuous mode is used only if sequencer is enabled (parameter 'ScanConvMode'). If sequencer is disabled, this parameter is discarded.
jhon309 0:88e313c910d0 106 Discontinuous mode can be enabled only if continuous mode is disabled. If continuous mode is enabled, this parameter setting is discarded.
jhon309 0:88e313c910d0 107 This parameter can be set to ENABLE or DISABLE
jhon309 0:88e313c910d0 108 Note: Number of discontinuous ranks increment is fixed to one-by-one. */
jhon309 0:88e313c910d0 109 uint32_t ExternalTrigConv; /*!< Selects the external event used to trigger the conversion start of regular group.
jhon309 0:88e313c910d0 110 If set to ADC_SOFTWARE_START, external triggers are disabled.
jhon309 0:88e313c910d0 111 This parameter can be a value of @ref ADC_External_trigger_source_Regular */
jhon309 0:88e313c910d0 112 uint32_t ExternalTrigConvEdge; /*!< Selects the external trigger edge of regular group.
jhon309 0:88e313c910d0 113 If trigger is set to ADC_SOFTWARE_START, this parameter is discarded.
jhon309 0:88e313c910d0 114 This parameter can be a value of @ref ADC_External_trigger_edge_Regular */
jhon309 0:88e313c910d0 115 uint32_t DMAContinuousRequests; /*!< Specifies whether the DMA requests are performed in one shot mode (DMA transfer stop when number of conversions is reached)
jhon309 0:88e313c910d0 116 or in Continuous mode (DMA transfer unlimited, whatever number of conversions).
jhon309 0:88e313c910d0 117 Note: In continuous mode, DMA must be configured in circular mode. Otherwise an overrun will be triggered when DMA buffer maximum pointer is reached.
jhon309 0:88e313c910d0 118 This parameter can be set to ENABLE or DISABLE. */
jhon309 0:88e313c910d0 119 uint32_t Overrun; /*!< Select the behaviour in case of overrun: data preserved or overwritten
jhon309 0:88e313c910d0 120 This parameter has an effect on regular group only, including in DMA mode.
jhon309 0:88e313c910d0 121 This parameter can be a value of @ref ADC_Overrun */
jhon309 0:88e313c910d0 122 }ADC_InitTypeDef;
jhon309 0:88e313c910d0 123
jhon309 0:88e313c910d0 124 /**
jhon309 0:88e313c910d0 125 * @brief Structure definition of ADC channel for regular group
jhon309 0:88e313c910d0 126 * @note The setting of these parameters with function HAL_ADC_ConfigChannel() is conditioned to ADC state.
jhon309 0:88e313c910d0 127 * ADC state can be either:
jhon309 0:88e313c910d0 128 * - For all parameters: ADC disabled or enabled without conversion on going on regular group.
jhon309 0:88e313c910d0 129 * If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed
jhon309 0:88e313c910d0 130 * 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).
jhon309 0:88e313c910d0 131 */
jhon309 0:88e313c910d0 132 typedef struct
jhon309 0:88e313c910d0 133 {
jhon309 0:88e313c910d0 134 uint32_t Channel; /*!< Specifies the channel to configure into ADC regular group.
jhon309 0:88e313c910d0 135 This parameter can be a value of @ref ADC_channels
jhon309 0:88e313c910d0 136 Note: Depending on devices, some channels may not be available on package pins. Refer to device datasheet for channels availability. */
jhon309 0:88e313c910d0 137 uint32_t Rank; /*!< Add or remove the channel from ADC regular group sequencer.
jhon309 0:88e313c910d0 138 On STM32F0 devices, rank is defined by each channel number (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
jhon309 0:88e313c910d0 139 Despite the channel rank is fixed, this parameter allow an additional possibility: to remove the selected rank (selected channel) from sequencer.
jhon309 0:88e313c910d0 140 This parameter can be a value of @ref ADC_rank */
jhon309 0:88e313c910d0 141 uint32_t SamplingTime; /*!< Sampling time value to be set for the selected channel.
jhon309 0:88e313c910d0 142 Unit: ADC clock cycles
jhon309 0:88e313c910d0 143 Conversion time is the addition of sampling time and processing time (12.5 ADC clock cycles at ADC resolution 12 bits, 10.5 cycles at 10 bits, 8.5 cycles at 8 bits, 6.5 cycles at 6 bits).
jhon309 0:88e313c910d0 144 This parameter can be a value of @ref ADC_sampling_times
jhon309 0:88e313c910d0 145 Caution: this setting impacts the entire regular group. Therefore, call of HAL_ADC_ConfigChannel() to configure a channel can impact the configuration of other channels previously set.
jhon309 0:88e313c910d0 146 Note: In case of usage of internal measurement channels (VrefInt/Vbat/TempSensor),
jhon309 0:88e313c910d0 147 sampling time constraints must be respected (sampling time can be adjusted in function of ADC clock frequency and sampling time setting)
jhon309 0:88e313c910d0 148 Refer to device datasheet for timings values, parameters TS_vrefint, TS_vbat, TS_temp (values rough order: 5us to 17us). */
jhon309 0:88e313c910d0 149 }ADC_ChannelConfTypeDef;
jhon309 0:88e313c910d0 150
jhon309 0:88e313c910d0 151 /**
jhon309 0:88e313c910d0 152 * @brief Structure definition of ADC analog watchdog
jhon309 0:88e313c910d0 153 * @note The setting of these parameters with function HAL_ADC_AnalogWDGConfig() is conditioned to ADC state.
jhon309 0:88e313c910d0 154 * ADC state can be either: ADC disabled or ADC enabled without conversion on going on regular group.
jhon309 0:88e313c910d0 155 */
jhon309 0:88e313c910d0 156 typedef struct
jhon309 0:88e313c910d0 157 {
jhon309 0:88e313c910d0 158 uint32_t WatchdogMode; /*!< Configures the ADC analog watchdog mode: single/all/none channels.
jhon309 0:88e313c910d0 159 This parameter can be a value of @ref ADC_analog_watchdog_mode. */
jhon309 0:88e313c910d0 160 uint32_t Channel; /*!< Selects which ADC channel to monitor by analog watchdog.
jhon309 0:88e313c910d0 161 This parameter has an effect only if parameter 'WatchdogMode' is configured on single channel. Only 1 channel can be monitored.
jhon309 0:88e313c910d0 162 This parameter can be a value of @ref ADC_channels. */
jhon309 0:88e313c910d0 163 uint32_t ITMode; /*!< Specifies whether the analog watchdog is configured in interrupt or polling mode.
jhon309 0:88e313c910d0 164 This parameter can be set to ENABLE or DISABLE */
jhon309 0:88e313c910d0 165 uint32_t HighThreshold; /*!< Configures the ADC analog watchdog High threshold value.
jhon309 0:88e313c910d0 166 Depending of ADC resolution selected (12, 10, 8 or 6 bits), this parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F respectively. */
jhon309 0:88e313c910d0 167 uint32_t LowThreshold; /*!< Configures the ADC analog watchdog High threshold value.
jhon309 0:88e313c910d0 168 Depending of ADC resolution selected (12, 10, 8 or 6 bits), this parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F respectively. */
jhon309 0:88e313c910d0 169 }ADC_AnalogWDGConfTypeDef;
jhon309 0:88e313c910d0 170
jhon309 0:88e313c910d0 171 /**
jhon309 0:88e313c910d0 172 * @brief HAL ADC state machine: ADC States structure definition
jhon309 0:88e313c910d0 173 */
jhon309 0:88e313c910d0 174 typedef enum
jhon309 0:88e313c910d0 175 {
jhon309 0:88e313c910d0 176 HAL_ADC_STATE_RESET = 0x00, /*!< ADC not yet initialized or disabled */
jhon309 0:88e313c910d0 177 HAL_ADC_STATE_READY = 0x01, /*!< ADC peripheral ready for use */
jhon309 0:88e313c910d0 178 HAL_ADC_STATE_BUSY = 0x02, /*!< An internal process is ongoing */
jhon309 0:88e313c910d0 179 HAL_ADC_STATE_BUSY_REG = 0x12, /*!< Regular conversion is ongoing */
jhon309 0:88e313c910d0 180 HAL_ADC_STATE_BUSY_INJ = 0x22, /*!< Not used on STM32F0xx devices (kept for compatibility with other devices featuring an injected group) */
jhon309 0:88e313c910d0 181 HAL_ADC_STATE_BUSY_INJ_REG = 0x32, /*!< Not used on STM32F0xx devices (kept for compatibility with other devices featuring an injected group) */
jhon309 0:88e313c910d0 182 HAL_ADC_STATE_TIMEOUT = 0x03, /*!< Timeout state */
jhon309 0:88e313c910d0 183 HAL_ADC_STATE_ERROR = 0x04, /*!< ADC state error */
jhon309 0:88e313c910d0 184 HAL_ADC_STATE_EOC = 0x05, /*!< Conversion is completed */
jhon309 0:88e313c910d0 185 HAL_ADC_STATE_EOC_REG = 0x15, /*!< Regular conversion is completed */
jhon309 0:88e313c910d0 186 HAL_ADC_STATE_EOC_INJ = 0x25, /*!< Not used on STM32F0xx devices (kept for compatibility with other devices featuring an injected group) */
jhon309 0:88e313c910d0 187 HAL_ADC_STATE_EOC_INJ_REG = 0x35, /*!< Not used on STM32F0xx devices (kept for compatibility with other devices featuring an injected group) */
jhon309 0:88e313c910d0 188 HAL_ADC_STATE_AWD = 0x06, /*!< ADC state analog watchdog */
jhon309 0:88e313c910d0 189 HAL_ADC_STATE_AWD2 = 0x07, /*!< Not used on STM32F0xx devices (kept for compatibility with other devices featuring several AWD) */
jhon309 0:88e313c910d0 190 HAL_ADC_STATE_AWD3 = 0x08, /*!< Not used on STM32F0xx devices (kept for compatibility with other devices featuring several AWD) */
jhon309 0:88e313c910d0 191 }HAL_ADC_StateTypeDef;
jhon309 0:88e313c910d0 192
jhon309 0:88e313c910d0 193 /**
jhon309 0:88e313c910d0 194 * @brief ADC handle Structure definition
jhon309 0:88e313c910d0 195 */
jhon309 0:88e313c910d0 196 typedef struct
jhon309 0:88e313c910d0 197 {
jhon309 0:88e313c910d0 198 ADC_TypeDef *Instance; /*!< Register base address */
jhon309 0:88e313c910d0 199
jhon309 0:88e313c910d0 200 ADC_InitTypeDef Init; /*!< ADC required parameters */
jhon309 0:88e313c910d0 201
jhon309 0:88e313c910d0 202 __IO uint32_t NbrOfConversionRank ; /*!< ADC conversion rank counter */
jhon309 0:88e313c910d0 203
jhon309 0:88e313c910d0 204 DMA_HandleTypeDef *DMA_Handle; /*!< Pointer DMA Handler */
jhon309 0:88e313c910d0 205
jhon309 0:88e313c910d0 206 HAL_LockTypeDef Lock; /*!< ADC locking object */
jhon309 0:88e313c910d0 207
jhon309 0:88e313c910d0 208 __IO HAL_ADC_StateTypeDef State; /*!< ADC communication state */
jhon309 0:88e313c910d0 209
jhon309 0:88e313c910d0 210 __IO uint32_t ErrorCode; /*!< ADC Error code */
jhon309 0:88e313c910d0 211 }ADC_HandleTypeDef;
jhon309 0:88e313c910d0 212 /**
jhon309 0:88e313c910d0 213 * @}
jhon309 0:88e313c910d0 214 */
jhon309 0:88e313c910d0 215
jhon309 0:88e313c910d0 216
jhon309 0:88e313c910d0 217
jhon309 0:88e313c910d0 218 /* Exported constants --------------------------------------------------------*/
jhon309 0:88e313c910d0 219
jhon309 0:88e313c910d0 220 /** @defgroup ADC_Exported_Constants ADC Exported Constants
jhon309 0:88e313c910d0 221 * @{
jhon309 0:88e313c910d0 222 */
jhon309 0:88e313c910d0 223
jhon309 0:88e313c910d0 224 /** @defgroup ADC_Error_Code ADC Error Code
jhon309 0:88e313c910d0 225 * @{
jhon309 0:88e313c910d0 226 */
jhon309 0:88e313c910d0 227 #define HAL_ADC_ERROR_NONE ((uint32_t)0x00) /*!< No error */
jhon309 0:88e313c910d0 228 #define HAL_ADC_ERROR_INTERNAL ((uint32_t)0x01) /*!< ADC IP internal error: if problem of clocking,
jhon309 0:88e313c910d0 229 enable/disable, erroneous state */
jhon309 0:88e313c910d0 230 #define HAL_ADC_ERROR_OVR ((uint32_t)0x02) /*!< Overrun error */
jhon309 0:88e313c910d0 231 #define HAL_ADC_ERROR_DMA ((uint32_t)0x04) /*!< DMA transfer error */
jhon309 0:88e313c910d0 232
jhon309 0:88e313c910d0 233 /**
jhon309 0:88e313c910d0 234 * @}
jhon309 0:88e313c910d0 235 */
jhon309 0:88e313c910d0 236
jhon309 0:88e313c910d0 237 /** @defgroup ADC_ClockPrescaler ADC ClockPrescaler
jhon309 0:88e313c910d0 238 * @{
jhon309 0:88e313c910d0 239 */
jhon309 0:88e313c910d0 240 #define ADC_CLOCK_ASYNC ((uint32_t)0x00000000) /*!< ADC asynchronous clock derived from ADC dedicated HSI */
jhon309 0:88e313c910d0 241
jhon309 0:88e313c910d0 242 #define ADC_CLOCK_SYNC_PCLK_DIV2 ((uint32_t)ADC_CFGR2_CKMODE_0) /*!< ADC synchronous clock derived from AHB clock divided by a prescaler of 2 */
jhon309 0:88e313c910d0 243 #define ADC_CLOCK_SYNC_PCLK_DIV4 ((uint32_t)ADC_CFGR2_CKMODE_1) /*!< ADC synchronous clock derived from AHB clock divided by a prescaler of 4 */
jhon309 0:88e313c910d0 244
jhon309 0:88e313c910d0 245 #define ADC_CLOCKPRESCALER_PCLK_DIV2 ADC_CLOCK_SYNC_PCLK_DIV2 /* Obsolete naming, kept for compatibility with some other devices */
jhon309 0:88e313c910d0 246 #define ADC_CLOCKPRESCALER_PCLK_DIV4 ADC_CLOCK_SYNC_PCLK_DIV4 /* Obsolete naming, kept for compatibility with some other devices */
jhon309 0:88e313c910d0 247
jhon309 0:88e313c910d0 248 #define IS_ADC_CLOCKPRESCALER(ADC_CLOCK) (((ADC_CLOCK) == ADC_CLOCK_ASYNC) || \
jhon309 0:88e313c910d0 249 ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV2) || \
jhon309 0:88e313c910d0 250 ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV4) )
jhon309 0:88e313c910d0 251
jhon309 0:88e313c910d0 252 /**
jhon309 0:88e313c910d0 253 * @}
jhon309 0:88e313c910d0 254 */
jhon309 0:88e313c910d0 255
jhon309 0:88e313c910d0 256 /** @defgroup ADC_Resolution ADC Resolution
jhon309 0:88e313c910d0 257 * @{
jhon309 0:88e313c910d0 258 */
jhon309 0:88e313c910d0 259 #define ADC_RESOLUTION12b ((uint32_t)0x00000000) /*!< ADC 12-bit resolution */
jhon309 0:88e313c910d0 260 #define ADC_RESOLUTION10b ((uint32_t)ADC_CFGR1_RES_0) /*!< ADC 10-bit resolution */
jhon309 0:88e313c910d0 261 #define ADC_RESOLUTION8b ((uint32_t)ADC_CFGR1_RES_1) /*!< ADC 8-bit resolution */
jhon309 0:88e313c910d0 262 #define ADC_RESOLUTION6b ((uint32_t)ADC_CFGR1_RES) /*!< ADC 6-bit resolution */
jhon309 0:88e313c910d0 263
jhon309 0:88e313c910d0 264 #define IS_ADC_RESOLUTION(RESOLUTION) (((RESOLUTION) == ADC_RESOLUTION12b) || \
jhon309 0:88e313c910d0 265 ((RESOLUTION) == ADC_RESOLUTION10b) || \
jhon309 0:88e313c910d0 266 ((RESOLUTION) == ADC_RESOLUTION8b) || \
jhon309 0:88e313c910d0 267 ((RESOLUTION) == ADC_RESOLUTION6b) )
jhon309 0:88e313c910d0 268 /**
jhon309 0:88e313c910d0 269 * @}
jhon309 0:88e313c910d0 270 */
jhon309 0:88e313c910d0 271
jhon309 0:88e313c910d0 272 /** @defgroup ADC_Data_align ADC Data_align
jhon309 0:88e313c910d0 273 * @{
jhon309 0:88e313c910d0 274 */
jhon309 0:88e313c910d0 275 #define ADC_DATAALIGN_RIGHT ((uint32_t)0x00000000)
jhon309 0:88e313c910d0 276 #define ADC_DATAALIGN_LEFT ((uint32_t)ADC_CFGR1_ALIGN)
jhon309 0:88e313c910d0 277
jhon309 0:88e313c910d0 278 #define IS_ADC_DATA_ALIGN(ALIGN) (((ALIGN) == ADC_DATAALIGN_RIGHT) || \
jhon309 0:88e313c910d0 279 ((ALIGN) == ADC_DATAALIGN_LEFT) )
jhon309 0:88e313c910d0 280 /**
jhon309 0:88e313c910d0 281 * @}
jhon309 0:88e313c910d0 282 */
jhon309 0:88e313c910d0 283
jhon309 0:88e313c910d0 284 /** @defgroup ADC_Scan_mode ADC Scan mode
jhon309 0:88e313c910d0 285 * @{
jhon309 0:88e313c910d0 286 */
jhon309 0:88e313c910d0 287 /* Note: Scan mode values must be compatible with other STM32 devices having */
jhon309 0:88e313c910d0 288 /* a configurable sequencer. */
jhon309 0:88e313c910d0 289 /* Scan direction setting values are defined by taking in account */
jhon309 0:88e313c910d0 290 /* already defined values for other STM32 devices: */
jhon309 0:88e313c910d0 291 /* ADC_SCAN_DISABLE ((uint32_t)0x00000000) */
jhon309 0:88e313c910d0 292 /* ADC_SCAN_ENABLE ((uint32_t)0x00000001) */
jhon309 0:88e313c910d0 293 /* Scan direction forward is considered as default setting equivalent */
jhon309 0:88e313c910d0 294 /* to scan enable. */
jhon309 0:88e313c910d0 295 /* Scan direction backward is considered as additional setting. */
jhon309 0:88e313c910d0 296 /* In case of migration from another STM32 device, the user will be */
jhon309 0:88e313c910d0 297 /* warned of change of setting choices with assert check. */
jhon309 0:88e313c910d0 298 #define ADC_SCAN_DIRECTION_FORWARD ((uint32_t)0x00000001) /*!< Scan direction forward: from channel 0 to channel 18 */
jhon309 0:88e313c910d0 299 #define ADC_SCAN_DIRECTION_BACKWARD ((uint32_t)0x00000002) /*!< Scan direction backward: from channel 18 to channel 0 */
jhon309 0:88e313c910d0 300
jhon309 0:88e313c910d0 301 #define ADC_SCAN_ENABLE ADC_SCAN_DIRECTION_FORWARD /* For compatibility with other STM32 devices */
jhon309 0:88e313c910d0 302
jhon309 0:88e313c910d0 303 #define IS_ADC_SCAN_MODE(SCAN_MODE) (((SCAN_MODE) == ADC_SCAN_DIRECTION_FORWARD) || \
jhon309 0:88e313c910d0 304 ((SCAN_MODE) == ADC_SCAN_DIRECTION_BACKWARD) )
jhon309 0:88e313c910d0 305 /**
jhon309 0:88e313c910d0 306 * @}
jhon309 0:88e313c910d0 307 */
jhon309 0:88e313c910d0 308
jhon309 0:88e313c910d0 309 /** @defgroup ADC_External_trigger_edge_Regular ADC External trigger edge Regular
jhon309 0:88e313c910d0 310 * @{
jhon309 0:88e313c910d0 311 */
jhon309 0:88e313c910d0 312 #define ADC_EXTERNALTRIGCONVEDGE_NONE ((uint32_t)0x00000000)
jhon309 0:88e313c910d0 313 #define ADC_EXTERNALTRIGCONVEDGE_RISING ((uint32_t)ADC_CFGR1_EXTEN_0)
jhon309 0:88e313c910d0 314 #define ADC_EXTERNALTRIGCONVEDGE_FALLING ((uint32_t)ADC_CFGR1_EXTEN_1)
jhon309 0:88e313c910d0 315 #define ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING ((uint32_t)ADC_CFGR1_EXTEN)
jhon309 0:88e313c910d0 316
jhon309 0:88e313c910d0 317 #define IS_ADC_EXTTRIG_EDGE(EDGE) (((EDGE) == ADC_EXTERNALTRIGCONVEDGE_NONE) || \
jhon309 0:88e313c910d0 318 ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISING) || \
jhon309 0:88e313c910d0 319 ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_FALLING) || \
jhon309 0:88e313c910d0 320 ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING) )
jhon309 0:88e313c910d0 321 /**
jhon309 0:88e313c910d0 322 * @}
jhon309 0:88e313c910d0 323 */
jhon309 0:88e313c910d0 324
jhon309 0:88e313c910d0 325 /** @defgroup ADC_External_trigger_source_Regular ADC External trigger source Regular
jhon309 0:88e313c910d0 326 * @{
jhon309 0:88e313c910d0 327 */
jhon309 0:88e313c910d0 328 /* List of external triggers with generic trigger name, sorted by trigger */
jhon309 0:88e313c910d0 329 /* name: */
jhon309 0:88e313c910d0 330
jhon309 0:88e313c910d0 331 /* External triggers of regular group for ADC1 */
jhon309 0:88e313c910d0 332 #define ADC_EXTERNALTRIGCONV_T1_TRGO ADC1_2_EXTERNALTRIG_T1_TRGO
jhon309 0:88e313c910d0 333 #define ADC_EXTERNALTRIGCONV_T1_CC4 ADC1_2_EXTERNALTRIG_T1_CC4
jhon309 0:88e313c910d0 334 #define ADC_EXTERNALTRIGCONV_T2_TRGO ADC1_2_EXTERNALTRIG_T2_TRGO
jhon309 0:88e313c910d0 335 #define ADC_EXTERNALTRIGCONV_T3_TRGO ADC1_2_EXTERNALTRIG_T3_TRGO
jhon309 0:88e313c910d0 336 #define ADC_EXTERNALTRIGCONV_T15_TRGO ADC1_2_EXTERNALTRIG_T15_TRGO
jhon309 0:88e313c910d0 337 #define ADC_SOFTWARE_START ((uint32_t)0x00000010)
jhon309 0:88e313c910d0 338
jhon309 0:88e313c910d0 339 #define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_TRGO) || \
jhon309 0:88e313c910d0 340 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC4) || \
jhon309 0:88e313c910d0 341 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_TRGO) || \
jhon309 0:88e313c910d0 342 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO) || \
jhon309 0:88e313c910d0 343 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T15_TRGO) || \
jhon309 0:88e313c910d0 344 ((REGTRIG) == ADC_SOFTWARE_START) )
jhon309 0:88e313c910d0 345 /**
jhon309 0:88e313c910d0 346 * @}
jhon309 0:88e313c910d0 347 */
jhon309 0:88e313c910d0 348
jhon309 0:88e313c910d0 349 /** @defgroup ADC_Internal_HAL_driver_Ext_trig_src_Regular ADC Internal HAL driver Ext trig src Regular
jhon309 0:88e313c910d0 350 * @{
jhon309 0:88e313c910d0 351 */
jhon309 0:88e313c910d0 352
jhon309 0:88e313c910d0 353 /* List of external triggers of regular group for ADC1: */
jhon309 0:88e313c910d0 354 /* (used internally by HAL driver. To not use into HAL structure parameters) */
jhon309 0:88e313c910d0 355 #define ADC1_2_EXTERNALTRIG_T1_TRGO ((uint32_t)0x00000000)
jhon309 0:88e313c910d0 356 #define ADC1_2_EXTERNALTRIG_T1_CC4 ((uint32_t)ADC_CFGR1_EXTSEL_0)
jhon309 0:88e313c910d0 357 #define ADC1_2_EXTERNALTRIG_T2_TRGO ((uint32_t)ADC_CFGR1_EXTSEL_1)
jhon309 0:88e313c910d0 358 #define ADC1_2_EXTERNALTRIG_T3_TRGO ((uint32_t)(ADC_CFGR1_EXTSEL_1 | ADC_CFGR1_EXTSEL_0))
jhon309 0:88e313c910d0 359 #define ADC1_2_EXTERNALTRIG_T15_TRGO ((uint32_t)ADC_CFGR1_EXTSEL_2)
jhon309 0:88e313c910d0 360
jhon309 0:88e313c910d0 361 /**
jhon309 0:88e313c910d0 362 * @}
jhon309 0:88e313c910d0 363 */
jhon309 0:88e313c910d0 364
jhon309 0:88e313c910d0 365 /** @defgroup ADC_EOCSelection ADC EOCSelection
jhon309 0:88e313c910d0 366 * @{
jhon309 0:88e313c910d0 367 */
jhon309 0:88e313c910d0 368 #define EOC_SINGLE_CONV ((uint32_t) ADC_ISR_EOC)
jhon309 0:88e313c910d0 369 #define EOC_SEQ_CONV ((uint32_t) ADC_ISR_EOS)
jhon309 0:88e313c910d0 370 #define EOC_SINGLE_SEQ_CONV ((uint32_t)(ADC_ISR_EOC | ADC_ISR_EOS)) /*!< reserved for future use */
jhon309 0:88e313c910d0 371
jhon309 0:88e313c910d0 372 #define IS_ADC_EOC_SELECTION(EOC_SELECTION) (((EOC_SELECTION) == EOC_SINGLE_CONV) || \
jhon309 0:88e313c910d0 373 ((EOC_SELECTION) == EOC_SEQ_CONV) || \
jhon309 0:88e313c910d0 374 ((EOC_SELECTION) == EOC_SINGLE_SEQ_CONV) )
jhon309 0:88e313c910d0 375 /**
jhon309 0:88e313c910d0 376 * @}
jhon309 0:88e313c910d0 377 */
jhon309 0:88e313c910d0 378
jhon309 0:88e313c910d0 379 /** @defgroup ADC_Overrun ADC Overrun
jhon309 0:88e313c910d0 380 * @{
jhon309 0:88e313c910d0 381 */
jhon309 0:88e313c910d0 382 #define OVR_DATA_OVERWRITTEN ((uint32_t)0x00000000)
jhon309 0:88e313c910d0 383 #define OVR_DATA_PRESERVED ((uint32_t)0x00000001)
jhon309 0:88e313c910d0 384
jhon309 0:88e313c910d0 385 #define IS_ADC_OVERRUN(OVR) (((OVR) == OVR_DATA_PRESERVED) || \
jhon309 0:88e313c910d0 386 ((OVR) == OVR_DATA_OVERWRITTEN) )
jhon309 0:88e313c910d0 387 /**
jhon309 0:88e313c910d0 388 * @}
jhon309 0:88e313c910d0 389 */
jhon309 0:88e313c910d0 390
jhon309 0:88e313c910d0 391 /** @defgroup ADC_channels ADC channels
jhon309 0:88e313c910d0 392 * @{
jhon309 0:88e313c910d0 393 */
jhon309 0:88e313c910d0 394 /* Note: Depending on devices, some channels may not be available on package */
jhon309 0:88e313c910d0 395 /* pins. Refer to device datasheet for channels availability. */
jhon309 0:88e313c910d0 396 /* Note: Channels are used by bitfields for setting of channel selection */
jhon309 0:88e313c910d0 397 /* (register ADC_CHSELR) and used by number for setting of analog watchdog */
jhon309 0:88e313c910d0 398 /* channel (bits AWDCH in register ADC_CFGR1). */
jhon309 0:88e313c910d0 399 /* Channels are defined with decimal numbers and converted them to bitfields */
jhon309 0:88e313c910d0 400 /* when needed. */
jhon309 0:88e313c910d0 401 #define ADC_CHANNEL_0 ((uint32_t) 0x00000000)
jhon309 0:88e313c910d0 402 #define ADC_CHANNEL_1 ((uint32_t) 0x00000001)
jhon309 0:88e313c910d0 403 #define ADC_CHANNEL_2 ((uint32_t) 0x00000002)
jhon309 0:88e313c910d0 404 #define ADC_CHANNEL_3 ((uint32_t) 0x00000003)
jhon309 0:88e313c910d0 405 #define ADC_CHANNEL_4 ((uint32_t) 0x00000004)
jhon309 0:88e313c910d0 406 #define ADC_CHANNEL_5 ((uint32_t) 0x00000005)
jhon309 0:88e313c910d0 407 #define ADC_CHANNEL_6 ((uint32_t) 0x00000006)
jhon309 0:88e313c910d0 408 #define ADC_CHANNEL_7 ((uint32_t) 0x00000007)
jhon309 0:88e313c910d0 409 #define ADC_CHANNEL_8 ((uint32_t) 0x00000008)
jhon309 0:88e313c910d0 410 #define ADC_CHANNEL_9 ((uint32_t) 0x00000009)
jhon309 0:88e313c910d0 411 #define ADC_CHANNEL_10 ((uint32_t) 0x0000000A)
jhon309 0:88e313c910d0 412 #define ADC_CHANNEL_11 ((uint32_t) 0x0000000B)
jhon309 0:88e313c910d0 413 #define ADC_CHANNEL_12 ((uint32_t) 0x0000000C)
jhon309 0:88e313c910d0 414 #define ADC_CHANNEL_13 ((uint32_t) 0x0000000D)
jhon309 0:88e313c910d0 415 #define ADC_CHANNEL_14 ((uint32_t) 0x0000000E)
jhon309 0:88e313c910d0 416 #define ADC_CHANNEL_15 ((uint32_t) 0x0000000F)
jhon309 0:88e313c910d0 417 #define ADC_CHANNEL_16 ((uint32_t) 0x00000010)
jhon309 0:88e313c910d0 418 #define ADC_CHANNEL_17 ((uint32_t) 0x00000011)
jhon309 0:88e313c910d0 419 #define ADC_CHANNEL_18 ((uint32_t) 0x00000012)
jhon309 0:88e313c910d0 420
jhon309 0:88e313c910d0 421 #define ADC_CHANNEL_TEMPSENSOR ADC_CHANNEL_16
jhon309 0:88e313c910d0 422 #define ADC_CHANNEL_VREFINT ADC_CHANNEL_17
jhon309 0:88e313c910d0 423 #define ADC_CHANNEL_VBAT ADC_CHANNEL_18
jhon309 0:88e313c910d0 424
jhon309 0:88e313c910d0 425 #define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) == ADC_CHANNEL_0) || \
jhon309 0:88e313c910d0 426 ((CHANNEL) == ADC_CHANNEL_1) || \
jhon309 0:88e313c910d0 427 ((CHANNEL) == ADC_CHANNEL_2) || \
jhon309 0:88e313c910d0 428 ((CHANNEL) == ADC_CHANNEL_3) || \
jhon309 0:88e313c910d0 429 ((CHANNEL) == ADC_CHANNEL_4) || \
jhon309 0:88e313c910d0 430 ((CHANNEL) == ADC_CHANNEL_5) || \
jhon309 0:88e313c910d0 431 ((CHANNEL) == ADC_CHANNEL_6) || \
jhon309 0:88e313c910d0 432 ((CHANNEL) == ADC_CHANNEL_7) || \
jhon309 0:88e313c910d0 433 ((CHANNEL) == ADC_CHANNEL_8) || \
jhon309 0:88e313c910d0 434 ((CHANNEL) == ADC_CHANNEL_9) || \
jhon309 0:88e313c910d0 435 ((CHANNEL) == ADC_CHANNEL_10) || \
jhon309 0:88e313c910d0 436 ((CHANNEL) == ADC_CHANNEL_11) || \
jhon309 0:88e313c910d0 437 ((CHANNEL) == ADC_CHANNEL_12) || \
jhon309 0:88e313c910d0 438 ((CHANNEL) == ADC_CHANNEL_13) || \
jhon309 0:88e313c910d0 439 ((CHANNEL) == ADC_CHANNEL_14) || \
jhon309 0:88e313c910d0 440 ((CHANNEL) == ADC_CHANNEL_15) || \
jhon309 0:88e313c910d0 441 ((CHANNEL) == ADC_CHANNEL_TEMPSENSOR) || \
jhon309 0:88e313c910d0 442 ((CHANNEL) == ADC_CHANNEL_VREFINT) || \
jhon309 0:88e313c910d0 443 ((CHANNEL) == ADC_CHANNEL_VBAT) )
jhon309 0:88e313c910d0 444 /**
jhon309 0:88e313c910d0 445 * @}
jhon309 0:88e313c910d0 446 */
jhon309 0:88e313c910d0 447
jhon309 0:88e313c910d0 448 /** @defgroup ADC_rank ADC rank
jhon309 0:88e313c910d0 449 * @{
jhon309 0:88e313c910d0 450 */
jhon309 0:88e313c910d0 451 #define ADC_RANK_CHANNEL_NUMBER ((uint32_t)0x00001000) /*!< Enable the rank of the selected channels. Rank is defined by each channel number (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...) */
jhon309 0:88e313c910d0 452 #define ADC_RANK_NONE ((uint32_t)0x00001001) /*!< Disable the selected rank (selected channel) from sequencer */
jhon309 0:88e313c910d0 453
jhon309 0:88e313c910d0 454 #define IS_ADC_RANK(WATCHDOG) (((WATCHDOG) == ADC_RANK_CHANNEL_NUMBER) || \
jhon309 0:88e313c910d0 455 ((WATCHDOG) == ADC_RANK_NONE) )
jhon309 0:88e313c910d0 456 /**
jhon309 0:88e313c910d0 457 * @}
jhon309 0:88e313c910d0 458 */
jhon309 0:88e313c910d0 459
jhon309 0:88e313c910d0 460 /** @defgroup ADC_sampling_times ADC sampling times
jhon309 0:88e313c910d0 461 * @{
jhon309 0:88e313c910d0 462 */
jhon309 0:88e313c910d0 463 #define ADC_SAMPLETIME_1CYCLE_5 ((uint32_t)0x00000000) /*!< Sampling time 1.5 ADC clock cycle */
jhon309 0:88e313c910d0 464 #define ADC_SAMPLETIME_7CYCLES_5 ((uint32_t) ADC_SMPR_SMP_0) /*!< Sampling time 7.5 ADC clock cycles */
jhon309 0:88e313c910d0 465 #define ADC_SAMPLETIME_13CYCLES_5 ((uint32_t) ADC_SMPR_SMP_1) /*!< Sampling time 13.5 ADC clock cycles */
jhon309 0:88e313c910d0 466 #define ADC_SAMPLETIME_28CYCLES_5 ((uint32_t)(ADC_SMPR_SMP_1 | ADC_SMPR_SMP_0)) /*!< Sampling time 28.5 ADC clock cycles */
jhon309 0:88e313c910d0 467 #define ADC_SAMPLETIME_41CYCLES_5 ((uint32_t) ADC_SMPR_SMP_2) /*!< Sampling time 41.5 ADC clock cycles */
jhon309 0:88e313c910d0 468 #define ADC_SAMPLETIME_55CYCLES_5 ((uint32_t)(ADC_SMPR_SMP_2 | ADC_SMPR_SMP_0)) /*!< Sampling time 55.5 ADC clock cycles */
jhon309 0:88e313c910d0 469 #define ADC_SAMPLETIME_71CYCLES_5 ((uint32_t)(ADC_SMPR_SMP_2 | ADC_SMPR_SMP_1)) /*!< Sampling time 71.5 ADC clock cycles */
jhon309 0:88e313c910d0 470 #define ADC_SAMPLETIME_239CYCLES_5 ((uint32_t) ADC_SMPR_SMP) /*!< Sampling time 239.5 ADC clock cycles */
jhon309 0:88e313c910d0 471
jhon309 0:88e313c910d0 472 #define IS_ADC_SAMPLE_TIME(TIME) (((TIME) == ADC_SAMPLETIME_1CYCLE_5) || \
jhon309 0:88e313c910d0 473 ((TIME) == ADC_SAMPLETIME_7CYCLES_5) || \
jhon309 0:88e313c910d0 474 ((TIME) == ADC_SAMPLETIME_13CYCLES_5) || \
jhon309 0:88e313c910d0 475 ((TIME) == ADC_SAMPLETIME_28CYCLES_5) || \
jhon309 0:88e313c910d0 476 ((TIME) == ADC_SAMPLETIME_41CYCLES_5) || \
jhon309 0:88e313c910d0 477 ((TIME) == ADC_SAMPLETIME_55CYCLES_5) || \
jhon309 0:88e313c910d0 478 ((TIME) == ADC_SAMPLETIME_71CYCLES_5) || \
jhon309 0:88e313c910d0 479 ((TIME) == ADC_SAMPLETIME_239CYCLES_5) )
jhon309 0:88e313c910d0 480 /**
jhon309 0:88e313c910d0 481 * @}
jhon309 0:88e313c910d0 482 */
jhon309 0:88e313c910d0 483
jhon309 0:88e313c910d0 484 /** @defgroup ADC_analog_watchdog_mode ADC analog watchdog mode
jhon309 0:88e313c910d0 485 * @{
jhon309 0:88e313c910d0 486 */
jhon309 0:88e313c910d0 487 #define ADC_ANALOGWATCHDOG_NONE ((uint32_t) 0x00000000)
jhon309 0:88e313c910d0 488 #define ADC_ANALOGWATCHDOG_SINGLE_REG ((uint32_t)(ADC_CFGR1_AWDSGL | ADC_CFGR1_AWDEN))
jhon309 0:88e313c910d0 489 #define ADC_ANALOGWATCHDOG_ALL_REG ((uint32_t) ADC_CFGR1_AWDEN)
jhon309 0:88e313c910d0 490
jhon309 0:88e313c910d0 491
jhon309 0:88e313c910d0 492 #define IS_ADC_ANALOG_WATCHDOG_MODE(WATCHDOG) (((WATCHDOG) == ADC_ANALOGWATCHDOG_NONE) || \
jhon309 0:88e313c910d0 493 ((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_REG) || \
jhon309 0:88e313c910d0 494 ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_REG) )
jhon309 0:88e313c910d0 495 /**
jhon309 0:88e313c910d0 496 * @}
jhon309 0:88e313c910d0 497 */
jhon309 0:88e313c910d0 498
jhon309 0:88e313c910d0 499 /** @defgroup ADC_Event_type ADC Event type
jhon309 0:88e313c910d0 500 * @{
jhon309 0:88e313c910d0 501 */
jhon309 0:88e313c910d0 502 #define AWD_EVENT ((uint32_t)ADC_FLAG_AWD) /*!< ADC Analog watchdog 1 event */
jhon309 0:88e313c910d0 503 #define OVR_EVENT ((uint32_t)ADC_FLAG_OVR) /*!< ADC overrun event */
jhon309 0:88e313c910d0 504
jhon309 0:88e313c910d0 505 #define IS_ADC_EVENT_TYPE(EVENT) (((EVENT) == AWD_EVENT) || \
jhon309 0:88e313c910d0 506 ((EVENT) == OVR_EVENT) )
jhon309 0:88e313c910d0 507 /**
jhon309 0:88e313c910d0 508 * @}
jhon309 0:88e313c910d0 509 */
jhon309 0:88e313c910d0 510
jhon309 0:88e313c910d0 511 /** @defgroup ADC_interrupts_definition ADC interrupts definition
jhon309 0:88e313c910d0 512 * @{
jhon309 0:88e313c910d0 513 */
jhon309 0:88e313c910d0 514 #define ADC_IT_AWD ADC_IER_AWDIE /*!< ADC Analog watchdog interrupt source */
jhon309 0:88e313c910d0 515 #define ADC_IT_OVR ADC_IER_OVRIE /*!< ADC overrun interrupt source */
jhon309 0:88e313c910d0 516 #define ADC_IT_EOS ADC_IER_EOSEQIE /*!< ADC End of Regular sequence of Conversions interrupt source */
jhon309 0:88e313c910d0 517 #define ADC_IT_EOC ADC_IER_EOCIE /*!< ADC End of Regular Conversion interrupt source */
jhon309 0:88e313c910d0 518 #define ADC_IT_EOSMP ADC_IER_EOSMPIE /*!< ADC End of Sampling interrupt source */
jhon309 0:88e313c910d0 519 #define ADC_IT_RDY ADC_IER_ADRDYIE /*!< ADC Ready interrupt source */
jhon309 0:88e313c910d0 520 /**
jhon309 0:88e313c910d0 521 * @}
jhon309 0:88e313c910d0 522 */
jhon309 0:88e313c910d0 523
jhon309 0:88e313c910d0 524 /** @defgroup ADC_flags_definition ADC flags definition
jhon309 0:88e313c910d0 525 * @{
jhon309 0:88e313c910d0 526 */
jhon309 0:88e313c910d0 527 #define ADC_FLAG_AWD ADC_ISR_AWD /*!< ADC Analog watchdog flag */
jhon309 0:88e313c910d0 528 #define ADC_FLAG_OVR ADC_ISR_OVR /*!< ADC overrun flag */
jhon309 0:88e313c910d0 529 #define ADC_FLAG_EOS ADC_ISR_EOSEQ /*!< ADC End of Regular sequence of Conversions flag */
jhon309 0:88e313c910d0 530 #define ADC_FLAG_EOC ADC_ISR_EOC /*!< ADC End of Regular Conversion flag */
jhon309 0:88e313c910d0 531 #define ADC_FLAG_EOSMP ADC_ISR_EOSMP /*!< ADC End of Sampling flag */
jhon309 0:88e313c910d0 532 #define ADC_FLAG_RDY ADC_ISR_ADRDY /*!< ADC Ready flag */
jhon309 0:88e313c910d0 533
jhon309 0:88e313c910d0 534 #define ADC_FLAG_ALL (ADC_FLAG_AWD | ADC_FLAG_OVR | ADC_FLAG_EOS | ADC_FLAG_EOC | \
jhon309 0:88e313c910d0 535 ADC_FLAG_EOSMP | ADC_FLAG_RDY )
jhon309 0:88e313c910d0 536
jhon309 0:88e313c910d0 537 /* Combination of all post-conversion flags bits: EOC/EOS, OVR, AWD */
jhon309 0:88e313c910d0 538 #define ADC_FLAG_POSTCONV_ALL (ADC_FLAG_AWD | ADC_FLAG_OVR | ADC_FLAG_EOS | ADC_FLAG_EOC)
jhon309 0:88e313c910d0 539 /**
jhon309 0:88e313c910d0 540 * @}
jhon309 0:88e313c910d0 541 */
jhon309 0:88e313c910d0 542
jhon309 0:88e313c910d0 543 /** @defgroup ADC_range_verification ADC range verification
jhon309 0:88e313c910d0 544 * in function of ADC resolution selected (12, 10, 8 or 6 bits)
jhon309 0:88e313c910d0 545 * @{
jhon309 0:88e313c910d0 546 */
jhon309 0:88e313c910d0 547 #define IS_ADC_RANGE(RESOLUTION, ADC_VALUE) \
jhon309 0:88e313c910d0 548 ((((RESOLUTION) == ADC_RESOLUTION12b) && ((ADC_VALUE) <= ((uint32_t)0x0FFF))) || \
jhon309 0:88e313c910d0 549 (((RESOLUTION) == ADC_RESOLUTION10b) && ((ADC_VALUE) <= ((uint32_t)0x03FF))) || \
jhon309 0:88e313c910d0 550 (((RESOLUTION) == ADC_RESOLUTION8b) && ((ADC_VALUE) <= ((uint32_t)0x00FF))) || \
jhon309 0:88e313c910d0 551 (((RESOLUTION) == ADC_RESOLUTION6b) && ((ADC_VALUE) <= ((uint32_t)0x003F))) )
jhon309 0:88e313c910d0 552 /**
jhon309 0:88e313c910d0 553 * @}
jhon309 0:88e313c910d0 554 */
jhon309 0:88e313c910d0 555
jhon309 0:88e313c910d0 556 /** @defgroup ADC_regular_rank_verification ADC regular rank verification
jhon309 0:88e313c910d0 557 * @{
jhon309 0:88e313c910d0 558 */
jhon309 0:88e313c910d0 559 #define IS_ADC_REGULAR_RANK(RANK) (((RANK) >= ((uint32_t)1)) && ((RANK) <= ((uint32_t)16)))
jhon309 0:88e313c910d0 560 /**
jhon309 0:88e313c910d0 561 * @}
jhon309 0:88e313c910d0 562 */
jhon309 0:88e313c910d0 563
jhon309 0:88e313c910d0 564 /**
jhon309 0:88e313c910d0 565 * @}
jhon309 0:88e313c910d0 566 */
jhon309 0:88e313c910d0 567
jhon309 0:88e313c910d0 568 /* Exported macros -----------------------------------------------------------*/
jhon309 0:88e313c910d0 569
jhon309 0:88e313c910d0 570 /** @defgroup ADC_Exported_Macros ADC Exported Macros
jhon309 0:88e313c910d0 571 * @{
jhon309 0:88e313c910d0 572 */
jhon309 0:88e313c910d0 573 /** @brief Reset ADC handle state
jhon309 0:88e313c910d0 574 * @param __HANDLE__: ADC handle
jhon309 0:88e313c910d0 575 * @retval None
jhon309 0:88e313c910d0 576 */
jhon309 0:88e313c910d0 577 #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_ADC_STATE_RESET)
jhon309 0:88e313c910d0 578
jhon309 0:88e313c910d0 579 /* Macro for internal HAL driver usage, and possibly can be used into code of */
jhon309 0:88e313c910d0 580 /* final user. */
jhon309 0:88e313c910d0 581
jhon309 0:88e313c910d0 582 /**
jhon309 0:88e313c910d0 583 * @brief Verification of ADC state: enabled or disabled
jhon309 0:88e313c910d0 584 * @param __HANDLE__: ADC handle
jhon309 0:88e313c910d0 585 * @retval SET (ADC enabled) or RESET (ADC disabled)
jhon309 0:88e313c910d0 586 */
jhon309 0:88e313c910d0 587 /* Note: If low power mode AutoPowerOff is enabled, power-on/off phases are */
jhon309 0:88e313c910d0 588 /* performed automatically by hardware and flag ADC_FLAG_RDY is not */
jhon309 0:88e313c910d0 589 /* set. */
jhon309 0:88e313c910d0 590 #define __HAL_ADC_IS_ENABLED(__HANDLE__) \
jhon309 0:88e313c910d0 591 (( ((((__HANDLE__)->Instance->CR) & (ADC_CR_ADEN | ADC_CR_ADDIS)) == ADC_CR_ADEN) && \
jhon309 0:88e313c910d0 592 (((((__HANDLE__)->Instance->ISR) & ADC_FLAG_RDY) == ADC_FLAG_RDY) || \
jhon309 0:88e313c910d0 593 ((((__HANDLE__)->Instance->CFGR1) & ADC_CFGR1_AUTOFF) == ADC_CFGR1_AUTOFF) ) \
jhon309 0:88e313c910d0 594 ) ? SET : RESET)
jhon309 0:88e313c910d0 595
jhon309 0:88e313c910d0 596 /**
jhon309 0:88e313c910d0 597 * @brief Test if conversion trigger of regular group is software start
jhon309 0:88e313c910d0 598 * or external trigger.
jhon309 0:88e313c910d0 599 * @param __HANDLE__: ADC handle
jhon309 0:88e313c910d0 600 * @retval SET (software start) or RESET (external trigger)
jhon309 0:88e313c910d0 601 */
jhon309 0:88e313c910d0 602 #define __HAL_ADC_IS_SOFTWARE_START_REGULAR(__HANDLE__) \
jhon309 0:88e313c910d0 603 (((__HANDLE__)->Instance->CFGR1 & ADC_CFGR1_EXTEN) == RESET)
jhon309 0:88e313c910d0 604
jhon309 0:88e313c910d0 605 /**
jhon309 0:88e313c910d0 606 * @brief Check if no conversion on going on regular group
jhon309 0:88e313c910d0 607 * @param __HANDLE__: ADC handle
jhon309 0:88e313c910d0 608 * @retval SET (conversion is on going) or RESET (no conversion is on going)
jhon309 0:88e313c910d0 609 */
jhon309 0:88e313c910d0 610 #define __HAL_ADC_IS_CONVERSION_ONGOING_REGULAR(__HANDLE__) \
jhon309 0:88e313c910d0 611 (( (((__HANDLE__)->Instance->CR) & ADC_CR_ADSTART) == RESET \
jhon309 0:88e313c910d0 612 ) ? RESET : SET)
jhon309 0:88e313c910d0 613
jhon309 0:88e313c910d0 614 /**
jhon309 0:88e313c910d0 615 * @brief Returns resolution bits in CFGR1 register: RES[1:0].
jhon309 0:88e313c910d0 616 * Returned value is among parameters to @ref ADC_Resolution.
jhon309 0:88e313c910d0 617 * @param __HANDLE__: ADC handle
jhon309 0:88e313c910d0 618 * @retval None
jhon309 0:88e313c910d0 619 */
jhon309 0:88e313c910d0 620 #define __HAL_ADC_GET_RESOLUTION(__HANDLE__) (((__HANDLE__)->Instance->CFGR1) & ADC_CFGR1_RES)
jhon309 0:88e313c910d0 621
jhon309 0:88e313c910d0 622 /**
jhon309 0:88e313c910d0 623 * @brief Returns ADC sample time bits in SMPR register: SMP[2:0].
jhon309 0:88e313c910d0 624 * Returned value is among parameters to @ref ADC_Resolution.
jhon309 0:88e313c910d0 625 * @param __HANDLE__: ADC handle
jhon309 0:88e313c910d0 626 * @retval None
jhon309 0:88e313c910d0 627 */
jhon309 0:88e313c910d0 628 #define __HAL_ADC_GET_SAMPLINGTIME(__HANDLE__) (((__HANDLE__)->Instance->SMPR) & ADC_SMPR_SMP)
jhon309 0:88e313c910d0 629
jhon309 0:88e313c910d0 630 /** @brief Checks if the specified ADC interrupt source is enabled or disabled.
jhon309 0:88e313c910d0 631 * @param __HANDLE__: ADC handle
jhon309 0:88e313c910d0 632 * @param __INTERRUPT__: ADC interrupt source to check
jhon309 0:88e313c910d0 633 * @retval State ofinterruption (SET or RESET)
jhon309 0:88e313c910d0 634 */
jhon309 0:88e313c910d0 635 #define __HAL_ADC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) \
jhon309 0:88e313c910d0 636 (( ((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__) \
jhon309 0:88e313c910d0 637 )? SET : RESET \
jhon309 0:88e313c910d0 638 )
jhon309 0:88e313c910d0 639
jhon309 0:88e313c910d0 640 /**
jhon309 0:88e313c910d0 641 * @brief Enable the ADC end of conversion interrupt.
jhon309 0:88e313c910d0 642 * @param __HANDLE__: ADC handle
jhon309 0:88e313c910d0 643 * @param __INTERRUPT__: ADC Interrupt
jhon309 0:88e313c910d0 644 * @retval None
jhon309 0:88e313c910d0 645 */
jhon309 0:88e313c910d0 646 #define __HAL_ADC_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) |= (__INTERRUPT__))
jhon309 0:88e313c910d0 647
jhon309 0:88e313c910d0 648 /**
jhon309 0:88e313c910d0 649 * @brief Disable the ADC end of conversion interrupt.
jhon309 0:88e313c910d0 650 * @param __HANDLE__: ADC handle
jhon309 0:88e313c910d0 651 * @param __INTERRUPT__: ADC Interrupt
jhon309 0:88e313c910d0 652 * @retval None
jhon309 0:88e313c910d0 653 */
jhon309 0:88e313c910d0 654 #define __HAL_ADC_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) &= ~(__INTERRUPT__))
jhon309 0:88e313c910d0 655
jhon309 0:88e313c910d0 656 /**
jhon309 0:88e313c910d0 657 * @brief Get the selected ADC's flag status.
jhon309 0:88e313c910d0 658 * @param __HANDLE__: ADC handle
jhon309 0:88e313c910d0 659 * @param __FLAG__: ADC flag
jhon309 0:88e313c910d0 660 * @retval None
jhon309 0:88e313c910d0 661 */
jhon309 0:88e313c910d0 662 #define __HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->ISR) & (__FLAG__)) == (__FLAG__))
jhon309 0:88e313c910d0 663
jhon309 0:88e313c910d0 664 /**
jhon309 0:88e313c910d0 665 * @brief Clear the ADC's pending flags
jhon309 0:88e313c910d0 666 * @param __HANDLE__: ADC handle
jhon309 0:88e313c910d0 667 * @param __FLAG__: ADC flag
jhon309 0:88e313c910d0 668 * @retval None
jhon309 0:88e313c910d0 669 */
jhon309 0:88e313c910d0 670 /* Note: bit cleared bit by writing 1 (writing 0 has no effect on any bit of register ISR) */
jhon309 0:88e313c910d0 671 #define __HAL_ADC_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR) = (__FLAG__))
jhon309 0:88e313c910d0 672
jhon309 0:88e313c910d0 673 /**
jhon309 0:88e313c910d0 674 * @brief Clear ADC error code (set it to error code: "no error")
jhon309 0:88e313c910d0 675 * @param __HANDLE__: ADC handle
jhon309 0:88e313c910d0 676 * @retval None
jhon309 0:88e313c910d0 677 */
jhon309 0:88e313c910d0 678 #define __HAL_ADC_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_ADC_ERROR_NONE)
jhon309 0:88e313c910d0 679
jhon309 0:88e313c910d0 680
jhon309 0:88e313c910d0 681 /**
jhon309 0:88e313c910d0 682 * @brief Configure the channel number into channel selection register
jhon309 0:88e313c910d0 683 * @param _CHANNEL_: ADC Channel
jhon309 0:88e313c910d0 684 * @retval None
jhon309 0:88e313c910d0 685 */
jhon309 0:88e313c910d0 686 /* This function converts ADC channels from numbers (see defgroup ADC_channels)
jhon309 0:88e313c910d0 687 to bitfields, to get the equivalence of CMSIS channels:
jhon309 0:88e313c910d0 688 ADC_CHANNEL_0 ((uint32_t) ADC_CHSELR_CHSEL0)
jhon309 0:88e313c910d0 689 ADC_CHANNEL_1 ((uint32_t) ADC_CHSELR_CHSEL1)
jhon309 0:88e313c910d0 690 ADC_CHANNEL_2 ((uint32_t) ADC_CHSELR_CHSEL2)
jhon309 0:88e313c910d0 691 ADC_CHANNEL_3 ((uint32_t) ADC_CHSELR_CHSEL3)
jhon309 0:88e313c910d0 692 ADC_CHANNEL_4 ((uint32_t) ADC_CHSELR_CHSEL4)
jhon309 0:88e313c910d0 693 ADC_CHANNEL_5 ((uint32_t) ADC_CHSELR_CHSEL5)
jhon309 0:88e313c910d0 694 ADC_CHANNEL_6 ((uint32_t) ADC_CHSELR_CHSEL6)
jhon309 0:88e313c910d0 695 ADC_CHANNEL_7 ((uint32_t) ADC_CHSELR_CHSEL7)
jhon309 0:88e313c910d0 696 ADC_CHANNEL_8 ((uint32_t) ADC_CHSELR_CHSEL8)
jhon309 0:88e313c910d0 697 ADC_CHANNEL_9 ((uint32_t) ADC_CHSELR_CHSEL9)
jhon309 0:88e313c910d0 698 ADC_CHANNEL_10 ((uint32_t) ADC_CHSELR_CHSEL10)
jhon309 0:88e313c910d0 699 ADC_CHANNEL_11 ((uint32_t) ADC_CHSELR_CHSEL11)
jhon309 0:88e313c910d0 700 ADC_CHANNEL_12 ((uint32_t) ADC_CHSELR_CHSEL12)
jhon309 0:88e313c910d0 701 ADC_CHANNEL_13 ((uint32_t) ADC_CHSELR_CHSEL13)
jhon309 0:88e313c910d0 702 ADC_CHANNEL_14 ((uint32_t) ADC_CHSELR_CHSEL14)
jhon309 0:88e313c910d0 703 ADC_CHANNEL_15 ((uint32_t) ADC_CHSELR_CHSEL15)
jhon309 0:88e313c910d0 704 ADC_CHANNEL_16 ((uint32_t) ADC_CHSELR_CHSEL16)
jhon309 0:88e313c910d0 705 ADC_CHANNEL_17 ((uint32_t) ADC_CHSELR_CHSEL17)
jhon309 0:88e313c910d0 706 ADC_CHANNEL_18 ((uint32_t) ADC_CHSELR_CHSEL18)
jhon309 0:88e313c910d0 707 */
jhon309 0:88e313c910d0 708 #define __HAL_ADC_CHSELR_CHANNEL(_CHANNEL_) ( 1U << (_CHANNEL_))
jhon309 0:88e313c910d0 709
jhon309 0:88e313c910d0 710 /**
jhon309 0:88e313c910d0 711 * @}
jhon309 0:88e313c910d0 712 */
jhon309 0:88e313c910d0 713
jhon309 0:88e313c910d0 714 /** @defgroup ADC_Exported_Macro_internal_HAL_driver ADC Exported Macro internal HAL driver
jhon309 0:88e313c910d0 715 * @{
jhon309 0:88e313c910d0 716 */
jhon309 0:88e313c910d0 717 /* Macro reserved for internal HAL driver usage, not intended to be used in */
jhon309 0:88e313c910d0 718 /* code of final user. */
jhon309 0:88e313c910d0 719
jhon309 0:88e313c910d0 720 /**
jhon309 0:88e313c910d0 721 * @brief Set the Analog Watchdog 1 channel.
jhon309 0:88e313c910d0 722 * @param _CHANNEL_: channel to be monitored by Analog Watchdog 1.
jhon309 0:88e313c910d0 723 * @retval None
jhon309 0:88e313c910d0 724 */
jhon309 0:88e313c910d0 725 #define __HAL_ADC_CFGR_AWDCH(_CHANNEL_) ((_CHANNEL_) << 26)
jhon309 0:88e313c910d0 726
jhon309 0:88e313c910d0 727 /**
jhon309 0:88e313c910d0 728 * @brief Enable ADC discontinuous conversion mode for regular group
jhon309 0:88e313c910d0 729 * @param _REG_DISCONTINUOUS_MODE_: Regular discontinuous mode.
jhon309 0:88e313c910d0 730 * @retval None
jhon309 0:88e313c910d0 731 */
jhon309 0:88e313c910d0 732 #define __HAL_ADC_CFGR1_REG_DISCCONTINUOUS(_REG_DISCONTINUOUS_MODE_) ((_REG_DISCONTINUOUS_MODE_) << 16)
jhon309 0:88e313c910d0 733
jhon309 0:88e313c910d0 734 /**
jhon309 0:88e313c910d0 735 * @brief Enable the ADC auto off mode.
jhon309 0:88e313c910d0 736 * @param _AUTOOFF_: Auto off bit enable or disable.
jhon309 0:88e313c910d0 737 * @retval None
jhon309 0:88e313c910d0 738 */
jhon309 0:88e313c910d0 739 #define __HAL_ADC_CFGR1_AUTOOFF(_AUTOOFF_) ((_AUTOOFF_) << 15)
jhon309 0:88e313c910d0 740
jhon309 0:88e313c910d0 741 /**
jhon309 0:88e313c910d0 742 * @brief Enable the ADC auto delay mode.
jhon309 0:88e313c910d0 743 * @param _AUTOWAIT_: Auto delay bit enable or disable.
jhon309 0:88e313c910d0 744 * @retval None
jhon309 0:88e313c910d0 745 */
jhon309 0:88e313c910d0 746 #define __HAL_ADC_CFGR1_AUTOWAIT(_AUTOWAIT_) ((_AUTOWAIT_) << 14)
jhon309 0:88e313c910d0 747
jhon309 0:88e313c910d0 748 /**
jhon309 0:88e313c910d0 749 * @brief Enable ADC continuous conversion mode.
jhon309 0:88e313c910d0 750 * @param _CONTINUOUS_MODE_: Continuous mode.
jhon309 0:88e313c910d0 751 * @retval None
jhon309 0:88e313c910d0 752 */
jhon309 0:88e313c910d0 753 #define __HAL_ADC_CFGR1_CONTINUOUS(_CONTINUOUS_MODE_) ((_CONTINUOUS_MODE_) << 13)
jhon309 0:88e313c910d0 754
jhon309 0:88e313c910d0 755 /**
jhon309 0:88e313c910d0 756 * @brief Enable ADC overrun mode.
jhon309 0:88e313c910d0 757 * @param _OVERRUN_MODE_: Overrun mode.
jhon309 0:88e313c910d0 758 * @retval Overun bit setting to be programmed into CFGR register
jhon309 0:88e313c910d0 759 */
jhon309 0:88e313c910d0 760 /* Note: Bit ADC_CFGR1_OVRMOD not used directly in constant */
jhon309 0:88e313c910d0 761 /* "OVR_DATA_OVERWRITTEN" to have this case defined to 0x00, to set it as the */
jhon309 0:88e313c910d0 762 /* default case to be compliant with other STM32 devices. */
jhon309 0:88e313c910d0 763 #define __HAL_ADC_CFGR1_OVERRUN(_OVERRUN_MODE_) \
jhon309 0:88e313c910d0 764 ( ( (_OVERRUN_MODE_) != (OVR_DATA_PRESERVED) \
jhon309 0:88e313c910d0 765 )? (ADC_CFGR1_OVRMOD) : (0x00000000) \
jhon309 0:88e313c910d0 766 )
jhon309 0:88e313c910d0 767
jhon309 0:88e313c910d0 768 /**
jhon309 0:88e313c910d0 769 * @brief Enable ADC scan mode to convert multiple ranks with sequencer.
jhon309 0:88e313c910d0 770 * @param _SCAN_MODE_: Scan conversion mode.
jhon309 0:88e313c910d0 771 * @retval None
jhon309 0:88e313c910d0 772 */
jhon309 0:88e313c910d0 773 #define __HAL_ADC_CFGR1_SCANDIR(_SCAN_MODE_) \
jhon309 0:88e313c910d0 774 ( ( (_SCAN_MODE_) == (ADC_SCAN_DIRECTION_BACKWARD) \
jhon309 0:88e313c910d0 775 )? (ADC_CFGR1_SCANDIR) : (0x00000000) \
jhon309 0:88e313c910d0 776 )
jhon309 0:88e313c910d0 777
jhon309 0:88e313c910d0 778 /**
jhon309 0:88e313c910d0 779 * @brief Enable the ADC DMA continuous request.
jhon309 0:88e313c910d0 780 * @param _DMACONTREQ_MODE_: DMA continuous request mode.
jhon309 0:88e313c910d0 781 * @retval None
jhon309 0:88e313c910d0 782 */
jhon309 0:88e313c910d0 783 #define __HAL_ADC_CFGR1_DMACONTREQ(_DMACONTREQ_MODE_) ((_DMACONTREQ_MODE_) << 1)
jhon309 0:88e313c910d0 784
jhon309 0:88e313c910d0 785 /**
jhon309 0:88e313c910d0 786 * @brief Configure the analog watchdog high threshold into register TR.
jhon309 0:88e313c910d0 787 * @param _Threshold_: Threshold value
jhon309 0:88e313c910d0 788 * @retval None
jhon309 0:88e313c910d0 789 */
jhon309 0:88e313c910d0 790 #define __HAL_ADC_TRX_HIGHTHRESHOLD(_Threshold_) ((_Threshold_) << 16)
jhon309 0:88e313c910d0 791
jhon309 0:88e313c910d0 792 /**
jhon309 0:88e313c910d0 793 * @brief Enable the ADC peripheral
jhon309 0:88e313c910d0 794 * @param __HANDLE__: ADC handle
jhon309 0:88e313c910d0 795 * @retval None
jhon309 0:88e313c910d0 796 */
jhon309 0:88e313c910d0 797 #define __HAL_ADC_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= ADC_CR_ADEN)
jhon309 0:88e313c910d0 798
jhon309 0:88e313c910d0 799 /**
jhon309 0:88e313c910d0 800 * @brief Verification of hardware constraints before ADC can be enabled
jhon309 0:88e313c910d0 801 * @param __HANDLE__: ADC handle
jhon309 0:88e313c910d0 802 * @retval SET (ADC can be enabled) or RESET (ADC cannot be enabled)
jhon309 0:88e313c910d0 803 */
jhon309 0:88e313c910d0 804 #define __HAL_ADC_ENABLING_CONDITIONS(__HANDLE__) \
jhon309 0:88e313c910d0 805 (( ( ((__HANDLE__)->Instance->CR) & \
jhon309 0:88e313c910d0 806 (ADC_CR_ADCAL | ADC_CR_ADSTP | \
jhon309 0:88e313c910d0 807 ADC_CR_ADSTART | ADC_CR_ADDIS | ADC_CR_ADEN ) \
jhon309 0:88e313c910d0 808 ) == RESET \
jhon309 0:88e313c910d0 809 ) ? SET : RESET)
jhon309 0:88e313c910d0 810
jhon309 0:88e313c910d0 811 /**
jhon309 0:88e313c910d0 812 * @brief Disable the ADC peripheral
jhon309 0:88e313c910d0 813 * @param __HANDLE__: ADC handle
jhon309 0:88e313c910d0 814 * @retval None
jhon309 0:88e313c910d0 815 */
jhon309 0:88e313c910d0 816 #define __HAL_ADC_DISABLE(__HANDLE__) \
jhon309 0:88e313c910d0 817 do{ \
jhon309 0:88e313c910d0 818 (__HANDLE__)->Instance->CR |= ADC_CR_ADDIS; \
jhon309 0:88e313c910d0 819 __HAL_ADC_CLEAR_FLAG((__HANDLE__), (ADC_FLAG_EOSMP | ADC_FLAG_RDY)); \
jhon309 0:88e313c910d0 820 } while(0)
jhon309 0:88e313c910d0 821
jhon309 0:88e313c910d0 822 /**
jhon309 0:88e313c910d0 823 * @brief Verification of hardware constraints before ADC can be disabled
jhon309 0:88e313c910d0 824 * @param __HANDLE__: ADC handle
jhon309 0:88e313c910d0 825 * @retval SET (ADC can be disabled) or RESET (ADC cannot be disabled)
jhon309 0:88e313c910d0 826 */
jhon309 0:88e313c910d0 827 #define __HAL_ADC_DISABLING_CONDITIONS(__HANDLE__) \
jhon309 0:88e313c910d0 828 (( ( ((__HANDLE__)->Instance->CR) & \
jhon309 0:88e313c910d0 829 (ADC_CR_ADSTART | ADC_CR_ADEN)) == ADC_CR_ADEN \
jhon309 0:88e313c910d0 830 ) ? SET : RESET)
jhon309 0:88e313c910d0 831
jhon309 0:88e313c910d0 832 /**
jhon309 0:88e313c910d0 833 * @brief Shift the AWD threshold in function of the selected ADC resolution.
jhon309 0:88e313c910d0 834 * Thresholds have to be left-aligned on bit 11, the LSB (right bits) are set to 0.
jhon309 0:88e313c910d0 835 * If resolution 12 bits, no shift.
jhon309 0:88e313c910d0 836 * If resolution 10 bits, shift of 2 ranks on the left.
jhon309 0:88e313c910d0 837 * If resolution 8 bits, shift of 4 ranks on the left.
jhon309 0:88e313c910d0 838 * If resolution 6 bits, shift of 6 ranks on the left.
jhon309 0:88e313c910d0 839 * therefore, shift = (12 - resolution) = 12 - (12- (((RES[1:0]) >> 3)*2))
jhon309 0:88e313c910d0 840 * @param __HANDLE__: ADC handle
jhon309 0:88e313c910d0 841 * @param _Threshold_: Value to be shifted
jhon309 0:88e313c910d0 842 * @retval None
jhon309 0:88e313c910d0 843 */
jhon309 0:88e313c910d0 844 #define __HAL_ADC_AWD1THRESHOLD_SHIFT_RESOLUTION(__HANDLE__, _Threshold_) \
jhon309 0:88e313c910d0 845 ((_Threshold_) << ((((__HANDLE__)->Instance->CFGR1 & ADC_CFGR1_RES) >> 3)*2))
jhon309 0:88e313c910d0 846
jhon309 0:88e313c910d0 847 /**
jhon309 0:88e313c910d0 848 * @}
jhon309 0:88e313c910d0 849 */
jhon309 0:88e313c910d0 850
jhon309 0:88e313c910d0 851 /* Include ADC HAL Extension module */
jhon309 0:88e313c910d0 852 #include "stm32f0xx_hal_adc_ex.h"
jhon309 0:88e313c910d0 853
jhon309 0:88e313c910d0 854 /* Exported functions --------------------------------------------------------*/
jhon309 0:88e313c910d0 855 /** @addtogroup ADC_Exported_Functions
jhon309 0:88e313c910d0 856 * @{
jhon309 0:88e313c910d0 857 */
jhon309 0:88e313c910d0 858
jhon309 0:88e313c910d0 859 /** @addtogroup ADC_Exported_Functions_Group1
jhon309 0:88e313c910d0 860 * @{
jhon309 0:88e313c910d0 861 */
jhon309 0:88e313c910d0 862
jhon309 0:88e313c910d0 863
jhon309 0:88e313c910d0 864 /* Initialization and de-initialization functions **********************************/
jhon309 0:88e313c910d0 865 HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc);
jhon309 0:88e313c910d0 866 HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef *hadc);
jhon309 0:88e313c910d0 867 void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc);
jhon309 0:88e313c910d0 868 void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc);
jhon309 0:88e313c910d0 869 /**
jhon309 0:88e313c910d0 870 * @}
jhon309 0:88e313c910d0 871 */
jhon309 0:88e313c910d0 872
jhon309 0:88e313c910d0 873 /* IO operation functions *****************************************************/
jhon309 0:88e313c910d0 874
jhon309 0:88e313c910d0 875 /** @addtogroup ADC_Exported_Functions_Group2
jhon309 0:88e313c910d0 876 * @{
jhon309 0:88e313c910d0 877 */
jhon309 0:88e313c910d0 878
jhon309 0:88e313c910d0 879
jhon309 0:88e313c910d0 880 /* Blocking mode: Polling */
jhon309 0:88e313c910d0 881 HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc);
jhon309 0:88e313c910d0 882 HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc);
jhon309 0:88e313c910d0 883 HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout);
jhon309 0:88e313c910d0 884 HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout);
jhon309 0:88e313c910d0 885
jhon309 0:88e313c910d0 886 /* Non-blocking mode: Interruption */
jhon309 0:88e313c910d0 887 HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc);
jhon309 0:88e313c910d0 888 HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc);
jhon309 0:88e313c910d0 889
jhon309 0:88e313c910d0 890 /* Non-blocking mode: DMA */
jhon309 0:88e313c910d0 891 HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length);
jhon309 0:88e313c910d0 892 HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc);
jhon309 0:88e313c910d0 893
jhon309 0:88e313c910d0 894 /* ADC retrieve conversion value intended to be used with polling or interruption */
jhon309 0:88e313c910d0 895 uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc);
jhon309 0:88e313c910d0 896
jhon309 0:88e313c910d0 897 /* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption and DMA) */
jhon309 0:88e313c910d0 898 void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc);
jhon309 0:88e313c910d0 899 void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc);
jhon309 0:88e313c910d0 900 void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc);
jhon309 0:88e313c910d0 901 void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc);
jhon309 0:88e313c910d0 902 void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc);
jhon309 0:88e313c910d0 903 /**
jhon309 0:88e313c910d0 904 * @}
jhon309 0:88e313c910d0 905 */
jhon309 0:88e313c910d0 906
jhon309 0:88e313c910d0 907
jhon309 0:88e313c910d0 908 /* Peripheral Control functions ***********************************************/
jhon309 0:88e313c910d0 909 /** @addtogroup ADC_Exported_Functions_Group3
jhon309 0:88e313c910d0 910 * @{
jhon309 0:88e313c910d0 911 */
jhon309 0:88e313c910d0 912 HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig);
jhon309 0:88e313c910d0 913 HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig);
jhon309 0:88e313c910d0 914 /**
jhon309 0:88e313c910d0 915 * @}
jhon309 0:88e313c910d0 916 */
jhon309 0:88e313c910d0 917
jhon309 0:88e313c910d0 918
jhon309 0:88e313c910d0 919 /* Peripheral State functions *************************************************/
jhon309 0:88e313c910d0 920 /** @addtogroup ADC_Exported_Functions_Group4
jhon309 0:88e313c910d0 921 * @{
jhon309 0:88e313c910d0 922 */
jhon309 0:88e313c910d0 923 HAL_ADC_StateTypeDef HAL_ADC_GetState(ADC_HandleTypeDef* hadc);
jhon309 0:88e313c910d0 924 uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc);
jhon309 0:88e313c910d0 925 /**
jhon309 0:88e313c910d0 926 * @}
jhon309 0:88e313c910d0 927 */
jhon309 0:88e313c910d0 928
jhon309 0:88e313c910d0 929
jhon309 0:88e313c910d0 930 /**
jhon309 0:88e313c910d0 931 * @}
jhon309 0:88e313c910d0 932 */
jhon309 0:88e313c910d0 933
jhon309 0:88e313c910d0 934
jhon309 0:88e313c910d0 935 /**
jhon309 0:88e313c910d0 936 * @}
jhon309 0:88e313c910d0 937 */
jhon309 0:88e313c910d0 938
jhon309 0:88e313c910d0 939 /**
jhon309 0:88e313c910d0 940 * @}
jhon309 0:88e313c910d0 941 */
jhon309 0:88e313c910d0 942
jhon309 0:88e313c910d0 943 #ifdef __cplusplus
jhon309 0:88e313c910d0 944 }
jhon309 0:88e313c910d0 945 #endif
jhon309 0:88e313c910d0 946
jhon309 0:88e313c910d0 947
jhon309 0:88e313c910d0 948 #endif /* __STM32F0xx_HAL_ADC_H */
jhon309 0:88e313c910d0 949
jhon309 0:88e313c910d0 950 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
jhon309 0:88e313c910d0 951