diff --git a/I2CManager.h b/I2CManager.h index b17accd..342d8d4 100644 --- a/I2CManager.h +++ b/I2CManager.h @@ -111,7 +111,7 @@ * */ -//#define I2C_USE_WIRE +#define I2C_USE_WIRE #ifndef I2C_NO_INTERRUPTS #define I2C_USE_INTERRUPTS #endif @@ -235,7 +235,7 @@ private: // Mark volatile as they are updated by IRC and read/written elsewhere. static I2CRB * volatile queueHead; static I2CRB * volatile queueTail; - static volatile uint8_t status; + static volatile uint8_t state; static I2CRB * volatile currentRequest; static volatile uint8_t txCount; diff --git a/I2CManager_AVR.h b/I2CManager_AVR.h index 9de9bf2..310afa2 100644 --- a/I2CManager_AVR.h +++ b/I2CManager_AVR.h @@ -136,7 +136,7 @@ void I2CManagerClass::I2C_handleInterrupt() { } else { // Nothing left to send or receive TWDR = 0xff; // Default condition = SDA released TWCR = (1< 0) { + if (state==I2C_STATE_ACTIVE && t!=0 && timeout > 0) { // Check for timeout if (currentMicros - startTime > timeout) { // Excessive time. Dequeue request @@ -148,7 +148,7 @@ void I2CManagerClass::checkForTimeout() { // Try close and init, not entirely satisfactory but sort of works... I2C_close(); // Shutdown and restart twi interface I2C_init(); - status = I2C_STATE_FREE; + state = I2C_STATE_FREE; // Initiate next queued request startTransaction(); @@ -178,7 +178,7 @@ void I2CManagerClass::handleInterrupt() { // Experimental -- perform the post processing with interrupts enabled. //interrupts(); - if (status!=I2C_STATUS_PENDING) { + if (state!=I2C_STATE_ACTIVE && state != I2C_STATE_FREE) { // Remove completed request from head of queue I2CRB * t; ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { @@ -187,10 +187,10 @@ void I2CManagerClass::handleInterrupt() { queueHead = t->nextRequest; if (!queueHead) queueTail = queueHead; t->nBytes = rxCount; - t->status = status; + t->status = state; } // I2C state machine is now free for next request - status = I2C_STATE_FREE; + state = I2C_STATE_FREE; } // Start next request (if any) I2CManager.startTransaction(); @@ -201,7 +201,7 @@ void I2CManagerClass::handleInterrupt() { I2CRB * volatile I2CManagerClass::queueHead = NULL; I2CRB * volatile I2CManagerClass::queueTail = NULL; I2CRB * volatile I2CManagerClass::currentRequest = NULL; -volatile uint8_t I2CManagerClass::status = I2C_STATE_FREE; +volatile uint8_t I2CManagerClass::state = I2C_STATE_FREE; volatile uint8_t I2CManagerClass::txCount; volatile uint8_t I2CManagerClass::rxCount; volatile uint8_t I2CManagerClass::operation;