This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new cd3e93ef17 esp32s3-devkit: Add support to ST7735 SPI LCD
cd3e93ef17 is described below

commit cd3e93ef1785fc150ef9fd4aa4d0b8b584cd70f9
Author: Alan Carvalho de Assis <[email protected]>
AuthorDate: Thu Jul 7 16:09:11 2022 -0300

    esp32s3-devkit: Add support to ST7735 SPI LCD
---
 boards/xtensa/esp32s3/esp32s3-devkit/src/Make.defs |   4 +
 .../esp32s3/esp32s3-devkit/src/esp32s3-devkit.h    |   5 +
 .../esp32s3/esp32s3-devkit/src/esp32s3_board_spi.c |   3 +-
 .../esp32s3/esp32s3-devkit/src/esp32s3_bringup.c   |  18 +++
 .../src/{esp32s3_board_spi.c => esp32s3_st7735.c}  | 128 +++++++++++----------
 5 files changed, 97 insertions(+), 61 deletions(-)

diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/src/Make.defs 
b/boards/xtensa/esp32s3/esp32s3-devkit/src/Make.defs
index bcce60fdd5..98779609f7 100644
--- a/boards/xtensa/esp32s3/esp32s3-devkit/src/Make.defs
+++ b/boards/xtensa/esp32s3/esp32s3-devkit/src/Make.defs
@@ -41,6 +41,10 @@ ifeq ($(CONFIG_ESP32S3_SPI),y)
 CSRCS += esp32s3_board_spi.c
 endif
 
+ifeq ($(CONFIG_LCD_ST7735),y)
+CSRCS += esp32s3_st7735.c
+endif
+
 SCRIPTIN = $(SCRIPTDIR)$(DELIM)esp32s3.template.ld
 SCRIPTOUT = $(SCRIPTDIR)$(DELIM)esp32s3_out.ld
 
diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h 
b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h
index df4f762a3c..56f3aec414 100644
--- a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h
+++ b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h
@@ -35,6 +35,11 @@
 
 /* ESP32-S3-DEVKIT GPIOs ****************************************************/
 
+/* LCD pins, i.e. used by ST7735 */
+
+#define GPIO_LCD_DC         14
+#define GPIO_LCD_RST        9
+
 /* BOOT Button */
 
 #define BUTTON_BOOT  0
diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_board_spi.c 
b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_board_spi.c
index d59e79a96d..c46be1d4e8 100644
--- a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_board_spi.c
+++ b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_board_spi.c
@@ -31,6 +31,7 @@
 #include <nuttx/spi/spi.h>
 
 #include "esp32s3_gpio.h"
+#include "esp32s3-devkit.h"
 
 /****************************************************************************
  * Private Functions
@@ -69,7 +70,7 @@ int esp32s3_spi2_cmddata(struct spi_dev_s *dev, uint32_t 
devid, bool cmd)
        *  data bits are data or a command.
        */
 
-      esp32s3_gpiowrite(CONFIG_ESP32S3_SPI2_MISOPIN, !cmd);
+      esp32s3_gpiowrite(GPIO_LCD_DC, !cmd);
 
       return OK;
     }
diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c 
b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c
index b6dc28f8e5..049d79374b 100644
--- a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c
+++ b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c
@@ -58,6 +58,10 @@
 #  include <nuttx/input/buttons.h>
 #endif
 
+#ifdef CONFIG_VIDEO_FB
+#include <nuttx/video/fb.h>
+#endif
+
 #include "esp32s3-devkit.h"
 
 /****************************************************************************
@@ -170,6 +174,20 @@ int esp32s3_bringup(void)
     }
 #endif
 
+#ifdef CONFIG_VIDEO_FB
+  ret = fb_register(0, 0);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to initialize Frame Buffer Driver.\n");
+    }
+#elif defined(CONFIG_LCD)
+  ret = board_lcd_initialize();
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to initialize LCD.\n");
+    }
+#endif
+
   /* If we got here then perhaps not all initialization was successful, but
    * at least enough succeeded to bring-up NSH with perhaps reduced
    * capabilities.
diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_board_spi.c 
b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_st7735.c
similarity index 55%
copy from boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_board_spi.c
copy to boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_st7735.c
index d59e79a96d..0ef4f27c8f 100644
--- a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_board_spi.c
+++ b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_st7735.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_board_spi.c
+ * boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_st7735.c
  *
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -24,102 +24,110 @@
 
 #include <nuttx/config.h>
 
-#include <stdint.h>
+#include <stdio.h>
 #include <stdbool.h>
 #include <debug.h>
+#include <errno.h>
 
+#include <nuttx/arch.h>
+#include <nuttx/board.h>
 #include <nuttx/spi/spi.h>
+#include <nuttx/lcd/lcd.h>
+#include <nuttx/lcd/st7735.h>
 
+#include "esp32s3_spi.h"
 #include "esp32s3_gpio.h"
+#include "esp32s3-devkit.h"
 
 /****************************************************************************
- * Private Functions
+ * Pre-processor Definitions
  ****************************************************************************/
 
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
+#define LCD_SPI_PORTNO     2
 
 /****************************************************************************
- * Name: esp32s3_spi2_status
+ * Private Data
  ****************************************************************************/
 
