/* Takes a single sample from an ADC interface */
int32_t hal_adc_value_get(adc_dev_t *adc, uint32_t *output, uint32_t timeout)
/* Takes a single sample from an ADC interface */
int32_t hal_adc_value_get(adc_dev_t *adc, uint32_t *output, uint32_t timeout)
{
	uint32_t startcount = SYSTIMER_TickGet();
	analogin_t *adc_t = adc->priv;
	uint8_t  ChIdx = adc_t->adc_idx;
	uint32_t data;
	ADC->ADC_CHSW_LIST[0] = ChIdx;
	ADC_ClearFIFO();
	ADC_SWTrigCmd(ENABLE);
	while(1){
		if(ADC_Readable())
			break;
		if(SYSTIMER_GetPassTime(startcount)>timeout)
			return -1;
	}
	ADC_SWTrigCmd(DISABLE);
	data = ADC_Read();
	*output = data & BIT_MASK_DAT_GLOBAL;
	return 0;
}