STM32H735xx HAL User Manual
stm32h7xx_ll_comp.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32h7xx_ll_comp.c
00004   * @author  MCD Application Team
00005   * @brief   COMP LL module driver
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 #if defined(USE_FULL_LL_DRIVER)
00019 
00020 /* Includes ------------------------------------------------------------------*/
00021 #include "stm32h7xx_ll_comp.h"
00022 
00023 #ifdef  USE_FULL_ASSERT
00024  #include "stm32_assert.h"
00025 #else
00026  #define assert_param(expr) ((void)0U)
00027 #endif
00028 
00029 /** @addtogroup STM32H7xx_LL_Driver
00030   * @{
00031   */
00032 
00033 #if defined (COMP1) || defined (COMP2)
00034 
00035 /** @addtogroup COMP_LL COMP
00036   * @{
00037   */
00038 
00039 /* Private types -------------------------------------------------------------*/
00040 /* Private variables ---------------------------------------------------------*/
00041 /* Private constants ---------------------------------------------------------*/
00042 /* Private macros ------------------------------------------------------------*/
00043 
00044 /** @addtogroup COMP_LL_Private_Macros
00045   * @{
00046   */
00047 
00048 /* Check of parameters for configuration of COMP hierarchical scope:          */
00049 /* COMP instance.                                                             */
00050 
00051 #define IS_LL_COMP_POWER_MODE(__POWER_MODE__)                                  \
00052   (   ((__POWER_MODE__) == LL_COMP_POWERMODE_HIGHSPEED)                        \
00053    || ((__POWER_MODE__) == LL_COMP_POWERMODE_MEDIUMSPEED)                      \
00054    || ((__POWER_MODE__) == LL_COMP_POWERMODE_ULTRALOWPOWER)                    \
00055   )
00056 
00057 /* Note: On this STM32 series, comparator input plus parameters are            */
00058 /*       the same on all COMP instances.                                      */
00059 /*       However, comparator instance kept as macro parameter for             */
00060 /*       compatibility with other STM32 families.                             */
00061 #if defined (COMP_CFGRx_INP2SEL)
00062 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__)               \
00063   (   ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1)                             \
00064    || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2)                             \
00065    || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_DAC2_CH1))
00066 #else
00067 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__)               \
00068   (   ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1)                             \
00069    || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2))
00070 #endif
00071     
00072 /* Note: On this STM32 series, comparator input minus parameters are           */
00073 /*       the same on all COMP instances.                                      */
00074 /*       However, comparator instance kept as macro parameter for             */
00075 /*       compatibility with other STM32 families.                             */
00076 #if defined (COMP_CFGRx_INMSEL_3)
00077 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__)             \
00078   (   ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT)                    \
00079    || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT)                    \
00080    || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT)                    \
00081    || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT)                       \
00082    || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1)                      \
00083    || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2)                      \
00084    || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1)                           \
00085    || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2)                           \
00086    || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_TPSENS_DAC2CH1)                \
00087    || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VBAT_VDDAP))
00088 #else
00089 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__)             \
00090   (   ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT)                    \
00091    || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT)                    \
00092    || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT)                    \
00093    || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT)                       \
00094    || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1)                      \
00095    || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2)                      \
00096    || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1)                           \
00097    || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2))
00098 #endif
00099     
00100 #define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__)                      \
00101   (   ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE)                      \
00102    || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_LOW)                       \
00103    || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_MEDIUM)                    \
00104    || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_HIGH)                      \
00105   )
00106 
00107 #define IS_LL_COMP_OUTPUT_POLARITY(__POLARITY__)                               \
00108   (   ((__POLARITY__) == LL_COMP_OUTPUTPOL_NONINVERTED)                        \
00109    || ((__POLARITY__) == LL_COMP_OUTPUTPOL_INVERTED)                           \
00110   )
00111 
00112 #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__OUTPUT_BLANKING_SOURCE__)          \
00113   (   ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)               \
00114    || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5)           \
00115    || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3)           \
00116    || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3)           \
00117    || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4)           \
00118    || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5)           \
00119    || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1)          \
00120   )
00121   
00122 /**
00123   * @}
00124   */
00125 
00126 
00127 /* Private function prototypes -----------------------------------------------*/
00128 
00129 /* Exported functions --------------------------------------------------------*/
00130 /** @addtogroup COMP_LL_Exported_Functions
00131   * @{
00132   */
00133 
00134 /** @addtogroup COMP_LL_EF_Init
00135   * @{
00136   */
00137 
00138 /**
00139   * @brief  De-initialize registers of the selected COMP instance
00140   *         to their default reset values.
00141   * @note   If comparator is locked, de-initialization by software is
00142   *         not possible.
00143   *         The only way to unlock the comparator is a device hardware reset.
00144   * @param  COMPx COMP instance
00145   * @retval An ErrorStatus enumeration value:
00146   *          - SUCCESS: COMP registers are de-initialized
00147   *          - ERROR: COMP registers are not de-initialized
00148   */
00149 ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx)
00150 {
00151   ErrorStatus status = SUCCESS;
00152   
00153   /* Check the parameters */
00154   assert_param(IS_COMP_ALL_INSTANCE(COMPx));
00155   
00156   /* Note: Hardware constraint (refer to description of this function):       */
00157   /*       COMP instance must not be locked.                                  */
00158   if(LL_COMP_IsLocked(COMPx) == 0UL)
00159   {
00160     LL_COMP_WriteReg((COMPx), CFGR, 0x00000000UL);
00161 
00162   }
00163   else
00164   {
00165     /* Comparator instance is locked: de-initialization by software is         */
00166     /* not possible.                                                           */
00167     /* The only way to unlock the comparator is a device hardware reset.       */
00168     status = ERROR;
00169   }
00170   
00171   return status;
00172 }
00173 
00174 /**
00175   * @brief  Initialize some features of COMP instance.
00176   * @note   This function configures features of the selected COMP instance.
00177   *         Some features are also available at scope COMP common instance
00178   *         (common to several COMP instances).
00179   *         Refer to functions having argument "COMPxy_COMMON" as parameter.
00180   * @param  COMPx COMP instance
00181   * @param  COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure
00182   * @retval An ErrorStatus enumeration value:
00183   *          - SUCCESS: COMP registers are initialized
00184   *          - ERROR: COMP registers are not initialized
00185   */
00186 ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct)
00187 {
00188   ErrorStatus status = SUCCESS;
00189   
00190   /* Check the parameters */
00191   assert_param(IS_COMP_ALL_INSTANCE(COMPx));
00192   assert_param(IS_LL_COMP_POWER_MODE(COMP_InitStruct->PowerMode));
00193   assert_param(IS_LL_COMP_INPUT_PLUS(COMPx, COMP_InitStruct->InputPlus));
00194   assert_param(IS_LL_COMP_INPUT_MINUS(COMPx, COMP_InitStruct->InputMinus));
00195   assert_param(IS_LL_COMP_INPUT_HYSTERESIS(COMP_InitStruct->InputHysteresis));
00196   assert_param(IS_LL_COMP_OUTPUT_POLARITY(COMP_InitStruct->OutputPolarity));
00197   assert_param(IS_LL_COMP_OUTPUT_BLANKING_SOURCE(COMP_InitStruct->OutputBlankingSource));
00198   
00199   /* Note: Hardware constraint (refer to description of this function)        */
00200   /*       COMP instance must not be locked.                                  */
00201   if(LL_COMP_IsLocked(COMPx) == 0UL)
00202   {
00203     /* Configuration of comparator instance :                                 */
00204     /*  - PowerMode                                                           */
00205     /*  - InputPlus                                                           */
00206     /*  - InputMinus                                                          */
00207     /*  - InputHysteresis                                                     */
00208     /*  - OutputPolarity                                                      */
00209     /*  - OutputBlankingSource                                                */
00210 #if defined (COMP_CFGRx_INP2SEL)
00211     MODIFY_REG(COMPx->CFGR,
00212                  COMP_CFGRx_PWRMODE
00213                | COMP_CFGRx_INPSEL
00214                | COMP_CFGRx_INP2SEL
00215                | COMP_CFGRx_SCALEN
00216                | COMP_CFGRx_BRGEN
00217                | COMP_CFGRx_INMSEL
00218                | COMP_CFGRx_HYST
00219                | COMP_CFGRx_POLARITY
00220                | COMP_CFGRx_BLANKING
00221               ,
00222                  COMP_InitStruct->PowerMode
00223                | COMP_InitStruct->InputPlus
00224                | COMP_InitStruct->InputMinus
00225                | COMP_InitStruct->InputHysteresis
00226                | COMP_InitStruct->OutputPolarity
00227                | COMP_InitStruct->OutputBlankingSource
00228               );
00229 #else
00230     MODIFY_REG(COMPx->CFGR,
00231                  COMP_CFGRx_PWRMODE
00232                | COMP_CFGRx_INPSEL
00233                | COMP_CFGRx_SCALEN
00234                | COMP_CFGRx_BRGEN
00235                | COMP_CFGRx_INMSEL
00236                | COMP_CFGRx_HYST
00237                | COMP_CFGRx_POLARITY
00238                | COMP_CFGRx_BLANKING
00239               ,
00240                  COMP_InitStruct->PowerMode
00241                | COMP_InitStruct->InputPlus
00242                | COMP_InitStruct->InputMinus
00243                | COMP_InitStruct->InputHysteresis
00244                | COMP_InitStruct->OutputPolarity
00245                | COMP_InitStruct->OutputBlankingSource
00246               );
00247 #endif
00248   }
00249   else
00250   {
00251     /* Initialization error: COMP instance is locked.                         */
00252     status = ERROR;
00253   }
00254   
00255   return status;
00256 }
00257 
00258 /**
00259   * @brief Set each @ref LL_COMP_InitTypeDef field to default value.
00260   * @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure
00261   *                        whose fields will be set to default values.
00262   * @retval None
00263   */
00264 void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct)
00265 {
00266   /* Set COMP_InitStruct fields to default values */
00267   COMP_InitStruct->PowerMode            = LL_COMP_POWERMODE_ULTRALOWPOWER;
00268   COMP_InitStruct->InputPlus            = LL_COMP_INPUT_PLUS_IO1;
00269   COMP_InitStruct->InputMinus           = LL_COMP_INPUT_MINUS_VREFINT;
00270   COMP_InitStruct->InputHysteresis      = LL_COMP_HYSTERESIS_NONE;
00271   COMP_InitStruct->OutputPolarity       = LL_COMP_OUTPUTPOL_NONINVERTED;
00272   COMP_InitStruct->OutputBlankingSource = LL_COMP_BLANKINGSRC_NONE;
00273 }
00274 
00275 /**
00276   * @}
00277   */
00278 
00279 /**
00280   * @}
00281   */
00282 
00283 /**
00284   * @}
00285   */
00286 
00287 #endif /* COMP1 || COMP2 */
00288 
00289 /**
00290   * @}
00291   */
00292 
00293 #endif /* USE_FULL_LL_DRIVER */
00294