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); }