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

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

commit 5486ed1e9b2ea1513d5f43d3ca76d24b26922715
Author: Alan Carvalho de Assis <[email protected]>
AuthorDate: Sun Aug 23 12:31:48 2026 -0300

    boards/esp32s3-touch-lcd7: Add support to LCD
    
    This patch adds support to 7" 800x480 LCD on esp32s3-touch-lcd7
    board.
    
    Signed-off-by: Alan C. Assis <[email protected]>
    Assisted-by: Claude Code
---
 boards/xtensa/esp32s3/esp32s3-touch-lcd7/Kconfig   |  12 ++
 .../esp32s3-touch-lcd7/configs/lcd/defconfig       |  86 +++++++++++++
 .../esp32s3/esp32s3-touch-lcd7/src/Make.defs       |   8 ++
 .../esp32s3-touch-lcd7/src/esp32s3-touch-lcd7.h    |  58 +++++++++
 ...2s3-touch-lcd7.h => esp32s3_board_ioexpander.c} |  76 ++++++++----
 .../esp32s3-touch-lcd7/src/esp32s3_bringup.c       |  10 ++
 .../esp32s3/esp32s3-touch-lcd7/src/esp32s3_lcd.c   | 138 +++++++++++++++++++++
 7 files changed, 366 insertions(+), 22 deletions(-)

diff --git a/boards/xtensa/esp32s3/esp32s3-touch-lcd7/Kconfig 
b/boards/xtensa/esp32s3/esp32s3-touch-lcd7/Kconfig
index e763d2ebc50..cc5875291ef 100644
--- a/boards/xtensa/esp32s3/esp32s3-touch-lcd7/Kconfig
+++ b/boards/xtensa/esp32s3/esp32s3-touch-lcd7/Kconfig
@@ -5,4 +5,16 @@
 
 if ARCH_BOARD_ESP32S3_TOUCH_LCD_7
 
+config ESP32S3_BOARD_LCD
+       bool "Enable Board LCD"
+       default n
+       depends on ESP32S3_LCD
+       select ESP32S3_I2C0
+       select IOEXPANDER
+       select IOEXPANDER_CH422G
+       ---help---
+               Enable the onboard 7 inch 800x480 RGB panel.  The panel reset 
and
+               the display enable are driven through the CH422G I/O expander on
+               I2C0, so both are selected here.
+
 endif # ARCH_BOARD_ESP32S3_TOUCH_LCD_7
