diff --git a/cpu/cc2538/periph/gpio.c b/cpu/cc2538/periph/gpio.c index 9356205390..464921dcad 100644 --- a/cpu/cc2538/periph/gpio.c +++ b/cpu/cc2538/periph/gpio.c @@ -24,6 +24,7 @@ #include #include "cpu.h" +#include "bitarithm.h" #include "periph/gpio.h" #define ENABLE_DEBUG (0) @@ -222,10 +223,9 @@ static inline void handle_isr(uint8_t port_num) /* mask all non-GPIO bits */ state &= (1 << GPIO_BITS_PER_PORT) - 1; + uint8_t pin = 0; while (state) { - /* we want the position of the first one bit, so N_bits - (N_zeros + 1) */ - int pin = 32 - __builtin_clz(state) - 1; - state &= ~(1 << pin); + state = bitarithm_test_and_clear(state, &pin); isr_ctx[port_num][pin].cb(isr_ctx[port_num][pin].arg); }