1 /**************************************************************************//**
2  * @file
3  * @brief Operational Amplifier (OPAMP) peripheral API
4  * @author Energy Micro AS
5  * @version 3.0.0
6  ******************************************************************************
7  * @section License
8  * <b>(C) Copyright 2012 Energy Micro AS, http://www.energymicro.com</b>
9  *******************************************************************************
10  *
11  * Permission is granted to anyone to use this software for any purpose,
12  * including commercial applications, and to alter it and redistribute it
13  * freely, subject to the following restrictions:
14  *
15  * 1. The origin of this software must not be misrepresented; you must not
16  *    claim that you wrote the original software.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  *    misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  *
21  * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
22  * obligation to support this Software. Energy Micro AS is providing the
23  * Software "AS IS", with no express or implied warranties of any kind,
24  * including, but not limited to, any implied warranties of merchantability
25  * or fitness for any particular purpose or warranties against infringement
26  * of any proprietary rights of a third party.
27  *
28  * Energy Micro AS will not be liable for any consequential, incidental, or
29  * special damages, or any other relief, or for any claim by any third party,
30  * arising from your use of this Software.
31  *
32  *****************************************************************************/
33 #ifndef __EM_OPAMP_H
34 #define __EM_OPAMP_H
35 
36 #include "em_part.h"
37 #if defined(OPAMP_PRESENT) && (OPAMP_COUNT == 1)
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 #include <stdint.h>
44 #include <stdbool.h>
45 #include "em_dac.h"
46 
47 /***************************************************************************//**
48  * @addtogroup EM_Library
49  * @{
50  ******************************************************************************/
51 
52 /***************************************************************************//**
53  * @addtogroup OPAMP
54  * @{
55  ******************************************************************************/
56 
57 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
58 
59 /** Validation of DAC OPA number for assert statements. */
60 #define DAC_OPA_VALID(opa)    ((opa) <= OPA2)
61 
62 /** @endcond */
63 
64 /*******************************************************************************
65  ********************************   ENUMS   ************************************
66  ******************************************************************************/
67 
68 /** OPAMP selector values. */
69 typedef enum
70 {
71   OPA0 = 0,                   /**< Select OPA0. */
72   OPA1 = 1,                   /**< Select OPA1. */
73   OPA2 = 2                    /**< Select OPA2. */
74 } OPAMP_TypeDef;
75 
76 /** OPAMP negative terminal input selection values. */
77 typedef enum
78 {
79   opaNegSelDisable   = DAC_OPA0MUX_NEGSEL_DISABLE,    /**< Input disabled.               */
80   opaNegSelUnityGain = DAC_OPA0MUX_NEGSEL_UG,         /**< Unity gain feedback path.     */
81   opaNegSelResTap    = DAC_OPA0MUX_NEGSEL_OPATAP,     /**< Feedback resistor ladder tap. */
82   opaNegSelNegPad    = DAC_OPA0MUX_NEGSEL_NEGPAD      /**< Negative pad as input.        */
83 } OPAMP_NegSel_TypeDef;
84 
85 /** OPAMP positive terminal input selection values. */
86 typedef enum
87 {
88   opaPosSelDisable    = DAC_OPA0MUX_POSSEL_DISABLE,   /**< Input disabled.          */
89   opaPosSelDac        = DAC_OPA0MUX_POSSEL_DAC,       /**< DAC as input (not OPA2). */
90   opaPosSelPosPad     = DAC_OPA0MUX_POSSEL_POSPAD,    /**< Positive pad as input.   */
91   opaPosSelOpaIn      = DAC_OPA0MUX_POSSEL_OPA0INP,   /**< Input from OPAx.         */
92   opaPosSelResTapOpa0 = DAC_OPA0MUX_POSSEL_OPATAP     /**< Feedback resistor ladder tap from OPA0. */
93 } OPAMP_PosSel_TypeDef;
94 
95 /** OPAMP output terminal selection values. */
96 typedef enum
97 {
98   opaOutModeDisable = DAC_OPA0MUX_OUTMODE_DISABLE,    /**< OPA output disabled.        */
99   opaOutModeMain    = DAC_OPA0MUX_OUTMODE_MAIN,       /**< Main output to pin enabled. */
100   opaOutModeAlt     = DAC_OPA0MUX_OUTMODE_ALT,        /**< Alternate output(s) enabled (not OPA2).     */
101   opaOutModeAll     = DAC_OPA0MUX_OUTMODE_ALL         /**< Both main and alternate enabled (not OPA2). */
102 } OPAMP_OutMode_TypeDef;
103 
104 /** OPAMP gain values. */
105 typedef enum
106 {
107   opaResSelDefault    = DAC_OPA0MUX_RESSEL_DEFAULT,  /**< Default value when resistor ladder is unused. */
108   opaResSelR2eq0_33R1 = DAC_OPA0MUX_RESSEL_RES0,     /**< R2 = 0.33 * R1 */
109   opaResSelR2eqR1     = DAC_OPA0MUX_RESSEL_RES1,     /**< R2 = R1        */
110   opaResSelR1eq1_67R1 = DAC_OPA0MUX_RESSEL_RES2,     /**< R2 = 1.67 R1   */
111   opaResSelR2eq2R1    = DAC_OPA0MUX_RESSEL_RES3,     /**< R2 = 2 * R1    */
112   opaResSelR2eq3R1    = DAC_OPA0MUX_RESSEL_RES4,     /**< R2 = 3 * R1    */
113   opaResSelR2eq4_33R1 = DAC_OPA0MUX_RESSEL_RES5,     /**< R2 = 4.33 * R1 */
114   opaResSelR2eq7R1    = DAC_OPA0MUX_RESSEL_RES6,     /**< R2 = 7 * R1    */
115   opaResSelR2eq15R1   = DAC_OPA0MUX_RESSEL_RES7      /**< R2 = 15 * R1   */
116 } OPAMP_ResSel_TypeDef;
117 
118 /** OPAMP resistor ladder input selector values. */
119 typedef enum
120 {
121   opaResInMuxDisable = DAC_OPA0MUX_RESINMUX_DISABLE,   /**< Resistor ladder disabled. */
122   opaResInMuxOpaIn   = DAC_OPA0MUX_RESINMUX_OPA0INP,   /**< Input from OPAx.          */
123   opaResInMuxNegPad  = DAC_OPA0MUX_RESINMUX_NEGPAD,    /**< Input from negative pad.  */
124   opaResInMuxPosPad  = DAC_OPA0MUX_RESINMUX_POSPAD,    /**< Input from positive pad.  */
125   opaResInMuxVss     = DAC_OPA0MUX_RESINMUX_VSS        /**< Input connected to Vss.   */
126 } OPAMP_ResInMux_TypeDef;
127 
128 /*******************************************************************************
129  *******************************   STRUCTS   ***********************************
130  ******************************************************************************/
131 
132 /** OPAMP init structure. */
133 typedef struct
134 {
135   OPAMP_NegSel_TypeDef   negSel;              /**< Select input source for negative terminal.    */
136   OPAMP_PosSel_TypeDef   posSel;              /**< Select input source for positive terminal.    */
137   OPAMP_OutMode_TypeDef  outMode;             /**< Output terminal connection.                   */
138   OPAMP_ResSel_TypeDef   resSel;              /**< Select R2/R1 resistor ratio.                  */
139   OPAMP_ResInMux_TypeDef resInMux;            /**< Select input source for resistor ladder.      */
140   uint32_t               outPen;              /**< Select alternate output terminal connections. */
141   uint32_t               bias;                /**< Set OPAMP bias current.                       */
142   bool                   halfBias;            /**< Divide OPAMP bias current by 2.               */
143   bool                   lpfPosPadDisable;    /**< Disable low pass filter on positive pad.      */
144   bool                   lpfNegPadDisable;    /**< Disable low pass filter on negative pad.      */
145   bool                   nextOut;             /**< Enable NEXTOUT signal source.                 */
146   bool                   npEn;                /**< Enable positive pad.                          */
147   bool                   ppEn;                /**< Enable negative pad.                          */
148   bool                   shortInputs;         /**< Short OPAMP input terminals.                  */
149   bool                   hcmDisable;          /**< Disable input rail-to-rail capability.        */
150   bool                   defaultOffset;       /**< Use factory calibrated opamp offset value.    */
151   uint32_t               offset;              /**< Opamp offset value when @ref defaultOffset is false.*/
152 } OPAMP_Init_TypeDef;
153 
154 /** Configuration of OPA0/1 in unity gain voltage follower mode.       */
155 #define OPA_INIT_UNITY_GAIN                                                       \
156   {                                                                               \
157     opaNegSelUnityGain,             /* Unity gain.                             */ \
158     opaPosSelPosPad,                /* Pos input from pad.                     */ \
159     opaOutModeMain,                 /* Main output enabled.                    */ \
160     opaResSelDefault,               /* Resistor ladder is not used.            */ \
161     opaResInMuxDisable,             /* Resistor ladder disabled.               */ \
162     0,                              /* No alternate outputs enabled.           */ \
163     _DAC_BIASPROG_BIASPROG_DEFAULT, /* Default bias setting.             */       \
164     _DAC_BIASPROG_HALFBIAS_DEFAULT, /* Default half-bias setting.        */       \
165     false,                          /* No low pass filter on pos pad.          */ \
166     false,                          /* No low pass filter on neg pad.          */ \
167     false,                          /* No nextout output enabled.              */ \
168     false,                          /* Neg pad disabled.                       */ \
169     true,                           /* Pos pad enabled, used as signal input.  */ \
170     false,                          /* No shorting of inputs.                  */ \
171     false,                          /* Rail-to-rail input enabled.             */ \
172     true,                           /* Use factory calibrated opamp offset.    */ \
173     0                               /* Opamp offset value (not used).          */ \
174   }
175 
176 /** Configuration of OPA2 in unity gain voltage follower mode.         */
177 #define OPA_INIT_UNITY_GAIN_OPA2                                                  \
178   {                                                                               \
179     opaNegSelUnityGain,             /* Unity gain.                             */ \
180     opaPosSelPosPad,                /* Pos input from pad.                     */ \
181     opaOutModeMain,                 /* Main output enabled.                    */ \
182     opaResSelDefault,               /* Resistor ladder is not used.            */ \
183     opaResInMuxDisable,             /* Resistor ladder disabled.               */ \
184     DAC_OPA0MUX_OUTPEN_OUT0,        /* Alternate output 0 enabled.             */ \
185     _DAC_BIASPROG_BIASPROG_DEFAULT, /* Default bias setting.             */       \
186     _DAC_BIASPROG_HALFBIAS_DEFAULT, /* Default half-bias setting.        */       \
187     false,                          /* No low pass filter on pos pad.          */ \
188     false,                          /* No low pass filter on neg pad.          */ \
189     false,                          /* No nextout output enabled.              */ \
190     false,                          /* Neg pad disabled.                       */ \
191     true,                           /* Pos pad enabled, used as signal input.  */ \
192     false,                          /* No shorting of inputs.                  */ \
193     false,                          /* Rail-to-rail input enabled.             */ \
194     true,                           /* Use factory calibrated opamp offset.    */ \
195     0                               /* Opamp offset value (not used).          */ \
196   }
197 
198 /** Configuration of OPA0/1 in non-inverting amplifier mode.           */
199 #define OPA_INIT_NON_INVERTING                                                    \
200   {                                                                               \
201     opaNegSelResTap,                /* Neg input from resistor ladder tap.     */ \
202     opaPosSelPosPad,                /* Pos input from pad.                     */ \
203     opaOutModeMain,                 /* Main output enabled.                    */ \
204     opaResSelR2eq0_33R1,            /* R2 = 1/3 R1                             */ \
205     opaResInMuxNegPad,              /* Resistor ladder input from neg pad.     */ \
206     0,                              /* No alternate outputs enabled.           */ \
207     _DAC_BIASPROG_BIASPROG_DEFAULT, /* Default bias setting.             */       \
208     _DAC_BIASPROG_HALFBIAS_DEFAULT, /* Default half-bias setting.        */       \
209     false,                          /* No low pass filter on pos pad.          */ \
210     false,                          /* No low pass filter on neg pad.          */ \
211     false,                          /* No nextout output enabled.              */ \
212     true,                           /* Neg pad enabled, used as signal ground. */ \
213     true,                           /* Pos pad enabled, used as signal input.  */ \
214     false,                          /* No shorting of inputs.                  */ \
215     false,                          /* Rail-to-rail input enabled.             */ \
216     true,                           /* Use factory calibrated opamp offset.    */ \
217     0                               /* Opamp offset value (not used).          */ \
218   }
219 
220 /** Configuration of OPA2 in non-inverting amplifier mode.             */
221 #define OPA_INIT_NON_INVERTING_OPA2                                               \
222   {                                                                               \
223     opaNegSelResTap,                /* Neg input from resistor ladder tap.     */ \
224     opaPosSelPosPad,                /* Pos input from pad.                     */ \
225     opaOutModeMain,                 /* Main output enabled.                    */ \
226     opaResSelR2eq0_33R1,            /* R2 = 1/3 R1                             */ \
227     opaResInMuxNegPad,              /* Resistor ladder input from neg pad.     */ \
228     DAC_OPA0MUX_OUTPEN_OUT0,        /* Alternate output 0 enabled.             */ \
229     _DAC_BIASPROG_BIASPROG_DEFAULT, /* Default bias setting.             */       \
230     _DAC_BIASPROG_HALFBIAS_DEFAULT, /* Default half-bias setting.        */       \
231     false,                          /* No low pass filter on pos pad.          */ \
232     false,                          /* No low pass filter on neg pad.          */ \
233     false,                          /* No nextout output enabled.              */ \
234     true,                           /* Neg pad enabled, used as signal ground. */ \
235     true,                           /* Pos pad enabled, used as signal input.  */ \
236     false,                          /* No shorting of inputs.                  */ \
237     false,                          /* Rail-to-rail input enabled.             */ \
238     true,                           /* Use factory calibrated opamp offset.    */ \
239     0                               /* Opamp offset value (not used).          */ \
240   }
241 
242 /** Configuration of OPA0/1 in inverting amplifier mode.               */
243 #define OPA_INIT_INVERTING                                                        \
244   {                                                                               \
245     opaNegSelResTap,                /* Neg input from resistor ladder tap.     */ \
246     opaPosSelPosPad,                /* Pos input from pad.                     */ \
247     opaOutModeMain,                 /* Main output enabled.                    */ \
248     opaResSelR2eqR1,                /* R2 = R1                                 */ \
249     opaResInMuxNegPad,              /* Resistor ladder input from neg pad.     */ \
250     0,                              /* No alternate outputs enabled.           */ \
251     _DAC_BIASPROG_BIASPROG_DEFAULT, /* Default bias setting.             */       \
252     _DAC_BIASPROG_HALFBIAS_DEFAULT, /* Default half-bias setting.        */       \
253     false,                          /* No low pass filter on pos pad.          */ \
254     false,                          /* No low pass filter on neg pad.          */ \
255     false,                          /* No nextout output enabled.              */ \
256     true,                           /* Neg pad enabled, used as signal input.  */ \
257     true,                           /* Pos pad enabled, used as signal ground. */ \
258     false,                          /* No shorting of inputs.                  */ \
259     false,                          /* Rail-to-rail input enabled.             */ \
260     true,                           /* Use factory calibrated opamp offset.    */ \
261     0                               /* Opamp offset value (not used).          */ \
262   }
263 
264 /** Configuration of OPA2 in inverting amplifier mode.                 */
265 #define OPA_INIT_INVERTING_OPA2                                                   \
266   {                                                                               \
267     opaNegSelResTap,                /* Neg input from resistor ladder tap.     */ \
268     opaPosSelPosPad,                /* Pos input from pad.                     */ \
269     opaOutModeMain,                 /* Main output enabled.                    */ \
270     opaResSelR2eqR1,                /* R2 = R1                                 */ \
271     opaResInMuxNegPad,              /* Resistor ladder input from neg pad.     */ \
272     DAC_OPA0MUX_OUTPEN_OUT0,        /* Alternate output 0 enabled.             */ \
273     _DAC_BIASPROG_BIASPROG_DEFAULT, /* Default bias setting.             */       \
274     _DAC_BIASPROG_HALFBIAS_DEFAULT, /* Default half-bias setting.        */       \
275     false,                          /* No low pass filter on pos pad.          */ \
276     false,                          /* No low pass filter on neg pad.          */ \
277     false,                          /* No nextout output enabled.              */ \
278     true,                           /* Neg pad enabled, used as signal input.  */ \
279     true,                           /* Pos pad enabled, used as signal ground. */ \
280     false,                          /* No shorting of inputs.                  */ \
281     false,                          /* Rail-to-rail input enabled.             */ \
282     true,                           /* Use factory calibrated opamp offset.    */ \
283     0                               /* Opamp offset value (not used).          */ \
284   }
285 
286 /** Configuration of OPA0 in cascaded non-inverting amplifier mode.    */
287 #define OPA_INIT_CASCADED_NON_INVERTING_OPA0                                      \
288   {                                                                               \
289     opaNegSelResTap,                /* Neg input from resistor ladder tap.     */ \
290     opaPosSelPosPad,                /* Pos input from pad.                     */ \
291     opaOutModeAll,                  /* Both main and alternate outputs.        */ \
292     opaResSelR2eq0_33R1,            /* R2 = 1/3 R1                             */ \
293     opaResInMuxNegPad,              /* Resistor ladder input from neg pad.     */ \
294     0,                              /* No alternate outputs enabled.           */ \
295     _DAC_BIASPROG_BIASPROG_DEFAULT, /* Default bias setting.             */       \
296     _DAC_BIASPROG_HALFBIAS_DEFAULT, /* Default half-bias setting.        */       \
297     false,                          /* No low pass filter on pos pad.          */ \
298     false,                          /* No low pass filter on neg pad.          */ \
299     true,                           /* Pass output to next stage (OPA1).       */ \
300     true,                           /* Neg pad enabled, used as signal ground. */ \
301     true,                           /* Pos pad enabled, used as signal input.  */ \
302     false,                          /* No shorting of inputs.                  */ \
303     false,                          /* Rail-to-rail input enabled.             */ \
304     true,                           /* Use factory calibrated opamp offset.    */ \
305     0                               /* Opamp offset value (not used).          */ \
306   }
307 
308 /** Configuration of OPA1 in cascaded non-inverting amplifier mode.    */
309 #define OPA_INIT_CASCADED_NON_INVERTING_OPA1                                      \
310   {                                                                               \
311     opaNegSelResTap,                /* Neg input from resistor ladder tap.     */ \
312     opaPosSelOpaIn,                 /* Pos input from OPA0 output.             */ \
313     opaOutModeAll,                  /* Both main and alternate outputs.        */ \
314     opaResSelR2eq0_33R1,            /* R2 = 1/3 R1                             */ \
315     opaResInMuxNegPad,              /* Resistor ladder input from neg pad.     */ \
316     0,                              /* No alternate outputs enabled.           */ \
317     _DAC_BIASPROG_BIASPROG_DEFAULT, /* Default bias setting.             */       \
318     _DAC_BIASPROG_HALFBIAS_DEFAULT, /* Default half-bias setting.        */       \
319     false,                          /* No low pass filter on pos pad.          */ \
320     false,                          /* No low pass filter on neg pad.          */ \
321     true,                           /* Pass output to next stage (OPA2).       */ \
322     true,                           /* Neg pad enabled, used as signal ground. */ \
323     false,                          /* Pos pad disabled.                       */ \
324     false,                          /* No shorting of inputs.                  */ \
325     false,                          /* Rail-to-rail input enabled.             */ \
326     true,                           /* Use factory calibrated opamp offset.    */ \
327     0                               /* Opamp offset value (not used).          */ \
328   }
329 
330 /** Configuration of OPA2 in cascaded non-inverting amplifier mode.    */
331 #define OPA_INIT_CASCADED_NON_INVERTING_OPA2                                      \
332   {                                                                               \
333     opaNegSelResTap,                /* Neg input from resistor ladder tap.     */ \
334     opaPosSelOpaIn,                 /* Pos input from OPA1 output.             */ \
335     opaOutModeMain,                 /* Main output enabled.                    */ \
336     opaResSelR2eq0_33R1,            /* R2 = 1/3 R1                             */ \
337     opaResInMuxNegPad,              /* Resistor ladder input from neg pad.     */ \
338     DAC_OPA0MUX_OUTPEN_OUT0,        /* Alternate output 0 enabled.             */ \
339     _DAC_BIASPROG_BIASPROG_DEFAULT, /* Default bias setting.             */       \
340     _DAC_BIASPROG_HALFBIAS_DEFAULT, /* Default half-bias setting.        */       \
341     false,                          /* No low pass filter on pos pad.          */ \
342     false,                          /* No low pass filter on neg pad.          */ \
343     false,                          /* No nextout output enabled.              */ \
344     true,                           /* Neg pad enabled, used as signal ground. */ \
345     false,                          /* Pos pad disabled.                       */ \
346     false,                          /* No shorting of inputs.                  */ \
347     false,                          /* Rail-to-rail input enabled.             */ \
348     true,                           /* Use factory calibrated opamp offset.    */ \
349     0                               /* Opamp offset value (not used).          */ \
350   }
351 
352 /** Configuration of OPA0 in cascaded inverting amplifier mode.        */
353 #define OPA_INIT_CASCADED_INVERTING_OPA0                                          \
354   {                                                                               \
355     opaNegSelResTap,                /* Neg input from resistor ladder tap.     */ \
356     opaPosSelPosPad,                /* Pos input from pad.                     */ \
357     opaOutModeAll,                  /* Both main and alternate outputs.        */ \
358     opaResSelR2eqR1,                /* R2 = R1                                 */ \
359     opaResInMuxNegPad,              /* Resistor ladder input from neg pad.     */ \
360     0,                              /* No alternate outputs enabled.           */ \
361     _DAC_BIASPROG_BIASPROG_DEFAULT, /* Default bias setting.             */       \
362     _DAC_BIASPROG_HALFBIAS_DEFAULT, /* Default half-bias setting.        */       \
363     false,                          /* No low pass filter on pos pad.          */ \
364     false,                          /* No low pass filter on neg pad.          */ \
365     true,                           /* Pass output to next stage (OPA1).       */ \
366     true,                           /* Neg pad enabled, used as signal input.  */ \
367     true,                           /* Pos pad enabled, used as signal ground. */ \
368     false,                          /* No shorting of inputs.                  */ \
369     false,                          /* Rail-to-rail input enabled.             */ \
370     true,                           /* Use factory calibrated opamp offset.    */ \
371     0                               /* Opamp offset value (not used).          */ \
372   }
373 
374 /** Configuration of OPA1 in cascaded inverting amplifier mode.        */
375 #define OPA_INIT_CASCADED_INVERTING_OPA1                                          \
376   {                                                                               \
377     opaNegSelResTap,                /* Neg input from resistor ladder tap.     */ \
378     opaPosSelPosPad,                /* Pos input from pad.                     */ \
379     opaOutModeAll,                  /* Both main and alternate outputs.        */ \
380     opaResSelR2eqR1,                /* R2 = R1                                 */ \
381     opaResInMuxOpaIn,               /* Resistor ladder input from OPA0.        */ \
382     0,                              /* No alternate outputs enabled.           */ \
383     _DAC_BIASPROG_BIASPROG_DEFAULT, /* Default bias setting.             */       \
384     _DAC_BIASPROG_HALFBIAS_DEFAULT, /* Default half-bias setting.        */       \
385     false,                          /* No low pass filter on pos pad.          */ \
386     false,                          /* No low pass filter on neg pad.          */ \
387     true,                           /* Pass output to next stage (OPA2).       */ \
388     false,                          /* Neg pad disabled.                       */ \
389     true,                           /* Pos pad enabled, used as signal ground. */ \
390     false,                          /* No shorting of inputs.                  */ \
391     false,                          /* Rail-to-rail input enabled.             */ \
392     true,                           /* Use factory calibrated opamp offset.    */ \
393     0                               /* Opamp offset value (not used).          */ \
394   }
395 
396 /** Configuration of OPA2 in cascaded inverting amplifier mode.        */
397 #define OPA_INIT_CASCADED_INVERTING_OPA2                                          \
398   {                                                                               \
399     opaNegSelResTap,                /* Neg input from resistor ladder tap.     */ \
400     opaPosSelPosPad,                /* Pos input from pad.                     */ \
401     opaOutModeMain,                 /* Main output enabled.                    */ \
402     opaResSelR2eqR1,                /* R2 = R1                                 */ \
403     opaResInMuxOpaIn,               /* Resistor ladder input from OPA1.        */ \
404     DAC_OPA0MUX_OUTPEN_OUT0,        /* Alternate output 0 enabled.             */ \
405     _DAC_BIASPROG_BIASPROG_DEFAULT, /* Default bias setting.             */       \
406     _DAC_BIASPROG_HALFBIAS_DEFAULT, /* Default half-bias setting.        */       \
407     false,                          /* No low pass filter on pos pad.          */ \
408     false,                          /* No low pass filter on neg pad.          */ \
409     false,                          /* No nextout output enabled.              */ \
410     false,                          /* Neg pad disabled.                       */ \
411     true,                           /* Pos pad enabled, used as signal ground. */ \
412     false,                          /* No shorting of inputs.                  */ \
413     false,                          /* Rail-to-rail input enabled.             */ \
414     true,                           /* Use factory calibrated opamp offset.    */ \
415     0                               /* Opamp offset value (not used).          */ \
416   }
417 
418 /** Configuration of OPA0 in two-opamp differential driver mode.       */
419 #define OPA_INIT_DIFF_DRIVER_OPA0                                                 \
420   {                                                                               \
421     opaNegSelUnityGain,             /* Unity gain.                             */ \
422     opaPosSelPosPad,                /* Pos input from pad.                     */ \
423     opaOutModeAll,                  /* Both main and alternate outputs.        */ \
424     opaResSelDefault,               /* Resistor ladder is not used.            */ \
425     opaResInMuxDisable,             /* Resistor ladder disabled.               */ \
426     0,                              /* No alternate outputs enabled.           */ \
427     _DAC_BIASPROG_BIASPROG_DEFAULT, /* Default bias setting.             */       \
428     _DAC_BIASPROG_HALFBIAS_DEFAULT, /* Default half-bias setting.        */       \
429     false,                          /* No low pass filter on pos pad.          */ \
430     false,                          /* No low pass filter on neg pad.          */ \
431     true,                           /* Pass output to next stage (OPA1).       */ \
432     false,                          /* Neg pad disabled.                       */ \
433     true,                           /* Pos pad enabled, used as signal input.  */ \
434     false,                          /* No shorting of inputs.                  */ \
435     false,                          /* Rail-to-rail input enabled.             */ \
436     true,                           /* Use factory calibrated opamp offset.    */ \
437     0                               /* Opamp offset value (not used).          */ \
438   }
439 
440 /** Configuration of OPA1 in two-opamp differential driver mode.       */
441 #define OPA_INIT_DIFF_DRIVER_OPA1                                                 \
442   {                                                                               \
443     opaNegSelResTap,                /* Neg input from resistor ladder tap.     */ \
444     opaPosSelPosPad,                /* Pos input from pad.                     */ \
445     opaOutModeMain,                 /* Main output enabled.                    */ \
446     opaResSelR2eqR1,                /* R2 = R1                                 */ \
447     opaResInMuxOpaIn,               /* Resistor ladder input from OPA0.        */ \
448     0,                              /* No alternate outputs enabled.           */ \
449     _DAC_BIASPROG_BIASPROG_DEFAULT, /* Default bias setting.             */       \
450     _DAC_BIASPROG_HALFBIAS_DEFAULT, /* Default half-bias setting.        */       \
451     false,                          /* No low pass filter on pos pad.          */ \
452     false,                          /* No low pass filter on neg pad.          */ \
453     false,                          /* No nextout output enabled.              */ \
454     false,                          /* Neg pad disabled.                       */ \
455     true,                           /* Pos pad enabled, used as signal ground. */ \
456     false,                          /* No shorting of inputs.                  */ \
457     false,                          /* Rail-to-rail input enabled.             */ \
458     true,                           /* Use factory calibrated opamp offset.    */ \
459     0                               /* Opamp offset value (not used).          */ \
460   }
461 
462 /** Configuration of OPA0 in three-opamp differential receiver mode.   */
463 #define OPA_INIT_DIFF_RECEIVER_OPA0                                               \
464   {                                                                               \
465     opaNegSelUnityGain,             /* Unity gain.                             */ \
466     opaPosSelPosPad,                /* Pos input from pad.                     */ \
467     opaOutModeAll,                  /* Both main and alternate outputs.        */ \
468     opaResSelR2eqR1,                /* R2 = R1                                 */ \
469     opaResInMuxNegPad,              /* Resistor ladder input from neg pad.     */ \
470     0,                              /* No alternate outputs enabled.           */ \
471     _DAC_BIASPROG_BIASPROG_DEFAULT, /* Default bias setting.             */       \
472     _DAC_BIASPROG_HALFBIAS_DEFAULT, /* Default half-bias setting.        */       \
473     false,                          /* No low pass filter on pos pad.          */ \
474     false,                          /* No low pass filter on neg pad.          */ \
475     true,                           /* Pass output to next stage (OPA2).       */ \
476     true,                           /* Neg pad enabled, used as signal ground. */ \
477     true,                           /* Pos pad enabled, used as signal input.  */ \
478     false,                          /* No shorting of inputs.                  */ \
479     false,                          /* Rail-to-rail input enabled.             */ \
480     true,                           /* Use factory calibrated opamp offset.    */ \
481     0                               /* Opamp offset value (not used).          */ \
482   }
483 
484 /** Configuration of OPA1 in three-opamp differential receiver mode.   */
485 #define OPA_INIT_DIFF_RECEIVER_OPA1                                               \
486   {                                                                               \
487     opaNegSelUnityGain,             /* Unity gain.                             */ \
488     opaPosSelPosPad,                /* Pos input from pad.                     */ \
489     opaOutModeAll,                  /* Both main and alternate outputs.        */ \
490     opaResSelDefault,               /* Resistor ladder is not used.            */ \
491     opaResInMuxDisable,             /* Disable resistor ladder.                */ \
492     0,                              /* No alternate outputs enabled.           */ \
493     _DAC_BIASPROG_BIASPROG_DEFAULT, /* Default bias setting.             */       \
494     _DAC_BIASPROG_HALFBIAS_DEFAULT, /* Default half-bias setting.        */       \
495     false,                          /* No low pass filter on pos pad.          */ \
496     false,                          /* No low pass filter on neg pad.          */ \
497     true,                           /* Pass output to next stage (OPA2).       */ \
498     false,                          /* Neg pad disabled.                       */ \
499     true,                           /* Pos pad enabled, used as signal input.  */ \
500     false,                          /* No shorting of inputs.                  */ \
501     false,                          /* Rail-to-rail input enabled.             */ \
502     true,                           /* Use factory calibrated opamp offset.    */ \
503     0                               /* Opamp offset value (not used).          */ \
504   }
505 
506 /** Configuration of OPA2 in three-opamp differential receiver mode.   */
507 #define OPA_INIT_DIFF_RECEIVER_OPA2                                               \
508   {                                                                               \
509     opaNegSelResTap,                /* Input from resistor ladder tap.         */ \
510     opaPosSelResTapOpa0,            /* Input from OPA0 resistor ladder tap.    */ \
511     opaOutModeMain,                 /* Main output enabled.                    */ \
512     opaResSelR2eqR1,                /* R2 = R1                                 */ \
513     opaResInMuxOpaIn,               /* Resistor ladder input from OPA1.        */ \
514     DAC_OPA0MUX_OUTPEN_OUT0,        /* Enable alternate output 0.              */ \
515     _DAC_BIASPROG_BIASPROG_DEFAULT, /* Default bias setting.             */       \
516     _DAC_BIASPROG_HALFBIAS_DEFAULT, /* Default half-bias setting.        */       \
517     false,                          /* No low pass filter on pos pad.          */ \
518     false,                          /* No low pass filter on neg pad.          */ \
519     false,                          /* No nextout output enabled.              */ \
520     false,                          /* Neg pad disabled.                       */ \
521     false,                          /* Pos pad disabled.                       */ \
522     false,                          /* No shorting of inputs.                  */ \
523     false,                          /* Rail-to-rail input enabled.             */ \
524     true,                           /* Use factory calibrated opamp offset.    */ \
525     0                               /* Opamp offset value (not used).          */ \
526   }
527 
528 /*******************************************************************************
529  *****************************   PROTOTYPES   **********************************
530  ******************************************************************************/
531 
532 void      OPAMP_Disable(DAC_TypeDef *dac, OPAMP_TypeDef opa);
533 void      OPAMP_Enable(DAC_TypeDef *dac, OPAMP_TypeDef opa, const OPAMP_Init_TypeDef *init);
534 
535 /** @} (end addtogroup OPAMP) */
536 /** @} (end addtogroup EM_Library) */
537 
538 #ifdef __cplusplus
539 }
540 #endif
541 
542 #endif /* defined( OPAMP_PRESENT ) && ( OPAMP_COUNT == 1 ) */
543 #endif /* __EM_DAC_H */
544