This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit effab1bd61f5a35f76f78150e16a2f6dc7e90b23 Author: Marco Casaroli <marco.casar...@gmail.com> AuthorDate: Tue Oct 10 10:59:50 2023 +0000 feat(esp32s3-eye): SPI and LCD LCD is connected to SPI2 and uses DC signalling. --- boards/xtensa/esp32s3/esp32s3-eye/Kconfig | 11 ++ boards/xtensa/esp32s3/esp32s3-eye/src/Make.defs | 8 ++ .../xtensa/esp32s3/esp32s3-eye/src/esp32s3-eye.h | 44 +++++++ .../src/{esp32s3-eye.h => esp32s3_board_lcd.c} | 140 +++++++++++++-------- .../src/{esp32s3-eye.h => esp32s3_board_spi.c} | 137 ++++++++++---------- .../esp32s3/esp32s3-eye/src/esp32s3_bringup.c | 35 ++++++ 6 files changed, 259 insertions(+), 116 deletions(-) diff --git a/boards/xtensa/esp32s3/esp32s3-eye/Kconfig b/boards/xtensa/esp32s3/esp32s3-eye/Kconfig index e955d65e3a..d533243d3e 100644 --- a/boards/xtensa/esp32s3/esp32s3-eye/Kconfig +++ b/boards/xtensa/esp32s3/esp32s3-eye/Kconfig @@ -48,4 +48,15 @@ config ESP32S3_SPIFLASH_LITTLEFS endchoice +config ESP32S3_EYE_LCD + bool "Enable ESP32-S3 LCD" + default n + select ESP32S3_SPI2 + select SPI_CMDDATA + select LCD + select LCD_DEV + select LCD_ST7789 + ---help--- + Enable board LCD support, IC is LCD_ST7789V. + endif # ARCH_BOARD_ESP32S3_EYE diff --git a/boards/xtensa/esp32s3/esp32s3-eye/src/Make.defs b/boards/xtensa/esp32s3/esp32s3-eye/src/Make.defs index 73d208e58e..d64e14030d 100644 --- a/boards/xtensa/esp32s3/esp32s3-eye/src/Make.defs +++ b/boards/xtensa/esp32s3/esp32s3-eye/src/Make.defs @@ -37,6 +37,14 @@ ifeq ($(CONFIG_DEV_GPIO),y) CSRCS += esp32s3_gpio.c endif +ifeq ($(CONFIG_ESP32S3_SPI),y) +CSRCS += esp32s3_board_spi.c +endif + +ifeq ($(CONFIG_ESP32S3_EYE_LCD),y) +CSRCS += esp32s3_board_lcd.c +endif + DEPPATH += --dep-path board VPATH += :board CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board diff --git a/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3-eye.h b/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3-eye.h index 2b0d143a43..6c89e6cc24 100644 --- a/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3-eye.h +++ b/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3-eye.h @@ -38,6 +38,11 @@ /* BOOT Button */ #define BUTTON_BOOT 0 +/* Display */ + +#define ESP32S3_EYE_DISPLAY_SPI 2 +#define ESP32S3_EYE_DISPLAY_DC 43 +#define ESP32S3_EYE_DISPLAY_BCKL 48 /**************************************************************************** * Public Types @@ -97,6 +102,45 @@ int esp32s3_gpio_init(void); int board_spiflash_init(void); #endif +/**************************************************************************** + * 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). + * + ****************************************************************************/ + +#ifdef CONFIG_ESP32S3_EYE_LCD +int board_lcd_initialize(void); +#endif + +/**************************************************************************** + * Name: board_lcd_getdev + * + * Description: + * Return a reference to the LCD object for the specified LCD. This allows + * support for multiple LCD devices. + * + ****************************************************************************/ + +#ifdef CONFIG_ESP32S3_EYE_LCD +struct lcd_dev_s *board_lcd_getdev(int lcddev); +#endif + +/**************************************************************************** + * Name: board_lcd_uninitialize + * + * Description: + * Uninitialize the LCD support. + * + ****************************************************************************/ + +#ifdef CONFIG_ESP32S3_EYE_LCD +void board_lcd_uninitialize(void); +#endif + /**************************************************************************** * Name: board_i2c_init * diff --git a/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3-eye.h b/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_board_lcd.c similarity index 50% copy from boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3-eye.h copy to boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_board_lcd.c index 2b0d143a43..e7d5eedc68 100644 --- a/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3-eye.h +++ b/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_board_lcd.c @@ -1,5 +1,5 @@ /**************************************************************************** - * boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3-eye.h + * boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_board_lcd.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -18,100 +18,136 @@ * ****************************************************************************/ -#ifndef __BOARDS_XTENSA_ESP32S3_ESP32S3_EYE_SRC_ESP32S3_EYE_H -#define __BOARDS_XTENSA_ESP32S3_ESP32S3_EYE_SRC_ESP32S3_EYE_H - /**************************************************************************** * Included Files ****************************************************************************/ #include <nuttx/config.h> -#include <nuttx/compiler.h> -#include <stdint.h> -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ +#include <stdio.h> +#include <stdbool.h> +#include <debug.h> +#include <errno.h> + +#include <nuttx/arch.h> +#include <nuttx/board.h> +#include <nuttx/signal.h> +#include <nuttx/spi/spi.h> +#include <nuttx/lcd/lcd.h> +#include <nuttx/lcd/st7789.h> -/* ESP32-S3-EYE GPIOs *******************************************************/ +#include <arch/board/board.h> -/* BOOT Button */ +#include "esp32s3_gpio.h" +#include "esp32s3_spi.h" +#include "hardware/esp32s3_gpio_sigmap.h" -#define BUTTON_BOOT 0 +#include "esp32s3-eye.h" /**************************************************************************** - * Public Types + * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** - * Public Data + * Private Data ****************************************************************************/ -#ifndef __ASSEMBLY__ +static struct spi_dev_s *g_spidev; +static struct lcd_dev_s *g_lcd; /**************************************************************************** - * Public Function Prototypes + * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: esp32s3_bringup + * Name: board_lcd_initialize * * Description: - * Perform architecture-specific initialization + * 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). * - * CONFIG_BOARD_LATE_INITIALIZE=y : - * Called from board_late_initialize(). - * - * CONFIG_BOARD_LATE_INITIALIZE=y && CONFIG_BOARDCTL=y : - * Called from the NSH library via board_app_initialize() + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. * ****************************************************************************/ -int esp32s3_bringup(void); +int board_lcd_initialize(void) +{ + /* Initialize non-SPI GPIOs */ -/**************************************************************************** - * Name: esp32s3_gpio_init - * - * Description: - * Configure the GPIO driver. - * - * Returned Value: - * Zero (OK) is returned on success; A negated errno value is returned - * to indicate the nature of any failure. - * - ****************************************************************************/ + esp32s3_configgpio(ESP32S3_EYE_DISPLAY_DC, OUTPUT); + esp32s3_configgpio(ESP32S3_EYE_DISPLAY_BCKL, OUTPUT); + + /* Turn on LCD backlight */ + + esp32s3_gpiowrite(ESP32S3_EYE_DISPLAY_BCKL, false); -#ifdef CONFIG_DEV_GPIO -int esp32s3_gpio_init(void); -#endif + g_spidev = esp32s3_spibus_initialize(ESP32S3_EYE_DISPLAY_SPI); + if (!g_spidev) + { + lcderr("ERROR: Failed to initialize SPI port %d\n", + ESP32S3_EYE_DISPLAY_SPI); + return -ENODEV; + } + + g_lcd = st7789_lcdinitialize(g_spidev); + if (!g_lcd) + { + lcderr("ERROR: st7789_lcdinitialize() failed\n"); + return -ENODEV; + } + + return OK; +} /**************************************************************************** - * Name: board_spiflash_init + * Name: board_lcd_getdev * * Description: - * Initialize the SPIFLASH and register the MTD device. + * Return a a reference to the LCD object for the specified LCD. This + * allows support for multiple LCD devices. + * + * Input Parameters: + * devno - LCD device nmber + * + * Returned Value: + * LCD device pointer if success or NULL if failed. * ****************************************************************************/ -#ifdef CONFIG_ESP32S3_SPIFLASH -int board_spiflash_init(void); -#endif +struct lcd_dev_s *board_lcd_getdev(int devno) +{ + if (!g_lcd) + { + lcderr("ERROR: Failed to bind SPI port %d to LCD %d\n", + ESP32S3_EYE_DISPLAY_SPI, devno); + } + else + { + lcdinfo("SPI port %d bound to LCD %d\n", + ESP32S3_EYE_DISPLAY_SPI, + devno); + return g_lcd; + } + + return NULL; +} /**************************************************************************** - * Name: board_i2c_init + * Name: board_lcd_uninitialize * * Description: - * Configure the I2C driver. + * Uninitialize the LCD support * * Returned Value: - * Zero (OK) is returned on success; A negated errno value is returned - * to indicate the nature of any failure. + * None * ****************************************************************************/ -#ifdef CONFIG_I2C_DRIVER -int board_i2c_init(void); -#endif +void board_lcd_uninitialize(void) +{ + /* Turn the display off */ -#endif /* __ASSEMBLY__ */ -#endif /* __BOARDS_XTENSA_ESP32S3_ESP32S3_EYE_SRC_ESP32S3_EYE_H */ + g_lcd->setpower(g_lcd, 0); +} diff --git a/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3-eye.h b/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_board_spi.c similarity index 53% copy from boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3-eye.h copy to boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_board_spi.c index 2b0d143a43..e7b3261812 100644 --- a/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3-eye.h +++ b/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_board_spi.c @@ -1,5 +1,5 @@ /**************************************************************************** - * boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3-eye.h + * boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_board_spi.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -18,100 +18,109 @@ * ****************************************************************************/ -#ifndef __BOARDS_XTENSA_ESP32S3_ESP32S3_EYE_SRC_ESP32S3_EYE_H -#define __BOARDS_XTENSA_ESP32S3_ESP32S3_EYE_SRC_ESP32S3_EYE_H - /**************************************************************************** * Included Files ****************************************************************************/ #include <nuttx/config.h> -#include <nuttx/compiler.h> -#include <stdint.h> - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -/* ESP32-S3-EYE GPIOs *******************************************************/ +#include <stdint.h> +#include <stdbool.h> +#include <debug.h> -/* BOOT Button */ +#include <nuttx/spi/spi.h> -#define BUTTON_BOOT 0 +#include "esp32s3_gpio.h" +#include "esp32s3-eye.h" /**************************************************************************** - * Public Types + * Private Functions ****************************************************************************/ /**************************************************************************** - * Public Data + * Public Functions ****************************************************************************/ -#ifndef __ASSEMBLY__ - /**************************************************************************** - * Public Function Prototypes + * Name: esp32s3_spi2_status ****************************************************************************/ -/**************************************************************************** - * Name: esp32s3_bringup - * - * Description: - * Perform architecture-specific initialization - * - * CONFIG_BOARD_LATE_INITIALIZE=y : - * Called from board_late_initialize(). - * - * CONFIG_BOARD_LATE_INITIALIZE=y && CONFIG_BOARDCTL=y : - * Called from the NSH library via board_app_initialize() - * - ****************************************************************************/ +#ifdef CONFIG_ESP32S3_SPI2 + +uint8_t esp32s3_spi2_status(struct spi_dev_s *dev, uint32_t devid) +{ + uint8_t status = 0; + + return status; +} -int esp32s3_bringup(void); +#endif /**************************************************************************** - * Name: esp32s3_gpio_init - * - * Description: - * Configure the GPIO driver. - * - * Returned Value: - * Zero (OK) is returned on success; A negated errno value is returned - * to indicate the nature of any failure. - * + * Name: esp32s3_spi2_cmddata ****************************************************************************/ -#ifdef CONFIG_DEV_GPIO -int esp32s3_gpio_init(void); +#if defined(CONFIG_ESP32S3_SPI2) && defined(CONFIG_SPI_CMDDATA) + +int esp32s3_spi2_cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + if (devid == SPIDEV_DISPLAY(0)) + { + /* This is the Data/Command control pad which determines whether the + * data bits are data or a command. + */ + + esp32s3_gpiowrite(ESP32S3_EYE_DISPLAY_DC, !cmd); + + return OK; + } + + spiinfo("devid: %" PRIu32 " CMD: %s\n", devid, cmd ? "command" : + "data"); + + return -ENODEV; +} + #endif /**************************************************************************** - * Name: board_spiflash_init - * - * Description: - * Initialize the SPIFLASH and register the MTD device. - * + * Name: esp32s3_spi3_status ****************************************************************************/ -#ifdef CONFIG_ESP32S3_SPIFLASH -int board_spiflash_init(void); +#ifdef CONFIG_ESP32S3_SPI3 + +uint8_t esp32s3_spi3_status(struct spi_dev_s *dev, uint32_t devid) +{ + uint8_t status = 0; + + return status; +} + #endif /**************************************************************************** - * Name: board_i2c_init - * - * Description: - * Configure the I2C driver. - * - * Returned Value: - * Zero (OK) is returned on success; A negated errno value is returned - * to indicate the nature of any failure. - * + * Name: esp32s3_spi3_cmddata ****************************************************************************/ -#ifdef CONFIG_I2C_DRIVER -int board_i2c_init(void); -#endif +#if defined(CONFIG_ESP32S3_SPI3) && defined(CONFIG_SPI_CMDDATA) + +int esp32s3_spi3_cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + if (devid == SPIDEV_DISPLAY(0)) + { + /* This is the Data/Command control pad which determines whether the + * data bits are data or a command. + */ -#endif /* __ASSEMBLY__ */ -#endif /* __BOARDS_XTENSA_ESP32S3_ESP32S3_EYE_SRC_ESP32S3_EYE_H */ + esp32s3_gpiowrite(CONFIG_ESP32S3_SPI3_MISOPIN, !cmd); + + return OK; + } + + spiinfo("devid: %" PRIu32 " CMD: %s\n", devid, cmd ? "command" : + "data"); + + return -ENODEV; +} + +#endif diff --git a/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_bringup.c b/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_bringup.c index d075e5a87c..5891609c5d 100644 --- a/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_bringup.c +++ b/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_bringup.c @@ -70,6 +70,15 @@ # include <nuttx/input/buttons.h> #endif +#ifdef CONFIG_ESP32S3_SPI +# include "esp32s3_spi.h" +#endif + +#ifdef CONFIG_LCD_DEV +# include <nuttx/board.h> +# include <nuttx/lcd/lcd_dev.h> +#endif + #include "esp32s3-eye.h" /**************************************************************************** @@ -206,6 +215,32 @@ int esp32s3_bringup(void) { syslog(LOG_ERR, "Failed to initialize GPIO Driver: %d\n", ret); } +#endif + +#ifdef CONFIG_ESP32S3_EYE_LCD + +#ifdef CONFIG_VIDEO_FB + ret = fb_register(0, 0); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize Frame Buffer Driver.\n"); + return ret; + } +#elif defined(CONFIG_LCD) + ret = board_lcd_initialize(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to initialize LCD.\n"); + return ret; + } + + ret = lcddev_register(0); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: lcddev_register() failed: %d\n", ret); + } +#endif + #endif /* If we got here then perhaps not all initialization was successful, but