From effab1bd61f5a35f76f78150e16a2f6dc7e90b23 Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Tue, 10 Oct 2023 10:59:50 +0000 Subject: [PATCH] feat(esp32s3-eye): SPI and LCD LCD is connected to SPI2 and uses DC signalling. --- boards/xtensa/esp32s3/esp32s3-eye/Kconfig | 11 ++ .../xtensa/esp32s3/esp32s3-eye/src/Make.defs | 8 + .../esp32s3/esp32s3-eye/src/esp32s3-eye.h | 44 +++++ .../esp32s3-eye/src/esp32s3_board_lcd.c | 153 ++++++++++++++++++ .../esp32s3-eye/src/esp32s3_board_spi.c | 126 +++++++++++++++ .../esp32s3/esp32s3-eye/src/esp32s3_bringup.c | 35 ++++ 6 files changed, 377 insertions(+) create mode 100644 boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_board_lcd.c create mode 100644 boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_board_spi.c 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_board_lcd.c b/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_board_lcd.c new file mode 100644 index 0000000000..e7d5eedc68 --- /dev/null +++ b/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_board_lcd.c @@ -0,0 +1,153 @@ +/**************************************************************************** + * 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 + * 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 + +#include + +#include "esp32s3_gpio.h" +#include "esp32s3_spi.h" +#include "hardware/esp32s3_gpio_sigmap.h" + +#include "esp32s3-eye.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct spi_dev_s *g_spidev; +static struct lcd_dev_s *g_lcd; + +/**************************************************************************** + * 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). + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int board_lcd_initialize(void) +{ + /* Initialize non-SPI GPIOs */ + + 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); + + 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_lcd_getdev + * + * Description: + * 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. + * + ****************************************************************************/ + +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_lcd_uninitialize + * + * Description: + * Uninitialize the LCD support + * + * Returned Value: + * None + * + ****************************************************************************/ + +void board_lcd_uninitialize(void) +{ + /* Turn the display off */ + + g_lcd->setpower(g_lcd, 0); +} diff --git a/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_board_spi.c b/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_board_spi.c new file mode 100644 index 0000000000..e7b3261812 --- /dev/null +++ b/boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_board_spi.c @@ -0,0 +1,126 @@ +/**************************************************************************** + * 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 + * 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 "esp32s3_gpio.h" +#include "esp32s3-eye.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32s3_spi2_status + ****************************************************************************/ + +#ifdef CONFIG_ESP32S3_SPI2 + +uint8_t esp32s3_spi2_status(struct spi_dev_s *dev, uint32_t devid) +{ + uint8_t status = 0; + + return status; +} + +#endif + +/**************************************************************************** + * Name: esp32s3_spi2_cmddata + ****************************************************************************/ + +#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: esp32s3_spi3_status + ****************************************************************************/ + +#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: esp32s3_spi3_cmddata + ****************************************************************************/ + +#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. + */ + + 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 #endif +#ifdef CONFIG_ESP32S3_SPI +# include "esp32s3_spi.h" +#endif + +#ifdef CONFIG_LCD_DEV +# include +# include +#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