stm32h7xx_hal_opamp.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_opamp.h
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 21-April-2017
  7. * @brief Header file of OPAMP HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32H7xx_HAL_OPAMP_H
  39. #define __STM32H7xx_HAL_OPAMP_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32h7xx_hal_def.h"
  45. /** @addtogroup STM32H7xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup OPAMP
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup OPAMP_Exported_Types OPAMP Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief OPAMP Init structure definition
  57. */
  58. typedef struct
  59. {
  60. uint32_t PowerMode; /*!< Specifies the power mode Normal or High Speed.
  61. This parameter must be a value of @ref OPAMP_PowerMode */
  62. uint32_t Mode; /*!< Specifies the OPAMP mode
  63. This parameter must be a value of @ref OPAMP_Mode
  64. mode is either Standalone, - Follower or PGA */
  65. uint32_t InvertingInput; /*!< Specifies the inverting input in Standalone & PGA modes
  66. - In Standalone mode i.e when mode is OPAMP_STANDALONE_MODE
  67. This parameter must be a value of @ref OPAMP_InvertingInput
  68. - In Follower mode i.e when mode is OPAMP_FOLLOWER_MODE
  69. & In PGA mode i.e when mode is OPAMP_PGA_MODE
  70. This parameter is Not Applicable */
  71. uint32_t NonInvertingInput; /*!< Specifies the non inverting input of the opamp:
  72. This parameter must be a value of @ref OPAMP_NonInvertingInput */
  73. uint32_t PgaGain; /*!< Specifies the gain in PGA mode
  74. i.e. when mode is OPAMP_PGA_MODE.
  75. This parameter must be a value of @ref OPAMP_PgaGain */
  76. uint32_t PgaConnect; /*!< Specifies the inverting pin in PGA mode
  77. i.e. when mode is OPAMP_PGA_MODE
  78. This parameter must be a value of @ref OPAMP_PgaConnect
  79. Either: not connected, connected to VINM0, connected to VINM1
  80. (VINM0 or VINM1 are typically used for external filtering) */
  81. uint32_t UserTrimming; /*!< Specifies the trimming mode
  82. This parameter must be a value of @ref OPAMP_UserTrimming
  83. UserTrimming is either factory or user trimming.*/
  84. uint32_t TrimmingValueP; /*!< Specifies the offset trimming value (PMOS) in Normal Mode
  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. 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. uint32_t TrimmingValuePHighSpeed; /*!< Specifies the offset trimming value (PMOS) in High Speed Mode
  93. i.e. when UserTrimming is OPAMP_TRIMMING_USER.
  94. This parameter must be a number between Min_Data = 0 and Max_Data = 31.
  95. 16 is typical default value */
  96. uint32_t TrimmingValueNHighSpeed; /*!< Specifies the offset trimming value (NMOS) in High Speed Mode
  97. i.e. when UserTrimming is OPAMP_TRIMMING_USER.
  98. This parameter must be a number between Min_Data = 0 and Max_Data = 31.
  99. 16 is typical default value */
  100. }OPAMP_InitTypeDef;
  101. /**
  102. * @brief HAL State structures definition
  103. */
  104. typedef enum
  105. {
  106. HAL_OPAMP_STATE_RESET = 0x00000000, /*!< OPAMP is not yet Initialized */
  107. HAL_OPAMP_STATE_READY = 0x00000001, /*!< OPAMP is initialized and ready for use */
  108. HAL_OPAMP_STATE_CALIBBUSY = 0x00000002, /*!< OPAMP is enabled in auto calibration mode */
  109. HAL_OPAMP_STATE_BUSY = 0x00000004, /*!< OPAMP is enabled and running in normal mode */
  110. HAL_OPAMP_STATE_BUSYLOCKED = 0x00000005 /*!< OPAMP is locked
  111. only system reset allows reconfiguring the opamp. */
  112. }HAL_OPAMP_StateTypeDef;
  113. /**
  114. * @brief OPAMP Handle Structure definition
  115. */
  116. typedef struct
  117. {
  118. OPAMP_TypeDef *Instance; /*!< OPAMP instance's registers base address */
  119. OPAMP_InitTypeDef Init; /*!< OPAMP required parameters */
  120. HAL_StatusTypeDef Status; /*!< OPAMP peripheral status */
  121. HAL_LockTypeDef Lock; /*!< Locking object */
  122. __IO HAL_OPAMP_StateTypeDef State; /*!< OPAMP communication state */
  123. } OPAMP_HandleTypeDef;
  124. /**
  125. * @brief HAl_OPAMP_TrimmingValueTypeDef definition
  126. */
  127. typedef uint32_t HAL_OPAMP_TrimmingValueTypeDef;
  128. /**
  129. * @}
  130. */
  131. /* Exported constants --------------------------------------------------------*/
  132. /** @defgroup OPAMP_Exported_Constants OPAMP Exported Constants
  133. * @{
  134. */
  135. /** @defgroup OPAMP_Mode OPAMP Mode
  136. * @{
  137. */
  138. #define OPAMP_STANDALONE_MODE ((uint32_t)0x00000000) /*!< standalone mode */
  139. #define OPAMP_PGA_MODE OPAMP_CSR_VMSEL_1 /*!< PGA mode */
  140. #define OPAMP_FOLLOWER_MODE (OPAMP_CSR_VMSEL_1 | OPAMP_CSR_VMSEL_0) /*!< follower mode */
  141. /**
  142. * @}
  143. */
  144. /** @defgroup OPAMP_NonInvertingInput OPAMP Non Inverting Input
  145. * @{
  146. */
  147. #define OPAMP_NONINVERTINGINPUT_IO0 ((uint32_t)0x00000000) /*!< OPAMP non-inverting input connected to dedicated IO pin */
  148. #define OPAMP_NONINVERTINGINPUT_DAC_CH OPAMP_CSR_VPSEL_0 /*!< OPAMP non-inverting input connected internally to DAC channel */
  149. /**
  150. * @}
  151. */
  152. /** @defgroup OPAMP_InvertingInput OPAMP Inverting Input
  153. * @{
  154. */
  155. #define OPAMP_INVERTINGINPUT_IO0 ((uint32_t)0x00000000) /*!< OPAMP inverting input connected to dedicated IO pin */
  156. #define OPAMP_INVERTINGINPUT_IO1 OPAMP_CSR_VMSEL_0 /*!< OPAMP inverting input connected to dedicated IO pin */
  157. /**
  158. * @}
  159. */
  160. /** @defgroup OPAMP_PgaConnect OPAMP Pga Connect
  161. * @{
  162. */
  163. #define OPAMP_PGA_CONNECT_INVERTINGINPUT_NO ((uint32_t)0x00000000) /*!< In PGA mode, the inverting input is not connected */
  164. #define OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0 OPAMP_CSR_PGGAIN_2 /*!< In PGA mode, the inverting input is connected to VINM0 */
  165. #define OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_BIAS OPAMP_CSR_PGGAIN_3 /*!< In PGA mode, the inverting input is connected to VINM0 or bias */
  166. #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 */
  167. /**
  168. * @}
  169. */
  170. /** @defgroup OPAMP_PgaGain OPAMP Pga Gain
  171. * @{
  172. */
  173. #define OPAMP_PGA_GAIN_2_OR_MINUS_1 ((uint32_t)0x00000000) /*!< PGA gain could be 2 or -1 */
  174. #define OPAMP_PGA_GAIN_4_OR_MINUS_3 OPAMP_CSR_PGGAIN_0 /*!< PGA gain could be 4 or -3 */
  175. #define OPAMP_PGA_GAIN_8_OR_MINUS_7 OPAMP_CSR_PGGAIN_1 /*!< PGA gain could be 8 or -7 */
  176. #define OPAMP_PGA_GAIN_16_OR_MINUS_15 (OPAMP_CSR_PGGAIN_0 | OPAMP_CSR_PGGAIN_1) /*!< PGA gain could be 16 or -15 */
  177. /**
  178. * @}
  179. */
  180. /** @defgroup OPAMP_PowerMode OPAMP PowerMode
  181. * @{
  182. */
  183. #define OPAMP_POWERMODE_NORMAL ((uint32_t)0x00000000)
  184. #define OPAMP_POWERMODE_HIGHSPEED OPAMP_CSR_OPAHSM
  185. /**
  186. * @}
  187. */
  188. /** @defgroup OPAMP_VREF OPAMP VREF
  189. * @{
  190. */
  191. #define OPAMP_VREF_3VDDA ((uint32_t)0x00000000) /*!< OPAMP Vref = 3.3% VDDA */
  192. #define OPAMP_VREF_10VDDA OPAMP_CSR_CALSEL_0 /*!< OPAMP Vref = 10% VDDA */
  193. #define OPAMP_VREF_50VDDA OPAMP_CSR_CALSEL_1 /*!< OPAMP Vref = 50% VDDA */
  194. #define OPAMP_VREF_90VDDA OPAMP_CSR_CALSEL /*!< OPAMP Vref = 90% VDDA */
  195. /**
  196. * @}
  197. */
  198. /** @defgroup OPAMP_UserTrimming OPAMP User Trimming
  199. * @{
  200. */
  201. #define OPAMP_TRIMMING_FACTORY ((uint32_t)0x00000000) /*!< Factory trimming */
  202. #define OPAMP_TRIMMING_USER OPAMP_CSR_USERTRIM /*!< User trimming */
  203. /**
  204. * @}
  205. */
  206. /** @defgroup OPAMP_FactoryTrimming OPAMP Factory Trimming
  207. * @{
  208. */
  209. #define OPAMP_FACTORYTRIMMING_DUMMY ((uint32_t)0xFFFFFFFF) /*!< Dummy value if trimming value could not be retrieved */
  210. #define OPAMP_FACTORYTRIMMING_N ((uint32_t)0x00000000) /*!< Offset trimming N */
  211. #define OPAMP_FACTORYTRIMMING_P ((uint32_t)0x00000001) /*!< Offset trimming P */
  212. /**
  213. * @}
  214. */
  215. /**
  216. * @}
  217. */
  218. /* Private constants ---------------------------------------------------------*/
  219. /** @defgroup OPAMP_Private_Constants OPAMP Private Constants
  220. * @brief OPAMP Private constants and defines
  221. * @{
  222. */
  223. /* NONINVERTING bit position in OTR & HSOTR */
  224. #define OPAMP_INPUT_NONINVERTING ((uint32_t) 8) /*!< Non inverting input */
  225. /* Offset trimming time: during calibration, minimum time needed between two */
  226. /* steps to have 1 mV accuracy. */
  227. /* Refer to datasheet, electrical characteristics: parameter tOFFTRIM Typ=2ms.*/
  228. /* Unit: ms. */
  229. #define OPAMP_TRIMMING_DELAY ((uint32_t) 2)
  230. /**
  231. * @}
  232. */
  233. /* Exported macros -----------------------------------------------------------*/
  234. /** @defgroup OPAMP_Exported_Macros OPAMP Exported Macros
  235. * @{
  236. */
  237. /** @brief Reset OPAMP handle state.
  238. * @param __HANDLE__: OPAMP handle.
  239. * @retval None
  240. */
  241. #define __HAL_OPAMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_OPAMP_STATE_RESET)
  242. /**
  243. * @}
  244. */
  245. /* Private macro -------------------------------------------------------------*/
  246. /** @defgroup OPAMP_Private_Macros OPAMP Private Macros
  247. * @{
  248. */
  249. #define IS_OPAMP_FUNCTIONAL_NORMALMODE(INPUT) (((INPUT) == OPAMP_STANDALONE_MODE) || \
  250. ((INPUT) == OPAMP_PGA_MODE) || \
  251. ((INPUT) == OPAMP_FOLLOWER_MODE))
  252. #define IS_OPAMP_INVERTING_INPUT_STANDALONE(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_IO0) || \
  253. ((INPUT) == OPAMP_INVERTINGINPUT_IO1))
  254. #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \
  255. ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH))
  256. #define IS_OPAMP_PGACONNECT(CONNECT) (((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_NO) || \
  257. ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0) || \
  258. ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_BIAS) || \
  259. ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_IO1_BIAS))
  260. #define IS_OPAMP_PGA_GAIN(GAIN) (((GAIN) == OPAMP_PGA_GAIN_2_OR_MINUS_1) || \
  261. ((GAIN) == OPAMP_PGA_GAIN_4_OR_MINUS_3) || \
  262. ((GAIN) == OPAMP_PGA_GAIN_8_OR_MINUS_7) || \
  263. ((GAIN) == OPAMP_PGA_GAIN_16_OR_MINUS_15))
  264. #define IS_OPAMP_VREF(VREF) (((VREF) == OPAMP_VREF_3VDDA) || \
  265. ((VREF) == OPAMP_VREF_10VDDA) || \
  266. ((VREF) == OPAMP_VREF_50VDDA) || \
  267. ((VREF) == OPAMP_VREF_90VDDA))
  268. #define IS_OPAMP_POWERMODE(TRIMMING) (((TRIMMING) == OPAMP_POWERMODE_NORMAL) || \
  269. ((TRIMMING) == OPAMP_POWERMODE_HIGHSPEED) )
  270. #define IS_OPAMP_TRIMMING(TRIMMING) (((TRIMMING) == OPAMP_TRIMMING_FACTORY) || \
  271. ((TRIMMING) == OPAMP_TRIMMING_USER))
  272. #define IS_OPAMP_TRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 0x1F)
  273. #define IS_OPAMP_FACTORYTRIMMING(TRIMMING) (((TRIMMING) == OPAMP_FACTORYTRIMMING_N) || \
  274. ((TRIMMING) == OPAMP_FACTORYTRIMMING_P))
  275. /**
  276. * @}
  277. */
  278. /* Include OPAMP HAL Extended module */
  279. #include "stm32h7xx_hal_opamp_ex.h"
  280. /* Exported functions --------------------------------------------------------*/
  281. /** @addtogroup OPAMP_Exported_Functions
  282. * @{
  283. */
  284. /** @addtogroup OPAMP_Exported_Functions_Group1
  285. * @{
  286. */
  287. /* Initialization/de-initialization functions **********************************/
  288. HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef *hopamp);
  289. HAL_StatusTypeDef HAL_OPAMP_DeInit (OPAMP_HandleTypeDef *hopamp);
  290. void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef *hopamp);
  291. void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef *hopamp);
  292. /**
  293. * @}
  294. */
  295. /** @addtogroup OPAMP_Exported_Functions_Group2
  296. * @{
  297. */
  298. /* I/O operation functions *****************************************************/
  299. HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef *hopamp);
  300. HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef *hopamp);
  301. HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef *hopamp);
  302. /**
  303. * @}
  304. */
  305. /** @addtogroup OPAMP_Exported_Functions_Group3
  306. * @{
  307. */
  308. /* Peripheral Control functions ************************************************/
  309. HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef *hopamp);
  310. HAL_OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset);
  311. /**
  312. * @}
  313. */
  314. /** @addtogroup OPAMP_Exported_Functions_Group4
  315. * @{
  316. */
  317. /* Peripheral State functions **************************************************/
  318. HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(OPAMP_HandleTypeDef *hopamp);
  319. /**
  320. * @}
  321. */
  322. /**
  323. * @}
  324. */
  325. /**
  326. * @}
  327. */
  328. /**
  329. * @}
  330. */
  331. #ifdef __cplusplus
  332. }
  333. #endif
  334. #endif /* __STM32H7xx_HAL_OPAMP_H */
  335. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/