aboutsummaryrefslogtreecommitdiff
path: root/nuttx/drivers/input
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/drivers/input')
-rw-r--r--nuttx/drivers/input/Kconfig191
-rw-r--r--nuttx/drivers/input/ads7843e.c224
-rw-r--r--nuttx/drivers/input/ads7843e.h2
3 files changed, 343 insertions, 74 deletions
diff --git a/nuttx/drivers/input/Kconfig b/nuttx/drivers/input/Kconfig
index 9fde35ff6..1f345ee14 100644
--- a/nuttx/drivers/input/Kconfig
+++ b/nuttx/drivers/input/Kconfig
@@ -2,6 +2,7 @@
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
+
config INPUT_TSC2007
bool "TI TSC2007 touchscreen controller"
default n
@@ -9,7 +10,29 @@ config INPUT_TSC2007
---help---
Enable support for the TI TSC2007 touchscreen controller
-
+if INPUT_TSC2007
+
+config TSC2007_8BIT
+ bool "8-bit Conversions"
+ default n
+ ---help---
+ Use faster, but less accurate, 8-bit conversions. Default: 12-bit conversions.
+
+config TSC2007_MULTIPLE
+ bool "Multiple TSC2007 Devices"
+ default n
+ ---help---
+ Can be defined to support multiple TSC2007 devices on board.
+
+config TSC2007_NPOLLWAITERS
+ int "Number poll waiters"
+ default 4
+ depends on !DISABLE_POLL
+ ---help---
+ Maximum number of threads that can be waiting on poll()
+
+endif
+
config INPUT_ADS7843E
bool "TI ADS7843/TSC2046 touchscreen controller"
default n
@@ -18,3 +41,169 @@ config INPUT_ADS7843E
Enable support for the TI/Burr-Brown ADS7842 touchscreen controller. I believe
that driver should be compatibile with the TI/Burr-Brown TSC2046 and XPT2046
touchscreen controllers as well.
+
+if INPUT_ADS7843E
+
+config ADS7843E_MULTIPLE
+ bool "Multiple ADS7843E Devices"
+ default n
+ ---help---
+ Can be defined to support multiple ADS7843E devices on board.
+
+config ADS7843E_NPOLLWAITERS
+ int "Number poll waiters"
+ default 4
+ depends on !DISABLE_POLL
+ ---help---
+ Maximum number of threads that can be waiting on poll()
+
+config ADS7843E_SPIMODE
+ int "SPI mode"
+ default 0
+ range 0,3
+ ---help---
+ Controls the SPI mode. The device should work in mode 0, but sometimes
+ you need to experiment.
+
+config ADS7843E_FREQUENCY
+ int "SPI frequency"
+ default 100000
+ ---help---
+ Define to use a different SPI bus frequency.
+
+config ADS7843E_SWAPXY
+ bool "Swap X/Y"
+ default n
+ ---help---
+ Reverse the meaning of X and Y to handle different LCD orientations.
+
+config ADS7843E_THRESHX
+ int "X threshold"
+ default 12
+ ---help---
+ New touch positions will only be reported when the X or Y data changes by these
+ thresholds. This trades reduces data rate for some loss in dragging accuracy. For
+ 12-bit values so the raw ranges are 0-4095. So for example, if your display is
+ 320x240, then THRESHX=13 and THRESHY=17 would correspond to one pixel. Default: 12
+
+config ADS7843E_THRESHY
+ int "Y threshold"
+ default 12
+ ---help---
+ New touch positions will only be reported when the X or Y data changes by these
+ thresholds. This trades reduces data rate for some loss in dragging accuracy. For
+ 12-bit values so the raw ranges are 0-4095. So for example, if your display is
+ 320x240, then THRESHX=13 and THRESHY=17 would correspond to one pixel. Default: 12
+
+endif
+
+config INPUT_STMPE811
+ bool "STMicro STMPE811 Driver"
+ default n
+ ---help---
+ Enables support for the STMPE811 driver
+
+if INPUT_STMPE811
+
+choice
+ prompt "STMPE Interface"
+ default STMPE811_I2C
+
+config STMPE811_SPI
+ bool "SPI Interface"
+ select SPI
+ ---help---
+ Enables support for the SPI interface (not currently supported)
+
+config STMPE811_I2C
+ bool "STMPE811 I2C Interface"
+ select I2C
+ ---help---
+ Enables support for the I2C interface
+
+endchoice
+
+config STMPE811_MULTIPLE
+ bool "Multiple STMPE811 Devices"
+ default n
+ ---help---
+ Can be defined to support multiple STMPE811 devices on board.
+
+config STMPE811_NPOLLWAITERS
+ int "Number poll waiters"
+ default 4
+ depends on !DISABLE_POLL
+ ---help---
+ Maximum number of threads that can be waiting on poll()
+
+config STMPE811_TSC_DISABLE
+ bool "Disable STMPE811 Touchscreen Support"
+ default n
+ ---help---
+ Disable driver touchscreen functionality.
+
+config STMPE811_SWAPXY
+ bool "Swap X/Y"
+ default n
+ depends on !STMPE811_TSC_DISABLE
+ ---help---
+ Reverse the meaning of X and Y to handle different LCD orientations.
+
+config STMPE811_THRESHX
+ int "X threshold"
+ default 12
+ depends on !STMPE811_TSC_DISABLE
+ ---help---
+ STMPE811 touchscreen data comes in a a very high rate. New touch positions
+ will only be reported when the X or Y data changes by these thresholds.
+ This trades reduces data rate for some loss in dragging accuracy. The
+ STMPE811 is configure for 12-bit values so the raw ranges are 0-4095. So
+ for example, if your display is 320x240, then THRESHX=13 and THRESHY=17
+ would correspond to one pixel. Default: 12
+
+config STMPE811_THRESHY
+ int "Y threshold"
+ default 12
+ depends on !STMPE811_TSC_DISABLE
+ ---help---
+ STMPE811 touchscreen data comes in a a very high rate. New touch positions
+ will only be reported when the X or Y data changes by these thresholds.
+ This trades reduces data rate for some loss in dragging accuracy. The
+ STMPE811 is configure for 12-bit values so the raw ranges are 0-4095. So
+ for example, if your display is 320x240, then THRESHX=13 and THRESHY=17
+ would correspond to one pixel. Default: 12
+
+config STMPE811_ADC_DISABLE
+ bool "Disable STMPE811 ADC Support"
+ default y
+ ---help---
+ Disable driver ADC functionality.
+
+config STMPE811_GPIO_DISABLE
+ bool "Disable STMPE811 GPIO Support"
+ default y
+ ---help---
+ Disable driver GPIO functionality.
+
+config STMPE811_GPIOINT_DISABLE
+ bool "Disable STMPE811 GPIO Interrupt Support"
+ default y
+ depends on !STMPE811_GPIO_DISABLE
+ ---help---
+ Disable driver GPIO interrupt functionlality (ignored if GPIO functionality is
+ disabled).
+
+config STMPE811_TEMP_DISABLE
+ bool "Disable STMPE811 Temperature Sensor Support"
+ default y
+ ---help---
+ Disable driver temperature sensor functionality.
+
+config STMPE811_REGDEBUG
+ bool "Enable Register-Level STMPE811 Debug"
+ default n
+ depends on DEBUG
+ ---help---
+ Enable very low register-level debug output.
+
+endif
diff --git a/nuttx/drivers/input/ads7843e.c b/nuttx/drivers/input/ads7843e.c
index 07e5e515d..06969e6d2 100644
--- a/nuttx/drivers/input/ads7843e.c
+++ b/nuttx/drivers/input/ads7843e.c
@@ -79,6 +79,12 @@
* Pre-processor Definitions
****************************************************************************/
+/* This is a value for the threshold that guantees a big difference on the
+ * first pendown (but can't overflow).
+ */
+
+#define INVALID_THRESHOLD 0x1000
+
/****************************************************************************
* Private Types
****************************************************************************/
@@ -88,13 +94,14 @@
****************************************************************************/
/* Low-level SPI helpers */
-static inline void ads7843e_configspi(FAR struct spi_dev_s *spi);
#ifdef CONFIG_SPI_OWNBUS
-static inline void ads7843e_select(FAR struct spi_dev_s *spi);
-static inline void ads7843e_deselect(FAR struct spi_dev_s *spi);
+static inline void ads7843e_configspi(FAR struct spi_dev_s *spi);
+# define ads7843e_lock(spi)
+# define ads7843e_unlock(spi)
#else
-static void ads7843e_select(FAR struct spi_dev_s *spi);
-static void ads7843e_deselect(FAR struct spi_dev_s *spi);
+# define ads7843e_configspi(spi);
+static void ads7843e_lock(FAR struct spi_dev_s *spi);
+static void ads7843e_unlock(FAR struct spi_dev_s *spi);
#endif
static inline void ads7843e_waitbusy(FAR struct ads7843e_dev_s *priv);
@@ -157,13 +164,12 @@ static struct ads7843e_dev_s *g_ads7843elist;
****************************************************************************/
/****************************************************************************
- * Function: ads7843e_select
+ * Function: ads7843e_lock
*
* Description:
- * Select the SPI, locking and re-configuring if necessary. This function
- * must be called before initiating any sequence of SPI operations. If we
- * are sharing the SPI bus with other devices (CONFIG_SPI_OWNBUS undefined)
- * then we need to lock and configure the SPI bus for each transfer.
+ * Lock the SPI bus and re-configure as necessary. This function must be
+ * to assure: (1) exclusive access to the SPI bus, and (2) to assure that
+ * the shared bus is properly configured for the touchscreen controller.
*
* Parameters:
* spi - Reference to the SPI driver structure
@@ -175,42 +181,35 @@ static struct ads7843e_dev_s *g_ads7843elist;
*
****************************************************************************/
-#ifdef CONFIG_SPI_OWNBUS
-static inline void ads7843e_select(FAR struct spi_dev_s *spi)
-{
- /* We own the SPI bus, so just select the chip */
-
- SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, true);
-}
-#else
-static void ads7843e_select(FAR struct spi_dev_s *spi)
+#ifndef CONFIG_SPI_OWNBUS
+static void ads7843e_lock(FAR struct spi_dev_s *spi)
{
- /* Select ADS7843 chip (locking the SPI bus in case there are multiple
- * devices competing for the SPI bus
+ /* Lock the SPI bus because there are multiple devices competing for the
+ * SPI bus
*/
(void)SPI_LOCK(spi, true);
- SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, true);
- /* Now make sure that the SPI bus is configured for the ADS7843 (it
- * might have gotten configured for a different device while unlocked)
+ /* We have the lock. Now make sure that the SPI bus is configured for the
+ * ADS7843 (it might have gotten configured for a different device while
+ * unlocked)
*/
+ SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, true);
SPI_SETMODE(spi, CONFIG_ADS7843E_SPIMODE);
SPI_SETBITS(spi, 8);
SPI_SETFREQUENCY(spi, CONFIG_ADS7843E_FREQUENCY);
+ SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, false);
}
#endif
/****************************************************************************
- * Function: ads7843e_deselect
+ * Function: ads7843e_unlock
*
* Description:
- * De-select the SPI, unlocking as necessary. This function must be
- * after completing a sequence of SPI operations. If we are sharing the SPI
- * bus with other devices (CONFIG_SPI_OWNBUS undefined) then we need to
- * un-lock the SPI bus for each transfer, possibly losing the current
- * configuration.
+ * If we are sharing the SPI bus with other devices (CONFIG_SPI_OWNBUS
+ * undefined) then we need to un-lock the SPI bus for each transfer,
+ * possibly losing the current configuration.
*
* Parameters:
* spi - Reference to the SPI driver structure
@@ -222,19 +221,11 @@ static void ads7843e_select(FAR struct spi_dev_s *spi)
*
****************************************************************************/
-#ifdef CONFIG_SPI_OWNBUS
-static inline void ads7843e_deselect(FAR struct spi_dev_s *spi)
-{
- /* We own the SPI bus, so just de-select the chip */
-
- SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, false);
-}
-#else
-static void ads7843e_deselect(FAR struct spi_dev_s *spi)
+#ifndef CONFIG_SPI_OWNBUS
+static void ads7843e_unlock(FAR struct spi_dev_s *spi)
{
- /* De-select ADS7843 chip and relinquish the SPI bus. */
+ /* Relinquish the SPI bus. */
- SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, false);
(void)SPI_LOCK(spi, false);
}
#endif
@@ -258,23 +249,20 @@ static void ads7843e_deselect(FAR struct spi_dev_s *spi)
*
****************************************************************************/
+#ifdef CONFIG_SPI_OWNBUS
static inline void ads7843e_configspi(FAR struct spi_dev_s *spi)
{
- idbg("Mode: %d Bits: 8 Frequency: %d\n",
- CONFIG_ADS7843E_SPIMODE, CONFIG_ADS7843E_FREQUENCY);
-
/* Configure SPI for the ADS7843. But only if we own the SPI bus. Otherwise, don't
* bother because it might change.
*/
-#ifdef CONFIG_SPI_OWNBUS
SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, true);
SPI_SETMODE(spi, CONFIG_ADS7843E_SPIMODE);
SPI_SETBITS(spi, 8);
SPI_SETFREQUENCY(spi, CONFIG_ADS7843E_FREQUENCY);
SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, false);
-#endif
}
+#endif
/****************************************************************************
* Name: ads7843e_waitbusy
@@ -296,7 +284,7 @@ static uint16_t ads7843e_sendcmd(FAR struct ads7843e_dev_s *priv, uint8_t cmd)
/* Select the ADS7843E */
- ads7843e_select(priv->spi);
+ SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, true);
/* Send the command */
@@ -306,7 +294,7 @@ static uint16_t ads7843e_sendcmd(FAR struct ads7843e_dev_s *priv, uint8_t cmd)
/* Read the data */
SPI_RECVBLOCK(priv->spi, buffer, 2);
- ads7843e_deselect(priv->spi);
+ SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, false);
result = ((uint16_t)buffer[0] << 8) | (uint16_t)buffer[1];
result = result >> 4;
@@ -554,7 +542,12 @@ static void ads7843e_worker(FAR void *arg)
{
FAR struct ads7843e_dev_s *priv = (FAR struct ads7843e_dev_s *)arg;
FAR struct ads7843e_config_s *config;
+ uint16_t x;
+ uint16_t y;
+ uint16_t xdiff;
+ uint16_t ydiff;
bool pendown;
+ int ret;
ASSERT(priv != NULL);
@@ -565,10 +558,30 @@ static void ads7843e_worker(FAR void *arg)
config = priv->config;
DEBUGASSERT(config != NULL);
- /* Disable the watchdog timer */
+ /* Disable the watchdog timer. This is safe because it is started only
+ * by this function and this function is serialized on the worker thread.
+ */
wd_cancel(priv->wdog);
+ /* Lock the SPI bus so that we have exclusive access */
+
+ ads7843e_lock(priv->spi);
+
+ /* Get exclusive access to the driver data structure */
+
+ do
+ {
+ ret = sem_wait(&priv->devsem);
+
+ /* This should only fail if the wait was canceled by an signal
+ * (and the worker thread will receive a lot of signals).
+ */
+
+ DEBUGASSERT(ret == OK || errno == EINTR);
+ }
+ while (ret < 0);
+
/* Check for pen up or down by reading the PENIRQ GPIO. */
pendown = config->pendown(config);
@@ -577,13 +590,20 @@ static void ads7843e_worker(FAR void *arg)
if (!pendown)
{
- /* Ignore the interrupt if the pen was already up (CONTACT_NONE == pen up and
- * already reported. CONTACT_UP == pen up, but not reported)
+ /* The pen is up.. reset thresholding variables. */
+
+ priv->threshx = INVALID_THRESHOLD;
+ priv->threshy = INVALID_THRESHOLD;
+
+ /* Ignore the interrupt if the pen was already up (CONTACT_NONE == pen up
+ * and already reported; CONTACT_UP == pen up, but not reported)
*/
- if (priv->sample.contact == CONTACT_NONE)
+ if (priv->sample.contact == CONTACT_NONE ||
+ priv->sample.contact == CONTACT_UP)
+
{
- goto errout;
+ goto ignored;
}
/* The pen is up. NOTE: We know from a previous test, that this is a
@@ -601,14 +621,57 @@ static void ads7843e_worker(FAR void *arg)
else if (priv->sample.contact == CONTACT_UP)
{
- goto errout;
+ /* If we have not yet processed the last pen up event, then we
+ * cannot handle this pen down event. We will have to discard it. That
+ * should be okay because we will set the timer to to sample again
+ * later.
+ */
+
+ wd_start(priv->wdog, ADS7843E_WDOG_DELAY, ads7843e_wdog, 1, (uint32_t)priv);
+ goto ignored;
}
else
{
/* Handle pen down events. First, sample positional values. */
- priv->sample.x = ads7843e_sendcmd(priv, ADS7843_CMD_XPOSITION);
- priv->sample.y = ads7843e_sendcmd(priv, ADS7843_CMD_YPOSITION);
+#ifdef CONFIG_ADS7843E_SWAPXY
+ x = ads7843e_sendcmd(priv, ADS7843_CMD_YPOSITION);
+ y = ads7843e_sendcmd(priv, ADS7843_CMD_XPOSITION);
+#else
+ x = ads7843e_sendcmd(priv, ADS7843_CMD_XPOSITION);
+ y = ads7843e_sendcmd(priv, ADS7843_CMD_YPOSITION);
+#endif
+
+ /* Perform a thresholding operation so that the results will be more stable.
+ * If the difference from the last sample is small, then ignore the event.
+ * REVISIT: Should a large change in pressure also generate a event?
+ */
+
+ xdiff = x > priv->threshx ? (x - priv->threshx) : (priv->threshx - x);
+ ydiff = y > priv->threshy ? (y - priv->threshy) : (priv->threshy - y);
+
+ /* Continue to sample the position while the pen is down */
+
+ wd_start(priv->wdog, ADS7843E_WDOG_DELAY, ads7843e_wdog, 1, (uint32_t)priv);
+
+ /* Check the thresholds. Bail if there is no significant difference */
+
+ if (xdiff < CONFIG_ADS7843E_THRESHX && ydiff < CONFIG_ADS7843E_THRESHY)
+ {
+ /* Little or no change in either direction ... don't report anything. */
+
+ goto ignored;
+ }
+
+ /* When we see a big difference, snap to the new x/y thresholds */
+
+ priv->threshx = x;
+ priv->threshy = y;
+
+ /* Update the x/y position in the sample data */
+
+ priv->sample.x = priv->threshx;
+ priv->sample.y = priv->threshy;
/* The X/Y positional data is now valid */
@@ -625,10 +688,6 @@ static void ads7843e_worker(FAR void *arg)
priv->sample.contact = CONTACT_DOWN;
}
-
- /* Continue to sample the position while the pen is down */
-
- wd_start(priv->wdog, ADS7843E_WDOG_DELAY, ads7843e_wdog, 1, (uint32_t)priv);
}
/* Indicate the availability of new sample data for this ID */
@@ -642,9 +701,15 @@ static void ads7843e_worker(FAR void *arg)
/* Exit, re-enabling ADS7843E interrupts */
-errout:
+ignored:
+
(void)ads7843e_sendcmd(priv, ADS7843_CMD_ENABPINIRQ);
config->enable(config, true);
+
+ /* Release our lock on the state structure and unlock the SPI bus */
+
+ sem_post(&priv->devsem);
+ ads7843e_unlock(priv->spi);
}
/****************************************************************************
@@ -871,7 +936,7 @@ static ssize_t ads7843e_read(FAR struct file *filep, FAR char *buffer, size_t le
report = (FAR struct touch_sample_s *)buffer;
memset(report, 0, SIZEOF_TOUCH_SAMPLE_S(1));
report->npoints = 1;
- report->point[0].id = priv->id;
+ report->point[0].id = sample.id;
report->point[0].x = sample.x;
report->point[0].y = sample.y;
@@ -886,8 +951,7 @@ static ssize_t ads7843e_read(FAR struct file *filep, FAR char *buffer, size_t le
if (sample.valid)
{
- report->point[0].flags = TOUCH_UP | TOUCH_ID_VALID |
- TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
+ report->point[0].flags = TOUCH_UP | TOUCH_ID_VALID | TOUCH_POS_VALID;
}
else
{
@@ -1098,7 +1162,7 @@ errout:
*
****************************************************************************/
-int ads7843e_register(FAR struct spi_dev_s *dev,
+int ads7843e_register(FAR struct spi_dev_s *spi,
FAR struct ads7843e_config_s *config, int minor)
{
FAR struct ads7843e_dev_s *priv;
@@ -1108,11 +1172,11 @@ int ads7843e_register(FAR struct spi_dev_s *dev,
#endif
int ret;
- ivdbg("dev: %p minor: %d\n", dev, minor);
+ ivdbg("spi: %p minor: %d\n", spi, minor);
/* Debug-only sanity checks */
- DEBUGASSERT(dev != NULL && config != NULL && minor >= 0 && minor < 100);
+ DEBUGASSERT(spi != NULL && config != NULL && minor >= 0 && minor < 100);
/* Create and initialize a ADS7843E device driver instance */
@@ -1130,11 +1194,14 @@ int ads7843e_register(FAR struct spi_dev_s *dev,
/* Initialize the ADS7843E device driver instance */
memset(priv, 0, sizeof(struct ads7843e_dev_s));
- priv->spi = dev; /* Save the SPI device handle */
- priv->config = config; /* Save the board configuration */
- priv->wdog = wd_create(); /* Create a watchdog timer */
- sem_init(&priv->devsem, 0, 1); /* Initialize device structure semaphore */
- sem_init(&priv->waitsem, 0, 0); /* Initialize pen event wait semaphore */
+ priv->spi = spi; /* Save the SPI device handle */
+ priv->config = config; /* Save the board configuration */
+ priv->wdog = wd_create(); /* Create a watchdog timer */
+ priv->threshx = INVALID_THRESHOLD; /* Initialize thresholding logic */
+ priv->threshy = INVALID_THRESHOLD; /* Initialize thresholding logic */
+
+ sem_init(&priv->devsem, 0, 1); /* Initialize device structure semaphore */
+ sem_init(&priv->waitsem, 0, 0); /* Initialize pen event wait semaphore */
/* Make sure that interrupts are disabled */
@@ -1150,14 +1217,25 @@ int ads7843e_register(FAR struct spi_dev_s *dev,
goto errout_with_priv;
}
+ idbg("Mode: %d Bits: 8 Frequency: %d\n",
+ CONFIG_ADS7843E_SPIMODE, CONFIG_ADS7843E_FREQUENCY);
+
+ /* Lock the SPI bus so that we have exclusive access */
+
+ ads7843e_lock(spi);
+
/* Configure the SPI interface */
- ads7843e_configspi(dev);
+ ads7843e_configspi(spi);
/* Enable the PEN IRQ */
ads7843e_sendcmd(priv, ADS7843_CMD_ENABPINIRQ);
+ /* Unlock the bus */
+
+ ads7843e_unlock(spi);
+
/* Register the device as an input device */
(void)snprintf(devname, DEV_NAMELEN, DEV_FORMAT, minor);
diff --git a/nuttx/drivers/input/ads7843e.h b/nuttx/drivers/input/ads7843e.h
index 43b79c7b7..6fd70d98b 100644
--- a/nuttx/drivers/input/ads7843e.h
+++ b/nuttx/drivers/input/ads7843e.h
@@ -139,6 +139,8 @@ struct ads7843e_dev_s
uint8_t nwaiters; /* Number of threads waiting for ADS7843E data */
uint8_t id; /* Current touch point ID */
volatile bool penchange; /* An unreported event is buffered */
+ uint16_t threshx; /* Thresholding X value */
+ uint16_t threshy; /* Thresholding Y value */
sem_t devsem; /* Manages exclusive access to this structure */
sem_t waitsem; /* Used to wait for the availability of data */