From 66f73fa67c4d796d4e96791a9e41b420b310a559 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 15 Jun 2014 12:43:33 -0600 Subject: [PATCH] SAM4S Xplained (both): Button interrupts not being disabled after being detached --- configs/sam4s-xplained-pro/src/sam_buttons.c | 21 ++++++++++++++++---- configs/sam4s-xplained/src/sam_buttons.c | 21 ++++++++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/configs/sam4s-xplained-pro/src/sam_buttons.c b/configs/sam4s-xplained-pro/src/sam_buttons.c index 5d3c7d92e4..49b983383c 100644 --- a/configs/sam4s-xplained-pro/src/sam_buttons.c +++ b/configs/sam4s-xplained-pro/src/sam_buttons.c @@ -141,11 +141,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/sam4s-xplained/src/sam_buttons.c b/configs/sam4s-xplained/src/sam_buttons.c index f5b06c6fa0..e3c3836aae 100644 --- a/configs/sam4s-xplained/src/sam_buttons.c +++ b/configs/sam4s-xplained/src/sam_buttons.c @@ -140,11 +140,24 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler) oldhandler = *g_irqbp2; *g_irqbp2 = irqhandler; - /* Configure the interrupt */ + /* Are we attaching or detaching? */ + + if (irqhandler != NULL) + { + /* Configure the interrupt */ + + sam_gpioirq(IRQ_BP2); + (void)irq_attach(IRQ_BP2, irqhandler); + sam_gpioirqenable(IRQ_BP2); + } + else + { + /* Detach and disable the interrupt */ + + (void)irq_detach(IRQ_BP2) + sam_gpioirqdisable(IRQ_BP2); + } - sam_gpioirq(IRQ_BP2); - (void)irq_attach(IRQ_BP2, irqhandler); - sam_gpioirqenable(IRQ_BP2); irqrestore(flags); }