diff --git a/boards/xtensa/esp32s3/esp32s3-touch-lcd7/configs/lcd/defconfig 
b/boards/xtensa/esp32s3/esp32s3-touch-lcd7/configs/lcd/defconfig
new file mode 100644
index 00000000000..9e6adb92e17
--- /dev/null
+++ b/boards/xtensa/esp32s3/esp32s3-touch-lcd7/configs/lcd/defconfig
@@ -0,0 +1,86 @@
+#
+# 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_NSH_ARGCAT is not set
+# CONFIG_NSH_CMDOPT_HEXDUMP is not set
+CONFIG_ARCH="xtensa"
+CONFIG_ARCH_BOARD="esp32s3-touch-lcd7"
+CONFIG_ARCH_BOARD_COMMON=y
+CONFIG_ARCH_BOARD_ESP32S3_TOUCH_LCD_7=y
+CONFIG_ARCH_CHIP="esp32s3"
+CONFIG_ARCH_CHIP_ESP32S3=y
+CONFIG_ARCH_CHIP_ESP32S3WROOM1N16R8=y
+CONFIG_ARCH_INTERRUPTSTACK=2048
+CONFIG_ARCH_IRQ_TO_NDX=y
+CONFIG_ARCH_MINIMAL_VECTORTABLE_DYNAMIC=y
+CONFIG_ARCH_NUSER_INTERRUPTS=2
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARCH_XTENSA=y
+CONFIG_BOARD_LOOPSPERMSEC=16717
+CONFIG_BUILTIN=y
+CONFIG_DEBUG_FULLOPT=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_ESP32S3_BOARD_LCD=y
+CONFIG_ESP32S3_DMA=y
+CONFIG_ESP32S3_I2C0_SCLPIN=9
+CONFIG_ESP32S3_I2C0_SDAPIN=8
+CONFIG_ESP32S3_LCD=y
+CONFIG_ESP32S3_LCD_BOUNCE_LINES=10
+CONFIG_ESP32S3_LCD_CLOCK_MHZ=16
+CONFIG_ESP32S3_LCD_DATA0_PIN=14
+CONFIG_ESP32S3_LCD_DATA10_PIN=21
+CONFIG_ESP32S3_LCD_DATA11_PIN=1
+CONFIG_ESP32S3_LCD_DATA12_PIN=2
+CONFIG_ESP32S3_LCD_DATA14_PIN=41
+CONFIG_ESP32S3_LCD_DATA15_PIN=40
+CONFIG_ESP32S3_LCD_DATA1_PIN=38
+CONFIG_ESP32S3_LCD_DATA2_PIN=18
+CONFIG_ESP32S3_LCD_DATA3_PIN=17
+CONFIG_ESP32S3_LCD_DATA4_PIN=10
+CONFIG_ESP32S3_LCD_DATA5_PIN=39
+CONFIG_ESP32S3_LCD_DATA6_PIN=0
+CONFIG_ESP32S3_LCD_DATA7_PIN=45
+CONFIG_ESP32S3_LCD_DATA8_PIN=48
+CONFIG_ESP32S3_LCD_DATA9_PIN=47
+CONFIG_ESP32S3_LCD_HBACKPORCH=8
+CONFIG_ESP32S3_LCD_HE_PIN=5
+CONFIG_ESP32S3_LCD_HFRONTPORCH=8
+CONFIG_ESP32S3_LCD_HPULSEWIDTH=4
+CONFIG_ESP32S3_LCD_HRES=800
+CONFIG_ESP32S3_LCD_PCLK_ACTIVE_NEG=y
+CONFIG_ESP32S3_LCD_PCLK_PIN=7
+CONFIG_ESP32S3_LCD_VBACKPORCH=8
+CONFIG_ESP32S3_LCD_VFRONTPORCH=8
+CONFIG_ESP32S3_LCD_VPULSEWIDTH=4
+CONFIG_ESP32S3_SPIRAM=y
+CONFIG_ESP32S3_SPIRAM_MODE_OCT=y
+CONFIG_ESP32S3_SPIRAM_SPEED_80M=y
+CONFIG_ESP32S3_UART0=y
+CONFIG_EXAMPLES_FB=y
+CONFIG_FS_PROCFS=y
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+CONFIG_IDLETHREAD_STACKSIZE=3072
+CONFIG_INIT_ENTRYPOINT="nsh_main"
+CONFIG_INIT_STACKSIZE=4096
+CONFIG_INTELHEX_BINARY=y
+CONFIG_LINE_MAX=64
+CONFIG_MM_REGIONS=2
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_READLINE=y
+CONFIG_PREALLOC_TIMERS=4
+CONFIG_RAM_SIZE=114688
+CONFIG_RAM_START=0x20000000
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_WAITPID=y
+CONFIG_START_DAY=6
+CONFIG_START_MONTH=12
+CONFIG_START_YEAR=2011
+CONFIG_SYSLOG_BUFFER=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_UART0_SERIAL_CONSOLE=y
diff --git a/boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/Make.defs 
b/boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/Make.defs
index 152d8d79276..db59a4ed4a4 100644
--- a/boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/Make.defs
+++ b/boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/Make.defs
@@ -26,6 +26,14 @@ ifeq ($(CONFIG_BOARDCTL_RESET),y)
 CSRCS += esp32s3_reset.c
 endif
 
+ifeq ($(CONFIG_IOEXPANDER_CH422G),y)
+CSRCS += esp32s3_board_ioexpander.c
+endif
+
+ifeq ($(CONFIG_ESP32S3_BOARD_LCD),y)
+CSRCS += esp32s3_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-touch-lcd7/src/esp32s3-touch-lcd7.h 
b/boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/esp32s3-touch-lcd7.h
index 7f63afbf247..3d02d955f7d 100644
--- a/boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/esp32s3-touch-lcd7.h
+++ b/boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/esp32s3-touch-lcd7.h
@@ -31,10 +31,35 @@
 #include <nuttx/compiler.h>
 #include <stdint.h>
 
+#ifdef CONFIG_IOEXPANDER_CH422G
+#  include <nuttx/ioexpander/ioexpander.h>
+#endif
+
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* I2C bus ******************************************************************/
+
+/* One I2C bus, GPIO8 (SDA) and GPIO9 (SCL), is shared by the CH422G I/O
+ * expander, the GT911 touch controller and the external I2C header.
+ */
+
+#define BOARD_I2C_BUS      0
+
+/* CH422G I/O expander ******************************************************/
+
+/* The board labels the expander pins EXIO0-EXIO7, and they are the CH422G
+ * pins IO0-IO7 in order, so the ioexpander pin number is the EXIO number.
+ * EXIO0, EXIO6 and EXIO7 are not connected to anything on this board.
+ */
+
+#define BOARD_EXIO_TP_RST  CH422G_IO1  /* GT911 touch controller reset */
+#define BOARD_EXIO_DISP    CH422G_IO2  /* LCD display and backlight enable */
+#define BOARD_EXIO_LCD_RST CH422G_IO3  /* LCD panel reset */
+#define BOARD_EXIO_SD_CS   CH422G_IO4  /* TF card chip select */
+#define BOARD_EXIO_USB_SEL CH422G_IO5  /* USB / CAN transceiver select */
+
 /****************************************************************************
  * Public Types
  ****************************************************************************/
