2012-05-05 19:27:03 +02:00
|
|
|
/****************************************************************************
|
2012-05-29 03:43:51 +02:00
|
|
|
* drivers/input/stmpe811_base.c
|
2012-05-05 19:27:03 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2012-05-05 19:27:03 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-05-05 19:27:03 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2012-05-05 19:27:03 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-03-04 07:10:42 +01:00
|
|
|
/* References:
|
|
|
|
* "STMPE811 S-Touch advanced resistive touchscreen controller with 8-bit
|
|
|
|
* GPIO expander," Doc ID 14489 Rev 6, CD00186725, STMicroelectronics"
|
|
|
|
*/
|
|
|
|
|
2012-05-05 19:27:03 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2012-05-09 00:10:29 +02:00
|
|
|
#include <unistd.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2012-05-05 19:27:03 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2012-05-08 17:07:53 +02:00
|
|
|
#include <nuttx/kmalloc.h>
|
2017-10-06 18:15:01 +02:00
|
|
|
#include <nuttx/signal.h>
|
2012-05-29 03:43:51 +02:00
|
|
|
#include <nuttx/input/stmpe811.h>
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#include "stmpe811.h"
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_STMPE811)
|
2012-05-05 19:27:03 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
/* If only a single STMPE811 device is supported, then the driver state
|
2012-05-05 19:27:03 +02:00
|
|
|
* structure may as well be pre-allocated.
|
|
|
|
*/
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#ifndef CONFIG_STMPE811_MULTIPLE
|
|
|
|
static struct stmpe811_dev_s g_stmpe811;
|
2012-05-05 19:27:03 +02:00
|
|
|
|
|
|
|
/* Otherwise, we will need to maintain allocated driver instances in a list */
|
|
|
|
|
|
|
|
#else
|
2012-05-29 03:43:51 +02:00
|
|
|
static struct stmpe811_dev_s *g_stmpe811list;
|
2012-05-05 19:27:03 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-05-06 01:17:25 +02:00
|
|
|
/****************************************************************************
|
2012-05-29 03:43:51 +02:00
|
|
|
* Name: stmpe811_worker
|
2012-05-06 01:17:25 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2012-05-29 03:43:51 +02:00
|
|
|
* This is the "bottom half" of the STMPE811 interrupt handler
|
2012-05-06 01:17:25 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
static void stmpe811_worker(FAR void *arg)
|
2012-05-06 01:17:25 +02:00
|
|
|
{
|
2012-05-29 03:43:51 +02:00
|
|
|
FAR struct stmpe811_dev_s *priv = (FAR struct stmpe811_dev_s *)arg;
|
2012-05-06 01:17:25 +02:00
|
|
|
uint8_t regval;
|
|
|
|
|
2012-05-09 00:10:29 +02:00
|
|
|
DEBUGASSERT(priv && priv->config);
|
|
|
|
|
|
|
|
/* Get the global interrupt status */
|
2012-05-06 01:17:25 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
regval = stmpe811_getreg8(priv, STMPE811_INT_STA);
|
2012-05-06 01:17:25 +02:00
|
|
|
|
|
|
|
/* Check for a touchscreen interrupt */
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#ifndef CONFIG_STMPE811_TSC_DISABLE
|
2015-10-10 18:41:00 +02:00
|
|
|
if ((regval & (INT_TOUCH_DET | INT_FIFO_TH | INT_FIFO_OFLOW)) != 0)
|
2012-05-06 01:17:25 +02:00
|
|
|
{
|
|
|
|
/* Dispatch the touchscreen interrupt if it was brought into the link */
|
|
|
|
|
2012-05-06 18:00:16 +02:00
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
2012-05-29 03:43:51 +02:00
|
|
|
if (stmpe811_tscworker)
|
2012-05-06 18:00:16 +02:00
|
|
|
#endif
|
2012-05-06 01:17:25 +02:00
|
|
|
{
|
2012-05-29 03:43:51 +02:00
|
|
|
stmpe811_tscworker(priv, regval);
|
2012-05-06 01:17:25 +02:00
|
|
|
}
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
stmpe811_putreg8(priv, STMPE811_INT_STA,
|
|
|
|
(INT_TOUCH_DET | INT_FIFO_TH | INT_FIFO_OFLOW));
|
|
|
|
regval &= ~(INT_TOUCH_DET | INT_FIFO_TH | INT_FIFO_OFLOW);
|
2012-05-06 01:17:25 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#if !defined(CONFIG_STMPE811_GPIO_DISABLE) && !defined(CONFIG_STMPE811_GPIOINT_DISABLE)
|
2012-05-06 01:17:25 +02:00
|
|
|
if ((regval & INT_GPIO) != 0)
|
|
|
|
{
|
|
|
|
/* Dispatch the GPIO interrupt if it was brought into the link */
|
|
|
|
|
2012-05-06 18:00:16 +02:00
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
2012-05-29 03:43:51 +02:00
|
|
|
if (stmpe811_gpioworker)
|
2012-05-06 18:00:16 +02:00
|
|
|
#endif
|
2012-05-06 01:17:25 +02:00
|
|
|
{
|
2012-05-29 03:43:51 +02:00
|
|
|
stmpe811_gpioworker(priv);
|
2012-05-06 01:17:25 +02:00
|
|
|
}
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
stmpe811_putreg8(priv, STMPE811_INT_STA, INT_GPIO);
|
2012-05-06 01:17:25 +02:00
|
|
|
regval &= ~INT_GPIO;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-05-09 00:10:29 +02:00
|
|
|
/* Clear any other residual, unhandled pending interrupt */
|
2012-05-06 01:17:25 +02:00
|
|
|
|
2012-05-09 00:10:29 +02:00
|
|
|
if (regval != 0)
|
|
|
|
{
|
2012-05-29 03:43:51 +02:00
|
|
|
stmpe811_putreg8(priv, STMPE811_INT_STA, regval);
|
2012-05-09 00:10:29 +02:00
|
|
|
}
|
2012-05-06 01:17:25 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
/* Re-enable the STMPE811 GPIO interrupt */
|
2012-05-06 01:17:25 +02:00
|
|
|
|
2012-05-09 00:10:29 +02:00
|
|
|
priv->config->enable(priv->config, true);
|
2012-05-06 01:17:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-05-29 03:43:51 +02:00
|
|
|
* Name: stmpe811_interrupt
|
2012-05-06 01:17:25 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2012-05-29 03:43:51 +02:00
|
|
|
* The STMPE811 interrupt handler
|
2012-05-06 01:17:25 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-02-27 18:41:48 +01:00
|
|
|
static int stmpe811_interrupt(int irq, FAR void *context, FAR void *arg)
|
2012-05-06 01:17:25 +02:00
|
|
|
{
|
2017-02-27 18:41:48 +01:00
|
|
|
FAR struct stmpe811_dev_s *priv = (FAR struct stmpe811_dev_s *)arg;
|
2012-05-29 03:43:51 +02:00
|
|
|
FAR struct stmpe811_config_s *config;
|
2017-02-27 18:41:48 +01:00
|
|
|
int ret;
|
2012-05-06 01:17:25 +02:00
|
|
|
|
2017-02-27 18:41:48 +01:00
|
|
|
DEBUGASSERT(priv != NULL && priv->config != NULL);
|
2012-05-06 01:17:25 +02:00
|
|
|
config = priv->config;
|
|
|
|
|
|
|
|
/* Disable further interrupts */
|
|
|
|
|
|
|
|
config->enable(config, false);
|
|
|
|
|
2012-05-21 19:36:26 +02: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-06 01:17:25 +02:00
|
|
|
*/
|
|
|
|
|
2012-05-21 19:36:26 +02:00
|
|
|
if (work_available(&priv->work))
|
2012-05-06 01:17:25 +02:00
|
|
|
{
|
2012-05-29 03:43:51 +02:00
|
|
|
/* Yes.. Transfer processing to the worker thread. Since STMPE811
|
2012-05-21 19:36:26 +02:00
|
|
|
* interrupts are disabled while the work is pending, no special
|
|
|
|
* action should be required to protect the work queue.
|
|
|
|
*/
|
|
|
|
|
2012-09-04 02:54:09 +02:00
|
|
|
ret = work_queue(HPWORK, &priv->work, stmpe811_worker, priv, 0);
|
2012-05-21 19:36:26 +02:00
|
|
|
if (ret != 0)
|
|
|
|
{
|
2016-06-20 20:44:38 +02:00
|
|
|
ierr("ERROR: Failed to queue work: %d\n", ret);
|
2012-05-21 19:36:26 +02:00
|
|
|
}
|
2012-05-06 01:17:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear any pending interrupts and return success */
|
|
|
|
|
|
|
|
config->clear(config);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2012-05-05 19:27:03 +02:00
|
|
|
/****************************************************************************
|
2012-05-29 03:43:51 +02:00
|
|
|
* Name: stmpe811_checkid
|
2012-05-05 19:27:03 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2012-05-29 03:43:51 +02:00
|
|
|
* Read and verify the STMPE811 chip ID
|
2012-05-05 19:27:03 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
static int stmpe811_checkid(FAR struct stmpe811_dev_s *priv)
|
2012-05-05 19:27:03 +02:00
|
|
|
{
|
|
|
|
uint16_t devid = 0;
|
|
|
|
|
|
|
|
/* Read device ID */
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
devid = stmpe811_getreg8(priv, STMPE811_CHIP_ID);
|
2012-05-05 19:27:03 +02:00
|
|
|
devid = (uint32_t)(devid << 8);
|
2020-09-17 08:49:04 +02:00
|
|
|
devid |= (uint32_t)stmpe811_getreg8(priv, STMPE811_CHIP_ID + 1);
|
2016-06-11 19:59:51 +02:00
|
|
|
iinfo("devid: %04x\n", devid);
|
2012-05-05 19:27:03 +02:00
|
|
|
|
|
|
|
if (devid != (uint16_t)CHIP_ID)
|
|
|
|
{
|
|
|
|
/* ID is not Correct */
|
|
|
|
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-05-29 03:43:51 +02:00
|
|
|
* Name: stmpe811_reset
|
2012-05-05 19:27:03 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2012-05-29 03:43:51 +02:00
|
|
|
* Reset the STMPE811
|
2012-05-05 19:27:03 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
static void stmpe811_reset(FAR struct stmpe811_dev_s *priv)
|
2012-05-05 19:27:03 +02:00
|
|
|
{
|
2012-05-29 03:43:51 +02:00
|
|
|
/* Power Down the STMPE811 */
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
stmpe811_putreg8(priv, STMPE811_SYS_CTRL1, SYS_CTRL1_SOFTRESET);
|
2012-05-05 19:27:03 +02:00
|
|
|
|
|
|
|
/* Wait a bit */
|
|
|
|
|
2020-09-17 08:49:04 +02:00
|
|
|
nxsig_usleep(20 * 1000);
|
2012-05-05 19:27:03 +02:00
|
|
|
|
|
|
|
/* Then power on again. All registers will be in their reset state. */
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
stmpe811_putreg8(priv, STMPE811_SYS_CTRL1, 0);
|
2012-05-05 19:27:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-05-29 03:43:51 +02:00
|
|
|
* Name: stmpe811_instantiate
|
2012-05-05 19:27:03 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2012-05-29 03:43:51 +02:00
|
|
|
* Instantiate and configure the STMPE811 device driver to use the provided
|
2012-05-05 19:27:03 +02:00
|
|
|
* I2C or SPIdevice instance.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* dev - An I2C or SPI driver instance
|
2020-02-22 19:31:14 +01:00
|
|
|
* config - Persistent board configuration data
|
2012-05-05 19:27:03 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* A non-zero handle is returned on success. This handle may then be used
|
2012-05-29 03:43:51 +02:00
|
|
|
* to configure the STMPE811 driver as necessary. A NULL handle value is
|
2012-05-05 19:27:03 +02:00
|
|
|
* returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#ifdef CONFIG_STMPE811_SPI
|
|
|
|
STMPE811_HANDLE stmpe811_instantiate(FAR struct spi_dev_s *dev,
|
|
|
|
FAR struct stmpe811_config_s *config)
|
2012-05-05 19:27:03 +02:00
|
|
|
#else
|
2016-01-30 15:36:47 +01:00
|
|
|
STMPE811_HANDLE stmpe811_instantiate(FAR struct i2c_master_s *dev,
|
2012-05-29 03:43:51 +02:00
|
|
|
FAR struct stmpe811_config_s *config)
|
2012-05-05 19:27:03 +02:00
|
|
|
#endif
|
|
|
|
{
|
2012-05-29 03:43:51 +02:00
|
|
|
FAR struct stmpe811_dev_s *priv;
|
2012-05-06 03:37:47 +02:00
|
|
|
uint8_t regval;
|
2012-05-05 19:27:03 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Allocate the device state structure */
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#ifdef CONFIG_STMPE811_MULTIPLE
|
2023-08-28 09:39:47 +02:00
|
|
|
priv = kmm_zalloc(sizeof(struct stmpe811_dev_s));
|
2012-05-05 19:27:03 +02:00
|
|
|
if (!priv)
|
|
|
|
{
|
2012-05-08 17:07:53 +02:00
|
|
|
return NULL;
|
2012-05-05 19:27:03 +02:00
|
|
|
}
|
|
|
|
|
2020-09-17 08:49:04 +02:00
|
|
|
/* And save the device structure in the list of STMPE811 so that we can
|
|
|
|
* find it later.
|
|
|
|
*/
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
priv->flink = g_stmpe811list;
|
|
|
|
g_stmpe811list = priv;
|
2012-05-05 19:27:03 +02:00
|
|
|
#else
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
/* Use the one-and-only STMPE811 driver instance */
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
priv = &g_stmpe811;
|
2012-05-05 19:27:03 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Initialize the device state structure */
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_init(&priv->lock);
|
2012-05-09 00:10:29 +02:00
|
|
|
priv->config = config;
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#ifdef CONFIG_STMPE811_SPI
|
2012-05-05 19:27:03 +02:00
|
|
|
priv->spi = dev;
|
|
|
|
#else
|
|
|
|
priv->i2c = dev;
|
|
|
|
#endif
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
/* Read and verify the STMPE811 chip ID */
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
ret = stmpe811_checkid(priv);
|
2012-05-05 19:27:03 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2022-10-16 18:50:59 +02:00
|
|
|
nxmutex_destroy(&priv->lock);
|
2012-05-29 03:43:51 +02:00
|
|
|
#ifdef CONFIG_STMPE811_MULTIPLE
|
2015-07-02 16:19:29 +02:00
|
|
|
g_stmpe811list = priv->flink;
|
2014-09-01 01:04:02 +02:00
|
|
|
kmm_free(priv);
|
2012-05-05 19:27:03 +02:00
|
|
|
#endif
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
/* Generate STMPE811 Software reset */
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
stmpe811_reset(priv);
|
2012-05-06 01:17:25 +02:00
|
|
|
|
2020-09-17 08:49:04 +02:00
|
|
|
/* Configure the interrupt output pin to generate interrupts on high or
|
|
|
|
* low level.
|
|
|
|
*/
|
2012-05-06 03:37:47 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
regval = stmpe811_getreg8(priv, STMPE811_INT_CTRL);
|
|
|
|
#ifdef CONFIG_STMPE811_ACTIVELOW
|
2012-05-09 00:10:29 +02: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-29 03:43:51 +02:00
|
|
|
#ifdef CONFIG_STMPE811_EDGE
|
2012-05-11 20:27:46 +02:00
|
|
|
regval |= INT_CTRL_INT_TYPE; /* Edge interrupt */
|
|
|
|
#else
|
2012-05-06 03:37:47 +02:00
|
|
|
regval &= ~INT_CTRL_INT_TYPE; /* Level interrupt */
|
2012-05-11 20:27:46 +02:00
|
|
|
#endif
|
2012-05-29 03:43:51 +02:00
|
|
|
stmpe811_putreg8(priv, STMPE811_INT_CTRL, regval);
|
2012-05-06 03:37:47 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
/* Attach the STMPE811 interrupt handler. */
|
2012-05-06 01:17:25 +02:00
|
|
|
|
2017-02-27 18:41:48 +01:00
|
|
|
config->attach(config, stmpe811_interrupt, priv);
|
2012-05-06 01:17:25 +02:00
|
|
|
|
|
|
|
/* Clear any pending interrupts */
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
stmpe811_putreg8(priv, STMPE811_INT_STA, INT_ALL);
|
2012-05-06 01:17:25 +02:00
|
|
|
config->clear(config);
|
|
|
|
config->enable(config, true);
|
|
|
|
|
2012-05-06 03:37:47 +02:00
|
|
|
/* Enable global interrupts */
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
regval = stmpe811_getreg8(priv, STMPE811_INT_CTRL);
|
2012-05-06 03:37:47 +02:00
|
|
|
regval |= INT_CTRL_GLOBAL_INT;
|
2012-05-29 03:43:51 +02:00
|
|
|
stmpe811_putreg8(priv, STMPE811_INT_CTRL, regval);
|
2012-05-06 03:37:47 +02:00
|
|
|
|
2012-05-06 01:17:25 +02:00
|
|
|
/* Return our private data structure as an opaque handle */
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
return (STMPE811_HANDLE)priv;
|
2012-05-05 19:27:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-05-29 03:43:51 +02:00
|
|
|
* Name: stmpe811_getreg8
|
2012-05-05 19:27:03 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2012-05-29 03:43:51 +02:00
|
|
|
* Read from an 8-bit STMPE811 register
|
2012-05-05 19:27:03 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
uint8_t stmpe811_getreg8(FAR struct stmpe811_dev_s *priv, uint8_t regaddr)
|
2012-05-05 19:27:03 +02:00
|
|
|
{
|
|
|
|
/* 8-bit data read sequence:
|
2020-09-17 08:49:04 +02:00
|
|
|
* i2c:
|
2014-04-13 22:32:20 +02:00
|
|
|
* Start - I2C_Write_Address - STMPE811_Reg_Address -
|
2012-05-29 03:43:51 +02:00
|
|
|
* Repeated_Start - I2C_Read_Address - STMPE811_Read_Data - STOP
|
2020-09-17 08:49:04 +02:00
|
|
|
* spi:
|
|
|
|
* [STMPE811_Reg_Address | 0x80] - Dummy Address - Read Register
|
2012-05-05 19:27:03 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
uint8_t regval;
|
2020-09-17 08:49:04 +02:00
|
|
|
#ifdef CONFIG_STMPE811_I2C
|
2012-05-05 19:27:03 +02:00
|
|
|
int ret;
|
2020-09-17 08:49:04 +02:00
|
|
|
struct i2c_msg_s msg[2];
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
/* Setup 8-bit STMPE811 address write message */
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2016-02-01 21:17:20 +01:00
|
|
|
msg[0].frequency = priv->config->frequency; /* I2C frequency */
|
|
|
|
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-05 19:27:03 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
/* Set up the 8-bit STMPE811 data read message */
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2016-02-01 21:17:20 +01:00
|
|
|
msg[1].frequency = priv->config->frequency; /* I2C frequency */
|
|
|
|
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) */
|
2012-05-05 19:27:03 +02:00
|
|
|
|
|
|
|
/* Perform the transfer */
|
|
|
|
|
|
|
|
ret = I2C_TRANSFER(priv->i2c, msg, 2);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-12 17:26:00 +02:00
|
|
|
ierr("ERROR: I2C_TRANSFER failed: %d\n", ret);
|
2012-05-05 19:27:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-09-17 08:49:04 +02:00
|
|
|
#else /* CONFIG_STMPE811_SPI */
|
|
|
|
SPI_LOCK(priv->spi, true);
|
|
|
|
|
|
|
|
SPI_SETMODE(priv->spi, SPIDEV_MODE0);
|
|
|
|
SPI_SETBITS(priv->spi, 8);
|
|
|
|
SPI_HWFEATURES(priv->spi, 0);
|
|
|
|
SPI_SETFREQUENCY(priv->spi, priv->config->frequency);
|
|
|
|
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN(0), true);
|
|
|
|
SPI_SEND(priv->spi, regaddr | 0x80); /* Issue a read on the address */
|
|
|
|
SPI_SEND(priv->spi, 0); /* Next address (not used) */
|
|
|
|
regval = SPI_SEND(priv->spi, 0); /* Read register */
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN(0), false);
|
|
|
|
SPI_LOCK(priv->spi, false);
|
|
|
|
#endif
|
2012-05-29 03:43:51 +02:00
|
|
|
#ifdef CONFIG_STMPE811_REGDEBUG
|
2016-06-16 20:33:32 +02:00
|
|
|
_err("%02x->%02x\n", regaddr, regval);
|
2012-05-09 00:10:29 +02:00
|
|
|
#endif
|
2012-05-05 19:27:03 +02:00
|
|
|
return regval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-05-29 03:43:51 +02:00
|
|
|
* Name: stmpe811_putreg8
|
2012-05-05 19:27:03 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2012-05-29 03:43:51 +02:00
|
|
|
* Write a value to an 8-bit STMPE811 register
|
2012-05-05 19:27:03 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
void stmpe811_putreg8(FAR struct stmpe811_dev_s *priv,
|
|
|
|
uint8_t regaddr, uint8_t regval)
|
2012-05-05 19:27:03 +02:00
|
|
|
{
|
|
|
|
/* 8-bit data read sequence:
|
|
|
|
*
|
2020-09-17 08:49:04 +02:00
|
|
|
* Start - I2C_Write_Address - STMPE811_Reg_Address -
|
|
|
|
* STMPE811_Write_Data - STOP
|
|
|
|
* spi:
|
|
|
|
* STMPE811_Reg_Address - Dummy Address - Write Data
|
2012-05-05 19:27:03 +02:00
|
|
|
*/
|
|
|
|
|
2020-09-17 08:49:04 +02:00
|
|
|
#ifdef CONFIG_STMPE811_I2C
|
|
|
|
int ret;
|
2012-05-05 19:27:03 +02:00
|
|
|
struct i2c_msg_s msg;
|
|
|
|
uint8_t txbuffer[2];
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#ifdef CONFIG_STMPE811_REGDEBUG
|
2016-06-16 20:33:32 +02:00
|
|
|
_err("%02x<-%02x\n", regaddr, regval);
|
2012-05-09 00:10:29 +02:00
|
|
|
#endif
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
/* Setup to the data to be transferred. Two bytes: The STMPE811 register
|
2012-05-05 19:27:03 +02:00
|
|
|
* address followed by one byte of data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
txbuffer[0] = regaddr;
|
|
|
|
txbuffer[1] = regval;
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
/* Setup 8-bit STMPE811 address write message */
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2016-02-01 21:17:20 +01:00
|
|
|
msg.frequency = priv->config->frequency; /* I2C frequency */
|
|
|
|
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
|
2020-09-17 08:49:04 +02:00
|
|
|
* (then STOP) */
|
2012-05-05 19:27:03 +02:00
|
|
|
|
|
|
|
/* Perform the transfer */
|
|
|
|
|
|
|
|
ret = I2C_TRANSFER(priv->i2c, &msg, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-12 17:26:00 +02:00
|
|
|
ierr("ERROR: I2C_TRANSFER failed: %d\n", ret);
|
2012-05-05 19:27:03 +02:00
|
|
|
}
|
2020-09-17 08:49:04 +02:00
|
|
|
#else /* CONFIG_STMPE811_SPI */
|
|
|
|
SPI_LOCK(priv->spi, true);
|
|
|
|
|
|
|
|
SPI_SETMODE(priv->spi, SPIDEV_MODE0);
|
|
|
|
SPI_SETBITS(priv->spi, 8);
|
|
|
|
SPI_HWFEATURES(priv->spi, 0);
|
|
|
|
SPI_SETFREQUENCY(priv->spi, priv->config->frequency);
|
|
|
|
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN(0), true);
|
|
|
|
SPI_SEND(priv->spi, regaddr); /* Issue a read on the address */
|
|
|
|
SPI_SEND(priv->spi, 0); /* Next address (not used) */
|
|
|
|
SPI_SEND(priv->spi, regval); /* write register */
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN(0), false);
|
|
|
|
SPI_LOCK(priv->spi, false);
|
2012-05-05 19:27:03 +02:00
|
|
|
#endif
|
2020-09-17 08:49:04 +02:00
|
|
|
}
|
2012-05-05 19:27:03 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2012-05-29 03:43:51 +02:00
|
|
|
* Name: stmpe811_getreg16
|
2012-05-05 19:27:03 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Read 16-bits of data from an STMPE-11 register
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
uint16_t stmpe811_getreg16(FAR struct stmpe811_dev_s *priv, uint8_t regaddr)
|
2012-05-05 19:27:03 +02:00
|
|
|
{
|
|
|
|
/* 16-bit data read sequence:
|
2020-09-17 08:49:04 +02:00
|
|
|
* i2c:
|
2014-04-13 22:32:20 +02:00
|
|
|
* Start - I2C_Write_Address - STMPE811_Reg_Address -
|
2012-05-29 03:43:51 +02:00
|
|
|
* Repeated_Start - I2C_Read_Address - STMPE811_Read_Data_1 -
|
|
|
|
* STMPE811_Read_Data_2 - STOP
|
2020-09-17 08:49:04 +02:00
|
|
|
* spi:
|
|
|
|
* 16 bit registers are MSB.
|
|
|
|
* [STMPE811_Reg_Address | 0x80] - [STMPE811_Reg_Address + 1 | 0x80] -
|
|
|
|
* Read Register - Read Register + 1
|
2012-05-05 19:27:03 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
uint8_t rxbuffer[2];
|
2020-09-17 08:49:04 +02:00
|
|
|
#ifdef CONFIG_STMPE811_I2C
|
2012-05-05 19:27:03 +02:00
|
|
|
int ret;
|
2020-09-17 08:49:04 +02:00
|
|
|
struct i2c_msg_s msg[2];
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
/* Setup 8-bit STMPE811 address write message */
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2016-02-01 21:17:20 +01:00
|
|
|
msg[0].frequency = priv->config->frequency; /* I2C frequency */
|
|
|
|
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-05 19:27:03 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
/* Set up the 8-bit STMPE811 data read message */
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2016-02-01 21:17:20 +01:00
|
|
|
msg[1].frequency = priv->config->frequency; /* I2C frequency */
|
|
|
|
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) */
|
2012-05-05 19:27:03 +02:00
|
|
|
|
|
|
|
/* Perform the transfer */
|
|
|
|
|
|
|
|
ret = I2C_TRANSFER(priv->i2c, msg, 2);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-12 17:26:00 +02:00
|
|
|
ierr("ERROR: I2C_TRANSFER failed: %d\n", ret);
|
2012-05-05 19:27:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-09-17 08:49:04 +02:00
|
|
|
#else /* CONFIG_STMPE811_SPI */
|
|
|
|
|
|
|
|
SPI_LOCK(priv->spi, true);
|
|
|
|
|
|
|
|
SPI_SETMODE(priv->spi, SPIDEV_MODE0);
|
|
|
|
SPI_SETBITS(priv->spi, 8);
|
|
|
|
SPI_HWFEATURES(priv->spi, 0);
|
|
|
|
SPI_SETFREQUENCY(priv->spi, priv->config->frequency);
|
|
|
|
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN(0), true);
|
|
|
|
SPI_SEND(priv->spi, regaddr | 0x80); /* Issue a read on the address */
|
|
|
|
SPI_SEND(priv->spi, regaddr + 1); /* Next address */
|
|
|
|
rxbuffer[0] = SPI_SEND(priv->spi, 0); /* Read MSB */
|
|
|
|
rxbuffer[1] = SPI_SEND(priv->spi, 0); /* Read LSB */
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN(0), true);
|
|
|
|
SPI_LOCK(priv->spi, false);
|
|
|
|
#endif
|
2012-05-29 03:43:51 +02:00
|
|
|
#ifdef CONFIG_STMPE811_REGDEBUG
|
2016-06-16 20:33:32 +02:00
|
|
|
_err("%02x->%02x%02x\n", regaddr, rxbuffer[0], rxbuffer[1]);
|
2012-05-09 00:10:29 +02:00
|
|
|
#endif
|
|
|
|
return (uint16_t)rxbuffer[0] << 8 | (uint16_t)rxbuffer[1];
|
2012-05-05 19:27:03 +02:00
|
|
|
}
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#endif /* CONFIG_INPUT && CONFIG_INPUT_STMPE811 */
|