From: Nathael Pajani Date: Mon, 3 Mar 2014 21:58:31 +0000 (+0100) Subject: Using concatenation in macro is confusing as it does not work with variables. Use... X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=3ad250de3f334d09bbb827ea85dc688022eafa20;p=soft%2Flpc122x%2Fcore Using concatenation in macro is confusing as it does not work with variables. Use a function instead. Adds some code, but not much. LPC_IO_FUNC_ALT() macro is still here for those who need small code. --- diff --git a/drivers/gpio.c b/drivers/gpio.c index e5ba6c4..308b32f 100644 --- a/drivers/gpio.c +++ b/drivers/gpio.c @@ -199,6 +199,33 @@ void set_gpio_pins(void) } +/* Most pins have GPIO function on function 0, but a few have it on another function ... + * Return the function number for the GPIO function. + */ +uint8_t lpc_io_func_gpio(uint8_t port, uint8_t pin){ + switch (port) { + case 1: + switch (pin) { + case 0: + case 1: + return 1; + } + break; + case 0: + switch (pin) { + case 13: + case 30: + case 31: + return 1; + case 25: + case 26: + return 6; + } + break; + } + return 0; +} + static void (*gpio_calbacks_port0[PORT0_NB_PINS]) (uint32_t); static void (*gpio_calbacks_port1[PORT1_NB_PINS]) (uint32_t); static void (*gpio_calbacks_port2[PORT2_NB_PINS]) (uint32_t); @@ -239,7 +266,7 @@ int set_gpio_callback(void (*callback) (uint32_t), uint8_t port, uint8_t pin, ui /* Configure the pin as interrupt source */ gpio_port->data_dir &= ~(1 << pin); /* Input */ - config_gpio(port, pin, (LPC_IO_FUNC_ALT(0) | LPC_IO_DIGITAL)); + config_gpio(port, pin, (lpc_io_func_gpio(port, pin) | LPC_IO_DIGITAL)); switch (sense) { case EDGES_BOTH: gpio_port->int_sense &= ~(1 << pin); @@ -391,8 +418,8 @@ void status_led_config(void) struct lpc_gpio* gpio1 = LPC_GPIO_1; uint32_t mode = (LPC_IO_MODE_PULL_UP | LPC_IO_DIGITAL | LPC_IO_DRIVE_HIGHCURENT); /* Status Led GPIO */ - config_gpio(1, LED_GREEN, (LPC_IO_FUNC_ALT(0) | mode)); - config_gpio(1, LED_RED, (LPC_IO_FUNC_ALT(0) | mode)); + config_gpio(1, LED_GREEN, (lpc_io_func_gpio(1, LED_GREEN) | mode)); + config_gpio(1, LED_RED, (lpc_io_func_gpio(1, LED_RED) | mode)); /* Configure both as output */ gpio1->data_dir |= (1 << LED_GREEN) | (1 << LED_RED); /* Turn both LEDs on */ diff --git a/include/drivers/gpio.h b/include/drivers/gpio.h index 2de74ae..1017520 100644 --- a/include/drivers/gpio.h +++ b/include/drivers/gpio.h @@ -39,66 +39,11 @@ enum gpio_interrupt_senses { LEVEL_LOW, }; -#define LPC_IO_FUNC_GPIO_0_0 0 -#define LPC_IO_FUNC_GPIO_0_1 0 -#define LPC_IO_FUNC_GPIO_0_2 0 -#define LPC_IO_FUNC_GPIO_0_3 0 -#define LPC_IO_FUNC_GPIO_0_4 0 -#define LPC_IO_FUNC_GPIO_0_5 0 -#define LPC_IO_FUNC_GPIO_0_6 0 -#define LPC_IO_FUNC_GPIO_0_7 0 -#define LPC_IO_FUNC_GPIO_0_8 0 -#define LPC_IO_FUNC_GPIO_0_9 0 -#define LPC_IO_FUNC_GPIO_0_10 0 -#define LPC_IO_FUNC_GPIO_0_11 0 -#define LPC_IO_FUNC_GPIO_0_12 0 -#define LPC_IO_FUNC_GPIO_0_13 1 -#define LPC_IO_FUNC_GPIO_0_14 0 -#define LPC_IO_FUNC_GPIO_0_15 0 -#define LPC_IO_FUNC_GPIO_0_16 0 -#define LPC_IO_FUNC_GPIO_0_17 0 -#define LPC_IO_FUNC_GPIO_0_18 0 -#define LPC_IO_FUNC_GPIO_0_19 0 -#define LPC_IO_FUNC_GPIO_0_20 0 -#define LPC_IO_FUNC_GPIO_0_21 0 -#define LPC_IO_FUNC_GPIO_0_22 0 -#define LPC_IO_FUNC_GPIO_0_23 0 -#define LPC_IO_FUNC_GPIO_0_24 0 -#define LPC_IO_FUNC_GPIO_0_25 6 -#define LPC_IO_FUNC_GPIO_0_26 6 -#define LPC_IO_FUNC_GPIO_0_27 0 -#define LPC_IO_FUNC_GPIO_0_28 0 -#define LPC_IO_FUNC_GPIO_0_29 0 -#define LPC_IO_FUNC_GPIO_0_30 1 -#define LPC_IO_FUNC_GPIO_0_31 1 - -#define LPC_IO_FUNC_GPIO_1_0 1 -#define LPC_IO_FUNC_GPIO_1_1 1 -#define LPC_IO_FUNC_GPIO_1_2 0 -#define LPC_IO_FUNC_GPIO_1_3 0 -#define LPC_IO_FUNC_GPIO_1_4 0 -#define LPC_IO_FUNC_GPIO_1_5 0 -#define LPC_IO_FUNC_GPIO_1_6 0 - -#define LPC_IO_FUNC_GPIO_2_0 0 -#define LPC_IO_FUNC_GPIO_2_1 0 -#define LPC_IO_FUNC_GPIO_2_2 0 -#define LPC_IO_FUNC_GPIO_2_3 0 -#define LPC_IO_FUNC_GPIO_2_4 0 -#define LPC_IO_FUNC_GPIO_2_5 0 -#define LPC_IO_FUNC_GPIO_2_6 0 -#define LPC_IO_FUNC_GPIO_2_7 0 -#define LPC_IO_FUNC_GPIO_2_8 0 -#define LPC_IO_FUNC_GPIO_2_9 0 -#define LPC_IO_FUNC_GPIO_2_10 0 -#define LPC_IO_FUNC_GPIO_2_11 0 -#define LPC_IO_FUNC_GPIO_2_12 0 -#define LPC_IO_FUNC_GPIO_2_13 0 -#define LPC_IO_FUNC_GPIO_2_14 0 -#define LPC_IO_FUNC_GPIO_2_15 0 - -#define LPC_IO_FUNC_GPIO(port, pin) LPC_IO_FUNC_GPIO_ ## port ## _ ## pin +/* Most pins have GPIO function on function 0, but a few have it on another function ... + * Return the function number for the GPIO function. + */ +uint8_t lpc_io_func_gpio(uint8_t port, uint8_t pin); int set_gpio_callback(void (*callback) (uint32_t), uint8_t port, uint8_t pin, uint8_t sense); void remove_gpio_callback(uint8_t port, uint8_t pin);