EFM32 Wonder Gecko Software Documentation  efm32wg-doc-5.1.2
em_vdac.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef EM_VDAC_H
34 #define EM_VDAC_H
35 
36 #include "em_device.h"
37 
38 #if defined(VDAC_COUNT) && (VDAC_COUNT > 0)
39 
40 #include "em_assert.h"
41 #include <stdbool.h>
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 
48 /***************************************************************************/
53 /***************************************************************************/
97 #define VDAC_REF_VALID(ref) ((ref) == VDAC0)
98 
101 /*******************************************************************************
102  ******************************** ENUMS ************************************
103  ******************************************************************************/
104 
106 typedef enum
107 {
108  vdacRefresh8 = _VDAC_CTRL_REFRESHPERIOD_8CYCLES,
109  vdacRefresh16 = _VDAC_CTRL_REFRESHPERIOD_16CYCLES,
110  vdacRefresh32 = _VDAC_CTRL_REFRESHPERIOD_32CYCLES,
111  vdacRefresh64 = _VDAC_CTRL_REFRESHPERIOD_64CYCLES,
112 } VDAC_Refresh_TypeDef;
113 
115 typedef enum
116 {
117  vdacRef1V25Ln = _VDAC_CTRL_REFSEL_1V25LN,
118  vdacRef2V5Ln = _VDAC_CTRL_REFSEL_2V5LN,
119  vdacRef1V25 = _VDAC_CTRL_REFSEL_1V25,
120  vdacRef2V5 = _VDAC_CTRL_REFSEL_2V5,
121  vdacRefAvdd = _VDAC_CTRL_REFSEL_VDD,
122  vdacRefExtPin = _VDAC_CTRL_REFSEL_EXT,
123 } VDAC_Ref_TypeDef;
124 
126 typedef enum
127 {
128  vdacPrsSelCh0 = _VDAC_CH0CTRL_PRSSEL_PRSCH0 ,
129  vdacPrsSelCh1 = _VDAC_CH0CTRL_PRSSEL_PRSCH1 ,
130  vdacPrsSelCh2 = _VDAC_CH0CTRL_PRSSEL_PRSCH2 ,
131  vdacPrsSelCh3 = _VDAC_CH0CTRL_PRSSEL_PRSCH3 ,
132  vdacPrsSelCh4 = _VDAC_CH0CTRL_PRSSEL_PRSCH4 ,
133  vdacPrsSelCh5 = _VDAC_CH0CTRL_PRSSEL_PRSCH5 ,
134  vdacPrsSelCh6 = _VDAC_CH0CTRL_PRSSEL_PRSCH6 ,
135  vdacPrsSelCh7 = _VDAC_CH0CTRL_PRSSEL_PRSCH7 ,
136  vdacPrsSelCh8 = _VDAC_CH0CTRL_PRSSEL_PRSCH8 ,
137  vdacPrsSelCh9 = _VDAC_CH0CTRL_PRSSEL_PRSCH9 ,
138  vdacPrsSelCh10 = _VDAC_CH0CTRL_PRSSEL_PRSCH10,
139  vdacPrsSelCh11 = _VDAC_CH0CTRL_PRSSEL_PRSCH11,
140 } VDAC_PrsSel_TypeDef;
141 
143 typedef enum
144 {
145  vdacTrigModeSw = _VDAC_CH0CTRL_TRIGMODE_SW,
146  vdacTrigModePrs = _VDAC_CH0CTRL_TRIGMODE_PRS,
147  vdacTrigModeRefresh = _VDAC_CH0CTRL_TRIGMODE_REFRESH,
148  vdacTrigModeSwPrs = _VDAC_CH0CTRL_TRIGMODE_SWPRS,
149  vdacTrigModeSwRefresh = _VDAC_CH0CTRL_TRIGMODE_SWREFRESH,
150  vdacTrigModeLesense = _VDAC_CH0CTRL_TRIGMODE_LESENSE,
151 } VDAC_TrigMode_TypeDef;
152 
153 /*******************************************************************************
154  ******************************* STRUCTS ***********************************
155  ******************************************************************************/
156 
158 typedef struct
159 {
161  bool mainCalibration;
162 
165  bool asyncClockMode;
166 
168  bool warmupKeepOn;
169 
171  VDAC_Refresh_TypeDef refresh;
172 
174  uint32_t prescaler;
175 
177  VDAC_Ref_TypeDef reference;
178 
180  bool ch0ResetPre;
181 
183  bool outEnablePRS;
184 
186  bool sineEnable;
187 
189  bool diff;
190 } VDAC_Init_TypeDef;
191 
193 #define VDAC_INIT_DEFAULT \
194 { \
195  true, /* Use main output path calibration values. */ \
196  false, /* Use synchronous clock mode. */ \
197  false, /* Turn off between sample off conversions.*/ \
198  vdacRefresh8, /* Refresh every 8th cycle. */ \
199  0, /* No prescaling. */ \
200  vdacRef1V25Ln, /* 1.25V internal low noise reference. */ \
201  false, /* Do not reset prescaler on CH 0 start. */ \
202  false, /* VDAC output enable always on. */ \
203  false, /* Disable sine mode. */ \
204  false /* Single ended mode. */ \
205 }
206 
208 typedef struct
209 {
211  bool enable;
212 
216  VDAC_PrsSel_TypeDef prsSel;
217 
219  bool prsAsync;
220 
222  VDAC_TrigMode_TypeDef trigMode;
223 
226  bool sampleOffMode;
227 } VDAC_InitChannel_TypeDef;
228 
230 #define VDAC_INITCHANNEL_DEFAULT \
231 { \
232  false, /* Leave channel disabled when init done. */ \
233  vdacPrsSelCh0, /* PRS CH 0 triggers conversion. */ \
234  false, /* Treat PRS channel as a synchronous signal. */ \
235  vdacTrigModeSw, /* Conversion trigged by CH0DATA or COMBDATA write. */ \
236  false, /* Channel conversion set to continous. */ \
237 }
238 
239 /*******************************************************************************
240  ***************************** PROTOTYPES **********************************
241  ******************************************************************************/
242 
243 void VDAC_ChannelOutputSet(VDAC_TypeDef *vdac,
244  unsigned int channel,
245  uint32_t value);
246 void VDAC_Enable(VDAC_TypeDef *vdac, unsigned int ch, bool enable);
247 void VDAC_Init(VDAC_TypeDef *vdac, const VDAC_Init_TypeDef *init);
248 void VDAC_InitChannel(VDAC_TypeDef *vdac,
249  const VDAC_InitChannel_TypeDef *init,
250  unsigned int ch);
251 
252 /***************************************************************************/
266 __STATIC_INLINE void VDAC_Channel0OutputSet(VDAC_TypeDef *vdac,
267  uint32_t value)
268 {
269  EFM_ASSERT(value<=_VDAC_CH0DATA_MASK);
270  vdac->CH0DATA = value;
271 }
272 
273 /***************************************************************************/
287 __STATIC_INLINE void VDAC_Channel1OutputSet(VDAC_TypeDef *vdac,
288  uint32_t value)
289 {
290  EFM_ASSERT(value<=_VDAC_CH1DATA_MASK);
291  vdac->CH1DATA = value;
292 }
293 
294 /***************************************************************************/
305 __STATIC_INLINE void VDAC_IntClear(VDAC_TypeDef *vdac, uint32_t flags)
306 {
307  vdac->IFC = flags;
308 }
309 
310 /***************************************************************************/
321 __STATIC_INLINE void VDAC_IntDisable(VDAC_TypeDef *vdac, uint32_t flags)
322 {
323  vdac->IEN &= ~flags;
324 }
325 
326 /***************************************************************************/
342 __STATIC_INLINE void VDAC_IntEnable(VDAC_TypeDef *vdac, uint32_t flags)
343 {
344  vdac->IEN |= flags;
345 }
346 
347 /***************************************************************************/
361 __STATIC_INLINE uint32_t VDAC_IntGet(VDAC_TypeDef *vdac)
362 {
363  return vdac->IF;
364 }
365 
366 /***************************************************************************/
385 __STATIC_INLINE uint32_t VDAC_IntGetEnabled(VDAC_TypeDef *vdac)
386 {
387  uint32_t ien = vdac->IEN;
388 
389  /* Bitwise AND of pending and enabled interrupts */
390  return vdac->IF & ien;
391 }
392 
393 /***************************************************************************/
404 __STATIC_INLINE void VDAC_IntSet(VDAC_TypeDef *vdac, uint32_t flags)
405 {
406  vdac->IFS = flags;
407 }
408 
409 uint32_t VDAC_PrescaleCalc(uint32_t vdacFreq, bool syncMode, uint32_t hfperFreq);
410 void VDAC_Reset(VDAC_TypeDef *vdac);
411 
415 #ifdef __cplusplus
416 }
417 #endif
418 
419 #endif /* defined(VDAC_COUNT) && (VDAC_COUNT > 0) */
420 #endif /* EM_VDAC_H */
Emlib peripheral API "assert" implementation.
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.