@@ -62,5 +87,38 @@
 
 int esp32s3_bringup(void);
 
+#ifdef CONFIG_IOEXPANDER_CH422G
+/****************************************************************************
+ * Name: board_ioexpander_initialize
+ *
+ * Description:
+ *   Bring up the CH422G I/O expander, if it has not been brought up
+ *   already, and return it.  Several parts of the board hang off the
+ *   expander, so the first caller initialises it and the rest share it.
+ *
+ * Returned Value:
+ *   The expander instance on success, NULL on failure.
+ *
+ ****************************************************************************/
+
+FAR struct ioexpander_dev_s *board_ioexpander_initialize(void);
+#endif
+
+#ifdef CONFIG_ESP32S3_BOARD_LCD
+/****************************************************************************
+ * Name: board_lcd_initialize
+ *
+ * Description:
+ *   Bring the RGB panel out of reset, switch the backlight on and register
+ *   the framebuffer character driver.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int board_lcd_initialize(void);
+#endif
+
 #endif /* __ASSEMBLY__ */
 #endif /* __BOARDS_XTENSA_ESP32S3_ESP32S3_TOUCH_LCD7_SRC_ESP32S3_TOUCH_LCD7_H 
*/
diff --git a/boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/esp32s3-touch-lcd7.h 
b/boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/esp32s3_board_ioexpander.c
similarity index 53%
copy from boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/esp32s3-touch-lcd7.h
copy to boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/esp32s3_board_ioexpander.c
index 7f63afbf247..2d056bb1c3b 100644
--- a/boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/esp32s3-touch-lcd7.h
+++ b/boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/esp32s3_board_ioexpander.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/esp32s3-touch-lcd7.h
+ * boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/esp32s3_board_ioexpander.c
  *
  * SPDX-License-Identifier: Apache-2.0
  *
@@ -20,47 +20,79 @@
  *
  ****************************************************************************/
 
-#ifndef __BOARDS_XTENSA_ESP32S3_ESP32S3_TOUCH_LCD7_SRC_ESP32S3_TOUCH_LCD7_H
-#define __BOARDS_XTENSA_ESP32S3_ESP32S3_TOUCH_LCD7_SRC_ESP32S3_TOUCH_LCD7_H
-
 /****************************************************************************
  * Included Files
  ****************************************************************************/
 
 #include <nuttx/config.h>
-#include <nuttx/compiler.h>
-#include <stdint.h>
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
+#include <errno.h>
+#include <syslog.h>
 
-/****************************************************************************
- * Public Types
- ****************************************************************************/
+#include <nuttx/i2c/i2c_master.h>
+#include <nuttx/ioexpander/ioexpander.h>
+#include <nuttx/ioexpander/ch422g.h>
+
+#include "esp32s3_i2c.h"
+#include "esp32s3-touch-lcd7.h"
+
+#ifdef CONFIG_IOEXPANDER_CH422G
 
 /****************************************************************************
- * Public Data
+ * Private Data
  ****************************************************************************/
 
-#ifndef __ASSEMBLY__
+static struct ch422g_config_s g_ch422g_config =
+{
+  .frequency = 400000,
+};
+
+/* The expander is shared, so it is brought up once and handed out. */
+
+static FAR struct ioexpander_dev_s *g_ioe;
 
 /****************************************************************************
- * Public Function Prototypes
+ * Public Functions
  ****************************************************************************/
 
 /****************************************************************************
- * Name: esp32s3_bringup
+ * Name: board_ioexpander_initialize
  *
  * Description:
- *   Perform architecture-specific initialization
+ *   Bring up the CH422G I/O expander, if it has not been brought up
+ *   already, and return it.  Several parts of the board hang off the
+ *   expander, so the first caller initialises it and the rest share it.
  *
- *   CONFIG_BOARD_LATE_INITIALIZE=y :
- *     Called from board_late_initialize().
+ * Returned Value:
+ *   The expander instance on success, NULL on failure.
  *
  ****************************************************************************/
 
