8static constexpr uint8_t INPUT_REG = 0;
9static constexpr uint8_t OUTPUT_REG = 1;
10static constexpr uint8_t INVERT_REG = 2;
11static constexpr uint8_t CONFIG_REG = 3;
13#ifdef USE_PCA9554_PCAL
15static constexpr uint8_t PCAL_BASE = 0x40;
16static constexpr uint8_t OUTPUT_DRIVE_0 = 0;
17static constexpr uint8_t OUTPUT_DRIVE_1 = 1;
18static constexpr uint8_t INPUT_LATCH = 2;
19static constexpr uint8_t PUPD_ENABLE = 3;
20static constexpr uint8_t PUPD_SEL = 4;
21static constexpr uint8_t INTERRUPT_MASK = 5;
29 ESP_LOGE(TAG,
"PCA95xx not detected at 0x%02X", this->
address_);
43#ifdef USE_PCA9554_PCAL
52 ESP_LOGD(TAG,
"Initialization complete. Warning: %d, Error: %d", this->
status_has_warning(),
63#ifdef USE_PCA9554_PCAL
64 ESP_LOGCONFIG(TAG,
" PCAL registers: %s", YESNO(this->
pcal_));
82#ifdef USE_PCA9554_PCAL
101#ifdef USE_PCA9554_PCAL
103 const uint16_t bit = 1U << pin;
119 ESP_LOGD(TAG,
"Device marked failed");
125 ESP_LOGE(TAG,
"read_register_(): I2C I/O error: %d", (
int) err);
129 if (this->reg_width_ == 2) {
132#ifdef USE_PCA9554_PCAL
141 outputs[0] = (uint8_t) value;
142 outputs[1] = (uint8_t) (value >> 8);
145 ESP_LOGE(TAG,
"write_register(): I2C I/O error: %d", (
int) err);
151#ifdef USE_PCA9554_PCAL
172 const uint16_t updated = (shadow & ~mask) | (value & mask);
void mark_failed()
Mark this component as failed.
bool status_comm_result(bool ok)
Clears the warning when ok, else sets it with message (default "Communication failed"); returns ok.
bool status_has_warning() const
bool status_has_error() const
void setup_interrupt_pin_()
InternalGPIOPin * interrupt_pin_
void enable_polling_loop_()
Call from pin_mode() for an input pin: without an interrupt pin the loop polls instead.
ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len) const
writes an array of bytes to a specific register in the I²C device
uint8_t address_
store the address of the device on the bus
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len)
reads an array of bytes from a specific register in the I²C device
void dump_config() override
bool write_pcal_shadows_()
Write every PCAL shadow to the chip; false when any write failed.
bool digital_read_cache(uint8_t pin) override
const uint8_t reg_width_
width of registers
bool write_register_(uint8_t reg, uint16_t value)
uint32_t drive_
Drive strength shadow, two bits per pin; the low reg_width_ bytes go to OUTPUT_DRIVE_0.
void retry_pcal_shadows_()
Retry the shadows when an earlier PCAL write failed.
uint16_t output_mask_
The mask to write as output state - 1 means HIGH, 0 means LOW.
void digital_write_hw(uint8_t pin, bool value) override
bool write_address_(uint8_t address, uint16_t value)
const uint8_t pin_count_
number of bits the expander has
void update_pcal_register_(uint8_t reg, uint16_t &shadow, uint16_t mask, uint16_t value)
Changes the masked bits of a shadow and writes the register only when it changed.
bool digital_read_hw(uint8_t pin) override
uint16_t input_mask_
The state of the actual input pins - 1 means HIGH, 0 means LOW.
void pin_mode(uint8_t pin, gpio::Flags flags)
Helper function to set the pin mode of a pin.
uint16_t config_mask_
Mask for the pin config - 1 means OUTPUT, 0 means INPUT.
bool write_pcal_register_(uint8_t reg, uint16_t value)
void setup() override
Check i2c availability and setup masks.
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
@ ERROR_OK
No error found during execution of method.
ESPHOME_LOG_TAG(TAG, "pca9554")
ESPHOME_ALWAYS_INLINE constexpr void assign_bits(T &value, std::type_identity_t< T > mask, bool on)
Set the bits of mask in value when on is true, clear them otherwise.