xref: /btstack/port/stm32-l451-miromico-sx1280/Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_adc.h (revision 2fd737d36a1de5d778cacc671d4b4d8c4f3fed82)
1 /**
2   ******************************************************************************
3   * @file    stm32l4xx_hal_adc.h
4   * @author  MCD Application Team
5   * @brief   Header file of ADC HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
10   * All rights reserved.</center></h2>
11   *
12   * This software component is licensed by ST under BSD 3-Clause license,
13   * the "License"; You may not use this file except in compliance with the
14   * License. You may obtain a copy of the License at:
15   *                        opensource.org/licenses/BSD-3-Clause
16   *
17   ******************************************************************************
18   */
19 
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32L4xx_HAL_ADC_H
22 #define STM32L4xx_HAL_ADC_H
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32l4xx_hal_def.h"
30 
31 /* Include low level driver */
32 #include "stm32l4xx_ll_adc.h"
33 
34 /** @addtogroup STM32L4xx_HAL_Driver
35   * @{
36   */
37 
38 /** @addtogroup ADC
39   * @{
40   */
41 
42 /* Exported types ------------------------------------------------------------*/
43 /** @defgroup ADC_Exported_Types ADC Exported Types
44   * @{
45   */
46 
47 /**
48   * @brief  ADC group regular oversampling structure definition
49   */
50 typedef struct
51 {
52   uint32_t Ratio;                         /*!< Configures the oversampling ratio.
53                                                This parameter can be a value of @ref ADC_HAL_EC_OVS_RATIO */
54 
55   uint32_t RightBitShift;                 /*!< Configures the division coefficient for the Oversampler.
56                                                This parameter can be a value of @ref ADC_HAL_EC_OVS_SHIFT */
57 
58   uint32_t TriggeredMode;                 /*!< Selects the regular triggered oversampling mode.
59                                                This parameter can be a value of @ref ADC_HAL_EC_OVS_DISCONT_MODE */
60 
61   uint32_t OversamplingStopReset;         /*!< Selects the regular oversampling mode.
62                                                The oversampling is either temporary stopped or reset upon an injected
63                                                sequence interruption.
64                                                If oversampling is enabled on both regular and injected groups, this parameter
65                                                is discarded and forced to setting "ADC_REGOVERSAMPLING_RESUMED_MODE"
66                                                (the oversampling buffer is zeroed during injection sequence).
67                                                This parameter can be a value of @ref ADC_HAL_EC_OVS_SCOPE_REG */
68 
69 } ADC_OversamplingTypeDef;
70 
71 /**
72   * @brief  Structure definition of ADC instance and ADC group regular.
73   * @note   Parameters of this structure are shared within 2 scopes:
74   *          - Scope entire ADC (affects ADC groups regular and injected): ClockPrescaler, Resolution, DataAlign,
75   *            ScanConvMode, EOCSelection, LowPowerAutoWait.
76   *          - Scope ADC group regular: ContinuousConvMode, NbrOfConversion, DiscontinuousConvMode, NbrOfDiscConversion,
77   *            ExternalTrigConv, ExternalTrigConvEdge, DMAContinuousRequests, Overrun, OversamplingMode, Oversampling.
78   * @note   The setting of these parameters by function HAL_ADC_Init() is conditioned to ADC state.
79   *         ADC state can be either:
80   *          - For all parameters: ADC disabled
81   *          - For all parameters except 'LowPowerAutoWait', 'DMAContinuousRequests' and 'Oversampling': ADC enabled without conversion on going on group regular.
82   *          - For parameters 'LowPowerAutoWait' and 'DMAContinuousRequests': ADC enabled without conversion on going on groups regular and injected.
83   *         If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed
84   *         without error reporting (as it can be the expected behavior in case of intended action to update another parameter
85   *         (which fulfills the ADC state condition) on the fly).
86   */
87 typedef struct
88 {
89   uint32_t ClockPrescaler;        /*!< Select ADC clock source (synchronous clock derived from APB clock or asynchronous clock derived from system clock or PLL (Refer to reference manual for list of clocks available)) and clock prescaler.
90                                        This parameter can be a value of @ref ADC_HAL_EC_COMMON_CLOCK_SOURCE.
91                                        Note: The ADC clock configuration is common to all ADC instances.
92                                        Note: In case of usage of channels on injected group, ADC frequency should be lower than AHB clock frequency /4 for resolution 12 or 10 bits,
93                                              AHB clock frequency /3 for resolution 8 bits, AHB clock frequency /2 for resolution 6 bits.
94                                        Note: In case of synchronous clock mode based on HCLK/1, the configuration must be enabled only
95                                              if the system clock has a 50% duty clock cycle (APB prescaler configured inside RCC
96                                              must be bypassed and PCLK clock must have 50% duty cycle). Refer to reference manual for details.
97                                        Note: In case of usage of asynchronous clock, the selected clock must be preliminarily enabled at RCC top level.
98                                        Note: This parameter can be modified only if all ADC instances are disabled. */
99 
100   uint32_t Resolution;            /*!< Configure the ADC resolution.
101                                        This parameter can be a value of @ref ADC_HAL_EC_RESOLUTION */
102 
103   uint32_t DataAlign;             /*!< Specify ADC data alignment in conversion data register (right or left).
104                                        Refer to reference manual for alignments formats versus resolutions.
105                                        This parameter can be a value of @ref ADC_HAL_EC_DATA_ALIGN */
106 
107   uint32_t ScanConvMode;          /*!< Configure the sequencer of ADC groups regular and injected.
108                                        This parameter can be associated to parameter 'DiscontinuousConvMode' to have main sequence subdivided in successive parts.
109                                        If disabled: Conversion is performed in single mode (one channel converted, the one defined in rank 1).
110                                                     Parameters 'NbrOfConversion' and 'InjectedNbrOfConversion' are discarded (equivalent to set to 1).
111                                        If enabled:  Conversions are performed in sequence mode (multiple ranks defined by 'NbrOfConversion' or 'InjectedNbrOfConversion' and rank of each channel in sequencer).
112                                                     Scan direction is upward: from rank 1 to rank 'n'.
113                                        This parameter can be a value of @ref ADC_Scan_mode */
114 
115   uint32_t EOCSelection;          /*!< Specify which EOC (End Of Conversion) flag is used for conversion by polling and interruption: end of unitary conversion or end of sequence conversions.
116                                        This parameter can be a value of @ref ADC_EOCSelection. */
117 
118   FunctionalState LowPowerAutoWait; /*!< Select the dynamic low power Auto Delay: new conversion start only when the previous
119                                        conversion (for ADC group regular) or previous sequence (for ADC group injected) has been retrieved by user software,
120                                        using function HAL_ADC_GetValue() or HAL_ADCEx_InjectedGetValue().
121                                        This feature automatically adapts the frequency of ADC conversions triggers to the speed of the system that reads the data. Moreover, this avoids risk of overrun
122                                        for low frequency applications.
123                                        This parameter can be set to ENABLE or DISABLE.
124                                        Note: Do not use with interruption or DMA (HAL_ADC_Start_IT(), HAL_ADC_Start_DMA()) since they clear immediately the EOC flag
125                                              to free the IRQ vector sequencer.
126                                              Do use with polling: 1. Start conversion with HAL_ADC_Start(), 2. Later on, when ADC conversion data is needed:
127                                              use HAL_ADC_PollForConversion() to ensure that conversion is completed and HAL_ADC_GetValue() to retrieve conversion result and trig another conversion start.
128                                              (in case of usage of ADC group injected, use the equivalent functions HAL_ADCExInjected_Start(), HAL_ADCEx_InjectedGetValue(), ...). */
129 
130   FunctionalState ContinuousConvMode; /*!< Specify whether the conversion is performed in single mode (one conversion) or continuous mode for ADC group regular,
131                                        after the first ADC conversion start trigger occurred (software start or external trigger).
132                                        This parameter can be set to ENABLE or DISABLE. */
133 
134   uint32_t NbrOfConversion;       /*!< Specify the number of ranks that will be converted within the regular group sequencer.
135                                        To use the regular group sequencer and convert several ranks, parameter 'ScanConvMode' must be enabled.
136                                        This parameter must be a number between Min_Data = 1 and Max_Data = 16.
137                                        Note: This parameter must be modified when no conversion is on going on regular group (ADC disabled, or ADC enabled without
138                                        continuous mode or external trigger that could launch a conversion). */
139 
140   FunctionalState DiscontinuousConvMode; /*!< Specify whether the conversions sequence of ADC group regular is performed in Complete-sequence/Discontinuous-sequence
141                                        (main sequence subdivided in successive parts).
142                                        Discontinuous mode is used only if sequencer is enabled (parameter 'ScanConvMode'). If sequencer is disabled, this parameter is discarded.
143                                        Discontinuous mode can be enabled only if continuous mode is disabled. If continuous mode is enabled, this parameter setting is discarded.
144                                        This parameter can be set to ENABLE or DISABLE. */
145 
146   uint32_t NbrOfDiscConversion;   /*!< Specifies the number of discontinuous conversions in which the main sequence of ADC group regular (parameter NbrOfConversion) will be subdivided.
147                                        If parameter 'DiscontinuousConvMode' is disabled, this parameter is discarded.
148                                        This parameter must be a number between Min_Data = 1 and Max_Data = 8. */
149 
150   uint32_t ExternalTrigConv;      /*!< Select the external event source used to trigger ADC group regular conversion start.
151                                        If set to ADC_SOFTWARE_START, external triggers are disabled and software trigger is used instead.
152                                        This parameter can be a value of @ref ADC_regular_external_trigger_source.
153                                        Caution: external trigger source is common to all ADC instances. */
154 
155   uint32_t ExternalTrigConvEdge;  /*!< Select the external event edge used to trigger ADC group regular conversion start.
156                                        If trigger source is set to ADC_SOFTWARE_START, this parameter is discarded.
157                                        This parameter can be a value of @ref ADC_regular_external_trigger_edge */
158 
159   FunctionalState DMAContinuousRequests; /*!< Specify whether the DMA requests are performed in one shot mode (DMA transfer stops when number of conversions is reached)
160                                        or in continuous mode (DMA transfer unlimited, whatever number of conversions).
161                                        This parameter can be set to ENABLE or DISABLE.
162                                        Note: In continuous mode, DMA must be configured in circular mode. Otherwise an overrun will be triggered when DMA buffer maximum pointer is reached. */
163 
164   uint32_t Overrun;               /*!< Select the behavior in case of overrun: data overwritten or preserved (default).
165                                        This parameter applies to ADC group regular only.
166                                        This parameter can be a value of @ref ADC_HAL_EC_REG_OVR_DATA_BEHAVIOR.
167                                        Note: In case of overrun set to data preserved and usage with programming model with interruption (HAL_Start_IT()): ADC IRQ handler has to clear
168                                        end of conversion flags, this induces the release of the preserved data. If needed, this data can be saved in function
169                                        HAL_ADC_ConvCpltCallback(), placed in user program code (called before end of conversion flags clear).
170                                        Note: Error reporting with respect to the conversion mode:
171                                              - Usage with ADC conversion by polling for event or interruption: Error is reported only if overrun is set to data preserved. If overrun is set to data
172                                                overwritten, user can willingly not read all the converted data, this is not considered as an erroneous case.
173                                              - Usage with ADC conversion by DMA: Error is reported whatever overrun setting (DMA is expected to process all data from data register). */
174 
175   FunctionalState OversamplingMode;       /*!< Specify whether the oversampling feature is enabled or disabled.
176                                                This parameter can be set to ENABLE or DISABLE.
177                                                Note: This parameter can be modified only if there is no conversion is ongoing on ADC groups regular and injected */
178 
179   ADC_OversamplingTypeDef Oversampling;   /*!< Specify the Oversampling parameters.
180                                                Caution: this setting overwrites the previous oversampling configuration if oversampling is already enabled. */
181 
182 #if defined(ADC_CFGR_DFSDMCFG) &&defined(DFSDM1_Channel0)
183   uint32_t DFSDMConfig;           /*!< Specify whether ADC conversion data is sent directly to DFSDM.
184                                        This parameter can be a value of @ref ADC_HAL_EC_REG_DFSDM_TRANSFER.
185                                        Note: This parameter can be modified only if there is no conversion is ongoing (both ADSTART and JADSTART cleared). */
186 
187 #endif
188 } ADC_InitTypeDef;
189 
190 /**
191   * @brief  Structure definition of ADC channel for regular group
192   * @note   The setting of these parameters by function HAL_ADC_ConfigChannel() is conditioned to ADC state.
193   *         ADC state can be either:
194   *          - For all parameters: ADC disabled (this is the only possible ADC state to modify parameter 'SingleDiff')
195   *          - For all except parameters 'SamplingTime', 'Offset', 'OffsetNumber': ADC enabled without conversion on going on regular group.
196   *          - For parameters 'SamplingTime', 'Offset', 'OffsetNumber': ADC enabled without conversion on going on regular and injected groups.
197   *         If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed
198   *         without error reporting (as it can be the expected behavior in case of intended action to update another parameter (which fulfills the ADC state condition)
199   *         on the fly).
200   */
201 typedef struct
202 {
203   uint32_t Channel;                /*!< Specify the channel to configure into ADC regular group.
204                                         This parameter can be a value of @ref ADC_HAL_EC_CHANNEL
205                                         Note: Depending on devices and ADC instances, some channels may not be available on device package pins. Refer to device datasheet for channels availability. */
206 
207   uint32_t Rank;                   /*!< Specify the rank in the regular group sequencer.
208                                         This parameter can be a value of @ref ADC_HAL_EC_REG_SEQ_RANKS
209                                         Note: to disable a channel or change order of conversion sequencer, rank containing a previous channel setting can be overwritten by
210                                         the new channel setting (or parameter number of conversions adjusted) */
211 
212   uint32_t SamplingTime;           /*!< Sampling time value to be set for the selected channel.
213                                         Unit: ADC clock cycles
214                                         Conversion time is the addition of sampling time and processing time
215                                         (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).
216                                         This parameter can be a value of @ref ADC_HAL_EC_CHANNEL_SAMPLINGTIME
217                                         Caution: This parameter applies to a channel that can be used into regular and/or injected group.
218                                                  It overwrites the last setting.
219                                         Note: In case of usage of internal measurement channels (VrefInt/Vbat/TempSensor),
220                                               sampling time constraints must be respected (sampling time can be adjusted in function of ADC clock frequency and sampling time setting)
221                                               Refer to device datasheet for timings values. */
222 
223   uint32_t SingleDiff;             /*!< Select single-ended or differential input.
224                                         In differential mode: Differential measurement is carried out between the selected channel 'i' (positive input) and channel 'i+1' (negative input).
225                                                               Only channel 'i' has to be configured, channel 'i+1' is configured automatically.
226                                         This parameter must be a value of @ref ADC_HAL_EC_CHANNEL_SINGLE_DIFF_ENDING
227                                         Caution: This parameter applies to a channel that can be used in a regular and/or injected group.
228                                                  It overwrites the last setting.
229                                         Note: Refer to Reference Manual to ensure the selected channel is available in differential mode.
230                                         Note: When configuring a channel 'i' in differential mode, the channel 'i+1' is not usable separately.
231                                         Note: This parameter must be modified when ADC is disabled (before ADC start conversion or after ADC stop conversion).
232                                               If ADC is enabled, this parameter setting is bypassed without error reporting (as it can be the expected behavior in case
233                                         of another parameter update on the fly) */
234 
235   uint32_t OffsetNumber;           /*!< Select the offset number
236                                         This parameter can be a value of @ref ADC_HAL_EC_OFFSET_NB
237                                         Caution: Only one offset is allowed per channel. This parameter overwrites the last setting. */
238 
239   uint32_t Offset;                 /*!< Define the offset to be subtracted from the raw converted data.
240                                         Offset value must be a positive number.
241                                         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,
242                                         0x3FF, 0xFF or 0x3F respectively.
243                                         Note: This parameter must be modified when no conversion is on going on both regular and injected groups (ADC disabled, or ADC enabled
244                                               without continuous mode or external trigger that could launch a conversion). */
245 
246 } ADC_ChannelConfTypeDef;
247 
248 /**
249   * @brief  Structure definition of ADC analog watchdog
250   * @note   The setting of these parameters by function HAL_ADC_AnalogWDGConfig() is conditioned to ADC state.
251   *         ADC state can be either:
252   *          - For all parameters: ADC disabled or ADC enabled without conversion on going on ADC groups regular and injected.
253   */
254 typedef struct
255 {
256   uint32_t WatchdogNumber;    /*!< Select which ADC analog watchdog is monitoring the selected channel.
257                                    For Analog Watchdog 1: Only 1 channel can be monitored (or overall group of channels by setting parameter 'WatchdogMode')
258                                    For Analog Watchdog 2 and 3: Several channels can be monitored (by successive calls of 'HAL_ADC_AnalogWDGConfig()' for each channel)
259                                    This parameter can be a value of @ref ADC_HAL_EC_AWD_NUMBER. */
260 
261   uint32_t WatchdogMode;      /*!< Configure the ADC analog watchdog mode: single/all/none channels.
262                                    For Analog Watchdog 1: Configure the ADC analog watchdog mode: single channel or all channels, ADC groups regular and-or injected.
263                                    For Analog Watchdog 2 and 3: Several channels can be monitored by applying successively the AWD init structure. Channels on ADC group regular and injected are not differentiated: Set value 'ADC_ANALOGWATCHDOG_SINGLE_xxx' to monitor 1 channel, value 'ADC_ANALOGWATCHDOG_ALL_xxx' to monitor all channels, 'ADC_ANALOGWATCHDOG_NONE' to monitor no channel.
264                                    This parameter can be a value of @ref ADC_analog_watchdog_mode. */
265 
266   uint32_t Channel;           /*!< Select which ADC channel to monitor by analog watchdog.
267                                    For Analog Watchdog 1: this parameter has an effect only if parameter 'WatchdogMode' is configured on single channel (only 1 channel can be monitored).
268                                    For Analog Watchdog 2 and 3: Several channels can be monitored. To use this feature, call successively the function HAL_ADC_AnalogWDGConfig() for each channel to be added (or removed with value 'ADC_ANALOGWATCHDOG_NONE').
269                                    This parameter can be a value of @ref ADC_HAL_EC_CHANNEL. */
270 
271   FunctionalState ITMode;     /*!< Specify whether the analog watchdog is configured in interrupt or polling mode.
272                                    This parameter can be set to ENABLE or DISABLE */
273 
274   uint32_t HighThreshold;     /*!< Configure the ADC analog watchdog High threshold value.
275                                    Depending of ADC resolution selected (12, 10, 8 or 6 bits), this parameter must be a number
276                                    between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F respectively.
277                                    Note: Analog watchdog 2 and 3 are limited to a resolution of 8 bits: if ADC resolution is 12 bits
278                                          the 4 LSB are ignored, if ADC resolution is 10 bits the 2 LSB are ignored.
279                                    Note: If ADC oversampling is enabled, ADC analog watchdog thresholds are
280                                          impacted: the comparison of analog watchdog thresholds is done on
281                                          oversampling final computation (after ratio and shift application):
282                                          ADC data register bitfield [15:4] (12 most significant bits). */
283 
284   uint32_t LowThreshold;      /*!< Configures the ADC analog watchdog Low threshold value.
285                                    Depending of ADC resolution selected (12, 10, 8 or 6 bits), this parameter must be a number
286                                    between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F respectively.
287                                    Note: Analog watchdog 2 and 3 are limited to a resolution of 8 bits: if ADC resolution is 12 bits
288                                          the 4 LSB are ignored, if ADC resolution is 10 bits the 2 LSB are ignored.
289                                    Note: If ADC oversampling is enabled, ADC analog watchdog thresholds are
290                                          impacted: the comparison of analog watchdog thresholds is done on
291                                          oversampling final computation (after ratio and shift application):
292                                          ADC data register bitfield [15:4] (12 most significant bits). */
293 } ADC_AnalogWDGConfTypeDef;
294 
295 /**
296   * @brief  ADC group injected contexts queue configuration
297   * @note   Structure intended to be used only through structure "ADC_HandleTypeDef"
298   */
299 typedef struct
300 {
301   uint32_t ContextQueue;                 /*!< Injected channel configuration context: build-up over each
302                                               HAL_ADCEx_InjectedConfigChannel() call to finally initialize
303                                               JSQR register at HAL_ADCEx_InjectedConfigChannel() last call */
304 
305   uint32_t ChannelCount;                 /*!< Number of channels in the injected sequence */
306 } ADC_InjectionConfigTypeDef;
307 
308 /** @defgroup ADC_States ADC States
309   * @{
310   */
311 
312 /**
313   * @brief  HAL ADC state machine: ADC states definition (bitfields)
314   * @note   ADC state machine is managed by bitfields, state must be compared
315   *         with bit by bit.
316   *         For example:
317   *           " if ((HAL_ADC_GetState(hadc1) & HAL_ADC_STATE_REG_BUSY) != 0UL) "
318   *           " if ((HAL_ADC_GetState(hadc1) & HAL_ADC_STATE_AWD1) != 0UL) "
319   */
320 /* States of ADC global scope */
321 #define HAL_ADC_STATE_RESET             (0x00000000UL)   /*!< ADC not yet initialized or disabled */
322 #define HAL_ADC_STATE_READY             (0x00000001UL)   /*!< ADC peripheral ready for use */
323 #define HAL_ADC_STATE_BUSY_INTERNAL     (0x00000002UL)   /*!< ADC is busy due to an internal process (initialization, calibration) */
324 #define HAL_ADC_STATE_TIMEOUT           (0x00000004UL)   /*!< TimeOut occurrence */
325 
326 /* States of ADC errors */
327 #define HAL_ADC_STATE_ERROR_INTERNAL    (0x00000010UL)   /*!< Internal error occurrence */
328 #define HAL_ADC_STATE_ERROR_CONFIG      (0x00000020UL)   /*!< Configuration error occurrence */
329 #define HAL_ADC_STATE_ERROR_DMA         (0x00000040UL)   /*!< DMA error occurrence */
330 
331 /* States of ADC group regular */
332 #define HAL_ADC_STATE_REG_BUSY          (0x00000100UL)   /*!< A conversion on ADC group regular is ongoing or can occur (either by continuous mode,
333                                                               external trigger, low power auto power-on (if feature available), multimode ADC master control (if feature available)) */
334 #define HAL_ADC_STATE_REG_EOC           (0x00000200UL)   /*!< Conversion data available on group regular */
335 #define HAL_ADC_STATE_REG_OVR           (0x00000400UL)   /*!< Overrun occurrence */
336 #define HAL_ADC_STATE_REG_EOSMP         (0x00000800UL)   /*!< Not available on this STM32 serie: End Of Sampling flag raised  */
337 
338 /* States of ADC group injected */
339 #define HAL_ADC_STATE_INJ_BUSY          (0x00001000UL)   /*!< A conversion on ADC group injected is ongoing or can occur (either by auto-injection mode,
340                                                               external trigger, low power auto power-on (if feature available), multimode ADC master control (if feature available)) */
341 #define HAL_ADC_STATE_INJ_EOC           (0x00002000UL)   /*!< Conversion data available on group injected */
342 #define HAL_ADC_STATE_INJ_JQOVF         (0x00004000UL)   /*!< Injected queue overflow occurrence */
343 
344 /* States of ADC analog watchdogs */
345 #define HAL_ADC_STATE_AWD1              (0x00010000UL)   /*!< Out-of-window occurrence of ADC analog watchdog 1 */
346 #define HAL_ADC_STATE_AWD2              (0x00020000UL)   /*!< Out-of-window occurrence of ADC analog watchdog 2 */
347 #define HAL_ADC_STATE_AWD3              (0x00040000UL)   /*!< Out-of-window occurrence of ADC analog watchdog 3 */
348 
349 /* States of ADC multi-mode */
350 #define HAL_ADC_STATE_MULTIMODE_SLAVE   (0x00100000UL)   /*!< ADC in multimode slave state, controlled by another ADC master (when feature available) */
351 
352 /**
353   * @}
354   */
355 
356 /**
357   * @brief  ADC handle Structure definition
358   */
359 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
360 typedef struct __ADC_HandleTypeDef
361 #else
362 typedef struct
363 #endif
364 {
365   ADC_TypeDef                   *Instance;              /*!< Register base address */
366   ADC_InitTypeDef               Init;                   /*!< ADC initialization parameters and regular conversions setting */
367   DMA_HandleTypeDef             *DMA_Handle;            /*!< Pointer DMA Handler */
368   HAL_LockTypeDef               Lock;                   /*!< ADC locking object */
369   __IO uint32_t                 State;                  /*!< ADC communication state (bitmap of ADC states) */
370   __IO uint32_t                 ErrorCode;              /*!< ADC Error code */
371   ADC_InjectionConfigTypeDef    InjectionConfig ;       /*!< ADC injected channel configuration build-up structure */
372 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
373   void (* ConvCpltCallback)(struct __ADC_HandleTypeDef *hadc);              /*!< ADC conversion complete callback */
374   void (* ConvHalfCpltCallback)(struct __ADC_HandleTypeDef *hadc);          /*!< ADC conversion DMA half-transfer callback */
375   void (* LevelOutOfWindowCallback)(struct __ADC_HandleTypeDef *hadc);      /*!< ADC analog watchdog 1 callback */
376   void (* ErrorCallback)(struct __ADC_HandleTypeDef *hadc);                 /*!< ADC error callback */
377   void (* InjectedConvCpltCallback)(struct __ADC_HandleTypeDef *hadc);      /*!< ADC group injected conversion complete callback */
378   void (* InjectedQueueOverflowCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC group injected context queue overflow callback */
379   void (* LevelOutOfWindow2Callback)(struct __ADC_HandleTypeDef *hadc);     /*!< ADC analog watchdog 2 callback */
380   void (* LevelOutOfWindow3Callback)(struct __ADC_HandleTypeDef *hadc);     /*!< ADC analog watchdog 3 callback */
381   void (* EndOfSamplingCallback)(struct __ADC_HandleTypeDef *hadc);         /*!< ADC end of sampling callback */
382   void (* MspInitCallback)(struct __ADC_HandleTypeDef *hadc);               /*!< ADC Msp Init callback */
383   void (* MspDeInitCallback)(struct __ADC_HandleTypeDef *hadc);             /*!< ADC Msp DeInit callback */
384 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
385 } ADC_HandleTypeDef;
386 
387 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
388 /**
389   * @brief  HAL ADC Callback ID enumeration definition
390   */
391 typedef enum
392 {
393   HAL_ADC_CONVERSION_COMPLETE_CB_ID     = 0x00U,  /*!< ADC conversion complete callback ID */
394   HAL_ADC_CONVERSION_HALF_CB_ID         = 0x01U,  /*!< ADC conversion DMA half-transfer callback ID */
395   HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID   = 0x02U,  /*!< ADC analog watchdog 1 callback ID */
396   HAL_ADC_ERROR_CB_ID                   = 0x03U,  /*!< ADC error callback ID */
397   HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID = 0x04U,  /*!< ADC group injected conversion complete callback ID */
398   HAL_ADC_INJ_QUEUE_OVEFLOW_CB_ID       = 0x05U,  /*!< ADC group injected context queue overflow callback ID */
399   HAL_ADC_LEVEL_OUT_OF_WINDOW_2_CB_ID   = 0x06U,  /*!< ADC analog watchdog 2 callback ID */
400   HAL_ADC_LEVEL_OUT_OF_WINDOW_3_CB_ID   = 0x07U,  /*!< ADC analog watchdog 3 callback ID */
401   HAL_ADC_END_OF_SAMPLING_CB_ID         = 0x08U,  /*!< ADC end of sampling callback ID */
402   HAL_ADC_MSPINIT_CB_ID                 = 0x09U,  /*!< ADC Msp Init callback ID          */
403   HAL_ADC_MSPDEINIT_CB_ID               = 0x0AU   /*!< ADC Msp DeInit callback ID        */
404 } HAL_ADC_CallbackIDTypeDef;
405 
406 /**
407   * @brief  HAL ADC Callback pointer definition
408   */
409 typedef  void (*pADC_CallbackTypeDef)(ADC_HandleTypeDef *hadc); /*!< pointer to a ADC callback function */
410 
411 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
412 
413 /**
414   * @}
415   */
416 
417 
418 /* Exported constants --------------------------------------------------------*/
419 
420 /** @defgroup ADC_Exported_Constants ADC Exported Constants
421   * @{
422   */
423 
424 /** @defgroup ADC_Error_Code ADC Error Code
425   * @{
426   */
427 #define HAL_ADC_ERROR_NONE              (0x00U)   /*!< No error                                    */
428 #define HAL_ADC_ERROR_INTERNAL          (0x01U)   /*!< ADC peripheral internal error (problem of clocking,
429                                                        enable/disable, erroneous state, ...)       */
430 #define HAL_ADC_ERROR_OVR               (0x02U)   /*!< Overrun error                               */
431 #define HAL_ADC_ERROR_DMA               (0x04U)   /*!< DMA transfer error                          */
432 #define HAL_ADC_ERROR_JQOVF             (0x08U)   /*!< Injected context queue overflow error       */
433 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
434 #define HAL_ADC_ERROR_INVALID_CALLBACK  (0x10U)   /*!< Invalid Callback error */
435 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
436 /**
437   * @}
438   */
439 
440 /** @defgroup ADC_HAL_EC_COMMON_CLOCK_SOURCE  ADC common - Clock source
441   * @{
442   */
443 #define ADC_CLOCK_SYNC_PCLK_DIV1           (LL_ADC_CLOCK_SYNC_PCLK_DIV1)  /*!< ADC synchronous clock derived from AHB clock without prescaler */
444 #define ADC_CLOCK_SYNC_PCLK_DIV2           (LL_ADC_CLOCK_SYNC_PCLK_DIV2)  /*!< ADC synchronous clock derived from AHB clock with prescaler division by 2 */
445 #define ADC_CLOCK_SYNC_PCLK_DIV4           (LL_ADC_CLOCK_SYNC_PCLK_DIV4)  /*!< ADC synchronous clock derived from AHB clock with prescaler division by 4 */
446 
447 #define ADC_CLOCK_ASYNC_DIV1               (LL_ADC_CLOCK_ASYNC_DIV1)      /*!< ADC asynchronous clock without prescaler */
448 #define ADC_CLOCK_ASYNC_DIV2               (LL_ADC_CLOCK_ASYNC_DIV2)      /*!< ADC asynchronous clock with prescaler division by 2   */
449 #define ADC_CLOCK_ASYNC_DIV4               (LL_ADC_CLOCK_ASYNC_DIV4)      /*!< ADC asynchronous clock with prescaler division by 4   */
450 #define ADC_CLOCK_ASYNC_DIV6               (LL_ADC_CLOCK_ASYNC_DIV6)      /*!< ADC asynchronous clock with prescaler division by 6   */
451 #define ADC_CLOCK_ASYNC_DIV8               (LL_ADC_CLOCK_ASYNC_DIV8)      /*!< ADC asynchronous clock with prescaler division by 8   */
452 #define ADC_CLOCK_ASYNC_DIV10              (LL_ADC_CLOCK_ASYNC_DIV10)     /*!< ADC asynchronous clock with prescaler division by 10  */
453 #define ADC_CLOCK_ASYNC_DIV12              (LL_ADC_CLOCK_ASYNC_DIV12)     /*!< ADC asynchronous clock with prescaler division by 12  */
454 #define ADC_CLOCK_ASYNC_DIV16              (LL_ADC_CLOCK_ASYNC_DIV16)     /*!< ADC asynchronous clock with prescaler division by 16  */
455 #define ADC_CLOCK_ASYNC_DIV32              (LL_ADC_CLOCK_ASYNC_DIV32)     /*!< ADC asynchronous clock with prescaler division by 32  */
456 #define ADC_CLOCK_ASYNC_DIV64              (LL_ADC_CLOCK_ASYNC_DIV64)     /*!< ADC asynchronous clock with prescaler division by 64  */
457 #define ADC_CLOCK_ASYNC_DIV128             (LL_ADC_CLOCK_ASYNC_DIV128)    /*!< ADC asynchronous clock with prescaler division by 128 */
458 #define ADC_CLOCK_ASYNC_DIV256             (LL_ADC_CLOCK_ASYNC_DIV256)    /*!< ADC asynchronous clock with prescaler division by 256 */
459 /**
460   * @}
461   */
462 
463 /** @defgroup ADC_HAL_EC_RESOLUTION  ADC instance - Resolution
464   * @{
465   */
466 #define ADC_RESOLUTION_12B                 (LL_ADC_RESOLUTION_12B)  /*!< ADC resolution 12 bits */
467 #define ADC_RESOLUTION_10B                 (LL_ADC_RESOLUTION_10B)  /*!< ADC resolution 10 bits */
468 #define ADC_RESOLUTION_8B                  (LL_ADC_RESOLUTION_8B)   /*!< ADC resolution  8 bits */
469 #define ADC_RESOLUTION_6B                  (LL_ADC_RESOLUTION_6B)   /*!< ADC resolution  6 bits */
470 /**
471   * @}
472   */
473 
474 /** @defgroup ADC_HAL_EC_DATA_ALIGN ADC conversion data alignment
475   * @{
476   */
477 #define ADC_DATAALIGN_RIGHT                (LL_ADC_DATA_ALIGN_RIGHT)/*!< ADC conversion data alignment: right aligned (alignment on data register LSB bit 0)*/
478 #define ADC_DATAALIGN_LEFT                 (LL_ADC_DATA_ALIGN_LEFT)       /*!< ADC conversion data alignment: left aligned (aligment on data register MSB bit 15)*/
479 /**
480   * @}
481   */
482 
483 /** @defgroup ADC_Scan_mode ADC sequencer scan mode
484   * @{
485   */
486 #define ADC_SCAN_DISABLE         (0x00000000UL)       /*!< Scan mode disabled */
487 #define ADC_SCAN_ENABLE          (0x00000001UL)       /*!< Scan mode enabled  */
488 /**
489   * @}
490   */
491 
492 /** @defgroup ADC_regular_external_trigger_source ADC group regular trigger source
493   * @{
494   */
495 /* ADC group regular trigger sources for all ADC instances */
496 #define ADC_SOFTWARE_START            (LL_ADC_REG_TRIG_SOFTWARE)                 /*!< ADC group regular conversion trigger internal: SW start. */
497 #define ADC_EXTERNALTRIG_T1_TRGO      (LL_ADC_REG_TRIG_EXT_TIM1_TRGO)            /*!< ADC group regular conversion trigger from external peripheral: TIM1 TRGO. Trigger edge set to rising edge (default setting). */
498 #define ADC_EXTERNALTRIG_T1_TRGO2     (LL_ADC_REG_TRIG_EXT_TIM1_TRGO2)           /*!< ADC group regular conversion trigger from external peripheral: TIM1 TRGO2. Trigger edge set to rising edge (default setting). */
499 #define ADC_EXTERNALTRIG_T1_CC1       (LL_ADC_REG_TRIG_EXT_TIM1_CH1)             /*!< ADC group regular conversion trigger from external peripheral: TIM1 channel 1 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
500 #define ADC_EXTERNALTRIG_T1_CC2       (LL_ADC_REG_TRIG_EXT_TIM1_CH2)             /*!< ADC group regular conversion trigger from external peripheral: TIM1 channel 2 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
501 #define ADC_EXTERNALTRIG_T1_CC3       (LL_ADC_REG_TRIG_EXT_TIM1_CH3)             /*!< ADC group regular conversion trigger from external peripheral: TIM1 channel 3 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
502 #define ADC_EXTERNALTRIG_T2_TRGO      (LL_ADC_REG_TRIG_EXT_TIM2_TRGO)            /*!< ADC group regular conversion trigger from external peripheral: TIM2 TRGO. Trigger edge set to rising edge (default setting). */
503 #define ADC_EXTERNALTRIG_T2_CC2       (LL_ADC_REG_TRIG_EXT_TIM2_CH2)             /*!< ADC group regular conversion trigger from external peripheral: TIM2 channel 2 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
504 #define ADC_EXTERNALTRIG_T3_TRGO      (LL_ADC_REG_TRIG_EXT_TIM3_TRGO)            /*!< ADC group regular conversion trigger from external peripheral: TIM3 TRGO. Trigger edge set to rising edge (default setting). */
505 #define ADC_EXTERNALTRIG_T3_CC4       (LL_ADC_REG_TRIG_EXT_TIM3_CH4)             /*!< ADC group regular conversion trigger from external peripheral: TIM3 channel 4 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
506 #define ADC_EXTERNALTRIG_T4_TRGO      (LL_ADC_REG_TRIG_EXT_TIM4_TRGO)            /*!< ADC group regular conversion trigger from external peripheral: TIM4 TRGO. Trigger edge set to rising edge (default setting). */
507 #define ADC_EXTERNALTRIG_T4_CC4       (LL_ADC_REG_TRIG_EXT_TIM4_CH4)             /*!< ADC group regular conversion trigger from external peripheral: TIM4 channel 4 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
508 #define ADC_EXTERNALTRIG_T6_TRGO      (LL_ADC_REG_TRIG_EXT_TIM6_TRGO)            /*!< ADC group regular conversion trigger from external peripheral: TIM6 TRGO. Trigger edge set to rising edge (default setting). */
509 #define ADC_EXTERNALTRIG_T8_TRGO      (LL_ADC_REG_TRIG_EXT_TIM8_TRGO)            /*!< ADC group regular conversion trigger from external peripheral: TIM8 TRGO. Trigger edge set to rising edge (default setting). */
510 #define ADC_EXTERNALTRIG_T8_TRGO2     (LL_ADC_REG_TRIG_EXT_TIM8_TRGO2)           /*!< ADC group regular conversion trigger from external peripheral: TIM8 TRGO2. Trigger edge set to rising edge (default setting). */
511 #define ADC_EXTERNALTRIG_T15_TRGO     (LL_ADC_REG_TRIG_EXT_TIM15_TRGO)           /*!< ADC group regular conversion trigger from external peripheral: TIM15 TRGO. Trigger edge set to rising edge (default setting). */
512 #define ADC_EXTERNALTRIG_EXT_IT11     (LL_ADC_REG_TRIG_EXT_EXTI_LINE11)          /*!< ADC group regular conversion trigger from external peripheral: external interrupt line 11. Trigger edge set to rising edge (default setting). */
513 /**
514   * @}
515   */
516 
517 /** @defgroup ADC_regular_external_trigger_edge ADC group regular trigger edge (when external trigger is selected)
518   * @{
519   */
520 #define ADC_EXTERNALTRIGCONVEDGE_NONE           (0x00000000UL)                      /*!< Regular conversions hardware trigger detection disabled */
521 #define ADC_EXTERNALTRIGCONVEDGE_RISING         (LL_ADC_REG_TRIG_EXT_RISING)        /*!< ADC group regular conversion trigger polarity set to rising edge */
522 #define ADC_EXTERNALTRIGCONVEDGE_FALLING        (LL_ADC_REG_TRIG_EXT_FALLING)       /*!< ADC group regular conversion trigger polarity set to falling edge */
523 #define ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING  (LL_ADC_REG_TRIG_EXT_RISINGFALLING) /*!< ADC group regular conversion trigger polarity set to both rising and falling edges */
524 /**
525   * @}
526   */
527 
528 /** @defgroup ADC_EOCSelection ADC sequencer end of unitary conversion or sequence conversions
529   * @{
530   */
531 #define ADC_EOC_SINGLE_CONV         (ADC_ISR_EOC)                 /*!< End of unitary conversion flag  */
532 #define ADC_EOC_SEQ_CONV            (ADC_ISR_EOS)                 /*!< End of sequence conversions flag    */
533 /**
534   * @}
535   */
536 
537 /** @defgroup ADC_HAL_EC_REG_OVR_DATA_BEHAVIOR  ADC group regular - Overrun behavior on conversion data
538   * @{
539   */
540 #define ADC_OVR_DATA_PRESERVED             (LL_ADC_REG_OVR_DATA_PRESERVED)    /*!< ADC group regular behavior in case of overrun: data preserved */
541 #define ADC_OVR_DATA_OVERWRITTEN           (LL_ADC_REG_OVR_DATA_OVERWRITTEN)  /*!< ADC group regular behavior in case of overrun: data overwritten */
542 /**
543   * @}
544   */
545 
546 /** @defgroup ADC_HAL_EC_REG_SEQ_RANKS  ADC group regular - Sequencer ranks
547   * @{
548   */
549 #define ADC_REGULAR_RANK_1                 (LL_ADC_REG_RANK_1)  /*!< ADC group regular sequencer rank 1 */
550 #define ADC_REGULAR_RANK_2                 (LL_ADC_REG_RANK_2)  /*!< ADC group regular sequencer rank 2 */
551 #define ADC_REGULAR_RANK_3                 (LL_ADC_REG_RANK_3)  /*!< ADC group regular sequencer rank 3 */
552 #define ADC_REGULAR_RANK_4                 (LL_ADC_REG_RANK_4)  /*!< ADC group regular sequencer rank 4 */
553 #define ADC_REGULAR_RANK_5                 (LL_ADC_REG_RANK_5)  /*!< ADC group regular sequencer rank 5 */
554 #define ADC_REGULAR_RANK_6                 (LL_ADC_REG_RANK_6)  /*!< ADC group regular sequencer rank 6 */
555 #define ADC_REGULAR_RANK_7                 (LL_ADC_REG_RANK_7)  /*!< ADC group regular sequencer rank 7 */
556 #define ADC_REGULAR_RANK_8                 (LL_ADC_REG_RANK_8)  /*!< ADC group regular sequencer rank 8 */
557 #define ADC_REGULAR_RANK_9                 (LL_ADC_REG_RANK_9)  /*!< ADC group regular sequencer rank 9 */
558 #define ADC_REGULAR_RANK_10                (LL_ADC_REG_RANK_10) /*!< ADC group regular sequencer rank 10 */
559 #define ADC_REGULAR_RANK_11                (LL_ADC_REG_RANK_11) /*!< ADC group regular sequencer rank 11 */
560 #define ADC_REGULAR_RANK_12                (LL_ADC_REG_RANK_12) /*!< ADC group regular sequencer rank 12 */
561 #define ADC_REGULAR_RANK_13                (LL_ADC_REG_RANK_13) /*!< ADC group regular sequencer rank 13 */
562 #define ADC_REGULAR_RANK_14                (LL_ADC_REG_RANK_14) /*!< ADC group regular sequencer rank 14 */
563 #define ADC_REGULAR_RANK_15                (LL_ADC_REG_RANK_15) /*!< ADC group regular sequencer rank 15 */
564 #define ADC_REGULAR_RANK_16                (LL_ADC_REG_RANK_16) /*!< ADC group regular sequencer rank 16 */
565 /**
566   * @}
567   */
568 
569 /** @defgroup ADC_HAL_EC_CHANNEL_SAMPLINGTIME  Channel - Sampling time
570   * @{
571   */
572 #define ADC_SAMPLETIME_2CYCLES_5         (LL_ADC_SAMPLINGTIME_2CYCLES_5)    /*!< Sampling time 2.5 ADC clock cycles */
573 #define ADC_SAMPLETIME_6CYCLES_5         (LL_ADC_SAMPLINGTIME_6CYCLES_5)    /*!< Sampling time 6.5 ADC clock cycles */
574 #define ADC_SAMPLETIME_12CYCLES_5        (LL_ADC_SAMPLINGTIME_12CYCLES_5)   /*!< Sampling time 12.5 ADC clock cycles */
575 #define ADC_SAMPLETIME_24CYCLES_5        (LL_ADC_SAMPLINGTIME_24CYCLES_5)   /*!< Sampling time 24.5 ADC clock cycles */
576 #define ADC_SAMPLETIME_47CYCLES_5        (LL_ADC_SAMPLINGTIME_47CYCLES_5)   /*!< Sampling time 47.5 ADC clock cycles */
577 #define ADC_SAMPLETIME_92CYCLES_5        (LL_ADC_SAMPLINGTIME_92CYCLES_5)   /*!< Sampling time 92.5 ADC clock cycles */
578 #define ADC_SAMPLETIME_247CYCLES_5       (LL_ADC_SAMPLINGTIME_247CYCLES_5)  /*!< Sampling time 247.5 ADC clock cycles */
579 #define ADC_SAMPLETIME_640CYCLES_5       (LL_ADC_SAMPLINGTIME_640CYCLES_5)  /*!< Sampling time 640.5 ADC clock cycles */
580 #if defined(ADC_SMPR1_SMPPLUS)
581 #define ADC_SAMPLETIME_3CYCLES_5           (ADC_SMPR1_SMPPLUS | LL_ADC_SAMPLINGTIME_2CYCLES_5) /*!< Sampling time 3.5 ADC clock cycles. If selected, this sampling time replaces all sampling time 2.5 ADC clock cycles. These 2 sampling times cannot be used simultaneously. */
582 #endif
583 /**
584   * @}
585   */
586 
587 /** @defgroup ADC_HAL_EC_CHANNEL  ADC instance - Channel number
588   * @{
589   */
590 /* Note: VrefInt, TempSensor and Vbat internal channels are not available on  */
591 /*        all ADC instances (refer to Reference Manual).                      */
592 #define ADC_CHANNEL_0                      (LL_ADC_CHANNEL_0)               /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN0  */
593 #define ADC_CHANNEL_1                      (LL_ADC_CHANNEL_1)               /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN1  */
594 #define ADC_CHANNEL_2                      (LL_ADC_CHANNEL_2)               /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN2  */
595 #define ADC_CHANNEL_3                      (LL_ADC_CHANNEL_3)               /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN3  */
596 #define ADC_CHANNEL_4                      (LL_ADC_CHANNEL_4)               /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN4  */
597 #define ADC_CHANNEL_5                      (LL_ADC_CHANNEL_5)               /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN5  */
598 #define ADC_CHANNEL_6                      (LL_ADC_CHANNEL_6)               /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN6  */
599 #define ADC_CHANNEL_7                      (LL_ADC_CHANNEL_7)               /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN7  */
600 #define ADC_CHANNEL_8                      (LL_ADC_CHANNEL_8)               /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN8  */
601 #define ADC_CHANNEL_9                      (LL_ADC_CHANNEL_9)               /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN9  */
602 #define ADC_CHANNEL_10                     (LL_ADC_CHANNEL_10)              /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN10 */
603 #define ADC_CHANNEL_11                     (LL_ADC_CHANNEL_11)              /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN11 */
604 #define ADC_CHANNEL_12                     (LL_ADC_CHANNEL_12)              /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN12 */
605 #define ADC_CHANNEL_13                     (LL_ADC_CHANNEL_13)              /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN13 */
606 #define ADC_CHANNEL_14                     (LL_ADC_CHANNEL_14)              /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN14 */
607 #define ADC_CHANNEL_15                     (LL_ADC_CHANNEL_15)              /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN15 */
608 #define ADC_CHANNEL_16                     (LL_ADC_CHANNEL_16)              /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN16 */
609 #define ADC_CHANNEL_17                     (LL_ADC_CHANNEL_17)              /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN17 */
610 #define ADC_CHANNEL_18                     (LL_ADC_CHANNEL_18)              /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN18 */
611 #define ADC_CHANNEL_VREFINT                (LL_ADC_CHANNEL_VREFINT)         /*!< ADC internal channel connected to VrefInt: Internal voltage reference. */
612 #define ADC_CHANNEL_TEMPSENSOR             (LL_ADC_CHANNEL_TEMPSENSOR)      /*!< ADC internal channel connected to Temperature sensor. */
613 #define ADC_CHANNEL_VBAT                   (LL_ADC_CHANNEL_VBAT)            /*!< ADC internal channel connected to Vbat/3: Vbat voltage through a divider ladder of factor 1/3 to have Vbat always below Vdda. */
614 #if defined(ADC1) && !defined(ADC2)
615 #define ADC_CHANNEL_DAC1CH1                (LL_ADC_CHANNEL_DAC1CH1)         /*!< ADC internal channel connected to DAC1 channel 1, channel specific to ADC1. This channel is shared with ADC internal channel connected to temperature sensor, selection is done using function @ref LL_ADC_SetCommonPathInternalCh(). */
616 #define ADC_CHANNEL_DAC1CH2                (LL_ADC_CHANNEL_DAC1CH2)         /*!< ADC internal channel connected to DAC1 channel 2, channel specific to ADC1. This channel is shared with ADC internal channel connected to Vbat, selection is done using function @ref LL_ADC_SetCommonPathInternalCh(). */
617 #elif defined(ADC2)
618 #define ADC_CHANNEL_DAC1CH1_ADC2           (LL_ADC_CHANNEL_DAC1CH1_ADC2)    /*!< ADC internal channel connected to DAC1 channel 1, channel specific to ADC2 */
619 #define ADC_CHANNEL_DAC1CH2_ADC2           (LL_ADC_CHANNEL_DAC1CH2_ADC2)    /*!< ADC internal channel connected to DAC1 channel 2, channel specific to ADC2 */
620 #if defined(ADC3)
621 #define ADC_CHANNEL_DAC1CH1_ADC3           (LL_ADC_CHANNEL_DAC1CH1_ADC3)    /*!< ADC internal channel connected to DAC1 channel 1, channel specific to ADC3 */
622 #define ADC_CHANNEL_DAC1CH2_ADC3           (LL_ADC_CHANNEL_DAC1CH2_ADC3)    /*!< ADC internal channel connected to DAC1 channel 2, channel specific to ADC3 */
623 #endif
624 #endif
625 /**
626   * @}
627   */
628 
629 /** @defgroup ADC_HAL_EC_AWD_NUMBER Analog watchdog - Analog watchdog number
630   * @{
631   */
632 #define ADC_ANALOGWATCHDOG_1               (LL_ADC_AWD1) /*!< ADC analog watchdog number 1 */
633 #define ADC_ANALOGWATCHDOG_2               (LL_ADC_AWD2) /*!< ADC analog watchdog number 2 */
634 #define ADC_ANALOGWATCHDOG_3               (LL_ADC_AWD3) /*!< ADC analog watchdog number 3 */
635 /**
636   * @}
637   */
638 
639 /** @defgroup ADC_analog_watchdog_mode ADC Analog Watchdog Mode
640   * @{
641   */
642 #define ADC_ANALOGWATCHDOG_NONE                 (0x00000000UL)                                          /*!< No analog watchdog selected                                             */
643 #define ADC_ANALOGWATCHDOG_SINGLE_REG           (ADC_CFGR_AWD1SGL | ADC_CFGR_AWD1EN)                    /*!< Analog watchdog applied to a regular group single channel               */
644 #define ADC_ANALOGWATCHDOG_SINGLE_INJEC         (ADC_CFGR_AWD1SGL | ADC_CFGR_JAWD1EN)                   /*!< Analog watchdog applied to an injected group single channel             */
645 #define ADC_ANALOGWATCHDOG_SINGLE_REGINJEC      (ADC_CFGR_AWD1SGL | ADC_CFGR_AWD1EN | ADC_CFGR_JAWD1EN) /*!< Analog watchdog applied to a regular and injected groups single channel */
646 #define ADC_ANALOGWATCHDOG_ALL_REG              (ADC_CFGR_AWD1EN)                                       /*!< Analog watchdog applied to regular group all channels                   */
647 #define ADC_ANALOGWATCHDOG_ALL_INJEC            (ADC_CFGR_JAWD1EN)                                      /*!< Analog watchdog applied to injected group all channels                  */
648 #define ADC_ANALOGWATCHDOG_ALL_REGINJEC         (ADC_CFGR_AWD1EN | ADC_CFGR_JAWD1EN)                    /*!< Analog watchdog applied to regular and injected groups all channels     */
649 /**
650   * @}
651   */
652 
653 /** @defgroup ADC_HAL_EC_OVS_RATIO  Oversampling - Ratio
654   * @{
655   */
656 #define ADC_OVERSAMPLING_RATIO_2           (LL_ADC_OVS_RATIO_2)   /*!< ADC oversampling ratio of 2 (2 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
657 #define ADC_OVERSAMPLING_RATIO_4           (LL_ADC_OVS_RATIO_4)   /*!< ADC oversampling ratio of 4 (4 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
658 #define ADC_OVERSAMPLING_RATIO_8           (LL_ADC_OVS_RATIO_8)   /*!< ADC oversampling ratio of 8 (8 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
659 #define ADC_OVERSAMPLING_RATIO_16          (LL_ADC_OVS_RATIO_16)  /*!< ADC oversampling ratio of 16 (16 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
660 #define ADC_OVERSAMPLING_RATIO_32          (LL_ADC_OVS_RATIO_32)  /*!< ADC oversampling ratio of 32 (32 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
661 #define ADC_OVERSAMPLING_RATIO_64          (LL_ADC_OVS_RATIO_64)  /*!< ADC oversampling ratio of 64 (64 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
662 #define ADC_OVERSAMPLING_RATIO_128         (LL_ADC_OVS_RATIO_128) /*!< ADC oversampling ratio of 128 (128 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
663 #define ADC_OVERSAMPLING_RATIO_256         (LL_ADC_OVS_RATIO_256) /*!< ADC oversampling ratio of 256 (256 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
664 /**
665   * @}
666   */
667 
668 /** @defgroup ADC_HAL_EC_OVS_SHIFT  Oversampling - Data shift
669   * @{
670   */
671 #define ADC_RIGHTBITSHIFT_NONE             (LL_ADC_OVS_SHIFT_NONE)    /*!< ADC oversampling no shift (sum of the ADC conversions data is not divided to result as the ADC oversampling conversion data) */
672 #define ADC_RIGHTBITSHIFT_1                (LL_ADC_OVS_SHIFT_RIGHT_1) /*!< ADC oversampling shift of 1 (sum of the ADC conversions data is divided by 2 to result as the ADC oversampling conversion data) */
673 #define ADC_RIGHTBITSHIFT_2                (LL_ADC_OVS_SHIFT_RIGHT_2) /*!< ADC oversampling shift of 2 (sum of the ADC conversions data is divided by 4 to result as the ADC oversampling conversion data) */
674 #define ADC_RIGHTBITSHIFT_3                (LL_ADC_OVS_SHIFT_RIGHT_3) /*!< ADC oversampling shift of 3 (sum of the ADC conversions data is divided by 8 to result as the ADC oversampling conversion data) */
675 #define ADC_RIGHTBITSHIFT_4                (LL_ADC_OVS_SHIFT_RIGHT_4) /*!< ADC oversampling shift of 4 (sum of the ADC conversions data is divided by 16 to result as the ADC oversampling conversion data) */
676 #define ADC_RIGHTBITSHIFT_5                (LL_ADC_OVS_SHIFT_RIGHT_5) /*!< ADC oversampling shift of 5 (sum of the ADC conversions data is divided by 32 to result as the ADC oversampling conversion data) */
677 #define ADC_RIGHTBITSHIFT_6                (LL_ADC_OVS_SHIFT_RIGHT_6) /*!< ADC oversampling shift of 6 (sum of the ADC conversions data is divided by 64 to result as the ADC oversampling conversion data) */
678 #define ADC_RIGHTBITSHIFT_7                (LL_ADC_OVS_SHIFT_RIGHT_7) /*!< ADC oversampling shift of 7 (sum of the ADC conversions data is divided by 128 to result as the ADC oversampling conversion data) */
679 #define ADC_RIGHTBITSHIFT_8                (LL_ADC_OVS_SHIFT_RIGHT_8) /*!< ADC oversampling shift of 8 (sum of the ADC conversions data is divided by 256 to result as the ADC oversampling conversion data) */
680 /**
681   * @}
682   */
683 
684 /** @defgroup ADC_HAL_EC_OVS_DISCONT_MODE  Oversampling - Discontinuous mode
685   * @{
686   */
687 #define ADC_TRIGGEREDMODE_SINGLE_TRIGGER   (LL_ADC_OVS_REG_CONT)          /*!< ADC oversampling discontinuous mode: continuous mode (all conversions of oversampling ratio are done from 1 trigger) */
688 #define ADC_TRIGGEREDMODE_MULTI_TRIGGER    (LL_ADC_OVS_REG_DISCONT)       /*!< ADC oversampling discontinuous mode: discontinuous mode (each conversion of oversampling ratio needs a trigger) */
689 /**
690   * @}
691   */
692 
693 /** @defgroup ADC_HAL_EC_OVS_SCOPE_REG  Oversampling - Oversampling scope for ADC group regular
694   * @{
695   */
696 #define ADC_REGOVERSAMPLING_CONTINUED_MODE    (LL_ADC_OVS_GRP_REGULAR_CONTINUED) /*!< Oversampling buffer maintained during injection sequence */
697 #define ADC_REGOVERSAMPLING_RESUMED_MODE      (LL_ADC_OVS_GRP_REGULAR_RESUMED)   /*!< Oversampling buffer zeroed during injection sequence     */
698 /**
699   * @}
700   */
701 
702 
703 /** @defgroup ADC_Event_type ADC Event type
704   * @{
705   */
706 #define ADC_EOSMP_EVENT          (ADC_FLAG_EOSMP) /*!< ADC End of Sampling event */
707 #define ADC_AWD1_EVENT           (ADC_FLAG_AWD1)  /*!< ADC Analog watchdog 1 event (main analog watchdog, present on all STM32 series) */
708 #define ADC_AWD2_EVENT           (ADC_FLAG_AWD2)  /*!< ADC Analog watchdog 2 event (additional analog watchdog, not present on all STM32 series) */
709 #define ADC_AWD3_EVENT           (ADC_FLAG_AWD3)  /*!< ADC Analog watchdog 3 event (additional analog watchdog, not present on all STM32 series) */
710 #define ADC_OVR_EVENT            (ADC_FLAG_OVR)   /*!< ADC overrun event */
711 #define ADC_JQOVF_EVENT          (ADC_FLAG_JQOVF) /*!< ADC Injected Context Queue Overflow event */
712 /**
713   * @}
714   */
715 #define ADC_AWD_EVENT            ADC_AWD1_EVENT      /*!< ADC Analog watchdog 1 event: Naming for compatibility with other STM32 devices having only one analog watchdog */
716 
717 /** @defgroup ADC_interrupts_definition ADC interrupts definition
718   * @{
719   */
720 #define ADC_IT_RDY           ADC_IER_ADRDYIE    /*!< ADC Ready interrupt source */
721 #define ADC_IT_EOSMP         ADC_IER_EOSMPIE    /*!< ADC End of sampling interrupt source */
722 #define ADC_IT_EOC           ADC_IER_EOCIE      /*!< ADC End of regular conversion interrupt source */
723 #define ADC_IT_EOS           ADC_IER_EOSIE      /*!< ADC End of regular sequence of conversions interrupt source */
724 #define ADC_IT_OVR           ADC_IER_OVRIE      /*!< ADC overrun interrupt source */
725 #define ADC_IT_JEOC          ADC_IER_JEOCIE     /*!< ADC End of injected conversion interrupt source */
726 #define ADC_IT_JEOS          ADC_IER_JEOSIE     /*!< ADC End of injected sequence of conversions interrupt source */
727 #define ADC_IT_AWD1          ADC_IER_AWD1IE     /*!< ADC Analog watchdog 1 interrupt source (main analog watchdog) */
728 #define ADC_IT_AWD2          ADC_IER_AWD2IE     /*!< ADC Analog watchdog 2 interrupt source (additional analog watchdog) */
729 #define ADC_IT_AWD3          ADC_IER_AWD3IE     /*!< ADC Analog watchdog 3 interrupt source (additional analog watchdog) */
730 #define ADC_IT_JQOVF         ADC_IER_JQOVFIE    /*!< ADC Injected Context Queue Overflow interrupt source */
731 
732 #define ADC_IT_AWD           ADC_IT_AWD1        /*!< ADC Analog watchdog 1 interrupt source: naming for compatibility with other STM32 devices having only one analog watchdog */
733 
734 /**
735   * @}
736   */
737 
738 /** @defgroup ADC_flags_definition ADC flags definition
739   * @{
740   */
741 #define ADC_FLAG_RDY           ADC_ISR_ADRDY    /*!< ADC Ready flag */
742 #define ADC_FLAG_EOSMP         ADC_ISR_EOSMP    /*!< ADC End of Sampling flag */
743 #define ADC_FLAG_EOC           ADC_ISR_EOC      /*!< ADC End of Regular Conversion flag */
744 #define ADC_FLAG_EOS           ADC_ISR_EOS      /*!< ADC End of Regular sequence of Conversions flag */
745 #define ADC_FLAG_OVR           ADC_ISR_OVR      /*!< ADC overrun flag */
746 #define ADC_FLAG_JEOC          ADC_ISR_JEOC     /*!< ADC End of Injected Conversion flag */
747 #define ADC_FLAG_JEOS          ADC_ISR_JEOS     /*!< ADC End of Injected sequence of Conversions flag */
748 #define ADC_FLAG_AWD1          ADC_ISR_AWD1     /*!< ADC Analog watchdog 1 flag (main analog watchdog) */
749 #define ADC_FLAG_AWD2          ADC_ISR_AWD2     /*!< ADC Analog watchdog 2 flag (additional analog watchdog) */
750 #define ADC_FLAG_AWD3          ADC_ISR_AWD3     /*!< ADC Analog watchdog 3 flag (additional analog watchdog) */
751 #define ADC_FLAG_JQOVF         ADC_ISR_JQOVF    /*!< ADC Injected Context Queue Overflow flag */
752 
753 #define ADC_FLAG_AWD           ADC_FLAG_AWD1    /*!< ADC Analog watchdog 1 flag: Naming for compatibility with other STM32 devices having only one analog watchdog */
754 
755 #define ADC_FLAG_ALL    (ADC_FLAG_RDY | ADC_FLAG_EOSMP | ADC_FLAG_EOC | ADC_FLAG_EOS |  \
756                          ADC_FLAG_JEOC | ADC_FLAG_JEOS | ADC_FLAG_OVR | ADC_FLAG_AWD1 | \
757                          ADC_FLAG_AWD2 | ADC_FLAG_AWD3 | ADC_FLAG_JQOVF)   /*!< ADC all flags */
758 
759 /* Combination of all post-conversion flags bits: EOC/EOS, JEOC/JEOS, OVR, AWDx, JQOVF */
760 #define ADC_FLAG_POSTCONV_ALL (ADC_FLAG_EOC | ADC_FLAG_EOS  | ADC_FLAG_JEOC | ADC_FLAG_JEOS | \
761                                ADC_FLAG_OVR | ADC_FLAG_AWD1 | ADC_FLAG_AWD2 | ADC_FLAG_AWD3 | \
762                                ADC_FLAG_JQOVF)                             /*!< ADC post-conversion all flags */
763 
764 /**
765   * @}
766   */
767 
768 /**
769   * @}
770   */
771 
772 /* Private macro -------------------------------------------------------------*/
773 
774 /** @defgroup ADC_Private_Macros ADC Private Macros
775   * @{
776   */
777 /* Macro reserved for internal HAL driver usage, not intended to be used in   */
778 /* code of final user.                                                        */
779 
780 /**
781   * @brief Return resolution bits in CFGR register RES[1:0] field.
782   * @param __HANDLE__ ADC handle
783   * @retval Value of bitfield RES in CFGR register.
784   */
785 #define ADC_GET_RESOLUTION(__HANDLE__)                                         \
786   (LL_ADC_GetResolution((__HANDLE__)->Instance))
787 
788 /**
789   * @brief Clear ADC error code (set it to no error code "HAL_ADC_ERROR_NONE").
790   * @param __HANDLE__ ADC handle
791   * @retval None
792   */
793 #define ADC_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_ADC_ERROR_NONE)
794 
795 /**
796   * @brief Verification of ADC state: enabled or disabled.
797   * @param __HANDLE__ ADC handle
798   * @retval SET (ADC enabled) or RESET (ADC disabled)
799   */
800 #define ADC_IS_ENABLE(__HANDLE__)                                                    \
801        (( ((((__HANDLE__)->Instance->CR) & (ADC_CR_ADEN | ADC_CR_ADDIS)) == ADC_CR_ADEN) && \
802           ((((__HANDLE__)->Instance->ISR) & ADC_FLAG_RDY) == ADC_FLAG_RDY)                  \
803         ) ? SET : RESET)
804 
805 /**
806   * @brief Check if conversion is on going on regular group.
807   * @param __HANDLE__ ADC handle
808   * @retval Value "0" (no conversion is on going) or value "1" (conversion is on going)
809   */
810 #define ADC_IS_CONVERSION_ONGOING_REGULAR(__HANDLE__)                          \
811   (LL_ADC_REG_IsConversionOngoing((__HANDLE__)->Instance))
812 
813 /**
814   * @brief Simultaneously clear and set specific bits of the handle State.
815   * @note  ADC_STATE_CLR_SET() macro is merely aliased to generic macro MODIFY_REG(),
816   *        the first parameter is the ADC handle State, the second parameter is the
817   *        bit field to clear, the third and last parameter is the bit field to set.
818   * @retval None
819   */
820 #define ADC_STATE_CLR_SET MODIFY_REG
821 
822 /**
823   * @brief Verify that a given value is aligned with the ADC resolution range.
824   * @param __RESOLUTION__ ADC resolution (12, 10, 8 or 6 bits).
825   * @param __ADC_VALUE__ value checked against the resolution.
826   * @retval SET (__ADC_VALUE__ in line with __RESOLUTION__) or RESET (__ADC_VALUE__ not in line with __RESOLUTION__)
827   */
828 #define IS_ADC_RANGE(__RESOLUTION__, __ADC_VALUE__) \
829   ((__ADC_VALUE__) <= __LL_ADC_DIGITAL_SCALE(__RESOLUTION__))
830 
831 /**
832   * @brief Verify the length of the scheduled regular conversions group.
833   * @param __LENGTH__ number of programmed conversions.
834   * @retval SET (__LENGTH__ is within the maximum number of possible programmable regular conversions) or RESET (__LENGTH__ is null or too large)
835   */
836 #define IS_ADC_REGULAR_NB_CONV(__LENGTH__) (((__LENGTH__) >= (1UL)) && ((__LENGTH__) <= (16UL)))
837 
838 
839 /**
840   * @brief Verify the number of scheduled regular conversions in discontinuous mode.
841   * @param NUMBER number of scheduled regular conversions in discontinuous mode.
842   * @retval SET (NUMBER is within the maximum number of regular conversions in discontinuous mode) or RESET (NUMBER is null or too large)
843   */
844 #define IS_ADC_REGULAR_DISCONT_NUMBER(NUMBER) (((NUMBER) >= (1UL)) && ((NUMBER) <= (8UL)))
845 
846 
847 /**
848   * @brief Verify the ADC clock setting.
849   * @param __ADC_CLOCK__ programmed ADC clock.
850   * @retval SET (__ADC_CLOCK__ is a valid value) or RESET (__ADC_CLOCK__ is invalid)
851   */
852 #define IS_ADC_CLOCKPRESCALER(__ADC_CLOCK__) (((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV1) || \
853                                               ((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV2) || \
854                                               ((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV4) || \
855                                               ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV1)     || \
856                                               ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV2)     || \
857                                               ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV4)     || \
858                                               ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV6)     || \
859                                               ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV8)     || \
860                                               ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV10)    || \
861                                               ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV12)    || \
862                                               ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV16)    || \
863                                               ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV32)    || \
864                                               ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV64)    || \
865                                               ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV128)   || \
866                                               ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV256) )
867 
868 /**
869   * @brief Verify the ADC resolution setting.
870   * @param __RESOLUTION__ programmed ADC resolution.
871   * @retval SET (__RESOLUTION__ is a valid value) or RESET (__RESOLUTION__ is invalid)
872   */
873 #define IS_ADC_RESOLUTION(__RESOLUTION__) (((__RESOLUTION__) == ADC_RESOLUTION_12B) || \
874                                            ((__RESOLUTION__) == ADC_RESOLUTION_10B) || \
875                                            ((__RESOLUTION__) == ADC_RESOLUTION_8B)  || \
876                                            ((__RESOLUTION__) == ADC_RESOLUTION_6B)    )
877 
878 /**
879   * @brief Verify the ADC resolution setting when limited to 6 or 8 bits.
880   * @param __RESOLUTION__ programmed ADC resolution when limited to 6 or 8 bits.
881   * @retval SET (__RESOLUTION__ is a valid value) or RESET (__RESOLUTION__ is invalid)
882   */
883 #define IS_ADC_RESOLUTION_8_6_BITS(__RESOLUTION__) (((__RESOLUTION__) == ADC_RESOLUTION_8B) || \
884                                                     ((__RESOLUTION__) == ADC_RESOLUTION_6B)   )
885 
886 /**
887   * @brief Verify the ADC converted data alignment.
888   * @param __ALIGN__ programmed ADC converted data alignment.
889   * @retval SET (__ALIGN__ is a valid value) or RESET (__ALIGN__ is invalid)
890   */
891 #define IS_ADC_DATA_ALIGN(__ALIGN__) (((__ALIGN__) == ADC_DATAALIGN_RIGHT) || \
892                                       ((__ALIGN__) == ADC_DATAALIGN_LEFT)    )
893 
894 /**
895   * @brief Verify the ADC scan mode.
896   * @param __SCAN_MODE__ programmed ADC scan mode.
897   * @retval SET (__SCAN_MODE__ is valid) or RESET (__SCAN_MODE__ is invalid)
898   */
899 #define IS_ADC_SCAN_MODE(__SCAN_MODE__) (((__SCAN_MODE__) == ADC_SCAN_DISABLE) || \
900                                          ((__SCAN_MODE__) == ADC_SCAN_ENABLE)    )
901 
902 /**
903   * @brief Verify the ADC edge trigger setting for regular group.
904   * @param __EDGE__ programmed ADC edge trigger setting.
905   * @retval SET (__EDGE__ is a valid value) or RESET (__EDGE__ is invalid)
906   */
907 #define IS_ADC_EXTTRIG_EDGE(__EDGE__) (((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_NONE)         || \
908                                        ((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_RISING)       || \
909                                        ((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_FALLING)      || \
910                                        ((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING)  )
911 
912 /**
913   * @brief Verify the ADC regular conversions external trigger.
914   * @param __HANDLE__ ADC handle
915   * @param __REGTRIG__ programmed ADC regular conversions external trigger.
916   * @retval SET (__REGTRIG__ is a valid value) or RESET (__REGTRIG__ is invalid)
917   */
918 #define IS_ADC_EXTTRIG(__HANDLE__, __REGTRIG__) (((__REGTRIG__) == ADC_EXTERNALTRIG_T1_CC1)   || \
919                                                  ((__REGTRIG__) == ADC_EXTERNALTRIG_T1_CC2)   || \
920                                                  ((__REGTRIG__) == ADC_EXTERNALTRIG_T1_CC3)   || \
921                                                  ((__REGTRIG__) == ADC_EXTERNALTRIG_T2_CC2)   || \
922                                                  ((__REGTRIG__) == ADC_EXTERNALTRIG_T3_TRGO)  || \
923                                                  ((__REGTRIG__) == ADC_EXTERNALTRIG_T4_CC4)   || \
924                                                  ((__REGTRIG__) == ADC_EXTERNALTRIG_EXT_IT11) || \
925                                                  ((__REGTRIG__) == ADC_EXTERNALTRIG_T8_TRGO)  || \
926                                                  ((__REGTRIG__) == ADC_EXTERNALTRIG_T8_TRGO2) || \
927                                                  ((__REGTRIG__) == ADC_EXTERNALTRIG_T1_TRGO)  || \
928                                                  ((__REGTRIG__) == ADC_EXTERNALTRIG_T1_TRGO2) || \
929                                                  ((__REGTRIG__) == ADC_EXTERNALTRIG_T2_TRGO)  || \
930                                                  ((__REGTRIG__) == ADC_EXTERNALTRIG_T4_TRGO)  || \
931                                                  ((__REGTRIG__) == ADC_EXTERNALTRIG_T6_TRGO)  || \
932                                                  ((__REGTRIG__) == ADC_EXTERNALTRIG_T15_TRGO) || \
933                                                  ((__REGTRIG__) == ADC_EXTERNALTRIG_T3_CC4)   || \
934                                                  ((__REGTRIG__) == ADC_SOFTWARE_START)           )
935 
936 /**
937   * @brief Verify the ADC regular conversions check for converted data availability.
938   * @param __EOC_SELECTION__ converted data availability check.
939   * @retval SET (__EOC_SELECTION__ is a valid value) or RESET (__EOC_SELECTION__ is invalid)
940   */
941 #define IS_ADC_EOC_SELECTION(__EOC_SELECTION__) (((__EOC_SELECTION__) == ADC_EOC_SINGLE_CONV)    || \
942                                                  ((__EOC_SELECTION__) == ADC_EOC_SEQ_CONV)  )
943 
944 /**
945   * @brief Verify the ADC regular conversions overrun handling.
946   * @param __OVR__ ADC regular conversions overrun handling.
947   * @retval SET (__OVR__ is a valid value) or RESET (__OVR__ is invalid)
948   */
949 #define IS_ADC_OVERRUN(__OVR__) (((__OVR__) == ADC_OVR_DATA_PRESERVED)  || \
950                                  ((__OVR__) == ADC_OVR_DATA_OVERWRITTEN)  )
951 
952 /**
953   * @brief Verify the ADC conversions sampling time.
954   * @param __TIME__ ADC conversions sampling time.
955   * @retval SET (__TIME__ is a valid value) or RESET (__TIME__ is invalid)
956   */
957 #if defined(ADC_SMPR1_SMPPLUS)
958 #define IS_ADC_SAMPLE_TIME(__TIME__) (((__TIME__) == ADC_SAMPLETIME_2CYCLES_5)   || \
959                                       ((__TIME__) == ADC_SAMPLETIME_3CYCLES_5)   || \
960                                       ((__TIME__) == ADC_SAMPLETIME_6CYCLES_5)   || \
961                                       ((__TIME__) == ADC_SAMPLETIME_12CYCLES_5)  || \
962                                       ((__TIME__) == ADC_SAMPLETIME_24CYCLES_5)  || \
963                                       ((__TIME__) == ADC_SAMPLETIME_47CYCLES_5)  || \
964                                       ((__TIME__) == ADC_SAMPLETIME_92CYCLES_5)  || \
965                                       ((__TIME__) == ADC_SAMPLETIME_247CYCLES_5) || \
966                                       ((__TIME__) == ADC_SAMPLETIME_640CYCLES_5)   )
967 #else
968 #define IS_ADC_SAMPLE_TIME(__TIME__) (((__TIME__) == ADC_SAMPLETIME_2CYCLES_5)   || \
969                                       ((__TIME__) == ADC_SAMPLETIME_6CYCLES_5)   || \
970                                       ((__TIME__) == ADC_SAMPLETIME_12CYCLES_5)  || \
971                                       ((__TIME__) == ADC_SAMPLETIME_24CYCLES_5)  || \
972                                       ((__TIME__) == ADC_SAMPLETIME_47CYCLES_5)  || \
973                                       ((__TIME__) == ADC_SAMPLETIME_92CYCLES_5)  || \
974                                       ((__TIME__) == ADC_SAMPLETIME_247CYCLES_5) || \
975                                       ((__TIME__) == ADC_SAMPLETIME_640CYCLES_5)   )
976 #endif
977 
978 /**
979   * @brief Verify the ADC regular channel setting.
980   * @param  __CHANNEL__ programmed ADC regular channel.
981   * @retval SET (__CHANNEL__ is valid) or RESET (__CHANNEL__ is invalid)
982   */
983 #define IS_ADC_REGULAR_RANK(__CHANNEL__) (((__CHANNEL__) == ADC_REGULAR_RANK_1 ) || \
984                                           ((__CHANNEL__) == ADC_REGULAR_RANK_2 ) || \
985                                           ((__CHANNEL__) == ADC_REGULAR_RANK_3 ) || \
986                                           ((__CHANNEL__) == ADC_REGULAR_RANK_4 ) || \
987                                           ((__CHANNEL__) == ADC_REGULAR_RANK_5 ) || \
988                                           ((__CHANNEL__) == ADC_REGULAR_RANK_6 ) || \
989                                           ((__CHANNEL__) == ADC_REGULAR_RANK_7 ) || \
990                                           ((__CHANNEL__) == ADC_REGULAR_RANK_8 ) || \
991                                           ((__CHANNEL__) == ADC_REGULAR_RANK_9 ) || \
992                                           ((__CHANNEL__) == ADC_REGULAR_RANK_10) || \
993                                           ((__CHANNEL__) == ADC_REGULAR_RANK_11) || \
994                                           ((__CHANNEL__) == ADC_REGULAR_RANK_12) || \
995                                           ((__CHANNEL__) == ADC_REGULAR_RANK_13) || \
996                                           ((__CHANNEL__) == ADC_REGULAR_RANK_14) || \
997                                           ((__CHANNEL__) == ADC_REGULAR_RANK_15) || \
998                                           ((__CHANNEL__) == ADC_REGULAR_RANK_16)   )
999 
1000 /**
1001   * @}
1002   */
1003 
1004 
1005 /* Private constants ---------------------------------------------------------*/
1006 
1007 /** @defgroup ADC_Private_Constants ADC Private Constants
1008   * @{
1009   */
1010 
1011 /* Fixed timeout values for ADC conversion (including sampling time)        */
1012 /* Maximum sampling time is 640.5 ADC clock cycle (SMPx[2:0] = 0b111        */
1013 /* Maximum conversion time is 12.5 + Maximum sampling time                  */
1014 /*                       or 12.5  + 640.5 = 653 ADC clock cycles            */
1015 /* Minimum ADC Clock frequency is 0.14 MHz                                  */
1016 /* Maximum conversion time is                                               */
1017 /*              653 / 0.14 MHz = 4.66 ms                                    */
1018 #define ADC_STOP_CONVERSION_TIMEOUT     ( 5UL)     /*!< ADC stop time-out value */
1019 
1020 /* Delay for temperature sensor stabilization time.                         */
1021 /* Maximum delay is 120us (refer device datasheet, parameter tSTART).       */
1022 /* Unit: us                                                                 */
1023 #define ADC_TEMPSENSOR_DELAY_US         (LL_ADC_DELAY_TEMPSENSOR_STAB_US)
1024 
1025 /**
1026   * @}
1027   */
1028 
1029 /* Exported macro ------------------------------------------------------------*/
1030 
1031 /** @defgroup ADC_Exported_Macros ADC Exported Macros
1032   * @{
1033   */
1034 /* Macro for internal HAL driver usage, and possibly can be used into code of */
1035 /* final user.                                                                */
1036 
1037 /** @defgroup ADC_HAL_EM_HANDLE_IT_FLAG HAL ADC macro to manage HAL ADC handle, IT and flags.
1038   * @{
1039   */
1040 
1041 /** @brief  Reset ADC handle state.
1042   * @param __HANDLE__ ADC handle
1043   * @retval None
1044   */
1045 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
1046 #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__)                               \
1047   do{                                                                          \
1048     (__HANDLE__)->State = HAL_ADC_STATE_RESET;                                 \
1049     (__HANDLE__)->MspInitCallback = NULL;                                      \
1050     (__HANDLE__)->MspDeInitCallback = NULL;                                    \
1051   } while(0)
1052 #else
1053 #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__)                               \
1054   ((__HANDLE__)->State = HAL_ADC_STATE_RESET)
1055 #endif
1056 
1057 /**
1058   * @brief Enable ADC interrupt.
1059   * @param __HANDLE__ ADC handle
1060   * @param __INTERRUPT__ ADC Interrupt
1061   *        This parameter can be one of the following values:
1062   *            @arg @ref ADC_IT_RDY    ADC Ready interrupt source
1063   *            @arg @ref ADC_IT_EOSMP  ADC End of Sampling interrupt source
1064   *            @arg @ref ADC_IT_EOC    ADC End of Regular Conversion interrupt source
1065   *            @arg @ref ADC_IT_EOS    ADC End of Regular sequence of Conversions interrupt source
1066   *            @arg @ref ADC_IT_OVR    ADC overrun interrupt source
1067   *            @arg @ref ADC_IT_JEOC   ADC End of Injected Conversion interrupt source
1068   *            @arg @ref ADC_IT_JEOS   ADC End of Injected sequence of Conversions interrupt source
1069   *            @arg @ref ADC_IT_AWD1   ADC Analog watchdog 1 interrupt source (main analog watchdog)
1070   *            @arg @ref ADC_IT_AWD2   ADC Analog watchdog 2 interrupt source (additional analog watchdog)
1071   *            @arg @ref ADC_IT_AWD3   ADC Analog watchdog 3 interrupt source (additional analog watchdog)
1072   *            @arg @ref ADC_IT_JQOVF  ADC Injected Context Queue Overflow interrupt source.
1073   * @retval None
1074   */
1075 #define __HAL_ADC_ENABLE_IT(__HANDLE__, __INTERRUPT__)                         \
1076   (((__HANDLE__)->Instance->IER) |= (__INTERRUPT__))
1077 
1078 /**
1079   * @brief Disable ADC interrupt.
1080   * @param __HANDLE__ ADC handle
1081   * @param __INTERRUPT__ ADC Interrupt
1082   *        This parameter can be one of the following values:
1083   *            @arg @ref ADC_IT_RDY    ADC Ready interrupt source
1084   *            @arg @ref ADC_IT_EOSMP  ADC End of Sampling interrupt source
1085   *            @arg @ref ADC_IT_EOC    ADC End of Regular Conversion interrupt source
1086   *            @arg @ref ADC_IT_EOS    ADC End of Regular sequence of Conversions interrupt source
1087   *            @arg @ref ADC_IT_OVR    ADC overrun interrupt source
1088   *            @arg @ref ADC_IT_JEOC   ADC End of Injected Conversion interrupt source
1089   *            @arg @ref ADC_IT_JEOS   ADC End of Injected sequence of Conversions interrupt source
1090   *            @arg @ref ADC_IT_AWD1   ADC Analog watchdog 1 interrupt source (main analog watchdog)
1091   *            @arg @ref ADC_IT_AWD2   ADC Analog watchdog 2 interrupt source (additional analog watchdog)
1092   *            @arg @ref ADC_IT_AWD3   ADC Analog watchdog 3 interrupt source (additional analog watchdog)
1093   *            @arg @ref ADC_IT_JQOVF  ADC Injected Context Queue Overflow interrupt source.
1094   * @retval None
1095   */
1096 #define __HAL_ADC_DISABLE_IT(__HANDLE__, __INTERRUPT__)                        \
1097   (((__HANDLE__)->Instance->IER) &= ~(__INTERRUPT__))
1098 
1099 /** @brief  Checks if the specified ADC interrupt source is enabled or disabled.
1100   * @param __HANDLE__ ADC handle
1101   * @param __INTERRUPT__ ADC interrupt source to check
1102   *          This parameter can be one of the following values:
1103   *            @arg @ref ADC_IT_RDY    ADC Ready interrupt source
1104   *            @arg @ref ADC_IT_EOSMP  ADC End of Sampling interrupt source
1105   *            @arg @ref ADC_IT_EOC    ADC End of Regular Conversion interrupt source
1106   *            @arg @ref ADC_IT_EOS    ADC End of Regular sequence of Conversions interrupt source
1107   *            @arg @ref ADC_IT_OVR    ADC overrun interrupt source
1108   *            @arg @ref ADC_IT_JEOC   ADC End of Injected Conversion interrupt source
1109   *            @arg @ref ADC_IT_JEOS   ADC End of Injected sequence of Conversions interrupt source
1110   *            @arg @ref ADC_IT_AWD1   ADC Analog watchdog 1 interrupt source (main analog watchdog)
1111   *            @arg @ref ADC_IT_AWD2   ADC Analog watchdog 2 interrupt source (additional analog watchdog)
1112   *            @arg @ref ADC_IT_AWD3   ADC Analog watchdog 3 interrupt source (additional analog watchdog)
1113   *            @arg @ref ADC_IT_JQOVF  ADC Injected Context Queue Overflow interrupt source.
1114   * @retval State of interruption (SET or RESET)
1115   */
1116 #define __HAL_ADC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)                     \
1117   (((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__))
1118 
1119 /**
1120   * @brief Check whether the specified ADC flag is set or not.
1121   * @param __HANDLE__ ADC handle
1122   * @param __FLAG__ ADC flag
1123   *        This parameter can be one of the following values:
1124   *            @arg @ref ADC_FLAG_RDY     ADC Ready flag
1125   *            @arg @ref ADC_FLAG_EOSMP   ADC End of Sampling flag
1126   *            @arg @ref ADC_FLAG_EOC     ADC End of Regular Conversion flag
1127   *            @arg @ref ADC_FLAG_EOS     ADC End of Regular sequence of Conversions flag
1128   *            @arg @ref ADC_FLAG_OVR     ADC overrun flag
1129   *            @arg @ref ADC_FLAG_JEOC    ADC End of Injected Conversion flag
1130   *            @arg @ref ADC_FLAG_JEOS    ADC End of Injected sequence of Conversions flag
1131   *            @arg @ref ADC_FLAG_AWD1    ADC Analog watchdog 1 flag (main analog watchdog)
1132   *            @arg @ref ADC_FLAG_AWD2    ADC Analog watchdog 2 flag (additional analog watchdog)
1133   *            @arg @ref ADC_FLAG_AWD3    ADC Analog watchdog 3 flag (additional analog watchdog)
1134   *            @arg @ref ADC_FLAG_JQOVF   ADC Injected Context Queue Overflow flag.
1135   * @retval State of flag (TRUE or FALSE).
1136   */
1137 #define __HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__)                               \
1138   ((((__HANDLE__)->Instance->ISR) & (__FLAG__)) == (__FLAG__))
1139 
1140 /**
1141   * @brief Clear the specified ADC flag.
1142   * @param __HANDLE__ ADC handle
1143   * @param __FLAG__ ADC flag
1144   *        This parameter can be one of the following values:
1145   *            @arg @ref ADC_FLAG_RDY     ADC Ready flag
1146   *            @arg @ref ADC_FLAG_EOSMP   ADC End of Sampling flag
1147   *            @arg @ref ADC_FLAG_EOC     ADC End of Regular Conversion flag
1148   *            @arg @ref ADC_FLAG_EOS     ADC End of Regular sequence of Conversions flag
1149   *            @arg @ref ADC_FLAG_OVR     ADC overrun flag
1150   *            @arg @ref ADC_FLAG_JEOC    ADC End of Injected Conversion flag
1151   *            @arg @ref ADC_FLAG_JEOS    ADC End of Injected sequence of Conversions flag
1152   *            @arg @ref ADC_FLAG_AWD1    ADC Analog watchdog 1 flag (main analog watchdog)
1153   *            @arg @ref ADC_FLAG_AWD2    ADC Analog watchdog 2 flag (additional analog watchdog)
1154   *            @arg @ref ADC_FLAG_AWD3    ADC Analog watchdog 3 flag (additional analog watchdog)
1155   *            @arg @ref ADC_FLAG_JQOVF   ADC Injected Context Queue Overflow flag.
1156   * @retval None
1157   */
1158 /* Note: bit cleared bit by writing 1 (writing 0 has no effect on any bit of register ISR) */
1159 #define __HAL_ADC_CLEAR_FLAG(__HANDLE__, __FLAG__)                             \
1160   (((__HANDLE__)->Instance->ISR) = (__FLAG__))
1161 
1162 /**
1163   * @}
1164   */
1165 
1166 /** @defgroup ADC_HAL_EM_HELPER_MACRO HAL ADC helper macro
1167   * @{
1168   */
1169 
1170 /**
1171   * @brief  Helper macro to get ADC channel number in decimal format
1172   *         from literals ADC_CHANNEL_x.
1173   * @note   Example:
1174   *           __HAL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_4)
1175   *           will return decimal number "4".
1176   * @note   The input can be a value from functions where a channel
1177   *         number is returned, either defined with number
1178   *         or with bitfield (only one bit must be set).
1179   * @param  __CHANNEL__ This parameter can be one of the following values:
1180   *         @arg @ref ADC_CHANNEL_0
1181   *         @arg @ref ADC_CHANNEL_1            (7)
1182   *         @arg @ref ADC_CHANNEL_2            (7)
1183   *         @arg @ref ADC_CHANNEL_3            (7)
1184   *         @arg @ref ADC_CHANNEL_4            (7)
1185   *         @arg @ref ADC_CHANNEL_5            (7)
1186   *         @arg @ref ADC_CHANNEL_6
1187   *         @arg @ref ADC_CHANNEL_7
1188   *         @arg @ref ADC_CHANNEL_8
1189   *         @arg @ref ADC_CHANNEL_9
1190   *         @arg @ref ADC_CHANNEL_10
1191   *         @arg @ref ADC_CHANNEL_11
1192   *         @arg @ref ADC_CHANNEL_12
1193   *         @arg @ref ADC_CHANNEL_13
1194   *         @arg @ref ADC_CHANNEL_14
1195   *         @arg @ref ADC_CHANNEL_15
1196   *         @arg @ref ADC_CHANNEL_16
1197   *         @arg @ref ADC_CHANNEL_17
1198   *         @arg @ref ADC_CHANNEL_18
1199   *         @arg @ref ADC_CHANNEL_VREFINT      (1)
1200   *         @arg @ref ADC_CHANNEL_TEMPSENSOR   (4)
1201   *         @arg @ref ADC_CHANNEL_VBAT         (4)
1202   *         @arg @ref ADC_CHANNEL_DAC1CH1         (5)
1203   *         @arg @ref ADC_CHANNEL_DAC1CH2         (5)
1204   *         @arg @ref ADC_CHANNEL_DAC1CH1_ADC2 (2)(6)
1205   *         @arg @ref ADC_CHANNEL_DAC1CH2_ADC2 (2)(6)
1206   *         @arg @ref ADC_CHANNEL_DAC1CH1_ADC3 (3)(6)
1207   *         @arg @ref ADC_CHANNEL_DAC1CH2_ADC3 (3)(6)
1208   *
1209   *         (1) On STM32L4, parameter available only on ADC instance: ADC1.\n
1210   *         (2) On STM32L4, parameter available only on ADC instance: ADC2.\n
1211   *         (3) On STM32L4, parameter available only on ADC instance: ADC3.\n
1212   *         (4) On STM32L4, parameter available only on ADC instances: ADC1, ADC3.\n
1213   *         (5) On STM32L4, parameter available on devices with only 1 ADC instance.\n
1214   *         (6) On STM32L4, parameter available on devices with several ADC instances.\n
1215   *         (7) On STM32L4, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
1216   *             Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
1217   * @retval Value between Min_Data=0 and Max_Data=18
1218   */
1219 #define __HAL_ADC_CHANNEL_TO_DECIMAL_NB(__CHANNEL__)                           \
1220   __LL_ADC_CHANNEL_TO_DECIMAL_NB((__CHANNEL__))
1221 
1222 /**
1223   * @brief  Helper macro to get ADC channel in literal format ADC_CHANNEL_x
1224   *         from number in decimal format.
1225   * @note   Example:
1226   *           __HAL_ADC_DECIMAL_NB_TO_CHANNEL(4)
1227   *           will return a data equivalent to "ADC_CHANNEL_4".
1228   * @param  __DECIMAL_NB__ Value between Min_Data=0 and Max_Data=18
1229   * @retval Returned value can be one of the following values:
1230   *         @arg @ref ADC_CHANNEL_0
1231   *         @arg @ref ADC_CHANNEL_1            (7)
1232   *         @arg @ref ADC_CHANNEL_2            (7)
1233   *         @arg @ref ADC_CHANNEL_3            (7)
1234   *         @arg @ref ADC_CHANNEL_4            (7)
1235   *         @arg @ref ADC_CHANNEL_5            (7)
1236   *         @arg @ref ADC_CHANNEL_6
1237   *         @arg @ref ADC_CHANNEL_7
1238   *         @arg @ref ADC_CHANNEL_8
1239   *         @arg @ref ADC_CHANNEL_9
1240   *         @arg @ref ADC_CHANNEL_10
1241   *         @arg @ref ADC_CHANNEL_11
1242   *         @arg @ref ADC_CHANNEL_12
1243   *         @arg @ref ADC_CHANNEL_13
1244   *         @arg @ref ADC_CHANNEL_14
1245   *         @arg @ref ADC_CHANNEL_15
1246   *         @arg @ref ADC_CHANNEL_16
1247   *         @arg @ref ADC_CHANNEL_17
1248   *         @arg @ref ADC_CHANNEL_18
1249   *         @arg @ref ADC_CHANNEL_VREFINT      (1)
1250   *         @arg @ref ADC_CHANNEL_TEMPSENSOR   (4)
1251   *         @arg @ref ADC_CHANNEL_VBAT         (4)
1252   *         @arg @ref ADC_CHANNEL_DAC1CH1         (5)
1253   *         @arg @ref ADC_CHANNEL_DAC1CH2         (5)
1254   *         @arg @ref ADC_CHANNEL_DAC1CH1_ADC2 (2)(6)
1255   *         @arg @ref ADC_CHANNEL_DAC1CH2_ADC2 (2)(6)
1256   *         @arg @ref ADC_CHANNEL_DAC1CH1_ADC3 (3)(6)
1257   *         @arg @ref ADC_CHANNEL_DAC1CH2_ADC3 (3)(6)
1258   *
1259   *         (1) On STM32L4, parameter available only on ADC instance: ADC1.\n
1260   *         (2) On STM32L4, parameter available only on ADC instance: ADC2.\n
1261   *         (3) On STM32L4, parameter available only on ADC instance: ADC3.\n
1262   *         (4) On STM32L4, parameter available only on ADC instances: ADC1, ADC3.\n
1263   *         (5) On STM32L4, parameter available on devices with only 1 ADC instance.\n
1264   *         (6) On STM32L4, parameter available on devices with several ADC instances.\n
1265   *         (7) On STM32L4, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
1266   *             Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).\n
1267   *         (1, 2, 3, 4) For ADC channel read back from ADC register,
1268   *                      comparison with internal channel parameter to be done
1269   *                      using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
1270   */
1271 #define __HAL_ADC_DECIMAL_NB_TO_CHANNEL(__DECIMAL_NB__)                        \
1272   __LL_ADC_DECIMAL_NB_TO_CHANNEL((__DECIMAL_NB__))
1273 
1274 /**
1275   * @brief  Helper macro to determine whether the selected channel
1276   *         corresponds to literal definitions of driver.
1277   * @note   The different literal definitions of ADC channels are:
1278   *         - ADC internal channel:
1279   *           ADC_CHANNEL_VREFINT, ADC_CHANNEL_TEMPSENSOR, ...
1280   *         - ADC external channel (channel connected to a GPIO pin):
1281   *           ADC_CHANNEL_1, ADC_CHANNEL_2, ...
1282   * @note   The channel parameter must be a value defined from literal
1283   *         definition of a ADC internal channel (ADC_CHANNEL_VREFINT,
1284   *         ADC_CHANNEL_TEMPSENSOR, ...),
1285   *         ADC external channel (ADC_CHANNEL_1, ADC_CHANNEL_2, ...),
1286   *         must not be a value from functions where a channel number is
1287   *         returned from ADC registers,
1288   *         because internal and external channels share the same channel
1289   *         number in ADC registers. The differentiation is made only with
1290   *         parameters definitions of driver.
1291   * @param  __CHANNEL__ This parameter can be one of the following values:
1292   *         @arg @ref ADC_CHANNEL_0
1293   *         @arg @ref ADC_CHANNEL_1            (7)
1294   *         @arg @ref ADC_CHANNEL_2            (7)
1295   *         @arg @ref ADC_CHANNEL_3            (7)
1296   *         @arg @ref ADC_CHANNEL_4            (7)
1297   *         @arg @ref ADC_CHANNEL_5            (7)
1298   *         @arg @ref ADC_CHANNEL_6
1299   *         @arg @ref ADC_CHANNEL_7
1300   *         @arg @ref ADC_CHANNEL_8
1301   *         @arg @ref ADC_CHANNEL_9
1302   *         @arg @ref ADC_CHANNEL_10
1303   *         @arg @ref ADC_CHANNEL_11
1304   *         @arg @ref ADC_CHANNEL_12
1305   *         @arg @ref ADC_CHANNEL_13
1306   *         @arg @ref ADC_CHANNEL_14
1307   *         @arg @ref ADC_CHANNEL_15
1308   *         @arg @ref ADC_CHANNEL_16
1309   *         @arg @ref ADC_CHANNEL_17
1310   *         @arg @ref ADC_CHANNEL_18
1311   *         @arg @ref ADC_CHANNEL_VREFINT      (1)
1312   *         @arg @ref ADC_CHANNEL_TEMPSENSOR   (4)
1313   *         @arg @ref ADC_CHANNEL_VBAT         (4)
1314   *         @arg @ref ADC_CHANNEL_DAC1CH1         (5)
1315   *         @arg @ref ADC_CHANNEL_DAC1CH2         (5)
1316   *         @arg @ref ADC_CHANNEL_DAC1CH1_ADC2 (2)(6)
1317   *         @arg @ref ADC_CHANNEL_DAC1CH2_ADC2 (2)(6)
1318   *         @arg @ref ADC_CHANNEL_DAC1CH1_ADC3 (3)(6)
1319   *         @arg @ref ADC_CHANNEL_DAC1CH2_ADC3 (3)(6)
1320   *
1321   *         (1) On STM32L4, parameter available only on ADC instance: ADC1.\n
1322   *         (2) On STM32L4, parameter available only on ADC instance: ADC2.\n
1323   *         (3) On STM32L4, parameter available only on ADC instance: ADC3.\n
1324   *         (4) On STM32L4, parameter available only on ADC instances: ADC1, ADC3.\n
1325   *         (5) On STM32L4, parameter available on devices with only 1 ADC instance.\n
1326   *         (6) On STM32L4, parameter available on devices with several ADC instances.\n
1327   *         (7) On STM32L4, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
1328   *             Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
1329   * @retval Value "0" if the channel corresponds to a parameter definition of a ADC external channel (channel connected to a GPIO pin).
1330   *         Value "1" if the channel corresponds to a parameter definition of a ADC internal channel.
1331   */
1332 #define __HAL_ADC_IS_CHANNEL_INTERNAL(__CHANNEL__)                             \
1333   __LL_ADC_IS_CHANNEL_INTERNAL((__CHANNEL__))
1334 
1335 /**
1336   * @brief  Helper macro to convert a channel defined from parameter
1337   *         definition of a ADC internal channel (ADC_CHANNEL_VREFINT,
1338   *         ADC_CHANNEL_TEMPSENSOR, ...),
1339   *         to its equivalent parameter definition of a ADC external channel
1340   *         (ADC_CHANNEL_1, ADC_CHANNEL_2, ...).
1341   * @note   The channel parameter can be, additionally to a value
1342   *         defined from parameter definition of a ADC internal channel
1343   *         (ADC_CHANNEL_VREFINT, ADC_CHANNEL_TEMPSENSOR, ...),
1344   *         a value defined from parameter definition of
1345   *         ADC external channel (ADC_CHANNEL_1, ADC_CHANNEL_2, ...)
1346   *         or a value from functions where a channel number is returned
1347   *         from ADC registers.
1348   * @param  __CHANNEL__ This parameter can be one of the following values:
1349   *         @arg @ref ADC_CHANNEL_0
1350   *         @arg @ref ADC_CHANNEL_1            (7)
1351   *         @arg @ref ADC_CHANNEL_2            (7)
1352   *         @arg @ref ADC_CHANNEL_3            (7)
1353   *         @arg @ref ADC_CHANNEL_4            (7)
1354   *         @arg @ref ADC_CHANNEL_5            (7)
1355   *         @arg @ref ADC_CHANNEL_6
1356   *         @arg @ref ADC_CHANNEL_7
1357   *         @arg @ref ADC_CHANNEL_8
1358   *         @arg @ref ADC_CHANNEL_9
1359   *         @arg @ref ADC_CHANNEL_10
1360   *         @arg @ref ADC_CHANNEL_11
1361   *         @arg @ref ADC_CHANNEL_12
1362   *         @arg @ref ADC_CHANNEL_13
1363   *         @arg @ref ADC_CHANNEL_14
1364   *         @arg @ref ADC_CHANNEL_15
1365   *         @arg @ref ADC_CHANNEL_16
1366   *         @arg @ref ADC_CHANNEL_17
1367   *         @arg @ref ADC_CHANNEL_18
1368   *         @arg @ref ADC_CHANNEL_VREFINT      (1)
1369   *         @arg @ref ADC_CHANNEL_TEMPSENSOR   (4)
1370   *         @arg @ref ADC_CHANNEL_VBAT         (4)
1371   *         @arg @ref ADC_CHANNEL_DAC1CH1         (5)
1372   *         @arg @ref ADC_CHANNEL_DAC1CH2         (5)
1373   *         @arg @ref ADC_CHANNEL_DAC1CH1_ADC2 (2)(6)
1374   *         @arg @ref ADC_CHANNEL_DAC1CH2_ADC2 (2)(6)
1375   *         @arg @ref ADC_CHANNEL_DAC1CH1_ADC3 (3)(6)
1376   *         @arg @ref ADC_CHANNEL_DAC1CH2_ADC3 (3)(6)
1377   *
1378   *         (1) On STM32L4, parameter available only on ADC instance: ADC1.\n
1379   *         (2) On STM32L4, parameter available only on ADC instance: ADC2.\n
1380   *         (3) On STM32L4, parameter available only on ADC instance: ADC3.\n
1381   *         (4) On STM32L4, parameter available only on ADC instances: ADC1, ADC3.\n
1382   *         (5) On STM32L4, parameter available on devices with only 1 ADC instance.\n
1383   *         (6) On STM32L4, parameter available on devices with several ADC instances.\n
1384   *         (7) On STM32L4, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
1385   *             Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
1386   * @retval Returned value can be one of the following values:
1387   *         @arg @ref ADC_CHANNEL_0
1388   *         @arg @ref ADC_CHANNEL_1
1389   *         @arg @ref ADC_CHANNEL_2
1390   *         @arg @ref ADC_CHANNEL_3
1391   *         @arg @ref ADC_CHANNEL_4
1392   *         @arg @ref ADC_CHANNEL_5
1393   *         @arg @ref ADC_CHANNEL_6
1394   *         @arg @ref ADC_CHANNEL_7
1395   *         @arg @ref ADC_CHANNEL_8
1396   *         @arg @ref ADC_CHANNEL_9
1397   *         @arg @ref ADC_CHANNEL_10
1398   *         @arg @ref ADC_CHANNEL_11
1399   *         @arg @ref ADC_CHANNEL_12
1400   *         @arg @ref ADC_CHANNEL_13
1401   *         @arg @ref ADC_CHANNEL_14
1402   *         @arg @ref ADC_CHANNEL_15
1403   *         @arg @ref ADC_CHANNEL_16
1404   *         @arg @ref ADC_CHANNEL_17
1405   *         @arg @ref ADC_CHANNEL_18
1406   */
1407 #define __HAL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL(__CHANNEL__)                    \
1408   __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL((__CHANNEL__))
1409 
1410 /**
1411   * @brief  Helper macro to determine whether the internal channel
1412   *         selected is available on the ADC instance selected.
1413   * @note   The channel parameter must be a value defined from parameter
1414   *         definition of a ADC internal channel (ADC_CHANNEL_VREFINT,
1415   *         ADC_CHANNEL_TEMPSENSOR, ...),
1416   *         must not be a value defined from parameter definition of
1417   *         ADC external channel (ADC_CHANNEL_1, ADC_CHANNEL_2, ...)
1418   *         or a value from functions where a channel number is
1419   *         returned from ADC registers,
1420   *         because internal and external channels share the same channel
1421   *         number in ADC registers. The differentiation is made only with
1422   *         parameters definitions of driver.
1423   * @param  __ADC_INSTANCE__ ADC instance
1424   * @param  __CHANNEL__ This parameter can be one of the following values:
1425   *         @arg @ref ADC_CHANNEL_VREFINT      (1)
1426   *         @arg @ref ADC_CHANNEL_TEMPSENSOR   (4)
1427   *         @arg @ref ADC_CHANNEL_VBAT         (4)
1428   *         @arg @ref ADC_CHANNEL_DAC1CH1         (5)
1429   *         @arg @ref ADC_CHANNEL_DAC1CH2         (5)
1430   *         @arg @ref ADC_CHANNEL_DAC1CH1_ADC2 (2)(6)
1431   *         @arg @ref ADC_CHANNEL_DAC1CH2_ADC2 (2)(6)
1432   *         @arg @ref ADC_CHANNEL_DAC1CH1_ADC3 (3)(6)
1433   *         @arg @ref ADC_CHANNEL_DAC1CH2_ADC3 (3)(6)
1434   *
1435   *         (1) On STM32L4, parameter available only on ADC instance: ADC1.\n
1436   *         (2) On STM32L4, parameter available only on ADC instance: ADC2.\n
1437   *         (3) On STM32L4, parameter available only on ADC instance: ADC3.\n
1438   *         (4) On STM32L4, parameter available only on ADC instances: ADC1, ADC3.\n
1439   *         (5) On STM32L4, parameter available on devices with only 1 ADC instance.\n
1440   *         (6) On STM32L4, parameter available on devices with several ADC instances.
1441   * @retval Value "0" if the internal channel selected is not available on the ADC instance selected.
1442   *         Value "1" if the internal channel selected is available on the ADC instance selected.
1443   */
1444 #define __HAL_ADC_IS_CHANNEL_INTERNAL_AVAILABLE(__ADC_INSTANCE__, __CHANNEL__)  \
1445   __LL_ADC_IS_CHANNEL_INTERNAL_AVAILABLE((__ADC_INSTANCE__), (__CHANNEL__))
1446 
1447 #if defined(ADC_MULTIMODE_SUPPORT)
1448 /**
1449   * @brief  Helper macro to get the ADC multimode conversion data of ADC master
1450   *         or ADC slave from raw value with both ADC conversion data concatenated.
1451   * @note   This macro is intended to be used when multimode transfer by DMA
1452   *         is enabled: refer to function @ref LL_ADC_SetMultiDMATransfer().
1453   *         In this case the transferred data need to processed with this macro
1454   *         to separate the conversion data of ADC master and ADC slave.
1455   * @param  __ADC_MULTI_MASTER_SLAVE__ This parameter can be one of the following values:
1456   *         @arg @ref LL_ADC_MULTI_MASTER
1457   *         @arg @ref LL_ADC_MULTI_SLAVE
1458   * @param  __ADC_MULTI_CONV_DATA__ Value between Min_Data=0x000 and Max_Data=0xFFF
1459   * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
1460   */
1461 #define __HAL_ADC_MULTI_CONV_DATA_MASTER_SLAVE(__ADC_MULTI_MASTER_SLAVE__, __ADC_MULTI_CONV_DATA__)  \
1462   __LL_ADC_MULTI_CONV_DATA_MASTER_SLAVE((__ADC_MULTI_MASTER_SLAVE__), (__ADC_MULTI_CONV_DATA__))
1463 #endif
1464 
1465 /**
1466   * @brief  Helper macro to select the ADC common instance
1467   *         to which is belonging the selected ADC instance.
1468   * @note   ADC common register instance can be used for:
1469   *         - Set parameters common to several ADC instances
1470   *         - Multimode (for devices with several ADC instances)
1471   *         Refer to functions having argument "ADCxy_COMMON" as parameter.
1472   * @param  __ADCx__ ADC instance
1473   * @retval ADC common register instance
1474   */
1475 #define __HAL_ADC_COMMON_INSTANCE(__ADCx__)                                    \
1476   __LL_ADC_COMMON_INSTANCE((__ADCx__))
1477 
1478 /**
1479   * @brief  Helper macro to check if all ADC instances sharing the same
1480   *         ADC common instance are disabled.
1481   * @note   This check is required by functions with setting conditioned to
1482   *         ADC state:
1483   *         All ADC instances of the ADC common group must be disabled.
1484   *         Refer to functions having argument "ADCxy_COMMON" as parameter.
1485   * @note   On devices with only 1 ADC common instance, parameter of this macro
1486   *         is useless and can be ignored (parameter kept for compatibility
1487   *         with devices featuring several ADC common instances).
1488   * @param  __ADCXY_COMMON__ ADC common instance
1489   *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
1490   * @retval Value "0" if all ADC instances sharing the same ADC common instance
1491   *         are disabled.
1492   *         Value "1" if at least one ADC instance sharing the same ADC common instance
1493   *         is enabled.
1494   */
1495 #define __HAL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__ADCXY_COMMON__)              \
1496   __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE((__ADCXY_COMMON__))
1497 
1498 /**
1499   * @brief  Helper macro to define the ADC conversion data full-scale digital
1500   *         value corresponding to the selected ADC resolution.
1501   * @note   ADC conversion data full-scale corresponds to voltage range
1502   *         determined by analog voltage references Vref+ and Vref-
1503   *         (refer to reference manual).
1504   * @param  __ADC_RESOLUTION__ This parameter can be one of the following values:
1505   *         @arg @ref ADC_RESOLUTION_12B
1506   *         @arg @ref ADC_RESOLUTION_10B
1507   *         @arg @ref ADC_RESOLUTION_8B
1508   *         @arg @ref ADC_RESOLUTION_6B
1509   * @retval ADC conversion data full-scale digital value
1510   */
1511 #define __HAL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__)                             \
1512   __LL_ADC_DIGITAL_SCALE((__ADC_RESOLUTION__))
1513 
1514 /**
1515   * @brief  Helper macro to convert the ADC conversion data from
1516   *         a resolution to another resolution.
1517   * @param  __DATA__ ADC conversion data to be converted
1518   * @param  __ADC_RESOLUTION_CURRENT__ Resolution of to the data to be converted
1519   *         This parameter can be one of the following values:
1520   *         @arg @ref ADC_RESOLUTION_12B
1521   *         @arg @ref ADC_RESOLUTION_10B
1522   *         @arg @ref ADC_RESOLUTION_8B
1523   *         @arg @ref ADC_RESOLUTION_6B
1524   * @param  __ADC_RESOLUTION_TARGET__ Resolution of the data after conversion
1525   *         This parameter can be one of the following values:
1526   *         @arg @ref ADC_RESOLUTION_12B
1527   *         @arg @ref ADC_RESOLUTION_10B
1528   *         @arg @ref ADC_RESOLUTION_8B
1529   *         @arg @ref ADC_RESOLUTION_6B
1530   * @retval ADC conversion data to the requested resolution
1531   */
1532 #define __HAL_ADC_CONVERT_DATA_RESOLUTION(__DATA__,\
1533                                           __ADC_RESOLUTION_CURRENT__,\
1534                                           __ADC_RESOLUTION_TARGET__)            \
1535   __LL_ADC_CONVERT_DATA_RESOLUTION((__DATA__),                                  \
1536                                    (__ADC_RESOLUTION_CURRENT__),                \
1537                                    (__ADC_RESOLUTION_TARGET__))
1538 
1539 /**
1540   * @brief  Helper macro to calculate the voltage (unit: mVolt)
1541   *         corresponding to a ADC conversion data (unit: digital value).
1542   * @note   Analog reference voltage (Vref+) must be either known from
1543   *         user board environment or can be calculated using ADC measurement
1544   *         and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
1545   * @param  __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
1546   * @param  __ADC_DATA__ ADC conversion data (resolution 12 bits)
1547   *                       (unit: digital value).
1548   * @param  __ADC_RESOLUTION__ This parameter can be one of the following values:
1549   *         @arg @ref ADC_RESOLUTION_12B
1550   *         @arg @ref ADC_RESOLUTION_10B
1551   *         @arg @ref ADC_RESOLUTION_8B
1552   *         @arg @ref ADC_RESOLUTION_6B
1553   * @retval ADC conversion data equivalent voltage value (unit: mVolt)
1554   */
1555 #define __HAL_ADC_CALC_DATA_TO_VOLTAGE(__VREFANALOG_VOLTAGE__,\
1556                                        __ADC_DATA__,\
1557                                        __ADC_RESOLUTION__)                     \
1558   __LL_ADC_CALC_DATA_TO_VOLTAGE((__VREFANALOG_VOLTAGE__),                      \
1559                                 (__ADC_DATA__),                                \
1560                                 (__ADC_RESOLUTION__))
1561 
1562 /**
1563   * @brief  Helper macro to calculate analog reference voltage (Vref+)
1564   *         (unit: mVolt) from ADC conversion data of internal voltage
1565   *         reference VrefInt.
1566   * @note   Computation is using VrefInt calibration value
1567   *         stored in system memory for each device during production.
1568   * @note   This voltage depends on user board environment: voltage level
1569   *         connected to pin Vref+.
1570   *         On devices with small package, the pin Vref+ is not present
1571   *         and internally bonded to pin Vdda.
1572   * @note   On this STM32 serie, calibration data of internal voltage reference
1573   *         VrefInt corresponds to a resolution of 12 bits,
1574   *         this is the recommended ADC resolution to convert voltage of
1575   *         internal voltage reference VrefInt.
1576   *         Otherwise, this macro performs the processing to scale
1577   *         ADC conversion data to 12 bits.
1578   * @param  __VREFINT_ADC_DATA__ ADC conversion data (resolution 12 bits)
1579   *         of internal voltage reference VrefInt (unit: digital value).
1580   * @param  __ADC_RESOLUTION__ This parameter can be one of the following values:
1581   *         @arg @ref ADC_RESOLUTION_12B
1582   *         @arg @ref ADC_RESOLUTION_10B
1583   *         @arg @ref ADC_RESOLUTION_8B
1584   *         @arg @ref ADC_RESOLUTION_6B
1585   * @retval Analog reference voltage (unit: mV)
1586   */
1587 #define __HAL_ADC_CALC_VREFANALOG_VOLTAGE(__VREFINT_ADC_DATA__,\
1588                                           __ADC_RESOLUTION__)                  \
1589   __LL_ADC_CALC_VREFANALOG_VOLTAGE((__VREFINT_ADC_DATA__),                     \
1590                                   (__ADC_RESOLUTION__))
1591 
1592 /**
1593   * @brief  Helper macro to calculate the temperature (unit: degree Celsius)
1594   *         from ADC conversion data of internal temperature sensor.
1595   * @note   Computation is using temperature sensor calibration values
1596   *         stored in system memory for each device during production.
1597   * @note   Calculation formula:
1598   *           Temperature = ((TS_ADC_DATA - TS_CAL1)
1599   *                           * (TS_CAL2_TEMP - TS_CAL1_TEMP))
1600   *                         / (TS_CAL2 - TS_CAL1) + TS_CAL1_TEMP
1601   *           with TS_ADC_DATA = temperature sensor raw data measured by ADC
1602   *                Avg_Slope = (TS_CAL2 - TS_CAL1)
1603   *                            / (TS_CAL2_TEMP - TS_CAL1_TEMP)
1604   *                TS_CAL1   = equivalent TS_ADC_DATA at temperature
1605   *                            TEMP_DEGC_CAL1 (calibrated in factory)
1606   *                TS_CAL2   = equivalent TS_ADC_DATA at temperature
1607   *                            TEMP_DEGC_CAL2 (calibrated in factory)
1608   *         Caution: Calculation relevancy under reserve that calibration
1609   *                  parameters are correct (address and data).
1610   *                  To calculate temperature using temperature sensor
1611   *                  datasheet typical values (generic values less, therefore
1612   *                  less accurate than calibrated values),
1613   *                  use helper macro @ref __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS().
1614   * @note   As calculation input, the analog reference voltage (Vref+) must be
1615   *         defined as it impacts the ADC LSB equivalent voltage.
1616   * @note   Analog reference voltage (Vref+) must be either known from
1617   *         user board environment or can be calculated using ADC measurement
1618   *         and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
1619   * @note   On this STM32 serie, calibration data of temperature sensor
1620   *         corresponds to a resolution of 12 bits,
1621   *         this is the recommended ADC resolution to convert voltage of
1622   *         temperature sensor.
1623   *         Otherwise, this macro performs the processing to scale
1624   *         ADC conversion data to 12 bits.
1625   * @param  __VREFANALOG_VOLTAGE__  Analog reference voltage (unit: mV)
1626   * @param  __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal
1627   *                                 temperature sensor (unit: digital value).
1628   * @param  __ADC_RESOLUTION__      ADC resolution at which internal temperature
1629   *                                 sensor voltage has been measured.
1630   *         This parameter can be one of the following values:
1631   *         @arg @ref ADC_RESOLUTION_12B
1632   *         @arg @ref ADC_RESOLUTION_10B
1633   *         @arg @ref ADC_RESOLUTION_8B
1634   *         @arg @ref ADC_RESOLUTION_6B
1635   * @retval Temperature (unit: degree Celsius)
1636   */
1637 #define __HAL_ADC_CALC_TEMPERATURE(__VREFANALOG_VOLTAGE__,\
1638                                    __TEMPSENSOR_ADC_DATA__,\
1639                                    __ADC_RESOLUTION__)                         \
1640   __LL_ADC_CALC_TEMPERATURE((__VREFANALOG_VOLTAGE__),                          \
1641                             (__TEMPSENSOR_ADC_DATA__),                         \
1642                             (__ADC_RESOLUTION__))
1643 
1644 /**
1645   * @brief  Helper macro to calculate the temperature (unit: degree Celsius)
1646   *         from ADC conversion data of internal temperature sensor.
1647   * @note   Computation is using temperature sensor typical values
1648   *         (refer to device datasheet).
1649   * @note   Calculation formula:
1650   *           Temperature = (TS_TYP_CALx_VOLT(uV) - TS_ADC_DATA * Conversion_uV)
1651   *                         / Avg_Slope + CALx_TEMP
1652   *           with TS_ADC_DATA      = temperature sensor raw data measured by ADC
1653   *                                   (unit: digital value)
1654   *                Avg_Slope        = temperature sensor slope
1655   *                                   (unit: uV/Degree Celsius)
1656   *                TS_TYP_CALx_VOLT = temperature sensor digital value at
1657   *                                   temperature CALx_TEMP (unit: mV)
1658   *         Caution: Calculation relevancy under reserve the temperature sensor
1659   *                  of the current device has characteristics in line with
1660   *                  datasheet typical values.
1661   *                  If temperature sensor calibration values are available on
1662   *                  on this device (presence of macro __LL_ADC_CALC_TEMPERATURE()),
1663   *                  temperature calculation will be more accurate using
1664   *                  helper macro @ref __LL_ADC_CALC_TEMPERATURE().
1665   * @note   As calculation input, the analog reference voltage (Vref+) must be
1666   *         defined as it impacts the ADC LSB equivalent voltage.
1667   * @note   Analog reference voltage (Vref+) must be either known from
1668   *         user board environment or can be calculated using ADC measurement
1669   *         and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
1670   * @note   ADC measurement data must correspond to a resolution of 12bits
1671   *         (full scale digital value 4095). If not the case, the data must be
1672   *         preliminarily rescaled to an equivalent resolution of 12 bits.
1673   * @param  __TEMPSENSOR_TYP_AVGSLOPE__   Device datasheet data: Temperature sensor slope typical value (unit: uV/DegCelsius).
1674   *                                       On STM32L4, refer to device datasheet parameter "Avg_Slope".
1675   * @param  __TEMPSENSOR_TYP_CALX_V__     Device datasheet data: Temperature sensor voltage typical value (at temperature and Vref+ defined in parameters below) (unit: mV).
1676   *                                       On STM32L4, refer to device datasheet parameter "V30" (corresponding to TS_CAL1).
1677   * @param  __TEMPSENSOR_CALX_TEMP__      Device datasheet data: Temperature at which temperature sensor voltage (see parameter above) is corresponding (unit: mV)
1678   * @param  __VREFANALOG_VOLTAGE__        Analog voltage reference (Vref+) voltage (unit: mV)
1679   * @param  __TEMPSENSOR_ADC_DATA__       ADC conversion data of internal temperature sensor (unit: digital value).
1680   * @param  __ADC_RESOLUTION__            ADC resolution at which internal temperature sensor voltage has been measured.
1681   *         This parameter can be one of the following values:
1682   *         @arg @ref ADC_RESOLUTION_12B
1683   *         @arg @ref ADC_RESOLUTION_10B
1684   *         @arg @ref ADC_RESOLUTION_8B
1685   *         @arg @ref ADC_RESOLUTION_6B
1686   * @retval Temperature (unit: degree Celsius)
1687   */
1688 #define __HAL_ADC_CALC_TEMPERATURE_TYP_PARAMS(__TEMPSENSOR_TYP_AVGSLOPE__,\
1689                                               __TEMPSENSOR_TYP_CALX_V__,\
1690                                               __TEMPSENSOR_CALX_TEMP__,\
1691                                               __VREFANALOG_VOLTAGE__,\
1692                                               __TEMPSENSOR_ADC_DATA__,\
1693                                               __ADC_RESOLUTION__)              \
1694   __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS((__TEMPSENSOR_TYP_AVGSLOPE__),          \
1695                                       (__TEMPSENSOR_TYP_CALX_V__),             \
1696                                       (__TEMPSENSOR_CALX_TEMP__),              \
1697                                       (__VREFANALOG_VOLTAGE__),                \
1698                                       (__TEMPSENSOR_ADC_DATA__),               \
1699                                       (__ADC_RESOLUTION__))
1700 
1701 /**
1702   * @}
1703   */
1704 
1705 /**
1706   * @}
1707   */
1708 
1709 /* Include ADC HAL Extended module */
1710 #include "stm32l4xx_hal_adc_ex.h"
1711 
1712 /* Exported functions --------------------------------------------------------*/
1713 /** @addtogroup ADC_Exported_Functions
1714   * @{
1715   */
1716 
1717 /** @addtogroup ADC_Exported_Functions_Group1
1718   * @brief    Initialization and Configuration functions
1719   * @{
1720   */
1721 /* Initialization and de-initialization functions  ****************************/
1722 HAL_StatusTypeDef       HAL_ADC_Init(ADC_HandleTypeDef *hadc);
1723 HAL_StatusTypeDef       HAL_ADC_DeInit(ADC_HandleTypeDef *hadc);
1724 void                    HAL_ADC_MspInit(ADC_HandleTypeDef *hadc);
1725 void                    HAL_ADC_MspDeInit(ADC_HandleTypeDef *hadc);
1726 
1727 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
1728 /* Callbacks Register/UnRegister functions  ***********************************/
1729 HAL_StatusTypeDef HAL_ADC_RegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID,
1730                                            pADC_CallbackTypeDef pCallback);
1731 HAL_StatusTypeDef HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID);
1732 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
1733 /**
1734   * @}
1735   */
1736 
1737 /** @addtogroup ADC_Exported_Functions_Group2
1738   * @brief    IO operation functions
1739   * @{
1740   */
1741 /* IO operation functions  *****************************************************/
1742 
1743 /* Blocking mode: Polling */
1744 HAL_StatusTypeDef       HAL_ADC_Start(ADC_HandleTypeDef *hadc);
1745 HAL_StatusTypeDef       HAL_ADC_Stop(ADC_HandleTypeDef *hadc);
1746 HAL_StatusTypeDef       HAL_ADC_PollForConversion(ADC_HandleTypeDef *hadc, uint32_t Timeout);
1747 HAL_StatusTypeDef       HAL_ADC_PollForEvent(ADC_HandleTypeDef *hadc, uint32_t EventType, uint32_t Timeout);
1748 
1749 /* Non-blocking mode: Interruption */
1750 HAL_StatusTypeDef       HAL_ADC_Start_IT(ADC_HandleTypeDef *hadc);
1751 HAL_StatusTypeDef       HAL_ADC_Stop_IT(ADC_HandleTypeDef *hadc);
1752 
1753 /* Non-blocking mode: DMA */
1754 HAL_StatusTypeDef       HAL_ADC_Start_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length);
1755 HAL_StatusTypeDef       HAL_ADC_Stop_DMA(ADC_HandleTypeDef *hadc);
1756 
1757 /* ADC retrieve conversion value intended to be used with polling or interruption */
1758 uint32_t                HAL_ADC_GetValue(ADC_HandleTypeDef *hadc);
1759 
1760 /* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption and DMA) */
1761 void                    HAL_ADC_IRQHandler(ADC_HandleTypeDef *hadc);
1762 void                    HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc);
1763 void                    HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef *hadc);
1764 void                    HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef *hadc);
1765 void                    HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc);
1766 /**
1767   * @}
1768   */
1769 
1770 /** @addtogroup ADC_Exported_Functions_Group3 Peripheral Control functions
1771   *  @brief    Peripheral Control functions
1772   * @{
1773   */
1774 /* Peripheral Control functions ***********************************************/
1775 HAL_StatusTypeDef       HAL_ADC_ConfigChannel(ADC_HandleTypeDef *hadc, ADC_ChannelConfTypeDef *sConfig);
1776 HAL_StatusTypeDef       HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef *hadc, ADC_AnalogWDGConfTypeDef *AnalogWDGConfig);
1777 
1778 /**
1779   * @}
1780   */
1781 
1782 /* Peripheral State functions *************************************************/
1783 /** @addtogroup ADC_Exported_Functions_Group4
1784   * @{
1785   */
1786 uint32_t                HAL_ADC_GetState(ADC_HandleTypeDef *hadc);
1787 uint32_t                HAL_ADC_GetError(ADC_HandleTypeDef *hadc);
1788 
1789 /**
1790   * @}
1791   */
1792 
1793 /**
1794   * @}
1795   */
1796 
1797 /* Private functions -----------------------------------------------------------*/
1798 /** @addtogroup ADC_Private_Functions ADC Private Functions
1799   * @{
1800   */
1801 HAL_StatusTypeDef ADC_ConversionStop(ADC_HandleTypeDef *hadc, uint32_t ConversionGroup);
1802 HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef *hadc);
1803 HAL_StatusTypeDef ADC_Disable(ADC_HandleTypeDef *hadc);
1804 void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma);
1805 void ADC_DMAHalfConvCplt(DMA_HandleTypeDef *hdma);
1806 void ADC_DMAError(DMA_HandleTypeDef *hdma);
1807 
1808 /**
1809   * @}
1810   */
1811 
1812 /**
1813   * @}
1814   */
1815 
1816 /**
1817   * @}
1818   */
1819 
1820 #ifdef __cplusplus
1821 }
1822 #endif
1823 
1824 
1825 #endif /* STM32L4xx_HAL_ADC_H */
1826 
1827 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
1828