2 ******************************************************************************
3 * @file stm32h7xx_ll_opamp.c
4 * @author MCD Application Team
5 * @brief OPAMP 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_opamp.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 (OPAMP1) || defined (OPAMP2)
35 /** @addtogroup OPAMP_LL OPAMP
39 /* Private types -------------------------------------------------------------*/
40 /* Private variables ---------------------------------------------------------*/
41 /* Private constants ---------------------------------------------------------*/
42 /* Private macros ------------------------------------------------------------*/
44 /** @addtogroup OPAMP_LL_Private_Macros
48 /* Check of parameters for configuration of OPAMP hierarchical scope: */
51 #define IS_LL_OPAMP_POWER_MODE(__POWER_MODE__) \
52 ( ((__POWER_MODE__) == LL_OPAMP_POWERMODE_NORMAL) \
53 || ((__POWER_MODE__) == LL_OPAMP_POWERMODE_HIGHSPEED))
55 #define IS_LL_OPAMP_FUNCTIONAL_MODE(__FUNCTIONAL_MODE__) \
56 ( ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_STANDALONE) \
57 || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_FOLLOWER) \
58 || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA) \
59 || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA_IO0) \
60 || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA_IO0_BIAS) \
61 || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA_IO0_IO1_BIAS) \
65 #define IS_LL_OPAMP_INPUT_NONINVERTING(__INPUT_NONINVERTING__) \
66 ( ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO0) \
67 || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_DAC) \
68 || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_DAC2) \
71 #define IS_LL_OPAMP_INPUT_NONINVERTING(__INPUT_NONINVERTING__) \
72 ( ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO0) \
73 || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_DAC) \
78 #define IS_LL_OPAMP_INPUT_INVERTING(__INPUT_INVERTING__) \
79 ( ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO0) \
80 || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO1) \
81 || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_CONNECT_NO) \
89 /* Private function prototypes -----------------------------------------------*/
91 /* Exported functions --------------------------------------------------------*/
92 /** @addtogroup OPAMP_LL_Exported_Functions
96 /** @addtogroup OPAMP_LL_EF_Init
101 * @brief De-initialize registers of the selected OPAMP instance
102 * to their default reset values.
103 * @note If comparator is locked, de-initialization by software is
105 * The only way to unlock the comparator is a device hardware reset.
106 * @param OPAMPx OPAMP instance
107 * @retval An ErrorStatus enumeration value:
108 * - SUCCESS: OPAMP registers are de-initialized
109 * - ERROR: OPAMP registers are not de-initialized
111 ErrorStatus
LL_OPAMP_DeInit(OPAMP_TypeDef
* OPAMPx
)
113 ErrorStatus status
= SUCCESS
;
115 /* Check the parameters */
116 assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx
));
118 LL_OPAMP_WriteReg(OPAMPx
, CSR
, 0x00000000U
);
124 * @brief Initialize some features of OPAMP instance.
125 * @note This function reset bit of calibration mode to ensure
126 * to be in functional mode, in order to have OPAMP parameters
127 * (inputs selection, ...) set with the corresponding OPAMP mode
129 * @param OPAMPx OPAMP instance
130 * @param OPAMP_InitStruct Pointer to a @ref LL_OPAMP_InitTypeDef structure
131 * @retval An ErrorStatus enumeration value:
132 * - SUCCESS: OPAMP registers are initialized
133 * - ERROR: OPAMP registers are not initialized
135 ErrorStatus
LL_OPAMP_Init(OPAMP_TypeDef
*OPAMPx
, LL_OPAMP_InitTypeDef
*OPAMP_InitStruct
)
137 ErrorStatus status
= SUCCESS
;
139 /* Check the parameters */
140 assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx
));
141 assert_param(IS_LL_OPAMP_POWER_MODE(OPAMP_InitStruct
->PowerMode
));
142 assert_param(IS_LL_OPAMP_FUNCTIONAL_MODE(OPAMP_InitStruct
->FunctionalMode
));
143 assert_param(IS_LL_OPAMP_INPUT_NONINVERTING(OPAMP_InitStruct
->InputNonInverting
));
145 /* Note: OPAMP inverting input can be used with OPAMP in mode standalone */
146 /* or PGA with external capacitors for filtering circuit. */
147 /* Otherwise (OPAMP in mode follower), OPAMP inverting input is */
148 /* not used (not connected to GPIO pin). */
149 if(OPAMP_InitStruct
->FunctionalMode
!= LL_OPAMP_MODE_FOLLOWER
)
151 assert_param(IS_LL_OPAMP_INPUT_INVERTING(OPAMP_InitStruct
->InputInverting
));
154 /* Configuration of OPAMP instance : */
156 /* - Functional mode */
157 /* - Input non-inverting */
158 /* - Input inverting */
159 /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode. */
160 if(OPAMP_InitStruct
->FunctionalMode
!= LL_OPAMP_MODE_FOLLOWER
)
162 MODIFY_REG(OPAMPx
->CSR
,
167 | OPAMP_CSR_PGGAIN_2
| OPAMP_CSR_PGGAIN_1
169 (OPAMP_InitStruct
->PowerMode
& OPAMP_POWERMODE_CSR_BIT_MASK
)
170 | OPAMP_InitStruct
->FunctionalMode
171 | OPAMP_InitStruct
->InputNonInverting
172 | OPAMP_InitStruct
->InputInverting
177 MODIFY_REG(OPAMPx
->CSR
,
182 | OPAMP_CSR_PGGAIN_2
| OPAMP_CSR_PGGAIN_1
184 (OPAMP_InitStruct
->PowerMode
& OPAMP_POWERMODE_CSR_BIT_MASK
)
185 | LL_OPAMP_MODE_FOLLOWER
186 | OPAMP_InitStruct
->InputNonInverting
194 * @brief Set each @ref LL_OPAMP_InitTypeDef field to default value.
195 * @param OPAMP_InitStruct pointer to a @ref LL_OPAMP_InitTypeDef structure
196 * whose fields will be set to default values.
199 void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef
*OPAMP_InitStruct
)
201 /* Set OPAMP_InitStruct fields to default values */
202 OPAMP_InitStruct
->PowerMode
= LL_OPAMP_POWERMODE_NORMAL
;
203 OPAMP_InitStruct
->FunctionalMode
= LL_OPAMP_MODE_FOLLOWER
;
204 OPAMP_InitStruct
->InputNonInverting
= LL_OPAMP_INPUT_NONINVERT_IO0
;
205 /* Note: Parameter discarded if OPAMP in functional mode follower, */
206 /* set anyway to its default value. */
207 OPAMP_InitStruct
->InputInverting
= LL_OPAMP_INPUT_INVERT_CONNECT_NO
;
222 #endif /* OPAMP1 || OPAMP2 */
228 #endif /* USE_FULL_LL_DRIVER */
230 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/