STM32L486xx HAL User Manual
stm32l4xx_hal_comp.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_comp.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of COMP HAL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00010   *
00011   * Redistribution and use in source and binary forms, with or without modification,
00012   * are permitted provided that the following conditions are met:
00013   *   1. Redistributions of source code must retain the above copyright notice,
00014   *      this list of conditions and the following disclaimer.
00015   *   2. Redistributions in binary form must reproduce the above copyright notice,
00016   *      this list of conditions and the following disclaimer in the documentation
00017   *      and/or other materials provided with the distribution.
00018   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00019   *      may be used to endorse or promote products derived from this software
00020   *      without specific prior written permission.
00021   *
00022   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00026   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00028   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00030   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032   *
00033   ******************************************************************************  
00034   */
00035 
00036 /* Define to prevent recursive inclusion -------------------------------------*/
00037 #ifndef __STM32L4xx_HAL_COMP_H
00038 #define __STM32L4xx_HAL_COMP_H
00039 
00040 #ifdef __cplusplus
00041 extern "C" {
00042 #endif
00043 
00044 /* Includes ------------------------------------------------------------------*/
00045 #include "stm32l4xx_hal_def.h"
00046 #include "stm32l4xx_ll_exti.h"
00047 
00048 /** @addtogroup STM32L4xx_HAL_Driver
00049   * @{
00050   */
00051 #if defined (COMP1) || defined (COMP2)
00052 
00053 /** @addtogroup COMP
00054   * @{
00055   */
00056 
00057 /* Exported types ------------------------------------------------------------*/ 
00058 /** @defgroup COMP_Exported_Types COMP Exported Types
00059   * @{
00060   */
00061 
00062 /** 
00063   * @brief  COMP Init structure definition  
00064   */
00065 typedef struct
00066 {
00067 
00068   uint32_t WindowMode;         /*!< Set window mode of a pair of comparators instances
00069                                     (2 consecutive instances odd and even COMP<x> and COMP<x+1>).
00070                                     Note: HAL COMP driver allows to set window mode from any COMP instance of the pair of COMP instances composing window mode.
00071                                     This parameter can be a value of @ref COMP_WindowMode */
00072 
00073   uint32_t Mode;               /*!< Set comparator operating mode to adjust power and speed.
00074                                     Note: For the characteritics of comparator power modes
00075                                           (propagation delay and power consumption), refer to device datasheet.
00076                                     This parameter can be a value of @ref COMP_PowerMode */
00077 
00078   uint32_t NonInvertingInput;  /*!< Set comparator input plus (non-inverting input).
00079                                     This parameter can be a value of @ref COMP_InputPlus */
00080 
00081   uint32_t InvertingInput;     /*!< Set comparator input minus (inverting input).
00082                                     This parameter can be a value of @ref COMP_InputMinus */
00083 
00084   uint32_t Hysteresis;         /*!< Set comparator hysteresis mode of the input minus.
00085                                     This parameter can be a value of @ref COMP_Hysteresis */
00086 
00087   uint32_t OutputPol;          /*!< Set comparator output polarity.
00088                                     This parameter can be a value of @ref COMP_OutputPolarity */
00089 
00090   uint32_t BlankingSrce;       /*!< Set comparator blanking source.
00091                                     This parameter can be a value of @ref COMP_BlankingSrce */
00092 
00093   uint32_t TriggerMode;        /*!< Set the comparator output triggering External Interrupt Line (EXTI).
00094                                     This parameter can be a value of @ref COMP_EXTI_TriggerMode */
00095 
00096 }COMP_InitTypeDef;
00097 
00098 /**
00099   * @brief  HAL COMP state machine: HAL COMP states definition
00100   */
00101 #define COMP_STATE_BITFIELD_LOCK  (0x10U)
00102 typedef enum
00103 {
00104   HAL_COMP_STATE_RESET             = 0x00U,                                             /*!< COMP not yet initialized                             */
00105   HAL_COMP_STATE_RESET_LOCKED      = (HAL_COMP_STATE_RESET | COMP_STATE_BITFIELD_LOCK), /*!< COMP not yet initialized and configuration is locked */
00106   HAL_COMP_STATE_READY             = 0x01U,                                             /*!< COMP initialized and ready for use                   */
00107   HAL_COMP_STATE_READY_LOCKED      = (HAL_COMP_STATE_READY | COMP_STATE_BITFIELD_LOCK), /*!< COMP initialized but configuration is locked         */
00108   HAL_COMP_STATE_BUSY              = 0x02U,                                             /*!< COMP is running                                      */
00109   HAL_COMP_STATE_BUSY_LOCKED       = (HAL_COMP_STATE_BUSY | COMP_STATE_BITFIELD_LOCK)   /*!< COMP is running and configuration is locked          */
00110 }HAL_COMP_StateTypeDef;
00111 
00112 /** 
00113   * @brief  COMP Handle Structure definition
00114   */
00115 typedef struct __COMP_HandleTypeDef
00116 {
00117   COMP_TypeDef       *Instance;       /*!< Register base address    */
00118   COMP_InitTypeDef   Init;            /*!< COMP required parameters */
00119   HAL_LockTypeDef    Lock;            /*!< Locking object           */
00120   __IO HAL_COMP_StateTypeDef  State;  /*!< COMP communication state */
00121   __IO uint32_t      ErrorCode;       /*!< COMP error code */
00122 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
00123   void (* TriggerCallback)(struct __COMP_HandleTypeDef *hcomp);   /*!< COMP trigger callback */
00124   void (* MspInitCallback)(struct __COMP_HandleTypeDef *hcomp);   /*!< COMP Msp Init callback */
00125   void (* MspDeInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp DeInit callback */
00126 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
00127 } COMP_HandleTypeDef;
00128 
00129 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
00130 /**
00131   * @brief  HAL COMP Callback ID enumeration definition
00132   */
00133 typedef enum
00134 {
00135   HAL_COMP_TRIGGER_CB_ID                = 0x00U,  /*!< COMP trigger callback ID */
00136   HAL_COMP_MSPINIT_CB_ID                = 0x01U,  /*!< COMP Msp Init callback ID */
00137   HAL_COMP_MSPDEINIT_CB_ID              = 0x02U   /*!< COMP Msp DeInit callback ID */
00138 } HAL_COMP_CallbackIDTypeDef;
00139 
00140 /**
00141   * @brief  HAL COMP Callback pointer definition
00142   */
00143 typedef  void (*pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp); /*!< pointer to a COMP callback function */
00144 
00145 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
00146 
00147 /**
00148   * @}
00149   */
00150 
00151 /* Exported constants --------------------------------------------------------*/
00152 /** @defgroup COMP_Exported_Constants COMP Exported Constants
00153   * @{
00154   */
00155 
00156 /** @defgroup COMP_Error_Code COMP Error Code
00157   * @{
00158   */
00159 #define HAL_COMP_ERROR_NONE             (0x00U)   /*!< No error */
00160 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
00161 #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01U)   /*!< Invalid Callback error */
00162 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
00163 /**
00164   * @}
00165   */
00166 
00167 /** @defgroup COMP_WindowMode COMP Window Mode
00168   * @{
00169   */
00170 #define COMP_WINDOWMODE_DISABLE                 (0x00000000U)          /*!< Window mode disable: Comparators instances pair COMP1 and COMP2 are independent */
00171 #define COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_WINMODE)     /*!< Window mode enable: Comparators instances pair COMP1 and COMP2 have their input plus connected together. The common input is COMP1 input plus (COMP2 input plus is no more accessible). */
00172 /**
00173   * @}
00174   */
00175 
00176 /** @defgroup COMP_PowerMode COMP power mode
00177   * @{
00178   */
00179 /* Note: For the characteritics of comparator power modes                     */
00180 /*       (propagation delay and power consumption),                           */
00181 /*       refer to device datasheet.                                           */
00182 #define COMP_POWERMODE_HIGHSPEED       (0x00000000U)          /*!< High Speed */
00183 #define COMP_POWERMODE_MEDIUMSPEED     (COMP_CSR_PWRMODE_0)   /*!< Medium Speed */
00184 #define COMP_POWERMODE_ULTRALOWPOWER   (COMP_CSR_PWRMODE)     /*!< Ultra-low power mode */
00185 /**
00186   * @}
00187   */
00188 
00189 /** @defgroup COMP_InputPlus COMP input plus (non-inverting input)
00190   * @{
00191   */
00192 #define COMP_INPUT_PLUS_IO1            (0x00000000U)          /*!< Comparator input plus connected to IO1 (pin PC5 for COMP1, pin PB4 for COMP2) */
00193 #define COMP_INPUT_PLUS_IO2            (COMP_CSR_INPSEL_0)    /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PB6 for COMP2) */
00194 #if defined(COMP_CSR_INPSEL_1)
00195 #define COMP_INPUT_PLUS_IO3            (COMP_CSR_INPSEL_1)    /*!< Comparator input plus connected to IO3 (pin PA1 for COMP1, pin PA3 for COMP2) */
00196 #endif
00197 /**
00198   * @}
00199   */
00200 
00201 /** @defgroup COMP_InputMinus COMP input minus (inverting input)
00202   * @{
00203   */
00204 #define COMP_INPUT_MINUS_1_4VREFINT    (                                                            COMP_CSR_SCALEN | COMP_CSR_BRGEN)        /*!< Comparator input minus connected to 1/4 VrefInt */
00205 #define COMP_INPUT_MINUS_1_2VREFINT    (                                        COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN | COMP_CSR_BRGEN)        /*!< Comparator input minus connected to 1/2 VrefInt */
00206 #define COMP_INPUT_MINUS_3_4VREFINT    (                    COMP_CSR_INMSEL_1                     | COMP_CSR_SCALEN | COMP_CSR_BRGEN)        /*!< Comparator input minus connected to 3/4 VrefInt */
00207 #define COMP_INPUT_MINUS_VREFINT       (                    COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN                 )        /*!< Comparator input minus connected to VrefInt */
00208 #define COMP_INPUT_MINUS_DAC1_CH1      (COMP_CSR_INMSEL_2                                        )                                           /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */
00209 #if defined(DAC_CHANNEL2_SUPPORT)
00210 #define COMP_INPUT_MINUS_DAC1_CH2      (COMP_CSR_INMSEL_2                     | COMP_CSR_INMSEL_0)                                           /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */
00211 #endif
00212 #define COMP_INPUT_MINUS_IO1           (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1                    )                                           /*!< Comparator input minus connected to IO1 (pin PB1 for COMP1, pin PB3 for COMP2) */ 
00213 #define COMP_INPUT_MINUS_IO2           (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0)                                           /*!< Comparator input minus connected to IO2 (pin PC4 for COMP1, pin PB7 for COMP2) */
00214 #if defined(COMP_CSR_INMESEL_1)
00215 #define COMP_INPUT_MINUS_IO3           (                     COMP_CSR_INMESEL_0 | COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO3 (pin PA0 for COMP1, pin PA2 for COMP2) */
00216 #define COMP_INPUT_MINUS_IO4           (COMP_CSR_INMESEL_1                      | COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO4 (pin PA4 for COMP1, pin PA4 for COMP2) */
00217 #define COMP_INPUT_MINUS_IO5           (COMP_CSR_INMESEL_1 | COMP_CSR_INMESEL_0 | COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO5 (pin PA5 for COMP1, pin PA5 for COMP2) */
00218 #endif
00219 /**
00220   * @}
00221   */
00222 
00223 /** @defgroup COMP_Hysteresis COMP hysteresis
00224   * @{
00225   */
00226 #define COMP_HYSTERESIS_NONE           (0x00000000U)                        /*!< No hysteresis */
00227 #define COMP_HYSTERESIS_LOW            (                  COMP_CSR_HYST_0)  /*!< Hysteresis level low */
00228 #define COMP_HYSTERESIS_MEDIUM         (COMP_CSR_HYST_1                  )  /*!< Hysteresis level medium */
00229 #define COMP_HYSTERESIS_HIGH           (COMP_CSR_HYST_1 | COMP_CSR_HYST_0)  /*!< Hysteresis level high */
00230 /**
00231   * @}
00232   */
00233 
00234 /** @defgroup COMP_OutputPolarity COMP output Polarity
00235   * @{
00236   */
00237 #define COMP_OUTPUTPOL_NONINVERTED     (0x00000000U)          /*!< COMP output level is not inverted (comparator output is high when the input plus is at a higher voltage than the input minus) */
00238 #define COMP_OUTPUTPOL_INVERTED        (COMP_CSR_POLARITY)    /*!< COMP output level is inverted     (comparator output is low  when the input plus is at a higher voltage than the input minus) */
00239 /**
00240   * @}
00241   */
00242 
00243 /** @defgroup COMP_BlankingSrce  COMP blanking source
00244   * @{
00245   */
00246 #define COMP_BLANKINGSRC_NONE            (0x00000000U)           /*!<Comparator output without blanking */
00247 #define COMP_BLANKINGSRC_TIM1_OC5_COMP1  (COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP1) */
00248 #define COMP_BLANKINGSRC_TIM2_OC3_COMP1  (COMP_CSR_BLANKING_1)   /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP1) */
00249 #define COMP_BLANKINGSRC_TIM3_OC3_COMP1  (COMP_CSR_BLANKING_2)   /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP1) */
00250 #define COMP_BLANKINGSRC_TIM3_OC4_COMP2  (COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM3 OC4 (specific to COMP instance: COMP2) */
00251 #define COMP_BLANKINGSRC_TIM8_OC5_COMP2  (COMP_CSR_BLANKING_1)   /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP2) */
00252 #define COMP_BLANKINGSRC_TIM15_OC1_COMP2 (COMP_CSR_BLANKING_2)   /*!< Comparator output blanking source TIM15 OC1 (specific to COMP instance: COMP2) */
00253 /**
00254   * @}
00255   */
00256 
00257 /** @defgroup COMP_OutputLevel COMP Output Level
00258   * @{
00259   */
00260 /* Note: Comparator output level values are fixed to "0" and "1",             */
00261 /* corresponding COMP register bit is managed by HAL function to match        */
00262 /* with these values (independently of bit position in register).             */
00263 
00264 /* When output polarity is not inverted, comparator output is low when
00265    the input plus is at a lower voltage than the input minus */
00266 #define COMP_OUTPUT_LEVEL_LOW              (0x00000000U)
00267 /* When output polarity is not inverted, comparator output is high when
00268    the input plus is at a higher voltage than the input minus */
00269 #define COMP_OUTPUT_LEVEL_HIGH             (0x00000001U)
00270 /**
00271   * @}
00272   */
00273 
00274 /** @defgroup COMP_EXTI_TriggerMode COMP output to EXTI
00275   * @{
00276   */
00277 #define COMP_TRIGGERMODE_NONE                 (0x00000000U)                                             /*!< Comparator output triggering no External Interrupt Line */
00278 #define COMP_TRIGGERMODE_IT_RISING            (COMP_EXTI_IT | COMP_EXTI_RISING)                         /*!< Comparator output triggering External Interrupt Line event with interruption, on rising edge */
00279 #define COMP_TRIGGERMODE_IT_FALLING           (COMP_EXTI_IT | COMP_EXTI_FALLING)                        /*!< Comparator output triggering External Interrupt Line event with interruption, on falling edge */
00280 #define COMP_TRIGGERMODE_IT_RISING_FALLING    (COMP_EXTI_IT | COMP_EXTI_RISING | COMP_EXTI_FALLING)     /*!< Comparator output triggering External Interrupt Line event with interruption, on both rising and falling edges */
00281 #define COMP_TRIGGERMODE_EVENT_RISING         (COMP_EXTI_EVENT | COMP_EXTI_RISING)                      /*!< Comparator output triggering External Interrupt Line event only (without interruption), on rising edge */
00282 #define COMP_TRIGGERMODE_EVENT_FALLING        (COMP_EXTI_EVENT | COMP_EXTI_FALLING)                     /*!< Comparator output triggering External Interrupt Line event only (without interruption), on falling edge */
00283 #define COMP_TRIGGERMODE_EVENT_RISING_FALLING (COMP_EXTI_EVENT | COMP_EXTI_RISING | COMP_EXTI_FALLING)  /*!< Comparator output triggering External Interrupt Line event only (without interruption), on both rising and falling edges */
00284 /**
00285   * @}
00286   */
00287 
00288 /**
00289   * @}
00290   */
00291 
00292 /* Exported macro ------------------------------------------------------------*/
00293 /** @defgroup COMP_Exported_Macros COMP Exported Macros
00294   * @{
00295   */
00296 
00297 /** @defgroup COMP_Handle_Management  COMP Handle Management
00298   * @{
00299   */
00300 
00301 /** @brief  Reset COMP handle state.
00302   * @param  __HANDLE__  COMP handle
00303   * @retval None
00304   */
00305 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
00306 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{                                                   \
00307                                                      (__HANDLE__)->State = HAL_COMP_STATE_RESET;      \
00308                                                      (__HANDLE__)->MspInitCallback = NULL;            \
00309                                                      (__HANDLE__)->MspDeInitCallback = NULL;          \
00310                                                     } while(0)
00311 #else
00312 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
00313 #endif
00314 
00315 /**
00316   * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE").
00317   * @param __HANDLE__ COMP handle
00318   * @retval None
00319   */
00320 #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE) 
00321 
00322 /**
00323   * @brief  Enable the specified comparator.
00324   * @param  __HANDLE__  COMP handle
00325   * @retval None
00326   */
00327 #define __HAL_COMP_ENABLE(__HANDLE__)              SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN)
00328 
00329 /**
00330   * @brief  Disable the specified comparator.
00331   * @param  __HANDLE__  COMP handle
00332   * @retval None
00333   */
00334 #define __HAL_COMP_DISABLE(__HANDLE__)             CLEAR_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN)
00335 
00336 /**
00337   * @brief  Lock the specified comparator configuration.
00338   * @note   Using this macro induce HAL COMP handle state machine being no
00339   *         more in line with COMP instance state.
00340   *         To keep HAL COMP handle state machine updated, it is recommended
00341   *         to use function "HAL_COMP_Lock')".
00342   * @param  __HANDLE__  COMP handle
00343   * @retval None
00344   */
00345 #define __HAL_COMP_LOCK(__HANDLE__)                SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK)
00346 
00347 /**
00348   * @brief  Check whether the specified comparator is locked.
00349   * @param  __HANDLE__  COMP handle
00350   * @retval Value 0 if COMP instance is not locked, value 1 if COMP instance is locked
00351   */
00352 #define __HAL_COMP_IS_LOCKED(__HANDLE__)           (READ_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK) == COMP_CSR_LOCK)
00353 
00354 /**
00355   * @}
00356   */
00357 
00358 /** @defgroup COMP_Exti_Management  COMP external interrupt line management
00359   * @{
00360   */
00361 
00362 /**
00363   * @brief  Enable the COMP1 EXTI line rising edge trigger.
00364   * @retval None
00365   */
00366 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE()    LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1)
00367 
00368 /**
00369   * @brief  Disable the COMP1 EXTI line rising edge trigger.
00370   * @retval None
00371   */
00372 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE()   LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1)
00373 
00374 /**
00375   * @brief  Enable the COMP1 EXTI line falling edge trigger.
00376   * @retval None
00377   */
00378 #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE()   LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1)
00379 
00380 /**
00381   * @brief  Disable the COMP1 EXTI line falling edge trigger.
00382   * @retval None
00383   */
00384 #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE()  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1)
00385 
00386 /**
00387   * @brief  Enable the COMP1 EXTI line rising & falling edge trigger.
00388   * @retval None
00389   */
00390 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
00391                                                                LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \
00392                                                                LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1); \
00393                                                              } while(0)
00394 
00395 /**
00396   * @brief  Disable the COMP1 EXTI line rising & falling edge trigger.
00397   * @retval None
00398   */                                         
00399 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
00400                                                                LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \
00401                                                                LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1); \
00402                                                              } while(0)
00403 
00404 /**
00405   * @brief  Enable the COMP1 EXTI line in interrupt mode.
00406   * @retval None
00407   */
00408 #define __HAL_COMP_COMP1_EXTI_ENABLE_IT()             LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP1)
00409 
00410 /**
00411   * @brief  Disable the COMP1 EXTI line in interrupt mode.
00412   * @retval None
00413   */
00414 #define __HAL_COMP_COMP1_EXTI_DISABLE_IT()            LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP1)
00415 
00416 /**
00417   * @brief  Generate a software interrupt on the COMP1 EXTI line.
00418   * @retval None
00419   */
00420 #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT()         LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP1)
00421 
00422 /**
00423   * @brief  Enable the COMP1 EXTI line in event mode.
00424   * @retval None
00425   */
00426 #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT()          LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP1)
00427 
00428 /**
00429   * @brief  Disable the COMP1 EXTI line in event mode.
00430   * @retval None
00431   */
00432 #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT()         LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP1)
00433 
00434 /**
00435   * @brief  Check whether the COMP1 EXTI line flag is set.
00436   * @retval RESET or SET
00437   */
00438 #define __HAL_COMP_COMP1_EXTI_GET_FLAG()              LL_EXTI_IsActiveFlag_0_31(COMP_EXTI_LINE_COMP1)
00439 
00440 /**
00441   * @brief  Clear the COMP1 EXTI flag.
00442   * @retval None
00443   */
00444 #define __HAL_COMP_COMP1_EXTI_CLEAR_FLAG()            LL_EXTI_ClearFlag_0_31(COMP_EXTI_LINE_COMP1)
00445 
00446 /**
00447   * @brief  Enable the COMP2 EXTI line rising edge trigger.
00448   * @retval None
00449   */
00450 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE()    LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2)
00451 
00452 /**
00453   * @brief  Disable the COMP2 EXTI line rising edge trigger.
00454   * @retval None
00455   */
00456 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE()   LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2)
00457 
00458 /**
00459   * @brief  Enable the COMP2 EXTI line falling edge trigger.
00460   * @retval None
00461   */
00462 #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE()   LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2)
00463 
00464 /**
00465   * @brief  Disable the COMP2 EXTI line falling edge trigger.
00466   * @retval None
00467   */
00468 #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE()  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2)
00469 
00470 /**
00471   * @brief  Enable the COMP2 EXTI line rising & falling edge trigger.
00472   * @retval None
00473   */
00474 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
00475                                                                LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \
00476                                                                LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2); \
00477                                                              } while(0)
00478 
00479 /**
00480   * @brief  Disable the COMP2 EXTI line rising & falling edge trigger.
00481   * @retval None
00482   */                                         
00483 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
00484                                                                LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \
00485                                                                LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2); \
00486                                                              } while(0)
00487 
00488 /**
00489   * @brief  Enable the COMP2 EXTI line in interrupt mode.
00490   * @retval None
00491   */
00492 #define __HAL_COMP_COMP2_EXTI_ENABLE_IT()             LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP2)
00493 
00494 /**
00495   * @brief  Disable the COMP2 EXTI line in interrupt mode.
00496   * @retval None
00497   */
00498 #define __HAL_COMP_COMP2_EXTI_DISABLE_IT()            LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP2)
00499 
00500 /**
00501   * @brief  Generate a software interrupt on the COMP2 EXTI line.
00502   * @retval None
00503   */
00504 #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT()         LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP2)
00505 
00506 /**
00507   * @brief  Enable the COMP2 EXTI line in event mode.
00508   * @retval None
00509   */
00510 #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT()          LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP2)
00511 
00512 /**
00513   * @brief  Disable the COMP2 EXTI line in event mode.
00514   * @retval None
00515   */
00516 #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT()         LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP2)
00517 
00518 /**
00519   * @brief  Check whether the COMP2 EXTI line flag is set.
00520   * @retval RESET or SET
00521   */
00522 #define __HAL_COMP_COMP2_EXTI_GET_FLAG()              LL_EXTI_IsActiveFlag_0_31(COMP_EXTI_LINE_COMP2)
00523 
00524 /**
00525   * @brief  Clear the COMP2 EXTI flag.
00526   * @retval None
00527   */
00528 #define __HAL_COMP_COMP2_EXTI_CLEAR_FLAG()            LL_EXTI_ClearFlag_0_31(COMP_EXTI_LINE_COMP2)
00529 
00530 /**
00531   * @}
00532   */
00533 
00534 /**
00535   * @}
00536   */
00537 
00538 
00539 /* Private types -------------------------------------------------------------*/
00540 /* Private constants ---------------------------------------------------------*/
00541 /** @defgroup COMP_Private_Constants COMP Private Constants
00542   * @{
00543   */
00544 
00545 /** @defgroup COMP_ExtiLine COMP EXTI Lines
00546   * @{
00547   */
00548 #define COMP_EXTI_LINE_COMP1           (LL_EXTI_LINE_21)  /*!< EXTI line 21 connected to COMP1 output */
00549 #define COMP_EXTI_LINE_COMP2           (LL_EXTI_LINE_22)  /*!< EXTI line 22 connected to COMP2 output */
00550 /**
00551   * @}
00552   */
00553 
00554 /** @defgroup COMP_ExtiLine COMP EXTI Lines
00555   * @{
00556   */
00557 #define COMP_EXTI_IT                        (0x01U)  /*!< EXTI line event with interruption */
00558 #define COMP_EXTI_EVENT                     (0x02U)  /*!< EXTI line event only (without interruption) */
00559 #define COMP_EXTI_RISING                    (0x10U)  /*!< EXTI line event on rising edge */
00560 #define COMP_EXTI_FALLING                   (0x20U)  /*!< EXTI line event on falling edge */
00561 /**
00562   * @}
00563   */
00564 
00565 /**
00566   * @}
00567   */
00568 
00569 /* Private macros ------------------------------------------------------------*/
00570 /** @defgroup COMP_Private_Macros COMP Private Macros
00571   * @{
00572   */
00573 
00574 /** @defgroup COMP_GET_EXTI_LINE COMP private macros to get EXTI line associated with comparators 
00575   * @{
00576   */
00577 /**
00578   * @brief  Get the specified EXTI line for a comparator instance.
00579   * @param  __INSTANCE__  specifies the COMP instance.
00580   * @retval value of @ref COMP_ExtiLine
00581   */
00582 #define COMP_GET_EXTI_LINE(__INSTANCE__)    (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1 \
00583                                             : COMP_EXTI_LINE_COMP2)
00584 /**
00585   * @}
00586   */
00587 
00588 /** @defgroup COMP_IS_COMP_Definitions COMP private macros to check input parameters
00589   * @{
00590   */
00591 #define IS_COMP_WINDOWMODE(__WINDOWMODE__)  (((__WINDOWMODE__) == COMP_WINDOWMODE_DISABLE)                || \
00592                                              ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON)  )
00593 
00594 #define IS_COMP_POWERMODE(__POWERMODE__)    (((__POWERMODE__) == COMP_POWERMODE_HIGHSPEED)    || \
00595                                              ((__POWERMODE__) == COMP_POWERMODE_MEDIUMSPEED)  || \
00596                                              ((__POWERMODE__) == COMP_POWERMODE_ULTRALOWPOWER)  )
00597 
00598 #if defined(COMP_CSR_INPSEL_1)
00599 #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \
00600                                                                ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2) || \
00601                                                                ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO3))
00602 #else
00603 #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \
00604                                                                ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2))
00605 #endif
00606 
00607 /* Note: On this STM32 serie, comparator input minus parameters are           */
00608 /*       the same on all COMP instances.                                      */
00609 /*       However, comparator instance kept as macro parameter for             */
00610 /*       compatibility with other STM32 families.                             */
00611 #if defined(COMP_CSR_INMESEL_1) && defined(DAC_CHANNEL2_SUPPORT)
00612 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT)  || \
00613                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT)  || \
00614                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT)  || \
00615                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT)     || \
00616                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1)    || \
00617                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2)    || \
00618                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1)         || \
00619                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2)         || \
00620                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO3)         || \
00621                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO4)         || \
00622                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO5))
00623 #elif defined(COMP_CSR_INMESEL_1)
00624 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT)  || \
00625                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT)  || \
00626                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT)  || \
00627                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT)     || \
00628                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1)    || \
00629                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1)         || \
00630                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2)         || \
00631                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO3)         || \
00632                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO4)         || \
00633                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO5))
00634 #elif defined(DAC_CHANNEL2_SUPPORT)
00635 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT)  || \
00636                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT)  || \
00637                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT)  || \
00638                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT)     || \
00639                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1)    || \
00640                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2)    || \
00641                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1)         || \
00642                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2))
00643 #else
00644 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT)  || \
00645                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT)  || \
00646                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT)  || \
00647                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT)     || \
00648                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1)    || \
00649                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1)         || \
00650                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2))
00651 #endif
00652 
00653 #define IS_COMP_HYSTERESIS(__HYSTERESIS__)  (((__HYSTERESIS__) == COMP_HYSTERESIS_NONE)   || \
00654                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_LOW)    || \
00655                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_MEDIUM) || \
00656                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_HIGH))
00657 
00658 #define IS_COMP_OUTPUTPOL(__POL__)          (((__POL__) == COMP_OUTPUTPOL_NONINVERTED) || \
00659                                              ((__POL__) == COMP_OUTPUTPOL_INVERTED))
00660 
00661 #define IS_COMP_BLANKINGSRCE(__OUTPUT_BLANKING_SOURCE__)                    \
00662   (   ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)               \
00663    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1)     \
00664    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1)     \
00665    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1)     \
00666    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4_COMP2)     \
00667    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP2)     \
00668    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1_COMP2)    \
00669   )
00670 
00671 #define IS_COMP_BLANKINGSRC_INSTANCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__)  \
00672    ((((__INSTANCE__) == COMP1) &&                                               \
00673     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
00674      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1)  ||      \
00675      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1)  ||      \
00676      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1)))        \
00677     ||                                                                          \
00678     (((__INSTANCE__) == COMP2) &&                                               \
00679      (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)           ||      \
00680       ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4_COMP2) ||      \
00681       ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP2) ||      \
00682       ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1_COMP2))))
00683 
00684 
00685 #define IS_COMP_TRIGGERMODE(__MODE__)       (((__MODE__) == COMP_TRIGGERMODE_NONE)                 || \
00686                                              ((__MODE__) == COMP_TRIGGERMODE_IT_RISING)            || \
00687                                              ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING)           || \
00688                                              ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING)    || \
00689                                              ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING)         || \
00690                                              ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING)        || \
00691                                              ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING))
00692 
00693 #define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW)     || \
00694                                                 ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH))
00695 
00696 /**
00697   * @}
00698   */
00699 
00700 /**
00701   * @}
00702   */
00703 
00704 
00705 /* Exported functions --------------------------------------------------------*/
00706 /** @addtogroup COMP_Exported_Functions
00707   * @{
00708   */
00709 
00710 /** @addtogroup COMP_Exported_Functions_Group1
00711   * @{
00712   */
00713 
00714 /* Initialization and de-initialization functions  **********************************/
00715 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
00716 HAL_StatusTypeDef HAL_COMP_DeInit (COMP_HandleTypeDef *hcomp);
00717 void              HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
00718 void              HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
00719 
00720 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
00721 /* Callbacks Register/UnRegister functions  ***********************************/
00722 HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID, pCOMP_CallbackTypeDef pCallback);
00723 HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID);
00724 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
00725 /**
00726   * @}
00727   */
00728 
00729 /* IO operation functions  *****************************************************/
00730 /** @addtogroup COMP_Exported_Functions_Group2
00731   * @{
00732   */
00733 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
00734 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
00735 void              HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
00736 /**
00737   * @}
00738   */
00739 
00740 /* Peripheral Control functions  ************************************************/
00741 /** @addtogroup COMP_Exported_Functions_Group3
00742   * @{
00743   */
00744 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
00745 uint32_t          HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp);
00746 /* Callback in interrupt mode */
00747 void              HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
00748 /**
00749   * @}
00750   */
00751 
00752 /* Peripheral State functions  **************************************************/
00753 /** @addtogroup COMP_Exported_Functions_Group4
00754   * @{
00755   */
00756 HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp);
00757 uint32_t              HAL_COMP_GetError(COMP_HandleTypeDef *hcomp);
00758 /**
00759   * @}
00760   */
00761 
00762 /**
00763   * @}
00764   */
00765 
00766 /**
00767   * @}
00768   */
00769 #endif /* COMP1 || COMP2 */
00770 /**
00771   * @}
00772   */
00773 
00774 #ifdef __cplusplus
00775 }
00776 #endif
00777 
00778 #endif /* __STM32L4xx_HAL_COMP_H */
00779 
00780 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/