Skip to content

Commit 55f91f1

Browse files
committed
Fixed errors in gpio_irq_api.c
1 parent c56d1a5 commit 55f91f1

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ static inline void handle_interrupt_in(uint32_t channel) {
3232
// the level of the pin as if it were just a normal input...
3333

3434
// Get the number of the pin being used and the port typedef
35-
uint8_t pin_number = (pin_names[channel] & (0x0f << 8)) >> 8;
35+
uint32_t pin = (pin_names[channel] & (0x0f << 8)) >> 8;
3636
LPC_GPIO_TypeDef *port_reg = ((LPC_GPIO_TypeDef *) (LPC_GPIO0_BASE + (((pin & 0xF000) >> PORT_SHIFT) * 0x10000)));
37+
uint32_t logiclevel = port_reg->DATA;
38+
logiclevel &= (uint32_t)(1 << pin) >> pin;
3739

38-
if ((port_reg->MASKED_ACCESS & (1 << pin_number)) >> pin_number) {
40+
if (logiclevel == 1) {
3941
// High, therefore rising edge...
4042
irq_handler(channel_ids[channel], IRQ_RISE);
4143
}
@@ -66,27 +68,27 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
6668
}
6769
*/
6870

69-
channel_ids[channnel] = id;
71+
channel_ids[channel] = id;
7072
pin_names[channel] = pin;
7173
obj->ch = channel;
7274

7375
// Which port are we using?
7476
switch (channel) {
7577
case 0:
7678
NVIC_SetVector(EINT0_IRQn, (uint32_t)gpio_irq0);
77-
NVIC_EnableIrq(EINT0_IRQn);
79+
NVIC_EnableIRQ(EINT0_IRQn);
7880
break;
7981
case 1:
8082
NVIC_SetVector(EINT1_IRQn, (uint32_t)gpio_irq1);
81-
NVIC_EnableIrq(EINT1_IRQn);
83+
NVIC_EnableIRQ(EINT1_IRQn);
8284
break;
8385
case 2:
8486
NVIC_SetVector(EINT2_IRQn, (uint32_t)gpio_irq2);
85-
NVIC_EnableIrq(EINT2_IRQn);
87+
NVIC_EnableIRQ(EINT2_IRQn);
8688
break;
8789
case 3:
8890
NVIC_SetVector(EINT3_IRQn, (uint32_t)gpio_irq3);
89-
NVIC_EnableIrq(EINT3_IRQn);
91+
NVIC_EnableIRQ(EINT3_IRQn);
9092
break;
9193
}
9294

@@ -99,8 +101,7 @@ void gpio_irq_free(gpio_irq_t *obj) {
99101
}
100102

101103
void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) {
102-
pin = obj->pin;
103-
LPC_GPIO_TypeDef *port_reg = ((LPC_GPIO_TypeDef *) (LPC_GPIO0_BASE + (((pin & 0xF000) >> PORT_SHIFT) * 0x10000)));
104+
LPC_GPIO_TypeDef *port_reg = ((LPC_GPIO_TypeDef *) (LPC_GPIO0_BASE + (((obj->pin & 0xF000) >> PORT_SHIFT) * 0x10000)));
104105

105106
/*
106107
Firstly, clear the interrupts for this pin,

0 commit comments

Comments
 (0)