Add I2CMultiplexer in generel and the TCA9548A in special (#1410)

* Added I2CMultiplexer in generel and the TCA9548A in special

* cleanup

* tidy

* tidy

* tidy

* tidy

* Update CODEOWNERS

* Update CODEOWNERS

* added CODEOWNERS

* Fix CODEOWNERS

* protected function

* fixed scan

* fixed style

* added to test1.yaml

* Update esphome/components/tca9548a/__init__.py

* Update esphome/components/i2c/__init__.py

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>

* Update esphome/components/i2c/i2c.cpp

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>

* Update esphome/components/i2c/__init__.py

* Update esphome/components/i2c/__init__.py

Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>

* Update esphome/components/i2c/i2c.cpp

Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>

* added define statements for I2C Multiplexer

* fix

* try to tidy

* bug fix

* tidy

* override fix

* only change channel if different

* tidy

* added test

* testfix

* added defines

* tidy

* fix dep

* like recommended

Co-authored-by: Andreas Hergert <andreas.hergert@otrs.com>
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
This commit is contained in:
Andreas Hergert
2021-03-29 21:50:30 +02:00
committed by GitHub
parent ad76312f66
commit 9e23987db8
8 changed files with 178 additions and 3 deletions
+17 -3
View File
@@ -1,6 +1,7 @@
#pragma once
#include <Wire.h>
#include "esphome/core/defines.h"
#include "esphome/core/component.h"
#include "esphome/core/helpers.h"
@@ -135,7 +136,7 @@ extern uint8_t next_i2c_bus_num_;
#endif
class I2CDevice;
class I2CMultiplexer;
class I2CRegister {
public:
I2CRegister(I2CDevice *parent, uint8_t a_register) : parent_(parent), register_(a_register) {}
@@ -167,7 +168,10 @@ class I2CDevice {
/// Manually set the i2c address of this device.
void set_i2c_address(uint8_t address);
#ifdef USE_I2C_MULTIPLEXER
/// Manually set the i2c multiplexer of this device.
void set_i2c_multiplexer(I2CMultiplexer *multiplexer, uint8_t channel);
#endif
/// Manually set the parent i2c bus for this device.
void set_i2c_parent(I2CComponent *parent);
@@ -280,9 +284,19 @@ class I2CDevice {
bool write_byte_16(uint8_t a_register, uint16_t data);
protected:
// Checks for multiplexer set and set channel
void check_multiplexer_();
uint8_t address_{0x00};
I2CComponent *parent_{nullptr};
#ifdef USE_I2C_MULTIPLEXER
I2CMultiplexer *multiplexer_{nullptr};
uint8_t channel_;
#endif
};
class I2CMultiplexer : public I2CDevice {
public:
I2CMultiplexer() = default;
virtual void set_channel(uint8_t channelno);
};
} // namespace i2c
} // namespace esphome