/TARGET_K64F/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_KPSDK_CODE/hal/adc/fsl_adc_hal.h substitute line 894 extern } by }

Fork of mbed by mbed official

Committer:
bogdanm
Date:
Wed Jun 11 15:14:05 2014 +0100
Revision:
85:024bf7f99721
Child:
92:4fc01daae5a5
Release 85 of the mbed library

Main changes:

- K64F Ethernet fixes
- Updated tests
- Fixes for various mbed targets
- Code cleanup: fixed warnings, more consistent code style
- GCC support for K64F

There is a known issue with the I2C interface on some ST targets. If you
find the I2C interface problematic on your ST board, please log a bug
against this on mbed.org.

Who changed what in which revision?

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