summaryrefslogtreecommitdiff
path: root/nuttx/drivers/input/stmpe11_base.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-05-05 23:17:25 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-05-05 23:17:25 +0000
commit5ec5d2ad4dc73eb8235d42f6b823754b53d7223d (patch)
tree3d90f49b12de4032eef21df067f4d2dff75a3221 /nuttx/drivers/input/stmpe11_base.c
parentfffb5bd4f05cf422e06f650f4d13b40fe9675463 (diff)
downloadpx4-nuttx-5ec5d2ad4dc73eb8235d42f6b823754b53d7223d.tar.gz
px4-nuttx-5ec5d2ad4dc73eb8235d42f6b823754b53d7223d.tar.bz2
px4-nuttx-5ec5d2ad4dc73eb8235d42f6b823754b53d7223d.zip
Add GPIO support to STMPE11 driver; NFS update
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4701 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/drivers/input/stmpe11_base.c')
-rw-r--r--nuttx/drivers/input/stmpe11_base.c131
1 files changed, 131 insertions, 0 deletions
diff --git a/nuttx/drivers/input/stmpe11_base.c b/nuttx/drivers/input/stmpe11_base.c
index 25f6a1e81..bfa1a45b8 100644
--- a/nuttx/drivers/input/stmpe11_base.c
+++ b/nuttx/drivers/input/stmpe11_base.c
@@ -79,6 +79,122 @@ static struct stmpe11_dev_s *g_stmpe11list;
****************************************************************************/
/****************************************************************************
+ * Name: stmpe11_worker
+ *
+ * Description:
+ * This is the "bottom half" of the STMPE11 interrupt handler
+ *
+ ****************************************************************************/
+
+static void stmpe11_worker(FAR void *arg)
+{
+ FAR struct stmpe11_dev_s *priv = (FAR struct stmpe11_dev_s *)arg;
+ uint8_t regval;
+
+ /* Get the globl interrupt status */
+
+ regval = stmpe11_getreg8(priv, STMPE11_INT_STA);
+
+ /* Check for a touchscreen interrupt */
+
+#ifndef CONFIG_STMPE11_TSC_DISABLE
+ if ((regval & (INT_TOUCH_DET|INT_FIFO_TH|INT_FIFO_OFLOW)) != 0)
+ {
+ /* Dispatch the touchscreen interrupt if it was brought into the link */
+
+ if (stmpe11_tscint)
+ {
+ stmpe11_tscint(priv);
+ }
+
+ stmpe11_putreg8(priv, STMPE11_INT_STA, (INT_TOUCH_DET|INT_FIFO_TH|INT_FIFO_OFLOW));
+ regval &= ~(INT_TOUCH_DET|INT_FIFO_TH|INT_FIFO_OFLOW);
+ }
+#endif
+
+#if !defined(CONFIG_STMPE11_GPIO_DISABLE) && !defined(CONFIG_STMPE11_GPIOINT_DISABLE)
+ if ((regval & INT_GPIO) != 0)
+ {
+ /* Dispatch the GPIO interrupt if it was brought into the link */
+
+ if (stmpe11_gpioint)
+ {
+ stmpe11_gpioint(priv);
+ }
+
+ stmpe11_putreg8(priv, STMPE11_INT_STA, INT_GPIO);
+ regval &= ~INT_GPIO;
+ }
+#endif
+
+ /* Clear any other residual, unhandled pending interrupt */
+
+ if (regval != 0)
+ {
+ stmpe11_putreg8(priv, STMPE11_INT_STA, regval);
+ }
+
+ /* Clear the STMPE11 global interrupt */
+
+ priv->config->clear(priv->config);
+}
+
+/****************************************************************************
+ * Name: stmpe11_interrupt
+ *
+ * Description:
+ * The STMPE11 interrupt handler
+ *
+ ****************************************************************************/
+
+static int stmpe11_interrupt(int irq, FAR void *context)
+{
+ FAR struct stmpe11_dev_s *priv;
+ FAR struct stmpe11_config_s *config;
+ int ret;
+
+ /* Which STMPE11 device caused the interrupt? */
+
+#ifndef CONFIG_STMPE11_MULTIPLE
+ priv = &g_stmpe11;
+#else
+ for (priv = g_stmpe11list;
+ priv && priv->configs->irq != irq;
+ priv = priv->flink);
+
+ ASSERT(priv != NULL);
+#endif
+
+ /* Get a pointer the callbacks for convenience (and so the code is not so
+ * ugly).
+ */
+
+ config = priv->config;
+ DEBUGASSERT(config != NULL);
+
+ /* Disable further interrupts */
+
+ config->enable(config, false);
+
+ /* Transfer processing to the worker thread. Since STMPE11 interrupts are
+ * disabled while the work is pending, no special action should be required
+ * to protected the work queue.
+ */
+
+ DEBUGASSERT(priv->work.worker == NULL);
+ ret = work_queue(&priv->work, stmpe11_worker, priv, 0);
+ if (ret != 0)
+ {
+ illdbg("Failed to queue work: %d\n", ret);
+ }
+
+ /* Clear any pending interrupts and return success */
+
+ config->clear(config);
+ return OK;
+}
+
+/****************************************************************************
* Name: stmpe11_checkid
*
* Description:
@@ -191,6 +307,7 @@ STMPE11_HANDLE stmpe11_instantiate(FAR struct i2c_dev_s *dev,
/* Initialize the device state structure */
+ sem_init(&priv->exclsem, 0, 1);
#ifdef CONFIG_STMPE11_SPI
priv->spi = dev;
#else
@@ -211,6 +328,20 @@ STMPE11_HANDLE stmpe11_instantiate(FAR struct i2c_dev_s *dev,
/* Generate STMPE11 Software reset */
stmpe11_reset(priv);
+
+ /* Attach the STMPE11 interrupt handler * yet).
+ */
+
+ config->attach(config, stmpe11_interrupt);
+
+ /* Clear any pending interrupts */
+
+ stmpe11_putreg8(priv, STMPE11_INT_STA, INT_ALL);
+ config->clear(config);
+ config->enable(config, true);
+
+ /* Return our private data structure as an opaque handle */
+
return (STMPE11_HANDLE)priv;
}