/* 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)
{
	int count = 5;
	enum HAL_GPADC_CHAN_T channel;
	HAL_GPADC_MV_T volt = HAL_GPADC_BAD_VALUE;
	if (output == NULL)
		return -EINVAL;
	channel = __hal_adc_port2chan(adc->port);
	if (channel >= HAL_GPADC_CHAN_QTY)
		return -EINVAL;
	hal_gpadc_open(channel, HAL_GPADC_ATP_ONESHOT, NULL);
	osDelay(1);
	while (count--) {
		if (hal_gpadc_get_volt(channel, &volt)) {
			*output = volt;
			return 0;
		}
		osDelay(1);
	}
	return -EIO;
}