emlib/src/em_vdac.c
void VDAC_Init(VDAC_TypeDef *vdac, const VDAC_Init_TypeDef *init)
{
  uint32_t cal, tmp = 0;
  uint32_t const volatile *calData;

  EFM_ASSERT(VDAC_REF_VALID(vdac));

  /* Make sure both channels are disabled. */
  vdac->CMD = VDAC_CMD_CH0DIS | VDAC_CMD_CH1DIS;
  while (vdac->STATUS & (VDAC_STATUS_CH0ENS | VDAC_STATUS_CH1ENS)) ;

  /* Get OFFSETTRIM calibration value. */
  cal = ((DEVINFO->VDAC0CH1CAL & _DEVINFO_VDAC0CH1CAL_OFFSETTRIM_MASK)
         >> _DEVINFO_VDAC0CH1CAL_OFFSETTRIM_SHIFT)
        << _VDAC_CAL_OFFSETTRIM_SHIFT;

  if (init->mainCalibration) {
    calData = &DEVINFO->VDAC0MAINCAL;
  } else {
    calData = &DEVINFO->VDAC0ALTCAL;
  }

  /* Get correct GAINERRTRIM calibration value. */
  switch (init->reference) {
    case vdacRef1V25Ln:
      tmp = (*calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25LN_MASK)
            >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25LN_SHIFT;
      break;

    case vdacRef2V5Ln:
      tmp = (*calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5LN_MASK)
            >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5LN_SHIFT;
      break;

    case vdacRef1V25:
      tmp = (*calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25_MASK)
            >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25_SHIFT;
      break;

    case vdacRef2V5:
      tmp = (*calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5_MASK)
            >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5_SHIFT;
      break;

    case vdacRefAvdd:
    case vdacRefExtPin:
      tmp = (*calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIMVDDANAEXTPIN_MASK)
            >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIMVDDANAEXTPIN_SHIFT;
      break;
  }

  /* Set GAINERRTRIM calibration value. */
  cal |= tmp << _VDAC_CAL_GAINERRTRIM_SHIFT;

  /* Get GAINERRTRIMCH1 calibration value. */
  switch (init->reference) {
    case vdacRef1V25Ln:
    case vdacRef1V25:
    case vdacRefAvdd:
    case vdacRefExtPin:
      tmp = (DEVINFO->VDAC0CH1CAL && _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1A_MASK)
            >> _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1A_SHIFT;
      break;

    case vdacRef2V5Ln:
    case vdacRef2V5:
      tmp = (DEVINFO->VDAC0CH1CAL && _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1B_MASK)
            >> _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1B_SHIFT;
      break;
  }

  /* Set GAINERRTRIM calibration value. */
  cal |= tmp << _VDAC_CAL_GAINERRTRIMCH1_SHIFT;

  tmp = ((uint32_t)init->asyncClockMode << _VDAC_CTRL_DACCLKMODE_SHIFT)
        | ((uint32_t)init->warmupKeepOn << _VDAC_CTRL_WARMUPMODE_SHIFT)
        | ((uint32_t)init->refresh      << _VDAC_CTRL_REFRESHPERIOD_SHIFT)
        | (((uint32_t)init->prescaler   << _VDAC_CTRL_PRESC_SHIFT)
           & _VDAC_CTRL_PRESC_MASK)
        | ((uint32_t)init->reference    << _VDAC_CTRL_REFSEL_SHIFT)
        | ((uint32_t)init->ch0ResetPre  << _VDAC_CTRL_CH0PRESCRST_SHIFT)
        | ((uint32_t)init->outEnablePRS << _VDAC_CTRL_OUTENPRS_SHIFT)
        | ((uint32_t)init->sineEnable   << _VDAC_CTRL_SINEMODE_SHIFT)
        | ((uint32_t)init->diff         << _VDAC_CTRL_DIFF_SHIFT);

  /* Write to VDAC registers. */
  vdac->CAL = cal;
  vdac->CTRL = tmp;
}
/***************************************************************************/
/**
 * @brief
 *   Initialize VDAC.
 *
 * @details
 *   Initializes common parts for both channels. This function will also load
 *   calibration values from the Device Information (DI) page into the VDAC
 *   calibration register.
 *   To complete a VDAC setup, channel control configuration must also be done,
 *   please refer to VDAC_InitChannel().
 *
 * @note
 *   This function will disable both channels prior to configuration.
 *
 * @param[in] vdac
 *   Pointer to VDAC peripheral register block.
 *
 * @param[in] init
 *   Pointer to VDAC initialization structure.
 ******************************************************************************/