-#ifdef CONFIG_ESP32S3_SPI2
-
-uint8_t esp32s3_spi2_status(struct spi_dev_s *dev, uint32_t devid)
-{
-  uint8_t status = 0;
-
-  return status;
-}
-
-#endif
+static struct spi_dev_s *g_spidev;
+static struct lcd_dev_s *g_lcd = NULL;
 
 /****************************************************************************
- * Name: esp32s3_spi2_cmddata
+ * Public Functions
  ****************************************************************************/
 
-#if defined(CONFIG_ESP32S3_SPI2) && defined(CONFIG_SPI_CMDDATA)
+/****************************************************************************
+ * 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 esp32s3_spi2_cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd)
+int board_lcd_initialize(void)
 {
-  if (devid == SPIDEV_DISPLAY(0))
+  g_spidev = esp32s3_spibus_initialize(LCD_SPI_PORTNO);
+  if (!g_spidev)
     {
-      /*  This is the Data/Command control pad which determines whether the
-       *  data bits are data or a command.
-       */
+      lcderr("ERROR: Failed to initialize SPI port %d\n", LCD_SPI_PORTNO);
+      return -ENODEV;
+    }
 
-      esp32s3_gpiowrite(CONFIG_ESP32S3_SPI2_MISOPIN, !cmd);
+  /* Data/Control PIN */
 
-      return OK;
-    }
+  esp32s3_configgpio(GPIO_LCD_DC, OUTPUT);
+  esp32s3_gpiowrite(GPIO_LCD_DC, true);
 
-  spiinfo("devid: %" PRIu32 " CMD: %s\n", devid, cmd ? "command" :
-          "data");
+  /* Reset device */
 
-  return -ENODEV;
-}
+  esp32s3_configgpio(GPIO_LCD_RST, OUTPUT);
+  esp32s3_gpiowrite(GPIO_LCD_RST, false);
+  usleep(10000);
+  esp32s3_gpiowrite(GPIO_LCD_RST, true);
+  usleep(100000);
 
-#endif
+  return OK;
+}
 
 /****************************************************************************
- * Name: esp32s3_spi3_status
+ * Name:  board_lcd_getdev
+ *
+ * Description:
+ *   Return a a reference to the LCD object for the specified LCD.  This
+ *   allows support for multiple LCD devices.
+ *
  ****************************************************************************/
 
-#ifdef CONFIG_ESP32S3_SPI3
-
-uint8_t esp32s3_spi3_status(struct spi_dev_s *dev, uint32_t devid)
+struct lcd_dev_s *board_lcd_getdev(int devno)
 {
-  uint8_t status = 0;
+  g_lcd = st7735_lcdinitialize(g_spidev);
+  if (!g_lcd)
+    {
+      lcderr("ERROR: Failed to bind SPI port %d to LCD %d\n", LCD_SPI_PORTNO,
+      devno);
+    }
+  else
+    {
+      lcdinfo("SPI port %d bound to LCD %d\n", LCD_SPI_PORTNO, devno);
+      return g_lcd;
+    }
 
-  return status;
+  return NULL;
 }
 
-#endif
-
 /****************************************************************************
- * Name: esp32s3_spi3_cmddata
+ * Name:  board_lcd_uninitialize
+ *
+ * Description:
+ *   Uninitialize the LCD support
+ *
  ****************************************************************************/
 
-#if defined(CONFIG_ESP32S3_SPI3) && defined(CONFIG_SPI_CMDDATA)
-
-int esp32s3_spi3_cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd)
+void board_lcd_uninitialize(void)
 {
-  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);
+  /* Turn the display off */
 
-      return OK;
-    }
-
-  spiinfo("devid: %" PRIu32 " CMD: %s\n", devid, cmd ? "command" :
-          "data");
-
-  return -ENODEV;
+  g_lcd->setpower(g_lcd, 0);
 }
-
-#endif

Reply via email to