1 /** 2 ********************************************************************************************************************** 3 * @file stm32h5xx_hal_opamp.h 4 * @author MCD Application Team 5 * @brief Header file of OPAMP HAL module. 6 ********************************************************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2022 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 STM32H5xx_HAL_OPAMP_H 21 #define STM32H5xx_HAL_OPAMP_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ----------------------------------------------------------------------------------------------------------*/ 28 #include "stm32h5xx_hal_def.h" 29 30 /** @addtogroup STM32H5xx_HAL_Driver 31 * @{ 32 */ 33 #if defined (OPAMP1) 34 35 /** @addtogroup OPAMP 36 * @{ 37 */ 38 39 /* Exported types ----------------------------------------------------------------------------------------------------*/ 40 41 /** @defgroup OPAMP_Exported_Types OPAMP Exported Types 42 * @{ 43 */ 44 45 /** 46 * @brief OPAMP Init structure definition 47 */ 48 49 typedef struct 50 { 51 52 uint32_t PowerMode; /*!< Specifies the power mode Normal or High Speed. 53 This parameter must be a value of @ref OPAMP_PowerMode */ 54 55 uint32_t Mode; /*!< Specifies the OPAMP mode 56 This parameter must be a value of @ref OPAMP_Mode 57 mode is either Standalone, Follower or PGA */ 58 59 uint32_t InvertingInput; /*!< Specifies the inverting input in Standalone & PGA modes. 60 - In Standalone mode i.e when mode is OPAMP_STANDALONE_MODE 61 This parameter must be a value of @ref OPAMP_InvertingInput 62 - In Follower mode i.e when mode is OPAMP_FOLLOWER_MODE 63 & In PGA mode i.e when mode is OPAMP_PGA_MODE 64 This parameter is Not Applicable */ 65 66 uint32_t NonInvertingInput; /*!< Specifies the non inverting input of the opamp: 67 This parameter must be a value of @ref OPAMP_NonInvertingInput */ 68 69 uint32_t PgaGain; /*!< Specifies the gain in PGA mode 70 i.e. when mode is OPAMP_PGA_MODE. 71 This parameter must be a value of @ref OPAMP_PgaGain */ 72 73 uint32_t PgaConnect; /*!< Specifies the inverting pin in PGA mode 74 i.e. when mode is OPAMP_PGA_MODE 75 This parameter must be a value of @ref OPAMP_PgaConnect 76 Either: not connected, connected to VINM0, connected to VINM1 77 (VINM0 or VINM1 are typically used for external filtering) */ 78 79 uint32_t UserTrimming; /*!< Specifies the trimming mode 80 This parameter must be a value of @ref OPAMP_UserTrimming 81 UserTrimming is either factory or user trimming. */ 82 83 uint32_t TrimmingValueP; /*!< Specifies the offset trimming value (PMOS) in Normal Mode 84 i.e. when UserTrimming is OPAMP_TRIMMING_USER. 85 This parameter must be a number between Min_Data = 0 and Max_Data = 31. 86 16 is typical default value */ 87 88 uint32_t TrimmingValueN; /*!< Specifies the offset trimming value (NMOS) in Normal Mode 89 i.e. when UserTrimming is OPAMP_TRIMMING_USER. 90 This parameter must be a number between Min_Data = 0 and Max_Data = 31. 91 16 is typical default value */ 92 93 uint32_t TrimmingValuePHighSpeed; /*!< Specifies the offset trimming value (PMOS) in High Speed Mode 94 i.e. when UserTrimming is OPAMP_TRIMMING_USER. 95 This parameter must be a number between Min_Data = 0 and Max_Data = 31. 96 16 is typical default value */ 97 98 uint32_t TrimmingValueNHighSpeed; /*!< Specifies the offset trimming value (NMOS) in High Speed Mode 99 i.e. when UserTrimming is OPAMP_TRIMMING_USER. 100 This parameter must be a number between Min_Data = 0 and Max_Data = 31. 101 16 is typical default value */ 102 103 } OPAMP_InitTypeDef; 104 105 /** 106 * @brief HAL State structures definition 107 */ 108 109 typedef enum 110 { 111 HAL_OPAMP_STATE_RESET = 0x00000000U, /*!< OPAMP is not yet Initialized */ 112 HAL_OPAMP_STATE_READY = 0x00000001U, /*!< OPAMP is initialized and ready for use */ 113 HAL_OPAMP_STATE_CALIBBUSY = 0x00000002U, /*!< OPAMP is enabled in auto calibration mode */ 114 HAL_OPAMP_STATE_BUSY = 0x00000004U, /*!< OPAMP is enabled and running in normal mode */ 115 HAL_OPAMP_STATE_BUSYLOCKED = 0x00000005U /*!< OPAMP is locked. Only system reset allows reconfiguring the opamp. */ 116 117 } HAL_OPAMP_StateTypeDef; 118 119 /** 120 * @brief OPAMP Handle Structure definition 121 */ 122 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1U) 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 == 1U) 135 void (* MspInitCallback)(struct __OPAMP_HandleTypeDef *hopamp); 136 void (* MspDeInitCallback)(struct __OPAMP_HandleTypeDef *hopamp); 137 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */ 138 } OPAMP_HandleTypeDef; 139 140 /** 141 * @brief HAl_OPAMP_TrimmingValueTypeDef definition 142 */ 143 144 typedef uint32_t HAL_OPAMP_TrimmingValueTypeDef; 145 146 /** 147 * @} 148 */ 149 150 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1U) 151 /** 152 * @brief HAL OPAMP Callback ID enumeration definition 153 */ 154 typedef enum 155 { 156 HAL_OPAMP_MSPINIT_CB_ID = 0x01U, /*!< OPAMP MspInit Callback ID */ 157 HAL_OPAMP_MSPDEINIT_CB_ID = 0x02U, /*!< OPAMP MspDeInit Callback ID */ 158 HAL_OPAMP_ALL_CB_ID = 0x03U /*!< OPAMP All ID */ 159 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 /** @defgroup OPAMP_Exported_Constants OPAMP Exported Constants 171 * @{ 172 */ 173 174 /** @defgroup OPAMP_Mode OPAMP Mode 175 * @{ 176 */ 177 #define OPAMP_STANDALONE_MODE 0x00000000U /*!< standalone mode */ 178 #define OPAMP_PGA_MODE OPAMP_CSR_VMSEL_1 /*!< PGA mode */ 179 #define OPAMP_FOLLOWER_MODE (OPAMP_CSR_VMSEL_1 | OPAMP_CSR_VMSEL_0) /*!< follower mode */ 180 /** 181 * @} 182 */ 183 184 /** @defgroup OPAMP_NonInvertingInput OPAMP Non Inverting Input 185 * @{ 186 */ 187 188 #define OPAMP_NONINVERTINGINPUT_IO0 0x00000000U /*!< OPAMP non inverting input connected to 189 I/O VINP0 (PB0 for OPAMP1) */ 190 #define OPAMP_NONINVERTINGINPUT_IO1 OPAMP_CSR_VPSEL_1 /*!< OPAMP non inverting input connected to 191 I/O VINP0 (PA0 for OPAMP1) */ 192 #define OPAMP_NONINVERTINGINPUT_DAC_CH OPAMP_CSR_VPSEL_0 /*!< OPAMP non-inverting input connected internally 193 to DAC channel */ 194 /** 195 * @} 196 */ 197 198 /** @defgroup OPAMP_InvertingInput OPAMP Inverting Input 199 * @{ 200 */ 201 #define OPAMP_INVERTINGINPUT_IO0 0x00000000U /*!< OPAMP inverting input connected to I/O VINM0 202 (PC5 for OPAMP1) */ 203 #define OPAMP_INVERTINGINPUT_IO1 OPAMP_CSR_VMSEL_0 /*!< OPAMP inverting input connected to I/0 VINM1 204 (PB1 for OPAMP1) */ 205 #define OPAMP_INVERTINGINPUT_CONNECT_NO OPAMP_CSR_VMSEL_1 /*!< OPAMP inverting input not externally connected 206 (intended for OPAMP in mode follower or 207 PGA with positive gain without bias). 208 Note: On this STM32 series, this literal 209 include cases of value 0x11 for mode follower 210 and value 0x10 for mode PGA. */ 211 /** 212 * @} 213 */ 214 215 /** @defgroup OPAMP_PgaConnect OPAMP Pga Connect 216 * @{ 217 */ 218 219 #define OPAMP_PGA_CONNECT_INVERTINGINPUT_NO 0x00000000U /*!< In PGA mode, the inverting input is 220 not connected */ 221 #define OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0 OPAMP_CSR_PGGAIN_2 /*!< In PGA mode, the inverting input is 222 connected to VINM0 */ 223 #define OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_BIAS OPAMP_CSR_PGGAIN_3 /*!< In PGA mode, the inverting input is 224 connected to VINM0 or bias */ 225 #define OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_IO1_BIAS (OPAMP_CSR_PGGAIN_2 |\ 226 OPAMP_CSR_PGGAIN_3) /*!< In PGA mode, the inverting input is 227 connected to VINM0 or bias , VINM1 228 connected for filtering */ 229 230 231 /** 232 * @} 233 */ 234 235 /** @defgroup OPAMP_PgaGain OPAMP Pga Gain 236 * @{ 237 */ 238 239 #define OPAMP_PGA_GAIN_2_OR_MINUS_1 0x00000000U /*!< PGA gain could be 2 or -1 */ 240 #define OPAMP_PGA_GAIN_4_OR_MINUS_3 OPAMP_CSR_PGGAIN_0 /*!< PGA gain could be 4 or -3 */ 241 #define OPAMP_PGA_GAIN_8_OR_MINUS_7 OPAMP_CSR_PGGAIN_1 /*!< PGA gain could be 8 or -7 */ 242 #define OPAMP_PGA_GAIN_16_OR_MINUS_15 (OPAMP_CSR_PGGAIN_0 | OPAMP_CSR_PGGAIN_1) /*!< PGA gain could be 16 or -15 */ 243 244 /** 245 * @} 246 */ 247 248 /** @defgroup OPAMP_PowerMode OPAMP PowerMode 249 * @{ 250 */ 251 #define OPAMP_POWERMODE_NORMAL 0x00000000U 252 #define OPAMP_POWERMODE_HIGHSPEED OPAMP_CSR_OPAHSM 253 254 /** 255 * @} 256 */ 257 258 259 /** @defgroup OPAMP_VREF OPAMP VREF 260 * @{ 261 */ 262 263 #define OPAMP_VREF_3VDDA 0x00000000U /*!< OPAMP Vref = 3.3% VDDA */ 264 #define OPAMP_VREF_10VDDA OPAMP_CSR_CALSEL_0 /*!< OPAMP Vref = 10% VDDA */ 265 #define OPAMP_VREF_50VDDA OPAMP_CSR_CALSEL_1 /*!< OPAMP Vref = 50% VDDA */ 266 #define OPAMP_VREF_90VDDA OPAMP_CSR_CALSEL /*!< OPAMP Vref = 90% VDDA */ 267 268 /** 269 * @} 270 */ 271 272 /** @defgroup OPAMP_UserTrimming OPAMP User Trimming 273 * @{ 274 */ 275 #define OPAMP_TRIMMING_FACTORY 0x00000000U /*!< Factory trimming */ 276 #define OPAMP_TRIMMING_USER OPAMP_CSR_USERTRIM /*!< User trimming */ 277 278 279 /** 280 * @} 281 */ 282 283 /** @defgroup OPAMP_FactoryTrimming OPAMP Factory Trimming 284 * @{ 285 */ 286 #define OPAMP_FACTORYTRIMMING_DUMMY 0xFFFFFFFFU /*!< Dummy value if trimming value could not be retrieved */ 287 #define OPAMP_FACTORYTRIMMING_N 0x00000000U /*!< Offset trimming N */ 288 #define OPAMP_FACTORYTRIMMING_P 0x00000001U /*!< Offset trimming P */ 289 290 /** 291 * @} 292 */ 293 294 /** 295 * @} 296 */ 297 298 /* Private constants -------------------------------------------------------------------------------------------------*/ 299 /** @defgroup OPAMP_Private_Constants OPAMP Private Constants 300 * @brief OPAMP Private constants and defines 301 * @{ 302 */ 303 304 /* NONINVERTING bit position in OTR & HSOTR */ 305 #define OPAMP_INPUT_NONINVERTING (8U) /*!< Non inverting input */ 306 307 /* Offset trimming time: during calibration, minimum time needed between two */ 308 /* steps to have 1 mV accuracy. */ 309 /* Refer to datasheet, electrical characteristics: parameter tOFFTRIM Typ=2ms.*/ 310 /* Unit: ms. */ 311 #define OPAMP_TRIMMING_DELAY (2U) 312 313 /** 314 * @} 315 */ 316 317 /* Exported macros ---------------------------------------------------------------------------------------------------*/ 318 /** @defgroup OPAMP_Exported_Macros OPAMP Exported Macros 319 * @{ 320 */ 321 322 /** @brief Reset OPAMP handle state. 323 * @param __HANDLE__: OPAMP handle. 324 * @retval None 325 */ 326 #define __HAL_OPAMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_OPAMP_STATE_RESET) 327 328 /** 329 * @} 330 */ 331 332 /* Private macro -----------------------------------------------------------------------------------------------------*/ 333 334 /** @defgroup OPAMP_Private_Macros OPAMP Private Macros 335 * @{ 336 */ 337 338 #define IS_OPAMP_FUNCTIONAL_NORMALMODE(INPUT) (((INPUT) == OPAMP_STANDALONE_MODE) || \ 339 ((INPUT) == OPAMP_PGA_MODE) || \ 340 ((INPUT) == OPAMP_FOLLOWER_MODE)) 341 342 #define IS_OPAMP_INVERTING_INPUT_STANDALONE(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_IO0) || \ 343 ((INPUT) == OPAMP_INVERTINGINPUT_IO1)) 344 345 #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \ 346 ((INPUT) == OPAMP_NONINVERTINGINPUT_IO1) || \ 347 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH)) 348 349 #define IS_OPAMP_PGACONNECT(CONNECT) (((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_NO) || \ 350 ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0) || \ 351 ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_BIAS) || \ 352 ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_IO1_BIAS)) 353 354 #define IS_OPAMP_PGA_GAIN(GAIN) (((GAIN) == OPAMP_PGA_GAIN_2_OR_MINUS_1) || \ 355 ((GAIN) == OPAMP_PGA_GAIN_4_OR_MINUS_3) || \ 356 ((GAIN) == OPAMP_PGA_GAIN_8_OR_MINUS_7) || \ 357 ((GAIN) == OPAMP_PGA_GAIN_16_OR_MINUS_15)) 358 359 360 #define IS_OPAMP_VREF(VREF) (((VREF) == OPAMP_VREF_3VDDA) || \ 361 ((VREF) == OPAMP_VREF_10VDDA) || \ 362 ((VREF) == OPAMP_VREF_50VDDA) || \ 363 ((VREF) == OPAMP_VREF_90VDDA)) 364 365 #define IS_OPAMP_POWERMODE(TRIMMING) (((TRIMMING) == OPAMP_POWERMODE_NORMAL) || \ 366 ((TRIMMING) == OPAMP_POWERMODE_HIGHSPEED) ) 367 368 369 #define IS_OPAMP_TRIMMING(TRIMMING) (((TRIMMING) == OPAMP_TRIMMING_FACTORY) || \ 370 ((TRIMMING) == OPAMP_TRIMMING_USER)) 371 372 373 #define IS_OPAMP_TRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 0x1FU) 374 375 #define IS_OPAMP_FACTORYTRIMMING(TRIMMING) (((TRIMMING) == OPAMP_FACTORYTRIMMING_N) || \ 376 ((TRIMMING) == OPAMP_FACTORYTRIMMING_P)) 377 378 /** 379 * @} 380 */ 381 382 /* Include OPAMP HAL Extended module */ 383 #include "stm32h5xx_hal_opamp_ex.h" 384 385 /* Exported functions ------------------------------------------------------------------------------------------------*/ 386 /** @addtogroup OPAMP_Exported_Functions 387 * @{ 388 */ 389 390 /** @addtogroup OPAMP_Exported_Functions_Group1 391 * @{ 392 */ 393 /* Initialization/de-initialization functions */ 394 HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef *hopamp); 395 HAL_StatusTypeDef HAL_OPAMP_DeInit(OPAMP_HandleTypeDef *hopamp); 396 void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef *hopamp); 397 void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef *hopamp); 398 /** 399 * @} 400 */ 401 402 /** @addtogroup OPAMP_Exported_Functions_Group2 403 * @{ 404 */ 405 406 /* I/O operation functions */ 407 HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef *hopamp); 408 HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef *hopamp); 409 HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef *hopamp); 410 411 /** 412 * @} 413 */ 414 415 /** @addtogroup OPAMP_Exported_Functions_Group3 416 * @{ 417 */ 418 419 /* Peripheral Control functions */ 420 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1U) 421 /* OPAMP callback registering/unregistering */ 422 HAL_StatusTypeDef HAL_OPAMP_RegisterCallback(OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackId, 423 pOPAMP_CallbackTypeDef pCallback); 424 HAL_StatusTypeDef HAL_OPAMP_UnRegisterCallback(OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackId); 425 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */ 426 HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef *hopamp); 427 HAL_OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset(const OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset); 428 429 /** 430 * @} 431 */ 432 433 /** @addtogroup OPAMP_Exported_Functions_Group4 434 * @{ 435 */ 436 437 /* Peripheral State functions */ 438 HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(const OPAMP_HandleTypeDef *hopamp); 439 440 /** 441 * @} 442 */ 443 444 /** 445 * @} 446 */ 447 448 /** 449 * @} 450 */ 451 #endif /* OPAMP1 */ 452 /** 453 * @} 454 */ 455 456 #ifdef __cplusplus 457 } 458 #endif 459 460 #endif /* STM32H5xx_HAL_OPAMP_H */ 461