mirror of https://github.com/ARMmbed/mbed-os.git
M2351: Fix GPIO rising/falling edge interrupts cannot exist simultaneously
parent
a2c9ae6b7d
commit
6f793fbb5a
|
@ -23,6 +23,7 @@
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "PeripheralPins.h"
|
#include "PeripheralPins.h"
|
||||||
#include "nu_bitutil.h"
|
#include "nu_bitutil.h"
|
||||||
|
#include "mbed_assert.h"
|
||||||
|
|
||||||
#define NU_MAX_PIN_PER_PORT 16
|
#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->pin = pin;
|
||||||
|
obj->irq_types = 0;
|
||||||
obj->irq_handler = (uint32_t) handler;
|
obj->irq_handler = (uint32_t) handler;
|
||||||
obj->irq_id = id;
|
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);
|
uint32_t port_index = NU_PINNAME_TO_PORT(obj->pin);
|
||||||
GPIO_T *gpio_base = NU_PORT_BASE(port_index);
|
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) {
|
switch (event) {
|
||||||
case IRQ_RISE:
|
case IRQ_RISE:
|
||||||
if (enable) {
|
irq_type = GPIO_INT_RISING;
|
||||||
GPIO_EnableInt(gpio_base, pin_index, GPIO_INT_RISING);
|
break;
|
||||||
} else {
|
|
||||||
gpio_base->INTEN &= ~(GPIO_INT_RISING << pin_index);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IRQ_FALL:
|
case IRQ_FALL:
|
||||||
if (enable) {
|
irq_type = GPIO_INT_FALLING;
|
||||||
GPIO_EnableInt(gpio_base, pin_index, GPIO_INT_FALLING);
|
break;
|
||||||
} else {
|
|
||||||
gpio_base->INTEN &= ~(GPIO_INT_FALLING << pin_index);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IRQ_NONE:
|
default:
|
||||||
default:
|
irq_type = 0;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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)
|
void gpio_irq_enable(gpio_irq_t *obj)
|
||||||
|
|
|
@ -29,6 +29,7 @@ extern "C" {
|
||||||
|
|
||||||
struct gpio_irq_s {
|
struct gpio_irq_s {
|
||||||
PinName pin;
|
PinName pin;
|
||||||
|
uint32_t irq_types;
|
||||||
uint32_t irq_handler;
|
uint32_t irq_handler;
|
||||||
uint32_t irq_id;
|
uint32_t irq_id;
|
||||||
struct gpio_irq_s *next;
|
struct gpio_irq_s *next;
|
||||||
|
|
Loading…
Reference in New Issue