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.
 
 
 

426 lines
17 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_opamp.h
  4. * @author MCD Application Team
  5. * @version V1.7.2
  6. * @date 16-June-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 __STM32L4xx_HAL_OPAMP_H
  39. #define __STM32L4xx_HAL_OPAMP_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32l4xx_hal_def.h"
  45. /** @addtogroup STM32L4xx_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 PowerSupplyRange; /*!< Specifies the power supply range: above or under 2.4V.
  61. This parameter must be a value of @ref OPAMP_PowerSupplyRange
  62. Caution: This parameter is common to all OPAMP instances: a modification of this parameter for the selected OPAMP impacts the other OPAMP instances. */
  63. uint32_t PowerMode; /*!< Specifies the power mode Normal or Low-Power.
  64. This parameter must be a value of @ref OPAMP_PowerMode */
  65. uint32_t Mode; /*!< Specifies the OPAMP mode
  66. This parameter must be a value of @ref OPAMP_Mode
  67. mode is either Standalone, - Follower or PGA */
  68. uint32_t InvertingInput; /*!< Specifies the inverting input in Standalone & PGA modes
  69. - In Standalone mode: i.e. when mode is OPAMP_STANDALONE_MODE
  70. & PGA mode: i.e. when mode is OPAMP_PGA_MODE
  71. This parameter must be a value of @ref OPAMP_InvertingInput
  72. - In Follower mode i.e. when mode is OPAMP_FOLLOWER_MODE
  73. This parameter is Not Applicable */
  74. uint32_t NonInvertingInput; /*!< Specifies the non inverting input of the opamp:
  75. This parameter must be a value of @ref OPAMP_NonInvertingInput */
  76. uint32_t PgaGain; /*!< Specifies the gain in PGA mode
  77. i.e. when mode is OPAMP_PGA_MODE.
  78. This parameter must be a value of @ref OPAMP_PgaGain (2, 4, 8 or 16 ) */
  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. uint32_t TrimmingValueP; /*!< Specifies the offset trimming value (PMOS)
  83. i.e. when UserTrimming is OPAMP_TRIMMING_USER.
  84. This parameter must be a number between Min_Data = 0 and Max_Data = 31
  85. 16 is typical default value */
  86. uint32_t TrimmingValueN; /*!< Specifies the offset trimming value (NMOS)
  87. i.e. when UserTrimming is OPAMP_TRIMMING_USER.
  88. This parameter must be a number between Min_Data = 0 and Max_Data = 31
  89. 16 is typical default value */
  90. uint32_t TrimmingValuePLowPower; /*!< Specifies the offset trimming value (PMOS)
  91. i.e. when UserTrimming is OPAMP_TRIMMING_USER.
  92. This parameter must be a number between Min_Data = 0 and Max_Data = 31
  93. 16 is typical default value */
  94. uint32_t TrimmingValueNLowPower; /*!< Specifies the offset trimming value (NMOS)
  95. i.e. when UserTrimming is OPAMP_TRIMMING_USER.
  96. This parameter must be a number between Min_Data = 0 and Max_Data = 31
  97. 16 is typical default value */
  98. }OPAMP_InitTypeDef;
  99. /**
  100. * @brief HAL State structures definition
  101. */
  102. typedef enum
  103. {
  104. HAL_OPAMP_STATE_RESET = 0x00000000, /*!< OPAMP is not yet Initialized */
  105. HAL_OPAMP_STATE_READY = 0x00000001, /*!< OPAMP is initialized and ready for use */
  106. HAL_OPAMP_STATE_CALIBBUSY = 0x00000002, /*!< OPAMP is enabled in auto calibration mode */
  107. HAL_OPAMP_STATE_BUSY = 0x00000004, /*!< OPAMP is enabled and running in normal mode */
  108. HAL_OPAMP_STATE_BUSYLOCKED = 0x00000005 /*!< OPAMP is locked
  109. only system reset allows reconfiguring the opamp. */
  110. }HAL_OPAMP_StateTypeDef;
  111. /**
  112. * @brief OPAMP Handle Structure definition
  113. */
  114. typedef struct
  115. {
  116. OPAMP_TypeDef *Instance; /*!< OPAMP instance's registers base address */
  117. OPAMP_InitTypeDef Init; /*!< OPAMP required parameters */
  118. HAL_StatusTypeDef Status; /*!< OPAMP peripheral status */
  119. HAL_LockTypeDef Lock; /*!< Locking object */
  120. __IO HAL_OPAMP_StateTypeDef State; /*!< OPAMP communication state */
  121. } OPAMP_HandleTypeDef;
  122. /**
  123. * @brief HAl_OPAMP_TrimmingValueTypeDef definition
  124. */
  125. typedef uint32_t HAL_OPAMP_TrimmingValueTypeDef;
  126. /**
  127. * @}
  128. */
  129. /* Exported constants --------------------------------------------------------*/
  130. /** @defgroup OPAMP_Exported_Constants OPAMP Exported Constants
  131. * @{
  132. */
  133. /** @defgroup OPAMP_Mode OPAMP Mode
  134. * @{
  135. */
  136. #define OPAMP_STANDALONE_MODE ((uint32_t)0x00000000) /*!< standalone mode */
  137. #define OPAMP_PGA_MODE OPAMP_CSR_OPAMODE_1 /*!< PGA mode */
  138. #define OPAMP_FOLLOWER_MODE OPAMP_CSR_OPAMODE /*!< follower mode */
  139. /**
  140. * @}
  141. */
  142. /** @defgroup OPAMP_NonInvertingInput OPAMP Non Inverting Input
  143. * @{
  144. */
  145. #define OPAMP_NONINVERTINGINPUT_IO0 ((uint32_t)0x00000000) /*!< OPAMP non-inverting input connected to dedicated IO pin */
  146. #define OPAMP_NONINVERTINGINPUT_DAC_CH OPAMP_CSR_VPSEL /*!< OPAMP non-inverting input connected internally to DAC channel */
  147. /**
  148. * @}
  149. */
  150. /** @defgroup OPAMP_InvertingInput OPAMP Inverting Input
  151. * @{
  152. */
  153. #define OPAMP_INVERTINGINPUT_IO0 ((uint32_t)0x00000000) /*!< OPAMP inverting input connected to dedicated IO pin low-leakage */
  154. #define OPAMP_INVERTINGINPUT_IO1 OPAMP_CSR_VMSEL_0 /*!< OPAMP inverting input connected to alternative IO pin available on some device packages */
  155. #define OPAMP_INVERTINGINPUT_CONNECT_NO OPAMP_CSR_VMSEL_1 /*!< OPAMP inverting input not connected externally (PGA mode only) */
  156. /**
  157. * @}
  158. */
  159. /** @defgroup OPAMP_PgaGain OPAMP Pga Gain
  160. * @{
  161. */
  162. #define OPAMP_PGA_GAIN_2 ((uint32_t)0x00000000) /*!< PGA gain = 2 */
  163. #define OPAMP_PGA_GAIN_4 OPAMP_CSR_PGGAIN_0 /*!< PGA gain = 4 */
  164. #define OPAMP_PGA_GAIN_8 OPAMP_CSR_PGGAIN_1 /*!< PGA gain = 8 */
  165. #define OPAMP_PGA_GAIN_16 (OPAMP_CSR_PGGAIN_0 | OPAMP_CSR_PGGAIN_1) /*!< PGA gain = 16 */
  166. /**
  167. * @}
  168. */
  169. /** @defgroup OPAMP_PowerMode OPAMP PowerMode
  170. * @{
  171. */
  172. #define OPAMP_POWERMODE_NORMAL ((uint32_t)0x00000000)
  173. #define OPAMP_POWERMODE_LOWPOWER OPAMP_CSR_OPALPM
  174. /**
  175. * @}
  176. */
  177. /** @defgroup OPAMP_PowerSupplyRange OPAMP PowerSupplyRange
  178. * @{
  179. */
  180. #define OPAMP_POWERSUPPLY_LOW ((uint32_t)0x00000000) /*!< Power supply range low (VDDA lower than 2.4V) */
  181. #define OPAMP_POWERSUPPLY_HIGH OPAMP1_CSR_OPARANGE /*!< Power supply range high (VDDA higher than 2.4V) */
  182. /**
  183. * @}
  184. */
  185. /** @defgroup OPAMP_UserTrimming OPAMP User Trimming
  186. * @{
  187. */
  188. #define OPAMP_TRIMMING_FACTORY ((uint32_t)0x00000000) /*!< Factory trimming */
  189. #define OPAMP_TRIMMING_USER OPAMP_CSR_USERTRIM /*!< User trimming */
  190. /**
  191. * @}
  192. */
  193. /** @defgroup OPAMP_FactoryTrimming OPAMP Factory Trimming
  194. * @{
  195. */
  196. #define OPAMP_FACTORYTRIMMING_DUMMY ((uint32_t)0xFFFFFFFF) /*!< Dummy value if trimming value could not be retrieved */
  197. #define OPAMP_FACTORYTRIMMING_N ((uint32_t)0x00000000) /*!< Offset trimming N */
  198. #define OPAMP_FACTORYTRIMMING_P ((uint32_t)0x00000001) /*!< Offset trimming P */
  199. /**
  200. * @}
  201. */
  202. /**
  203. * @}
  204. */
  205. /* Private constants ---------------------------------------------------------*/
  206. /** @defgroup OPAMP_Private_Constants OPAMP Private Constants
  207. * @brief OPAMP Private constants and defines
  208. * @{
  209. */
  210. /* NONINVERTING bit position in OTR & LPOTR */
  211. #define OPAMP_INPUT_NONINVERTING ((uint32_t) 8) /*!< Non inverting input */
  212. /* Offset trimming time: during calibration, minimum time needed between two */
  213. /* steps to have 1 mV accuracy. */
  214. /* Refer to datasheet, electrical characteristics: parameter tOFFTRIM Typ=1ms.*/
  215. /* Unit: ms. */
  216. #define OPAMP_TRIMMING_DELAY ((uint32_t) 1)
  217. /**
  218. * @}
  219. */
  220. /* Exported macros -----------------------------------------------------------*/
  221. /** @defgroup OPAMP_Exported_Macros OPAMP Exported Macros
  222. * @{
  223. */
  224. /** @brief Reset OPAMP handle state.
  225. * @param __HANDLE__: OPAMP handle.
  226. * @retval None
  227. */
  228. #define __HAL_OPAMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_OPAMP_STATE_RESET)
  229. /**
  230. * @}
  231. */
  232. /* Private macro -------------------------------------------------------------*/
  233. /** @defgroup OPAMP_Private_Macros OPAMP Private Macros
  234. * @{
  235. */
  236. #define IS_OPAMP_FUNCTIONAL_NORMALMODE(INPUT) (((INPUT) == OPAMP_STANDALONE_MODE) || \
  237. ((INPUT) == OPAMP_PGA_MODE) || \
  238. ((INPUT) == OPAMP_FOLLOWER_MODE))
  239. #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
  240. #define IS_OPAMP_INVERTING_INPUT_STANDALONE(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_IO0) || \
  241. ((INPUT) == OPAMP_INVERTINGINPUT_IO1))
  242. #endif /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */
  243. #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx)
  244. #define IS_OPAMP_INVERTING_INPUT_STANDALONE(INPUT) ((INPUT) == OPAMP_INVERTINGINPUT_IO0)
  245. #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx STM32L451xx STM32L452xx STM32L462xx */
  246. #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \
  247. ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH))
  248. #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
  249. #define IS_OPAMP_INVERTING_INPUT_PGA(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_IO0) || \
  250. ((INPUT) == OPAMP_INVERTINGINPUT_IO1)|| \
  251. ((INPUT) == OPAMP_INVERTINGINPUT_CONNECT_NO))
  252. #endif /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */
  253. #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx)
  254. #define IS_OPAMP_INVERTING_INPUT_PGA(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_IO0) || \
  255. ((INPUT) == OPAMP_INVERTINGINPUT_CONNECT_NO))
  256. #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx STM32L451xx STM32L452xx STM32L462xx */
  257. #define IS_OPAMP_PGA_GAIN(GAIN) (((GAIN) == OPAMP_PGA_GAIN_2) || \
  258. ((GAIN) == OPAMP_PGA_GAIN_4) || \
  259. ((GAIN) == OPAMP_PGA_GAIN_8) || \
  260. ((GAIN) == OPAMP_PGA_GAIN_16))
  261. #define IS_OPAMP_POWERMODE(TRIMMING) (((TRIMMING) == OPAMP_POWERMODE_NORMAL) || \
  262. ((TRIMMING) == OPAMP_POWERMODE_LOWPOWER) )
  263. #define IS_OPAMP_POWER_SUPPLY_RANGE(RANGE) (((RANGE) == OPAMP_POWERSUPPLY_LOW) || \
  264. ((RANGE) == OPAMP_POWERSUPPLY_HIGH) )
  265. #define IS_OPAMP_TRIMMING(TRIMMING) (((TRIMMING) == OPAMP_TRIMMING_FACTORY) || \
  266. ((TRIMMING) == OPAMP_TRIMMING_USER))
  267. #define IS_OPAMP_TRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 0x1F)
  268. #define IS_OPAMP_FACTORYTRIMMING(TRIMMING) (((TRIMMING) == OPAMP_FACTORYTRIMMING_N) || \
  269. ((TRIMMING) == OPAMP_FACTORYTRIMMING_P))
  270. /**
  271. * @}
  272. */
  273. /* Include OPAMP HAL Extended module */
  274. #include "stm32l4xx_hal_opamp_ex.h"
  275. /* Exported functions --------------------------------------------------------*/
  276. /** @addtogroup OPAMP_Exported_Functions
  277. * @{
  278. */
  279. /** @addtogroup OPAMP_Exported_Functions_Group1
  280. * @{
  281. */
  282. /* Initialization/de-initialization functions **********************************/
  283. HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef *hopamp);
  284. HAL_StatusTypeDef HAL_OPAMP_DeInit (OPAMP_HandleTypeDef *hopamp);
  285. void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef *hopamp);
  286. void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef *hopamp);
  287. /**
  288. * @}
  289. */
  290. /** @addtogroup OPAMP_Exported_Functions_Group2
  291. * @{
  292. */
  293. /* I/O operation functions *****************************************************/
  294. HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef *hopamp);
  295. HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef *hopamp);
  296. HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef *hopamp);
  297. /**
  298. * @}
  299. */
  300. /** @addtogroup OPAMP_Exported_Functions_Group3
  301. * @{
  302. */
  303. /* Peripheral Control functions ************************************************/
  304. HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef *hopamp);
  305. HAL_OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset);
  306. /**
  307. * @}
  308. */
  309. /** @addtogroup OPAMP_Exported_Functions_Group4
  310. * @{
  311. */
  312. /* Peripheral State functions **************************************************/
  313. HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(OPAMP_HandleTypeDef *hopamp);
  314. /**
  315. * @}
  316. */
  317. /**
  318. * @}
  319. */
  320. /**
  321. * @}
  322. */
  323. /**
  324. * @}
  325. */
  326. #ifdef __cplusplus
  327. }
  328. #endif
  329. #endif /* __STM32L4xx_HAL_OPAMP_H */
  330. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/