From 1da8e8a2c72a2d8bed36645463c95ea6952ad5bf Mon Sep 17 00:00:00 2001 From: Matthew Else Date: Mon, 22 Jul 2013 13:30:00 +0100 Subject: [PATCH] Started to implement gpio_irq_set --- .../TARGET_NXP/TARGET_LPC11XX/gpio_irq_api.c | 60 ++++++++++++------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/gpio_irq_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/gpio_irq_api.c index aaff0d0d8a..55f7d15a09 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/gpio_irq_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX/gpio_irq_api.c @@ -23,6 +23,7 @@ static uint32_t channel_ids[CHANNEL_NUM] = {0}; static gpio_irq_handler irq_handler; +static int gpioIrqInitialised = 0; #warning (matthewelse) This code isn't working yet, so don't rely on it, or try to use it. @@ -56,6 +57,7 @@ void gpio_irq3(void) {handle_interrupt_in(3);} int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) { if (pin == NC) return -1; + if (gpioInitialised) return; irq_handler = handler; @@ -96,6 +98,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32 NVIC_SetVector((IRQn_Type)(PININT_IRQ - obj->ch)), (uint32_t)channels_irq); NVIC_EnableIRQ((IRQn_Type)(PININT_IRQ - obj->ch)); + gpioInitialised = 1; return 0; } @@ -105,27 +108,40 @@ void gpio_irq_free(gpio_irq_t *obj) { } void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) { - unsigned int ch_bit = (1 << obj->ch); - - LPC_GPIO_TypeDef *port_reg = ((LPC_GPIO_TypeDef *) LPC_GPIO0_BASE + (obj->ch * 0x10000)); + if (!gpioIqrInitialised) gpio_irq_init(); - // Clear interrupt - if (!(&port_reg->ISEL & ch_bit)) - &port_reg->IST = ch_bit; - - // Edge trigger - &port_reg->ISEL &= ~ch_bit; - if (event == IRQ_RISE) { - if (enable) { - &port_reg->IENR |= ch_bit; - } else { - &port_reg->IENR &= ~ch_bit; - } - } else { - if (enable) { - &port_reg->IENF |= ch_bit; - } else { - &port_reg->IENF &= ~ch_bit; - } +#warning (matthewelse) TODO: undefined port and value. Also need to do something with the *obj... + int port = 0; + int pin = 0; + + LPC_GPIO_TypeDef *gpioRegisters; + + switch (port) { + case 0: + gpioRegisters = LPC_GPIO0; + break; + case 1: + gpioRegisters = LPC_GPIO1; + break; + case 2: + gpioRegisters = LPC_GPIO2; + break; + case 3: + gpioRegisters = LPC_GPIO3; + break; } -} \ No newline at end of file + + gpioRegisters->IBE 0; // Assume that we only want to interrupt on high or low edges, not both. + gpioRegisters->IS &= ~(1 << pin); + + if (enable) { + gpioRegisters->IE |= (1<IEV |= 1 << pin; + } + else { + gpioRegisters->IEV &= ~(1 << pin); + } +}