From c8825a59173bf00e2683ae211bcc369d3b8b37e7 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 3 Jun 2015 18:12:58 +0200 Subject: [PATCH 01/33] tests: removed gpio_exti test --- tests/periph_gpio_exti/Makefile | 8 - tests/periph_gpio_exti/main.c | 330 -------------------------------- 2 files changed, 338 deletions(-) delete mode 100644 tests/periph_gpio_exti/Makefile delete mode 100644 tests/periph_gpio_exti/main.c diff --git a/tests/periph_gpio_exti/Makefile b/tests/periph_gpio_exti/Makefile deleted file mode 100644 index 98565b6a07a3..000000000000 --- a/tests/periph_gpio_exti/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -export APPLICATION = periph_gpio_exti -include ../Makefile.tests_common - -FEATURES_REQUIRED = periph_gpio - -DISABLE_MODULE += auto_init - -include $(RIOTBASE)/Makefile.include diff --git a/tests/periph_gpio_exti/main.c b/tests/periph_gpio_exti/main.c deleted file mode 100644 index 8bdb2b311e42..000000000000 --- a/tests/periph_gpio_exti/main.c +++ /dev/null @@ -1,330 +0,0 @@ -/* - * Copyright (C) 2014 Freie Universität Berlin - * - * This file is subject to the terms and conditions of the GNU Lesser General - * Public License v2.1. See the file LICENSE in the top level directory for more - * details. - */ - -/** - * @ingroup tests - * @{ - * - * @file - * @brief Test external interrupt for GPIO driver - * - * @author Hauke Petersen - * - * @} - */ - -#include -#include - -#include "periph_conf.h" -#include "periph/gpio.h" - -#define ACTIVE_FLANK GPIO_RISING -#define PULL GPIO_NOPULL - -uint32_t state = 0; -uint32_t old_state = 0; - -#if GPIO_0_EN -void g0_cb(void *arg){ - puts("GPIO_0 triggered"); -} -#endif - -#if GPIO_1_EN -void g1_cb(void *arg){ - puts("GPIO_1 triggered"); -} -#endif - -#if GPIO_2_EN -void g2_cb(void *arg){ - puts("GPIO_2 triggered"); -} -#endif - -#if GPIO_3_EN -void g3_cb(void *arg){ - puts("GPIO_3 triggered"); -} -#endif - -#if GPIO_4_EN -void g4_cb(void *arg){ - puts("GPIO_4 triggered"); -} -#endif - -#if GPIO_5_EN -void g5_cb(void *arg){ - puts("GPIO_5 triggered"); -} -#endif - -#if GPIO_6_EN -void g6_cb(void *arg){ - puts("GPIO_6 triggered"); -} -#endif - -#if GPIO_7_EN -void g7_cb(void *arg){ - puts("GPIO_7 triggered"); -} -#endif - -#if GPIO_8_EN -void g8_cb(void *arg){ - puts("GPIO_8 triggered"); -} -#endif - -#if GPIO_9_EN -void g9_cb(void *arg){ - puts("GPIO_9 triggered"); -} -#endif - -#if GPIO_10_EN -void g10_cb(void *arg){ - puts("GPIO_10 triggered"); -} -#endif - -#if GPIO_11_EN -void g11_cb(void *arg){ - puts("GPIO_11 triggered"); -} -#endif - -#if GPIO_12_EN -void g12_cb(void *arg){ - puts("GPIO_12 triggered"); -} -#endif - -#if GPIO_13_EN -void g13_cb(void *arg){ - puts("GPIO_13 triggered"); -} -#endif - -#if GPIO_14_EN -void g14_cb(void *arg){ - puts("GPIO_14 triggered"); -} -#endif - -#if GPIO_15_EN -void g15_cb(void *arg){ - puts("GPIO_15 triggered"); -} -#endif - -#if GPIO_16_EN -void g16_cb(void *arg){ - puts("GPIO_16 triggered"); -} -#endif - -#if GPIO_17_EN -void g17_cb(void *arg){ - puts("GPIO_17 triggered"); -} -#endif - -#if GPIO_18_EN -void g18_cb(void *arg){ - puts("GPIO_18 triggered"); -} -#endif - -#if GPIO_19_EN -void g19_cb(void *arg){ - puts("GPIO_19 triggered"); -} -#endif - -#if GPIO_20_EN -void g20_cb(void *arg){ - puts("GPIO_20 triggered"); -} -#endif - -#if GPIO_21_EN -void g21_cb(void *arg){ - puts("GPIO_21 triggered"); -} -#endif - -#if GPIO_22_EN -void g22_cb(void *arg){ - puts("GPIO_22 triggered"); -} -#endif - -#if GPIO_23_EN -void g23_cb(void *arg){ - puts("GPIO_23 triggered"); -} -#endif - -#if GPIO_24_EN -void g24_cb(void *arg){ - puts("GPIO_24 triggered"); -} -#endif - -#if GPIO_25_EN -void g25_cb(void *arg){ - puts("GPIO_25 triggered"); -} -#endif - -#if GPIO_26_EN -void g26_cb(void *arg){ - puts("GPIO_26 triggered"); -} -#endif - -#if GPIO_27_EN -void g27_cb(void *arg){ - puts("GPIO_27 triggered"); -} -#endif - -#if GPIO_28_EN -void g28_cb(void *arg){ - puts("GPIO_28 triggered"); -} -#endif - -#if GPIO_29_EN -void g29_cb(void *arg){ - puts("GPIO_29 triggered"); -} -#endif - -#if GPIO_30_EN -void g30_cb(void *arg){ - puts("GPIO_30 triggered"); -} -#endif - -#if GPIO_31_EN -void g31_cb(void *arg){ - puts("GPIO_31 triggered"); -} -#endif - -int main(void) -{ - puts("GPIO driver test - external interrupts"); - puts("Initializing all GPIOs as external interrupt sources"); - -#if GPIO_0_EN - gpio_init_int(GPIO_0, PULL, ACTIVE_FLANK, g0_cb, 0); -#endif -#if GPIO_1_EN - gpio_init_int(GPIO_1, PULL, ACTIVE_FLANK, g1_cb, 0); -#endif -#if GPIO_2_EN - gpio_init_int(GPIO_2, PULL, ACTIVE_FLANK, g2_cb, 0); -#endif -#if GPIO_3_EN - gpio_init_int(GPIO_3, PULL, ACTIVE_FLANK, g3_cb, 0); -#endif -#if GPIO_4_EN - gpio_init_int(GPIO_4, PULL, ACTIVE_FLANK, g4_cb, 0); -#endif -#if GPIO_5_EN - gpio_init_int(GPIO_5, PULL, ACTIVE_FLANK, g5_cb, 0); -#endif -#if GPIO_6_EN - gpio_init_int(GPIO_6, PULL, ACTIVE_FLANK, g6_cb, 0); -#endif -#if GPIO_7_EN - gpio_init_int(GPIO_7, PULL, ACTIVE_FLANK, g7_cb, 0); -#endif -#if GPIO_8_EN - gpio_init_int(GPIO_8, PULL, ACTIVE_FLANK, g8_cb, 0); -#endif -#if GPIO_9_EN - gpio_init_int(GPIO_9, PULL, ACTIVE_FLANK, g9_cb, 0); -#endif -#if GPIO_10_EN - gpio_init_int(GPIO_10, PULL, ACTIVE_FLANK, g10_cb, 0); -#endif -#if GPIO_11_EN - gpio_init_int(GPIO_11, PULL, ACTIVE_FLANK, g11_cb, 0); -#endif -#if GPIO_12_EN - gpio_init_int(GPIO_12, PULL, ACTIVE_FLANK, g12_cb, 0); -#endif -#if GPIO_13_EN - gpio_init_int(GPIO_13, PULL, ACTIVE_FLANK, g13_cb, 0); -#endif -#if GPIO_14_EN - gpio_init_int(GPIO_14, PULL, ACTIVE_FLANK, g14_cb, 0); -#endif -#if GPIO_15_EN - gpio_init_int(GPIO_15, PULL, ACTIVE_FLANK, g15_cb, 0); -#endif -#if GPIO_16_EN - gpio_init_int(GPIO_16, PULL, ACTIVE_FLANK, g16_cb, 0); -#endif -#if GPIO_17_EN - gpio_init_int(GPIO_17, PULL, ACTIVE_FLANK, g17_cb, 0); -#endif -#if GPIO_18_EN - gpio_init_int(GPIO_18, PULL, ACTIVE_FLANK, g18_cb, 0); -#endif -#if GPIO_19_EN - gpio_init_int(GPIO_19, PULL, ACTIVE_FLANK, g19_cb, 0); -#endif -#if GPIO_20_EN - gpio_init_int(GPIO_20, PULL, ACTIVE_FLANK, g20_cb, 0); -#endif -#if GPIO_21_EN - gpio_init_int(GPIO_21, PULL, ACTIVE_FLANK, g21_cb, 0); -#endif -#if GPIO_22_EN - gpio_init_int(GPIO_22, PULL, ACTIVE_FLANK, g22_cb, 0); -#endif -#if GPIO_23_EN - gpio_init_int(GPIO_23, PULL, ACTIVE_FLANK, g23_cb, 0); -#endif -#if GPIO_24_EN - gpio_init_int(GPIO_24, PULL, ACTIVE_FLANK, g24_cb, 0); -#endif -#if GPIO_25_EN - gpio_init_int(GPIO_25, PULL, ACTIVE_FLANK, g25_cb, 0); -#endif -#if GPIO_26_EN - gpio_init_int(GPIO_26, PULL, ACTIVE_FLANK, g26_cb, 0); -#endif -#if GPIO_27_EN - gpio_init_int(GPIO_27, PULL, ACTIVE_FLANK, g27_cb, 0); -#endif -#if GPIO_28_EN - gpio_init_int(GPIO_28, PULL, ACTIVE_FLANK, g28_cb, 0); -#endif -#if GPIO_29_EN - gpio_init_int(GPIO_29, PULL, ACTIVE_FLANK, g29_cb, 0); -#endif -#if GPIO_30_EN - gpio_init_int(GPIO_30, PULL, ACTIVE_FLANK, g30_cb, 0); -#endif -#if GPIO_31_EN - gpio_init_int(GPIO_31, PULL, ACTIVE_FLANK, g31_cb, 0); -#endif - - puts("Initialization done, going to sleep now"); - - return 0; -} From 8ccd289f8254ddc1655bed0470c4f1ea1c0bcf93 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 3 Jun 2015 18:13:41 +0200 Subject: [PATCH 02/33] tests: remoldeled the periph_gpio test --- tests/periph_gpio/Makefile | 3 +- tests/periph_gpio/main.c | 259 ++++++++++++++++++++++++++++++------- 2 files changed, 213 insertions(+), 49 deletions(-) diff --git a/tests/periph_gpio/Makefile b/tests/periph_gpio/Makefile index 983113639937..d987ff764639 100644 --- a/tests/periph_gpio/Makefile +++ b/tests/periph_gpio/Makefile @@ -3,6 +3,7 @@ include ../Makefile.tests_common FEATURES_REQUIRED = periph_gpio -DISABLE_MODULE += auto_init +USEMODULE += uart0 +USEMODULE += shell include $(RIOTBASE)/Makefile.include diff --git a/tests/periph_gpio/main.c b/tests/periph_gpio/main.c index f9955f2c3a4b..b34f65d98fae 100644 --- a/tests/periph_gpio/main.c +++ b/tests/periph_gpio/main.c @@ -7,11 +7,11 @@ */ /** - * @ingroup tests + * @ingroup tests * @{ * * @file - * @brief Test input and output functionality of low-level GPIO driver + * @brief Manual test application for GPIO peripheral drivers * * @author Hauke Petersen * @@ -19,74 +19,237 @@ */ #include +#include -#include "cpu.h" -#include "periph_conf.h" +#include "shell.h" +#include "posix_io.h" +#include "board_uart0.h" #include "periph/gpio.h" #include "hwtimer.h" -uint32_t state = 0; -uint32_t old_state = 0; +#define SHELL_BUFSIZE (64U) -int main(void) +static void cb(void *arg) { - puts("GPIO driver test"); - + printf("INT: external interrupt from pin %i\n", (int)arg); +} - puts("Setting GPIOs to output w/o pull resistor"); - for (int i = 0; i < GPIO_NUMOF; i++) { - gpio_init_out(i, GPIO_NOPULL); +static int parse_pull(char *val) +{ + switch (atoi(val)) { + case 0: + return GPIO_NOPULL; + case 1: + return GPIO_PULLUP; + case 2: + return GPIO_PULLDOWN; + default: + puts("Error: invalid pull configuration"); + return -1; } +} - puts("Turning pins 1s on"); - for (int i = 0; i < GPIO_NUMOF; i++) { - gpio_set(i); +static int init_out(int argc, char **argv) +{ + int port, pin, pull; + + if (argc < 3) { + printf("usage: %s [pull_config]\n", argv[0]); + puts(" pull_config: 0: no pull resistor (default)\n" + " 1: pull up\n" + " 2: pull down"); + return 1; + } + port = atoi(argv[1]); + pin = atoi(argv[2]); + if (argc >= 4) { + pull = parse_pull(argv[3]); + if (pull < 0) { + return 1; + } + } + else { + pull = GPIO_NOPULL; } - hwtimer_wait(1000000); + if (gpio_init(GPIO(port, pin), GPIO_DIR_OUT, pull) < 0) { + printf("Error while initializing PORT_%i.%i as output\n", port, pin); + return 1; + } + printf("PORT_%i.%i initialized successful as output\n", port, pin); + return 0; +} - puts("Turning pins 1s off"); - for (int i = 0; i < GPIO_NUMOF; i++) { - gpio_clear(i); +static int init_in(int argc, char **argv) +{ + int port, pin, pull; + + if (argc < 3) { + printf("usage: %s [pull_config]\n", argv[0]); + puts(" pull_config: 0: no pull resistor (default)\n" + " 1: pull up\n" + " 2: pull down"); + return 1; + } + port = atoi(argv[1]); + pin = atoi(argv[2]); + if (argc >= 4) { + pull = parse_pull(argv[3]); + if (pull < 0) { + return 1; + } + } + else { + pull = GPIO_NOPULL; } - hwtimer_wait(1000000); + if (gpio_init(GPIO(port, pin), GPIO_DIR_IN, pull) < 0) { + printf("Error while initializing PORT_%i.%02i as input\n", port, pin); + return 1; + } + printf("PORT_%i.%02i initialized successful as input\n", port, pin); - puts("Now toggling pins 6 times with 500ms interval"); - for (int c = 0; c < 6; c++) { - for (int i = 0; i < GPIO_NUMOF; i++) { - gpio_toggle(i); + return 0; +} + +static int init_int(int argc, char **argv) +{ + int port, pin, flank, pull; + + if (argc < 4) { + printf("usage: %s [pull_config]\n", argv[0]); + puts(" flank: 0: falling\n" + " 1: rising\n" + " 2: both\n" + " pull_config: 0: no pull resistor (default)\n" + " 1: pull up\n" + " 2: pull down"); + return 1; + } + port = atoi(argv[1]); + pin = atoi(argv[2]); + flank = atoi(argv[3]); + switch (flank) { + case 0: + flank = GPIO_FALLING; + break; + case 1: + flank = GPIO_RISING; + break; + case 2: + flank = GPIO_BOTH; + break; + default: + printf("wrong flank setting.\n"); + return 0; + } + if (argc >= 5) { + pull = parse_pull(argv[4]); + if (pull < 0) { + return 1; } - hwtimer_wait(500000); } + else { + pull = GPIO_NOPULL; + } + if (gpio_init_int(GPIO(port, pin), pull, flank, cb, (void *)pin) < 0) { + printf("Error while initializing PORT_%i.%02i as external interrupt\n", + port, pin); + return 1; + } + printf("PORT_%i.%02i initialized successful as external interrupt\n", + port, pin); + return 0; +} - puts("\n--------------------------------------------\n"); - puts("Setting GPIOs to input w/o pull resister now"); - for (int i = 0; i < GPIO_NUMOF; i++) { - gpio_init_in(i, GPIO_NOPULL); +static int read(int argc, char **argv) +{ + int port, pin; + + if (argc < 3) { + printf("usage: %s \n", argv[0]); + return 1; + } + port = atoi(argv[1]); + pin = atoi(argv[2]); + if (gpio_read(GPIO(port, pin))) { + printf("PORT_%i.%02i is HIGH\n", port, pin); } + else { + printf("PORT_%i.%02i is LOW\n", port, pin); + } + return 0; +} - puts("Will now poll all pins and print status on change"); +static int set(int argc, char **argv) +{ + int port, pin; - while (1) { - state = 0; - for (int i = 0; i < GPIO_NUMOF; i++) { - if (gpio_read(i)) { - state |= (1 << i); - } - } - if (state != old_state) { - for (int i = 0; i < GPIO_NUMOF; i++) { - if (state & (1 << i)) { - printf("GPIO_%i:H ", i); - } else { - printf("GPIO_%i:L ", i); - } - } - printf("\n"); - old_state = state; - } + if (argc < 3) { + printf("usage: %s \n", argv[0]); + return 1; } + port = atoi(argv[1]); + pin = atoi(argv[2]); + + gpio_set(GPIO(port, pin)); + return 0; +} + +static int clear(int argc, char **argv) +{ + int port, pin; + + if (argc < 3) { + printf("usage: %s \n", argv[0]); + return 1; + } + port = atoi(argv[1]); + pin = atoi(argv[2]); + gpio_clear(GPIO(port, pin)); + return 0; +} + +static int toggle(int argc, char **argv) +{ + int port, pin; + + if (argc < 3) { + printf("usage: %s \n", argv[0]); + return 1; + } + port = atoi(argv[1]); + pin = atoi(argv[2]); + gpio_toggle(GPIO(port, pin)); + return 0; +} + +static const shell_command_t shell_commands[] = { + { "init_in", "initialize pin as output", init_in }, + { "init_out", "initialize pin as input", init_out }, + { "init_int", "initialize pin as EXTI", init_int }, + { "read", "read pin status", read }, + { "set", "set pin to HIGH", set }, + { "clear", "set pin to LOW", clear }, + { "toggle", "toggle pin", toggle }, + { NULL, NULL, NULL } +}; + +int main(void) +{ + shell_t shell; + + puts("GPIO peripheral driver test\n"); + puts("In this test, pins are specified by integer port and pin numbers.\n" + "So if your platform has a pin PA01, it will be port=0 and pin=1,\n" + "PC14 would be port=2 and pin=14 etc.\n\n" + "NOTE: make sure the values you use exist on your platform! The\n" + " behavior for not existing ports/pins is not defined!"); + + /* start the shell */ + (void) posix_open(uart0_handler_pid, 0); + shell_init(&shell, shell_commands, SHELL_BUFSIZE, uart0_readc, uart0_putc); + shell_run(&shell); return 0; } From 2deedcff6a1837994db2f4d1f8a5ed7c88d7905a Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Thu, 4 Jun 2015 12:14:51 +0200 Subject: [PATCH 03/33] tests/periph_spi: adapted to change GPIO driver IF --- tests/periph_spi/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/periph_spi/main.c b/tests/periph_spi/main.c index cef61c8779ea..cfb426a32f14 100644 --- a/tests/periph_spi/main.c +++ b/tests/periph_spi/main.c @@ -185,9 +185,9 @@ int cmd_init_master(int argc, char **argv) printf("spi_init_master: error initializing SPI_%i device (code %i)\n", spi_dev, res); return 1; } - res = gpio_init_out(spi_cs, GPIO_PULLUP); + res = gpio_init(spi_cs, GPIO_DIR_OUT, GPIO_PULLUP); if (res < 0){ - printf("gpio_init_out: error initializing GPIO_%i as CS line (code %i)\n", spi_cs, res); + printf("gpio_init: error initializing GPIO_%i as CS line (code %i)\n", spi_cs, res); return 1; } gpio_set(spi_cs); @@ -211,9 +211,9 @@ int cmd_init_slave(int argc, char **argv) printf("spi_init_slave: error initializing SPI_%i device (code: %i)\n", spi_dev, res); return 1; } - res = gpio_init_int(spi_cs, GPIO_NOPULL, GPIO_FALLING, slave_on_cs, 0); + res = gpio_init_exti(spi_cs, GPIO_NOPULL, GPIO_FALLING, slave_on_cs, 0); if (res < 0){ - printf("gpio_init_int: error initializing GPIO_%i as CS line (code %i)\n", spi_cs, res); + printf("gpio_init_exti: error initializing GPIO_%i as CS line (code %i)\n", spi_cs, res); return 1; } spi_master = 0; From b49f11bed782e1b9c6ff81f2a7412b5e863eda52 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 3 Jun 2015 18:14:16 +0200 Subject: [PATCH 04/33] drivers/gpio: overhaul of the periph GPIO driver - merged init_in and init_out - renamed init_int to init_exti - made datatypes overwritable --- drivers/include/periph/dev_enums.h | 140 +++++++++++++++++++ drivers/include/periph/gpio.h | 215 +++++++++-------------------- 2 files changed, 203 insertions(+), 152 deletions(-) create mode 100644 drivers/include/periph/dev_enums.h diff --git a/drivers/include/periph/dev_enums.h b/drivers/include/periph/dev_enums.h new file mode 100644 index 000000000000..95920e869cdb --- /dev/null +++ b/drivers/include/periph/dev_enums.h @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup driver_periph + * + * @{ + * @file + * @brief Device enumerations for backward compatibility with existing + * peripheral driver implementations + * + * TODO: Remove this file once all peripheral drivers are ported to the more + * efficient implementations style + * + * @author Hauke Petersen + */ + +#ifndef PERIPH_COMPAT_H_ +#define PERIPH_COMPAT_H_ + +#include "periph_conf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Legacy definition of GPIO pins. + */ +enum { +#if GPIO_0_EN + GPIO_0, /**< GPIO device 0 */ +#endif +#if GPIO_1_EN + GPIO_1, /**< GPIO device 1 */ +#endif +#if GPIO_2_EN + GPIO_2, /**< GPIO device 2 */ +#endif +#if GPIO_3_EN + GPIO_3, /**< GPIO device 3 */ +#endif +#if GPIO_4_EN + GPIO_4, /**< GPIO device 4 */ +#endif +#if GPIO_5_EN + GPIO_5, /**< GPIO device 5 */ +#endif +#if GPIO_6_EN + GPIO_6, /**< GPIO device 6 */ +#endif +#if GPIO_7_EN + GPIO_7, /**< GPIO device 7 */ +#endif +#if GPIO_8_EN + GPIO_8, /**< GPIO device 8 */ +#endif +#if GPIO_9_EN + GPIO_9, /**< GPIO device 9 */ +#endif +#if GPIO_10_EN + GPIO_10, /**< GPIO device 10 */ +#endif +#if GPIO_11_EN + GPIO_11, /**< GPIO device 11 */ +#endif +#if GPIO_12_EN + GPIO_12, /**< GPIO device 12 */ +#endif +#if GPIO_13_EN + GPIO_13, /**< GPIO device 13 */ +#endif +#if GPIO_14_EN + GPIO_14, /**< GPIO device 14 */ +#endif +#if GPIO_15_EN + GPIO_15, /**< GPIO device 15 */ +#endif +#if GPIO_16_EN + GPIO_16, /**< GPIO device 16 */ +#endif +#if GPIO_17_EN + GPIO_17, /**< GPIO device 17 */ +#endif +#if GPIO_18_EN + GPIO_18, /**< GPIO device 18 */ +#endif +#if GPIO_19_EN + GPIO_19, /**< GPIO device 19 */ +#endif +#if GPIO_20_EN + GPIO_20, /**< GPIO device 20 */ +#endif +#if GPIO_21_EN + GPIO_21, /**< GPIO device 21 */ +#endif +#if GPIO_22_EN + GPIO_22, /**< GPIO device 22 */ +#endif +#if GPIO_23_EN + GPIO_23, /**< GPIO device 23 */ +#endif +#if GPIO_24_EN + GPIO_24, /**< GPIO device 24 */ +#endif +#if GPIO_25_EN + GPIO_25, /**< GPIO device 25 */ +#endif +#if GPIO_26_EN + GPIO_26, /**< GPIO device 26 */ +#endif +#if GPIO_27_EN + GPIO_27, /**< GPIO device 27 */ +#endif +#if GPIO_28_EN + GPIO_28, /**< GPIO device 28 */ +#endif +#if GPIO_29_EN + GPIO_29, /**< GPIO device 29 */ +#endif +#if GPIO_30_EN + GPIO_30, /**< GPIO device 30 */ +#endif +#if GPIO_31_EN + GPIO_31, /**< GPIO device 31 */ +#endif + GPIO_NUMOF +}; + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_COMPAT_H_ */ +/** @} */ diff --git a/drivers/include/periph/gpio.h b/drivers/include/periph/gpio.h index 6d02fe3b55ed..9d7ac0a65904 100644 --- a/drivers/include/periph/gpio.h +++ b/drivers/include/periph/gpio.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Freie Universität Berlin + * Copyright (C) 2015 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -21,239 +21,150 @@ #ifndef GPIO_H #define GPIO_H -#include "periph_conf.h" +#include "periph_cpu.h" #ifdef __cplusplus extern "C" { #endif -/* guard file in case no GPIO devices are defined */ -#if GPIO_NUMOF - /** - * @brief Definition of available GPIO devices. Each device is managing exactly one pin. + * @brief Defined the */ -typedef enum { -#if GPIO_0_EN - GPIO_0 = 0, /**< GPIO device 0 */ -#endif -#if GPIO_1_EN - GPIO_1, /**< GPIO device 1 */ -#endif -#if GPIO_2_EN - GPIO_2, /**< GPIO device 2 */ -#endif -#if GPIO_3_EN - GPIO_3, /**< GPIO device 3 */ -#endif -#if GPIO_4_EN - GPIO_4, /**< GPIO device 4 */ -#endif -#if GPIO_5_EN - GPIO_5, /**< GPIO device 5 */ -#endif -#if GPIO_6_EN - GPIO_6, /**< GPIO device 6 */ -#endif -#if GPIO_7_EN - GPIO_7, /**< GPIO device 7 */ -#endif -#if GPIO_8_EN - GPIO_8, /**< GPIO device 8 */ -#endif -#if GPIO_9_EN - GPIO_9, /**< GPIO device 9 */ -#endif -#if GPIO_10_EN - GPIO_10, /**< GPIO device 10 */ -#endif -#if GPIO_11_EN - GPIO_11, /**< GPIO device 11 */ -#endif -#if GPIO_12_EN - GPIO_12, /**< GPIO device 12 */ -#endif -#if GPIO_13_EN - GPIO_13, /**< GPIO device 13 */ -#endif -#if GPIO_14_EN - GPIO_14, /**< GPIO device 14 */ -#endif -#if GPIO_15_EN - GPIO_15, /**< GPIO device 15 */ -#endif -#if GPIO_16_EN - GPIO_16, /**< GPIO device 16 */ -#endif -#if GPIO_17_EN - GPIO_17, /**< GPIO device 17 */ -#endif -#if GPIO_18_EN - GPIO_18, /**< GPIO device 18 */ -#endif -#if GPIO_19_EN - GPIO_19, /**< GPIO device 19 */ -#endif -#if GPIO_20_EN - GPIO_20, /**< GPIO device 20 */ -#endif -#if GPIO_21_EN - GPIO_21, /**< GPIO device 21 */ -#endif -#if GPIO_22_EN - GPIO_22, /**< GPIO device 22 */ +#ifndef GPIO +#define GPIO(x,y) ((x & 0) | y) #endif -#if GPIO_23_EN - GPIO_23, /**< GPIO device 23 */ -#endif -#if GPIO_24_EN - GPIO_24, /**< GPIO device 24 */ -#endif -#if GPIO_25_EN - GPIO_25, /**< GPIO device 25 */ -#endif -#if GPIO_26_EN - GPIO_26, /**< GPIO device 26 */ -#endif -#if GPIO_27_EN - GPIO_27, /**< GPIO device 27 */ -#endif -#if GPIO_28_EN - GPIO_28, /**< GPIO device 28 */ -#endif -#if GPIO_29_EN - GPIO_29, /**< GPIO device 29 */ -#endif -#if GPIO_30_EN - GPIO_30, /**< GPIO device 30 */ + +/** + * @brief Define the default GPIO type identifier + */ +#ifndef HAVE_GPIO_T +typedef int gpio_t; #endif -#if GPIO_31_EN - GPIO_31, /**< GPIO device 31 */ + +/** + * @brief Definition of available pin directions + */ +#ifndef HAVE_GPIO_DIR_T +typedef enum { + GPIO_DIR_IN = 0, /**< configure pin as input */ + GPIO_DIR_OUT = 1, /**< configure pin as output */ +} gpio_dir_t; #endif -} gpio_t; /** - * @brief Definition of pull-up/pull-down modes + * @brief Definition of pull-up/pull-down modes */ +#ifndef HAVE_GPIO_PP_T typedef enum { GPIO_NOPULL = 0, /**< do not use internal pull resistors */ GPIO_PULLUP = 1, /**< enable internal pull-up resistor */ GPIO_PULLDOWN = 2 /**< enable internal pull-down resistor */ } gpio_pp_t; +#endif /** - * @brief Definition of possible active flanks for external interrupt mode + * @brief Definition of possible active flanks for external interrupt mode */ +#ifndef HAVE_GPIO_FLANK_T typedef enum { GPIO_FALLING = 0, /**< emit interrupt on falling flank */ GPIO_RISING = 1, /**< emit interrupt on rising flank */ GPIO_BOTH = 2 /**< emit interrupt on both flanks */ } gpio_flank_t; +#endif /** - * @brief Signature for function called from interrupt context after an external event + * @brief Signature of event callback functions triggered from interrupts * * @param[in] arg optional context for the callback */ typedef void (*gpio_cb_t)(void *arg); /** - * @brief Initialize GPIO pin as output pin + * @brief Initialize the given pin as general purpose input or output * - * @param[in] dev the GPIO pin to set as output - * @param[in] pullup define if pull resistors should be used + * @param[in] pin pin to initialize + * @param[in] dir direction for the pin, input or output + * @param[in] pullup define what pull resistors should be used * * @return 0 on success - * @return -1 on pull-up mode unavailable + * @return -1 on error */ -int gpio_init_out(gpio_t dev, gpio_pp_t pullup); +int gpio_init(gpio_t pin, gpio_dir_t dir, gpio_pp_t pullup); /** - * @brief Initialize a GPIO pin in input mode + * @brief Initialize a GPIO pin for external interrupt usage * - * @param[in] dev the GPIO pin to use as input - * @param[in] pullup define if pull resistors should be used - * - * @return 0 on success - * @return -1 on pull-up mode unavailable - */ -int gpio_init_in(gpio_t dev, gpio_pp_t pullup); - -/** - * @brief Initialize a GPIO pin for external interrupt usage - * - * The registered callback function will be called in interrupt context every time the defined flank(s) - * are detected. + * The registered callback function will be called in interrupt context every + * time the defined flank(s) are detected. * * The interrupt is activated automatically after the initialization. * - * @param[in] dev the GPIO pin to initialize - * @param[in] pullup define if pull resistors should be enabled + * @param[in] pin pin to initialize + * @param[in] pullup define what pull resistors should be enabled * @param[in] flank define the active flank(s) - * @param[in] cb register the callback that is called in interrupt context + * @param[in] cb callback that is called from interrupt context * @param[in] arg optional argument passed to the callback * * @return 0 on success - * @return -1 on pull-up mode unavailable - * @return -2 on active flank unavailable + * @return -1 on error */ -int gpio_init_int(gpio_t dev, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb, void *arg); +int gpio_init_exti(gpio_t pin, gpio_pp_t pullup, gpio_flank_t flank, + gpio_cb_t cb, void *arg); /** - * @brief Enable the GPIO pin's interrupt if configured as external interrupt source. + * @brief Enable pin's interrupt if configured as interrupt source * - * @param[in] dev the GPIO pin to enable the interrupt for + * @param[in] pin the pin to enable the interrupt for */ -void gpio_irq_enable(gpio_t dev); +void gpio_irq_enable(gpio_t pin); /** - * @brief Disable the GPIO pin's interrupt if configured as external interrupt source. + * @brief Disable the pin's interrupt if configured as interrupt source * - * @param[in] dev the GPIO pin to disable the interrupt for + * @param[in] pin the pin to disable the interrupt for */ -void gpio_irq_disable(gpio_t dev); +void gpio_irq_disable(gpio_t pin); /** - * @brief Get the current value of the given GPIO pin + * @brief Get the current value of the given pin * - * @param[in] dev the GPIO pin to read + * @param[in] pin the pin to read * @return the current value, 0 for LOW, != 0 for HIGH * * @return 0 when pin is LOW * @return greater 0 for HIGH */ -int gpio_read(gpio_t dev); +int gpio_read(gpio_t pin); /** - * @brief Set the given GPIO pin to HIGH + * @brief Set the given pin to HIGH * - * @param[in] dev the GPIO pin to set + * @param[in] pin the pin to set */ -void gpio_set(gpio_t dev); +void gpio_set(gpio_t pin); /** - * @brief Set the given GPIO pin to LOW + * @brief Set the given pin to LOW * - * @param[in] dev the GPIO pin to clear + * @param[in] pin the pin to clear */ -void gpio_clear(gpio_t dev); +void gpio_clear(gpio_t pin); /** - * @brief Toggle the value of the given GPIO pin + * @brief Toggle the value of the given pin * - * @param[in] dev the GPIO pin to toggle + * @param[in] pin the pin to toggle */ -void gpio_toggle(gpio_t dev); +void gpio_toggle(gpio_t pin); /** - * @brief Set the given GPIO pin to the given value + * @brief Set the given pin to the given value * - * @param[in] dev the GPIO pin to set + * @param[in] pin the pin to set * @param[in] value value to set the pin to, 0 for LOW, HIGH otherwise */ -void gpio_write(gpio_t dev, int value); - -#endif /* GPIO_NUMOF */ +void gpio_write(gpio_t pin, int value); #ifdef __cplusplus } From 315ac1bedb8f3bbe04149d4f8e8f21bf6fa8f2cf Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Fri, 12 Jun 2015 19:10:16 +0200 Subject: [PATCH 05/33] tests: adjusted test to changed GPIO interface --- tests/driver_at86rf2xx/Makefile | 10 +++++----- tests/driver_dht/Makefile | 4 ++-- tests/driver_isl29125/Makefile | 2 +- tests/driver_kw2xrf/Makefile | 8 ++++---- tests/driver_l3g4200d/Makefile | 4 ++-- tests/driver_lis3dh/Makefile | 6 +++--- tests/driver_lsm303dlhc/Makefile | 4 ++-- tests/driver_nrf24l01p_lowlevel/Makefile | 6 +++--- tests/driver_nvram_spi/Makefile | 2 +- tests/driver_pcd8544/Makefile | 6 +++--- tests/driver_pir/Makefile | 6 +++--- 11 files changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/driver_at86rf2xx/Makefile b/tests/driver_at86rf2xx/Makefile index 004b877c5a00..71d58cbbdfa1 100644 --- a/tests/driver_at86rf2xx/Makefile +++ b/tests/driver_at86rf2xx/Makefile @@ -33,27 +33,27 @@ ifneq (true,$(USE_BOARD_PARAMETERS)) ifneq (,$(ATRF_SPI)) CFLAGS += -DATRF_SPI=$(ATRF_SPI) else - CFLAGS += -DATRF_SPI=SPI_0 # set default + CFLAGS += -DATRF_SPI=SPI_0 # set default endif ifneq (,$(ATRF_CS)) CFLAGS += -DATRF_CS=$(ATRF_CS) else - CFLAGS += -DATRF_CS=GPIO_0 # set default + CFLAGS += -DATRF_CS=GPIO\(0,0\) # set default endif ifneq (,$(ATRF_INT)) CFLAGS += -DATRF_INT=$(ATRF_INT) else - CFLAGS += -DATRF_INT=GPIO_1 # set default + CFLAGS += -DATRF_INT=GPIO\(0,1\) # set default endif ifneq (,$(ATRF_SLEEP)) CFLAGS += -DATRF_SLEEP=$(ATRF_SLEEP) else - CFLAGS += -DATRF_SLEEP=GPIO_2 # set default + CFLAGS += -DATRF_SLEEP=GPIO\(0,2\) # set default endif ifneq (,$(ATRF_RESET)) CFLAGS += -DATRF_RESET=$(ATRF_RESET) else - CFLAGS += -DATRF_RESET=GPIO_3 # set default + CFLAGS += -DATRF_RESET=GPIO\(0,3\) # set default endif ifneq (,$(ATRF_SPI_SPEED)) CFLAGS += -DATRF_SPI_SPEED=$(ATRF_SPI_SPEED) diff --git a/tests/driver_dht/Makefile b/tests/driver_dht/Makefile index aba9f8731b17..4e8bc9cd6546 100644 --- a/tests/driver_dht/Makefile +++ b/tests/driver_dht/Makefile @@ -5,7 +5,7 @@ FEATURES_REQUIRED = periph_gpio # define default pin mappings for some boards: ifneq (,$(filter stm32f4discovery,$(BOARD))) - export DHT_GPIO ?= GPIO_4 + export DHT_GPIO ?= GPIO\(4,3\) endif USEMODULE += dht @@ -21,7 +21,7 @@ ifneq (,$(DHT_GPIO)) CFLAGS += -DDHT_GPIO=$(DHT_GPIO) else # set random default - CFLAGS += -DDHT_GPIO=GPIO_0 + CFLAGS += -DDHT_GPIO=GPIO\(0,0\) endif include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_isl29125/Makefile b/tests/driver_isl29125/Makefile index 0450ce888f94..f9330a02d929 100644 --- a/tests/driver_isl29125/Makefile +++ b/tests/driver_isl29125/Makefile @@ -16,7 +16,7 @@ ifneq (,$(TEST_ISL29125_IRQ_PIN)) CFLAGS += -DTEST_ISL29125_IRQ_PIN=$(TEST_ISL29125_IRQ_PIN) else # set random default - CFLAGS += -DTEST_ISL29125_IRQ_PIN=GPIO_5 + CFLAGS += -DTEST_ISL29125_IRQ_PIN=GPIO\(0,0\) endif include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_kw2xrf/Makefile b/tests/driver_kw2xrf/Makefile index 055c70367059..c9e149e5a269 100644 --- a/tests/driver_kw2xrf/Makefile +++ b/tests/driver_kw2xrf/Makefile @@ -27,22 +27,22 @@ ifneq (true,$(USE_BOARD_PARAMETERS)) ifneq (,$(KWRF_SHARED_SPI)) CFLAGS += -DKW2XRF_SHARED_SPI=$(DKW2XRF_SHARED_SPI) else - CFLAGS += -DKW2XRFD_SHARED_SPI=1 # activate spi-lock + CFLAGS += -DKW2XRFD_SHARED_SPI=1 # activate spi-lock endif ifneq (,$(KWRF_SPI)) CFLAGS += -DKWRF_SPI=$(KWRF_SPI) else - CFLAGS += -DKWRF_SPI=SPI_0 # set default + CFLAGS += -DKWRF_SPI=SPI_0 # set default endif ifneq (,$(KWRF_CS)) CFLAGS += -DKWRF_CS=$(KWRF_CS) else - CFLAGS += -DKWRF_CS=GPIO_0 # set default + CFLAGS += -DKWRF_CS=GPIO\(0,0\) # set default endif ifneq (,$(KWRF_INT)) CFLAGS += -DKWRF_INT=$(KWRF_INT) else - CFLAGS += -DKWRF_INT=GPIO_1 # set default + CFLAGS += -DKWRF_INT=GPIO\(0,1\) # set default endif ifneq (,$(KWRF_SPI_SPEED)) CFLAGS += -DKWRF_SPI_SPEED=$(KWRF_SPI_SPEED) diff --git a/tests/driver_l3g4200d/Makefile b/tests/driver_l3g4200d/Makefile index e40c1066d67b..47ed268550d6 100644 --- a/tests/driver_l3g4200d/Makefile +++ b/tests/driver_l3g4200d/Makefile @@ -22,13 +22,13 @@ ifneq (,$(TEST_L3G4200D_INT)) CFLAGS += -DTEST_L3G4200D_INT=$(TEST_L3G4200D_INT) else # set random default - CFLAGS += -DTEST_L3G4200D_INT=GPIO_0 + CFLAGS += -DTEST_L3G4200D_INT=GPIO\(0,0\) endif ifneq (,$(TEST_L3G4200D_DRDY)) CFLAGS += -DTEST_L3G4200D_DRDY=$(TEST_L3G4200D_DRDY) else # set random default - CFLAGS += -DTEST_L3G4200D_DRDY=GPIO_1 + CFLAGS += -DTEST_L3G4200D_DRDY=GPIO\(0,1\) endif include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_lis3dh/Makefile b/tests/driver_lis3dh/Makefile index 21bf6fafdfcf..a8dfcc26842c 100644 --- a/tests/driver_lis3dh/Makefile +++ b/tests/driver_lis3dh/Makefile @@ -16,19 +16,19 @@ ifneq (,$(TEST_LIS3DH_CS)) CFLAGS += -DTEST_LIS3DH_CS=$(TEST_LIS3DH_CS) else # set arbitrary default - CFLAGS += -DTEST_LIS3DH_CS=GPIO_0 + CFLAGS += -DTEST_LIS3DH_CS=GPIO\(0,0\) endif ifneq (,$(TEST_LIS3DH_INT1)) CFLAGS += -DTEST_LIS3DH_INT1=$(TEST_LIS3DH_INT1) else # set arbitrary default - CFLAGS += -DTEST_LIS3DH_INT1=GPIO_1 + CFLAGS += -DTEST_LIS3DH_INT1=GPIO\(0,1\) endif ifneq (,$(TEST_LIS3DH_INT2)) CFLAGS += -DTEST_LIS3DH_INT2=$(TEST_LIS3DH_INT2) else # set arbitrary default - CFLAGS += -DTEST_LIS3DH_INT2=GPIO_2 + CFLAGS += -DTEST_LIS3DH_INT2=GPIO\(0,2\) endif include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_lsm303dlhc/Makefile b/tests/driver_lsm303dlhc/Makefile index 9c409545678f..6f954b2b4e0a 100644 --- a/tests/driver_lsm303dlhc/Makefile +++ b/tests/driver_lsm303dlhc/Makefile @@ -35,13 +35,13 @@ ifneq (,$(TEST_LSM303DLHC_ACC_PIN)) CFLAGS += -DTEST_LSM303DLHC_ACC_PIN=$(TEST_LSM303DLHC_ACC_PIN) else # set random default - CFLAGS += -DTEST_LSM303DLHC_ACC_PIN=GPIO_0 + CFLAGS += -DTEST_LSM303DLHC_ACC_PIN=GPIO\(0,0\) endif ifneq (,$(TEST_LSM303DLHC_MAG_PIN)) CFLAGS += -DTEST_LSM303DLHC_MAG_PIN=$(TEST_LSM303DLHC_MAG_PIN) else # set random default - CFLAGS += -DTEST_LSM303DLHC_MAG_PIN=GPIO_1 + CFLAGS += -DTEST_LSM303DLHC_MAG_PIN=GPIO\(0,1\) endif include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_nrf24l01p_lowlevel/Makefile b/tests/driver_nrf24l01p_lowlevel/Makefile index 18f8721019bf..d031f04cc222 100644 --- a/tests/driver_nrf24l01p_lowlevel/Makefile +++ b/tests/driver_nrf24l01p_lowlevel/Makefile @@ -10,9 +10,9 @@ USEMODULE += nrf24l01p FEATURES_REQUIRED = periph_spi SPI_PORT ?= SPI_0 -CE_PIN ?= GPIO_0 -CS_PIN ?= GPIO_1 -IRQ_PIN ?= GPIO_2 +CE_PIN ?= GPIO\(0,0\) +CS_PIN ?= GPIO\(0,1\) +IRQ_PIN ?= GPIO\(0,2\) include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_nvram_spi/Makefile b/tests/driver_nvram_spi/Makefile index d764782ba9fe..3231b208042a 100644 --- a/tests/driver_nvram_spi/Makefile +++ b/tests/driver_nvram_spi/Makefile @@ -16,7 +16,7 @@ ifneq (,$(TEST_NVRAM_SPI_CS)) CFLAGS += -DTEST_NVRAM_SPI_CS=$(TEST_NVRAM_SPI_CS) else # set arbitrary default - CFLAGS += -DTEST_NVRAM_SPI_CS=GPIO_0 + CFLAGS += -DTEST_NVRAM_SPI_CS=GPIO\(0,0\) endif ifneq (,$(TEST_NVRAM_SPI_SIZE)) CFLAGS += -DTEST_NVRAM_SPI_SIZE=$(TEST_NVRAM_SPI_SIZE) diff --git a/tests/driver_pcd8544/Makefile b/tests/driver_pcd8544/Makefile index 44c0c263f53c..9bd3beef35d2 100644 --- a/tests/driver_pcd8544/Makefile +++ b/tests/driver_pcd8544/Makefile @@ -11,13 +11,13 @@ ifeq (,$(TEST_PCD8544_SPI)) CFLAGS += -DTEST_PCD8544_SPI=SPI_0 endif ifeq (,$(TEST_PCD8544_CS)) - CFLAGS += -DTEST_PCD8544_CS=GPIO_0 + CFLAGS += -DTEST_PCD8544_CS=GPIO\(0,0\) endif ifeq (,$(TEST_PCD8544_RESET)) - CFLAGS += -DTEST_PCD8544_RESET=GPIO_1 + CFLAGS += -DTEST_PCD8544_RESET=GPIO\(0,1\) endif ifeq (,$(TEST_PCD8544_MODE)) - CFLAGS += -DTEST_PCD8544_MODE=GPIO_2 + CFLAGS += -DTEST_PCD8544_MODE=GPIO\(0,2\) endif include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_pir/Makefile b/tests/driver_pir/Makefile index 3e3411af22bb..5a5c38a2c683 100644 --- a/tests/driver_pir/Makefile +++ b/tests/driver_pir/Makefile @@ -5,10 +5,10 @@ FEATURES_REQUIRED = periph_gpio # Define default pin mappings for some boards: ifneq (,$(filter stm32f4discovery,$(BOARD))) - export PIR_GPIO ?= GPIO_8 + export PIR_GPIO ?= GPIO\(3,7\) endif ifneq (,$(filter arduino-due,$(BOARD))) - export PIR_GPIO ?= GPIO_10 + export PIR_GPIO ?= GPIO\(0,20\) endif USEMODULE += pir @@ -18,7 +18,7 @@ ifneq (,$(PIR_GPIO)) CFLAGS += -DPIR_GPIO=$(PIR_GPIO) else # set random default - CFLAGS += -DPIR_GPIO=GPIO_0 + CFLAGS += -DPIR_GPIO=GPIO\(0,0\) endif include $(RIOTBASE)/Makefile.include From 2cc2d9f740d5c245d7ebcbbbde53f4e8c4d13225 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Fri, 12 Jun 2015 19:10:29 +0200 Subject: [PATCH 06/33] drivers: adjusted drivers to changed GPIO interface --- drivers/at86rf231/at86rf231.c | 6 +++--- drivers/cc110x/cc110x-spi.c | 2 +- drivers/cc110x/cc110x.c | 6 +++--- drivers/dht/dht.c | 6 +++--- drivers/include/periph/gpio.h | 2 +- drivers/kw2xrf/kw2xrf_spi.c | 2 +- drivers/lis3dh/lis3dh.c | 2 +- drivers/lsm303dlhc/lsm303dlhc.c | 8 ++++---- drivers/ng_at86rf2xx/ng_at86rf2xx.c | 6 +++--- drivers/nrf24l01p/nrf24l01p.c | 4 ++-- drivers/nvram_spi/nvram-spi.c | 2 +- drivers/pcd8544/pcd8544.c | 6 +++--- drivers/pir/pir.c | 2 +- drivers/xbee/xbee.c | 4 ++-- 14 files changed, 29 insertions(+), 29 deletions(-) diff --git a/drivers/at86rf231/at86rf231.c b/drivers/at86rf231/at86rf231.c index 0cdfbf5832a4..450a40632c6c 100644 --- a/drivers/at86rf231/at86rf231.c +++ b/drivers/at86rf231/at86rf231.c @@ -420,11 +420,11 @@ void at86rf231_gpio_spi_interrupts_init(void) /* IRQ0 */ gpio_init_int(AT86RF231_INT, GPIO_NOPULL, GPIO_RISING, (gpio_cb_t)at86rf231_rx_irq, NULL); /* CS */ - gpio_init_out(AT86RF231_CS, GPIO_NOPULL); + gpio_init(AT86RF231_CS, GPIO_DIR_OUT, GPIO_NOPULL); /* SLEEP */ - gpio_init_out(AT86RF231_SLEEP, GPIO_NOPULL); + gpio_init(AT86RF231_SLEEP, GPIO_DIR_OUT, GPIO_NOPULL); /* RESET */ - gpio_init_out(AT86RF231_RESET, GPIO_NOPULL); + gpio_init(AT86RF231_RESET, GPIO_DIR_OUT, GPIO_NOPULL); } void at86rf231_reset(void) diff --git a/drivers/cc110x/cc110x-spi.c b/drivers/cc110x/cc110x-spi.c index 16a21c7f6748..c7815e689856 100644 --- a/drivers/cc110x/cc110x-spi.c +++ b/drivers/cc110x/cc110x-spi.c @@ -39,7 +39,7 @@ void cc110x_cs(void) { volatile int retry_count = 0; /* Switch MISO/GDO1 to GPIO input mode */ - gpio_init_in(CC110X_GDO1, GPIO_NOPULL); + gpio_init(CC110X_GDO1, GPIO_DIR_IN, GPIO_NOPULL); /* CS to low */ gpio_clear(CC110X_CS); /* Wait for SO to go low (voltage regulator diff --git a/drivers/cc110x/cc110x.c b/drivers/cc110x/cc110x.c index 762098f8c2d8..33ba5a5d9cbc 100644 --- a/drivers/cc110x/cc110x.c +++ b/drivers/cc110x/cc110x.c @@ -66,11 +66,11 @@ int cc110x_initialize(netdev_t *dev) rx_buffer_next = 0; /* Configure chip-select */ - gpio_init_out(CC110X_CS, GPIO_NOPULL); + gpio_init(CC110X_CS, GPIO_DIR_OUT, GPIO_NOPULL); gpio_set(CC110X_CS); /* Configure GDO0, GDO1, GDO2 */ - gpio_init_in(CC110X_GDO0, GPIO_NOPULL); - gpio_init_in(CC110X_GDO1, GPIO_NOPULL); + gpio_init(CC110X_GDO0, GPIO_DIR_IN, GPIO_NOPULL); + gpio_init(CC110X_GDO1, GPIO_DIR_IN, GPIO_NOPULL); gpio_init_int(CC110X_GDO2, GPIO_NOPULL, GPIO_FALLING, &cc110x_rx_handler, 0); gpio_irq_disable(CC110X_GDO2); diff --git a/drivers/dht/dht.c b/drivers/dht/dht.c index 60808009ca51..c83041483c6b 100644 --- a/drivers/dht/dht.c +++ b/drivers/dht/dht.c @@ -84,7 +84,7 @@ static void dht_read_data(gpio_t dev, uint32_t *data, uint8_t *checksum) hwtimer_wait(HWTIMER_TICKS(40)); /* sync on device */ - gpio_init_in(dev, GPIO_PULLUP); + gpio_init(dev, GPIO_DIR_IN, GPIO_PULLUP); while (!gpio_read(dev)) ; while (gpio_read(dev)) ; @@ -123,7 +123,7 @@ static void dht_read_data(gpio_t dev, uint32_t *data, uint8_t *checksum) *checksum = les_bits & 0x00000000000000FF; *data = (les_bits >> 8) & 0x00000000FFFFFFFF; - gpio_init_out(dev, GPIO_PULLUP); + gpio_init(dev, GPIO_DIR_OUT, GPIO_PULLUP); gpio_set(dev); } @@ -138,7 +138,7 @@ int dht_init(dht_t *dev, dht_type_t type, gpio_t gpio) dev->gpio = gpio; dev->type = type; - if (gpio_init_out(gpio, GPIO_PULLUP) == -1) { + if (gpio_init(gpio, GPIO_DIR_OUT, GPIO_PULLUP) == -1) { return -1; } gpio_set(gpio); diff --git a/drivers/include/periph/gpio.h b/drivers/include/periph/gpio.h index 9d7ac0a65904..279e0078b9c6 100644 --- a/drivers/include/periph/gpio.h +++ b/drivers/include/periph/gpio.h @@ -109,7 +109,7 @@ int gpio_init(gpio_t pin, gpio_dir_t dir, gpio_pp_t pullup); * @return 0 on success * @return -1 on error */ -int gpio_init_exti(gpio_t pin, gpio_pp_t pullup, gpio_flank_t flank, +int gpio_init_int(gpio_t pin, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb, void *arg); /** diff --git a/drivers/kw2xrf/kw2xrf_spi.c b/drivers/kw2xrf/kw2xrf_spi.c index c6e3a43cb14d..27250833c52d 100644 --- a/drivers/kw2xrf/kw2xrf_spi.c +++ b/drivers/kw2xrf/kw2xrf_spi.c @@ -64,7 +64,7 @@ int kw2xrf_spi_init(spi_t spi, spi_speed_t spi_speed, res = spi_init_master(kw2xrf_spi, SPI_CONF_FIRST_RISING, spi_speed); #if KW2XRF_SHARED_SPI spi_release(kw2xrf_spi); - gpio_init_out(kw2xrf_cs_pin, GPIO_NOPULL); + gpio_init(kw2xrf_cs_pin, GPIO_DIR_OUT, GPIO_NOPULL); gpio_set(kw2xrf_cs_pin); #endif diff --git a/drivers/lis3dh/lis3dh.c b/drivers/lis3dh/lis3dh.c index 2b11cd81ea20..35d7a70272dd 100644 --- a/drivers/lis3dh/lis3dh.c +++ b/drivers/lis3dh/lis3dh.c @@ -41,7 +41,7 @@ int lis3dh_init(lis3dh_t *dev, spi_t spi, gpio_t cs_pin, gpio_t int1_pin, gpio_t dev->scale = 0; /* CS */ - gpio_init_out(dev->cs, GPIO_NOPULL); + gpio_init(dev->cs, GPIO_DIR_OUT, GPIO_NOPULL); gpio_set(dev->cs); if (lis3dh_read_regs(dev, LIS3DH_REG_WHO_AM_I, 1, &in) < 0) { diff --git a/drivers/lsm303dlhc/lsm303dlhc.c b/drivers/lsm303dlhc/lsm303dlhc.c index d2251b11473d..7c149364c497 100644 --- a/drivers/lsm303dlhc/lsm303dlhc.c +++ b/drivers/lsm303dlhc/lsm303dlhc.c @@ -70,7 +70,7 @@ int lsm303dlhc_init(lsm303dlhc_t *dev, i2c_t i2c, gpio_t acc_pin, gpio_t mag_pin res += i2c_write_reg(dev->i2c, dev->acc_address, LSM303DLHC_REG_CTRL3_A, LSM303DLHC_CTRL3_A_I1_NONE); /* configure acc data ready pin */ - gpio_init_in(acc_pin, GPIO_NOPULL); + gpio_init(acc_pin, GPIO_DIR_IN, GPIO_NOPULL); /* configure magnetometer and temperature */ /* enable temperature output and set sample rate */ @@ -85,7 +85,7 @@ int lsm303dlhc_init(lsm303dlhc_t *dev, i2c_t i2c, gpio_t acc_pin, gpio_t mag_pin LSM303DLHC_REG_MR_M, LSM303DLHC_MAG_MODE_CONTINUOUS); i2c_release(dev->i2c); /* configure mag data ready pin */ - gpio_init_in(mag_pin, GPIO_NOPULL); + gpio_init(mag_pin, GPIO_DIR_IN, GPIO_NOPULL); return (res < 7) ? -1 : 0; } @@ -215,7 +215,7 @@ int lsm303dlhc_enable(lsm303dlhc_t *dev) tmp = (LSM303DLHC_CTRL4_A_BDU| LSM303DLHC_CTRL4_A_SCALE_2G | LSM303DLHC_CTRL4_A_HR); res += i2c_write_reg(dev->i2c, dev->acc_address, LSM303DLHC_REG_CTRL4_A, tmp); res += i2c_write_reg(dev->i2c, dev->acc_address, LSM303DLHC_REG_CTRL3_A, LSM303DLHC_CTRL3_A_I1_DRDY1); - gpio_init_in(dev->acc_pin, GPIO_NOPULL); + gpio_init(dev->acc_pin, GPIO_DIR_IN, GPIO_NOPULL); tmp = LSM303DLHC_TEMP_EN | LSM303DLHC_TEMP_SAMPLE_75HZ; res += i2c_write_reg(dev->i2c, dev->mag_address, LSM303DLHC_REG_CRA_M, tmp); @@ -227,7 +227,7 @@ int lsm303dlhc_enable(lsm303dlhc_t *dev) LSM303DLHC_REG_MR_M, LSM303DLHC_MAG_MODE_CONTINUOUS); i2c_release(dev->i2c); - gpio_init_in(dev->mag_pin, GPIO_NOPULL); + gpio_init(dev->mag_pin, GPIO_DIR_IN, GPIO_NOPULL); return (res < 6) ? -1 : 0; } diff --git a/drivers/ng_at86rf2xx/ng_at86rf2xx.c b/drivers/ng_at86rf2xx/ng_at86rf2xx.c index 41ee854afe70..b4259fa22009 100644 --- a/drivers/ng_at86rf2xx/ng_at86rf2xx.c +++ b/drivers/ng_at86rf2xx/ng_at86rf2xx.c @@ -65,11 +65,11 @@ int ng_at86rf2xx_init(ng_at86rf2xx_t *dev, spi_t spi, spi_speed_t spi_speed, /* initialise SPI */ spi_init_master(dev->spi, SPI_CONF_FIRST_RISING, spi_speed); /* initialise GPIOs */ - gpio_init_out(dev->cs_pin, GPIO_NOPULL); + gpio_init(dev->cs_pin, GPIO_DIR_OUT, GPIO_NOPULL); gpio_set(dev->cs_pin); - gpio_init_out(dev->sleep_pin, GPIO_NOPULL); + gpio_init(dev->sleep_pin, GPIO_DIR_OUT, GPIO_NOPULL); gpio_clear(dev->sleep_pin); - gpio_init_out(dev->reset_pin, GPIO_NOPULL); + gpio_init(dev->reset_pin, GPIO_DIR_OUT, GPIO_NOPULL); gpio_set(dev->reset_pin); gpio_init_int(dev->int_pin, GPIO_NOPULL, GPIO_RISING, _irq_handler, dev); diff --git a/drivers/nrf24l01p/nrf24l01p.c b/drivers/nrf24l01p/nrf24l01p.c index 43b68defb8f5..3ac0e2a32c4d 100644 --- a/drivers/nrf24l01p/nrf24l01p.c +++ b/drivers/nrf24l01p/nrf24l01p.c @@ -80,10 +80,10 @@ int nrf24l01p_init(nrf24l01p_t *dev, spi_t spi, gpio_t ce, gpio_t cs, gpio_t irq dev->listener = KERNEL_PID_UNDEF; /* Init CE pin */ - gpio_init_out(dev->ce, GPIO_NOPULL); + gpio_init(dev->ce, GPIO_DIR_OUT, GPIO_NOPULL); /* Init CS pin */ - gpio_init_out(dev->cs, GPIO_NOPULL); + gpio_init(dev->cs, GPIO_DIR_OUT, GPIO_NOPULL); gpio_set(dev->cs); /* Init IRQ pin */ diff --git a/drivers/nvram_spi/nvram-spi.c b/drivers/nvram_spi/nvram-spi.c index 4ae873b554fd..441dc4ab131c 100644 --- a/drivers/nvram_spi/nvram-spi.c +++ b/drivers/nvram_spi/nvram-spi.c @@ -114,7 +114,7 @@ int nvram_spi_init(nvram_t *dev, nvram_spi_params_t *spi_params, size_t size) } dev->extra = spi_params; - gpio_init_out(spi_params->cs, GPIO_NOPULL); + gpio_init(spi_params->cs, GPIO_DIR_OUT, GPIO_NOPULL); gpio_set(spi_params->cs); return 0; diff --git a/drivers/pcd8544/pcd8544.c b/drivers/pcd8544/pcd8544.c index fbe7c0612857..054cabd87be8 100644 --- a/drivers/pcd8544/pcd8544.c +++ b/drivers/pcd8544/pcd8544.c @@ -231,9 +231,9 @@ int pcd8544_init(pcd8544_t *dev, spi_t spi, gpio_t cs, gpio_t reset, gpio_t mode DEBUG("done setting dev members\n"); /* initialze pins */ - gpio_init_out(cs, GPIO_NOPULL); - gpio_init_out(reset, GPIO_NOPULL); - gpio_init_out(mode, GPIO_NOPULL); + gpio_init(cs, GPIO_DIR_OUT, GPIO_NOPULL); + gpio_init(reset, GPIO_DIR_OUT, GPIO_NOPULL); + gpio_init(mode, GPIO_DIR_OUT, GPIO_NOPULL); DEBUG("done with gpios\n"); /* clear CS line */ gpio_set(cs); diff --git a/drivers/pir/pir.c b/drivers/pir/pir.c index 2a802b20c6c9..3a7c8a49f02a 100644 --- a/drivers/pir/pir.c +++ b/drivers/pir/pir.c @@ -41,7 +41,7 @@ int pir_init(pir_t *dev, gpio_t gpio) { dev->gpio_dev = gpio; dev->msg_thread_pid = KERNEL_PID_UNDEF; - return gpio_init_in(dev->gpio_dev, GPIO_NOPULL); + return gpio_init(dev->gpio_dev, GPIO_DIR_IN, GPIO_NOPULL); } pir_event_t pir_get_status(pir_t *dev) diff --git a/drivers/xbee/xbee.c b/drivers/xbee/xbee.c index bd7f60339cb3..e7cf19112abb 100644 --- a/drivers/xbee/xbee.c +++ b/drivers/xbee/xbee.c @@ -437,14 +437,14 @@ int xbee_init(xbee_t *dev, uart_t uart, uint32_t baudrate, return -ENXIO; } if (reset_pin < GPIO_NUMOF) { - if (gpio_init_out(reset_pin, GPIO_NOPULL) < 0) { + if (gpio_init(reset_pin, GPIO_DIR_OUT, GPIO_NOPULL) < 0) { DEBUG("xbee: Error initializing RESET pin\n"); return -ENXIO; } gpio_set(reset_pin); } if (sleep_pin < GPIO_NUMOF) { - if (gpio_init_out(sleep_pin, GPIO_NOPULL) < 0) { + if (gpio_init(sleep_pin, GPIO_DIR_OUT, GPIO_NOPULL) < 0) { DEBUG("xbee: Error initializing SLEEP pin\n"); return -ENXIO; } From 69d16af81cbf52896283c7d7111791da65eeee2d Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 3 Jun 2015 18:20:22 +0200 Subject: [PATCH 07/33] cpu/stm32f4: remodeled GPIO implementation --- cpu/stm32f4/include/periph_cpu.h | 93 +++++ cpu/stm32f4/periph/gpio.c | 646 ++++++------------------------- cpu/stm32f4/startup.c | 22 +- 3 files changed, 223 insertions(+), 538 deletions(-) create mode 100644 cpu/stm32f4/include/periph_cpu.h diff --git a/cpu/stm32f4/include/periph_cpu.h b/cpu/stm32f4/include/periph_cpu.h new file mode 100644 index 000000000000..b0b3eea7ea34 --- /dev/null +++ b/cpu/stm32f4/include/periph_cpu.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup cpu_stm32f4 + * @{ + * + * @file + * @brief CPU specific definitions for internal peripheral handling + * + * @author Hauke Petersen + */ + +#ifndef CPU_PERIPH_H_ +#define CPU_PERIPH_H_ + +#include "cpu.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Overwrite the default gpio_t type definition + * @{ + */ +#define HAVE_GPIO_T +typedef uint32_t gpio_t; +/** @} */ + +/** + * @brief Define a CPU specific GPIO pin generator macro + */ +#define GPIO(x, y) ((GPIOA_BASE + (x << 10)) | y) + +/** + * @brief Available ports on the STM32F4 family + */ +enum { + PORT_A = 0, /**< port A */ + PORT_B = 1, /**< port B */ + PORT_C = 2, /**< port C */ + PORT_D = 3, /**< port D */ + PORT_E = 4, /**< port E */ + PORT_F = 5, /**< port F */ + PORT_G = 6, /**< port G */ + PORT_H = 7, /**< port H */ + PORT_I = 8 /**< port I */ +}; + +/** + * @brief Available MUX values for configuring a pin's alternate function + */ +typedef enum { + GPIO_AF0 = 0, /**< use alternate function 0 */ + GPIO_AF1, /**< use alternate function 1 */ + GPIO_AF2, /**< use alternate function 2 */ + GPIO_AF3, /**< use alternate function 3 */ + GPIO_AF4, /**< use alternate function 4 */ + GPIO_AF5, /**< use alternate function 5 */ + GPIO_AF6, /**< use alternate function 6 */ + GPIO_AF7, /**< use alternate function 7 */ + GPIO_AF8, /**< use alternate function 8 */ + GPIO_AF9, /**< use alternate function 9 */ + GPIO_AF10, /**< use alternate function 10 */ + GPIO_AF11, /**< use alternate function 11 */ + GPIO_AF12, /**< use alternate function 12 */ + GPIO_AF13, /**< use alternate function 13 */ + GPIO_AF14 /**< use alternate function 14 */ +} gpio_af_t; + +/** + * @brief Configure the alternate function for the given pin + * + * @note This is meant for internal use in STM32F4 peripheral drivers only + * + * @param[in] pin pin to configure + * @param[in] af alternate function to use + */ +void gpio_init_af(gpio_t pin, gpio_af_t af); + + +#ifdef __cplusplus +} +#endif + +#endif /* CPU_PERIPH_H_ */ +/** @} */ diff --git a/cpu/stm32f4/periph/gpio.c b/cpu/stm32f4/periph/gpio.c index 86adb506ced1..b8bf944e5094 100644 --- a/cpu/stm32f4/periph/gpio.c +++ b/cpu/stm32f4/periph/gpio.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Freie Universität Berlin + * Copyright (C) 2015 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser General * Public License v2.1. See the file LICENSE in the top level directory for more @@ -25,598 +25,196 @@ #include "periph/gpio.h" #include "periph_conf.h" -/* guard file in case no GPIO devices are defined */ -#if GPIO_NUMOF +/** + * @brief Number of available external interrupt lines + */ +#define GPIO_ISR_CHAN_NUMOF (16U) +/** + * @brief Datastructure to hold an interrupt context + */ typedef struct { - gpio_cb_t cb; /**< callback to call on GPIO interrupt */ - void *arg; /**< argument passed to the callback */ -} gpio_state_t; + void (*cb)(void *arg); /**< interrupt callback routine */ + void *arg; /**< optional argument */ +} exti_ctx_t; /** - * @brief Unified IRQ handler shared by all interrupt routines - * - * @param[in] dev the device that triggered the interrupt + * @brief Hold one callback function pointer for each interrupt line */ -static inline void irq_handler(gpio_t dev); - -/* static port mapping */ -static GPIO_TypeDef *const gpio_port_map[GPIO_NUMOF] = { -#if GPIO_0_EN - [GPIO_0] = GPIO_0_PORT, -#endif -#if GPIO_1_EN - [GPIO_1] = GPIO_1_PORT, -#endif -#if GPIO_2_EN - [GPIO_2] = GPIO_2_PORT, -#endif -#if GPIO_3_EN - [GPIO_3] = GPIO_3_PORT, -#endif -#if GPIO_4_EN - [GPIO_4] = GPIO_4_PORT, -#endif -#if GPIO_5_EN - [GPIO_5] = GPIO_5_PORT, -#endif -#if GPIO_6_EN - [GPIO_6] = GPIO_6_PORT, -#endif -#if GPIO_7_EN - [GPIO_7] = GPIO_7_PORT, -#endif -#if GPIO_8_EN - [GPIO_8] = GPIO_8_PORT, -#endif -#if GPIO_9_EN - [GPIO_9] = GPIO_9_PORT, -#endif -#if GPIO_10_EN - [GPIO_10] = GPIO_10_PORT, -#endif -#if GPIO_11_EN - [GPIO_11] = GPIO_11_PORT, -#endif -#if GPIO_12_EN - [GPIO_12] = GPIO_12_PORT, -#endif -#if GPIO_13_EN - [GPIO_13] = GPIO_13_PORT, -#endif -#if GPIO_14_EN - [GPIO_14] = GPIO_14_PORT, -#endif -#if GPIO_15_EN - [GPIO_15] = GPIO_15_PORT, -#endif -}; - -/* static pin mapping */ -static const uint8_t gpio_pin_map[GPIO_NUMOF] = { -#if GPIO_0_EN - [GPIO_0] = GPIO_0_PIN, -#endif -#if GPIO_1_EN - [GPIO_1] = GPIO_1_PIN, -#endif -#if GPIO_2_EN - [GPIO_2] = GPIO_2_PIN, -#endif -#if GPIO_3_EN - [GPIO_3] = GPIO_3_PIN, -#endif -#if GPIO_4_EN - [GPIO_4] = GPIO_4_PIN, -#endif -#if GPIO_5_EN - [GPIO_5] = GPIO_5_PIN, -#endif -#if GPIO_6_EN - [GPIO_6] = GPIO_6_PIN, -#endif -#if GPIO_7_EN - [GPIO_7] = GPIO_7_PIN, -#endif -#if GPIO_8_EN - [GPIO_8] = GPIO_8_PIN, -#endif -#if GPIO_9_EN - [GPIO_9] = GPIO_9_PIN, -#endif -#if GPIO_10_EN - [GPIO_10] = GPIO_10_PIN, -#endif -#if GPIO_11_EN - [GPIO_11] = GPIO_11_PIN, -#endif -#if GPIO_12_EN - [GPIO_12] = GPIO_12_PIN, -#endif -#if GPIO_13_EN - [GPIO_13] = GPIO_13_PIN, -#endif -#if GPIO_14_EN - [GPIO_14] = GPIO_14_PIN, -#endif -#if GPIO_15_EN - [GPIO_15] = GPIO_15_PIN, -#endif -}; - -/* static irq id mapping */ -static const IRQn_Type gpio_irq_map[GPIO_NUMOF] = { -#if GPIO_0_EN - [GPIO_0] = GPIO_0_IRQ, -#endif -#if GPIO_1_EN - [GPIO_1] = GPIO_1_IRQ, -#endif -#if GPIO_2_EN - [GPIO_2] = GPIO_2_IRQ, -#endif -#if GPIO_3_EN - [GPIO_3] = GPIO_3_IRQ, -#endif -#if GPIO_4_EN - [GPIO_4] = GPIO_4_IRQ, -#endif -#if GPIO_5_EN - [GPIO_5] = GPIO_5_IRQ, -#endif -#if GPIO_6_EN - [GPIO_6] = GPIO_6_IRQ, -#endif -#if GPIO_7_EN - [GPIO_7] = GPIO_7_IRQ, -#endif -#if GPIO_8_EN - [GPIO_8] = GPIO_8_IRQ, -#endif -#if GPIO_9_EN - [GPIO_9] = GPIO_9_IRQ, -#endif -#if GPIO_10_EN - [GPIO_10] = GPIO_10_IRQ, -#endif -#if GPIO_11_EN - [GPIO_11] = GPIO_11_IRQ, -#endif -#if GPIO_12_EN - [GPIO_12] = GPIO_12_IRQ, -#endif -#if GPIO_13_EN - [GPIO_13] = GPIO_13_IRQ, -#endif -#if GPIO_14_EN - [GPIO_14] = GPIO_14_IRQ, -#endif -#if GPIO_15_EN - [GPIO_15] = GPIO_15_IRQ, -#endif -}; - -/* static clock mapping */ -static const uint8_t gpio_clock_map[GPIO_NUMOF] = { -#if GPIO_0_EN - [GPIO_0] = GPIO_0_CLK, -#endif -#if GPIO_1_EN - [GPIO_1] = GPIO_1_CLK, -#endif -#if GPIO_2_EN - [GPIO_2] = GPIO_2_CLK, -#endif -#if GPIO_3_EN - [GPIO_3] = GPIO_3_CLK, -#endif -#if GPIO_4_EN - [GPIO_4] = GPIO_4_CLK, -#endif -#if GPIO_5_EN - [GPIO_5] = GPIO_5_CLK, -#endif -#if GPIO_6_EN - [GPIO_6] = GPIO_6_CLK, -#endif -#if GPIO_7_EN - [GPIO_7] = GPIO_7_CLK, -#endif -#if GPIO_8_EN - [GPIO_8] = GPIO_8_CLK, -#endif -#if GPIO_9_EN - [GPIO_9] = GPIO_9_CLK, -#endif -#if GPIO_10_EN - [GPIO_10] = GPIO_10_CLK, -#endif -#if GPIO_11_EN - [GPIO_11] = GPIO_11_CLK, -#endif -#if GPIO_12_EN - [GPIO_12] = GPIO_12_CLK, -#endif -#if GPIO_13_EN - [GPIO_13] = GPIO_13_CLK, -#endif -#if GPIO_14_EN - [GPIO_14] = GPIO_14_CLK, -#endif -#if GPIO_15_EN - [GPIO_15] = GPIO_15_CLK, -#endif -}; +static exti_ctx_t exti_chan[GPIO_ISR_CHAN_NUMOF]; /** - * @brief Hold one callback function pointer for each gpio device + * @brief Extract the port base address from the given pin identifier */ -static gpio_state_t gpio_config[GPIO_NUMOF]; - -int gpio_init_out(gpio_t dev, gpio_pp_t pullup) +static inline GPIO_TypeDef *_port(gpio_t pin) { - GPIO_TypeDef *port; - uint32_t pin; - - if (dev >= GPIO_NUMOF) { - return -1; - } - - port = gpio_port_map[dev]; - pin = gpio_pin_map[dev]; - - RCC->AHB1ENR |= (1 << gpio_clock_map[dev]); - - port->MODER &= ~(2 << (2 * pin)); /* set pin to output mode */ - port->MODER |= (1 << (2 * pin)); - port->OTYPER &= ~(1 << pin); /* set to push-pull configuration */ - port->OSPEEDR |= (3 << (2 * pin)); /* set to high speed */ - port->PUPDR &= ~(3 << (2 * pin)); /* configure push-pull resistors */ - port->PUPDR |= (pullup << (2 * pin)); - port->ODR &= ~(1 << pin); /* set pin to low signal */ - - return 0; /* all OK */ + return (GPIO_TypeDef *)(pin & ~(0x0f)); } -int gpio_init_in(gpio_t dev, gpio_pp_t pullup) +/** + * @brief Extract the port number form the given identifier + * + * The port number is extracted by looking at bits 10, 11, 12, 13 of the base + * register addresses. + */ +static inline int _port_num(gpio_t pin) { - GPIO_TypeDef *port; - uint32_t pin; - - if (dev >= GPIO_NUMOF) { - return -1; - } - - port = gpio_port_map[dev]; - pin = gpio_pin_map[dev]; - - RCC->AHB1ENR |= (1 << gpio_clock_map[dev]); - - port->MODER &= ~(3 << (2 * pin)); /* configure pin as input */ - port->PUPDR &= ~(3 << (2 * pin)); /* configure push-pull resistors */ - port->PUPDR |= (pullup << (2 * pin)); + return ((pin >> 10) & 0x0f); +} - return 0; /* everything alright here */ +/** + * @brief Extract the pin number from the last 4 bit of the pin identifier + */ +static inline int _pin_num(gpio_t pin) +{ + return (pin & 0x0f); } -int gpio_init_int(gpio_t dev, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb, void *arg) +int gpio_init(gpio_t pin, gpio_dir_t dir, gpio_pp_t pullup) { - int res; - uint32_t pin; + GPIO_TypeDef *port = _port(pin); + int pin_num = _pin_num(pin); - res = gpio_init_in(dev, pullup); - if (res < 0) { - return res; + /* enable clock */ + RCC->AHB1ENR |= (RCC_AHB1ENR_GPIOAEN << _port_num(pin)); + /* configure pull register */ + port->PUPDR &= ~(3 << (2 * pin_num)); + port->PUPDR |= (pullup << (2 * pin_num)); + /* set direction */ + if (dir == GPIO_DIR_OUT) { + port->MODER &= ~(3 << (2 * pin_num)); /* set pin to output mode */ + port->MODER |= (1 << (2 * pin_num)); + port->OTYPER &= ~(1 << pin_num); /* set to push-pull */ + port->OSPEEDR |= (3 << (2 * pin_num)); /* set to high speed */ + port->ODR &= ~(1 << pin_num); /* set pin to low signal */ } + else { + port->MODER &= ~(3 << (2 * pin_num)); /* configure pin as input */ + } + return 0; +} - pin = gpio_pin_map[dev]; +int gpio_init_int(gpio_t pin, + gpio_pp_t pullup, gpio_flank_t flank, + gpio_cb_t cb, void *arg) +{ + int pin_num = _pin_num(pin); + int port_num = _port_num(pin); + /* configure and save exti configuration struct */ + exti_chan[pin_num].cb = cb; + exti_chan[pin_num].arg = arg; /* enable the SYSCFG clock */ RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; - - /* enable IRQ */ - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - GPIO_0_EXTI_CFG(); - break; -#endif -#if GPIO_1_EN - case GPIO_1: - GPIO_1_EXTI_CFG(); - break; -#endif -#if GPIO_2_EN - case GPIO_2: - GPIO_2_EXTI_CFG(); - break; -#endif -#if GPIO_3_EN - case GPIO_3: - GPIO_3_EXTI_CFG(); - break; -#endif -#if GPIO_4_EN - case GPIO_4: - GPIO_4_EXTI_CFG(); - break; -#endif -#if GPIO_5_EN - case GPIO_5: - GPIO_5_EXTI_CFG(); - break; -#endif -#if GPIO_6_EN - case GPIO_6: - GPIO_6_EXTI_CFG(); - break; -#endif -#if GPIO_7_EN - case GPIO_7: - GPIO_7_EXTI_CFG(); - break; -#endif -#if GPIO_8_EN - case GPIO_8: - GPIO_8_EXTI_CFG(); - break; -#endif -#if GPIO_9_EN - case GPIO_9: - GPIO_9_EXTI_CFG(); - break; -#endif -#if GPIO_10_EN - case GPIO_10: - GPIO_10_EXTI_CFG(); - break; -#endif -#if GPIO_11_EN - case GPIO_11: - GPIO_11_EXTI_CFG(); - break; -#endif -#if GPIO_12_EN - case GPIO_12: - GPIO_12_EXTI_CFG(); - break; -#endif -#if GPIO_13_EN - case GPIO_13: - GPIO_13_EXTI_CFG(); - break; -#endif -#if GPIO_14_EN - case GPIO_14: - GPIO_14_EXTI_CFG(); - break; -#endif -#if GPIO_15_EN - case GPIO_15: - GPIO_15_EXTI_CFG(); - break; -#endif + /* initialize pin as input */ + gpio_init(pin, GPIO_DIR_IN, pullup); + /* enable global pin interrupt */ + if (pin_num < 5) { + NVIC_EnableIRQ(EXTI0_IRQn + pin_num); } - NVIC_SetPriority(gpio_irq_map[dev], GPIO_IRQ_PRIO); - NVIC_EnableIRQ(gpio_irq_map[dev]); - - /* set callback */ - gpio_config[dev].cb = cb; - gpio_config[dev].arg = arg; - - /* configure the active edges */ + else if (pin_num < 10) { + NVIC_EnableIRQ(EXTI9_5_IRQn); + } + else { + NVIC_EnableIRQ(EXTI15_10_IRQn); + } + /* configure the active edge(s) */ switch (flank) { case GPIO_RISING: - EXTI->RTSR |= (1 << pin); - EXTI->FTSR &= ~(1 << pin); + EXTI->RTSR |= (1 << pin_num); + EXTI->FTSR &= ~(1 << pin_num); break; case GPIO_FALLING: - EXTI->RTSR &= ~(1 << pin); - EXTI->FTSR |= (1 << pin); + EXTI->RTSR &= ~(1 << pin_num); + EXTI->FTSR |= (1 << pin_num); break; case GPIO_BOTH: - EXTI->RTSR |= (1 << pin); - EXTI->FTSR |= (1 << pin); + EXTI->RTSR |= (1 << pin_num); + EXTI->FTSR |= (1 << pin_num); break; } - + /* enable specific pin as exti sources */ + SYSCFG->EXTICR[pin_num >> 2] &= ~(0xf << ((pin_num & 0x03) * 4)); + SYSCFG->EXTICR[pin_num >> 2] |= (port_num << ((pin_num & 0x03) * 4)); /* clear any pending requests */ - EXTI->PR = (1 << pin); + EXTI->PR = (1 << pin_num); /* enable interrupt for EXTI line */ - EXTI->IMR |= (1 << pin); - + EXTI->IMR |= (1 << pin_num); return 0; } -void gpio_irq_enable(gpio_t dev) +void gpio_init_af(gpio_t pin, gpio_af_t af) { - uint32_t pin; + GPIO_TypeDef *port = _port(pin); + uint32_t pin_num = _pin_num(pin); - if (dev >= GPIO_NUMOF) { - return; - } - - pin = gpio_pin_map[dev]; - EXTI->IMR |= (1 << pin); + /* set pin to AF mode */ + port->MODER &= ~(3 << (2 * pin_num)); + port->MODER |= (2 << (2 * pin_num)); + /* set selected function */ + port->AFR[pin_num & 0x10] &= ~(0xf << ((pin_num & 0x0f) * 4)); + port->AFR[pin_num & 0x10] |= (af << ((pin_num & 0x0f) * 4)); } -void gpio_irq_disable(gpio_t dev) +void gpio_irq_enable(gpio_t pin) { - uint32_t pin; - - if (dev >= GPIO_NUMOF) { - return; - } - - pin = gpio_pin_map[dev]; - EXTI->IMR &= ~(1 << pin); + EXTI->IMR |= (1 << _pin_num(pin)); } -int gpio_read(gpio_t dev) +void gpio_irq_disable(gpio_t pin) { - GPIO_TypeDef *port; - uint32_t pin; - - if (dev >= GPIO_NUMOF) { - return -1; - } + EXTI->IMR &= ~(1 << _pin_num(pin)); +} - port = gpio_port_map[dev]; - pin = gpio_pin_map[dev]; +int gpio_read(gpio_t pin) +{ + GPIO_TypeDef *port = _port(pin); + uint32_t pin_num = _pin_num(pin); - if (port->MODER & (3 << (pin * 2))) { /* if configured as output */ - return port->ODR & (1 << pin); /* read output data register */ + if (port->MODER & (3 << (pin_num * 2))) { /* if configured as output */ + return port->ODR & (1 << pin_num); /* read output data reg */ } else { - return port->IDR & (1 << pin); /* else read input data register */ + return port->IDR & (1 << pin_num); /* else read input data reg */ } } -void gpio_set(gpio_t dev) +void gpio_set(gpio_t pin) { - GPIO_TypeDef *port; - uint32_t pin; - - if (dev >= GPIO_NUMOF) { - return; - } - - port = gpio_port_map[dev]; - pin = gpio_pin_map[dev]; - - port->BSRRL = (1 << pin); + _port(pin)->BSRRL = (1 << _pin_num(pin)); } -void gpio_clear(gpio_t dev) +void gpio_clear(gpio_t pin) { - GPIO_TypeDef *port; - uint32_t pin; - - if (dev >= GPIO_NUMOF) { - return; - } - - port = gpio_port_map[dev]; - pin = gpio_pin_map[dev]; - - port->BSRRH = (1 << pin); + _port(pin)->BSRRH = (1 << _pin_num(pin)); } -void gpio_toggle(gpio_t dev) +void gpio_toggle(gpio_t pin) { - if (gpio_read(dev)) { - gpio_clear(dev); + if (gpio_read(pin)) { + gpio_clear(pin); } else { - gpio_set(dev); + gpio_set(pin); } } -void gpio_write(gpio_t dev, int value) +void gpio_write(gpio_t pin, int value) { if (value) { - gpio_set(dev); + gpio_set(pin); } else { - gpio_clear(dev); + gpio_clear(pin); } } -static inline void irq_handler(gpio_t dev) +void isr_exti(void) { - gpio_config[dev].cb(gpio_config[dev].arg); + for (int i = 0; i < GPIO_ISR_CHAN_NUMOF; i++) { + if (EXTI->PR & (1 << i)) { + EXTI->PR |= (1 << i); /* clear by writing a 1 */ + exti_chan[i].cb(exti_chan[i].arg); + } + } if (sched_context_switch_request) { thread_yield(); } } - -void isr_exti0(void) -{ - if (EXTI->PR & EXTI_PR_PR0) { - EXTI->PR |= EXTI_PR_PR0; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_0); - } -} - -void isr_exti1(void) -{ - if (EXTI->PR & EXTI_PR_PR1) { - EXTI->PR |= EXTI_PR_PR1; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_1); - } -} - -void isr_exti2(void) -{ - if (EXTI->PR & EXTI_PR_PR2) { - EXTI->PR |= EXTI_PR_PR2; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_2); - } -} - -void isr_exti3(void) -{ - if (EXTI->PR & EXTI_PR_PR3) { - EXTI->PR |= EXTI_PR_PR3; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_3); - } -} - -void isr_exti4(void) -{ - if (EXTI->PR & EXTI_PR_PR4) { - EXTI->PR |= EXTI_PR_PR4; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_4); - } -} - -void isr_exti9_5(void) -{ - if (EXTI->PR & EXTI_PR_PR5) { - EXTI->PR |= EXTI_PR_PR5; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_5); - } - if (EXTI->PR & EXTI_PR_PR6) { - EXTI->PR |= EXTI_PR_PR6; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_6); - } - if (EXTI->PR & EXTI_PR_PR7) { - EXTI->PR |= EXTI_PR_PR7; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_7); - } - if (EXTI->PR & EXTI_PR_PR8) { - EXTI->PR |= EXTI_PR_PR8; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_8); - } - if (EXTI->PR & EXTI_PR_PR9) { - EXTI->PR |= EXTI_PR_PR9; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_9); - } -} - -void isr_exti15_10(void) -{ - if (EXTI->PR & EXTI_PR_PR10) { - EXTI->PR |= EXTI_PR_PR10; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_10); - } - if (EXTI->PR & EXTI_PR_PR11) { - EXTI->PR |= EXTI_PR_PR11; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_11); - } - if (EXTI->PR & EXTI_PR_PR12) { - EXTI->PR |= EXTI_PR_PR12; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_12); - } - if (EXTI->PR & EXTI_PR_PR13) { - EXTI->PR |= EXTI_PR_PR13; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_13); - } - if (EXTI->PR & EXTI_PR_PR14) { - EXTI->PR |= EXTI_PR_PR14; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_14); - } - if (EXTI->PR & EXTI_PR_PR15) { - EXTI->PR |= EXTI_PR_PR15; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_15); - } -} - -#endif /* GPIO_NUMOF */ diff --git a/cpu/stm32f4/startup.c b/cpu/stm32f4/startup.c index 84e151f2a56f..fe71b60c0d0f 100644 --- a/cpu/stm32f4/startup.c +++ b/cpu/stm32f4/startup.c @@ -128,11 +128,7 @@ void isr_tamp_stamp(void) __attribute__ ((weak, alias("dummy_handler") void isr_rtc_wkup(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_flash(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_rcc(void) __attribute__ ((weak, alias("dummy_handler"))); -void isr_exti0(void) __attribute__ ((weak, alias("dummy_handler"))); -void isr_exti1(void) __attribute__ ((weak, alias("dummy_handler"))); -void isr_exti2(void) __attribute__ ((weak, alias("dummy_handler"))); -void isr_exti3(void) __attribute__ ((weak, alias("dummy_handler"))); -void isr_exti4(void) __attribute__ ((weak, alias("dummy_handler"))); +void isr_exti(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_dma1_stream0(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_dma1_stream1(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_dma1_stream2(void) __attribute__ ((weak, alias("dummy_handler"))); @@ -145,7 +141,6 @@ void isr_can1_tx(void) __attribute__ ((weak, alias("dummy_handler") void isr_can1_rx0(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_can1_rx1(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_can1_sce(void) __attribute__ ((weak, alias("dummy_handler"))); -void isr_exti9_5(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_tim1_brk_tim9(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_tim1_up_tim10(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_tim1_trg_com_tim11(void) __attribute__ ((weak, alias("dummy_handler"))); @@ -162,7 +157,6 @@ void isr_spi2(void) __attribute__ ((weak, alias("dummy_handler") void isr_usart1(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_usart2(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_usart3(void) __attribute__ ((weak, alias("dummy_handler"))); -void isr_exti15_10(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_rtc_alarm(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_otg_fs_wkup(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_tim8_brk_tim12(void) __attribute__ ((weak, alias("dummy_handler"))); @@ -233,11 +227,11 @@ const void *interrupt_vector[] = { (void*) isr_rtc_wkup, /* RTC Wakeup through the EXTI line */ (void*) isr_flash, /* FLASH */ (void*) isr_rcc, /* RCC */ - (void*) isr_exti0, /* EXTI Line0 */ - (void*) isr_exti1, /* EXTI Line1 */ - (void*) isr_exti2, /* EXTI Line2 */ - (void*) isr_exti3, /* EXTI Line3 */ - (void*) isr_exti4, /* EXTI Line4 */ + (void*) isr_exti, /* EXTI Line0 */ + (void*) isr_exti, /* EXTI Line1 */ + (void*) isr_exti, /* EXTI Line2 */ + (void*) isr_exti, /* EXTI Line3 */ + (void*) isr_exti, /* EXTI Line4 */ (void*) isr_dma1_stream0, /* DMA1 Stream 0 */ (void*) isr_dma1_stream1, /* DMA1 Stream 1 */ (void*) isr_dma1_stream2, /* DMA1 Stream 2 */ @@ -250,7 +244,7 @@ const void *interrupt_vector[] = { (void*) isr_can1_rx0, /* CAN1 RX0 */ (void*) isr_can1_rx1, /* CAN1 RX1 */ (void*) isr_can1_sce, /* CAN1 SCE */ - (void*) isr_exti9_5, /* External Line[9:5]s */ + (void*) isr_exti, /* External Line[9:5]s */ (void*) isr_tim1_brk_tim9, /* TIM1 Break and TIM9 */ (void*) isr_tim1_up_tim10, /* TIM1 Update and TIM10 */ (void*) isr_tim1_trg_com_tim11, /* TIM1 Trigger and Commutation and TIM11 */ @@ -267,7 +261,7 @@ const void *interrupt_vector[] = { (void*) isr_usart1, /* USART1 */ (void*) isr_usart2, /* USART2 */ (void*) isr_usart3, /* USART3 */ - (void*) isr_exti15_10, /* External Line[15:10]s */ + (void*) isr_exti, /* External Line[15:10]s */ (void*) isr_rtc_alarm, /* RTC Alarm (A and B) through EXTI Line */ (void*) isr_otg_fs_wkup, /* USB OTG FS Wakeup through EXTI line */ (void*) isr_tim8_brk_tim12, /* TIM8 Break and TIM12 */ From 3a2d89f88ddd81fc0c4c895e3511e02ce9112c39 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 3 Jun 2015 18:21:29 +0200 Subject: [PATCH 08/33] cpu/stm32f3: remodeled GPIO driver implementation --- cpu/stm32f3/include/periph_cpu.h | 81 +++ cpu/stm32f3/periph/gpio.c | 903 +++++-------------------------- cpu/stm32f3/startup.c | 22 +- 3 files changed, 218 insertions(+), 788 deletions(-) create mode 100644 cpu/stm32f3/include/periph_cpu.h diff --git a/cpu/stm32f3/include/periph_cpu.h b/cpu/stm32f3/include/periph_cpu.h new file mode 100644 index 000000000000..1a735e319250 --- /dev/null +++ b/cpu/stm32f3/include/periph_cpu.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup cpu_stm32f3 + * @{ + * + * @file + * @brief CPU specific definitions for internal peripheral handling + * + * @author Hauke Petersen + */ + +#ifndef PERIPH_CPU_H_ +#define PERIPH_CPU_H_ + +#include "cpu.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Overwrite the default gpio_t type definition + * @{ + */ +#define HAVE_GPIO_T +typedef uint32_t gpio_t; +/** @} */ + +/** + * @brief Define a CPU specific GPIO pin generator macro + */ +#define GPIO(x, y) ((GPIOA_BASE + (x << 10)) | y) + +/** + * @brief Available ports on the STM32F3 family + */ +enum { + PORT_A = 0, /**< port A */ + PORT_B = 1, /**< port B */ + PORT_C = 2, /**< port C */ + PORT_D = 3, /**< port D */ + PORT_E = 4, /**< port E */ + PORT_F = 5, /**< port F */ +}; + +/** + * @brief Available MUX values for configuring a pin's alternate function + * + * For some reason AF13 is not used on this CPU. + */ +typedef enum { + GPIO_AF0 = 0, /**< use alternate function 0 */ + GPIO_AF1, /**< use alternate function 1 */ + GPIO_AF2, /**< use alternate function 2 */ + GPIO_AF3, /**< use alternate function 3 */ + GPIO_AF4, /**< use alternate function 4 */ + GPIO_AF5, /**< use alternate function 5 */ + GPIO_AF6, /**< use alternate function 6 */ + GPIO_AF7, /**< use alternate function 7 */ + GPIO_AF8, /**< use alternate function 8 */ + GPIO_AF9, /**< use alternate function 9 */ + GPIO_AF10, /**< use alternate function 10 */ + GPIO_AF11, /**< use alternate function 11 */ + GPIO_AF12, /**< use alternate function 12 */ + GPIO_AF14, /**< use alternate function 14 */ + GPIO_AF15 /**< use alternate function 14 */ +} gpio_af_t; + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CPU_H_ */ +/** @} */ diff --git a/cpu/stm32f3/periph/gpio.c b/cpu/stm32f3/periph/gpio.c index 65614884597e..d1a0f281f02c 100644 --- a/cpu/stm32f3/periph/gpio.c +++ b/cpu/stm32f3/periph/gpio.c @@ -24,845 +24,200 @@ #include "periph/gpio.h" #include "periph_conf.h" -/* guard file in case no GPIO device is defined */ -#if GPIO_NUMOF +#define ENABLE_DEBUG (1) +#include "debug.h" +/** + * @brief The STM32F3 has 16 EXTI channels + */ +#define EXTI_NUMOF (16U) + +/** + * @brief Datastructure to hold an interrupt context + */ typedef struct { gpio_cb_t cb; /**< callback called from GPIO interrupt */ void *arg; /**< argument passed to the callback */ } gpio_state_t; -static inline void irq_handler(gpio_t dev); - -static gpio_state_t gpio_config[GPIO_NUMOF]; +/** + * @brief Hold one callback function pointer for each interrupt line + */ +static gpio_state_t exti_chan[EXTI_NUMOF]; -int gpio_init_out(gpio_t dev, gpio_pp_t pushpull) +/** + * @brief Extract the port base address from the given pin identifier + */ +static inline GPIO_TypeDef *_port(gpio_t pin) { - GPIO_TypeDef *port = 0; - uint32_t pin = 0; - - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - GPIO_0_CLKEN(); - port = GPIO_0_PORT; - pin = GPIO_0_PIN; - break; -#endif -#if GPIO_1_EN - case GPIO_1: - GPIO_1_CLKEN(); - port = GPIO_1_PORT; - pin = GPIO_1_PIN; - break; -#endif -#if GPIO_2_EN - case GPIO_2: - GPIO_2_CLKEN(); - port = GPIO_2_PORT; - pin = GPIO_2_PIN; - break; -#endif -#if GPIO_3_EN - case GPIO_3: - GPIO_3_CLKEN(); - port = GPIO_3_PORT; - pin = GPIO_3_PIN; - break; -#endif -#if GPIO_4_EN - case GPIO_4: - GPIO_4_CLKEN(); - port = GPIO_4_PORT; - pin = GPIO_4_PIN; - break; -#endif -#if GPIO_5_EN - case GPIO_5: - GPIO_5_CLKEN(); - port = GPIO_5_PORT; - pin = GPIO_5_PIN; - break; -#endif -#if GPIO_6_EN - case GPIO_6: - GPIO_6_CLKEN(); - port = GPIO_6_PORT; - pin = GPIO_6_PIN; - break; -#endif -#if GPIO_7_EN - case GPIO_7: - GPIO_7_CLKEN(); - port = GPIO_7_PORT; - pin = GPIO_7_PIN; - break; -#endif -#if GPIO_8_EN - case GPIO_8: - GPIO_8_CLKEN(); - port = GPIO_8_PORT; - pin = GPIO_8_PIN; - break; -#endif -#if GPIO_9_EN - case GPIO_9: - GPIO_9_CLKEN(); - port = GPIO_9_PORT; - pin = GPIO_9_PIN; - break; -#endif -#if GPIO_10_EN - case GPIO_10: - GPIO_10_CLKEN(); - port = GPIO_10_PORT; - pin = GPIO_10_PIN; - break; -#endif -#if GPIO_11_EN - case GPIO_11: - GPIO_11_CLKEN(); - port = GPIO_11_PORT; - pin = GPIO_11_PIN; - break; -#endif - default: - return -1; - } - - port->MODER &= ~(2 << (2 * pin)); /* set pin to output mode */ - port->MODER |= (1 << (2 * pin)); - port->OTYPER &= ~(1 << pin); /* set to push-pull configuration */ - port->OSPEEDR |= (3 << (2 * pin)); /* set to high speed */ - port->PUPDR &= ~(3 << (2 * pin)); /* configure push-pull resistors */ - port->PUPDR |= (pushpull << (2 * pin)); - port->ODR &= ~(1 << pin); /* set pin to low signal */ + return (GPIO_TypeDef *)(pin & ~(0x0f)); +} - return 0; /* all OK */ +/** + * @brief Extract the port number form the given identifier + * + * The port number is extracted by looking at bits 10, 11, 12, 13 of the base + * register addresses. + */ +static inline int _port_num(gpio_t pin) +{ + return ((pin >> 10) & 0x0f); } -int gpio_init_in(gpio_t dev, gpio_pp_t pushpull) +/** + * @brief Extract the pin number from the last 4 bit of the pin identifier + */ +static inline int _pin_num(gpio_t pin) { - GPIO_TypeDef *port = 0; - uint32_t pin = 0; + return (pin & 0x0f); +} - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - GPIO_0_CLKEN(); - port = GPIO_0_PORT; - pin = GPIO_0_PIN; - break; -#endif -#if GPIO_1_EN - case GPIO_1: - GPIO_1_CLKEN(); - port = GPIO_1_PORT; - pin = GPIO_1_PIN; - break; -#endif -#if GPIO_2_EN - case GPIO_2: - GPIO_2_CLKEN(); - port = GPIO_2_PORT; - pin = GPIO_2_PIN; - break; -#endif -#if GPIO_3_EN - case GPIO_3: - GPIO_3_CLKEN(); - port = GPIO_3_PORT; - pin = GPIO_3_PIN; - break; -#endif -#if GPIO_4_EN - case GPIO_4: - GPIO_4_CLKEN(); - port = GPIO_4_PORT; - pin = GPIO_4_PIN; - break; -#endif -#if GPIO_5_EN - case GPIO_5: - GPIO_5_CLKEN(); - port = GPIO_5_PORT; - pin = GPIO_5_PIN; - break; -#endif -#if GPIO_6_EN - case GPIO_6: - GPIO_6_CLKEN(); - port = GPIO_6_PORT; - pin = GPIO_6_PIN; - break; -#endif -#if GPIO_7_EN - case GPIO_7: - GPIO_7_CLKEN(); - port = GPIO_7_PORT; - pin = GPIO_7_PIN; - break; -#endif -#if GPIO_8_EN - case GPIO_8: - GPIO_8_CLKEN(); - port = GPIO_8_PORT; - pin = GPIO_8_PIN; - break; -#endif -#if GPIO_9_EN - case GPIO_9: - GPIO_9_CLKEN(); - port = GPIO_9_PORT; - pin = GPIO_9_PIN; - break; -#endif -#if GPIO_10_EN - case GPIO_10: - GPIO_10_CLKEN(); - port = GPIO_10_PORT; - pin = GPIO_10_PIN; - break; -#endif -#if GPIO_11_EN - case GPIO_11: - GPIO_11_CLKEN(); - port = GPIO_11_PORT; - pin = GPIO_11_PIN; - break; -#endif - default: - return -1; - } +int gpio_init(gpio_t pin, gpio_dir_t dir, gpio_pp_t pushpull) +{ + GPIO_TypeDef *port = _port(pin); + int pin_num = _pin_num(pin); - port->MODER &= ~(3 << (2 * pin)); /* configure pin as input */ - port->PUPDR &= ~(3 << (2 * pin)); /* configure push-pull resistors */ - port->PUPDR |= (pushpull << (2 * pin)); + DEBUG("Init %i: port %i, pin %i\n", dir, pin_num, _port_num(pin)); - return 0; /* everything alright here */ + /* enable clock */ + RCC->AHBENR |= (RCC_AHBENR_GPIOAEN << _port_num(pin)); + /* configure pull register */ + port->PUPDR &= ~(3 << (2 * pin_num)); + port->PUPDR |= (pushpull << (2 * pin_num)); + /* set direction */ + if (dir == GPIO_DIR_OUT) { + port->MODER &= ~(3 << (2 * pin_num)); /* set pin to output mode */ + port->MODER |= (1 << (2 * pin_num)); + port->OTYPER &= ~(1 << pin_num); /* set to push-pull */ + port->OSPEEDR |= (3 << (2 * pin_num)); /* set to high speed */ + port->ODR &= ~(1 << pin_num); /* set pin to low signal */ + } + else { + port->MODER &= ~(3 << (2 * pin_num)); /* configure pin as input */ + } + return 0; } -int gpio_init_int(gpio_t dev, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb, void *arg) +int gpio_init_int(gpio_t pin, gpio_pp_t pullup, gpio_flank_t flank, + gpio_cb_t cb, void *arg) { - uint32_t pin = 0; - - int res = gpio_init_in(dev, pullup); - if (res < 0) { - return res; - } + int pin_num = _pin_num(pin); + int port_num = _port_num(pin); + /* configure and save exti configuration struct */ + exti_chan[pin_num].cb = cb; + exti_chan[pin_num].arg = arg; /* enable the SYSCFG clock */ RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; - - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - pin = GPIO_0_PIN; - GPIO_0_EXTI_CFG1(); - GPIO_0_EXTI_CFG2(); - NVIC_SetPriority(GPIO_0_IRQ, GPIO_IRQ_PRIO); - NVIC_EnableIRQ(GPIO_0_IRQ); - break; -#endif -#if GPIO_1_EN - case GPIO_1: - pin = GPIO_1_PIN; - GPIO_1_EXTI_CFG1(); - GPIO_1_EXTI_CFG2(); - NVIC_SetPriority(GPIO_1_IRQ, GPIO_IRQ_PRIO); - NVIC_EnableIRQ(GPIO_1_IRQ); - break; -#endif -#if GPIO_2_EN - case GPIO_2: - pin = GPIO_2_PIN; - GPIO_2_EXTI_CFG1(); - GPIO_2_EXTI_CFG2(); - NVIC_SetPriority(GPIO_2_IRQ, GPIO_IRQ_PRIO); - NVIC_EnableIRQ(GPIO_2_IRQ); - break; -#endif -#if GPIO_3_EN - case GPIO_3: - pin = GPIO_3_PIN; - GPIO_3_EXTI_CFG1(); - GPIO_3_EXTI_CFG2(); - NVIC_SetPriority(GPIO_3_IRQ, GPIO_IRQ_PRIO); - NVIC_EnableIRQ(GPIO_3_IRQ); - break; -#endif -#if GPIO_4_EN - case GPIO_4: - pin = GPIO_4_PIN; - GPIO_4_EXTI_CFG1(); - GPIO_4_EXTI_CFG2(); - NVIC_SetPriority(GPIO_4_IRQ, GPIO_IRQ_PRIO); - NVIC_EnableIRQ(GPIO_4_IRQ); - break; -#endif -#if GPIO_5_EN - case GPIO_5: - pin = GPIO_5_PIN; - GPIO_5_EXTI_CFG1(); - GPIO_5_EXTI_CFG2(); - NVIC_SetPriority(GPIO_5_IRQ, GPIO_IRQ_PRIO); - NVIC_EnableIRQ(GPIO_5_IRQ); - break; -#endif -#if GPIO_6_EN - case GPIO_6: - pin = GPIO_6_PIN; - GPIO_6_EXTI_CFG1(); - GPIO_6_EXTI_CFG2(); - NVIC_SetPriority(GPIO_6_IRQ, GPIO_IRQ_PRIO); - NVIC_EnableIRQ(GPIO_6_IRQ); - break; -#endif -#if GPIO_7_EN - case GPIO_7: - pin = GPIO_7_PIN; - GPIO_7_EXTI_CFG1(); - GPIO_7_EXTI_CFG2(); - NVIC_SetPriority(GPIO_7_IRQ, GPIO_IRQ_PRIO); - NVIC_EnableIRQ(GPIO_7_IRQ); - break; -#endif -#if GPIO_8_EN - case GPIO_8: - pin = GPIO_8_PIN; - GPIO_8_EXTI_CFG1(); - GPIO_8_EXTI_CFG2(); - NVIC_SetPriority(GPIO_8_IRQ, GPIO_IRQ_PRIO); - NVIC_EnableIRQ(GPIO_8_IRQ); - break; -#endif -#if GPIO_9_EN - case GPIO_9: - pin = GPIO_9_PIN; - GPIO_9_EXTI_CFG1(); - GPIO_9_EXTI_CFG2(); - NVIC_SetPriority(GPIO_9_IRQ, GPIO_IRQ_PRIO); - NVIC_EnableIRQ(GPIO_9_IRQ); - break; -#endif -#if GPIO_10_EN - case GPIO_10: - pin = GPIO_10_PIN; - GPIO_10_EXTI_CFG1(); - GPIO_10_EXTI_CFG2(); - NVIC_SetPriority(GPIO_10_IRQ, GPIO_IRQ_PRIO); - NVIC_EnableIRQ(GPIO_10_IRQ); - break; -#endif -#if GPIO_11_EN - case GPIO_11: - pin = GPIO_11_PIN; - GPIO_11_EXTI_CFG1(); - GPIO_11_EXTI_CFG2(); - NVIC_SetPriority(GPIO_11_IRQ, GPIO_IRQ_PRIO); - NVIC_EnableIRQ(GPIO_11_IRQ); - break; -#endif + /* configure pin as input */ + gpio_init(pin, GPIO_DIR_IN, pullup); + /* enable global pin interrupt */ + if (pin_num < 5) { + NVIC_EnableIRQ(EXTI0_IRQn + pin_num); } - - /* set callback */ - gpio_config[dev].cb = cb; - gpio_config[dev].arg = arg; - - /* configure the active edges */ + else if (pin_num < 10) { + NVIC_EnableIRQ(EXTI9_5_IRQn); + } + else { + NVIC_EnableIRQ(EXTI15_10_IRQn); + } + /* configure the active edge(s) */ switch (flank) { case GPIO_RISING: - EXTI->RTSR |= (1 << pin); + EXTI->RTSR |= (1 << pin_num); + EXTI->FTSR &= ~(1 << pin_num); break; case GPIO_FALLING: - EXTI->FTSR |= (1 << pin); + EXTI->RTSR &= ~(1 << pin_num); + EXTI->FTSR |= (1 << pin_num); break; case GPIO_BOTH: - EXTI->RTSR |= (1 << pin); - EXTI->FTSR |= (1 << pin); + EXTI->RTSR |= (1 << pin_num); + EXTI->FTSR |= (1 << pin_num); break; } - + /* enable specific pin as exti sources */ + SYSCFG->EXTICR[pin_num >> 2] &= ~(0xf << ((pin_num & 0x03) * 4)); + SYSCFG->EXTICR[pin_num >> 2] |= (port_num << ((pin_num & 0x03) * 4)); /* clear any pending requests */ - EXTI->PR = (1 << pin); + EXTI->PR = (1 << pin_num); /* enable interrupt for EXTI line */ - EXTI->IMR |= (1 << pin); - + EXTI->IMR |= (1 << pin_num); return 0; } -void gpio_irq_enable(gpio_t dev) -{ - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - EXTI->IMR |= (1 << GPIO_0_PIN); - break; -#endif -#if GPIO_1_EN - case GPIO_1: - EXTI->IMR |= (1 << GPIO_1_PIN); - break; -#endif -#if GPIO_2_EN - case GPIO_2: - EXTI->IMR |= (1 << GPIO_2_PIN); - break; -#endif -#if GPIO_3_EN - case GPIO_3: - EXTI->IMR |= (1 << GPIO_3_PIN); - break; -#endif -#if GPIO_4_EN - case GPIO_4: - EXTI->IMR |= (1 << GPIO_4_PIN); - break; -#endif -#if GPIO_5_EN - case GPIO_5: - EXTI->IMR |= (1 << GPIO_5_PIN); - break; -#endif -#if GPIO_6_EN - case GPIO_6: - EXTI->IMR |= (1 << GPIO_6_PIN); - break; -#endif -#if GPIO_7_EN - case GPIO_7: - EXTI->IMR |= (1 << GPIO_7_PIN); - break; -#endif -#if GPIO_8_EN - case GPIO_8: - EXTI->IMR |= (1 << GPIO_8_PIN); - break; -#endif -#if GPIO_9_EN - case GPIO_9: - EXTI->IMR |= (1 << GPIO_9_PIN); - break; -#endif -#if GPIO_10_EN - case GPIO_10: - EXTI->IMR |= (1 << GPIO_10_PIN); - break; -#endif -#if GPIO_11_EN - case GPIO_11: - EXTI->IMR |= (1 << GPIO_11_PIN); - break; -#endif - } -} - -void gpio_irq_disable(gpio_t dev) -{ - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - EXTI->IMR &= ~(1 << GPIO_0_PIN); - break; -#endif -#if GPIO_1_EN - case GPIO_1: - EXTI->IMR &= ~(1 << GPIO_1_PIN); - break; -#endif -#if GPIO_2_EN - case GPIO_2: - EXTI->IMR &= ~(1 << GPIO_2_PIN); - break; -#endif -#if GPIO_3_EN - case GPIO_3: - EXTI->IMR &= ~(1 << GPIO_3_PIN); - break; -#endif -#if GPIO_4_EN - case GPIO_4: - EXTI->IMR &= ~(1 << GPIO_4_PIN); - break; -#endif -#if GPIO_5_EN - case GPIO_5: - EXTI->IMR &= ~(1 << GPIO_5_PIN); - break; -#endif -#if GPIO_6_EN - case GPIO_6: - EXTI->IMR &= ~(1 << GPIO_6_PIN); - break; -#endif -#if GPIO_7_EN - case GPIO_7: - EXTI->IMR &= ~(1 << GPIO_7_PIN); - break; -#endif -#if GPIO_8_EN - case GPIO_8: - EXTI->IMR &= ~(1 << GPIO_8_PIN); - break; -#endif -#if GPIO_9_EN - case GPIO_9: - EXTI->IMR &= ~(1 << GPIO_9_PIN); - break; -#endif -#if GPIO_10_EN - case GPIO_10: - EXTI->IMR &= ~(1 << GPIO_10_PIN); - break; -#endif -#if GPIO_11_EN - case GPIO_11: - EXTI->IMR &= ~(1 << GPIO_11_PIN); - break; -#endif - } -} - -int gpio_read(gpio_t dev) -{ - GPIO_TypeDef *port = 0; - uint32_t pin = 0; - - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - port = GPIO_0_PORT; - pin = GPIO_0_PIN; - break; -#endif -#if GPIO_1_EN - case GPIO_1: - port = GPIO_1_PORT; - pin = GPIO_1_PIN; - break; -#endif -#if GPIO_2_EN - case GPIO_2: - port = GPIO_2_PORT; - pin = GPIO_2_PIN; - break; -#endif -#if GPIO_3_EN - case GPIO_3: - port = GPIO_3_PORT; - pin = GPIO_3_PIN; - break; -#endif -#if GPIO_4_EN - case GPIO_4: - port = GPIO_4_PORT; - pin = GPIO_4_PIN; - break; -#endif -#if GPIO_5_EN - case GPIO_5: - port = GPIO_5_PORT; - pin = GPIO_5_PIN; - break; -#endif -#if GPIO_6_EN - case GPIO_6: - port = GPIO_6_PORT; - pin = GPIO_6_PIN; - break; -#endif -#if GPIO_7_EN - case GPIO_7: - port = GPIO_7_PORT; - pin = GPIO_7_PIN; - break; -#endif -#if GPIO_8_EN - case GPIO_8: - port = GPIO_8_PORT; - pin = GPIO_8_PIN; - break; -#endif -#if GPIO_9_EN - case GPIO_9: - port = GPIO_9_PORT; - pin = GPIO_9_PIN; - break; -#endif -#if GPIO_10_EN - case GPIO_10: - port = GPIO_10_PORT; - pin = GPIO_10_PIN; - break; -#endif -#if GPIO_11_EN - case GPIO_11: - port = GPIO_11_PORT; - pin = GPIO_11_PIN; - break; -#endif - default: - return -1; - } - - if (port->MODER & (3 << (pin * 2))) { /* if configured as output */ - return port->ODR & (1 << pin); /* read output data register */ - } - else { - return port->IDR & (1 << pin); /* else read input data register */ - } -} - -void gpio_set(gpio_t dev) -{ - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - GPIO_0_PORT->BSRRL = (1 << GPIO_0_PIN); - break; -#endif -#if GPIO_1_EN - case GPIO_1: - GPIO_1_PORT->BSRRL = (1 << GPIO_1_PIN); - break; -#endif -#if GPIO_2_EN - case GPIO_2: - GPIO_2_PORT->BSRRL = (1 << GPIO_2_PIN); - break; -#endif -#if GPIO_3_EN - case GPIO_3: - GPIO_3_PORT->BSRRL = (1 << GPIO_3_PIN); - break; -#endif -#if GPIO_4_EN - case GPIO_4: - GPIO_4_PORT->BSRRL = (1 << GPIO_4_PIN); - break; -#endif -#if GPIO_5_EN - case GPIO_5: - GPIO_5_PORT->BSRRL = (1 << GPIO_5_PIN); - break; -#endif -#if GPIO_6_EN - case GPIO_6: - GPIO_6_PORT->BSRRL = (1 << GPIO_6_PIN); - break; -#endif -#if GPIO_7_EN - case GPIO_7: - GPIO_7_PORT->BSRRL = (1 << GPIO_7_PIN); - break; -#endif -#if GPIO_8_EN - case GPIO_8: - GPIO_8_PORT->BSRRL = (1 << GPIO_8_PIN); - break; -#endif -#if GPIO_9_EN - case GPIO_9: - GPIO_9_PORT->BSRRL = (1 << GPIO_9_PIN); - break; -#endif -#if GPIO_10_EN - case GPIO_10: - GPIO_10_PORT->BSRRL = (1 << GPIO_10_PIN); - break; -#endif -#if GPIO_11_EN - case GPIO_11: - GPIO_11_PORT->BSRRL = (1 << GPIO_11_PIN); - break; -#endif - } -} - -void gpio_clear(gpio_t dev) +void gpio_init_af(gpio_t pin, gpio_af_t af) { - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - GPIO_0_PORT->BSRRH = (1 << GPIO_0_PIN); - break; -#endif -#if GPIO_1_EN - case GPIO_1: - GPIO_1_PORT->BSRRH = (1 << GPIO_1_PIN); - break; -#endif -#if GPIO_2_EN - case GPIO_2: - GPIO_2_PORT->BSRRH = (1 << GPIO_2_PIN); - break; -#endif -#if GPIO_3_EN - case GPIO_3: - GPIO_3_PORT->BSRRH = (1 << GPIO_3_PIN); - break; -#endif -#if GPIO_4_EN - case GPIO_4: - GPIO_4_PORT->BSRRH = (1 << GPIO_4_PIN); - break; -#endif -#if GPIO_5_EN - case GPIO_5: - GPIO_5_PORT->BSRRH = (1 << GPIO_5_PIN); - break; -#endif -#if GPIO_6_EN - case GPIO_6: - GPIO_6_PORT->BSRRH = (1 << GPIO_6_PIN); - break; -#endif -#if GPIO_7_EN - case GPIO_7: - GPIO_7_PORT->BSRRH = (1 << GPIO_7_PIN); - break; -#endif -#if GPIO_8_EN - case GPIO_8: - GPIO_8_PORT->BSRRH = (1 << GPIO_8_PIN); - break; -#endif -#if GPIO_9_EN - case GPIO_9: - GPIO_9_PORT->BSRRH = (1 << GPIO_9_PIN); - break; -#endif -#if GPIO_10_EN - case GPIO_10: - GPIO_10_PORT->BSRRH = (1 << GPIO_10_PIN); - break; -#endif -#if GPIO_11_EN - case GPIO_11: - GPIO_11_PORT->BSRRH = (1 << GPIO_11_PIN); - break; -#endif - } -} + GPIO_TypeDef *port = _port(pin); + uint32_t pin_num = _pin_num(pin); -void gpio_toggle(gpio_t dev) -{ - if (gpio_read(dev)) { - gpio_clear(dev); - } - else { - gpio_set(dev); - } + /* set pin to AF mode */ + port->MODER &= ~(3 << (2 * pin_num)); + port->MODER |= (2 << (2 * pin_num)); + /* set selected function */ + port->AFR[pin_num & 0x10] &= ~(0xf << ((pin_num & 0x0f) * 4)); + port->AFR[pin_num & 0x10] |= (af << ((pin_num & 0x0f) * 4)); } -void gpio_write(gpio_t dev, int value) +void gpio_irq_enable(gpio_t pin) { - if (value) { - gpio_set(dev); - } - else { - gpio_clear(dev); - } + EXTI->IMR |= (1 << _pin_num(pin)); } -static inline void irq_handler(gpio_t dev) +void gpio_irq_disable(gpio_t pin) { - gpio_config[dev].cb(gpio_config[dev].arg); - if (sched_context_switch_request) { - thread_yield(); - } + EXTI->IMR &= ~(1 << _pin_num(pin)); } -void isr_exti0(void) +int gpio_read(gpio_t pin) { - if (EXTI->PR & EXTI_PR_PR0) { - EXTI->PR |= EXTI_PR_PR0; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_0); - } -} + GPIO_TypeDef *port = _port(pin); + uint32_t pin_num = _pin_num(pin); -void isr_exti1(void) -{ - if (EXTI->PR & EXTI_PR_PR1) { - EXTI->PR |= EXTI_PR_PR1; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_1); + if (port->MODER & (3 << (pin_num * 2))) { /* if configured as output */ + return port->ODR & (1 << pin_num); /* read output data reg */ + } else { + return port->IDR & (1 << pin_num); /* else read input data reg */ } } -void isr_exti2_tsc(void) +void gpio_set(gpio_t pin) { - if (EXTI->PR & EXTI_PR_PR2) { - EXTI->PR |= EXTI_PR_PR2; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_2); - } + _port(pin)->BSRRL = (1 << _pin_num(pin)); } -void isr_exti3(void) +void gpio_clear(gpio_t pin) { - if (EXTI->PR & EXTI_PR_PR3) { - EXTI->PR |= EXTI_PR_PR3; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_3); - } + _port(pin)->BSRRH = (1 << _pin_num(pin)); } -void isr_exti4(void) +void gpio_toggle(gpio_t pin) { - if (EXTI->PR & EXTI_PR_PR4) { - EXTI->PR |= EXTI_PR_PR4; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_4); + if (gpio_read(pin)) { + gpio_clear(pin); + } else { + gpio_set(pin); } } -void isr_exti9_5(void) +void gpio_write(gpio_t pin, int value) { - if (EXTI->PR & EXTI_PR_PR5) { - EXTI->PR |= EXTI_PR_PR5; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_5); - } - else if (EXTI->PR & EXTI_PR_PR6) { - EXTI->PR |= EXTI_PR_PR6; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_6); - } - else if (EXTI->PR & EXTI_PR_PR7) { - EXTI->PR |= EXTI_PR_PR7; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_7); - } - else if (EXTI->PR & EXTI_PR_PR8) { - EXTI->PR |= EXTI_PR_PR8; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_8); - } - else if (EXTI->PR & EXTI_PR_PR9) { - EXTI->PR |= EXTI_PR_PR9; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_9); + if (value) { + gpio_set(pin); + } else { + gpio_clear(pin); } } -void isr_exti15_10(void) +void isr_exti(void) { - if (EXTI->PR & EXTI_PR_PR10) { - EXTI->PR |= EXTI_PR_PR10; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_10); - } - else if (EXTI->PR & EXTI_PR_PR11) { - EXTI->PR |= EXTI_PR_PR11; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_11); - } - else if (EXTI->PR & EXTI_PR_PR12) { - EXTI->PR |= EXTI_PR_PR12; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_12); + for (int i = 0; i < EXTI_NUMOF; i++) { + if (EXTI->PR & (1 << i)) { + EXTI->PR |= (1 << i); /* clear by writing a 1 */ + exti_chan[i].cb(exti_chan[i].arg); + } } - else if (EXTI->PR & EXTI_PR_PR13) { - EXTI->PR |= EXTI_PR_PR13; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_13); - } - else if (EXTI->PR & EXTI_PR_PR14) { - EXTI->PR |= EXTI_PR_PR14; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_14); - } - else if (EXTI->PR & EXTI_PR_PR15) { - EXTI->PR |= EXTI_PR_PR15; /* clear status bit by writing a 1 to it */ - irq_handler(GPIO_IRQ_15); + if (sched_context_switch_request) { + thread_yield(); } } - -#endif /* GPIO_NUMOF */ diff --git a/cpu/stm32f3/startup.c b/cpu/stm32f3/startup.c index ccd36a7d2022..aec1ae6c9a99 100644 --- a/cpu/stm32f3/startup.c +++ b/cpu/stm32f3/startup.c @@ -123,11 +123,7 @@ void isr_tamp_stamp(void) __attribute__ ((weak, alias("dummy_handler" void isr_rtc_wkup(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_flash(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_rcc(void) __attribute__ ((weak, alias("dummy_handler"))); -void isr_exti0(void) __attribute__ ((weak, alias("dummy_handler"))); -void isr_exti1(void) __attribute__ ((weak, alias("dummy_handler"))); -void isr_exti2_tsc(void) __attribute__ ((weak, alias("dummy_handler"))); -void isr_exti3(void) __attribute__ ((weak, alias("dummy_handler"))); -void isr_exti4(void) __attribute__ ((weak, alias("dummy_handler"))); +void isr_exti(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_dma1_channel1(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_dma1_channel2(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_dma1_channel3(void) __attribute__ ((weak, alias("dummy_handler"))); @@ -140,7 +136,6 @@ void isr_usb_hp_can_tx(void) __attribute__ ((weak, alias("dummy_handl void isr_usb_lp_can_rx0(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_can_rx1(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_can_sce(void) __attribute__ ((weak, alias("dummy_handler"))); -void isr_exti9_5(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_tim1_brk_tim15(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_tim1_up_tim16(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_tim1_trg_com_tim17(void) __attribute__ ((weak, alias("dummy_handler"))); @@ -157,7 +152,6 @@ void isr_spi2(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_usart1(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_usart2(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_usart3(void) __attribute__ ((weak, alias("dummy_handler"))); -void isr_exti15_10(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_rtc_alarm(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_usbwakeup(void) __attribute__ ((weak, alias("dummy_handler"))); void isr_tim8_brk(void) __attribute__ ((weak, alias("dummy_handler"))); @@ -213,11 +207,11 @@ const void *interrupt_vector[] = { (void*) isr_rtc_wkup, /* */ (void*) isr_flash, /* */ (void*) isr_rcc, /* */ - (void*) isr_exti0, /* */ - (void*) isr_exti1, /* */ - (void*) isr_exti2_tsc, /* */ - (void*) isr_exti3, /* */ - (void*) isr_exti4, /* */ + (void*) isr_exti, /* */ + (void*) isr_exti, /* */ + (void*) isr_exti, /* */ + (void*) isr_exti, /* */ + (void*) isr_exti, /* */ (void*) isr_dma1_channel1, /* */ (void*) isr_dma1_channel2, /* */ (void*) isr_dma1_channel3, /* */ @@ -230,7 +224,7 @@ const void *interrupt_vector[] = { (void*) isr_usb_lp_can_rx0, /* */ (void*) isr_can_rx1, /* */ (void*) isr_can_sce, /* */ - (void*) isr_exti9_5, /* */ + (void*) isr_exti, /* */ (void*) isr_tim1_brk_tim15, /* */ (void*) isr_tim1_up_tim16, /* */ (void*) isr_tim1_trg_com_tim17, /* */ @@ -247,7 +241,7 @@ const void *interrupt_vector[] = { (void*) isr_usart1, /* */ (void*) isr_usart2, /* */ (void*) isr_usart3, /* */ - (void*) isr_exti15_10, /* */ + (void*) isr_exti, /* */ (void*) isr_rtc_alarm, /* */ (void*) isr_usbwakeup, /* */ (void*) isr_tim8_brk, /* */ From aeecb098834372f6a2646bb64f205103e93c8034 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 3 Jun 2015 18:22:24 +0200 Subject: [PATCH 09/33] cpu/saml21: remodeld GPIO driver implementation --- cpu/saml21/include/periph_cpu.h | 89 +++++++ cpu/saml21/include/saml21_periph.h | 46 ---- cpu/saml21/periph/gpio.c | 405 +++++++++-------------------- cpu/saml21/periph/spi.c | 16 +- 4 files changed, 213 insertions(+), 343 deletions(-) create mode 100644 cpu/saml21/include/periph_cpu.h diff --git a/cpu/saml21/include/periph_cpu.h b/cpu/saml21/include/periph_cpu.h new file mode 100644 index 000000000000..309a699359ae --- /dev/null +++ b/cpu/saml21/include/periph_cpu.h @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup cpu_saml21 + * @{ + * + * @file + * @brief CPU specific definitions for internal peripheral handling + * + * @author Hauke Petersen + */ + +#ifndef PERIPH_CPU_H_ +#define PERIPH_CPU_H_ + +#include "cpu.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Define mandatory GPIO types for NRF51822 CPUs + * @{ + */ +#define HAVE_GPIO_T +typedef uint32_t gpio_t; +/** @} */ + +/** + * @brief Mandatory function for defining a GPIO pins + * @{ + */ +#define GPIO(x, y) (((gpio_t)(&PORT->Group[x])) | y) + +/** + * @brief Available ports on the SAML21 for convenient access + */ +enum { + PA = 0, /**< port A */ + PB = 1, /**< port B */ +}; + +/** + * @brief Override active flank configuration values + * @{ + */ +#define HAVE_GPIO_FLANK_T +typedef enum { + GPIO_FALLING = 2, /**< emit interrupt on falling flank */ + GPIO_RISING = 1, /**< emit interrupt on rising flank */ + GPIO_BOTH = 3 /**< emit interrupt on both flanks */ +} gpio_flank_t; +/** @} */ + +/** + * @brief Available MUX values for configuring a pin's alternate function + */ +typedef enum { + GPIO_MUX_A = 0x0, /**< select peripheral function A */ + GPIO_MUX_B = 0x1, /**< select peripheral function B */ + GPIO_MUX_C = 0x2, /**< select peripheral function C */ + GPIO_MUX_D = 0x3, /**< select peripheral function D */ + GPIO_MUX_E = 0x4, /**< select peripheral function E */ + GPIO_MUX_F = 0x5, /**< select peripheral function F */ + GPIO_MUX_G = 0x6, /**< select peripheral function G */ + GPIO_MUX_H = 0x7, /**< select peripheral function H */ +} gpio_mux_t; + +/** + * @brief Set up alternate function (PMUX setting) for a PORT pin + * + * @param[in] dev Pin to set the multiplexing for + * @param[in] mux Mux value + */ +void gpio_init_mux(gpio_t dev, gpio_mux_t mux); + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CPU_H_ */ +/** @} */ diff --git a/cpu/saml21/include/saml21_periph.h b/cpu/saml21/include/saml21_periph.h index 6a4593a2d728..fae207f99b4f 100644 --- a/cpu/saml21/include/saml21_periph.h +++ b/cpu/saml21/include/saml21_periph.h @@ -27,52 +27,6 @@ extern "C" { #include "cpu_conf.h" #include "panic.h" -/** - * @brief gpio dev to gpio id mapping table (used internally by implementation) - */ -extern const uint8_t gpio_table[]; - -/** - * @brief return PORT ptr for GPIO pin - * - * @param[in] dev GPIO dev to get PORT for - * - * @returns pointer to PORT instance - */ -static inline PortGroup* _port(gpio_t dev) -{ - /* Config validity check. See saml21 periph_conf.h. - * This gets optimized out if the configuration is correct. - * I put it here so it crashes the board on first GPIO use. */ - if (GPIO_NUMOF != GPIO_UNUSED) { - core_panic(0, "unmatched GPIO_NUMOF and GPIO_UNUSED. Fix periph_conf.\n"); - } - return &PORT->Group[gpio_table[dev]/32]; -} - -/** - * @brief return pin nr for gpio dev - * - * E.g., PA02 -> 2, PC19 -> 19 - * - * @param[in] dev GPIO dev to get pin nr from - * @returns pin nr of GPIO dev - */ -static inline uint32_t _pin(gpio_t dev) -{ - return gpio_table[dev] % 32; -} - -/** - * @brief Set up alternate function (PMUX setting) for a PORT pin - * - * @param[in] dev The Port ID to work on (port*32 + pin) - * @param[in] mux required PMUX setting (Mapping A = 0, B=1, ...) - * - * @returns 0 on success, <0 on error - */ -int gpio_init_mux(gpio_t dev, uint32_t mux); - #ifdef __cplusplus } #endif diff --git a/cpu/saml21/periph/gpio.c b/cpu/saml21/periph/gpio.c index 3fad5262f6b5..1d5130c74b96 100644 --- a/cpu/saml21/periph/gpio.c +++ b/cpu/saml21/periph/gpio.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Freie Universität Berlin + * Copyright (C) 2014-2015 Freie Universität Berlin * 2015 Kaspar Schleiser * 2015 FreshTemp, LLC. * @@ -18,6 +18,7 @@ * @author Troels Hoffmeyer * @author Thomas Eichinger * @author Kaspar Schleiser + * @author Hauke Petersen * * @} */ @@ -32,366 +33,196 @@ #include "thread.h" #include "panic.h" -#define ENABLE_DEBUG (1) +#define ENABLE_DEBUG (0) #include "debug.h" -/* guard file in case no GPIO devices are defined */ -#if GPIO_NUMOF - -typedef struct { - gpio_cb_t cb; /**< callback called from GPIO interrupt */ - void *arg; /**< argument passed to the callback */ -} gpio_state_t; - /** - * Shitloads of macros just to make sure we don't have to allocate - * more than the actually enabled amount of exti states. - * The result is an array with the amount of enabled EXIT lines times gpio_state_t, - * and an array mapping any EXTI nr to either a unique slot or -1. - * - * Example: only GPIO_EXTI3_EN and GPIO_EXTI7_EN are set. - * GPIO_EXTI_TOTAL will be "2" - * gpio_config will be 2*sizeof(gpio_state_t) - * gpio_exti_map will have the following content: - * - * { -1, -1, -1, 0, -1, -1, -1, 1, -1 , ...} - * - * This maps EXTI3 to gpio_config[0], EXTI7 to gpio_config[1]. - * - * */ -#define GPIO_EXTI0_POS 0 -#define GPIO_EXTI1_POS GPIO_EXTI0_EN -#define GPIO_EXTI2_POS (GPIO_EXTI1_POS + GPIO_EXTI1_EN) -#define GPIO_EXTI3_POS (GPIO_EXTI2_POS + GPIO_EXTI2_EN) -#define GPIO_EXTI4_POS (GPIO_EXTI3_POS + GPIO_EXTI3_EN) -#define GPIO_EXTI5_POS (GPIO_EXTI4_POS + GPIO_EXTI4_EN) -#define GPIO_EXTI6_POS (GPIO_EXTI5_POS + GPIO_EXTI5_EN) -#define GPIO_EXTI7_POS (GPIO_EXTI6_POS + GPIO_EXTI6_EN) -#define GPIO_EXTI8_POS (GPIO_EXTI7_POS + GPIO_EXTI7_EN) -#define GPIO_EXTI9_POS (GPIO_EXTI8_POS + GPIO_EXTI8_EN) -#define GPIO_EXTI10_POS (GPIO_EXTI9_POS + GPIO_EXTI9_EN) -#define GPIO_EXTI11_POS (GPIO_EXTI10_POS + GPIO_EXTI10_EN) -#define GPIO_EXTI12_POS (GPIO_EXTI11_POS + GPIO_EXTI11_EN) -#define GPIO_EXTI13_POS (GPIO_EXTI12_POS + GPIO_EXTI12_EN) -#define GPIO_EXTI14_POS (GPIO_EXTI13_POS + GPIO_EXTI13_EN) -#define GPIO_EXTI15_POS (GPIO_EXTI14_POS + GPIO_EXTI14_EN) - -const static int8_t gpio_exti_map[] = { - GPIO_EXTI0_EN ? GPIO_EXTI0_POS : -1, - GPIO_EXTI1_EN ? GPIO_EXTI1_POS : -1, - GPIO_EXTI2_EN ? GPIO_EXTI2_POS : -1, - GPIO_EXTI3_EN ? GPIO_EXTI3_POS : -1, - GPIO_EXTI4_EN ? GPIO_EXTI4_POS : -1, - GPIO_EXTI5_EN ? GPIO_EXTI5_POS : -1, - GPIO_EXTI6_EN ? GPIO_EXTI6_POS : -1, - GPIO_EXTI7_EN ? GPIO_EXTI7_POS : -1, - GPIO_EXTI8_EN ? GPIO_EXTI8_POS : -1, - GPIO_EXTI9_EN ? GPIO_EXTI9_POS : -1, - GPIO_EXTI10_EN ? GPIO_EXTI10_POS : -1, - GPIO_EXTI11_EN ? GPIO_EXTI11_POS : -1, - GPIO_EXTI12_EN ? GPIO_EXTI12_POS : -1, - GPIO_EXTI13_EN ? GPIO_EXTI13_POS : -1, - GPIO_EXTI14_EN ? GPIO_EXTI14_POS : -1, - GPIO_EXTI15_EN ? GPIO_EXTI15_POS : -1, -}; - -#define GPIO_EXTI_TOTAL (\ - GPIO_EXTI0_EN + \ - GPIO_EXTI1_EN + \ - GPIO_EXTI2_EN + \ - GPIO_EXTI3_EN + \ - GPIO_EXTI4_EN + \ - GPIO_EXTI5_EN + \ - GPIO_EXTI6_EN + \ - GPIO_EXTI7_EN + \ - GPIO_EXTI8_EN + \ - GPIO_EXTI9_EN + \ - GPIO_EXTI10_EN + \ - GPIO_EXTI11_EN + \ - GPIO_EXTI12_EN + \ - GPIO_EXTI13_EN + \ - GPIO_EXTI14_EN + \ - GPIO_EXTI15_EN) - -static gpio_state_t gpio_config[GPIO_EXTI_TOTAL]; - -/** - * @brief Convenience enum + * @brief Number of external interrupt lines */ -enum { - PA, - PB, - PC, - PD, - PE, - PF -}; +#define NUMOF_IRQS (16U) /** - * @brief Map from 0..GPIO_NUMOF-1 to actual GPIO pins - * - * This map/macro combo is used to map natural integers - * starting by 0 upto GPIO_NUMOF-1 to the actual GPIO pin. - * - * GPIO pins are mapped into an implicit flat number space, e.g., - * Port C Pin 14 is mapped to (2*32 + 14) - * - * Pxn is supposed to be part of an enum set in "periph_conf.h". - * - * Example: - * - * enum { - * PA2, - * PB10, - * GPIO_UNUSED, - * PB5, - * PA3, - * }; - * - * All pins > GPIO_UNUSED are mapped to the same spot so - * they don't waste memory. + * @brief Mapping of pins to EXTI lines, -1 means not EXTI possible */ -#define DEFINE_GPIO_PIN(port, pin) [(port ## pin) > GPIO_UNUSED ? GPIO_UNUSED : (port ## pin)] = (port*32 + pin) -const uint8_t gpio_table[] = { - DEFINE_GPIO_PIN(PA, 2), - DEFINE_GPIO_PIN(PA, 4), - DEFINE_GPIO_PIN(PA, 5), - DEFINE_GPIO_PIN(PA, 6), - DEFINE_GPIO_PIN(PA, 7), - DEFINE_GPIO_PIN(PA, 3), - DEFINE_GPIO_PIN(PA, 12), - DEFINE_GPIO_PIN(PA, 13), - DEFINE_GPIO_PIN(PB, 4), - DEFINE_GPIO_PIN(PB, 5), - DEFINE_GPIO_PIN(PB, 6), - DEFINE_GPIO_PIN(PB, 7), - DEFINE_GPIO_PIN(PB, 9), - DEFINE_GPIO_PIN(PB, 10), +static const int8_t exti_config[2][32] = { + { 0, 1, 2, 3, 4, 5, 6, 7, -1, 9, 10, 11, 12, 13, 14, 15, + 0, 1, 2, 3, 4, 5, 6, 7, 12, 13, -1, 15, -1, -1, 10, 11}, + {-1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 0, 1, -1, -1, -1, -1, 6, 7, -1, -1, -1, -1, -1, -1, 14, 15}, }; -int gpio_init_mux(gpio_t dev, uint32_t mux) -{ - if (dev >= GPIO_NUMOF) { - return -1; - } - - PortGroup* port = _port(dev); - uint32_t pin = _pin(dev); +typedef struct { + gpio_cb_t cb; /**< callback called from GPIO interrupt */ + void *arg; /**< argument passed to the callback */ +} gpio_state_t; - /* WRCONFIG supports only half of the pin-space, selected by HWSEL - * (half-word selection). - * So here we either just use the lower half, or shift it by a - * half-word and set the half-word select (HWSEL) flag. - * */ - uint32_t hwmode = (pin < 16) ? (1 << pin) : (((1 << pin) >> 16) | PORT_WRCONFIG_HWSEL); +static gpio_state_t gpio_config[NUMOF_IRQS]; - port->WRCONFIG.reg = PORT_WRCONFIG_WRPINCFG - | PORT_WRCONFIG_WRPMUX - | PORT_WRCONFIG_PMUX(mux) - | PORT_WRCONFIG_PMUXEN - /*| (mux ? PORT_WRCONFIG_PMUXEN : 0)*/ - | hwmode; - return 0; +static inline PortGroup *_port(gpio_t pin) +{ + return (PortGroup *)(pin & ~(0x1f)); } -int gpio_init_out(gpio_t dev, gpio_pp_t pushpull) + +static inline int _pin_pos(gpio_t pin) { - if (dev >= GPIO_NUMOF) { - return -1; - } + return (pin & 0x1f); +} - PortGroup* port = _port(dev); - uint32_t pin = _pin(dev); +static inline int _pin_mask(gpio_t pin) +{ + return (1 << _pin_pos(pin)); +} - /* configure as output */ - port->DIRSET.reg = 1 << pin; +static int _exti(gpio_t pin) +{ + int port_num = ((pin >> 7) & 0x03); - /* configure the pin's pull resistor state */ - switch (pushpull) { - case GPIO_PULLDOWN: - return -1; - case GPIO_PULLUP: - port->PINCFG[pin].bit.PULLEN = true; - break; - case GPIO_NOPULL: - port->PINCFG[pin].bit.PULLEN = false; - break; + if (port_num > 1) { + return -1; } - - return 0; + return exti_config[port_num][_pin_pos(pin)]; } -int gpio_init_in(gpio_t dev, gpio_pp_t pushpull) +void gpio_init_mux(gpio_t pin, gpio_mux_t mux) { - if (dev >= GPIO_NUMOF) { - return -1; - } + PortGroup* port = _port(pin); + int pin_pos = _pin_pos(pin); - PortGroup* port = _port(dev); - uint32_t pin = _pin(dev); + port->PINCFG[pin_pos].reg |= PORT_PINCFG_PMUXEN; + port->PMUX[pin_pos >> 1].reg &= ~(0xf << (4 * (pin_pos & 0x1))); + port->PMUX[pin_pos >> 1].reg |= (mux << (4 * (pin_pos & 0x1))); +} - /* configure as input */ - port->DIRCLR.reg = 1 << pin; - /* buffer input value */ - port->PINCFG[pin].bit.INEN = true; +int gpio_init(gpio_t pin, gpio_dir_t dir, gpio_pp_t pushpull) +{ + PortGroup* port = _port(pin); + int pin_pos = _pin_pos(pin); + int pin_mask = _pin_mask(pin); - /* configure the pin's pull resistor state */ + /* configure the pin's pull resistor and reset all other configuration */ switch (pushpull) { case GPIO_PULLDOWN: - port->OUTCLR.reg = 1 << pin; - port->PINCFG[pin].bit.PULLEN = true; + port->OUTCLR.reg = pin_mask; + port->PINCFG[pin_pos].reg = PORT_PINCFG_PULLEN; break; case GPIO_PULLUP: - port->OUTSET.reg = 1 << pin; - port->PINCFG[pin].bit.PULLEN = true; + port->OUTSET.reg = pin_mask; + port->PINCFG[pin_pos].reg = PORT_PINCFG_PULLEN; break; case GPIO_NOPULL: - port->PINCFG[pin].bit.PULLEN = false; + port->PINCFG[pin_pos].reg = 0; break; } - + /* set pin_pos direction */ + if (dir == GPIO_DIR_OUT) { + if (pushpull == GPIO_PULLDOWN) { + return -1; + } + port->DIRSET.reg = pin_mask; /* configure as output */ + port->OUTCLR.reg = pin_mask; /* set pin LOW on init */ + } + else { + port->DIRCLR.reg = pin_mask; /* configure as input */ + port->PINCFG[pin_pos].reg |= PORT_PINCFG_INEN; + } return 0; } -int gpio_init_int(gpio_t dev, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb, void *arg) +int gpio_init_int(gpio_t pin, gpio_pp_t pullup, gpio_flank_t flank, + gpio_cb_t cb, void *arg) { - if (dev >= GPIO_NUMOF) { - return -1; - } - - uint32_t pin = _pin(dev); - uint32_t extint = pin % 16; + int exti = _exti(pin); - int exti_pos = gpio_exti_map[extint]; - if (exti_pos == -1) { - /* EXTI line not enabled. */ + /* make sure EIC channel is valid */ + if (exti == -1) { return -1; } - int res = 0; - - /* set pin mux */ - gpio_init_mux(dev, 0); - - /* configure pin as input */ - res = gpio_init_in(dev, pullup); - if (res < 0) { - return res; - } - - /* Turn on APB clock */ + /* save callback */ + gpio_config[exti].cb = cb; + gpio_config[exti].arg = arg; + /* configure ping as input and set MUX to peripheral function A */ + gpio_init(pin, GPIO_DIR_IN, pullup); + gpio_init_mux(pin, GPIO_MUX_A); + /* enable clocks for the EIC module */ MCLK->APBAMASK.reg |= MCLK_APBAMASK_EIC; - - /* setup GCLK for EIC */ GCLK->PCHCTRL[EIC_GCLK_ID].reg = GCLK_PCHCTRL_CHEN | GCLK_PCHCTRL_GEN_GCLK0; - - /* Setup interrupt */ - NVIC_SetPriority(EIC_IRQn, 10); + /* configure the active flank */ + EIC->CONFIG[exti >> 3].reg &= ~(0xf << ((exti & 0x7) * 4)); + EIC->CONFIG[exti >> 3].reg |= (flank << ((exti & 0x7) * 4)); + /* enable the global EIC interrupt */ NVIC_EnableIRQ(EIC_IRQn); - - /* save callback */ - gpio_config[exti_pos].cb = cb; - gpio_config[exti_pos].arg = arg; - - /* must disable EIC before configuring. */ - EIC->CTRLA.bit.ENABLE = false; - /*Enable pin interrupt */ - EIC->INTFLAG.reg |= (1 << extint); - EIC->INTENSET.reg = 1 << extint; - - /*Set config */ - uint8_t config_pos = (4 * (extint % 8)); - uint8_t config_reg = extint / 8; - /*Set flank detection */ - switch (flank) { - case GPIO_FALLING: - EIC->CONFIG[config_reg].reg - |= (EIC_CONFIG_SENSE0_FALL_Val << config_pos); - break; - case GPIO_RISING: - EIC->CONFIG[config_reg].reg - |= (EIC_CONFIG_SENSE0_RISE_Val << config_pos); - break; - case GPIO_BOTH: - EIC->CONFIG[config_reg].reg - |= (EIC_CONFIG_SENSE0_BOTH_Val << config_pos); - break; - } - - /*Enable external interrupts*/ - EIC->CTRLA.bit.ENABLE = true; + EIC->INTFLAG.reg = (1 << exti); + EIC->INTENSET.reg = (1 << exti); + /* enable the EIC module*/ + EIC->CTRLA.reg = EIC_CTRLA_ENABLE; + while (EIC->SYNCBUSY.reg & EIC_SYNCBUSY_ENABLE); return 0; } -void gpio_irq_enable(gpio_t dev) +void gpio_irq_enable(gpio_t pin) { - uint32_t extint = _pin(dev) % 16; - EIC->INTENSET.reg = 1 << extint; + int exti = _exti(pin); + if (exti == -1) { + return; + } + EIC->INTENSET.reg = (1 << exti); } -void gpio_irq_disable(gpio_t dev) +void gpio_irq_disable(gpio_t pin) { - uint32_t extint = _pin(dev) % 16; - EIC->INTENCLR.reg = 1 << extint; + int exti = _exti(pin); + if (exti == -1) { + return; + } + EIC->INTENCLR.reg = (1 << exti); } -int gpio_read(gpio_t dev) +int gpio_read(gpio_t pin) { - PortGroup* port = _port(dev); - uint32_t pin = _pin(dev); - int res = -1; - - res = port->IN.reg & (1 << pin); + PortGroup *port = _port(pin); + int mask = _pin_mask(pin); - /* make sure we are not returning a negative value if bit 31 is set */ - if (res < -1) { - res = 1; + if (port->DIR.reg & mask) { + return (port->OUT.reg & mask) ? 1 : 0; + } + else { + return (port->IN.reg & mask) ? 1 : 0; } - - return res; } -void gpio_set(gpio_t dev) +void gpio_set(gpio_t pin) { - PortGroup* port = _port(dev); - uint32_t pin = _pin(dev); - - port->OUTSET.reg = 1 << pin; + _port(pin)->OUTSET.reg = _pin_mask(pin); } -void gpio_clear(gpio_t dev) +void gpio_clear(gpio_t pin) { - PortGroup* port = _port(dev); - uint32_t pin = _pin(dev); - port->OUTCLR.reg = 1 << pin; + _port(pin)->OUTCLR.reg = _pin_mask(pin); } -void gpio_toggle(gpio_t dev) +void gpio_toggle(gpio_t pin) { - PortGroup* port = _port(dev); - uint32_t pin = _pin(dev); - port->OUTTGL.reg = 1 << pin; + _port(pin)->OUTTGL.reg = _pin_mask(pin); } -void gpio_write(gpio_t dev, int value) +void gpio_write(gpio_t pin, int value) { if (value) { - gpio_set(dev); + _port(pin)->OUTSET.reg = _pin_mask(pin); } else { - gpio_clear(dev); + _port(pin)->OUTCLR.reg = _pin_mask(pin); } } void isr_eic(void) { - uint16_t status = EIC->INTFLAG.reg; - for (int i = 0; i < 16; i++) { - if (status & (0x1<INTFLAG.reg = 0x1 << i; - break; + for (int i = 0; i < NUMOF_IRQS; i++) { + if (EIC->INTFLAG.reg & (1 << i)) { + EIC->INTFLAG.reg = (1 << i); + gpio_config[i].cb(gpio_config[i].arg); } } @@ -399,5 +230,3 @@ void isr_eic(void) thread_yield(); } } - -#endif /* GPIO_NUMOF */ diff --git a/cpu/saml21/periph/spi.c b/cpu/saml21/periph/spi.c index 8cb5f4d5900a..846a818ac0f4 100644 --- a/cpu/saml21/periph/spi.c +++ b/cpu/saml21/periph/spi.c @@ -72,7 +72,7 @@ typedef struct spi_saml21 { static const spi_saml21_t spi[] = { #if SPI_0_EN /* SPI device */ /* MCLK flag */ /* GLCK id */ /* SCLK */ /* MISO */ /* MOSI */ /* dipo+dopo */ - { &(SERCOM0->SPI), MCLK_APBCMASK_SERCOM0, SERCOM0_GCLK_ID_CORE, { PA7, 3 }, { PA4, 3 }, { PA6, 3 }, 0, 1 } + { &(SERCOM0->SPI), MCLK_APBCMASK_SERCOM0, SERCOM0_GCLK_ID_CORE, { GPIO(PA,7), 3 }, { GPIO(PA,4), 3 }, { GPIO(PA,6), 3 }, 0, 1 } #endif }; @@ -133,21 +133,19 @@ int spi_init_master(spi_t dev, spi_conf_t conf, spi_speed_t speed) while (!(GCLK->PCHCTRL[spi[dev].gclk_id].reg & GCLK_PCHCTRL_CHEN)); + /* SCLK+MOSI = output */ + gpio_init(spi[dev].sclk.pin, GPIO_DIR_OUT, GPIO_NOPULL); + gpio_init(spi[dev].mosi.pin, GPIO_DIR_OUT, GPIO_NOPULL); + /* MISO = input */ + gpio_init(spi[dev].miso.pin, GPIO_DIR_IN, GPIO_PULLUP); + /* * Set alternate funcion (PMUX) for our ports. - * This has to be done before gpio_init_[in|out]. */ gpio_init_mux(spi[dev].sclk.pin, spi[dev].sclk.pmux); gpio_init_mux(spi[dev].miso.pin, spi[dev].miso.pmux); gpio_init_mux(spi[dev].mosi.pin, spi[dev].mosi.pmux); - /* SCLK+MOSI = output */ - gpio_init_out(spi[dev].sclk.pin, GPIO_NOPULL); - gpio_init_out(spi[dev].mosi.pin, GPIO_NOPULL); - - /* MISO = input */ - gpio_init_in(spi[dev].miso.pin, GPIO_PULLUP); - /* pin pad mapping */ dipo = spi[dev].dipo; dopo = spi[dev].dopo; From 368f5fb64f498e4ede88bcfc5e2f96ad207ce05c Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 3 Jun 2015 18:23:01 +0200 Subject: [PATCH 10/33] cpu/samd21: remodeled GPIO driver implementation --- cpu/samd21/include/periph_cpu.h | 90 +++ cpu/samd21/periph/gpio.c | 1077 ++++--------------------------- 2 files changed, 219 insertions(+), 948 deletions(-) create mode 100644 cpu/samd21/include/periph_cpu.h diff --git a/cpu/samd21/include/periph_cpu.h b/cpu/samd21/include/periph_cpu.h new file mode 100644 index 000000000000..ce4d59f93266 --- /dev/null +++ b/cpu/samd21/include/periph_cpu.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup cpu_samd21 + * @{ + * + * @file + * @brief CPU specific definitions for internal peripheral handling + * + * @author Hauke Petersen + */ + +#ifndef CPU_PERIPH_H_ +#define CPU_PERIPH_H_ + +#include "cpu.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Define mandatory GPIO types for NRF51822 CPUs + * @{ + */ +#define HAVE_GPIO_T +typedef uint32_t gpio_t; +/** @} */ + +/** + * @brief Mandatory function for defining a GPIO pins + * @{ + */ +#define GPIO(x, y) (((gpio_t)(&PORT->Group[x])) | y) + +/** + * @brief Available ports on the SAMD21 + */ +enum { + PA = 0, /**< port A */ + PB = 1, /**< port B */ + PC = 2, /**< port C */ +}; + +/** + * @brief Override active flank configuration values + * @{ + */ +#define HAVE_GPIO_FLANK_T +typedef enum { + GPIO_FALLING = 2, /**< emit interrupt on falling flank */ + GPIO_RISING = 1, /**< emit interrupt on rising flank */ + GPIO_BOTH = 3 /**< emit interrupt on both flanks */ +} gpio_flank_t; +/** @} */ + +/** + * @brief Available MUX values for configuring a pin's alternate function + */ +typedef enum { + GPIO_MUX_A = 0x0, /**< select peripheral function A */ + GPIO_MUX_B = 0x1, /**< select peripheral function B */ + GPIO_MUX_C = 0x2, /**< select peripheral function C */ + GPIO_MUX_D = 0x3, /**< select peripheral function D */ + GPIO_MUX_E = 0x4, /**< select peripheral function E */ + GPIO_MUX_F = 0x5, /**< select peripheral function F */ + GPIO_MUX_G = 0x6, /**< select peripheral function G */ + GPIO_MUX_H = 0x7, /**< select peripheral function H */ +} gpio_mux_t; + +/** + * @brief Set up alternate function (PMUX setting) for a PORT pin + * + * @param[in] dev Pin to set the multiplexing for + * @param[in] mux Mux value + */ +int gpio_init_mux(gpio_t dev, gpio_mux_t mux); + +#ifdef __cplusplus +} +#endif + +#endif /* CPU_PERIPH_H_ */ +/** @} */ diff --git a/cpu/samd21/periph/gpio.c b/cpu/samd21/periph/gpio.c index bb4f2e3c5c40..e1c9e0112fb3 100644 --- a/cpu/samd21/periph/gpio.c +++ b/cpu/samd21/periph/gpio.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Freie Universität Berlin + * Copyright (C) 2014-2015 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -15,1036 +15,217 @@ * * @author Troels Hoffmeyer * @author Thomas Eichinger + * @author Hauke Petersen * * @} */ #include "cpu.h" +#include "sched.h" +#include "thread.h" #include "periph/gpio.h" #include "periph_conf.h" -#include "sched.h" -#include "thread.h" #define ENABLE_DEBUG (0) #include "debug.h" -/* guard file in case no GPIO devices are defined */ -#if GPIO_NUMOF +/** + * @brief Number of external interrupt lines + */ +#define NUMOF_IRQS (16U) + +/** + * @brief Mapping of pins to EXTI lines, -1 means not EXTI possible + */ +static const int8_t exti_config[2][32] = { + {-1, 1, -1, -1, 4, 5, 6, 7, -1, 9, 10, 11, 12, 13, 14, 15, + -1, 1, 2, 3, -1, -1, 6, 7, 12, 13, -1, -1, -1, -1, -1, -1}, + { 0, -1, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 0, 1, -1, -1, -1, -1, 6, 7, -1, -1, -1, 15, 8, -1, 10, 11}, +}; +/** + * @brief Datatype to use for saving the interrupt contexts + */ typedef struct { - gpio_cb_t cb; /**< callback called from GPIO interrupt */ + gpio_cb_t cb; /**< callback to call on GPIO interrupt */ void *arg; /**< argument passed to the callback */ -} gpio_state_t; +} gpio_exti_t; -#define EXTI_NUMOF 16 -static gpio_state_t gpio_config[EXTI_NUMOF]; +/** + * @brief Hold one interrupt context per interrupt line + */ +static gpio_exti_t gpio_config[NUMOF_IRQS]; -int gpio_init_out(gpio_t dev, gpio_pp_t pushpull) +static inline PortGroup *_port(gpio_t pin) { - PortGroup* port = NULL; - uint32_t pin = 0; - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - port = &GPIO_0_DEV; - pin = GPIO_0_PIN; - break; -#endif -#if GPIO_1_EN - case GPIO_1: - port = &GPIO_1_DEV; - pin = GPIO_1_PIN; - break; -#endif -#if GPIO_2_EN - case GPIO_2: - port = &GPIO_2_DEV; - pin = GPIO_2_PIN; - break; -#endif -#if GPIO_3_EN - case GPIO_3: - port = &GPIO_3_DEV; - pin = GPIO_3_PIN; - break; -#endif -#if GPIO_4_EN - case GPIO_4: - port = &GPIO_4_DEV; - pin = GPIO_4_PIN; - break; -#endif -#if GPIO_5_EN - case GPIO_5: - port = &GPIO_5_DEV; - pin = GPIO_5_PIN; - break; -#endif -#if GPIO_6_EN - case GPIO_6: - port = &GPIO_6_DEV; - pin = GPIO_6_PIN; - break; -#endif -#if GPIO_7_EN - case GPIO_7: - port = &GPIO_7_DEV; - pin = GPIO_7_PIN; - break; -#endif -#if GPIO_8_EN - case GPIO_8: - port = &GPIO_8_DEV; - pin = GPIO_8_PIN; - break; -#endif -#if GPIO_9_EN - case GPIO_9: - port = &GPIO_9_DEV; - pin = GPIO_9_PIN; - break; -#endif -#if GPIO_10_EN - case GPIO_10: - port = &GPIO_10_DEV; - pin = GPIO_10_PIN; - break; -#endif -#if GPIO_11_EN - case GPIO_11: - port = &GPIO_11_DEV; - pin = GPIO_11_PIN; - break; -#endif -#if GPIO_12_EN - case GPIO_12: - port = &GPIO_12_DEV; - pin = GPIO_12_PIN; - break; -#endif -#if GPIO_13_EN - case GPIO_13: - port = &GPIO_13_DEV; - pin = GPIO_13_PIN; - break; -#endif -#if GPIO_14_EN - case GPIO_14: - port = &GPIO_14_DEV; - pin = GPIO_14_PIN; - break; -#endif -#if GPIO_15_EN - case GPIO_15: - port = &GPIO_15_DEV; - pin = GPIO_15_PIN; - break; -#endif - default: - return -1; - } - - if (port == NULL) { - return -1; - } - - /* configure as output */ - port->DIRSET.reg = 1 << pin; + return (PortGroup *)(pin & ~(0x1f)); +} - /* configure the pin's pull resistor state */ - switch (pushpull) { - case GPIO_PULLDOWN: - return -1; - case GPIO_PULLUP: - port->PINCFG[pin].bit.PULLEN = true; - break; - case GPIO_NOPULL: - port->PINCFG[pin].bit.PULLEN = false; - break; - } +static inline int _pin_pos(gpio_t pin) +{ + return (pin & 0x1f); +} - return 0; +static inline int _pin_mask(gpio_t pin) +{ + return (1 << _pin_pos(pin)); } -int gpio_init_in(gpio_t dev, gpio_pp_t pushpull) +static int _exti(gpio_t pin) { - PortGroup* port = NULL; - uint32_t pin = 0; - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - port = &GPIO_0_DEV; - pin = GPIO_0_PIN; - break; -#endif -#if GPIO_1_EN - case GPIO_1: - port = &GPIO_1_DEV; - pin = GPIO_1_PIN; - break; -#endif -#if GPIO_2_EN - case GPIO_2: - port = &GPIO_2_DEV; - pin = GPIO_2_PIN; - break; -#endif -#if GPIO_3_EN - case GPIO_3: - port = &GPIO_3_DEV; - pin = GPIO_3_PIN; - break; -#endif -#if GPIO_4_EN - case GPIO_4: - port = &GPIO_4_DEV; - pin = GPIO_4_PIN; - break; -#endif -#if GPIO_5_EN - case GPIO_5: - port = &GPIO_5_DEV; - pin = GPIO_5_PIN; - break; -#endif -#if GPIO_6_EN - case GPIO_6: - port = &GPIO_6_DEV; - pin = GPIO_6_PIN; - break; -#endif -#if GPIO_7_EN - case GPIO_7: - port = &GPIO_7_DEV; - pin = GPIO_7_PIN; - break; -#endif -#if GPIO_8_EN - case GPIO_8: - port = &GPIO_8_DEV; - pin = GPIO_8_PIN; - break; -#endif -#if GPIO_9_EN - case GPIO_9: - port = &GPIO_9_DEV; - pin = GPIO_9_PIN; - break; -#endif -#if GPIO_10_EN - case GPIO_10: - port = &GPIO_10_DEV; - pin = GPIO_10_PIN; - break; -#endif -#if GPIO_11_EN - case GPIO_11: - port = &GPIO_11_DEV; - pin = GPIO_11_PIN; - break; -#endif -#if GPIO_12_EN - case GPIO_12: - port = &GPIO_12_DEV; - pin = GPIO_12_PIN; - break; -#endif -#if GPIO_13_EN - case GPIO_13: - port = &GPIO_13_DEV; - pin = GPIO_13_PIN; - break; -#endif -#if GPIO_14_EN - case GPIO_14: - port = &GPIO_14_DEV; - pin = GPIO_14_PIN; - break; -#endif -#if GPIO_15_EN - case GPIO_15: - port = &GPIO_15_DEV; - pin = GPIO_15_PIN; - break; -#endif - default: - return -1; - } + int port_num = ((pin >> 7) & 0x03); - if (port == NULL) { + if (port_num > 1) { return -1; } + return exti_config[port_num][_pin_pos(pin)]; +} + +int gpio_init_mux(gpio_t pin, gpio_mux_t mux) +{ + PortGroup* port = _port(pin); + int pin_pos = _pin_pos(pin); + + port->PINCFG[pin_pos].reg |= PORT_PINCFG_PMUXEN; + port->PMUX[pin_pos >> 1].reg &= ~(0xf << (4 * (pin_pos & 0x1))); + port->PMUX[pin_pos >> 1].reg |= (mux << (4 * (pin_pos & 0x1))); + return 0; +} - /* configure as input */ - port->DIRCLR.reg = 1 << pin; - /* buffer input value */ - port->PINCFG[pin].bit.INEN = true; +int gpio_init(gpio_t pin, gpio_dir_t dir, gpio_pp_t pushpull) +{ + PortGroup* port = _port(pin); + int pin_pos = _pin_pos(pin); + int pin_mask = _pin_mask(pin); - /* configure the pin's pull resistor state */ + /* configure the pin's pull resistor and reset all other configuration */ switch (pushpull) { case GPIO_PULLDOWN: - port->OUTCLR.reg = 1 << pin; - port->PINCFG[pin].bit.PULLEN = true; + port->OUTCLR.reg = pin_mask; + port->PINCFG[pin_pos].reg = PORT_PINCFG_PULLEN; break; case GPIO_PULLUP: - port->OUTSET.reg = 1 << pin; - port->PINCFG[pin].bit.PULLEN = true; + port->OUTSET.reg = pin_mask; + port->PINCFG[pin_pos].reg = PORT_PINCFG_PULLEN; break; case GPIO_NOPULL: - port->PINCFG[pin].bit.PULLEN = false; + port->PINCFG[pin_pos].reg = 0; break; } - + /* set pin_pos direction */ + if (dir == GPIO_DIR_OUT) { + if (pushpull == GPIO_PULLDOWN) { + return -1; + } + port->DIRSET.reg = pin_mask; /* configure as output */ + port->OUTCLR.reg = pin_mask; /* set pin LOW on init */ + } + else { + port->DIRCLR.reg = pin_mask; /* configure as input */ + port->PINCFG[pin_pos].reg |= PORT_PINCFG_INEN; + } return 0; } -int gpio_init_int(gpio_t dev, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb, void *arg) +int gpio_init_int(gpio_t pin, gpio_pp_t pullup, gpio_flank_t flank, + gpio_cb_t cb, void *arg) { - PortGroup* port = NULL; - uint32_t pin = 0; - uint32_t extint = 0; - int res = 0; - - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - port = &GPIO_0_DEV; - pin = GPIO_0_PIN; - extint = GPIO_0_EXTINT; - break; -#endif -#if GPIO_1_EN - case GPIO_1: - port = &GPIO_1_DEV; - pin = GPIO_1_PIN; - extint = GPIO_1_EXTINT; - break; -#endif -#if GPIO_2_EN - case GPIO_2: - port = &GPIO_2_DEV; - pin = GPIO_2_PIN; - extint = GPIO_2_EXTINT; - break; -#endif -#if GPIO_3_EN - case GPIO_3: - port = &GPIO_3_DEV; - pin = GPIO_3_PIN; - extint = GPIO_3_EXTINT; - break; -#endif -#if GPIO_4_EN - case GPIO_4: - port = &GPIO_4_DEV; - pin = GPIO_4_PIN; - extint = GPIO_4_EXTINT; - break; -#endif -#if GPIO_5_EN - case GPIO_5: - port = &GPIO_5_DEV; - pin = GPIO_5_PIN; - extint = GPIO_5_EXTINT; - break; -#endif -#if GPIO_6_EN - case GPIO_6: - port = &GPIO_6_DEV; - pin = GPIO_6_PIN; - extint = GPIO_6_EXTINT; - break; -#endif -#if GPIO_7_EN - case GPIO_7: - port = &GPIO_7_DEV; - pin = GPIO_7_PIN; - extint = GPIO_7_EXTINT; - break; -#endif -#if GPIO_8_EN - case GPIO_8: - port = &GPIO_8_DEV; - pin = GPIO_8_PIN; - extint = GPIO_8_EXTINT; - break; -#endif -#if GPIO_9_EN - case GPIO_9: - port = &GPIO_9_DEV; - pin = GPIO_9_PIN; - extint = GPIO_9_EXTINT; - break; -#endif -#if GPIO_10_EN - case GPIO_10: - port = &GPIO_10_DEV; - pin = GPIO_10_PIN; - extint = GPIO_10_EXTINT; - break; -#endif -#if GPIO_11_EN - case GPIO_11: - port = &GPIO_11_DEV; - pin = GPIO_11_PIN; - extint = GPIO_11_EXTINT; - break; -#endif -#if GPIO_12_EN - case GPIO_12: - port = &GPIO_12_DEV; - pin = GPIO_12_PIN; - extint = GPIO_12_EXTINT; - break; -#endif -#if GPIO_13_EN - case GPIO_13: - port = &GPIO_13_DEV; - pin = GPIO_13_PIN; - extint = GPIO_13_EXTINT; - break; -#endif -#if GPIO_14_EN - case GPIO_14: - port = &GPIO_14_DEV; - pin = GPIO_14_PIN; - extint = GPIO_14_EXTINT; - break; -#endif -#if GPIO_15_EN - case GPIO_15: - port = &GPIO_15_DEV; - pin = GPIO_15_PIN; - extint = GPIO_15_EXTINT; - break; -#endif - default: - return -1; - } + int exti = _exti(pin); - if (port == NULL) { + /* make sure EIC channel is valid */ + if (exti == -1) { return -1; } - - - if (pin < 16) { - port->WRCONFIG.reg = PORT_WRCONFIG_WRPINCFG \ - | PORT_WRCONFIG_WRPMUX \ - | PORT_WRCONFIG_PMUX(0x0) \ - | PORT_WRCONFIG_PMUXEN \ - | (1 << pin); - } - else { - port->WRCONFIG.reg = PORT_WRCONFIG_HWSEL \ - | PORT_WRCONFIG_WRPINCFG \ - | PORT_WRCONFIG_WRPMUX \ - | PORT_WRCONFIG_PMUX(0x0) \ - | PORT_WRCONFIG_PMUXEN \ - | ((1 << pin) >> 16); - } - - /* configure pin as input */ - res = gpio_init_in(dev, pullup); - if (res < 0) { - return res; - } - - /* Turn on APB clock */ + /* save callback */ + gpio_config[exti].cb = cb; + gpio_config[exti].arg = arg; + /* configure ping as input and set MUX to peripheral function A */ + gpio_init(pin, GPIO_DIR_IN, pullup); + gpio_init_mux(pin, GPIO_MUX_A); + /* enable clocks for the EIC module */ PM->APBAMASK.reg |= PM_APBAMASK_EIC; - - GCLK->CLKCTRL = (GCLK_CLKCTRL_Type){ - .bit.ID = EIC_GCLK_ID, - .bit.GEN = 0, - .bit.CLKEN = 1, - .bit.WRTLOCK = 0 - }; - - /* Setup interrupt */ - NVIC_SetPriority(EIC_IRQn, 10); + GCLK->CLKCTRL.reg = (EIC_GCLK_ID | GCLK_CLKCTRL_CLKEN); + /* configure the active flank */ + EIC->CONFIG[exti >> 3].reg &= ~(0xf << ((exti & 0x7) * 4)); + EIC->CONFIG[exti >> 3].reg |= (flank << ((exti & 0x7) * 4)); + /* enable the global EIC interrupt */ NVIC_EnableIRQ(EIC_IRQn); - - /* save callback */ - gpio_config[extint].cb = cb; - gpio_config[extint].arg = arg; - - /*Enable pin interrupt */ - EIC->INTFLAG.reg |= (1 << extint); - EIC->INTENSET.reg = 1 << extint; - EIC->WAKEUP.reg |= 1 << extint; - - /*Set config */ - uint8_t config_pos = (4 * (extint % 8)); - uint8_t config_reg = extint / 8; - /*Set flank detection */ - switch (flank) { - case GPIO_FALLING: - EIC->CONFIG[config_reg].reg - |= (EIC_CONFIG_SENSE0_FALL_Val << config_pos); - break; - case GPIO_RISING: - EIC->CONFIG[config_reg].reg - |= (EIC_CONFIG_SENSE0_RISE_Val << config_pos); - break; - case GPIO_BOTH: - EIC->CONFIG[config_reg].reg - |= (EIC_CONFIG_SENSE0_BOTH_Val << config_pos); - break; - } - - /*Enable external interrupts*/ - EIC->CTRL.bit.ENABLE = true; + /* clear interrupt flag and enable the interrupt line and line wakeup */ + EIC->INTFLAG.reg = (1 << exti); + EIC->WAKEUP.reg |= (1 << exti); + EIC->INTENSET.reg = (1 << exti); + /* enable the EIC module*/ + EIC->CTRL.reg = EIC_CTRL_ENABLE; + while (EIC->STATUS.reg & EIC_STATUS_SYNCBUSY); return 0; } -void gpio_irq_enable(gpio_t dev) +void gpio_irq_enable(gpio_t pin) { - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - EIC->INTENSET.reg = 1 << GPIO_0_EXTINT; - break; -#endif -#if GPIO_1_EN - case GPIO_1: - EIC->INTENSET.reg = 1 << GPIO_1_EXTINT; - break; -#endif -#if GPIO_2_EN - case GPIO_2: - EIC->INTENSET.reg = 1 << GPIO_2_EXTINT; - break; -#endif -#if GPIO_3_EN - case GPIO_3: - EIC->INTENSET.reg = 1 << GPIO_3_EXTINT; - break; -#endif -#if GPIO_4_EN - case GPIO_4: - EIC->INTENSET.reg = 1 << GPIO_4_EXTINT; - break; -#endif -#if GPIO_5_EN - case GPIO_5: - EIC->INTENSET.reg = 1 << GPIO_5_EXTINT; - break; -#endif -#if GPIO_6_EN - case GPIO_6: - EIC->INTENSET.reg = 1 << GPIO_6_EXTINT; - break; -#endif -#if GPIO_7_EN - case GPIO_7: - EIC->INTENSET.reg = 1 << GPIO_7_EXTINT; - break; -#endif -#if GPIO_8_EN - case GPIO_8: - EIC->INTENSET.reg = 1 << GPIO_8_EXTINT; - break; -#endif -#if GPIO_9_EN - case GPIO_9: - EIC->INTENSET.reg = 1 << GPIO_9_EXTINT; - break; -#endif -#if GPIO_10_EN - case GPIO_10: - EIC->INTENSET.reg = 1 << GPIO_10_EXTINT; - break; -#endif -#if GPIO_11_EN - case GPIO_11: - EIC->INTENSET.reg = 1 << GPIO_11_EXTINT; - break; -#endif -#if GPIO_12_EN - case GPIO_12: - EIC->INTENSET.reg = 1 << GPIO_12_EXTINT; - break; -#endif -#if GPIO_13_EN - case GPIO_13: - EIC->INTENSET.reg = 1 << GPIO_13_EXTINT; - break; -#endif -#if GPIO_14_EN - case GPIO_14: - EIC->INTENSET.reg = 1 << GPIO_14_EXTINT; - break; -#endif -#if GPIO_15_EN - case GPIO_15: - EIC->INTENSET.reg = 1 << GPIO_15_EXTINT; - break; -#endif + int exti = _exti(pin); + if (exti == -1) { + return; } + EIC->INTENSET.reg = (1 << exti); } -void gpio_irq_disable(gpio_t dev) +void gpio_irq_disable(gpio_t pin) { - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - EIC->INTENCLR.reg = 1 << GPIO_0_EXTINT; - break; -#endif -#if GPIO_1_EN - case GPIO_1: - EIC->INTENCLR.reg = 1 << GPIO_1_EXTINT; - break; -#endif -#if GPIO_2_EN - case GPIO_2: - EIC->INTENCLR.reg = 1 << GPIO_2_EXTINT; - break; -#endif -#if GPIO_3_EN - case GPIO_3: - EIC->INTENCLR.reg = 1 << GPIO_3_EXTINT; - break; -#endif -#if GPIO_4_EN - case GPIO_4: - EIC->INTENCLR.reg = 1 << GPIO_4_EXTINT; - break; -#endif -#if GPIO_5_EN - case GPIO_5: - EIC->INTENCLR.reg = 1 << GPIO_5_EXTINT; - break; -#endif -#if GPIO_6_EN - case GPIO_6: - EIC->INTENCLR.reg = 1 << GPIO_6_EXTINT; - break; -#endif -#if GPIO_7_EN - case GPIO_7: - EIC->INTENCLR.reg = 1 << GPIO_7_EXTINT; - break; -#endif -#if GPIO_8_EN - case GPIO_8: - EIC->INTENCLR.reg = 1 << GPIO_8_EXTINT; - break; -#endif -#if GPIO_9_EN - case GPIO_9: - EIC->INTENCLR.reg = 1 << GPIO_9_EXTINT; - break; -#endif -#if GPIO_10_EN - case GPIO_10: - EIC->INTENCLR.reg = 1 << GPIO_10_EXTINT; - break; -#endif -#if GPIO_11_EN - case GPIO_11: - EIC->INTENCLR.reg = 1 << GPIO_11_EXTINT; - break; -#endif -#if GPIO_12_EN - case GPIO_12: - EIC->INTENCLR.reg = 1 << GPIO_12_EXTINT; - break; -#endif -#if GPIO_13_EN - case GPIO_13: - EIC->INTENCLR.reg = 1 << GPIO_13_EXTINT; - break; -#endif -#if GPIO_14_EN - case GPIO_14: - EIC->INTENCLR.reg = 1 << GPIO_14_EXTINT; - break; -#endif -#if GPIO_15_EN - case GPIO_15: - EIC->INTENCLR.reg = 1 << GPIO_15_EXTINT; - break; -#endif + int exti = _exti(pin); + if (exti == -1) { + return; } + EIC->INTENCLR.reg = (1 << exti); } -int gpio_read(gpio_t dev) +int gpio_read(gpio_t pin) { - int res = -1; + PortGroup *port = _port(pin); + int mask = _pin_mask(pin); - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - res = (&GPIO_0_DEV)->IN.reg & (1 << GPIO_0_PIN); - break; -#endif -#if GPIO_1_EN - case GPIO_1: - res = (&GPIO_1_DEV)->IN.reg & (1 << GPIO_1_PIN); - break; -#endif -#if GPIO_2_EN - case GPIO_2: - res = (&GPIO_2_DEV)->IN.reg & (1 << GPIO_2_PIN); - break; -#endif -#if GPIO_3_EN - case GPIO_3: - res = (&GPIO_3_DEV)->IN.reg & (1 << GPIO_3_PIN); - break; -#endif -#if GPIO_4_EN - case GPIO_4: - res = (&GPIO_4_DEV)->IN.reg & (1 << GPIO_4_PIN); - break; -#endif -#if GPIO_5_EN - case GPIO_5: - res = (&GPIO_5_DEV)->IN.reg & (1 << GPIO_5_PIN); - break; -#endif -#if GPIO_6_EN - case GPIO_6: - res = (&GPIO_6_DEV)->IN.reg & (1 << GPIO_6_PIN); - break; -#endif -#if GPIO_7_EN - case GPIO_7: - res = (&GPIO_7_DEV)->IN.reg & (1 << GPIO_7_PIN); - break; -#endif -#if GPIO_8_EN - case GPIO_8: - res = (&GPIO_8_DEV)->IN.reg & (1 << GPIO_8_PIN); - break; -#endif -#if GPIO_9_EN - case GPIO_9: - res = (&GPIO_9_DEV)->IN.reg & (1 << GPIO_9_PIN); - break; -#endif -#if GPIO_10_EN - case GPIO_10: - res = (&GPIO_10_DEV)->IN.reg & (1 << GPIO_10_PIN); - break; -#endif -#if GPIO_11_EN - case GPIO_11: - res = (&GPIO_11_DEV)->IN.reg & (1 << GPIO_11_PIN); - break; -#endif -#if GPIO_12_EN - case GPIO_12: - res = (&GPIO_12_DEV)->IN.reg & (1 << GPIO_12_PIN); - break; -#endif -#if GPIO_13_EN - case GPIO_13: - res = (&GPIO_13_DEV)->IN.reg & (1 << GPIO_13_PIN); - break; -#endif -#if GPIO_14_EN - case GPIO_14: - res = (&GPIO_14_DEV)->IN.reg & (1 << GPIO_14_PIN); - break; -#endif -#if GPIO_15_EN - case GPIO_15: - res = (&GPIO_15_DEV)->IN.reg & (1 << GPIO_15_PIN); - break; -#endif + if (port->DIR.reg & mask) { + return (port->OUT.reg & mask) ? 1 : 0; } - - /* make sure we are not returning a negative value if bit 31 is set */ - if (res < -1) { - res = 1; + else { + return (port->IN.reg & mask) ? 1 : 0; } - - return res; } -void gpio_set(gpio_t dev) +void gpio_set(gpio_t pin) { - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - (&GPIO_0_DEV)->OUTSET.reg = 1 << GPIO_0_PIN; - break; -#endif -#if GPIO_1_EN - case GPIO_1: - (&GPIO_1_DEV)->OUTSET.reg = 1 << GPIO_1_PIN; - break; -#endif -#if GPIO_2_EN - case GPIO_2: - (&GPIO_2_DEV)->OUTSET.reg = 1 << GPIO_2_PIN; - break; -#endif -#if GPIO_3_EN - case GPIO_3: - (&GPIO_3_DEV)->OUTSET.reg = 1 << GPIO_3_PIN; - break; -#endif -#if GPIO_4_EN - case GPIO_4: - (&GPIO_4_DEV)->OUTSET.reg = 1 << GPIO_4_PIN; - break; -#endif -#if GPIO_5_EN - case GPIO_5: - (&GPIO_5_DEV)->OUTSET.reg = 1 << GPIO_5_PIN; - break; -#endif -#if GPIO_6_EN - case GPIO_6: - (&GPIO_6_DEV)->OUTSET.reg = 1 << GPIO_6_PIN; - break; -#endif -#if GPIO_7_EN - case GPIO_7: - (&GPIO_7_DEV)->OUTSET.reg = 1 << GPIO_7_PIN; - break; -#endif -#if GPIO_8_EN - case GPIO_8: - (&GPIO_8_DEV)->OUTSET.reg = 1 << GPIO_8_PIN; - break; -#endif -#if GPIO_9_EN - case GPIO_9: - (&GPIO_9_DEV)->OUTSET.reg = 1 << GPIO_9_PIN; - break; -#endif -#if GPIO_10_EN - case GPIO_10: - (&GPIO_10_DEV)->OUTSET.reg = 1 << GPIO_10_PIN; - break; -#endif -#if GPIO_11_EN - case GPIO_11: - (&GPIO_11_DEV)->OUTSET.reg = 1 << GPIO_11_PIN; - break; -#endif -#if GPIO_12_EN - case GPIO_12: - (&GPIO_12_DEV)->OUTSET.reg = 1 << GPIO_12_PIN; - break; -#endif -#if GPIO_13_EN - case GPIO_13: - (&GPIO_13_DEV)->OUTSET.reg = 1 << GPIO_13_PIN; - break; -#endif -#if GPIO_14_EN - case GPIO_14: - (&GPIO_14_DEV)->OUTSET.reg = 1 << GPIO_14_PIN; - break; -#endif -#if GPIO_15_EN - case GPIO_15: - (&GPIO_15_DEV)->OUTSET.reg = 1 << GPIO_15_PIN; - break; -#endif - } + _port(pin)->OUTSET.reg = _pin_mask(pin); } -void gpio_clear(gpio_t dev) +void gpio_clear(gpio_t pin) { - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - (&GPIO_0_DEV)->OUTCLR.reg = 1 << GPIO_0_PIN; - break; -#endif -#if GPIO_1_EN - case GPIO_1: - (&GPIO_1_DEV)->OUTCLR.reg = 1 << GPIO_1_PIN; - break; -#endif -#if GPIO_2_EN - case GPIO_2: - (&GPIO_2_DEV)->OUTCLR.reg = 1 << GPIO_2_PIN; - break; -#endif -#if GPIO_3_EN - case GPIO_3: - (&GPIO_3_DEV)->OUTCLR.reg = 1 << GPIO_3_PIN; - break; -#endif -#if GPIO_4_EN - case GPIO_4: - (&GPIO_4_DEV)->OUTCLR.reg = 1 << GPIO_4_PIN; - break; - -#endif -#if GPIO_5_EN - case GPIO_5: - (&GPIO_5_DEV)->OUTCLR.reg = 1 << GPIO_5_PIN; - break; -#endif -#if GPIO_6_EN - case GPIO_6: - (&GPIO_6_DEV)->OUTCLR.reg = 1 << GPIO_6_PIN; - break; -#endif -#if GPIO_7_EN - case GPIO_7: - (&GPIO_7_DEV)->OUTCLR.reg = 1 << GPIO_7_PIN; - break; -#endif -#if GPIO_8_EN - case GPIO_8: - (&GPIO_8_DEV)->OUTCLR.reg = 1 << GPIO_8_PIN; - break; -#endif -#if GPIO_9_EN - case GPIO_9: - (&GPIO_9_DEV)->OUTCLR.reg = 1 << GPIO_9_PIN; - break; -#endif -#if GPIO_10_EN - case GPIO_10: - (&GPIO_10_DEV)->OUTCLR.reg = 1 << GPIO_10_PIN; - break; -#endif -#if GPIO_11_EN - case GPIO_11: - (&GPIO_11_DEV)->OUTCLR.reg = 1 << GPIO_11_PIN; - break; -#endif -#if GPIO_12_EN - case GPIO_12: - (&GPIO_12_DEV)->OUTCLR.reg = 1 << GPIO_12_PIN; - break; -#endif -#if GPIO_13_EN - case GPIO_13: - (&GPIO_13_DEV)->OUTCLR.reg = 1 << GPIO_13_PIN; - break; -#endif -#if GPIO_14_EN - case GPIO_14: - (&GPIO_14_DEV)->OUTCLR.reg = 1 << GPIO_14_PIN; - break; -#endif -#if GPIO_15_EN - case GPIO_15: - (&GPIO_15_DEV)->OUTCLR.reg = 1 << GPIO_15_PIN; - break; -#endif - } + _port(pin)->OUTCLR.reg = _pin_mask(pin); } -void gpio_toggle(gpio_t dev) +void gpio_toggle(gpio_t pin) { - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - (&GPIO_0_DEV)->OUTTGL.reg = 1 << GPIO_0_PIN; - break; -#endif -#if GPIO_1_EN - case GPIO_1: - (&GPIO_1_DEV)->OUTTGL.reg = 1 << GPIO_1_PIN; - break; -#endif -#if GPIO_2_EN - case GPIO_2: - (&GPIO_2_DEV)->OUTTGL.reg = 1 << GPIO_2_PIN; - break; -#endif -#if GPIO_3_EN - case GPIO_3: - (&GPIO_3_DEV)->OUTTGL.reg = 1 << GPIO_3_PIN; - break; -#endif -#if GPIO_4_EN - case GPIO_4: - (&GPIO_4_DEV)->OUTTGL.reg = 1 << GPIO_4_PIN; - break; -#endif -#if GPIO_5_EN - case GPIO_5: - (&GPIO_5_DEV)->OUTTGL.reg = 1 << GPIO_5_PIN; - break; -#endif -#if GPIO_6_EN - case GPIO_6: - (&GPIO_6_DEV)->OUTTGL.reg = 1 << GPIO_6_PIN; - break; -#endif -#if GPIO_7_EN - case GPIO_7: - (&GPIO_7_DEV)->OUTTGL.reg = 1 << GPIO_7_PIN; - break; -#endif -#if GPIO_8_EN - case GPIO_8: - (&GPIO_8_DEV)->OUTTGL.reg = 1 << GPIO_8_PIN; - break; -#endif -#if GPIO_9_EN - case GPIO_9: - (&GPIO_9_DEV)->OUTTGL.reg = 1 << GPIO_9_PIN; - break; -#endif -#if GPIO_10_EN - case GPIO_10: - (&GPIO_10_DEV)->OUTTGL.reg = 1 << GPIO_10_PIN; - break; -#endif -#if GPIO_11_EN - case GPIO_11: - (&GPIO_11_DEV)->OUTTGL.reg = 1 << GPIO_11_PIN; - break; -#endif -#if GPIO_12_EN - case GPIO_12: - (&GPIO_12_DEV)->OUTTGL.reg = 1 << GPIO_12_PIN; - break; -#endif -#if GPIO_13_EN - case GPIO_13: - (&GPIO_13_DEV)->OUTTGL.reg = 1 << GPIO_13_PIN; - break; -#endif -#if GPIO_14_EN - case GPIO_14: - (&GPIO_14_DEV)->OUTTGL.reg = 1 << GPIO_14_PIN; - break; -#endif -#if GPIO_15_EN - case GPIO_15: - (&GPIO_15_DEV)->OUTTGL.reg = 1 << GPIO_15_PIN; - break; -#endif - } + _port(pin)->OUTTGL.reg = _pin_mask(pin); } -void gpio_write(gpio_t dev, int value) +void gpio_write(gpio_t pin, int value) { if (value) { - gpio_set(dev); + _port(pin)->OUTSET.reg = _pin_mask(pin); } else { - gpio_clear(dev); + _port(pin)->OUTCLR.reg = _pin_mask(pin); } } void isr_eic(void) { - uint16_t status = EIC->INTFLAG.reg; - for (int i = 0; i < 16; i++) { - if (status & (0x1<INTFLAG.reg & (1 << i)) { + EIC->INTFLAG.reg = (1 << i); gpio_config[i].cb(gpio_config[i].arg); - EIC->INTFLAG.reg = 0x1 << i; } } - if (sched_context_switch_request) { thread_yield(); } } - -#endif /* GPIO_NUMOF */ From 55db7008d81974d594ff00f596a05f213d9837db Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 3 Jun 2015 18:23:26 +0200 Subject: [PATCH 11/33] cpu/nrf51822: remodeled GPIO driver implementation --- cpu/nrf51822/include/periph_cpu.h | 70 ++++++++ cpu/nrf51822/periph/gpio.c | 271 ++++++------------------------ 2 files changed, 117 insertions(+), 224 deletions(-) create mode 100644 cpu/nrf51822/include/periph_cpu.h diff --git a/cpu/nrf51822/include/periph_cpu.h b/cpu/nrf51822/include/periph_cpu.h new file mode 100644 index 000000000000..3fe6ac02b7cb --- /dev/null +++ b/cpu/nrf51822/include/periph_cpu.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup cpu_nrf51822 + * @{ + * + * @file + * @brief CPU specific definitions for handling peripherals + * + * @author Hauke Petersen + */ + +#ifndef CPU_PERIPH_H_ +#define CPU_PERIPH_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Define mandatory GPIO types for NRF51822 CPUs + * @{ + */ +typedef int gpio_t; +typedef int gpio_mux_t; +/** @} */ + +/** + * @brief Override GPIO pull register select values + * @{ + */ +#define HAVE_GPIO_PP_T +typedef enum { + GPIO_NOPULL = 0, /**< do not use internal pull resistors */ + GPIO_PULLUP = 2, /**< enable internal pull-up resistor */ + GPIO_PULLDOWN = 1 /**< enable internal pull-down resistor */ +} gpio_pp_t; +/** @} */ + +/** + * @brief Override GPIO active flank values + * @{ + */ +#define HAVE_GPIO_FLANK_T +typedef enum { + GPIO_FALLING = 2, /**< emit interrupt on falling flank */ + GPIO_RISING = 1, /**< emit interrupt on rising flank */ + GPIO_BOTH = 3 /**< emit interrupt on both flanks */ +} gpio_flank_t; +/** @} */ + +/** + * @brief Mandatory macro for defining GPIO pins + * + * The port definition is used (and zeroed) to suppress compiler warnings + */ +#define GPIO(x,y) ((x & 0) | y) + +#ifdef __cplusplus +} +#endif + +#endif /* CPU_PERIPH_H_ */ +/** @} */ diff --git a/cpu/nrf51822/periph/gpio.c b/cpu/nrf51822/periph/gpio.c index 4182e6a2ab43..00d34c144f11 100644 --- a/cpu/nrf51822/periph/gpio.c +++ b/cpu/nrf51822/periph/gpio.c @@ -1,9 +1,9 @@ /* - * Copyright (C) 2014 Freie Universität Berlin + * Copyright (C) 2015 Freie Universität Berlin * - * This file is subject to the terms and conditions of the GNU Lesser General - * Public License v2.1. See the file LICENSE in the top level directory for more - * details. + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. */ /** @@ -29,269 +29,94 @@ #include "periph/gpio.h" #include "periph_conf.h" -/* guard file in case no GPIO device is defined */ -#if GPIO_NUMOF - +/** + * @brief Datastructure to hold an interrupt context + */ typedef struct { - gpio_t dev; - gpio_cb_t cb; - void *arg; -} gpio_state_t; - -static gpio_state_t gpio_config; + void (*cb)(void *arg); /**< interrupt callback routine */ + void *arg; /**< optional argument */ +} exti_ctx_t; /** - * @brief helper function to get the pin that corresponds to a GPIO device - * - * @param[in] dev the device the returned pin corresponds to - * - * @return the pin number of for the given device - * @return -1 if device unknown + * @brief Place to store the interrupt context */ -static inline int get_pin(gpio_t dev) -{ - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - return GPIO_0_PIN; - break; -#endif -#if GPIO_1_EN - case GPIO_1: - return GPIO_1_PIN; - break; -#endif -#if GPIO_2_EN - case GPIO_2: - return GPIO_2_PIN; - break; -#endif -#if GPIO_3_EN - case GPIO_3: - return GPIO_3_PIN; - break; -#endif -#if GPIO_4_EN - case GPIO_4: - return GPIO_4_PIN; - break; -#endif -#if GPIO_5_EN - case GPIO_5: - return GPIO_5_PIN; - break; -#endif -#if GPIO_6_EN - case GPIO_6: - return GPIO_6_PIN; - break; -#endif -#if GPIO_7_EN - case GPIO_7: - return GPIO_7_PIN; - break; -#endif -#if GPIO_8_EN - case GPIO_8: - return GPIO_8_PIN; - break; -#endif -#if GPIO_9_EN - case GPIO_9: - return GPIO_9_PIN; - break; -#endif -#if GPIO_10_EN - case GPIO_10: - return GPIO_10_PIN; - break; -#endif -#if GPIO_11_EN - case GPIO_11: - return GPIO_11_PIN; - break; -#endif -#if GPIO_12_EN - case GPIO_12: - return GPIO_12_PIN; - break; -#endif -#if GPIO_13_EN - case GPIO_13: - return GPIO_13_PIN; - break; -#endif -#if GPIO_14_EN - case GPIO_14: - return GPIO_14_PIN; - break; -#endif -#if GPIO_15_EN - case GPIO_15: - return GPIO_15_PIN; - break; -#endif - } - - return -1; -} - -int gpio_init_out(gpio_t dev, gpio_pp_t pullup) -{ - int pin = get_pin(dev); - if (pin < 0) { - return pin; - } +static exti_ctx_t exti_chan; - /* configure pin: output, input buffer disabled */ - NRF_GPIO->PIN_CNF[pin] = (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos) | - (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos); - /* configure pull up value, map 0x1 -> 0x2; 0x2 -> 0x1 */ - if (pullup > 0) { - NRF_GPIO->PIN_CNF[pin] |= ((pullup ^ 0x3) << GPIO_PIN_CNF_PULL_Pos); - } - - return 0; -} - -int gpio_init_in(gpio_t dev, gpio_pp_t pullup) +int gpio_init(gpio_t pin, gpio_dir_t dir, gpio_pp_t pullup) { - int pin = get_pin(dev); - if (pin < 0) { - return pin; - } - - /* configure pin: output, input buffer disabled */ - NRF_GPIO->PIN_CNF[pin] = (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | - (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos); - /* configure pull up value, map 0x1 -> 0x2; 0x2 -> 0x1 */ - if (pullup > 0) { - NRF_GPIO->PIN_CNF[pin] |= ((pullup ^ 0x3) << GPIO_PIN_CNF_PULL_Pos); - } - + /* configure pin direction, input buffer and pull resistor state */ + NRF_GPIO->PIN_CNF[pin] = ((dir << GPIO_PIN_CNF_DIR_Pos) | + (dir << GPIO_PIN_CNF_INPUT_Pos) | + (pullup << GPIO_PIN_CNF_PULL_Pos)); return 0; } -int gpio_init_int(gpio_t dev, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb, void *arg) +int gpio_init_int(gpio_t pin, gpio_pp_t pullup, gpio_flank_t flank, + gpio_cb_t cb, void *arg) { - int res; - uint32_t pin; - + /* disable external interrupt in case one is active */ + NRF_GPIOTE->INTENSET &= ~(GPIOTE_INTENSET_IN0_Msk); + /* save callback */ + exti_chan.cb = cb; + exti_chan.arg = arg; /* configure pin as input */ - res = gpio_init_in(dev, pullup); - if (res < 0) { - return res; - } - - /* get pin */ - pin = get_pin(dev); /* no need to check return value, init_in already did */ - + gpio_init(pin, GPIO_DIR_IN, pullup); /* set interrupt priority and enable global GPIOTE interrupt */ - NVIC_SetPriority(GPIOTE_IRQn, GPIO_IRQ_PRIO); NVIC_EnableIRQ(GPIOTE_IRQn); - - /* save callback */ - gpio_config.dev = dev; - gpio_config.cb = cb; - gpio_config.arg = arg; - - /* reset GPIOTE configuration register to EVENT mode*/ - NRF_GPIOTE->CONFIG[0] = GPIOTE_CONFIG_MODE_Event; - - /* select active pin for external interrupt */ - NRF_GPIOTE->CONFIG[0] |= (pin << GPIOTE_CONFIG_PSEL_Pos); - - /* set active flank */ - switch (flank) { - case GPIO_FALLING: - NRF_GPIOTE->CONFIG[0] |= (1 << GPIOTE_CONFIG_POLARITY_Pos); - break; - case GPIO_RISING: - NRF_GPIOTE->CONFIG[0] |= (2 << GPIOTE_CONFIG_POLARITY_Pos); - break; - case GPIO_BOTH: - NRF_GPIOTE->CONFIG[0] |= (3 << GPIOTE_CONFIG_POLARITY_Pos); - break; - } - + /* configure the GPIOTE channel: set even mode, pin and active flank */ + NRF_GPIOTE->CONFIG[0] = (GPIOTE_CONFIG_MODE_Event | + (pin << GPIOTE_CONFIG_PSEL_Pos) | + (flank << GPIOTE_CONFIG_POLARITY_Pos)); /* enable external interrupt */ NRF_GPIOTE->INTENSET |= GPIOTE_INTENSET_IN0_Msk; - return 0; } -void gpio_irq_enable(gpio_t dev) +/* + * the gpio_init_mux function is not defined as it is not needed for this CPU + */ + +void gpio_irq_enable(gpio_t pin) { - if (gpio_config.dev == dev) { - NRF_GPIOTE->INTENSET |= GPIOTE_INTENSET_IN0_Msk; - } + NRF_GPIOTE->INTENSET |= GPIOTE_INTENSET_IN0_Msk; } void gpio_irq_disable(gpio_t dev) { - if (gpio_config.dev == dev) { - NRF_GPIOTE->INTENCLR |= GPIOTE_INTENSET_IN0_Msk; - } + NRF_GPIOTE->INTENCLR |= GPIOTE_INTENSET_IN0_Msk; } -int gpio_read(gpio_t dev) +int gpio_read(gpio_t pin) { - /* get pin */ - int pin = get_pin(dev); - if (pin < 0) { - return pin; - } - - /* read pin value depending if pin is input or output */ - int res; if (NRF_GPIO->DIR & (1 << pin)) { - res = (NRF_GPIO->OUT & (1 << pin)); + return (NRF_GPIO->OUT & (1 << pin)) ? 1 : 0; } else { - res = (NRF_GPIO->IN & (1 << pin)); - } - - /* fix issue with negative number if pin 31 is set */ - if (res < -1) { - res = 1; + return (NRF_GPIO->IN & (1 << pin)) ? 1 : 0; } - - return res; } -void gpio_set(gpio_t dev) +void gpio_set(gpio_t pin) { - int pin = get_pin(dev); - if (pin < 0) { - return; - } NRF_GPIO->OUTSET = (1 << pin); } -void gpio_clear(gpio_t dev) +void gpio_clear(gpio_t pin) { - int pin = get_pin(dev); - if (pin < 0) { - return; - } NRF_GPIO->OUTCLR = (1 << pin); } -void gpio_toggle(gpio_t dev) +void gpio_toggle(gpio_t pin) { - if (gpio_read(dev)) { - gpio_clear(dev); - } else { - gpio_set(dev); - } + NRF_GPIO->OUT ^= (1 << pin); } -void gpio_write(gpio_t dev, int value) +void gpio_write(gpio_t pin, int value) { if (value) { - gpio_set(dev); + NRF_GPIO->OUTSET = (1 << pin); } else { - gpio_clear(dev); + NRF_GPIO->OUTCLR = (1 << pin); } } @@ -300,11 +125,9 @@ void isr_gpiote(void) if (NRF_GPIOTE->EVENTS_IN[0] == 1) { NRF_GPIOTE->EVENTS_IN[0] = 0; - gpio_config.cb(gpio_config.arg); + exti_chan.cb(exti_chan.arg); } if (sched_context_switch_request) { thread_yield(); } } - -#endif /* GPIO_NUMOF */ From 47e8472949a610d7f364966815511c569929383b Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 3 Jun 2015 18:24:08 +0200 Subject: [PATCH 12/33] cpu/cc2538: adjusted to changed GPIO interface --- cpu/cc2538/include/periph_cpu.h | 35 +++++++++++++++++++++++++++++ cpu/cc2538/periph/gpio.c | 40 ++++++++++----------------------- 2 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 cpu/cc2538/include/periph_cpu.h diff --git a/cpu/cc2538/include/periph_cpu.h b/cpu/cc2538/include/periph_cpu.h new file mode 100644 index 000000000000..51264b5d428c --- /dev/null +++ b/cpu/cc2538/include/periph_cpu.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup cpu_cc2538 + * @{ + * + * @file + * @brief CPU specific definitions for internal peripheral handling + * + * @author Hauke Petersen + */ + +#ifndef PERIPH_CPU_H_ +#define PERIPH_CPU_H_ + +#include "periph/dev_enums.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* nothing to do here, yet */ + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CPU_H_ */ +/** @} */ diff --git a/cpu/cc2538/periph/gpio.c b/cpu/cc2538/periph/gpio.c index ce1095513b31..f45e695b9461 100644 --- a/cpu/cc2538/periph/gpio.c +++ b/cpu/cc2538/periph/gpio.c @@ -26,9 +26,6 @@ #include "periph/gpio.h" #include "periph_conf.h" -/* guard file in case no GPIO devices are defined */ -#if GPIO_NUMOF - /** * @brief Generate a bit mask in which only the specified bit is high. * @@ -357,7 +354,7 @@ static const uint32_t ioc_mask_lut[] = { [GPIO_PULLDOWN] = IOC_OVERRIDE_PDE, }; -int gpio_init_out(gpio_t dev, gpio_pp_t pushpull) +int gpio_init(gpio_t dev, gpio_dir_t dir, gpio_pp_t pushpull) { int pin; @@ -367,28 +364,17 @@ int gpio_init_out(gpio_t dev, gpio_pp_t pushpull) pin = pin_lut[dev]; gpio_software_control(pin); - gpio_dir_output(pin); - - /* configure the pin's pull resistor state */ - IOC_PXX_OVER[pin] = IOC_OVERRIDE_OE | ioc_mask_lut[pushpull]; - - return 0; -} -int gpio_init_in(gpio_t dev, gpio_pp_t pushpull) -{ - int pin; - - if (!gpio_enabled(dev)) { - return -1; + if (dir == GPIO_DIR_OUT) { + gpio_dir_output(pin); + /* configure the pin's pull resistor state */ + IOC_PXX_OVER[pin] = IOC_OVERRIDE_OE | ioc_mask_lut[pushpull]; + } + else { + gpio_dir_input(pin); + /* configure the pin's pull resistor state */ + IOC_PXX_OVER[pin] = ioc_mask_lut[pushpull]; } - - pin = pin_lut[dev]; - gpio_software_control(pin); - gpio_dir_input(pin); - - /* configure the pin's pull resistor state */ - IOC_PXX_OVER[pin] = ioc_mask_lut[pushpull]; return 0; } @@ -399,8 +385,8 @@ int gpio_init_int(gpio_t dev, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb uint32_t mask; cc2538_gpio_t* instance; - /* Note: gpio_init_in() also checks if the gpio is enabled. */ - res = gpio_init_in(dev, pullup); + /* Note: gpio_init() also checks if the gpio is enabled. */ + res = gpio_init(dev, GPIO_DIR_IN, pullup); if (res < 0) { return res; } @@ -623,5 +609,3 @@ void isr_gpiod(void) thread_yield(); } } - -#endif /* GPIO_NUMOF */ From d7f659db71c7824d5d5933c6721af76b4fa65c8a Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 3 Jun 2015 18:24:34 +0200 Subject: [PATCH 13/33] cpu/kinetis_common: adjusted to changed GPIO if --- cpu/kinetis_common/gpio.c | 224 +----------------------- cpu/kinetis_common/include/periph_cpu.h | 35 ++++ 2 files changed, 42 insertions(+), 217 deletions(-) create mode 100644 cpu/kinetis_common/include/periph_cpu.h diff --git a/cpu/kinetis_common/gpio.c b/cpu/kinetis_common/gpio.c index f0f34898de40..707df40a56bd 100644 --- a/cpu/kinetis_common/gpio.c +++ b/cpu/kinetis_common/gpio.c @@ -30,8 +30,6 @@ #include "periph/gpio.h" #include "periph_conf.h" -#if GPIO_NUMOF - #define ENABLE_DEBUG (0) #include "debug.h" @@ -181,7 +179,7 @@ static inline void irq_handler(gpio_t dev); */ static gpio_state_t config[GPIO_NUMOF]; -int gpio_init_out(gpio_t dev, gpio_pp_t pushpull) +int gpio_init(gpio_t dev, gpio_dir_t dir, gpio_pp_t pushpull) { switch (dev) { #if GPIO_0_EN @@ -388,220 +386,14 @@ int gpio_init_out(gpio_t dev, gpio_pp_t pushpull) break; } - gpio->PDDR |= GPIO_PDDR_PDD(1 << pin); /* set pin to output mode */ - gpio->PCOR |= GPIO_PCOR_PTCO(1 << pin); /* set output to low */ - /* Select GPIO function for the pin */ - port->PCR[pin] |= PORT_PCR_MUX(PIN_MUX_FUNCTION_GPIO); - - return 0; -} - -int gpio_init_in(gpio_t dev, gpio_pp_t pushpull) -{ - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - GPIO_0_CLKEN(); - break; -#endif -#if GPIO_1_EN - case GPIO_1: - GPIO_1_CLKEN(); - break; -#endif -#if GPIO_2_EN - case GPIO_2: - GPIO_2_CLKEN(); - break; -#endif -#if GPIO_3_EN - - case GPIO_3: - GPIO_3_CLKEN(); - break; -#endif -#if GPIO_4_EN - case GPIO_4: - GPIO_4_CLKEN(); - break; -#endif -#if GPIO_5_EN - case GPIO_5: - GPIO_5_CLKEN(); - break; -#endif -#if GPIO_6_EN - case GPIO_6: - GPIO_6_CLKEN(); - break; -#endif -#if GPIO_7_EN - - case GPIO_7: - GPIO_7_CLKEN(); - break; -#endif -#if GPIO_8_EN - - case GPIO_8: - GPIO_8_CLKEN(); - break; -#endif -#if GPIO_9_EN - - case GPIO_9: - GPIO_9_CLKEN(); - break; -#endif -#if GPIO_10_EN - - case GPIO_10: - GPIO_10_CLKEN(); - break; -#endif -#if GPIO_11_EN - - case GPIO_11: - GPIO_11_CLKEN(); - break; -#endif -#if GPIO_12_EN - - case GPIO_12: - GPIO_12_CLKEN(); - break; -#endif -#if GPIO_13_EN - - case GPIO_13: - GPIO_13_CLKEN(); - break; -#endif -#if GPIO_14_EN - - case GPIO_14: - GPIO_14_CLKEN(); - break; -#endif -#if GPIO_15_EN - - case GPIO_15: - GPIO_15_CLKEN(); - break; -#endif -#if GPIO_16_EN - - case GPIO_16: - GPIO_16_CLKEN(); - break; -#endif -#if GPIO_17_EN - - case GPIO_17: - GPIO_17_CLKEN(); - break; -#endif -#if GPIO_18_EN - - case GPIO_18: - GPIO_18_CLKEN(); - break; -#endif -#if GPIO_19_EN - case GPIO_19: - GPIO_19_CLKEN(); - break; -#endif -#if GPIO_20_EN - case GPIO_20: - GPIO_20_CLKEN(); - break; -#endif -#if GPIO_21_EN - case GPIO_21: - GPIO_21_CLKEN(); - break; -#endif -#if GPIO_22_EN - case GPIO_22: - GPIO_22_CLKEN(); - break; -#endif -#if GPIO_23_EN - case GPIO_23: - GPIO_23_CLKEN(); - break; -#endif -#if GPIO_24_EN - case GPIO_24: - GPIO_24_CLKEN(); - break; -#endif -#if GPIO_25_EN - case GPIO_25: - GPIO_25_CLKEN(); - break; -#endif -#if GPIO_26_EN - case GPIO_26: - GPIO_26_CLKEN(); - break; -#endif -#if GPIO_27_EN - case GPIO_27: - GPIO_27_CLKEN(); - break; -#endif -#if GPIO_28_EN - case GPIO_28: - GPIO_28_CLKEN(); - break; -#endif -#if GPIO_29_EN - case GPIO_29: - GPIO_29_CLKEN(); - break; -#endif -#if GPIO_30_EN - case GPIO_30: - GPIO_30_CLKEN(); - break; -#endif -#if GPIO_31_EN - case GPIO_31: - GPIO_31_CLKEN(); - break; -#endif - default: - return -1; + if (dir == GPIO_DIR_OUT) { + gpio->PDDR |= GPIO_PDDR_PDD(1 << pin); /* set pin to output mode */ + gpio->PCOR |= GPIO_PCOR_PTCO(1 << pin); /* set output to low */ } - - uint8_t pin = kinetis_gpio_lut[dev].pin; - PORT_Type *port = kinetis_gpio_lut[dev].port; - GPIO_Type *gpio = kinetis_gpio_lut[dev].gpio; - - /* Reset all pin control settings for the pin */ - /* Switch to analog input function while fiddling with the settings, to be safe. */ - port->PCR[pin] = PORT_PCR_MUX(PIN_MUX_FUNCTION_ANALOG); - - /* set to push-pull configuration */ - switch (pushpull) { - case GPIO_NOPULL: - break; - - case GPIO_PULLUP: - port->PCR[pin] |= PORT_PCR_PE_MASK | PORT_PCR_PS_MASK; /* Pull enable, pull up */ - break; - - case GPIO_PULLDOWN: - port->PCR[pin] |= PORT_PCR_PE_MASK; /* Pull enable */ - break; - - default: - break; + else { + gpio->PDDR &= ~(GPIO_PDDR_PDD(1 << pin)); /* set pin to input mode */ } - gpio->PDDR &= ~(GPIO_PDDR_PDD(1 << pin)); /* set pin to input mode */ /* Select GPIO function for the pin */ port->PCR[pin] |= PORT_PCR_MUX(PIN_MUX_FUNCTION_GPIO); @@ -612,7 +404,7 @@ int gpio_init_int(gpio_t dev, gpio_pp_t pushpull, gpio_flank_t flank, gpio_cb_t { int res; - res = gpio_init_in(dev, pushpull); + res = gpio_init(dev, GPIO_DIR_IN, pushpull); if (res < 0) { return res; @@ -2084,5 +1876,3 @@ void ISR_PORT_H(void) } #endif /* PORTH_BASE */ - -#endif /* GPIO_NUMOF */ diff --git a/cpu/kinetis_common/include/periph_cpu.h b/cpu/kinetis_common/include/periph_cpu.h new file mode 100644 index 000000000000..ee093418fd58 --- /dev/null +++ b/cpu/kinetis_common/include/periph_cpu.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup cpu_kinetis_common + * @{ + * + * @file + * @brief CPU specific definitions for internal peripheral handling + * + * @author Hauke Petersen + */ + +#ifndef PERIPH_CPU_H_ +#define PERIPH_CPU_H_ + +#include "periph/dev_enums.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* nothing to do here, yet */ + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CPU_H_ */ +/** @} */ From 17c8640708588eaae33fdb0cb0cc9b630d945064 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 3 Jun 2015 18:24:54 +0200 Subject: [PATCH 14/33] cpu/lpc1768: added periph_cpu.h --- cpu/lpc1768/include/periph_cpu.h | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 cpu/lpc1768/include/periph_cpu.h diff --git a/cpu/lpc1768/include/periph_cpu.h b/cpu/lpc1768/include/periph_cpu.h new file mode 100644 index 000000000000..30009438fd18 --- /dev/null +++ b/cpu/lpc1768/include/periph_cpu.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup cpu_lpc1768 + * @{ + * + * @file + * @brief CPU specific definitions for internal peripheral handling + * + * @author Hauke Petersen + */ + +#ifndef PERIPH_CPU_H_ +#define PERIPH_CPU_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* nothing to do here, yet */ + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CPU_H_ */ +/** @} */ From 854730cfa4635cea4fb33362fc35a1c4e0a89aca Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 3 Jun 2015 18:25:13 +0200 Subject: [PATCH 15/33] cpu/sam3x8e: adjusted to changed GPIO interface --- cpu/sam3x8e/include/periph_cpu.h | 35 +++++ cpu/sam3x8e/periph/gpio.c | 242 ++----------------------------- 2 files changed, 47 insertions(+), 230 deletions(-) create mode 100644 cpu/sam3x8e/include/periph_cpu.h diff --git a/cpu/sam3x8e/include/periph_cpu.h b/cpu/sam3x8e/include/periph_cpu.h new file mode 100644 index 000000000000..ebb7b6aad31d --- /dev/null +++ b/cpu/sam3x8e/include/periph_cpu.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup cpu_sam3x8e + * @{ + * + * @file + * @brief CPU specific definitions for internal peripheral handling + * + * @author Hauke Petersen + */ + +#ifndef PERIPH_CPU_H_ +#define PERIPH_CPU_H_ + +#include "periph/dev_enums.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* nothing defined here so far... */ + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CPU_H_ */ +/** @} */ diff --git a/cpu/sam3x8e/periph/gpio.c b/cpu/sam3x8e/periph/gpio.c index 29c87544d457..058161acb96a 100644 --- a/cpu/sam3x8e/periph/gpio.c +++ b/cpu/sam3x8e/periph/gpio.c @@ -27,9 +27,6 @@ #define ENABLE_DEBUG (0) #include "debug.h" -/* guard file in case no GPIO devices are defined */ -#if GPIO_NUMOF - typedef struct { gpio_cb_t cb; /**< callback called from GPIO interrupt */ void *arg; /**< argument passed to the callback */ @@ -37,227 +34,7 @@ typedef struct { static gpio_state_t gpio_config[GPIO_NUMOF]; -int gpio_init_out(gpio_t dev, gpio_pp_t pushpull) -{ - Pio *port = 0; - uint32_t pin = 0; - - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - port = GPIO_0_DEV; - pin = GPIO_0_PIN; - break; -#endif -#if GPIO_1_EN - case GPIO_1: - port = GPIO_1_DEV; - pin = GPIO_1_PIN; - break; -#endif -#if GPIO_2_EN - case GPIO_2: - port = GPIO_2_DEV; - pin = GPIO_2_PIN; - break; -#endif -#if GPIO_3_EN - case GPIO_3: - port = GPIO_3_DEV; - pin = GPIO_3_PIN; - break; -#endif -#if GPIO_4_EN - case GPIO_4: - port = GPIO_4_DEV; - pin = GPIO_4_PIN; - break; -#endif -#if GPIO_5_EN - case GPIO_5: - port = GPIO_5_DEV; - pin = GPIO_5_PIN; - break; -#endif -#if GPIO_6_EN - case GPIO_6: - port = GPIO_6_DEV; - pin = GPIO_6_PIN; - break; -#endif -#if GPIO_7_EN - case GPIO_7: - port = GPIO_7_DEV; - pin = GPIO_7_PIN; - break; -#endif -#if GPIO_8_EN - case GPIO_8: - port = GPIO_8_DEV; - pin = GPIO_8_PIN; - break; -#endif -#if GPIO_9_EN - case GPIO_9: - port = GPIO_9_DEV; - pin = GPIO_9_PIN; - break; -#endif -#if GPIO_10_EN - case GPIO_10: - port = GPIO_10_DEV; - pin = GPIO_10_PIN; - break; -#endif -#if GPIO_11_EN - case GPIO_11: - port = GPIO_11_DEV; - pin = GPIO_11_PIN; - break; -#endif -#if GPIO_12_EN - case GPIO_12: - port = GPIO_12_DEV; - pin = GPIO_12_PIN; - break; -#endif -#if GPIO_13_EN - case GPIO_13: - port = GPIO_13_DEV; - pin = GPIO_13_PIN; - break; -#endif -#if GPIO_14_EN - case GPIO_14: - port = GPIO_14_DEV; - pin = GPIO_14_PIN; - break; -#endif -#if GPIO_15_EN - case GPIO_15: - port = GPIO_15_DEV; - pin = GPIO_15_PIN; - break; -#endif -#if GPIO_16_EN - case GPIO_16: - port = GPIO_16_DEV; - pin = GPIO_16_PIN; - break; -#endif -#if GPIO_17_EN - case GPIO_17: - port = GPIO_17_DEV; - pin = GPIO_17_PIN; - break; -#endif -#if GPIO_18_EN - case GPIO_18: - port = GPIO_18_DEV; - pin = GPIO_18_PIN; - break; -#endif -#if GPIO_19_EN - case GPIO_19: - port = GPIO_19_DEV; - pin = GPIO_19_PIN; - break; -#endif -#if GPIO_20_EN - case GPIO_20: - port = GPIO_20_DEV; - pin = GPIO_20_PIN; - break; -#endif -#if GPIO_21_EN - case GPIO_21: - port = GPIO_21_DEV; - pin = GPIO_21_PIN; - break; -#endif -#if GPIO_22_EN - case GPIO_22: - port = GPIO_22_DEV; - pin = GPIO_22_PIN; - break; -#endif -#if GPIO_23_EN - case GPIO_23: - port = GPIO_23_DEV; - pin = GPIO_23_PIN; - break; -#endif -#if GPIO_24_EN - case GPIO_24: - port = GPIO_24_DEV; - pin = GPIO_24_PIN; - break; -#endif -#if GPIO_25_EN - case GPIO_25: - port = GPIO_25_DEV; - pin = GPIO_25_PIN; - break; -#endif -#if GPIO_26_EN - case GPIO_26: - port = GPIO_26_DEV; - pin = GPIO_26_PIN; - break; -#endif -#if GPIO_27_EN - case GPIO_27: - port = GPIO_27_DEV; - pin = GPIO_27_PIN; - break; -#endif -#if GPIO_28_EN - case GPIO_28: - port = GPIO_28_DEV; - pin = GPIO_28_PIN; - break; -#endif -#if GPIO_29_EN - case GPIO_29: - port = GPIO_29_DEV; - pin = GPIO_29_PIN; - break; -#endif -#if GPIO_30_EN - case GPIO_30: - port = GPIO_30_DEV; - pin = GPIO_30_PIN; - break; -#endif -#if GPIO_31_EN - case GPIO_31: - port = GPIO_31_DEV; - pin = GPIO_31_PIN; - break; -#endif - } - - /* configure pin as output */ - port->PIO_PER = pin; - port->PIO_OER = pin; - port->PIO_CODR = pin; - - /* configure the pin's pull resistor state */ - switch (pushpull) { - case GPIO_PULLDOWN: - return -1; - case GPIO_PULLUP: - port->PIO_PUER = pin; - break; - case GPIO_NOPULL: - port->PIO_PUDR = pin; - break; - } - - return 0; -} - -int gpio_init_in(gpio_t dev, gpio_pp_t pushpull) +int gpio_init(gpio_t dev, gpio_dir_t dir, gpio_pp_t pushpull) { Pio *port = 0; uint32_t pin = 0; @@ -491,9 +268,6 @@ int gpio_init_in(gpio_t dev, gpio_pp_t pushpull) /* give the PIO module the power over the corresponding pin */ port->PIO_PER = pin; - /* configure pin as input */ - port->PIO_ODR = pin; - /* configure the pin's pull resistor state */ switch (pushpull) { case GPIO_PULLDOWN: @@ -505,6 +279,15 @@ int gpio_init_in(gpio_t dev, gpio_pp_t pushpull) port->PIO_PUDR = pin; break; } + if (dir == GPIO_DIR_OUT) { + /* configure pin as output */ + port->PIO_OER = pin; + port->PIO_CODR = pin; + } + else { + /* configure pin as input */ + port->PIO_ODR = pin; + } return 0; } @@ -516,7 +299,7 @@ int gpio_init_int(gpio_t dev, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb uint32_t pin = 0; /* initialize port as input */ - res = gpio_init_in(dev, pullup); + res = gpio_init(dev, GPIO_DIR_IN, pullup); if (res < 0) { return res; } @@ -1543,6 +1326,7 @@ void gpio_irq_disable(gpio_t dev) #endif } } + void gpio_irq_enable(gpio_t dev) { switch (dev) { @@ -2380,5 +2164,3 @@ void isr_piod(void) thread_yield(); } } - -#endif /* GPIO_NUMOF */ From f9bb383118504f1ce7522169ff5c44aa403346f3 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 3 Jun 2015 18:25:42 +0200 Subject: [PATCH 16/33] cpu/stm32f0: adjusted to changed GPIO interface --- cpu/stm32f0/include/periph_cpu.h | 35 ++++++++++++++++++++++++++ cpu/stm32f0/periph/gpio.c | 43 +++++++++----------------------- 2 files changed, 47 insertions(+), 31 deletions(-) create mode 100644 cpu/stm32f0/include/periph_cpu.h diff --git a/cpu/stm32f0/include/periph_cpu.h b/cpu/stm32f0/include/periph_cpu.h new file mode 100644 index 000000000000..f4d650441c52 --- /dev/null +++ b/cpu/stm32f0/include/periph_cpu.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup cpu_stm32f0 + * @{ + * + * @file + * @brief CPU specific definitions for internal peripheral handling + * + * @author Hauke Petersen + */ + +#ifndef PERIPH_CPU_H_ +#define PERIPH_CPU_H_ + +#include "periph/dev_enums.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* nothing to do here, yet */ + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CPU_H_ */ +/** @} */ diff --git a/cpu/stm32f0/periph/gpio.c b/cpu/stm32f0/periph/gpio.c index 7cbd639df630..fdc757a7000c 100644 --- a/cpu/stm32f0/periph/gpio.c +++ b/cpu/stm32f0/periph/gpio.c @@ -24,9 +24,6 @@ #include "periph/gpio.h" #include "periph_conf.h" -/* guard file in case no GPIO devices are defined */ -#if GPIO_NUMOF - typedef struct { gpio_cb_t cb; void *arg; @@ -194,7 +191,7 @@ static const uint8_t gpio_clock_map[GPIO_NUMOF] = { #endif }; -int gpio_init_out(gpio_t dev, gpio_pp_t pullup) +int gpio_init(gpio_t dev, gpio_dir_t dir, gpio_pp_t pullup) { GPIO_TypeDef *port; uint8_t pin; @@ -208,36 +205,22 @@ int gpio_init_out(gpio_t dev, gpio_pp_t pullup) RCC->AHBENR |= (1 << gpio_clock_map[dev]); - port->MODER &= ~(2 << (2 * pin)); /* set pin to output mode */ - port->MODER |= (1 << (2 * pin)); - port->OTYPER &= ~(1 << pin); /* set to push-pull configuration */ - port->OSPEEDR |= (3 << (2 * pin)); /* set to high speed */ port->PUPDR &= ~(3 << (2 * pin)); /* configure push-pull resistors */ port->PUPDR |= (pullup << (2 * pin)); - port->ODR &= ~(1 << pin); /* set pin to low signal */ - - return 0; /* all OK */ -} - -int gpio_init_in(gpio_t dev, gpio_pp_t pullup) -{ - GPIO_TypeDef *port; - uint8_t pin; - if (dev >= GPIO_NUMOF) { - return -1; + if (dir == GPIO_DIR_OUT) { + port->MODER &= ~(2 << (2 * pin)); /* set pin to output mode */ + port->MODER |= (1 << (2 * pin)); + port->OTYPER &= ~(1 << pin); /* set to push-pull configuration */ + port->OSPEEDR |= (3 << (2 * pin)); /* set to high speed */ + port->ODR &= ~(1 << pin); /* set pin to low signal */ } + else { + port->MODER &= ~(3 << (2 * pin)); /* configure pin as input */ - port = gpio_port_map[dev]; - pin = gpio_pin_map[dev]; - - RCC->AHBENR |= (1 << gpio_clock_map[dev]); - - port->MODER &= ~(3 << (2 * pin)); /* configure pin as input */ - port->PUPDR &= ~(3 << (2 * pin)); /* configure push-pull resistors */ - port->PUPDR |= (pullup << (2 * pin)); + } - return 0; /* everything alright here */ + return 0; /* all OK */ } int gpio_init_int(gpio_t dev, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb, void *arg) @@ -252,7 +235,7 @@ int gpio_init_int(gpio_t dev, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb pin = gpio_pin_map[dev]; /* configure pin as input */ - res = gpio_init_in(dev, pullup); + res = gpio_init(dev, GPIO_DIR_IN, pullup); if (res < 0) { return res; } @@ -565,5 +548,3 @@ void isr_exti4_15(void) thread_yield(); } } - -#endif /* GPIO_NUMOF */ From 6284bbbbe4c79e454a1ef716f6fd7d5b235f2638 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 3 Jun 2015 18:26:00 +0200 Subject: [PATCH 17/33] cpu/stm32f1: adjusted to changed GPIO interface --- cpu/stm32f1/include/periph_cpu.h | 35 +++++++ cpu/stm32f1/periph/gpio.c | 175 +++++-------------------------- 2 files changed, 59 insertions(+), 151 deletions(-) create mode 100644 cpu/stm32f1/include/periph_cpu.h diff --git a/cpu/stm32f1/include/periph_cpu.h b/cpu/stm32f1/include/periph_cpu.h new file mode 100644 index 000000000000..fba3e31ad908 --- /dev/null +++ b/cpu/stm32f1/include/periph_cpu.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup cpu_stm32f1 + * @{ + * + * @file + * @brief CPU specific definitions for internal peripheral handling + * + * @author Hauke Petersen + */ + +#ifndef PERIPH_CPU_H_ +#define PERIPH_CPU_H_ + +#include "periph/dev_enums.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* nothing defined here so far... */ + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CPU_H_ */ +/** @} */ diff --git a/cpu/stm32f1/periph/gpio.c b/cpu/stm32f1/periph/gpio.c index 1b1016c1e458..b16c224ad1af 100644 --- a/cpu/stm32f1/periph/gpio.c +++ b/cpu/stm32f1/periph/gpio.c @@ -20,19 +20,16 @@ */ #include "cpu.h" -#include "stm32f10x.h" +#include "board.h" #include "periph/gpio.h" +#include "periph_cpu.h" #include "periph_conf.h" -#include "board.h" - #include "thread.h" +#include "sched.h" #define ENABLE_DEBUG (0) #include "debug.h" -/* guard file in case no GPIO device is defined */ -#if GPIO_NUMOF - typedef struct { gpio_cb_t cb; /**< callback called from GPIO interrupt */ void *arg; /**< argument passed to the callback */ @@ -40,7 +37,7 @@ typedef struct { static gpio_state_t config[GPIO_NUMOF]; -int gpio_init_out(gpio_t dev, gpio_pp_t pullup) +int gpio_init(gpio_t dev, gpio_dir_t dir, gpio_pp_t pullup) { GPIO_TypeDef *port; uint32_t pin; @@ -163,152 +160,30 @@ int gpio_init_out(gpio_t dev, gpio_pp_t pullup) return -1; } - if (pin < 8) { - port->CRL &= ~(0xf << (4 * pin)); - port->CRL |= (0x3 << (4* pin)); /* Output mode, 50 MHz */ - /* general purpose push-pull set implicitly */ - } - else { - port->CRH &= ~(0xf << (4 * (pin-8))); - port->CRH |= (0x3 << (4* (pin-8))); /* Output mode, 50 MHz */ + if (dir == GPIO_DIR_OUT) { + if (pin < 8) { + port->CRL &= ~(0xf << (4 * pin)); + port->CRL |= (0x3 << (4* pin)); /* Output mode, 50 MHz */ /* general purpose push-pull set implicitly */ - } - - return 0; /* all OK */ -} - -int gpio_init_in(gpio_t dev, gpio_pp_t pullup) -{ - GPIO_TypeDef *port; - uint32_t pin; - - switch (dev) { -#if GPIO_0_EN - case GPIO_0: - GPIO_0_CLKEN(); - port = GPIO_0_PORT; - pin = GPIO_0_PIN; - break; -#endif -#if GPIO_1_EN - case GPIO_1: - GPIO_1_CLKEN(); - port = GPIO_1_PORT; - pin = GPIO_1_PIN; - break; -#endif -#if GPIO_2_EN - case GPIO_2: - GPIO_2_CLKEN(); - port = GPIO_2_PORT; - pin = GPIO_2_PIN; - break; -#endif -#if GPIO_3_EN - case GPIO_3: - GPIO_3_CLKEN(); - port = GPIO_3_PORT; - pin = GPIO_3_PIN; - break; -#endif -#if GPIO_4_EN - case GPIO_4: - GPIO_4_CLKEN(); - port = GPIO_4_PORT; - pin = GPIO_4_PIN; - break; -#endif -#if GPIO_5_EN - case GPIO_5: - GPIO_5_CLKEN(); - port = GPIO_5_PORT; - pin = GPIO_5_PIN; - break; -#endif -#if GPIO_6_EN - case GPIO_6: - GPIO_6_CLKEN(); - port = GPIO_6_PORT; - pin = GPIO_6_PIN; - break; -#endif -#if GPIO_7_EN - case GPIO_7: - GPIO_7_CLKEN(); - port = GPIO_7_PORT; - pin = GPIO_7_PIN; - break; -#endif -#if GPIO_8_EN - case GPIO_8: - GPIO_8_CLKEN(); - port = GPIO_8_PORT; - pin = GPIO_8_PIN; - break; -#endif -#if GPIO_9_EN - case GPIO_9: - GPIO_9_CLKEN(); - port = GPIO_9_PORT; - pin = GPIO_9_PIN; - break; -#endif -#if GPIO_10_EN - case GPIO_10: - GPIO_10_CLKEN(); - port = GPIO_10_PORT; - pin = GPIO_10_PIN; - break; -#endif -#if GPIO_11_EN - case GPIO_11: - GPIO_11_CLKEN(); - port = GPIO_11_PORT; - pin = GPIO_11_PIN; - break; -#endif -#if GPIO_12_EN - case GPIO_12: - GPIO_12_CLKEN(); - port = GPIO_12_PORT; - pin = GPIO_12_PIN; - break; -#endif -#if GPIO_13_EN - case GPIO_13: - GPIO_13_CLKEN(); - port = GPIO_13_PORT; - pin = GPIO_13_PIN; - break; -#endif -#if GPIO_14_EN - case GPIO_14: - GPIO_14_CLKEN(); - port = GPIO_14_PORT; - pin = GPIO_14_PIN; - break; -#endif -#if GPIO_15_EN - case GPIO_15: - GPIO_15_CLKEN(); - port = GPIO_15_PORT; - pin = GPIO_15_PIN; - break; -#endif - default: - return -1; - } - - if (pin < 8) { - port->CRL &= ~(0xf << (4 * pin)); - port->CRL |= (0x4 << (4 * pin)); + } + else { + port->CRH &= ~(0xf << (4 * (pin-8))); + port->CRH |= (0x3 << (4* (pin-8))); /* Output mode, 50 MHz */ + /* general purpose push-pull set implicitly */ + } } else { - port->CRL &= ~(0xf << (4 * pin)); - port->CRH |= (0x4 << (4 * (pin-8))); + if (pin < 8) { + port->CRL &= ~(0xf << (4 * pin)); + port->CRL |= (0x4 << (4 * pin)); + } + else { + port->CRL &= ~(0xf << (4 * pin)); + port->CRH |= (0x4 << (4 * (pin-8))); + } } - return 0; /* everything alright here */ + return 0; /* all OK */ } int gpio_init_int(gpio_t dev, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb, void *arg) @@ -318,7 +193,7 @@ int gpio_init_int(gpio_t dev, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb uint8_t gpio_irq; /* configure pin as input */ - res = gpio_init_in(dev, pullup); + res = gpio_init(dev, GPIO_DIR_IN, pullup); if (res < 0) { return res; } @@ -1167,5 +1042,3 @@ void isr_exti15_10(void) } } #endif - -#endif From 480d3c68d8b82bedd96043a10754dfc28345c995 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 3 Jun 2015 18:26:20 +0200 Subject: [PATCH 18/33] cpu/stm32l1: adjusted to changed GPIO interface --- cpu/stm32l1/include/periph_cpu.h | 35 ++++++++++++++++++++++++++ cpu/stm32l1/periph/gpio.c | 43 +++++++++----------------------- 2 files changed, 47 insertions(+), 31 deletions(-) create mode 100644 cpu/stm32l1/include/periph_cpu.h diff --git a/cpu/stm32l1/include/periph_cpu.h b/cpu/stm32l1/include/periph_cpu.h new file mode 100644 index 000000000000..88865f061b53 --- /dev/null +++ b/cpu/stm32l1/include/periph_cpu.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup cpu_stm32l1 + * @{ + * + * @file + * @brief CPU specific definitions for internal peripheral handling + * + * @author Hauke Petersen + */ + +#ifndef PERIPH_CPU_H_ +#define PERIPH_CPU_H_ + +#include "periph/dev_enums.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* nothing defined here, yet */ + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CPU_H_ */ +/** @} */ diff --git a/cpu/stm32l1/periph/gpio.c b/cpu/stm32l1/periph/gpio.c index 5901373c275a..251997dfb24e 100644 --- a/cpu/stm32l1/periph/gpio.c +++ b/cpu/stm32l1/periph/gpio.c @@ -24,9 +24,6 @@ #include "periph/gpio.h" #include "periph_conf.h" -/* guard file in case no GPIO devices are defined */ -#if GPIO_NUMOF - typedef struct { gpio_cb_t cb; void *arg; @@ -190,7 +187,7 @@ static const IRQn_Type gpio_irq_map[GPIO_NUMOF] = { #endif }; -int gpio_init_out(gpio_t dev, gpio_pp_t pullup) +int gpio_init(gpio_t dev, gpio_dir_t dir, gpio_pp_t pullup) { GPIO_TypeDef *port; uint8_t pin; @@ -202,34 +199,20 @@ int gpio_init_out(gpio_t dev, gpio_pp_t pullup) port = gpio_port_map[dev]; pin = gpio_pin_map[dev]; - port->MODER &= ~(2 << (2 * pin)); /* set pin to output mode */ - port->MODER |= (1 << (2 * pin)); - port->OTYPER &= ~(1 << pin); /* set to push-pull configuration */ - port->OSPEEDR |= (3 << (2 * pin)); /* set to high speed */ - port->PUPDR &= ~(3 << (2 * pin)); /* configure push-pull resistors */ - port->PUPDR |= (pullup << (2 * pin)); - port->ODR &= ~(1 << pin); /* set pin to low signal */ - - return 0; /* all OK */ -} - -int gpio_init_in(gpio_t dev, gpio_pp_t pullup) -{ - GPIO_TypeDef *port; - uint8_t pin; - - if (dev >= GPIO_NUMOF) { - return -1; + if (dir == GPIO_DIR_OUT) { + port->MODER &= ~(2 << (2 * pin)); /* set pin to output mode */ + port->MODER |= (1 << (2 * pin)); + port->OTYPER &= ~(1 << pin); /* set to push-pull configuration */ + port->OSPEEDR |= (3 << (2 * pin)); /* set to high speed */ + port->ODR &= ~(1 << pin); /* set pin to low signal */ + } + else { + port->MODER &= ~(3 << (2 * pin)); /* configure pin as input */ } - - port = gpio_port_map[dev]; - pin = gpio_pin_map[dev]; - - port->MODER &= ~(3 << (2 * pin)); /* configure pin as input */ port->PUPDR &= ~(3 << (2 * pin)); /* configure push-pull resistors */ port->PUPDR |= (pullup << (2 * pin)); - return 0; /* everything alright here */ + return 0; /* all OK */ } int gpio_init_int(gpio_t dev, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb, void *arg) @@ -244,7 +227,7 @@ int gpio_init_int(gpio_t dev, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb pin = gpio_pin_map[dev]; /* configure pin as input */ - res = gpio_init_in(dev, pullup); + res = gpio_init(dev, GPIO_DIR_IN, pullup); if (res < 0) { return res; } @@ -583,5 +566,3 @@ void isr_exti15_10(void) } } #endif - -#endif /* GPIO_NUMOF */ From 5abd2ffc0ad92e02552585018d54714d20afdb97 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Fri, 12 Jun 2015 16:30:45 +0200 Subject: [PATCH 19/33] cpu/native: added periph_cpu.h --- cpu/native/include/periph_cpu.h | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 cpu/native/include/periph_cpu.h diff --git a/cpu/native/include/periph_cpu.h b/cpu/native/include/periph_cpu.h new file mode 100644 index 000000000000..4e831a234f4d --- /dev/null +++ b/cpu/native/include/periph_cpu.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup native_cpu + * @{ + * + * @file + * @brief CPU specific definitions for internal peripheral handling + * + * @author Hauke Petersen + */ + +#ifndef PERIPH_CPU_H_ +#define PERIPH_CPU_H_ + +#include "periph/dev_enums.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* nothing defined here so far... */ + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CPU_H_ */ +/** @} */ From 4d34100585e05796cf739fc7284a8b90d3bbe786 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Thu, 4 Jun 2015 12:15:35 +0200 Subject: [PATCH 20/33] cpu/atmega2560: adapted to changed GPIO driver IF --- cpu/atmega2560/include/periph_cpu.h | 35 +++++++++++++++++++++++++++++ cpu/atmega2560/periph/gpio.c | 7 +----- 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 cpu/atmega2560/include/periph_cpu.h diff --git a/cpu/atmega2560/include/periph_cpu.h b/cpu/atmega2560/include/periph_cpu.h new file mode 100644 index 000000000000..f4b1548294c2 --- /dev/null +++ b/cpu/atmega2560/include/periph_cpu.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup cpu_atmega2560 + * @{ + * + * @file + * @brief CPU specific definitions for internal peripheral handling + * + * @author Hauke Petersen + */ + +#ifndef PERIPH_CPU_H_ +#define PERIPH_CPU_H_ + +#include "periph/dev_enums.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* nothing defined here so far... */ + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CPU_H_ */ +/** @} */ diff --git a/cpu/atmega2560/periph/gpio.c b/cpu/atmega2560/periph/gpio.c index 2c81e7d80438..fa634de46daa 100644 --- a/cpu/atmega2560/periph/gpio.c +++ b/cpu/atmega2560/periph/gpio.c @@ -36,12 +36,7 @@ typedef struct { -int gpio_init_out(gpio_t dev, gpio_pp_t pushpull) -{ - return -1; -} - -int gpio_init_in(gpio_t dev, gpio_pp_t pushpull) +int gpio_init(gpio_t dev, gpio_dir_t dir, gpio_pp_t pushpull) { return -1; } From a174b7644a3f3e40942e60d114979149f739c9c2 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 3 Jun 2015 18:27:05 +0200 Subject: [PATCH 21/33] boards: adjusted peripheral confs to GPIO changes --- boards/airfy-beacon/include/periph_conf.h | 43 ------ boards/arduino-due/include/periph_conf.h | 3 +- boards/arduino-mega2560/include/periph_conf.h | 1 - boards/cc2538dk/include/periph_conf.h | 2 - boards/fox/include/periph_conf.h | 1 - boards/iot-lab_M3/include/periph_conf.h | 1 - boards/msbiot/include/board.h | 8 +- boards/msbiot/include/periph_conf.h | 139 ------------------ boards/mulle/board.c | 12 +- boards/mulle/include/periph_conf.h | 1 - boards/nucleo-f091/include/periph_conf.h | 1 - boards/nucleo-f334/include/periph_conf.h | 1 - boards/nucleo-l1/include/periph_conf.h | 1 - boards/openmote/include/periph_conf.h | 1 - boards/pba-d-01-kw2x/include/periph_conf.h | 1 - boards/saml21-xpro/board.c | 2 +- boards/saml21-xpro/include/periph_conf.h | 73 --------- boards/samr21-xpro/include/board.h | 17 ++- boards/samr21-xpro/include/periph_conf.h | 90 ------------ boards/spark-core/include/periph_conf.h | 1 - boards/stm32f0discovery/include/periph_conf.h | 1 - boards/stm32f3discovery/include/periph_conf.h | 1 + boards/stm32f4discovery/include/periph_conf.h | 113 +------------- boards/udoo/include/periph_conf.h | 1 - 24 files changed, 25 insertions(+), 490 deletions(-) diff --git a/boards/airfy-beacon/include/periph_conf.h b/boards/airfy-beacon/include/periph_conf.h index 8ae3cfaa478d..ac21ed602b59 100644 --- a/boards/airfy-beacon/include/periph_conf.h +++ b/boards/airfy-beacon/include/periph_conf.h @@ -133,49 +133,6 @@ #define RADIO_IRQ_PRIO 1 /** @} */ -/** - * @name GPIO configuration - * @{ - */ -#define GPIO_NUMOF (16U) -#define GPIO_0_EN 1 -#define GPIO_1_EN 1 -#define GPIO_2_EN 1 -#define GPIO_3_EN 1 -#define GPIO_4_EN 1 -#define GPIO_5_EN 1 -#define GPIO_6_EN 0 /* not usable */ -#define GPIO_7_EN 1 -#define GPIO_8_EN 1 -#define GPIO_9_EN 1 -#define GPIO_10_EN 1 -#define GPIO_11_EN 1 -#define GPIO_12_EN 1 -#define GPIO_13_EN 1 -#define GPIO_14_EN 1 -#define GPIO_15_EN 1 -#define GPIO_IRQ_PRIO 1 - -/* GPIO pin configuration */ -#define GPIO_0_PIN 0 -#define GPIO_1_PIN 1 -#define GPIO_2_PIN 2 -#define GPIO_3_PIN 3 -#define GPIO_4_PIN 4 -#define GPIO_5_PIN 5 -#define GPIO_6_PIN 6 /* not usable */ -#define GPIO_7_PIN 7 -#define GPIO_8_PIN 8 -#define GPIO_9_PIN 9 -#define GPIO_10_PIN 10 -#define GPIO_11_PIN 11 -#define GPIO_12_PIN 12 -#define GPIO_13_PIN 13 -#define GPIO_14_PIN 14 -#define GPIO_15_PIN 15 - -/** @} */ - #ifdef __cplusplus } /* end extern "C" */ #endif diff --git a/boards/arduino-due/include/periph_conf.h b/boards/arduino-due/include/periph_conf.h index 6d1fa45f28c8..dfb053c06722 100644 --- a/boards/arduino-due/include/periph_conf.h +++ b/boards/arduino-due/include/periph_conf.h @@ -146,7 +146,6 @@ extern "C" { * @name GPIO configuration * @{ */ -#define GPIO_NUMOF (32U) #define GPIO_0_EN 1 #define GPIO_1_EN 1 #define GPIO_2_EN 1 @@ -179,6 +178,8 @@ extern "C" { #define GPIO_29_EN 1 #define GPIO_30_EN 1 #define GPIO_31_EN 1 + +/* interrupt priority */ #define GPIO_IRQ_PRIO 1 /* GPIO channel 0 config */ diff --git a/boards/arduino-mega2560/include/periph_conf.h b/boards/arduino-mega2560/include/periph_conf.h index 351e59f602ae..c41b33273fa7 100644 --- a/boards/arduino-mega2560/include/periph_conf.h +++ b/boards/arduino-mega2560/include/periph_conf.h @@ -264,7 +264,6 @@ extern "C" { /** * @brief GPIO configuration */ -#define GPIO_NUMOF (0U) #define GPIO_0_EN 0 #define GPIO_1_EN 0 #define GPIO_2_EN 0 diff --git a/boards/cc2538dk/include/periph_conf.h b/boards/cc2538dk/include/periph_conf.h index e6d341b5166d..3e8e8dbc8c1f 100644 --- a/boards/cc2538dk/include/periph_conf.h +++ b/boards/cc2538dk/include/periph_conf.h @@ -116,8 +116,6 @@ extern "C" { * @name GPIO configuration * @{ */ -#define GPIO_NUMOF 32 - #define GPIO_IRQ_PRIO 1 #define GPIO_0_EN 1 diff --git a/boards/fox/include/periph_conf.h b/boards/fox/include/periph_conf.h index b20edddd4615..e60df5d80c67 100644 --- a/boards/fox/include/periph_conf.h +++ b/boards/fox/include/periph_conf.h @@ -115,7 +115,6 @@ extern "C" { /** * @brief GPIO configuration */ -#define GPIO_NUMOF 13 #define GPIO_0_EN 1 #define GPIO_1_EN 1 #define GPIO_2_EN 1 diff --git a/boards/iot-lab_M3/include/periph_conf.h b/boards/iot-lab_M3/include/periph_conf.h index 8bb4912c1c42..78ca6696f641 100644 --- a/boards/iot-lab_M3/include/periph_conf.h +++ b/boards/iot-lab_M3/include/periph_conf.h @@ -116,7 +116,6 @@ extern "C" { /** * @brief GPIO configuration */ -#define GPIO_NUMOF 16 #define GPIO_0_EN 1 #define GPIO_1_EN 1 #define GPIO_2_EN 1 diff --git a/boards/msbiot/include/board.h b/boards/msbiot/include/board.h index 843aa751646f..49df2dc98585 100644 --- a/boards/msbiot/include/board.h +++ b/boards/msbiot/include/board.h @@ -45,10 +45,10 @@ extern "C" { * @{ */ #define CC110X_SPI SPI_0 -#define CC110X_CS GPIO_7 -#define CC110X_GDO0 GPIO_11 -#define CC110X_GDO1 GPIO_2 -#define CC110X_GDO2 GPIO_12 +#define CC110X_CS GPIO(PORT_B, 12) +#define CC110X_GDO0 GPIO(PORT_C, 4) +#define CC110X_GDO1 GPIO(PORT_A, 6) +#define CC110X_GDO2 GPIO(PORT_C, 5) typedef uint8_t radio_packet_length_t; /** @} */ diff --git a/boards/msbiot/include/periph_conf.h b/boards/msbiot/include/periph_conf.h index 6135a7f3b8b3..5b1a321a0576 100644 --- a/boards/msbiot/include/periph_conf.h +++ b/boards/msbiot/include/periph_conf.h @@ -252,145 +252,6 @@ extern "C" { #define I2C_0_SDA_AF 4 #define I2C_0_SDA_CLKEN() (RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN) -/** - * @name GPIO configuration - * @{ - */ -#define GPIO_NUMOF 16 -#define GPIO_0_EN 1 -#define GPIO_1_EN 1 -#define GPIO_2_EN 1 -#define GPIO_3_EN 1 -#define GPIO_4_EN 1 -#define GPIO_5_EN 1 -#define GPIO_6_EN 1 -#define GPIO_7_EN 1 -#define GPIO_8_EN 1 -#define GPIO_9_EN 1 -#define GPIO_10_EN 1 -#define GPIO_11_EN 1 -#define GPIO_12_EN 1 -#define GPIO_13_EN 1 -#define GPIO_14_EN 1 -#define GPIO_15_EN 1 -#define GPIO_IRQ_PRIO 1 - -/* IRQ config */ -#define GPIO_IRQ_0 GPIO_0 /* alternatively GPIO_4 or GPIO_9 could be used here */ -#define GPIO_IRQ_1 GPIO_1 /* alternatively GPIO_10 could be used here */ -#define GPIO_IRQ_2 GPIO_15 -#define GPIO_IRQ_3 -1/* not configured */ -#define GPIO_IRQ_4 GPIO_11 -#define GPIO_IRQ_5 GPIO_12 -#define GPIO_IRQ_6 GPIO_2 -#define GPIO_IRQ_7 -1/* not configured */ -#define GPIO_IRQ_8 GPIO_13 -#define GPIO_IRQ_9 GPIO_5 -#define GPIO_IRQ_10 GPIO_3 -#define GPIO_IRQ_11 GPIO_6 -#define GPIO_IRQ_12 GPIO_7 -#define GPIO_IRQ_13 GPIO_8 /* alternatively GPIO_14 could be used here */ -#define GPIO_IRQ_14 -1/* not configured */ -#define GPIO_IRQ_15 -1/* not configured */ - -/* GPIO channel 0 config */ -#define GPIO_0_PORT GPIOA /* User Button 2 */ -#define GPIO_0_PIN 0 -#define GPIO_0_CLK 0 /* 0: PORT A, 1: B ... */ -#define GPIO_0_EXTI_CFG() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI0_PA) -#define GPIO_0_IRQ EXTI0_IRQn -/* GPIO channel 1 config */ -#define GPIO_1_PORT GPIOA -#define GPIO_1_PIN 1 -#define GPIO_1_CLK 0 -#define GPIO_1_EXTI_CFG() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI1_PA) -#define GPIO_1_IRQ EXTI1_IRQn -/* GPIO channel 2 config */ -#define GPIO_2_PORT GPIOA /* CC1101 GDO1 */ -#define GPIO_2_PIN 6 -#define GPIO_2_CLK 0 -#define GPIO_2_EXTI_CFG() (SYSCFG->EXTICR[1] |= SYSCFG_EXTICR2_EXTI6_PA) -#define GPIO_2_IRQ EXTI9_5_IRQn -/* GPIO channel 3 config */ -#define GPIO_3_PORT GPIOA /* CC3000 SPI_IRQ */ -#define GPIO_3_PIN 10 -#define GPIO_3_CLK 0 -#define GPIO_3_EXTI_CFG() (SYSCFG->EXTICR[2] |= SYSCFG_EXTICR3_EXTI10_PA) -#define GPIO_3_IRQ EXTI15_10_IRQn -/* GPIO channel 4 config */ -#define GPIO_4_PORT GPIOB -#define GPIO_4_PIN 0 -#define GPIO_4_CLK 1 -#define GPIO_4_EXTI_CFG() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI0_PB) -#define GPIO_4_IRQ EXTI0_IRQn -/* GPIO channel 5 config */ -#define GPIO_5_PORT GPIOB /* BEEPER Input */ -#define GPIO_5_PIN 9 -#define GPIO_5_CLK 1 -#define GPIO_5_EXTI_CFG() (SYSCFG->EXTICR[2] |= SYSCFG_EXTICR3_EXTI9_PB) -#define GPIO_5_IRQ EXTI9_5_IRQn -/* GPIO channel 6 config */ -#define GPIO_6_PORT GPIOB /* IMU-9150 INT */ -#define GPIO_6_PIN 11 -#define GPIO_6_CLK 1 -#define GPIO_6_EXTI_CFG() (SYSCFG->EXTICR[2] |= SYSCFG_EXTICR3_EXTI11_PB) -#define GPIO_6_IRQ EXTI15_10_IRQn -/* GPIO channel 7 config */ -#define GPIO_7_PORT GPIOB /* CC1101 CS */ -#define GPIO_7_PIN 12 -#define GPIO_7_CLK 1 -#define GPIO_7_EXTI_CFG() (SYSCFG->EXTICR[3] |= SYSCFG_EXTICR4_EXTI12_PB) -#define GPIO_7_IRQ EXTI15_10_IRQn -/* GPIO channel 8 config */ -#define GPIO_8_PORT GPIOB /* User Button 1 */ -#define GPIO_8_PIN 13 -#define GPIO_8_CLK 1 -#define GPIO_8_EXTI_CFG() (SYSCFG->EXTICR[3] |= SYSCFG_EXTICR4_EXTI13_PB) -#define GPIO_8_IRQ EXTI15_10_IRQn -/* GPIO channel 9 config */ -#define GPIO_9_PORT GPIOC /* TCA6416 Reset */ -#define GPIO_9_PIN 0 -#define GPIO_9_CLK 2 -#define GPIO_9_EXTI_CFG() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI0_PC) -#define GPIO_9_IRQ EXTI0_IRQn -/* GPIO channel 10 config */ -#define GPIO_10_PORT GPIOC /* CC3000 CS */ -#define GPIO_10_PIN 1 -#define GPIO_10_CLK 2 -#define GPIO_10_EXTI_CFG() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI1_PC) -#define GPIO_10_IRQ EXTI1_IRQn -/* GPIO channel 11 config */ -#define GPIO_11_PORT GPIOC /* CC1101 GDO 0 */ -#define GPIO_11_PIN 4 -#define GPIO_11_CLK 2 -#define GPIO_11_EXTI_CFG() (SYSCFG->EXTICR[1] |= SYSCFG_EXTICR2_EXTI4_PC) -#define GPIO_11_IRQ EXTI4_IRQn -/* GPIO channel 12 config */ -#define GPIO_12_PORT GPIOC /* CC1101 GDO 2 */ -#define GPIO_12_PIN 5 -#define GPIO_12_CLK 2 -#define GPIO_12_EXTI_CFG() (SYSCFG->EXTICR[1] |= SYSCFG_EXTICR2_EXTI5_PC) -#define GPIO_12_IRQ EXTI9_5_IRQn -/* GPIO channel 13 config */ -#define GPIO_13_PORT GPIOC /* TCA6416 INT */ -#define GPIO_13_PIN 8 -#define GPIO_13_CLK 2 -#define GPIO_13_EXTI_CFG() (SYSCFG->EXTICR[2] |= SYSCFG_EXTICR3_EXTI8_PC) -#define GPIO_13_IRQ EXTI9_5_IRQn -/* GPIO channel 14 config */ -#define GPIO_14_PORT GPIOC /* CC3000 VBAT_SW_EN */ -#define GPIO_14_PIN 13 -#define GPIO_14_CLK 2 -#define GPIO_14_EXTI_CFG() (SYSCFG->EXTICR[3] |= SYSCFG_EXTICR4_EXTI13_PC) -#define GPIO_14_IRQ EXTI15_10_IRQn -/* GPIO channel 15 config */ -#define GPIO_15_PORT GPIOD /* Micro SD Sockel CS */ -#define GPIO_15_PIN 2 -#define GPIO_15_CLK 3 -#define GPIO_15_EXTI_CFG() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI2_PD) -#define GPIO_15_IRQ EXTI2_IRQn -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/mulle/board.c b/boards/mulle/board.c index dbec6acf4a23..bec2290ff824 100644 --- a/boards/mulle/board.c +++ b/boards/mulle/board.c @@ -108,16 +108,16 @@ void board_init(void) static inline void leds_init(void) { /* The pin configuration can be found in board.h and periph_conf.h */ - gpio_init_out(LED_RED_GPIO, GPIO_NOPULL); - gpio_init_out(LED_YELLOW_GPIO, GPIO_NOPULL); - gpio_init_out(LED_GREEN_GPIO, GPIO_NOPULL); + gpio_init(LED_RED_GPIO, GPIO_DIR_OUT, GPIO_NOPULL); + gpio_init(LED_YELLOW_GPIO, GPIO_DIR_OUT, GPIO_NOPULL); + gpio_init(LED_GREEN_GPIO, GPIO_DIR_OUT, GPIO_NOPULL); } static inline void power_pins_init(void) { - gpio_init_out(MULLE_POWER_AVDD, GPIO_NOPULL); - gpio_init_out(MULLE_POWER_VPERIPH, GPIO_NOPULL); - gpio_init_out(MULLE_POWER_VSEC, GPIO_NOPULL); + gpio_init(MULLE_POWER_AVDD, GPIO_DIR_OUT, GPIO_NOPULL); + gpio_init(MULLE_POWER_VPERIPH, GPIO_DIR_OUT, GPIO_NOPULL); + gpio_init(MULLE_POWER_VSEC, GPIO_DIR_OUT, GPIO_NOPULL); gpio_clear(MULLE_POWER_AVDD); gpio_clear(MULLE_POWER_VPERIPH); gpio_clear(MULLE_POWER_VSEC); diff --git a/boards/mulle/include/periph_conf.h b/boards/mulle/include/periph_conf.h index 8b54f4588285..f79e240f5239 100644 --- a/boards/mulle/include/periph_conf.h +++ b/boards/mulle/include/periph_conf.h @@ -468,7 +468,6 @@ extern "C" * @name GPIO configuration * @{ */ -#define GPIO_NUMOF 27 #define GPIO_0_EN 1 #define GPIO_1_EN 1 #define GPIO_2_EN 1 diff --git a/boards/nucleo-f091/include/periph_conf.h b/boards/nucleo-f091/include/periph_conf.h index f0594249077e..7163198442e6 100644 --- a/boards/nucleo-f091/include/periph_conf.h +++ b/boards/nucleo-f091/include/periph_conf.h @@ -92,7 +92,6 @@ extern "C" { * @name GPIO configuration * @{ */ -#define GPIO_NUMOF (6U) #define GPIO_0_EN 1 #define GPIO_1_EN 1 #define GPIO_2_EN 1 diff --git a/boards/nucleo-f334/include/periph_conf.h b/boards/nucleo-f334/include/periph_conf.h index 9168aaf09911..b8609d9a5ec2 100644 --- a/boards/nucleo-f334/include/periph_conf.h +++ b/boards/nucleo-f334/include/periph_conf.h @@ -112,7 +112,6 @@ extern "C" { * @brief GPIO configuration * @{ */ -#define GPIO_NUMOF 3 #define GPIO_0_EN 1 #define GPIO_1_EN 1 #define GPIO_2_EN 1 diff --git a/boards/nucleo-l1/include/periph_conf.h b/boards/nucleo-l1/include/periph_conf.h index 3b25c8f8d553..bcfb064d7fe7 100644 --- a/boards/nucleo-l1/include/periph_conf.h +++ b/boards/nucleo-l1/include/periph_conf.h @@ -102,7 +102,6 @@ extern "C" { /** * @brief GPIO configuration */ -#define GPIO_NUMOF 16 #define GPIO_0_EN 1 #define GPIO_1_EN 1 #define GPIO_2_EN 1 diff --git a/boards/openmote/include/periph_conf.h b/boards/openmote/include/periph_conf.h index 6dc5ab8344ce..22a751dc67e8 100644 --- a/boards/openmote/include/periph_conf.h +++ b/boards/openmote/include/periph_conf.h @@ -106,7 +106,6 @@ * @name GPIO configuration * @{ */ -#define GPIO_NUMOF 12 #define GPIO_0_EN 1 #define GPIO_1_EN 1 #define GPIO_2_EN 1 diff --git a/boards/pba-d-01-kw2x/include/periph_conf.h b/boards/pba-d-01-kw2x/include/periph_conf.h index 11ca5db40f07..ef7a00bc0a12 100644 --- a/boards/pba-d-01-kw2x/include/periph_conf.h +++ b/boards/pba-d-01-kw2x/include/periph_conf.h @@ -303,7 +303,6 @@ extern "C" * @name GPIO configuration * @{ */ -#define GPIO_NUMOF 8 #define GPIO_0_EN 1 #define GPIO_1_EN 1 #define GPIO_2_EN 1 diff --git a/boards/saml21-xpro/board.c b/boards/saml21-xpro/board.c index 326b17aaa45f..e20b6d35f278 100644 --- a/boards/saml21-xpro/board.c +++ b/boards/saml21-xpro/board.c @@ -44,5 +44,5 @@ void board_init(void) */ void led_init(void) { - gpio_init_out(PB10, GPIO_NOPULL); + gpio_init(GPIO(PB,10), GPIO_DIR_OUT, GPIO_NOPULL); } diff --git a/boards/saml21-xpro/include/periph_conf.h b/boards/saml21-xpro/include/periph_conf.h index 37a902d578e1..08317f22cb74 100644 --- a/boards/saml21-xpro/include/periph_conf.h +++ b/boards/saml21-xpro/include/periph_conf.h @@ -103,79 +103,6 @@ extern "C" { #define RTT_NUMOF (1) /** @} */ -/** - * @name GPIO configuration - * @{ - */ - -/* GPIO pin mapping */ -enum { - PA2, /* EXT1 P10, SW0 */ - PB10, /* orange LED */ - PB6, /* EXT1 P05 */ - PA12, /* EXT1 P07 */ - PB4, /* EXT1 P09 */ - PA5, /* EXT1 P15 SPI_SS */ - PA6, /* EXT1 P16 SPI_MOSI */ - PA4, /* EXT1 P17 SPI_MISO */ - PA7, /* EXT1 P18 SPI_SCK */ - GPIO_UNUSED, - PB5, - PA3, - PB7, - PB9, - PA13, -}; - -/* define this to the value of GPIO_UNNUSED. - * Unfortunately the preprocessor can't access the enum's value.*/ -#define GPIO_NUMOF 9 /* same as GPIO_UNUSED */ - -enum { - EXT1_SPI, /* EXT1 -> SPI0 */ -}; - -enum { - EXT1_P07 = PA12, - EXT1_P09 = PB4, - EXT1_P10 = PA2, - EXT1_SPI_SS = PA5, - EXT1_SPI_MOSI = PA6, - EXT1_SPI_MISO = PA4, - EXT1_SPI_SCK = PA7, -}; - -#define GPIO_EXTI0_EN 0 -#define GPIO_EXTI1_EN 0 -#define GPIO_EXTI2_EN 1 /* for PA02/BUTTON0 */ -#define GPIO_EXTI3_EN 0 -#define GPIO_EXTI4_EN 1 /* for PB04 */ -#define GPIO_EXTI5_EN 0 -#define GPIO_EXTI6_EN 0 -#define GPIO_EXTI7_EN 0 -#define GPIO_EXTI8_EN 0 -#define GPIO_EXTI9_EN 0 -#define GPIO_EXTI10_EN 0 -#define GPIO_EXTI11_EN 0 -#define GPIO_EXTI12_EN 1 -#define GPIO_EXTI13_EN 0 -#define GPIO_EXTI14_EN 0 -#define GPIO_EXTI15_EN 0 - -/* defines to satisfy periph/gpio.h - * In order to support GPIO_0..n in applications, you have to define these here. - */ -#define GPIO_0_EN 1 -#define GPIO_1_EN 1 -#define GPIO_2_EN 1 -#define GPIO_3_EN 1 -#define GPIO_4_EN 1 -#define GPIO_5_EN 1 -#define GPIO_6_EN 1 -#define GPIO_7_EN 1 -#define GPIO_8_EN 1 -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/samr21-xpro/include/board.h b/boards/samr21-xpro/include/board.h index 782f4469771d..c7cf676d025b 100644 --- a/boards/samr21-xpro/include/board.h +++ b/boards/samr21-xpro/include/board.h @@ -24,6 +24,7 @@ #include "cpu.h" #include "periph_conf.h" +#include "periph_cpu.h" #ifdef __cplusplus extern "C" { @@ -44,10 +45,10 @@ extern "C" { * @{ */ #define NG_AT86RF233_SPI (SPI_0) -#define NG_AT86RF233_CS (GPIO_4) -#define NG_AT86RF233_INT (GPIO_5) -#define NG_AT86RF233_RESET (GPIO_6) -#define NG_AT86RF233_SLEEP (GPIO_7) +#define NG_AT86RF233_CS GPIO(PB, 31) +#define NG_AT86RF233_INT GPIO(PB, 0) +#define NG_AT86RF233_RESET GPIO(PB, 15) +#define NG_AT86RF233_SLEEP GPIO(PA, 20) #define NG_AT86RF233_SPI_CLK (SPI_SPEED_1MHZ) /** @}*/ @@ -56,10 +57,10 @@ extern "C" { * @{ */ #define AT86RF231_SPI SPI_0 -#define AT86RF231_CS GPIO_4 -#define AT86RF231_INT GPIO_5 -#define AT86RF231_RESET GPIO_6 -#define AT86RF231_SLEEP GPIO_7 +#define AT86RF231_CS GPIO(PB, 31) +#define AT86RF231_INT GPIO(PB, 0) +#define AT86RF231_RESET GPIO(PB, 15) +#define AT86RF231_SLEEP GPIO(PA, 20) #define AT86RF231_SPI_SPEED SPI_SPEED_1MHZ /** @} */ diff --git a/boards/samr21-xpro/include/periph_conf.h b/boards/samr21-xpro/include/periph_conf.h index ef2daf0bcc22..414e0a5c38d2 100644 --- a/boards/samr21-xpro/include/periph_conf.h +++ b/boards/samr21-xpro/include/periph_conf.h @@ -259,96 +259,6 @@ static const pwm_conf_t pwm_config[] = { #define RTT_RUNSTDBY (1) /* Keep RTT running in sleep states */ /** @} */ - -/** - * @name GPIO configuration - * @{ - */ -#define GPIO_NUMOF (9U) -#define GPIO_0_EN 1 -#define GPIO_1_EN 1 -#define GPIO_2_EN 1 -#define GPIO_3_EN 1 -/*4-7 -> internal */ -#define GPIO_4_EN 1 -#define GPIO_5_EN 1 -#define GPIO_6_EN 1 -#define GPIO_7_EN 1 -#define GPIO_8_EN 1 -#define GPIO_9_EN 0 -#define GPIO_10_EN 0 -#define GPIO_11_EN 0 - -#define GPIO_12_EN 0 -#define GPIO_13_EN 0 -#define GPIO_14_EN 0 -#define GPIO_15_EN 0 - -#define GPIO_NO_EXTINT (18) - -/* GPIO channel 0 config */ -#define GPIO_0_DEV PORT->Group[0] -#define GPIO_0_PIN (13) -#define GPIO_0_EXTINT (13) -/* GPIO channel 1 config */ -#define GPIO_1_DEV PORT->Group[0] -#define GPIO_1_PIN (28) -#define GPIO_1_EXTINT (8) -/* GPIO channel 2 config */ -#define GPIO_2_DEV PORT->Group[0] -#define GPIO_2_PIN (15) -#define GPIO_2_EXTINT (15) -/* GPIO channel 3 config */ -#define GPIO_3_DEV PORT->Group[1] -#define GPIO_3_PIN (3) -#define GPIO_3_EXTINT (3) -/* GPIO 4-7 Internal radio pins*/ -/* GPIO channel 4 config radio CS*/ -#define GPIO_4_DEV PORT->Group[1] -#define GPIO_4_PIN (31) -#define GPIO_4_EXTINT GPIO_NO_EXTINT -/* GPIO channel 5 config radio IRQ0*/ -#define GPIO_5_DEV PORT->Group[1] -#define GPIO_5_PIN (0) -#define GPIO_5_EXTINT (0) -/* GPIO channel 6 config radio reset*/ -#define GPIO_6_DEV PORT->Group[1] -#define GPIO_6_PIN (15) -#define GPIO_6_EXTINT GPIO_NO_EXTINT -/* GPIO channel 7 config radio sleep*/ -#define GPIO_7_DEV PORT->Group[0] -#define GPIO_7_PIN (20) -#define GPIO_7_EXTINT GPIO_NO_EXTINT -/* GPIO channel 8 config */ -#define GPIO_8_DEV PORT->Group[0] -#define GPIO_8_PIN (27) -#define GPIO_8_EXTINT GPIO_NO_EXTINT -/* GPIO channel 9 config */ -#define GPIO_9_DEV -#define GPIO_9_PIN -#define GPIO_9_EXTINT -/* GPIO channel 10 config */ -#define GPIO_10_DEV -#define GPIO_10_PIN -#define GPIO_10_EXTINT -/* GPIO channel 11 config */ -#define GPIO_11_DEV -#define GPIO_11_PIN -#define GPIO_11_EXTINT -/* GPIO channel 12 config */ -#define GPIO_12_PIN -#define GPIO_12_EXTINT -/* GPIO channel 13 config */ -#define GPIO_13_PIN -#define GPIO_13_EXTINT -/* GPIO channel 14 config */ -#define GPIO_14_PIN -#define GPIO_14_EXTINT -/* GPIO channel 15 config */ -#define GPIO_15_PIN -#define GPIO_15_EXTINT -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/spark-core/include/periph_conf.h b/boards/spark-core/include/periph_conf.h index a77a1abe80a9..2be755e89ecd 100644 --- a/boards/spark-core/include/periph_conf.h +++ b/boards/spark-core/include/periph_conf.h @@ -99,7 +99,6 @@ /** * @brief GPIO configuration */ -#define GPIO_NUMOF (13U) #define GPIO_0_EN 1 #define GPIO_1_EN 1 #define GPIO_2_EN 1 diff --git a/boards/stm32f0discovery/include/periph_conf.h b/boards/stm32f0discovery/include/periph_conf.h index b9fdc988eca5..57e42657dfa9 100644 --- a/boards/stm32f0discovery/include/periph_conf.h +++ b/boards/stm32f0discovery/include/periph_conf.h @@ -165,7 +165,6 @@ extern "C" { * @name GPIO configuration * @{ */ -#define GPIO_NUMOF 12 #define GPIO_0_EN 1 #define GPIO_1_EN 1 #define GPIO_2_EN 1 diff --git a/boards/stm32f3discovery/include/periph_conf.h b/boards/stm32f3discovery/include/periph_conf.h index 8120902dfa5e..2c346c5ba995 100644 --- a/boards/stm32f3discovery/include/periph_conf.h +++ b/boards/stm32f3discovery/include/periph_conf.h @@ -248,6 +248,7 @@ extern "C" { * @brief GPIO configuration * @{ */ + #define GPIO_NUMOF 12 #define GPIO_0_EN 1 #define GPIO_1_EN 1 diff --git a/boards/stm32f4discovery/include/periph_conf.h b/boards/stm32f4discovery/include/periph_conf.h index 7e29a0686447..ed7ddb29cd7b 100644 --- a/boards/stm32f4discovery/include/periph_conf.h +++ b/boards/stm32f4discovery/include/periph_conf.h @@ -80,6 +80,8 @@ extern "C" { #define UART_IRQ_PRIO 1 #define UART_CLK (14000000U) /* UART clock runs with 14MHz */ + + /* UART 0 device configuration */ #define UART_0_DEV USART2 #define UART_0_CLKEN() (RCC->APB1ENR |= RCC_APB1ENR_USART2EN) @@ -294,117 +296,6 @@ extern "C" { #define I2C_0_SDA_CLKEN() (RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN) /** @} */ -/** - * @name GPIO configuration - * @{ - */ -#define GPIO_NUMOF 12 -#define GPIO_0_EN 1 -#define GPIO_1_EN 1 -#define GPIO_2_EN 1 -#define GPIO_3_EN 1 -#define GPIO_4_EN 1 -#define GPIO_5_EN 1 -#define GPIO_6_EN 1 -#define GPIO_7_EN 1 -#define GPIO_8_EN 1 -#define GPIO_9_EN 1 -#define GPIO_10_EN 1 -#define GPIO_11_EN 1 -#define GPIO_IRQ_PRIO 1 - -/* IRQ config */ -#define GPIO_IRQ_0 GPIO_0 /* alternatively GPIO_1 could be used here */ -#define GPIO_IRQ_1 GPIO_2 -#define GPIO_IRQ_2 GPIO_3 -#define GPIO_IRQ_3 GPIO_4 -#define GPIO_IRQ_4 GPIO_5 -#define GPIO_IRQ_5 GPIO_6 -#define GPIO_IRQ_6 GPIO_7 -#define GPIO_IRQ_7 GPIO_8 -#define GPIO_IRQ_8 GPIO_9 -#define GPIO_IRQ_9 GPIO_10 -#define GPIO_IRQ_10 GPIO_11 -#define GPIO_IRQ_11 -1/* not configured */ -#define GPIO_IRQ_12 -1/* not configured */ -#define GPIO_IRQ_13 -1/* not configured */ -#define GPIO_IRQ_14 -1/* not configured */ -#define GPIO_IRQ_15 -1/* not configured */ - -/* GPIO channel 0 config */ -#define GPIO_0_PORT GPIOA /* Used for user button 1 */ -#define GPIO_0_PIN 0 -#define GPIO_0_CLK 0 /* 0: PORT A, 1: B ... */ -#define GPIO_0_EXTI_CFG() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI0_PA) -#define GPIO_0_IRQ EXTI0_IRQn -/* GPIO channel 1 config */ -#define GPIO_1_PORT GPIOE /* LIS302DL INT1 */ -#define GPIO_1_PIN 0 -#define GPIO_1_CLK 4 -#define GPIO_1_EXTI_CFG() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI0_PE) -#define GPIO_1_IRQ EXTI0_IRQn -/* GPIO channel 2 config */ -#define GPIO_2_PORT GPIOE /* LIS302DL INT2 */ -#define GPIO_2_PIN 1 -#define GPIO_2_CLK 4 -#define GPIO_2_EXTI_CFG() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI1_PE) -#define GPIO_2_IRQ EXTI1_IRQn -/* GPIO channel 3 config */ -#define GPIO_3_PORT GPIOE -#define GPIO_3_PIN 2 -#define GPIO_3_CLK 4 -#define GPIO_3_EXTI_CFG() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI2_PE) -#define GPIO_3_IRQ EXTI2_IRQn -/* GPIO channel 4 config */ -#define GPIO_4_PORT GPIOE /* LIS302DL CS */ -#define GPIO_4_PIN 3 -#define GPIO_4_CLK 4 -#define GPIO_4_EXTI_CFG() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI3_PE) -#define GPIO_4_IRQ EXTI3_IRQn -/* GPIO channel 5 config */ -#define GPIO_5_PORT GPIOD /* CS43L22 RESET */ -#define GPIO_5_PIN 4 -#define GPIO_5_CLK 3 -#define GPIO_5_EXTI_CFG() (SYSCFG->EXTICR[1] |= SYSCFG_EXTICR2_EXTI4_PD) -#define GPIO_5_IRQ EXTI4_IRQn -/* GPIO channel 6 config */ -#define GPIO_6_PORT GPIOD /* LD8 */ -#define GPIO_6_PIN 5 -#define GPIO_6_CLK 3 -#define GPIO_6_EXTI_CFG() (SYSCFG->EXTICR[1] |= SYSCFG_EXTICR2_EXTI5_PD) -#define GPIO_6_IRQ EXTI9_5_IRQn -/* GPIO channel 7 config */ -#define GPIO_7_PORT GPIOD -#define GPIO_7_PIN 6 -#define GPIO_7_CLK 3 -#define GPIO_7_EXTI_CFG() (SYSCFG->EXTICR[1] |= SYSCFG_EXTICR2_EXTI6_PD) -#define GPIO_7_IRQ EXTI9_5_IRQn -/* GPIO channel 8 config */ -#define GPIO_8_PORT GPIOD -#define GPIO_8_PIN 7 -#define GPIO_8_CLK 3 -#define GPIO_8_EXTI_CFG() (SYSCFG->EXTICR[1] |= SYSCFG_EXTICR2_EXTI7_PD) -#define GPIO_8_IRQ EXTI9_5_IRQn -/* GPIO channel 9 config */ -#define GPIO_9_PORT GPIOA -#define GPIO_9_PIN 8 -#define GPIO_9_CLK 0 -#define GPIO_9_EXTI_CFG() (SYSCFG->EXTICR[2] |= SYSCFG_EXTICR3_EXTI8_PA) -#define GPIO_9_IRQ EXTI9_5_IRQn -/* GPIO channel 10 config */ -#define GPIO_10_PORT GPIOA /* LD7 */ -#define GPIO_10_PIN 9 -#define GPIO_10_CLK 0 -#define GPIO_10_EXTI_CFG() (SYSCFG->EXTICR[2] |= SYSCFG_EXTICR3_EXTI9_PA) -#define GPIO_10_IRQ EXTI9_5_IRQn -/* GPIO channel 11 config */ -#define GPIO_11_PORT GPIOD -#define GPIO_11_PIN 10 -#define GPIO_11_CLK 3 -#define GPIO_11_EXTI_CFG() (SYSCFG->EXTICR[2] |= SYSCFG_EXTICR3_EXTI10_PD) -#define GPIO_11_IRQ EXTI15_10_IRQn -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/udoo/include/periph_conf.h b/boards/udoo/include/periph_conf.h index 5c49bf3adc88..bd80fefcfdb6 100644 --- a/boards/udoo/include/periph_conf.h +++ b/boards/udoo/include/periph_conf.h @@ -146,7 +146,6 @@ extern "C" { * @name GPIO configuration * @{ */ -#define GPIO_NUMOF (32U) #define GPIO_0_EN 1 #define GPIO_1_EN 1 #define GPIO_2_EN 1 From 6994a1d4ec056d6ef6017331a95b63420262fd6b Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Sun, 14 Jun 2015 13:01:18 +0200 Subject: [PATCH 22/33] test/periph_spi: adjusted to GPIO driver changes --- tests/periph_spi/main.c | 42 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/periph_spi/main.c b/tests/periph_spi/main.c index cfb426a32f14..790980a6f4ff 100644 --- a/tests/periph_spi/main.c +++ b/tests/periph_spi/main.c @@ -38,7 +38,7 @@ enum { } rw; static int spi_dev = -1; -static int spi_cs = -1; +static gpio_t spi_cs = -1; static int spi_mode = -1; static int spi_speed = -1; static int spi_master = -1; /* 0 for slave, 1 for master, -1 for not initialized */ @@ -48,31 +48,33 @@ static char rx_buffer[256]; /* global receive buffer */ static int rx_counter = 0; static volatile int state; -static char* mem = "Hello Master! abcdefghijklmnopqrstuvwxyz 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +static char* mem = "Hello Master! abcdefghijklmnopqrstuvwxyz 0123456789 " + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int parse_spi_dev(int argc, char **argv) { /* reset default values */ + int port, pin; spi_dev = SPI_0; spi_mode = SPI_CONF_FIRST_RISING; spi_speed = SPI_SPEED_1MHZ; - if (argc < 3 || argc > 5) { - printf("usage: %s DEV CS [MODE [SPEED]]\n", argv[0]); + if (argc < 4) { + printf("usage: %s [mode [speed]]\n", argv[0]); puts(" DEV is the SPI device to use:"); for (int i = 0; i < SPI_NUMOF; i++) { printf(" %i - SPI_%i\n", i, i); } - puts(" CS is the GPIO used for the chip-select signal:"); - for (int i = 0; i < GPIO_NUMOF; i++) { - printf(" %i - GPIO_%i\n", i, i); - } - puts(" MODE must be one of the following options (* marks default value):"); + puts(" cs port: port to use as the chip select line"); + puts(" cs pin: pin to use on th given port as cs line"); + puts(" mode: must be one of the following options (* marks " + "default value):"); puts(" *0 - POL:0, PHASE:0 - ON FIRST RISING EDGE"); puts(" 1 - POL:0, PHASE:1 - ON SECOND RISING EDGE"); puts(" 2 - POL:1, PHASE:0 - ON FIRST FALLING EDGE"); puts(" 3 - POL:1, PHASE:1 - on second falling edge"); - puts(" SPEED must be one of the following options (only used in master mode):"); + puts(" speed: must be one of the following options (only used " + "in master mode):"); puts(" 0 - 100 KHz"); puts(" 1 - 400 KHz"); puts(" *2 - 1 MHz"); @@ -85,20 +87,18 @@ int parse_spi_dev(int argc, char **argv) puts("error: invalid DEV value given"); return -1; } - spi_cs = atoi(argv[2]); - if (spi_dev < 0 || spi_dev >= GPIO_NUMOF) { - puts("error: invalid CS value given"); - return -1; - } - if (argc >= 4) { - spi_mode = argv[3][0] - '0'; + port = atoi(argv[2]); + pin = atoi(argv[3]); + spi_cs = GPIO(port,pin); + if (argc >= 5) { + spi_mode = argv[4][0] - '0'; if (spi_mode < 0 || spi_mode > 3) { puts("error: invalid MODE value given"); return -2; } } - if (argc >= 5) { - spi_speed = argv[4][0] - '0'; + if (argc >= 6) { + spi_speed = argv[5][0] - '0'; if (spi_speed < 0 || spi_speed > 4) { puts("error: invalid SPEED value given"); return -3; @@ -211,9 +211,9 @@ int cmd_init_slave(int argc, char **argv) printf("spi_init_slave: error initializing SPI_%i device (code: %i)\n", spi_dev, res); return 1; } - res = gpio_init_exti(spi_cs, GPIO_NOPULL, GPIO_FALLING, slave_on_cs, 0); + res = gpio_init_int(spi_cs, GPIO_NOPULL, GPIO_FALLING, slave_on_cs, 0); if (res < 0){ - printf("gpio_init_exti: error initializing GPIO_%i as CS line (code %i)\n", spi_cs, res); + printf("gpio_init_int: error initializing GPIO_%i as CS line (code %i)\n", spi_cs, res); return 1; } spi_master = 0; From 24c85bbbe1b7d2e9e7a3eaea47cad48ba1064d72 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Sun, 14 Jun 2015 16:04:02 +0200 Subject: [PATCH 23/33] test/driver_xbee: removed obsolete auto_init file --- .../auto_init_ng_netif/netif_app.c | 77 ------------------- 1 file changed, 77 deletions(-) delete mode 100644 tests/driver_xbee/auto_init_ng_netif/netif_app.c diff --git a/tests/driver_xbee/auto_init_ng_netif/netif_app.c b/tests/driver_xbee/auto_init_ng_netif/netif_app.c deleted file mode 100644 index 90cf1bfadeb4..000000000000 --- a/tests/driver_xbee/auto_init_ng_netif/netif_app.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2015 Freie Universität Berlin - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup tests - * @{ - * - * @file - * @brief Xbee device initialization - * - * @author Hauke Petersen - * - * @} - */ - -#include - -#include "kernel.h" -#include "xbee.h" -#include "net/ng_nomac.h" -#include "net/ng_netbase.h" - -/* make sure an UART to device is defined in the Makefile */ -#ifndef XBEE_UART -#error "XBEE_UART not defined" -#endif - -/** - * @brief This is the default baudrate the Xbee modules are programmed to - * when you buy them - */ -#define XBEE_BAUDRATE (9600U) - -/** - * @brief MAC layer stack configuration - * @{ - */ -#define STACKSIZE (THREAD_STACKSIZE_DEFAULT) -#define PRIO (0) -/** @} */ - -/** - * @brief The Xbee device descriptor - */ -static xbee_t dev; - -/** - * @brief Stack for the nomac thread - */ -static char nomac_stack[STACKSIZE]; - - -void auto_init_ng_netif(void) -{ - int res; - kernel_pid_t iface; - - /* setup Xbee device */ - printf("Initializing the Xbee S1 device UART_%i... \n", XBEE_UART); - res = xbee_init(&dev, XBEE_UART, XBEE_BAUDRATE, GPIO_NUMOF, GPIO_NUMOF); - if (res < 0) { - puts("Error initializing xbee device driver"); - return; - } - /* start MAC layer */ - iface = ng_nomac_init(nomac_stack, sizeof(nomac_stack), PRIO, "xbee", - (ng_netdev_t *)(&dev)); - if (iface <= KERNEL_PID_UNDEF) { - puts("Error initializing MAC layer"); - return; - } -} From 6698a019589ea0ac6be74bee811d2f4d4508df2c Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Sun, 14 Jun 2015 16:11:19 +0200 Subject: [PATCH 24/33] boards: removed obsolete GPIO defines - touched pca10000, pca10005, stm32f3discovery, yunjia-nrf51822 --- boards/pca10000/include/periph_conf.h | 42 ------ boards/pca10005/include/periph_conf.h | 42 ------ boards/stm32f3discovery/include/periph_conf.h | 125 ------------------ boards/yunjia-nrf51822/include/periph_conf.h | 26 ---- 4 files changed, 235 deletions(-) diff --git a/boards/pca10000/include/periph_conf.h b/boards/pca10000/include/periph_conf.h index 9b1fee932d0b..851dbf95acb8 100644 --- a/boards/pca10000/include/periph_conf.h +++ b/boards/pca10000/include/periph_conf.h @@ -121,48 +121,6 @@ extern "C" { #define RADIO_IRQ_PRIO 1 /** @} */ -/** - * @name GPIO configuration - * @{ - */ -#define GPIO_NUMOF 16 -#define GPIO_0_EN 1 -#define GPIO_1_EN 1 -#define GPIO_2_EN 1 -#define GPIO_3_EN 1 -#define GPIO_4_EN 1 -#define GPIO_5_EN 1 -#define GPIO_6_EN 1 -#define GPIO_7_EN 1 -#define GPIO_8_EN 1 -#define GPIO_9_EN 1 -#define GPIO_10_EN 1 -#define GPIO_11_EN 1 -#define GPIO_12_EN 1 -#define GPIO_13_EN 1 -#define GPIO_14_EN 1 -#define GPIO_15_EN 1 -#define GPIO_IRQ_PRIO 1 - -/* GPIO pin configuration */ -#define GPIO_0_PIN 0 -#define GPIO_1_PIN 1 -#define GPIO_2_PIN 2 -#define GPIO_3_PIN 3 -#define GPIO_4_PIN 4 -#define GPIO_5_PIN 5 -#define GPIO_6_PIN 6 -#define GPIO_7_PIN 7 -#define GPIO_8_PIN 8 -#define GPIO_9_PIN 9 -#define GPIO_10_PIN 10 -#define GPIO_11_PIN 11 -#define GPIO_12_PIN 12 -#define GPIO_13_PIN 13 -#define GPIO_14_PIN 14 -#define GPIO_15_PIN 15 -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/pca10005/include/periph_conf.h b/boards/pca10005/include/periph_conf.h index d935a6069c49..502c0704026f 100644 --- a/boards/pca10005/include/periph_conf.h +++ b/boards/pca10005/include/periph_conf.h @@ -140,48 +140,6 @@ extern "C" { #define RADIO_IRQ_PRIO 1 /** @} */ -/** - * @name GPIO configuration - * @{ - */ -#define GPIO_NUMOF 16 -#define GPIO_0_EN 1 -#define GPIO_1_EN 1 -#define GPIO_2_EN 1 -#define GPIO_3_EN 1 -#define GPIO_4_EN 1 -#define GPIO_5_EN 1 -#define GPIO_6_EN 1 -#define GPIO_7_EN 1 -#define GPIO_8_EN 1 -#define GPIO_9_EN 1 -#define GPIO_10_EN 1 -#define GPIO_11_EN 1 -#define GPIO_12_EN 1 -#define GPIO_13_EN 1 -#define GPIO_14_EN 1 -#define GPIO_15_EN 1 -#define GPIO_IRQ_PRIO 1 - -/* GPIO pin configuration */ -#define GPIO_0_PIN 0 -#define GPIO_1_PIN 1 -#define GPIO_2_PIN 2 -#define GPIO_3_PIN 3 -#define GPIO_4_PIN 4 -#define GPIO_5_PIN 5 -#define GPIO_6_PIN 6 -#define GPIO_7_PIN 7 -#define GPIO_8_PIN 8 -#define GPIO_9_PIN 9 -#define GPIO_10_PIN 10 -#define GPIO_11_PIN 11 -#define GPIO_12_PIN 12 -#define GPIO_13_PIN 13 -#define GPIO_14_PIN 14 -#define GPIO_15_PIN 15 -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/stm32f3discovery/include/periph_conf.h b/boards/stm32f3discovery/include/periph_conf.h index 2c346c5ba995..b7f5ed86c36b 100644 --- a/boards/stm32f3discovery/include/periph_conf.h +++ b/boards/stm32f3discovery/include/periph_conf.h @@ -244,131 +244,6 @@ extern "C" { #define I2C_1_SDA_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOFEN) /** @} */ -/** - * @brief GPIO configuration - * @{ - */ - -#define GPIO_NUMOF 12 -#define GPIO_0_EN 1 -#define GPIO_1_EN 1 -#define GPIO_2_EN 1 -#define GPIO_3_EN 1 -#define GPIO_4_EN 1 -#define GPIO_5_EN 1 -#define GPIO_6_EN 1 -#define GPIO_7_EN 1 -#define GPIO_8_EN 1 -#define GPIO_9_EN 1 -#define GPIO_10_EN 1 -#define GPIO_11_EN 1 -#define GPIO_IRQ_PRIO 1 - -/* IRQ config */ -#define GPIO_IRQ_0 GPIO_11 /* alternatively GPIO_4 could be used here */ -#define GPIO_IRQ_1 GPIO_5 -#define GPIO_IRQ_2 GPIO_0 -#define GPIO_IRQ_3 GPIO_3 -#define GPIO_IRQ_4 GPIO_1 -#define GPIO_IRQ_5 GPIO_2 -#define GPIO_IRQ_6 (-1) /* not configured */ -#define GPIO_IRQ_7 (-1) /* not configured */ -#define GPIO_IRQ_8 (-1) /* not configured */ -#define GPIO_IRQ_9 (-1) /* not configured */ -#define GPIO_IRQ_10 (-1) /* not configured */ -#define GPIO_IRQ_11 GPIO_6 -#define GPIO_IRQ_12 GPIO_7 -#define GPIO_IRQ_13 GPIO_8 -#define GPIO_IRQ_14 GPIO_9 -#define GPIO_IRQ_15 GPIO_10 - -/* GPIO channel 0 config */ -#define GPIO_0_PORT GPIOE /* LSM303DLHC -> DRDY */ -#define GPIO_0_PIN 2 -#define GPIO_0_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOEEN) -#define GPIO_0_EXTI_CFG1() (SYSCFG->EXTICR[0] &= ~(SYSCFG_EXTICR1_EXTI2)) -#define GPIO_0_EXTI_CFG2() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI2_PE) -#define GPIO_0_IRQ EXTI2_TSC_IRQn - -/* GPIO channel 1 config */ -#define GPIO_1_PORT GPIOE /* LSM303DLHC -> INT1 */ -#define GPIO_1_PIN 4 -#define GPIO_1_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOEEN) -#define GPIO_1_EXTI_CFG1() (SYSCFG->EXTICR[1] &= ~(SYSCFG_EXTICR2_EXTI4)) -#define GPIO_1_EXTI_CFG2() (SYSCFG->EXTICR[1] |= SYSCFG_EXTICR2_EXTI4_PE) -#define GPIO_1_IRQ EXTI4_IRQn -/* GPIO channel 2 config */ -#define GPIO_2_PORT GPIOE /* LSM303DLHC -> INT2 */ -#define GPIO_2_PIN 5 -#define GPIO_2_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOEEN) -#define GPIO_2_EXTI_CFG1() (SYSCFG->EXTICR[1] &= ~(SYSCFG_EXTICR2_EXTI5)) -#define GPIO_2_EXTI_CFG2() (SYSCFG->EXTICR[1] |= SYSCFG_EXTICR2_EXTI5_PE) -#define GPIO_2_IRQ EXTI9_5_IRQn -/* GPIO channel 3 config */ -#define GPIO_3_PORT GPIOE /* L2GD20 -> CS */ -#define GPIO_3_PIN 3 -#define GPIO_3_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOEEN) -#define GPIO_3_EXTI_CFG1() (SYSCFG->EXTICR[0] &= ~(SYSCFG_EXTICR1_EXTI3)) -#define GPIO_3_EXTI_CFG2() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI3_PE) -#define GPIO_3_IRQ EXTI3_IRQn -/* GPIO channel 4 config */ -#define GPIO_4_PORT GPIOE /* L2GD20 -> INT1 */ -#define GPIO_4_PIN 0 -#define GPIO_4_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOEEN) -#define GPIO_4_EXTI_CFG1() (SYSCFG->EXTICR[0] &= ~(SYSCFG_EXTICR1_EXTI0)) -#define GPIO_4_EXTI_CFG2() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI0_PE) -#define GPIO_4_IRQ EXTI0_IRQn -/* GPIO channel 5 config */ -#define GPIO_5_PORT GPIOE /* L2GD20 -> INT2/DRDY */ -#define GPIO_5_PIN 1 -#define GPIO_5_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOEEN) -#define GPIO_5_EXTI_CFG1() (SYSCFG->EXTICR[0] &= ~(SYSCFG_EXTICR1_EXTI1)) -#define GPIO_5_EXTI_CFG2() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI1_PE) -#define GPIO_5_IRQ EXTI1_IRQn -/* GPIO channel 6 config */ -#define GPIO_6_PORT GPIOB -#define GPIO_6_PIN 11 -#define GPIO_6_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOBEN) -#define GPIO_6_EXTI_CFG1() (SYSCFG->EXTICR[2] &= ~(SYSCFG_EXTICR3_EXTI11)) -#define GPIO_6_EXTI_CFG2() (SYSCFG->EXTICR[2] |= SYSCFG_EXTICR3_EXTI11_PB) -#define GPIO_6_IRQ EXTI15_10_IRQn -/* GPIO channel 7 config */ -#define GPIO_7_PORT GPIOB -#define GPIO_7_PIN 12 -#define GPIO_7_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOBEN) -#define GPIO_7_EXTI_CFG1() (SYSCFG->EXTICR[3] &= ~(SYSCFG_EXTICR4_EXTI12)) -#define GPIO_7_EXTI_CFG2() (SYSCFG->EXTICR[3] |= SYSCFG_EXTICR4_EXTI12_PB) -#define GPIO_7_IRQ EXTI15_10_IRQn -/* GPIO channel 8 config */ -#define GPIO_8_PORT GPIOB -#define GPIO_8_PIN 13 -#define GPIO_8_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOBEN) -#define GPIO_8_EXTI_CFG1() (SYSCFG->EXTICR[3] &= ~(SYSCFG_EXTICR4_EXTI13)) -#define GPIO_8_EXTI_CFG2() (SYSCFG->EXTICR[3] |= SYSCFG_EXTICR4_EXTI13_PB) -#define GPIO_8_IRQ EXTI15_10_IRQn -/* GPIO channel 9 config */ -#define GPIO_9_PORT GPIOB -#define GPIO_9_PIN 14 -#define GPIO_9_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOBEN) -#define GPIO_9_EXTI_CFG1() (SYSCFG->EXTICR[3] &= ~(SYSCFG_EXTICR4_EXTI14)) -#define GPIO_9_EXTI_CFG2() (SYSCFG->EXTICR[3] |= SYSCFG_EXTICR4_EXTI14_PB) -#define GPIO_9_IRQ EXTI15_10_IRQn -/* GPIO channel 10 config */ -#define GPIO_10_PORT GPIOB -#define GPIO_10_PIN 15 -#define GPIO_10_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOBEN) -#define GPIO_10_EXTI_CFG1() (SYSCFG->EXTICR[3] &= ~(SYSCFG_EXTICR4_EXTI15)) -#define GPIO_10_EXTI_CFG2() (SYSCFG->EXTICR[3] |= SYSCFG_EXTICR4_EXTI15_PB) -#define GPIO_10_IRQ EXTI15_10_IRQn -/* GPIO channel 11 config */ -#define GPIO_11_PORT GPIOA /* User button 1 */ -#define GPIO_11_PIN 0 -#define GPIO_11_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOAEN) -#define GPIO_11_EXTI_CFG1() (SYSCFG->EXTICR[0] &= ~(SYSCFG_EXTICR1_EXTI0)) -#define GPIO_11_EXTI_CFG2() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI0_PA) -#define GPIO_11_IRQ EXTI0_IRQn -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/yunjia-nrf51822/include/periph_conf.h b/boards/yunjia-nrf51822/include/periph_conf.h index d4144a17b81a..f32d3a631911 100644 --- a/boards/yunjia-nrf51822/include/periph_conf.h +++ b/boards/yunjia-nrf51822/include/periph_conf.h @@ -138,32 +138,6 @@ extern "C" { #define RADIO_IRQ_PRIO 1 /** @} */ -/** - * @name GPIO configuration - * @{ - */ -#define GPIO_NUMOF (8U) -#define GPIO_0_EN 1 -#define GPIO_1_EN 1 -#define GPIO_2_EN 1 -#define GPIO_3_EN 1 -#define GPIO_4_EN 1 -#define GPIO_5_EN 1 -#define GPIO_6_EN 1 -#define GPIO_7_EN 1 -#define GPIO_IRQ_PRIO 1 - -/* GPIO pin configuration */ -#define GPIO_0_PIN 7 -#define GPIO_1_PIN 8 -#define GPIO_2_PIN 9 -#define GPIO_3_PIN 10 -#define GPIO_4_PIN 11 -#define GPIO_5_PIN 12 -#define GPIO_6_PIN 13 -#define GPIO_7_PIN 14 -/** @} */ - #ifdef __cplusplus } #endif From 4a4ee44abc3d9837535ab666f217c22bb5bacd5a Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Sun, 14 Jun 2015 16:12:20 +0200 Subject: [PATCH 25/33] drivers/gpio: added GPIO_UNDEF define --- drivers/include/periph/gpio.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/include/periph/gpio.h b/drivers/include/periph/gpio.h index 279e0078b9c6..187a6d0dc587 100644 --- a/drivers/include/periph/gpio.h +++ b/drivers/include/periph/gpio.h @@ -28,12 +28,19 @@ extern "C" { #endif /** - * @brief Defined the + * @brief Default GPIO macro maps port-pin tuples to the pin value */ #ifndef GPIO #define GPIO(x,y) ((x & 0) | y) #endif +/** + * @brief Define global value for GPIO not defined + */ +#ifndef GPIO_UNDEF +#define GPIO_UNDEF (-1) +#endif + /** * @brief Define the default GPIO type identifier */ From 55e0362814e3935a48d1b2e12bfd838cd74f3c3f Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Sun, 14 Jun 2015 16:12:47 +0200 Subject: [PATCH 26/33] drivers/xbee: use GPIO_UNDEF instead of GPIO_NUMOF --- drivers/include/xbee.h | 8 ++++---- drivers/xbee/xbee.c | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/include/xbee.h b/drivers/include/xbee.h index 8d1d09f77c8d..7cb52731e96c 100644 --- a/drivers/include/xbee.h +++ b/drivers/include/xbee.h @@ -154,9 +154,9 @@ extern const ng_netdev_driver_t xbee_driver; * @param[in] uart UART interfaced the device is connected to * @param[in] baudrate baudrate to use * @param[in] sleep_pin GPIO pin that is connected to the SLEEP pin, set to - * GPIO_NUMOF if not used + * GPIO_UNDEF if not used * @param[in] status_pin GPIO pin that is connected to the STATUS pin, set to - * GPIO_NUMOF if not used + * GPIO_UNDEF if not used * * @return 0 on success * @return -ENODEV on invalid device descriptor @@ -172,9 +172,9 @@ typedef struct xbee_params { uart_t uart; /**< UART interfaced the device is connected to */ uint32_t baudrate; /**< baudrate to use */ gpio_t sleep_pin; /**< GPIO pin that is connected to the SLEEP pin - set to GPIO_NUMOF if not used */ + set to GPIO_UNDEF if not used */ gpio_t status_pin; /**< GPIO pin that is connected to the STATUS pin - set to GPIO_NUMOF if not used */ + set to GPIO_UNDEF if not used */ } xbee_params_t; #ifdef __cplusplus diff --git a/drivers/xbee/xbee.c b/drivers/xbee/xbee.c index e7cf19112abb..93277a49ee6a 100644 --- a/drivers/xbee/xbee.c +++ b/drivers/xbee/xbee.c @@ -436,14 +436,14 @@ int xbee_init(xbee_t *dev, uart_t uart, uint32_t baudrate, DEBUG("xbee: Error initializing UART\n"); return -ENXIO; } - if (reset_pin < GPIO_NUMOF) { + if (reset_pin != GPIO_UNDEF) { if (gpio_init(reset_pin, GPIO_DIR_OUT, GPIO_NOPULL) < 0) { DEBUG("xbee: Error initializing RESET pin\n"); return -ENXIO; } gpio_set(reset_pin); } - if (sleep_pin < GPIO_NUMOF) { + if (sleep_pin != GPIO_UNDEF) { if (gpio_init(sleep_pin, GPIO_DIR_OUT, GPIO_NOPULL) < 0) { DEBUG("xbee: Error initializing SLEEP pin\n"); return -ENXIO; @@ -451,7 +451,7 @@ int xbee_init(xbee_t *dev, uart_t uart, uint32_t baudrate, gpio_clear(sleep_pin); } /* if reset pin is connected, do a hardware reset */ - if (reset_pin < GPIO_NUMOF) { + if (reset_pin != GPIO_UNDEF) { gpio_clear(reset_pin); hwtimer_wait(HWTIMER_TICKS(RESET_DELAY)); gpio_set(reset_pin); From e0241dfcad79a9758b49315fce0af3811b6f307a Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Sun, 14 Jun 2015 16:13:17 +0200 Subject: [PATCH 27/33] tests/driver_xbee: s/GPIO_NUMOF/GPIO_UNDEF/ --- tests/driver_xbee/xbee_params.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/driver_xbee/xbee_params.h b/tests/driver_xbee/xbee_params.h index 01c03d135b7e..55c67ad13105 100644 --- a/tests/driver_xbee/xbee_params.h +++ b/tests/driver_xbee/xbee_params.h @@ -26,8 +26,8 @@ extern "C" { static xbee_params_t xbee_params[] = { { .uart = XBEE_UART, .baudrate = 9600U, - .sleep_pin = GPIO_NUMOF, - .status_pin = GPIO_NUMOF + .sleep_pin = GPIO_UNDEF, + .status_pin = GPIO_UNDEF }, }; From d748d4ba4f2cbdb2ad5470a916ae1c3c440e2032 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Sun, 14 Jun 2015 16:14:48 +0200 Subject: [PATCH 28/33] cpu/atmega2560: removed empty gpio.c file --- cpu/atmega2560/periph/gpio.c | 70 ------------------------------------ 1 file changed, 70 deletions(-) delete mode 100644 cpu/atmega2560/periph/gpio.c diff --git a/cpu/atmega2560/periph/gpio.c b/cpu/atmega2560/periph/gpio.c deleted file mode 100644 index fa634de46daa..000000000000 --- a/cpu/atmega2560/periph/gpio.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup driver_periph - * @{ - * - * @file - * @brief Low-level GPIO driver implementation - * - * @author Hauke Petersen - * - * @} - */ - -/* - * TODO: Implement GPIO interface - */ - -#include "cpu.h" -#include "periph/gpio.h" -#include "periph_conf.h" - -#if GPIO_NUMOF - -typedef struct { - void (*cb)(void); -} gpio_state_t; - -/*static gpio_state_t config[GPIO_NUMOF]; */ - - - -int gpio_init(gpio_t dev, gpio_dir_t dir, gpio_pp_t pushpull) -{ - return -1; -} - -int gpio_init_int(gpio_t dev, gpio_pp_t pushpull, gpio_flank_t flank, gpio_cb_t cb, void *arg) -{ - return -1; -} - -int gpio_read(gpio_t dev) -{ - return -1; -} - -void gpio_set(gpio_t dev) -{ -} - -void gpio_clear(gpio_t dev) -{ -} - -void gpio_toggle(gpio_t dev) -{ -} - -void gpio_write(gpio_t dev, int value) -{ -} - -#endif /* GPIO_NUMOF */ From c7f54c11899939557a07e443d71b815629762352 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Sun, 14 Jun 2015 16:15:19 +0200 Subject: [PATCH 29/33] cpu/nrf51822: added custom GPIO_UNDEF define --- cpu/nrf51822/include/periph_cpu.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/cpu/nrf51822/include/periph_cpu.h b/cpu/nrf51822/include/periph_cpu.h index 3fe6ac02b7cb..f1154fcfaf98 100644 --- a/cpu/nrf51822/include/periph_cpu.h +++ b/cpu/nrf51822/include/periph_cpu.h @@ -23,14 +23,6 @@ extern "C" { #endif -/** - * @brief Define mandatory GPIO types for NRF51822 CPUs - * @{ - */ -typedef int gpio_t; -typedef int gpio_mux_t; -/** @} */ - /** * @brief Override GPIO pull register select values * @{ From 138a6a7d1bf7e26ee04f03a882dc449a8d719c95 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Sun, 14 Jun 2015 16:15:53 +0200 Subject: [PATCH 30/33] cpu/samd21: added custom GPIO_UNDEF define --- cpu/samd21/include/periph_cpu.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cpu/samd21/include/periph_cpu.h b/cpu/samd21/include/periph_cpu.h index ce4d59f93266..873439888430 100644 --- a/cpu/samd21/include/periph_cpu.h +++ b/cpu/samd21/include/periph_cpu.h @@ -26,13 +26,18 @@ extern "C" { #endif /** - * @brief Define mandatory GPIO types for NRF51822 CPUs + * @brief Define a custom type for GPIO pins * @{ */ #define HAVE_GPIO_T typedef uint32_t gpio_t; /** @} */ +/** + * @brief Definition of a fitting UNDEF value + */ +#define GPIO_UNDEF (0xffffffff) + /** * @brief Mandatory function for defining a GPIO pins * @{ From ac8ad5419de9e281b80c8fe786009f120b3daa23 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Sun, 14 Jun 2015 16:16:04 +0200 Subject: [PATCH 31/33] cpu/saml21: added custom GPIO_UNDEF define --- cpu/saml21/include/periph_cpu.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cpu/saml21/include/periph_cpu.h b/cpu/saml21/include/periph_cpu.h index 309a699359ae..774e7ef168e8 100644 --- a/cpu/saml21/include/periph_cpu.h +++ b/cpu/saml21/include/periph_cpu.h @@ -33,6 +33,11 @@ extern "C" { typedef uint32_t gpio_t; /** @} */ +/** + * @brief Definition of a fitting UNDEF value + */ +#define GPIO_UNDEF (0xffffffff) + /** * @brief Mandatory function for defining a GPIO pins * @{ From 8c690f1d6aa6c85c59988ac02f84ebadb7fffc5c Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Sun, 14 Jun 2015 16:16:28 +0200 Subject: [PATCH 32/33] cpu/stm32f3: added custom GPIO_UNDEF define --- cpu/stm32f3/include/periph_cpu.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cpu/stm32f3/include/periph_cpu.h b/cpu/stm32f3/include/periph_cpu.h index 1a735e319250..3b9a6afd6fde 100644 --- a/cpu/stm32f3/include/periph_cpu.h +++ b/cpu/stm32f3/include/periph_cpu.h @@ -33,6 +33,11 @@ extern "C" { typedef uint32_t gpio_t; /** @} */ +/** + * @brief Definition of a fitting UNDEF value + */ +#define GPIO_UNDEF (0xffffffff) + /** * @brief Define a CPU specific GPIO pin generator macro */ From 71995e7cde1358ef8e6059f5ae1f9223cc523dd8 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Sun, 14 Jun 2015 16:16:39 +0200 Subject: [PATCH 33/33] cpu/stm32f4: added custom GPIO_UNDEF define --- cpu/stm32f4/include/periph_cpu.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cpu/stm32f4/include/periph_cpu.h b/cpu/stm32f4/include/periph_cpu.h index b0b3eea7ea34..646e0fcb97db 100644 --- a/cpu/stm32f4/include/periph_cpu.h +++ b/cpu/stm32f4/include/periph_cpu.h @@ -33,6 +33,11 @@ extern "C" { typedef uint32_t gpio_t; /** @} */ +/** + * @brief Definition of a fitting UNDEF value + */ +#define GPIO_UNDEF (0xffffffff) + /** * @brief Define a CPU specific GPIO pin generator macro */