akafugu/Xmegaduino — pull request #37 by psychogenic (2014-12-17 21:47:29+00:00)
Title: Timeout option for Wire library.

The Wire library freezes programs whenever there's a problem on the line (e.g. unresponsive slave)... This patch leaves things exactly as-is, by default, but allows you to:

Wire.setAutoTimeout(UINT8); // set auto timeouts to a value between 0 (disabled) and 255 ms

Then proceed as usual. If auto-timeout is set, Xmega (xmWire) version may return TWI_ERROR_TIMEOUT errors on beginTransmission() and requestFrom(), should a timeout occur. As it doesn't have a facility for elaborate error reporting, the Mega version simply returns 0 length read on timeouts from readFrom().