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.
 
 
 

231 lines
8.2 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_ll_opamp.c
  4. * @author MCD Application Team
  5. * @brief OPAMP LL module driver
  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. #if defined(USE_FULL_LL_DRIVER)
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32h7xx_ll_opamp.h"
  22. #ifdef USE_FULL_ASSERT
  23. #include "stm32_assert.h"
  24. #else
  25. #define assert_param(expr) ((void)0U)
  26. #endif
  27. /** @addtogroup STM32H7xx_LL_Driver
  28. * @{
  29. */
  30. #if defined (OPAMP1) || defined (OPAMP2)
  31. /** @addtogroup OPAMP_LL OPAMP
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /* Private macros ------------------------------------------------------------*/
  38. /** @addtogroup OPAMP_LL_Private_Macros
  39. * @{
  40. */
  41. /* Check of parameters for configuration of OPAMP hierarchical scope: */
  42. /* OPAMP instance. */
  43. #define IS_LL_OPAMP_POWER_MODE(__POWER_MODE__) \
  44. ( ((__POWER_MODE__) == LL_OPAMP_POWERMODE_NORMAL) \
  45. || ((__POWER_MODE__) == LL_OPAMP_POWERMODE_HIGHSPEED))
  46. #define IS_LL_OPAMP_FUNCTIONAL_MODE(__FUNCTIONAL_MODE__) \
  47. ( ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_STANDALONE) \
  48. || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_FOLLOWER) \
  49. || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA) \
  50. || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA_IO0) \
  51. || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA_IO0_BIAS) \
  52. || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA_IO0_IO1_BIAS) \
  53. )
  54. #if defined(DAC2)
  55. #define IS_LL_OPAMP_INPUT_NONINVERTING(__INPUT_NONINVERTING__) \
  56. ( ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO0) \
  57. || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_DAC) \
  58. || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_DAC2) \
  59. )
  60. #else
  61. #define IS_LL_OPAMP_INPUT_NONINVERTING(__INPUT_NONINVERTING__) \
  62. ( ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO0) \
  63. || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_DAC) \
  64. )
  65. #endif /* DAC2 */
  66. #define IS_LL_OPAMP_INPUT_INVERTING(__INPUT_INVERTING__) \
  67. ( ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO0) \
  68. || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO1) \
  69. || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_CONNECT_NO) \
  70. )
  71. /**
  72. * @}
  73. */
  74. /* Private function prototypes -----------------------------------------------*/
  75. /* Exported functions --------------------------------------------------------*/
  76. /** @addtogroup OPAMP_LL_Exported_Functions
  77. * @{
  78. */
  79. /** @addtogroup OPAMP_LL_EF_Init
  80. * @{
  81. */
  82. /**
  83. * @brief De-initialize registers of the selected OPAMP instance
  84. * to their default reset values.
  85. * @note If comparator is locked, de-initialization by software is
  86. * not possible.
  87. * The only way to unlock the comparator is a device hardware reset.
  88. * @param OPAMPx OPAMP instance
  89. * @retval An ErrorStatus enumeration value:
  90. * - SUCCESS: OPAMP registers are de-initialized
  91. * - ERROR: OPAMP registers are not de-initialized
  92. */
  93. ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef* OPAMPx)
  94. {
  95. ErrorStatus status = SUCCESS;
  96. /* Check the parameters */
  97. assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx));
  98. LL_OPAMP_WriteReg(OPAMPx, CSR, 0x00000000U);
  99. return status;
  100. }
  101. /**
  102. * @brief Initialize some features of OPAMP instance.
  103. * @note This function reset bit of calibration mode to ensure
  104. * to be in functional mode, in order to have OPAMP parameters
  105. * (inputs selection, ...) set with the corresponding OPAMP mode
  106. * to be effective.
  107. * @param OPAMPx OPAMP instance
  108. * @param OPAMP_InitStruct Pointer to a @ref LL_OPAMP_InitTypeDef structure
  109. * @retval An ErrorStatus enumeration value:
  110. * - SUCCESS: OPAMP registers are initialized
  111. * - ERROR: OPAMP registers are not initialized
  112. */
  113. ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct)
  114. {
  115. ErrorStatus status = SUCCESS;
  116. /* Check the parameters */
  117. assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx));
  118. assert_param(IS_LL_OPAMP_POWER_MODE(OPAMP_InitStruct->PowerMode));
  119. assert_param(IS_LL_OPAMP_FUNCTIONAL_MODE(OPAMP_InitStruct->FunctionalMode));
  120. assert_param(IS_LL_OPAMP_INPUT_NONINVERTING(OPAMP_InitStruct->InputNonInverting));
  121. /* Note: OPAMP inverting input can be used with OPAMP in mode standalone */
  122. /* or PGA with external capacitors for filtering circuit. */
  123. /* Otherwise (OPAMP in mode follower), OPAMP inverting input is */
  124. /* not used (not connected to GPIO pin). */
  125. if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER)
  126. {
  127. assert_param(IS_LL_OPAMP_INPUT_INVERTING(OPAMP_InitStruct->InputInverting));
  128. }
  129. /* Configuration of OPAMP instance : */
  130. /* - PowerMode */
  131. /* - Functional mode */
  132. /* - Input non-inverting */
  133. /* - Input inverting */
  134. /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode. */
  135. if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER)
  136. {
  137. MODIFY_REG(OPAMPx->CSR,
  138. OPAMP_CSR_OPAHSM
  139. | OPAMP_CSR_CALON
  140. | OPAMP_CSR_VMSEL
  141. | OPAMP_CSR_VPSEL
  142. | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_PGGAIN_1
  143. ,
  144. (OPAMP_InitStruct->PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK)
  145. | OPAMP_InitStruct->FunctionalMode
  146. | OPAMP_InitStruct->InputNonInverting
  147. | OPAMP_InitStruct->InputInverting
  148. );
  149. }
  150. else
  151. {
  152. MODIFY_REG(OPAMPx->CSR,
  153. OPAMP_CSR_OPAHSM
  154. | OPAMP_CSR_CALON
  155. | OPAMP_CSR_VMSEL
  156. | OPAMP_CSR_VPSEL
  157. | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_PGGAIN_1
  158. ,
  159. (OPAMP_InitStruct->PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK)
  160. | LL_OPAMP_MODE_FOLLOWER
  161. | OPAMP_InitStruct->InputNonInverting
  162. );
  163. }
  164. return status;
  165. }
  166. /**
  167. * @brief Set each @ref LL_OPAMP_InitTypeDef field to default value.
  168. * @param OPAMP_InitStruct pointer to a @ref LL_OPAMP_InitTypeDef structure
  169. * whose fields will be set to default values.
  170. * @retval None
  171. */
  172. void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct)
  173. {
  174. /* Set OPAMP_InitStruct fields to default values */
  175. OPAMP_InitStruct->PowerMode = LL_OPAMP_POWERMODE_NORMAL;
  176. OPAMP_InitStruct->FunctionalMode = LL_OPAMP_MODE_FOLLOWER;
  177. OPAMP_InitStruct->InputNonInverting = LL_OPAMP_INPUT_NONINVERT_IO0;
  178. /* Note: Parameter discarded if OPAMP in functional mode follower, */
  179. /* set anyway to its default value. */
  180. OPAMP_InitStruct->InputInverting = LL_OPAMP_INPUT_INVERT_CONNECT_NO;
  181. }
  182. /**
  183. * @}
  184. */
  185. /**
  186. * @}
  187. */
  188. /**
  189. * @}
  190. */
  191. #endif /* OPAMP1 || OPAMP2 */
  192. /**
  193. * @}
  194. */
  195. #endif /* USE_FULL_LL_DRIVER */
  196. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/