From 487121513866e2a3f519e39dd8e56b0ff82be751 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 9 Jan 2014 10:57:17 -0600 Subject: Add support for the XPT2046 touchscreen controller on the Viewtool LCD module --- apps/nshlib/Kconfig | 17 +- nuttx/ChangeLog | 4 + nuttx/arch/arm/src/stm32/stm32_spi.h | 51 ++-- nuttx/configs/viewtool-stm32f107/README.txt | 53 +++- nuttx/configs/viewtool-stm32f107/nsh/defconfig | 9 +- nuttx/configs/viewtool-stm32f107/src/Makefile | 4 + nuttx/configs/viewtool-stm32f107/src/stm32_spi.c | 24 +- .../viewtool-stm32f107/src/stm32_touchscreen.c | 325 +++++++++++++++++++++ 8 files changed, 447 insertions(+), 40 deletions(-) create mode 100644 nuttx/configs/viewtool-stm32f107/src/stm32_touchscreen.c diff --git a/apps/nshlib/Kconfig b/apps/nshlib/Kconfig index 7953cf681..19216ecb3 100644 --- a/apps/nshlib/Kconfig +++ b/apps/nshlib/Kconfig @@ -12,6 +12,7 @@ config NSH_LIBRARY in order to implement the full NuttShell (NSH). if NSH_LIBRARY + config NSH_BUILTIN_APPS bool "Enable built-in applications" default n @@ -320,7 +321,7 @@ config NSH_ROMFSETC at /etc/init.d/rcS. The default startup script will mount a FAT FS RAMDISK at /tmp but the logic is easily extensible. -endif +endif # NSH_LIBRARY if NSH_ROMFSETC @@ -380,7 +381,6 @@ config NSH_ROMFSSECTSIZE config NSH_ARCHROMFS bool "Architecture-specific ROMFS header" default n - depends on NSH_ROMFSETC ---help--- Enable this option to provide an architecture-specific ROMFS header at . Note that this header @@ -424,9 +424,10 @@ config NSH_FATMOUNTPT will mount a FAT FS under /tmp. This is the location where the FAT FS will be mounted. Default is "/tmp". -endif +endif # NSH_ROMFSETC if NSH_LIBRARY + config NSH_CONSOLE bool "Use console" default y @@ -478,6 +479,7 @@ config USBDEV_MINOR minor number may also need to be provided. Default: 0 comment "USB Trace Support" + config NSH_USBDEV_TRACE bool "Enable Builtin USB Trace Support" default n @@ -524,7 +526,7 @@ config NSH_USBDEV_TRACEINTERRUPTS ---help--- Show interrupt-related events -endif +endif # NSH_USBDEV_TRACE config NSH_CONDEV bool "Default console device" @@ -565,7 +567,7 @@ config NSH_TELNET you may log into NuttX remotely using telnet in order to access NSH. -endif +endif # NSH_LIBRARY if NSH_TELNET @@ -634,8 +636,8 @@ config NSH_TELNET_FAILCOUNT ---help--- Number of login retry attempts. -endif -endif +endif # NSH_TELNET_LOGIN +endif # NSH_TELNET config NSH_DHCPC bool "Use DHCP to get IP address" @@ -702,4 +704,3 @@ config NSH_MAX_ROUNDTRIP ---help--- This is the maximum round trip for a response to a ICMP ECHO request. It is in units of deciseconds. The default is 20 (2 seconds). - diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 62fed73d4..4c250d28e 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -6404,4 +6404,8 @@ nx_open.c, and nx_openwindow.c: Needs to use kuzalloc and kufree, not umm_zalloc and umm_free. Additional typo in nx_constructwindow.c (wnd should be hwnd). Also noted by Steve Redler IV (2014-1-7). + * configs/viewtool-stm32f107/src/stm32_touchscreen.c (and other + files): Add support for the XPT2046 touchscreen controller on + the Viewtool LCD module connected to the Viewtool STM32F103 + board (2014-1-9). diff --git a/nuttx/arch/arm/src/stm32/stm32_spi.h b/nuttx/arch/arm/src/stm32/stm32_spi.h index e40db48dd..62f304dfb 100644 --- a/nuttx/arch/arm/src/stm32/stm32_spi.h +++ b/nuttx/arch/arm/src/stm32/stm32_spi.h @@ -54,7 +54,8 @@ #undef EXTERN #if defined(__cplusplus) #define EXTERN extern "C" -extern "C" { +extern "C" +{ #else #define EXTERN extern #endif @@ -99,29 +100,41 @@ enum spi_dev_e; * ************************************************************************************/ -EXTERN void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); -EXTERN uint8_t stm32_spi1status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); -EXTERN int stm32_spi1cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#ifdef CONFIG_STM32_SPI1 +void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); +uint8_t stm32_spi1status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +int stm32_spi1cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#endif -EXTERN void stm32_spi2select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); -EXTERN uint8_t stm32_spi2status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); -EXTERN int stm32_spi2cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#ifdef CONFIG_STM32_SPI2 +void stm32_spi2select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); +uint8_t stm32_spi2status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +int stm32_spi2cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#endif -EXTERN void stm32_spi3select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); -EXTERN uint8_t stm32_spi3status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); -EXTERN int stm32_spi3cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#ifdef CONFIG_STM32_SPI3 +void stm32_spi3select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); +uint8_t stm32_spi3status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +int stm32_spi3cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#endif -EXTERN void stm32_spi4select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); -EXTERN uint8_t stm32_spi4status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); -EXTERN int stm32_spi4cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#ifdef CONFIG_STM32_SPI4 +void stm32_spi4select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); +uint8_t stm32_spi4status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +int stm32_spi4cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#endif -EXTERN void stm32_spi5select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); -EXTERN uint8_t stm32_spi5status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); -EXTERN int stm32_spi5cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#ifdef CONFIG_STM32_SPI5 +void stm32_spi5select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); +uint8_t stm32_spi5status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +int stm32_spi5cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#endif -EXTERN void stm32_spi6select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); -EXTERN uint8_t stm32_spi6status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); -EXTERN int stm32_spi6cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#ifdef CONFIG_STM32_SPI6 +void stm32_spi6select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); +uint8_t stm32_spi6status(FAR struct spi_dev_s *dev, enum spi_dev_e devid); +int stm32_spi6cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); +#endif #undef EXTERN #if defined(__cplusplus) diff --git a/nuttx/configs/viewtool-stm32f107/README.txt b/nuttx/configs/viewtool-stm32f107/README.txt index f339aadce..d55bdf924 100644 --- a/nuttx/configs/viewtool-stm32f107/README.txt +++ b/nuttx/configs/viewtool-stm32f107/README.txt @@ -28,7 +28,7 @@ Contents o USB Interface o microSD Card Interface o ViewTool DP83848 Ethernet Module - o LCD Interface + o LCD/Touchscreen Interface o Toolchains - NOTE about Windows native toolchains o Configurations @@ -397,8 +397,8 @@ ViewTool DP83848 Ethernet Module (also FTP, TFTP, WGET, NFS, etc. if you also have a mass storage device). -LCD Interface -============= +LCD/Touchscreen Interface +========================= An LCD may be connected via J11. Only the the STM32F103 supports the FSMC signals needed to drive the LCD. @@ -650,6 +650,53 @@ Configurations 4. USB support is disabled by default. See the section above entitled, "USB Interface" + 5. This configuration has been used for verifying the touchscreen on + on the Viewtool LCD module. NOTE: The LCD module can really only + be used on the STM32F103 version of the board. The LCD requires + FSMC support (the touchscreen, however, does not but the touchscreen + is not very meaningful with no LCD). + + CONFIG_ARCH_CHIP_STM32F103VCT6=y : Select STM32F103VCT6 + + With the following modifications, you can include the touchscreen + test program at apps/examples/touchscreen as an NSH built-in + application. You can enable the touchscreen and test by modifying + the default configuration in the following ways: + + Device Drivers + CONFIG_SPI=y : Enable SPI support + CONFIG_SPI_EXCHANGE=y : The exchange() method is supported + CONFIG_SPI_OWNBUS=y : Smaller code if this is the only SPI device + + CONFIG_INPUT=y : Enable support for input devices + CONFIG_INPUT_ADS7843E=y : Enable support for the XPT2046 + CONFIG_ADS7843E_SPIDEV=2 : Use SPI2 for communication + CONFIG_ADS7843E_SPIMODE=0 : Use SPI mode 0 + CONFIG_ADS7843E_FREQUENCY=1000000 : SPI BAUD 1MHz + CONFIG_ADS7843E_SWAPXY=y : If landscape orientation + CONFIG_ADS7843E_THRESHX=51 : These will probably need to be tuned + CONFIG_ADS7843E_THRESHY=39 + + System Type -> Peripherals: + CONFIG_STM32_SPI2=y : Enable support for SPI2 + + RTOS Features: + CONFIG_DISABLE_SIGNALS=n : Signals are required + + Library Support: + CONFIG_SCHED_WORKQUEUE=y : Work queue support required + + Applicaton Configuration: + CONFIG_EXAMPLES_TOUCHSCREEN=y : Enable the touchscreen built-int test + + Defaults should be okay for related touchscreen settings. Touchscreen + debug output on USART1 can be enabled with: + + Build Setup: + CONFIG_DEBUG=y : Enable debug features + CONFIG_DEBUG_VERBOSE=y : Enable verbose debug output + CONFIG_DEBUG_INPUT=y : Enable debug output from input devices + highpri: This configuration was used to verify the NuttX high priority, nested diff --git a/nuttx/configs/viewtool-stm32f107/nsh/defconfig b/nuttx/configs/viewtool-stm32f107/nsh/defconfig index b09764e6b..bd00df156 100644 --- a/nuttx/configs/viewtool-stm32f107/nsh/defconfig +++ b/nuttx/configs/viewtool-stm32f107/nsh/defconfig @@ -211,6 +211,8 @@ CONFIG_STM32_CONNECTIVITYLINE=y # # STM32 Peripheral Support # +# CONFIG_STM32_HAVE_USBDEV is not set +CONFIG_STM32_HAVE_OTGFS=y # CONFIG_STM32_ADC1 is not set # CONFIG_STM32_ADC2 is not set # CONFIG_STM32_ADC3 is not set @@ -224,6 +226,7 @@ CONFIG_STM32_CONNECTIVITYLINE=y # CONFIG_STM32_ETHMAC is not set # CONFIG_STM32_I2C1 is not set # CONFIG_STM32_I2C2 is not set +# CONFIG_STM32_OTGFS is not set CONFIG_STM32_PWR=y # CONFIG_STM32_SPI1 is not set # CONFIG_STM32_SPI2 is not set @@ -241,7 +244,6 @@ CONFIG_STM32_USART1=y # CONFIG_STM32_USART3 is not set # CONFIG_STM32_UART4 is not set # CONFIG_STM32_UART5 is not set -# CONFIG_STM32_USB is not set # CONFIG_STM32_IWDG is not set # CONFIG_STM32_WWDG is not set @@ -667,16 +669,11 @@ CONFIG_EXAMPLES_NSH=y # Networking Utilities # # CONFIG_NETUTILS_CODECS is not set -# CONFIG_NETUTILS_DHCPC is not set # CONFIG_NETUTILS_DHCPD is not set # CONFIG_NETUTILS_FTPC is not set # CONFIG_NETUTILS_FTPD is not set # CONFIG_NETUTILS_JSON is not set -CONFIG_NETUTILS_RESOLV=y -CONFIG_NET_RESOLV_ENTRIES=8 -CONFIG_NET_RESOLV_MAXRESPONSE=96 # CONFIG_NETUTILS_SMTP is not set -# CONFIG_NETUTILS_TELNETD is not set CONFIG_NETUTILS_TFTPC=y # CONFIG_NETUTILS_THTTPD is not set CONFIG_NETUTILS_UIPLIB=y diff --git a/nuttx/configs/viewtool-stm32f107/src/Makefile b/nuttx/configs/viewtool-stm32f107/src/Makefile index 6c4c57b0b..f5f5cf1a4 100644 --- a/nuttx/configs/viewtool-stm32f107/src/Makefile +++ b/nuttx/configs/viewtool-stm32f107/src/Makefile @@ -62,6 +62,10 @@ CSRCS += stm32_usbdev.c endif endif +ifeq ($(CONFIG_INPUT_ADS7843E),y) # F103 +CSRCS += stm32_touchscreen.c +endif + ifeq ($(CONFIG_LCD_SSD1289),y) # F103 CSRCS += stm32_ssd1289.c endif diff --git a/nuttx/configs/viewtool-stm32f107/src/stm32_spi.c b/nuttx/configs/viewtool-stm32f107/src/stm32_spi.c index 38f4acd81..5ac136b3f 100644 --- a/nuttx/configs/viewtool-stm32f107/src/stm32_spi.c +++ b/nuttx/configs/viewtool-stm32f107/src/stm32_spi.c @@ -87,7 +87,8 @@ * Name: stm32_spiinitialize * * Description: - * Called to configure SPI chip select GPIO pins for the Viewtools stm32f103/107 board. + * Called to configure SPI chip select GPIO pins for the Viewtool stm32f103/107 + * board. * ************************************************************************************/ @@ -98,6 +99,12 @@ void weak_function stm32_spiinitialize(void) * Here, we only initialize chip select pins unique to the board * architecture. */ + +#if defined(CONFIG_STM32_SPI2) && defined(CONFIG_INPUT_ADS7843E) + /* Configure the XPT2046 SPI2 CS pin as an output */ + + (void)stm32_configgpio(GPIO_LCDTP_CS); +#endif } /**************************************************************************** @@ -141,6 +148,15 @@ uint8_t stm32_spi1status(FAR struct spi_dev_s *dev, enum spi_dev_e devid) void stm32_spi2select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected) { spidbg("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert"); + +#ifdef CONFIG_INPUT_ADS7843E + /* Select/de-select the touchscreen */ + + if (devid == SPIDEV_TOUCHSCREEN) + { + stm32_gpiowrite(GPIO_LCDTP_CS, !selected); + } +#endif } uint8_t stm32_spi2status(FAR struct spi_dev_s *dev, enum spi_dev_e devid) @@ -149,13 +165,13 @@ uint8_t stm32_spi2status(FAR struct spi_dev_s *dev, enum spi_dev_e devid) } #endif -#ifdef CONFIG_STM32_SPI2 -void stm32_spi2select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected) +#ifdef CONFIG_STM32_SPI3 +void stm32_spi3select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected) { spidbg("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert"); } -uint8_t stm32_spi2status(FAR struct spi_dev_s *dev, enum spi_dev_e devid) +uint8_t stm32_spi3status(FAR struct spi_dev_s *dev, enum spi_dev_e devid) { return 0; } diff --git a/nuttx/configs/viewtool-stm32f107/src/stm32_touchscreen.c b/nuttx/configs/viewtool-stm32f107/src/stm32_touchscreen.c new file mode 100644 index 000000000..e2061e469 --- /dev/null +++ b/nuttx/configs/viewtool-stm32f107/src/stm32_touchscreen.c @@ -0,0 +1,325 @@ +/************************************************************************************ + * configs/viewtools-stm32f107/src/stm32_touchscreen.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "up_arch.h" +#include "stm32_gpio.h" + +#include "viewtool_stm32f107.h" + +#ifdef CONFIG_INPUT_ADS7843E + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ + +#ifndef CONFIG_STM32_SPI2 +# error CONFIG_STM32_SPI2 is required for touchscreen support +#endif + +#ifndef CONFIG_ADS7843E_FREQUENCY +# define CONFIG_ADS7843E_FREQUENCY 500000 +#endif + +#ifndef CONFIG_ADS7843E_DEVMINOR +# define CONFIG_ADS7843E_DEVMINOR 0 +#endif + +/* The touchscreen communicates on SPI2 */ + +#define TSC_DEVNUM 2 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct viewtool_tscinfo_s +{ + /* Standard ADS7843/XTP2046 interface */ + + struct ads7843e_config_s config; + + /* Extensions for the viewtool board */ + + xcpt_t handler; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* IRQ/GPIO access callbacks. These operations all hidden behind + * callbacks to isolate the XPT2046 driver from differences in GPIO + * 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. + * + * attach - Attach the XPT2046 interrupt handler to the GPIO interrupt + * 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 + ****************************************************************************/ + +/* A reference to a structure of this type must be passed to the XPT2046 + * driver. This structure provides information about the configuration + * of the XPT2046 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 writable because, under certain circumstances, the driver + * may modify certain values. + */ + +static struct viewtool_tscinfo_s g_tscinfo = +{ + .config = + { + .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 + * callbacks to isolate the XPT2046 driver from differences in GPIO + * 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. + * + * attach - Attach the XPT2046 interrupt handler to the GPIO interrupt + * 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) +{ + FAR struct viewtool_tscinfo_s *priv = (FAR struct viewtool_tscinfo_s *)state; + + if (isr) + { + /* Just save the address of the handler for now. The new handler will + * be attached when the interrupt is next enabled. + */ + + ivdbg("Attaching %p\n", isr); + priv->handler = isr; + } + else + { + ivdbg("Detaching %p\n", priv->handler); + tsc_enable(state, false); + priv->handler = NULL; + } + + return OK; +} + +static void tsc_enable(FAR struct ads7843e_config_s *state, bool enable) +{ + FAR struct viewtool_tscinfo_s *priv = (FAR struct viewtool_tscinfo_s *)state; + irqstate_t flags; + + /* Attach and enable, or detach and disable. Enabling and disabling GPIO + * interrupts is a multi-step process so the safest thing is to keep + * interrupts disabled during the reconfiguration. + */ + + flags = irqsave(); + if (enable && priv->handler) + { + /* Configure the EXTI interrupt using the SAVED handler */ + + (void)stm32_gpiosetevent(GPIO_LCDTP_IRQ, true, true, true, priv->handler); + } + else + { + /* Configure the EXTI interrupt with a NULL handler to disable it */ + + (void)stm32_gpiosetevent(GPIO_LCDTP_IRQ, false, false, false, NULL); + } + + irqrestore(flags); +} + +static void tsc_clear(FAR struct ads7843e_config_s *state) +{ + /* Does nothing */ +} + +static bool tsc_busy(FAR struct ads7843e_config_s *state) +{ + return false; /* The BUSY signal is not connected */ +} + +static bool tsc_pendown(FAR struct ads7843e_config_s *state) +{ + /* The /PENIRQ value is active low */ + + bool pendown = !stm32_gpioread(GPIO_LCDTP_IRQ); + 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) +{ + FAR struct spi_dev_s *dev; + static bool initialized = false; + int ret; + + idbg("minor %d\n", minor); + DEBUGASSERT(minor == 0); + + /* Have we already initialized? Since we never uninitialize we must prevent + * multiple initializations. This is necessary, for example, when the + * touchscreen example is used as a built-in application in NSH and can be + * called numerous time. It will attempt to initialize each time. + */ + + if (!initialized) + { + /* Configure the XPT2046 interrupt pin as an input */ + + (void)stm32_configgpio(GPIO_LCDTP_IRQ); + + /* Get an instance of the SPI interface for the touchscreen chip select */ + + dev = up_spiinitialize(TSC_DEVNUM); + if (!dev) + { + idbg("Failed to initialize SPI%d\n", TSC_DEVNUM); + return -ENODEV; + } + + /* Initialize and register the SPI touchscreen device */ + + ret = ads7843e_register(dev, &g_tscinfo.config, CONFIG_ADS7843E_DEVMINOR); + if (ret < 0) + { + idbg("Failed to register touchscreen device\n"); + /* up_spiuninitialize(dev); */ + return -ENODEV; + } + + /* Now we are initialized */ + + initialized = true; + } + + 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) +{ + /* No support for un-initializing the touchscreen XPT2046 device. It will + * continue to run and process touch interrupts in the background. + */ +} + +#endif /* CONFIG_INPUT_ADS7843E */ -- cgit v1.2.3