Feature: Implement TwoWire support for TEA5767 #76
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This pull request adds support for utilizing a secondary I2C bus via
TwoWireto interface with the TEA5767 radio chip. The TEA5767 is known to be sensitive to shared I2C traffic, and when operated on the same bus as other peripherals (e.g., LCDs), it may suffer from degraded audio quality or complete communication failure.By enabling the use of a dedicated I2C bus, this update allows developers to isolate the TEA5767, mitigating interference and improving overall system reliability.
The Problem
The current TEA5767 implementation is hardcoded to use the global
Wireobject for I2C communication. This design limitation prevents developers from utilizing alternative I2C interfaces—such as the secondary bus available on the ESP32 or other multi-bus platforms—effectively forcing the TEA5767 to share the primary I2C bus with all other peripherals. This constraint can lead to resource contention and degraded performance, particularly in systems with sensitive or high-traffic devices.The Solution
This pull request implements the
initWire(TwoWire &port)virtual function, which exists in the baseRADIOclass but was previously unimplemented in theTEA5767subclass. This enhancement aligns with the library’s architecture for supporting multiple I2C buses.Key Changes:
Utilization of
_i2cPort:The base
RADIOclass provides aTwoWire* _i2cPortpointer. This PR updates theTEA5767class to use_i2cPortfor all I2C operations, replacing the previously hardcodedWireobject.Implementation of
initWire():The
initWire(TwoWire &port)method is now implemented. When invoked, it assigns the internal_i2cPortto the user-specified I2C bus, enabling flexible multi-bus support.Centralized Initialization Logic:
A private helper function
_init()has been introduced to handle the TEA5767’s register setup. Bothinit()andinitWire()now delegate to_init(), ensuring consistent configuration and eliminating code duplication.Backwards Compatibility:
The default constructor continues to set
_i2cPort = &Wire;, preserving existing behavior. Users calling the originalinit()function will experience no changes. As per standard practice, users are responsible for invokingWire.begin()themselves.How to Use this Feature
A developer can now choose which I2C bus to use at initialization.
Standard Usage (Default I2C Bus):
New Feature (Secondary I2C Bus):
Summary of Changes
TEA5767.h Updates:
bool initWire(TwoWire &port) override;to support custom I2C bus initialization.void _init();for centralized register setup.TEA5767.cpp Updates:
_i2cPort = &Wire;by default._init()to handle the TEA5767’s default register configuration.init()to delegate setup to_init()for consistent behavior.initWire()to assign_i2cPortto the user-provided I2C bus and invoke_init().Wirereferences in methods such as_readRegisters()and_writeRegisters()with the_i2cPortpointer.Impact:
These changes significantly improve the library’s flexibility, enabling seamless integration with multi-bus platforms like the ESP32. The update maintains full backward compatibility, ensuring existing implementations remain unaffected.