Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions src/TEA5767.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -313,4 +325,3 @@ void TEA5767::_waitEnd() {

// The End.


6 changes: 5 additions & 1 deletion src/TEA5767.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -91,6 +92,9 @@ class TEA5767 : public RADIO {

void _seek(bool seekUp = true);
void _waitEnd();

// ----- private helper methods needed
void _init();
};

#endif