From 1502693f938c492c5a4c54fe75a877ff8499df38 Mon Sep 17 00:00:00 2001 From: Michal Lenc Date: Tue, 22 Dec 2020 18:53:36 +0100 Subject: [PATCH] boards/arm/imxrt/teensy-4.x: Added support for LCD display with ST7789 Signed-off-by: Michal Lenc --- .../teensy-4.x/configs/lcd-4.1/defconfig | 61 +++++++++ boards/arm/imxrt/teensy-4.x/src/Makefile | 4 + boards/arm/imxrt/teensy-4.x/src/imxrt_spi.c | 22 ++- .../arm/imxrt/teensy-4.x/src/imxrt_st7789.c | 125 ++++++++++++++++++ boards/arm/imxrt/teensy-4.x/src/teensy-4.h | 8 ++ 5 files changed, 214 insertions(+), 6 deletions(-) create mode 100644 boards/arm/imxrt/teensy-4.x/configs/lcd-4.1/defconfig create mode 100644 boards/arm/imxrt/teensy-4.x/src/imxrt_st7789.c diff --git a/boards/arm/imxrt/teensy-4.x/configs/lcd-4.1/defconfig b/boards/arm/imxrt/teensy-4.x/configs/lcd-4.1/defconfig new file mode 100644 index 0000000000..89ba71806f --- /dev/null +++ b/boards/arm/imxrt/teensy-4.x/configs/lcd-4.1/defconfig @@ -0,0 +1,61 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="teensy-4.x" +CONFIG_ARCH_BOARD_TEENSY_4X=y +CONFIG_ARCH_CHIP="imxrt" +CONFIG_ARCH_CHIP_IMXRT=y +CONFIG_ARCH_CHIP_MIMXRT1062DVL6A=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARMV7M_DCACHE=y +CONFIG_ARMV7M_DCACHE_WRITETHROUGH=y +CONFIG_ARMV7M_ICACHE=y +CONFIG_ARMV7M_USEBASEPRI=y +CONFIG_BOARD_LOOPSPERMSEC=104926 +CONFIG_BUILTIN=y +CONFIG_CDCACM=y +CONFIG_CDCACM_CONSOLE=y +CONFIG_DRIVERS_VIDEO=y +CONFIG_EXAMPLES_FB=y +CONFIG_FS_PROCFS=y +CONFIG_IDLETHREAD_STACKSIZE=2048 +CONFIG_IMXRT_LPSPI4=y +CONFIG_IMXRT_LPUART1=y +CONFIG_IMXRT_USBDEV=y +CONFIG_INTELHEX_BINARY=y +CONFIG_LCD=y +CONFIG_LCD_FRAMEBUFFER=y +CONFIG_LCD_PORTRAIT=y +CONFIG_LCD_ST7789=y +CONFIG_MAX_TASKS=16 +CONFIG_NFILE_DESCRIPTORS=8 +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_DISABLE_IFUPDOWN=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_READLINE=y +CONFIG_NSH_USBCONSOLE=y +CONFIG_NXFONTS_DISABLE_16BPP=y +CONFIG_NXFONTS_DISABLE_1BPP=y +CONFIG_NXFONTS_DISABLE_24BPP=y +CONFIG_NXFONTS_DISABLE_2BPP=y +CONFIG_NXFONTS_DISABLE_32BPP=y +CONFIG_NXFONTS_DISABLE_4BPP=y +CONFIG_NXFONTS_DISABLE_8BPP=y +CONFIG_RAM_SIZE=1048576 +CONFIG_RAM_START=0x20200000 +CONFIG_SPI=y +CONFIG_SPI_CMDDATA=y +CONFIG_START_DAY=14 +CONFIG_START_MONTH=3 +CONFIG_SYSTEM_NSH=y +CONFIG_TEENSY_41=y +CONFIG_USBDEV=y +CONFIG_USER_ENTRYPOINT="nsh_main" +CONFIG_VIDEO_FB=y diff --git a/boards/arm/imxrt/teensy-4.x/src/Makefile b/boards/arm/imxrt/teensy-4.x/src/Makefile index 5de101bd87..6e820fd8c2 100644 --- a/boards/arm/imxrt/teensy-4.x/src/Makefile +++ b/boards/arm/imxrt/teensy-4.x/src/Makefile @@ -54,4 +54,8 @@ ifeq ($(CONFIG_IMXRT_ADC),y) CSRCS += imxrt_adc.c endif +ifeq ($(CONFIG_LCD_ST7789),y) +CSRCS += imxrt_st7789.c +endif + include $(TOPDIR)/boards/Board.mk diff --git a/boards/arm/imxrt/teensy-4.x/src/imxrt_spi.c b/boards/arm/imxrt/teensy-4.x/src/imxrt_spi.c index ed02f5f8a3..44a2c800e1 100644 --- a/boards/arm/imxrt/teensy-4.x/src/imxrt_spi.c +++ b/boards/arm/imxrt/teensy-4.x/src/imxrt_spi.c @@ -34,7 +34,6 @@ #include "arm_arch.h" -#include "imxrt_config.h" #include "imxrt_lpspi.h" #include "imxrt_gpio.h" #include "teensy-4.h" @@ -62,6 +61,7 @@ void weak_function imxrt_spidev_initialize(void) #endif #ifdef CONFIG_IMXRT_LPSPI4 imxrt_config_gpio(GPIO_LPSPI4_CS); /* LPSPI4 chip select */ + imxrt_config_gpio(GPIO_LCD_CD); #endif } @@ -144,10 +144,12 @@ uint8_t imxrt_lpspi3status(FAR struct spi_dev_s *dev, uint32_t devid) void imxrt_lpspi4select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected) { - spiinfo("devid: %d CS: %s\n", (int)devid, - selected ? "assert" : "de-assert"); - - imxrt_gpio_write(GPIO_LPSPI4_CS, !selected); + spiinfo("devid: %d CS: %s\n", (int)devid, + selected ? "assert" : "de-assert"); + if (devid == SPIDEV_DISPLAY(0)) + { + imxrt_gpio_write(GPIO_LPSPI4_CS, !selected); + } } uint8_t imxrt_lpspi4status(FAR struct spi_dev_s *dev, uint32_t devid) @@ -204,7 +206,15 @@ int imxrt_lpspi3cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd) #ifdef CONFIG_IMXRT_LPSPI4 int imxrt_lpspi4cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd) { - return -ENODEV; + if (devid == SPIDEV_DISPLAY(0)) + { + imxrt_gpio_write(GPIO_LCD_CD, !cmd); + return OK; + } + else + { + return -ENODEV; + } } #endif #endif /* CONFIG_SPI_CMDDATA */ diff --git a/boards/arm/imxrt/teensy-4.x/src/imxrt_st7789.c b/boards/arm/imxrt/teensy-4.x/src/imxrt_st7789.c new file mode 100644 index 0000000000..5574738e67 --- /dev/null +++ b/boards/arm/imxrt/teensy-4.x/src/imxrt_st7789.c @@ -0,0 +1,125 @@ +/**************************************************************************** + * boards/arm/imxrt/teensy-4.x/src/imxrt_st7789.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "imxrt_lpspi.h" +#include "teensy-4.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define LCD_SPI_PORTNO 4 + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct spi_dev_s *g_spidev; +static struct lcd_dev_s *g_lcd = NULL; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_lcd_initialize + * + * Description: + * Initialize the LCD video hardware. The initial state of the LCD is + * fully initialized, display memory cleared, and the LCD ready to use, but + * with the power setting at 0 (full off). + * + ****************************************************************************/ + +int board_lcd_initialize(void) +{ + imxrt_config_gpio(GPIO_LCD_RST); + + g_spidev = imxrt_lpspibus_initialize(LCD_SPI_PORTNO); + if (!g_spidev) + { + lcderr("ERROR: Failed to initialize SPI port %d\n", LCD_SPI_PORTNO); + return -ENODEV; + } + + imxrt_gpio_write(GPIO_LCD_RST, 0); + up_mdelay(1); + imxrt_gpio_write(GPIO_LCD_RST, 1); + up_mdelay(120); + + return OK; +} + +/**************************************************************************** + * Name: board_lcd_getdev + * + * Description: + * Return a a reference to the LCD object for the specified LCD. This + * allows support for multiple LCD devices. + * + ****************************************************************************/ + +FAR struct lcd_dev_s *board_lcd_getdev(int devno) +{ + g_lcd = st7789_lcdinitialize(g_spidev); + if (!g_lcd) + { + lcderr("ERROR: Failed to bind SPI port 4 to LCD %d\n", devno); + } + else + { + lcdinfo("SPI port 4 bound to LCD %d\n", devno); + return g_lcd; + } + + return NULL; +} + +/**************************************************************************** + * Name: board_lcd_uninitialize + * + * Description: + * Uninitialize the LCD support + * + ****************************************************************************/ + +void board_lcd_uninitialize(void) +{ + /* Turn the display off */ + + g_lcd->setpower(g_lcd, 0); +} diff --git a/boards/arm/imxrt/teensy-4.x/src/teensy-4.h b/boards/arm/imxrt/teensy-4.x/src/teensy-4.h index 186c76206b..b768ff1a30 100644 --- a/boards/arm/imxrt/teensy-4.x/src/teensy-4.h +++ b/boards/arm/imxrt/teensy-4.x/src/teensy-4.h @@ -79,6 +79,14 @@ # define GPIO_LPSPI4_CS (GPIO_OUTPUT | GPIO_OUTPUT_ONE | \ GPIO_PORT2 | GPIO_PIN0 | IOMUX_LPSPI4_CS) +/* LCD dispay */ + +# define GPIO_LCD_RST (GPIO_OUTPUT | GPIO_OUTPUT_ONE | \ + GPIO_PORT2 | GPIO_PIN18 | IOMUX_LPSPI4_CS) /* B1_02 */ + +# define GPIO_LCD_CD (GPIO_OUTPUT | GPIO_OUTPUT_ONE | \ + GPIO_PORT2 | GPIO_PIN19 | IOMUX_LPSPI4_CS) /* B1_03 */ + /* USB OTG ID Pin: GPIO_AD_B1_02 */ #define GPIO_USBOTG_ID (GPIO_USB_OTG1_ID_1 | IOMUX_USBOTG_ID_DEFAULT) /* AD_B1_02 */