diff options
author | Jack Humbert <jack.humb@gmail.com> | 2018-06-23 14:18:47 -0400 |
---|---|---|
committer | Jack Humbert <jack.humb@gmail.com> | 2018-06-23 14:18:47 -0400 |
commit | 7a44ad83fce391c938d18abcc2125e15c1982078 (patch) | |
tree | 1c0db8fbaf33aa1cf408ba418cdb3705b526d618 /drivers | |
parent | 6380f8319057d33bb6d07c66789867e49c634504 (diff) |
adds immediate i2c return, fixes ez matrix code
Diffstat (limited to 'drivers')
-rwxr-xr-x | drivers/avr/i2c_master.c | 12 | ||||
-rwxr-xr-x | drivers/avr/i2c_master.h | 3 |
2 files changed, 9 insertions, 6 deletions
diff --git a/drivers/avr/i2c_master.c b/drivers/avr/i2c_master.c index 30ea760c9f..f25e354b80 100755 --- a/drivers/avr/i2c_master.c +++ b/drivers/avr/i2c_master.c @@ -28,7 +28,7 @@ i2c_status_t i2c_start(uint8_t address, uint16_t timeout) uint16_t timeout_timer = timer_read(); while( !(TWCR & (1<<TWINT)) ) { - if (timeout && ((timer_read() - timeout_timer) > timeout)) { + if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) { return I2C_STATUS_TIMEOUT; } } @@ -43,7 +43,7 @@ i2c_status_t i2c_start(uint8_t address, uint16_t timeout) timeout_timer = timer_read(); while( !(TWCR & (1<<TWINT)) ) { - if (timeout && ((timer_read() - timeout_timer) > timeout)) { + if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) { return I2C_STATUS_TIMEOUT; } } @@ -64,7 +64,7 @@ i2c_status_t i2c_write(uint8_t data, uint16_t timeout) uint16_t timeout_timer = timer_read(); while( !(TWCR & (1<<TWINT)) ) { - if (timeout && ((timer_read() - timeout_timer) > timeout)) { + if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) { return I2C_STATUS_TIMEOUT; } } @@ -82,7 +82,7 @@ int16_t i2c_read_ack(uint16_t timeout) uint16_t timeout_timer = timer_read(); while( !(TWCR & (1<<TWINT)) ) { - if (timeout && ((timer_read() - timeout_timer) > timeout)) { + if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) { return I2C_STATUS_TIMEOUT; } } @@ -99,7 +99,7 @@ int16_t i2c_read_nack(uint16_t timeout) uint16_t timeout_timer = timer_read(); while( !(TWCR & (1<<TWINT)) ) { - if (timeout && ((timer_read() - timeout_timer) > timeout)) { + if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) { return I2C_STATUS_TIMEOUT; } } @@ -210,7 +210,7 @@ i2c_status_t i2c_stop(uint16_t timeout) uint16_t timeout_timer = timer_read(); while(TWCR & (1<<TWSTO)) { - if (timeout && ((timer_read() - timeout_timer) > timeout)) { + if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) { return I2C_STATUS_TIMEOUT; } } diff --git a/drivers/avr/i2c_master.h b/drivers/avr/i2c_master.h index 0806d76aa9..cf93680be4 100755 --- a/drivers/avr/i2c_master.h +++ b/drivers/avr/i2c_master.h @@ -14,6 +14,9 @@ typedef int16_t i2c_status_t; #define I2C_STATUS_ERROR (-1) #define I2C_STATUS_TIMEOUT (-2) +#define I2C_TIMEOUT_IMMEDIATE (0) +#define I2C_TIMEOUT_INFINITE (0xFFFF) + void i2c_init(void); i2c_status_t i2c_start(uint8_t address, uint16_t timeout); i2c_status_t i2c_write(uint8_t data, uint16_t timeout); |