STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_ll_opamp.c
Go to the documentation of this file.
1 
19 #if defined(USE_FULL_LL_DRIVER)
20 
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32l4xx_ll_opamp.h"
23 
24 #ifdef USE_FULL_ASSERT
25  #include "stm32_assert.h"
26 #else
27  #define assert_param(expr) ((void)0U)
28 #endif
29 
34 #if defined (OPAMP1) || defined (OPAMP2)
35 
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 /* Private constants ---------------------------------------------------------*/
43 /* Private macros ------------------------------------------------------------*/
44 
49 /* Check of parameters for configuration of OPAMP hierarchical scope: */
50 /* OPAMP instance. */
51 
52 #define IS_LL_OPAMP_POWER_MODE(__POWER_MODE__) \
53  ( ((__POWER_MODE__) == LL_OPAMP_POWERMODE_NORMAL) \
54  || ((__POWER_MODE__) == LL_OPAMP_POWERMODE_LOWPOWER))
55 
56 #define IS_LL_OPAMP_FUNCTIONAL_MODE(__FUNCTIONAL_MODE__) \
57  ( ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_STANDALONE) \
58  || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_FOLLOWER) \
59  || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA) \
60  )
61 
62 /* Note: Comparator non-inverting inputs parameters are the same on all */
63 /* OPAMP instances. */
64 /* However, comparator instance kept as macro parameter for */
65 /* compatibility with other STM32 families. */
66 #define IS_LL_OPAMP_INPUT_NONINVERTING(__OPAMPX__, __INPUT_NONINVERTING__) \
67  ( ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO0) \
68  || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINV_DAC1_CH1) \
69  )
70 
71 /* Note: Comparator non-inverting inputs parameters are the same on all */
72 /* OPAMP instances. */
73 /* However, comparator instance kept as macro parameter for */
74 /* compatibility with other STM32 families. */
75 #define IS_LL_OPAMP_INPUT_INVERTING(__OPAMPX__, __INPUT_INVERTING__) \
76  ( ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO0) \
77  || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO1) \
78  || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_CONNECT_NO) \
79  )
80 
86 /* Private function prototypes -----------------------------------------------*/
87 
88 /* Exported functions --------------------------------------------------------*/
105 ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef* OPAMPx)
106 {
107  ErrorStatus status = SUCCESS;
108 
109  /* Check the parameters */
110  assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx));
111 
112  LL_OPAMP_WriteReg(OPAMPx, CSR, 0x00000000U);
113 
114  return status;
115 }
116 
133 ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct)
134 {
135  /* Check the parameters */
136  assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx));
137  assert_param(IS_LL_OPAMP_POWER_MODE(OPAMP_InitStruct->PowerMode));
138  assert_param(IS_LL_OPAMP_FUNCTIONAL_MODE(OPAMP_InitStruct->FunctionalMode));
139  assert_param(IS_LL_OPAMP_INPUT_NONINVERTING(OPAMPx, OPAMP_InitStruct->InputNonInverting));
140 
141  /* Note: OPAMP inverting input can be used with OPAMP in mode standalone */
142  /* or PGA with external capacitors for filtering circuit. */
143  /* Otherwise (OPAMP in mode follower), OPAMP inverting input is */
144  /* not used (not connected to GPIO pin). */
145  if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER)
146  {
147  assert_param(IS_LL_OPAMP_INPUT_INVERTING(OPAMPx, OPAMP_InitStruct->InputInverting));
148  }
149 
150  /* Configuration of OPAMP instance : */
151  /* - PowerMode */
152  /* - Functional mode */
153  /* - Input non-inverting */
154  /* - Input inverting */
155  /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode. */
156  if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER)
157  {
158  MODIFY_REG(OPAMPx->CSR,
159  OPAMP_CSR_OPALPM
160  | OPAMP_CSR_OPAMODE
161  | OPAMP_CSR_CALON
162  | OPAMP_CSR_VMSEL
163  | OPAMP_CSR_VPSEL
164  ,
165  (OPAMP_InitStruct->PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK)
166  | OPAMP_InitStruct->FunctionalMode
167  | OPAMP_InitStruct->InputNonInverting
168  | OPAMP_InitStruct->InputInverting
169  );
170  }
171  else
172  {
173  MODIFY_REG(OPAMPx->CSR,
174  OPAMP_CSR_OPALPM
175  | OPAMP_CSR_OPAMODE
176  | OPAMP_CSR_CALON
177  | OPAMP_CSR_VMSEL
178  | OPAMP_CSR_VPSEL
179  ,
180  (OPAMP_InitStruct->PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK)
181  | LL_OPAMP_MODE_FOLLOWER
182  | OPAMP_InitStruct->InputNonInverting
183  | LL_OPAMP_INPUT_INVERT_CONNECT_NO
184  );
185  }
186 
187  return SUCCESS;
188 }
189 
197 {
198  /* Set OPAMP_InitStruct fields to default values */
199  OPAMP_InitStruct->PowerMode = LL_OPAMP_POWERMODE_NORMAL;
200  OPAMP_InitStruct->FunctionalMode = LL_OPAMP_MODE_FOLLOWER;
201  OPAMP_InitStruct->InputNonInverting = LL_OPAMP_INPUT_NONINVERT_IO0;
202  /* Note: Parameter discarded if OPAMP in functional mode follower, */
203  /* set anyway to its default value. */
204  OPAMP_InitStruct->InputInverting = LL_OPAMP_INPUT_INVERT_CONNECT_NO;
205 }
206 
219 #endif /* OPAMP1 || OPAMP2 */
220 
225 #endif /* USE_FULL_LL_DRIVER */
226 
227 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct)
Set each LL_OPAMP_InitTypeDef field to default value.
Structure definition of some features of OPAMP instance.
Header file of OPAMP LL module.
ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct)
Initialize some features of OPAMP instance.
ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx)
De-initialize registers of the selected OPAMP instance to their default reset values.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))