1 /**
2   ******************************************************************************
3   * @file    stm32f30x_opamp.h
4   * @author  MCD Application Team
5   * @version V1.2.3
6   * @date    10-July-2015
7   * @brief   This file contains all the functions prototypes for the operational
8   *          amplifiers (OPAMP) firmware library.
9   ******************************************************************************
10   * @attention
11   *
12   * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
13   *
14   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
15   * You may not use this file except in compliance with the License.
16   * You may obtain a copy of the License at:
17   *
18   *        http://www.st.com/software_license_agreement_liberty_v2
19   *
20   * Unless required by applicable law or agreed to in writing, software
21   * distributed under the License is distributed on an "AS IS" BASIS,
22   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23   * See the License for the specific language governing permissions and
24   * limitations under the License.
25   *
26   ******************************************************************************
27   */
28 
29 /* Define to prevent recursive inclusion -------------------------------------*/
30 #ifndef __STM32F30x_OPAMP_H
31 #define __STM32F30x_OPAMP_H
32 
33 #ifdef __cplusplus
34  extern "C" {
35 #endif
36 
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f30x.h"
39 
40 /** @addtogroup STM32F30x_StdPeriph_Driver
41   * @{
42   */
43 
44 /** @addtogroup OPAMP
45   * @{
46   */
47 
48 /* Exported types ------------------------------------------------------------*/
49 
50 /**
51   * @brief  OPAMP Init structure definition
52   */
53 
54 typedef struct
55 {
56 
57   uint32_t OPAMP_InvertingInput;     /*!< Selects the inverting input of the operational amplifier.
58                                           This parameter can be a value of @ref OPAMP_InvertingInput */
59 
60   uint32_t OPAMP_NonInvertingInput;  /*!< Selects the non inverting input of the operational amplifier.
61                                          This parameter can be a value of @ref OPAMP_NonInvertingInput */
62 
63 }OPAMP_InitTypeDef;
64 
65 /* Exported constants --------------------------------------------------------*/
66 
67 /** @defgroup OPAMP_Exported_Constants
68   * @{
69   */
70 
71 /** @defgroup OPAMP_Selection
72   * @{
73   */
74 
75 #define OPAMP_Selection_OPAMP1                    ((uint32_t)0x00000000) /*!< OPAMP1 Selection */
76 #define OPAMP_Selection_OPAMP2                    ((uint32_t)0x00000004) /*!< OPAMP2 Selection */
77 #define OPAMP_Selection_OPAMP3                    ((uint32_t)0x00000008) /*!< OPAMP3 Selection */
78 #define OPAMP_Selection_OPAMP4                    ((uint32_t)0x0000000C) /*!< OPAMP4 Selection */
79 
80 #define IS_OPAMP_ALL_PERIPH(PERIPH) (((PERIPH) == OPAMP_Selection_OPAMP1) || \
81                                      ((PERIPH) == OPAMP_Selection_OPAMP2) || \
82                                      ((PERIPH) == OPAMP_Selection_OPAMP3) || \
83                                      ((PERIPH) == OPAMP_Selection_OPAMP4))
84 
85 /**
86   * @}
87   */
88 
89 /** @defgroup OPAMP_InvertingInput
90   * @{
91   */
92 
93 #define OPAMP_InvertingInput_IO1          ((uint32_t)0x00000000) /*!< IO1 (PC5 for OPAMP1 and OPAMP2, PB10 for OPAMP3 and OPAMP4)
94                                                                      connected to OPAMPx inverting input */
95 #define OPAMP_InvertingInput_IO2          OPAMP_CSR_VMSEL_0      /*!< IO2 (PA3 for OPAMP1, PA5 for OPAMP2, PB2 for OPAMP3, PD8 for OPAMP4)
96                                                                       connected to OPAMPx inverting input */
97 #define OPAMP_InvertingInput_PGA          OPAMP_CSR_VMSEL_1      /*!< Resistor feedback output connected to OPAMPx inverting input (PGA mode) */
98 #define OPAMP_InvertingInput_Vout         OPAMP_CSR_VMSEL        /*!< Vout connected to OPAMPx inverting input (follower mode) */
99 
100 #define IS_OPAMP_INVERTING_INPUT(INPUT) (((INPUT) == OPAMP_InvertingInput_IO1) || \
101                                          ((INPUT) == OPAMP_InvertingInput_IO2) || \
102                                          ((INPUT) == OPAMP_InvertingInput_PGA) || \
103                                          ((INPUT) == OPAMP_InvertingInput_Vout))
104 /**
105   * @}
106   */
107 
108 /** @defgroup OPAMP_NonInvertingInput
109   * @{
110   */
111 
112 #define OPAMP_NonInvertingInput_IO1          ((uint32_t)0x00000000) /*!< IO1 (PA7 for OPAMP1, PD14 for OPAMP2, PB13 for OPAMP3, PD11 for OPAMP4)
113                                                                         connected to OPAMPx non inverting input */
114 #define OPAMP_NonInvertingInput_IO2          OPAMP_CSR_VPSEL_0      /*!< IO2 (PA5 for OPAMP1, PB14 for OPAMP2, PA5 for OPAMP3, PB11 for OPAMP4)
115                                                                          connected to OPAMPx non inverting input */
116 #define OPAMP_NonInvertingInput_IO3          OPAMP_CSR_VPSEL_1      /*!< IO3 (PA3 for OPAMP1, PB0 for OPAMP2, PA1 for OPAMP3, PA4 for OPAMP4)
117                                                                          connected to OPAMPx non inverting input */
118 #define OPAMP_NonInvertingInput_IO4          OPAMP_CSR_VPSEL        /*!< IO4 (PA1 for OPAMP1, PA7 for OPAMP2, PB0 for OPAMP3, PB13 for OPAMP4)
119                                                                          connected to OPAMPx non inverting input */
120 
121 #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NonInvertingInput_IO1) || \
122                                             ((INPUT) == OPAMP_NonInvertingInput_IO2) || \
123                                             ((INPUT) == OPAMP_NonInvertingInput_IO3) || \
124                                             ((INPUT) == OPAMP_NonInvertingInput_IO4))
125 /**
126   * @}
127   */
128 
129 /** @defgroup OPAMP_PGAGain_Config
130   * @{
131   */
132 
133 #define OPAMP_OPAMP_PGAGain_2                ((uint32_t)0x00000000)
134 #define OPAMP_OPAMP_PGAGain_4                OPAMP_CSR_PGGAIN_0
135 #define OPAMP_OPAMP_PGAGain_8                OPAMP_CSR_PGGAIN_1
136 #define OPAMP_OPAMP_PGAGain_16               ((uint32_t)0x0000C000)
137 
138 #define IS_OPAMP_PGAGAIN(GAIN) (((GAIN) == OPAMP_OPAMP_PGAGain_2) || \
139                                 ((GAIN) == OPAMP_OPAMP_PGAGain_4) || \
140                                 ((GAIN) == OPAMP_OPAMP_PGAGain_8) || \
141                                 ((GAIN) == OPAMP_OPAMP_PGAGain_16))
142 /**
143   * @}
144   */
145 
146 /** @defgroup OPAMP_PGAConnect_Config
147   * @{
148   */
149 
150 #define OPAMP_PGAConnect_No                ((uint32_t)0x00000000)
151 #define OPAMP_PGAConnect_IO1               OPAMP_CSR_PGGAIN_3
152 #define OPAMP_PGAConnect_IO2               ((uint32_t)0x00030000)
153 
154 #define IS_OPAMP_PGACONNECT(CONNECT) (((CONNECT) == OPAMP_PGAConnect_No)  || \
155                                       ((CONNECT) == OPAMP_PGAConnect_IO1) || \
156                                       ((CONNECT) == OPAMP_PGAConnect_IO2))
157 /**
158   * @}
159   */
160 
161 /** @defgroup OPAMP_SecondaryInvertingInput
162   * @{
163   */
164 
165 #define IS_OPAMP_SECONDARY_INVINPUT(INVINPUT) (((INVINPUT) == OPAMP_InvertingInput_IO1) || \
166                                                ((INVINPUT) == OPAMP_InvertingInput_IO2))
167 /**
168   * @}
169   */
170 
171 /** @defgroup OPAMP_Input
172   * @{
173   */
174 
175 #define OPAMP_Input_Inverting                 ((uint32_t)0x00000018) /*!< Inverting input */
176 #define OPAMP_Input_NonInverting              ((uint32_t)0x00000013) /*!< Non inverting input */
177 
178 #define IS_OPAMP_INPUT(INPUT) (((INPUT) == OPAMP_Input_Inverting) || \
179                                ((INPUT) == OPAMP_Input_NonInverting))
180 
181 /**
182   * @}
183   */
184 
185 /** @defgroup OPAMP_Vref
186   * @{
187   */
188 
189 #define OPAMP_Vref_3VDDA                    ((uint32_t)0x00000000) /*!< OPMAP Vref = 3.3% VDDA */
190 #define OPAMP_Vref_10VDDA                    OPAMP_CSR_CALSEL_0     /*!< OPMAP Vref = 10% VDDA  */
191 #define OPAMP_Vref_50VDDA                    OPAMP_CSR_CALSEL_1     /*!< OPMAP Vref = 50% VDDA  */
192 #define OPAMP_Vref_90VDDA                    OPAMP_CSR_CALSEL       /*!< OPMAP Vref = 90% VDDA  */
193 
194 #define IS_OPAMP_VREF(VREF) (((VREF) == OPAMP_Vref_3VDDA)  || \
195                              ((VREF) == OPAMP_Vref_10VDDA) || \
196                              ((VREF) == OPAMP_Vref_50VDDA) || \
197                              ((VREF) == OPAMP_Vref_90VDDA))
198 
199 /**
200   * @}
201   */
202 
203 /** @defgroup OPAMP_Trimming
204   */
205 
206 #define OPAMP_Trimming_Factory        ((uint32_t)0x00000000) /*!< Factory trimming */
207 #define OPAMP_Trimming_User           OPAMP_CSR_USERTRIM     /*!< User trimming */
208 
209 #define IS_OPAMP_TRIMMING(TRIMMING) (((TRIMMING) == OPAMP_Trimming_Factory) || \
210                                      ((TRIMMING) == OPAMP_Trimming_User))
211 
212 /**
213   * @}
214   */
215 
216 /** @defgroup OPAMP_TrimValue
217   * @{
218   */
219 
220 #define IS_OPAMP_TRIMMINGVALUE(VALUE) ((VALUE) <= 0x0000001F) /*!< Trimming value */
221 
222 /**
223   * @}
224   */
225 
226 /** @defgroup OPAMP_OutputLevel
227   * @{
228   */
229 
230 #define OPAMP_OutputLevel_High                   OPAMP_CSR_OUTCAL
231 #define OPAMP_OutputLevel_Low                    ((uint32_t)0x00000000)
232 
233 /**
234   * @}
235   */
236 
237 /* Exported macro ------------------------------------------------------------*/
238 /* Exported functions ------------------------------------------------------- */
239 
240 /*  Function used to set the OPAMP configuration to the default reset state ***/
241 void OPAMP_DeInit(uint32_t OPAMP_Selection);
242 
243 /* Initialization and Configuration functions *********************************/
244 void OPAMP_Init(uint32_t OPAMP_Selection, OPAMP_InitTypeDef* OPAMP_InitStruct);
245 void OPAMP_StructInit(OPAMP_InitTypeDef* OPAMP_InitStruct);
246 void OPAMP_PGAConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_PGAGain, uint32_t OPAMP_PGAConnect);
247 void OPAMP_VrefConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_Vref);
248 void OPAMP_VrefConnectADCCmd(uint32_t OPAMP_Selection, FunctionalState NewState);
249 void OPAMP_TimerControlledMuxConfig(uint32_t OPAMP_Selection, OPAMP_InitTypeDef* OPAMP_InitStruct);
250 void OPAMP_TimerControlledMuxCmd(uint32_t OPAMP_Selection, FunctionalState NewState);
251 void OPAMP_Cmd(uint32_t OPAMP_Selection, FunctionalState NewState);
252 uint32_t OPAMP_GetOutputLevel(uint32_t OPAMP_Selection);
253 
254 /* Calibration functions ******************************************************/
255 void OPAMP_VrefConnectNonInvertingInput(uint32_t OPAMP_Selection, FunctionalState NewState);
256 void OPAMP_OffsetTrimModeSelect(uint32_t OPAMP_Selection, uint32_t OPAMP_Trimming);
257 void OPAMP_OffsetTrimConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_Input, uint32_t OPAMP_TrimValue);
258 void OPAMP_StartCalibration(uint32_t OPAMP_Selection, FunctionalState NewState);
259 
260 /* OPAMP configuration locking function ***************************************/
261 void OPAMP_LockConfig(uint32_t OPAMP_Selection);
262 
263 #ifdef __cplusplus
264 }
265 #endif
266 
267 #endif /*__STM32F30x_OPAMP_H */
268 
269 /**
270   * @}
271   */
272 
273 /**
274   * @}
275   */
276 
277 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
278