1 /** 2 ****************************************************************************** 3 * @file stm32l4xx_hal_opamp.h 4 * @author MCD Application Team 5 * @brief Header file of OPAMP HAL 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 STM32L4xx_HAL_OPAMP_H 21 #define STM32L4xx_HAL_OPAMP_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32l4xx_hal_def.h" 29 30 /** @addtogroup STM32L4xx_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 /** 148 * @} 149 */ 150 151 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1) 152 /** 153 * @brief HAL OPAMP Callback ID enumeration definition 154 */ 155 typedef enum 156 { 157 HAL_OPAMP_MSPINIT_CB_ID = 0x01U, /*!< OPAMP MspInit Callback ID */ 158 HAL_OPAMP_MSPDEINIT_CB_ID = 0x02U, /*!< OPAMP MspDeInit Callback ID */ 159 HAL_OPAMP_ALL_CB_ID = 0x03U /*!< OPAMP All ID */ 160 }HAL_OPAMP_CallbackIDTypeDef; 161 162 /** 163 * @brief HAL OPAMP Callback pointer definition 164 */ 165 typedef void (*pOPAMP_CallbackTypeDef)(OPAMP_HandleTypeDef *hopamp); 166 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */ 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 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \ 322 defined (STM32L496xx) || defined (STM32L4A6xx) || \ 323 defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \ 324 defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx) 325 #define IS_OPAMP_INVERTING_INPUT_STANDALONE(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_IO0) || \ 326 ((INPUT) == OPAMP_INVERTINGINPUT_IO1)) 327 #endif /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx */ 328 /* STM32L496xx STM32L4A6xx */ 329 /* STM32L4P5xx STM32L4Q5xx */ 330 /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */ 331 332 #if defined (STM32L412xx) || defined (STM32L422xx) || \ 333 defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \ 334 defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) 335 #define IS_OPAMP_INVERTING_INPUT_STANDALONE(INPUT) ((INPUT) == OPAMP_INVERTINGINPUT_IO0) 336 #endif /* STM32L412xx STM32L422xx */ 337 /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */ 338 /* STM32L451xx STM32L452xx STM32L462xx */ 339 340 #if defined (STM32L412xx) || defined (STM32L422xx) 341 #define IS_OPAMP_NONINVERTING_INPUT(INPUT) ((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) 342 #endif /* STM32L412xx STM32L422xx */ 343 344 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \ 345 defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || \ 346 defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \ 347 defined (STM32L496xx) || defined (STM32L4A6xx) || \ 348 defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \ 349 defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx) 350 #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \ 351 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH)) 352 #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */ 353 /* STM32L451xx STM32L452xx STM32L462xx */ 354 /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx */ 355 /* STM32L496xx STM32L4A6xx */ 356 /* STM32L4P5xx STM32L4Q5xx */ 357 /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */ 358 359 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \ 360 defined (STM32L496xx) || defined (STM32L4A6xx) || \ 361 defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \ 362 defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx) 363 #define IS_OPAMP_INVERTING_INPUT_PGA(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_IO0) || \ 364 ((INPUT) == OPAMP_INVERTINGINPUT_IO1) || \ 365 ((INPUT) == OPAMP_INVERTINGINPUT_CONNECT_NO)) 366 #endif /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx */ 367 /* STM32L496xx STM32L4A6xx */ 368 /* STM32L4P5xx STM32L4Q5xx */ 369 /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */ 370 371 #if defined (STM32L412xx) || defined (STM32L422xx) || \ 372 defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \ 373 defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) 374 #define IS_OPAMP_INVERTING_INPUT_PGA(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_IO0) || \ 375 ((INPUT) == OPAMP_INVERTINGINPUT_CONNECT_NO)) 376 #endif /* STM32L412xx STM32L422xx */ 377 /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */ 378 /* STM32L451xx STM32L452xx STM32L462xx */ 379 380 #define IS_OPAMP_PGA_GAIN(GAIN) (((GAIN) == OPAMP_PGA_GAIN_2) || \ 381 ((GAIN) == OPAMP_PGA_GAIN_4) || \ 382 ((GAIN) == OPAMP_PGA_GAIN_8) || \ 383 ((GAIN) == OPAMP_PGA_GAIN_16)) 384 385 #define IS_OPAMP_POWERMODE(TRIMMING) (((TRIMMING) == OPAMP_POWERMODE_NORMALPOWER) || \ 386 ((TRIMMING) == OPAMP_POWERMODE_LOWPOWER) ) 387 388 #define IS_OPAMP_POWER_SUPPLY_RANGE(RANGE) (((RANGE) == OPAMP_POWERSUPPLY_LOW) || \ 389 ((RANGE) == OPAMP_POWERSUPPLY_HIGH) ) 390 391 #define IS_OPAMP_TRIMMING(TRIMMING) (((TRIMMING) == OPAMP_TRIMMING_FACTORY) || \ 392 ((TRIMMING) == OPAMP_TRIMMING_USER)) 393 394 395 #define IS_OPAMP_TRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 31U) 396 397 #define IS_OPAMP_FACTORYTRIMMING(TRIMMING) (((TRIMMING) == OPAMP_FACTORYTRIMMING_N) || \ 398 ((TRIMMING) == OPAMP_FACTORYTRIMMING_P)) 399 400 /** 401 * @} 402 */ 403 404 /* Include OPAMP HAL Extended module */ 405 #include "stm32l4xx_hal_opamp_ex.h" 406 407 /* Exported functions --------------------------------------------------------*/ 408 /** @addtogroup OPAMP_Exported_Functions 409 * @{ 410 */ 411 412 /** @addtogroup OPAMP_Exported_Functions_Group1 413 * @{ 414 */ 415 /* Initialization/de-initialization functions **********************************/ 416 HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef *hopamp); 417 HAL_StatusTypeDef HAL_OPAMP_DeInit (OPAMP_HandleTypeDef *hopamp); 418 void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef *hopamp); 419 void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef *hopamp); 420 /** 421 * @} 422 */ 423 424 /** @addtogroup OPAMP_Exported_Functions_Group2 425 * @{ 426 */ 427 428 /* I/O operation functions *****************************************************/ 429 HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef *hopamp); 430 HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef *hopamp); 431 HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef *hopamp); 432 433 /** 434 * @} 435 */ 436 437 /** @addtogroup OPAMP_Exported_Functions_Group3 438 * @{ 439 */ 440 441 /* Peripheral Control functions ************************************************/ 442 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1) 443 /* OPAMP callback registering/unregistering */ 444 HAL_StatusTypeDef HAL_OPAMP_RegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackID, pOPAMP_CallbackTypeDef pCallback); 445 HAL_StatusTypeDef HAL_OPAMP_UnRegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackID); 446 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */ 447 448 HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef *hopamp); 449 HAL_OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset); 450 451 /** 452 * @} 453 */ 454 455 /** @addtogroup OPAMP_Exported_Functions_Group4 456 * @{ 457 */ 458 459 /* Peripheral State functions **************************************************/ 460 HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(OPAMP_HandleTypeDef *hopamp); 461 462 /** 463 * @} 464 */ 465 466 /** 467 * @} 468 */ 469 470 /** 471 * @} 472 */ 473 474 /** 475 * @} 476 */ 477 478 #ifdef __cplusplus 479 } 480 #endif 481 482 #endif /* STM32L4xx_HAL_OPAMP_H */ 483