]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32L0/stm32l0xx_hal_adc.h
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[max/tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32L0 / stm32l0xx_hal_adc.h
1 /**
2   ******************************************************************************
3   * @file    stm32l0xx_hal_adc.h
4   * @author  MCD Application Team
5   * @version V1.2.0
6   * @date    06-February-2015
7   * @brief   This file contains all the functions prototypes for the ADC firmware 
8   *          library.
9   ******************************************************************************
10   * @attention
11   *
12   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
13   *
14   * Redistribution and use in source and binary forms, with or without modification,
15   * are permitted provided that the following conditions are met:
16   *   1. Redistributions of source code must retain the above copyright notice,
17   *      this list of conditions and the following disclaimer.
18   *   2. Redistributions in binary form must reproduce the above copyright notice,
19   *      this list of conditions and the following disclaimer in the documentation
20   *      and/or other materials provided with the distribution.
21   *   3. Neither the name of STMicroelectronics nor the names of its contributors
22   *      may be used to endorse or promote products derived from this software
23   *      without specific prior written permission.
24   *
25   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35   *
36   ******************************************************************************
37   */
38
39 /* Define to prevent recursive inclusion -------------------------------------*/
40 #ifndef __STM32L0xx_ADC_H
41 #define __STM32L0xx_ADC_H
42
43 #ifdef __cplusplus
44  extern "C" {
45 #endif
46
47 /* Includes ------------------------------------------------------------------*/
48 #include "stm32l0xx_hal_def.h"
49    
50 /** @addtogroup STM32L0xx_HAL_Driver
51   * @{
52   */
53
54 /** @addtogroup ADC
55   * @{
56   */ 
57
58 /* Exported types ------------------------------------------------------------*/   
59 /** 
60   * @brief  HAL State structures definition  
61   */ 
62 typedef enum
63 {
64   HAL_ADC_STATE_RESET                   = 0x00,    /*!< ADC not yet initialized or disabled */
65   HAL_ADC_STATE_READY                   = 0x01,    /*!< ADC peripheral ready for use */
66   HAL_ADC_STATE_BUSY                    = 0x02,    /*!< An internal process is ongoing */ 
67   HAL_ADC_STATE_BUSY_REG                = 0x12,    /*!< Regular conversion is ongoing */
68   HAL_ADC_STATE_TIMEOUT                 = 0x03,    /*!< Timeout state */
69   HAL_ADC_STATE_ERROR                   = 0x04,    /*!< ADC state error */
70   HAL_ADC_STATE_EOC                     = 0x05,    /*!< Conversion is completed */
71   HAL_ADC_STATE_AWD                     = 0x06,    /*!< ADC state analog watchdog */
72 }HAL_ADC_StateTypeDef;
73
74
75 /** 
76   * @brief  ADC Oversampler structure definition  
77   */
78 typedef struct
79 {
80   uint32_t Ratio;                         /*!< Configures the oversampling ratio.
81                                                This parameter can be a value of @ref ADC_Oversampling_Ratio */
82   uint32_t RightBitShift;                 /*!< Configures the division coefficient for the Oversampler.
83                                                This parameter can be a value of @ref ADC_Right_Bit_Shift */
84   uint32_t TriggeredMode;                 /*!< Selects the regular triggered oversampling mode
85                                                This parameter can be a value of @ref ADC_Triggered_Oversampling_Mode */
86                                         
87 }ADC_OversamplingTypeDef;
88
89 /**
90   * @brief  ADC Init structure definition  
91   * @note   The setting of these parameters with function HAL_ADC_Init() is conditioned by the ADC state.
92   *         If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed
93   *         without error reporting (as it can be the expected behaviour in case of intended action to update antother parameter (which fullfills the ADC state condition) on the fly).
94   */
95 typedef struct
96 {
97   uint32_t OversamplingMode;             /*!< Specifies whether the oversampling feature is enabled or disabled
98                                               This parameter can be set to ENABLE or DISABLE.
99                                               Note: This parameter can be modified only if there is no conversion is ongoing. */
100   ADC_OversamplingTypeDef  Oversample;   /*!< Specifies the Oversampling parameters
101                                               Note: This parameter can be modified only if there is no conversion is ongoing. */
102   uint32_t ClockPrescaler;               /*!< Selects the ADC clock frequency.
103                                               This parameter can be a value of @ref ADC_ClockPrescaler
104                                               Note: This parameter can be modified only if ADC is disabled. */
105   uint32_t Resolution;                   /*!< Configures the ADC resolution mode. 
106                                               This parameter can be a value of @ref ADC_Resolution
107                                               Note: This parameter can be modified only if ADC is disabled. */
108   uint32_t SamplingTime;                 /*!< The sample time value to be set for all channels.
109                                               This parameter can be a value of @ref ADC_sampling_times
110                                               Note: This parameter can be modified only if there is no conversion ongoing. */
111   uint32_t ScanConvMode;                  /*!< The scan sequence direction.
112                                               This parameter can be a value of @ref ADC_Scan_mode
113                                               Note: This parameter can be modified only if there is no conversion is ongoing. */
114   uint32_t DataAlign;                    /*!< Specifies whether the ADC data  alignment is left or right.  
115                                               This parameter can be a value of @ref ADC_data_align
116                                               Note: This parameter can be modified only if there is no conversion is ongoing. */
117   uint32_t ContinuousConvMode;           /*!< Specifies whether the conversion is performed in Continuous or Single mode.
118                                               This parameter can be set to ENABLE or DISABLE.
119                                               Note: This parameter can be modified only if there is no conversion is ongoing. */
120   uint32_t DiscontinuousConvMode;        /*!< Specifies whether the conversion is performed
121                                               in Complete-sequence/Discontinuous-sequence.
122                                               Discontinuous mode can be enabled only if continuous mode is disabled.
123                                               This parameter can be set to ENABLE or DISABLE.
124                                               Note: This parameter can be modified only if there is no conversion is ongoing. */
125   uint32_t ExternalTrigConvEdge;         /*!< Select the external trigger edge and enable the trigger. 
126                                               This parameter can be a value of @ref ADC_Regular_External_Trigger_Source_Edge
127                                               Note: This parameter can be modified only if there is no conversion is ongoing. */
128   uint32_t ExternalTrigConv;             /*!< Select the external event used to trigger the start of conversion.
129                                               This parameter can be a value of @ref ADC_External_trigger_Source
130                                               Note: This parameter can be modified only if there is no conversion is ongoing. */
131   uint32_t DMAContinuousRequests;        /*!< Specifies whether the DMA requests are performed in one shot mode (DMA transfer stop when number of conversions is reached)
132                                               or in Continuous mode (DMA transfer unlimited, whatever number of conversions).
133                                               Note: In continuous mode, DMA must be configured in circular mode. Otherwise an overrun will be triggered when DMA buffer max pointer is reached.
134                                               This parameter can be set to ENABLE or DISABLE.
135                                               Note: This parameter can be modified only if there is no conversion is ongoing. */
136   uint32_t EOCSelection;                 /*!< Specifies what EOC (End Of Conversion) flag is used for conversion polling and interruption:  
137                                               end of single channel conversion or end of channels conversions sequence.
138                                               This parameter can be a value of @ref ADC_EOCSelection */ 
139   uint32_t Overrun;                      /*!< Select the behaviour in case of overrun: data preserved or overwritten 
140                                               This parameter has an effect on regular channels only, including in DMA mode.
141                                               This parameter can be a value of @ref ADC_Overrun
142                                               Note: This parameter can be modified only if there is no conversion is ongoing. */
143   uint32_t LowPowerAutoWait;             /*!< Specifies the usage of dynamic low power Auto Delay: new conversion start only
144                                               when the previous conversion (for regular channel) is completed.
145                                               This avoids risk of overrun for low frequency application. 
146                                               This parameter can be set to ENABLE or DISABLE.
147                                               Note: This parameter can be modified only if there is no conversion is ongoing. */
148   uint32_t LowPowerFrequencyMode;        /*!< When selecting an analog ADC clock frequency lower than 2.8MHz,
149                                               it is mandatory to first enable the Low Frequency Mode.
150                                               This parameter can be set to ENABLE or DISABLE.
151                                               Note: This parameter can be modified only if there is no conversion is ongoing. */
152   uint32_t LowPowerAutoPowerOff;         /*!< When setting the AutoOff feature, the ADC is always powered off when not converting and automatically
153                                               wakes-up when a conversion is started (by software or hardware trigger).
154                                               This parameter can be set to ENABLE or DISABLE.
155                                               Note: This parameter can be modified only if there is no conversion is ongoing. */
156 }ADC_InitTypeDef;
157
158 /** 
159   * @brief  ADC handle Structure definition  
160   */ 
161 typedef struct __ADC_HandleTypeDef
162 {
163   ADC_TypeDef                   *Instance;              /*!< Register base address */
164
165   ADC_InitTypeDef               Init;                   /*!< ADC required parameters */
166
167   DMA_HandleTypeDef             *DMA_Handle;            /*!< Pointer DMA Handler */
168
169   HAL_LockTypeDef               Lock;                   /*!< ADC locking object */
170
171   __IO HAL_ADC_StateTypeDef     State;                  /*!< ADC communication state */
172
173   __IO uint32_t                 ErrorCode;              /*!< ADC Error code */
174 }ADC_HandleTypeDef;
175
176 /** 
177   * @brief  ADC Configuration regular Channel structure definition  
178   */ 
179 typedef struct 
180 {
181   uint32_t Channel;                /*!< the ADC channel to configure 
182                                         This parameter can be a value of @ref ADC_channels */ 
183 }ADC_ChannelConfTypeDef;
184
185
186 /** 
187   * @brief   ADC Configuration analog watchdog definition  
188   */ 
189 typedef struct
190 {
191   uint32_t WatchdogMode;      /*!< Configures the ADC analog watchdog mode: single/all channels.
192                                    This parameter can be a value of @ref ADC_analog_watchdog_mode */
193   uint32_t Channel;           /*!< Selects which ADC channel to monitor by analog watchdog.
194                                    This parameter has an effect only if watchdog mode is configured on single channel (parameter WatchdogMode)
195                                    This parameter can be a value of @ref ADC_channels */
196   uint32_t ITMode;            /*!< Specifies whether the analog watchdog is configured in interrupt or polling mode.
197                                    This parameter can be set to ENABLE or DISABLE */
198   uint32_t HighThreshold;     /*!< Configures the ADC analog watchdog High threshold value.
199                                    Depending of ADC resolution selected (12, 10, 8 or 6 bits),
200                                    this parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F respectively. */
201   uint32_t LowThreshold;      /*!< Configures the ADC analog watchdog High threshold value.
202                                    Depending of ADC resolution selected (12, 10, 8 or 6 bits),
203                                    this parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F respectively. */
204 }ADC_AnalogWDGConfTypeDef;
205
206
207 /* Exported constants --------------------------------------------------------*/
208
209 /** @defgroup ADC_Exported_Constants
210   * @{
211   */
212
213 /** @defgroup ADC_Error_Code 
214   * @{
215   */ 
216 #define HAL_ADC_ERROR_NONE        ((uint32_t)0x00)   /*!< No error           */
217 #define HAL_ADC_ERROR_INTERNAL    ((uint32_t)0x01)   /*!< ADC IP internal error: if problem of clocking, 
218                                                           enable/disable, erroneous state */
219 #define HAL_ADC_ERROR_OVR         ((uint32_t)0x02)   /*!< OVR error          */
220 #define HAL_ADC_ERROR_DMA         ((uint32_t)0x03)   /*!< DMA transfer error */
221 /**
222   * @}
223   */  
224
225 /** @defgroup ADC_TimeOut_Values
226   * @{
227   */ 
228
229   /* Fixed timeout values for ADC calibration, enable settling time, disable  */
230   /* settling time.                                                           */
231   /* Values defined to be higher than worst cases: low clocks freq,           */
232   /* maximum prescalers.                                                      */
233   /* Unit: ms                                                                 */      
234 #define ADC_ENABLE_TIMEOUT            10
235 #define ADC_DISABLE_TIMEOUT           10
236 #define ADC_STOP_CONVERSION_TIMEOUT   10
237
238   /* Delay of 10us fixed to worst case: maximum CPU frequency 180MHz to have  */
239   /* the minimum number of CPU cycles to fulfill this delay                   */
240   #define ADC_DELAY_10US_MIN_CPU_CYCLES         1800 
241 /**
242   * @}
243   */
244
245 /** @defgroup ADC_ClockPrescaler
246   * @{
247   */     
248 #define ADC_CLOCK_ASYNC_DIV1              ((uint32_t)0x00000000)                                /*!< ADC Asynchronous clock mode divided by 1 */
249 #define ADC_CLOCK_ASYNC_DIV2              (ADC_CCR_PRESC_0)                                     /*!< ADC Asynchronous clock mode divided by 2 */
250 #define ADC_CLOCK_ASYNC_DIV4              (ADC_CCR_PRESC_1)                                     /*!< ADC Asynchronous clock mode divided by 2 */
251 #define ADC_CLOCK_ASYNC_DIV6              (ADC_CCR_PRESC_1 | ADC_CCR_PRESC_0)                   /*!< ADC Asynchronous clock mode divided by 2 */
252 #define ADC_CLOCK_ASYNC_DIV8              (ADC_CCR_PRESC_2)                                     /*!< ADC Asynchronous clock mode divided by 2 */
253 #define ADC_CLOCK_ASYNC_DIV10             (ADC_CCR_PRESC_2 | ADC_CCR_PRESC_0)                   /*!< ADC Asynchronous clock mode divided by 2 */
254 #define ADC_CLOCK_ASYNC_DIV12             (ADC_CCR_PRESC_2 | ADC_CCR_PRESC_1)                   /*!< ADC Asynchronous clock mode divided by 2 */
255 #define ADC_CLOCK_ASYNC_DIV16             (ADC_CCR_PRESC_2 | ADC_CCR_PRESC_1 | ADC_CCR_PRESC_0) /*!< ADC Asynchronous clock mode divided by 2 */
256 #define ADC_CLOCK_ASYNC_DIV32             (ADC_CCR_PRESC_3)                                     /*!< ADC Asynchronous clock mode divided by 2 */
257 #define ADC_CLOCK_ASYNC_DIV64             (ADC_CCR_PRESC_3 | ADC_CCR_PRESC_0)                   /*!< ADC Asynchronous clock mode divided by 2 */
258 #define ADC_CLOCK_ASYNC_DIV128            (ADC_CCR_PRESC_3 | ADC_CCR_PRESC_1)                   /*!< ADC Asynchronous clock mode divided by 2 */
259 #define ADC_CLOCK_ASYNC_DIV256            (ADC_CCR_PRESC_3 | ADC_CCR_PRESC_1 | ADC_CCR_PRESC_0) /*!< ADC Asynchronous clock mode divided by 2 */
260
261 #define ADC_CLOCK_SYNC_PCLK_DIV1         ((uint32_t)ADC_CFGR2_CKMODE_0)  /*!< Synchronous clock mode divided by 1 
262                                                                                This configuration must be enabled only if PCLK has a 50%
263                                                                                duty clock cycle (APB prescaler configured inside the RCC must be bypassed and the system clock
264                                                                                must by 50% duty cycle)*/
265 #define ADC_CLOCK_SYNC_PCLK_DIV2          ((uint32_t)ADC_CFGR2_CKMODE_1)  /*!< Synchronous clock mode divided by 2 */
266 #define ADC_CLOCK_SYNC_PCLK_DIV4          ((uint32_t)ADC_CFGR2_CKMODE)    /*!< Synchronous clock mode divided by 4 */
267
268 #define IS_ADC_CLOCKPRESCALER(ADC_CLOCK) (((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV1) ||\
269                                           ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV1) ||\
270                                           ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV2) ||\
271                                           ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV4) ||\
272                                           ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV1  ) ||\
273                                           ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV2  ) ||\
274                                           ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV4  ) ||\
275                                           ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV6  ) ||\
276                                           ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV8  ) ||\
277                                           ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV10 ) ||\
278                                           ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV12 ) ||\
279                                           ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV16 ) ||\
280                                           ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV32 ) ||\
281                                           ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV64 ) ||\
282                                           ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV128 ) ||\
283                                           ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV256))
284 /**                                                       
285   * @}
286   */ 
287
288 /** @defgroup ADC_Resolution
289   * @{
290   */ 
291 #define ADC_RESOLUTION_12B      ((uint32_t)0x00000000)          /*!<  ADC 12-bit resolution */
292 #define ADC_RESOLUTION_10B      ((uint32_t)ADC_CFGR1_RES_0)      /*!<  ADC 10-bit resolution */
293 #define ADC_RESOLUTION_8B       ((uint32_t)ADC_CFGR1_RES_1)      /*!<  ADC 8-bit resolution */
294 #define ADC_RESOLUTION_6B       ((uint32_t)ADC_CFGR1_RES)        /*!<  ADC 6-bit resolution */
295
296 #define IS_ADC_RESOLUTION(RESOLUTION) (((RESOLUTION) == ADC_RESOLUTION_12B) || \
297                                        ((RESOLUTION) == ADC_RESOLUTION_10B) || \
298                                        ((RESOLUTION) == ADC_RESOLUTION_8B) || \
299                                        ((RESOLUTION) == ADC_RESOLUTION_6B))
300
301 #define IS_ADC_RESOLUTION_8_6_BITS(RESOLUTION) (((RESOLUTION) == ADC_RESOLUTION_8B) || \
302                                                 ((RESOLUTION) == ADC_RESOLUTION_6B))
303 /**
304   * @}
305   */ 
306
307 /** @defgroup ADC_data_align
308   * @{
309   */ 
310 #define ADC_DATAALIGN_RIGHT      ((uint32_t)0x00000000)
311 #define ADC_DATAALIGN_LEFT       ((uint32_t)ADC_CFGR1_ALIGN)
312
313 #define IS_ADC_DATA_ALIGN(ALIGN) (((ALIGN) == ADC_DATAALIGN_RIGHT) || \
314                                   ((ALIGN) == ADC_DATAALIGN_LEFT))
315 /**
316   * @}
317   */ 
318
319 /** @defgroup ADC_Regular_External_Trigger_Source_Edge ADC External Trigger Source Edge for Regular Group
320   * @{
321   */ 
322 #define ADC_EXTERNALTRIGCONVEDGE_NONE           ((uint32_t)0x00000000)
323 #define ADC_EXTERNALTRIGCONVEDGE_RISING         ((uint32_t)ADC_CFGR1_EXTEN_0)         
324 #define ADC_EXTERNALTRIGCONVEDGE_FALLING        ((uint32_t)ADC_CFGR1_EXTEN_1)
325 #define ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING  ((uint32_t)ADC_CFGR1_EXTEN)
326
327 #define IS_ADC_EXTTRIG_EDGE(EDGE) (((EDGE) == ADC_EXTERNALTRIGCONVEDGE_NONE) || \
328                                    ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISING) || \
329                                    ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_FALLING) || \
330                                    ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING))
331 /**
332   * @}
333   */ 
334
335 /** @defgroup ADC_External_trigger_Source
336   * @{
337   */
338 #define ADC_EXTERNALTRIGCONV_T6_TRGO               ((uint32_t)0x00000000)
339 #define ADC_EXTERNALTRIGCONV_T21_CC2               ADC_CFGR1_EXTSEL_0
340 #define ADC_EXTERNALTRIGCONV_T2_TRGO               ADC_CFGR1_EXTSEL_1
341 #define ADC_EXTERNALTRIGCONV_T2_CC4                ((uint32_t)0x000000C0)
342 #define ADC_EXTERNALTRIGCONV_T22_TRGO              ADC_CFGR1_EXTSEL_2
343 #define ADC_EXTERNALTRIGCONV_EXT_IT11              ADC_CFGR1_EXTSEL
344
345 #define IS_ADC_EXTERNAL_TRIG_CONV(CONV) (((CONV) == ADC_EXTERNALTRIGCONV_T6_TRGO  )  || \
346                                          ((CONV) == ADC_EXTERNALTRIGCONV_T21_CC2  )  || \
347                                          ((CONV) == ADC_EXTERNALTRIGCONV_T2_TRGO  )  || \
348                                          ((CONV) == ADC_EXTERNALTRIGCONV_T2_CC4   )  || \
349                                          ((CONV) == ADC_EXTERNALTRIGCONV_T22_TRGO )  || \
350                                          ((CONV) == ADC_EXTERNALTRIGCONV_EXT_IT11 ))
351
352 /**
353   * @}
354   */ 
355
356 /** @defgroup ADC_EOCSelection
357   * @{
358   */ 
359 #define ADC_EOC_SINGLE_CONV         ((uint32_t) ADC_ISR_EOC)
360 #define ADC_EOC_SEQ_CONV            ((uint32_t) ADC_ISR_EOS)
361 #define ADC_EOC_SINGLE_SEQ_CONV    ((uint32_t)(ADC_ISR_EOC | ADC_ISR_EOS))  /*!< reserved for future use */
362
363 #define IS_ADC_EOC_SELECTION(EOC_SELECTION) (((EOC_SELECTION) == ADC_EOC_SINGLE_CONV)   || \
364                                              ((EOC_SELECTION) == ADC_EOC_SEQ_CONV)      || \
365                                              ((EOC_SELECTION) == ADC_EOC_SINGLE_SEQ_CONV))
366 /**
367   * @}
368   */ 
369
370 /** @defgroup ADC_Overrun
371   * @{
372   */ 
373 #define ADC_OVR_DATA_PRESERVED              ((uint32_t)0x00000000)
374 #define ADC_OVR_DATA_OVERWRITTEN            ((uint32_t)ADC_CFGR1_OVRMOD)
375
376 #define IS_ADC_OVERRUN(OVR) (((OVR) == ADC_OVR_DATA_PRESERVED) || \
377                              ((OVR) == ADC_OVR_DATA_OVERWRITTEN))
378 /**
379   * @}
380   */ 
381
382 /** @defgroup ADC_channels
383   * @{
384   */
385 #define ADC_CHANNEL_0           ((uint32_t)(ADC_CHSELR_CHSEL0))
386 #define ADC_CHANNEL_1           ((uint32_t)(ADC_CHSELR_CHSEL1) | ADC_CFGR1_AWDCH_0)
387 #define ADC_CHANNEL_2           ((uint32_t)(ADC_CHSELR_CHSEL2) | ADC_CFGR1_AWDCH_1)
388 #define ADC_CHANNEL_3           ((uint32_t)(ADC_CHSELR_CHSEL3)| ADC_CFGR1_AWDCH_1 | ADC_CFGR1_AWDCH_0)
389 #define ADC_CHANNEL_4           ((uint32_t)(ADC_CHSELR_CHSEL4)| ADC_CFGR1_AWDCH_2)
390 #define ADC_CHANNEL_5           ((uint32_t)(ADC_CHSELR_CHSEL5)| ADC_CFGR1_AWDCH_2| ADC_CFGR1_AWDCH_0)
391 #define ADC_CHANNEL_6           ((uint32_t)(ADC_CHSELR_CHSEL6)| ADC_CFGR1_AWDCH_2| ADC_CFGR1_AWDCH_1)
392 #define ADC_CHANNEL_7           ((uint32_t)(ADC_CHSELR_CHSEL7)| ADC_CFGR1_AWDCH_2| ADC_CFGR1_AWDCH_1 | ADC_CFGR1_AWDCH_0)
393 #define ADC_CHANNEL_8           ((uint32_t)(ADC_CHSELR_CHSEL8)| ADC_CFGR1_AWDCH_3)
394 #define ADC_CHANNEL_9           ((uint32_t)(ADC_CHSELR_CHSEL9)| ADC_CFGR1_AWDCH_3| ADC_CFGR1_AWDCH_0)
395 #define ADC_CHANNEL_10          ((uint32_t)(ADC_CHSELR_CHSEL10)| ADC_CFGR1_AWDCH_3| ADC_CFGR1_AWDCH_1)
396 #define ADC_CHANNEL_11          ((uint32_t)(ADC_CHSELR_CHSEL11)| ADC_CFGR1_AWDCH_3| ADC_CFGR1_AWDCH_1| ADC_CFGR1_AWDCH_0)
397 #define ADC_CHANNEL_12          ((uint32_t)(ADC_CHSELR_CHSEL12)| ADC_CFGR1_AWDCH_3| ADC_CFGR1_AWDCH_2)
398 #define ADC_CHANNEL_13          ((uint32_t)(ADC_CHSELR_CHSEL13)| ADC_CFGR1_AWDCH_3| ADC_CFGR1_AWDCH_2| ADC_CFGR1_AWDCH_0)
399 #define ADC_CHANNEL_14          ((uint32_t)(ADC_CHSELR_CHSEL14)| ADC_CFGR1_AWDCH_3| ADC_CFGR1_AWDCH_2| ADC_CFGR1_AWDCH_1)
400 #define ADC_CHANNEL_15          ((uint32_t)(ADC_CHSELR_CHSEL15)| ADC_CFGR1_AWDCH_3| ADC_CFGR1_AWDCH_2| ADC_CFGR1_AWDCH_1| ADC_CFGR1_AWDCH_0)
401 #define ADC_CHANNEL_16          ((uint32_t)(ADC_CHSELR_CHSEL16)| ADC_CFGR1_AWDCH_4)
402 #define ADC_CHANNEL_17          ((uint32_t)(ADC_CHSELR_CHSEL17)| ADC_CFGR1_AWDCH_4| ADC_CFGR1_AWDCH_0)
403 #define ADC_CHANNEL_18          ((uint32_t)(ADC_CHSELR_CHSEL18)| ADC_CFGR1_AWDCH_4| ADC_CFGR1_AWDCH_1)
404
405 /* Internal channels */
406 #define ADC_CHANNEL_VLCD         ADC_CHANNEL_16    
407 #define ADC_CHANNEL_VREFINT      ADC_CHANNEL_17
408 #define ADC_CHANNEL_TEMPSENSOR   ADC_CHANNEL_18    
409
410     
411 #define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) == ADC_CHANNEL_0)           || \
412                                  ((CHANNEL) == ADC_CHANNEL_1)           || \
413                                  ((CHANNEL) == ADC_CHANNEL_2)           || \
414                                  ((CHANNEL) == ADC_CHANNEL_3)           || \
415                                  ((CHANNEL) == ADC_CHANNEL_4)           || \
416                                  ((CHANNEL) == ADC_CHANNEL_5)           || \
417                                  ((CHANNEL) == ADC_CHANNEL_6)           || \
418                                  ((CHANNEL) == ADC_CHANNEL_7)           || \
419                                  ((CHANNEL) == ADC_CHANNEL_8)           || \
420                                  ((CHANNEL) == ADC_CHANNEL_9)           || \
421                                  ((CHANNEL) == ADC_CHANNEL_10)          || \
422                                  ((CHANNEL) == ADC_CHANNEL_11)          || \
423                                  ((CHANNEL) == ADC_CHANNEL_12)          || \
424                                  ((CHANNEL) == ADC_CHANNEL_13)          || \
425                                  ((CHANNEL) == ADC_CHANNEL_14)          || \
426                                  ((CHANNEL) == ADC_CHANNEL_15)          || \
427                                  ((CHANNEL) == ADC_CHANNEL_TEMPSENSOR)  || \
428                                  ((CHANNEL) == ADC_CHANNEL_VREFINT)     || \
429                                  ((CHANNEL) == ADC_CHANNEL_VLCD))
430
431 /**
432   * @}
433   */
434
435 /** @defgroup ADC_Channel_AWD_Masks
436   * @{
437   */
438 #define ADC_CHANNEL_MASK        ((uint32_t)0x0007FFFF)
439 #define ADC_CHANNEL_AWD_MASK    ((uint32_t)0x7C000000)
440 /**
441   * @}
442   */
443
444
445 /** @defgroup ADC_sampling_times
446   * @{
447   */
448     
449 #define ADC_SAMPLETIME_1CYCLE_5       ((uint32_t)0x00000000)                          /*!<  ADC sampling time 1.5 cycle */
450 #define ADC_SAMPLETIME_7CYCLES_5      ((uint32_t)ADC_SMPR_SMPR_0)                     /*!<  ADC sampling time 7.5 CYCLES */
451 #define ADC_SAMPLETIME_13CYCLES_5     ((uint32_t)ADC_SMPR_SMPR_1)                     /*!<  ADC sampling time 13.5 CYCLES */
452 #define ADC_SAMPLETIME_28CYCLES_5     ((uint32_t)(ADC_SMPR_SMPR_1 | ADC_SMPR_SMPR_0)) /*!<  ADC sampling time 28.5 CYCLES */
453 #define ADC_SAMPLETIME_41CYCLES_5     ((uint32_t)ADC_SMPR_SMPR_2)                     /*!<  ADC sampling time 41.5 CYCLES */
454 #define ADC_SAMPLETIME_55CYCLES_5     ((uint32_t)(ADC_SMPR_SMPR_2 | ADC_SMPR_SMPR_0)) /*!<  ADC sampling time 55.5 CYCLES */
455 #define ADC_SAMPLETIME_71CYCLES_5     ((uint32_t)(ADC_SMPR_SMPR_2 | ADC_SMPR_SMPR_1)) /*!<  ADC sampling time 71.5 CYCLES */
456 #define ADC_SAMPLETIME_239CYCLES_5    ((uint32_t)ADC_SMPR_SMPR)                       /*!<  ADC sampling time 239.5 CYCLES */
457
458 #define IS_ADC_SAMPLE_TIME(TIME) (((TIME) == ADC_SAMPLETIME_1CYCLE_5   ) || \
459                                   ((TIME) == ADC_SAMPLETIME_7CYCLES_5  ) || \
460                                   ((TIME) == ADC_SAMPLETIME_13CYCLES_5 ) || \
461                                   ((TIME) == ADC_SAMPLETIME_28CYCLES_5 ) || \
462                                   ((TIME) == ADC_SAMPLETIME_41CYCLES_5 ) || \
463                                   ((TIME) == ADC_SAMPLETIME_55CYCLES_5 ) || \
464                                   ((TIME) == ADC_SAMPLETIME_71CYCLES_5 ) || \
465                                   ((TIME) == ADC_SAMPLETIME_239CYCLES_5))
466 /**
467   * @}
468   */
469
470
471 /** @defgroup ADC_Scan_mode ADC Scan mode
472   * @{
473   */
474 /* Note: Scan mode values must be compatible with other STM32 devices having  */
475 /*       a configurable sequencer.                                            */
476 /*       Scan direction setting values are defined by taking in account       */
477 /*       already defined values for other STM32 devices:                      */
478 /*         ADC_SCAN_DISABLE         ((uint32_t)0x00000000)                    */
479 /*         ADC_SCAN_ENABLE          ((uint32_t)0x00000001)                    */
480 /*       Scan direction forward is considered as default setting equivalent   */
481 /*       to scan enable.                                                      */
482 /*       Scan direction backward is considered as additional setting.         */
483 /*       In case of migration from another STM32 device, the user will be     */
484 /*       warned of change of setting choices with assert check.               */
485 #define ADC_SCAN_DIRECTION_FORWARD        ((uint32_t)0x00000001)        /*!< Scan direction forward: from channel 0 to channel 18 */
486 #define ADC_SCAN_DIRECTION_BACKWARD       ((uint32_t)0x00000002)        /*!< Scan direction backward: from channel 18 to channel 0 */
487
488 #define ADC_SCAN_ENABLE         ADC_SCAN_DIRECTION_FORWARD             /* For compatibility with other STM32 devices */
489
490 #define IS_ADC_SCAN_MODE(SCAN_MODE) (((SCAN_MODE) == ADC_SCAN_DIRECTION_FORWARD) || \
491                                      ((SCAN_MODE) == ADC_SCAN_DIRECTION_BACKWARD))
492
493 /**
494   * @}
495   */
496
497 /** @defgroup ADC_Oversampling_Ratio
498   * @{
499   */
500
501 #define ADC_OVERSAMPLING_RATIO_2                    ((uint32_t)0x00000000)  /*!<  ADC Oversampling ratio 2x */
502 #define ADC_OVERSAMPLING_RATIO_4                    ((uint32_t)0x00000004)  /*!<  ADC Oversampling ratio 4x */
503 #define ADC_OVERSAMPLING_RATIO_8                    ((uint32_t)0x00000008)  /*!<  ADC Oversampling ratio 8x */
504 #define ADC_OVERSAMPLING_RATIO_16                   ((uint32_t)0x0000000C)  /*!<  ADC Oversampling ratio 16x */
505 #define ADC_OVERSAMPLING_RATIO_32                   ((uint32_t)0x00000010)  /*!<  ADC Oversampling ratio 32x */
506 #define ADC_OVERSAMPLING_RATIO_64                   ((uint32_t)0x00000014)  /*!<  ADC Oversampling ratio 64x */
507 #define ADC_OVERSAMPLING_RATIO_128                  ((uint32_t)0x00000018)  /*!<  ADC Oversampling ratio 128x */
508 #define ADC_OVERSAMPLING_RATIO_256                  ((uint32_t)0x0000001C)  /*!<  ADC Oversampling ratio 256x */
509 #define IS_ADC_OVERSAMPLING_RATIO(RATIO)          (((RATIO) == ADC_OVERSAMPLING_RATIO_2   ) || \
510                                                    ((RATIO) == ADC_OVERSAMPLING_RATIO_4   ) || \
511                                                    ((RATIO) == ADC_OVERSAMPLING_RATIO_8   ) || \
512                                                    ((RATIO) == ADC_OVERSAMPLING_RATIO_16  ) || \
513                                                    ((RATIO) == ADC_OVERSAMPLING_RATIO_32  ) || \
514                                                    ((RATIO) == ADC_OVERSAMPLING_RATIO_64  ) || \
515                                                    ((RATIO) == ADC_OVERSAMPLING_RATIO_128 ) || \
516                                                    ((RATIO) == ADC_OVERSAMPLING_RATIO_256 ))
517 /**
518   * @}
519   */
520
521 /** @defgroup ADC_Right_Bit_Shift
522   * @{
523   */
524 #define ADC_RIGHTBITSHIFT_NONE                       ((uint32_t)0x00000000)  /*!<  ADC No bit shift for oversampling */
525 #define ADC_RIGHTBITSHIFT_1                          ((uint32_t)0x00000020)  /*!<  ADC 1 bit shift for oversampling */
526 #define ADC_RIGHTBITSHIFT_2                          ((uint32_t)0x00000040)  /*!<  ADC 2 bits shift for oversampling */
527 #define ADC_RIGHTBITSHIFT_3                          ((uint32_t)0x00000060)  /*!<  ADC 3 bits shift for oversampling */
528 #define ADC_RIGHTBITSHIFT_4                          ((uint32_t)0x00000080)  /*!<  ADC 4 bits shift for oversampling */
529 #define ADC_RIGHTBITSHIFT_5                          ((uint32_t)0x000000A0)  /*!<  ADC 5 bits shift for oversampling */
530 #define ADC_RIGHTBITSHIFT_6                          ((uint32_t)0x000000C0)  /*!<  ADC 6 bits shift for oversampling */
531 #define ADC_RIGHTBITSHIFT_7                          ((uint32_t)0x000000E0)  /*!<  ADC 7 bits shift for oversampling */
532 #define ADC_RIGHTBITSHIFT_8                          ((uint32_t)0x00000100)  /*!<  ADC 8 bits shift for oversampling */
533 #define IS_ADC_RIGHT_BIT_SHIFT(SHIFT)               (((SHIFT) == ADC_RIGHTBITSHIFT_NONE) || \
534                                                      ((SHIFT) == ADC_RIGHTBITSHIFT_1   ) || \
535                                                      ((SHIFT) == ADC_RIGHTBITSHIFT_2   ) || \
536                                                      ((SHIFT) == ADC_RIGHTBITSHIFT_3   ) || \
537                                                      ((SHIFT) == ADC_RIGHTBITSHIFT_4   ) || \
538                                                      ((SHIFT) == ADC_RIGHTBITSHIFT_5   ) || \
539                                                      ((SHIFT) == ADC_RIGHTBITSHIFT_6   ) || \
540                                                      ((SHIFT) == ADC_RIGHTBITSHIFT_7   ) || \
541                                                      ((SHIFT) == ADC_RIGHTBITSHIFT_8   ))
542 /**
543   * @}
544   */
545
546 /** @defgroup ADC_Triggered_Oversampling_Mode
547   * @{
548   */
549 #define ADC_TRIGGEREDMODE_SINGLE_TRIGGER            ((uint32_t)0x00000000)  /*!<  ADC No bit shift for oversampling */
550 #define ADC_TRIGGEREDMODE_MULTI_TRIGGER             ((uint32_t)0x00000200)  /*!<  ADC No bit shift for oversampling */
551 #define IS_ADC_TRIGGERED_OVERSAMPLING_MODE(MODE)     (((MODE) == ADC_TRIGGEREDMODE_SINGLE_TRIGGER) || \
552                                                       ((MODE) == ADC_TRIGGEREDMODE_MULTI_TRIGGER) )
553 /**
554   * @}
555   */
556
557 /** @defgroup ADC_analog_watchdog_mode
558   * @{
559   */ 
560 #define ADC_ANALOGWATCHDOG_NONE                     ((uint32_t) 0x00000000)
561 #define ADC_ANALOGWATCHDOG_SINGLE_REG               ((uint32_t)(ADC_CFGR1_AWDSGL | ADC_CFGR1_AWDEN))
562 #define ADC_ANALOGWATCHDOG_ALL_REG                  ((uint32_t) ADC_CFGR1_AWDEN)
563                                                   
564                                                   
565 #define IS_ADC_ANALOG_WATCHDOG_MODE(WATCHDOG)     (((WATCHDOG) == ADC_ANALOGWATCHDOG_NONE      )   || \
566                                                    ((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_REG)   || \
567                                                    ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_REG   ))
568 /**
569   * @}
570   */
571
572 /** @defgroup ADC_conversion_type
573   * @{
574   */ 
575 #define ADC_REGULAR_GROUP                         ((uint32_t)(ADC_FLAG_EOC | ADC_FLAG_EOS))                                              
576 #define IS_ADC_CONVERSION_GROUP(CONVERSION)   ((CONVERSION) == ADC_REGULAR_GROUP)
577 /**
578   * @}
579   */
580
581 /** @defgroup ADC_Event_type
582   * @{
583   */ 
584 #define ADC_AWD_EVENT              ((uint32_t)ADC_FLAG_AWD)
585 #define ADC_OVR_EVENT              ((uint32_t)ADC_FLAG_OVR)
586     
587 #define IS_ADC_EVENT_TYPE(EVENT) (((EVENT) == ADC_AWD_EVENT) || \
588                                   ((EVENT) == ADC_OVR_EVENT))
589 /**
590   * @}
591   */
592   
593 /** @defgroup ADC_interrupts_definition
594   * @{
595   */
596 #define ADC_IT_RDY           ADC_IER_ADRDYIE     /*!< ADC Ready (ADRDY) interrupt source */
597 #define ADC_IT_EOSMP         ADC_IER_EOSMPIE     /*!< ADC End of Sampling interrupt source */
598 #define ADC_IT_EOC           ADC_IER_EOCIE       /*!< ADC End of Regular Conversion interrupt source */
599 #define ADC_IT_EOS           ADC_IER_EOSEQIE     /*!< ADC End of Regular sequence of Conversions interrupt source */
600 #define ADC_IT_OVR           ADC_IER_OVRIE       /*!< ADC overrun interrupt source */
601 #define ADC_IT_AWD           ADC_IER_AWDIE       /*!< ADC Analog watchdog 1 interrupt source */
602 #define ADC_IT_EOCAL         ADC_IER_EOCALIE     /*!< ADC End of Calibration interrupt source */
603
604 /* Check of single flag */
605 #define IS_ADC_IT(IT) (((IT) == ADC_IT_AWD)   || ((IT) == ADC_IT_RDY) || \
606                        ((IT) == ADC_IT_EOSMP) || ((IT) == ADC_IT_EOC) || \
607                        ((IT) == ADC_IT_EOS)   || ((IT) == ADC_IT_OVR))
608 /**
609   * @}
610   */ 
611
612   
613
614 /** @defgroup ADC_flags_definition
615   * @{
616   */
617 #define ADC_FLAG_RDY           ADC_ISR_ADRDY    /*!< ADC Ready (ADRDY) flag */
618 #define ADC_FLAG_EOSMP         ADC_ISR_EOSMP    /*!< ADC End of Sampling flag */
619 #define ADC_FLAG_EOC           ADC_ISR_EOC      /*!< ADC End of Regular Conversion flag */
620 #define ADC_FLAG_EOS           ADC_ISR_EOSEQ    /*!< ADC End of Regular sequence of Conversions flag */
621 #define ADC_FLAG_OVR           ADC_ISR_OVR      /*!< ADC overrun flag */
622 #define ADC_FLAG_AWD           ADC_ISR_AWD      /*!< ADC Analog watchdog flag */
623 #define ADC_FLAG_EOCAL         ADC_ISR_EOCAL    /*!< ADC Enf Of Calibration flag */
624
625
626 #define ADC_FLAG_ALL    (ADC_FLAG_RDY | ADC_FLAG_EOSMP | ADC_FLAG_EOC | ADC_FLAG_EOS |  \
627                          ADC_FLAG_OVR | ADC_FLAG_AWD   | ADC_FLAG_EOCAL)
628
629 /* Check of single flag */
630 #define IS_ADC_FLAG(FLAG) (((FLAG) == ADC_FLAG_RDY)  || ((FLAG) == ADC_FLAG_EOSMP) || \
631                            ((FLAG) == ADC_FLAG_EOC)  || ((FLAG) == ADC_FLAG_EOS)   || \
632                            ((FLAG) == ADC_FLAG_OVR)  || ((FLAG) == ADC_FLAG_AWD)   || \
633                            ((FLAG) == ADC_FLAG_EOCAL))
634 /**
635   * @}
636   */
637
638
639 /** @defgroup ADC_range_verification
640   * in function of ADC resolution selected (12, 10, 8 or 6 bits)
641   * @{
642   */ 
643 #define IS_ADC_RANGE(RESOLUTION, ADC_VALUE)                                     \
644    ((((RESOLUTION) == ADC_RESOLUTION_12B) && ((ADC_VALUE) <= ((uint32_t)0x0FFF))) || \
645     (((RESOLUTION) == ADC_RESOLUTION_10B) && ((ADC_VALUE) <= ((uint32_t)0x03FF))) || \
646     (((RESOLUTION) == ADC_RESOLUTION_8B)  && ((ADC_VALUE) <= ((uint32_t)0x00FF))) || \
647     (((RESOLUTION) == ADC_RESOLUTION_6B)  && ((ADC_VALUE) <= ((uint32_t)0x003F))))
648 /**
649   * @}
650   */ 
651
652 /** @defgroup ADC_regular_nb_conv_verification
653   * @{
654   */ 
655 #define IS_ADC_REGULAR_NB_CONV(LENGTH) (((LENGTH) >= ((uint32_t)1)) && ((LENGTH) <= ((uint32_t)16)))
656 /**
657   * @}
658   */
659
660 /**
661   * @}
662   */
663 /* Exported macro ------------------------------------------------------------*/
664      
665 /** @defgroup ADC_Exported_Macro
666   * @{
667   */
668 /** @brief Reset ADC handle state
669   * @param  __HANDLE__: ADC handle
670   * @retval None
671   */
672 #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_ADC_STATE_RESET)
673
674 /**
675   * @brief Enable the ADC peripheral
676   * @param __HANDLE__: ADC handle
677   * @retval None
678   */
679 #define __HAL_ADC_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= ADC_CR_ADEN)
680
681 /**
682   * @brief Verification of hardware constraints before ADC can be enabled
683   * @param __HANDLE__: ADC handle
684   * @retval SET (ADC can be enabled) or RESET (ADC cannot be enabled)
685   */
686 #define ADC_ENABLING_CONDITIONS(__HANDLE__)           \
687        (( ( ((__HANDLE__)->Instance->CR) &                  \
688             (ADC_CR_ADCAL | ADC_CR_ADSTP | ADC_CR_ADSTART | \
689              ADC_CR_ADDIS | ADC_CR_ADEN )                   \
690            ) == RESET                                       \
691         ) ? SET : RESET)
692
693 /**
694   * @brief Disable the ADC peripheral
695   * @param __HANDLE__: ADC handle
696   * @retval None
697   */
698 #define __HAL_ADC_DISABLE(__HANDLE__)                                          \
699   do{                                                                          \
700          (__HANDLE__)->Instance->CR |= ADC_CR_ADDIS;                           \
701           __HAL_ADC_CLEAR_FLAG((__HANDLE__), (ADC_FLAG_EOSMP | ADC_FLAG_RDY)); \
702   } while(0)
703     
704 /**
705   * @brief Verification of hardware constraints before ADC can be disabled
706   * @param __HANDLE__: ADC handle
707   * @retval SET (ADC can be disabled) or RESET (ADC cannot be disabled)
708   */
709 #define ADC_DISABLING_CONDITIONS(__HANDLE__)                             \
710        (( ( ((__HANDLE__)->Instance->CR) &                                     \
711             (ADC_CR_ADSTART | ADC_CR_ADEN)) == ADC_CR_ADEN   \
712         ) ? SET : RESET)
713          
714 /**
715   * @brief Verification of ADC state: enabled or disabled
716   * @param __HANDLE__: ADC handle
717   * @retval SET (ADC enabled) or RESET (ADC disabled)
718   */
719 #define ADC_IS_ENABLE(__HANDLE__)                                                    \
720        (( ((((__HANDLE__)->Instance->CR) & (ADC_CR_ADEN | ADC_CR_ADDIS)) == ADC_CR_ADEN) && \
721           ((((__HANDLE__)->Instance->ISR) & ADC_FLAG_RDY) == ADC_FLAG_RDY)                  \
722         ) ? SET : RESET)
723          
724 /**
725   * @brief Returns resolution bits in CFGR register: RES[1:0]. Return value among parameter to @ref ADC_Resolution.
726   * @param __HANDLE__: ADC handle
727   * @retval None
728   */
729 #define ADC_GET_RESOLUTION(__HANDLE__) (((__HANDLE__)->Instance->CFGR1) & ADC_CFGR1_RES)
730
731 /**
732   * @brief Check if no conversion is ongoing on regular groups
733   * @param __HANDLE__: ADC handle
734   * @retval SET (conversion is on going) or RESET (no conversion is on going)
735   */
736 #define ADC_IS_CONVERSION_ONGOING(__HANDLE__) \
737        (( (((__HANDLE__)->Instance->CR) & (ADC_CR_ADSTART)) == RESET ) ? RESET : SET)
738  
739 /**
740   * @brief Enable ADC continuous conversion mode.
741   * @param _CONTINUOUS_MODE_: Continuous mode.
742   * @retval None
743   */
744 #define ADC_CONTINUOUS(_CONTINUOUS_MODE_) ((_CONTINUOUS_MODE_) << 13)
745
746 /**
747   * @brief Enable ADC scan mode to convert multiple ranks with sequencer.
748   * @param _SCAN_MODE_: Scan conversion mode.
749   * @retval None
750   */
751 #define ADC_SCANDIR(_SCAN_MODE_)                                   \
752   ( ( (_SCAN_MODE_) == (ADC_SCAN_DIRECTION_BACKWARD)                           \
753     )? (ADC_CFGR1_SCANDIR) : (0x00000000)                                      \
754   )
755
756 /**
757   * @brief Configures the number of discontinuous conversions for the regular group channels.
758   * @param _NBR_DISCONTINUOUS_CONV_: Number of discontinuous conversions.
759   * @retval None
760   */
761 #define __HAL_ADC_CFGR1_DISCONTINUOUS_NUM(_NBR_DISCONTINUOUS_CONV_) (((_NBR_DISCONTINUOUS_CONV_) - 1) << 17)
762
763 /**
764   * @brief Enable the ADC DMA continuous request.
765   * @param _DMAContReq_MODE_: DMA continuous request mode.
766   * @retval None
767   */
768 #define ADC_DMACONTREQ(_DMAContReq_MODE_) ((_DMAContReq_MODE_) << 1)
769
770 /**
771   * @brief Enable the ADC Auto Delay.
772   * @param _AutoDelay_: Auto delay bit enable or disable.
773   * @retval None
774   */
775 #define __HAL_ADC_CFGR1_AutoDelay(_AutoDelay_) ((_AutoDelay_) << 14)
776
777 /**
778   * @brief Enable the ADC LowPowerAutoPowerOff.
779   * @param _AUTOFF_: AutoOff bit enable or disable.
780   * @retval None
781   */
782 #define __HAL_ADC_CFGR1_AUTOFF(_AUTOFF_) ((_AUTOFF_) << 15)
783           
784 /**
785   * @brief Configure the analog watchdog high threshold into registers TR1, TR2 or TR3.
786   * @param _Threshold_: Threshold value
787   * @retval None
788   */
789 #define ADC_TRX_HIGHTHRESHOLD(_Threshold_) ((_Threshold_) << 16)
790
791           /**
792   * @brief Enable the ADC Low Frequency mode.
793   * @param _LOW_FREQUENCY_MODE_: Low Frequency mode.
794   * @retval None
795   */
796 #define __HAL_ADC_CCR_LOWFREQUENCY(_LOW_FREQUENCY_MODE_) ((_LOW_FREQUENCY_MODE_) << 25)
797     
798 /**
799   * @brief Shift the offset in function of the selected ADC resolution. 
800   *        Offset has to be left-aligned on bit 11, the LSB (right bits) are set to 0
801   *        If resolution 12 bits, no shift.
802   *        If resolution 10 bits, shift of 2 ranks on the right.
803   *        If resolution 8 bits, shift of 4 ranks on the right.
804   *        If resolution 6 bits, shift of 6 ranks on the right.
805   *        therefore, shift = (12 - resolution) = 12 - (12- (((RES[1:0]) >> 3)*2))
806   * @param __HANDLE__: ADC handle.
807   * @param _Offset_: Value to be shifted
808   * @retval None
809   */
810 #define ADC_OFFSET_SHIFT_RESOLUTION(__HANDLE__, _Offset_) \
811         ((_Offset_) << ((((__HANDLE__)->Instance->CFGR & ADC_CFGR1_RES) >> 3)*2))
812
813 /**
814   * @brief Shift the AWD1 threshold in function of the selected ADC resolution.
815   *        Thresholds have to be left-aligned on bit 11, the LSB (right bits) are set to 0
816   *        If resolution 12 bits, no shift.
817   *        If resolution 10 bits, shift of 2 ranks on the right.
818   *        If resolution 8 bits, shift of 4 ranks on the right.
819   *        If resolution 6 bits, shift of 6 ranks on the right.
820   *        therefore, shift = (12 - resolution) = 12 - (12- (((RES[1:0]) >> 3)*2))
821   * @param __HANDLE__: ADC handle.
822   * @param _Threshold_: Value to be shifted
823   * @retval None
824   */
825 #define ADC_AWD1THRESHOLD_SHIFT_RESOLUTION(__HANDLE__, _Threshold_) \
826         ((_Threshold_) << ((((__HANDLE__)->Instance->CFGR1 & ADC_CFGR1_RES) >> 3)*2))
827        
828 /**
829   * @brief Shift the value on the left, less significant are set to 0. 
830   * @param _Value_: Value to be shifted
831   * @param _Shift_: Number of shift to be done
832   * @retval None
833   */
834 #define __HAL_ADC_Value_Shift_left(_Value_, _Shift_) ((_Value_) << (_Shift_))
835
836
837 /**
838   * @brief Enable the ADC end of conversion interrupt.
839   * @param __HANDLE__: ADC handle.
840   * @param __INTERRUPT__: ADC Interrupt.
841   * @retval None
842   */
843 #define __HAL_ADC_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) |= (__INTERRUPT__))
844
845 /**
846   * @brief Disable the ADC end of conversion interrupt.
847   * @param __HANDLE__: ADC handle.
848   * @param __INTERRUPT__: ADC interrupt.
849   * @retval None
850   */
851 #define __HAL_ADC_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) &= ~(__INTERRUPT__))
852
853 /** @brief  Checks if the specified ADC interrupt source is enabled or disabled.
854   * @param __HANDLE__: specifies the ADC Handle.
855   * @param __INTERRUPT__: specifies the ADC interrupt source to check.
856   * @retval The new state of __IT__ (TRUE or FALSE).
857   */
858 #define __HAL_ADC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
859
860 /**
861   * @brief Clear the ADC's pending flags
862   * @param __HANDLE__: ADC handle.
863   * @param __FLAG__: ADC flag.
864   * @retval None
865   */
866 /* Note: bit cleared bit by writing 1 */
867 #define __HAL_ADC_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR) = (__FLAG__))
868
869 /**
870   * @brief Get the selected ADC's flag status.
871   * @param __HANDLE__: ADC handle.
872   * @param __FLAG__: ADC flag.
873   * @retval None
874   */
875 #define __HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->ISR) & (__FLAG__)) == (__FLAG__))
876
877     
878    
879 /**
880   * @brief Configuration of ADC clock & prescaler: clock source PCLK or Asynchronous with selectable prescaler
881   * @param __HANDLE__: ADC handle
882   * @retval None
883   */
884
885 #define __HAL_ADC_CLOCK_PRESCALER(__HANDLE__)                                       \
886   do{                                                                               \
887       if ((((__HANDLE__)->Init.ClockPrescaler) == ADC_CLOCK_SYNC_PCLK_DIV1) ||  \
888           (((__HANDLE__)->Init.ClockPrescaler) == ADC_CLOCK_SYNC_PCLK_DIV2) ||  \
889           (((__HANDLE__)->Init.ClockPrescaler) == ADC_CLOCK_SYNC_PCLK_DIV4))    \
890       {                                                                             \
891         (__HANDLE__)->Instance->CFGR2 &= ~(ADC_CFGR2_CKMODE);                       \
892         (__HANDLE__)->Instance->CFGR2 |=  (__HANDLE__)->Init.ClockPrescaler;        \
893       }                                                                             \
894       else                                                                          \
895       {                                                                             \
896         /* CKMOD bits must be reset */                                              \
897         (__HANDLE__)->Instance->CFGR2 &= ~(ADC_CFGR2_CKMODE);                       \
898         ADC->CCR &= ~(ADC_CCR_PRESC);                                               \
899         ADC->CCR |=  (__HANDLE__)->Init.ClockPrescaler;                             \
900       }                                                                             \
901   } while(0)
902
903  /**
904   * @}
905   */
906          
907 /* Include ADC HAL Extension module */
908 #include "stm32l0xx_hal_adc_ex.h"
909     
910 /* Exported functions --------------------------------------------------------*/  
911 /* Initialization and de-initialization functions  **********************************/
912 HAL_StatusTypeDef    HAL_ADC_Init(ADC_HandleTypeDef* hadc);
913 HAL_StatusTypeDef    HAL_ADC_DeInit(ADC_HandleTypeDef *hadc);
914 void                 HAL_ADC_MspInit(ADC_HandleTypeDef* hadc);
915 void                 HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc);
916
917 /* IO operation functions  *****************************************************/
918 /* Blocking mode: Polling */
919 HAL_StatusTypeDef    HAL_ADC_Start(ADC_HandleTypeDef* hadc);
920 HAL_StatusTypeDef    HAL_ADC_Stop(ADC_HandleTypeDef* hadc);
921 HAL_StatusTypeDef    HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout);                 
922 HAL_StatusTypeDef    HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout);
923                      
924 /* Non-blocking mode: Interruption */
925 HAL_StatusTypeDef    HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc);
926 HAL_StatusTypeDef    HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc);
927                      
928 /* Non-blocking mode: DMA */
929 HAL_StatusTypeDef    HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length);
930 HAL_StatusTypeDef    HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc);
931                      
932 /* ADC retrieve conversion value intended to be used with polling or interruption */
933 uint32_t             HAL_ADC_GetValue(ADC_HandleTypeDef* hadc);
934                      
935 /* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption and DMA) */
936 void                    HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc);
937 void                 HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc);
938 void                 HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc);
939 void                 HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc);
940 void                 HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc);
941
942 /* Peripheral Control functions ***********************************************/
943 HAL_StatusTypeDef    HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig);
944 HAL_StatusTypeDef    HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig);
945
946 /* Peripheral State functions *************************************************/
947 HAL_ADC_StateTypeDef HAL_ADC_GetState(ADC_HandleTypeDef* hadc);
948 uint32_t             HAL_ADC_GetError(ADC_HandleTypeDef *hadc);
949
950
951 /**
952   * @}
953   */ 
954
955 /**
956   * @}
957   */
958
959 #ifdef __cplusplus
960 }
961 #endif
962
963 #endif /*__STM32L0xx_ADC_H */
964
965
966 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/