mirror of
https://github.com/esphome/esphome.git
synced 2026-06-01 09:25:09 +08:00
Clear latched MCP23xxx interrupts during setup, fix uint8_t truncation
- MCP23008/MCP23S08: Read GPIO register before attaching ISR to clear any latched interrupt from a previous MCU run (chip may stay powered) - MCP23017/MCP23S17: Read both GPIOA and GPIOB to clear latched state - PI4IOE5V6408: Add explicit static_cast<uint8_t> for ~mode_mask_ to avoid implicit int-to-uint8_t truncation
This commit is contained in:
@@ -23,6 +23,11 @@ void MCP23008::setup() {
|
||||
this->write_reg(mcp23x08_base::MCP23X08_IOCON, iocon | IOCON_ODR);
|
||||
}
|
||||
|
||||
// Clear any latched interrupt by reading GPIO before attaching ISR
|
||||
if (this->interrupt_pin_ != nullptr) {
|
||||
uint8_t val;
|
||||
this->read_reg(mcp23x08_base::MCP23X08_GPIO, &val);
|
||||
}
|
||||
this->setup_interrupt_pin_();
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,12 @@ void MCP23017::setup() {
|
||||
this->write_reg(mcp23x17_base::MCP23X17_IOCONB, iocon | iocon_flags);
|
||||
}
|
||||
|
||||
// Clear any latched interrupt by reading GPIO before attaching ISR
|
||||
if (this->interrupt_pin_ != nullptr) {
|
||||
uint8_t val;
|
||||
this->read_reg(mcp23x17_base::MCP23X17_GPIOA, &val);
|
||||
this->read_reg(mcp23x17_base::MCP23X17_GPIOB, &val);
|
||||
}
|
||||
this->setup_interrupt_pin_();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,11 @@ void MCP23S08::setup() {
|
||||
this->write_reg(mcp23x08_base::MCP23X08_IOCON, IOCON_SEQOP | IOCON_HAEN | IOCON_ODR);
|
||||
}
|
||||
|
||||
// Clear any latched interrupt by reading GPIO before attaching ISR
|
||||
if (this->interrupt_pin_ != nullptr) {
|
||||
uint8_t val;
|
||||
this->read_reg(mcp23x08_base::MCP23X08_GPIO, &val);
|
||||
}
|
||||
this->setup_interrupt_pin_();
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,12 @@ void MCP23S17::setup() {
|
||||
this->write_reg(mcp23x17_base::MCP23X17_IOCONB, iocon_flags);
|
||||
}
|
||||
|
||||
// Clear any latched interrupt by reading GPIO before attaching ISR
|
||||
if (this->interrupt_pin_ != nullptr) {
|
||||
uint8_t val;
|
||||
this->read_reg(mcp23x17_base::MCP23X17_GPIOA, &val);
|
||||
this->read_reg(mcp23x17_base::MCP23X17_GPIOB, &val);
|
||||
}
|
||||
this->setup_interrupt_pin_();
|
||||
}
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ bool PI4IOE5V6408Component::write_gpio_modes_() {
|
||||
// Enable interrupts for input pins when interrupt pin is configured
|
||||
// (input pins have mode_mask_ bit cleared)
|
||||
if (this->interrupt_pin_ != nullptr &&
|
||||
!this->write_byte(PI4IOE5V6408_REGISTER_INTERRUPT_ENABLE_MASK, ~this->mode_mask_)) {
|
||||
!this->write_byte(PI4IOE5V6408_REGISTER_INTERRUPT_ENABLE_MASK, static_cast<uint8_t>(~this->mode_mask_))) {
|
||||
this->status_set_warning(LOG_STR("Failed to write interrupt enable mask"));
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user