2 ******************************************************************************
3 * @file stm32f0xx_hal_comp.h
4 * @author MCD Application Team
6 * @date 11-December-2014
7 * @brief Header file of COMP HAL module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F0xx_HAL_COMP_H
40 #define __STM32F0xx_HAL_COMP_H
46 #if defined(STM32F051x8) || defined(STM32F058xx) || \
47 defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
48 defined(STM32F091xC) || defined(STM32F098xx)
50 /* Includes ------------------------------------------------------------------*/
51 #include "stm32f0xx_hal_def.h"
53 /** @addtogroup STM32F0xx_HAL_Driver
57 /** @addtogroup COMP COMP HAL Module Driver
61 /* Exported types ------------------------------------------------------------*/
62 /** @defgroup COMP_Exported_Types COMP Exported Types
67 * @brief COMP Init structure definition
72 uint32_t InvertingInput; /*!< Selects the inverting input of the comparator.
73 This parameter can be a value of @ref COMP_InvertingInput */
75 uint32_t NonInvertingInput; /*!< Selects the non inverting input of the comparator.
76 This parameter can be a value of @ref COMP_NonInvertingInput */
78 uint32_t Output; /*!< Selects the output redirection of the comparator.
79 This parameter can be a value of @ref COMP_Output */
81 uint32_t OutputPol; /*!< Selects the output polarity of the comparator.
82 This parameter can be a value of @ref COMP_OutputPolarity */
84 uint32_t Hysteresis; /*!< Selects the hysteresis voltage of the comparator.
85 This parameter can be a value of @ref COMP_Hysteresis */
87 uint32_t Mode; /*!< Selects the operating comsumption mode of the comparator
88 to adjust the speed/consumption.
89 This parameter can be a value of @ref COMP_Mode */
91 uint32_t WindowMode; /*!< Selects the window mode of the comparator 1 & 2.
92 This parameter can be a value of @ref COMP_WindowMode */
94 uint32_t TriggerMode; /*!< Selects the trigger mode of the comparator (interrupt mode).
95 This parameter can be a value of @ref COMP_TriggerMode */
100 * @brief COMP Handle Structure definition
104 COMP_TypeDef *Instance; /*!< Register base address */
105 COMP_InitTypeDef Init; /*!< COMP required parameters */
106 HAL_LockTypeDef Lock; /*!< Locking object */
107 __IO uint32_t State; /*!< COMP communication state
108 This parameter can be a value of @ref COMP_State */
115 /* Exported constants --------------------------------------------------------*/
116 /** @defgroup COMP_Exported_Constants COMP Exported Constants
120 /** @defgroup COMP_State COMP State
123 #define HAL_COMP_STATE_RESET ((uint32_t)0x00000000) /*!< COMP not yet initialized or disabled */
124 #define HAL_COMP_STATE_READY ((uint32_t)0x00000001) /*!< COMP initialized and ready for use */
125 #define HAL_COMP_STATE_READY_LOCKED ((uint32_t)0x00000011) /*!< COMP initialized but the configuration is locked */
126 #define HAL_COMP_STATE_BUSY ((uint32_t)0x00000002) /*!< COMP is running */
127 #define HAL_COMP_STATE_BUSY_LOCKED ((uint32_t)0x00000012) /*!< COMP is running and the configuration is locked */
132 /** @defgroup COMP_OutputPolarity COMP OutputPolarity
135 #define COMP_OUTPUTPOL_NONINVERTED ((uint32_t)0x00000000) /*!< COMP output on GPIO isn't inverted */
136 #define COMP_OUTPUTPOL_INVERTED COMP_CSR_COMP1POL /*!< COMP output on GPIO is inverted */
138 #define IS_COMP_OUTPUTPOL(POL) (((POL) == COMP_OUTPUTPOL_NONINVERTED) || \
139 ((POL) == COMP_OUTPUTPOL_INVERTED))
144 /** @defgroup COMP_Hysteresis COMP Hysteresis
147 #define COMP_HYSTERESIS_NONE ((uint32_t)0x00000000) /*!< No hysteresis */
148 #define COMP_HYSTERESIS_LOW COMP_CSR_COMP1HYST_0 /*!< Hysteresis level low */
149 #define COMP_HYSTERESIS_MEDIUM COMP_CSR_COMP1HYST_1 /*!< Hysteresis level medium */
150 #define COMP_HYSTERESIS_HIGH COMP_CSR_COMP1HYST /*!< Hysteresis level high */
152 #define IS_COMP_HYSTERESIS(HYSTERESIS) (((HYSTERESIS) == COMP_HYSTERESIS_NONE) || \
153 ((HYSTERESIS) == COMP_HYSTERESIS_LOW) || \
154 ((HYSTERESIS) == COMP_HYSTERESIS_MEDIUM) || \
155 ((HYSTERESIS) == COMP_HYSTERESIS_HIGH))
160 /** @defgroup COMP_Mode COMP Mode
163 /* Please refer to the electrical characteristics in the device datasheet for
164 the power consumption values */
165 #define COMP_MODE_HIGHSPEED ((uint32_t)0x00000000) /*!< High Speed */
166 #define COMP_MODE_MEDIUMSPEED COMP_CSR_COMP1MODE_0 /*!< Medium Speed */
167 #define COMP_MODE_LOWPOWER COMP_CSR_COMP1MODE_1 /*!< Low power mode */
168 #define COMP_MODE_ULTRALOWPOWER COMP_CSR_COMP1MODE /*!< Ultra-low power mode */
170 #define IS_COMP_MODE(MODE) (((MODE) == COMP_MODE_HIGHSPEED) || \
171 ((MODE) == COMP_MODE_MEDIUMSPEED) || \
172 ((MODE) == COMP_MODE_LOWPOWER) || \
173 ((MODE) == COMP_MODE_ULTRALOWPOWER))
179 /** @defgroup COMP_InvertingInput COMP InvertingInput
183 #define COMP_INVERTINGINPUT_1_4VREFINT ((uint32_t)0x00000000) /*!< 1/4 VREFINT connected to comparator inverting input */
184 #define COMP_INVERTINGINPUT_1_2VREFINT COMP_CSR_COMP1INSEL_0 /*!< 1/2 VREFINT connected to comparator inverting input */
185 #define COMP_INVERTINGINPUT_3_4VREFINT COMP_CSR_COMP1INSEL_1 /*!< 3/4 VREFINT connected to comparator inverting input */
186 #define COMP_INVERTINGINPUT_VREFINT (COMP_CSR_COMP1INSEL_1|COMP_CSR_COMP1INSEL_0) /*!< VREFINT connected to comparator inverting input */
187 #define COMP_INVERTINGINPUT_DAC1 COMP_CSR_COMP1INSEL_2 /*!< DAC_OUT1 (PA4) connected to comparator inverting input */
188 #define COMP_INVERTINGINPUT_DAC1SWITCHCLOSED (COMP_CSR_COMP1INSEL_2|COMP_CSR_COMP1SW1) /*!< DAC_OUT1 (PA4) connected to comparator inverting input
189 and close switch (PA0 for COMP1 only) */
190 #define COMP_INVERTINGINPUT_DAC2 (COMP_CSR_COMP1INSEL_2|COMP_CSR_COMP1INSEL_0) /*!< DAC_OUT2 (PA5) connected to comparator inverting input */
191 #define COMP_INVERTINGINPUT_IO1 (COMP_CSR_COMP1INSEL_2|COMP_CSR_COMP1INSEL_1) /*!< IO (PA0 for COMP1 and PA2 for COMP2) connected to comparator inverting input */
193 #define IS_COMP_INVERTINGINPUT(INPUT) (((INPUT) == COMP_INVERTINGINPUT_1_4VREFINT) || \
194 ((INPUT) == COMP_INVERTINGINPUT_1_2VREFINT) || \
195 ((INPUT) == COMP_INVERTINGINPUT_3_4VREFINT) || \
196 ((INPUT) == COMP_INVERTINGINPUT_VREFINT) || \
197 ((INPUT) == COMP_INVERTINGINPUT_DAC1) || \
198 ((INPUT) == COMP_INVERTINGINPUT_DAC1SWITCHCLOSED) || \
199 ((INPUT) == COMP_INVERTINGINPUT_DAC2) || \
200 ((INPUT) == COMP_INVERTINGINPUT_IO1))
205 /** @defgroup COMP_NonInvertingInput COMP NonInvertingInput
208 #define COMP_NONINVERTINGINPUT_IO1 ((uint32_t)0x00000000) /*!< I/O1 (PA1 for COMP1, PA3 for COMP2)
209 connected to comparator non inverting input */
210 #define COMP_NONINVERTINGINPUT_DAC1SWITCHCLOSED COMP_CSR_COMP1SW1 /*!< DAC ouput connected to comparator COMP1 non inverting input */
212 #define IS_COMP_NONINVERTINGINPUT(INPUT) (((INPUT) == COMP_NONINVERTINGINPUT_IO1) || \
213 ((INPUT) == COMP_NONINVERTINGINPUT_DAC1SWITCHCLOSED))
218 /** @defgroup COMP_Output COMP Output
222 /* Output Redirection common for COMP1 and COMP2 */
223 #define COMP_OUTPUT_NONE ((uint32_t)0x00000000) /*!< COMP output isn't connected to other peripherals */
224 #define COMP_OUTPUT_TIM1BKIN COMP_CSR_COMP1OUTSEL_0 /*!< COMP output connected to TIM1 Break Input (BKIN) */
225 #define COMP_OUTPUT_TIM1IC1 COMP_CSR_COMP1OUTSEL_1 /*!< COMP output connected to TIM1 Input Capture 1 */
226 #define COMP_OUTPUT_TIM1OCREFCLR (COMP_CSR_COMP1OUTSEL_1|COMP_CSR_COMP1OUTSEL_0) /*!< COMP output connected to TIM1 OCREF Clear */
227 #define COMP_OUTPUT_TIM2IC4 COMP_CSR_COMP1OUTSEL_2 /*!< COMP output connected to TIM2 Input Capture 4 */
228 #define COMP_OUTPUT_TIM2OCREFCLR (COMP_CSR_COMP1OUTSEL_2|COMP_CSR_COMP1OUTSEL_0) /*!< COMP output connected to TIM2 OCREF Clear */
229 #define COMP_OUTPUT_TIM3IC1 (COMP_CSR_COMP1OUTSEL_2|COMP_CSR_COMP1OUTSEL_1) /*!< COMP output connected to TIM3 Input Capture 1 */
230 #define COMP_OUTPUT_TIM3OCREFCLR COMP_CSR_COMP1OUTSEL /*!< COMP output connected to TIM3 OCREF Clear */
232 #define IS_COMP_OUTPUT(OUTPUT) (((OUTPUT) == COMP_OUTPUT_NONE) || \
233 ((OUTPUT) == COMP_OUTPUT_TIM1BKIN) || \
234 ((OUTPUT) == COMP_OUTPUT_TIM1IC1) || \
235 ((OUTPUT) == COMP_OUTPUT_TIM1OCREFCLR) || \
236 ((OUTPUT) == COMP_OUTPUT_TIM2IC4) || \
237 ((OUTPUT) == COMP_OUTPUT_TIM2OCREFCLR) || \
238 ((OUTPUT) == COMP_OUTPUT_TIM3IC1) || \
239 ((OUTPUT) == COMP_OUTPUT_TIM3OCREFCLR))
245 /** @defgroup COMP_OutputLevel COMP OutputLevel
248 /* When output polarity is not inverted, comparator output is low when
249 the non-inverting input is at a lower voltage than the inverting input*/
250 #define COMP_OUTPUTLEVEL_LOW ((uint32_t)0x00000000)
251 /* When output polarity is not inverted, comparator output is high when
252 the non-inverting input is at a higher voltage than the inverting input */
253 #define COMP_OUTPUTLEVEL_HIGH COMP_CSR_COMP1OUT
258 /** @defgroup COMP_TriggerMode COMP TriggerMode
261 #define COMP_TRIGGERMODE_NONE ((uint32_t)0x00000000) /*!< No External Interrupt trigger detection */
262 #define COMP_TRIGGERMODE_IT_RISING ((uint32_t)0x00000001) /*!< External Interrupt Mode with Rising edge trigger detection */
263 #define COMP_TRIGGERMODE_IT_FALLING ((uint32_t)0x00000002) /*!< External Interrupt Mode with Falling edge trigger detection */
264 #define COMP_TRIGGERMODE_IT_RISING_FALLING ((uint32_t)0x00000003) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
266 #define IS_COMP_TRIGGERMODE(MODE) (((MODE) == COMP_TRIGGERMODE_NONE) || \
267 ((MODE) == COMP_TRIGGERMODE_IT_RISING) || \
268 ((MODE) == COMP_TRIGGERMODE_IT_FALLING) || \
269 ((MODE) == COMP_TRIGGERMODE_IT_RISING_FALLING))
274 /** @defgroup COMP_WindowMode COMP WindowMode
277 #define COMP_WINDOWMODE_DISABLED ((uint32_t)0x00000000) /*!< Window mode disabled */
278 #define COMP_WINDOWMODE_ENABLED COMP_CSR_WNDWEN /*!< Window mode enabled: non inverting input of comparator 2
279 is connected to the non inverting input of comparator 1 (PA1) */
281 #define IS_COMP_WINDOWMODE(WINDOWMODE) (((WINDOWMODE) == COMP_WINDOWMODE_DISABLED) || \
282 ((WINDOWMODE) == COMP_WINDOWMODE_ENABLED))
287 /** @defgroup COMP_ExtiLineEvent COMP ExtiLineEvent
288 * Elements values convention: XXXX0000
289 * - XXXX : Interrupt mask in the EMR/IMR/RTSR/FTSR register
292 #define COMP_EXTI_LINE_COMP1_EVENT ((uint32_t)0x00200000) /*!< External interrupt line 21 Connected to COMP1 */
293 #define COMP_EXTI_LINE_COMP2_EVENT ((uint32_t)0x00400000) /*!< External interrupt line 22 Connected to COMP2 */
299 /** @defgroup COMP_Lock COMP Lock
302 #define COMP_LOCK_DISABLE ((uint32_t)0x00000000)
303 #define COMP_LOCK_ENABLE COMP_CSR_COMP1LOCK
305 #define COMP_STATE_BIT_LOCK ((uint32_t)0x10)
315 /* Exported macros -----------------------------------------------------------*/
316 /** @defgroup COMP_Exported_Macros COMP Exported Macros
320 /** @brief Reset COMP handle state
321 * @param __HANDLE__: COMP handle.
324 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
327 * @brief Checks whether the specified EXTI line flag is set or not.
328 * @param __FLAG__: specifies the COMP Exti sources to be checked.
329 * This parameter can be a value of @ref COMP_ExtiLineEvent
330 * @retval The state of __FLAG__ (SET or RESET).
332 #define __HAL_COMP_EXTI_GET_FLAG(__FLAG__) (EXTI->PR & (__FLAG__))
335 * @brief Clear the COMP Exti flags.
336 * @param __FLAG__: specifies the COMP Exti sources to be cleared.
337 * This parameter can be a value of @ref COMP_ExtiLineEvent
340 #define __HAL_COMP_EXTI_CLEAR_FLAG(__FLAG__) (EXTI->PR = (__FLAG__))
343 * @brief Enable the COMP Exti Line.
344 * @param __EXTILINE__: specifies the COMP Exti sources to be enabled.
345 * This parameter can be a value of @ref COMP_ExtiLineEvent
348 #define __HAL_COMP_EXTI_ENABLE_IT(__EXTILINE__) (EXTI->IMR |= (__EXTILINE__))
351 * @brief Disable the COMP Exti Line.
352 * @param __EXTILINE__: specifies the COMP Exti sources to be disabled.
353 * This parameter can be a value of @ref COMP_ExtiLineEvent
356 #define __HAL_COMP_EXTI_DISABLE_IT(__EXTILINE__) (EXTI->IMR &= ~(__EXTILINE__))
359 * @brief Enable the Exti Line rising edge trigger.
360 * @param __EXTILINE__: specifies the COMP Exti sources to be enabled.
361 * This parameter can be a value of @ref COMP_ExtiLineEvent
364 #define __HAL_COMP_EXTI_RISING_IT_ENABLE(__EXTILINE__) (EXTI->RTSR |= (__EXTILINE__))
367 * @brief Disable the Exti Line rising edge trigger.
368 * @param __EXTILINE__: specifies the COMP Exti sources to be disabled.
369 * This parameter can be a value of @ref COMP_ExtiLineEvent
372 #define __HAL_COMP_EXTI_RISING_IT_DISABLE(__EXTILINE__) (EXTI->RTSR &= ~(__EXTILINE__))
375 * @brief Enable the Exti Line falling edge trigger.
376 * @param __EXTILINE__: specifies the COMP Exti sources to be enabled.
377 * This parameter can be a value of @ref COMP_ExtiLineEvent
380 #define __HAL_COMP_EXTI_FALLING_IT_ENABLE(__EXTILINE__) (EXTI->FTSR |= (__EXTILINE__))
383 * @brief Disable the Exti Line falling edge trigger.
384 * @param __EXTILINE__: specifies the COMP Exti sources to be disabled.
385 * This parameter can be a value of @ref COMP_ExtiLineEvent
388 #define __HAL_COMP_EXTI_FALLING_IT_DISABLE(__EXTILINE__) (EXTI->FTSR &= ~(__EXTILINE__))
391 * @brief Get the specified EXTI line for a comparator instance
392 * @param __INSTANCE__: specifies the COMP instance.
393 * @retval value of @ref COMP_ExtiLineEvent
395 #define __HAL_COMP_GET_EXTI_LINE(__INSTANCE__) (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1_EVENT : \
396 COMP_EXTI_LINE_COMP2_EVENT)
401 /* Exported functions --------------------------------------------------------*/
402 /** @addtogroup COMP_Exported_Functions COMP Exported Functions
405 /** @addtogroup COMP_Exported_Functions_Group1 Initialization/de-initialization functions
406 * @brief Initialization and Configuration functions
409 /* Initialization and de-initialization functions ****************************/
410 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
411 HAL_StatusTypeDef HAL_COMP_DeInit (COMP_HandleTypeDef *hcomp);
412 void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
413 void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
418 /** @addtogroup COMP_Exported_Functions_Group2 I/O operation functions
419 * @brief Data transfers functions
422 /* IO operation functions *****************************************************/
423 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
424 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
425 HAL_StatusTypeDef HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp);
426 HAL_StatusTypeDef HAL_COMP_Stop_IT(COMP_HandleTypeDef *hcomp);
427 void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
432 /** @addtogroup COMP_Exported_Functions_Group3 Peripheral Control functions
433 * @brief management functions
436 /* Peripheral Control functions ***********************************************/
437 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
438 uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp);
440 /* Callback in Interrupt mode */
441 void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
446 /** @addtogroup COMP_Exported_Functions_Group4 Peripheral State functions
447 * @brief Peripheral State functions
450 /* Peripheral State and Error functions ***************************************/
451 uint32_t HAL_COMP_GetState(COMP_HandleTypeDef *hcomp);
468 #endif /* STM32F051x8 || STM32F058xx || */
469 /* STM32F071xB || STM32F072xB || STM32F078xx || */
470 /* STM32F091xC || STM32F098xx */
476 #endif /* __STM32F0xx_HAL_COMP_H */
478 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/