Skip to content

Commit ecb444b

Browse files
mmahadevan108Evelyne Donnaes
authored andcommitted
MCUXpresso: Fix the LPC GPIO IRQ driver
The IRQ disable was always disabling both rising and falling edges of the interrupt thereby causing failures in cases when one of the two should stay enabled. Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent f23bb08 commit ecb444b

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC/gpio_irq_api.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
6767
return -1;
6868
}
6969

70+
obj->pin = pin & 0x1F;
71+
obj->port = pin / 32;
72+
73+
if (obj->port >= INTERRUPT_PORTS) {
74+
return -1;
75+
}
76+
7077
irq_handler = handler;
7178

7279
for (i = 0; i < NUMBER_OF_GPIO_INTS; i++) {
@@ -82,13 +89,6 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
8289
return -1;
8390
}
8491

85-
obj->pin = pin & 0x1F;
86-
obj->port = pin / 32;
87-
88-
if (obj->port >= INTERRUPT_PORTS) {
89-
return -1;
90-
}
91-
9292
/* Connect trigger sources to PINT */
9393
INPUTMUX_Init(INPUTMUX);
9494

@@ -139,7 +139,26 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
139139
}
140140
}
141141
} else {
142-
PINT_PinInterruptConfig(PINT, (pint_pin_int_t)obj->ch, kPINT_PinIntEnableNone, NULL);
142+
if (event == IRQ_RISE) {
143+
/* Checking if falling edge interrupt is already enabled on this pin */
144+
if (PINT->IENF & (1U << obj->ch)) {
145+
/* Leave falling edge interrupt enabled */
146+
PINT_PinInterruptConfig(PINT, (pint_pin_int_t)obj->ch, kPINT_PinIntEnableFallEdge, pint_intr_callback);
147+
} else {
148+
/* Both rising and falling edge interrupt are disabled */
149+
PINT_PinInterruptConfig(PINT, (pint_pin_int_t)obj->ch, kPINT_PinIntEnableNone, pint_intr_callback);
150+
}
151+
} else {
152+
/* Checking if rising edge interrupt is already enabled on this pin */
153+
if (PINT->IENR & (1U << obj->ch)) {
154+
/* Leave rising edge interrupt enabled */
155+
PINT_PinInterruptConfig(PINT, (pint_pin_int_t)obj->ch, kPINT_PinIntEnableRiseEdge, pint_intr_callback);
156+
} else {
157+
/* Both rising and falling edge interrupt are disabled */
158+
PINT_PinInterruptConfig(PINT, (pint_pin_int_t)obj->ch, kPINT_PinIntEnableNone, pint_intr_callback);
159+
}
160+
}
161+
143162
}
144163
}
145164

0 commit comments

Comments
 (0)