mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
Diff: targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/gpio_irq_api.c
- Revision:
- 172:2f4f8c56b261
- Parent:
- 158:3121b9889f7b
- Child:
- 250:a49055e7a707
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/gpio_irq_api.c Fri Apr 25 14:45:06 2014 +0100 +++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/gpio_irq_api.c Mon Apr 28 16:00:08 2014 +0100 @@ -29,10 +29,8 @@ */ #include <stddef.h> #include "cmsis.h" - #include "gpio_irq_api.h" #include "pinmap.h" -#include "stm32f4xx_hal.h" #include "error.h" #define EDGE_NONE (0) @@ -54,30 +52,49 @@ uint32_t pin = (uint32_t)(1 << channel_pin[irq_index]); // Clear interrupt flag - if (__HAL_GPIO_EXTI_GET_FLAG(pin) != RESET) - { + if (__HAL_GPIO_EXTI_GET_FLAG(pin) != RESET) { __HAL_GPIO_EXTI_CLEAR_FLAG(pin); } - + if (channel_ids[irq_index] == 0) return; - + // Check which edge has generated the irq if ((gpio->IDR & pin) == 0) { irq_handler(channel_ids[irq_index], IRQ_FALL); - } - else { + } else { irq_handler(channel_ids[irq_index], IRQ_RISE); } } // The irq_index is passed to the function -static void gpio_irq0(void) {handle_interrupt_in(0);} // EXTI line 0 -static void gpio_irq1(void) {handle_interrupt_in(1);} // EXTI line 1 -static void gpio_irq2(void) {handle_interrupt_in(2);} // EXTI line 2 -static void gpio_irq3(void) {handle_interrupt_in(3);} // EXTI line 3 -static void gpio_irq4(void) {handle_interrupt_in(4);} // EXTI line 4 -static void gpio_irq5(void) {handle_interrupt_in(5);} // EXTI lines 5 to 9 -static void gpio_irq6(void) {handle_interrupt_in(6);} // EXTI lines 10 to 15 +// EXTI line 0 +static void gpio_irq0(void) { + handle_interrupt_in(0); +} +// EXTI line 1 +static void gpio_irq1(void) { + handle_interrupt_in(1); +} +// EXTI line 2 +static void gpio_irq2(void) { + handle_interrupt_in(2); +} +// EXTI line 3 +static void gpio_irq3(void) { + handle_interrupt_in(3); +} +// EXTI line 4 +static void gpio_irq4(void) { + handle_interrupt_in(4); +} +// EXTI lines 5 to 9 +static void gpio_irq5(void) { + handle_interrupt_in(5); +} +// EXTI lines 10 to 15 +static void gpio_irq6(void) { + handle_interrupt_in(6); +} extern uint32_t Set_GPIO_Clock(uint32_t port_idx); @@ -138,7 +155,7 @@ irq_index = 6; break; default: - error("InterruptIn error: pin not supported."); + error("InterruptIn error: pin not supported.\n"); return -1; } @@ -147,7 +164,7 @@ // Configure GPIO pin_function(pin, STM_PIN_DATA(STM_MODE_IT_FALLING, GPIO_NOPULL, 0)); - + // Enable EXTI interrupt NVIC_SetVector(irq_n, vector); NVIC_EnableIRQ(irq_n); @@ -160,9 +177,9 @@ channel_ids[irq_index] = id; channel_gpio[irq_index] = gpio_add; channel_pin[irq_index] = pin_index; - - irq_handler = handler; - + + irq_handler = handler; + return 0; } @@ -180,37 +197,34 @@ uint32_t pull = GPIO_NOPULL; if (enable) { - + pull = GPIO_NOPULL; - + if (event == IRQ_RISE) { if ((obj->event == EDGE_FALL) || (obj->event == EDGE_BOTH)) { mode = STM_MODE_IT_RISING_FALLING; obj->event = EDGE_BOTH; - } - else { // NONE or RISE + } else { // NONE or RISE mode = STM_MODE_IT_RISING; obj->event = EDGE_RISE; } } - + if (event == IRQ_FALL) { if ((obj->event == EDGE_RISE) || (obj->event == EDGE_BOTH)) { mode = STM_MODE_IT_RISING_FALLING; obj->event = EDGE_BOTH; - } - else { // NONE or FALL + } else { // NONE or FALL mode = STM_MODE_IT_FALLING; obj->event = EDGE_FALL; } } - } - else { + } else { mode = STM_MODE_INPUT; pull = GPIO_NOPULL; obj->event = EDGE_NONE; } - + pin_function(obj->pin, STM_PIN_DATA(mode, pull, 0)); }