I2C: provide a busy-detection.

Nowhere used so far, so no binary size change.
This commit is contained in:
Markus Hitter 2016-04-05 19:00:20 +02:00
parent aab447567c
commit 55be863b84
2 changed files with 18 additions and 0 deletions

17
i2c.c
View File

@ -141,6 +141,20 @@ void i2c_init(uint8_t address) {
#endif
}
/**
Report wether I2C is busy.
\return Wether I2C is currently busy, which means that eventual new
transactions would have to wait.
Idea is that non-crucial display writes check the bus before actually
writing, so they avoid long waits. If i2c_busy() returns zero, the bus
is free and writes won't cause a delay.
*/
uint8_t i2c_busy(void) {
return (i2c_state & I2C_MODE_BUSY);
}
/**
Send a byte to the I2C partner.
@ -164,6 +178,9 @@ void i2c_init(uint8_t address) {
amounts don't get lost, but this function has to wait until sufficient
previous data was sent.
To avoid unexpected delays, invoking code can check for bus availability
with i2c_busy().
Note that calling code has to send bytes quickly enough to not drain the
buffer. It looks like the I2C protocol doesn't, unlike e.g. SPI, allow
to pause sending without dropping the transmission. Positive of this

1
i2c.h
View File

@ -39,6 +39,7 @@
void i2c_init(uint8_t address);
uint8_t i2c_busy(void);
void i2c_write(uint8_t address, uint8_t data, uint8_t last_byte);
#endif /* I2C */