1
0
mirror of https://github.com/esphome/esphome.git synced 2026-03-21 02:36:45 +01:00
Andreas Hergert 9e23987db8
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>
2021-03-29 16:50:30 -03:00

42 lines
1.1 KiB
C++

#include "tca9548a.h"
#include "esphome/core/log.h"
namespace esphome {
namespace tca9548a {
static const char *TAG = "tca9548a";
void TCA9548AComponent::setup() {
ESP_LOGCONFIG(TAG, "Setting up TCA9548A...");
uint8_t status = 0;
if (!this->read_byte(0x00, &status)) {
ESP_LOGI(TAG, "TCA9548A failed");
return;
}
// out of range to make sure on first set_channel a new one will be set
this->current_channelno_ = 8;
ESP_LOGCONFIG(TAG, "Channels currently open: %d", status);
}
void TCA9548AComponent::dump_config() {
ESP_LOGCONFIG(TAG, "TCA9548A:");
LOG_I2C_DEVICE(this);
if (this->scan_) {
for (uint8_t i = 0; i < 8; i++) {
ESP_LOGCONFIG(TAG, "Activating channel: %d", i);
this->set_channel(i);
this->parent_->dump_config();
}
}
}
void TCA9548AComponent::set_channel(uint8_t channelno) {
if (this->current_channelno_ != channelno) {
this->current_channelno_ = channelno;
uint8_t channelbyte = 1 << channelno;
this->write_byte(0x70, channelbyte);
}
}
} // namespace tca9548a
} // namespace esphome