emlib/src/em_csen.c
void CSEN_InitMode(CSEN_TypeDef *csen, const CSEN_InitMode_TypeDef *init)
{
  uint32_t tmp;

  EFM_ASSERT(CSEN_REF_VALID(csen));
  EFM_ASSERT(init->dmIterPerCycle < 0x10);
  EFM_ASSERT(init->dmCycles < 0x10);

  /* Initialize CTRL. This will stop any conversion in progress.
   * These composite inputs set multiple fields. They do not need
   * to be shifted. */
  tmp = ((uint32_t)init->sampleMode
         | (uint32_t)init->convSel
         | (uint32_t)init->cmpMode);

  tmp |= (init->trigSel << _CSEN_CTRL_STM_SHIFT)
         | (init->accMode << _CSEN_CTRL_ACU_SHIFT)
         | (init->sarRes << _CSEN_CTRL_SARCR_SHIFT);

  if (init->enableDma) {
    tmp |= CSEN_CTRL_DMAEN_ENABLE;
  }

  if (init->sumOnly) {
    tmp |= CSEN_CTRL_DRSF_ENABLE;
  }

  if (init->autoGnd) {
    tmp |= CSEN_CTRL_AUTOGND_ENABLE;
  }

  /* Preserve the fields that were initialized by CSEN_Init(). */
  tmp |= csen->CTRL & (_CSEN_CTRL_CPACCURACY_MASK
                       | _CSEN_CTRL_LOCALSENS_MASK
                       | _CSEN_CTRL_WARMUPMODE_MASK);

  csen->CTRL = tmp;

  /* EMACTRL only has one field */
  csen->EMACTRL = init->emaSample << _CSEN_EMACTRL_EMASAMPLE_SHIFT;

  /* CMPTHR only has one field */
  csen->CMPTHR = init->cmpThr << _CSEN_CMPTHR_CMPTHR_SHIFT;

  /* SINGLECTRL only has one field */
  csen->SINGLECTRL = init->singleSel << _CSEN_SINGLECTRL_SINGLESEL_SHIFT;

  /* Set all input enables */
  csen->SCANMASK0 = init->inputMask0;
  csen->SCANMASK1 = init->inputMask1;

  /* Initialize DMCFG. */
  tmp = (init->dmRes << _CSEN_DMCFG_CRMODE_SHIFT)
        | (init->dmCycles << _CSEN_DMCFG_DMCR_SHIFT)
        | (init->dmIterPerCycle << _CSEN_DMCFG_DMR_SHIFT)
        | (init->dmDelta << _CSEN_DMCFG_DMG_SHIFT);

  if (init->dmFixedDelta) {
    tmp |= CSEN_DMCFG_DMGRDIS;
  }

  csen->DMCFG = tmp;

  /* Initialize ANACTRL. */
  csen->ANACTRL = (init->resetPhase << _CSEN_ANACTRL_TRSTPROG_SHIFT)
                  | (init->driveSel << _CSEN_ANACTRL_IDACIREFS_SHIFT)
                  | (init->gainSel << _CSEN_ANACTRL_IREFPROG_SHIFT);
}
/***************************************************************************/
/**
 * @brief
 *   Initialize a CSEN measurement mode.
 *
 * @details
 *   Used to configure any type of measurement mode. After the measurement
 *   has been configured, calling @ref CSEN_Enable() will enable CSEN and
 *   allow it to start a conversion from the selected trigger source. To
 *   manually start a conversion use @ref CSEN_Start(). To check if a
 *   conversion is in progress use @ref CSEN_IsBusy(), or alternatively
 *   use the interrupt flags returned by @ref CSEN_IntGet() to detect when
 *   a conversion is completed.
 *
 * @note
 *   This function will stop any ongoing conversion and disable CSEN.
 *
 * @param[in] csen
 *   Pointer to CSEN peripheral register block.
 *
 * @param[in] init
 *   Pointer to CSEN measurement mode initialization structure.
 ******************************************************************************/
@brief
Initialize a CSEN measurement mode.

@details
Used to configure any type of measurement mode. After the measurement
has been configured, calling @ref CSEN_Enable() will enable CSEN and
allow it to start a conversion from the selected trigger source. To
manually start a conversion use @ref CSEN_Start(). To check if a
conversion is in progress use @ref CSEN_IsBusy(), or alternatively
use the interrupt flags returned by @ref CSEN_IntGet() to detect when
a conversion is completed.

@note
This function will stop any ongoing conversion and disable CSEN.

@param[in] csen
Pointer to CSEN peripheral register block.