@brief
Initialize VDAC.

@details
Initializes common parts for both channels. This function will also load
calibration values from the Device Information (DI) page into the VDAC
calibration register.
To complete a VDAC setup, channel control configuration must also be done,
please refer to VDAC_InitChannel().

@note
This function will disable both channels prior to configuration.

@param[in] vdac
Pointer to VDAC peripheral register block.

@param[in] init
Pointer to VDAC initialization structure.
@brief Initialize VDAC . @details Initializes common parts for both channels . This function will also load calibration values from the Device Information ( DI ) page into the VDAC calibration register . To complete a VDAC setup channel control configuration must also be done please refer to VDAC_InitChannel () . @note This function will disable both channels prior to configuration . @param [ in ] vdac Pointer to VDAC peripheral register block . @param [ in ] init Pointer to VDAC initialization structure .
void VDAC_Init(VDAC_TypeDef *vdac, const VDAC_Init_TypeDef *init)
{
  uint32_t cal, tmp = 0;
  uint32_t const volatile *calData;
  EFM_ASSERT(VDAC_REF_VALID(vdac));
  vdac->CMD = VDAC_CMD_CH0DIS | VDAC_CMD_CH1DIS;
  while (vdac->STATUS & (VDAC_STATUS_CH0ENS | VDAC_STATUS_CH1ENS)) ;
  cal = ((DEVINFO->VDAC0CH1CAL & _DEVINFO_VDAC0CH1CAL_OFFSETTRIM_MASK)
         >> _DEVINFO_VDAC0CH1CAL_OFFSETTRIM_SHIFT)
        << _VDAC_CAL_OFFSETTRIM_SHIFT;
  if (init->mainCalibration) {
    calData = &DEVINFO->VDAC0MAINCAL;
  } else {
    calData = &DEVINFO->VDAC0ALTCAL;
  }
  switch (init->reference) {
    case vdacRef1V25Ln:
      tmp = (*calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25LN_MASK)
            >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25LN_SHIFT;
      break;
    case vdacRef2V5Ln:
      tmp = (*calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5LN_MASK)
            >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5LN_SHIFT;
      break;
    case vdacRef1V25:
      tmp = (*calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25_MASK)
            >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25_SHIFT;
      break;
    case vdacRef2V5:
      tmp = (*calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5_MASK)
            >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5_SHIFT;
      break;
    case vdacRefAvdd:
    case vdacRefExtPin:
      tmp = (*calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIMVDDANAEXTPIN_MASK)
            >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIMVDDANAEXTPIN_SHIFT;
      break;
  }
  cal |= tmp << _VDAC_CAL_GAINERRTRIM_SHIFT;
  switch (init->reference) {
    case vdacRef1V25Ln:
    case vdacRef1V25:
    case vdacRefAvdd:
    case vdacRefExtPin:
      tmp = (DEVINFO->VDAC0CH1CAL && _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1A_MASK)
            >> _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1A_SHIFT;
      break;
    case vdacRef2V5Ln:
    case vdacRef2V5:
      tmp = (DEVINFO->VDAC0CH1CAL && _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1B_MASK)
            >> _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1B_SHIFT;
      break;
  }
  cal |= tmp << _VDAC_CAL_GAINERRTRIMCH1_SHIFT;
  tmp = ((uint32_t)init->asyncClockMode << _VDAC_CTRL_DACCLKMODE_SHIFT)
        | ((uint32_t)init->warmupKeepOn << _VDAC_CTRL_WARMUPMODE_SHIFT)
        | ((uint32_t)init->refresh      << _VDAC_CTRL_REFRESHPERIOD_SHIFT)
        | (((uint32_t)init->prescaler   << _VDAC_CTRL_PRESC_SHIFT)
           & _VDAC_CTRL_PRESC_MASK)
        | ((uint32_t)init->reference    << _VDAC_CTRL_REFSEL_SHIFT)
        | ((uint32_t)init->ch0ResetPre  << _VDAC_CTRL_CH0PRESCRST_SHIFT)
        | ((uint32_t)init->outEnablePRS << _VDAC_CTRL_OUTENPRS_SHIFT)
        | ((uint32_t)init->sineEnable   << _VDAC_CTRL_SINEMODE_SHIFT)
        | ((uint32_t)init->diff         << _VDAC_CTRL_DIFF_SHIFT);
  vdac->CAL = cal;
  vdac->CTRL = tmp;
}
void VDAC_Init ( VDAC_TypeDef * vdac , const VDAC_Init_TypeDef * init ) { uint32_t cal , tmp = 0 ; uint32_t const volatile * calData ; EFM_ASSERT ( VDAC_REF_VALID ( vdac ) ) ; vdac -> CMD = VDAC_CMD_CH0DIS | VDAC_CMD_CH1DIS ; while ( vdac -> STATUS & ( VDAC_STATUS_CH0ENS | VDAC_STATUS_CH1ENS ) ) ; cal = ( ( DEVINFO -> VDAC0CH1CAL & _DEVINFO_VDAC0CH1CAL_OFFSETTRIM_MASK ) >> _DEVINFO_VDAC0CH1CAL_OFFSETTRIM_SHIFT ) << _VDAC_CAL_OFFSETTRIM_SHIFT ; if ( init -> mainCalibration ) { calData = & DEVINFO -> VDAC0MAINCAL ; } else { calData = & DEVINFO -> VDAC0ALTCAL ; } switch ( init -> reference ) { case vdacRef1V25Ln : tmp = ( * calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25LN_MASK ) >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25LN_SHIFT ; break ; case vdacRef2V5Ln : tmp = ( * calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5LN_MASK ) >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5LN_SHIFT ; break ; case vdacRef1V25 : tmp = ( * calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25_MASK ) >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIM1V25_SHIFT ; break ; case vdacRef2V5 : tmp = ( * calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5_MASK ) >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIM2V5_SHIFT ; break ; case vdacRefAvdd : case vdacRefExtPin : tmp = ( * calData & _DEVINFO_VDAC0MAINCAL_GAINERRTRIMVDDANAEXTPIN_MASK ) >> _DEVINFO_VDAC0MAINCAL_GAINERRTRIMVDDANAEXTPIN_SHIFT ; break ; } cal |= tmp << _VDAC_CAL_GAINERRTRIM_SHIFT ; switch ( init -> reference ) { case vdacRef1V25Ln : case vdacRef1V25 : case vdacRefAvdd : case vdacRefExtPin : tmp = ( DEVINFO -> VDAC0CH1CAL && _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1A_MASK ) >> _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1A_SHIFT ; break ; case vdacRef2V5Ln : case vdacRef2V5 : tmp = ( DEVINFO -> VDAC0CH1CAL && _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1B_MASK ) >> _DEVINFO_VDAC0CH1CAL_GAINERRTRIMCH1B_SHIFT ; break ; } cal |= tmp << _VDAC_CAL_GAINERRTRIMCH1_SHIFT ; tmp = ( ( uint32_t ) init -> asyncClockMode << _VDAC_CTRL_DACCLKMODE_SHIFT ) | ( ( uint32_t ) init -> warmupKeepOn << _VDAC_CTRL_WARMUPMODE_SHIFT ) | ( ( uint32_t ) init -> refresh << _VDAC_CTRL_REFRESHPERIOD_SHIFT ) | ( ( ( uint32_t ) init -> prescaler << _VDAC_CTRL_PRESC_SHIFT ) & _VDAC_CTRL_PRESC_MASK ) | ( ( uint32_t ) init -> reference << _VDAC_CTRL_REFSEL_SHIFT ) | ( ( uint32_t ) init -> ch0ResetPre << _VDAC_CTRL_CH0PRESCRST_SHIFT ) | ( ( uint32_t ) init -> outEnablePRS << _VDAC_CTRL_OUTENPRS_SHIFT ) | ( ( uint32_t ) init -> sineEnable << _VDAC_CTRL_SINEMODE_SHIFT ) | ( ( uint32_t ) init -> diff << _VDAC_CTRL_DIFF_SHIFT ) ; vdac -> CAL = cal ; vdac -> CTRL = tmp ; }
@brief
   Initialize VDAC.
@brief Initialize VDAC .
/* Make sure both channels are disabled. */ /* Get OFFSETTRIM calibration value. */ /* Get correct GAINERRTRIM calibration value. */ /* Set GAINERRTRIM calibration value. */ /* Get GAINERRTRIMCH1 calibration value. */ /* Set GAINERRTRIM calibration value. */ /* Write to VDAC registers. */