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