/* We need to calculate how long before the voltage starts to drop or increase It returns with the loop count. Each loop takes several readings (532us)  */
static int wait_for_voltage_change(int vdd_last)
/* We need to calculate how long before the voltage starts to drop or increase It returns with the loop count. Each loop takes several readings (532us)  */
static int wait_for_voltage_change(int vdd_last)
{
	int timeout, vdd_current;
	vdd_current = read_voltage();
	for (timeout = 0; abs(vdd_last - vdd_current) <= 4 &&
		timeout < 100; timeout++) {
		vdd_current = read_voltage();
	}
	if (timeout >= 100) {
		printf("VID: Voltage adjustment timeout\n");
		return -1;
	}
	return timeout;
}