From 1182702b808bcf8e878ff2ffe252875b18ec30ca Mon Sep 17 00:00:00 2001 From: Sebastien Lorquet Date: Thu, 19 Oct 2017 08:10:40 -0600 Subject: [PATCH] drivers/ioexpander: The IRQ subsystem now supports passing a void * parameter to IRQ handlers. Use that method to support multiple pc9555 devices, by passing a pointer to the device to the board defined irq handler. Now the CONFIG_ for multiple PCA devices just allocates device structures dynamically instead of statically when not enabled. The same interrupt handler is entered with the device structure parameter in all situations, multiple or single PCA. One should still be careful if multiple PCA devices share the same IRQ. --- drivers/ioexpander/Kconfig | 1 - drivers/ioexpander/pca9555.c | 15 +++------------ include/nuttx/ioexpander/pca9555.h | 7 ++----- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/drivers/ioexpander/Kconfig b/drivers/ioexpander/Kconfig index 2b801e86dce..0e9e0503a53 100644 --- a/drivers/ioexpander/Kconfig +++ b/drivers/ioexpander/Kconfig @@ -26,7 +26,6 @@ if IOEXPANDER_PCA9555 config PCA9555_MULTIPLE bool "Multiple PCA9555 Devices" default n - depends on EXPERIMENTAL ---help--- Can be defined to support multiple PCA9555 devices on board. diff --git a/drivers/ioexpander/pca9555.c b/drivers/ioexpander/pca9555.c index 454a7e2a32d..f7a1bd9d6f0 100644 --- a/drivers/ioexpander/pca9555.c +++ b/drivers/ioexpander/pca9555.c @@ -868,18 +868,9 @@ static void pca9555_irqworker(void *arg) * ****************************************************************************/ -static int pca9555_interrupt(int irq, FAR void *context) +static int pca9555_interrupt(int irq, FAR void *context, FAR void *arg) { -#ifdef CONFIG_PCA9555_MULTIPLE - /* To support multiple devices, - * retrieve the pca structure using the irq number. - */ - -# warning Missing logic - -#else - register FAR struct pca9555_dev_s *pca = &g_pca9555; -#endif + register FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s*)arg; /* In complex environments, we cannot do I2C transfers from the interrupt * handler because semaphores are probably used to lock the I2C bus. In @@ -956,7 +947,7 @@ FAR struct ioexpander_dev_s *pca9555_initialize(FAR struct i2c_master_s *i2cdev, pcadev->config = config; #ifdef CONFIG_PCA9555_INT_ENABLE - pcadev->config->attach(pcadev->config, pca9555_interrupt); + pcadev->config->attach(pcadev->config, pca9555_interrupt, pcadev); pcadev->config->enable(pcadev->config, TRUE); #endif diff --git a/include/nuttx/ioexpander/pca9555.h b/include/nuttx/ioexpander/pca9555.h index 151b9fed36a..f48e061c89d 100644 --- a/include/nuttx/ioexpander/pca9555.h +++ b/include/nuttx/ioexpander/pca9555.h @@ -74,10 +74,6 @@ struct pca9555_config_s * be provided for each so that their interrupts can be distinguished. */ -#ifdef CONFIG_PCA9555_MULTIPLE - int irq; /* IRQ number received by interrupt handler. */ -#endif - /* IRQ/GPIO access callbacks. These operations all hidden behind * callbacks to isolate the PCA9555 driver from differences in GPIO * interrupt handling by varying boards and MCUs. @@ -86,7 +82,8 @@ struct pca9555_config_s * enable - Enable or disable the GPIO interrupt */ - CODE int (*attach)(FAR struct pca9555_config_s *state, xcpt_t isr); + CODE int (*attach)(FAR struct pca9555_config_s *state, xcpt_t isr, + FAR void *arg); CODE void (*enable)(FAR struct pca9555_config_s *state, bool enable); #endif };