em_idac.c

Go to the documentation of this file.
00001 /***************************************************************************/
00034 #include "em_idac.h"
00035 #if defined(IDAC_COUNT) && (IDAC_COUNT > 0)
00036 #include "em_cmu.h"
00037 #include "em_assert.h"
00038 #include "em_bitband.h"
00039 
00040 /***************************************************************************/
00045 /***************************************************************************/
00051 /*******************************************************************************
00052  **************************   GLOBAL FUNCTIONS   *******************************
00053  ******************************************************************************/
00054 /***************************************************************************/
00071 void IDAC_Init(IDAC_TypeDef *idac, const IDAC_Init_TypeDef *init)
00072 {
00073   uint32_t tmp;
00074 
00075   EFM_ASSERT(IDAC_REF_VALID(idac));
00076 
00077   tmp = (uint32_t)(init->prsSel);
00078 
00079   tmp |= init->outMode;
00080 
00081   if (init->enable)
00082   {
00083     tmp |= IDAC_CTRL_EN;
00084   }
00085   if (init->prsEnable)
00086   {
00087     tmp |= IDAC_CTRL_OUTENPRS;
00088   }
00089   if (init->sinkEnable)
00090   {
00091     tmp |= IDAC_CTRL_CURSINK;
00092   }
00093 
00094   idac->CTRL = tmp;
00095 }
00096 
00097 
00098 /***************************************************************************/
00108 void IDAC_Enable(IDAC_TypeDef *idac, bool enable)
00109 {
00110   volatile uint32_t *reg;
00111 
00112   EFM_ASSERT(IDAC_REF_VALID(idac));
00113 
00114   reg = &(idac->CTRL);
00115 
00116   BITBAND_Peripheral(reg, _IDAC_CTRL_EN_SHIFT, (unsigned int) enable);
00117 }
00118 
00119 
00120 /***************************************************************************/
00127 void IDAC_Reset(IDAC_TypeDef *idac)
00128 {
00129   EFM_ASSERT(IDAC_REF_VALID(idac));
00130 
00131   idac->CTRL       = _IDAC_CTRL_RESETVALUE;
00132   idac->CURPROG    = _IDAC_CURPROG_RESETVALUE;
00133   idac->CAL        = _IDAC_CAL_RESETVALUE;
00134   idac->DUTYCONFIG = _IDAC_DUTYCONFIG_RESETVALUE;
00135 }
00136 
00137 
00138 /***************************************************************************/
00148 void IDAC_MinimalOutputTransitionMode(IDAC_TypeDef *idac, bool enable)
00149 {
00150   volatile uint32_t *reg;
00151 
00152   EFM_ASSERT(IDAC_REF_VALID(idac));
00153 
00154   reg = &(idac->CTRL);
00155 
00156   BITBAND_Peripheral(reg, _IDAC_CTRL_MINOUTTRANS_SHIFT, (unsigned int) enable);
00157 }
00158 
00159 
00160 /***************************************************************************/
00176 void IDAC_RangeSet(IDAC_TypeDef *idac, const IDAC_Range_TypeDef range)
00177 {
00178   uint32_t tmp;
00179 
00180   EFM_ASSERT(IDAC_REF_VALID(idac));
00181   EFM_ASSERT((range >> _IDAC_CURPROG_RANGESEL_SHIFT) <= (_IDAC_CURPROG_RANGESEL_MASK >> _IDAC_CURPROG_RANGESEL_SHIFT));
00182 
00183   /* Load proper calibration data depending on selected range */
00184   switch ((IDAC_Range_TypeDef) range)
00185   {
00186   case idacCurrentRange0:
00187     idac->CAL = (DEVINFO->IDAC0CAL0 & _DEVINFO_IDAC0CAL0_RANGE0_MASK) >> _DEVINFO_IDAC0CAL0_RANGE0_SHIFT;
00188     break;
00189   case idacCurrentRange1:
00190     idac->CAL = (DEVINFO->IDAC0CAL0 & _DEVINFO_IDAC0CAL0_RANGE1_MASK) >> _DEVINFO_IDAC0CAL0_RANGE1_SHIFT;
00191     break;
00192   case idacCurrentRange2:
00193     idac->CAL = (DEVINFO->IDAC0CAL0 & _DEVINFO_IDAC0CAL0_RANGE2_MASK) >> _DEVINFO_IDAC0CAL0_RANGE2_SHIFT;
00194     break;
00195   case idacCurrentRange3:
00196     idac->CAL = (DEVINFO->IDAC0CAL0 & _DEVINFO_IDAC0CAL0_RANGE3_MASK) >> _DEVINFO_IDAC0CAL0_RANGE3_SHIFT;
00197     break;
00198   }
00199 
00200   tmp  = idac->CURPROG & ~_IDAC_CURPROG_RANGESEL_MASK;
00201   tmp |= (uint32_t) range;
00202 
00203   idac->CURPROG = tmp;
00204 }
00205 
00206 
00207 /***************************************************************************/
00217 void IDAC_StepSet(IDAC_TypeDef *idac, const uint32_t step)
00218 {
00219   uint32_t tmp;
00220 
00221   EFM_ASSERT(IDAC_REF_VALID(idac));
00222   EFM_ASSERT(step <= (_IDAC_CURPROG_STEPSEL_MASK >> _IDAC_CURPROG_STEPSEL_SHIFT));
00223 
00224   tmp  = idac->CURPROG & ~_IDAC_CURPROG_STEPSEL_MASK;
00225   tmp |= step << _IDAC_CURPROG_STEPSEL_SHIFT;
00226 
00227   idac->CURPROG = tmp;
00228 }
00229 
00230 
00231 /***************************************************************************/
00241 void IDAC_OutEnable(IDAC_TypeDef *idac, bool enable)
00242 {
00243   volatile uint32_t *reg;
00244 
00245   EFM_ASSERT(IDAC_REF_VALID(idac));
00246 
00247   reg = &(idac->CTRL);
00248 
00249   BITBAND_Peripheral(reg, _IDAC_CTRL_OUTEN_SHIFT, (unsigned int) enable);
00250 }
00251 
00252 
00256 #endif /* defined(IDAC_COUNT) && (IDAC_COUNT > 0) */