EFM32 Leopard Gecko Software Documentation  efm32lg-doc-4.2.1
em_idac.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef __SILICON_LABS_EM_IDAC_H__
34 #define __SILICON_LABS_EM_IDAC_H__
35 
36 #include "em_device.h"
37 
38 #if defined(IDAC_COUNT) && (IDAC_COUNT > 0)
39 #include <stdbool.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /***************************************************************************/
50 /***************************************************************************/
58 #define IDAC_REF_VALID(ref) ((ref) == IDAC0)
59 
62 /*******************************************************************************
63  ******************************** ENUMS ************************************
64  ******************************************************************************/
65 
67 typedef enum
68 {
69 #if defined( _IDAC_CTRL_OUTMODE_MASK )
70  idacOutputPin = IDAC_CTRL_OUTMODE_PIN,
71  idacOutputADC = IDAC_CTRL_OUTMODE_ADC
72 #elif ( _IDAC_CTRL_APORTOUTSEL_MASK )
73  idacOutputAPORT1XCH0 = IDAC_CTRL_APORTOUTSEL_APORT1XCH0,
74  idacOutputAPORT1YCH1 = IDAC_CTRL_APORTOUTSEL_APORT1YCH1,
75  idacOutputAPORT1XCH2 = IDAC_CTRL_APORTOUTSEL_APORT1XCH2,
76  idacOutputAPORT1YCH3 = IDAC_CTRL_APORTOUTSEL_APORT1YCH3,
77  idacOutputAPORT1XCH4 = IDAC_CTRL_APORTOUTSEL_APORT1XCH4,
78  idacOutputAPORT1YCH5 = IDAC_CTRL_APORTOUTSEL_APORT1YCH5,
79  idacOutputAPORT1XCH6 = IDAC_CTRL_APORTOUTSEL_APORT1XCH6,
80  idacOutputAPORT1YCH7 = IDAC_CTRL_APORTOUTSEL_APORT1YCH7,
81  idacOutputAPORT1XCH8 = IDAC_CTRL_APORTOUTSEL_APORT1XCH8,
82  idacOutputAPORT1YCH9 = IDAC_CTRL_APORTOUTSEL_APORT1YCH9,
83  idacOutputAPORT1XCH10 = IDAC_CTRL_APORTOUTSEL_APORT1XCH10,
84  idacOutputAPORT1YCH11 = IDAC_CTRL_APORTOUTSEL_APORT1YCH11,
85  idacOutputAPORT1XCH12 = IDAC_CTRL_APORTOUTSEL_APORT1XCH12,
86  idacOutputAPORT1YCH13 = IDAC_CTRL_APORTOUTSEL_APORT1YCH13,
87  idacOutputAPORT1XCH14 = IDAC_CTRL_APORTOUTSEL_APORT1XCH14,
88  idacOutputAPORT1YCH15 = IDAC_CTRL_APORTOUTSEL_APORT1YCH15,
89  idacOutputAPORT1XCH16 = IDAC_CTRL_APORTOUTSEL_APORT1XCH16,
90  idacOutputAPORT1YCH17 = IDAC_CTRL_APORTOUTSEL_APORT1YCH17,
91  idacOutputAPORT1XCH18 = IDAC_CTRL_APORTOUTSEL_APORT1XCH18,
92  idacOutputAPORT1YCH19 = IDAC_CTRL_APORTOUTSEL_APORT1YCH19,
93  idacOutputAPORT1XCH20 = IDAC_CTRL_APORTOUTSEL_APORT1XCH20,
94  idacOutputAPORT1YCH21 = IDAC_CTRL_APORTOUTSEL_APORT1YCH21,
95  idacOutputAPORT1XCH22 = IDAC_CTRL_APORTOUTSEL_APORT1XCH22,
96  idacOutputAPORT1YCH23 = IDAC_CTRL_APORTOUTSEL_APORT1YCH23,
97  idacOutputAPORT1XCH24 = IDAC_CTRL_APORTOUTSEL_APORT1XCH24,
98  idacOutputAPORT1YCH25 = IDAC_CTRL_APORTOUTSEL_APORT1YCH25,
99  idacOutputAPORT1XCH26 = IDAC_CTRL_APORTOUTSEL_APORT1XCH26,
100  idacOutputAPORT1YCH27 = IDAC_CTRL_APORTOUTSEL_APORT1YCH27,
101  idacOutputAPORT1XCH28 = IDAC_CTRL_APORTOUTSEL_APORT1XCH28,
102  idacOutputAPORT1YCH29 = IDAC_CTRL_APORTOUTSEL_APORT1YCH29,
103  idacOutputAPORT1XCH30 = IDAC_CTRL_APORTOUTSEL_APORT1XCH30,
104  idacOutputAPORT1YCH31 = IDAC_CTRL_APORTOUTSEL_APORT1YCH31,
105 #endif
106 } IDAC_OutMode_TypeDef;
107 
108 
111 typedef enum
112 {
113  idacPRSSELCh0 = IDAC_CTRL_PRSSEL_PRSCH0,
114  idacPRSSELCh1 = IDAC_CTRL_PRSSEL_PRSCH1,
115  idacPRSSELCh2 = IDAC_CTRL_PRSSEL_PRSCH2,
116  idacPRSSELCh3 = IDAC_CTRL_PRSSEL_PRSCH3,
117 #if defined( IDAC_CTRL_PRSSEL_PRSCH4 )
118  idacPRSSELCh4 = IDAC_CTRL_PRSSEL_PRSCH4,
119  idacPRSSELCh5 = IDAC_CTRL_PRSSEL_PRSCH5,
120 #endif
121 #if defined( IDAC_CTRL_PRSSEL_PRSCH6 )
122  idacPRSSELCh6 = IDAC_CTRL_PRSSEL_PRSCH6,
123  idacPRSSELCh7 = IDAC_CTRL_PRSSEL_PRSCH7,
124  idacPRSSELCh8 = IDAC_CTRL_PRSSEL_PRSCH8,
125  idacPRSSELCh9 = IDAC_CTRL_PRSSEL_PRSCH9,
126  idacPRSSELCh10 = IDAC_CTRL_PRSSEL_PRSCH10,
127  idacPRSSELCh11 = IDAC_CTRL_PRSSEL_PRSCH11,
128 #endif
129 } IDAC_PRSSEL_TypeDef;
130 
131 
133 typedef enum
134 {
135  idacCurrentRange0 = IDAC_CURPROG_RANGESEL_RANGE0,
136  idacCurrentRange1 = IDAC_CURPROG_RANGESEL_RANGE1,
137  idacCurrentRange2 = IDAC_CURPROG_RANGESEL_RANGE2,
138  idacCurrentRange3 = IDAC_CURPROG_RANGESEL_RANGE3,
139 } IDAC_Range_TypeDef;
140 
141 /*******************************************************************************
142  ******************************* STRUCTS ***********************************
143  ******************************************************************************/
144 
146 typedef struct
147 {
149  bool enable;
150 
152  IDAC_OutMode_TypeDef outMode;
153 
159  bool prsEnable;
160 
165  IDAC_PRSSEL_TypeDef prsSel;
166 
168  bool sinkEnable;
169 
170 } IDAC_Init_TypeDef;
171 
173 #if defined( _IDAC_CTRL_OUTMODE_MASK )
174 #define IDAC_INIT_DEFAULT \
175 { \
176  false, \
177  idacOutputPin, \
178  false, \
179  idacPRSSELCh0, \
180  false \
181 }
182 #elif ( _IDAC_CTRL_APORTOUTSEL_MASK )
183 #define IDAC_INIT_DEFAULT \
184 { \
185  false, \
186  idacOutputAPORT1XCH0, \
187  false, \
188  idacPRSSELCh0, \
189  false \
190 }
191 #endif
192 
193 
194 /*******************************************************************************
195  ***************************** PROTOTYPES **********************************
196  ******************************************************************************/
197 
198 /***************************************************************************/
215 void IDAC_Init(IDAC_TypeDef *idac, const IDAC_Init_TypeDef *init);
216 
217 
218 /***************************************************************************/
228 void IDAC_Enable(IDAC_TypeDef *idac, bool enable);
229 
230 
231 /***************************************************************************/
238 void IDAC_Reset(IDAC_TypeDef *idac);
239 
240 
241 /***************************************************************************/
251 void IDAC_MinimalOutputTransitionMode(IDAC_TypeDef *idac, bool enable);
252 
253 
254 /***************************************************************************/
270 void IDAC_RangeSet(IDAC_TypeDef *idac, const IDAC_Range_TypeDef range);
271 
272 
273 /***************************************************************************/
283 void IDAC_StepSet(IDAC_TypeDef *idac, const uint32_t step);
284 
285 
286 /***************************************************************************/
296 void IDAC_OutEnable(IDAC_TypeDef *idac, bool enable);
297 
298 
299 #if defined( _IDAC_IEN_MASK )
300 /***************************************************************************/
311 __STATIC_INLINE void IDAC_IntClear(IDAC_TypeDef *idac, uint32_t flags)
312 {
313  idac->IFC = flags;
314 }
315 
316 
317 /***************************************************************************/
328 __STATIC_INLINE void IDAC_IntDisable(IDAC_TypeDef *idac, uint32_t flags)
329 {
330  idac->IEN &= ~flags;
331 }
332 
333 
334 /***************************************************************************/
350 __STATIC_INLINE void IDAC_IntEnable(IDAC_TypeDef *idac, uint32_t flags)
351 {
352  idac->IEN |= flags;
353 }
354 
355 
356 /***************************************************************************/
370 __STATIC_INLINE uint32_t IDAC_IntGet(IDAC_TypeDef *idac)
371 {
372  return idac->IF;
373 }
374 
375 
376 /***************************************************************************/
395 __STATIC_INLINE uint32_t IDAC_IntGetEnabled(IDAC_TypeDef *idac)
396 {
397  uint32_t ien;
398 
399  /* Store flags in temporary variable in order to define explicit order
400  * of volatile accesses. */
401  ien = idac->IEN;
402 
403  /* Bitwise AND of pending and enabled interrupts */
404  return idac->IF & ien;
405 }
406 
407 
408 /***************************************************************************/
419 __STATIC_INLINE void IDAC_IntSet(IDAC_TypeDef *idac, uint32_t flags)
420 {
421  idac->IFS = flags;
422 }
423 #endif
424 
425 
429 #ifdef __cplusplus
430 }
431 #endif
432 
433 #endif /* defined(IDAC_COUNT) && (IDAC_COUNT > 0) */
434 
435 #endif /* __SILICON_LABS_EM_IDAC_H__ */
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.