STM32H735xx HAL User Manual
stm32h7xx_ll_comp.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32h7xx_ll_comp.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of COMP LL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * Copyright (c) 2017 STMicroelectronics.
00010   * All rights reserved.
00011   *
00012   * This software is licensed under terms that can be found in the LICENSE file
00013   * in the root directory of this software component.
00014   * If no LICENSE file comes with this software, it is provided AS-IS.
00015   *
00016   ******************************************************************************
00017   */
00018 
00019 /* Define to prevent recursive inclusion -------------------------------------*/
00020 #ifndef __STM32H7xx_LL_COMP_H
00021 #define __STM32H7xx_LL_COMP_H
00022 
00023 #ifdef __cplusplus
00024 extern "C" {
00025 #endif
00026 
00027 /* Includes ------------------------------------------------------------------*/
00028 #include "stm32h7xx.h"
00029 
00030 /** @addtogroup STM32H7xx_LL_Driver
00031   * @{
00032   */
00033 
00034 #if defined (COMP1) || defined (COMP2)
00035 
00036 /** @defgroup COMP_LL COMP
00037   * @{
00038   */
00039 
00040 /* Private types -------------------------------------------------------------*/
00041 /* Private variables ---------------------------------------------------------*/
00042 /* Private constants ---------------------------------------------------------*/
00043 /** @defgroup COMP_LL_Private_Constants COMP Private Constants
00044   * @{
00045   */
00046 
00047 /* COMP registers bits positions */
00048 #define LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS (30U) /* Value equivalent to POSITION_VAL(COMP_CSR_VALUE) */
00049 
00050 /**
00051   * @}
00052   */
00053 
00054 /* Private macros ------------------------------------------------------------*/
00055 /* Exported types ------------------------------------------------------------*/
00056 #if defined(USE_FULL_LL_DRIVER)
00057 /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
00058   * @{
00059   */
00060 
00061 /**
00062   * @brief  Structure definition of some features of COMP instance.
00063   */
00064 typedef struct
00065 {
00066   uint32_t PowerMode;                   /*!< Set comparator operating mode to adjust power and speed.
00067                                              This parameter can be a value of @ref COMP_LL_EC_POWERMODE
00068                                              
00069                                              This feature can be modified afterwards using unitary function @ref LL_COMP_SetPowerMode(). */
00070 
00071   uint32_t InputPlus;                   /*!< Set comparator input plus (non-inverting input).
00072                                              This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
00073                                              
00074                                              This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputPlus(). */
00075 
00076   uint32_t InputMinus;                  /*!< Set comparator input minus (inverting input).
00077                                              This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
00078                                              
00079                                              This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputMinus(). */
00080 
00081   uint32_t InputHysteresis;             /*!< Set comparator hysteresis mode of the input minus.
00082                                              This parameter can be a value of @ref COMP_LL_EC_INPUT_HYSTERESIS
00083                                              
00084                                              This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputHysteresis(). */
00085 
00086   uint32_t OutputPolarity;              /*!< Set comparator output polarity.
00087                                              This parameter can be a value of @ref COMP_LL_EC_OUTPUT_POLARITY
00088                                              
00089                                              This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputPolarity(). */
00090 
00091   uint32_t OutputBlankingSource;        /*!< Set comparator blanking source.
00092                                              This parameter can be a value of @ref COMP_LL_EC_OUTPUT_BLANKING_SOURCE
00093                                              
00094                                              This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputBlankingSource(). */
00095 
00096 } LL_COMP_InitTypeDef;
00097 
00098 /**
00099   * @}
00100   */
00101 #endif /* USE_FULL_LL_DRIVER */
00102 
00103 /* Exported constants --------------------------------------------------------*/
00104 /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
00105   * @{
00106   */
00107 
00108 /** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode
00109   * @{
00110   */
00111 #define LL_COMP_WINDOWMODE_DISABLE                 (0x00000000UL)          /*!< Window mode disable: Comparators 1 and 2 are independent */
00112 #define LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CFGRx_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). */
00113 /**
00114   * @}
00115   */
00116 
00117 /** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode
00118   * @{
00119   */
00120 #define LL_COMP_POWERMODE_HIGHSPEED     (0x00000000UL)                                /*!< COMP power mode to high speed */
00121 #define LL_COMP_POWERMODE_MEDIUMSPEED   (COMP_CFGRx_PWRMODE_0)                        /*!< COMP power mode to medium speed */
00122 #define LL_COMP_POWERMODE_ULTRALOWPOWER (COMP_CFGRx_PWRMODE_1 | COMP_CFGRx_PWRMODE_0) /*!< COMP power mode to ultra-low power */
00123 /**
00124   * @}
00125   */
00126 
00127 /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
00128   * @{
00129   */
00130 #define LL_COMP_INPUT_PLUS_IO1          (0x00000000UL)                           /*!< Comparator input plus connected to IO1 (pin PB0 for COMP1, pin PE9 for COMP2) */
00131 #define LL_COMP_INPUT_PLUS_IO2          (COMP_CFGRx_INPSEL)                      /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PE11 for COMP2) */
00132 #if defined (COMP_CFGRx_INP2SEL)
00133 #define LL_COMP_INPUT_PLUS_DAC2_CH1     (COMP_CFGRx_INP2SEL)                     /*!< Comparator input plus 2 connected to (DAC2_CH1 for COMP1)                      */
00134 #endif
00135 /**
00136   * @}
00137   */
00138 
00139 /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
00140   * @{
00141   */
00142 #define LL_COMP_INPUT_MINUS_1_4VREFINT      (                                                                                        COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN)   /*!< Comparator input minus connected to 1/4 VrefInt  */
00143 #define LL_COMP_INPUT_MINUS_1_2VREFINT      (                                                                  COMP_CFGRx_INMSEL_0 | COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN)   /*!< Comparator input minus connected to 1/2 VrefInt  */
00144 #define LL_COMP_INPUT_MINUS_3_4VREFINT      (                                            COMP_CFGRx_INMSEL_1                       | COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN)   /*!< Comparator input minus connected to 3/4 VrefInt  */
00145 #define LL_COMP_INPUT_MINUS_VREFINT         (                                            COMP_CFGRx_INMSEL_1 | COMP_CFGRx_INMSEL_0 | COMP_CFGRx_SCALEN                   )   /*!< Comparator input minus connected to VrefInt */
00146 #define LL_COMP_INPUT_MINUS_DAC1_CH1        (                      COMP_CFGRx_INMSEL_2                                                                                   )   /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1)  */
00147 #define LL_COMP_INPUT_MINUS_DAC1_CH2        (                      COMP_CFGRx_INMSEL_2                       | COMP_CFGRx_INMSEL_0                                       )   /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2)  */
00148 #define LL_COMP_INPUT_MINUS_IO1             (                      COMP_CFGRx_INMSEL_2 | COMP_CFGRx_INMSEL_1                                                             )   /*!< Comparator input minus connected to IO1 (pin PB1 for COMP1, pin PE10 for COMP2) */
00149 #define LL_COMP_INPUT_MINUS_IO2             (                      COMP_CFGRx_INMSEL_2 | COMP_CFGRx_INMSEL_1 | COMP_CFGRx_INMSEL_0                                       )   /*!< Comparator input minus connected to IO2 (pin PC4 for COMP1, pin PE7 for COMP2) */
00150 #if defined (COMP_CFGRx_INMSEL_3)
00151 #define LL_COMP_INPUT_MINUS_TPSENS_DAC2CH1  (COMP_CFGRx_INMSEL_3                                                                                                         )   /*!< Comparator input minus connected to  (temp sensor which is exist in ADC for COMP1, DAC2_CH1 for COMP2) */
00152 #define LL_COMP_INPUT_MINUS_VBAT_VDDAP      (COMP_CFGRx_INMSEL_3                                             | COMP_CFGRx_INMSEL_0                                       )   /*!< Comparator input minus connected to  (VBAT/4 for COMP1, VDDAP for COMP2) */
00153 #endif
00154 /**
00155   * @}
00156   */
00157 
00158 /** @defgroup COMP_LL_EC_INPUT_HYSTERESIS Comparator input - Hysteresis
00159   * @{
00160   */
00161 #define LL_COMP_HYSTERESIS_NONE         (0x00000000UL)                            /*!< No hysteresis */
00162 #define LL_COMP_HYSTERESIS_LOW          (                    COMP_CFGRx_HYST_0)   /*!< Hysteresis level low */
00163 #define LL_COMP_HYSTERESIS_MEDIUM       (COMP_CFGRx_HYST_1                    )   /*!< Hysteresis level medium */
00164 #define LL_COMP_HYSTERESIS_HIGH         (COMP_CFGRx_HYST_1 | COMP_CFGRx_HYST_0)   /*!< Hysteresis level high */
00165 /**
00166   * @}
00167   */
00168 
00169 /** @defgroup COMP_LL_EC_OUTPUT_POLARITY Comparator output - Output polarity
00170   * @{
00171   */
00172 #define LL_COMP_OUTPUTPOL_NONINVERTED   (0x00000000UL)          /*!< COMP output polarity is not inverted: comparator output is high when the plus (non-inverting) input is at a higher voltage than the minus (inverting) input */
00173 #define LL_COMP_OUTPUTPOL_INVERTED      (COMP_CFGRx_POLARITY)   /*!< COMP output polarity is inverted: comparator output is low when the plus (non-inverting) input is at a lower voltage than the minus (inverting) input */
00174 /**
00175   * @}
00176   */
00177 
00178 /** @defgroup COMP_LL_EC_OUTPUT_BLANKING_SOURCE Comparator output - Blanking source
00179   * @{
00180   */
00181 #define LL_COMP_BLANKINGSRC_NONE      (0x00000000UL)                                  /*!<Comparator output without blanking */
00182 #define LL_COMP_BLANKINGSRC_TIM1_OC5  (COMP_CFGRx_BLANKING_0)                         /*!< Comparator output blanking source TIM1 OC5 (common to all COMP instances: COMP1, COMP2) */
00183 #define LL_COMP_BLANKINGSRC_TIM2_OC3  (COMP_CFGRx_BLANKING_1)                         /*!< Comparator output blanking source TIM2 OC3 (common to all COMP instances: COMP1, COMP2) */
00184 #define LL_COMP_BLANKINGSRC_TIM3_OC3  (COMP_CFGRx_BLANKING_0 |COMP_CFGRx_BLANKING_1)  /*!< Comparator output blanking source TIM3 OC3 (common to all COMP instances: COMP1, COMP2) */
00185 #define LL_COMP_BLANKINGSRC_TIM3_OC4  (COMP_CFGRx_BLANKING_2)                         /*!< Comparator output blanking source TIM3 OC4 (common to all COMP instances: COMP1, COMP2) */
00186 #define LL_COMP_BLANKINGSRC_TIM8_OC5  (COMP_CFGRx_BLANKING_2|COMP_CFGRx_BLANKING_0)   /*!< Comparator output blanking source TIM8 OC5 (common to all COMP instances: COMP1, COMP2) */
00187 #define LL_COMP_BLANKINGSRC_TIM15_OC1 (COMP_CFGRx_BLANKING_2|COMP_CFGRx_BLANKING_1)   /*!< Comparator output blanking source TIM15 OC1 (common to all COMP instances: COMP1, COMP2) */
00188 /**
00189   * @}
00190   */
00191 
00192 /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
00193   * @{
00194   */
00195 #define LL_COMP_OUTPUT_LEVEL_LOW        (0x00000000UL)           /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
00196 #define LL_COMP_OUTPUT_LEVEL_HIGH       (0x00000001UL)           /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */
00197 /**
00198   * @}
00199   */
00200 /** @defgroup COMP_LL_EC_OUTPUT_BKIN_TIMER Comparator output - Output to BKIN timer
00201   * @{
00202   */
00203 #define LL_COMP_AF_PA6          COMP_OR_AFOPA6       /*!< Comparator Alternate Function PA6 source selected to timer BKIN input  */
00204 #define LL_COMP_AF_PA8          COMP_OR_AFOPA8       /*!< Comparator Alternate Function PA8 source selected to timer BKIN input  */
00205 #define LL_COMP_AF_PB12         COMP_OR_AFOPB12      /*!< Comparator Alternate Function PB12 source selected to timer BKIN input */
00206 #define LL_COMP_AF_PE6          COMP_OR_AFOPE6       /*!< Comparator Alternate Function PE6 source selected to timer BKIN input  */
00207 #define LL_COMP_AF_PE15         COMP_OR_AFOPE15      /*!< Comparator Alternate Function PE15 source selected to timer BKIN input */
00208 #define LL_COMP_AF_PG2          COMP_OR_AFOPG2       /*!< Comparator Alternate Function PG2 source selected to timer BKIN input  */
00209 #define LL_COMP_AF_PG3          COMP_OR_AFOPG3       /*!< Comparator Alternate Function PG3 source selected to timer BKIN input  */
00210 #define LL_COMP_AF_PG4          COMP_OR_AFOPG4       /*!< Comparator Alternate Function PG4 source selected to timer BKIN input  */
00211 #define LL_COMP_AF_PI1          COMP_OR_AFOPI1       /*!< Comparator Alternate Function PI1 source selected to timer BKIN input  */
00212 #define LL_COMP_AF_PI4          COMP_OR_AFOPI4       /*!< Comparator Alternate Function PI4 source selected to timer BKIN input  */
00213 #define LL_COMP_AF_PK2          COMP_OR_AFOPK2       /*!< Comparator Alternate Function PK2 source selected to timer BKIN input  */
00214 /**
00215   * @}
00216   */
00217 
00218 /** @defgroup COMP_LL_EC_HW_DELAYS  Definitions of COMP hardware constraints delays
00219   * @note   Only COMP IP HW delays are defined in COMP LL driver driver,
00220   *         not timeout values.
00221   *         For details on delays values, refer to descriptions in source code
00222   *         above each literal definition.
00223   * @{
00224   */
00225 
00226 /* Delay for comparator startup time.                                         */
00227 /* Note: Delay required to reach propagation delay specification.             */
00228 /* Literal set to maximum value (refer to device datasheet,                   */
00229 /* parameter "tSTART").                                                       */
00230 /* Unit: us                                                                   */
00231 #define LL_COMP_DELAY_STARTUP_US          ( 80UL)  /*!< Delay for COMP startup time */
00232 
00233 /* Delay for comparator voltage scaler stabilization time.                    */
00234 /* Note: Voltage scaler is used when selecting comparator input               */
00235 /*       based on VrefInt: VrefInt or subdivision of VrefInt.                 */
00236 /* Literal set to maximum value (refer to device datasheet,                   */
00237 /* parameter "tSTART_SCALER").                                                */
00238 /* Unit: us                                                                   */
00239 #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ( 200UL)  /*!< Delay for COMP voltage scaler stabilization time */
00240 
00241 /**
00242   * @}
00243   */
00244 
00245 /**
00246   * @}
00247   */
00248 
00249 /* Exported macro ------------------------------------------------------------*/
00250 /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
00251   * @{
00252   */
00253 /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
00254   * @{
00255   */
00256 
00257 /**
00258   * @brief  Write a value in COMP register
00259   * @param  __INSTANCE__ comparator instance
00260   * @param  __REG__ Register to be written
00261   * @param  __VALUE__ Value to be written in the register
00262   * @retval None
00263   */
00264 #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
00265 
00266 /**
00267   * @brief  Read a value in COMP register
00268   * @param  __INSTANCE__ comparator instance
00269   * @param  __REG__ Register to be read
00270   * @retval Register value
00271   */
00272 #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
00273 /**
00274   * @}
00275   */
00276 
00277 /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
00278   * @{
00279   */
00280 
00281 /**
00282   * @brief  Helper macro to select the COMP common instance
00283   *         to which is belonging the selected COMP instance.
00284   * @note   COMP common register instance can be used to
00285   *         set parameters common to several COMP instances.
00286   *         Refer to functions having argument "COMPxy_COMMON" as parameter.
00287   * @param  __COMPx__ COMP instance
00288   * @retval COMP common instance or value "0" if there is no COMP common instance.
00289   */
00290 #define __LL_COMP_COMMON_INSTANCE(__COMPx__)                                   \
00291   (COMP12_COMMON)
00292 
00293 /**
00294   * @}
00295   */
00296 
00297 /**
00298   * @}
00299   */
00300 
00301 /* Exported functions --------------------------------------------------------*/
00302 /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
00303   * @{
00304   */
00305 
00306 /** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration of COMP hierarchical scope: common to several COMP instances
00307   * @{
00308   */
00309 
00310 /**
00311   * @brief  Set window mode of a pair of comparators instances
00312   *         (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
00313   * @rmtoll CFGRx    WINMODE        LL_COMP_SetCommonWindowMode
00314   * @param  COMPxy_COMMON Comparator common instance
00315   *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
00316   * @param  WindowMode This parameter can be one of the following values:
00317   *         @arg @ref LL_COMP_WINDOWMODE_DISABLE
00318   *         @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
00319   * @retval None
00320   */
00321 __STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode)
00322 {
00323   /* Note: On this STM32 series, window mode can be set only                   */
00324   /*       from COMP instance: COMP2.                                         */
00325   MODIFY_REG(COMPxy_COMMON->CFGR, COMP_CFGRx_WINMODE, WindowMode);
00326 }
00327 
00328 /**
00329   * @brief  Get window mode of a pair of comparators instances
00330   *         (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
00331   * @rmtoll CFGRx    WINMODE        LL_COMP_GetCommonWindowMode
00332   * @param  COMPxy_COMMON Comparator common instance
00333   *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
00334   * @retval Returned value can be one of the following values:
00335   *         @arg @ref LL_COMP_WINDOWMODE_DISABLE
00336   *         @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
00337   */
00338 __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON)
00339 {
00340   return (uint32_t)(READ_BIT(COMPxy_COMMON->CFGR, COMP_CFGRx_WINMODE));
00341 }
00342 
00343 /**
00344   * @}
00345   */
00346 
00347 /** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes
00348   * @{
00349   */
00350 
00351 /**
00352   * @brief  Set comparator instance operating mode to adjust power and speed.
00353   * @rmtoll CFGRx    PWRMODE        LL_COMP_SetPowerMode
00354   * @param  COMPx Comparator instance
00355   * @param  PowerMode This parameter can be one of the following values:
00356   *         @arg @ref LL_COMP_POWERMODE_HIGHSPEED
00357   *         @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
00358   *         @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER
00359   * @retval None
00360   */
00361 __STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode)
00362 {
00363   MODIFY_REG(COMPx->CFGR, COMP_CFGRx_PWRMODE, PowerMode);
00364 }
00365 
00366 /**
00367   * @brief  Get comparator instance operating mode to adjust power and speed.
00368   * @rmtoll CFGRx    PWRMODE        LL_COMP_GetPowerMode
00369   * @param  COMPx Comparator instance
00370   * @retval Returned value can be one of the following values:
00371   *         @arg @ref LL_COMP_POWERMODE_HIGHSPEED
00372   *         @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
00373   *         @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER
00374   */
00375 __STATIC_INLINE uint32_t LL_COMP_GetPowerMode(COMP_TypeDef *COMPx)
00376 {
00377   return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_PWRMODE));
00378 }
00379 
00380 /**
00381   * @}
00382   */
00383 
00384 /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
00385   * @{
00386   */
00387 
00388 /**
00389   * @brief  Set comparator inputs minus (inverting) and plus (non-inverting).
00390   * @note   In case of comparator input selected to be connected to IO:
00391   *         GPIO pins are specific to each comparator instance.
00392   *         Refer to description of parameters or to reference manual.
00393   * @note   On this STM32 series, scaler bridge is configurable:
00394   *         to optimize power consumption, this function enables the
00395   *         voltage scaler bridge only when required
00396   *         (when selecting comparator input based on VrefInt: VrefInt or
00397   *         subdivision of VrefInt).
00398   *         - For scaler bridge power consumption values, 
00399   *           refer to device datasheet, parameter "IDDA(SCALER)".
00400   *         - Voltage scaler requires a delay for voltage stabilization.
00401   *           Refer to device datasheet, parameter "tSTART_SCALER".
00402   *         - Scaler bridge is common for all comparator instances,
00403   *           therefore if at least one of the comparator instance
00404   *           is requiring the scaler bridge, it remains enabled.
00405   * @rmtoll CFGRx      INMSEL         LL_COMP_ConfigInputs\n
00406   *         CFGRx      INPSEL         LL_COMP_ConfigInputs\n
00407   *         CFGRx      BRGEN          LL_COMP_ConfigInputs\n
00408   *         CFGRx      SCALEN         LL_COMP_ConfigInputs
00409   * @param  COMPx Comparator instance
00410   * @param  InputMinus This parameter can be one of the following values:
00411   *         @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
00412   *         @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
00413   *         @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
00414   *         @arg @ref LL_COMP_INPUT_MINUS_VREFINT
00415   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
00416   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2 
00417   *         @arg @ref LL_COMP_INPUT_MINUS_IO1
00418   *         @arg @ref LL_COMP_INPUT_MINUS_IO2
00419   *         @arg @ref LL_COMP_INPUT_MINUS_TPSENS_DAC2CH1
00420   *         @arg @ref LL_COMP_INPUT_MINUS_VBAT_VDDAP
00421   * @param  InputPlus This parameter can be one of the following values:
00422   *         @arg @ref LL_COMP_INPUT_PLUS_IO1
00423   *         @arg @ref LL_COMP_INPUT_PLUS_IO2
00424   *         @arg @ref LL_COMP_INPUT_PLUS_DAC2_CH1
00425   * @retval None
00426   */
00427 __STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
00428 {
00429 #if defined (COMP_CFGRx_INP2SEL)
00430   MODIFY_REG(COMPx->CFGR,
00431              COMP_CFGRx_INMSEL | COMP_CFGRx_INPSEL | 
00432              COMP_CFGRx_INP2SEL | 
00433              COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN,
00434              InputMinus | InputPlus);
00435 #else
00436   MODIFY_REG(COMPx->CFGR,
00437              COMP_CFGRx_INMSEL | COMP_CFGRx_INPSEL | 
00438              COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN,
00439              InputMinus | InputPlus);
00440 #endif
00441 }
00442 
00443 /**
00444   * @brief  Set comparator input plus (non-inverting).
00445   * @note   In case of comparator input selected to be connected to IO:
00446   *         GPIO pins are specific to each comparator instance.
00447   *         Refer to description of parameters or to reference manual.
00448   * @rmtoll CFGRx    INPSEL         LL_COMP_SetInputPlus
00449   * @param  COMPx Comparator instance
00450   * @param  InputPlus This parameter can be one of the following values:
00451   *         @arg @ref LL_COMP_INPUT_PLUS_IO1
00452   *         @arg @ref LL_COMP_INPUT_PLUS_IO2
00453   *         @arg @ref LL_COMP_INPUT_PLUS_DAC2_CH1
00454   * @retval None
00455   */
00456 __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
00457 {
00458 #if defined (COMP_CFGRx_INP2SEL)
00459   MODIFY_REG(COMPx->CFGR, COMP_CFGRx_INPSEL | COMP_CFGRx_INP2SEL , InputPlus);
00460 #else
00461   MODIFY_REG(COMPx->CFGR, COMP_CFGRx_INPSEL , InputPlus);
00462 #endif
00463 }
00464 
00465 /**
00466   * @brief  Get comparator input plus (non-inverting).
00467   * @note   In case of comparator input selected to be connected to IO:
00468   *         GPIO pins are specific to each comparator instance.
00469   *         Refer to description of parameters or to reference manual.
00470   * @rmtoll CFGRx    INPSEL         LL_COMP_GetInputPlus
00471   * @param  COMPx Comparator instance
00472   * @retval Returned value can be one of the following values:
00473   *         @arg @ref LL_COMP_INPUT_PLUS_IO1
00474   *         @arg @ref LL_COMP_INPUT_PLUS_IO2
00475   *         @arg @ref LL_COMP_INPUT_PLUS_DAC2_CH1
00476   */
00477 __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(COMP_TypeDef *COMPx)
00478 {
00479 #if defined (COMP_CFGRx_INP2SEL)
00480   return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_INPSEL | COMP_CFGRx_INP2SEL));
00481 #else
00482   return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_INPSEL));
00483 #endif
00484 }
00485 
00486 /**
00487   * @brief  Set comparator input minus (inverting).
00488   * @note   In case of comparator input selected to be connected to IO:
00489   *         GPIO pins are specific to each comparator instance.
00490   *         Refer to description of parameters or to reference manual.
00491   * @note   On this STM32 series, scaler bridge is configurable:
00492   *         to optimize power consumption, this function enables the
00493   *         voltage scaler bridge only when required
00494   *         (when selecting comparator input based on VrefInt: VrefInt or
00495   *         subdivision of VrefInt).
00496   *         - For scaler bridge power consumption values, 
00497   *           refer to device datasheet, parameter "IDDA(SCALER)".
00498   *         - Voltage scaler requires a delay for voltage stabilization.
00499   *           Refer to device datasheet, parameter "tSTART_SCALER".
00500   *         - Scaler bridge is common for all comparator instances,
00501   *           therefore if at least one of the comparator instance
00502   *           is requiring the scaler bridge, it remains enabled.
00503   * @rmtoll CFGRx     INMSEL         LL_COMP_SetInputMinus\n
00504   *         CFGRx     BRGEN          LL_COMP_SetInputMinus\n
00505   *         CFGRx     SCALEN         LL_COMP_SetInputMinus
00506   * @param  COMPx Comparator instance
00507   * @param  InputMinus This parameter can be one of the following values:
00508   *         @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
00509   *         @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
00510   *         @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
00511   *         @arg @ref LL_COMP_INPUT_MINUS_VREFINT
00512   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
00513   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
00514   *         @arg @ref LL_COMP_INPUT_MINUS_IO1
00515   *         @arg @ref LL_COMP_INPUT_MINUS_IO2
00516   *         @arg @ref LL_COMP_INPUT_MINUS_TPSENS_DAC2CH1
00517   *         @arg @ref LL_COMP_INPUT_MINUS_VBAT_VDDAP
00518   * @retval None
00519   */
00520 __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
00521 {
00522   MODIFY_REG(COMPx->CFGR, COMP_CFGRx_INMSEL | COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN, InputMinus);
00523 }
00524 
00525 /**
00526   * @brief  Get comparator input minus (inverting).
00527   * @note   In case of comparator input selected to be connected to IO:
00528   *         GPIO pins are specific to each comparator instance.
00529   *         Refer to description of parameters or to reference manual.
00530   * @rmtoll CFGRx     INMSEL         LL_COMP_GetInputMinus\n
00531   *         CFGRx     BRGEN          LL_COMP_GetInputMinus\n
00532   *         CFGRx     SCALEN         LL_COMP_GetInputMinus
00533   * @param  COMPx Comparator instance
00534   * @retval Returned value can be one of the following values:
00535   *         @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
00536   *         @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
00537   *         @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
00538   *         @arg @ref LL_COMP_INPUT_MINUS_VREFINT
00539   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
00540   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2  
00541   *         @arg @ref LL_COMP_INPUT_MINUS_IO1
00542   *         @arg @ref LL_COMP_INPUT_MINUS_IO2
00543   *         @arg @ref LL_COMP_INPUT_MINUS_TPSENS_DAC2CH1
00544   *         @arg @ref LL_COMP_INPUT_MINUS_VBAT_VDDAP
00545   */
00546 __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(COMP_TypeDef *COMPx)
00547 {
00548   return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_INMSEL | COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN));
00549 }
00550 
00551 /**
00552   * @brief  Set comparator instance hysteresis mode of the input minus (inverting input).
00553   * @rmtoll CFGRx    HYST           LL_COMP_SetInputHysteresis
00554   * @param  COMPx Comparator instance
00555   * @param  InputHysteresis This parameter can be one of the following values:
00556   *         @arg @ref LL_COMP_HYSTERESIS_NONE
00557   *         @arg @ref LL_COMP_HYSTERESIS_LOW
00558   *         @arg @ref LL_COMP_HYSTERESIS_MEDIUM
00559   *         @arg @ref LL_COMP_HYSTERESIS_HIGH
00560   * @retval None
00561   */
00562 __STATIC_INLINE void LL_COMP_SetInputHysteresis(COMP_TypeDef *COMPx, uint32_t InputHysteresis)
00563 {
00564   MODIFY_REG(COMPx->CFGR, COMP_CFGRx_HYST, InputHysteresis);
00565 }
00566 
00567 /**
00568   * @brief  Get comparator instance hysteresis mode of the minus (inverting) input.
00569   * @rmtoll CSR      HYST           LL_COMP_GetInputHysteresis
00570   * @param  COMPx Comparator instance
00571   * @retval Returned value can be one of the following values:
00572   *         @arg @ref LL_COMP_HYSTERESIS_NONE
00573   *         @arg @ref LL_COMP_HYSTERESIS_LOW
00574   *         @arg @ref LL_COMP_HYSTERESIS_MEDIUM
00575   *         @arg @ref LL_COMP_HYSTERESIS_HIGH
00576   */
00577 __STATIC_INLINE uint32_t LL_COMP_GetInputHysteresis(COMP_TypeDef *COMPx)
00578 {
00579   return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_HYST));
00580 }
00581 
00582 /**
00583   * @}
00584   */
00585 
00586 /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
00587   * @{
00588   */
00589 
00590 /**
00591   * @brief  Set comparator instance output polarity.
00592   * @rmtoll CFGRx    POLARITY       LL_COMP_SetOutputPolarity
00593   * @param  COMPx Comparator instance
00594   * @param  OutputPolarity This parameter can be one of the following values:
00595   *         @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
00596   *         @arg @ref LL_COMP_OUTPUTPOL_INVERTED
00597   * @retval None
00598   */
00599 __STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
00600 {
00601   MODIFY_REG(COMPx->CFGR, COMP_CFGRx_POLARITY, OutputPolarity);
00602 }
00603 
00604 /**
00605   * @brief  Get comparator instance output polarity.
00606   * @rmtoll CFGRx    POLARITY       LL_COMP_GetOutputPolarity
00607   * @param  COMPx Comparator instance
00608   * @retval Returned value can be one of the following values:
00609   *         @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
00610   *         @arg @ref LL_COMP_OUTPUTPOL_INVERTED
00611   */
00612 __STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(COMP_TypeDef *COMPx)
00613 {
00614   return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_POLARITY));
00615 }
00616 
00617 /**
00618   * @brief  Set comparator instance blanking source.
00619   * @note   Blanking source may be specific to each comparator instance.
00620   *         Refer to description of parameters or to reference manual.
00621   * @note   Availability of parameters of blanking source from timer
00622   *         depends on timers availability on the selected device.
00623   * @rmtoll CFGR     BLANKING       LL_COMP_SetOutputBlankingSource
00624   * @param  COMPx Comparator instance
00625   * @param  BlankingSource This parameter can be one of the following values:
00626   *         @arg @ref LL_COMP_BLANKINGSRC_NONE
00627   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5  
00628   *         @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3
00629   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3
00630   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4
00631   *         @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5
00632   *         @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1 
00633   * @retval None
00634   */
00635 __STATIC_INLINE void LL_COMP_SetOutputBlankingSource(COMP_TypeDef *COMPx, uint32_t BlankingSource)
00636 {
00637   MODIFY_REG(COMPx->CFGR, COMP_CFGRx_BLANKING, BlankingSource);
00638 }
00639 
00640 /**
00641   * @brief  Get comparator instance blanking source.
00642   * @note   Availability of parameters of blanking source from timer
00643   *         depends on timers availability on the selected device.
00644   * @note   Blanking source may be specific to each comparator instance.
00645   *         Refer to description of parameters or to reference manual.
00646   * @rmtoll CFGR     BLANKING       LL_COMP_GetOutputBlankingSource
00647   * @param  COMPx Comparator instance
00648   * @retval Returned value can be one of the following values:
00649   *         @arg @ref LL_COMP_BLANKINGSRC_NONE
00650   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5 
00651   *         @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3 
00652   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3
00653   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4 
00654   *         @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5  
00655   *         @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1  
00656   */
00657 __STATIC_INLINE uint32_t LL_COMP_GetOutputBlankingSource(COMP_TypeDef *COMPx)
00658 {
00659   return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_BLANKING));
00660 }
00661 
00662 /** @brief  Set the output alternate function in the Option register
00663   *         in order to be used with the alternate function
00664   *         of the timer break input.
00665   * @rmtoll OR    AFOP       COMP_LL_EC_OUTPUT_BKIN_TIMER
00666   * @param  COMPx specifies the instance.
00667   * @param  CompAFx specifies the Alternate Function source selection.
00668   *          This parameter can be one of the following values:
00669   *            @arg @ref LL_COMP_AF_PA6
00670   *            @arg @ref LL_COMP_AF_PA8
00671   *            @arg @ref LL_COMP_AF_PB12
00672   *            @arg @ref LL_COMP_AF_PE6
00673   *            @arg @ref LL_COMP_AF_PE15
00674   *            @arg @ref LL_COMP_AF_PG2
00675   *            @arg @ref LL_COMP_AF_PG3
00676   *            @arg @ref LL_COMP_AF_PG4
00677   *            @arg @ref LL_COMP_AF_PI1
00678   *            @arg @ref LL_COMP_AF_PI4
00679   *            @arg @ref LL_COMP_AF_PK2
00680   * @retval None
00681   */
00682 __STATIC_INLINE void LL_COMP_SetOutputAlternateFunction(COMP_TypeDef *COMPx, uint32_t CompAFx)
00683 {
00684   MODIFY_REG(COMP12->OR, 0x7FFUL, (COMPx == COMP1) ? ((~CompAFx) & 0x7FFUL) : CompAFx);
00685 }
00686 
00687 /** @brief  Get the output alternate function from the Option register.
00688   * @rmtoll OR     AFOP       COMP_LL_EC_OUTPUT_BKIN_TIMER
00689   * @param  COMPx specifies the Comparator instance.
00690   * @retval Returned value can be one of the following values:
00691   *            @arg @ref LL_COMP_AF_PA6
00692   *            @arg @ref LL_COMP_AF_PA8
00693   *            @arg @ref LL_COMP_AF_PB12
00694   *            @arg @ref LL_COMP_AF_PE6
00695   *            @arg @ref LL_COMP_AF_PE15
00696   *            @arg @ref LL_COMP_AF_PG2
00697   *            @arg @ref LL_COMP_AF_PG3
00698   *            @arg @ref LL_COMP_AF_PG4
00699   *            @arg @ref LL_COMP_AF_PI1
00700   *            @arg @ref LL_COMP_AF_PI4
00701   *            @arg @ref LL_COMP_AF_PK2
00702   */
00703 __STATIC_INLINE uint32_t LL_COMP_GetOutputAlternateFunction(COMP_TypeDef *COMPx )
00704 {
00705   return (uint32_t) ((COMPx == COMP1) ? ((~COMP12->OR) & 0x7FFUL) : (COMP12->OR &  0x7FFUL));
00706 }
00707 
00708 /**
00709   * @}
00710   */
00711 
00712 /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
00713   * @{
00714   */
00715 
00716 /**
00717   * @brief  Enable comparator instance.
00718   * @note   After enable from off state, comparator requires a delay
00719   *         to reach reach propagation delay specification.
00720   *         Refer to device datasheet, parameter "tSTART".
00721   * @rmtoll CFGR     EN             LL_COMP_Enable
00722   * @param  COMPx Comparator instance
00723   * @retval None
00724   */
00725 __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
00726 {
00727   SET_BIT(COMPx->CFGR, COMP_CFGRx_EN);
00728 }
00729 
00730 /**
00731   * @brief  Disable comparator instance.
00732   * @rmtoll CFGR     EN             LL_COMP_Disable
00733   * @param  COMPx Comparator instance
00734   * @retval None
00735   */
00736 __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
00737 {
00738   CLEAR_BIT(COMPx->CFGR, COMP_CFGRx_EN);
00739 }
00740 
00741 /**
00742   * @brief  Get comparator enable state
00743   *         (0: COMP is disabled, 1: COMP is enabled)
00744   * @rmtoll CFGR     EN             LL_COMP_IsEnabled
00745   * @param  COMPx Comparator instance
00746   * @retval State of bit (1 or 0).
00747   */
00748 __STATIC_INLINE uint32_t LL_COMP_IsEnabled(COMP_TypeDef *COMPx)
00749 {
00750   return ((READ_BIT(COMPx->CFGR, COMP_CFGRx_EN) == (COMP_CFGRx_EN)) ? 1UL : 0UL);
00751 }
00752 
00753 /**
00754   * @brief  Lock comparator instance.
00755   * @note   Once locked, comparator configuration can be accessed in read-only.
00756   * @note   The only way to unlock the comparator is a device hardware reset.
00757   * @rmtoll CFGR     LOCK           LL_COMP_Lock
00758   * @param  COMPx Comparator instance
00759   * @retval None
00760   */
00761 __STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx)
00762 {
00763   SET_BIT(COMPx->CFGR, COMP_CFGRx_LOCK);
00764 }
00765 
00766 /**
00767   * @brief  Get comparator lock state
00768   *         (0: COMP is unlocked, 1: COMP is locked).
00769   * @note   Once locked, comparator configuration can be accessed in read-only.
00770   * @note   The only way to unlock the comparator is a device hardware reset.
00771   * @rmtoll CFGR     LOCK           LL_COMP_IsLocked
00772   * @param  COMPx Comparator instance
00773   * @retval State of bit (1 or 0).
00774   */
00775 __STATIC_INLINE uint32_t LL_COMP_IsLocked(COMP_TypeDef *COMPx)
00776 {
00777   return ((READ_BIT(COMPx->CFGR, COMP_CFGRx_LOCK) == (COMP_CFGRx_LOCK)) ? 1UL : 0UL);
00778 }
00779 
00780 /**
00781   * @brief  Read comparator instance output level.
00782   * @note   The comparator output level depends on the selected polarity
00783   *         (Refer to function @ref LL_COMP_SetOutputPolarity()).
00784   *         If the comparator polarity is not inverted:
00785   *          - Comparator output is low when the input plus
00786   *            is at a lower voltage than the input minus
00787   *          - Comparator output is high when the input plus
00788   *            is at a higher voltage than the input minus
00789   *         If the comparator polarity is inverted:
00790   *          - Comparator output is high when the input plus
00791   *            is at a lower voltage than the input minus
00792   *          - Comparator output is low when the input plus
00793   *            is at a higher voltage than the input minus
00794   * @rmtoll CFGR     VALUE          LL_COMP_ReadOutputLevel
00795   * @param  COMPx Comparator instance
00796   * @retval Returned value can be one of the following values:
00797   *         @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
00798   *         @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
00799   */
00800 __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(COMP_TypeDef *COMPx)
00801 {
00802   if (COMPx == COMP1)
00803   {
00804     return (uint32_t)(READ_BIT(COMP12->SR, COMP_SR_C1VAL));
00805   }
00806   else
00807   {
00808     return (uint32_t)((READ_BIT(COMP12->SR, COMP_SR_C2VAL))>> 1); 
00809   }
00810 }
00811 
00812 /**
00813   * @}
00814   */
00815 
00816 #if defined(USE_FULL_LL_DRIVER)
00817 /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
00818   * @{
00819   */
00820 
00821 ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
00822 ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct);
00823 void        LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
00824 
00825 /**
00826   * @}
00827   */
00828 #endif /* USE_FULL_LL_DRIVER */
00829 
00830 /**
00831   * @}
00832   */
00833 
00834 /**
00835   * @}
00836   */
00837 
00838 #endif /* COMP1 || COMP2 */
00839 
00840 /**
00841   * @}
00842   */
00843 
00844 #ifdef __cplusplus
00845 }
00846 #endif
00847 
00848 #endif /* __STM32H7xx_LL_COMP_H */
00849 
00850