From 98f00300ec26018d040dfd9a39ca46066dba9150 Mon Sep 17 00:00:00 2001 From: travis-farmer Date: Fri, 10 Nov 2023 15:09:56 -0500 Subject: [PATCH] removed I2C port change option as it is breaking --- I2CManager_Wire.h | 48 ++++++++++++++++++++++------------------------- defines.h | 8 -------- 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/I2CManager_Wire.h b/I2CManager_Wire.h index 69ffc96..db2ae0c 100644 --- a/I2CManager_Wire.h +++ b/I2CManager_Wire.h @@ -35,11 +35,7 @@ #define WIRE_HAS_TIMEOUT #endif -#if defined(GIGA_I2C_1) -#define DCCEX_WIRE Wire1 -#else -#define DCCEX_WIRE Wire -#endif + @@ -47,9 +43,9 @@ * Initialise I2C interface software ***************************************************************************/ void I2CManagerClass::_initialise() { - DCCEX_WIRE.begin(); + Wire.begin(); #if defined(WIRE_HAS_TIMEOUT) - DCCEX_WIRE.setWireTimeout(_timeout, true); + Wire.setWireTimeout(_timeout, true); #endif } @@ -58,7 +54,7 @@ void I2CManagerClass::_initialise() { * on Arduino. Mega4809 supports 1000000 (Fast+) too. ***************************************************************************/ void I2CManagerClass::_setClock(unsigned long i2cClockSpeed) { - DCCEX_WIRE.setClock(i2cClockSpeed); + Wire.setClock(i2cClockSpeed); } /*************************************************************************** @@ -69,7 +65,7 @@ void I2CManagerClass::_setClock(unsigned long i2cClockSpeed) { void I2CManagerClass::setTimeout(unsigned long value) { _timeout = value; #if defined(WIRE_HAS_TIMEOUT) - DCCEX_WIRE.setWireTimeout(value, true); + Wire.setWireTimeout(value, true); #endif } @@ -82,7 +78,7 @@ static uint8_t muxSelect(I2CAddress address) { I2CMux muxNo = address.muxNumber(); I2CSubBus subBus = address.subBus(); if (muxNo != I2CMux_None) { - DCCEX_WIRE.beginTransmission(I2C_MUX_BASE_ADDRESS+muxNo); + Wire.beginTransmission(I2C_MUX_BASE_ADDRESS+muxNo); uint8_t data = (subBus == SubBus_All) ? 0xff : (subBus == SubBus_None) ? 0x00 : #if defined(I2CMUX_PCA9547) @@ -94,8 +90,8 @@ static uint8_t muxSelect(I2CAddress address) { // with a bit set for the subBus to be enabled 1 << subBus; #endif - DCCEX_WIRE.write(&data, 1); - return DCCEX_WIRE.endTransmission(true); // have to release I2C bus for it to work + Wire.write(&data, 1); + return Wire.endTransmission(true); // have to release I2C bus for it to work } return I2C_STATUS_OK; } @@ -118,9 +114,9 @@ uint8_t I2CManagerClass::write(I2CAddress address, const uint8_t buffer[], uint8 #endif // Only send new transaction if address is non-zero. if (muxStatus == I2C_STATUS_OK && address != 0) { - DCCEX_WIRE.beginTransmission(address); - if (size > 0) DCCEX_WIRE.write(buffer, size); - status = DCCEX_WIRE.endTransmission(); + Wire.beginTransmission(address); + if (size > 0) Wire.write(buffer, size); + status = Wire.endTransmission(); } #ifdef I2C_EXTENDED_ADDRESS // Deselect MUX if there's more than one MUX present, to avoid having multiple ones selected @@ -169,25 +165,25 @@ uint8_t I2CManagerClass::read(I2CAddress address, uint8_t readBuffer[], uint8_t // Only start new transaction if address is non-zero. if (muxStatus == I2C_STATUS_OK && address != 0) { if (writeSize > 0) { - DCCEX_WIRE.beginTransmission(address); - DCCEX_WIRE.write(writeBuffer, writeSize); - status = DCCEX_WIRE.endTransmission(false); // Don't free bus yet + Wire.beginTransmission(address); + Wire.write(writeBuffer, writeSize); + status = Wire.endTransmission(false); // Don't free bus yet } if (status == I2C_STATUS_OK) { #ifdef WIRE_HAS_TIMEOUT - DCCEX_WIRE.clearWireTimeoutFlag(); - DCCEX_WIRE.requestFrom(address, (size_t)readSize); - if (!DCCEX_WIRE.getWireTimeoutFlag()) { - while (DCCEX_WIRE.available() && nBytes < readSize) - readBuffer[nBytes++] = DCCEX_WIRE.read(); + Wire.clearWireTimeoutFlag(); + Wire.requestFrom(address, (size_t)readSize); + if (!Wire.getWireTimeoutFlag()) { + while (Wire.available() && nBytes < readSize) + readBuffer[nBytes++] = Wire.read(); if (nBytes < readSize) status = I2C_STATUS_TRUNCATED; } else { status = I2C_STATUS_TIMEOUT; } #else - DCCEX_WIRE.requestFrom(address, (size_t)readSize); - while (DCCEX_WIRE.available() && nBytes < readSize) - readBuffer[nBytes++] = DCCEX_WIRE.read(); + Wire.requestFrom(address, (size_t)readSize); + while (Wire.available() && nBytes < readSize) + readBuffer[nBytes++] = Wire.read(); if (nBytes < readSize) status = I2C_STATUS_TRUNCATED; #endif } diff --git a/defines.h b/defines.h index 8c5ada4..756e45a 100644 --- a/defines.h +++ b/defines.h @@ -161,14 +161,6 @@ //#endif #define SDA I2C_SDA #define SCL I2C_SCL - #define DCC_EX_TIMER - // these don't work... - //extern const uint16_t PROGMEM port_to_input_PGM[]; - //extern const uint16_t PROGMEM port_to_output_PGM[]; - //extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[]; - //#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) ) - //#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) ) - //#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) ) /* TODO when ready #elif defined(ARDUINO_ARCH_RP2040)