EFM32 Giant Gecko Software Documentation  efm32gg-doc-5.1.2
em_dac.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef EM_DAC_H
34 #define EM_DAC_H
35 
36 #include "em_device.h"
37 
38 #if defined(DAC_COUNT) && (DAC_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 /***************************************************************************/
61 #define DAC_REF_VALID(ref) ((ref) == DAC0)
62 
65 /*******************************************************************************
66  ******************************** ENUMS ************************************
67  ******************************************************************************/
68 
70 typedef enum
71 {
76 
78 typedef enum
79 {
85 
86 
88 typedef enum
89 {
94 #if defined( _DAC_CH0CTRL_PRSSEL_PRSCH4 )
96 #endif
97 #if defined( _DAC_CH0CTRL_PRSSEL_PRSCH5 )
99 #endif
100 #if defined( _DAC_CH0CTRL_PRSSEL_PRSCH6 )
102 #endif
103 #if defined( _DAC_CH0CTRL_PRSSEL_PRSCH7 )
105 #endif
106 #if defined( _DAC_CH0CTRL_PRSSEL_PRSCH8 )
108 #endif
109 #if defined( _DAC_CH0CTRL_PRSSEL_PRSCH9 )
111 #endif
112 #if defined( _DAC_CH0CTRL_PRSSEL_PRSCH10 )
114 #endif
115 #if defined( _DAC_CH0CTRL_PRSSEL_PRSCH11 )
117 #endif
119 
120 
122 typedef enum
123 {
128 
129 
131 typedef enum
132 {
138 
139 
140 /*******************************************************************************
141  ******************************* STRUCTS ***********************************
142  ******************************************************************************/
143 
145 typedef struct
146 {
149 
152 
155 
158 
163  uint8_t prescale;
164 
166  bool lpEnable;
167 
170 
173 
176 
178  bool diff;
180 
182 #define DAC_INIT_DEFAULT \
183 { \
184  dacRefresh8, /* Refresh every 8 prescaled cycles. */ \
185  dacRef1V25, /* 1.25V internal reference. */ \
186  dacOutputPin, /* Output to pin only. */ \
187  dacConvModeContinuous, /* Continuous mode. */ \
188  0, /* No prescaling. */ \
189  false, /* Do not enable low pass filter. */ \
190  false, /* Do not reset prescaler on ch0 start. */ \
191  false, /* DAC output enable always on. */ \
192  false, /* Disable sine mode. */ \
193  false /* Single ended mode. */ \
194 }
195 
196 
198 typedef struct
199 {
201  bool enable;
202 
207  bool prsEnable;
208 
214 
221 
223 #define DAC_INITCHANNEL_DEFAULT \
224 { \
225  false, /* Leave channel disabled when init done. */ \
226  false, /* Disable PRS triggering. */ \
227  false, /* Channel not refreshed automatically. */ \
228  dacPRSSELCh0 /* Select PRS ch0 (if PRS triggering enabled). */ \
229 }
230 
231 
232 /*******************************************************************************
233  ***************************** PROTOTYPES **********************************
234  ******************************************************************************/
235 
236 void DAC_Enable(DAC_TypeDef *dac, unsigned int ch, bool enable);
237 void DAC_Init(DAC_TypeDef *dac, const DAC_Init_TypeDef *init);
238 void DAC_InitChannel(DAC_TypeDef *dac,
239  const DAC_InitChannel_TypeDef *init,
240  unsigned int ch);
242  unsigned int channel,
243  uint32_t value);
244 
245 /***************************************************************************/
259 __STATIC_INLINE void DAC_Channel0OutputSet( DAC_TypeDef *dac,
260  uint32_t value )
261 {
262  EFM_ASSERT(value<=_DAC_CH0DATA_MASK);
263  dac->CH0DATA = value;
264 }
265 
266 
267 /***************************************************************************/
281 __STATIC_INLINE void DAC_Channel1OutputSet( DAC_TypeDef *dac,
282  uint32_t value )
283 {
284  EFM_ASSERT(value<=_DAC_CH1DATA_MASK);
285  dac->CH1DATA = value;
286 }
287 
288 
289 /***************************************************************************/
300 __STATIC_INLINE void DAC_IntClear(DAC_TypeDef *dac, uint32_t flags)
301 {
302  dac->IFC = flags;
303 }
304 
305 
306 /***************************************************************************/
317 __STATIC_INLINE void DAC_IntDisable(DAC_TypeDef *dac, uint32_t flags)
318 {
319  dac->IEN &= ~flags;
320 }
321 
322 
323 /***************************************************************************/
339 __STATIC_INLINE void DAC_IntEnable(DAC_TypeDef *dac, uint32_t flags)
340 {
341  dac->IEN |= flags;
342 }
343 
344 
345 /***************************************************************************/
359 __STATIC_INLINE uint32_t DAC_IntGet(DAC_TypeDef *dac)
360 {
361  return dac->IF;
362 }
363 
364 
365 /***************************************************************************/
384 __STATIC_INLINE uint32_t DAC_IntGetEnabled(DAC_TypeDef *dac)
385 {
386  uint32_t ien;
387 
388  /* Store DAC->IEN in temporary variable in order to define explicit order
389  * of volatile accesses. */
390  ien = dac->IEN;
391 
392  /* Bitwise AND of pending and enabled interrupts */
393  return dac->IF & ien;
394 }
395 
396 
397 /***************************************************************************/
408 __STATIC_INLINE void DAC_IntSet(DAC_TypeDef *dac, uint32_t flags)
409 {
410  dac->IFS = flags;
411 }
412 
413 uint8_t DAC_PrescaleCalc(uint32_t dacFreq, uint32_t hfperFreq);
414 void DAC_Reset(DAC_TypeDef *dac);
415 
419 #ifdef __cplusplus
420 }
421 #endif
422 
423 #endif /* defined(DAC_COUNT) && (DAC_COUNT > 0) */
424 #endif /* EM_DAC_H */
#define _DAC_CH0CTRL_PRSSEL_PRSCH11
Definition: efm32gg_dac.h:189
#define _DAC_CH0CTRL_PRSSEL_PRSCH1
Definition: efm32gg_dac.h:179
DAC_PRSSEL_TypeDef
Definition: em_dac.h:88
Emlib peripheral API "assert" implementation.
void DAC_Enable(DAC_TypeDef *dac, unsigned int ch, bool enable)
Enable/disable DAC channel.
Definition: em_dac.c:86
__IOM uint32_t IEN
Definition: efm32gg_dac.h:47
DAC_Refresh_TypeDef
Definition: em_dac.h:131
DAC_Ref_TypeDef reference
Definition: em_dac.h:151
#define _DAC_CTRL_CONVMODE_CONTINUOUS
Definition: efm32gg_dac.h:85
void DAC_InitChannel(DAC_TypeDef *dac, const DAC_InitChannel_TypeDef *init, unsigned int ch)
Initialize DAC channel.
Definition: em_dac.c:193
bool outEnablePRS
Definition: em_dac.h:172
__IOM uint32_t CH0DATA
Definition: efm32gg_dac.h:51
uint8_t DAC_PrescaleCalc(uint32_t dacFreq, uint32_t hfperFreq)
Calculate prescaler value used to determine DAC clock.
Definition: em_dac.c:287
#define _DAC_CTRL_REFRSEL_16CYCLES
Definition: efm32gg_dac.h:134
#define _DAC_CH0CTRL_PRSSEL_PRSCH2
Definition: efm32gg_dac.h:180
#define _DAC_CTRL_REFRSEL_32CYCLES
Definition: efm32gg_dac.h:135
DAC_Output_TypeDef
Definition: em_dac.h:78
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
#define _DAC_CTRL_OUTMODE_PIN
Definition: efm32gg_dac.h:96
#define _DAC_CTRL_REFSEL_VDD
Definition: efm32gg_dac.h:119
DAC_Refresh_TypeDef refresh
Definition: em_dac.h:148
DAC_Ref_TypeDef
Definition: em_dac.h:122
__IOM uint32_t IFC
Definition: efm32gg_dac.h:50
#define _DAC_CH1DATA_MASK
Definition: efm32gg_dac.h:357
#define _DAC_CH0CTRL_PRSSEL_PRSCH9
Definition: efm32gg_dac.h:187
__STATIC_INLINE void DAC_IntEnable(DAC_TypeDef *dac, uint32_t flags)
Enable one or more DAC interrupts.
Definition: em_dac.h:339
#define _DAC_CH0CTRL_PRSSEL_PRSCH3
Definition: efm32gg_dac.h:181
#define _DAC_CTRL_REFRSEL_8CYCLES
Definition: efm32gg_dac.h:133
__STATIC_INLINE void DAC_IntClear(DAC_TypeDef *dac, uint32_t flags)
Clear one or more pending DAC interrupts.
Definition: em_dac.h:300
DAC_ConvMode_TypeDef
Definition: em_dac.h:70
__IM uint32_t IF
Definition: efm32gg_dac.h:48
__IOM uint32_t CH1DATA
Definition: efm32gg_dac.h:52
__STATIC_INLINE void DAC_Channel0OutputSet(DAC_TypeDef *dac, uint32_t value)
Set the output signal of DAC channel 0 to a given value.
Definition: em_dac.h:259
__STATIC_INLINE void DAC_Channel1OutputSet(DAC_TypeDef *dac, uint32_t value)
Set the output signal of DAC channel 1 to a given value.
Definition: em_dac.h:281
#define _DAC_CH0CTRL_PRSSEL_PRSCH0
Definition: efm32gg_dac.h:178
DAC_Output_TypeDef outMode
Definition: em_dac.h:154
#define _DAC_CTRL_CONVMODE_SAMPLEHOLD
Definition: efm32gg_dac.h:86
bool sineEnable
Definition: em_dac.h:175
#define _DAC_CH0CTRL_PRSSEL_PRSCH4
Definition: efm32gg_dac.h:182
__IOM uint32_t IFS
Definition: efm32gg_dac.h:49
__STATIC_INLINE void DAC_IntSet(DAC_TypeDef *dac, uint32_t flags)
Set one or more pending DAC interrupts from SW.
Definition: em_dac.h:408
#define _DAC_CTRL_OUTMODE_PINADC
Definition: efm32gg_dac.h:98
__STATIC_INLINE void DAC_IntDisable(DAC_TypeDef *dac, uint32_t flags)
Disable one or more DAC interrupts.
Definition: em_dac.h:317
uint8_t prescale
Definition: em_dac.h:163
#define _DAC_CTRL_CONVMODE_SAMPLEOFF
Definition: efm32gg_dac.h:87
DAC_ConvMode_TypeDef convMode
Definition: em_dac.h:157
void DAC_Reset(DAC_TypeDef *dac)
Reset DAC to same state as after a HW reset.
Definition: em_dac.c:330
#define _DAC_CTRL_OUTMODE_DISABLE
Definition: efm32gg_dac.h:94
DAC_PRSSEL_TypeDef prsSel
Definition: em_dac.h:219
#define _DAC_CTRL_REFSEL_1V25
Definition: efm32gg_dac.h:117
#define _DAC_CH0CTRL_PRSSEL_PRSCH8
Definition: efm32gg_dac.h:186
#define _DAC_CH0CTRL_PRSSEL_PRSCH7
Definition: efm32gg_dac.h:185
#define _DAC_CH0CTRL_PRSSEL_PRSCH10
Definition: efm32gg_dac.h:188
#define _DAC_CH0DATA_MASK
Definition: efm32gg_dac.h:349
bool ch0ResetPre
Definition: em_dac.h:169
void DAC_ChannelOutputSet(DAC_TypeDef *dac, unsigned int channel, uint32_t value)
Set the output signal of a DAC channel to a given value.
Definition: em_dac.c:247
#define _DAC_CTRL_REFRSEL_64CYCLES
Definition: efm32gg_dac.h:136
#define _DAC_CH0CTRL_PRSSEL_PRSCH5
Definition: efm32gg_dac.h:183
void DAC_Init(DAC_TypeDef *dac, const DAC_Init_TypeDef *init)
Initialize DAC.
Definition: em_dac.c:123
__STATIC_INLINE uint32_t DAC_IntGetEnabled(DAC_TypeDef *dac)
Get enabled and pending DAC interrupt flags. Useful for handling more interrupt sources in the same i...
Definition: em_dac.h:384
#define _DAC_CH0CTRL_PRSSEL_PRSCH6
Definition: efm32gg_dac.h:184
__STATIC_INLINE uint32_t DAC_IntGet(DAC_TypeDef *dac)
Get pending DAC interrupt flags.
Definition: em_dac.h:359
#define _DAC_CTRL_REFSEL_2V5
Definition: efm32gg_dac.h:118
#define _DAC_CTRL_OUTMODE_ADC
Definition: efm32gg_dac.h:97