1 /***************************************************************************//**
\r
3 * @brief Current Digital to Analog Converter (IDAC) peripheral API
\r
5 *******************************************************************************
\r
7 * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
\r
8 *******************************************************************************
\r
10 * Permission is granted to anyone to use this software for any purpose,
\r
11 * including commercial applications, and to alter it and redistribute it
\r
12 * freely, subject to the following restrictions:
\r
14 * 1. The origin of this software must not be misrepresented; you must not
\r
15 * claim that you wrote the original software.
\r
16 * 2. Altered source versions must be plainly marked as such, and must not be
\r
17 * misrepresented as being the original software.
\r
18 * 3. This notice may not be removed or altered from any source distribution.
\r
20 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
\r
21 * obligation to support this Software. Silicon Labs is providing the
\r
22 * Software "AS IS", with no express or implied warranties of any kind,
\r
23 * including, but not limited to, any implied warranties of merchantability
\r
24 * or fitness for any particular purpose or warranties against infringement
\r
25 * of any proprietary rights of a third party.
\r
27 * Silicon Labs will not be liable for any consequential, incidental, or
\r
28 * special damages, or any other relief, or for any claim by any third party,
\r
29 * arising from your use of this Software.
\r
31 ******************************************************************************/
\r
34 #ifndef __SILICON_LABS_EM_IDAC_H_
\r
35 #define __SILICON_LABS_EM_IDAC_H_
\r
37 #include "em_device.h"
\r
39 #if defined(IDAC_COUNT) && (IDAC_COUNT > 0)
\r
40 #include <stdbool.h>
\r
46 /***************************************************************************//**
\r
47 * @addtogroup EM_Library
\r
49 ******************************************************************************/
\r
51 /***************************************************************************//**
\r
54 ******************************************************************************/
\r
56 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
\r
58 /** Validation of IDAC register block pointer reference for assert statements. */
\r
59 #define IDAC_REF_VALID(ref) ((ref) == IDAC0)
\r
63 /*******************************************************************************
\r
64 ******************************** ENUMS ************************************
\r
65 ******************************************************************************/
\r
70 idacOutputPin = IDAC_CTRL_OUTMODE_PIN, /**< Output to IDAC OUT pin */
\r
71 idacOutputADC = IDAC_CTRL_OUTMODE_ADC /**< Output to ADC */
\r
72 } IDAC_OutMode_TypeDef;
\r
75 /** Selects which Peripheral Reflex System (PRS) signal to use when
\r
76 PRS is set to control the IDAC output. */
\r
79 idacPRSSELCh0 = IDAC_CTRL_PRSSEL_PRSCH0, /**< PRS channel 0. */
\r
80 idacPRSSELCh1 = IDAC_CTRL_PRSSEL_PRSCH1, /**< PRS channel 1. */
\r
81 idacPRSSELCh2 = IDAC_CTRL_PRSSEL_PRSCH2, /**< PRS channel 2. */
\r
82 idacPRSSELCh3 = IDAC_CTRL_PRSSEL_PRSCH3, /**< PRS channel 3. */
\r
83 #if defined( IDAC_CTRL_PRSSEL_PRSCH4 )
\r
84 idacPRSSELCh4 = IDAC_CTRL_PRSSEL_PRSCH4, /**< PRS channel 4. */
\r
86 #if defined( IDAC_CTRL_PRSSEL_PRSCH5 )
\r
87 idacPRSSELCh5 = IDAC_CTRL_PRSSEL_PRSCH5, /**< PRS channel 5. */
\r
89 #if defined( IDAC_CTRL_PRSSEL_PRSCH6 )
\r
90 idacPRSSELCh6 = IDAC_CTRL_PRSSEL_PRSCH6, /**< PRS channel 6. */
\r
92 #if defined( IDAC_CTRL_PRSSEL_PRSCH7 )
\r
93 idacPRSSELCh7 = IDAC_CTRL_PRSSEL_PRSCH7, /**< PRS channel 7. */
\r
95 #if defined( IDAC_CTRL_PRSSEL_PRSCH8 )
\r
96 idacPRSSELCh8 = IDAC_CTRL_PRSSEL_PRSCH8, /**< PRS channel 8. */
\r
98 #if defined( IDAC_CTRL_PRSSEL_PRSCH9 )
\r
99 idacPRSSELCh9 = IDAC_CTRL_PRSSEL_PRSCH9, /**< PRS channel 9. */
\r
101 #if defined( IDAC_CTRL_PRSSEL_PRSCH10 )
\r
102 idacPRSSELCh10 = IDAC_CTRL_PRSSEL_PRSCH10, /**< PRS channel 10 */
\r
104 #if defined( IDAC_CTRL_PRSSEL_PRSCH11 )
\r
105 idacPRSSELCh11 = IDAC_CTRL_PRSSEL_PRSCH11, /**< PRS channel 11 */
\r
107 } IDAC_PRSSEL_TypeDef;
\r
110 /** Selects which current range to use. */
\r
113 idacCurrentRange0 = IDAC_CURPROG_RANGESEL_RANGE0, /**< current range 0. */
\r
114 idacCurrentRange1 = IDAC_CURPROG_RANGESEL_RANGE1, /**< current range 1. */
\r
115 idacCurrentRange2 = IDAC_CURPROG_RANGESEL_RANGE2, /**< current range 2. */
\r
116 idacCurrentRange3 = IDAC_CURPROG_RANGESEL_RANGE3, /**< current range 3. */
\r
117 } IDAC_Range_TypeDef;
\r
119 /*******************************************************************************
\r
120 ******************************* STRUCTS ***********************************
\r
121 ******************************************************************************/
\r
123 /** IDAC init structure, common for both channels. */
\r
126 /** Enable IDAC. */
\r
130 IDAC_OutMode_TypeDef outMode;
\r
133 * Enable Peripheral reflex system (PRS) to control IDAC output. If false,
\r
134 * the IDAC output is controlled by writing to IDAC_OUTEN in IDAC_CTRL or
\r
135 * by calling IDAC_OutEnable().
\r
140 * Peripheral reflex system channel selection. Only applicable if @p prsEnable
\r
143 IDAC_PRSSEL_TypeDef prsSel;
\r
145 /** Enable/disable current sink mode. */
\r
148 } IDAC_Init_TypeDef;
\r
150 /** Default config for IDAC init structure. */
\r
151 #define IDAC_INIT_DEFAULT \
\r
152 { false, /* Leave IDAC disabled when init done. */ \
\r
153 idacOutputPin, /* Output to IDAC OUT pin. */ \
\r
154 false, /* Disable PRS triggering. */ \
\r
155 idacPRSSELCh0, /* Select PRS ch0 (if PRS triggering enabled). */ \
\r
156 false /* Disable current sink mode. */ \
\r
160 /*******************************************************************************
\r
161 ***************************** PROTOTYPES **********************************
\r
162 ******************************************************************************/
\r
164 /***************************************************************************//**
\r
169 * Initializes IDAC according to the initialization structure parameter, and
\r
170 * sets the default calibration value stored in the DEVINFO structure.
\r
173 * This function will disable the IDAC prior to configuration.
\r
176 * Pointer to IDAC peripheral register block.
\r
179 * Pointer to IDAC initialization structure.
\r
180 ******************************************************************************/
\r
181 void IDAC_Init(IDAC_TypeDef *idac, const IDAC_Init_TypeDef *init);
\r
184 /***************************************************************************//**
\r
186 * Enable/disable IDAC.
\r
189 * Pointer to IDAC peripheral register block.
\r
191 * @param[in] enable
\r
192 * true to enable IDAC, false to disable.
\r
193 ******************************************************************************/
\r
194 void IDAC_Enable(IDAC_TypeDef *idac, bool enable);
\r
197 /***************************************************************************//**
\r
199 * Reset IDAC to same state as after a HW reset.
\r
202 * Pointer to IDAC peripheral register block.
\r
203 ******************************************************************************/
\r
204 void IDAC_Reset(IDAC_TypeDef *idac);
\r
207 /***************************************************************************//**
\r
209 * Enable/disable Minimal Output Transition mode.
\r
212 * Pointer to IDAC peripheral register block.
\r
214 * @param[in] enable
\r
215 * true to enable Minimal Output Transition mode, false to disable.
\r
216 ******************************************************************************/
\r
217 void IDAC_MinimalOutputTransitionMode(IDAC_TypeDef *idac, bool enable);
\r
220 /***************************************************************************//**
\r
222 * Set the current range of the IDAC output.
\r
225 * This function sets the current range of the IDAC output. The function
\r
226 * also updates the IDAC calibration register (IDAC_CAL) with the default
\r
227 * calibration value (from DEVINFO, factory setting) corresponding to the
\r
231 * Pointer to IDAC peripheral register block.
\r
234 * Current range value.
\r
235 ******************************************************************************/
\r
236 void IDAC_RangeSet(IDAC_TypeDef *idac, const IDAC_Range_TypeDef range);
\r
239 /***************************************************************************//**
\r
241 * Set the current step of the IDAC output.
\r
244 * Pointer to IDAC peripheral register block.
\r
247 * Step value for IDAC output. Valid range is 0-31.
\r
248 ******************************************************************************/
\r
249 void IDAC_StepSet(IDAC_TypeDef *idac, const uint32_t step);
\r
252 /***************************************************************************//**
\r
254 * Enable/disable the IDAC OUT pin.
\r
257 * Pointer to IDAC peripheral register block.
\r
259 * @param[in] enable
\r
260 * true to enable the IDAC OUT pin, false to disable.
\r
261 ******************************************************************************/
\r
262 void IDAC_OutEnable(IDAC_TypeDef *idac, bool enable);
\r
265 /** @} (end addtogroup IDAC) */
\r
266 /** @} (end addtogroup EM_Library) */
\r
272 #endif /* defined(IDAC_COUNT) && (IDAC_COUNT > 0) */
\r
274 #endif /* __SILICON_LABS_EM_IDAC_H_ */
\r