@param[in] init
Pointer to CSEN measurement mode initialization structure.
@brief Initialize a CSEN measurement mode . @details Used to configure any type of measurement mode . After the measurement has been configured calling @ref CSEN_Enable () will enable CSEN and allow it to start a conversion from the selected trigger source . To manually start a conversion use @ref CSEN_Start () . To check if a conversion is in progress use @ref CSEN_IsBusy () or alternatively use the interrupt flags returned by @ref CSEN_IntGet () to detect when a conversion is completed . @note This function will stop any ongoing conversion and disable CSEN . @param [ in ] csen Pointer to CSEN peripheral register block . @param [ in ] init Pointer to CSEN measurement mode initialization structure .
void CSEN_InitMode(CSEN_TypeDef *csen, const CSEN_InitMode_TypeDef *init)
{
  uint32_t tmp;
  EFM_ASSERT(CSEN_REF_VALID(csen));
  EFM_ASSERT(init->dmIterPerCycle < 0x10);
  EFM_ASSERT(init->dmCycles < 0x10);
  tmp = ((uint32_t)init->sampleMode
         | (uint32_t)init->convSel
         | (uint32_t)init->cmpMode);
  tmp |= (init->trigSel << _CSEN_CTRL_STM_SHIFT)
         | (init->accMode << _CSEN_CTRL_ACU_SHIFT)
         | (init->sarRes << _CSEN_CTRL_SARCR_SHIFT);
  if (init->enableDma) {
    tmp |= CSEN_CTRL_DMAEN_ENABLE;
  }
  if (init->sumOnly) {
    tmp |= CSEN_CTRL_DRSF_ENABLE;
  }
  if (init->autoGnd) {
    tmp |= CSEN_CTRL_AUTOGND_ENABLE;
  }
  tmp |= csen->CTRL & (_CSEN_CTRL_CPACCURACY_MASK
                       | _CSEN_CTRL_LOCALSENS_MASK
                       | _CSEN_CTRL_WARMUPMODE_MASK);
  csen->CTRL = tmp;
  csen->EMACTRL = init->emaSample << _CSEN_EMACTRL_EMASAMPLE_SHIFT;
  csen->CMPTHR = init->cmpThr << _CSEN_CMPTHR_CMPTHR_SHIFT;
  csen->SINGLECTRL = init->singleSel << _CSEN_SINGLECTRL_SINGLESEL_SHIFT;
  csen->SCANMASK0 = init->inputMask0;
  csen->SCANMASK1 = init->inputMask1;
  tmp = (init->dmRes << _CSEN_DMCFG_CRMODE_SHIFT)
        | (init->dmCycles << _CSEN_DMCFG_DMCR_SHIFT)
        | (init->dmIterPerCycle << _CSEN_DMCFG_DMR_SHIFT)
        | (init->dmDelta << _CSEN_DMCFG_DMG_SHIFT);
  if (init->dmFixedDelta) {
    tmp |= CSEN_DMCFG_DMGRDIS;
  }
  csen->DMCFG = tmp;
  csen->ANACTRL = (init->resetPhase << _CSEN_ANACTRL_TRSTPROG_SHIFT)
                  | (init->driveSel << _CSEN_ANACTRL_IDACIREFS_SHIFT)
                  | (init->gainSel << _CSEN_ANACTRL_IREFPROG_SHIFT);
}
void CSEN_InitMode ( CSEN_TypeDef * csen , const CSEN_InitMode_TypeDef * init ) { uint32_t tmp ; EFM_ASSERT ( CSEN_REF_VALID ( csen ) ) ; EFM_ASSERT ( init -> dmIterPerCycle < 0x10 ) ; EFM_ASSERT ( init -> dmCycles < 0x10 ) ; tmp = ( ( uint32_t ) init -> sampleMode | ( uint32_t ) init -> convSel | ( uint32_t ) init -> cmpMode ) ; tmp |= ( init -> trigSel << _CSEN_CTRL_STM_SHIFT ) | ( init -> accMode << _CSEN_CTRL_ACU_SHIFT ) | ( init -> sarRes << _CSEN_CTRL_SARCR_SHIFT ) ; if ( init -> enableDma ) { tmp |= CSEN_CTRL_DMAEN_ENABLE ; } if ( init -> sumOnly ) { tmp |= CSEN_CTRL_DRSF_ENABLE ; } if ( init -> autoGnd ) { tmp |= CSEN_CTRL_AUTOGND_ENABLE ; } tmp |= csen -> CTRL & ( _CSEN_CTRL_CPACCURACY_MASK | _CSEN_CTRL_LOCALSENS_MASK | _CSEN_CTRL_WARMUPMODE_MASK ) ; csen -> CTRL = tmp ; csen -> EMACTRL = init -> emaSample << _CSEN_EMACTRL_EMASAMPLE_SHIFT ; csen -> CMPTHR = init -> cmpThr << _CSEN_CMPTHR_CMPTHR_SHIFT ; csen -> SINGLECTRL = init -> singleSel << _CSEN_SINGLECTRL_SINGLESEL_SHIFT ; csen -> SCANMASK0 = init -> inputMask0 ; csen -> SCANMASK1 = init -> inputMask1 ; tmp = ( init -> dmRes << _CSEN_DMCFG_CRMODE_SHIFT ) | ( init -> dmCycles << _CSEN_DMCFG_DMCR_SHIFT ) | ( init -> dmIterPerCycle << _CSEN_DMCFG_DMR_SHIFT ) | ( init -> dmDelta << _CSEN_DMCFG_DMG_SHIFT ) ; if ( init -> dmFixedDelta ) { tmp |= CSEN_DMCFG_DMGRDIS ; } csen -> DMCFG = tmp ; csen -> ANACTRL = ( init -> resetPhase << _CSEN_ANACTRL_TRSTPROG_SHIFT ) | ( init -> driveSel << _CSEN_ANACTRL_IDACIREFS_SHIFT ) | ( init -> gainSel << _CSEN_ANACTRL_IREFPROG_SHIFT ) ; }
@brief
   Initialize a CSEN measurement mode.
@brief Initialize a CSEN measurement mode .
/* Initialize CTRL. This will stop any conversion in progress.
   * These composite inputs set multiple fields. They do not need
   * to be shifted. */ /* Preserve the fields that were initialized by CSEN_Init(). */ /* EMACTRL only has one field */ /* CMPTHR only has one field */ /* SINGLECTRL only has one field */ /* Set all input enables */ /* Initialize DMCFG. */ /* Initialize ANACTRL. */