/* Waits until the device can accept read and write user actions.  */
int32_t ad7124_wait_for_spi_ready(struct ad7124_dev *dev, uint32_t timeout)
/* Waits until the device can accept read and write user actions.  */
int32_t ad7124_wait_for_spi_ready(struct ad7124_dev *dev, uint32_t timeout)
{
	struct ad7124_st_reg *regs;
	int32_t ret;
	int8_t ready = 0;
	if(!dev)
		return INVALID_VAL;
	regs = dev->regs;
	while(!ready && --timeout) {
		ret = ad7124_read_register(dev, &regs[AD7124_Error]);
		if(ret < 0)
			return ret;
		ready = (regs[AD7124_Error].value &
			 AD7124_ERR_REG_SPI_IGNORE_ERR) == 0;
	}
	return timeout ? 0 : TIMEOUT;
}