mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Thu May 22 20:00:09 2014 +0100
Revision:
205:c41fc65bcfb4
Child:
218:44081b78fdc2
Synchronized with git revision ea4b6f76efab17a3f7d7777b0cc1ef05fec6d1cb

Full URL: https://github.com/mbedmicro/mbed/commit/ea4b6f76efab17a3f7d7777b0cc1ef05fec6d1cb/

[NUCLEO_F072RB] cmsis files

Who changed what in which revision?

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