2 ******************************************************************************
3 * @file stm32l1xx_hal_opamp.h
4 * @author MCD Application Team
6 * @date 5-September-2014
7 * @brief Header file of OPAMP HAL module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32L1xx_HAL_OPAMP_H
40 #define __STM32L1xx_HAL_OPAMP_H
46 #if defined (STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined (STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) || defined (STM32L162xC) || defined (STM32L152xC) || defined (STM32L151xC)
48 /* Includes ------------------------------------------------------------------*/
49 #include "stm32l1xx_hal_def.h"
51 /** @addtogroup STM32L1xx_HAL_Driver
59 /* Exported types ------------------------------------------------------------*/
61 /** @defgroup OPAMP_Exported_Types OPAMP Exported Types
65 * @brief OPAMP Init structure definition
70 uint32_t PowerSupplyRange; /*!< Specifies the power supply range: above or under 2.4V.
71 This parameter must be a value of @ref OPAMP_PowerSupplyRange
72 Caution: This parameter is common to all OPAMP instances: a modification of this parameter for the selected OPAMP impacts the other OPAMP instances. */
74 uint32_t UserTrimming; /*!< Specifies the trimming mode
75 This parameter must be a value of @ref OPAMP_UserTrimming
76 UserTrimming is either factory or user trimming.
77 Caution: This parameter is common to all OPAMP instances: a modification of this parameter for the selected OPAMP impacts the other OPAMP instances. */
79 uint32_t Mode; /*!< Specifies the OPAMP mode
80 This parameter must be a value of @ref OPAMP_Mode
81 mode is either Standalone or Follower */
83 uint32_t InvertingInput; /*!< Specifies the inverting input in Standalone mode
84 - In Standalone mode: i.e when mode is OPAMP_STANDALONE_MODE
85 This parameter must be a value of @ref OPAMP_InvertingInput
86 InvertingInput is either VM0 or VM1
87 - In Follower mode: i.e when mode is OPAMP_FOLLOWER_MODE
88 This parameter is Not Applicable */
90 uint32_t NonInvertingInput; /*!< Specifies the non inverting input of the opamp:
91 This parameter must be a value of @ref OPAMP_NonInvertingInput
92 NonInvertingInput is either VP0, VP1 or VP2 */
94 uint32_t PowerMode; /*!< Specifies the power mode Normal or Low-Power.
95 This parameter must be a value of @ref OPAMP_PowerMode */
97 uint32_t TrimmingValueP; /*!< Specifies the offset trimming value (PMOS)
98 i.e. when UserTrimming is OPAMP_TRIMMING_USER.
99 This parameter must be a number between Min_Data = 0 and Max_Data = 30 (Trimming value 31 is forbidden) */
101 uint32_t TrimmingValueN; /*!< Specifies the offset trimming value (NMOS)
102 i.e. when UserTrimming is OPAMP_TRIMMING_USER.
103 This parameter must be a number between Min_Data = 0 and Max_Data = 30 (Trimming value 31 is forbidden) */
105 uint32_t TrimmingValuePLowPower; /*!< Specifies the offset trimming value (PMOS)
106 i.e. when UserTrimming is OPAMP_TRIMMING_USER.
107 This parameter must be a number between Min_Data = 0 and Max_Data = 30 (Trimming value 31 is forbidden) */
109 uint32_t TrimmingValueNLowPower; /*!< Specifies the offset trimming value (NMOS)
110 i.e. when UserTrimming is OPAMP_TRIMMING_USER.
111 This parameter must be a number between Min_Data = 0 and Max_Data = 30 (Trimming value 31 is forbidden) */
116 * @brief HAL State structures definition
121 HAL_OPAMP_STATE_RESET = 0x00000000, /*!< OPMAP is not yet Initialized */
123 HAL_OPAMP_STATE_READY = 0x00000001, /*!< OPAMP is initialized and ready for use */
124 HAL_OPAMP_STATE_CALIBBUSY = 0x00000002, /*!< OPAMP is enabled in auto calibration mode */
126 HAL_OPAMP_STATE_BUSY = 0x00000004, /*!< OPAMP is enabled and running in normal mode */
127 HAL_OPAMP_STATE_BUSYLOCKED = 0x00000005, /*!< OPAMP is locked
128 only system reset allows reconfiguring the opamp. */
130 }HAL_OPAMP_StateTypeDef;
133 * @brief OPAMP Handle Structure definition
137 OPAMP_TypeDef *Instance; /*!< OPAMP instance's registers base address */
138 OPAMP_InitTypeDef Init; /*!< OPAMP required parameters */
139 HAL_StatusTypeDef Status; /*!< OPAMP peripheral status */
140 HAL_LockTypeDef Lock; /*!< Locking object */
141 __IO HAL_OPAMP_StateTypeDef State; /*!< OPAMP communication state */
143 } OPAMP_HandleTypeDef;
146 * @brief OPAMP_TrimmingValueTypeDef @brief definition
149 typedef uint32_t OPAMP_TrimmingValueTypeDef;
155 /* Exported constants --------------------------------------------------------*/
156 /** @defgroup OPAMP_Exported_Constants OPAMP Exported Constants
163 #define OPAMP_TRIM_VALUE_MASK OPAMP_OTR_AO1_OPT_OFFSET_TRIM_LOW
168 #define OPAMP_CSR_INSTANCE_OFFSET ((uint32_t) 8) /* Offset of each OPAMP instance into register CSR */
169 #define OPAMP_OTR_INSTANCE_OFFSET ((uint32_t) 10) /* Offset of each OPAMP instance into register OTR */
172 /** @defgroup OPAMP_Mode OPAMP Mode
175 #define OPAMP_STANDALONE_MODE ((uint32_t)0x00000000) /*!< OPAMP standalone mode */
176 #define OPAMP_FOLLOWER_MODE ((uint32_t)0x00000001) /*!< OPAMP follower mode */
178 #define IS_OPAMP_FUNCTIONAL_NORMALMODE(INPUT) (((INPUT) == OPAMP_STANDALONE_MODE) || \
179 ((INPUT) == OPAMP_FOLLOWER_MODE))
184 /** @defgroup OPAMP_NonInvertingInput OPAMP NonInvertingInput
187 #define OPAMP_NONINVERTINGINPUT_VP0 ((uint32_t)0x00000000) /*!< Comparator non-inverting input connected to dedicated IO pin low-leakage */
188 #define OPAMP_NONINVERTINGINPUT_DAC_CH1 ((uint32_t)0x00000001) /*!< Comparator non-inverting input connected internally to DAC channel 1 */
189 #define OPAMP_NONINVERTINGINPUT_DAC_CH2 ((uint32_t)0x00000002) /*!< Comparator non-inverting input connected internally to DAC channel 2. Available on OPAMP2 only. */
191 #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_VP0) || \
192 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH1) || \
193 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH2) )
198 /** @defgroup OPAMP_InvertingInput OPAMP InvertingInput
201 #define OPAMP_INVERTINGINPUT_VM0 ((uint32_t)0x00000000) /*!< Comparator inverting input connected to dedicated IO pin low-leakage */
202 #define OPAMP_INVERTINGINPUT_VM1 ((uint32_t)0x00000001) /*!< Comparator inverting input connected to alternative IO pin available on some device packages */
204 #define OPAMP_INVERTINGINPUT_VINM OPAMP_INVERTINGINPUT_VM1 /*!< Alternate name for comparator inverting input connected to alternative IO pin available on some device packages */
206 #define IOPAMP_INVERTINGINPUT_VM0 OPAMP_INVERTINGINPUT_VM0 /* For compatibility with other STM32 devices */
207 #define IOPAMP_INVERTINGINPUT_VM1 OPAMP_INVERTINGINPUT_VM1 /* For compatibility with other STM32 devices */
209 #define IS_OPAMP_INVERTING_INPUT(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_VM0) || \
210 ((INPUT) == OPAMP_INVERTINGINPUT_VM1) )
215 /** @defgroup OPAMP_PowerMode OPAMP PowerMode
218 #define OPAMP_POWERMODE_NORMAL ((uint32_t)0x00000000)
219 #define OPAMP_POWERMODE_LOWPOWER ((uint32_t)0x00000001)
221 #define IS_OPAMP_POWERMODE(TRIMMING) (((TRIMMING) == OPAMP_POWERMODE_NORMAL) || \
222 ((TRIMMING) == OPAMP_POWERMODE_LOWPOWER) )
227 /** @defgroup OPAMP_PowerSupplyRange OPAMP PowerSupplyRange
230 #define OPAMP_POWERSUPPLY_LOW ((uint32_t)0x00000000) /*!< Power supply range low (VDDA lower than 2.4V) */
231 #define OPAMP_POWERSUPPLY_HIGH OPAMP_CSR_AOP_RANGE /*!< Power supply range high (VDDA higher than 2.4V) */
233 #define IS_OPAMP_POWER_SUPPLY_RANGE(RANGE) (((RANGE) == OPAMP_POWERSUPPLY_LOW) || \
234 ((RANGE) == OPAMP_POWERSUPPLY_HIGH) )
239 /** @defgroup OPAMP_UserTrimming OPAMP UserTrimming
242 #define OPAMP_TRIMMING_FACTORY ((uint32_t)0x00000000) /*!< Factory trimming */
243 #define OPAMP_TRIMMING_USER OPAMP_OTR_OT_USER /*!< User trimming */
245 #define IS_OPAMP_TRIMMING(TRIMMING) (((TRIMMING) == OPAMP_TRIMMING_FACTORY) || \
246 ((TRIMMING) == OPAMP_TRIMMING_USER))
251 /** @defgroup OPAMP_FactoryTrimming OPAMP FactoryTrimming
254 #define OPAMP_FACTORYTRIMMING_DUMMY ((uint32_t)0xFFFFFFFF) /*!< Dummy value if trimming value could not be retrieved */
256 #define OPAMP_FACTORYTRIMMING_P ((uint32_t)0x00000000) /*!< Offset trimming P */
257 #define OPAMP_FACTORYTRIMMING_N POSITION_VAL(OPAMP_OTR_AO1_OPT_OFFSET_TRIM_HIGH) /*!< Offset trimming N */
259 #define IS_OPAMP_FACTORYTRIMMING(TRIMMING) (((TRIMMING) == OPAMP_FACTORYTRIMMING_N) || \
260 ((TRIMMING) == OPAMP_FACTORYTRIMMING_P) )
269 /* Private constants ---------------------------------------------------------*/
270 /** @defgroup OPAMP_Private_Constants OPAMP Private Constants
274 /* Offset trimming time: during calibration, minimum time needed between two */
275 /* steps to have 1 mV accuracy. */
276 /* Refer to datasheet, electrical characteristics: parameter tOFFTRIM Typ=1ms.*/
278 #define OPAMP_TRIMMING_DELAY ((uint32_t) 1)
285 /* Exported macros -----------------------------------------------------------*/
287 /** @defgroup OPAMP_Private_Macro OPAMP Private Macro
291 /** @brief Reset OPAMP handle state
292 * @param __HANDLE__: OPAMP handle.
295 #define __HAL_OPAMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_OPAMP_STATE_RESET)
302 /* Private macro -------------------------------------------------------------*/
304 /** @defgroup OPAMP_Private_Macro OPAMP Private Macro
309 * @brief Select the OPAMP bit OPAxPD (power-down) corresponding to the
310 * selected OPAMP instance.
311 * @param __HANDLE__: OPAMP handle
314 #define __OPAMP_CSR_OPAXPD(__HANDLE__) \
315 (OPAMP_CSR_OPA1PD << (__OPAMP_INSTANCE_DECIMAL__(__HANDLE__) * OPAMP_CSR_INSTANCE_OFFSET))
318 * @brief Select the OPAMP bit S3SELx (switch 3) corresponding to the
319 * selected OPAMP instance.
320 * @param __HANDLE__: OPAMP handle
323 #define __OPAMP_CSR_S3SELX(__HANDLE__) \
324 (OPAMP_CSR_S3SEL1 << (__OPAMP_INSTANCE_DECIMAL__(__HANDLE__) * OPAMP_CSR_INSTANCE_OFFSET))
327 * @brief Select the OPAMP bit S4SELx (switch 4) corresponding to the
328 * selected OPAMP instance.
329 * @param __HANDLE__: OPAMP handle
332 #define __OPAMP_CSR_S4SELX(__HANDLE__) \
333 (OPAMP_CSR_S4SEL1 << (__OPAMP_INSTANCE_DECIMAL__(__HANDLE__) * OPAMP_CSR_INSTANCE_OFFSET))
336 * @brief Select the OPAMP bit S5SELx (switch 5) corresponding to the
337 * selected OPAMP instance.
338 * @param __HANDLE__: OPAMP handle
341 #define __OPAMP_CSR_S5SELX(__HANDLE__) \
342 (OPAMP_CSR_S5SEL1 << (__OPAMP_INSTANCE_DECIMAL__(__HANDLE__) * OPAMP_CSR_INSTANCE_OFFSET))
345 * @brief Select the OPAMP bit S3SELx (switch 6) corresponding to the
346 * selected OPAMP instance.
347 * @param __HANDLE__: OPAMP handle
350 #define __OPAMP_CSR_S6SELX(__HANDLE__) \
351 (OPAMP_CSR_S6SEL1 << (__OPAMP_INSTANCE_DECIMAL__(__HANDLE__) * OPAMP_CSR_INSTANCE_OFFSET))
354 * @brief Select the OPAMP bit OPAxCAL_L (offset calibration for differential
355 * pair P) corresponding to the selected OPAMP instance.
356 * @param __HANDLE__: OPAMP handle
359 #define __OPAMP_CSR_OPAXCAL_L(__HANDLE__) \
360 (OPAMP_CSR_OPA1CAL_L << (__OPAMP_INSTANCE_DECIMAL__(__HANDLE__) * OPAMP_CSR_INSTANCE_OFFSET))
363 * @brief Select the OPAMP bit OPAxCAL_H (offset calibration for differential
364 * pair N) corresponding to the selected OPAMP instance.
365 * @param __HANDLE__: OPAMP handle
368 #define __OPAMP_CSR_OPAXCAL_H(__HANDLE__) \
369 (OPAMP_CSR_OPA1CAL_H << (__OPAMP_INSTANCE_DECIMAL__(__HANDLE__) * OPAMP_CSR_INSTANCE_OFFSET))
372 * @brief Select the OPAMP bit OPAxLPM (low power mode) corresponding to the
373 * selected OPAMP instance.
374 * @param __HANDLE__: OPAMP handle
377 #define __OPAMP_CSR_OPAXLPM(__HANDLE__) \
378 (OPAMP_CSR_OPA1LPM << (__OPAMP_INSTANCE_DECIMAL__(__HANDLE__) * OPAMP_CSR_INSTANCE_OFFSET))
381 * @brief Select the OPAMP bits of all switches corresponding to the
382 * selected OPAMP instance.
383 * @param __HANDLE__: OPAMP handle
386 #define __OPAMP_CSR_ALL_SWITCHES(__HANDLE__) \
387 ( ( ((__HANDLE__)->Instance != OPAMP2) \
390 ((OPAMP_CSR_S3SEL1 | OPAMP_CSR_S4SEL1 | OPAMP_CSR_S5SEL1 | OPAMP_CSR_S6SEL1) << (__OPAMP_INSTANCE_DECIMAL__(__HANDLE__) * OPAMP_CSR_INSTANCE_OFFSET)) \
392 (OPAMP_CSR_ANAWSEL1 << (__OPAMP_INSTANCE_DECIMAL__(__HANDLE__))) \
396 ((OPAMP_CSR_S3SEL1 | OPAMP_CSR_S4SEL1 | OPAMP_CSR_S5SEL1 | OPAMP_CSR_S6SEL1) << (__OPAMP_INSTANCE_DECIMAL__(__HANDLE__) * OPAMP_CSR_INSTANCE_OFFSET)) \
398 (OPAMP_CSR_ANAWSEL1 << (__OPAMP_INSTANCE_DECIMAL__(__HANDLE__))) \
405 * @brief Select the OPAMP bit ANAWSELx (switch SanA) corresponding to the
406 * selected OPAMP instance.
407 * @param __HANDLE__: OPAMP handle
410 #define __OPAMP_CSR_ANAWSELX(__HANDLE__) \
411 (OPAMP_CSR_ANAWSEL1 << (__OPAMP_INSTANCE_DECIMAL__(__HANDLE__)))
414 * @brief Select the OPAMP bit OPAxCALOUT in function of the selected
416 * @param __HANDLE__: OPAMP handle
419 #define __OPAMP_CSR_OPAXCALOUT(__HANDLE__) \
420 (OPAMP_CSR_OPA1CALOUT << (__OPAMP_INSTANCE_DECIMAL__(__HANDLE__)))
423 * @brief Select the OPAMP trimming bits position value (position of LSB)
424 * in register OPAMP_OTR or register OPAMP_LPOTR in function of the selected
425 * OPAMP instance and the transistors differential pair high (PMOS) or
427 * @param __HANDLE__: OPAMP handle
428 * @param __TRIM_HIGH_LOW__: transistors differential pair high or low.
429 * Must be a value of @ref OPAMP_FactoryTrimming.
432 #define __OPAMP_OFFSET_TRIM_BITSPOSITION(__HANDLE__, __TRIM_HIGH_LOW__) \
433 ((__OPAMP_INSTANCE_DECIMAL__((__HANDLE__)) * OPAMP_OTR_INSTANCE_OFFSET) + (__TRIM_HIGH_LOW__))
436 * @brief Shift the OPAMP trimming bits to register OPAMP_OTR or register
437 * OPAMP_LPOTR in function of the selected OPAMP instance and the transistors
438 * differential pair high (PMOS) or low (NMOS).
439 * @param __HANDLE__: OPAMP handle
440 * @param __TRIM_HIGH_LOW__: transistors differential pair high or low.
441 * Must be a value of @ref OPAMP_FactoryTrimming.
442 * @param __TRIMMING_VALUE__: Trimming value
445 #define __OPAMP_OFFSET_TRIM_SET(__HANDLE__, __TRIM_HIGH_LOW__, __TRIMMING_VALUE__) \
446 ((__TRIMMING_VALUE__) << (__OPAMP_OFFSET_TRIM_BITSPOSITION((__HANDLE__), (__TRIM_HIGH_LOW__))))
449 * @brief Check that trimming value is within correct range
450 * @param TRIMMINGVALUE: OPAMP trimming value
453 #define IS_OPAMP_TRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 0x1E)
460 /* Include OPAMP HAL Extension module */
461 #include "stm32l1xx_hal_opamp_ex.h"
463 /* Exported functions --------------------------------------------------------*/
465 /** @addtogroup OPAMP_Exported_Functions
469 /** @addtogroup OPAMP_Exported_Functions_Group1
472 /* Initialization/de-initialization functions **********************************/
473 HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef *hopamp);
474 HAL_StatusTypeDef HAL_OPAMP_DeInit (OPAMP_HandleTypeDef *hopamp);
475 void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef *hopamp);
476 void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef *hopamp);
481 /** @addtogroup OPAMP_Exported_Functions_Group2
484 /* I/O operation functions *****************************************************/
485 HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef *hopamp);
486 HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef *hopamp);
487 HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef *hopamp);
488 OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset);
493 /** @addtogroup OPAMP_Exported_Functions_Group3
496 /* Peripheral Control functions ************************************************/
497 HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef *hopamp);
502 /** @addtogroup OPAMP_Exported_Functions_Group4
505 /* Peripheral State functions **************************************************/
506 HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(OPAMP_HandleTypeDef *hopamp);
526 #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE || STM32L162xC || STM32L152xC || STM32L151xC */
531 #endif /* __STM32L1xx_HAL_OPAMP_H */
533 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/