1 /**
2   ******************************************************************************
3   * @file    stm32f3xx_hal_adc.h
4   * @author  MCD Application Team
5   * @brief   Header file containing functions prototypes of ADC HAL library.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2016 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef __STM32F3xx_ADC_H
21 #define __STM32F3xx_ADC_H
22 
23 #ifdef __cplusplus
24  extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32f3xx_hal_def.h"
29 
30 /* Include ADC HAL Extended module */
31 /* (include on top of file since ADC structures are defined in extended file) */
32 #include "stm32f3xx_hal_adc_ex.h"
33 
34 /** @addtogroup STM32F3xx_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   * @brief  HAL ADC state machine: ADC states definition (bitfields)
48   * @note   ADC state machine is managed by bitfields, state must be compared
49   *         with bit by bit.
50   *         For example:
51   *           " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_REG_BUSY)) "
52   *           " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_AWD1)    ) "
53   */
54 /* States of ADC global scope */
55 #define HAL_ADC_STATE_RESET             (0x00000000U)    /*!< ADC not yet initialized or disabled */
56 #define HAL_ADC_STATE_READY             (0x00000001U)    /*!< ADC peripheral ready for use */
57 #define HAL_ADC_STATE_BUSY_INTERNAL     (0x00000002U)    /*!< ADC is busy to internal process (initialization, calibration) */
58 #define HAL_ADC_STATE_TIMEOUT           (0x00000004U)    /*!< TimeOut occurrence */
59 
60 /* States of ADC errors */
61 #define HAL_ADC_STATE_ERROR_INTERNAL    (0x00000010U)    /*!< Internal error occurrence */
62 #define HAL_ADC_STATE_ERROR_CONFIG      (0x00000020U)    /*!< Configuration error occurrence */
63 #define HAL_ADC_STATE_ERROR_DMA         (0x00000040U)    /*!< DMA error occurrence */
64 
65 /* States of ADC group regular */
66 #define HAL_ADC_STATE_REG_BUSY          (0x00000100U)    /*!< A conversion on group regular is ongoing or can occur (either by continuous mode,
67                                                                        external trigger, low power auto power-on, multimode ADC master control) */
68 #define HAL_ADC_STATE_REG_EOC           (0x00000200U)    /*!< Conversion data available on group regular */
69 #define HAL_ADC_STATE_REG_OVR           (0x00000400U)    /*!< Overrun occurrence */
70 #define HAL_ADC_STATE_REG_EOSMP         (0x00000800U)    /*!< End Of Sampling flag raised  */
71 
72 /* States of ADC group injected */
73 #define HAL_ADC_STATE_INJ_BUSY          (0x00001000U)    /*!< A conversion on group injected is ongoing or can occur (either by auto-injection mode,
74                                                                        external trigger, low power auto power-on, multimode ADC master control) */
75 #define HAL_ADC_STATE_INJ_EOC           (0x00002000U)    /*!< Conversion data available on group injected */
76 #define HAL_ADC_STATE_INJ_JQOVF         (0x00004000U)    /*!< Injected queue overflow occurrence */
77 
78 /* States of ADC analog watchdogs */
79 #define HAL_ADC_STATE_AWD1              (0x00010000U)    /*!< Out-of-window occurrence of analog watchdog 1 */
80 #define HAL_ADC_STATE_AWD2              (0x00020000U)    /*!< Out-of-window occurrence of analog watchdog 2 */
81 #define HAL_ADC_STATE_AWD3              (0x00040000U)    /*!< Out-of-window occurrence of analog watchdog 3 */
82 
83 /* States of ADC multi-mode */
84 #define HAL_ADC_STATE_MULTIMODE_SLAVE   (0x00100000U)    /*!< ADC in multimode slave state, controlled by another ADC master ( */
85 
86 
87 /**
88   * @brief  ADC handle Structure definition
89   */
90 typedef struct __ADC_HandleTypeDef
91 {
92   ADC_TypeDef                   *Instance;              /*!< Register base address */
93 
94   ADC_InitTypeDef               Init;                   /*!< ADC required parameters */
95 
96   DMA_HandleTypeDef             *DMA_Handle;            /*!< Pointer DMA Handler */
97 
98   HAL_LockTypeDef               Lock;                   /*!< ADC locking object */
99 
100   __IO uint32_t                 State;                  /*!< ADC communication state (bitmap of ADC states) */
101 
102   __IO uint32_t                 ErrorCode;              /*!< ADC Error code */
103 
104 #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \
105     defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \
106     defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \
107     defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
108   ADC_InjectionConfigTypeDef    InjectionConfig ;       /*!< ADC injected channel configuration build-up structure */
109 #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */
110        /* STM32F302xC || STM32F303xC || STM32F358xx || */
111        /* STM32F303x8 || STM32F334x8 || STM32F328xx || */
112        /* STM32F301x8 || STM32F302x8 || STM32F318xx    */
113 
114 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
115   void (* ConvCpltCallback)(struct __ADC_HandleTypeDef *hadc);              /*!< ADC conversion complete callback */
116   void (* ConvHalfCpltCallback)(struct __ADC_HandleTypeDef *hadc);          /*!< ADC conversion DMA half-transfer callback */
117   void (* LevelOutOfWindowCallback)(struct __ADC_HandleTypeDef *hadc);      /*!< ADC analog watchdog 1 callback */
118   void (* ErrorCallback)(struct __ADC_HandleTypeDef *hadc);                 /*!< ADC error callback */
119   void (* InjectedConvCpltCallback)(struct __ADC_HandleTypeDef *hadc);      /*!< ADC group injected conversion complete callback */       /*!< ADC end of sampling callback */
120   void (* MspInitCallback)(struct __ADC_HandleTypeDef *hadc);               /*!< ADC Msp Init callback */
121   void (* MspDeInitCallback)(struct __ADC_HandleTypeDef *hadc);             /*!< ADC Msp DeInit callback */
122 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
123 }ADC_HandleTypeDef;
124 
125 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
126 /**
127   * @brief  HAL ADC Callback ID enumeration definition
128   */
129 typedef enum
130 {
131   HAL_ADC_CONVERSION_COMPLETE_CB_ID     = 0x00U,  /*!< ADC conversion complete callback ID */
132   HAL_ADC_CONVERSION_HALF_CB_ID         = 0x01U,  /*!< ADC conversion DMA half-transfer callback ID */
133   HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID   = 0x02U,  /*!< ADC analog watchdog 1 callback ID */
134   HAL_ADC_ERROR_CB_ID                   = 0x03U,  /*!< ADC error callback ID */
135   HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID = 0x04U,  /*!< ADC group injected conversion complete callback ID */
136   HAL_ADC_MSPINIT_CB_ID                 = 0x09U,  /*!< ADC Msp Init callback ID          */
137   HAL_ADC_MSPDEINIT_CB_ID               = 0x0AU   /*!< ADC Msp DeInit callback ID        */
138 } HAL_ADC_CallbackIDTypeDef;
139 
140 /**
141   * @brief  HAL ADC Callback pointer definition
142   */
143 typedef  void (*pADC_CallbackTypeDef)(ADC_HandleTypeDef *hadc); /*!< pointer to a ADC callback function */
144 
145 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
146 
147 /**
148   * @}
149   */
150 
151 /* Exported constants --------------------------------------------------------*/
152 /* Exported macros -----------------------------------------------------------*/
153 
154 /** @defgroup ADC_Exported_Macro ADC Exported Macros
155   * @{
156   */
157 /** @brief  Reset ADC handle state
158   * @param  __HANDLE__ ADC handle
159   * @retval None
160   */
161 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
162 #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__)                               \
163   do{                                                                          \
164      (__HANDLE__)->State = HAL_ADC_STATE_RESET;                                \
165      (__HANDLE__)->MspInitCallback = NULL;                                     \
166      (__HANDLE__)->MspDeInitCallback = NULL;                                   \
167     } while(0)
168 #else
169 #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__)                               \
170   ((__HANDLE__)->State = HAL_ADC_STATE_RESET)
171 #endif
172 
173 /**
174   * @}
175   */
176 
177 
178 
179 /* Exported functions --------------------------------------------------------*/
180 /** @addtogroup ADC_Exported_Functions ADC Exported Functions
181   * @{
182   */
183 
184 /** @addtogroup ADC_Exported_Functions_Group1 Initialization and de-initialization functions
185  * @{
186  */
187 /* Initialization and de-initialization functions  **********************************/
188 HAL_StatusTypeDef       HAL_ADC_Init(ADC_HandleTypeDef* hadc);
189 HAL_StatusTypeDef       HAL_ADC_DeInit(ADC_HandleTypeDef *hadc);
190 void                    HAL_ADC_MspInit(ADC_HandleTypeDef* hadc);
191 void                    HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc);
192 
193 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
194 /* Callbacks Register/UnRegister functions  ***********************************/
195 HAL_StatusTypeDef HAL_ADC_RegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID, pADC_CallbackTypeDef pCallback);
196 HAL_StatusTypeDef HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID);
197 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
198 /**
199   * @}
200   */
201 
202 /** @addtogroup ADC_Exported_Functions_Group2 Input and Output operation functions
203  * @{
204  */
205 /* Blocking mode: Polling */
206 HAL_StatusTypeDef       HAL_ADC_Start(ADC_HandleTypeDef* hadc);
207 HAL_StatusTypeDef       HAL_ADC_Stop(ADC_HandleTypeDef* hadc);
208 HAL_StatusTypeDef       HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout);
209 HAL_StatusTypeDef       HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout);
210 
211 /* Non-blocking mode: Interruption */
212 HAL_StatusTypeDef       HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc);
213 HAL_StatusTypeDef       HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc);
214 
215 /* Non-blocking mode: DMA */
216 HAL_StatusTypeDef       HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length);
217 HAL_StatusTypeDef       HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc);
218 
219 /* ADC retrieve conversion value intended to be used with polling or interruption */
220 uint32_t                HAL_ADC_GetValue(ADC_HandleTypeDef* hadc);
221 
222 /* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption and DMA) */
223 void                    HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc);
224 void                    HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc);
225 void                    HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc);
226 void                    HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc);
227 void                    HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc);
228 /**
229   * @}
230   */
231 
232 /** @addtogroup ADC_Exported_Functions_Group3 Peripheral Control functions
233  * @{
234  */
235 /* Peripheral Control functions ***********************************************/
236 HAL_StatusTypeDef       HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig);
237 HAL_StatusTypeDef       HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig);
238 /**
239   * @}
240   */
241 
242 /** @defgroup ADC_Exported_Functions_Group4 Peripheral State functions
243  *  @brief   ADC Peripheral State functions
244  * @{
245  */
246 /* Peripheral State functions *************************************************/
247 uint32_t                HAL_ADC_GetState(ADC_HandleTypeDef* hadc);
248 uint32_t                HAL_ADC_GetError(ADC_HandleTypeDef *hadc);
249 /**
250   * @}
251   */
252 
253 /**
254   * @}
255   */
256 
257 /**
258   * @}
259   */
260 
261 /**
262   * @}
263   */
264 
265 #ifdef __cplusplus
266 }
267 #endif
268 
269 #endif /*__STM32F3xx_ADC_H */
270 
271