ESPHome 2025.9.0
Loading...
Searching...
No Matches
tca9548a.cpp
Go to the documentation of this file.
1#include "tca9548a.h"
2#include "esphome/core/log.h"
3
4namespace esphome {
5namespace tca9548a {
6
7static const char *const TAG = "tca9548a";
8
9i2c::ErrorCode TCA9548AChannel::write_readv(uint8_t address, const uint8_t *write_buffer, size_t write_count,
10 uint8_t *read_buffer, size_t read_count) {
12 if (err != i2c::ERROR_OK)
13 return err;
14 err = this->parent_->bus_->write_readv(address, write_buffer, write_count, read_buffer, read_count);
16 return err;
17}
19 uint8_t status = 0;
20 if (this->read(&status, 1) != i2c::ERROR_OK) {
21 ESP_LOGE(TAG, "TCA9548A failed");
22 this->mark_failed();
23 return;
24 }
25 ESP_LOGD(TAG, "Channels currently open: %d", status);
26}
28 ESP_LOGCONFIG(TAG, "TCA9548A:");
29 LOG_I2C_DEVICE(this);
30}
31
33 if (this->is_failed())
35
36 uint8_t channel_val = 1 << channel;
37 return this->write(&channel_val, 1);
38}
39
41 if (this->write(&TCA9548A_DISABLE_CHANNELS_COMMAND, 1) != i2c::ERROR_OK) {
42 ESP_LOGE(TAG, "Failed to disable all channels.");
43 this->status_set_error(); // couldn't disable channels, set error status
44 }
45}
46
47} // namespace tca9548a
48} // namespace esphome
uint8_t address
Definition bl0906.h:4
uint8_t status
Definition bl0942.h:8
virtual void mark_failed()
Mark this component as failed.
bool is_failed() const
void status_set_error(const char *message=nullptr)
virtual ErrorCode write_readv(uint8_t address, const uint8_t *write_buffer, size_t write_count, uint8_t *read_buffer, size_t read_count)=0
This virtual method writes bytes to an I2CBus from an array, then reads bytes into an array of ReadBu...
ErrorCode write(const uint8_t *data, size_t len) const
writes an array of bytes to a device using an I2CBus
Definition i2c.h:184
I2CBus * bus_
pointer to I2CBus instance
Definition i2c.h:303
ErrorCode read(uint8_t *data, size_t len) const
reads an array of bytes from the device using an I2CBus
Definition i2c.h:164
i2c::ErrorCode write_readv(uint8_t address, const uint8_t *write_buffer, size_t write_count, uint8_t *read_buffer, size_t read_count) override
Definition tca9548a.cpp:9
TCA9548AComponent * parent_
Definition tca9548a.h:22
i2c::ErrorCode switch_to_channel(uint8_t channel)
Definition tca9548a.cpp:32
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
Definition i2c_bus.h:31
@ ERROR_OK
No error found during execution of method.
Definition i2c_bus.h:33
@ ERROR_NOT_INITIALIZED
call method to a not initialized bus
Definition i2c_bus.h:37
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7