/* Initialize ADC scan sequence. 
When selecting an external reference, the gain and offset calibration must be set explicitly (CAL register). For other references, the calibration is updated with values defined during manufacturing. */
void ADC_InitScan(ADC_TypeDef *adc, const ADC_InitScan_TypeDef *init)
/* Initialize ADC scan sequence. 
When selecting an external reference, the gain and offset calibration must be set explicitly (CAL register). For other references, the calibration is updated with values defined during manufacturing. */
void ADC_InitScan(ADC_TypeDef *adc, const ADC_InitScan_TypeDef *init)
{
  uint32_t tmp;
  EFM_ASSERT(ADC_REF_VALID(adc));
  adc->CMD = ADC_CMD_SCANSTOP;
  ADC_CalibrateLoadScan(adc, init->reference);
  tmp = ((uint32_t)(init->prsSel) << _ADC_SCANCTRL_PRSSEL_SHIFT) |
        ((uint32_t)(init->acqTime) << _ADC_SCANCTRL_AT_SHIFT) |
        ((uint32_t)(init->reference) << _ADC_SCANCTRL_REF_SHIFT) |
        init->input |
        ((uint32_t)(init->resolution) << _ADC_SCANCTRL_RES_SHIFT);
  if (init->prsEnable)
  {
    tmp |= ADC_SCANCTRL_PRSEN;
  }
  if (init->leftAdjust)
  {
    tmp |= ADC_SCANCTRL_ADJ_LEFT;
  }
  if (init->diff)
  {
    tmp |= ADC_SCANCTRL_DIFF;
  }
  if (init->rep)
  {
    tmp |= ADC_SCANCTRL_REP;
  }
  adc->SCANCTRL = tmp;
}