34 #if defined(DAC_COUNT) && (DAC_COUNT > 0)
62 #define DAC_CH_VALID(ch) ((ch) <= 1)
65 #define DAC_MAX_CLOCK 1000000
86 void DAC_Enable(DAC_TypeDef *dac,
unsigned int ch,
bool enable)
88 volatile uint32_t *reg;
90 EFM_ASSERT(DAC_REF_VALID(dac));
91 EFM_ASSERT(DAC_CH_VALID(ch));
95 reg = &(dac->CH0CTRL);
99 reg = &(dac->CH1CTRL);
123 void DAC_Init(DAC_TypeDef *dac,
const DAC_Init_TypeDef *init)
127 EFM_ASSERT(DAC_REF_VALID(dac));
134 switch (init->reference)
149 tmp = ((uint32_t)(init->refresh) << _DAC_CTRL_REFRSEL_SHIFT)
150 | (((uint32_t)(init->prescale) << _DAC_CTRL_PRESC_SHIFT)
151 & _DAC_CTRL_PRESC_MASK)
152 | ((uint32_t)(init->reference) << _DAC_CTRL_REFSEL_SHIFT)
153 | ((uint32_t)(init->outMode) << _DAC_CTRL_OUTMODE_SHIFT)
154 | ((uint32_t)(init->convMode) << _DAC_CTRL_CONVMODE_SHIFT);
156 if (init->ch0ResetPre)
158 tmp |= DAC_CTRL_CH0PRESCRST;
161 if (init->outEnablePRS)
163 tmp |= DAC_CTRL_OUTENPRS;
166 if (init->sineEnable)
168 tmp |= DAC_CTRL_SINEMODE;
173 tmp |= DAC_CTRL_DIFF;
193 void DAC_InitChannel(DAC_TypeDef *dac,
194 const DAC_InitChannel_TypeDef *init,
199 EFM_ASSERT(DAC_REF_VALID(dac));
200 EFM_ASSERT(DAC_CH_VALID(ch));
202 tmp = (uint32_t)(init->prsSel) << _DAC_CH0CTRL_PRSSEL_SHIFT;
206 tmp |= DAC_CH0CTRL_EN;
211 tmp |= DAC_CH0CTRL_PRSEN;
214 if (init->refreshEnable)
216 tmp |= DAC_CH0CTRL_REFREN;
247 void DAC_ChannelOutputSet( DAC_TypeDef *dac,
248 unsigned int channel,
254 DAC_Channel0OutputSet(dac, value);
257 DAC_Channel1OutputSet(dac, value);
287 uint8_t DAC_PrescaleCalc(uint32_t dacFreq, uint32_t hfperFreq)
292 if (dacFreq > DAC_MAX_CLOCK)
294 dacFreq = DAC_MAX_CLOCK;
306 for (ret = 0; ret <= (_DAC_CTRL_PRESC_MASK >> _DAC_CTRL_PRESC_SHIFT); ret++)
308 if ((hfperFreq >> ret) <= dacFreq)
314 if (ret > (_DAC_CTRL_PRESC_MASK >> _DAC_CTRL_PRESC_SHIFT))
316 ret = _DAC_CTRL_PRESC_MASK >> _DAC_CTRL_PRESC_SHIFT;
330 void DAC_Reset(DAC_TypeDef *dac)
333 dac->CH0CTRL = _DAC_CH0CTRL_RESETVALUE;
334 dac->CH1CTRL = _DAC_CH1CTRL_RESETVALUE;
335 dac->CTRL = _DAC_CTRL_RESETVALUE;
336 dac->IEN = _DAC_IEN_RESETVALUE;
337 dac->IFC = _DAC_IFC_MASK;
339 dac->BIASPROG = _DAC_BIASPROG_RESETVALUE;
Clock management unit (CMU) API.
Emlib peripheral API "assert" implementation.
RAM and peripheral bit-field set and clear API.
Digital to Analog Converter (DAC) peripheral API.
__STATIC_INLINE void BUS_RegBitWrite(volatile uint32_t *addr, unsigned int bit, unsigned int val)
Perform a single-bit write operation on a peripheral register.
uint32_t CMU_ClockFreqGet(CMU_Clock_TypeDef clock)
Get clock frequency for a clock point.