1 /**
2   ******************************************************************************
3   * @file    stm32f3xx_hal_comp.h
4   * @author  MCD Application Team
5   * @brief   Header file of COMP HAL module.
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_HAL_COMP_H
21 #define STM32F3xx_HAL_COMP_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32f3xx_hal_def.h"
29 
30 /** @addtogroup STM32F3xx_HAL_Driver
31   * @{
32   */
33 
34 /** @addtogroup COMP
35   * @{
36   */
37 
38 /* Exported types ------------------------------------------------------------*/
39 /** @defgroup COMP_Exported_Types COMP Exported Types
40   * @{
41   */
42 /**
43   * @brief  COMP Init structure definition
44   */
45 typedef struct
46 {
47 
48   uint32_t InvertingInput;     /*!< Selects the inverting input of the comparator.
49                                     This parameter can be a value of @ref COMPEx_InvertingInput */
50 
51   uint32_t NonInvertingInput;  /*!< Selects the non inverting input of the comparator.
52                                     This parameter can be a value of @ref COMPEx_NonInvertingInput
53                                     Note: Only available on STM32F302xB/xC, STM32F303xB/xC and STM32F358xx devices */
54 
55   uint32_t Output;             /*!< Selects the output redirection of the comparator.
56                                     This parameter can be a value of @ref COMPEx_Output */
57 
58   uint32_t OutputPol;          /*!< Selects the output polarity of the comparator.
59                                     This parameter can be a value of @ref COMP_OutputPolarity */
60 
61   uint32_t Hysteresis;         /*!< Selects the hysteresis voltage of the comparator.
62                                     This parameter can be a value of @ref COMPEx_Hysteresis
63                                     Note: Only available on STM32F302xB/xC, STM32F303xB/xC, STM32F373xB/xC, STM32F358xx and STM32F378xx devices */
64 
65   uint32_t BlankingSrce;       /*!< Selects the output blanking source of the comparator.
66                                     This parameter can be a value of @ref COMPEx_BlankingSrce
67                                     Note: Not available on STM32F373xB/C and STM32F378xx devices */
68 
69   uint32_t Mode;               /*!< Selects the operating consumption mode of the comparator
70                                     to adjust the speed/consumption.
71                                     This parameter can be a value of @ref COMPEx_Mode
72                                     Note: Not available on STM32F301x6/x8, STM32F302x6/x8, STM32F334x6/x8, STM32F318xx and STM32F328xx devices */
73 
74   uint32_t WindowMode;         /*!< Selects the window mode of the comparator X (X=2U, 4 or 6 if available).
75                                     This parameter can be a value of @ref COMPEx_WindowMode */
76 
77   uint32_t TriggerMode;        /*!< Selects the trigger mode of the comparator (interrupt mode).
78                                     This parameter can be a value of @ref COMP_TriggerMode */
79 
80 } COMP_InitTypeDef;
81 
82 /**
83   * @brief  HAL State structures definition
84   */
85 typedef enum
86 {
87   HAL_COMP_STATE_RESET             = 0x00U,    /*!< COMP not yet initialized or disabled             */
88   HAL_COMP_STATE_READY             = 0x01U,    /*!< COMP initialized and ready for use               */
89   HAL_COMP_STATE_READY_LOCKED      = 0x11U,    /*!< COMP initialized but the configuration is locked */
90   HAL_COMP_STATE_BUSY              = 0x02U,    /*!< COMP is running                                  */
91   HAL_COMP_STATE_BUSY_LOCKED       = 0x12      /*!< COMP is running and the configuration is locked  */
92 } HAL_COMP_StateTypeDef;
93 
94 /**
95   * @brief  COMP Handle Structure definition
96   */
97 typedef struct __COMP_HandleTypeDef
98 {
99   COMP_TypeDef                *Instance;                          /*!< Register base address    */
100   COMP_InitTypeDef            Init;                               /*!< COMP required parameters */
101   HAL_LockTypeDef             Lock;                               /*!< Locking object           */
102   __IO HAL_COMP_StateTypeDef  State;                              /*!< COMP communication state */
103   __IO uint32_t      ErrorCode;                                   /*!< COMP Error code */
104 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
105   void (* TriggerCallback)(struct __COMP_HandleTypeDef *hcomp);   /*!< COMP trigger callback */
106   void (* MspInitCallback)(struct __COMP_HandleTypeDef *hcomp);   /*!< COMP Msp Init callback */
107   void (* MspDeInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp DeInit callback */
108 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
109 } COMP_HandleTypeDef;
110 
111 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
112 /**
113   * @brief  HAL COMP Callback ID enumeration definition
114   */
115 typedef enum
116 {
117   HAL_COMP_TRIGGER_CB_ID                = 0x00U,  /*!< COMP trigger callback ID */
118   HAL_COMP_MSPINIT_CB_ID                = 0x01U,  /*!< COMP Msp Init callback ID */
119   HAL_COMP_MSPDEINIT_CB_ID              = 0x02U   /*!< COMP Msp DeInit callback ID */
120 } HAL_COMP_CallbackIDTypeDef;
121 
122 /**
123   * @brief  HAL COMP Callback pointer definition
124   */
125 typedef  void (*pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp); /*!< pointer to a COMP callback function */
126 
127 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
128 
129 /**
130   * @}
131   */
132 
133 /* Exported constants --------------------------------------------------------*/
134 /** @defgroup COMP_Exported_Constants COMP Exported Constants
135   * @{
136   */
137 
138 /** @defgroup COMP_Error_Code COMP Error Code
139   * @{
140   */
141 #define HAL_COMP_ERROR_NONE             (0x00U)   /*!< No error */
142 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
143 #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01U)   /*!< Invalid Callback error */
144 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
145 /**
146   * @}
147   */
148 
149 /** @defgroup COMP_OutputPolarity COMP Output Polarity
150   * @{
151   */
152 #define COMP_OUTPUTPOL_NONINVERTED             (0x00000000U)  /*!< COMP output on GPIO isn't inverted */
153 #define COMP_OUTPUTPOL_INVERTED                COMP_CSR_COMPxPOL       /*!< COMP output on GPIO is inverted  */
154 /**
155   * @}
156   */
157 
158 /** @defgroup COMP_OutputLevel COMP Output Level
159   * @{
160   */
161 /* When output polarity is not inverted, comparator output is low when
162    the non-inverting input is at a lower voltage than the inverting input*/
163 #define COMP_OUTPUTLEVEL_LOW                   (0x00000000U)
164 /* When output polarity is not inverted, comparator output is high when
165    the non-inverting input is at a higher voltage than the inverting input */
166 #define COMP_OUTPUTLEVEL_HIGH                  COMP_CSR_COMPxOUT
167 /**
168   * @}
169   */
170 
171 /** @defgroup COMP_TriggerMode COMP Trigger Mode
172   * @{
173   */
174 #define COMP_TRIGGERMODE_NONE                 (0x00000000U)   /*!< No External Interrupt trigger detection */
175 #define COMP_TRIGGERMODE_IT_RISING            (0x00000001U)   /*!< External Interrupt Mode with Rising edge trigger detection */
176 #define COMP_TRIGGERMODE_IT_FALLING           (0x00000002U)   /*!< External Interrupt Mode with Falling edge trigger detection */
177 #define COMP_TRIGGERMODE_IT_RISING_FALLING    (0x00000003U)   /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
178 #define COMP_TRIGGERMODE_EVENT_RISING         (0x00000010U)   /*!< Event Mode with Rising edge trigger detection */
179 #define COMP_TRIGGERMODE_EVENT_FALLING        (0x00000020U)   /*!< Event Mode with Falling edge trigger detection */
180 #define COMP_TRIGGERMODE_EVENT_RISING_FALLING (0x00000030U)   /*!< Event Mode with Rising/Falling edge trigger detection */
181 /**
182   * @}
183   */
184 
185 /** @defgroup COMP_State_Lock COMP State Lock
186   * @{
187   */
188 #define COMP_STATE_BIT_LOCK                   (0x00000010U)   /* Lock bit in COMP handle state */
189 /**
190   * @}
191   */
192 
193 /**
194   * @}
195   */
196 
197 /* Exported macros -----------------------------------------------------------*/
198 /** @defgroup COMP_Exported_Macros COMP Exported Macros
199   * @{
200   */
201 
202 /** @brief  Reset COMP handle state.
203   * @param  __HANDLE__  COMP handle.
204   * @retval None
205   */
206 
207 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
208 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{                                                   \
209                                                      (__HANDLE__)->State = HAL_COMP_STATE_RESET;      \
210                                                      (__HANDLE__)->MspInitCallback = NULL;            \
211                                                      (__HANDLE__)->MspDeInitCallback = NULL;          \
212                                                     } while(0)
213 #else
214 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
215 #endif
216 
217 /**
218   * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE").
219   * @param __HANDLE__ COMP handle
220   * @retval None
221   */
222 #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE)
223 
224 /**
225   * @}
226   */
227 
228 /* Include COMP HAL Extended module */
229 #include "stm32f3xx_hal_comp_ex.h"
230 
231 /* Exported functions --------------------------------------------------------*/
232 /** @addtogroup COMP_Exported_Functions
233   * @{
234   */
235 /** @addtogroup COMP_Exported_Functions_Group1
236  * @{
237  */
238 /* Initialization and de-initialization functions  ****************************/
239 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
240 HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp);
241 void              HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
242 void              HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
243 
244 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
245 /* Callbacks Register/UnRegister functions  ***********************************/
246 HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID, pCOMP_CallbackTypeDef pCallback);
247 HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID);
248 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
249 
250 /**
251  * @}
252  */
253 
254 /* IO operation functions  *****************************************************/
255 /** @addtogroup COMP_Exported_Functions_Group2
256  * @{
257  */
258 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
259 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
260 HAL_StatusTypeDef HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp);
261 HAL_StatusTypeDef HAL_COMP_Stop_IT(COMP_HandleTypeDef *hcomp);
262 void              HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
263 /* Callback in Interrupt mode */
264 void              HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
265 /**
266   * @}
267   */
268 
269 /* Peripheral Control functions  ************************************************/
270 /** @addtogroup COMP_Exported_Functions_Group3
271  * @{
272  */
273 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
274 uint32_t          HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp);
275 /**
276   * @}
277   */
278 
279 /* Peripheral State functions  **************************************************/
280 /** @addtogroup COMP_Exported_Functions_Group4
281   * @{
282   */
283 HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp);
284 uint32_t              HAL_COMP_GetError(COMP_HandleTypeDef *hcomp);
285 /**
286   * @}
287   */
288 
289 /**
290   * @}
291   */
292 
293 /* Private macros ------------------------------------------------------------*/
294 /** @defgroup COMP_Private_Macros COMP Private Macros
295   * @{
296   */
297 
298 /** @defgroup COMP_IS_COMP_Definitions COMP Private macros to check input parameters
299   * @{
300   */
301 
302 #define IS_COMP_OUTPUTPOL(__POL__)  (((__POL__) == COMP_OUTPUTPOL_NONINVERTED)  || \
303                                      ((__POL__) == COMP_OUTPUTPOL_INVERTED))
304 
305 #define IS_COMP_TRIGGERMODE(__MODE__)  (((__MODE__) == COMP_TRIGGERMODE_NONE)                 || \
306                                         ((__MODE__) == COMP_TRIGGERMODE_IT_RISING)            || \
307                                         ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING)           || \
308                                         ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING)    || \
309                                         ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING)         || \
310                                         ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING)        || \
311                                         ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING))
312 
313 /**
314   * @}
315   */
316 
317 /**
318   * @}
319   */
320 
321 /**
322   * @}
323   */
324 
325 /**
326   * @}
327   */
328 
329 #ifdef __cplusplus
330 }
331 #endif
332 
333 #endif /* STM32F3xx_HAL_COMP_H */
334 
335