1 /**
2   ******************************************************************************
3   * @file    stm32h7xx_hal_opamp.h
4   * @author  MCD Application Team
5   * @brief   Header file of OPAMP HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2017 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32H7xx_HAL_OPAMP_H
21 #define STM32H7xx_HAL_OPAMP_H
22 
23 #ifdef __cplusplus
24  extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32h7xx_hal_def.h"
29 
30 /** @addtogroup STM32H7xx_HAL_Driver
31   * @{
32   */
33 
34 /** @addtogroup OPAMP
35   * @{
36   */
37 
38 /* Exported types ------------------------------------------------------------*/
39 
40 /** @defgroup OPAMP_Exported_Types OPAMP Exported Types
41   * @{
42   */
43 
44 /**
45   * @brief  OPAMP Init structure definition
46   */
47 
48 typedef struct
49 {
50 
51   uint32_t PowerMode;                   /*!< Specifies the power mode Normal or High Speed.
52                                              This parameter must be a value of @ref OPAMP_PowerMode */
53 
54   uint32_t Mode;                        /*!< Specifies the OPAMP mode
55                                              This parameter must be a value of @ref OPAMP_Mode
56                                              mode is either Standalone, - Follower or PGA */
57 
58   uint32_t InvertingInput;              /*!< Specifies the inverting input in Standalone & PGA modes
59                                              - In Standalone mode i.e when mode is OPAMP_STANDALONE_MODE
60                                                  This parameter must be a value of @ref OPAMP_InvertingInput
61                                              - In Follower mode i.e when mode is OPAMP_FOLLOWER_MODE
62                                            & In PGA mode i.e when mode is OPAMP_PGA_MODE
63                                                  This parameter is Not Applicable */
64 
65   uint32_t NonInvertingInput;           /*!< Specifies the non inverting input of the opamp:
66                                              This parameter must be a value of @ref OPAMP_NonInvertingInput */
67 
68   uint32_t PgaGain;                     /*!< Specifies the gain in PGA mode
69                                              i.e. when mode is OPAMP_PGA_MODE.
70                                              This parameter must be a value of @ref OPAMP_PgaGain */
71 
72   uint32_t PgaConnect;                  /*!< Specifies the inverting pin in PGA mode
73                                              i.e. when mode is OPAMP_PGA_MODE
74                                              This parameter must be a value of @ref OPAMP_PgaConnect
75                                              Either: not connected, connected to VINM0, connected to VINM1
76                                              (VINM0 or VINM1 are typically used for external filtering) */
77 
78   uint32_t UserTrimming;                /*!< Specifies the trimming mode
79                                              This parameter must be a value of @ref OPAMP_UserTrimming
80                                              UserTrimming is either factory or user trimming.*/
81 
82   uint32_t TrimmingValueP;              /*!< Specifies the offset trimming value (PMOS) in Normal Mode
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 
87   uint32_t TrimmingValueN;              /*!< Specifies the offset trimming value (NMOS) in Normal Mode
88                                              i.e. when UserTrimming is OPAMP_TRIMMING_USER.
89                                              This parameter must be a number between Min_Data = 0 and Max_Data = 31.
90                                              16 is typical default value */
91 
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 
97   uint32_t TrimmingValueNHighSpeed;      /*!< Specifies the offset trimming value (NMOS) in High Speed Mode
98                                              i.e. when UserTrimming is OPAMP_TRIMMING_USER.
99                                              This parameter must be a number between Min_Data = 0 and Max_Data = 31.
100                                              16 is typical default value */
101 
102 }OPAMP_InitTypeDef;
103 
104 /**
105   * @brief  HAL State structures definition
106   */
107 
108 typedef enum
109 {
110   HAL_OPAMP_STATE_RESET               = 0x00000000U, /*!< OPAMP is not yet Initialized          */
111 
112   HAL_OPAMP_STATE_READY               = 0x00000001U, /*!< OPAMP is initialized and ready for use */
113   HAL_OPAMP_STATE_CALIBBUSY           = 0x00000002U, /*!< OPAMP is enabled in auto calibration mode */
114 
115   HAL_OPAMP_STATE_BUSY                = 0x00000004U, /*!< OPAMP is enabled and running in normal mode */
116   HAL_OPAMP_STATE_BUSYLOCKED          = 0x00000005U  /*!< OPAMP is locked
117                                                          only system reset allows reconfiguring the opamp. */
118 
119 }HAL_OPAMP_StateTypeDef;
120 
121 /**
122   * @brief OPAMP Handle Structure definition
123   */
124 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
125 typedef struct __OPAMP_HandleTypeDef
126 #else
127 typedef struct
128 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
129 {
130   OPAMP_TypeDef                 *Instance;                    /*!< OPAMP instance's registers base address */
131   OPAMP_InitTypeDef              Init;                         /*!< OPAMP required parameters */
132   HAL_StatusTypeDef              Status;                       /*!< OPAMP peripheral status   */
133   HAL_LockTypeDef                Lock;                         /*!< Locking object          */
134   __IO HAL_OPAMP_StateTypeDef    State;                        /*!< OPAMP communication state */
135 
136 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
137 void (* MspInitCallback)                (struct __OPAMP_HandleTypeDef *hopamp);
138 void (* MspDeInitCallback)              (struct __OPAMP_HandleTypeDef *hopamp);
139 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
140 } OPAMP_HandleTypeDef;
141 
142 /**
143   * @brief HAl_OPAMP_TrimmingValueTypeDef definition
144   */
145 
146 typedef  uint32_t HAL_OPAMP_TrimmingValueTypeDef;
147 
148 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
149 /**
150   * @brief  HAL OPAMP Callback ID enumeration definition
151   */
152 typedef enum
153 {
154   HAL_OPAMP_MSPINIT_CB_ID                     = 0x01U,  /*!< OPAMP MspInit Callback ID           */
155   HAL_OPAMP_MSPDEINIT_CB_ID                   = 0x02U,  /*!< OPAMP MspDeInit Callback ID         */
156   HAL_OPAMP_ALL_CB_ID                         = 0x03U   /*!< OPAMP All ID                        */
157 }HAL_OPAMP_CallbackIDTypeDef;
158 
159 /**
160   * @brief  HAL OPAMP Callback pointer definition
161   */
162 typedef void (*pOPAMP_CallbackTypeDef)(OPAMP_HandleTypeDef *hopamp);
163 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
164 /**
165   * @}
166   */
167 
168 /* Exported constants --------------------------------------------------------*/
169 /** @defgroup OPAMP_Exported_Constants OPAMP Exported Constants
170   * @{
171   */
172 
173 /** @defgroup OPAMP_Mode OPAMP Mode
174   * @{
175   */
176 #define OPAMP_STANDALONE_MODE             0x00000000U                                  /*!< standalone mode */
177 #define OPAMP_PGA_MODE                    OPAMP_CSR_VMSEL_1                            /*!< PGA mode */
178 #define OPAMP_FOLLOWER_MODE               (OPAMP_CSR_VMSEL_1 | OPAMP_CSR_VMSEL_0)      /*!< follower mode */
179 
180 /**
181   * @}
182   */
183 
184 /** @defgroup OPAMP_NonInvertingInput OPAMP Non Inverting Input
185   * @{
186   */
187 
188 #define OPAMP_NONINVERTINGINPUT_IO0         0x00000000U                /*!< OPAMP non-inverting input connected to dedicated IO pin */
189 #define OPAMP_NONINVERTINGINPUT_DAC_CH      OPAMP_CSR_VPSEL_0          /*!< OPAMP non-inverting input connected internally to DAC channel */
190 #if defined(DAC2)
191 #define OPAMP_NONINVERTINGINPUT_DAC2_CH     OPAMP_CSR_VPSEL_1         /*!< Only OPAMP2 non-inverting input connected internally to DAC2 channel */
192 #endif /* DAC2 */
193 
194 /**
195   * @}
196   */
197 
198 /** @defgroup OPAMP_InvertingInput OPAMP Inverting Input
199   * @{
200   */
201 
202 #define OPAMP_INVERTINGINPUT_IO0               0x00000000U                            /*!< OPAMP inverting input connected to dedicated IO pin */
203 #define OPAMP_INVERTINGINPUT_IO1               OPAMP_CSR_VMSEL_0                      /*!< OPAMP inverting input connected to dedicated IO pin */
204 
205 /**
206   * @}
207   */
208 
209 /** @defgroup OPAMP_PgaConnect OPAMP Pga Connect
210   * @{
211   */
212 
213 #define OPAMP_PGA_CONNECT_INVERTINGINPUT_NO                0x00000000U                                /*!< In PGA mode, the inverting input is not connected */
214 #define OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0               OPAMP_CSR_PGGAIN_2                         /*!< In PGA mode, the inverting input is connected to VINM0 */
215 #define OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_BIAS          OPAMP_CSR_PGGAIN_3                         /*!< In PGA mode, the inverting input is connected to VINM0 or bias */
216 #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 */
217 
218 
219 /**
220   * @}
221   */
222 
223 /** @defgroup OPAMP_PgaGain OPAMP Pga Gain
224   * @{
225   */
226 
227 #define OPAMP_PGA_GAIN_2_OR_MINUS_1               0x00000000U                                 /*!< PGA gain could be 2 or -1   */
228 #define OPAMP_PGA_GAIN_4_OR_MINUS_3               OPAMP_CSR_PGGAIN_0                          /*!< PGA gain could be 4 or -3   */
229 #define OPAMP_PGA_GAIN_8_OR_MINUS_7               OPAMP_CSR_PGGAIN_1                          /*!< PGA gain could be 8 or -7   */
230 #define OPAMP_PGA_GAIN_16_OR_MINUS_15             (OPAMP_CSR_PGGAIN_0 | OPAMP_CSR_PGGAIN_1)   /*!< PGA gain could be 16 or -15 */
231 
232 /**
233   * @}
234   */
235 
236 /** @defgroup OPAMP_PowerMode OPAMP PowerMode
237   * @{
238   */
239 #define OPAMP_POWERMODE_NORMAL         0x00000000U
240 #define OPAMP_POWERMODE_HIGHSPEED      OPAMP_CSR_OPAHSM
241 
242 /**
243   * @}
244   */
245 
246 
247 /** @defgroup OPAMP_VREF OPAMP VREF
248   * @{
249   */
250 
251 #define OPAMP_VREF_3VDDA                     0x00000000U                 /*!< OPAMP Vref = 3.3% VDDA */
252 #define OPAMP_VREF_10VDDA                    OPAMP_CSR_CALSEL_0          /*!< OPAMP Vref = 10% VDDA  */
253 #define OPAMP_VREF_50VDDA                    OPAMP_CSR_CALSEL_1          /*!< OPAMP Vref = 50% VDDA  */
254 #define OPAMP_VREF_90VDDA                    OPAMP_CSR_CALSEL            /*!< OPAMP Vref = 90% VDDA  */
255 
256 /**
257   * @}
258   */
259 
260 /** @defgroup OPAMP_UserTrimming OPAMP User Trimming
261   * @{
262   */
263 #define OPAMP_TRIMMING_FACTORY         0x00000000U                             /*!< Factory trimming */
264 #define OPAMP_TRIMMING_USER            OPAMP_CSR_USERTRIM                      /*!< User trimming */
265 
266 
267 /**
268   * @}
269   */
270 
271 /** @defgroup OPAMP_FactoryTrimming OPAMP Factory Trimming
272   * @{
273   */
274 #define OPAMP_FACTORYTRIMMING_DUMMY    0xFFFFFFFFU                          /*!< Dummy value if trimming value could not be retrieved */
275 
276 #define OPAMP_FACTORYTRIMMING_N        0x00000000U                          /*!< Offset trimming N */
277 #define OPAMP_FACTORYTRIMMING_P        0x00000001U                          /*!< Offset trimming P */
278 
279 /**
280   * @}
281   */
282 
283  /**
284   * @}
285   */
286 
287 /* Private constants ---------------------------------------------------------*/
288 /** @defgroup OPAMP_Private_Constants OPAMP Private Constants
289   * @brief   OPAMP Private constants and defines
290   * @{
291   */
292 
293 /* NONINVERTING bit position in OTR & HSOTR */
294 #define OPAMP_INPUT_NONINVERTING           (8U)  /*!< Non inverting input */
295 
296 /* Offset trimming time: during calibration, minimum time needed between two  */
297 /* steps to have 1 mV accuracy.                                               */
298 /* Refer to datasheet, electrical characteristics: parameter tOFFTRIM Typ=2ms.*/
299 /* Unit: ms.                                                                  */
300 #define OPAMP_TRIMMING_DELAY               (2U)
301 
302 /**
303   * @}
304   */
305 
306 /* Exported macros -----------------------------------------------------------*/
307 /** @defgroup OPAMP_Exported_Macros OPAMP Exported Macros
308   * @{
309   */
310 
311 /** @brief Reset OPAMP handle state.
312   * @param  __HANDLE__: OPAMP handle.
313   * @retval None
314   */
315 #define __HAL_OPAMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_OPAMP_STATE_RESET)
316 
317 /**
318   * @}
319   */
320 
321 /* Private macro -------------------------------------------------------------*/
322 
323 /** @defgroup OPAMP_Private_Macros OPAMP Private Macros
324   * @{
325   */
326 
327 #define IS_OPAMP_FUNCTIONAL_NORMALMODE(INPUT) (((INPUT) == OPAMP_STANDALONE_MODE) || \
328                                                ((INPUT) == OPAMP_PGA_MODE) || \
329                                                ((INPUT) == OPAMP_FOLLOWER_MODE))
330 
331 #define IS_OPAMP_INVERTING_INPUT_STANDALONE(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_IO0) || \
332                                                     ((INPUT) == OPAMP_INVERTINGINPUT_IO1))
333 
334 #if defined(DAC2)
335 #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \
336                                             ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH) || \
337                                             ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC2_CH))
338 #else
339 #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \
340                                             ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH))
341 #endif /* DAC2 */
342 
343 #define IS_OPAMP_PGACONNECT(CONNECT) (((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_NO)  || \
344                                       ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0) || \
345                                       ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_BIAS) || \
346                                       ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_IO1_BIAS))
347 
348 #define IS_OPAMP_PGA_GAIN(GAIN) (((GAIN) == OPAMP_PGA_GAIN_2_OR_MINUS_1) || \
349                                  ((GAIN) == OPAMP_PGA_GAIN_4_OR_MINUS_3) || \
350                                  ((GAIN) == OPAMP_PGA_GAIN_8_OR_MINUS_7) || \
351                                  ((GAIN) == OPAMP_PGA_GAIN_16_OR_MINUS_15))
352 
353 
354 #define IS_OPAMP_VREF(VREF) (((VREF) == OPAMP_VREF_3VDDA)  || \
355                              ((VREF) == OPAMP_VREF_10VDDA) || \
356                              ((VREF) == OPAMP_VREF_50VDDA) || \
357                              ((VREF) == OPAMP_VREF_90VDDA))
358 
359 #define IS_OPAMP_POWERMODE(TRIMMING) (((TRIMMING) == OPAMP_POWERMODE_NORMAL) || \
360                                       ((TRIMMING) == OPAMP_POWERMODE_HIGHSPEED) )
361 
362 
363 #define IS_OPAMP_TRIMMING(TRIMMING) (((TRIMMING) == OPAMP_TRIMMING_FACTORY) || \
364                                      ((TRIMMING) == OPAMP_TRIMMING_USER))
365 
366 
367 #define IS_OPAMP_TRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 0x1FU)
368 
369 #define IS_OPAMP_FACTORYTRIMMING(TRIMMING) (((TRIMMING) == OPAMP_FACTORYTRIMMING_N) || \
370                                              ((TRIMMING) == OPAMP_FACTORYTRIMMING_P))
371 
372 /**
373   * @}
374   */
375 
376 /* Include OPAMP HAL Extended module */
377 #include "stm32h7xx_hal_opamp_ex.h"
378 
379 /* Exported functions --------------------------------------------------------*/
380 /** @addtogroup OPAMP_Exported_Functions
381   * @{
382   */
383 
384 /** @addtogroup OPAMP_Exported_Functions_Group1
385   * @{
386   */
387 /* Initialization/de-initialization functions  **********************************/
388 HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef *hopamp);
389 HAL_StatusTypeDef HAL_OPAMP_DeInit (OPAMP_HandleTypeDef *hopamp);
390 void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef *hopamp);
391 void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef *hopamp);
392 /**
393   * @}
394   */
395 
396 /** @addtogroup OPAMP_Exported_Functions_Group2
397   * @{
398   */
399 
400 /* I/O operation functions  *****************************************************/
401 HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef *hopamp);
402 HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef *hopamp);
403 HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef *hopamp);
404 
405 /**
406   * @}
407   */
408 
409 /** @addtogroup OPAMP_Exported_Functions_Group3
410   * @{
411   */
412 
413 /* Peripheral Control functions  ************************************************/
414 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
415 /* OPAMP callback registering/unregistering */
416 HAL_StatusTypeDef HAL_OPAMP_RegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackId, pOPAMP_CallbackTypeDef pCallback);
417 HAL_StatusTypeDef HAL_OPAMP_UnRegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackId);
418 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
419 HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef *hopamp);
420 HAL_OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset);
421 
422 /**
423   * @}
424   */
425 
426 /** @addtogroup OPAMP_Exported_Functions_Group4
427   * @{
428   */
429 
430 /* Peripheral State functions  **************************************************/
431 HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(OPAMP_HandleTypeDef *hopamp);
432 
433 /**
434   * @}
435   */
436 
437 /**
438   * @}
439   */
440 
441 /**
442   * @}
443   */
444 
445 /**
446   * @}
447   */
448 
449 #ifdef __cplusplus
450 }
451 #endif
452 
453 #endif /* STM32H7xx_HAL_OPAMP_H */
454 
455