stm32l4xx_hal_opamp.h 18 KB

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