The official mbed C/C SDK provides the software platform and libraries to build your applications.

Fork of mbed by mbed official

Committer:
Mikchel
Date:
Sun May 03 16:04:42 2015 +0000
Revision:
99:7f6c6de930c0
Parent:
93:e188a91d3eaa
12

Who changed what in which revision?

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