From 7d2413a6a061e848cd3aae28bf84ba58facd2fa5 Mon Sep 17 00:00:00 2001 From: Lwazi Dube Date: Mon, 31 Dec 2018 17:07:09 -0600 Subject: [PATCH] configs/tm4c1294-launchpad/src: Add IRQBUTTONS support to tm4c1294 launchpad. --- configs/Kconfig | 1 + .../src/tm4c1294-launchpad.h | 15 +++++-- configs/tm4c1294-launchpad/src/tm4c_bringup.c | 19 +++++++- configs/tm4c1294-launchpad/src/tm4c_buttons.c | 45 ++++++++++++++++++- 4 files changed, 74 insertions(+), 6 deletions(-) diff --git a/configs/Kconfig b/configs/Kconfig index c23e4c17bf..a181d9f036 100644 --- a/configs/Kconfig +++ b/configs/Kconfig @@ -1552,6 +1552,7 @@ config ARCH_BOARD_TM4C1294_LAUNCHPAD depends on ARCH_CHIP_TM4C1294NC select ARCH_HAVE_LEDS select ARCH_HAVE_BUTTONS + select ARCH_HAVE_IRQBUTTONS ---help--- Tiva EK-TM4C1294XL LaunchPad. diff --git a/configs/tm4c1294-launchpad/src/tm4c1294-launchpad.h b/configs/tm4c1294-launchpad/src/tm4c1294-launchpad.h index c5e3b7050a..ba9f698ccb 100644 --- a/configs/tm4c1294-launchpad/src/tm4c1294-launchpad.h +++ b/configs/tm4c1294-launchpad/src/tm4c1294-launchpad.h @@ -1,7 +1,7 @@ /************************************************************************************ * configs/tm4c1294-launchpad/src/ek-tm4c1294xl.h * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -122,8 +122,17 @@ * PJ1 USR_SW2 * --- ------------ */ -#define GPIO_SW1 (GPIO_FUNC_INPUT | GPIO_PORTJ | GPIO_PIN_0) -#define GPIO_SW2 (GPIO_FUNC_INPUT | GPIO_PORTJ | GPIO_PIN_1) +#ifdef CONFIG_ARCH_IRQBUTTONS +# define GPIO_SW1 (GPIO_FUNC_INTERRUPT | GPIO_INT_BOTHEDGES | \ + GPIO_STRENGTH_2MA | GPIO_PADTYPE_STDWPU | \ + GPIO_PORTJ | GPIO_PIN_0) +# define GPIO_SW2 (GPIO_FUNC_INTERRUPT | GPIO_INT_BOTHEDGES | \ + GPIO_STRENGTH_2MA | GPIO_PADTYPE_STDWPU | \ + GPIO_PORTJ | GPIO_PIN_1) +#else +# define GPIO_SW1 (GPIO_FUNC_INPUT | GPIO_PORTJ | GPIO_PIN_0) +# define GPIO_SW2 (GPIO_FUNC_INPUT | GPIO_PORTJ | GPIO_PIN_1) +#endif /* SPI Chip selects ****************************************************************/ /* SSI0: PA3 is used for SSI0 chip select to the second booster pack (No pull- diff --git a/configs/tm4c1294-launchpad/src/tm4c_bringup.c b/configs/tm4c1294-launchpad/src/tm4c_bringup.c index 16ccb611df..6bc430197f 100644 --- a/configs/tm4c1294-launchpad/src/tm4c_bringup.c +++ b/configs/tm4c1294-launchpad/src/tm4c_bringup.c @@ -49,6 +49,10 @@ #include +#ifdef CONFIG_BUTTONS +# include +#endif + #include "tiva_i2c.h" #include "tiva_pwm.h" #include "tiva_qencoder.h" @@ -306,9 +310,7 @@ static void tm4c_qei(void) int tm4c_bringup(void) { -#if defined(HAVE_TIMER) || defined(HAVE_HCIUART) int ret; -#endif /* Register I2C drivers on behalf of the I2C tool */ @@ -337,6 +339,8 @@ int tm4c_bringup(void) #endif #ifdef HAVE_HCIUART + /* Register the Bluetooth HCI UART device */ + ret = hciuart_dev_initialize(); if (ret < 0) { @@ -344,5 +348,16 @@ int tm4c_bringup(void) } #endif +#ifdef CONFIG_BUTTONS_LOWER + /* Register the BUTTON driver */ + + ret = btn_lower_initialize("/dev/buttons"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret); + } +#endif + + UNUSED(ret); return OK; } diff --git a/configs/tm4c1294-launchpad/src/tm4c_buttons.c b/configs/tm4c1294-launchpad/src/tm4c_buttons.c index 5b72e5bb29..c4f3549fcc 100644 --- a/configs/tm4c1294-launchpad/src/tm4c_buttons.c +++ b/configs/tm4c1294-launchpad/src/tm4c_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/tm4c1294-launchpad/src/tm4c_buttons.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -96,6 +96,12 @@ void board_button_initialize(void) { tiva_configgpio(g_buttons[i]); } + +#ifdef CONFIG_ARCH_IRQBUTTONS + /* Configure GPIO interrupts */ + + (void)tiva_gpioirqinitialize(); +#endif } /**************************************************************************** @@ -125,4 +131,41 @@ uint32_t board_buttons(void) return ret; } + +/**************************************************************************** + * Name: board_button_irq + * + * Description: + * This function may be called to register an interrupt handler that will + * be called when a button is depressed or released. + * + ****************************************************************************/ + +#ifdef CONFIG_ARCH_IRQBUTTONS +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +{ + int ret; + + if (id < 0 || id >= NUM_BUTTONS ) + { + ret = -EINVAL; + } + else + { + /* Are we attaching or detaching? */ + + if (irqhandler != NULL) + { + ret = tiva_gpioirqattach(g_buttons[id], irqhandler, arg); + } + else + { + ret = tiva_gpioirqdetach(g_buttons[id]); + } + } + + return ret; +} +#endif + #endif /* CONFIG_ARCH_BUTTONS */