From b2d415da791a9a48ad01aa72dc45de0acfb7d447 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 24 Feb 2018 13:11:27 -0600 Subject: [PATCH] configs/viewtool-stm32f107: Add support for FT80X initialization. Add ft80x configuration that will eventually be used for testing the ft80x if I ever receive hardware. --- configs/viewtool-stm32f107/Kconfig | 29 ++ configs/viewtool-stm32f107/README.txt | 128 +++++++- configs/viewtool-stm32f107/ft80x/defconfig | 44 +++ .../include/board-stm32f107vct6.h | 2 +- configs/viewtool-stm32f107/nsh/defconfig | 1 + configs/viewtool-stm32f107/src/Makefile | 10 +- .../{stm32_touchscreen.c => stm32_ads7843e.c} | 2 +- .../viewtool-stm32f107/src/stm32_bringup.c | 8 + configs/viewtool-stm32f107/src/stm32_ft80x.c | 305 ++++++++++++++++++ configs/viewtool-stm32f107/src/stm32_spi.c | 32 ++ .../src/viewtool_stm32f107.h | 47 ++- drivers/lcd/ft80x_spi.c | 3 +- include/nuttx/lcd/ft80x.h | 6 +- 13 files changed, 606 insertions(+), 11 deletions(-) create mode 100644 configs/viewtool-stm32f107/ft80x/defconfig rename configs/viewtool-stm32f107/src/{stm32_touchscreen.c => stm32_ads7843e.c} (99%) create mode 100644 configs/viewtool-stm32f107/src/stm32_ft80x.c diff --git a/configs/viewtool-stm32f107/Kconfig b/configs/viewtool-stm32f107/Kconfig index 512d58630b6..5e2d7e8cca9 100644 --- a/configs/viewtool-stm32f107/Kconfig +++ b/configs/viewtool-stm32f107/Kconfig @@ -35,4 +35,33 @@ config VIEWTOOL_TIM6_PERIOD period of the TIM6 interrupt in units of VIEWTOOL_TIM6_FREQUENCY. endif # VIEWTOOL_HIGHPRI + +if LCD_FT80X_SPI && ((STM32_SPI1 && !STM32_SPI1_REMAP) || STM32_SPI2) + +choice + prompt "FT80x SPI Selection" + default VIEWTOOL_FT80X_SPI1 if STM32_SPI1 && !STM32_SPI1_REMAP + default VIEWTOOL_FT80X_SPI2 if STM32_SPI2 && (!STM32_SPI1 || STM32_SPI1_REMAP) + +config VIEWTOOL_FT80X_SPI1 + bool "FT80x on SPI1" + depends on STM32_SPI1 && !STM32_SPI1_REMAP + +config VIEWTOOL_FT80X_SPI2 + bool "FT80x on SPI2" + depends on STM32_SPI3 + +endchoice # FT80x SPI Selection + +config VIEWTOOL_FT80X_INITFREQUENCY + int "FT80x initialization frequency" + default 400000 + range 400000 11000000 + +config VIEWTOOL_FT80X_OPFREQUENCY + int "FT80x initialization frequency" + default 20000000 + range 400000 30000000 + +endif # LCD_FT80X_SPI && ((STM32_SPI1 && !STM32_SPI1_REMAP) || STM32_SPI2) endif # ARCH_BOARD_VIEWTOOL_STM32F107 diff --git a/configs/viewtool-stm32f107/README.txt b/configs/viewtool-stm32f107/README.txt index 42faf94f79d..db17063653b 100644 --- a/configs/viewtool-stm32f107/README.txt +++ b/configs/viewtool-stm32f107/README.txt @@ -30,6 +30,7 @@ Contents o ViewTool DP83848 Ethernet Module o Freescale MPL115A barometer sensor o LCD/Touchscreen Interface + o FT80x Integration o Toolchains - NOTE about Windows native toolchains o Configurations @@ -498,6 +499,125 @@ LCD/Touchscreen Interface LO LO LO LO HI LO HI LO HI LO +FT80x Integration +================= + + I have used the ViewTool F107 for initial testing of the two displays + based on FTDI/BridgeTek FT800 GUIs: + + Haoyu 5" + -------- + I purchased a Haoyu 5" FT800 display on eBay. Pin out and board + connectivity is as follows: + + 2x5 Connector J2 using SPI1: + PIN NAME VIEWTOOL STM32 PIN NAME VIEWTOOL STM32 + 1 5V J18 Pin 2 2 GND J8 Pin 8 + 3 SCK J8 Pin 11 PA5/SCK1 4 MISO J8 Pin 9 PA6/MISO1 + 5 MOSI J8 Pin 10 PA7/MOSI1 6 CS J8 Pin 12 PA4/NSS1 + 7 INT J18 Pin 8 PA1 8 PD J18 Pin 6 PC5 + 9 AUDIO-L 10 GND + + 2x5 Connector J2 using SPI2: + PIN NAME VIEWTOOL STM32 PIN NAME VIEWTOOL STM32 + 1 5V J18 Pin 2 2 GND J8 Pin 2 + 3 SCK J8 Pin 5 PB13/SCK2 4 MISO J8 Pin 3 PB14/MISO2 + 5 MOSI J8 Pin 4 PB15/MOSI2 6 CS J8 Pin 6 PB12/NSS2 + 7 INT J18 Pin 8 PA1 8 PD J18 Pin 6 PC5 + 9 AUDIO-L 10 GND J18 Pin 4 + + MikroElektronkia ConnectEVE FT800 + --------------------------------- + + 2x5 Connector CN2 using SPI1: + ---- ------ ----------- ---------- ---- ------ ---------- ---------- + PIN NAME VIEWTOOL STM32 PIN NAME VIEWTOOL STM32 + ---- ------ ----------- ---------- ---- ------ ---------- ---------- + 1 PD# J18 Pin 6 PC5 2 INT# J18 Pin 8 PA1 + 3 CS# J8 Pin 12 PA4/NSS1 4 SCK 8 Pin 11 PA5/SCK1 + 5 MISO J8 Pin 9 PA6/MISO1 6 MOSI J8 Pin 10 PA7/MOSI1 + 7 N/C 8 N/C + 9 3.3V J8 Pin 7 10 GND J8 Pin 8 + + 2x5 Connector CN2 using SPI2: + ---- ------ ----------- ---------- ---- ------ ---------- ---------- + PIN NAME VIEWTOOL STM32 PIN NAME VIEWTOOL STM32 + ---- ------ ----------- ---------- ---- ------ ---------- ---------- + 1 PD# J18 Pin 6 PC5 2 INT# J18 Pin 8 PA1 + 3 CS# J8 Pin 6 PB12/NSS2 4 SCK J8 Pin 5 PB13/SCK2 + 5 MISO J8 Pin 3 PB14/MISO2 6 MOSI J8 Pin 4 PB15/MOSI2 + 7 N/C 8 N/C + 9 3.3V J8 Pin 1 10 GND J8 Pin 2 + + 1x10 Connector CN3 using SPI1: + ---- ------ ----------- ----------- + PIN NAME VIEWTOOL STM32 + ---- ------ ----------- ----------- + 1 CS# J8 Pin 12 PA4/NSS1 + 2 SCK J8 Pin 11 PA5/SCK1 + 3 MISO J8 Pin 9 PA6/MISO1 + 4 MOSI J8 Pin 10 PA7/MOSI1 + 5 INT# J18 Pin 8 PA1 + 6 PD# J18 Pin 6 PC5 + 7 AUDIO+ + 8 AUDIO- + 9 3.3V J8 Pin 7 + 10 GND J8 Pin 8 + + 1x10 Connector CN3 using SPI2: + ---- ------ ----------- ----------- + PIN NAME VIEWTOOL STM32 + ---- ------ ----------- ----------- + 1 CS# J8 Pin 6 PB12/NSS2 + 2 SCK J8 Pin 5 PB13/SCK2 + 3 MISO J8 Pin 3 PB14/MISO2 + 4 MOSI J8 Pin 4 PB15/MOSI2 + 5 INT# J18 Pin 8 PA1 + 6 PD# J18 Pin 6 PC5 + 7 AUDIO+ + 8 AUDIO- + 9 3.3V J8 Pin 1 + 10 GND J8 Pin 2 + + Configurations using FT80x should not enable Ethernet, CAN2 or LED + support. The LCD connector, J28 pin 9, and the upper row of J18 are + also assumed to be unused: + + J8 upper row (SPI2) conflicts: + + Pin 2 PB14 also used by LCD + Pin 4 PB15 also used by LCD + Pin 5 PB13 also used by Ethernet, CAN2, LCD and LED4 + Pin 6 PB12 also used by Ethernet, CAN2, J28 pin 9, and LED3 + + J8 lower row (SPI1) conflicts: + + Pin 9 PA6 also used by J8 pin 9 and LED1 + Pin 10 PA7 also used Ethernet + Pin 11 PA5 also used by J8 pin 7 + Pin 12 PA4 also used by J8 pin 5 (J8 pin 5 not used) + + J18 upper row is not used in this configuration. Cannot be used with + SPI1. Not used with SPI2 because SPI2 has the same conflicts as the + lower row so why bother? + + Pin 5 PA4 also used by SPI1/NSS1 + Pin 7 PA5 also used by SPI1/SCK1 + Pin 9 PA6 also used by SPI1/MOSI1 and LED1 + + J18 lower row conflicts: + + Pin 6 PC5 also used by Ethernet and the LCD interface + Pin 8 PA1 also used by Ethernet + Pin 10 PA0 also used by Ethernet and Wake-up button (not used) + + Remapped SPI1 pins are not supported, but that would permit these options: + + PA15/NSS1 also used by LCD + PB3/SCK1 also used by USART1 and JTAG + PB4/MISO1 also used by JTAG + PB5/MOSI1 also used by USART1, Ethernet, and J28 pin 10 + Toolchains ========== @@ -587,11 +707,17 @@ Configurations 5. These configurations all assume that you are loading code using something like the ST-Link v2 JTAG. None of these configurations are setup to use the DFU bootloader but should be easily reconfigured to - use that bootloader is so desired. + use that bootloader if so desired. Configuration Sub-directories ----------------------------- + f80x: + + This configuration was added in order to verify the FTDI/Bridgetick + Ft80x driver. At this point, I have no hardware in that. So this + configuration is totally unverified. + netnsh: This configuration directory provide the NuttShell (NSH) with diff --git a/configs/viewtool-stm32f107/ft80x/defconfig b/configs/viewtool-stm32f107/ft80x/defconfig new file mode 100644 index 00000000000..3b14136e5e0 --- /dev/null +++ b/configs/viewtool-stm32f107/ft80x/defconfig @@ -0,0 +1,44 @@ +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +CONFIG_ARCH_BOARD_VIEWTOOL_STM32F107=y +CONFIG_ARCH_BOARD="viewtool-stm32f107" +CONFIG_ARCH_BUTTONS=y +CONFIG_ARCH_CHIP_STM32=y +CONFIG_ARCH_CHIP_STM32F107VC=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARCH="arm" +CONFIG_BOARD_LOOPSPERMSEC=5483 +CONFIG_BUILTIN=y +CONFIG_EXAMPLES_FT80X=y +CONFIG_EXAMPLES_NSH=y +CONFIG_EXPERIMENTAL=y +CONFIG_FS_PROCFS=y +CONFIG_HOST_WINDOWS=y +CONFIG_INTELHEX_BINARY=y +CONFIG_LCD_FT80X=y +CONFIG_LCD=y +CONFIG_MAX_TASKS=16 +CONFIG_MAX_WDOGPARMS=2 +CONFIG_NFILE_DESCRIPTORS=8 +CONFIG_NFILE_STREAMS=8 +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_READLINE=y +CONFIG_PREALLOC_MQ_MSGS=4 +CONFIG_PREALLOC_TIMERS=4 +CONFIG_PREALLOC_WDOGS=8 +CONFIG_RAM_SIZE=65536 +CONFIG_RAM_START=0x20000000 +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_HPWORKPRIORITY=192 +CONFIG_SCHED_HPWORKSTACKSIZE=1024 +CONFIG_SCHED_WAITPID=y +CONFIG_SDCLONE_DISABLE=y +CONFIG_START_DAY=24 +CONFIG_START_MONTH=2 +CONFIG_STM32_JTAG_FULL_ENABLE=y +CONFIG_STM32_PWR=y +CONFIG_STM32_SPI1=y +CONFIG_STM32_USART1=y +CONFIG_USART1_SERIAL_CONSOLE=y +CONFIG_USER_ENTRYPOINT="nsh_main" +CONFIG_WDOG_INTRESERVE=0 diff --git a/configs/viewtool-stm32f107/include/board-stm32f107vct6.h b/configs/viewtool-stm32f107/include/board-stm32f107vct6.h index 7f5088f2c12..3e368cbdb9a 100644 --- a/configs/viewtool-stm32f107/include/board-stm32f107vct6.h +++ b/configs/viewtool-stm32f107/include/board-stm32f107vct6.h @@ -117,7 +117,7 @@ * * STM32_PLL_PREDIV2 = 5, 25MHz / 5 => 5MHz * - * NOTE: The Viewtool DP83848C module has its on, on-board 50MHz clock. No + * NOTE: The Viewtool DP83848C module has its own, on-board 50MHz clock. No * MCO clock need be provided on that board. */ diff --git a/configs/viewtool-stm32f107/nsh/defconfig b/configs/viewtool-stm32f107/nsh/defconfig index 5743226a8b1..c0b4eb7dd38 100644 --- a/configs/viewtool-stm32f107/nsh/defconfig +++ b/configs/viewtool-stm32f107/nsh/defconfig @@ -13,6 +13,7 @@ CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y CONFIG_BOARD_LOOPSPERMSEC=5483 CONFIG_BUILTIN=y CONFIG_EXAMPLES_NSH=y +CONFIG_FS_PROCFS=y CONFIG_HOST_WINDOWS=y CONFIG_INTELHEX_BINARY=y CONFIG_MAX_TASKS=16 diff --git a/configs/viewtool-stm32f107/src/Makefile b/configs/viewtool-stm32f107/src/Makefile index c90e9df6205..a7c0dc2e2e4 100644 --- a/configs/viewtool-stm32f107/src/Makefile +++ b/configs/viewtool-stm32f107/src/Makefile @@ -1,7 +1,7 @@ ############################################################################ # configs/viewtool-stm32f107/src/Makefile # -# Copyright (C) 2013, 2017 Gregory Nutt. All rights reserved. +# Copyright (C) 2013, 2017-2018 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -59,7 +59,7 @@ CSRCS += stm32_mpl115a.c endif ifeq ($(CONFIG_INPUT_ADS7843E),y) # F103 -CSRCS += stm32_touchscreen.c +CSRCS += stm32_ads7843e.c endif ifeq ($(CONFIG_LCD_SSD1289),y) # F103 @@ -82,4 +82,10 @@ ifeq ($(CONFIG_VIEWTOOL_HIGHPRI),y) CSRCS += stm32_highpri.c endif +ifeq ($(CONFIG_VIEWTOOL_FT80X_SPI1),y) +CSRCS += stm32_ft80x.c +else ifeq ($(CONFIG_VIEWTOOL_FT80X_SPI2),y) +CSRCS += stm32_ft80x.c +endif + include $(TOPDIR)/configs/Board.mk diff --git a/configs/viewtool-stm32f107/src/stm32_touchscreen.c b/configs/viewtool-stm32f107/src/stm32_ads7843e.c similarity index 99% rename from configs/viewtool-stm32f107/src/stm32_touchscreen.c rename to configs/viewtool-stm32f107/src/stm32_ads7843e.c index 39130e78932..448f1ca6b31 100644 --- a/configs/viewtool-stm32f107/src/stm32_touchscreen.c +++ b/configs/viewtool-stm32f107/src/stm32_ads7843e.c @@ -1,5 +1,5 @@ /************************************************************************************ - * configs/viewtools-stm32f107/src/stm32_touchscreen.c + * configs/viewtools-stm32f107/src/stm32_ads7843e.c * * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/configs/viewtool-stm32f107/src/stm32_bringup.c b/configs/viewtool-stm32f107/src/stm32_bringup.c index 97ca12b9861..80937135873 100644 --- a/configs/viewtool-stm32f107/src/stm32_bringup.c +++ b/configs/viewtool-stm32f107/src/stm32_bringup.c @@ -193,6 +193,14 @@ int stm32_bringup(void) } #endif +#if defined(CONFIG_VIEWTOOL_FT80X_SPI1) || defined(CONFIG_VIEWTOOL_FT80X_SPI2) + ret = stm32_ft80x_setup(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: stm32_ft80x_setup failed: %d\n", ret); + } +#endif + UNUSED(ret); return OK; } diff --git a/configs/viewtool-stm32f107/src/stm32_ft80x.c b/configs/viewtool-stm32f107/src/stm32_ft80x.c new file mode 100644 index 00000000000..f684a132328 --- /dev/null +++ b/configs/viewtool-stm32f107/src/stm32_ft80x.c @@ -0,0 +1,305 @@ +/************************************************************************************ + * configs/viewtools-stm32f107/src/stm32_ft80x.c + * + * Copyright (C) 2018 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 + +#include "up_arch.h" +#include "stm32_gpio.h" +#include "stm32_spi.h" + +#include "viewtool_stm32f107.h" + +#if defined(CONFIG_VIEWTOOL_FT80X_SPI1) || defined(CONFIG_VIEWTOOL_FT80X_SPI2) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct viewtool_ft80xlower_s +{ + /* Standard FT80x interface */ + + struct ft80x_config_s config; + + /* Extensions for the viewtool board */ + + xcpt_t handler; + FAR void *arg; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* IRQ/GPIO access callbacks. These operations all hidden behind callbacks + * to isolate the FT80X driver from differences in GPIO interrupt handling + * by varying boards and MCUs. + * + * Interrupts should be configured on the falling edge of nINT. + * + * attach - Attach the ADS7843E interrupt handler to the GPIO interrupt + * enable - Enable or disable the GPIO interrupt + * clear - Acknowledge/clear any pending GPIO interrupt as necessary. + * pwrdown - Power the FT80X up or down. + * audio - Enable audio (i.e., set the external audio amplifier shutdown + * pin to the appropriate level to enable or disable the + * external audio amplifier) + * destroy - The driver has been unlinked. Cleanup as necessary. + */ + +static int ft80x_attach(FAR const struct ft80x_config_s *lower, xcpt_t isr, + FAR void *arg); +static void ft80x_enable(FAR const struct ft80x_config_s *lower, bool enable); +static void ft80x_clear(FAR const struct ft80x_config_s *lower); + +static void ft80x_pwrdown(FAR const struct ft80x_config_s *lower, + bool pwrdown); +static void ft80x_audio(FAR const struct ft80x_config_s *lower, bool enable); +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS +static void ft80x_destroy(FAR const struct ft80x_config_s *lower); +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* A reference to a structure of this type must be passed to the FT80x + * driver. This structure provides information about the configuration + * of the FT80x 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_ft80xlower_s g_ft80xlower = +{ + .config = + { + .init_frequency = CONFIG_VIEWTOOL_FT80X_INITFREQUENCY, + .op_frequency = CONFIG_VIEWTOOL_FT80X_OPFREQUENCY, + + .attach = ft80x_attach, + .enable = ft80x_enable, + .clear = ft80x_clear, + .pwrdown = ft80x_pwrdown, + .audio = ft80x_audio, +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + .destroy = ft80x_destroy, +#endif + }, +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * IRQ/GPIO access callbacks. These operations all hidden behind + * callbacks to isolate the FT80x 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 as necessary. + * pwrdown - Power the FT80X up or down. + * audio - Enable audio (i.e., set the external audio amplifier shutdown + * pin to the appropriate level to enable or disable the + * external audio amplifier) + * destroy - The driver has been unlinked. Cleanup as necessary. + * + ****************************************************************************/ + +static int ft80x_attach(FAR const struct ft80x_config_s *lower, xcpt_t isr, + FAR void *arg) +{ + FAR struct viewtool_ft80xlower_s *priv = + (FAR struct viewtool_ft80xlower_s *)lower; + + if (isr) + { + /* Just save the address of the handler for now. The new handler will + * be attached when the interrupt is next enabled. + */ + + iinfo("Attaching %p\n", isr); + priv->handler = isr; + priv->arg = arg; + } + else + { + iinfo("Detaching %p\n", priv->handler); + ft80x_enable(lower, false); + priv->handler = NULL; + priv->arg = NULL; + } + + return OK; +} + +static void ft80x_enable(FAR const struct ft80x_config_s *lower, + bool enable) +{ + FAR struct viewtool_ft80xlower_s *priv = + (FAR struct viewtool_ft80xlower_s *)lower; + 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 = enter_critical_section(); + if (enable && priv->handler) + { + /* Configure the EXTI interrupt using the SAVED handler */ + + (void)stm32_gpiosetevent(GPIO_LCDTP_IRQ, true, true, true, + priv->handler, priv->arg); + } + else + { + /* Configure the EXTI interrupt with a NULL handler to disable it. + * + * REVISIT: There is a problem here... interrupts received while + * the EXIT is de-configured will not pend but will be lost. + */ + + (void)stm32_gpiosetevent(GPIO_LCDTP_IRQ, false, false, false, + NULL, NULL); + } + + leave_critical_section(flags); +} + +static void ft80x_clear(FAR const struct ft80x_config_s *lower) +{ + /* Does nothing */ +} + +static void ft80x_pwrdown(FAR const struct ft80x_config_s *lower, + bool pwrdown) +{ + /* Powerdown pin is active low */ + + stm32_gpiowrite(GPIO_FT80_PD, !pwrdown); +} + +static void ft80x_audio(FAR const struct ft80x_config_s *lower, bool enable) +{ + /* Does nothing */ +} + +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS +static void ft80x_destroy(FAR const struct ft80x_config_s *lower) +{ + /* Does nothing */ +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_ft80x_setup + * + * Description: + * This function is called by board-bringup logic to configure the + * touchscreen device. This function will register the driver as + * /dev/inputN where N is the minor device number. + * + * Input Parameters: + * None + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int stm32_ft80x_setup(void) +{ + FAR struct spi_dev_s *spi; + int ret; + + /* Configure the FT80x interrupt pin as an input and powerdown pin as an + * output. Device is initially powered down. + */ + + (void)stm32_configgpio(GPIO_FT80X_INT); + (void)stm32_configgpio(GPIO_FT80_PD); + + /* Get an instance of the SPI interface for the touchscreen chip select */ + + spi = stm32_spibus_initialize(FT80X_SPIBUS); + if (!spi) + { + lcderr("ERROR: Failed to initialize SPI%d\n", FT80X_SPIBUS); + return -ENODEV; + } + + /* Initialize and register the SPI touchscreen device */ + + ret = ft80x_register(spi, &g_ft80xlower.config); + if (ret < 0) + { + lcderr("ERROR: Failed to register touchscreen device\n"); + /* up_spiuninitialize(spi); */ + return -ENODEV; + } + + return OK; +} + +#endif /* CONFIG_VIEWTOOL_FT80X_SPI1 || CONFIG_VIEWTOOL_FT80X_SPI2 */ diff --git a/configs/viewtool-stm32f107/src/stm32_spi.c b/configs/viewtool-stm32f107/src/stm32_spi.c index 24b79f79d0f..11441679379 100644 --- a/configs/viewtool-stm32f107/src/stm32_spi.c +++ b/configs/viewtool-stm32f107/src/stm32_spi.c @@ -85,6 +85,12 @@ void weak_function stm32_spidev_initialize(void) (void)stm32_configgpio(GPIO_MPL115A_CS); #endif + +#if defined(CONFIG_VIEWTOOL_FT80X_SPI1) || defined(CONFIG_VIEWTOOL_FT80X_SPI2) + /* Configure the FT80x CS pin as an input */ + + (void)stm32_configgpio(GPIO_FT80X_CS); +#endif } /**************************************************************************** @@ -116,6 +122,19 @@ void weak_function stm32_spidev_initialize(void) void stm32_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected) { spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert"); + +#ifdef CONFIG_VIEWTOOL_FT80X_SPI1 + /* Select/de-select the FT80x */ + + if (devid == SPIDEV_DISPLAY(0)) + { + stm32_gpiowrite(GPIO_FT80X_CS, !selected); + } + else +#endif + { + spierr("ERROR: Unrecognized devid: %08lx\n", (unsigned long)devid); + } } uint8_t stm32_spi1status(FAR struct spi_dev_s *dev, uint32_t devid) @@ -136,7 +155,20 @@ void stm32_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected) { stm32_gpiowrite(GPIO_LCDTP_CS, !selected); } + else #endif +#ifdef CONFIG_VIEWTOOL_FT80X_SPI2 + /* Select/de-select the FT80x */ + + if (devid == SPIDEV_DISPLAY(0)) + { + stm32_gpiowrite(GPIO_FT80X_CS, !selected); + } + else +#endif + { + spierr("ERROR: Unrecognized devid: %08lx\n", (unsigned long)devid); + } } uint8_t stm32_spi2status(FAR struct spi_dev_s *dev, uint32_t devid) diff --git a/configs/viewtool-stm32f107/src/viewtool_stm32f107.h b/configs/viewtool-stm32f107/src/viewtool_stm32f107.h index 7aaa0f01146..f7e1e1f5246 100644 --- a/configs/viewtool-stm32f107/src/viewtool_stm32f107.h +++ b/configs/viewtool-stm32f107/src/viewtool_stm32f107.h @@ -130,7 +130,6 @@ #define GPIO_LED4 (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz|\ GPIO_OUTPUT_SET | GPIO_PORTB | GPIO_PIN13) - /* Buttons ******************************************************************/ /* All pulled high and will be sensed low when depressed. * @@ -302,6 +301,31 @@ #define GPIO_MPL115A_CS (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz | \ GPIO_OUTPUT_SET | GPIO_PORTB | GPIO_PIN6) +/* FT80x GUI Discrete I/O (See README.txt for details): + * + * ------ ----------- -------------------- + * NAME VIEWTOOL STM32 + * ------ ----------- -------------------- + * CS# J8 Pin 12 PA4/NSS1 (For SPI1) + * CS# J8 Pin 6 PB12/NSS2 (For SPI2) + * INT# J18 Pin 8 PA1 + * PD# J18 Pin 6 PC5 + */ + +#if defined(CONFIG_VIEWTOOL_FT80X_SPI1) +# define FT80X_SPIBUS 1 +# define GPIO_FT80X_CS (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz | \ + GPIO_OUTPUT_SET | GPIO_PORTA | GPIO_PIN4) +#elif defined(CONFIG_VIEWTOOL_FT80X_SPI2) +# define FT80X_SPIBUS 2 +# define GPIO_FT80X_CS (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz | \ + GPIO_OUTPUT_SET | GPIO_PORTB | GPIO_PIN12) +#endif +#define GPIO_FT80X_INT (GPIO_INPUT | GPIO_CNF_INFLOAT | GPIO_MODE_INPUT | \ + GPIO_EXTI | GPIO_PORTA | GPIO_PIN1) +#define GPIO_FT80_PD (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz | \ + GPIO_OUTPUT_CLEAR | GPIO_PORTC| GPIO_PIN5) + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -419,5 +443,26 @@ int stm32_can_setup(void); int stm32_mpl115ainitialize(FAR const char *devpath); #endif +/**************************************************************************** + * Name: stm32_ft80x_setup + * + * Description: + * This function is called by board-bringup logic to configure the + * touchscreen device. This function will register the driver as + * /dev/inputN where N is the minor device number. + * + * Input Parameters: + * None + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +#if defined(CONFIG_VIEWTOOL_FT80X_SPI1) || defined(CONFIG_VIEWTOOL_FT80X_SPI2) +int stm32_ft80x_setup(void); +#endif + #endif /* __ASSEMBLY__ */ #endif /* __CONFIGS_VIEWTOOL_STM32F107_SRC_H */ diff --git a/drivers/lcd/ft80x_spi.c b/drivers/lcd/ft80x_spi.c index e0a4e0a285a..47193a40597 100644 --- a/drivers/lcd/ft80x_spi.c +++ b/drivers/lcd/ft80x_spi.c @@ -64,8 +64,7 @@ static void ft80x_select(FAR struct ft80x_dev_s *priv) { - lcdinfo("Mode: %d Bits: 8 Frequency: %d\n", - CONFIG_FT80X_SPIMODE, CONFIG_FT80X_FREQUENCY); + lcdinfo("Mode: %d Bits: 8 Frequency: %d\n", SPIDEV_MODE0, priv->frequency); DEBUGASSERT(priv != NULL); diff --git a/include/nuttx/lcd/ft80x.h b/include/nuttx/lcd/ft80x.h index 8d7a9156e72..604d646e2e1 100644 --- a/include/nuttx/lcd/ft80x.h +++ b/include/nuttx/lcd/ft80x.h @@ -828,7 +828,7 @@ * In addition, if there is a audio amplifier on board (such as TPA6205A or LM4864), then * there may also be an active low audio shutdown output: * - * N/A O nSHDN Audio shutdown (active los) + * N/A O nSHDN Audio shutdown (active low) * * SCL/SDA, SCLK/MISO/MOSI/nCS are handled by generic I2C or SPI logic. nInt and nPD are * directly managed by this interface. @@ -869,8 +869,8 @@ struct ft80x_config_s FAR void *arg); CODE void (*enable)(FAR const struct ft80x_config_s *lower, bool enable); CODE void (*clear)(FAR const struct ft80x_config_s *lower); - CODE bool (*pwrdown)(FAR const struct ft80x_config_s *lower, bool pwrdown); - CODE bool (*audio)(FAR const struct ft80x_config_s *lower, bool enable); + CODE void (*pwrdown)(FAR const struct ft80x_config_s *lower, bool pwrdown); + CODE void (*audio)(FAR const struct ft80x_config_s *lower, bool enable); #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS CODE void (*destroy)(FAR const struct ft80x_config_s *lower); #endif