diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-05-13 11:28:38 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-05-13 11:28:38 -0600 |
commit | 7b247cf0dd893d1641004f682415cfbbc705b4b2 (patch) | |
tree | c8783acae0cc53cba84e335f3878cba82813d1b7 | |
parent | e744f86727763c51c67790d8f98aedcd57d1048a (diff) | |
download | nuttx-7b247cf0dd893d1641004f682415cfbbc705b4b2.tar.gz nuttx-7b247cf0dd893d1641004f682415cfbbc705b4b2.tar.bz2 nuttx-7b247cf0dd893d1641004f682415cfbbc705b4b2.zip |
SAM4E-EK: Add a touchscreen driver (untestd on initial checkin)
-rw-r--r-- | nuttx/ChangeLog | 2 | ||||
-rw-r--r-- | nuttx/configs/sam4e-ek/Kconfig | 3 | ||||
-rw-r--r-- | nuttx/configs/sam4e-ek/README.txt | 97 | ||||
-rw-r--r-- | nuttx/configs/sam4e-ek/src/Makefile | 8 | ||||
-rw-r--r-- | nuttx/configs/sam4e-ek/src/sam_ads7843e.c | 290 |
5 files changed, 388 insertions, 12 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 7f6d2d4aa..2f3d7a48c 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -7333,3 +7333,5 @@ Charles Ash (2014-5-12). * configs/sam4e-ek/src/sam_ili9325.c: Add an LCD driver for the SAM4E-EK board. Untested on initial check-in (2014-5-13). + * configs/sam4e-ek/src/sam_ads7843e.c: Add a touchscreen driver for the + SAM4E-EK board. Untested on initial check-in (2014-5-13). diff --git a/nuttx/configs/sam4e-ek/Kconfig b/nuttx/configs/sam4e-ek/Kconfig index e056070a7..34a7e1897 100644 --- a/nuttx/configs/sam4e-ek/Kconfig +++ b/nuttx/configs/sam4e-ek/Kconfig @@ -70,15 +70,12 @@ choice config SAM4EEK_LCD_RGB565 bool "RGB565" - default n config SAM4EEK_LCD_RGB24 bool "RGB24 / RGB888" - default n config SAM4EEK_LCD_RGB32 bool "RGB32" - default n endchoice # ILI9325-based LCD Color Configuration diff --git a/nuttx/configs/sam4e-ek/README.txt b/nuttx/configs/sam4e-ek/README.txt index f20f283c8..f4f30db62 100644 --- a/nuttx/configs/sam4e-ek/README.txt +++ b/nuttx/configs/sam4e-ek/README.txt @@ -857,8 +857,8 @@ Touchscreen 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 SPI CS 2 for communication + CONFIG_INPUT_ADS7843E=y : Enable support for the ADS7843E + CONFIG_ADS7843E_SPIDEV=0 : Use SPI CS 0 for communication CONFIG_ADS7843E_SPIMODE=0 : Use SPI mode 0 CONFIG_ADS7843E_FREQUENCY=1000000 : SPI BAUD 1MHz CONFIG_ADS7843E_SWAPXY=y : If landscape orientation @@ -889,9 +889,6 @@ Touchscreen CONFIG_DEBUG_VERBOSE=y : Enable verbose debug output CONFIG_DEBUG_INPUT=y : Enable debug output from input devices - STATUS - 2014-3-27: As of this writing, the touchscreen is untested. - ILI9325-Based LCD ================= @@ -1335,6 +1332,96 @@ Configurations slot. Support for the SD slot can be enabled following the instructions provided above in the paragraph entitled "HSMCI." + 11. This configuration has been used for verifying the touchscreen on + on the SAM4E-EK LCD module. + + The NSH configuration can be used to verify the ADS7843E touchscreen on + the SAM4E-EK LCD. With these 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 ADS7843E + CONFIG_ADS7843E_SPIDEV=0 : Use SPI CS 0 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_SAM34_SPI0=y : Enable support for SPI + + System Type: + CONFIG_SAM34_GPIO_IRQ=y : GPIO interrupt support + CONFIG_SAM34_GPIOA_IRQ=y : Enable GPIO interrupts from port A + + RTOS Features: + CONFIG_DISABLE_SIGNALS=n : Signals are required + + Library Support: + CONFIG_SCHED_WORKQUEUE=y : Work queue support required + + Application Configuration: + CONFIG_EXAMPLES_TOUCHSCREEN=y : Enable the touchscreen built-in test + + Defaults should be okay for related touchscreen settings. Touchscreen + debug output on UART0 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 + + 11. This configuration can be re-configured to test the on-board LCD + module. + + System Type -> AT91SAM3/4 Configuration Options + CONFIG_SAM34_SMC=y : SMC support + + Device Drivers -> LCD Driver Support + CONFIG_LCD=y : Enable LCD support + CONFIG_NX_LCDDRIVER=y : LCD graphics device + CONFIG_LCD_MAXCONTRAST=1 : Value should not matter + CONFIG_LCD_MAXPOWER=64 : Must be > 16 + CONFIG_LCD_LANDSCAPE=y : Landscape orientation + + Board Selection + CONFIG_SAM4EEK_LCD_RGB565=y : Color resolution + CONFIG_SAM4EEK_LCD_BGCOLOR=0x00 : Initial background color + + Graphics Support + CONFIG_NX=y + + Graphics Support -> Supported Pixel Depths + CONFIG_NX_DISABLE_1BPP=y : Only 16BPP supported + CONFIG_NX_DISABLE_2BPP=y + CONFIG_NX_DISABLE_4BPP=y + CONFIG_NX_DISABLE_8BPP=y + CONFIG_NX_DISABLE_24BPP=y + CONFIG_NX_DISABLE_32BPP=y + + Graphics Support -> Font Selections + CONFIG_NXFONTS_CHARBITS=7 + CONFIG_NXFONT_SANS22X29B=y + CONFIG_NXFONT_SANS23X27=y + + Application Configuration -> Examples + CONFIG_EXAMPLES_NXLINES=y + CONFIG_EXAMPLES_NXLINES_BGCOLOR=0x0320 + CONFIG_EXAMPLES_NXLINES_LINEWIDTH=16 + CONFIG_EXAMPLES_NXLINES_LINECOLOR=0xffe0 + CONFIG_EXAMPLES_NXLINES_BORDERWIDTH=4 + CONFIG_EXAMPLES_NXLINES_BORDERCOLOR=0xffe0 + CONFIG_EXAMPLES_NXLINES_CIRCLECOLOR=0xf7bb + CONFIG_EXAMPLES_NXLINES_BPP=16 + STATUS: 2014-3-24: DMA is not currently functional and without DMA, there may not be reliable data transfers at high speeds due diff --git a/nuttx/configs/sam4e-ek/src/Makefile b/nuttx/configs/sam4e-ek/src/Makefile index a04cb5d7c..c16a4b7c2 100644 --- a/nuttx/configs/sam4e-ek/src/Makefile +++ b/nuttx/configs/sam4e-ek/src/Makefile @@ -46,10 +46,6 @@ ifeq ($(CONFIG_HAVE_CXXINITIALIZE),y) CSRCS += sam_cxxinitialize.c endif -ifeq ($(CONFIG_SAM4EEK_ILI9325),y) -CSRCS += sam_ili9325.c -endif - ifeq ($(CONFIG_NSH_ARCHINIT),y) CSRCS += sam_nsh.c endif @@ -62,6 +58,10 @@ ifeq ($(CONFIG_LCD),y) CSRCS += sam_ili9325.c endif +ifeq ($(CONFIG_INPUT_ADS7843E),y) +CSRCS += sam_ads7843e.c +endif + ifeq ($(CONFIG_SAM34_SPI0),y) CSRCS += sam_spi.c ifeq ($(CONFIG_MTD_AT25),y) diff --git a/nuttx/configs/sam4e-ek/src/sam_ads7843e.c b/nuttx/configs/sam4e-ek/src/sam_ads7843e.c new file mode 100644 index 000000000..1f3265bcf --- /dev/null +++ b/nuttx/configs/sam4e-ek/src/sam_ads7843e.c @@ -0,0 +1,290 @@ +/************************************************************************************ + * configs/sam4e-ek/src/sam_ads7843e.c + * + * Copyright (C) 2014 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/spi/spi.h> +#include <nuttx/input/touchscreen.h> +#include <nuttx/input/ads7843e.h> + +#include "sam_gpio.h" +#include "sam4e-ek.h" + +#if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_ADS7843E) + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ + +#ifndef CONFIG_SAM34_SPI0 +# error "Touchscreen support requires CONFIG_SAM34_SPI0" +#endif + +#ifndef CONFIG_SAM34_GPIOA_IRQ +# error "Touchscreen support requires CONFIG_SAM34_GPIOA_IRQ" +#endif + +#ifndef CONFIG_ADS7843E_FREQUENCY +# define CONFIG_ADS7843E_FREQUENCY 500000 +#endif + +#ifndef CONFIG_ADS7843E_SPIDEV +# define CONFIG_ADS7843E_SPIDEV TSC_CSNUM +#endif + +#if CONFIG_ADS7843E_SPIDEV != TSC_CSNUM +# error "CONFIG_ADS7843E_SPIDEV must have the same value as TSC_CSNUM" +#endif + +#ifndef CONFIG_ADS7843E_DEVMINOR +# define CONFIG_ADS7843E_DEVMINOR 0 +#endif + +/**************************************************************************** + * Static Function Prototypes + ****************************************************************************/ + +/* IRQ/GPIO access callbacks. These operations all hidden behind + * callbacks to isolate the ADS7843E 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 ADS7843E 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 ADS7843E + * driver. This structure provides information about the configuration + * of the ADS7843E 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. + */ + +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 + * callbacks to isolate the ADS7843E 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 ADS7843E 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) +{ + /* Attach the ADS7843E interrupt */ + + ivdbg("Attaching %p to IRQ %d\n", isr, SAM_TCS_IRQ); + return irq_attach(SAM_TCS_IRQ, isr); +} + +static void tsc_enable(FAR struct ads7843e_config_s *state, bool enable) +{ + /* Attach and enable, or detach and disable */ + + ivdbg("IRQ:%d enable:%d\n", SAM_TCS_IRQ, enable); + if (enable) + { + sam_gpioirqenable(SAM_TCS_IRQ); + } + else + { + sam_gpioirqdisable(SAM_TCS_IRQ); + } +} + +static void tsc_clear(FAR struct ads7843e_config_s *state) +{ + /* Does nothing */ +} + +static bool tsc_busy(FAR struct ads7843e_config_s *state) +{ +#if defined(CONFIG_DEBUG_INPUT) && defined(CONFIG_DEBUG_VERBOSE) + static bool last = (bool)-1; +#endif + + /* BUSY is high impedance when CS is high (not selected). When CS is + * is low, BUSY is active high. + */ + + bool busy = sam_gpioread(GPIO_TCS_BUSY); +#if defined(CONFIG_DEBUG_INPUT) && defined(CONFIG_DEBUG_VERBOSE) + if (busy != last) + { + ivdbg("busy:%d\n", busy); + last = busy; + } +#endif + + return busy; +} + +static bool tsc_pendown(FAR struct ads7843e_config_s *state) +{ + /* The /PENIRQ value is active low */ + + bool pendown = !sam_gpioread(GPIO_TCS_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; + int ret; + + idbg("minor %d\n", minor); + DEBUGASSERT(minor == 0); + + /* Configure and enable the ADS7843E interrupt pin as an input */ + + (void)sam_configgpio(GPIO_TCS_BUSY); + (void)sam_configgpio(GPIO_TCS_IRQ); + + /* Configure the PIO interrupt */ + + sam_gpioirq(GPIO_TCS_IRQ); + + /* Get an instance of the SPI interface for the touchscreen chip select */ + + dev = up_spiinitialize(TSC_CSNUM); + if (!dev) + { + idbg("Failed to initialize SPI chip select %d\n", TSC_CSNUM); + return -ENODEV; + } + + /* Initialize and register the SPI touschscreen device */ + + ret = ads7843e_register(dev, &g_tscinfo, CONFIG_ADS7843E_DEVMINOR); + if (ret < 0) + { + idbg("Failed to initialize SPI chip select %d\n", TSC_CSNUM); + /* up_spiuninitialize(dev); */ + return -ENODEV; + } + + 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 ADS7843E device yet */ +} + +#endif /* CONFIG_INPUT && CONFIG_INPUT_ADS7843E */ |