1 /** 2 ****************************************************************************** 3 * @file stm32l5xx_hal_opamp.h 4 * @author MCD Application Team 5 * @brief Header file of OPAMP HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2019 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 STM32L5xx_HAL_OPAMP_H 21 #define STM32L5xx_HAL_OPAMP_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32l5xx_hal_def.h" 29 30 /** @addtogroup STM32L5xx_HAL_Driver 31 * @{ 32 */ 33 34 /** @addtogroup OPAMP 35 * @{ 36 */ 37 38 /* Exported types ------------------------------------------------------------*/ 39 40 /** @defgroup OPAMP_Exported_Types OPAMP Exported Types 41 * @{ 42 */ 43 44 /** 45 * @brief OPAMP Init structure definition 46 */ 47 48 typedef struct 49 { 50 uint32_t PowerSupplyRange; /*!< Specifies the power supply range: above or under 2.4V. 51 This parameter must be a value of @ref OPAMP_PowerSupplyRange 52 Caution: This parameter is common to all OPAMP instances: a modification of this parameter for the selected OPAMP impacts the other OPAMP instances. */ 53 54 uint32_t PowerMode; /*!< Specifies the power mode Normal or Low-Power. 55 This parameter must be a value of @ref OPAMP_PowerMode */ 56 57 uint32_t Mode; /*!< Specifies the OPAMP mode 58 This parameter must be a value of @ref OPAMP_Mode 59 mode is either Standalone, - Follower or PGA */ 60 61 uint32_t InvertingInput; /*!< Specifies the inverting input in Standalone & PGA modes 62 - In Standalone mode: i.e. when mode is OPAMP_STANDALONE_MODE 63 & PGA mode: i.e. when mode is OPAMP_PGA_MODE 64 This parameter must be a value of @ref OPAMP_InvertingInput 65 - In Follower mode i.e. when mode is OPAMP_FOLLOWER_MODE 66 This parameter is Not Applicable */ 67 68 uint32_t NonInvertingInput; /*!< Specifies the non inverting input of the opamp: 69 This parameter must be a value of @ref OPAMP_NonInvertingInput */ 70 71 uint32_t PgaGain; /*!< Specifies the gain in PGA mode 72 i.e. when mode is OPAMP_PGA_MODE. 73 This parameter must be a value of @ref OPAMP_PgaGain (2, 4, 8 or 16 ) */ 74 75 uint32_t UserTrimming; /*!< Specifies the trimming mode 76 This parameter must be a value of @ref OPAMP_UserTrimming 77 UserTrimming is either factory or user trimming.*/ 78 79 uint32_t TrimmingValueP; /*!< Specifies the offset trimming value (PMOS) 80 i.e. when UserTrimming is OPAMP_TRIMMING_USER. 81 This parameter must be a number between Min_Data = 0 and Max_Data = 31 82 16 is typical default value */ 83 84 uint32_t TrimmingValueN; /*!< Specifies the offset trimming value (NMOS) 85 i.e. when UserTrimming is OPAMP_TRIMMING_USER. 86 This parameter must be a number between Min_Data = 0 and Max_Data = 31 87 16 is typical default value */ 88 89 uint32_t TrimmingValuePLowPower; /*!< Specifies the offset trimming value (PMOS) 90 i.e. when UserTrimming is OPAMP_TRIMMING_USER. 91 This parameter must be a number between Min_Data = 0 and Max_Data = 31 92 16 is typical default value */ 93 94 uint32_t TrimmingValueNLowPower; /*!< Specifies the offset trimming value (NMOS) 95 i.e. when UserTrimming is OPAMP_TRIMMING_USER. 96 This parameter must be a number between Min_Data = 0 and Max_Data = 31 97 16 is typical default value */ 98 99 }OPAMP_InitTypeDef; 100 101 /** 102 * @brief HAL State structures definition 103 */ 104 105 typedef enum 106 { 107 HAL_OPAMP_STATE_RESET = 0x00000000, /*!< OPAMP is not yet Initialized */ 108 109 HAL_OPAMP_STATE_READY = 0x00000001, /*!< OPAMP is initialized and ready for use */ 110 HAL_OPAMP_STATE_CALIBBUSY = 0x00000002, /*!< OPAMP is enabled in auto calibration mode */ 111 112 HAL_OPAMP_STATE_BUSY = 0x00000004, /*!< OPAMP is enabled and running in normal mode */ 113 HAL_OPAMP_STATE_BUSYLOCKED = 0x00000005 /*!< OPAMP is locked 114 only system reset allows reconfiguring the opamp. */ 115 116 }HAL_OPAMP_StateTypeDef; 117 118 /** 119 * @brief OPAMP Handle Structure definition 120 */ 121 122 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1) 123 typedef struct __OPAMP_HandleTypeDef 124 #else 125 typedef struct 126 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */ 127 { 128 OPAMP_TypeDef *Instance; /*!< OPAMP instance's registers base address */ 129 OPAMP_InitTypeDef Init; /*!< OPAMP required parameters */ 130 HAL_StatusTypeDef Status; /*!< OPAMP peripheral status */ 131 HAL_LockTypeDef Lock; /*!< Locking object */ 132 __IO HAL_OPAMP_StateTypeDef State; /*!< OPAMP communication state */ 133 134 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1) 135 void (* MspInitCallback) (struct __OPAMP_HandleTypeDef *hopamp); 136 void (* MspDeInitCallback) (struct __OPAMP_HandleTypeDef *hopamp); 137 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */ 138 139 }OPAMP_HandleTypeDef; 140 141 /** 142 * @brief HAl_OPAMP_TrimmingValueTypeDef definition 143 */ 144 145 typedef uint32_t HAL_OPAMP_TrimmingValueTypeDef; 146 147 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1) 148 /** 149 * @brief HAL OPAMP Callback ID enumeration definition 150 */ 151 typedef enum 152 { 153 HAL_OPAMP_MSPINIT_CB_ID = 0x01U, /*!< OPAMP MspInit Callback ID */ 154 HAL_OPAMP_MSPDEINIT_CB_ID = 0x02U, /*!< OPAMP MspDeInit Callback ID */ 155 HAL_OPAMP_ALL_CB_ID = 0x03U /*!< OPAMP All ID */ 156 }HAL_OPAMP_CallbackIDTypeDef; 157 158 /** 159 * @brief HAL OPAMP Callback pointer definition 160 */ 161 typedef void (*pOPAMP_CallbackTypeDef)(OPAMP_HandleTypeDef *hopamp); 162 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */ 163 164 /** 165 * @} 166 */ 167 168 169 /* Exported constants --------------------------------------------------------*/ 170 171 /** @defgroup OPAMP_Exported_Constants OPAMP Exported Constants 172 * @{ 173 */ 174 175 /** @defgroup OPAMP_Mode OPAMP Mode 176 * @{ 177 */ 178 #define OPAMP_STANDALONE_MODE 0x00000000U /*!< standalone mode */ 179 #define OPAMP_PGA_MODE OPAMP_CSR_OPAMODE_1 /*!< PGA mode */ 180 #define OPAMP_FOLLOWER_MODE OPAMP_CSR_OPAMODE /*!< follower mode */ 181 182 /** 183 * @} 184 */ 185 186 /** @defgroup OPAMP_NonInvertingInput OPAMP Non Inverting Input 187 * @{ 188 */ 189 190 #define OPAMP_NONINVERTINGINPUT_IO0 0x00000000U /*!< OPAMP non-inverting input connected to dedicated IO pin */ 191 #define OPAMP_NONINVERTINGINPUT_DAC_CH OPAMP_CSR_VPSEL /*!< OPAMP non-inverting input connected internally to DAC channel */ 192 193 /** 194 * @} 195 */ 196 197 /** @defgroup OPAMP_InvertingInput OPAMP Inverting Input 198 * @{ 199 */ 200 201 #define OPAMP_INVERTINGINPUT_IO0 0x00000000U /*!< OPAMP inverting input connected to dedicated IO pin low-leakage */ 202 #define OPAMP_INVERTINGINPUT_IO1 OPAMP_CSR_VMSEL_0 /*!< OPAMP inverting input connected to alternative IO pin available on some device packages */ 203 #define OPAMP_INVERTINGINPUT_CONNECT_NO OPAMP_CSR_VMSEL_1 /*!< OPAMP inverting input not connected externally (PGA mode only) */ 204 205 /** 206 * @} 207 */ 208 209 /** @defgroup OPAMP_PgaGain OPAMP Pga Gain 210 * @{ 211 */ 212 213 #define OPAMP_PGA_GAIN_2 0x00000000U /*!< PGA gain = 2 */ 214 #define OPAMP_PGA_GAIN_4 OPAMP_CSR_PGGAIN_0 /*!< PGA gain = 4 */ 215 #define OPAMP_PGA_GAIN_8 OPAMP_CSR_PGGAIN_1 /*!< PGA gain = 8 */ 216 #define OPAMP_PGA_GAIN_16 (OPAMP_CSR_PGGAIN_0 | OPAMP_CSR_PGGAIN_1) /*!< PGA gain = 16 */ 217 218 /** 219 * @} 220 */ 221 222 /** @defgroup OPAMP_PowerMode OPAMP PowerMode 223 * @{ 224 */ 225 #define OPAMP_POWERMODE_NORMALPOWER 0x00000000U /*!< OPAMP power mode normal */ 226 #define OPAMP_POWERMODE_LOWPOWER OPAMP_CSR_OPALPM /*!< OPAMP power mode low-power */ 227 228 /** 229 * @} 230 */ 231 232 /** @defgroup OPAMP_PowerSupplyRange OPAMP PowerSupplyRange 233 * @{ 234 */ 235 #define OPAMP_POWERSUPPLY_LOW 0x00000000U /*!< Power supply range low (VDDA lower than 2.4V) */ 236 #define OPAMP_POWERSUPPLY_HIGH OPAMP1_CSR_OPARANGE /*!< Power supply range high (VDDA higher than 2.4V) */ 237 238 /** 239 * @} 240 */ 241 242 /** @defgroup OPAMP_UserTrimming OPAMP User Trimming 243 * @{ 244 */ 245 #define OPAMP_TRIMMING_FACTORY 0x00000000U /*!< Factory trimming */ 246 #define OPAMP_TRIMMING_USER OPAMP_CSR_USERTRIM /*!< User trimming */ 247 248 /** 249 * @} 250 */ 251 252 /** @defgroup OPAMP_FactoryTrimming OPAMP Factory Trimming 253 * @{ 254 */ 255 #define OPAMP_FACTORYTRIMMING_DUMMY 0xFFFFFFFFU /*!< Dummy value if trimming value could not be retrieved */ 256 #define OPAMP_FACTORYTRIMMING_N 0U /*!< Offset trimming N */ 257 #define OPAMP_FACTORYTRIMMING_P 1U /*!< Offset trimming P */ 258 259 /** 260 * @} 261 */ 262 263 /** 264 * @} 265 */ 266 267 /* Private constants ---------------------------------------------------------*/ 268 /** @defgroup OPAMP_Private_Constants OPAMP Private Constants 269 * @brief OPAMP Private constants and defines 270 * @{ 271 */ 272 273 /* NONINVERTING bit position in OTR & LPOTR */ 274 #define OPAMP_INPUT_NONINVERTING ((uint32_t) 8) /*!< Non inverting input */ 275 276 /* Offset trimming time: during calibration, minimum time needed between two */ 277 /* steps to have 1 mV accuracy. */ 278 /* Refer to datasheet, electrical characteristics: parameter tOFFTRIM Typ=1ms.*/ 279 /* Unit: ms. */ 280 #define OPAMP_TRIMMING_DELAY ((uint32_t) 1) 281 282 /** 283 * @} 284 */ 285 286 /* Exported macros -----------------------------------------------------------*/ 287 /** @defgroup OPAMP_Exported_Macros OPAMP Exported Macros 288 * @{ 289 */ 290 291 /** @brief Reset OPAMP handle state. 292 * @param __HANDLE__ OPAMP handle. 293 * @retval None 294 */ 295 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1) 296 #define __HAL_OPAMP_RESET_HANDLE_STATE(__HANDLE__) do { \ 297 (__HANDLE__)->State = HAL_OPAMP_STATE_RESET; \ 298 (__HANDLE__)->MspInitCallback = NULL; \ 299 (__HANDLE__)->MspDeInitCallback = NULL; \ 300 } while(0) 301 #else 302 #define __HAL_OPAMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_OPAMP_STATE_RESET) 303 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */ 304 305 306 307 /** 308 * @} 309 */ 310 311 /* Private macro -------------------------------------------------------------*/ 312 313 /** @defgroup OPAMP_Private_Macros OPAMP Private Macros 314 * @{ 315 */ 316 317 #define IS_OPAMP_FUNCTIONAL_NORMALMODE(INPUT) (((INPUT) == OPAMP_STANDALONE_MODE) || \ 318 ((INPUT) == OPAMP_PGA_MODE) || \ 319 ((INPUT) == OPAMP_FOLLOWER_MODE)) 320 321 #define IS_OPAMP_INVERTING_INPUT_STANDALONE(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_IO0) || \ 322 ((INPUT) == OPAMP_INVERTINGINPUT_IO1)) 323 324 #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \ 325 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH)) 326 327 #define IS_OPAMP_INVERTING_INPUT_PGA(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_IO0) || \ 328 ((INPUT) == OPAMP_INVERTINGINPUT_IO1) || \ 329 ((INPUT) == OPAMP_INVERTINGINPUT_CONNECT_NO)) 330 331 #define IS_OPAMP_PGA_GAIN(GAIN) (((GAIN) == OPAMP_PGA_GAIN_2) || \ 332 ((GAIN) == OPAMP_PGA_GAIN_4) || \ 333 ((GAIN) == OPAMP_PGA_GAIN_8) || \ 334 ((GAIN) == OPAMP_PGA_GAIN_16)) 335 336 #define IS_OPAMP_POWERMODE(TRIMMING) (((TRIMMING) == OPAMP_POWERMODE_NORMALPOWER) || \ 337 ((TRIMMING) == OPAMP_POWERMODE_LOWPOWER) ) 338 339 #define IS_OPAMP_POWER_SUPPLY_RANGE(RANGE) (((RANGE) == OPAMP_POWERSUPPLY_LOW) || \ 340 ((RANGE) == OPAMP_POWERSUPPLY_HIGH) ) 341 342 #define IS_OPAMP_TRIMMING(TRIMMING) (((TRIMMING) == OPAMP_TRIMMING_FACTORY) || \ 343 ((TRIMMING) == OPAMP_TRIMMING_USER)) 344 345 346 #define IS_OPAMP_TRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 31U) 347 348 #define IS_OPAMP_FACTORYTRIMMING(TRIMMING) (((TRIMMING) == OPAMP_FACTORYTRIMMING_N) || \ 349 ((TRIMMING) == OPAMP_FACTORYTRIMMING_P)) 350 351 /** 352 * @} 353 */ 354 355 /* Include OPAMP HAL Extended module */ 356 #include "stm32l5xx_hal_opamp_ex.h" 357 358 /* Exported functions --------------------------------------------------------*/ 359 /** @addtogroup OPAMP_Exported_Functions 360 * @{ 361 */ 362 363 /** @addtogroup OPAMP_Exported_Functions_Group1 364 * @{ 365 */ 366 /* Initialization/de-initialization functions **********************************/ 367 HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef *hopamp); 368 HAL_StatusTypeDef HAL_OPAMP_DeInit (OPAMP_HandleTypeDef *hopamp); 369 void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef *hopamp); 370 void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef *hopamp); 371 /** 372 * @} 373 */ 374 375 /** @addtogroup OPAMP_Exported_Functions_Group2 376 * @{ 377 */ 378 379 /* I/O operation functions *****************************************************/ 380 HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef *hopamp); 381 HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef *hopamp); 382 HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef *hopamp); 383 384 /** 385 * @} 386 */ 387 388 /** @addtogroup OPAMP_Exported_Functions_Group3 389 * @{ 390 */ 391 392 /* Peripheral Control functions ************************************************/ 393 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1) 394 /* OPAMP callback registering/unregistering */ 395 HAL_StatusTypeDef HAL_OPAMP_RegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackID, pOPAMP_CallbackTypeDef pCallback); 396 HAL_StatusTypeDef HAL_OPAMP_UnRegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackID); 397 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */ 398 399 HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef *hopamp); 400 HAL_OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset); 401 402 /** 403 * @} 404 */ 405 406 /** @addtogroup OPAMP_Exported_Functions_Group4 407 * @{ 408 */ 409 410 /* Peripheral State functions **************************************************/ 411 HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(OPAMP_HandleTypeDef *hopamp); 412 413 /** 414 * @} 415 */ 416 417 /** 418 * @} 419 */ 420 421 /** 422 * @} 423 */ 424 425 /** 426 * @} 427 */ 428 429 #ifdef __cplusplus 430 } 431 #endif 432 433 #endif /* STM32L5xx_HAL_OPAMP_H */ 434 435