mbed official / mbed

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

Committer:
Kojto
Date:
Thu Jul 07 14:34:11 2016 +0100
Revision:
122:f9eeca106725
Parent:
109:9296ab0bfc11
Release 122 of the mbed library

Changes:
- new targets - Nucleo L432KC, Beetle, Nucleo F446ZE, Nucleo L011K4
- Thread safety addition - mbed API should contain a statement about thread safety
- critical section API addition
- CAS API (core_util_atomic_incr/decr)
- DEVICE_ are generated from targets.json file, device.h deprecated
- Callback replaces FunctionPointer to provide std like interface
- mbed HAL API docs improvements
- toolchain - prexif attributes with MBED_
- add new attributes - packed, weak, forcedinline, align
- target.json - contains targets definitions
- ST - L1XX - Cube update to 1.5
- SPI clock selection fix (clock from APB domain)
- F7 - Cube update v1.4.0
- L0 - baudrate init fix
- L1 - Cube update v1.5
- F3 - baudrate init fix, 3 targets CAN support
- F4 - Cube update v1.12.0, 3 targets CAN support
- L4XX - Cube update v1.5.1
- F0 - update Cube to v1.5.0
- L4 - 2 targets (L476RG/VG) CAN support
- NXP - pwm clock fix for KSDK2 MCU
- LPC2368 - remove ARM toolchain support - due to regression
- KSDK2 - fix SPI , I2C address and repeat start
- Silabs - some fixes backported from mbed 3
- Renesas - RZ_A1H - SystemCoreClockUpdate addition

Who changed what in which revision?

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