ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
tca9548a.cpp
Go to the documentation of this file.
1#include "tca9548a.h"
2#include "esphome/core/log.h"
3
5
6static const char *const TAG = "tca9548a";
7
8i2c::ErrorCode TCA9548AChannel::write_readv(uint8_t address, const uint8_t *write_buffer, size_t write_count,
9 uint8_t *read_buffer, size_t read_count) {
10 auto err = this->parent_->switch_to_channel(channel_);
11 if (err != i2c::ERROR_OK)
12 return err;
13 err = this->parent_->bus_->write_readv(address, write_buffer, write_count, read_buffer, read_count);
15 return err;
16}
18 uint8_t status = 0;
19 if (this->read(&status, 1) != i2c::ERROR_OK) {
20 ESP_LOGE(TAG, "TCA9548A failed");
21 this->mark_failed();
22 return;
23 }
24 ESP_LOGD(TAG, "Channels currently open: %d", status);
25}
27 ESP_LOGCONFIG(TAG, "TCA9548A:");
28 LOG_I2C_DEVICE(this);
29}
30
32 if (this->is_failed())
34
35 uint8_t channel_val = 1 << channel;
36 return this->write(&channel_val, 1);
37}
38
40 if (this->write(&TCA9548A_DISABLE_CHANNELS_COMMAND, 1) != i2c::ERROR_OK) {
41 ESP_LOGE(TAG, "Failed to disable all channels.");
42 this->status_set_error(); // couldn't disable channels, set error status
43 }
44}
45
46} // namespace esphome::tca9548a
uint8_t address
Definition bl0906.h:4
uint8_t status
Definition bl0942.h:8
void mark_failed()
Mark this component as failed.
bool is_failed() const
Definition component.h:272
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:183
I2CBus * bus_
pointer to I2CBus instance
Definition i2c.h:271
ErrorCode read(uint8_t *data, size_t len) const
reads an array of bytes from the device using an I2CBus
Definition i2c.h:163
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:8
TCA9548AComponent * parent_
Definition tca9548a.h:21
i2c::ErrorCode switch_to_channel(uint8_t channel)
Definition tca9548a.cpp:31
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
Definition i2c_bus.h:12
@ ERROR_OK
No error found during execution of method.
Definition i2c_bus.h:14
@ ERROR_NOT_INITIALIZED
call method to a not initialized bus
Definition i2c_bus.h:18