/* Waits until a new conversion result is available.  */
int32_t AD717X_WaitForReady(ad717x_dev *device, uint32_t timeout)
/* Waits until a new conversion result is available.  */
int32_t AD717X_WaitForReady(ad717x_dev *device, uint32_t timeout)
{
	ad717x_st_reg *statusReg;
	int32_t ret;
	int8_t ready = 0;
	if(!device || !device->regs)
		return INVALID_VAL;
	statusReg = AD717X_GetReg(device, AD717X_STATUS_REG);
	if (!statusReg)
		return INVALID_VAL;
	while(!ready && --timeout) {
		ret = AD717X_ReadRegister(device, AD717X_STATUS_REG);
		if(ret < 0)
			return ret;
		ready = (statusReg->value & AD717X_STATUS_REG_RDY) == 0;
	}
	return timeout ? 0 : TIMEOUT;
}