Merge pull request #11189 from klutvott123/move-telemetry-displayport-init
[betaflight.git] / lib / main / STM32F3 / Drivers / STM32F3xx_HAL_Driver / Src / stm32f3xx_ll_opamp.c
blob8fea1cef9721cfca9ed6f916b2429ad70e336e7d
1 /**
2 ******************************************************************************
3 * @file stm32f3xx_ll_opamp.c
4 * @author MCD Application Team
5 * @brief OPAMP LL module driver
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. Neither the name of STMicroelectronics nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ******************************************************************************
35 #if defined(USE_FULL_LL_DRIVER)
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f3xx_ll_opamp.h"
40 #ifdef USE_FULL_ASSERT
41 #include "stm32_assert.h"
42 #else
43 #define assert_param(expr) ((void)0U)
44 #endif
46 /** @addtogroup STM32F3xx_LL_Driver
47 * @{
50 #if defined (OPAMP1) || defined (OPAMP2) || defined (OPAMP3) || defined (OPAMP4)
52 /** @addtogroup OPAMP_LL OPAMP
53 * @{
56 /* Private types -------------------------------------------------------------*/
57 /* Private variables ---------------------------------------------------------*/
58 /* Private constants ---------------------------------------------------------*/
59 /* Private macros ------------------------------------------------------------*/
61 /** @addtogroup OPAMP_LL_Private_Macros
62 * @{
65 /* Check of parameters for configuration of OPAMP hierarchical scope: */
66 /* OPAMP instance. */
68 #define IS_LL_OPAMP_FUNCTIONAL_MODE(__FUNCTIONAL_MODE__) \
69 ( ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_STANDALONE) \
70 || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_FOLLOWER) \
71 || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA) \
74 /* Note: Comparator non-inverting inputs parameters are the same on all */
75 /* OPAMP instances. */
76 /* However, comparator instance kept as macro parameter for */
77 /* compatibility with other STM32 families. */
78 #define IS_LL_OPAMP_INPUT_NONINVERTING(__OPAMPX__, __INPUT_NONINVERTING__) \
79 ( ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO0) \
80 || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO1) \
81 || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO2) \
82 || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO3) \
85 /* Note: Comparator non-inverting inputs parameters are the same on all */
86 /* OPAMP instances. */
87 /* However, comparator instance kept as macro parameter for */
88 /* compatibility with other STM32 families. */
89 #define IS_LL_OPAMP_INPUT_INVERTING(__OPAMPX__, __INPUT_INVERTING__) \
90 ( ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO0) \
91 || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO1) \
92 || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_CONNECT_NO) \
95 /**
96 * @}
100 /* Private function prototypes -----------------------------------------------*/
102 /* Exported functions --------------------------------------------------------*/
103 /** @addtogroup OPAMP_LL_Exported_Functions
104 * @{
107 /** @addtogroup OPAMP_LL_EF_Init
108 * @{
112 * @brief De-initialize registers of the selected OPAMP instance
113 * to their default reset values.
114 * @note If comparator is locked, de-initialization by software is
115 * not possible.
116 * The only way to unlock the comparator is a device hardware reset.
117 * @param OPAMPx OPAMP instance
118 * @retval An ErrorStatus enumeration value:
119 * - SUCCESS: OPAMP registers are de-initialized
120 * - ERROR: OPAMP registers are not de-initialized
122 ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef* OPAMPx)
124 ErrorStatus status = SUCCESS;
126 /* Check the parameters */
127 assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx));
129 /* Note: Hardware constraint (refer to description of this function): */
130 /* OPAMP instance must not be locked. */
131 if(LL_OPAMP_IsLocked(OPAMPx) == 0U)
133 LL_OPAMP_WriteReg(OPAMPx, CSR, 0x00000000U);
135 else
137 /* OPAMP instance is locked: de-initialization by software is */
138 /* not possible. */
139 /* The only way to unlock the OPAMP is a device hardware reset. */
140 status = ERROR;
143 return status;
147 * @brief Initialize some features of OPAMP instance.
148 * @note This function reset bit of calibration mode to ensure
149 * to be in functional mode, in order to have OPAMP parameters
150 * (inputs selection, ...) set with the corresponding OPAMP mode
151 * to be effective.
152 * @param OPAMPx OPAMP instance
153 * @param OPAMP_InitStruct Pointer to a @ref LL_OPAMP_InitTypeDef structure
154 * @retval An ErrorStatus enumeration value:
155 * - SUCCESS: OPAMP registers are initialized
156 * - ERROR: OPAMP registers are not initialized
158 ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct)
160 ErrorStatus status = SUCCESS;
162 /* Check the parameters */
163 assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx));
164 assert_param(IS_LL_OPAMP_FUNCTIONAL_MODE(OPAMP_InitStruct->FunctionalMode));
165 assert_param(IS_LL_OPAMP_INPUT_NONINVERTING(OPAMPx, OPAMP_InitStruct->InputNonInverting));
167 /* Note: OPAMP inverting input can be used with OPAMP in mode standalone */
168 /* or PGA with external capacitors for filtering circuit. */
169 /* Otherwise (OPAMP in mode follower), OPAMP inverting input is */
170 /* not used (not connected to GPIO pin). */
171 if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER)
173 assert_param(IS_LL_OPAMP_INPUT_INVERTING(OPAMPx, OPAMP_InitStruct->InputInverting));
176 /* Note: Hardware constraint (refer to description of this function): */
177 /* OPAMP instance must not be locked. */
178 if(LL_OPAMP_IsLocked(OPAMPx) == 0U)
180 /* Configuration of OPAMP instance : */
181 /* - Functional mode */
182 /* - Input non-inverting */
183 /* - Input inverting */
184 /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode. */
185 if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER)
187 MODIFY_REG(OPAMPx->CSR,
188 OPAMP_CSR_CALON
189 | OPAMP_CSR_VMSEL
190 | OPAMP_CSR_VPSEL
192 OPAMP_InitStruct->FunctionalMode
193 | OPAMP_InitStruct->InputNonInverting
194 | OPAMP_InitStruct->InputInverting
197 else
199 MODIFY_REG(OPAMPx->CSR,
200 OPAMP_CSR_CALON
201 | OPAMP_CSR_VMSEL
202 | OPAMP_CSR_VPSEL
204 LL_OPAMP_MODE_FOLLOWER
205 | OPAMP_InitStruct->InputNonInverting
209 else
211 /* Initialization error: OPAMP instance is locked. */
212 status = ERROR;
215 return status;
219 * @brief Set each @ref LL_OPAMP_InitTypeDef field to default value.
220 * @param OPAMP_InitStruct pointer to a @ref LL_OPAMP_InitTypeDef structure
221 * whose fields will be set to default values.
222 * @retval None
224 void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct)
226 /* Set OPAMP_InitStruct fields to default values */
227 OPAMP_InitStruct->FunctionalMode = LL_OPAMP_MODE_FOLLOWER;
228 OPAMP_InitStruct->InputNonInverting = LL_OPAMP_INPUT_NONINVERT_IO0;
229 /* Note: Parameter discarded if OPAMP in functional mode follower, */
230 /* set anyway to its default value. */
231 OPAMP_InitStruct->InputInverting = LL_OPAMP_INPUT_INVERT_CONNECT_NO;
235 * @}
239 * @}
243 * @}
246 #endif /* OPAMP1 || OPAMP2 || OPAMP3 || OPAMP4 */
249 * @}
252 #endif /* USE_FULL_LL_DRIVER */
254 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/