2012-05-05 14:27:03 -03:00
|
|
|
|
/****************************************************************************
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* drivers/input/stmpe811_base.c
|
2012-05-05 14:27:03 -03:00
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
|
*
|
|
|
|
|
* References:
|
|
|
|
|
* "STMPE811 S-Touch<63> advanced resistive touchscreen controller with 8-bit
|
|
|
|
|
* GPIO expander," Doc ID 14489 Rev 6, CD00186725, STMicroelectronics"
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
|
* distribution.
|
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
|
* without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Included Files
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
2012-05-08 19:10:29 -03:00
|
|
|
|
#include <unistd.h>
|
2012-05-05 14:27:03 -03:00
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
2012-05-08 12:07:53 -03:00
|
|
|
|
#include <nuttx/kmalloc.h>
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#include <nuttx/input/stmpe811.h>
|
2012-05-05 14:27:03 -03:00
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#include "stmpe811.h"
|
2012-05-05 14:27:03 -03:00
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_STMPE811)
|
2012-05-05 14:27:03 -03:00
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Private Types
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Private Data
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
/* If only a single STMPE811 device is supported, then the driver state
|
2012-05-05 14:27:03 -03:00
|
|
|
|
* structure may as well be pre-allocated.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#ifndef CONFIG_STMPE811_MULTIPLE
|
|
|
|
|
static struct stmpe811_dev_s g_stmpe811;
|
2012-05-05 14:27:03 -03:00
|
|
|
|
|
|
|
|
|
/* Otherwise, we will need to maintain allocated driver instances in a list */
|
|
|
|
|
|
|
|
|
|
#else
|
2012-05-28 22:43:51 -03:00
|
|
|
|
static struct stmpe811_dev_s *g_stmpe811list;
|
2012-05-05 14:27:03 -03:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Private Functions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2012-05-05 20:17:25 -03:00
|
|
|
|
/****************************************************************************
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* Name: stmpe811_worker
|
2012-05-05 20:17:25 -03:00
|
|
|
|
*
|
|
|
|
|
* Description:
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* This is the "bottom half" of the STMPE811 interrupt handler
|
2012-05-05 20:17:25 -03:00
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
static void stmpe811_worker(FAR void *arg)
|
2012-05-05 20:17:25 -03:00
|
|
|
|
{
|
2012-05-28 22:43:51 -03:00
|
|
|
|
FAR struct stmpe811_dev_s *priv = (FAR struct stmpe811_dev_s *)arg;
|
2012-05-05 20:17:25 -03:00
|
|
|
|
uint8_t regval;
|
|
|
|
|
|
2012-05-08 19:10:29 -03:00
|
|
|
|
DEBUGASSERT(priv && priv->config);
|
|
|
|
|
|
|
|
|
|
/* Get the global interrupt status */
|
2012-05-05 20:17:25 -03:00
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
regval = stmpe811_getreg8(priv, STMPE811_INT_STA);
|
2012-05-05 20:17:25 -03:00
|
|
|
|
|
|
|
|
|
/* Check for a touchscreen interrupt */
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#ifndef CONFIG_STMPE811_TSC_DISABLE
|
2012-05-05 20:17:25 -03:00
|
|
|
|
if ((regval & (INT_TOUCH_DET|INT_FIFO_TH|INT_FIFO_OFLOW)) != 0)
|
|
|
|
|
{
|
|
|
|
|
/* Dispatch the touchscreen interrupt if it was brought into the link */
|
|
|
|
|
|
2012-05-06 13:00:16 -03:00
|
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
2012-05-28 22:43:51 -03:00
|
|
|
|
if (stmpe811_tscworker)
|
2012-05-06 13:00:16 -03:00
|
|
|
|
#endif
|
2012-05-05 20:17:25 -03:00
|
|
|
|
{
|
2012-05-28 22:43:51 -03:00
|
|
|
|
stmpe811_tscworker(priv, regval);
|
2012-05-05 20:17:25 -03:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
stmpe811_putreg8(priv, STMPE811_INT_STA, (INT_TOUCH_DET|INT_FIFO_TH|INT_FIFO_OFLOW));
|
2012-05-05 20:17:25 -03:00
|
|
|
|
regval &= ~(INT_TOUCH_DET|INT_FIFO_TH|INT_FIFO_OFLOW);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#if !defined(CONFIG_STMPE811_GPIO_DISABLE) && !defined(CONFIG_STMPE811_GPIOINT_DISABLE)
|
2012-05-05 20:17:25 -03:00
|
|
|
|
if ((regval & INT_GPIO) != 0)
|
|
|
|
|
{
|
|
|
|
|
/* Dispatch the GPIO interrupt if it was brought into the link */
|
|
|
|
|
|
2012-05-06 13:00:16 -03:00
|
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
2012-05-28 22:43:51 -03:00
|
|
|
|
if (stmpe811_gpioworker)
|
2012-05-06 13:00:16 -03:00
|
|
|
|
#endif
|
2012-05-05 20:17:25 -03:00
|
|
|
|
{
|
2012-05-28 22:43:51 -03:00
|
|
|
|
stmpe811_gpioworker(priv);
|
2012-05-05 20:17:25 -03:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
stmpe811_putreg8(priv, STMPE811_INT_STA, INT_GPIO);
|
2012-05-05 20:17:25 -03:00
|
|
|
|
regval &= ~INT_GPIO;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-05-08 19:10:29 -03:00
|
|
|
|
/* Clear any other residual, unhandled pending interrupt */
|
2012-05-05 20:17:25 -03:00
|
|
|
|
|
2012-05-08 19:10:29 -03:00
|
|
|
|
if (regval != 0)
|
|
|
|
|
{
|
2012-05-28 22:43:51 -03:00
|
|
|
|
stmpe811_putreg8(priv, STMPE811_INT_STA, regval);
|
2012-05-08 19:10:29 -03:00
|
|
|
|
}
|
2012-05-05 20:17:25 -03:00
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
/* Re-enable the STMPE811 GPIO interrupt */
|
2012-05-05 20:17:25 -03:00
|
|
|
|
|
2012-05-08 19:10:29 -03:00
|
|
|
|
priv->config->enable(priv->config, true);
|
2012-05-05 20:17:25 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* Name: stmpe811_interrupt
|
2012-05-05 20:17:25 -03:00
|
|
|
|
*
|
|
|
|
|
* Description:
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* The STMPE811 interrupt handler
|
2012-05-05 20:17:25 -03:00
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
static int stmpe811_interrupt(int irq, FAR void *context)
|
2012-05-05 20:17:25 -03:00
|
|
|
|
{
|
2012-05-28 22:43:51 -03:00
|
|
|
|
FAR struct stmpe811_dev_s *priv;
|
|
|
|
|
FAR struct stmpe811_config_s *config;
|
2012-05-05 20:17:25 -03:00
|
|
|
|
int ret;
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
/* Which STMPE811 device caused the interrupt? */
|
2012-05-05 20:17:25 -03:00
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#ifndef CONFIG_STMPE811_MULTIPLE
|
|
|
|
|
priv = &g_stmpe811;
|
2012-05-05 20:17:25 -03:00
|
|
|
|
#else
|
2012-05-28 22:43:51 -03:00
|
|
|
|
for (priv = g_stmpe811list;
|
2012-05-08 12:07:53 -03:00
|
|
|
|
priv && priv->config->irq != irq;
|
2012-05-05 20:17:25 -03:00
|
|
|
|
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);
|
|
|
|
|
|
2012-05-21 14:36:26 -03:00
|
|
|
|
/* Check if interrupt work is already queue. If it is already busy, then
|
|
|
|
|
* we already have interrupt processing in the pipeline and we need to do
|
|
|
|
|
* nothing more.
|
2012-05-05 20:17:25 -03:00
|
|
|
|
*/
|
|
|
|
|
|
2012-05-21 14:36:26 -03:00
|
|
|
|
if (work_available(&priv->work))
|
2012-05-05 20:17:25 -03:00
|
|
|
|
{
|
2012-05-28 22:43:51 -03:00
|
|
|
|
/* Yes.. Transfer processing to the worker thread. Since STMPE811
|
2012-05-21 14:36:26 -03:00
|
|
|
|
* interrupts are disabled while the work is pending, no special
|
|
|
|
|
* action should be required to protect the work queue.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
ret = work_queue(&priv->work, stmpe811_worker, priv, 0);
|
2012-05-21 14:36:26 -03:00
|
|
|
|
if (ret != 0)
|
|
|
|
|
{
|
|
|
|
|
illdbg("Failed to queue work: %d\n", ret);
|
|
|
|
|
}
|
2012-05-05 20:17:25 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Clear any pending interrupts and return success */
|
|
|
|
|
|
|
|
|
|
config->clear(config);
|
|
|
|
|
return OK;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 14:27:03 -03:00
|
|
|
|
/****************************************************************************
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* Name: stmpe811_checkid
|
2012-05-05 14:27:03 -03:00
|
|
|
|
*
|
|
|
|
|
* Description:
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* Read and verify the STMPE811 chip ID
|
2012-05-05 14:27:03 -03:00
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
static int stmpe811_checkid(FAR struct stmpe811_dev_s *priv)
|
2012-05-05 14:27:03 -03:00
|
|
|
|
{
|
|
|
|
|
uint16_t devid = 0;
|
|
|
|
|
|
|
|
|
|
/* Read device ID */
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
devid = stmpe811_getreg8(priv, STMPE811_CHIP_ID);
|
2012-05-05 14:27:03 -03:00
|
|
|
|
devid = (uint32_t)(devid << 8);
|
2012-05-28 22:43:51 -03:00
|
|
|
|
devid |= (uint32_t)stmpe811_getreg8(priv, STMPE811_CHIP_ID+1);
|
2012-05-05 14:27:03 -03:00
|
|
|
|
ivdbg("devid: %04x\n", devid);
|
|
|
|
|
|
|
|
|
|
if (devid != (uint16_t)CHIP_ID)
|
|
|
|
|
{
|
|
|
|
|
/* ID is not Correct */
|
|
|
|
|
|
|
|
|
|
return -ENODEV;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* Name: stmpe811_reset
|
2012-05-05 14:27:03 -03:00
|
|
|
|
*
|
|
|
|
|
* Description:
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* Reset the STMPE811
|
2012-05-05 14:27:03 -03:00
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
static void stmpe811_reset(FAR struct stmpe811_dev_s *priv)
|
2012-05-05 14:27:03 -03:00
|
|
|
|
{
|
2012-05-28 22:43:51 -03:00
|
|
|
|
/* Power Down the STMPE811 */
|
2012-05-05 14:27:03 -03:00
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
stmpe811_putreg8(priv, STMPE811_SYS_CTRL1, SYS_CTRL1_SOFTRESET);
|
2012-05-05 14:27:03 -03:00
|
|
|
|
|
|
|
|
|
/* Wait a bit */
|
|
|
|
|
|
2012-05-08 19:10:29 -03:00
|
|
|
|
usleep(20*1000);
|
2012-05-05 14:27:03 -03:00
|
|
|
|
|
|
|
|
|
/* Then power on again. All registers will be in their reset state. */
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
stmpe811_putreg8(priv, STMPE811_SYS_CTRL1, 0);
|
2012-05-05 14:27:03 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Public Functions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* Name: stmpe811_instantiate
|
2012-05-05 14:27:03 -03:00
|
|
|
|
*
|
|
|
|
|
* Description:
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* Instantiate and configure the STMPE811 device driver to use the provided
|
2012-05-05 14:27:03 -03:00
|
|
|
|
* I2C or SPIdevice instance.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* dev - An I2C or SPI driver instance
|
|
|
|
|
* config - Persistant board configuration data
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* A non-zero handle is returned on success. This handle may then be used
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* to configure the STMPE811 driver as necessary. A NULL handle value is
|
2012-05-05 14:27:03 -03:00
|
|
|
|
* returned on failure.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#ifdef CONFIG_STMPE811_SPI
|
|
|
|
|
STMPE811_HANDLE stmpe811_instantiate(FAR struct spi_dev_s *dev,
|
|
|
|
|
FAR struct stmpe811_config_s *config)
|
2012-05-05 14:27:03 -03:00
|
|
|
|
#else
|
2012-05-28 22:43:51 -03:00
|
|
|
|
STMPE811_HANDLE stmpe811_instantiate(FAR struct i2c_dev_s *dev,
|
|
|
|
|
FAR struct stmpe811_config_s *config)
|
2012-05-05 14:27:03 -03:00
|
|
|
|
#endif
|
|
|
|
|
{
|
2012-05-28 22:43:51 -03:00
|
|
|
|
FAR struct stmpe811_dev_s *priv;
|
2012-05-05 22:37:47 -03:00
|
|
|
|
uint8_t regval;
|
2012-05-05 14:27:03 -03:00
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
/* Allocate the device state structure */
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#ifdef CONFIG_STMPE811_MULTIPLE
|
|
|
|
|
priv = (FAR struct stmpe811_dev_s *)kzalloc(sizeof(struct stmpe811_dev_s));
|
2012-05-05 14:27:03 -03:00
|
|
|
|
if (!priv)
|
|
|
|
|
{
|
2012-05-08 12:07:53 -03:00
|
|
|
|
return NULL;
|
2012-05-05 14:27:03 -03:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
/* And save the device structure in the list of STMPE811 so that we can find it later */
|
2012-05-05 14:27:03 -03:00
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
priv->flink = g_stmpe811list;
|
|
|
|
|
g_stmpe811list = priv;
|
2012-05-05 14:27:03 -03:00
|
|
|
|
#else
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
/* Use the one-and-only STMPE811 driver instance */
|
2012-05-05 14:27:03 -03:00
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
priv = &g_stmpe811;
|
2012-05-05 14:27:03 -03:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Initialize the device state structure */
|
|
|
|
|
|
2012-05-05 20:17:25 -03:00
|
|
|
|
sem_init(&priv->exclsem, 0, 1);
|
2012-05-08 19:10:29 -03:00
|
|
|
|
priv->config = config;
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#ifdef CONFIG_STMPE811_SPI
|
2012-05-05 14:27:03 -03:00
|
|
|
|
priv->spi = dev;
|
|
|
|
|
#else
|
|
|
|
|
priv->i2c = dev;
|
2012-05-08 19:10:29 -03:00
|
|
|
|
|
|
|
|
|
/* Set the I2C address and frequency. REVISIT: This logic would be
|
|
|
|
|
* insufficient if we share the I2C bus with any other devices that also
|
|
|
|
|
* modify the address and frequency.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
I2C_SETADDRESS(dev, config->address, 7);
|
|
|
|
|
I2C_SETFREQUENCY(dev, config->frequency);
|
2012-05-05 14:27:03 -03:00
|
|
|
|
#endif
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
/* Read and verify the STMPE811 chip ID */
|
2012-05-05 14:27:03 -03:00
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
ret = stmpe811_checkid(priv);
|
2012-05-05 14:27:03 -03:00
|
|
|
|
if (ret < 0)
|
|
|
|
|
{
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#ifdef CONFIG_STMPE811_MULTIPLE
|
2012-05-05 14:27:03 -03:00
|
|
|
|
kfree(priv);
|
|
|
|
|
#endif
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
/* Generate STMPE811 Software reset */
|
2012-05-05 14:27:03 -03:00
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
stmpe811_reset(priv);
|
2012-05-05 20:17:25 -03:00
|
|
|
|
|
2012-05-08 19:10:29 -03:00
|
|
|
|
/* Configure the interrupt output pin to generate interrupts on high or low level. */
|
2012-05-05 22:37:47 -03:00
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
regval = stmpe811_getreg8(priv, STMPE811_INT_CTRL);
|
|
|
|
|
#ifdef CONFIG_STMPE811_ACTIVELOW
|
2012-05-08 19:10:29 -03:00
|
|
|
|
regval &= ~INT_CTRL_INT_POLARITY; /* Pin polarity: Active low / falling edge */
|
|
|
|
|
#else
|
|
|
|
|
regval |= INT_CTRL_INT_POLARITY; /* Pin polarity: Active high / rising edge */
|
|
|
|
|
#endif
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#ifdef CONFIG_STMPE811_EDGE
|
2012-05-11 15:27:46 -03:00
|
|
|
|
regval |= INT_CTRL_INT_TYPE; /* Edge interrupt */
|
|
|
|
|
#else
|
2012-05-05 22:37:47 -03:00
|
|
|
|
regval &= ~INT_CTRL_INT_TYPE; /* Level interrupt */
|
2012-05-11 15:27:46 -03:00
|
|
|
|
#endif
|
2012-05-28 22:43:51 -03:00
|
|
|
|
stmpe811_putreg8(priv, STMPE811_INT_CTRL, regval);
|
2012-05-05 22:37:47 -03:00
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
/* Attach the STMPE811 interrupt handler. */
|
2012-05-05 20:17:25 -03:00
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
config->attach(config, stmpe811_interrupt);
|
2012-05-05 20:17:25 -03:00
|
|
|
|
|
|
|
|
|
/* Clear any pending interrupts */
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
stmpe811_putreg8(priv, STMPE811_INT_STA, INT_ALL);
|
2012-05-05 20:17:25 -03:00
|
|
|
|
config->clear(config);
|
|
|
|
|
config->enable(config, true);
|
|
|
|
|
|
2012-05-05 22:37:47 -03:00
|
|
|
|
/* Enable global interrupts */
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
regval = stmpe811_getreg8(priv, STMPE811_INT_CTRL);
|
2012-05-05 22:37:47 -03:00
|
|
|
|
regval |= INT_CTRL_GLOBAL_INT;
|
2012-05-28 22:43:51 -03:00
|
|
|
|
stmpe811_putreg8(priv, STMPE811_INT_CTRL, regval);
|
2012-05-05 22:37:47 -03:00
|
|
|
|
|
2012-05-05 20:17:25 -03:00
|
|
|
|
/* Return our private data structure as an opaque handle */
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
return (STMPE811_HANDLE)priv;
|
2012-05-05 14:27:03 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* Name: stmpe811_getreg8
|
2012-05-05 14:27:03 -03:00
|
|
|
|
*
|
|
|
|
|
* Description:
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* Read from an 8-bit STMPE811 register
|
2012-05-05 14:27:03 -03:00
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#ifdef CONFIG_STMPE811_I2C
|
|
|
|
|
uint8_t stmpe811_getreg8(FAR struct stmpe811_dev_s *priv, uint8_t regaddr)
|
2012-05-05 14:27:03 -03:00
|
|
|
|
{
|
|
|
|
|
/* 8-bit data read sequence:
|
|
|
|
|
*
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* Start - I2C_Write_Address - STMPE811_Reg_Address -
|
|
|
|
|
* Repeated_Start - I2C_Read_Address - STMPE811_Read_Data - STOP
|
2012-05-05 14:27:03 -03:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
struct i2c_msg_s msg[2];
|
|
|
|
|
uint8_t regval;
|
|
|
|
|
int ret;
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
/* Setup 8-bit STMPE811 address write message */
|
2012-05-05 14:27:03 -03:00
|
|
|
|
|
|
|
|
|
msg[0].addr = priv->config->address; /* 7-bit address */
|
|
|
|
|
msg[0].flags = 0; /* Write transaction, beginning with START */
|
|
|
|
|
msg[0].buffer = ®addr; /* Transfer from this address */
|
|
|
|
|
msg[0].length = 1; /* Send one byte following the address
|
|
|
|
|
* (no STOP) */
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
/* Set up the 8-bit STMPE811 data read message */
|
2012-05-05 14:27:03 -03:00
|
|
|
|
|
|
|
|
|
msg[1].addr = priv->config->address; /* 7-bit address */
|
|
|
|
|
msg[1].flags = I2C_M_READ; /* Read transaction, beginning with Re-START */
|
|
|
|
|
msg[1].buffer = ®val; /* Transfer to this address */
|
|
|
|
|
msg[1].length = 1; /* Receive one byte following the address
|
|
|
|
|
* (then STOP) */
|
|
|
|
|
|
|
|
|
|
/* Perform the transfer */
|
|
|
|
|
|
|
|
|
|
ret = I2C_TRANSFER(priv->i2c, msg, 2);
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
{
|
|
|
|
|
idbg("I2C_TRANSFER failed: %d\n", ret);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#ifdef CONFIG_STMPE811_REGDEBUG
|
2012-05-08 19:10:29 -03:00
|
|
|
|
dbg("%02x->%02x\n", regaddr, regval);
|
|
|
|
|
#endif
|
2012-05-05 14:27:03 -03:00
|
|
|
|
return regval;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* Name: stmpe811_putreg8
|
2012-05-05 14:27:03 -03:00
|
|
|
|
*
|
|
|
|
|
* Description:
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* Write a value to an 8-bit STMPE811 register
|
2012-05-05 14:27:03 -03:00
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#ifdef CONFIG_STMPE811_I2C
|
|
|
|
|
void stmpe811_putreg8(FAR struct stmpe811_dev_s *priv,
|
|
|
|
|
uint8_t regaddr, uint8_t regval)
|
2012-05-05 14:27:03 -03:00
|
|
|
|
{
|
|
|
|
|
/* 8-bit data read sequence:
|
|
|
|
|
*
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* Start - I2C_Write_Address - STMPE811_Reg_Address - STMPE811_Write_Data - STOP
|
2012-05-05 14:27:03 -03:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
struct i2c_msg_s msg;
|
|
|
|
|
uint8_t txbuffer[2];
|
|
|
|
|
int ret;
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#ifdef CONFIG_STMPE811_REGDEBUG
|
2012-05-08 19:10:29 -03:00
|
|
|
|
dbg("%02x<-%02x\n", regaddr, regval);
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
/* Setup to the data to be transferred. Two bytes: The STMPE811 register
|
2012-05-05 14:27:03 -03:00
|
|
|
|
* address followed by one byte of data.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
txbuffer[0] = regaddr;
|
|
|
|
|
txbuffer[1] = regval;
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
/* Setup 8-bit STMPE811 address write message */
|
2012-05-05 14:27:03 -03:00
|
|
|
|
|
|
|
|
|
msg.addr = priv->config->address; /* 7-bit address */
|
|
|
|
|
msg.flags = 0; /* Write transaction, beginning with START */
|
|
|
|
|
msg.buffer = txbuffer; /* Transfer from this address */
|
|
|
|
|
msg.length = 2; /* Send two byte following the address
|
|
|
|
|
* (then STOP) */
|
|
|
|
|
|
|
|
|
|
/* Perform the transfer */
|
|
|
|
|
|
|
|
|
|
ret = I2C_TRANSFER(priv->i2c, &msg, 1);
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
{
|
|
|
|
|
idbg("I2C_TRANSFER failed: %d\n", ret);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* Name: stmpe811_getreg16
|
2012-05-05 14:27:03 -03:00
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Read 16-bits of data from an STMPE-11 register
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#ifdef CONFIG_STMPE811_I2C
|
|
|
|
|
uint16_t stmpe811_getreg16(FAR struct stmpe811_dev_s *priv, uint8_t regaddr)
|
2012-05-05 14:27:03 -03:00
|
|
|
|
{
|
|
|
|
|
/* 16-bit data read sequence:
|
|
|
|
|
*
|
2012-05-28 22:43:51 -03:00
|
|
|
|
* Start - I2C_Write_Address - STMPE811_Reg_Address -
|
|
|
|
|
* Repeated_Start - I2C_Read_Address - STMPE811_Read_Data_1 -
|
|
|
|
|
* STMPE811_Read_Data_2 - STOP
|
2012-05-05 14:27:03 -03:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct i2c_msg_s msg[2];
|
|
|
|
|
uint8_t rxbuffer[2];
|
|
|
|
|
int ret;
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
/* Setup 8-bit STMPE811 address write message */
|
2012-05-05 14:27:03 -03:00
|
|
|
|
|
|
|
|
|
msg[0].addr = priv->config->address; /* 7-bit address */
|
|
|
|
|
msg[0].flags = 0; /* Write transaction, beginning with START */
|
|
|
|
|
msg[0].buffer = ®addr; /* Transfer from this address */
|
|
|
|
|
msg[0].length = 1; /* Send one byte following the address
|
|
|
|
|
* (no STOP) */
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
/* Set up the 8-bit STMPE811 data read message */
|
2012-05-05 14:27:03 -03:00
|
|
|
|
|
|
|
|
|
msg[1].addr = priv->config->address; /* 7-bit address */
|
|
|
|
|
msg[1].flags = I2C_M_READ; /* Read transaction, beginning with Re-START */
|
|
|
|
|
msg[1].buffer = rxbuffer; /* Transfer to this address */
|
|
|
|
|
msg[1].length = 2; /* Receive two bytes following the address
|
|
|
|
|
* (then STOP) */
|
|
|
|
|
|
|
|
|
|
/* Perform the transfer */
|
|
|
|
|
|
|
|
|
|
ret = I2C_TRANSFER(priv->i2c, msg, 2);
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
{
|
|
|
|
|
idbg("I2C_TRANSFER failed: %d\n", ret);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#ifdef CONFIG_STMPE811_REGDEBUG
|
2012-05-08 19:10:29 -03:00
|
|
|
|
dbg("%02x->%02x%02x\n", regaddr, rxbuffer[0], rxbuffer[1]);
|
|
|
|
|
#endif
|
|
|
|
|
return (uint16_t)rxbuffer[0] << 8 | (uint16_t)rxbuffer[1];
|
2012-05-05 14:27:03 -03:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-05-28 22:43:51 -03:00
|
|
|
|
#endif /* CONFIG_INPUT && CONFIG_INPUT_STMPE811 */
|
2012-05-05 14:27:03 -03:00
|
|
|
|
|