diff --git a/arch/avr/src/at32uc3/at32uc3.h b/arch/avr/src/at32uc3/at32uc3.h index 47ecb3ad033..4fc12171ed4 100644 --- a/arch/avr/src/at32uc3/at32uc3.h +++ b/arch/avr/src/at32uc3/at32uc3.h @@ -296,7 +296,7 @@ void weak_function gpio_irqinitialize(void); ****************************************************************************/ #ifdef CONFIG_AVR32_GPIOIRQ -int gpio_irqattach(int irq, xcpt_t newisr, xcpt_t *oldisr); +int gpio_irqattach(int irq, xcpt_t handler, void *arg); #endif /**************************************************************************** diff --git a/arch/avr/src/at32uc3/at32uc3_gpioirq.c b/arch/avr/src/at32uc3/at32uc3_gpioirq.c index f525edd4451..66e82476554 100644 --- a/arch/avr/src/at32uc3/at32uc3_gpioirq.c +++ b/arch/avr/src/at32uc3/at32uc3_gpioirq.c @@ -57,20 +57,22 @@ #ifdef CONFIG_AVR32_GPIOIRQ /**************************************************************************** - * Pre-processor Definitions + * Private Types ****************************************************************************/ +struct g_gpiohandler_s +{ + xcpt_t handler; /* Interrupt handler entry point */ + void *arg; /* The argument that accompanies the interrupt handler */ +}; + /**************************************************************************** * Private Data ****************************************************************************/ /* A table of handlers for each GPIO interrupt */ -static FAR xcpt_t g_gpiohandler[NR_GPIO_IRQS]; - -/**************************************************************************** - * Public Data - ****************************************************************************/ +static struct g_gpiohandler_s g_gpiohandler[NR_GPIO_IRQS]; /**************************************************************************** * Private Functions @@ -221,10 +223,10 @@ static void gpio_porthandler(uint32_t regbase, int irqbase, uint32_t irqset, voi /* Dispatch handling for this pin */ - xcpt_t handler = g_gpiohandler[irq]; - if (handler) + xcpt_t handler = g_gpiohandler[irq].handler; + if (handler != NULL) { - handler(irq, context); + handler(irq, contex, g_gpiohandler[irq].arg); } else { @@ -304,7 +306,8 @@ void gpio_irqinitialize(void) for (i = 0; i < NR_GPIO_IRQS; i++) { - g_gpiohandler[i] = irq_unexpected_isr; + g_gpiohandler[i].handler = irq_unexpected_isr; + g_gpiohandler[i].arg = NULL; } /* Then attach the GPIO interrupt handlers */ @@ -325,7 +328,7 @@ void gpio_irqinitialize(void) * ****************************************************************************/ -int gpio_irqattach(int irq, xcpt_t newisr, xcpt_t *oldisr) +int gpio_irqattach(int irq, xcpt_t handler, void *arg) { irqstate_t flags; int ret = -EINVAL; @@ -338,25 +341,23 @@ int gpio_irqattach(int irq, xcpt_t newisr, xcpt_t *oldisr) */ flags = enter_critical_section(); - if (newisr == NULL) + if (handler == NULL) { gpio_irqdisable(irq); - newisr = irq_unexpected_isr; + + handler = irq_unexpected_isr; + arg = NULL; } - /* Return the old ISR (in case the caller ever wants to restore it) */ + /* Save the new ISR in the table. */ - if (oldisr) - { - *oldisr = g_gpiohandler[irq]; - } + g_gpiohandler[irq].handler = handler; + g_gpiohandler[irq].arg = arg; - /* Then save the new ISR in the table. */ - - g_gpiohandler[irq] = newisr; leave_critical_section(flags); ret = OK; } + return ret; } diff --git a/configs/avr32dev1/src/avr32_buttons.c b/configs/avr32dev1/src/avr32_buttons.c index 228a43098a9..72191bb5855 100644 --- a/configs/avr32dev1/src/avr32_buttons.c +++ b/configs/avr32dev1/src/avr32_buttons.c @@ -42,6 +42,7 @@ #include #include +#include #include #include @@ -69,28 +70,26 @@ #if defined(CONFIG_AVR32_GPIOIRQ) && defined(CONFIG_ARCH_IRQBUTTONS) && \ (defined(CONFIG_AVR32DEV_BUTTON1_IRQ) || defined(CONFIG_AVR32DEV_BUTTON2_IRQ)) -static xcpt_t board_button_irqx(int irq, xcpt_t irqhandler, void *arg) +static int board_button_irqx(int irq, xcpt_t irqhandler, void *arg) { - xcpt_t oldhandler; - /* Attach the handler */ - gpio_irqattach(irq, irqhandler, &oldhandler); - - /* Enable/disable the interrupt */ - - if (irqhandler) + int ret = gpio_irqattach(irq, irqhandler, &oldhandler, arg); + if (ret >= 0) { - gpio_irqenable(irq); - } - else - { - gpio_irqdisable(irq); + /* Enable/disable the interrupt */ + + if (irqhandler != NULL) + { + gpio_irqenable(irq); + } + else + { + gpio_irqdisable(irq); + } } - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return OK; } #endif @@ -143,8 +142,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address isreturned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_GPIOIRQ must be selected to enable the @@ -156,25 +154,29 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_AVR32_GPIOIRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { + int ret; + #ifdef CONFIG_AVR32DEV_BUTTON1_IRQ if (id == BUTTON1) { - return board_button_irqx(GPIO_BUTTON1_IRQ, irqhandler, arg); + ret = board_button_irqx(GPIO_BUTTON1_IRQ, irqhandler, arg); } else #endif #ifdef CONFIG_AVR32DEV_BUTTON2_IRQ if (id == BUTTON2) { - return board_button_irqx(GPIO_BUTTON2_IRQ, irqhandler, arg); + ret = board_button_irqx(GPIO_BUTTON2_IRQ, irqhandler, arg); } else #endif { - return NULL; + ret = -EINVAL; } + + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/bambino-200e/src/lpc43_buttons.c b/configs/bambino-200e/src/lpc43_buttons.c index dbaf33d1b53..8aaeac3c95c 100644 --- a/configs/bambino-200e/src/lpc43_buttons.c +++ b/configs/bambino-200e/src/lpc43_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/bambino-200e/src/lpc43_buttons.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * Alan Carvalho de Assis acassis@gmail.com [nuttx] * @@ -66,13 +66,7 @@ static const uint16_t g_buttoncfg[BOARD_NUM_BUTTONS] = BAMBINO_BUT1 }; -/* This array defines all of the interrupt handlers current attached to - * button events. - */ - #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC43_GPIO_IRQ) -static xcpt_t g_buttonisr[BOARD_NUM_BUTTONS]; - /* This array provides the mapping from button ID numbers to button IRQ * numbers. */ @@ -161,8 +155,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BOARD_BUTTON_* and BOARD_JOYSTICK_* definitions in board.h for the meaning - * of enumeration values. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * of enumeration values. * * Note that board_button_irq() also enables button interrupts. Button * interrupts will remain enabled after the interrupt handler is attached. @@ -172,9 +165,8 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC43_GPIO_IRQ) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; irqstate_t flags; int irq; @@ -182,11 +174,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) if ((unsigned)id < BOARD_NUM_BUTTONS) { - /* Return the current button handler and set the new interrupt handler */ - - oldhandler = g_buttonisr[id]; - g_buttonisr[id] = irqhandler; - /* Disable interrupts until we are done */ flags = enter_critical_section(); @@ -200,7 +187,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { /* Attach then enable the new interrupt handler */ - (void)irq_attach(irq, irqhandler, NULL); + (void)irq_attach(irq, irqhandler, arg); up_enable_irq(irq); } else @@ -210,10 +197,11 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) up_disable_irq(irq); (void)irq_detach(irq); } + leave_critical_section(flags); } - return oldhandler; + return OK; } #endif diff --git a/configs/cloudctrl/src/stm32_buttons.c b/configs/cloudctrl/src/stm32_buttons.c index 5766e8ca331..35e250e4bcc 100644 --- a/configs/cloudctrl/src/stm32_buttons.c +++ b/configs/cloudctrl/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/cloudctrl/src/stm32_buttons.c * - * Copyright (C) 2012, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * Darcy Gong * @@ -151,15 +151,13 @@ uint8_t board_buttons(void) * board_button_irq() may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See - * the - * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of - * enumeration value. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * the BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of + * enumeration value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { xcpt_t oldhandler = NULL; @@ -171,7 +169,8 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) irqhandler, arg); } - return oldhandler; + UNUSED(oldhandler); + return OK; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/dk-tm4c129x/src/tm4c_buttons.c b/configs/dk-tm4c129x/src/tm4c_buttons.c index 69b1766a116..c6b79f3570a 100644 --- a/configs/dk-tm4c129x/src/tm4c_buttons.c +++ b/configs/dk-tm4c129x/src/tm4c_buttons.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -144,18 +145,16 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_TIVA_GPIOP_IRQS) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { static xcpt_t handler = NULL; - xcpt_t oldhandler = handler; irqstate_t flags; - int ret; + int ret = -EINVAL; /* Interrupts are supported only on ports P and Q and, hence, only on button SW4 */ @@ -186,7 +185,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) leave_critical_section(flags); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/fire-stm32v2/src/stm32_buttons.c b/configs/fire-stm32v2/src/stm32_buttons.c index aac98c1973a..b0a3c76f43a 100644 --- a/configs/fire-stm32v2/src/stm32_buttons.c +++ b/configs/fire-stm32v2/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/fire-stm32v2/src/stm32_buttons.c * - * Copyright (C) 2012, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -128,14 +128,14 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See * the BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of - * enumeration values. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * enumeration values. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { + xcpt_t oldhandler; uint16_t gpio; if (id == BUTTON_KEY1) @@ -151,7 +151,10 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) return NULL; } - return stm32_gpiosetevent(gpio, true, true, true, irqhandler, arg); + oldhandler = stm32_gpiosetevent(gpio, true, true, true, irqhandler, arg); + + UNUSED(oldhandler); + return OK; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/freedom-k64f/src/k64_buttons.c b/configs/freedom-k64f/src/k64_buttons.c index 659b55497b5..0c9f22e8c86 100644 --- a/configs/freedom-k64f/src/k64_buttons.c +++ b/configs/freedom-k64f/src/k64_buttons.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -127,16 +128,15 @@ uint8_t board_buttons(void) * will be called when a button is depressed or released. The ID value is * a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* and JOYSTICK_* definitions in board.h for the meaning - * of enumeration value. The previous interrupt handler address is - * returned (so that it may restored, if so desired). + * of enumeration value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler; uint32_t pinset; + int ret; /* Map the button id to the GPIO bit set. */ @@ -150,7 +150,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } else { - return NULL; + return -EINVAL; } /* The button has already been configured as an interrupting input (by @@ -159,12 +159,15 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) * Attach the new button handler. */ - oldhandler = knetis_pinirqattach(pinset, irqhandler); + ret = kinetis_pinirqattach(pinset, irqhandler); + if (ret >= 0) + { + /* Then make sure that interrupts are enabled on the pin */ - /* Then make sure that interrupts are enabled on the pin */ + kinetis_pindmaenable(pinset); + } - kinetis_pindmaenable(pinset); - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/freedom-k66f/src/k66_buttons.c b/configs/freedom-k66f/src/k66_buttons.c index 3cd2844d62a..966f742ead6 100644 --- a/configs/freedom-k66f/src/k66_buttons.c +++ b/configs/freedom-k66f/src/k66_buttons.c @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -131,13 +132,12 @@ uint8_t board_buttons(void) * will be called when a button is depressed or released. The ID value is * a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* and JOYSTICK_* definitions in board.h for the meaning - * of enumeration value. The previous interrupt handler address is - * returned (so that it may restored, if so desired). + * of enumeration value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { uint32_t pinset; @@ -153,7 +153,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } else { - return NULL; + return -EINVAL; } /* The button has already been configured as an interrupting input (by @@ -162,11 +162,14 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) * Attach the new button handler. */ - (void)kinetis_pinirqattach(pinset, irqhandler, NULL); + ret = kinetis_pinirqattach(pinset, irqhandler, NULL); + if (ret >= 0) + { + /* Then make sure that interrupts are enabled on the pin */ - /* Then make sure that interrupts are enabled on the pin */ + kinetis_pinirqenable(pinset); + } - kinetis_pinirqenable(pinset); return NULL; } #endif diff --git a/configs/hymini-stm32v/src/stm32_buttons.c b/configs/hymini-stm32v/src/stm32_buttons.c index 578b2fa5b43..a3d36b3ea6c 100644 --- a/configs/hymini-stm32v/src/stm32_buttons.c +++ b/configs/hymini-stm32v/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/hymini-stm32v/src/stm32_buttons.c * - * Copyright (C) 2009, 2011, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2011, 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -69,39 +69,44 @@ ****************************************************************************/ void board_button_initialize(void) - { - stm32_configgpio(GPIO_BTN_KEYA); - stm32_configgpio(GPIO_BTN_KEYB); - } +{ + stm32_configgpio(GPIO_BTN_KEYA); + stm32_configgpio(GPIO_BTN_KEYB); +} /**************************************************************************** * Name: board_buttons ****************************************************************************/ uint8_t board_buttons(void) - { - uint8_t ret = 0; - bool pinValue; +{ + uint8_t ret = 0; + bool pinValue; - /* Check that state of each key */ + /* Check that state of each key */ - /* Pin is pulled up */ - pinValue = stm32_gpioread(GPIO_BTN_KEYA); - if (!pinValue) - { - // Button pressed - ret = 1 << BUTTON_KEYA; - } + /* Pin is pulled up */ - /* Pin is pulled down */ - pinValue = stm32_gpioread(GPIO_BTN_KEYB); - if (pinValue) - { - // Button pressed - ret |= 1 << BUTTON_KEYB; - } - return ret; - } + pinValue = stm32_gpioread(GPIO_BTN_KEYA); + if (!pinValue) + { + /* Button pressed */ + + ret = 1 << BUTTON_KEYA; + } + + /* Pin is pulled down */ + + pinValue = stm32_gpioread(GPIO_BTN_KEYB); + if (pinValue) + { + /* Button pressed */ + + ret |= 1 << BUTTON_KEYB; + } + + return ret; +} /**************************************************************************** * Button support. @@ -122,28 +127,29 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See * the BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it - * may be restored, if so desired). + * value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) - { - xcpt_t oldhandler = NULL; - uint32_t pinset = GPIO_BTN_KEYA; +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +{ + xcpt_t oldhandler = NULL; + uint32_t pinset = GPIO_BTN_KEYA; - if (id == 1) - { - pinset = GPIO_BTN_KEYB; - } - if (id < 2) - { - oldhandler = stm32_gpiosetevent(pinset, true, true, true, - irqhandler, arg); - } + if (id == 1) + { + pinset = GPIO_BTN_KEYB; + } - return oldhandler; - } + if (id < 2) + { + oldhandler = stm32_gpiosetevent(pinset, true, true, true, + irqhandler, arg); + } + + UNUSED(oldhandler); + return OK; +} #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/kwikstik-k40/src/k40_buttons.c b/configs/kwikstik-k40/src/k40_buttons.c index 3fff4a2333f..7057ab1bd83 100644 --- a/configs/kwikstik-k40/src/k40_buttons.c +++ b/configs/kwikstik-k40/src/k40_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/kwikstik-k40/src/k40_buttons.c * - * Copyright (C) 2011, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -49,18 +50,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -111,17 +100,16 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. * See the BUTTON_* and JOYSTICK_* definitions in board.h for the meaning - * of enumeration value. The previous interrupt handler address is - * returned (so that it may be restored, if so desired). + * of enumeration value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { /* The KwikStik-K40 board has no standard GPIO contact buttons */ - return NULL; + return -EINVAL; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/launchxl-tms57004/src/tms570_buttons.c b/configs/launchxl-tms57004/src/tms570_buttons.c index 68c8231926c..c0f307d2feb 100644 --- a/configs/launchxl-tms57004/src/tms570_buttons.c +++ b/configs/launchxl-tms57004/src/tms570_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sam4e-ek/src/tms570_buttons.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -84,10 +85,9 @@ static xcpt_t g_irq_button; ****************************************************************************/ #ifdef HAVE_IRQBUTTONS -static xcpt_t board_button_irqx(gio_pinset_t pinset, int irq, - xcpt_t irqhandler, xcpt_t *store, void *arg) +static int board_button_irqx(gio_pinset_t pinset, int irq, + xcpt_t irqhandler, xcpt_t *store, void *arg) { - xcpt_t oldhandler; irqstate_t flags; /* Disable interrupts until we are done. This guarantees that the following @@ -98,7 +98,6 @@ static xcpt_t board_button_irqx(gio_pinset_t pinset, int irq, /* Get the old button interrupt handler and save the new one */ - oldhandler = *store; *store = irqhandler; /* Are we attaching or detaching? */ @@ -123,7 +122,7 @@ static xcpt_t board_button_irqx(gio_pinset_t pinset, int irq, /* Return the old button handler (so that it can be restored) */ - return oldhandler; + return OK; } #endif @@ -171,8 +170,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_GIOIRQ must be selected to enable the @@ -183,7 +181,7 @@ uint8_t board_buttons(void) * ****************************************************************************/ -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { #ifdef HAVE_IRQBUTTONS if (id == BUTTON_GIOA7) @@ -193,8 +191,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } #endif - return NULL; - + return -EINVAL; } #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/lincoln60/src/lpc17_buttons.c b/configs/lincoln60/src/lpc17_buttons.c index 5764415e4e1..bcee2e34f0f 100644 --- a/configs/lincoln60/src/lpc17_buttons.c +++ b/configs/lincoln60/src/lpc17_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/lincoln60/src/lpc17_buttons.c * - * Copyright (C) 2012-2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -69,13 +69,7 @@ static const uint16_t g_buttoncfg[BOARD_NUM_BUTTONS] = LINCOLN60_BUT1 }; -/* This array defines all of the interrupt handlers current attached to - * button events. - */ - #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC17_GPIOIRQ) -static xcpt_t g_buttonisr[BOARD_NUM_BUTTONS]; - /* This array provides the mapping from button ID numbers to button IRQ * numbers. */ @@ -168,8 +162,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BOARD_BUTTON_* and BOARD_JOYSTICK_* definitions in board.h for the meaning - * of enumeration values. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * of enumeration values. * * Note that board_button_irq() also enables button interrupts. Button * interrupts will remain enabled after the interrupt handler is attached. @@ -179,9 +172,8 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC17_GPIOIRQ) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; irqstate_t flags; int irq; @@ -189,11 +181,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) if ((unsigned)id < BOARD_NUM_BUTTONS) { - /* Return the current button handler and set the new interrupt handler */ - - oldhandler = g_buttonisr[id]; - g_buttonisr[id] = irqhandler; - /* Disable interrupts until we are done */ flags = enter_critical_section(); @@ -207,7 +194,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { /* Attach then enable the new interrupt handler */ - (void)irq_attach(irq, irqhandler, NULL); + (void)irq_attach(irq, irqhandler, arg); up_enable_irq(irq); } else @@ -217,9 +204,11 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) up_disable_irq(irq); (void)irq_detach(irq); } + leave_critical_section(flags); } - return oldhandler; + + return OK; } #endif diff --git a/configs/lpc4330-xplorer/src/lpc43_buttons.c b/configs/lpc4330-xplorer/src/lpc43_buttons.c index 33431b6f0ab..0d0f5db695c 100644 --- a/configs/lpc4330-xplorer/src/lpc43_buttons.c +++ b/configs/lpc4330-xplorer/src/lpc43_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/lpc4330-xplorer/src/lpc43_buttons.c * - * Copyright (C) 2012, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -68,13 +68,7 @@ static const uint16_t g_buttoncfg[BOARD_NUM_BUTTONS] = LPC4330_XPLORER_BUT1 }; -/* This array defines all of the interrupt handlers current attached to - * button events. - */ - #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC43_GPIO_IRQ) -static xcpt_t g_buttonisr[BOARD_NUM_BUTTONS]; - /* This array provides the mapping from button ID numbers to button IRQ * numbers. */ @@ -167,8 +161,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BOARD_BUTTON_* and BOARD_JOYSTICK_* definitions in board.h for the meaning - * of enumeration values. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * of enumeration values. * * Note that board_button_irq() also enables button interrupts. Button * interrupts will remain enabled after the interrupt handler is attached. @@ -178,9 +171,8 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC43_GPIO_IRQ) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; irqstate_t flags; int irq; @@ -188,11 +180,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) if ((unsigned)id < BOARD_NUM_BUTTONS) { - /* Return the current button handler and set the new interrupt handler */ - - oldhandler = g_buttonisr[id]; - g_buttonisr[id] = irqhandler; - /* Disable interrupts until we are done */ flags = enter_critical_section(); @@ -206,7 +193,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { /* Attach then enable the new interrupt handler */ - (void)irq_attach(irq, irqhandler, NULL); + (void)irq_attach(irq, irqhandler, arg); up_enable_irq(irq); } else @@ -216,9 +203,11 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) up_disable_irq(irq); (void)irq_detach(irq); } + leave_critical_section(flags); } - return oldhandler; + + return OK; } #endif diff --git a/configs/lpc4357-evb/src/lpc43_buttons.c b/configs/lpc4357-evb/src/lpc43_buttons.c index feeab979a06..6ece9541d3d 100644 --- a/configs/lpc4357-evb/src/lpc43_buttons.c +++ b/configs/lpc4357-evb/src/lpc43_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/lpc4357-evb/src/board_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -68,13 +69,7 @@ static const uint16_t g_buttoncfg[BOARD_NUM_BUTTONS] = { }; -/* This array defines all of the interrupt handlers current attached to - * button events. - */ - #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC43_GPIO_IRQ) -static xcpt_t g_buttonisr[BOARD_NUM_BUTTONS]; - /* This array provides the mapping from button ID numbers to button IRQ * numbers. */ @@ -173,8 +168,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BOARD_BUTTON_* and BOARD_JOYSTICK_* definitions in board.h for the meaning - * of enumeration values. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * of enumeration values. * * Note that board_button_irq() also enables button interrupts. Button * interrupts will remain enabled after the interrupt handler is attached. @@ -187,7 +181,6 @@ uint8_t board_buttons(void) xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { #if 0 /* Not yet implemented */ - xcpt_t oldhandler = NULL; irqstate_t flags; int irq; @@ -195,11 +188,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) if ((unsigned)id < BOARD_NUM_BUTTONS) { - /* Return the current button handler and set the new interrupt handler */ - - oldhandler = g_buttonisr[id]; - g_buttonisr[id] = irqhandler; - /* Disable interrupts until we are done */ flags = enter_critical_section(); @@ -213,7 +201,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { /* Attach then enable the new interrupt handler */ - (void)irq_attach(irq, irqhandler, NULL); + (void)irq_attach(irq, irqhandler, arg); up_enable_irq(irq); } else @@ -223,12 +211,13 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) up_disable_irq(irq); (void)irq_detach(irq); } + leave_critical_section(flags); } - return oldhandler; + return OK; #else - return NULL; + return -ENOSYS; #endif /* Not yet implemented */ } #endif diff --git a/configs/nucleo-144/src/stm32_buttons.c b/configs/nucleo-144/src/stm32_buttons.c index 7745758cb9d..5f622770adc 100644 --- a/configs/nucleo-144/src/stm32_buttons.c +++ b/configs/nucleo-144/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/nucleo-144/src/stm32_buttons.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. * Authors: Gregory Nutt * David Sidrane * @@ -99,13 +99,12 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { xcpt_t oldhandler = NULL; @@ -115,7 +114,8 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) irqhandler, arg); } - return oldhandler; + UNUSED(oldhandler); + return OK; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/nucleo-f303re/src/stm32_buttons.c b/configs/nucleo-f303re/src/stm32_buttons.c index f5dcc7224f2..484abb4e7a5 100644 --- a/configs/nucleo-f303re/src/stm32_buttons.c +++ b/configs/nucleo-f303re/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/nucleo-f303re/src/stm32_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. * Authors: Gregory Nutt * Paul Alexander Patience @@ -120,13 +120,12 @@ uint8_t board_buttons(void) * will be called when a button is depressed or released. The ID value is * a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* definitions in board.h for the meaning of the - * enumeration value. The previous interrupt handler address is returned - * (so that it may be restored, if so desired). + * enumeration value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { xcpt_t oldhandler = NULL; @@ -136,7 +135,8 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) irqhandler, arg); } - return oldhandler; + UNUSED(oldhandler); + return OK; } #endif diff --git a/configs/nucleo-f4x1re/src/stm32_buttons.c b/configs/nucleo-f4x1re/src/stm32_buttons.c index c93b03d21a9..7b1abbaf4f7 100644 --- a/configs/nucleo-f4x1re/src/stm32_buttons.c +++ b/configs/nucleo-f4x1re/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/nucleo-f4x1re/src/stm32_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -117,13 +117,12 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { xcpt_t oldhandler = NULL; @@ -133,7 +132,8 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) irqhandler, arg); } - return oldhandler; + UNUSED(oldhandler); + return OK; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/nucleo-l476rg/src/stm32_buttons.c b/configs/nucleo-l476rg/src/stm32_buttons.c index 63a96d7a92c..c4a642ecb7b 100644 --- a/configs/nucleo-l476rg/src/stm32_buttons.c +++ b/configs/nucleo-l476rg/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/nucleo-l476rg/src/stm32_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -117,13 +117,12 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { xcpt_t oldhandler = NULL; @@ -133,7 +132,8 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) irqhandler, arg); } - return oldhandler; + UNUSED(oldhandler); + return OK; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c b/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c index 10c0df1ae00..e2bcba1a58f 100644 --- a/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c +++ b/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/olimex-efm32g880f128-stk/src/efm32_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -75,9 +75,6 @@ ****************************************************************************/ #if defined(CONFIG_EFM32_GPIO_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -#if 0 /* REVISIT -- See comments in board_button_irq() */ -static xcpt_t g_button_handlers[NUM_BUTTONS]; -#endif static const uint8_t g_button_irqs[NUM_BUTTONS]; #endif @@ -154,8 +151,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_EFM32_GPIO_IRQ must be selected to enable the @@ -168,10 +164,8 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_EFM32_GPIO_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; - if (id >=0 && id < NUM_BUTTONS) { irqstate_t flags; @@ -182,19 +176,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) flags = enter_critical_section(); - /* Get/set the old button handler - * - * REVISIT: Keeping copies of the hander in RAM seems wasteful - * since the OS already has this information internally. - */ - -#if 0 /* REVISIT */ - oldhandler = g_button_handlers[id]; - g_button_handlers[id] = irqhandler; -#else - oldhandler = NULL; -#endif - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -205,7 +186,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Attach and enable the interrupt */ - (void)irq_attach(g_button_irqs[id], irqhandler, NULL); + (void)irq_attach(g_button_irqs[id], irqhandler, arg); efm32_gpioirqenable(g_button_irqs[id]); } else @@ -221,7 +202,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Return the old button handler (so that it can be restored) */ - return oldhandler; + return OK; } #endif diff --git a/configs/olimex-lpc1766stk/src/lpc17_buttons.c b/configs/olimex-lpc1766stk/src/lpc17_buttons.c index 3b541d94024..37326a82773 100644 --- a/configs/olimex-lpc1766stk/src/lpc17_buttons.c +++ b/configs/olimex-lpc1766stk/src/lpc17_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/olimex-lpc1766stk/src/lpc17_buttons.c * - * Copyright (C) 2011, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -70,13 +70,7 @@ static const uint16_t g_buttoncfg[BOARD_NUM_BUTTONS] = LPC1766STK_UP, LPC1766STK_DOWN, LPC1766STK_LEFT, LPC1766STK_RIGHT }; -/* This array defines all of the interrupt handlers current attached to - * button events. - */ - #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC17_GPIOIRQ) -static xcpt_t g_buttonisr[BOARD_NUM_BUTTONS]; - /* This array provides the mapping from button ID numbers to button IRQ * numbers. */ @@ -171,8 +165,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BOARD_BUTTON_* and BOARD_JOYSTICK_* definitions in board.h for the meaning - * of enumeration values. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * of enumeration values. * * Note that board_button_irq() also enables button interrupts. Button * interrupts will remain enabled after the interrupt handler is attached. @@ -182,9 +175,8 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC17_GPIOIRQ) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; irqstate_t flags; int irq; @@ -192,11 +184,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) if ((unsigned)id < BOARD_NUM_BUTTONS) { - /* Return the current button handler and set the new interrupt handler */ - - oldhandler = g_buttonisr[id]; - g_buttonisr[id] = irqhandler; - /* Disable interrupts until we are done */ flags = enter_critical_section(); @@ -210,7 +197,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { /* Attach then enable the new interrupt handler */ - (void)irq_attach(irq, irqhandler, NULL); + (void)irq_attach(irq, irqhandler, arg); up_enable_irq(irq); } else @@ -220,9 +207,11 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) up_disable_irq(irq); (void)irq_detach(irq); } + leave_critical_section(flags); } - return oldhandler; + + return OK; } #endif diff --git a/configs/olimex-stm32-e407/src/stm32_buttons.c b/configs/olimex-stm32-e407/src/stm32_buttons.c index 32681e5e2d9..f5d8aabbe82 100644 --- a/configs/olimex-stm32-e407/src/stm32_buttons.c +++ b/configs/olimex-stm32-e407/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/olimex-stm32-e407/src/stm32_buttons.c * - * Copyright (C) 2014-2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -127,13 +127,12 @@ uint8_t board_buttons(void) * will be called when a button is depressed or released. The ID value is * a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it - * may restored, if so desired). + * value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { xcpt_t oldhandler = NULL; @@ -145,7 +144,8 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, arg); } - return oldhandler; + UNUSED(oldhandler); + return OK; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/olimex-stm32-h405/src/stm32_buttons.c b/configs/olimex-stm32-h405/src/stm32_buttons.c index 03092eaece8..64adcceb9ef 100644 --- a/configs/olimex-stm32-h405/src/stm32_buttons.c +++ b/configs/olimex-stm32-h405/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/olimex-stm32-h405/src/stm32_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -135,13 +135,12 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { xcpt_t oldhandler = NULL; @@ -153,7 +152,8 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) irqhandler, arg); } - return oldhandler; + UNUSED(oldhandler); + return OK; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/olimex-stm32-h407/src/stm32_buttons.c b/configs/olimex-stm32-h407/src/stm32_buttons.c index da8c5657654..0723f7e9389 100644 --- a/configs/olimex-stm32-h407/src/stm32_buttons.c +++ b/configs/olimex-stm32-h407/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/olimex-stm32-h407/src/stm32_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -127,13 +127,12 @@ uint8_t board_buttons(void) * will be called when a button is depressed or released. The ID value is * a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it - * may restored, if so desired). + * value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { xcpt_t oldhandler = NULL; @@ -145,7 +144,8 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) irqhandler, arg); } - return oldhandler; + UNUSED(oldhandler); + return OK; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/olimex-stm32-p207/src/stm32_buttons.c b/configs/olimex-stm32-p207/src/stm32_buttons.c index 17c0cc50ff4..c84325cd993 100644 --- a/configs/olimex-stm32-p207/src/stm32_buttons.c +++ b/configs/olimex-stm32-p207/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/olimex-stm32-p207/src/stm32_buttons.c * - * Copyright (C) 2011-2012, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2012, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -171,13 +171,12 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { xcpt_t oldhandler = NULL; @@ -189,7 +188,8 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) irqhandler, arg); } - return oldhandler; + UNUSED(oldhandler); + return OK; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/olimex-stm32-p407/src/stm32_buttons.c b/configs/olimex-stm32-p407/src/stm32_buttons.c index ab07a2ed1e9..8833669bf98 100644 --- a/configs/olimex-stm32-p407/src/stm32_buttons.c +++ b/configs/olimex-stm32-p407/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/olimex-stm32-p407/src/stm32_buttons.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -165,13 +165,12 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { xcpt_t oldhandler = NULL; @@ -183,7 +182,8 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) irqhandler, arg); } - return oldhandler; + UNUSED(oldhandler); + return OK; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/olimexino-stm32/src/stm32_buttons.c b/configs/olimexino-stm32/src/stm32_buttons.c index 55021c3a948..80decbe8313 100644 --- a/configs/olimexino-stm32/src/stm32_buttons.c +++ b/configs/olimexino-stm32/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/olimexino-stm32/src/stm32_buttons.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * David_s5 * @@ -80,8 +80,7 @@ * will be called when a button is depressed or released. The ID value is * a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * value. * ****************************************************************************/ @@ -127,13 +126,12 @@ uint8_t board_buttons(void) * will be called when a button is depressed or released. The ID value is * a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { xcpt_t oldhandler = NULL; @@ -145,7 +143,8 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) irqhandler, arg); } - return oldhandler; + UNUSED(oldhandler); + return OK; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/open1788/src/lpc17_buttons.c b/configs/open1788/src/lpc17_buttons.c index c9313525524..e7a7cf88517 100644 --- a/configs/open1788/src/lpc17_buttons.c +++ b/configs/open1788/src/lpc17_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/open1788/src/lpc17_buttons.c * - * Copyright (C) 2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -89,13 +90,7 @@ static const lpc17_pinset_t g_buttoncfg[BOARD_NUM_BUTTONS] = GPIO_JOY_B, GPIO_JOY_C, GPIO_JOY_D, GPIO_JOY_CTR }; -/* This array defines all of the interrupt handlers current attached to - * button events. - */ - #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC17_GPIOIRQ) -static xcpt_t g_buttonisr[BOARD_NUM_BUTTONS]; - /* This array provides the mapping from button ID numbers to button IRQ * numbers. */ @@ -189,8 +184,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BOARD_BUTTON_* and BOARD_JOYSTICK_* definitions in board.h for the meaning - * of enumeration values. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * of enumeration values. * * Note that board_button_irq() also enables button interrupts. Button * interrupts will remain enabled after the interrupt handler is attached. @@ -200,10 +194,10 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC17_GPIOIRQ) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; irqstate_t flags; + int ret = -EINVAL; int irq; /* Verify that the button ID is within range */ @@ -221,11 +215,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) flags = enter_critical_section(); - /* Return the current button handler and set the new interrupt handler */ - - oldhandler = g_buttonisr[id]; - g_buttonisr[id] = irqhandler; - /* Configure the interrupt. Either attach and enable the new * interrupt or disable and detach the old interrupt handler. */ @@ -234,7 +223,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { /* Attach then enable the new interrupt handler */ - (void)irq_attach(irq, irqhandler, NULL); + (void)irq_attach(irq, irqhandler, arg); up_enable_irq(irq); } else @@ -247,9 +236,11 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) leave_critical_section(flags); } + + ret = OK; } - return oldhandler; + return ret; } #endif diff --git a/configs/pcduino-a10/src/a1x_buttons.c b/configs/pcduino-a10/src/a1x_buttons.c index 2cc53b81d6b..acd43334530 100644 --- a/configs/pcduino-a10/src/a1x_buttons.c +++ b/configs/pcduino-a10/src/a1x_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/pcduino-a10/src/a1x_buttons.c * - * Copyright (C) 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -52,22 +53,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#ifdef CONFIG_ARCH_IRQBUTTONS -static xcpt_t g_irqbutton[BOARD_NBUTTONS]; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -110,8 +95,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address isreturned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_ARCH_IRQBUTTONS must be selected to enable the @@ -120,9 +104,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; if (id < BOARD_NBUTTONS) { @@ -134,22 +118,17 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = g_irqbutton[id]; - g_irqbutton[id] = irqhandler; - /* Configure the interrupt */ a1x_pioirq(xxx); (void)irq_attach(xxx, irqhandler, NULL); a1x_pioirqenable(xxx); leave_critical_section(flags); + + ret = OK; } - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return ret; } #endif diff --git a/configs/pic32mz-starterkit/src/pic32mz_buttons.c b/configs/pic32mz-starterkit/src/pic32mz_buttons.c index 21fed886e55..a51ca05f08d 100644 --- a/configs/pic32mz-starterkit/src/pic32mz_buttons.c +++ b/configs/pic32mz-starterkit/src/pic32mz_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/pic32mz-starterkit/src/pic32mz_buttons.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -146,13 +147,12 @@ uint8_t board_buttons(void) * will be called when a button is depressed or released. The ID value is * a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it - * may restored, if so desired). + * value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { #ifdef CONFIG_PIC32MZ_GPIOIRQ_PORTB int ret = OK; diff --git a/configs/sam3u-ek/src/sam_buttons.c b/configs/sam3u-ek/src/sam_buttons.c index 6bfdf269d54..a5dc4765d98 100644 --- a/configs/sam3u-ek/src/sam_buttons.c +++ b/configs/sam3u-ek/src/sam_buttons.c @@ -170,8 +170,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address isreturned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_GPIOIRQ must be selected to enable the diff --git a/configs/sam4e-ek/src/sam_buttons.c b/configs/sam4e-ek/src/sam_buttons.c index 23851d10832..196bc3c5c68 100644 --- a/configs/sam4e-ek/src/sam_buttons.c +++ b/configs/sam4e-ek/src/sam_buttons.c @@ -176,8 +176,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address isreturned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_GPIOIRQ must be selected to enable the diff --git a/configs/sam4l-xplained/src/sam_buttons.c b/configs/sam4l-xplained/src/sam_buttons.c index 9095bd820b5..c12fcdf4b6c 100644 --- a/configs/sam4l-xplained/src/sam_buttons.c +++ b/configs/sam4l-xplained/src/sam_buttons.c @@ -111,8 +111,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_GPIOIRQ must be selected to enable the diff --git a/configs/sam4s-xplained-pro/src/sam_buttons.c b/configs/sam4s-xplained-pro/src/sam_buttons.c index 0a4f057dd8a..aa51ea530ea 100644 --- a/configs/sam4s-xplained-pro/src/sam_buttons.c +++ b/configs/sam4s-xplained-pro/src/sam_buttons.c @@ -110,8 +110,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_GPIOIRQ must be selected to enable the diff --git a/configs/sam4s-xplained/src/sam_buttons.c b/configs/sam4s-xplained/src/sam_buttons.c index 4ce25925927..fa0944910d9 100644 --- a/configs/sam4s-xplained/src/sam_buttons.c +++ b/configs/sam4s-xplained/src/sam_buttons.c @@ -111,8 +111,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_GPIOIRQ must be selected to enable the diff --git a/configs/sama5d2-xult/src/sam_buttons.c b/configs/sama5d2-xult/src/sam_buttons.c index 3dd77011814..179e9432c42 100644 --- a/configs/sama5d2-xult/src/sam_buttons.c +++ b/configs/sama5d2-xult/src/sam_buttons.c @@ -122,8 +122,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_SAMA5_PIO_IRQ must be selected to enable the diff --git a/configs/sama5d3-xplained/src/sam_buttons.c b/configs/sama5d3-xplained/src/sam_buttons.c index b2d0af924ea..e12c5fad805 100644 --- a/configs/sama5d3-xplained/src/sam_buttons.c +++ b/configs/sama5d3-xplained/src/sam_buttons.c @@ -126,8 +126,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_SAMA5_PIO_IRQ must be selected to enable the diff --git a/configs/sama5d3x-ek/src/sam_buttons.c b/configs/sama5d3x-ek/src/sam_buttons.c index d9ea68baa42..9f3dc5ff66a 100644 --- a/configs/sama5d3x-ek/src/sam_buttons.c +++ b/configs/sama5d3x-ek/src/sam_buttons.c @@ -126,8 +126,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address isreturned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_SAMA5_PIO_IRQ must be selected to enable the diff --git a/configs/sama5d4-ek/src/sam_buttons.c b/configs/sama5d4-ek/src/sam_buttons.c index b0fa42ecde3..c442960fb53 100644 --- a/configs/sama5d4-ek/src/sam_buttons.c +++ b/configs/sama5d4-ek/src/sam_buttons.c @@ -122,8 +122,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_SAMA5_PIO_IRQ must be selected to enable the diff --git a/configs/samd20-xplained/src/sam_buttons.c b/configs/samd20-xplained/src/sam_buttons.c index 5edeb965d8a..282c222f33d 100644 --- a/configs/samd20-xplained/src/sam_buttons.c +++ b/configs/samd20-xplained/src/sam_buttons.c @@ -111,8 +111,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address isreturned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_PORTIRQ must be selected to enable the diff --git a/configs/samd21-xplained/src/sam_buttons.c b/configs/samd21-xplained/src/sam_buttons.c index cb5806f748a..989bfd35a83 100644 --- a/configs/samd21-xplained/src/sam_buttons.c +++ b/configs/samd21-xplained/src/sam_buttons.c @@ -111,8 +111,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address isreturned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_PORTIRQ must be selected to enable the diff --git a/configs/same70-xplained/src/sam_buttons.c b/configs/same70-xplained/src/sam_buttons.c index 251cf113c0e..7d464377776 100644 --- a/configs/same70-xplained/src/sam_buttons.c +++ b/configs/same70-xplained/src/sam_buttons.c @@ -175,8 +175,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_GPIOIRQ must be selected to enable the diff --git a/configs/saml21-xplained/src/sam_buttons.c b/configs/saml21-xplained/src/sam_buttons.c index 303a95a084f..e571f251a65 100644 --- a/configs/saml21-xplained/src/sam_buttons.c +++ b/configs/saml21-xplained/src/sam_buttons.c @@ -111,8 +111,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address isreturned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_PORTIRQ must be selected to enable the diff --git a/configs/samv71-xult/src/sam_buttons.c b/configs/samv71-xult/src/sam_buttons.c index 7e2ecd1b404..a8c3f148dc2 100644 --- a/configs/samv71-xult/src/sam_buttons.c +++ b/configs/samv71-xult/src/sam_buttons.c @@ -195,8 +195,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_GPIOIRQ must be selected to enable the diff --git a/configs/shenzhou/src/stm32_buttons.c b/configs/shenzhou/src/stm32_buttons.c index 2d90fafcc16..6c1f2e806e0 100644 --- a/configs/shenzhou/src/stm32_buttons.c +++ b/configs/shenzhou/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/shenzhou/src/stm32_buttons.c * - * Copyright (C) 2012, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -150,13 +150,12 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { xcpt_t oldhandler = NULL; @@ -167,7 +166,9 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, arg); } - return oldhandler; + + UNUSED(oldhandler); + return OK; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/spark/src/stm32_buttons.c b/configs/spark/src/stm32_buttons.c index d38a868cc59..90c6ceb2db8 100644 --- a/configs/spark/src/stm32_buttons.c +++ b/configs/spark/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/spark/src/stm32_buttons.c * - * Copyright (C) 2011-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -49,18 +49,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -114,13 +102,12 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { xcpt_t oldhandler = NULL; @@ -131,7 +118,8 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) oldhandler = stm32_gpiosetevent(GPIO_BTN, true, true, true, irqhandler, arg); } - return oldhandler; + UNUSED(oldhandler); + return OK; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/stm3210e-eval/src/stm32_buttons.c b/configs/stm3210e-eval/src/stm32_buttons.c index a2dc1c6cf7e..f1c76a022e0 100644 --- a/configs/stm3210e-eval/src/stm32_buttons.c +++ b/configs/stm3210e-eval/src/stm32_buttons.c @@ -155,8 +155,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ diff --git a/configs/stm3220g-eval/src/stm32_buttons.c b/configs/stm3220g-eval/src/stm32_buttons.c index ec5428eb069..e3c2a7afca6 100644 --- a/configs/stm3220g-eval/src/stm32_buttons.c +++ b/configs/stm3220g-eval/src/stm32_buttons.c @@ -151,8 +151,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ diff --git a/configs/stm3240g-eval/src/stm32_buttons.c b/configs/stm3240g-eval/src/stm32_buttons.c index db034d5a4e3..2bbc166aca8 100644 --- a/configs/stm3240g-eval/src/stm32_buttons.c +++ b/configs/stm3240g-eval/src/stm32_buttons.c @@ -151,8 +151,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ diff --git a/configs/stm32f103-minimum/src/stm32_buttons.c b/configs/stm32f103-minimum/src/stm32_buttons.c index 96fd053eef3..1d086cf28ff 100644 --- a/configs/stm32f103-minimum/src/stm32_buttons.c +++ b/configs/stm32f103-minimum/src/stm32_buttons.c @@ -146,8 +146,7 @@ uint8_t board_buttons(void) * will be called when a button is depressed or released. The ID value is * a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it - * may be restored, if so desired). + * value. * ****************************************************************************/ diff --git a/configs/stm32f3discovery/src/stm32_buttons.c b/configs/stm32f3discovery/src/stm32_buttons.c index f15c22f8a9c..c1a20c003b2 100644 --- a/configs/stm32f3discovery/src/stm32_buttons.c +++ b/configs/stm32f3discovery/src/stm32_buttons.c @@ -146,8 +146,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ diff --git a/configs/stm32f429i-disco/src/stm32_buttons.c b/configs/stm32f429i-disco/src/stm32_buttons.c index 396b8750546..8be644e5257 100644 --- a/configs/stm32f429i-disco/src/stm32_buttons.c +++ b/configs/stm32f429i-disco/src/stm32_buttons.c @@ -146,8 +146,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ diff --git a/configs/stm32f4discovery/src/stm32_buttons.c b/configs/stm32f4discovery/src/stm32_buttons.c index 5143fd8eca0..7880b5e9658 100644 --- a/configs/stm32f4discovery/src/stm32_buttons.c +++ b/configs/stm32f4discovery/src/stm32_buttons.c @@ -146,8 +146,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ diff --git a/configs/stm32f746g-disco/src/stm32_buttons.c b/configs/stm32f746g-disco/src/stm32_buttons.c index 43051e49604..a9cddac58f5 100644 --- a/configs/stm32f746g-disco/src/stm32_buttons.c +++ b/configs/stm32f746g-disco/src/stm32_buttons.c @@ -98,8 +98,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ diff --git a/configs/stm32l476-mdk/src/stm32_buttons.c b/configs/stm32l476-mdk/src/stm32_buttons.c index f87c9936ecc..79a02aed05f 100644 --- a/configs/stm32l476-mdk/src/stm32_buttons.c +++ b/configs/stm32l476-mdk/src/stm32_buttons.c @@ -144,8 +144,7 @@ uint8_t board_buttons(void) * will be called when a button is depressed or released. The ID value * is a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it - * may be restored, if so desired). + * value. * ****************************************************************************/ diff --git a/configs/stm32l476vg-disco/src/stm32_buttons.c b/configs/stm32l476vg-disco/src/stm32_buttons.c index 8e8f43313f2..7acdb433962 100644 --- a/configs/stm32l476vg-disco/src/stm32_buttons.c +++ b/configs/stm32l476vg-disco/src/stm32_buttons.c @@ -319,8 +319,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ diff --git a/configs/stm32ldiscovery/src/stm32_buttons.c b/configs/stm32ldiscovery/src/stm32_buttons.c index b703bf8d2de..60b4c12be48 100644 --- a/configs/stm32ldiscovery/src/stm32_buttons.c +++ b/configs/stm32ldiscovery/src/stm32_buttons.c @@ -146,8 +146,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ diff --git a/configs/stm32vldiscovery/src/stm32_buttons.c b/configs/stm32vldiscovery/src/stm32_buttons.c index 63be9ee2a17..87d63268523 100644 --- a/configs/stm32vldiscovery/src/stm32_buttons.c +++ b/configs/stm32vldiscovery/src/stm32_buttons.c @@ -101,8 +101,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ diff --git a/configs/sure-pic32mx/src/pic32mx_buttons.c b/configs/sure-pic32mx/src/pic32mx_buttons.c index 85cc49fe917..6c378dd0a6f 100644 --- a/configs/sure-pic32mx/src/pic32mx_buttons.c +++ b/configs/sure-pic32mx/src/pic32mx_buttons.c @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -192,8 +193,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * * Interrupts are automatically enabled when the button handler is attached and * automatically disabled when the button handler is detached. @@ -206,9 +206,9 @@ uint8_t board_buttons(void) ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - int ret = OK; + int ret = -EINVAL; if (id < NUM_BUTTONS) { diff --git a/configs/tm4c123g-launchpad/src/tm4c_buttons.c b/configs/tm4c123g-launchpad/src/tm4c_buttons.c index 5ff886c37bb..a61c7e9c78d 100644 --- a/configs/tm4c123g-launchpad/src/tm4c_buttons.c +++ b/configs/tm4c123g-launchpad/src/tm4c_buttons.c @@ -39,6 +39,8 @@ #include +#include + #include #include #include @@ -143,13 +145,12 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { uint32_t pinset = 0; int ret; @@ -167,7 +168,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) break; default: - return NULL; + return -EINVAL; } /* Are we attaching or detaching? */ @@ -181,8 +182,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) ret = tiva_gpioirqdetach(pinset); } - UNUSED(ret); - return OK; + return ret; } #endif diff --git a/configs/twr-k60n512/src/k60_buttons.c b/configs/twr-k60n512/src/k60_buttons.c index 6a936935da1..a952f64828d 100644 --- a/configs/twr-k60n512/src/k60_buttons.c +++ b/configs/twr-k60n512/src/k60_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/twr-k60n512/src/k60_buttons.c * - * Copyright (C) 2011, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -128,15 +129,13 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler; uint32_t pinset; /* Map the button id to the GPIO bit set. */ @@ -151,7 +150,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } else { - return NULL; + return -EINVAL; } /* The button has already been configured as an interrupting input (by @@ -160,12 +159,15 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) * Attach the new button handler. */ - oldhandler = knetis_pinirqattach(pinset, irqhandler); + ret = kinetis_pinirqattach(pinset, irqhandler, arg); + if (ret >= 0) + { + /* Then make sure that interrupts are enabled on the pin */ - /* Then make sure that interrupts are enabled on the pin */ + kinetis_pindmaenable(pinset); + } - kinetis_pindmaenable(pinset); - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/ubw32/src/pic32_buttons.c b/configs/ubw32/src/pic32_buttons.c index de9e16e542a..f612e1eea4b 100644 --- a/configs/ubw32/src/pic32_buttons.c +++ b/configs/ubw32/src/pic32_buttons.c @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -166,9 +167,7 @@ uint8_t board_buttons(void) * board_button_irq() may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the - * BUTTON_* definitions in board.h for the meaning of enumeration value. The - * previous interrupt handler address is returned (so that it may restored, if - * so desired). + * BUTTON_* definitions in board.h for the meaning of enumeration value. * * Interrupts are automatically enabled when the button handler is attached and * automatically disabled when the button handler is detached. @@ -181,9 +180,9 @@ uint8_t board_buttons(void) ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - int ret = OK; + int ret = -EINVAL; if (id < NUM_BUTTONS) { diff --git a/configs/viewtool-stm32f107/src/stm32_buttons.c b/configs/viewtool-stm32f107/src/stm32_buttons.c index 97b02d1c5c3..b29e0d3131e 100644 --- a/configs/viewtool-stm32f107/src/stm32_buttons.c +++ b/configs/viewtool-stm32f107/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/viewtool-stm32f107/src/stm32_buttons.c * - * Copyright (C) 2013, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -146,13 +146,12 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { xcpt_t oldhandler = NULL; @@ -164,7 +163,8 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) irqhandler, arg); } - return oldhandler; + UNUSED(oldhandler); + return OK; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/zkit-arm-1769/src/lpc17_buttons.c b/configs/zkit-arm-1769/src/lpc17_buttons.c index 24d60216938..936f63576f5 100644 --- a/configs/zkit-arm-1769/src/lpc17_buttons.c +++ b/configs/zkit-arm-1769/src/lpc17_buttons.c @@ -6,7 +6,7 @@ * * Based on configs/stm3210e-eval/src/board_buttons.c * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2011, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -76,10 +76,6 @@ static const uint16_t g_buttons[BOARD_NUM_BUTTONS] = ZKITARM_KEY1, ZKITARM_KEY2, ZKITARM_KEY3, ZKITARM_KEY4, ZKITARM_KEY5 }; -/* Old KEY5 interrupt handler */ - -static xcpt_t g_oldhandler; - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -154,27 +150,21 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #if defined CONFIG_ARCH_IRQBUTTONS && CONFIG_LPC17_GPIOIRQ -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t rethandler = NULL; irqstate_t flags; - int ret; + int ret = -EINVAL; /* Interrupts are supported on KEY5 only */ if (id == BOARD_BUTTON_5) { - /* Return the previous value of the interrupt handler */ - flags = enter_critical_section(); - rethandler = g_oldhandler; - g_oldhandler = irqhandler; /* Attach or detach the interrupt handler for KEY5. */ @@ -202,13 +192,13 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Configure KEY5 as a non-interrupting input */ lpc17_configgpio(ZKITARM_KEY5); - + ret = OK; } leave_critical_section(flags); } - return rethandler; + return ret; } #endif diff --git a/include/nuttx/board.h b/include/nuttx/board.h index 633ea9c6839..cd08aceddd0 100644 --- a/include/nuttx/board.h +++ b/include/nuttx/board.h @@ -603,8 +603,6 @@ uint8_t board_buttons(void); * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. - * The previous interrupt handler address is returned (so that it may - * restored, if so desired). * * NOTE: This interface may or may not be supported by board-specific * logic. If the board supports any button interfaces, then @@ -614,7 +612,7 @@ uint8_t board_buttons(void); ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg); +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg); #endif /****************************************************************************