diff --git a/src/ExtensionIOXL9555.hpp b/src/ExtensionIOXL9555.hpp index 108868b..890e543 100644 --- a/src/ExtensionIOXL9555.hpp +++ b/src/ExtensionIOXL9555.hpp @@ -213,6 +213,10 @@ class ExtensionIOXL9555 : void setPinEvent(uint8_t pin, uint8_t mode, gpio_event_t event, void *user_data) { + if (pin > XL9555_MAX_PIN) { + log_e("XL9555 Max use io pin is 0 ~ 15 ."); + return; + } this->event[pin].cb = event; this->event[pin].mode = mode; this->event[pin].user_data = user_data; @@ -220,6 +224,10 @@ class ExtensionIOXL9555 : void removePinEvent(uint8_t pin) { + if (pin > XL9555_MAX_PIN) { + log_e("XL9555 Max use io pin is 0 ~ 15 ."); + return; + } this->event[pin].cb = NULL; } @@ -227,11 +235,11 @@ class ExtensionIOXL9555 : { uint16_t val = this->read(); - int i = 15; + int i = XL9555_MAX_PIN; for (; i >= 0; i--) { - uint8_t _index = 15 - i; + uint8_t _index = XL9555_MAX_PIN - i; if (this->event[_index].cb != NULL) { diff --git a/src/REG/XL9555Constants.h b/src/REG/XL9555Constants.h index 8e62b4f..7061e41 100644 --- a/src/REG/XL9555Constants.h +++ b/src/REG/XL9555Constants.h @@ -28,6 +28,6 @@ // Configuration Port 1 /RW #define XL9555_CTRL_CFG1 (0x07) - +#define XL9555_MAX_PIN (15)