drivers: gpio_mcux_igpio: fix code disabling the interrupt

When disabling the interrupt current implementation of the
gpio_pin_interrupt_configure function will first reconfigure the
interrupt to be active on gpio low level.
Since the pin interrupt is enabled if the gpio pin level happens
to be low at the time the interrupt will trigger immediately.
Rewrite the function to disable the interrupt in a safe manner.

Signed-off-by: Frank Li <lgl88911@163.com>
This commit is contained in:
Frank Li 2020-03-18 22:23:34 +08:00 committed by Maureen Helm
commit 007aa031b5

View file

@ -123,6 +123,17 @@ static int mcux_igpio_pin_interrupt_configure(struct device *dev,
u8_t icr; u8_t icr;
int shift; int shift;
if (mode == GPIO_INT_MODE_DISABLED) {
key = irq_lock();
WRITE_BIT(base->IMR, pin, 0);
WRITE_BIT(data->pin_callback_enables, pin, 0);
irq_unlock(key);
return 0;
}
if ((mode == GPIO_INT_MODE_EDGE) && (trig == GPIO_INT_TRIG_LOW)) { if ((mode == GPIO_INT_MODE_EDGE) && (trig == GPIO_INT_TRIG_LOW)) {
icr = 3; icr = 3;
} else if ((mode == GPIO_INT_MODE_EDGE) && } else if ((mode == GPIO_INT_MODE_EDGE) &&
@ -148,10 +159,9 @@ static int mcux_igpio_pin_interrupt_configure(struct device *dev,
key = irq_lock(); key = irq_lock();
WRITE_BIT(base->EDGE_SEL, pin, trig == GPIO_INT_TRIG_BOTH); WRITE_BIT(base->EDGE_SEL, pin, trig == GPIO_INT_TRIG_BOTH);
WRITE_BIT(base->ISR, pin, mode != GPIO_INT_MODE_DISABLED); WRITE_BIT(base->ISR, pin, 1);
WRITE_BIT(base->IMR, pin, mode != GPIO_INT_MODE_DISABLED); WRITE_BIT(base->IMR, pin, 1);
WRITE_BIT(data->pin_callback_enables, pin, WRITE_BIT(data->pin_callback_enables, pin, 1);
mode != GPIO_INT_MODE_DISABLED);
irq_unlock(key); irq_unlock(key);