I2C: wrap the currently abandoned code for reading properly.

Not removed entirely, because it might be needed later.
This commit is contained in:
Markus Hitter 2016-04-05 21:21:38 +02:00
parent ecaab2423c
commit eb21ac7485
2 changed files with 18 additions and 3 deletions

8
i2c.c
View File

@ -345,8 +345,9 @@ ISR(TWI_vect) {
// Try to resend when the bus became free. // Try to resend when the bus became free.
TWCR = (1<<TWINT)|(I2C_MODE<<TWEA)|(1<<TWSTA)|(0<<TWSTO)|(1<<TWEN)|(1<<TWIE); TWCR = (1<<TWINT)|(I2C_MODE<<TWEA)|(1<<TWSTA)|(0<<TWSTO)|(1<<TWEN)|(1<<TWIE);
break; break;
#if 0
// Note: we currently have no receive buffer, so we can't receive anything. #ifdef I2C_READ_SUPPORT
case TW_MR_SLA_ACK: case TW_MR_SLA_ACK:
// SLA+R was sent, got АСК, then received a byte. // SLA+R was sent, got АСК, then received a byte.
if (i2c_index + 1 == i2c_byte_count) { if (i2c_index + 1 == i2c_byte_count) {
@ -381,7 +382,8 @@ ISR(TWI_vect) {
// Send stop condition. // Send stop condition.
TWCR = (1<<TWINT)|(I2C_MODE<<TWEA)|(0<<TWSTA)|(1<<TWSTO)|(1<<TWEN)|(0<<TWIE); TWCR = (1<<TWINT)|(I2C_MODE<<TWEA)|(0<<TWSTA)|(1<<TWSTO)|(1<<TWEN)|(0<<TWIE);
break; break;
#endif
#endif /* I2C_READ_SUPPORT */
#ifdef I2C_SLAVE_MODE #ifdef I2C_SLAVE_MODE

13
i2c.h
View File

@ -22,6 +22,19 @@
*/ */
//#define I2C_SLAVE_MODE //#define I2C_SLAVE_MODE
/** \def I2C_READ_SUPPORT
Currently, reading from the I2C bus is implemented only partially. The
already existing parts are wrapped with this #define.
If reading from I2C is needed, at least a read buffer has to be added. This
buffer used to be 'i2c_buffer[]', a pointer 'i2c_index' into this buffer and
a variable 'i2c_byte_count' to track on how many bytes should be read.
Further requirements are adjustments to the wrapped code to use this buffer
and a function to make the read data available to calling code.
*/
//#define I2C_READ_SUPPORT
/** \def I2C_EEPROM_SUPPORT /** \def I2C_EEPROM_SUPPORT
It's currently unclear what this enables exactly, apparently something to It's currently unclear what this enables exactly, apparently something to