+
+ #ifdef I2C_TIMEOUT
+ uint16_t timeout_timer = timer_read();
+ while( !(TWCR & (1<<TWINT)) ) {
+ if ((timer_read() - timeout_timer) > I2C_TIMEOUT) {
+ return 2; // should make these codes standard
+ }
+ }
+ #else
+ // wait for end of transmission
+ while( !(TWCR & (1<<TWINT)) );
+ #endif