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:
J. Nick Koston
2026-04-04 10:21:28 -10:00
parent 1e9e5ca763
commit aeb8e9413b
5 changed files with 23 additions and 1 deletions
+5
View File
@@ -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_();
}
+6
View File
@@ -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_();
}
+5
View File
@@ -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_();
}
+6
View File
@@ -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;
}