M2351: Fix GPIO rising/falling edge interrupts cannot exist simultaneously

pull/12404/head
Chun-Chieh Li 2020-02-07 15:48:57 +08:00
parent a2c9ae6b7d
commit 6f793fbb5a
2 changed files with 25 additions and 17 deletions

View File

@ -23,6 +23,7 @@
#include "pinmap.h"
#include "PeripheralPins.h"
#include "nu_bitutil.h"
#include "mbed_assert.h"
#define NU_MAX_PIN_PER_PORT 16
@ -89,6 +90,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
}
obj->pin = pin;
obj->irq_types = 0;
obj->irq_handler = (uint32_t) handler;
obj->irq_id = id;
@ -156,27 +158,32 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
uint32_t port_index = NU_PINNAME_TO_PORT(obj->pin);
GPIO_T *gpio_base = NU_PORT_BASE(port_index);
/* We assume BSP has such coding so that we can easily add/remove either irq type. */
MBED_STATIC_ASSERT(GPIO_INT_BOTH_EDGE == (GPIO_INT_RISING | GPIO_INT_FALLING),
"GPIO_INT_BOTH_EDGE must be bitwise OR of GPIO_INT_RISING and GPIO_INT_FALLING");
uint32_t irq_type;
switch (event) {
case IRQ_RISE:
if (enable) {
GPIO_EnableInt(gpio_base, pin_index, GPIO_INT_RISING);
} else {
gpio_base->INTEN &= ~(GPIO_INT_RISING << pin_index);
}
break;
case IRQ_RISE:
irq_type = GPIO_INT_RISING;
break;
case IRQ_FALL:
if (enable) {
GPIO_EnableInt(gpio_base, pin_index, GPIO_INT_FALLING);
} else {
gpio_base->INTEN &= ~(GPIO_INT_FALLING << pin_index);
}
break;
case IRQ_FALL:
irq_type = GPIO_INT_FALLING;
break;
case IRQ_NONE:
default:
break;
default:
irq_type = 0;
}
/* We can handle invalid/null irq type. */
if (enable) {
obj->irq_types |= irq_type;
} else {
obj->irq_types &= ~irq_type;
}
/* Update irq types */
GPIO_EnableInt(gpio_base, pin_index, obj->irq_types);
}
void gpio_irq_enable(gpio_irq_t *obj)

View File

@ -29,6 +29,7 @@ extern "C" {
struct gpio_irq_s {
PinName pin;
uint32_t irq_types;
uint32_t irq_handler;
uint32_t irq_id;
struct gpio_irq_s *next;