From: Jack Humbert Date: Wed, 20 Jun 2018 20:26:43 +0000 (-0400) Subject: start updating i2c for timeouts X-Git-Url: https://git.donarmstrong.com/?p=qmk_firmware.git;a=commitdiff_plain;h=76e0d23887b8ddc70e9afb30bb7b91e9fec96c35 start updating i2c for timeouts --- diff --git a/drivers/avr/i2c_master.c b/drivers/avr/i2c_master.c index 97f690043..caca2179e 100755 --- a/drivers/avr/i2c_master.c +++ b/drivers/avr/i2c_master.c @@ -19,24 +19,19 @@ void i2c_init(void) //TWBR = 10; } -uint8_t i2c_start(uint8_t address) +i2c_status_t i2c_start(uint8_t address, uint8_t timeout) { // reset TWI control register TWCR = 0; // transmit START condition TWCR = (1< I2C_TIMEOUT) { - return 2; // should make these codes standard - } + uint16_t timeout_timer = timer_read(); + while( !(TWCR & (1< timeout) { + return I2C_STATUS_TIMEOUT; } - #else - // wait for end of transmission - while( !(TWCR & (1< I2C_TIMEOUT) { - return 2; // should make these codes standard - } + timeout_timer = timer_read(); + while( !(TWCR & (1< I2C_TIMEOUT) { + return I2C_STATUS_TIMEOUT; } - #else - // wait for end of transmission - while( !(TWCR & (1< I2C_TIMEOUT) { - return 2; // should make these codes standard - } + uint16_t timeout_timer = timer_read(); + while( !(TWCR & (1< I2C_TIMEOUT) { + return I2C_STATUS_TIMEOUT; } - #else - // wait for end of transmission - while( !(TWCR & (1< I2C_TIMEOUT) { - return 2; // should make these codes standard - } + uint16_t timeout_timer = timer_read(); + while( !(TWCR & (1< I2C_TIMEOUT) { + return I2C_STATUS_TIMEOUT; } - #else - // wait for end of transmission - while( !(TWCR & (1< I2C_TIMEOUT) { - return 2; // should make these codes standard - } + uint16_t timeout_timer = timer_read(); + while( !(TWCR & (1< I2C_TIMEOUT) { + return I2C_STATUS_TIMEOUT; } - #else - // wait for end of transmission - while( !(TWCR & (1< I2C_TIMEOUT) { - return 2; // should make these codes standard - } + uint16_t timeout_timer = timer_read(); + while(TWCR & (1< I2C_TIMEOUT) { + return I2C_STATUS_TIMEOUT; } - #else - // wait for end of transmission - while(TWCR & (1<