-int esp32s3_bringup(void);
+FAR struct ioexpander_dev_s *board_ioexpander_initialize(void)
+{
+  FAR struct i2c_master_s *i2c;
+
+  if (g_ioe != NULL)
+    {
+      return g_ioe;
+    }
+
+  i2c = esp32s3_i2cbus_initialize(BOARD_I2C_BUS);
+  if (i2c == NULL)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to initialize I2C%d\n", BOARD_I2C_BUS);
+      return NULL;
+    }
+
+  g_ioe = ch422g_initialize(i2c, &g_ch422g_config);
+  if (g_ioe == NULL)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to initialize CH422G\n");
+      esp32s3_i2cbus_uninitialize(i2c);
+      return NULL;
+    }
+
+  return g_ioe;
+}
 
-#endif /* __ASSEMBLY__ */
-#endif /* __BOARDS_XTENSA_ESP32S3_ESP32S3_TOUCH_LCD7_SRC_ESP32S3_TOUCH_LCD7_H 
*/
+#endif /* CONFIG_IOEXPANDER_CH422G */
diff --git a/boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/esp32s3_bringup.c 
b/boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/esp32s3_bringup.c
index 63caf1f6a7f..b7da58a11f6 100644
--- a/boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/esp32s3_bringup.c
+++ b/boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/esp32s3_bringup.c
@@ -97,6 +97,16 @@ int esp32s3_bringup(void)
     }
 #endif
 
+#ifdef CONFIG_ESP32S3_BOARD_LCD
+  /* Bring up the RGB panel and register the framebuffer */
+
+  ret = board_lcd_initialize();
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: board_lcd_initialize() failed: %d\n", ret);
+    }
+#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-touch-lcd7/src/esp32s3_lcd.c 
b/boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/esp32s3_lcd.c
new file mode 100644
index 00000000000..75d7f8599e0
--- /dev/null
+++ b/boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/esp32s3_lcd.c
@@ -0,0 +1,138 @@
+/****************************************************************************
+ * boards/xtensa/esp32s3/esp32s3-touch-lcd7/src/esp32s3_lcd.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/* The 7" 800x480 panel is driven by the LCD_CAM peripheral over a 16-bit
+ * parallel RGB565 bus, which arch/xtensa/src/esp32s3/esp32s3_lcd.c owns.
+ * Everything that is specific to this board is here: the panel reset and
+ * the display enable are not wired to GPIOs but to the CH422G I/O expander,
+ * because the RGB bus has taken most of the usable pins.
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <syslog.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/board.h>
+#include <nuttx/ioexpander/ioexpander.h>
+#include <nuttx/ioexpander/ch422g.h>
+#include <nuttx/video/fb.h>
+
+#include "esp32s3-touch-lcd7.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* The EK9716 wants its reset held for at least 10us and needs time to come
+ * up before it is clocked.  These are comfortably longer than that.
+ */
+
+#define LCD_RESET_HOLD_US   (20 * 1000)
+#define LCD_RESET_WAIT_US  (120 * 1000)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_lcd_initialize
+ *
+ * Description:
+ *   Bring the RGB panel out of reset, switch the backlight on and register
+ *   the framebuffer character driver.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int board_lcd_initialize(void)
+{
+  FAR struct ioexpander_dev_s *ioe;
+  int ret;
+
+  ioe = board_ioexpander_initialize();
+  if (ioe == NULL)
+    {
+      return -ENODEV;
+    }
+
+  /* The panel reset and the display enable are outputs of the expander.
+   * Drive the panel into reset and keep the display off while it settles.
+   */
+
+  ret = IOEXP_SETDIRECTION(ioe, BOARD_EXIO_LCD_RST,
+                           IOEXPANDER_DIRECTION_OUT);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to configure LCD reset: %d\n", ret);
+      return ret;
+    }
+
+  ret = IOEXP_SETDIRECTION(ioe, BOARD_EXIO_DISP, IOEXPANDER_DIRECTION_OUT);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to configure display enable: %d\n",
+             ret);
+      return ret;
+    }
+
+  IOEXP_WRITEPIN(ioe, BOARD_EXIO_DISP, false);
+  IOEXP_WRITEPIN(ioe, BOARD_EXIO_LCD_RST, false);
+  up_udelay(LCD_RESET_HOLD_US);
+
+  ret = IOEXP_WRITEPIN(ioe, BOARD_EXIO_LCD_RST, true);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to release LCD reset: %d\n", ret);
+      return ret;
+    }
+
+  up_udelay(LCD_RESET_WAIT_US);
+
+  /* The framebuffer has to exist, and so be scanning out a defined buffer,
+   * before the display is enabled.  Enabling it first shows whatever the
+   * panel happens to latch until the first frame arrives.
+   */
+
+  ret = fb_register(0, 0);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: fb_register() failed: %d\n", ret);
+      return ret;
+    }
+
+  ret = IOEXP_WRITEPIN(ioe, BOARD_EXIO_DISP, true);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to enable the display: %d\n", ret);
+      return ret;
+    }
+
+  return OK;
+}

Reply via email to