From 9685fd8c99c727e5e8558a50252031b48baee44a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 1 Aug 2016 13:52:27 -0600 Subject: [PATCH] GPIO driver: Add an IOCTL to unregister a signal handler --- drivers/ioexpander/gpio.c | 27 +++++++++++++++++++++++++++ include/nuttx/ioexpander/gpio.h | 13 +++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/drivers/ioexpander/gpio.c b/drivers/ioexpander/gpio.c index 137d988ee8..bf256e8a0a 100644 --- a/drivers/ioexpander/gpio.c +++ b/drivers/ioexpander/gpio.c @@ -268,6 +268,33 @@ static int gpio_ioctl(FAR struct file *filep, int cmd, unsigned long arg) } break; + /* Command: GPIOC_UNREGISTER + * Description: Stop receiving signals for pin interrupts. + * Argument: None. + */ + + case GPIOC_UNREGISTER: + if (dev->gp_pintype == GPIO_INTERRUPT_PIN) + { + /* Make sure that the pin interrupt is disabled */ + + ret = dev->gp_ops->go_enable(dev, false); + if (ret >= 0) + { + /* Detach the handler */ + + ret = dev->gp_ops->go_attach(dev, NULL); + + dev->gp_pid = 0; + dev->gp_signo = 0; + } + } + else + { + ret = -EACCES; + } + break; + /* Unrecognized command */ default: diff --git a/include/nuttx/ioexpander/gpio.h b/include/nuttx/ioexpander/gpio.h index 7d8028e86f..287d0fa9d2 100644 --- a/include/nuttx/ioexpander/gpio.h +++ b/include/nuttx/ioexpander/gpio.h @@ -70,12 +70,17 @@ * depends upon interrupt GPIO support from the platform. * Argument: The number of signal to be generated when the interrupt * occurs. + * + * Command: GPIOC_UNREGISTER + * Description: Stop receiving signals for pin interrupts. + * Argument: None. */ -#define GPIOC_WRITE _GPIOC(1) -#define GPIOC_READ _GPIOC(2) -#define GPIOC_PINTYPE _GPIOC(3) -#define GPIOC_REGISTER _GPIOC(4) +#define GPIOC_WRITE _GPIOC(1) +#define GPIOC_READ _GPIOC(2) +#define GPIOC_PINTYPE _GPIOC(3) +#define GPIOC_REGISTER _GPIOC(4) +#define GPIOC_UNREGISTER _GPIOC(5) /**************************************************************************** * Public Types