SMTPE11 and NxWM touchscreen fixes

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4722 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2012-05-11 18:27:46 +00:00
parent 834af0f5fb
commit db6865da85
9 changed files with 107 additions and 53 deletions

View File

@ -2730,5 +2730,9 @@
* configs/sam3u-ek, configs/sim, arch/sim/src/up_touchscreen.c, and
apps/examples/touchscreen: Standardize the board-specific, touchscreen
initialization interfaces.
* drivers/input/stmpe11_base.c and configs/stm3240g-eval: The STMPE11-based
touchscreen seems to work better with edge (vs. level) interrupts
* drivers/input/stmpe11_tsc.c: Fix some status checks so that the touchscreen
interrupt handling logic does not read data if the fifo is not at the
threshold level.

View File

@ -4690,7 +4690,11 @@ build
</li>
<li>
<code>CONFIG_STMPE11_ACTIVELOW</code>:
Interrupt is generated by an active low signal.
Interrupt is generated by an active low signal (or falling edge).
</li>
<li>
<code>CONFIG_STMPE11_EDGE</code>:
Interrupt is generated on an edge (vs. on the active level)
</li>
<li>
<code>CONFIG_STMPE11_NPOLLWAITERS</code>:

View File

@ -793,7 +793,9 @@ defconfig -- This is a configuration file similar to the Linux
CONFIG_STMPE11_MULTIPLE
Can be defined to support multiple STMPE11 devices on board.
CONFIG_STMPE11_ACTIVELOW
Interrupt is generated by an active low signal.
Interrupt is generated by an active low signal (or falling edge).
CONFIG_STMPE11_EDGE
Interrupt is generated on an edge (vs. on the active level)
CONFIG_STMPE11_NPOLLWAITERS
Maximum number of threads that can be waiting on poll() (ignored if
CONFIG_DISABLE_POLL is set).

View File

@ -968,7 +968,9 @@ CONFIG_INPUT_TSC2007=n
# CONFIG_STMPE11_MULTIPLE
# Can be defined to support multiple STMPE11 devices on board.
# CONFIG_STMPE11_ACTIVELOW
# Interrupt is generated by an active low signal.
# Interrupt is generated by an active low signal (or falling edge).
# CONFIG_STMPE11_EDGE
# Interrupt is generated on an edge (vs. on the active level)
# CONFIG_STMPE11_NPOLLWAITERS
# Maximum number of threads that can be waiting on poll() (ignored if
# CONFIG_DISABLE_POLL is set).
@ -994,6 +996,7 @@ CONFIG_STMPE11_SPI=n
CONFIG_STMPE11_I2C=y
CONFIG_STMPE11_MULTIPLE=y
CONFIG_STMPE11_ACTIVELOW=y
CONFIG_STMPE11_EDGE=y
#CONFIG_STMPE11_NPOLLWAITERS
CONFIG_STMPE11_TSC_DISABLE=n
CONFIG_STMPE11_ADC_DISABLE=y

View File

@ -968,7 +968,9 @@ CONFIG_INPUT_TSC2007=n
# CONFIG_STMPE11_MULTIPLE
# Can be defined to support multiple STMPE11 devices on board.
# CONFIG_STMPE11_ACTIVELOW
# Interrupt is generated by an active low signal.
# Interrupt is generated by an active low signal (or falling edge).
# CONFIG_STMPE11_EDGE
# Interrupt is generated on an edge (vs. on the active level)
# CONFIG_STMPE11_NPOLLWAITERS
# Maximum number of threads that can be waiting on poll() (ignored if
# CONFIG_DISABLE_POLL is set).
@ -994,6 +996,7 @@ CONFIG_STMPE11_SPI=n
CONFIG_STMPE11_I2C=y
CONFIG_STMPE11_MULTIPLE=y
CONFIG_STMPE11_ACTIVELOW=y
CONFIG_STMPE11_EDGE=y
#CONFIG_STMPE11_NPOLLWAITERS
CONFIG_STMPE11_TSC_DISABLE=n
CONFIG_STMPE11_ADC_DISABLE=y

View File

