From 131bcb49d141a2315fc6ce7c2790e1577d1d216e Mon Sep 17 00:00:00 2001 From: FrankCVanris Date: Sat, 23 Aug 2025 12:44:44 -0700 Subject: [PATCH] updated support for TEA5767 Updated the TEA5767 support due to manufacturing conflicts. the TEA5767 doesn't have support for multiple devices on the same bus sadly. So we needed to create a work around for that. --- src/TEA5767.cpp | 43 +++++++++++++++++++++++++++---------------- src/TEA5767.h | 6 +++++- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/TEA5767.cpp b/src/TEA5767.cpp index 2b8b817..c6481e1 100644 --- a/src/TEA5767.cpp +++ b/src/TEA5767.cpp @@ -76,16 +76,12 @@ // initialize the extra variables in SI4703 TEA5767::TEA5767() { + _i2cPort = &Wire; // DEFAULT: Point to the standard I2C bus. _maxVolume = 1; } -// initialize all internals. -bool TEA5767::init() { - bool result = false; // no chip found yet. - DEBUG_FUNC0("init"); - - RADIO::init(); // will create reset impulse - +// new private helper method +void TEA5767::_init() { registers[0] = 0x00; registers[1] = 0x00; registers[2] = 0xB0; @@ -96,11 +92,27 @@ bool TEA5767::init() { #else registers[REG_5] = REG_5_DTC; // 75 ms Europe setup #endif - Wire.begin(); +} - return(result); +// initialize all internals. +bool TEA5767::init() { + bool result = false; // no chip found yet. + DEBUG_FUNC0("init"); + RADIO::init(); // will create reset impulse + _i2cPort = &Wire; + _init(); + return(_wireExists(_i2cPort, TEA5767_ADR)); } // init() +// ADDING THE NEW INIT FUNCTION +bool TEA5767::initWire(TwoWire &port) { + bool result = false; + DEBUG_FUNC0("initWire"); + RADIO::init(); + _i2cPort = &port; + _init(); + return (_wireExists(_i2cPort, TEA5767_ADR)); +} // switch the power off void TEA5767::term() @@ -237,11 +249,11 @@ void TEA5767::seekDown(bool toNextSender) { /// Load all status registers from to the chip void TEA5767::_readRegisters() { - Wire.requestFrom(TEA5767_ADR, 5); // We want to read all the 5 registers. + _i2cPort->requestFrom(TEA5767_ADR, 5); // We want to read all the 5 registers. - if (Wire.available()) { + if (_i2cPort->available()) { for (uint8_t n = 0; n < 5; n++) { - status[n] = Wire.read(); + status[n] = _i2cPort->read(); } // for } // if } // _readRegisters @@ -251,12 +263,12 @@ void TEA5767::_readRegisters() // using the sequential write access mode. void TEA5767::_saveRegisters() { - Wire.beginTransmission(TEA5767_ADR); + _i2cPort->beginTransmission(TEA5767_ADR); for (uint8_t n = 0; n < sizeof(registers); n++) { - Wire.write(registers[n]); + _i2cPort->write(registers[n]); } // for - byte ack = Wire.endTransmission(); + byte ack = _i2cPort->endTransmission(); if (ack != 0) { //We have a problem! Serial.print("Write Fail:"); //No ACK! Serial.println(ack, DEC); //I2C error: 0 = success, 1 = data too long, 2 = rx NACK on address, 3 = rx NACK on data, 4 = other error @@ -313,4 +325,3 @@ void TEA5767::_waitEnd() { // The End. - diff --git a/src/TEA5767.h b/src/TEA5767.h index c5c7987..e8b8dc4 100644 --- a/src/TEA5767.h +++ b/src/TEA5767.h @@ -34,7 +34,8 @@ class TEA5767 : public RADIO { TEA5767(); bool init(); // initialize library and the chip. - void term(); // terminate all radio functions. + bool initWire(TwoWire &port) override; // ADDING THIS NEW INIT FUNCTION + void term() override; // terminate all radio functions UPDATED FOR OVERRIDING. // Control of the audio features @@ -91,6 +92,9 @@ class TEA5767 : public RADIO { void _seek(bool seekUp = true); void _waitEnd(); + + // ----- private helper methods needed + void _init(); }; #endif