2013-04-02 00:00:37 +02:00
|
|
|
/************************************************************************************
|
|
|
|
* configs/open1788/src/lpc17_touchscreen.c
|
|
|
|
* arch/arm/src/board/lpc17_touchscreen.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 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 <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/irq.h>
|
2013-07-01 16:11:54 +02:00
|
|
|
#include <nuttx/spi/spi.h>
|
2013-04-02 00:00:37 +02:00
|
|
|
#include <nuttx/input/touchscreen.h>
|
|
|
|
#include <nuttx/input/ads7843e.h>
|
|
|
|
|
|
|
|
#include "lpc17_gpio.h"
|
|
|
|
#include "lpc17_ssp.h"
|
|
|
|
#include "open1788.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_INPUT_ADS7843E
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-Processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
/* Configuration ************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_INPUT
|
|
|
|
# error "Touchscreen support requires CONFIG_INPUT"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_LPC17_SSP1
|
|
|
|
# error "Touchscreen support requires CONFIG_LPC17_SSP1"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_GPIO_IRQ
|
|
|
|
# error "Touchscreen support requires CONFIG_GPIO_IRQ"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_ADS7843E_FREQUENCY
|
|
|
|
# define CONFIG_ADS7843E_FREQUENCY 500000
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_ADS7843E_SPIDEV
|
2013-04-02 18:36:19 +02:00
|
|
|
# define CONFIG_ADS7843E_SPIDEV 1
|
2013-04-02 00:00:37 +02:00
|
|
|
#endif
|
|
|
|
|
2013-04-02 18:36:19 +02:00
|
|
|
#if CONFIG_ADS7843E_SPIDEV != 1
|
|
|
|
# error "CONFIG_ADS7843E_SPIDEV must be one"
|
2013-04-02 00:00:37 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_ADS7843E_DEVMINOR
|
|
|
|
# define CONFIG_ADS7843E_DEVMINOR 0
|
|
|
|
#endif
|
|
|
|
|
2013-04-02 18:36:19 +02:00
|
|
|
/* REVISIT: Currently, XPT2046 reports BUSY all of the time. This is
|
|
|
|
* probably GPIO setting issues. But there is this cryptic statement in
|
|
|
|
* the XPT2046 spec: "No DCLK delay required with dedicated serial port."
|
|
|
|
*
|
|
|
|
* The busy state is used by the XPT2046 driver to control the delay
|
|
|
|
* between sending the command, then reading the returned data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define XPT2046_NO_BUSY 1
|
|
|
|
|
2013-04-02 00:00:37 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* IRQ/GPIO access callbacks. These operations all hidden behind
|
2013-04-02 18:36:19 +02:00
|
|
|
* callbacks to isolate the XPT2046 driver from differences in GPIO
|
2013-04-02 00:00:37 +02:00
|
|
|
* interrupt handling by varying boards and MCUs. If possible,
|
|
|
|
* interrupts should be configured on both rising and falling edges
|
|
|
|
* so that contact and loss-of-contact events can be detected.
|
|
|
|
*
|
2013-04-02 18:36:19 +02:00
|
|
|
* attach - Attach the XPT2046 interrupt handler to the GPIO interrupt
|
2013-04-02 00:00:37 +02:00
|
|
|
* enable - Enable or disable the GPIO interrupt
|
|
|
|
* clear - Acknowledge/clear any pending GPIO interrupt
|
|
|
|
* pendown - Return the state of the pen down GPIO input
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int tsc_attach(FAR struct ads7843e_config_s *state, xcpt_t isr);
|
|
|
|
static void tsc_enable(FAR struct ads7843e_config_s *state, bool enable);
|
|
|
|
static void tsc_clear(FAR struct ads7843e_config_s *state);
|
|
|
|
static bool tsc_busy(FAR struct ads7843e_config_s *state);
|
|
|
|
static bool tsc_pendown(FAR struct ads7843e_config_s *state);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-04-02 18:36:19 +02:00
|
|
|
/* A reference to a structure of this type must be passed to the XPT2046
|
2013-04-02 00:00:37 +02:00
|
|
|
* driver. This structure provides information about the configuration
|
2013-04-02 18:36:19 +02:00
|
|
|
* of the XPT2046 and provides some board-specific hooks.
|
2013-04-02 00:00:37 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct ads7843e_config_s g_tscinfo =
|
|
|
|
{
|
|
|
|
.frequency = CONFIG_ADS7843E_FREQUENCY,
|
|
|
|
.attach = tsc_attach,
|
|
|
|
.enable = tsc_enable,
|
|
|
|
.clear = tsc_clear,
|
|
|
|
.busy = tsc_busy,
|
|
|
|
.pendown = tsc_pendown,
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* IRQ/GPIO access callbacks. These operations all hidden behind
|
2013-04-02 18:36:19 +02:00
|
|
|
* callbacks to isolate the XPT2046 driver from differences in GPIO
|
2013-04-02 00:00:37 +02:00
|
|
|
* interrupt handling by varying boards and MCUs. If possible,
|
|
|
|
* interrupts should be configured on both rising and falling edges
|
|
|
|
* so that contact and loss-of-contact events can be detected.
|
|
|
|
*
|
2013-04-02 18:36:19 +02:00
|
|
|
* attach - Attach the XPT2046 interrupt handler to the GPIO interrupt
|
2013-04-02 00:00:37 +02:00
|
|
|
* enable - Enable or disable the GPIO interrupt
|
|
|
|
* clear - Acknowledge/clear any pending GPIO interrupt
|
|
|
|
* pendown - Return the state of the pen down GPIO input
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int tsc_attach(FAR struct ads7843e_config_s *state, xcpt_t handler)
|
|
|
|
{
|
|
|
|
/* Attach then enable the touchscreen interrupt handler */
|
|
|
|
|
|
|
|
(void)irq_attach(LPC17_IRQ_PENIRQ, handler);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tsc_enable(FAR struct ads7843e_config_s *state, bool enable)
|
|
|
|
{
|
|
|
|
ivdbg("enable:%d\n", enable);
|
|
|
|
if (enable)
|
|
|
|
{
|
2013-04-08 00:30:47 +02:00
|
|
|
/* Enable PENIRQ interrupts. NOTE: The pin interrupt is enabled from worker thread
|
2013-04-07 23:16:29 +02:00
|
|
|
* logic after completion of processing of the touchscreen interrupt.
|
|
|
|
*/
|
2013-04-07 21:46:05 +02:00
|
|
|
|
2013-04-02 00:00:37 +02:00
|
|
|
up_enable_irq(LPC17_IRQ_PENIRQ);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-04-07 23:16:29 +02:00
|
|
|
/* Disable PENIRQ interrupts. NOTE: The PENIRQ interrupt will be disabled from
|
|
|
|
* interrupt handling logic.
|
2013-04-07 21:46:05 +02:00
|
|
|
*/
|
|
|
|
|
2013-04-02 00:00:37 +02:00
|
|
|
up_disable_irq(LPC17_IRQ_PENIRQ);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tsc_clear(FAR struct ads7843e_config_s *state)
|
|
|
|
{
|
2013-04-03 21:35:21 +02:00
|
|
|
/* Does nothing. The interrupt is cleared automatically in the GPIO
|
|
|
|
* logic for the LPC17xx family.
|
|
|
|
*/
|
2013-04-02 00:00:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool tsc_busy(FAR struct ads7843e_config_s *state)
|
|
|
|
{
|
2013-04-02 18:36:19 +02:00
|
|
|
/* The busy state is used by the XPT2046 driver to control the delay
|
|
|
|
* between sending the command, then reading the returned data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef XPT2046_NO_BUSY
|
|
|
|
/* REVISIT: Currently, XPT2046 reports BUSY all of the time. This is
|
|
|
|
* probably GPIO setting issues. But there is this cryptic statement in
|
|
|
|
* the XPT2046 spec: "No DCLK delay required with dedicated serial port."
|
|
|
|
*/
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#else /* XPT2046_NO_BUSY */
|
|
|
|
|
2013-04-02 00:00:37 +02:00
|
|
|
#if defined(CONFIG_DEBUG_INPUT) && defined(CONFIG_DEBUG_VERBOSE)
|
|
|
|
static bool last = (bool)-1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* REVISIT: This might need to be inverted */
|
|
|
|
|
|
|
|
bool busy = lpc17_gpioread(GPIO_TC_BUSY);
|
|
|
|
#if defined(CONFIG_DEBUG_INPUT) && defined(CONFIG_DEBUG_VERBOSE)
|
|
|
|
if (busy != last)
|
|
|
|
{
|
|
|
|
ivdbg("busy:%d\n", busy);
|
|
|
|
last = busy;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return busy;
|
2013-04-02 18:36:19 +02:00
|
|
|
|
|
|
|
#endif /* XPT2046_NO_BUSY */
|
2013-04-02 00:00:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool tsc_pendown(FAR struct ads7843e_config_s *state)
|
|
|
|
{
|
|
|
|
/* XPT2046 uses an an internal pullup resistor. The PENIRQ output goes low
|
|
|
|
* due to the current path through the touch screen to ground, which
|
|
|
|
* initiates an interrupt to the processor via TP_INT.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool pendown = !lpc17_gpioread(GPIO_TC_PENIRQ);
|
|
|
|
ivdbg("pendown:%d\n", pendown);
|
|
|
|
return pendown;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: arch_tcinitialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Each board that supports a touchscreen device must provide this
|
|
|
|
* function. This function is called by application-specific, setup logic
|
|
|
|
* to configure the touchscreen device. This function will register the
|
|
|
|
* driver as /dev/inputN where N is the minor device number.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* 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 arch_tcinitialize(int minor)
|
|
|
|
{
|
2013-04-02 18:36:19 +02:00
|
|
|
static bool initialized = false;
|
2013-04-02 00:00:37 +02:00
|
|
|
FAR struct spi_dev_s *dev;
|
|
|
|
int ret;
|
|
|
|
|
2013-04-02 18:36:19 +02:00
|
|
|
idbg("initialized:%d minor:%d\n", initialized, minor);
|
2013-04-02 00:00:37 +02:00
|
|
|
DEBUGASSERT(minor == 0);
|
|
|
|
|
2013-04-02 18:36:19 +02:00
|
|
|
/* Since there is no uninitialized logic, this initialization can be
|
|
|
|
* performed only one time.
|
|
|
|
*/
|
2013-04-02 00:00:37 +02:00
|
|
|
|
2013-04-02 18:36:19 +02:00
|
|
|
if (!initialized)
|
|
|
|
{
|
2013-04-07 23:16:29 +02:00
|
|
|
/* Configure and enable the XPT2046 PENIRQ pin as an interrupting input. */
|
2013-04-02 00:00:37 +02:00
|
|
|
|
2013-04-07 23:16:29 +02:00
|
|
|
(void)lpc17_configgpio(GPIO_TC_PENIRQ);
|
2013-04-02 00:00:37 +02:00
|
|
|
|
2013-04-02 18:36:19 +02:00
|
|
|
/* Configure the XPT2046 BUSY pin as a normal input. */
|
2013-04-02 00:00:37 +02:00
|
|
|
|
2013-04-02 18:36:19 +02:00
|
|
|
#ifndef XPT2046_NO_BUSY
|
|
|
|
(void)lpc17_configgpio(GPIO_TC_BUSY);
|
|
|
|
#endif
|
2013-04-02 00:00:37 +02:00
|
|
|
|
2013-04-02 18:36:19 +02:00
|
|
|
/* Get an instance of the SPI interface */
|
2013-04-02 00:00:37 +02:00
|
|
|
|
2013-04-02 18:36:19 +02:00
|
|
|
dev = lpc17_sspinitialize(CONFIG_ADS7843E_SPIDEV);
|
|
|
|
if (!dev)
|
|
|
|
{
|
|
|
|
idbg("Failed to initialize SPI bus %d\n", CONFIG_ADS7843E_SPIDEV);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2013-04-02 00:00:37 +02:00
|
|
|
|
2013-04-02 18:36:19 +02:00
|
|
|
/* Initialize and register the SPI touchscreen device */
|
|
|
|
|
|
|
|
ret = ads7843e_register(dev, &g_tscinfo, CONFIG_ADS7843E_DEVMINOR);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
idbg("Failed to register touchscreen device minor=%d\n",
|
|
|
|
CONFIG_ADS7843E_DEVMINOR);
|
2013-04-07 21:46:05 +02:00
|
|
|
/* up_spiuninitialize(dev); */
|
2013-04-02 18:36:19 +02:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
initialized = true;
|
2013-04-02 00:00:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: arch_tcuninitialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Each board that supports a touchscreen device must provide this function.
|
|
|
|
* This function is called by application-specific, setup logic to
|
|
|
|
* uninitialize the touchscreen device.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void arch_tcuninitialize(void)
|
|
|
|
{
|
2013-04-02 18:36:19 +02:00
|
|
|
/* No support for un-initializing the touchscreen XPT2046 device yet */
|
2013-04-02 00:00:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_INPUT_ADS7843E */
|