STM32H735xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32h7xx_hal_opamp.h 00004 * @author MCD Application Team 00005 * @brief Header file of OPAMP HAL module. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * Copyright (c) 2017 STMicroelectronics. 00010 * All rights reserved. 00011 * 00012 * This software is licensed under terms that can be found in the LICENSE file 00013 * in the root directory of this software component. 00014 * If no LICENSE file comes with this software, it is provided AS-IS. 00015 * 00016 ****************************************************************************** 00017 */ 00018 00019 /* Define to prevent recursive inclusion -------------------------------------*/ 00020 #ifndef STM32H7xx_HAL_OPAMP_H 00021 #define STM32H7xx_HAL_OPAMP_H 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 /* Includes ------------------------------------------------------------------*/ 00028 #include "stm32h7xx_hal_def.h" 00029 00030 /** @addtogroup STM32H7xx_HAL_Driver 00031 * @{ 00032 */ 00033 00034 /** @addtogroup OPAMP 00035 * @{ 00036 */ 00037 00038 /* Exported types ------------------------------------------------------------*/ 00039 00040 /** @defgroup OPAMP_Exported_Types OPAMP Exported Types 00041 * @{ 00042 */ 00043 00044 /** 00045 * @brief OPAMP Init structure definition 00046 */ 00047 00048 typedef struct 00049 { 00050 00051 uint32_t PowerMode; /*!< Specifies the power mode Normal or High Speed. 00052 This parameter must be a value of @ref OPAMP_PowerMode */ 00053 00054 uint32_t Mode; /*!< Specifies the OPAMP mode 00055 This parameter must be a value of @ref OPAMP_Mode 00056 mode is either Standalone, - Follower or PGA */ 00057 00058 uint32_t InvertingInput; /*!< Specifies the inverting input in Standalone & PGA modes 00059 - In Standalone mode i.e when mode is OPAMP_STANDALONE_MODE 00060 This parameter must be a value of @ref OPAMP_InvertingInput 00061 - In Follower mode i.e when mode is OPAMP_FOLLOWER_MODE 00062 & In PGA mode i.e when mode is OPAMP_PGA_MODE 00063 This parameter is Not Applicable */ 00064 00065 uint32_t NonInvertingInput; /*!< Specifies the non inverting input of the opamp: 00066 This parameter must be a value of @ref OPAMP_NonInvertingInput */ 00067 00068 uint32_t PgaGain; /*!< Specifies the gain in PGA mode 00069 i.e. when mode is OPAMP_PGA_MODE. 00070 This parameter must be a value of @ref OPAMP_PgaGain */ 00071 00072 uint32_t PgaConnect; /*!< Specifies the inverting pin in PGA mode 00073 i.e. when mode is OPAMP_PGA_MODE 00074 This parameter must be a value of @ref OPAMP_PgaConnect 00075 Either: not connected, connected to VINM0, connected to VINM1 00076 (VINM0 or VINM1 are typically used for external filtering) */ 00077 00078 uint32_t UserTrimming; /*!< Specifies the trimming mode 00079 This parameter must be a value of @ref OPAMP_UserTrimming 00080 UserTrimming is either factory or user trimming.*/ 00081 00082 uint32_t TrimmingValueP; /*!< Specifies the offset trimming value (PMOS) in Normal Mode 00083 i.e. when UserTrimming is OPAMP_TRIMMING_USER. 00084 This parameter must be a number between Min_Data = 0 and Max_Data = 31. 00085 16 is typical default value */ 00086 00087 uint32_t TrimmingValueN; /*!< Specifies the offset trimming value (NMOS) in Normal Mode 00088 i.e. when UserTrimming is OPAMP_TRIMMING_USER. 00089 This parameter must be a number between Min_Data = 0 and Max_Data = 31. 00090 16 is typical default value */ 00091 00092 uint32_t TrimmingValuePHighSpeed; /*!< Specifies the offset trimming value (PMOS) in High Speed Mode 00093 i.e. when UserTrimming is OPAMP_TRIMMING_USER. 00094 This parameter must be a number between Min_Data = 0 and Max_Data = 31. 00095 16 is typical default value */ 00096 00097 uint32_t TrimmingValueNHighSpeed; /*!< Specifies the offset trimming value (NMOS) in High Speed Mode 00098 i.e. when UserTrimming is OPAMP_TRIMMING_USER. 00099 This parameter must be a number between Min_Data = 0 and Max_Data = 31. 00100 16 is typical default value */ 00101 00102 }OPAMP_InitTypeDef; 00103 00104 /** 00105 * @brief HAL State structures definition 00106 */ 00107 00108 typedef enum 00109 { 00110 HAL_OPAMP_STATE_RESET = 0x00000000U, /*!< OPAMP is not yet Initialized */ 00111 00112 HAL_OPAMP_STATE_READY = 0x00000001U, /*!< OPAMP is initialized and ready for use */ 00113 HAL_OPAMP_STATE_CALIBBUSY = 0x00000002U, /*!< OPAMP is enabled in auto calibration mode */ 00114 00115 HAL_OPAMP_STATE_BUSY = 0x00000004U, /*!< OPAMP is enabled and running in normal mode */ 00116 HAL_OPAMP_STATE_BUSYLOCKED = 0x00000005U /*!< OPAMP is locked 00117 only system reset allows reconfiguring the opamp. */ 00118 00119 }HAL_OPAMP_StateTypeDef; 00120 00121 /** 00122 * @brief OPAMP Handle Structure definition 00123 */ 00124 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1) 00125 typedef struct __OPAMP_HandleTypeDef 00126 #else 00127 typedef struct 00128 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */ 00129 { 00130 OPAMP_TypeDef *Instance; /*!< OPAMP instance's registers base address */ 00131 OPAMP_InitTypeDef Init; /*!< OPAMP required parameters */ 00132 HAL_StatusTypeDef Status; /*!< OPAMP peripheral status */ 00133 HAL_LockTypeDef Lock; /*!< Locking object */ 00134 __IO HAL_OPAMP_StateTypeDef State; /*!< OPAMP communication state */ 00135 00136 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1) 00137 void (* MspInitCallback) (struct __OPAMP_HandleTypeDef *hopamp); 00138 void (* MspDeInitCallback) (struct __OPAMP_HandleTypeDef *hopamp); 00139 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */ 00140 } OPAMP_HandleTypeDef; 00141 00142 /** 00143 * @brief HAl_OPAMP_TrimmingValueTypeDef definition 00144 */ 00145 00146 typedef uint32_t HAL_OPAMP_TrimmingValueTypeDef; 00147 00148 /** 00149 * @} 00150 */ 00151 00152 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1) 00153 /** 00154 * @brief HAL OPAMP Callback ID enumeration definition 00155 */ 00156 typedef enum 00157 { 00158 HAL_OPAMP_MSPINIT_CB_ID = 0x01U, /*!< OPAMP MspInit Callback ID */ 00159 HAL_OPAMP_MSPDEINIT_CB_ID = 0x02U, /*!< OPAMP MspDeInit Callback ID */ 00160 HAL_OPAMP_ALL_CB_ID = 0x03U /*!< OPAMP All ID */ 00161 }HAL_OPAMP_CallbackIDTypeDef; 00162 00163 /** 00164 * @brief HAL OPAMP Callback pointer definition 00165 */ 00166 typedef void (*pOPAMP_CallbackTypeDef)(OPAMP_HandleTypeDef *hopamp); 00167 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */ 00168 00169 00170 /* Exported constants --------------------------------------------------------*/ 00171 /** @defgroup OPAMP_Exported_Constants OPAMP Exported Constants 00172 * @{ 00173 */ 00174 00175 /** @defgroup OPAMP_Mode OPAMP Mode 00176 * @{ 00177 */ 00178 #define OPAMP_STANDALONE_MODE 0x00000000U /*!< standalone mode */ 00179 #define OPAMP_PGA_MODE OPAMP_CSR_VMSEL_1 /*!< PGA mode */ 00180 #define OPAMP_FOLLOWER_MODE (OPAMP_CSR_VMSEL_1 | OPAMP_CSR_VMSEL_0) /*!< follower mode */ 00181 00182 /** 00183 * @} 00184 */ 00185 00186 /** @defgroup OPAMP_NonInvertingInput OPAMP Non Inverting Input 00187 * @{ 00188 */ 00189 00190 #define OPAMP_NONINVERTINGINPUT_IO0 0x00000000U /*!< OPAMP non-inverting input connected to dedicated IO pin */ 00191 #define OPAMP_NONINVERTINGINPUT_DAC_CH OPAMP_CSR_VPSEL_0 /*!< OPAMP non-inverting input connected internally to DAC channel */ 00192 #if defined(DAC2) 00193 #define OPAMP_NONINVERTINGINPUT_DAC2_CH OPAMP_CSR_VPSEL_1 /*!< Only OPAMP2 non-inverting input connected internally to DAC2 channel */ 00194 #endif /* DAC2 */ 00195 00196 /** 00197 * @} 00198 */ 00199 00200 /** @defgroup OPAMP_InvertingInput OPAMP Inverting Input 00201 * @{ 00202 */ 00203 00204 #define OPAMP_INVERTINGINPUT_IO0 0x00000000U /*!< OPAMP inverting input connected to dedicated IO pin */ 00205 #define OPAMP_INVERTINGINPUT_IO1 OPAMP_CSR_VMSEL_0 /*!< OPAMP inverting input connected to dedicated IO pin */ 00206 00207 /** 00208 * @} 00209 */ 00210 00211 /** @defgroup OPAMP_PgaConnect OPAMP Pga Connect 00212 * @{ 00213 */ 00214 00215 #define OPAMP_PGA_CONNECT_INVERTINGINPUT_NO 0x00000000U /*!< In PGA mode, the inverting input is not connected */ 00216 #define OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0 OPAMP_CSR_PGGAIN_2 /*!< In PGA mode, the inverting input is connected to VINM0 */ 00217 #define OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_BIAS OPAMP_CSR_PGGAIN_3 /*!< In PGA mode, the inverting input is connected to VINM0 or bias */ 00218 #define OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_IO1_BIAS (OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_PGGAIN_3) /*!< In PGA mode, the inverting input is connected to VINM0 or bias , VINM1 connected for filtering */ 00219 00220 00221 /** 00222 * @} 00223 */ 00224 00225 /** @defgroup OPAMP_PgaGain OPAMP Pga Gain 00226 * @{ 00227 */ 00228 00229 #define OPAMP_PGA_GAIN_2_OR_MINUS_1 0x00000000U /*!< PGA gain could be 2 or -1 */ 00230 #define OPAMP_PGA_GAIN_4_OR_MINUS_3 OPAMP_CSR_PGGAIN_0 /*!< PGA gain could be 4 or -3 */ 00231 #define OPAMP_PGA_GAIN_8_OR_MINUS_7 OPAMP_CSR_PGGAIN_1 /*!< PGA gain could be 8 or -7 */ 00232 #define OPAMP_PGA_GAIN_16_OR_MINUS_15 (OPAMP_CSR_PGGAIN_0 | OPAMP_CSR_PGGAIN_1) /*!< PGA gain could be 16 or -15 */ 00233 00234 /** 00235 * @} 00236 */ 00237 00238 /** @defgroup OPAMP_PowerMode OPAMP PowerMode 00239 * @{ 00240 */ 00241 #define OPAMP_POWERMODE_NORMAL 0x00000000U 00242 #define OPAMP_POWERMODE_HIGHSPEED OPAMP_CSR_OPAHSM 00243 00244 /** 00245 * @} 00246 */ 00247 00248 00249 /** @defgroup OPAMP_VREF OPAMP VREF 00250 * @{ 00251 */ 00252 00253 #define OPAMP_VREF_3VDDA 0x00000000U /*!< OPAMP Vref = 3.3% VDDA */ 00254 #define OPAMP_VREF_10VDDA OPAMP_CSR_CALSEL_0 /*!< OPAMP Vref = 10% VDDA */ 00255 #define OPAMP_VREF_50VDDA OPAMP_CSR_CALSEL_1 /*!< OPAMP Vref = 50% VDDA */ 00256 #define OPAMP_VREF_90VDDA OPAMP_CSR_CALSEL /*!< OPAMP Vref = 90% VDDA */ 00257 00258 /** 00259 * @} 00260 */ 00261 00262 /** @defgroup OPAMP_UserTrimming OPAMP User Trimming 00263 * @{ 00264 */ 00265 #define OPAMP_TRIMMING_FACTORY 0x00000000U /*!< Factory trimming */ 00266 #define OPAMP_TRIMMING_USER OPAMP_CSR_USERTRIM /*!< User trimming */ 00267 00268 00269 /** 00270 * @} 00271 */ 00272 00273 /** @defgroup OPAMP_FactoryTrimming OPAMP Factory Trimming 00274 * @{ 00275 */ 00276 #define OPAMP_FACTORYTRIMMING_DUMMY 0xFFFFFFFFU /*!< Dummy value if trimming value could not be retrieved */ 00277 00278 #define OPAMP_FACTORYTRIMMING_N 0x00000000U /*!< Offset trimming N */ 00279 #define OPAMP_FACTORYTRIMMING_P 0x00000001U /*!< Offset trimming P */ 00280 00281 /** 00282 * @} 00283 */ 00284 00285 /** 00286 * @} 00287 */ 00288 00289 /* Private constants ---------------------------------------------------------*/ 00290 /** @defgroup OPAMP_Private_Constants OPAMP Private Constants 00291 * @brief OPAMP Private constants and defines 00292 * @{ 00293 */ 00294 00295 /* NONINVERTING bit position in OTR & HSOTR */ 00296 #define OPAMP_INPUT_NONINVERTING (8U) /*!< Non inverting input */ 00297 00298 /* Offset trimming time: during calibration, minimum time needed between two */ 00299 /* steps to have 1 mV accuracy. */ 00300 /* Refer to datasheet, electrical characteristics: parameter tOFFTRIM Typ=2ms.*/ 00301 /* Unit: ms. */ 00302 #define OPAMP_TRIMMING_DELAY (2U) 00303 00304 /** 00305 * @} 00306 */ 00307 00308 /* Exported macros -----------------------------------------------------------*/ 00309 /** @defgroup OPAMP_Exported_Macros OPAMP Exported Macros 00310 * @{ 00311 */ 00312 00313 /** @brief Reset OPAMP handle state. 00314 * @param __HANDLE__: OPAMP handle. 00315 * @retval None 00316 */ 00317 #define __HAL_OPAMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_OPAMP_STATE_RESET) 00318 00319 /** 00320 * @} 00321 */ 00322 00323 /* Private macro -------------------------------------------------------------*/ 00324 00325 /** @defgroup OPAMP_Private_Macros OPAMP Private Macros 00326 * @{ 00327 */ 00328 00329 #define IS_OPAMP_FUNCTIONAL_NORMALMODE(INPUT) (((INPUT) == OPAMP_STANDALONE_MODE) || \ 00330 ((INPUT) == OPAMP_PGA_MODE) || \ 00331 ((INPUT) == OPAMP_FOLLOWER_MODE)) 00332 00333 #define IS_OPAMP_INVERTING_INPUT_STANDALONE(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_IO0) || \ 00334 ((INPUT) == OPAMP_INVERTINGINPUT_IO1)) 00335 00336 #if defined(DAC2) 00337 #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \ 00338 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH) || \ 00339 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC2_CH)) 00340 #else 00341 #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \ 00342 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH)) 00343 #endif /* DAC2 */ 00344 00345 #define IS_OPAMP_PGACONNECT(CONNECT) (((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_NO) || \ 00346 ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0) || \ 00347 ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_BIAS) || \ 00348 ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_IO1_BIAS)) 00349 00350 #define IS_OPAMP_PGA_GAIN(GAIN) (((GAIN) == OPAMP_PGA_GAIN_2_OR_MINUS_1) || \ 00351 ((GAIN) == OPAMP_PGA_GAIN_4_OR_MINUS_3) || \ 00352 ((GAIN) == OPAMP_PGA_GAIN_8_OR_MINUS_7) || \ 00353 ((GAIN) == OPAMP_PGA_GAIN_16_OR_MINUS_15)) 00354 00355 00356 #define IS_OPAMP_VREF(VREF) (((VREF) == OPAMP_VREF_3VDDA) || \ 00357 ((VREF) == OPAMP_VREF_10VDDA) || \ 00358 ((VREF) == OPAMP_VREF_50VDDA) || \ 00359 ((VREF) == OPAMP_VREF_90VDDA)) 00360 00361 #define IS_OPAMP_POWERMODE(TRIMMING) (((TRIMMING) == OPAMP_POWERMODE_NORMAL) || \ 00362 ((TRIMMING) == OPAMP_POWERMODE_HIGHSPEED) ) 00363 00364 00365 #define IS_OPAMP_TRIMMING(TRIMMING) (((TRIMMING) == OPAMP_TRIMMING_FACTORY) || \ 00366 ((TRIMMING) == OPAMP_TRIMMING_USER)) 00367 00368 00369 #define IS_OPAMP_TRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 0x1FU) 00370 00371 #define IS_OPAMP_FACTORYTRIMMING(TRIMMING) (((TRIMMING) == OPAMP_FACTORYTRIMMING_N) || \ 00372 ((TRIMMING) == OPAMP_FACTORYTRIMMING_P)) 00373 00374 /** 00375 * @} 00376 */ 00377 00378 /* Include OPAMP HAL Extended module */ 00379 #include "stm32h7xx_hal_opamp_ex.h" 00380 00381 /* Exported functions --------------------------------------------------------*/ 00382 /** @addtogroup OPAMP_Exported_Functions 00383 * @{ 00384 */ 00385 00386 /** @addtogroup OPAMP_Exported_Functions_Group1 00387 * @{ 00388 */ 00389 /* Initialization/de-initialization functions **********************************/ 00390 HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef *hopamp); 00391 HAL_StatusTypeDef HAL_OPAMP_DeInit (OPAMP_HandleTypeDef *hopamp); 00392 void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef *hopamp); 00393 void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef *hopamp); 00394 /** 00395 * @} 00396 */ 00397 00398 /** @addtogroup OPAMP_Exported_Functions_Group2 00399 * @{ 00400 */ 00401 00402 /* I/O operation functions *****************************************************/ 00403 HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef *hopamp); 00404 HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef *hopamp); 00405 HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef *hopamp); 00406 00407 /** 00408 * @} 00409 */ 00410 00411 /** @addtogroup OPAMP_Exported_Functions_Group3 00412 * @{ 00413 */ 00414 00415 /* Peripheral Control functions ************************************************/ 00416 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1) 00417 /* OPAMP callback registering/unregistering */ 00418 HAL_StatusTypeDef HAL_OPAMP_RegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackId, pOPAMP_CallbackTypeDef pCallback); 00419 HAL_StatusTypeDef HAL_OPAMP_UnRegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackId); 00420 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */ 00421 HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef *hopamp); 00422 HAL_OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset); 00423 00424 /** 00425 * @} 00426 */ 00427 00428 /** @addtogroup OPAMP_Exported_Functions_Group4 00429 * @{ 00430 */ 00431 00432 /* Peripheral State functions **************************************************/ 00433 HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(OPAMP_HandleTypeDef *hopamp); 00434 00435 /** 00436 * @} 00437 */ 00438 00439 /** 00440 * @} 00441 */ 00442 00443 /** 00444 * @} 00445 */ 00446 00447 /** 00448 * @} 00449 */ 00450 00451 #ifdef __cplusplus 00452 } 00453 #endif 00454 00455 #endif /* STM32H7xx_HAL_OPAMP_H */ 00456