drivers/input/ft5x06.c: Add a driver for the FT5x06 capacitive, multi-touch, touchscreen controller. configs/lpcxpresso-lpc54628: Add support for the the FT5x06. Enable the driver as well as the apps/examples touchscreen test. Untested on initial commit.

This commit is contained in:
Gregory Nutt
2017-12-17 15:17:06 -06:00
parent 87252297d6
commit c62a9ea727
7 changed files with 1870 additions and 0 deletions
+4
View File
@@ -57,6 +57,10 @@ STATUS
are processed. This, I suspect, is a consequence of the strong glitch are processed. This, I suspect, is a consequence of the strong glitch
filtering that is enbled in the pin configuration. Snappier filtering that is enbled in the pin configuration. Snappier
response my be obtainble with filtering off. response my be obtainble with filtering off.
2017-12-17: Added a driver for the FT5x06 capacitive, multi-touch
controller. Add support logic for the LPCXpresso-LPC54528 to
initialize and the register the FT5x06 driver. Untested on initial
commit
Configurations Configurations
============== ==============
@@ -0,0 +1,246 @@
/****************************************************************************
* configs/lpcxpresso-lpc54628/src/lpc54_ft5x06.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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>
#include <syslog.h>
#include <errno.h>
#include <nuttx/arch.h>
#include <nuttx/i2c/i2c_master.h>
#include <nuttx/input/ft5x06.h>
#include "lpc54_config.h"
#include "lpc54_gpio.h"
#include "lpcxpresso-lpc54628.h"
#ifdef HAVE_FT5x06
/****************************************************************************
* Pre-processor Defintions
****************************************************************************/
#define FT5x06_FREQUENCY 400000 /* For now, will boost later */
/****************************************************************************
* Private Function Ptototypes
****************************************************************************/
static int lpc54_ft5x06_attach(FAR const struct ft5x06_config_s *config,
enum ft5x06_irqsource_e irqsrc, xcpt_t isr, FAR void *arg);
static void lpc54_ft5x06_enable(FAR const struct ft5x06_config_s *config,
enum ft5x06_irqsource_e irqsrc, bool enable);
static void lpc54_ft5x06_clear(FAR const struct ft5x06_config_s *config,
enum ft5x06_irqsource_e irqsrc);
static void lpc54_ft5x06_nreset(FAR const struct ft5x06_config_s *config,
bool state);
/****************************************************************************
* Private Data
****************************************************************************/
static const struct ft5x06_config_s g_ft5x06_config =
{
.address = FT5x06_I2C_ADDRESS,
.frequency = FT5x06_FREQUENCY,
.attach = lpc54_ft5x06_attach,
.enable = lpc54_ft5x06_enable,
.clear = lpc54_ft5x06_clear,
.nreset = lpc54_ft5x06_nreset
};
static uint8_t g_ft5x06_irq;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: lpc54_ft5x06_attach
*
* Description:
* Attach an FT5x06 interrupt handler to a GPIO interrupt
*
****************************************************************************/
static int lpc54_ft5x06_attach(FAR const struct ft5x06_config_s *config,
enum ft5x06_irqsource_e irqsrc, xcpt_t isr,
FAR void *arg)
{
if (irqsrc == FT5X06_DATA_SOURCE)
{
return irq_attach(g_ft5x06_irq, isr, arg);
}
else
{
return -ENOSYS;
}
}
/****************************************************************************
* Name: lpc54_ft5x06_enable
*
* Description:
* Enable or disable a GPIO interrupt
*
****************************************************************************/
static void lpc54_ft5x06_enable(FAR const struct ft5x06_config_s *config,
enum ft5x06_irqsource_e irqsrc, bool enable)
{
if (irqsrc == FT5X06_DATA_SOURCE)
{
up_enable_irq(g_ft5x06_irq);
}
}
/****************************************************************************
* Name: lpc54_ft5x06_clear
*
* Description:
* Acknowledge/clear any pending GPIO interrupt
*
****************************************************************************/
static void lpc54_ft5x06_clear(FAR const struct ft5x06_config_s *config,
enum ft5x06_irqsource_e irqsrc)
{
if (irqsrc == FT5X06_DATA_SOURCE)
{
(void)lpc54_gpio_ackedge(g_ft5x06_irq);
}
}
/****************************************************************************
* Name: lpc54_ft5x06_nreset
*
* Description:
* Control the chip reset pin (active low)
*
****************************************************************************/
static void lpc54_ft5x06_nreset(FAR const struct ft5x06_config_s *config,
bool nstate)
{
lpc54_gpio_write(GPIO_FT5x06_CTRSTn, nstate);
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: lpc54_ft5x06_register
*
* Description:
* Register the FT5x06 touch panel driver
*
****************************************************************************/
int lpc54_ft5x06_register(void)
{
FAR struct i2c_master_s *i2c;
int irq;
int ret;
/* Initialize GPIO pins. NOTE: The nRST pin was already configured during
* early LCD initialization. The Part is in reset now.
*/
lpc54_gpio_config(GPIO_FT5x06_INTR);
irq = lpc54_gpio_irqno(GPIO_FT5x06_INTR);
DEBUGASSERT(irq > 0 && irq < UINT8_MAX);
g_ft5x06_irq = (uint8_t)irq;
/* Make sure that the interrupt is disabled at the NVIC */
lpc54_gpio_ackedge(irq);
up_disable_irq(irq);
/* Take the FT5x06 out of reset */
lpc54_gpio_write(GPIO_FT5x06_CTRSTn, true);
/* The FT5x06 is on I2C2. Get the handle and register the F5x06 device */
i2c = lpc54_i2c_handle(2, I2C2NDX);
if (i2c == NULL)
{
syslog(LOG_ERR, "ERROR: Failed to get I2C2 interface\n");
return -ENODEV;
}
else
{
ret = ft5x06_register(i2c, &g_ft5x06_config, 0);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed to register FT5x06 driver: %d\n",
ret);
lpc54_gpio_write(GPIO_FT5x06_CTRSTn, false);
lpc54_i2c_free(I2C2NDX);
return ret;
}
}
return OK;
}
/****************************************************************************
* Name: board_tsc_setup and board_tsc_teardown
*
* Description:
* Stubs for expected interfaces. This implementation does not permit the
* application to mange the touch screen controller.
*
****************************************************************************/
#ifdef CONFIG_BOARDCTL_TSCTEST
int board_tsc_setup(int minor)
{
DEBUGASSERT(minor == 0);
return OK;
}
void board_tsc_teardown(void)
{
}
#endif
#endif /* HAVE_FT5x06*/
+107
View File
@@ -0,0 +1,107 @@
/****************************************************************************
* configs/lpcxpresso-lpc54628/src/lpc54_i2c.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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>
#include <syslog.h>
#include <nuttx/i2c/i2c_master.h>
#include "lpc54_config.h"
#include "lpc54_i2c_master.h"
#include "lpcxpresso-lpc54628.h"
#if defined(HAVE_I2CTOOL) || defined(HAVE_FT5x06)
/****************************************************************************
* Private Data
****************************************************************************/
static FAR struct i2c_master_s *g_i2c_handle[NI2C];
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: lpc54_i2c_handle
*
* Description:
* Create (or reuse) an I2C handle
*
****************************************************************************/
FAR struct i2c_master_s *lpc54_i2c_handle(int bus, int ndx)
{
FAR struct i2c_master_s *i2c = g_i2c_handle[ndx];
if (i2c == NULL)
{
i2c = lpc54_i2cbus_initialize(bus);
if (i2c == NULL)
{
syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", bus);
}
else
{
g_i2c_handle[ndx] = i2c;
}
}
return i2c;
}
/****************************************************************************
* Name: lpc54_i2c_free
*
* Description:
* Free an I2C handle created by lpc54_i2c_handle
*
****************************************************************************/
void lpc54_i2c_free(int ndx)
{
if (g_i2c_handle[ndx] != NULL)
{
lpc54_i2cbus_uninitialize(g_i2c_handle[ndx]);
g_i2c_handle[ndx] = NULL;
}
}
#endif /* HAVE_I2CTOOL || HAVE_FT5x06*/
@@ -0,0 +1,132 @@
/****************************************************************************
* configs/lpcxpresso-lpc54628/src/lpc54_i2ctool.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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>
#include <syslog.h>
#include <nuttx/i2c/i2c_master.h>
#include "lpc54_config.h"
#include "lpc54_i2c_master.h"
#include "lpcxpresso-lpc54628.h"
#ifdef HAVE_I2CTOOL
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: lpc54_i2c_register
*
* Description:
* Register one I2C drivers for the I2C tool.
*
****************************************************************************/
static void lpc54_i2c_register(int bus, int ndx)
{
FAR struct i2c_master_s *i2c;
int ret;
i2c = lpc54_i2c_handle(bus, ndx);
if (i2c == NULL)
{
syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", bus);
}
else
{
ret = i2c_register(i2c, bus);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",
bus, ret);
lpc54_i2cbus_uninitialize(i2c);
}
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: lpc54_i2ctool
*
* Description:
* Register I2C drivers for the I2C tool.
*
****************************************************************************/
void lpc54_i2ctool(void)
{
#ifdef CONFIG_LPC54_I2C0_MASTER
lpc54_i2c_register(0, I2C0NDX);
#endif
#ifdef CONFIG_LPC54_I2C1_MASTER
lpc54_i2c_register(1, I2C1NDX);
#endif
#ifdef CONFIG_LPC54_I2C2_MASTER
lpc54_i2c_register(2, I2C2NDX);
#endif
#ifdef CONFIG_LPC54_I2C3_MASTER
lpc54_i2c_register(3, I2C3NDX);
#endif
#ifdef CONFIG_LPC54_I2C4_MASTER
lpc54_i2c_register(4, I2C4NDX);
#endif
#ifdef CONFIG_LPC54_I2C5_MASTER
lpc54_i2c_register(5, I2C5NDX);
#endif
#ifdef CONFIG_LPC54_I2C6_MASTER
lpc54_i2c_register(6, I2C6NDX);
#endif
#ifdef CONFIG_LPC54_I2C7_MASTER
lpc54_i2c_register(7, I2C7NDX);
#endif
#ifdef CONFIG_LPC54_I2C8_MASTER
lpc54_i2c_register(8, I2C8NDX);
#endif
#ifdef CONFIG_LPC54_I2C9_MASTER
lpc54_i2c_register(9, I2C9NDX);
#endif
}
#endif /* HAVE_I2CTOOL */
File diff suppressed because it is too large Load Diff
+196
View File
@@ -0,0 +1,196 @@
/****************************************************************************
* drivers/input/ft5x06.h
*
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* References:
* "FT5x06", FocalTech Systems Co., Ltd, D-FT5x06-1212-V4.0, Revised
* Dec. 18, 2012
*
* Some of this driver was developed with input from NXP sample code for
* the LPCXpresso-LPC54628 baord. That sample code as a compatible BSD
* license:
*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
*
* 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.
*
****************************************************************************/
/* The FT5x06 Series ICs are single-chip capacitive touch panel controller
* ICs with a built-in 8 bit Micro-controller unit (MCU). They adopt the
* mutual capacitance approach, which supports true multi-touch capability.
* In conjunction with a mutual capacitive touch panel, the FT5x06 have
* user-friendly input functions, which can be applied on many portable
* devices, such as cellular phones, MIDs, netbook and notebook personal
* computers.
*/
#ifndef __DRIVERS_INPUT_FT5X06_H
#define __DRIVERS_INPUT_FT5X06_H
/****************************************************************************
* Included Files
****************************************************************************/
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* WARNING: Some definitions may apply only to the FT5336 */
/* FT5x06 maximum number of simultaneously detected touches. */
#define FT5x06_MAX_TOUCHES (5)
/* FT5x06 raw touch data length. */
#define FT5x06_TOUCH_DATA_LEN (0x20)
/* FT5x06 register addresses */
#define FT5x06_TOUCH_MODE_REG (0x00) /* Mode register */
#define FT5x06_TOUCH_GESTID_REG (0x01) /* Gesture ID register */
#define FT5x06_TOUCH_STAT_REG (0x02) /* Touch data status */
/* See struct ft5x06_touch_point_s */
#define FT5x06_TH_GROUP_REG (0x80) /* Threshold for touch detection */
#define FT5x06_TH_DIFF_REG (0x85) /* Filter function coefficients */
#define FT5x06_CTRL_REG (0x86) /* Control register */
#define FT5x06_TIMEENTERMONITOR_REG (0x87) /* Time switching Active to Monitor */
#define FT5x06_PERIODACTIVE_REG (0x88) /* Report rate in Active mode */
#define FT5x06_PERIODMONITOR_REG (0x89) /* Report rate in Monitor mode */
#define FT5x06_RADIAN_VALUE_REG (0x91) /* Minimum allowing angle */
#define FT5x06_OFFSET_LEFT_RIGHT_REG (0x92) /* Mimimum offset */
#define FT5x06_OFFSET_UP_DOWN_REG (0x93) /* Maximum offset */
#define FT5x06_DISTANCE_LEFT_RIGHT_REG (0x94) /* Minimum distance */
#define FT5x06_DISTANCE_UP_DOWN_REG (0x95) /* Minimum distance */
#define FT5x06_DISTANCE_ZOOM_REG (0x96) /* Maximum distance */
#define FT5x06_LIB_VER_H_REG (0xa1) /* MS LIB version */
#define FT5x06_LIB_VER_L_REG (0xa2) /* LS LIB version */
#define FT5x06_CIPHER_REG (0xa3) /* Chip selecting */
#define FT5x06_GMODE_REG (0xa4) /* Interrupt mode */
#define FT5x06_PWR_MODE_REG (0xa5) /* Power mode */
#define FT5x06_FIRMID_REG (0xa6) /* Firmware version */
#define FT5x06_CHIP_ID_REG (0xa8) /* Chip ID */
#define FT5x06_RELEASE_CODE_ID_REG (0xaf) /* Release code version */
#define FT5x06_STATE_REG (0xbc) /* Current operating mode */
#define FT5x06_TOUCH_DATA_STARTREG (1) /* Address where data begins */
/* Possible values of the DEV_MODE register */
#define FT5x06_DEV_MODE_WORKING (0x00)
#define FT5x06_DEV_MODE_FACTORY (0x04)
/* Possible values of the GEST_ID register */
#define FT5x06_GEST_ID_NO_GESTURE (0x00)
#define FT5x06_GEST_ID_MOVE_UP (0x10)
#define FT5x06_GEST_ID_MOVE_RIGHT (0x14)
#define FT5x06_GEST_ID_MOVE_DOWN (0x18)
#define FT5x06_GEST_ID_MOVE_LEFT (0x1C)
#define FT5x06_GEST_ID_SINGLE_CLICK (0x20)
#define FT5x06_GEST_ID_DOUBLE_CLICK (0x22)
#define FT5x06_GEST_ID_ROTATE_CLOCKWISE (0x28)
#define FT5x06_GEST_ID_ROTATE_C_CLOCKWISE (0x29)
#define FT5x06_GEST_ID_ZOOM_IN (0x40)
#define FT5x06_GEST_ID_ZOOM_OUT (0x49)
/* Values related to FT5x06_CTRL_REG */
#define FT5x06_CTRL_KEEP_ACTIVE_MODE (0x00)
#define FT5x06_CTRL_KEEP_AUTO_SWITCH_MONITOR_MODE (0x01)
/* Possible values of FT5x06_GMODE_REG */
#define FT5x06_G_MODE_INTERRUPT_POLLING (0x00)
#define FT5x06_G_MODE_INTERRUPT_TRIGGER (0x01)
/* Possible values of FT5x06_CHIP_ID_REG */
#define FT5x06_ID_VALUE (0x51)
/* Operations on struct ft5x06_touch_point_s */
#define TOUCH_POINT_GET_EVENT(t) ((t).xh >> 6)
#define TOUCH_POINT_GET_ID(t) ((t).yh >> 4)
#define TOUCH_POINT_GET_X(t) ((((t).xh & 0x0f) << 8) | (t).xl)
#define TOUCH_POINT_GET_Y(t) ((((t).yh & 0x0f) << 8) | (t).yl)
/****************************************************************************
* Public Types
****************************************************************************/
enum touch_event_e
{
FT5x06_DOWN = 0, /* The state changed to touched */
FT5x06_UP = 1, /* The state changed to not touched */
FT5x06_CONTACT = 2, /* There is a continuous touch being detected */
FT5x06_INVALID = 3 /* No touch information available */
};
/* Describes on touchpoint returned by the FT5x06 */
struct ft5x06_touch_point_s
{
uint8_t xh;
uint8_t xl;
uint8_t yh;
uint8_t yl;
uint8_t weight;
uint8_t area;
};
/* Describes all touch data returned by the FT5x06 */
struct ft5x06_touch_data_s
{
uint8_t gestid; /* Gesture ID */
uint8_t tdstatus; /* Touch status */
struct ft5x06_touch_point_s touch[FT5x06_MAX_TOUCHES];
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __DRIVERS_INPUT_FT5X06_H */
+182
View File
@@ -0,0 +1,182 @@
/****************************************************************************
* include/nuttx/input/ft5x06.h
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* References:
* "FT5x06", FocalTech Systems Co., Ltd, D-FT5x06-1212-V4.0, Revised
* Dec. 18, 2012
*
* 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.
*
****************************************************************************/
/* The FT5x06 Series ICs are single-chip capacitive touch panel controller
* ICs with a built-in 8 bit Micro-controller unit (MCU). They adopt the
* mutual capacitance approach, which supports true multi-touch capability.
* In conjunction with a mutual capacitive touch panel, the FT5x06 have
* user-friendly input functions, which can be applied on many portable
* devices, such as cellular phones, MIDs, netbook and notebook personal
* computers.
*/
#ifndef __INCLUDE_NUTTX_INPUT_FT5X06_H
#define __INCLUDE_NUTTX_INPUT_FT5X06_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/irq.h>
#include <nuttx/i2c/i2c_master.h>
#ifdef CONFIG_INPUT_FT5X06
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* Maximum number of threads than can be waiting for POLL events */
#ifndef CONFIG_FT5X06_NPOLLWAITERS
# define CONFIG_FT5X06_NPOLLWAITERS 2
#endif
/* Check for some required settings. This can save the user a lot of time
* in getting the right configuration.
*/
#ifdef CONFIG_DISABLE_SIGNALS
# error "Signals are required. CONFIG_DISABLE_SIGNALS must not be selected."
#endif
#ifndef CONFIG_SCHED_WORKQUEUE
# error "Work queue support required. CONFIG_SCHED_WORKQUEUE must be selected."
#endif
/****************************************************************************
* Public Types
****************************************************************************/
/* The FT5x08 provides two interrupts pins:
*
* INT -A n interrupt signal to inform the host processor that touch data
* is ready for ready to be read.
* WAKE - An interrupt signal for the host to change FT5x06 from Hibernate
* to Active mode.
*
* A value from this enumeration must be passed to each interrupt-related
* interface method to distinguish the interrupt sources.
*/
enum ft5x06_irqsource_e
{
FT5X06_DATA_SOURCE = 0,
FT5X06_WAKE_SOURCE,
};
/* A reference to a structure of this type must be passed to the FT5X06
* driver. This structure provides information about the configuration
* of the FT5x06 and provides some board-specific hooks.
*
* Memory for this structure is provided by the caller. It is not copied
* by the driver and is presumed to persist while the driver is active. The
* memory must be writeable because, under certain circumstances, the driver
* may modify frequency or X plate resistance values.
*/
struct ft5x06_config_s
{
/* Device characterization */
uint8_t address; /* 7-bit I2C address (only bits 0-6 used) */
uint32_t frequency; /* Default I2C frequency */
/* IRQ/GPIO access callbacks. These operations all hidden behind
* callbacks to isolate the FT5X06 driver from differences in GPIO
* interrupt handling by varying boards and MCUs.
*
* attach - Attach an FT5x06 interrupt handler to a GPIO interrupt
* enable - Enable or disable a GPIO interrupt
* clear - Acknowledge/clear any pending GPIO interrupt
* nreset - Control the chip reset pin (active low)
*/
int (*attach)(FAR const struct ft5x06_config_s *config,
enum ft5x06_irqsource_e irqsrc, xcpt_t isr, FAR void *arg);
void (*enable)(FAR const struct ft5x06_config_s *config,
enum ft5x06_irqsource_e irqsrc, bool enable);
void (*clear)(FAR const struct ft5x06_config_s *config,
enum ft5x06_irqsource_e irqsrc);
void (*nreset)(FAR const struct ft5x06_config_s *config,
bool state);
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: ft5x06_register
*
* Description:
* Configure the FT5x06 to use the provided I2C device instance. This
* will register the driver as /dev/inputN where N is the minor device
* number
*
* Input Parameters:
* i2c - An I2C driver instance
* config - Persistent board configuration data
* minor - The input device minor number
*
* Returned Value:
* Zero is returned on success. Otherwise, a negated errno value is
* returned to indicate the nature of the failure.
*
****************************************************************************/
int ft5x06_register(FAR struct i2c_master_s *i2c,
FAR const struct ft5x06_config_s *config, int minor);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* CONFIG_INPUT_FT5X06 */
#endif /* __INCLUDE_NUTTX_INPUT_FT5X06_H */