From 9d7827917346a7d7b53c0e3a5719b2b472d5f3d3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 15 Jun 2014 12:55:48 -0600 Subject: [PATCH] Several other interrupt button implementations had the same problem as did the sam4s-xplained --- configs/sam3u-ek/src/up_buttons.c | 21 +++++++++++++++++---- configs/sam4e-ek/src/sam_buttons.c | 21 +++++++++++++++++---- configs/sam4l-xplained/src/sam_buttons.c | 21 +++++++++++++++++---- configs/sure-pic32mx/src/pic32mx_buttons.c | 6 ++++-- configs/ubw32/src/up_buttons.c | 6 ++++-- 5 files changed, 59 insertions(+), 16 deletions(-) diff --git a/configs/sam3u-ek/src/up_buttons.c b/configs/sam3u-ek/src/up_buttons.c index 8406025de1..f188d396e1 100644 --- a/configs/sam3u-ek/src/up_buttons.c +++ b/configs/sam3u-ek/src/up_buttons.c @@ -94,11 +94,24 @@ static xcpt_t board_button_irqx(int irq, xcpt_t irqhandler, xcpt_t *store) oldhandler = *store; *store = irqhandler; - /* Configure the interrupt */ + /* Are we attaching or detaching? */ + + if (irqhandler != NULL) + { + /* Configure the interrupt */ + + sam_gpioirq(irq); + (void)irq_attach(irq, irqhandler); + sam_gpioirqenable(irq); + } + else + { + /* Detach and disable the interrupt */ + + (void)irq_detach(irq) + sam_gpioirqdisable(irq); + } - sam_gpioirq(irq); - (void)irq_attach(irq, irqhandler); - sam_gpioirqenable(irq); irqrestore(flags); /* Return the old button handler (so that it can be restored) */ diff --git a/configs/sam4e-ek/src/sam_buttons.c b/configs/sam4e-ek/src/sam_buttons.c index 9f6283878c..72ef722a5f 100644 --- a/configs/sam4e-ek/src/sam_buttons.c +++ b/configs/sam4e-ek/src/sam_buttons.c @@ -96,11 +96,24 @@ static xcpt_t board_button_irqx(int irq, xcpt_t irqhandler, xcpt_t *store) oldhandler = *store; *store = irqhandler; - /* Configure the interrupt */ + /* Are we attaching or detaching? */ + + if (irqhandler != NULL) + { + /* Configure the interrupt */ + + sam_gpioirq(irq); + (void)irq_attach(irq, irqhandler); + sam_gpioirqenable(irq); + } + else + { + /* Detach and disable the interrupt */ + + (void)irq_detach(irq) + sam_gpioirqdisable(irq); + } - sam_gpioirq(irq); - (void)irq_attach(irq, irqhandler); - sam_gpioirqenable(irq); irqrestore(flags); /* Return the old button handler (so that it can be restored) */ diff --git a/configs/sam4l-xplained/src/sam_buttons.c b/configs/sam4l-xplained/src/sam_buttons.c index 13401d3ac9..f0e7459fe4 100644 --- a/configs/sam4l-xplained/src/sam_buttons.c +++ b/configs/sam4l-xplained/src/sam_buttons.c @@ -142,11 +142,24 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler) oldhandler = *g_irqsw0; *g_irqsw0 = irqhandler; - /* Configure the interrupt */ + /* Are we attaching or detaching? */ + + if (irqhandler != NULL) + { + /* Configure the interrupt */ + + sam_gpioirq(IRQ_SW0); + (void)irq_attach(IRQ_SW0, irqhandler); + sam_gpioirqenable(IRQ_SW0); + } + else + { + /* Detach and disable the interrupt */ + + (void)irq_detach(IRQ_SW0) + sam_gpioirqdisable(IRQ_SW0); + } - sam_gpioirq(IRQ_SW0); - (void)irq_attach(IRQ_SW0, irqhandler); - sam_gpioirqenable(IRQ_SW0); irqrestore(flags); } diff --git a/configs/sure-pic32mx/src/pic32mx_buttons.c b/configs/sure-pic32mx/src/pic32mx_buttons.c index 2e91cf193e..b29bb73fa2 100644 --- a/configs/sure-pic32mx/src/pic32mx_buttons.c +++ b/configs/sure-pic32mx/src/pic32mx_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sure-pic32mx/src/pic32mx_buttons.c * - * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013-2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -211,12 +211,14 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler) if (id < NUM_BUTTONS) { + pic32mx_gpioirqdisable(g_buttoncn[id]); oldhandler = pic32mx_gpioattach(g_buttonset[id], g_buttoncn[id], irqhandler); - if (irqbuttron) + if (irqhandler != NULL) { pic32mx_gpioirqenable(g_buttoncn[id]); } } + return oldhandler; } #endif diff --git a/configs/ubw32/src/up_buttons.c b/configs/ubw32/src/up_buttons.c index abc6e70f95..c1fa1125b1 100644 --- a/configs/ubw32/src/up_buttons.c +++ b/configs/ubw32/src/up_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/ubw32/src/board_buttons.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -186,12 +186,14 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler) if (id < NUM_BUTTONS) { + pic32mx_gpioirqdisable(g_buttoncn[id]); oldhandler = pic32mx_gpioattach(g_buttonset[id], g_buttoncn[id], irqhandler); - if (irqbuttron) + if (irqhandler) { pic32mx_gpioirqenable(g_buttoncn[id]); } } + return oldhandler; } #endif