2 ******************************************************************************
3 * @file stm32h7xx_ll_comp.c
4 * @author MCD Application Team
5 * @brief COMP LL module driver
6 ******************************************************************************
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
12 * This software component is licensed by ST under BSD 3-Clause license,
13 * the "License"; You may not use this file except in compliance with the
14 * License. You may obtain a copy of the License at:
15 * opensource.org/licenses/BSD-3-Clause
17 ******************************************************************************
19 #if defined(USE_FULL_LL_DRIVER)
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32h7xx_ll_comp.h"
24 #ifdef USE_FULL_ASSERT
25 #include "stm32_assert.h"
27 #define assert_param(expr) ((void)0U)
30 /** @addtogroup STM32H7xx_LL_Driver
34 #if defined (COMP1) || defined (COMP2)
36 /** @addtogroup COMP_LL COMP
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 /* Private constants ---------------------------------------------------------*/
43 /* Private macros ------------------------------------------------------------*/
45 /** @addtogroup COMP_LL_Private_Macros
49 /* Check of parameters for configuration of COMP hierarchical scope: */
52 #define IS_LL_COMP_POWER_MODE(__POWER_MODE__) \
53 ( ((__POWER_MODE__) == LL_COMP_POWERMODE_HIGHSPEED) \
54 || ((__POWER_MODE__) == LL_COMP_POWERMODE_MEDIUMSPEED) \
55 || ((__POWER_MODE__) == LL_COMP_POWERMODE_ULTRALOWPOWER) \
58 /* Note: On this STM32 serie, comparator input plus parameters are */
59 /* the same on all COMP instances. */
60 /* However, comparator instance kept as macro parameter for */
61 /* compatibility with other STM32 families. */
62 #if defined (COMP_CFGRx_INP2SEL)
63 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
64 ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
65 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \
66 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_DAC2_CH1))
68 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
69 ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
70 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2))
73 /* Note: On this STM32 serie, comparator input minus parameters are */
74 /* the same on all COMP instances. */
75 /* However, comparator instance kept as macro parameter for */
76 /* compatibility with other STM32 families. */
77 #if defined (COMP_CFGRx_INMSEL_3)
78 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
79 ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
80 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
81 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
82 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
83 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
84 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \
85 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
86 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
87 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_TPSENS_DAC2CH1) \
88 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VBAT_VDDAP))
90 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
91 ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
92 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
93 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
94 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
95 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
96 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \
97 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
98 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2))
101 #define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__) \
102 ( ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE) \
103 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_LOW) \
104 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_MEDIUM) \
105 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_HIGH) \
108 #define IS_LL_COMP_OUTPUT_POLARITY(__POLARITY__) \
109 ( ((__POLARITY__) == LL_COMP_OUTPUTPOL_NONINVERTED) \
110 || ((__POLARITY__) == LL_COMP_OUTPUTPOL_INVERTED) \
113 #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__OUTPUT_BLANKING_SOURCE__) \
114 ( ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) \
115 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5) \
116 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3) \
117 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3) \
118 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4) \
119 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5) \
120 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1) \
128 /* Private function prototypes -----------------------------------------------*/
130 /* Exported functions --------------------------------------------------------*/
131 /** @addtogroup COMP_LL_Exported_Functions
135 /** @addtogroup COMP_LL_EF_Init
140 * @brief De-initialize registers of the selected COMP instance
141 * to their default reset values.
142 * @note If comparator is locked, de-initialization by software is
144 * The only way to unlock the comparator is a device hardware reset.
145 * @param COMPx COMP instance
146 * @retval An ErrorStatus enumeration value:
147 * - SUCCESS: COMP registers are de-initialized
148 * - ERROR: COMP registers are not de-initialized
150 ErrorStatus
LL_COMP_DeInit(COMP_TypeDef
*COMPx
)
152 ErrorStatus status
= SUCCESS
;
154 /* Check the parameters */
155 assert_param(IS_COMP_ALL_INSTANCE(COMPx
));
157 /* Note: Hardware constraint (refer to description of this function): */
158 /* COMP instance must not be locked. */
159 if(LL_COMP_IsLocked(COMPx
) == 0UL)
161 LL_COMP_WriteReg((COMPx
), CFGR
, 0x00000000UL
);
166 /* Comparator instance is locked: de-initialization by software is */
168 /* The only way to unlock the comparator is a device hardware reset. */
176 * @brief Initialize some features of COMP instance.
177 * @note This function configures features of the selected COMP instance.
178 * Some features are also available at scope COMP common instance
179 * (common to several COMP instances).
180 * Refer to functions having argument "COMPxy_COMMON" as parameter.
181 * @param COMPx COMP instance
182 * @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure
183 * @retval An ErrorStatus enumeration value:
184 * - SUCCESS: COMP registers are initialized
185 * - ERROR: COMP registers are not initialized
187 ErrorStatus
LL_COMP_Init(COMP_TypeDef
*COMPx
, LL_COMP_InitTypeDef
*COMP_InitStruct
)
189 ErrorStatus status
= SUCCESS
;
191 /* Check the parameters */
192 assert_param(IS_COMP_ALL_INSTANCE(COMPx
));
193 assert_param(IS_LL_COMP_POWER_MODE(COMP_InitStruct
->PowerMode
));
194 assert_param(IS_LL_COMP_INPUT_PLUS(COMPx
, COMP_InitStruct
->InputPlus
));
195 assert_param(IS_LL_COMP_INPUT_MINUS(COMPx
, COMP_InitStruct
->InputMinus
));
196 assert_param(IS_LL_COMP_INPUT_HYSTERESIS(COMP_InitStruct
->InputHysteresis
));
197 assert_param(IS_LL_COMP_OUTPUT_POLARITY(COMP_InitStruct
->OutputPolarity
));
198 assert_param(IS_LL_COMP_OUTPUT_BLANKING_SOURCE(COMP_InitStruct
->OutputBlankingSource
));
200 /* Note: Hardware constraint (refer to description of this function) */
201 /* COMP instance must not be locked. */
202 if(LL_COMP_IsLocked(COMPx
) == 0UL)
204 /* Configuration of comparator instance : */
208 /* - InputHysteresis */
209 /* - OutputPolarity */
210 /* - OutputBlankingSource */
211 #if defined (COMP_CFGRx_INP2SEL)
212 MODIFY_REG(COMPx
->CFGR
,
220 | COMP_CFGRx_POLARITY
221 | COMP_CFGRx_BLANKING
223 COMP_InitStruct
->PowerMode
224 | COMP_InitStruct
->InputPlus
225 | COMP_InitStruct
->InputMinus
226 | COMP_InitStruct
->InputHysteresis
227 | COMP_InitStruct
->OutputPolarity
228 | COMP_InitStruct
->OutputBlankingSource
231 MODIFY_REG(COMPx
->CFGR
,
238 | COMP_CFGRx_POLARITY
239 | COMP_CFGRx_BLANKING
241 COMP_InitStruct
->PowerMode
242 | COMP_InitStruct
->InputPlus
243 | COMP_InitStruct
->InputMinus
244 | COMP_InitStruct
->InputHysteresis
245 | COMP_InitStruct
->OutputPolarity
246 | COMP_InitStruct
->OutputBlankingSource
252 /* Initialization error: COMP instance is locked. */
260 * @brief Set each @ref LL_COMP_InitTypeDef field to default value.
261 * @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure
262 * whose fields will be set to default values.
265 void LL_COMP_StructInit(LL_COMP_InitTypeDef
*COMP_InitStruct
)
267 /* Set COMP_InitStruct fields to default values */
268 COMP_InitStruct
->PowerMode
= LL_COMP_POWERMODE_ULTRALOWPOWER
;
269 COMP_InitStruct
->InputPlus
= LL_COMP_INPUT_PLUS_IO1
;
270 COMP_InitStruct
->InputMinus
= LL_COMP_INPUT_MINUS_VREFINT
;
271 COMP_InitStruct
->InputHysteresis
= LL_COMP_HYSTERESIS_NONE
;
272 COMP_InitStruct
->OutputPolarity
= LL_COMP_OUTPUTPOL_NONINVERTED
;
273 COMP_InitStruct
->OutputBlankingSource
= LL_COMP_BLANKINGSRC_NONE
;
288 #endif /* COMP1 || COMP2 */
294 #endif /* USE_FULL_LL_DRIVER */
296 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/