You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

459 lines
17 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_opamp.h
  4. * @author MCD Application Team
  5. * @brief Header file of OPAMP HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32H7xx_HAL_OPAMP_H
  21. #define STM32H7xx_HAL_OPAMP_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32h7xx_hal_def.h"
  27. /** @addtogroup STM32H7xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup OPAMP
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup OPAMP_Exported_Types OPAMP Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief OPAMP Init structure definition
  39. */
  40. typedef struct
  41. {
  42. uint32_t PowerMode; /*!< Specifies the power mode Normal or High Speed.
  43. This parameter must be a value of @ref OPAMP_PowerMode */
  44. uint32_t Mode; /*!< Specifies the OPAMP mode
  45. This parameter must be a value of @ref OPAMP_Mode
  46. mode is either Standalone, - Follower or PGA */
  47. uint32_t InvertingInput; /*!< Specifies the inverting input in Standalone & PGA modes
  48. - In Standalone mode i.e when mode is OPAMP_STANDALONE_MODE
  49. This parameter must be a value of @ref OPAMP_InvertingInput
  50. - In Follower mode i.e when mode is OPAMP_FOLLOWER_MODE
  51. & In PGA mode i.e when mode is OPAMP_PGA_MODE
  52. This parameter is Not Applicable */
  53. uint32_t NonInvertingInput; /*!< Specifies the non inverting input of the opamp:
  54. This parameter must be a value of @ref OPAMP_NonInvertingInput */
  55. uint32_t PgaGain; /*!< Specifies the gain in PGA mode
  56. i.e. when mode is OPAMP_PGA_MODE.
  57. This parameter must be a value of @ref OPAMP_PgaGain */
  58. uint32_t PgaConnect; /*!< Specifies the inverting pin in PGA mode
  59. i.e. when mode is OPAMP_PGA_MODE
  60. This parameter must be a value of @ref OPAMP_PgaConnect
  61. Either: not connected, connected to VINM0, connected to VINM1
  62. (VINM0 or VINM1 are typically used for external filtering) */
  63. uint32_t UserTrimming; /*!< Specifies the trimming mode
  64. This parameter must be a value of @ref OPAMP_UserTrimming
  65. UserTrimming is either factory or user trimming.*/
  66. uint32_t TrimmingValueP; /*!< Specifies the offset trimming value (PMOS) in Normal Mode
  67. i.e. when UserTrimming is OPAMP_TRIMMING_USER.
  68. This parameter must be a number between Min_Data = 0 and Max_Data = 31.
  69. 16 is typical default value */
  70. uint32_t TrimmingValueN; /*!< Specifies the offset trimming value (NMOS) in Normal Mode
  71. i.e. when UserTrimming is OPAMP_TRIMMING_USER.
  72. This parameter must be a number between Min_Data = 0 and Max_Data = 31.
  73. 16 is typical default value */
  74. uint32_t TrimmingValuePHighSpeed; /*!< Specifies the offset trimming value (PMOS) in High Speed Mode
  75. i.e. when UserTrimming is OPAMP_TRIMMING_USER.
  76. This parameter must be a number between Min_Data = 0 and Max_Data = 31.
  77. 16 is typical default value */
  78. uint32_t TrimmingValueNHighSpeed; /*!< Specifies the offset trimming value (NMOS) in High Speed Mode
  79. i.e. when UserTrimming is OPAMP_TRIMMING_USER.
  80. This parameter must be a number between Min_Data = 0 and Max_Data = 31.
  81. 16 is typical default value */
  82. }OPAMP_InitTypeDef;
  83. /**
  84. * @brief HAL State structures definition
  85. */
  86. typedef enum
  87. {
  88. HAL_OPAMP_STATE_RESET = 0x00000000U, /*!< OPAMP is not yet Initialized */
  89. HAL_OPAMP_STATE_READY = 0x00000001U, /*!< OPAMP is initialized and ready for use */
  90. HAL_OPAMP_STATE_CALIBBUSY = 0x00000002U, /*!< OPAMP is enabled in auto calibration mode */
  91. HAL_OPAMP_STATE_BUSY = 0x00000004U, /*!< OPAMP is enabled and running in normal mode */
  92. HAL_OPAMP_STATE_BUSYLOCKED = 0x00000005U /*!< OPAMP is locked
  93. only system reset allows reconfiguring the opamp. */
  94. }HAL_OPAMP_StateTypeDef;
  95. /**
  96. * @brief OPAMP Handle Structure definition
  97. */
  98. #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
  99. typedef struct __OPAMP_HandleTypeDef
  100. #else
  101. typedef struct
  102. #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
  103. {
  104. OPAMP_TypeDef *Instance; /*!< OPAMP instance's registers base address */
  105. OPAMP_InitTypeDef Init; /*!< OPAMP required parameters */
  106. HAL_StatusTypeDef Status; /*!< OPAMP peripheral status */
  107. HAL_LockTypeDef Lock; /*!< Locking object */
  108. __IO HAL_OPAMP_StateTypeDef State; /*!< OPAMP communication state */
  109. #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
  110. void (* MspInitCallback) (struct __OPAMP_HandleTypeDef *hopamp);
  111. void (* MspDeInitCallback) (struct __OPAMP_HandleTypeDef *hopamp);
  112. #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
  113. } OPAMP_HandleTypeDef;
  114. /**
  115. * @brief HAl_OPAMP_TrimmingValueTypeDef definition
  116. */
  117. typedef uint32_t HAL_OPAMP_TrimmingValueTypeDef;
  118. /**
  119. * @}
  120. */
  121. #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
  122. /**
  123. * @brief HAL OPAMP Callback ID enumeration definition
  124. */
  125. typedef enum
  126. {
  127. HAL_OPAMP_MSPINIT_CB_ID = 0x01U, /*!< OPAMP MspInit Callback ID */
  128. HAL_OPAMP_MSPDEINIT_CB_ID = 0x02U, /*!< OPAMP MspDeInit Callback ID */
  129. HAL_OPAMP_ALL_CB_ID = 0x03U /*!< OPAMP All ID */
  130. }HAL_OPAMP_CallbackIDTypeDef;
  131. /**
  132. * @brief HAL OPAMP Callback pointer definition
  133. */
  134. typedef void (*pOPAMP_CallbackTypeDef)(OPAMP_HandleTypeDef *hopamp);
  135. #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
  136. /* Exported constants --------------------------------------------------------*/
  137. /** @defgroup OPAMP_Exported_Constants OPAMP Exported Constants
  138. * @{
  139. */
  140. /** @defgroup OPAMP_Mode OPAMP Mode
  141. * @{
  142. */
  143. #define OPAMP_STANDALONE_MODE 0x00000000U /*!< standalone mode */
  144. #define OPAMP_PGA_MODE OPAMP_CSR_VMSEL_1 /*!< PGA mode */
  145. #define OPAMP_FOLLOWER_MODE (OPAMP_CSR_VMSEL_1 | OPAMP_CSR_VMSEL_0) /*!< follower mode */
  146. /**
  147. * @}
  148. */
  149. /** @defgroup OPAMP_NonInvertingInput OPAMP Non Inverting Input
  150. * @{
  151. */
  152. #define OPAMP_NONINVERTINGINPUT_IO0 0x00000000U /*!< OPAMP non-inverting input connected to dedicated IO pin */
  153. #define OPAMP_NONINVERTINGINPUT_DAC_CH OPAMP_CSR_VPSEL_0 /*!< OPAMP non-inverting input connected internally to DAC channel */
  154. #if defined(DAC2)
  155. #define OPAMP_NONINVERTINGINPUT_DAC2_CH OPAMP_CSR_VPSEL_1 /*!< Only OPAMP2 non-inverting input connected internally to DAC2 channel */
  156. #endif /* DAC2 */
  157. /**
  158. * @}
  159. */
  160. /** @defgroup OPAMP_InvertingInput OPAMP Inverting Input
  161. * @{
  162. */
  163. #define OPAMP_INVERTINGINPUT_IO0 0x00000000U /*!< OPAMP inverting input connected to dedicated IO pin */
  164. #define OPAMP_INVERTINGINPUT_IO1 OPAMP_CSR_VMSEL_0 /*!< OPAMP inverting input connected to dedicated IO pin */
  165. /**
  166. * @}
  167. */
  168. /** @defgroup OPAMP_PgaConnect OPAMP Pga Connect
  169. * @{
  170. */
  171. #define OPAMP_PGA_CONNECT_INVERTINGINPUT_NO 0x00000000U /*!< In PGA mode, the inverting input is not connected */
  172. #define OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0 OPAMP_CSR_PGGAIN_2 /*!< In PGA mode, the inverting input is connected to VINM0 */
  173. #define OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_BIAS OPAMP_CSR_PGGAIN_3 /*!< In PGA mode, the inverting input is connected to VINM0 or bias */
  174. #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 */
  175. /**
  176. * @}
  177. */
  178. /** @defgroup OPAMP_PgaGain OPAMP Pga Gain
  179. * @{
  180. */
  181. #define OPAMP_PGA_GAIN_2_OR_MINUS_1 0x00000000U /*!< PGA gain could be 2 or -1 */
  182. #define OPAMP_PGA_GAIN_4_OR_MINUS_3 OPAMP_CSR_PGGAIN_0 /*!< PGA gain could be 4 or -3 */
  183. #define OPAMP_PGA_GAIN_8_OR_MINUS_7 OPAMP_CSR_PGGAIN_1 /*!< PGA gain could be 8 or -7 */
  184. #define OPAMP_PGA_GAIN_16_OR_MINUS_15 (OPAMP_CSR_PGGAIN_0 | OPAMP_CSR_PGGAIN_1) /*!< PGA gain could be 16 or -15 */
  185. /**
  186. * @}
  187. */
  188. /** @defgroup OPAMP_PowerMode OPAMP PowerMode
  189. * @{
  190. */
  191. #define OPAMP_POWERMODE_NORMAL 0x00000000U
  192. #define OPAMP_POWERMODE_HIGHSPEED OPAMP_CSR_OPAHSM
  193. /**
  194. * @}
  195. */
  196. /** @defgroup OPAMP_VREF OPAMP VREF
  197. * @{
  198. */
  199. #define OPAMP_VREF_3VDDA 0x00000000U /*!< OPAMP Vref = 3.3% VDDA */
  200. #define OPAMP_VREF_10VDDA OPAMP_CSR_CALSEL_0 /*!< OPAMP Vref = 10% VDDA */
  201. #define OPAMP_VREF_50VDDA OPAMP_CSR_CALSEL_1 /*!< OPAMP Vref = 50% VDDA */
  202. #define OPAMP_VREF_90VDDA OPAMP_CSR_CALSEL /*!< OPAMP Vref = 90% VDDA */
  203. /**
  204. * @}
  205. */
  206. /** @defgroup OPAMP_UserTrimming OPAMP User Trimming
  207. * @{
  208. */
  209. #define OPAMP_TRIMMING_FACTORY 0x00000000U /*!< Factory trimming */
  210. #define OPAMP_TRIMMING_USER OPAMP_CSR_USERTRIM /*!< User trimming */
  211. /**
  212. * @}
  213. */
  214. /** @defgroup OPAMP_FactoryTrimming OPAMP Factory Trimming
  215. * @{
  216. */
  217. #define OPAMP_FACTORYTRIMMING_DUMMY 0xFFFFFFFFU /*!< Dummy value if trimming value could not be retrieved */
  218. #define OPAMP_FACTORYTRIMMING_N 0x00000000U /*!< Offset trimming N */
  219. #define OPAMP_FACTORYTRIMMING_P 0x00000001U /*!< Offset trimming P */
  220. /**
  221. * @}
  222. */
  223. /**
  224. * @}
  225. */
  226. /* Private constants ---------------------------------------------------------*/
  227. /** @defgroup OPAMP_Private_Constants OPAMP Private Constants
  228. * @brief OPAMP Private constants and defines
  229. * @{
  230. */
  231. /* NONINVERTING bit position in OTR & HSOTR */
  232. #define OPAMP_INPUT_NONINVERTING (8U) /*!< Non inverting input */
  233. /* Offset trimming time: during calibration, minimum time needed between two */
  234. /* steps to have 1 mV accuracy. */
  235. /* Refer to datasheet, electrical characteristics: parameter tOFFTRIM Typ=2ms.*/
  236. /* Unit: ms. */
  237. #define OPAMP_TRIMMING_DELAY (2U)
  238. /**
  239. * @}
  240. */
  241. /* Exported macros -----------------------------------------------------------*/
  242. /** @defgroup OPAMP_Exported_Macros OPAMP Exported Macros
  243. * @{
  244. */
  245. /** @brief Reset OPAMP handle state.
  246. * @param __HANDLE__: OPAMP handle.
  247. * @retval None
  248. */
  249. #define __HAL_OPAMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_OPAMP_STATE_RESET)
  250. /**
  251. * @}
  252. */
  253. /* Private macro -------------------------------------------------------------*/
  254. /** @defgroup OPAMP_Private_Macros OPAMP Private Macros
  255. * @{
  256. */
  257. #define IS_OPAMP_FUNCTIONAL_NORMALMODE(INPUT) (((INPUT) == OPAMP_STANDALONE_MODE) || \
  258. ((INPUT) == OPAMP_PGA_MODE) || \
  259. ((INPUT) == OPAMP_FOLLOWER_MODE))
  260. #define IS_OPAMP_INVERTING_INPUT_STANDALONE(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_IO0) || \
  261. ((INPUT) == OPAMP_INVERTINGINPUT_IO1))
  262. #if defined(DAC2)
  263. #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \
  264. ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH) || \
  265. ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC2_CH))
  266. #else
  267. #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \
  268. ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH))
  269. #endif /* DAC2 */
  270. #define IS_OPAMP_PGACONNECT(CONNECT) (((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_NO) || \
  271. ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0) || \
  272. ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_BIAS) || \
  273. ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_IO1_BIAS))
  274. #define IS_OPAMP_PGA_GAIN(GAIN) (((GAIN) == OPAMP_PGA_GAIN_2_OR_MINUS_1) || \
  275. ((GAIN) == OPAMP_PGA_GAIN_4_OR_MINUS_3) || \
  276. ((GAIN) == OPAMP_PGA_GAIN_8_OR_MINUS_7) || \
  277. ((GAIN) == OPAMP_PGA_GAIN_16_OR_MINUS_15))
  278. #define IS_OPAMP_VREF(VREF) (((VREF) == OPAMP_VREF_3VDDA) || \
  279. ((VREF) == OPAMP_VREF_10VDDA) || \
  280. ((VREF) == OPAMP_VREF_50VDDA) || \
  281. ((VREF) == OPAMP_VREF_90VDDA))
  282. #define IS_OPAMP_POWERMODE(TRIMMING) (((TRIMMING) == OPAMP_POWERMODE_NORMAL) || \
  283. ((TRIMMING) == OPAMP_POWERMODE_HIGHSPEED) )
  284. #define IS_OPAMP_TRIMMING(TRIMMING) (((TRIMMING) == OPAMP_TRIMMING_FACTORY) || \
  285. ((TRIMMING) == OPAMP_TRIMMING_USER))
  286. #define IS_OPAMP_TRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 0x1FU)
  287. #define IS_OPAMP_FACTORYTRIMMING(TRIMMING) (((TRIMMING) == OPAMP_FACTORYTRIMMING_N) || \
  288. ((TRIMMING) == OPAMP_FACTORYTRIMMING_P))
  289. /**
  290. * @}
  291. */
  292. /* Include OPAMP HAL Extended module */
  293. #include "stm32h7xx_hal_opamp_ex.h"
  294. /* Exported functions --------------------------------------------------------*/
  295. /** @addtogroup OPAMP_Exported_Functions
  296. * @{
  297. */
  298. /** @addtogroup OPAMP_Exported_Functions_Group1
  299. * @{
  300. */
  301. /* Initialization/de-initialization functions **********************************/
  302. HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef *hopamp);
  303. HAL_StatusTypeDef HAL_OPAMP_DeInit (OPAMP_HandleTypeDef *hopamp);
  304. void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef *hopamp);
  305. void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef *hopamp);
  306. /**
  307. * @}
  308. */
  309. /** @addtogroup OPAMP_Exported_Functions_Group2
  310. * @{
  311. */
  312. /* I/O operation functions *****************************************************/
  313. HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef *hopamp);
  314. HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef *hopamp);
  315. HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef *hopamp);
  316. /**
  317. * @}
  318. */
  319. /** @addtogroup OPAMP_Exported_Functions_Group3
  320. * @{
  321. */
  322. /* Peripheral Control functions ************************************************/
  323. #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
  324. /* OPAMP callback registering/unregistering */
  325. HAL_StatusTypeDef HAL_OPAMP_RegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackId, pOPAMP_CallbackTypeDef pCallback);
  326. HAL_StatusTypeDef HAL_OPAMP_UnRegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackId);
  327. #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
  328. HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef *hopamp);
  329. HAL_OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset);
  330. /**
  331. * @}
  332. */
  333. /** @addtogroup OPAMP_Exported_Functions_Group4
  334. * @{
  335. */
  336. /* Peripheral State functions **************************************************/
  337. HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(OPAMP_HandleTypeDef *hopamp);
  338. /**
  339. * @}
  340. */
  341. /**
  342. * @}
  343. */
  344. /**
  345. * @}
  346. */
  347. /**
  348. * @}
  349. */
  350. #ifdef __cplusplus
  351. }
  352. #endif
  353. #endif /* STM32H7xx_HAL_OPAMP_H */
  354. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/