2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
2012-05-29 03:43:51 +02:00
|
|
|
* drivers/input/stmpe811.h
|
2012-04-27 20:29:04 +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-04-27 20:29:04 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-04-27 20:29:04 +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-04-27 20:29:04 +02:00
|
|
|
*
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2012-04-27 20:29:04 +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-29 03:43:51 +02:00
|
|
|
#ifndef __DRIVERS_INPUT_STMPE811_H
|
|
|
|
#define __DRIVERS_INPUT_STMPE811_H
|
2012-04-27 20:29:04 +02:00
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
2012-04-27 20:29:04 +02:00
|
|
|
* Included Files
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2012-04-27 20:29:04 +02:00
|
|
|
|
2012-05-05 19:27:03 +02:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2020-02-01 08:17:32 +01:00
|
|
|
#include <nuttx/semaphore.h>
|
2014-08-21 19:16:55 +02:00
|
|
|
#include <nuttx/wdog.h>
|
2012-05-21 19:36:26 +02:00
|
|
|
#include <nuttx/clock.h>
|
2012-05-05 19:27:03 +02:00
|
|
|
#include <nuttx/wqueue.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
|
|
|
#if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_STMPE811)
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
2015-04-08 15:15:32 +02:00
|
|
|
* Pre-processor Definitions
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2020-08-09 14:51:47 +02:00
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/* Configuration ************************************************************/
|
2020-08-09 14:51:47 +02:00
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/* Reference counting is partially implemented, but not needed in the current
|
|
|
|
* design.
|
|
|
|
*/
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#undef CONFIG_STMPE811_REFCNT
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/* Driver support ***********************************************************/
|
2020-08-09 14:51:47 +02:00
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/* This format is used to construct the /dev/input[n] device driver path.
|
|
|
|
* It defined here so that it will be used consistently in all places.
|
2012-05-05 19:27:03 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEV_FORMAT "/dev/input%d"
|
|
|
|
#define DEV_NAMELEN 16
|
2012-04-27 20:29:04 +02:00
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/* STMPE811 Resources *******************************************************/
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#ifndef CONFIG_STMPE811_TSC_DISABLE
|
|
|
|
# define STMPE811_ADC_NPINS 4 /* Only pins 0-3 can be used for ADC */
|
|
|
|
# define STMPE811_GPIO_NPINS 4 /* Only pins 0-3 can be used as GPIOs */
|
2012-05-06 03:37:47 +02:00
|
|
|
#else
|
2012-05-29 03:43:51 +02:00
|
|
|
# define STMPE811_ADC_NPINS 8 /* All pins can be used for ADC */
|
|
|
|
# define STMPE811_GPIO_NPINS 8 /* All pins can be used as GPIOs */
|
2012-05-06 03:37:47 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Driver flags */
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#define STMPE811_FLAGS_TSC_INITIALIZED (1 << 0) /* 1: The TSC block has been initialized */
|
|
|
|
#define STMPE811_FLAGS_GPIO_INITIALIZED (1 << 1) /* 1: The GIO block has been initialized */
|
|
|
|
#define STMPE811_FLAGS_ADC_INITIALIZED (1 << 2) /* 1: The ADC block has been initialized */
|
|
|
|
#define STMPE811_FLAGS_TS_INITIALIZED (1 << 3) /* 1: The TS block has been initialized */
|
2012-05-06 03:37:47 +02:00
|
|
|
|
2012-05-21 19:36:26 +02:00
|
|
|
/* Timeout to detect missing pen up events */
|
|
|
|
|
2014-08-08 02:00:38 +02:00
|
|
|
#define STMPE811_PENUP_TICKS MSEC2TICK(100)
|
2012-05-21 19:36:26 +02:00
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
2012-04-27 20:29:04 +02:00
|
|
|
* Public Types
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2020-08-09 14:51:47 +02:00
|
|
|
|
2012-05-05 19:27:03 +02:00
|
|
|
/* This describes the state of one contact */
|
2012-04-27 20:29:04 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
enum stmpe811_contact_3
|
2012-05-05 19:27:03 +02:00
|
|
|
{
|
|
|
|
CONTACT_NONE = 0, /* No contact */
|
|
|
|
CONTACT_DOWN, /* First contact */
|
|
|
|
CONTACT_MOVE, /* Same contact, possibly different position */
|
|
|
|
CONTACT_UP, /* Contact lost */
|
|
|
|
};
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
/* This structure describes the results of one STMPE811 sample */
|
2012-04-27 20:29:04 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
struct stmpe811_sample_s
|
2012-05-05 19:27:03 +02:00
|
|
|
{
|
|
|
|
uint8_t id; /* Sampled touch point ID */
|
2012-05-29 03:43:51 +02:00
|
|
|
uint8_t contact; /* Contact state (see enum stmpe811_contact_e) */
|
2012-05-13 20:28:43 +02:00
|
|
|
bool valid; /* True: x,y,z contain valid, sampled data */
|
2012-05-05 19:27:03 +02:00
|
|
|
uint16_t x; /* Measured X position */
|
|
|
|
uint16_t y; /* Measured Y position */
|
2012-05-06 18:00:16 +02:00
|
|
|
uint8_t z; /* Measured Z index */
|
2012-05-05 19:27:03 +02:00
|
|
|
};
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
/* This structure represents the state of the STMPE811 driver */
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
struct stmpe811_dev_s
|
2012-05-05 19:27:03 +02:00
|
|
|
{
|
2012-05-29 03:43:51 +02:00
|
|
|
#ifdef CONFIG_STMPE811_MULTIPLE
|
2020-08-09 14:51:47 +02:00
|
|
|
FAR struct stmpe811_dev_s *flink; /* Supports a singly linked list of drivers */
|
2012-05-05 19:27:03 +02:00
|
|
|
#endif
|
|
|
|
|
2012-05-06 01:17:25 +02:00
|
|
|
/* Common fields */
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
FAR struct stmpe811_config_s *config; /* Board configuration data */
|
2020-08-09 14:51:47 +02:00
|
|
|
sem_t exclsem; /* Manages exclusive access to this structure */
|
2012-05-29 03:43:51 +02:00
|
|
|
#ifdef CONFIG_STMPE811_SPI
|
2020-08-09 14:51:47 +02:00
|
|
|
FAR struct spi_dev_s *spi; /* Saved SPI driver instance */
|
2012-04-27 20:29:04 +02:00
|
|
|
#else
|
2020-08-09 14:51:47 +02:00
|
|
|
FAR struct i2c_master_s *i2c; /* Saved I2C driver instance */
|
2012-04-27 20:29:04 +02:00
|
|
|
#endif
|
|
|
|
|
2020-08-09 14:51:47 +02:00
|
|
|
uint8_t inuse; /* STMPE811 pins in use */
|
|
|
|
uint8_t flags; /* See STMPE811_FLAGS_* definitions */
|
|
|
|
struct work_s work; /* Supports the interrupt handling "bottom half" */
|
2012-05-06 01:17:25 +02:00
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/* Fields that may be disabled to save size if touchscreen support
|
|
|
|
* is not used.
|
|
|
|
*/
|
2012-05-06 01:17:25 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#ifndef CONFIG_STMPE811_TSC_DISABLE
|
|
|
|
#ifdef CONFIG_STMPE811_REFCNT
|
2020-08-09 14:51:47 +02:00
|
|
|
uint8_t crefs; /* Number of times the device has been opened */
|
2012-05-06 01:17:25 +02:00
|
|
|
#endif
|
2020-08-09 14:51:47 +02:00
|
|
|
uint8_t nwaiters; /* Number of threads waiting for STMPE811 data */
|
|
|
|
uint8_t id; /* Current touch point ID */
|
|
|
|
uint8_t minor; /* Touchscreen minor device number */
|
|
|
|
volatile bool penchange; /* An unreported event is buffered */
|
|
|
|
|
|
|
|
uint16_t threshx; /* Thresholded X value */
|
|
|
|
uint16_t threshy; /* Thresholded Y value */
|
|
|
|
sem_t waitsem; /* Used to wait for the availability of data */
|
|
|
|
|
|
|
|
struct work_s timeout; /* Supports tiemeout work */
|
|
|
|
struct wdog_s wdog; /* Timeout to detect missing pen down events */
|
|
|
|
struct stmpe811_sample_s sample; /* Last sampled touch point data */
|
2012-05-05 19:27:03 +02:00
|
|
|
|
|
|
|
/* The following is a list if poll structures of threads waiting for
|
|
|
|
* driver events. The 'struct pollfd' reference for each open is also
|
|
|
|
* retained in the f_priv field of the 'struct file'.
|
|
|
|
*/
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
struct pollfd *fds[CONFIG_STMPE811_NPOLLWAITERS];
|
2012-05-06 01:17:25 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Fields that may be disabled to save size of GPIO support is not used */
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#if !defined(CONFIG_STMPE811_GPIO_DISABLE) && !defined(CONFIG_STMPE811_GPIOINT_DISABLE)
|
|
|
|
stmpe811_handler_t handlers[STMPE811_GPIO_NPINS]; /* GPIO "interrupt handlers" */
|
2012-05-06 01:17:25 +02:00
|
|
|
#endif
|
2012-05-05 19:27:03 +02:00
|
|
|
};
|
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
2012-05-05 19:27:03 +02:00
|
|
|
* Public Function Prototypes
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2021-03-04 08:02:21 +01: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
|
|
|
*
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
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
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
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
|
|
|
*
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
void stmpe811_putreg8(FAR struct stmpe811_dev_s *priv,
|
|
|
|
uint8_t regaddr, uint8_t regval);
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2021-03-04 08:02:21 +01: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
|
|
|
|
*
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2012-05-05 19:27:03 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
uint16_t stmpe811_getreg16(FAR struct stmpe811_dev_s *priv, uint8_t regaddr);
|
2012-04-27 20:29:04 +02:00
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
2012-05-29 03:43:51 +02:00
|
|
|
* Name: stmpe811_tscint
|
2012-05-06 01:17:25 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2021-03-04 08:02:21 +01:00
|
|
|
* Handle touchscreen interrupt events (this function actually executes in
|
|
|
|
* the context of the worker thread).
|
2012-05-06 01:17:25 +02:00
|
|
|
*
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2012-05-06 01:17:25 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#ifndef CONFIG_STMPE811_TSC_DISABLE
|
2021-03-04 08:02:21 +01:00
|
|
|
void stmpe811_tscworker(FAR struct stmpe811_dev_s *priv,
|
|
|
|
uint8_t intsta) weak_function;
|
2012-05-06 01:17:25 +02:00
|
|
|
#endif
|
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
2012-05-29 03:43:51 +02:00
|
|
|
* Name: stmpe811_gpioworker
|
2012-05-06 01:17:25 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2021-03-04 08:02:21 +01:00
|
|
|
* Handle GPIO interrupt events (this function actually executes in the
|
|
|
|
* context of the worker thread).
|
2012-05-06 01:17:25 +02:00
|
|
|
*
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2012-05-06 01:17:25 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#if !defined(CONFIG_STMPE811_GPIO_DISABLE) && !defined(CONFIG_STMPE811_GPIOINT_DISABLE)
|
|
|
|
void stmpe811_gpioworker(FAR struct stmpe811_dev_s *priv) weak_function;
|
2012-05-06 01:17:25 +02:00
|
|
|
#endif
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#endif /* CONFIG_INPUT && CONFIG_INPUT_STMPE811 */
|
|
|
|
#endif /* __DRIVERS_INPUT_STMPE811_H */
|