1 /**
2 ******************************************************************************
3 * @file stm32l4xx_ll_opamp.h
4 * @author MCD Application Team
5 * @brief Header file of OPAMP LL module.
6 ******************************************************************************
7 * @attention
8 *
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
11 *
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
16 *
17 ******************************************************************************
18 */
19
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32L4xx_LL_OPAMP_H
22 #define STM32L4xx_LL_OPAMP_H
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32l4xx.h"
30
31 /** @addtogroup STM32L4xx_LL_Driver
32 * @{
33 */
34
35 #if defined (OPAMP1) || defined (OPAMP2)
36
37 /** @defgroup OPAMP_LL OPAMP
38 * @{
39 */
40
41 /* Private types -------------------------------------------------------------*/
42 /* Private variables ---------------------------------------------------------*/
43
44 /* Private constants ---------------------------------------------------------*/
45 /** @defgroup OPAMP_LL_Private_Constants OPAMP Private Constants
46 * @{
47 */
48
49 /* Internal mask for OPAMP power mode: */
50 /* To select into literal LL_OPAMP_POWERMODE_x the relevant bits for: */
51 /* - OPAMP power mode into control register */
52 /* - OPAMP trimming register offset */
53
54 /* Internal register offset for OPAMP trimming configuration */
55 #define OPAMP_POWERMODE_OTR_REGOFFSET 0x00000000U
56 #define OPAMP_POWERMODE_LPOTR_REGOFFSET 0x00000001U
57 #define OPAMP_POWERMODE_OTR_REGOFFSET_MASK (OPAMP_POWERMODE_OTR_REGOFFSET | OPAMP_POWERMODE_LPOTR_REGOFFSET)
58
59 /* Mask for OPAMP power mode into control register */
60 #define OPAMP_POWERMODE_CSR_BIT_MASK (OPAMP_CSR_OPALPM)
61
62 /* Internal mask for OPAMP trimming of transistors differential pair NMOS */
63 /* or PMOS. */
64 /* To select into literal LL_OPAMP_TRIMMING_x the relevant bits for: */
65 /* - OPAMP trimming selection of transistors differential pair */
66 /* - OPAMP trimming values of transistors differential pair */
67 #define OPAMP_TRIMMING_SELECT_MASK (OPAMP1_CSR_CALSEL)
68 #define OPAMP_TRIMMING_VALUE_MASK (OPAMP_OTR_TRIMOFFSETP | OPAMP_OTR_TRIMOFFSETN)
69
70 /**
71 * @}
72 */
73
74
75 /* Private macros ------------------------------------------------------------*/
76 /** @defgroup OPAMP_LL_Private_Macros OPAMP Private Macros
77 * @{
78 */
79
80 /**
81 * @brief Driver macro reserved for internal use: set a pointer to
82 * a register from a register basis from which an offset
83 * is applied.
84 * @param __REG__ Register basis from which the offset is applied.
85 * @param __REG_OFFSET__ Offset to be applied (unit: number of registers).
86 * @retval Register address
87 */
88 #define __OPAMP_PTR_REG_OFFSET(__REG__, __REG_OFFSET__) \
89 ((uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFSET__) << 2U))))
90
91
92
93
94 /**
95 * @}
96 */
97
98
99 /* Exported types ------------------------------------------------------------*/
100 #if defined(USE_FULL_LL_DRIVER)
101 /** @defgroup OPAMP_LL_ES_INIT OPAMP Exported Init structure
102 * @{
103 */
104
105 /**
106 * @brief Structure definition of some features of OPAMP instance.
107 */
108 typedef struct
109 {
110 uint32_t PowerMode; /*!< Set OPAMP power mode.
111 This parameter can be a value of @ref OPAMP_LL_EC_POWERMODE
112
113 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetPowerMode(). */
114
115 uint32_t FunctionalMode; /*!< Set OPAMP functional mode by setting internal connections: OPAMP operation in standalone, follower, ...
116 This parameter can be a value of @ref OPAMP_LL_EC_FUNCTIONAL_MODE
117 @note If OPAMP is configured in mode PGA, the gain can be configured using function @ref LL_OPAMP_SetPGAGain().
118
119 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetFunctionalMode(). */
120
121 uint32_t InputNonInverting; /*!< Set OPAMP input non-inverting connection.
122 This parameter can be a value of @ref OPAMP_LL_EC_INPUT_NONINVERTING
123
124 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputNonInverting(). */
125
126 uint32_t InputInverting; /*!< Set OPAMP inverting input connection.
127 This parameter can be a value of @ref OPAMP_LL_EC_INPUT_INVERTING
128 @note OPAMP inverting input is used with OPAMP in mode standalone or PGA with external capacitors for filtering circuit. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin), this parameter is discarded.
129
130 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputInverting(). */
131
132 } LL_OPAMP_InitTypeDef;
133
134 /**
135 * @}
136 */
137 #endif /* USE_FULL_LL_DRIVER */
138
139 /* Exported constants --------------------------------------------------------*/
140 /** @defgroup OPAMP_LL_Exported_Constants OPAMP Exported Constants
141 * @{
142 */
143
144 /** @defgroup OPAMP_LL_EC_POWERSUPPLY_RANGE OPAMP power supply range
145 * @{
146 */
147 #define LL_OPAMP_POWERSUPPLY_RANGE_LOW 0x00000000U /*!< Power supply range low. On STM32L4 serie: Vdda lower than 2.4V. */
148 #define LL_OPAMP_POWERSUPPLY_RANGE_HIGH (OPAMP1_CSR_OPARANGE) /*!< Power supply range high. On STM32L4 serie: Vdda higher than 2.4V. */
149 /**
150 * @}
151 */
152
153 /** @defgroup OPAMP_LL_EC_POWERMODE OPAMP power mode
154 * @{
155 */
156 #define LL_OPAMP_POWERMODE_NORMAL (OPAMP_POWERMODE_OTR_REGOFFSET) /*!< OPAMP power mode normal */
157 #define LL_OPAMP_POWERMODE_LOWPOWER (OPAMP_POWERMODE_LPOTR_REGOFFSET | OPAMP_CSR_OPALPM) /*!< OPAMP power mode low-power */
158 /**
159 * @}
160 */
161
162 /** @defgroup OPAMP_LL_EC_MODE OPAMP mode calibration or functional.
163 * @{
164 */
165 #define LL_OPAMP_MODE_FUNCTIONAL 0x00000000U /*!< OPAMP functional mode */
166 #define LL_OPAMP_MODE_CALIBRATION (OPAMP_CSR_CALON) /*!< OPAMP calibration mode */
167 /**
168 * @}
169 */
170
171 /** @defgroup OPAMP_LL_EC_FUNCTIONAL_MODE OPAMP functional mode
172 * @{
173 */
174 #define LL_OPAMP_MODE_STANDALONE 0x00000000U /*!< OPAMP functional mode, OPAMP operation in standalone */
175 #define LL_OPAMP_MODE_FOLLOWER (OPAMP_CSR_OPAMODE_1 | OPAMP_CSR_OPAMODE_0) /*!< OPAMP functional mode, OPAMP operation in follower */
176 #define LL_OPAMP_MODE_PGA (OPAMP_CSR_OPAMODE_1) /*!< OPAMP functional mode, OPAMP operation in PGA */
177 /**
178 * @}
179 */
180
181 /** @defgroup OPAMP_LL_EC_MODE_PGA_GAIN OPAMP PGA gain (relevant when OPAMP is in functional mode PGA)
182 * @{
183 */
184 #define LL_OPAMP_PGA_GAIN_2 0x00000000U /*!< OPAMP PGA gain 2 */
185 #define LL_OPAMP_PGA_GAIN_4 (OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 4 */
186 #define LL_OPAMP_PGA_GAIN_8 (OPAMP_CSR_PGGAIN_1) /*!< OPAMP PGA gain 8 */
187 #define LL_OPAMP_PGA_GAIN_16 (OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0 ) /*!< OPAMP PGA gain 16 */
188 /**
189 * @}
190 */
191
192 /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING OPAMP input non-inverting
193 * @{
194 */
195 #define LL_OPAMP_INPUT_NONINVERT_IO0 0x00000000U /*!< OPAMP non inverting input connected to GPIO pin (pin PA0 for OPAMP1, pin PA6 for OPAMP2) */
196 #define LL_OPAMP_INPUT_NONINV_DAC1_CH1 (OPAMP1_CSR_VPSEL) /*!< OPAMP non inverting input connected to DAC1 channel1 output */
197 /**
198 * @}
199 */
200
201 /** @defgroup OPAMP_LL_EC_INPUT_INVERTING OPAMP input inverting
202 * @{
203 */
204 #define LL_OPAMP_INPUT_INVERT_IO0 0x00000000U /*!< OPAMP inverting input connected to GPIO pin (valid also in PGA mode for filtering). Note: OPAMP inverting input is used with OPAMP in mode standalone or PGA with external capacitors for filtering circuit. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin). */
205 #define LL_OPAMP_INPUT_INVERT_IO1 (OPAMP_CSR_VMSEL_0) /*!< OPAMP inverting input (low leakage input) connected to GPIO pin (available only on package BGA132). Note: OPAMP inverting input is used with OPAMP in mode standalone or PGA with external capacitors for filtering circuit. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin). */
206 #define LL_OPAMP_INPUT_INVERT_CONNECT_NO (OPAMP_CSR_VMSEL_1) /*!< OPAMP inverting input not externally connected (intended for OPAMP in mode follower or PGA without external capacitors for filtering) */
207 /**
208 * @}
209 */
210
211 /** @defgroup OPAMP_LL_EC_INPUT_LEGACY OPAMP inputs legacy literals name
212 * @{
213 */
214 #define LL_OPAMP_NONINVERTINGINPUT_IO0 LL_OPAMP_INPUT_NONINVERT_IO0
215 #define LL_OPAMP_NONINVERTINGINPUT_DAC_CH LL_OPAMP_INPUT_NONINV_DAC1_CH1
216
217 #define LL_OPAMP_INVERTINGINPUT_IO0 LL_OPAMP_INPUT_INVERT_IO0
218 #define LL_OPAMP_INVERTINGINPUT_IO1 LL_OPAMP_INPUT_INVERT_IO1
219 #define LL_OPAMP_INVERTINGINPUT_CONNECT_NO LL_OPAMP_INPUT_INVERT_CONNECT_NO
220
221 #define LL_OPAMP_INPUT_NONINVERT_DAC1_CH1 LL_OPAMP_INPUT_NONINV_DAC1_CH1
222 /**
223 * @}
224 */
225
226 /** @defgroup OPAMP_LL_EC_TRIMMING_MODE OPAMP trimming mode
227 * @{
228 */
229 #define LL_OPAMP_TRIMMING_FACTORY 0x00000000U /*!< OPAMP trimming factors set to factory values */
230 #define LL_OPAMP_TRIMMING_USER (OPAMP_CSR_USERTRIM) /*!< OPAMP trimming factors set to user values */
231 /**
232 * @}
233 */
234
235 /** @defgroup OPAMP_LL_EC_TRIMMING_TRANSISTORS_DIFF_PAIR OPAMP trimming of transistors differential pair NMOS or PMOS
236 * @{
237 */
238 #define LL_OPAMP_TRIMMING_NMOS (OPAMP_OTR_TRIMOFFSETN) /*!< OPAMP trimming of transistors differential pair NMOS */
239 #define LL_OPAMP_TRIMMING_PMOS (OPAMP_OTR_TRIMOFFSETP | OPAMP1_CSR_CALSEL) /*!< OPAMP trimming of transistors differential pair PMOS */
240 /**
241 * @}
242 */
243
244 /** @defgroup OPAMP_LL_EC_HW_DELAYS Definitions of OPAMP hardware constraints delays
245 * @note Only OPAMP IP HW delays are defined in OPAMP LL driver driver,
246 * not timeout values.
247 * For details on delays values, refer to descriptions in source code
248 * above each literal definition.
249 * @{
250 */
251
252 /* Delay for OPAMP startup time (transition from state disable to enable). */
253 /* Note: OPAMP startup time depends on board application environment: */
254 /* impedance connected to OPAMP output. */
255 /* The delay below is specified under conditions: */
256 /* - OPAMP in mode low power */
257 /* - OPAMP in functional mode follower */
258 /* - load impedance of 4kOhm (min), 50pF (max) */
259 /* Literal set to maximum value (refer to device datasheet, */
260 /* parameter "tWAKEUP"). */
261 /* Unit: us */
262 #define LL_OPAMP_DELAY_STARTUP_US ((uint32_t) 30U) /*!< Delay for OPAMP startup time */
263
264 /**
265 * @}
266 */
267
268 /**
269 * @}
270 */
271
272 /* Exported macro ------------------------------------------------------------*/
273 /** @defgroup OPAMP_LL_Exported_Macros OPAMP Exported Macros
274 * @{
275 */
276 /** @defgroup OPAMP_LL_EM_WRITE_READ Common write and read registers macro
277 * @{
278 */
279 /**
280 * @brief Write a value in OPAMP register
281 * @param __INSTANCE__ OPAMP Instance
282 * @param __REG__ Register to be written
283 * @param __VALUE__ Value to be written in the register
284 * @retval None
285 */
286 #define LL_OPAMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
287
288 /**
289 * @brief Read a value in OPAMP register
290 * @param __INSTANCE__ OPAMP Instance
291 * @param __REG__ Register to be read
292 * @retval Register value
293 */
294 #define LL_OPAMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
295 /**
296 * @}
297 */
298
299 /** @defgroup OPAMP_LL_EM_HELPER_MACRO OPAMP helper macro
300 * @{
301 */
302
303 /**
304 * @brief Helper macro to select the OPAMP common instance
305 * to which is belonging the selected OPAMP instance.
306 * @note OPAMP common register instance can be used to
307 * set parameters common to several OPAMP instances.
308 * Refer to functions having argument "OPAMPxy_COMMON" as parameter.
309 * @param __OPAMPx__ OPAMP instance
310 * @retval OPAMP common instance
311 */
312 #if defined(OPAMP1) && defined(OPAMP2)
313 #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__) \
314 (OPAMP12_COMMON)
315 #else
316 #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__) \
317 (OPAMP1_COMMON)
318 #endif
319
320 /**
321 * @brief Helper macro to check if all OPAMP instances sharing the same
322 * OPAMP common instance are disabled.
323 * @note This check is required by functions with setting conditioned to
324 * OPAMP state:
325 * All OPAMP instances of the OPAMP common group must be disabled.
326 * Refer to functions having argument "OPAMPxy_COMMON" as parameter.
327 * @retval 0: All OPAMP instances sharing the same OPAMP common instance
328 * are disabled.
329 * 1: At least one OPAMP instance sharing the same OPAMP common instance
330 * is enabled
331 */
332 #if defined(OPAMP1) && defined(OPAMP2)
333 #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE() \
334 (LL_OPAMP_IsEnabled(OPAMP1) | \
335 LL_OPAMP_IsEnabled(OPAMP2) )
336 #else
337 #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE() \
338 (LL_OPAMP_IsEnabled(OPAMP1))
339 #endif
340
341 /**
342 * @}
343 */
344
345 /**
346 * @}
347 */
348
349 /* Exported functions --------------------------------------------------------*/
350 /** @defgroup OPAMP_LL_Exported_Functions OPAMP Exported Functions
351 * @{
352 */
353
354 /** @defgroup OPAMP_LL_EF_Configuration_opamp_common Configuration of OPAMP hierarchical scope: common to several OPAMP instances
355 * @{
356 */
357
358 /**
359 * @brief Set OPAMP power range.
360 * @note The OPAMP power range applies to several OPAMP instances
361 * (if several OPAMP instances available on the selected device).
362 * @note On this STM32 serie, setting of this feature is conditioned to
363 * OPAMP state:
364 * All OPAMP instances of the OPAMP common group must be disabled.
365 * This check can be done with function @ref LL_OPAMP_IsEnabled() for each
366 * OPAMP instance or by using helper macro
367 * @ref __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE().
368 * @rmtoll CSR OPARANGE LL_OPAMP_SetCommonPowerRange
369 * @param OPAMPxy_COMMON OPAMP common instance
370 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_OPAMP_COMMON_INSTANCE() )
371 * @param PowerRange This parameter can be one of the following values:
372 * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_LOW
373 * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_HIGH
374 * @retval None
375 */
LL_OPAMP_SetCommonPowerRange(OPAMP_Common_TypeDef * OPAMPxy_COMMON,uint32_t PowerRange)376 __STATIC_INLINE void LL_OPAMP_SetCommonPowerRange(OPAMP_Common_TypeDef *OPAMPxy_COMMON, uint32_t PowerRange)
377 {
378 /* Prevent unused parameter warning */
379 (void)(*OPAMPxy_COMMON);
380
381 MODIFY_REG(OPAMP1->CSR, OPAMP1_CSR_OPARANGE, PowerRange);
382 }
383
384 /**
385 * @brief Get OPAMP power range.
386 * @note The OPAMP power range applies to several OPAMP instances
387 * (if several OPAMP instances available on the selected device).
388 * @rmtoll CSR OPARANGE LL_OPAMP_GetCommonPowerRange
389 * @param OPAMPxy_COMMON OPAMP common instance
390 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_OPAMP_COMMON_INSTANCE() )
391 * @retval Returned value can be one of the following values:
392 * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_LOW
393 * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_HIGH
394 */
LL_OPAMP_GetCommonPowerRange(OPAMP_Common_TypeDef * OPAMPxy_COMMON)395 __STATIC_INLINE uint32_t LL_OPAMP_GetCommonPowerRange(OPAMP_Common_TypeDef *OPAMPxy_COMMON)
396 {
397 /* Prevent unused parameter warning */
398 (void)(*OPAMPxy_COMMON);
399
400 return (uint32_t)(READ_BIT(OPAMP1->CSR, OPAMP1_CSR_OPARANGE));
401 }
402
403 /**
404 * @}
405 */
406
407 /** @defgroup OPAMP_LL_EF_CONFIGURATION_OPAMP_INSTANCE Configuration of OPAMP hierarchical scope: OPAMP instance
408 * @{
409 */
410
411 /**
412 * @brief Set OPAMP power mode.
413 * @note The OPAMP must be disabled to change this configuration.
414 * @rmtoll CSR OPALPM LL_OPAMP_SetPowerMode
415 * @param OPAMPx OPAMP instance
416 * @param PowerMode This parameter can be one of the following values:
417 * @arg @ref LL_OPAMP_POWERMODE_NORMAL
418 * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
419 * @retval None
420 */
LL_OPAMP_SetPowerMode(OPAMP_TypeDef * OPAMPx,uint32_t PowerMode)421 __STATIC_INLINE void LL_OPAMP_SetPowerMode(OPAMP_TypeDef *OPAMPx, uint32_t PowerMode)
422 {
423 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPALPM, (PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK));
424 }
425
426 /**
427 * @brief Get OPAMP power mode.
428 * @rmtoll CSR OPALPM LL_OPAMP_GetPowerMode
429 * @param OPAMPx OPAMP instance
430 * @retval Returned value can be one of the following values:
431 * @arg @ref LL_OPAMP_POWERMODE_NORMAL
432 * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
433 */
LL_OPAMP_GetPowerMode(OPAMP_TypeDef * OPAMPx)434 __STATIC_INLINE uint32_t LL_OPAMP_GetPowerMode(OPAMP_TypeDef *OPAMPx)
435 {
436 register uint32_t power_mode = (READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPALPM));
437
438 return (uint32_t)(power_mode | (power_mode >> (OPAMP_CSR_OPALPM_Pos)));
439 }
440
441 /**
442 * @brief Set OPAMP mode calibration or functional.
443 * @note OPAMP mode corresponds to functional or calibration mode:
444 * - functional mode: OPAMP operation in standalone, follower, ...
445 * Set functional mode using function
446 * @ref LL_OPAMP_SetFunctionalMode().
447 * - calibration mode: offset calibration of the selected
448 * transistors differential pair NMOS or PMOS.
449 * @note On this STM32 serie, during calibration, OPAMP functional
450 * mode must be set to standalone or follower mode
451 * (in order to open internal connections to resistors
452 * of PGA mode).
453 * Refer to function @ref LL_OPAMP_SetFunctionalMode().
454 * @rmtoll CSR CALON LL_OPAMP_SetMode
455 * @param OPAMPx OPAMP instance
456 * @param Mode This parameter can be one of the following values:
457 * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
458 * @arg @ref LL_OPAMP_MODE_CALIBRATION
459 * @retval None
460 */
LL_OPAMP_SetMode(OPAMP_TypeDef * OPAMPx,uint32_t Mode)461 __STATIC_INLINE void LL_OPAMP_SetMode(OPAMP_TypeDef *OPAMPx, uint32_t Mode)
462 {
463 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALON, Mode);
464 }
465
466 /**
467 * @brief Get OPAMP mode calibration or functional.
468 * @note OPAMP mode corresponds to functional or calibration mode:
469 * - functional mode: OPAMP operation in standalone, follower, ...
470 * Set functional mode using function
471 * @ref LL_OPAMP_SetFunctionalMode().
472 * - calibration mode: offset calibration of the selected
473 * transistors differential pair NMOS or PMOS.
474 * @rmtoll CSR CALON LL_OPAMP_GetMode
475 * @param OPAMPx OPAMP instance
476 * @retval Returned value can be one of the following values:
477 * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
478 * @arg @ref LL_OPAMP_MODE_CALIBRATION
479 */
LL_OPAMP_GetMode(OPAMP_TypeDef * OPAMPx)480 __STATIC_INLINE uint32_t LL_OPAMP_GetMode(OPAMP_TypeDef *OPAMPx)
481 {
482 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALON));
483 }
484
485 /**
486 * @brief Set OPAMP functional mode by setting internal connections.
487 * OPAMP operation in standalone, follower, ...
488 * @note This function reset bit of calibration mode to ensure
489 * to be in functional mode, in order to have OPAMP parameters
490 * (inputs selection, ...) set with the corresponding OPAMP mode
491 * to be effective.
492 * @rmtoll CSR OPAMODE LL_OPAMP_SetFunctionalMode
493 * @param OPAMPx OPAMP instance
494 * @param FunctionalMode This parameter can be one of the following values:
495 * @arg @ref LL_OPAMP_MODE_STANDALONE
496 * @arg @ref LL_OPAMP_MODE_FOLLOWER
497 * @arg @ref LL_OPAMP_MODE_PGA
498 * @retval None
499 */
LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef * OPAMPx,uint32_t FunctionalMode)500 __STATIC_INLINE void LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef *OPAMPx, uint32_t FunctionalMode)
501 {
502 /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode */
503 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPAMODE | OPAMP_CSR_CALON, FunctionalMode);
504 }
505
506 /**
507 * @brief Get OPAMP functional mode from setting of internal connections.
508 * OPAMP operation in standalone, follower, ...
509 * @rmtoll CSR OPAMODE LL_OPAMP_GetFunctionalMode
510 * @param OPAMPx OPAMP instance
511 * @retval Returned value can be one of the following values:
512 * @arg @ref LL_OPAMP_MODE_STANDALONE
513 * @arg @ref LL_OPAMP_MODE_FOLLOWER
514 * @arg @ref LL_OPAMP_MODE_PGA
515 */
LL_OPAMP_GetFunctionalMode(OPAMP_TypeDef * OPAMPx)516 __STATIC_INLINE uint32_t LL_OPAMP_GetFunctionalMode(OPAMP_TypeDef *OPAMPx)
517 {
518 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMODE));
519 }
520
521 /**
522 * @brief Set OPAMP PGA gain.
523 * @note Preliminarily, OPAMP must be set in mode PGA
524 * using function @ref LL_OPAMP_SetFunctionalMode().
525 * @rmtoll CSR PGGAIN LL_OPAMP_SetPGAGain
526 * @param OPAMPx OPAMP instance
527 * @param PGAGain This parameter can be one of the following values:
528 * @arg @ref LL_OPAMP_PGA_GAIN_2
529 * @arg @ref LL_OPAMP_PGA_GAIN_4
530 * @arg @ref LL_OPAMP_PGA_GAIN_8
531 * @arg @ref LL_OPAMP_PGA_GAIN_16
532 * @retval None
533 */
LL_OPAMP_SetPGAGain(OPAMP_TypeDef * OPAMPx,uint32_t PGAGain)534 __STATIC_INLINE void LL_OPAMP_SetPGAGain(OPAMP_TypeDef *OPAMPx, uint32_t PGAGain)
535 {
536 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN, PGAGain);
537 }
538
539 /**
540 * @brief Get OPAMP PGA gain.
541 * @note Preliminarily, OPAMP must be set in mode PGA
542 * using function @ref LL_OPAMP_SetFunctionalMode().
543 * @rmtoll CSR PGGAIN LL_OPAMP_GetPGAGain
544 * @param OPAMPx OPAMP instance
545 * @retval Returned value can be one of the following values:
546 * @arg @ref LL_OPAMP_PGA_GAIN_2
547 * @arg @ref LL_OPAMP_PGA_GAIN_4
548 * @arg @ref LL_OPAMP_PGA_GAIN_8
549 * @arg @ref LL_OPAMP_PGA_GAIN_16
550 */
LL_OPAMP_GetPGAGain(OPAMP_TypeDef * OPAMPx)551 __STATIC_INLINE uint32_t LL_OPAMP_GetPGAGain(OPAMP_TypeDef *OPAMPx)
552 {
553 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN));
554 }
555
556 /**
557 * @}
558 */
559
560 /** @defgroup OPAMP_LL_EF_CONFIGURATION_INPUTS Configuration of OPAMP inputs
561 * @{
562 */
563
564 /**
565 * @brief Set OPAMP non-inverting input connection.
566 * @rmtoll CSR VPSEL LL_OPAMP_SetInputNonInverting
567 * @param OPAMPx OPAMP instance
568 * @param InputNonInverting This parameter can be one of the following values:
569 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
570 * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1
571 * @retval None
572 */
LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef * OPAMPx,uint32_t InputNonInverting)573 __STATIC_INLINE void LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
574 {
575 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VPSEL, InputNonInverting);
576 }
577
578 /**
579 * @brief Get OPAMP non-inverting input connection.
580 * @rmtoll CSR VPSEL LL_OPAMP_GetInputNonInverting
581 * @param OPAMPx OPAMP instance
582 * @retval Returned value can be one of the following values:
583 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
584 * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1
585 */
LL_OPAMP_GetInputNonInverting(OPAMP_TypeDef * OPAMPx)586 __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInverting(OPAMP_TypeDef *OPAMPx)
587 {
588 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VPSEL));
589 }
590
591 /**
592 * @brief Set OPAMP inverting input connection.
593 * @note OPAMP inverting input is used with OPAMP in mode standalone
594 * or PGA with external capacitors for filtering circuit.
595 * Otherwise (OPAMP in mode follower), OPAMP inverting input
596 * is not used (not connected to GPIO pin).
597 * @rmtoll CSR VMSEL LL_OPAMP_SetInputInverting
598 * @param OPAMPx OPAMP instance
599 * @param InputInverting This parameter can be one of the following values:
600 * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
601 * @arg @ref LL_OPAMP_INPUT_INVERT_IO1
602 * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
603 * @retval None
604 */
LL_OPAMP_SetInputInverting(OPAMP_TypeDef * OPAMPx,uint32_t InputInverting)605 __STATIC_INLINE void LL_OPAMP_SetInputInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting)
606 {
607 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VMSEL, InputInverting);
608 }
609
610 /**
611 * @brief Get OPAMP inverting input connection.
612 * @rmtoll CSR VMSEL LL_OPAMP_GetInputInverting
613 * @param OPAMPx OPAMP instance
614 * @retval Returned value can be one of the following values:
615 * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
616 * @arg @ref LL_OPAMP_INPUT_INVERT_IO1
617 * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
618 */
LL_OPAMP_GetInputInverting(OPAMP_TypeDef * OPAMPx)619 __STATIC_INLINE uint32_t LL_OPAMP_GetInputInverting(OPAMP_TypeDef *OPAMPx)
620 {
621 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VMSEL));
622 }
623
624 /**
625 * @}
626 */
627
628 /** @defgroup OPAMP_LL_EF_Configuration_Legacy_Functions Configuration of OPAMP, legacy functions name
629 * @{
630 */
631 /* Old functions name kept for legacy purpose, to be replaced by the */
632 /* current functions name. */
LL_OPAMP_SetNonInvertingInput(OPAMP_TypeDef * OPAMPx,uint32_t NonInvertingInput)633 __STATIC_INLINE void LL_OPAMP_SetNonInvertingInput(OPAMP_TypeDef *OPAMPx, uint32_t NonInvertingInput)
634 {
635 LL_OPAMP_SetInputNonInverting(OPAMPx, NonInvertingInput);
636 }
637
LL_OPAMP_SetInvertingInput(OPAMP_TypeDef * OPAMPx,uint32_t InvertingInput)638 __STATIC_INLINE void LL_OPAMP_SetInvertingInput(OPAMP_TypeDef *OPAMPx, uint32_t InvertingInput)
639 {
640 LL_OPAMP_SetInputInverting(OPAMPx, InvertingInput);
641 }
642
643 /**
644 * @}
645 */
646
647 /** @defgroup OPAMP_LL_EF_OPAMP_TRIMMING Configuration and operation of OPAMP trimming
648 * @{
649 */
650
651 /**
652 * @brief Set OPAMP trimming mode.
653 * @rmtoll CSR USERTRIM LL_OPAMP_SetTrimmingMode
654 * @param OPAMPx OPAMP instance
655 * @param TrimmingMode This parameter can be one of the following values:
656 * @arg @ref LL_OPAMP_TRIMMING_FACTORY
657 * @arg @ref LL_OPAMP_TRIMMING_USER
658 * @retval None
659 */
LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef * OPAMPx,uint32_t TrimmingMode)660 __STATIC_INLINE void LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef *OPAMPx, uint32_t TrimmingMode)
661 {
662 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_USERTRIM, TrimmingMode);
663 }
664
665 /**
666 * @brief Get OPAMP trimming mode.
667 * @rmtoll CSR USERTRIM LL_OPAMP_GetTrimmingMode
668 * @param OPAMPx OPAMP instance
669 * @retval Returned value can be one of the following values:
670 * @arg @ref LL_OPAMP_TRIMMING_FACTORY
671 * @arg @ref LL_OPAMP_TRIMMING_USER
672 */
LL_OPAMP_GetTrimmingMode(OPAMP_TypeDef * OPAMPx)673 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingMode(OPAMP_TypeDef *OPAMPx)
674 {
675 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_USERTRIM));
676 }
677
678 /**
679 * @brief Set OPAMP offset to calibrate the selected transistors
680 * differential pair NMOS or PMOS.
681 * @note Preliminarily, OPAMP must be set in mode calibration
682 * using function @ref LL_OPAMP_SetMode().
683 * @rmtoll CSR CALSEL LL_OPAMP_SetCalibrationSelection
684 * @param OPAMPx OPAMP instance
685 * @param TransistorsDiffPair This parameter can be one of the following values:
686 * @arg @ref LL_OPAMP_TRIMMING_NMOS
687 * @arg @ref LL_OPAMP_TRIMMING_PMOS
688 * @retval None
689 */
LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef * OPAMPx,uint32_t TransistorsDiffPair)690 __STATIC_INLINE void LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair)
691 {
692 /* Parameter used with mask "OPAMP_TRIMMING_SELECT_MASK" because */
693 /* containing other bits reserved for other purpose. */
694 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALSEL, (TransistorsDiffPair & OPAMP_TRIMMING_SELECT_MASK));
695 }
696
697 /**
698 * @brief Get OPAMP offset to calibrate the selected transistors
699 * differential pair NMOS or PMOS.
700 * @note Preliminarily, OPAMP must be set in mode calibration
701 * using function @ref LL_OPAMP_SetMode().
702 * @rmtoll CSR CALSEL LL_OPAMP_GetCalibrationSelection
703 * @param OPAMPx OPAMP instance
704 * @retval Returned value can be one of the following values:
705 * @arg @ref LL_OPAMP_TRIMMING_NMOS
706 * @arg @ref LL_OPAMP_TRIMMING_PMOS
707 */
LL_OPAMP_GetCalibrationSelection(OPAMP_TypeDef * OPAMPx)708 __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationSelection(OPAMP_TypeDef *OPAMPx)
709 {
710 register uint32_t CalibrationSelection = (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALSEL));
711
712 return (CalibrationSelection |
713 (((CalibrationSelection & OPAMP_CSR_CALSEL) == 0UL) ? OPAMP_OTR_TRIMOFFSETN : OPAMP_OTR_TRIMOFFSETP));
714 }
715
716 /**
717 * @brief Get OPAMP calibration result of toggling output.
718 * @note This functions returns:
719 * 0 if OPAMP calibration output is reset
720 * 1 if OPAMP calibration output is set
721 * @rmtoll CSR CALOUT LL_OPAMP_IsCalibrationOutputSet
722 * @param OPAMPx OPAMP instance
723 * @retval State of bit (1 or 0).
724 */
LL_OPAMP_IsCalibrationOutputSet(OPAMP_TypeDef * OPAMPx)725 __STATIC_INLINE uint32_t LL_OPAMP_IsCalibrationOutputSet(OPAMP_TypeDef *OPAMPx)
726 {
727 return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALOUT) == OPAMP_CSR_CALOUT) ? 1UL : 0UL);
728 }
729
730 /**
731 * @brief Set OPAMP trimming factor for the selected transistors
732 * differential pair NMOS or PMOS, corresponding to the selected
733 * power mode.
734 * @rmtoll OTR TRIMOFFSETN LL_OPAMP_SetTrimmingValue\n
735 * OTR TRIMOFFSETP LL_OPAMP_SetTrimmingValue\n
736 * LPOTR TRIMLPOFFSETN LL_OPAMP_SetTrimmingValue\n
737 * LPOTR TRIMLPOFFSETP LL_OPAMP_SetTrimmingValue
738 * @param OPAMPx OPAMP instance
739 * @param PowerMode This parameter can be one of the following values:
740 * @arg @ref LL_OPAMP_POWERMODE_NORMAL
741 * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
742 * @param TransistorsDiffPair This parameter can be one of the following values:
743 * @arg @ref LL_OPAMP_TRIMMING_NMOS
744 * @arg @ref LL_OPAMP_TRIMMING_PMOS
745 * @param TrimmingValue 0x00...0x1F
746 * @retval None
747 */
LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef * OPAMPx,uint32_t PowerMode,uint32_t TransistorsDiffPair,uint32_t TrimmingValue)748 __STATIC_INLINE void LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair, uint32_t TrimmingValue)
749 {
750 register uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
751
752 /* Set bits with position in register depending on parameter */
753 /* "TransistorsDiffPair". */
754 /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */
755 /* containing other bits reserved for other purpose. */
756 MODIFY_REG(*preg,
757 (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK),
758 TrimmingValue << ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_OTR_TRIMOFFSETN_Pos : OPAMP_OTR_TRIMOFFSETP_Pos));
759 }
760
761 /**
762 * @brief Get OPAMP trimming factor for the selected transistors
763 * differential pair NMOS or PMOS, corresponding to the selected
764 * power mode.
765 * @rmtoll OTR TRIMOFFSETN LL_OPAMP_GetTrimmingValue\n
766 * OTR TRIMOFFSETP LL_OPAMP_GetTrimmingValue\n
767 * LPOTR TRIMLPOFFSETN LL_OPAMP_GetTrimmingValue\n
768 * LPOTR TRIMLPOFFSETP LL_OPAMP_GetTrimmingValue
769 * @param OPAMPx OPAMP instance
770 * @param PowerMode This parameter can be one of the following values:
771 * @arg @ref LL_OPAMP_POWERMODE_NORMAL
772 * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
773 * @param TransistorsDiffPair This parameter can be one of the following values:
774 * @arg @ref LL_OPAMP_TRIMMING_NMOS
775 * @arg @ref LL_OPAMP_TRIMMING_PMOS
776 * @retval 0x0...0x1F
777 */
LL_OPAMP_GetTrimmingValue(OPAMP_TypeDef * OPAMPx,uint32_t PowerMode,uint32_t TransistorsDiffPair)778 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair)
779 {
780 register const uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
781
782 /* Retrieve bits with position in register depending on parameter */
783 /* "TransistorsDiffPair". */
784 /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */
785 /* containing other bits reserved for other purpose. */
786 return (uint32_t)(READ_BIT(*preg, (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK))
787 >> ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_OTR_TRIMOFFSETN_Pos : OPAMP_OTR_TRIMOFFSETP_Pos));
788 }
789
790 /**
791 * @}
792 */
793
794 /** @defgroup OPAMP_LL_EF_OPERATION Operation on OPAMP instance
795 * @{
796 */
797 /**
798 * @brief Enable OPAMP instance.
799 * @note After enable from off state, OPAMP requires a delay
800 * to fullfill wake up time specification.
801 * Refer to device datasheet, parameter "tWAKEUP".
802 * @rmtoll CSR OPAMPXEN LL_OPAMP_Enable
803 * @param OPAMPx OPAMP instance
804 * @retval None
805 */
LL_OPAMP_Enable(OPAMP_TypeDef * OPAMPx)806 __STATIC_INLINE void LL_OPAMP_Enable(OPAMP_TypeDef *OPAMPx)
807 {
808 SET_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
809 }
810
811 /**
812 * @brief Disable OPAMP instance.
813 * @rmtoll CSR OPAMPXEN LL_OPAMP_Disable
814 * @param OPAMPx OPAMP instance
815 * @retval None
816 */
LL_OPAMP_Disable(OPAMP_TypeDef * OPAMPx)817 __STATIC_INLINE void LL_OPAMP_Disable(OPAMP_TypeDef *OPAMPx)
818 {
819 CLEAR_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
820 }
821
822 /**
823 * @brief Get OPAMP instance enable state
824 * (0: OPAMP is disabled, 1: OPAMP is enabled)
825 * @rmtoll CSR OPAMPXEN LL_OPAMP_IsEnabled
826 * @param OPAMPx OPAMP instance
827 * @retval State of bit (1 or 0).
828 */
LL_OPAMP_IsEnabled(OPAMP_TypeDef * OPAMPx)829 __STATIC_INLINE uint32_t LL_OPAMP_IsEnabled(OPAMP_TypeDef *OPAMPx)
830 {
831 return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN) == (OPAMP_CSR_OPAMPxEN)) ? 1UL : 0UL);
832 }
833
834 /**
835 * @}
836 */
837
838 #if defined(USE_FULL_LL_DRIVER)
839 /** @defgroup OPAMP_LL_EF_Init Initialization and de-initialization functions
840 * @{
841 */
842
843 ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx);
844 ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
845 void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
846
847 /**
848 * @}
849 */
850 #endif /* USE_FULL_LL_DRIVER */
851
852 /**
853 * @}
854 */
855
856 /**
857 * @}
858 */
859
860 #endif /* OPAMP1 || OPAMP2 */
861
862 /**
863 * @}
864 */
865
866 #ifdef __cplusplus
867 }
868 #endif
869
870 #endif /* STM32L4xx_LL_OPAMP_H */
871
872 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
873