Skip to content

Commit 3172fd9

Browse files
committed
Fix both edge bug in gpio_irq_api.c
Fixes #22
1 parent ddbb67a commit 3172fd9

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/gpio_irq_api.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,20 @@ static inline void handle_interrupt_in(uint32_t channel) {
3737
uint8_t pin_num = (pin_names[channel] & (0x0f << PIN_SHIFT)) >> PIN_SHIFT;
3838
uint8_t trigger_event = trigger_events[channel];
3939

40-
if (trigger_event == 1) {
41-
// Rising edge.
40+
if (trigger_event == 1)
4241
irq_handler(channel_ids[channel], IRQ_RISE);
43-
}
44-
else if (trigger_event == 2) {
45-
// Low, therefore falling edge...
42+
else if (trigger_event == 2)
4643
irq_handler(channel_ids[channel], IRQ_FALL);
47-
}
4844
else {
49-
// This is supposed to be triggered by both cases...
50-
irq_handler(channel_ids[channel], IRQ_RISE);
45+
// In order to get an idea of which kind of event it is,
46+
// We need to read the logic level of the pin...
47+
48+
uint8_t logic = (port_reg->DATA & (1 << pin_num)) >> pin_num;
49+
50+
if (logic == 1)
51+
irq_handler(channel_ids[channel], IRQ_RISE);
52+
else
53+
irq_handler(channel_ids[channel], IRQ_FALL);
5154
}
5255

5356
// Clear the interrupt...

0 commit comments

Comments
 (0)