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) | |
| download | qmk_firmware-7a44ad83fce391c938d18abcc2125e15c1982078.tar.gz qmk_firmware-7a44ad83fce391c938d18abcc2125e15c1982078.zip | |
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 30ea760c9..f25e354b8 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) | |||
| 28 | 28 | ||
| 29 | uint16_t timeout_timer = timer_read(); | 29 | uint16_t timeout_timer = timer_read(); |
| 30 | while( !(TWCR & (1<<TWINT)) ) { | 30 | while( !(TWCR & (1<<TWINT)) ) { |
| 31 | if (timeout && ((timer_read() - timeout_timer) > timeout)) { | 31 | if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) { |
| 32 | return I2C_STATUS_TIMEOUT; | 32 | return I2C_STATUS_TIMEOUT; |
| 33 | } | 33 | } |
| 34 | } | 34 | } |
| @@ -43,7 +43,7 @@ i2c_status_t i2c_start(uint8_t address, uint16_t timeout) | |||
| 43 | 43 | ||
| 44 | timeout_timer = timer_read(); | 44 | timeout_timer = timer_read(); |
| 45 | while( !(TWCR & (1<<TWINT)) ) { | 45 | while( !(TWCR & (1<<TWINT)) ) { |
| 46 | if (timeout && ((timer_read() - timeout_timer) > timeout)) { | 46 | if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) { |
| 47 | return I2C_STATUS_TIMEOUT; | 47 | return I2C_STATUS_TIMEOUT; |
| 48 | } | 48 | } |
| 49 | } | 49 | } |
| @@ -64,7 +64,7 @@ i2c_status_t i2c_write(uint8_t data, uint16_t timeout) | |||
| 64 | 64 | ||
| 65 | uint16_t timeout_timer = timer_read(); | 65 | uint16_t timeout_timer = timer_read(); |
| 66 | while( !(TWCR & (1<<TWINT)) ) { | 66 | while( !(TWCR & (1<<TWINT)) ) { |
| 67 | if (timeout && ((timer_read() - timeout_timer) > timeout)) { | 67 | if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) { |
| 68 | return I2C_STATUS_TIMEOUT; | 68 | return I2C_STATUS_TIMEOUT; |
| 69 | } | 69 | } |
| 70 | } | 70 | } |
| @@ -82,7 +82,7 @@ int16_t i2c_read_ack(uint16_t timeout) | |||
| 82 | 82 | ||
| 83 | uint16_t timeout_timer = timer_read(); | 83 | uint16_t timeout_timer = timer_read(); |
| 84 | while( !(TWCR & (1<<TWINT)) ) { | 84 | while( !(TWCR & (1<<TWINT)) ) { |
| 85 | if (timeout && ((timer_read() - timeout_timer) > timeout)) { | 85 | if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) { |
| 86 | return I2C_STATUS_TIMEOUT; | 86 | return I2C_STATUS_TIMEOUT; |
| 87 | } | 87 | } |
| 88 | } | 88 | } |
| @@ -99,7 +99,7 @@ int16_t i2c_read_nack(uint16_t timeout) | |||
| 99 | 99 | ||
| 100 | uint16_t timeout_timer = timer_read(); | 100 | uint16_t timeout_timer = timer_read(); |
| 101 | while( !(TWCR & (1<<TWINT)) ) { | 101 | while( !(TWCR & (1<<TWINT)) ) { |
| 102 | if (timeout && ((timer_read() - timeout_timer) > timeout)) { | 102 | if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) { |
| 103 | return I2C_STATUS_TIMEOUT; | 103 | return I2C_STATUS_TIMEOUT; |
| 104 | } | 104 | } |
| 105 | } | 105 | } |
| @@ -210,7 +210,7 @@ i2c_status_t i2c_stop(uint16_t timeout) | |||
| 210 | 210 | ||
| 211 | uint16_t timeout_timer = timer_read(); | 211 | uint16_t timeout_timer = timer_read(); |
| 212 | while(TWCR & (1<<TWSTO)) { | 212 | while(TWCR & (1<<TWSTO)) { |
| 213 | if (timeout && ((timer_read() - timeout_timer) > timeout)) { | 213 | if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) { |
| 214 | return I2C_STATUS_TIMEOUT; | 214 | return I2C_STATUS_TIMEOUT; |
| 215 | } | 215 | } |
| 216 | } | 216 | } |
diff --git a/drivers/avr/i2c_master.h b/drivers/avr/i2c_master.h index 0806d76aa..cf93680be 100755 --- a/drivers/avr/i2c_master.h +++ b/drivers/avr/i2c_master.h | |||
| @@ -14,6 +14,9 @@ typedef int16_t i2c_status_t; | |||
| 14 | #define I2C_STATUS_ERROR (-1) | 14 | #define I2C_STATUS_ERROR (-1) |
| 15 | #define I2C_STATUS_TIMEOUT (-2) | 15 | #define I2C_STATUS_TIMEOUT (-2) |
| 16 | 16 | ||
| 17 | #define I2C_TIMEOUT_IMMEDIATE (0) | ||
| 18 | #define I2C_TIMEOUT_INFINITE (0xFFFF) | ||
| 19 | |||
| 17 | void i2c_init(void); | 20 | void i2c_init(void); |
| 18 | i2c_status_t i2c_start(uint8_t address, uint16_t timeout); | 21 | i2c_status_t i2c_start(uint8_t address, uint16_t timeout); |
| 19 | i2c_status_t i2c_write(uint8_t data, uint16_t timeout); | 22 | i2c_status_t i2c_write(uint8_t data, uint16_t timeout); |