@ -49,6 +49,8 @@
#include <nuttx/input/touchscreen.h>
#include <nuttx/input/stmpe11.h>
#include <arch/irq.h>
#include "stm32_internal.h"
#include "stm3240g-internal.h"
@ -221,10 +223,14 @@ static int stmpe11_attach(FAR struct stmpe11_config_s *state, xcpt_t isr)
static void stmpe11_enable(FAR struct stmpe11_config_s *state, bool enable)
{
FAR struct stm32_stmpe11config_s *priv = (FAR struct stm32_stmpe11config_s *)state;
irqstate_t flags;
/* Attach and enable, or detach and disable */
/* Attach and enable, or detach and disable. Enabling and disabling GPIO
* interrupts is a multi-step process so the safest thing is to keep
* interrupts disabled during the reconfiguratino.
*/
ivdbg("IRQ:%d enable:%d\n", STM32_IRQ_EXTI2, enable);
flags = irqsave();
if (enable)
{
/* Configure the EXTI interrupt using the SAVED handler */
@ -237,6 +243,7 @@ static void stmpe11_enable(FAR struct stmpe11_config_s *state, bool enable)
(void)stm32_gpiosetevent(GPIO_IO_EXPANDER, false, false, false, NULL);
}
irqrestore(flags);
}
static void stmpe11_clear(FAR struct stmpe11_config_s *state)

View File

@ -216,7 +216,7 @@ uint16_t stmpe11_getreg16(FAR struct stmpe11_dev_s *priv, uint8_t regaddr);
********************************************************************************************/
#ifndef CONFIG_STMPE11_TSC_DISABLE
void stmpe11_tscworker(FAR struct stmpe11_dev_s *priv) weak_function;
void stmpe11_tscworker(FAR struct stmpe11_dev_s *priv, uint8_t intsta) weak_function;
#endif
/********************************************************************************************

View File

@ -109,7 +109,7 @@ static void stmpe11_worker(FAR void *arg)
if (stmpe11_tscworker)
#endif
{
stmpe11_tscworker(priv);
stmpe11_tscworker(priv, regval);
}
stmpe11_putreg8(priv, STMPE11_INT_STA, (INT_TOUCH_DET|INT_FIFO_TH|INT_FIFO_OFLOW));
@ -349,7 +349,11 @@ STMPE11_HANDLE stmpe11_instantiate(FAR struct i2c_dev_s *dev,
#else
regval |= INT_CTRL_INT_POLARITY; /* Pin polarity: Active high / rising edge */
#endif
#ifdef CONFIG_STMPE11_EDGE
regval |= INT_CTRL_INT_TYPE; /* Edge interrupt */
#else
regval &= ~INT_CTRL_INT_TYPE; /* Level interrupt */
#endif
stmpe11_putreg8(priv, STMPE11_INT_CTRL, regval);
/* Attach the STMPE11 interrupt handler. */

View File

