Fix pin_interrupt_mode overriding auto-enabled CHANGE interrupt

MCP23XXXGPIOPin::setup() calls pin_interrupt_mode(pin, NO_INTERRUPT)
after pin_mode() already auto-enabled CHANGE, undoing the auto-enable.
Skip the explicit pin_interrupt_mode call when interrupt_pin is
configured and the user didn't override the default.
This commit is contained in:
J. Nick Koston
2026-04-04 10:05:00 -10:00
parent 85036d64d9
commit 1e9e5ca763
2 changed files with 7 additions and 1 deletions
@@ -7,7 +7,12 @@ namespace mcp23xxx_base {
template<uint8_t N> void MCP23XXXGPIOPin<N>::setup() {
this->pin_mode(flags_);
this->parent_->pin_interrupt_mode(this->pin_, this->interrupt_mode_);
// When interrupt_pin is configured, pin_mode() already auto-enables CHANGE
// interrupt for input pins, so skip the explicit call if the user didn't
// override the default (NO_INTERRUPT)
if (this->interrupt_mode_ != MCP23XXX_NO_INTERRUPT || this->parent_->get_interrupt_pin() == nullptr) {
this->parent_->pin_interrupt_mode(this->pin_, this->interrupt_mode_);
}
}
template<uint8_t N> void MCP23XXXGPIOPin<N>::pin_mode(gpio::Flags flags) { this->parent_->pin_mode(this->pin_, flags); }
template<uint8_t N> bool MCP23XXXGPIOPin<N>::digital_read() {
@@ -16,6 +16,7 @@ template<uint8_t N> class MCP23XXXBase : public Component, public gpio_expander:
void set_open_drain_ints(const bool value) { this->open_drain_ints_ = value; }
void set_interrupt_pin(InternalGPIOPin *pin) { this->interrupt_pin_ = pin; }
InternalGPIOPin *get_interrupt_pin() const { return this->interrupt_pin_; }
float get_setup_priority() const override { return setup_priority::IO; }
void loop() override {