1 /***************************************************************************//**
\r
3 * @brief Current Digital to Analog Converter (IDAC) peripheral API
\r
5 *******************************************************************************
\r
7 * <b>(C) Copyright 2015 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
33 #ifndef __SILICON_LABS_EM_IDAC_H__
\r
34 #define __SILICON_LABS_EM_IDAC_H__
\r
36 #include "em_device.h"
\r
38 #if defined(IDAC_COUNT) && (IDAC_COUNT > 0)
\r
39 #include <stdbool.h>
\r
45 /***************************************************************************//**
\r
46 * @addtogroup EM_Library
\r
48 ******************************************************************************/
\r
50 /***************************************************************************//**
\r
53 ******************************************************************************/
\r
55 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
\r
57 /** Validation of IDAC register block pointer reference for assert statements. */
\r
58 #define IDAC_REF_VALID(ref) ((ref) == IDAC0)
\r
62 /*******************************************************************************
\r
63 ******************************** ENUMS ************************************
\r
64 ******************************************************************************/
\r
69 #if defined( _IDAC_CTRL_OUTMODE_MASK )
\r
70 idacOutputPin = IDAC_CTRL_OUTMODE_PIN, /**< Output to IDAC OUT pin */
\r
71 idacOutputADC = IDAC_CTRL_OUTMODE_ADC /**< Output to ADC */
\r
72 #elif ( _IDAC_CTRL_APORTOUTSEL_MASK )
\r
73 idacOutputAPORT1XCH0 = IDAC_CTRL_APORTOUTSEL_APORT1XCH0, /**< Output to APORT 1X CH0 */
\r
74 idacOutputAPORT1YCH1 = IDAC_CTRL_APORTOUTSEL_APORT1YCH1, /**< Output to APORT 1Y CH1 */
\r
75 idacOutputAPORT1XCH2 = IDAC_CTRL_APORTOUTSEL_APORT1XCH2, /**< Output to APORT 1X CH2 */
\r
76 idacOutputAPORT1YCH3 = IDAC_CTRL_APORTOUTSEL_APORT1YCH3, /**< Output to APORT 1Y CH3 */
\r
77 idacOutputAPORT1XCH4 = IDAC_CTRL_APORTOUTSEL_APORT1XCH4, /**< Output to APORT 1X CH4 */
\r
78 idacOutputAPORT1YCH5 = IDAC_CTRL_APORTOUTSEL_APORT1YCH5, /**< Output to APORT 1Y CH5 */
\r
79 idacOutputAPORT1XCH6 = IDAC_CTRL_APORTOUTSEL_APORT1XCH6, /**< Output to APORT 1X CH6 */
\r
80 idacOutputAPORT1YCH7 = IDAC_CTRL_APORTOUTSEL_APORT1YCH7, /**< Output to APORT 1Y CH7 */
\r
81 idacOutputAPORT1XCH8 = IDAC_CTRL_APORTOUTSEL_APORT1XCH8, /**< Output to APORT 1X CH8 */
\r
82 idacOutputAPORT1YCH9 = IDAC_CTRL_APORTOUTSEL_APORT1YCH9, /**< Output to APORT 1Y CH9 */
\r
83 idacOutputAPORT1XCH10 = IDAC_CTRL_APORTOUTSEL_APORT1XCH10, /**< Output to APORT 1X CH10 */
\r
84 idacOutputAPORT1YCH11 = IDAC_CTRL_APORTOUTSEL_APORT1YCH11, /**< Output to APORT 1Y CH11 */
\r
85 idacOutputAPORT1XCH12 = IDAC_CTRL_APORTOUTSEL_APORT1XCH12, /**< Output to APORT 1X CH12 */
\r
86 idacOutputAPORT1YCH13 = IDAC_CTRL_APORTOUTSEL_APORT1YCH13, /**< Output to APORT 1Y CH13 */
\r
87 idacOutputAPORT1XCH14 = IDAC_CTRL_APORTOUTSEL_APORT1XCH14, /**< Output to APORT 1X CH14 */
\r
88 idacOutputAPORT1YCH15 = IDAC_CTRL_APORTOUTSEL_APORT1YCH15, /**< Output to APORT 1Y CH15 */
\r
89 idacOutputAPORT1XCH16 = IDAC_CTRL_APORTOUTSEL_APORT1XCH16, /**< Output to APORT 1X CH16 */
\r
90 idacOutputAPORT1YCH17 = IDAC_CTRL_APORTOUTSEL_APORT1YCH17, /**< Output to APORT 1Y CH17 */
\r
91 idacOutputAPORT1XCH18 = IDAC_CTRL_APORTOUTSEL_APORT1XCH18, /**< Output to APORT 1X CH18 */
\r
92 idacOutputAPORT1YCH19 = IDAC_CTRL_APORTOUTSEL_APORT1YCH19, /**< Output to APORT 1Y CH19 */
\r
93 idacOutputAPORT1XCH20 = IDAC_CTRL_APORTOUTSEL_APORT1XCH20, /**< Output to APORT 1X CH20 */
\r
94 idacOutputAPORT1YCH21 = IDAC_CTRL_APORTOUTSEL_APORT1YCH21, /**< Output to APORT 1Y CH21 */
\r
95 idacOutputAPORT1XCH22 = IDAC_CTRL_APORTOUTSEL_APORT1XCH22, /**< Output to APORT 1X CH22 */
\r
96 idacOutputAPORT1YCH23 = IDAC_CTRL_APORTOUTSEL_APORT1YCH23, /**< Output to APORT 1Y CH23 */
\r
97 idacOutputAPORT1XCH24 = IDAC_CTRL_APORTOUTSEL_APORT1XCH24, /**< Output to APORT 1X CH24 */
\r
98 idacOutputAPORT1YCH25 = IDAC_CTRL_APORTOUTSEL_APORT1YCH25, /**< Output to APORT 1Y CH25 */
\r
99 idacOutputAPORT1XCH26 = IDAC_CTRL_APORTOUTSEL_APORT1XCH26, /**< Output to APORT 1X CH26 */
\r
100 idacOutputAPORT1YCH27 = IDAC_CTRL_APORTOUTSEL_APORT1YCH27, /**< Output to APORT 1Y CH27 */
\r
101 idacOutputAPORT1XCH28 = IDAC_CTRL_APORTOUTSEL_APORT1XCH28, /**< Output to APORT 1X CH28 */
\r
102 idacOutputAPORT1YCH29 = IDAC_CTRL_APORTOUTSEL_APORT1YCH29, /**< Output to APORT 1Y CH29 */
\r
103 idacOutputAPORT1XCH30 = IDAC_CTRL_APORTOUTSEL_APORT1XCH30, /**< Output to APORT 1X CH30 */
\r
104 idacOutputAPORT1YCH31 = IDAC_CTRL_APORTOUTSEL_APORT1YCH31, /**< Output to APORT 1Y CH31 */
\r
106 } IDAC_OutMode_TypeDef;
\r
109 /** Selects which Peripheral Reflex System (PRS) signal to use when
\r
110 PRS is set to control the IDAC output. */
\r
113 idacPRSSELCh0 = IDAC_CTRL_PRSSEL_PRSCH0, /**< PRS channel 0. */
\r
114 idacPRSSELCh1 = IDAC_CTRL_PRSSEL_PRSCH1, /**< PRS channel 1. */
\r
115 idacPRSSELCh2 = IDAC_CTRL_PRSSEL_PRSCH2, /**< PRS channel 2. */
\r
116 idacPRSSELCh3 = IDAC_CTRL_PRSSEL_PRSCH3, /**< PRS channel 3. */
\r
117 #if defined( IDAC_CTRL_PRSSEL_PRSCH4 )
\r
118 idacPRSSELCh4 = IDAC_CTRL_PRSSEL_PRSCH4, /**< PRS channel 4. */
\r
119 idacPRSSELCh5 = IDAC_CTRL_PRSSEL_PRSCH5, /**< PRS channel 5. */
\r
121 #if defined( IDAC_CTRL_PRSSEL_PRSCH6 )
\r
122 idacPRSSELCh6 = IDAC_CTRL_PRSSEL_PRSCH6, /**< PRS channel 6. */
\r
123 idacPRSSELCh7 = IDAC_CTRL_PRSSEL_PRSCH7, /**< PRS channel 7. */
\r
124 idacPRSSELCh8 = IDAC_CTRL_PRSSEL_PRSCH8, /**< PRS channel 8. */
\r
125 idacPRSSELCh9 = IDAC_CTRL_PRSSEL_PRSCH9, /**< PRS channel 9. */
\r
126 idacPRSSELCh10 = IDAC_CTRL_PRSSEL_PRSCH10, /**< PRS channel 10 */
\r
127 idacPRSSELCh11 = IDAC_CTRL_PRSSEL_PRSCH11, /**< PRS channel 11 */
\r
129 } IDAC_PRSSEL_TypeDef;
\r
132 /** Selects which current range to use. */
\r
135 idacCurrentRange0 = IDAC_CURPROG_RANGESEL_RANGE0, /**< current range 0. */
\r
136 idacCurrentRange1 = IDAC_CURPROG_RANGESEL_RANGE1, /**< current range 1. */
\r
137 idacCurrentRange2 = IDAC_CURPROG_RANGESEL_RANGE2, /**< current range 2. */
\r
138 idacCurrentRange3 = IDAC_CURPROG_RANGESEL_RANGE3, /**< current range 3. */
\r
139 } IDAC_Range_TypeDef;
\r
141 /*******************************************************************************
\r
142 ******************************* STRUCTS ***********************************
\r
143 ******************************************************************************/
\r
145 /** IDAC init structure, common for both channels. */
\r
148 /** Enable IDAC. */
\r
152 IDAC_OutMode_TypeDef outMode;
\r
155 * Enable Peripheral reflex system (PRS) to control IDAC output. If false,
\r
156 * the IDAC output is controlled by writing to IDAC_OUTEN in IDAC_CTRL or
\r
157 * by calling IDAC_OutEnable().
\r
162 * Peripheral reflex system channel selection. Only applicable if @p prsEnable
\r
165 IDAC_PRSSEL_TypeDef prsSel;
\r
167 /** Enable/disable current sink mode. */
\r
170 } IDAC_Init_TypeDef;
\r
172 /** Default config for IDAC init structure. */
\r
173 #if defined( _IDAC_CTRL_OUTMODE_MASK )
\r
174 #define IDAC_INIT_DEFAULT \
\r
176 false, /**< Leave IDAC disabled when init done. */ \
\r
177 idacOutputPin, /**< Output to IDAC output pin. */ \
\r
178 false, /**< Disable PRS triggering. */ \
\r
179 idacPRSSELCh0, /**< Select PRS ch0 (if PRS triggering enabled). */ \
\r
180 false /**< Disable current sink mode. */ \
\r
182 #elif ( _IDAC_CTRL_APORTOUTSEL_MASK )
\r
183 #define IDAC_INIT_DEFAULT \
\r
185 false, /**< Leave IDAC disabled when init done. */ \
\r
186 idacOutputAPORT1XCH0, /**< Output to APORT. */ \
\r
187 false, /**< Disable PRS triggering. */ \
\r
188 idacPRSSELCh0, /**< Select PRS ch0 (if PRS triggering enabled). */ \
\r
189 false /**< Disable current sink mode. */ \
\r
194 /*******************************************************************************
\r
195 ***************************** PROTOTYPES **********************************
\r
196 ******************************************************************************/
\r
198 /***************************************************************************//**
\r
203 * Initializes IDAC according to the initialization structure parameter, and
\r
204 * sets the default calibration value stored in the DEVINFO structure.
\r
207 * This function will disable the IDAC prior to configuration.
\r
210 * Pointer to IDAC peripheral register block.
\r
213 * Pointer to IDAC initialization structure.
\r
214 ******************************************************************************/
\r
215 void IDAC_Init(IDAC_TypeDef *idac, const IDAC_Init_TypeDef *init);
\r
218 /***************************************************************************//**
\r
220 * Enable/disable IDAC.
\r
223 * Pointer to IDAC peripheral register block.
\r
225 * @param[in] enable
\r
226 * true to enable IDAC, false to disable.
\r
227 ******************************************************************************/
\r
228 void IDAC_Enable(IDAC_TypeDef *idac, bool enable);
\r
231 /***************************************************************************//**
\r
233 * Reset IDAC to same state as after a HW reset.
\r
236 * Pointer to IDAC peripheral register block.
\r
237 ******************************************************************************/
\r
238 void IDAC_Reset(IDAC_TypeDef *idac);
\r
241 /***************************************************************************//**
\r
243 * Enable/disable Minimal Output Transition mode.
\r
246 * Pointer to IDAC peripheral register block.
\r
248 * @param[in] enable
\r
249 * true to enable Minimal Output Transition mode, false to disable.
\r
250 ******************************************************************************/
\r
251 void IDAC_MinimalOutputTransitionMode(IDAC_TypeDef *idac, bool enable);
\r
254 /***************************************************************************//**
\r
256 * Set the current range of the IDAC output.
\r
259 * This function sets the current range of the IDAC output. The function
\r
260 * also updates the IDAC calibration register (IDAC_CAL) with the default
\r
261 * calibration value (from DEVINFO, factory setting) corresponding to the
\r
265 * Pointer to IDAC peripheral register block.
\r
268 * Current range value.
\r
269 ******************************************************************************/
\r
270 void IDAC_RangeSet(IDAC_TypeDef *idac, const IDAC_Range_TypeDef range);
\r
273 /***************************************************************************//**
\r
275 * Set the current step of the IDAC output.
\r
278 * Pointer to IDAC peripheral register block.
\r
281 * Step value for IDAC output. Valid range is 0-31.
\r
282 ******************************************************************************/
\r
283 void IDAC_StepSet(IDAC_TypeDef *idac, const uint32_t step);
\r
286 /***************************************************************************//**
\r
288 * Enable/disable the IDAC OUT pin.
\r
291 * Pointer to IDAC peripheral register block.
\r
293 * @param[in] enable
\r
294 * true to enable the IDAC OUT pin, false to disable.
\r
295 ******************************************************************************/
\r
296 void IDAC_OutEnable(IDAC_TypeDef *idac, bool enable);
\r
299 #if defined( _IDAC_IEN_MASK )
\r
300 /***************************************************************************//**
\r
302 * Clear one or more pending IDAC interrupts.
\r
305 * Pointer to IDAC peripheral register block.
\r
308 * Pending IDAC interrupt source(s) to clear. Use one or more valid
\r
309 * interrupt flags for the IDAC module (IDAC_IF_nnn) OR'ed together.
\r
310 ******************************************************************************/
\r
311 __STATIC_INLINE void IDAC_IntClear(IDAC_TypeDef *idac, uint32_t flags)
\r
317 /***************************************************************************//**
\r
319 * Disable one or more IDAC interrupts.
\r
322 * Pointer to IDAC peripheral register block.
\r
325 * IDAC interrupt source(s) to disable. Use one or more valid
\r
326 * interrupt flags for the IDAC module (IDAC_IF_nnn) OR'ed together.
\r
327 ******************************************************************************/
\r
328 __STATIC_INLINE void IDAC_IntDisable(IDAC_TypeDef *idac, uint32_t flags)
\r
330 idac->IEN &= ~flags;
\r
334 /***************************************************************************//**
\r
336 * Enable one or more IDAC interrupts.
\r
339 * Depending on the use, a pending interrupt may already be set prior to
\r
340 * enabling the interrupt. Consider using IDAC_IntClear() prior to enabling
\r
341 * if such a pending interrupt should be ignored.
\r
344 * Pointer to IDAC peripheral register block.
\r
347 * IDAC interrupt source(s) to enable. Use one or more valid
\r
348 * interrupt flags for the IDAC module (IDAC_IF_nnn) OR'ed together.
\r
349 ******************************************************************************/
\r
350 __STATIC_INLINE void IDAC_IntEnable(IDAC_TypeDef *idac, uint32_t flags)
\r
352 idac->IEN |= flags;
\r
356 /***************************************************************************//**
\r
358 * Get pending IDAC interrupt flags.
\r
361 * The event bits are not cleared by the use of this function.
\r
364 * Pointer to IDAC peripheral register block.
\r
367 * IDAC interrupt source(s) pending. Returns one or more valid
\r
368 * interrupt flags for the IDAC module (IDAC_IF_nnn) OR'ed together.
\r
369 ******************************************************************************/
\r
370 __STATIC_INLINE uint32_t IDAC_IntGet(IDAC_TypeDef *idac)
\r
376 /***************************************************************************//**
\r
378 * Get enabled and pending IDAC interrupt flags.
\r
379 * Useful for handling more interrupt sources in the same interrupt handler.
\r
382 * Pointer to IDAC peripheral register block.
\r
385 * Interrupt flags are not cleared by the use of this function.
\r
388 * Pending and enabled IDAC interrupt sources.
\r
389 * The return value is the bitwise AND combination of
\r
390 * - the OR combination of enabled interrupt sources in IDACx_IEN_nnn
\r
391 * register (IDACx_IEN_nnn) and
\r
392 * - the OR combination of valid interrupt flags of the IDAC module
\r
394 ******************************************************************************/
\r
395 __STATIC_INLINE uint32_t IDAC_IntGetEnabled(IDAC_TypeDef *idac)
\r
399 /* Store flags in temporary variable in order to define explicit order
\r
400 * of volatile accesses. */
\r
403 /* Bitwise AND of pending and enabled interrupts */
\r
404 return idac->IF & ien;
\r
408 /***************************************************************************//**
\r
410 * Set one or more pending IDAC interrupts from SW.
\r
413 * Pointer to IDAC peripheral register block.
\r
416 * IDAC interrupt source(s) to set to pending. Use one or more valid
\r
417 * interrupt flags for the IDAC module (IDAC_IF_nnn) OR'ed together.
\r
418 ******************************************************************************/
\r
419 __STATIC_INLINE void IDAC_IntSet(IDAC_TypeDef *idac, uint32_t flags)
\r
426 /** @} (end addtogroup IDAC) */
\r
427 /** @} (end addtogroup EM_Library) */
\r
433 #endif /* defined(IDAC_COUNT) && (IDAC_COUNT > 0) */
\r
435 #endif /* __SILICON_LABS_EM_IDAC_H__ */
\r