@ -239,14 +239,22 @@ static int stmpe11_sample(FAR struct stmpe11_dev_s *priv,
if (sample->contact == CONTACT_UP)
{
/* Next.. no contract. Increment the ID so that next contact ID will be unique */
/* The sampling logic has detected pen-up in some condition other
* than CONTACT_NONE. Set the next state to CONTACT_NONE: Further
* pen-down reports will be ignored. Increment the ID so that
* next contact ID will be unique
*/
priv->sample.contact = CONTACT_NONE;
priv->id++;
}
else if (sample->contact == CONTACT_DOWN)
{
/* First report -- next report will be a movement */
/* The sampling logic has detected pen-up in some condition other
* than CONTACT_MOVE. Set the next state to CONTACT_MOVE: Further
* samples collected while the pen is down will reported as movement
* events.
*/
priv->sample.contact = CONTACT_MOVE;
}
@ -553,20 +561,15 @@ static ssize_t stmpe11_read(FAR struct file *filep, FAR char *buffer, size_t len
{
/* First contact */
report->point[0].flags = TOUCH_DOWN | TOUCH_ID_VALID | TOUCH_POS_VALID;
report->point[0].flags = TOUCH_DOWN | TOUCH_ID_VALID |
TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
}
else /* if (sample->contact == CONTACT_MOVE) */
{
/* Movement of the same contact */
report->point[0].flags = TOUCH_MOVE | TOUCH_ID_VALID | TOUCH_POS_VALID;
}
/* A pressure measurement of zero means that pressure is not available */
if (report->point[0].pressure != 0)
{
report->point[0].flags |= TOUCH_PRESSURE_VALID;
report->point[0].flags = TOUCH_MOVE | TOUCH_ID_VALID |
TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
}
}
@ -904,7 +907,7 @@ int stmpe11_register(STMPE11_HANDLE handle, int minor)
*
****************************************************************************/
void stmpe11_tscworker(FAR struct stmpe11_dev_s *priv)
void stmpe11_tscworker(FAR struct stmpe11_dev_s *priv, uint8_t intsta)
{
FAR struct stmpe11_config_s *config; /* Convenience pointer */
bool pendown; /* true: pend is down */
@ -913,7 +916,6 @@ void stmpe11_tscworker(FAR struct stmpe11_dev_s *priv)
uint16_t x; /* X position */
uint16_t y; /* Y position */
ivdbg("Sampling\n");
ASSERT(priv != NULL);
/* Get a pointer the callbacks for convenience (and so the code is not so
@ -931,18 +933,36 @@ void stmpe11_tscworker(FAR struct stmpe11_dev_s *priv)
if (!pendown)
{
/* Ignore the interrupt if the pen was already down (CONTACT_NONE == pen up and
* already reported. CONTACT_UP == pen up, but not reported)
/* The pen is up.. reset thresholding variables. FIFOs will read zero if
* there is no data available (hence the choice of (0,0)
*/
if (priv->sample.contact == CONTACT_NONE)
priv->threshx = 0;
priv->threshy = 0;
/* 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 ||
priv->sample.contact == CONTACT_UP)
{
return;
goto ignored;
}
/* A pen-down to up transition has been detected. CONTACT_UP indicates the
* initial loss of contzt. The state will be changed to CONTACT_NONE
* after the loss of contact is sampled.
*/
priv->sample.contact = CONTACT_UP;
}
else
/* The pen is down... check for data in the FIFO */
else if ((intsta & (INT_FIFO_TH|INT_FIFO_OFLOW)) != 0)
{
/* Read the next x and y positions */
/* Read the next x and y positions. */
#ifdef CONFIG_STMPE11_SWAPXY
x = stmpe11_getreg16(priv, STMPE11_TSC_DATAX);
@ -957,34 +977,32 @@ void stmpe11_tscworker(FAR struct stmpe11_dev_s *priv)
xdiff = x > priv->threshx ? (x - priv->threshx) : (priv->threshx - x);
ydiff = y > priv->threshy ? (y - priv->threshy) : (priv->threshy - y);
/* When we see a big difference, snap to the new x/y position */
/* If the difference from the last sample is small, then ignore the event.
* REVISIT: Should a large change in pressure also generate a event?
*/
if (xdiff + ydiff > 5)
if (xdiff + ydiff < 6)
{
priv->threshx = x;
priv->threshy = y;
/* Little or no change in position... don't report */
goto ignored;
}
/* Update the x/y position */
/* 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;
/* Update the Z pression index */
/* Update the Z pressure index */
priv->sample.z = stmpe11_getreg8(priv, STMPE11_TSC_DATAZ);
}
/* Clear the interrupt pending bit and enable the FIFO again */
stmpe11_putreg8(priv, STMPE11_FIFO_STA, 0x01);
stmpe11_putreg8(priv, STMPE11_FIFO_STA, 0x00);
/* Note the availability of new measurements */
if (pendown)
{
/* If this is the first (acknowledged) pend down report, then report
/* If this is the first (acknowledged) pen down report, then report
* this as the first contact. If contact == CONTACT_DOWN, it will be
* set to set to CONTACT_MOVE after the contact is first sampled.
*/
@ -996,17 +1014,20 @@ void stmpe11_tscworker(FAR struct stmpe11_dev_s *priv)
priv->sample.contact = CONTACT_DOWN;
}
}
else /* if (priv->sample.contact != CONTACT_NONE) */
{
/* The pen is up. NOTE: We know from a previous test, that this is a
* loss of contact condition. This will be changed to CONTACT_NONE
* after the loss of contact is sampled.
*/
priv->sample.contact = CONTACT_UP;
/* Pen down, but no data in FIFO */
else
{
/* Ignore the interrupt... wait until there is data in the FIFO */
goto ignored;
}
/* Indicate the availability of new sample data for this ID */
/* We get here if (1) we just went from a pen down to a pen up state OR (2)
* We just get a measurement from the FIFO in a pen down state. Indicate
* the availability of new sample data for this ID.
*/
priv->sample.id = priv->id;
priv->penchange = true;
@ -1014,6 +1035,12 @@ void stmpe11_tscworker(FAR struct stmpe11_dev_s *priv)
/* Notify any waiters that new STMPE11 data is available */
stmpe11_notify(priv);
/* Clear the interrupt pending bit and enable the FIFO again */
ignored:
stmpe11_putreg8(priv, STMPE11_FIFO_STA, 0x01);
stmpe11_putreg8(priv, STMPE11_FIFO_STA, 0x00);
}
#endif /* CONFIG_INPUT && CONFIG_INPUT_STMPE11 && !CONFIG_STMPE11_TSC_DISABLE */