diff --git a/configs/dk-tm4c129x/src/tm4c_buttons.c b/configs/dk-tm4c129x/src/tm4c_buttons.c index c6b79f3570..9d22ec3617 100644 --- a/configs/dk-tm4c129x/src/tm4c_buttons.c +++ b/configs/dk-tm4c129x/src/tm4c_buttons.c @@ -174,7 +174,7 @@ int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) if (irqhandler) { - ret = irq_attach(IRQ_SW4, irqhandler, NULL); + ret = irq_attach(IRQ_SW4, irqhandler, arg); if (ret == OK) { handler = irqhandler; diff --git a/configs/pcduino-a10/src/a1x_buttons.c b/configs/pcduino-a10/src/a1x_buttons.c index acd4333453..a690ae866d 100644 --- a/configs/pcduino-a10/src/a1x_buttons.c +++ b/configs/pcduino-a10/src/a1x_buttons.c @@ -121,7 +121,7 @@ int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Configure the interrupt */ a1x_pioirq(xxx); - (void)irq_attach(xxx, irqhandler, NULL); + (void)irq_attach(xxx, irqhandler, arg); a1x_pioirqenable(xxx); leave_critical_section(flags); diff --git a/configs/sam3u-ek/src/sam_buttons.c b/configs/sam3u-ek/src/sam_buttons.c index a5dc4765d9..520f05e1a5 100644 --- a/configs/sam3u-ek/src/sam_buttons.c +++ b/configs/sam3u-ek/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sam3u-ek/src/up_leds.c * - * Copyright (C) 2010, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 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 @@ -53,19 +54,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irqbutton1; -static xcpt_t g_irqbutton2; -#endif - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -79,10 +67,9 @@ static xcpt_t g_irqbutton2; ****************************************************************************/ #if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, - xcpt_t irqhandler, xcpt_t *store, void *arg) +static int board_button_irqx(gpio_pinset_t pinset, int irq, xcpt_t irqhandler, + void *arg) { - xcpt_t oldhandler; irqstate_t flags; /* Disable interrupts until we are done. This guarantees that the following @@ -91,11 +78,6 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = *store; - *store = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -115,10 +97,7 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, } leave_critical_section(flags); - - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return OK; } #endif @@ -182,21 +161,19 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_SAM34_GPIOA_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) { if (id == BUTTON1) { - return board_button_irqx(GPIO_BUTTON1, IRQ_BUTTON1, - irqhandler, &g_irqbutton1, arg); + return board_button_irqx(GPIO_BUTTON1, IRQ_BUTTON1, irqhandler, arg); } else if (id == BUTTON2) { - return board_button_irqx(GPIO_BUTTON2, IRQ_BUTTON2, - irqhandler, &g_irqbutton2, arg); + return board_button_irqx(GPIO_BUTTON2, IRQ_BUTTON2, irqhandler, arg); } else { - return NULL; + return -EINVAL; } } #endif diff --git a/configs/sam4e-ek/src/sam_buttons.c b/configs/sam4e-ek/src/sam_buttons.c index 196bc3c5c6..d9fbabeb6d 100644 --- a/configs/sam4e-ek/src/sam_buttons.c +++ b/configs/sam4e-ek/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sam4e-ek/src/sam_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 @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -53,21 +54,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irq_scrollup; -static xcpt_t g_irq_scrolldown; -static xcpt_t g_irq_waku; -static xcpt_t g_irq_tamp; -#endif - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -81,10 +67,9 @@ static xcpt_t g_irq_tamp; ****************************************************************************/ #if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, - xcpt_t irqhandler, xcpt_t *store, void *arg) +static int board_button_irqx(gpio_pinset_t pinset, int irq, xcpt_t irqhandler, + void *arg) { - xcpt_t oldhandler; irqstate_t flags; /* Disable interrupts until we are done. This guarantees that the following @@ -93,11 +78,6 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = *store; - *store = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -117,10 +97,7 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, } leave_critical_section(flags); - - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return OK; } #endif @@ -188,28 +165,24 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_SAM34_GPIOA_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) { switch (id) { case BUTTON_SCROLLUP: - return board_button_irqx(GPIO_SCROLLUP, IRQ_SCROLLUP, - irqhandler, &g_irq_scrollup, arg); + return board_button_irqx(GPIO_SCROLLUP, IRQ_SCROLLUP, irqhandler, arg); case BUTTON_SCROLLDOWN: - return board_button_irqx(GPIO_SCROLLDWN, IRQ_SCROLLDWN, - irqhandler, &g_irq_scrolldown, arg); + return board_button_irqx(GPIO_SCROLLDWN, IRQ_SCROLLDWN, irqhandler, arg); case BUTTON_WAKU: - return board_button_irqx(GPIO_WAKU, IRQ_WAKU, - irqhandler, &g_irq_waku, arg); + return board_button_irqx(GPIO_WAKU, IRQ_WAKU, irqhandler, arg); case BUTTON_TAMP: - return board_button_irqx(GPIO_TAMP, IRQ_TAMP, - irqhandler, &g_irq_tamp, arg); + return board_button_irqx(GPIO_TAMP, IRQ_TAMP, irqhandler, arg); default: - return NULL; + return -EINVAL; } } #endif diff --git a/configs/sam4l-xplained/src/sam_buttons.c b/configs/sam4l-xplained/src/sam_buttons.c index c12fcdf4b6..619f7d658b 100644 --- a/configs/sam4l-xplained/src/sam_buttons.c +++ b/configs/sam4l-xplained/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sam4l-xplained/src/sam_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 @@ -53,18 +53,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irqsw0; -#endif - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -123,9 +111,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_SAM34_GPIOA_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; + int ret = -EINVAL; if (id == BUTTON_SW0) { @@ -137,11 +125,6 @@ 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_irqsw0; - *g_irqsw0 = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -149,7 +132,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Configure the interrupt */ sam_gpioirq(GPIO_SW0); - (void)irq_attach(IRQ_SW0, irqhandler, NULL); + (void)irq_attach(IRQ_SW0, irqhandler, arg); sam_gpioirqenable(IRQ_SW0); } else @@ -161,11 +144,10 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } 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/sam4s-xplained-pro/src/sam_buttons.c b/configs/sam4s-xplained-pro/src/sam_buttons.c index aa51ea530e..daae49b89e 100644 --- a/configs/sam4s-xplained-pro/src/sam_buttons.c +++ b/configs/sam4s-xplained-pro/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sam4s-xplained-pro/src/sam_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Authors: Gregory Nutt * Bob Doiron * @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -54,20 +55,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static xcpt_t g_irqsw0; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -122,9 +109,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_SAM34_GPIOA_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; + int ret = -EINVAL; if (id == BUTTON_SW0) { @@ -136,11 +123,6 @@ 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_irqsw0; - g_irqsw0 = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -148,7 +130,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Configure the interrupt */ sam_gpioirq(GPIO_SW0); - (void)irq_attach(IRQ_SW0, irqhandler, NULL); + (void)irq_attach(IRQ_SW0, irqhandler, arg); sam_gpioirqenable(IRQ_SW0); } else @@ -160,11 +142,12 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } 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/sam4s-xplained/src/sam_buttons.c b/configs/sam4s-xplained/src/sam_buttons.c index fa0944910d..940f97edae 100644 --- a/configs/sam4s-xplained/src/sam_buttons.c +++ b/configs/sam4s-xplained/src/sam_buttons.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -53,22 +54,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irqbp2; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -123,9 +108,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_SAM34_GPIOA_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; + int ret = -EINVAL; if (id == BUTTON_BP2) { @@ -137,11 +122,6 @@ 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_irqbp2; - *g_irqbp2 = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -149,7 +129,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Configure the interrupt */ sam_gpioirq(GPIO_BP2); - (void)irq_attach(IRQ_BP2, irqhandler, NULL); + (void)irq_attach(IRQ_BP2, irqhandler, arg); sam_gpioirqenable(IRQ_BP2); } else @@ -161,11 +141,10 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } 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/sama5d2-xult/src/sam_buttons.c b/configs/sama5d2-xult/src/sam_buttons.c index 179e9432c4..c93fa6b904 100644 --- a/configs/sama5d2-xult/src/sam_buttons.c +++ b/configs/sama5d2-xult/src/sam_buttons.c @@ -51,6 +51,7 @@ #include #include +#include #include #include @@ -64,22 +65,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_SAMA5_PIOB_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irquser1; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -132,9 +117,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_SAMA5_PIOB_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; + int ret = -EINVAL; if (id == BUTTON_USER) { @@ -146,11 +131,6 @@ 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_irquser1; - g_irquser1 = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -158,7 +138,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Configure the interrupt */ sam_pioirq(PIO_BTN_USER); - (void)irq_attach(IRQ_BTN_USER, irqhandler, NULL); + (void)irq_attach(IRQ_BTN_USER, irqhandler, arg); sam_pioirqenable(IRQ_BTN_USER); } else @@ -170,11 +150,10 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } 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/sama5d3-xplained/src/sam_buttons.c b/configs/sama5d3-xplained/src/sam_buttons.c index e12c5fad80..b7fd824556 100644 --- a/configs/sama5d3-xplained/src/sam_buttons.c +++ b/configs/sama5d3-xplained/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sama5d3-xplained/src/sam_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 @@ -55,6 +55,7 @@ #include #include +#include #include #include @@ -68,22 +69,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_SAMA5_PIOE_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irquser1; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -136,9 +121,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_SAMA5_PIOE_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; + int ret = -EINVAL; if (id == BUTTON_USER) { @@ -150,11 +135,6 @@ 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_irquser1; - g_irquser1 = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -162,7 +142,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Configure the interrupt */ sam_pioirq(PIO_USER); - (void)irq_attach(IRQ_USER1, irqhandler, NULL); + (void)irq_attach(IRQ_USER1, irqhandler, arg); sam_pioirqenable(IRQ_USER1); } else @@ -172,14 +152,12 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) sam_pioirqdisable(IRQ_USER1); (void)irq_detach(IRQ_USER1); } - /* Configure the interrupt */ 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/sama5d3x-ek/src/sam_buttons.c b/configs/sama5d3x-ek/src/sam_buttons.c index 9f3dc5ff66..5b7ccc9b90 100644 --- a/configs/sama5d3x-ek/src/sam_buttons.c +++ b/configs/sama5d3x-ek/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sama5d3x-ek/src/sam_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 @@ -55,6 +55,7 @@ #include #include +#include #include #include @@ -68,22 +69,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_SAMA5_PIOE_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irquser1; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -136,9 +121,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_SAMA5_PIOE_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; + int ret = -EINVAL; if (id == BUTTON_USER1) { @@ -150,11 +135,6 @@ 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_irquser1; - g_irquser1 = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -162,7 +142,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Configure the interrupt */ sam_pioirq(PIO_USER1); - (void)irq_attach(IRQ_USER1, irqhandler, NULL); + (void)irq_attach(IRQ_USER1, irqhandler, arg); sam_pioirqenable(IRQ_USER1); } else @@ -174,11 +154,10 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } 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/sama5d4-ek/src/sam_buttons.c b/configs/sama5d4-ek/src/sam_buttons.c index c442960fb5..5696d96de5 100644 --- a/configs/sama5d4-ek/src/sam_buttons.c +++ b/configs/sama5d4-ek/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sama5d4-ek/src/sam_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 @@ -51,6 +51,7 @@ #include #include +#include #include #include @@ -64,22 +65,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_SAMA5_PIOE_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irquser1; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -132,9 +117,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_SAMA5_PIOE_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; + int ret = -EINVAL; if (id == BUTTON_USER) { @@ -146,11 +131,6 @@ 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_irquser1; - g_irquser1 = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -158,7 +138,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Configure the interrupt */ sam_pioirq(PIO_BTN_USER); - (void)irq_attach(IRQ_BTN_USER, irqhandler, NULL); + (void)irq_attach(IRQ_BTN_USER, irqhandler, arg); sam_pioirqenable(IRQ_BTN_USER); } else @@ -170,11 +150,10 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } 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/samd20-xplained/src/sam_buttons.c b/configs/samd20-xplained/src/sam_buttons.c index 282c222f33..88c24aced7 100644 --- a/configs/samd20-xplained/src/sam_buttons.c +++ b/configs/samd20-xplained/src/sam_buttons.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -53,22 +54,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_PORTA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irqsw0; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -123,9 +108,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_PORTA_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; + int ret = -EINVAL; if (id == BUTTON_SW0) { @@ -137,20 +122,15 @@ 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_irqsw0; - *g_irqsw0 = irqhandler; - /* Configure the interrupt */ sam_portirq(IRQ_SW0); - (void)irq_attach(IRQ_SW0, irqhandler, NULL); + (void)irq_attach(IRQ_SW0, irqhandler, arg); sam_portirqenable(IRQ_SW0); - leave_critical_section(flags); - } - /* Return the old button handler (so that it can be restored) */ + leave_critical_section(flags); + ret = OK; + } return oldhandler; } diff --git a/configs/samd21-xplained/src/sam_buttons.c b/configs/samd21-xplained/src/sam_buttons.c index 989bfd35a8..aa19ddc008 100644 --- a/configs/samd21-xplained/src/sam_buttons.c +++ b/configs/samd21-xplained/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/samd21-xplained/src/sam_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 @@ -53,22 +54,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_PORTA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irqsw0; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -123,9 +108,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_PORTA_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; + int ret = -EINVAL; if (id == BUTTON_SW0) { @@ -137,22 +122,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_irqsw0; - *g_irqsw0 = irqhandler; - /* Configure the interrupt */ sam_portirq(IRQ_SW0); - (void)irq_attach(IRQ_SW0, irqhandler, NULL); + (void)irq_attach(IRQ_SW0, irqhandler, arg); sam_portirqenable(IRQ_SW0); + 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/same70-xplained/src/sam_buttons.c b/configs/same70-xplained/src/sam_buttons.c index 7d46437777..669a6d3bfe 100644 --- a/configs/same70-xplained/src/sam_buttons.c +++ b/configs/same70-xplained/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sam4e-ek/src/sam_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 @@ -59,20 +60,11 @@ * Pre-processor Definitions ****************************************************************************/ -/**************************************************************************** - * Private Data - ****************************************************************************/ - #ifdef CONFIG_ARCH_IRQBUTTONS - -#define HAVE_IRQBUTTONS 1 -#ifndef CONFIG_SAMV7_GPIOA_IRQ -# undef HAVE_IRQBUTTONS -#endif - -#ifdef CONFIG_SAMV7_GPIOA_IRQ -static xcpt_t g_irq_sw0; -#endif +# define HAVE_IRQBUTTONS 1 +# ifndef CONFIG_SAMV7_GPIOA_IRQ +# undef HAVE_IRQBUTTONS +# endif #endif /**************************************************************************** @@ -88,10 +80,9 @@ static xcpt_t g_irq_sw0; ****************************************************************************/ #ifdef HAVE_IRQBUTTONS -static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, - xcpt_t irqhandler, xcpt_t *store, void *arg) +static int board_button_irqx(gpio_pinset_t pinset, int irq, + xcpt_t irqhandler, void *arg) { - xcpt_t oldhandler; irqstate_t flags; /* Disable interrupts until we are done. This guarantees that the following @@ -100,11 +91,6 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = *store; - *store = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -124,10 +110,7 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, } leave_critical_section(flags); - - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return OK; } #endif @@ -187,17 +170,16 @@ 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) { #ifdef HAVE_IRQBUTTONS if (id == BUTTON_SW0) { - return board_button_irqx(GPIO_SW0, IRQ_SW0, irqhandler, &g_irq_sw0, arg); + return board_button_irqx(GPIO_SW0, IRQ_SW0, irqhandler, arg); } #endif - return NULL; - + return -EINVAL; } #endif diff --git a/configs/saml21-xplained/src/sam_buttons.c b/configs/saml21-xplained/src/sam_buttons.c index e571f251a6..73b344124f 100644 --- a/configs/saml21-xplained/src/sam_buttons.c +++ b/configs/saml21-xplained/src/sam_buttons.c @@ -145,7 +145,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Configure the interrupt */ sam_portirq(IRQ_SW0); - (void)irq_attach(IRQ_SW0, irqhandler, NULL); + (void)irq_attach(IRQ_SW0, irqhandler, arg); sam_portirqenable(IRQ_SW0); leave_critical_section(flags); } diff --git a/configs/samv71-xult/src/sam_buttons.c b/configs/samv71-xult/src/sam_buttons.c index a8c3f148dc..65230f0781 100644 --- a/configs/samv71-xult/src/sam_buttons.c +++ b/configs/samv71-xult/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sam4e-ek/src/sam_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 @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -64,18 +65,10 @@ ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS - -#define HAVE_IRQBUTTONS 1 -#if !defined(CONFIG_SAMV7_GPIOA_IRQ) && !defined(CONFIG_SAMV7_GPIOB_IRQ) -# undef HAVE_IRQBUTTONS -#endif - -#ifdef CONFIG_SAMV7_GPIOA_IRQ -static xcpt_t g_irq_sw0; -#endif -#ifdef CONFIG_SAMV7_GPIOB_IRQ -static xcpt_t g_irq_sw1; -#endif +# define HAVE_IRQBUTTONS 1 +# if !defined(CONFIG_SAMV7_GPIOA_IRQ) && !defined(CONFIG_SAMV7_GPIOB_IRQ) +# undef HAVE_IRQBUTTONS +# endif #endif /**************************************************************************** @@ -92,9 +85,8 @@ static xcpt_t g_irq_sw1; #ifdef HAVE_IRQBUTTONS static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, - xcpt_t irqhandler, xcpt_t *store, void *arg) + xcpt_t irqhandler, void *arg) { - xcpt_t oldhandler; irqstate_t flags; /* Disable interrupts until we are done. This guarantees that the following @@ -103,11 +95,6 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = *store; - *store = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -127,10 +114,7 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, } leave_critical_section(flags); - - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return OK; } #endif @@ -207,7 +191,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) { #ifdef HAVE_IRQBUTTONS @@ -215,21 +199,21 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { #ifdef CONFIG_SAMV7_GPIOA_IRQ case BUTTON_SW0: - return board_button_irqx(GPIO_SW0, IRQ_SW0, irqhandler, &g_irq_sw0, arg); + return board_button_irqx(GPIO_SW0, IRQ_SW0, irqhandler, arg); #endif #ifdef CONFIG_SAMV7_GPIOB_IRQ case BUTTON_SW1: - return board_button_irqx(GPIO_SW1, IRQ_SW1, irqhandler, &g_irq_sw1, arg); + return board_button_irqx(GPIO_SW1, IRQ_SW1, irqhandler, arg); #endif default: - return NULL; + return -EINVAL; } #else - return NULL; + return -ENOSYS; #endif } diff --git a/configs/zkit-arm-1769/src/lpc17_buttons.c b/configs/zkit-arm-1769/src/lpc17_buttons.c index 936f63576f..6c98465032 100644 --- a/configs/zkit-arm-1769/src/lpc17_buttons.c +++ b/configs/zkit-arm-1769/src/lpc17_buttons.c @@ -176,7 +176,7 @@ int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Attach the new interrupt handler and enable the interrupt */ - ret = irq_attach(ZKITARM_KEY5_IRQ, irqhandler, NULL); + ret = irq_attach(ZKITARM_KEY5_IRQ, irqhandler, arg); if (ret == OK) { up_enable_irq(ZKITARM_KEY5_IRQ);