34 #if defined(VDAC_COUNT) && (VDAC_COUNT > 0)
54 #define VDAC_CH_VALID(ch) ((ch) <= 1)
57 #define VDAC_MAX_CLOCK 1000000
60 #define VDAC_INTERNAL_CLOCK_FREQ 12000000
81 void VDAC_Enable(VDAC_TypeDef *vdac,
unsigned int ch,
bool enable)
83 EFM_ASSERT(VDAC_REF_VALID(vdac));
84 EFM_ASSERT(VDAC_CH_VALID(ch));
90 vdac->CMD = VDAC_CMD_CH0EN;
94 vdac->CMD = VDAC_CMD_CH0DIS;
95 while (vdac->STATUS & VDAC_STATUS_CH0ENS);
102 vdac->CMD = VDAC_CMD_CH1EN;
106 vdac->CMD = VDAC_CMD_CH1DIS;
107 while (vdac->STATUS & VDAC_STATUS_CH1ENS);
132 void VDAC_Init(VDAC_TypeDef *vdac,
const VDAC_Init_TypeDef *init)
134 uint32_t cal, tmp = 0;
135 uint32_t
const volatile *calData;
137 EFM_ASSERT(VDAC_REF_VALID(vdac));
140 vdac->CMD = VDAC_CMD_CH0DIS | VDAC_CMD_CH1DIS;
141 while (vdac->STATUS & (VDAC_STATUS_CH0ENS | VDAC_STATUS_CH1ENS));
144 cal = ((
DEVINFO->VDAC0CH1CAL & _DEVINFO_VDAC0CH1CAL_OFFSETTRIM_MASK)
145 >> _DEVINFO_VDAC0CH1CAL_OFFSETTRIM_SHIFT)
146 << _VDAC_CAL_OFFSETTRIM_SHIFT;
148 if (init->mainCalibration)
150 calData = &
DEVINFO->VDAC0MAINCAL;
154 calData = &
DEVINFO->VDAC0ALTCAL;
158 switch (init->reference)
161 tmp = (*calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25LN_MASK)
162 >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25LN_SHIFT;
166 tmp = (*calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5LN_MASK)
167 >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5LN_SHIFT;
171 tmp = (*calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25_MASK)
172 >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25_SHIFT;
176 tmp = (*calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5_MASK)
177 >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5_SHIFT;
182 tmp = (*calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIMVDDANAEXTPIN_MASK)
183 >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIMVDDANAEXTPIN_SHIFT;
188 cal |= tmp << _VDAC_CAL_GAINERRTRIM_SHIFT;
191 switch (init->reference)
197 tmp = (
DEVINFO->VDAC0CH1CAL && _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1A_MASK)
198 >> _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1A_SHIFT;
203 tmp = (
DEVINFO->VDAC0CH1CAL && _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1B_MASK)
204 >> _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1B_SHIFT;
209 cal |= tmp << _VDAC_CAL_GAINERRTRIMCH1_SHIFT;
211 tmp = ((uint32_t)init->asyncClockMode << _VDAC_CTRL_DACCLKMODE_SHIFT)
212 | ((uint32_t)init->warmupKeepOn << _VDAC_CTRL_WARMUPMODE_SHIFT)
213 | ((uint32_t)init->refresh << _VDAC_CTRL_REFRESHPERIOD_SHIFT)
214 | (((uint32_t)init->prescaler << _VDAC_CTRL_PRESC_SHIFT)
215 & _VDAC_CTRL_PRESC_MASK)
216 | ((uint32_t)init->reference << _VDAC_CTRL_REFSEL_SHIFT)
217 | ((uint32_t)init->ch0ResetPre << _VDAC_CTRL_CH0PRESCRST_SHIFT)
218 | ((uint32_t)init->outEnablePRS << _VDAC_CTRL_OUTENPRS_SHIFT)
219 | ((uint32_t)init->sineEnable << _VDAC_CTRL_SINEMODE_SHIFT)
220 | ((uint32_t)init->diff << _VDAC_CTRL_DIFF_SHIFT);
240 void VDAC_InitChannel(VDAC_TypeDef *vdac,
241 const VDAC_InitChannel_TypeDef *init,
244 uint32_t vdacChCtrl, vdacStatus;
246 EFM_ASSERT(VDAC_REF_VALID(vdac));
247 EFM_ASSERT(VDAC_CH_VALID(ch));
250 vdacStatus = vdac->STATUS;
251 vdac->CMD = VDAC_CMD_CH0DIS | VDAC_CMD_CH1DIS;
252 while (vdac->STATUS & (VDAC_STATUS_CH0ENS | VDAC_STATUS_CH1ENS));
254 vdacChCtrl = ((uint32_t)init->prsSel << _VDAC_CH0CTRL_PRSSEL_SHIFT)
255 | ((uint32_t)init->prsAsync << _VDAC_CH0CTRL_PRSASYNC_SHIFT)
256 | ((uint32_t)init->trigMode << _VDAC_CH0CTRL_TRIGMODE_SHIFT)
257 | ((uint32_t)init->sampleOffMode << _VDAC_CH0CTRL_CONVMODE_SHIFT);
261 vdac->CH0CTRL = vdacChCtrl;
265 vdac->CH1CTRL = vdacChCtrl;
273 vdac->CMD = VDAC_CMD_CH0EN;
277 vdac->CMD = VDAC_CMD_CH1EN;
285 if (vdacStatus & VDAC_STATUS_CH1ENS)
287 vdac->CMD = VDAC_CMD_CH1EN;
292 if (vdacStatus & VDAC_STATUS_CH0ENS)
294 vdac->CMD = VDAC_CMD_CH0EN;
316 void VDAC_ChannelOutputSet(VDAC_TypeDef *vdac,
317 unsigned int channel,
323 VDAC_Channel0OutputSet(vdac, value);
326 VDAC_Channel1OutputSet(vdac, value);
366 uint32_t VDAC_PrescaleCalc(uint32_t vdacFreq,
bool syncMode, uint32_t hfperFreq)
368 uint32_t ret, refFreq;
371 if (vdacFreq > VDAC_MAX_CLOCK)
373 vdacFreq = VDAC_MAX_CLOCK;
378 refFreq = VDAC_INTERNAL_CLOCK_FREQ;
395 for (ret = 0; ret <= _VDAC_CTRL_PRESC_MASK >> _VDAC_CTRL_PRESC_SHIFT; ret++)
397 if ((refFreq / (ret + 1)) <= vdacFreq)
405 if (ret > (_VDAC_CTRL_PRESC_MASK >> _VDAC_CTRL_PRESC_SHIFT))
407 ret = _VDAC_CTRL_PRESC_MASK >> _VDAC_CTRL_PRESC_SHIFT;
420 void VDAC_Reset(VDAC_TypeDef *vdac)
423 vdac->CMD = VDAC_CMD_CH0DIS | VDAC_CMD_CH1DIS;
424 while (vdac->STATUS & (VDAC_STATUS_CH0ENS | VDAC_STATUS_CH1ENS));
425 vdac->CH0CTRL = _VDAC_CH0CTRL_RESETVALUE;
426 vdac->CH1CTRL = _VDAC_CH1CTRL_RESETVALUE;
427 vdac->CH0DATA = _VDAC_CH0DATA_RESETVALUE;
428 vdac->CH1DATA = _VDAC_CH1DATA_RESETVALUE;
429 vdac->CTRL = _VDAC_CTRL_RESETVALUE;
430 vdac->IEN = _VDAC_IEN_RESETVALUE;
431 vdac->IFC = _VDAC_IFC_MASK;
432 vdac->CAL = _VDAC_CAL_RESETVALUE;
Clock management unit (CMU) API.
Digital to Analog Converter (VDAC) peripheral API.
uint32_t CMU_ClockFreqGet(CMU_Clock_TypeDef clock)
Get clock frequency for a clock point.