Skip to content

Commit 07ce9d2

Browse files
committed
fix io_expander hal lib
1 parent e27f677 commit 07ce9d2

1 file changed

Lines changed: 30 additions & 15 deletions

File tree

lib/HAL/io_expander/io_expander.h

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ class io_expander : public IO_EXP_CLASS {
6262
private:
6363
bool _started = false;
6464

65+
static void clearInterruptBit(uint16_t &mask, int8_t pin) {
66+
if (pin >= 0 && pin <= 15) {
67+
mask = static_cast<uint16_t>(mask & ~(static_cast<uint16_t>(1u) << static_cast<uint8_t>(pin)));
68+
}
69+
}
70+
71+
bool interruptEnableGPIOWrapper(uint16_t mask) {
72+
#if defined(IO_EXPANDER_AW9523)
73+
return interruptEnableGPIO(mask);
74+
#else
75+
(void)mask;
76+
return true;
77+
#endif
78+
}
79+
6580
public:
6681
io_expander() : IO_EXP_CLASS() {};
6782

@@ -88,7 +103,7 @@ class io_expander : public IO_EXP_CLASS {
88103
button(IO_EXP_SEL);
89104

90105
// IMPORTANT: Disable all interrupts at startup
91-
interruptEnableGPIO(0x0000);
106+
interruptEnableGPIOWrapper(0x0000);
92107

93108
return _started;
94109
}
@@ -112,25 +127,25 @@ class io_expander : public IO_EXP_CLASS {
112127
if (pin >= 0 && pin <= 15) { setPinDirection(pin, INPUT); }
113128
}
114129

115-
bool enableGPIOInterrupts() {
116-
if (!_started) return false;
130+
bool enableGPIOInterrupts() {
131+
if (!_started) return false;
117132

118-
// Start with ALL interrupts DISABLED (bits = 1 = disable)
119-
uint16_t mask = 0xFFFF;
133+
// Start with ALL interrupts DISABLED (bits = 1 = disable)
134+
uint16_t mask = 0xFFFF;
120135

121-
// Clear bits (set to 0 = enable) for the input/button pins
122-
if (IO_EXP_UP >= 0 && IO_EXP_UP <= 15) mask &= ~(1 << IO_EXP_UP);
123-
if (IO_EXP_DOWN >= 0 && IO_EXP_DOWN <= 15) mask &= ~(1 << IO_EXP_DOWN);
124-
if (IO_EXP_ESC >= 0 && IO_EXP_ESC <= 15) mask &= ~(1 << IO_EXP_ESC);
125-
if (IO_EXP_LEFT >= 0 && IO_EXP_LEFT <= 15) mask &= ~(1 << IO_EXP_LEFT);
126-
if (IO_EXP_RIGHT >= 0 && IO_EXP_RIGHT <= 15) mask &= ~(1 << IO_EXP_RIGHT);
127-
if (IO_EXP_SEL >= 0 && IO_EXP_SEL <= 15) mask &= ~(1 << IO_EXP_SEL);
136+
// Clear bits (set to 0 = enable) for the input/button pins
137+
clearInterruptBit(mask, IO_EXP_UP);
138+
clearInterruptBit(mask, IO_EXP_DOWN);
139+
clearInterruptBit(mask, IO_EXP_ESC);
140+
clearInterruptBit(mask, IO_EXP_LEFT);
141+
clearInterruptBit(mask, IO_EXP_RIGHT);
142+
clearInterruptBit(mask, IO_EXP_SEL);
128143

129-
return interruptEnableGPIO(mask);
130-
}
144+
return interruptEnableGPIOWrapper(mask);
145+
}
131146
// Optional: turn off all interrupts
132147
void disableGPIOInterrupts() {
133-
if (_started) interruptEnableGPIO(0x0000);
148+
if (_started) interruptEnableGPIOWrapper(0x0000);
134149
}
135150
};
136151

0 commit comments

Comments
 (0)