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

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

commit e67b8c171e7129314272704abff3149cf9be462a
Author: Filipe Cavalcanti <[email protected]>
AuthorDate: Wed Aug 5 22:37:42 2026 -0300

    board/risc-v: touchscreen support on esp32p4-tab5
    
    Adds support for ST7123 touchscreen controller on esp32p4-tab5.
    Includes new KConfig option and additions to hmi_power source.
    
    Signed-off-by: Filipe Cavalcanti <[email protected]>
---
 boards/risc-v/esp32p4/esp32p4-tab5/Kconfig         |   9 ++
 .../risc-v/esp32p4/esp32p4-tab5/src/CMakeLists.txt |   4 +
 boards/risc-v/esp32p4/esp32p4-tab5/src/Make.defs   |   4 +
 .../risc-v/esp32p4/esp32p4-tab5/src/esp32p4-tab5.h |  34 +++++
 .../esp32p4/esp32p4-tab5/src/esp32p4_bringup.c     |  21 ++++
 .../esp32p4/esp32p4-tab5/src/esp32p4_hmi_power.c   |  35 ++++++
 .../esp32p4/esp32p4-tab5/src/esp32p4_ioexpander.c  |   1 +
 .../src/{esp32p4_ioexpander.c => esp32p4_touch.c}  | 137 +++++++++------------
 8 files changed, 164 insertions(+), 81 deletions(-)

diff --git a/boards/risc-v/esp32p4/esp32p4-tab5/Kconfig 
b/boards/risc-v/esp32p4/esp32p4-tab5/Kconfig
index 64cbc517d40..44a9ed1c838 100644
--- a/boards/risc-v/esp32p4/esp32p4-tab5/Kconfig
+++ b/boards/risc-v/esp32p4/esp32p4-tab5/Kconfig
@@ -98,4 +98,13 @@ config ESP32P4_TAB5_LCD_ST7123
 
 endchoice
 
+config ESP32P4_TAB5_TOUCHSCREEN
+       bool "Touch Screen Controller"
+       default n
+       select INPUT
+       select INPUT_ST7123
+       select ESP32P4_TAB5_HMI_POWER
+       ---help---
+               Initialize the ST7123 touch screen controller.
+
 endif # ARCH_BOARD_ESP32P4_TAB5
diff --git a/boards/risc-v/esp32p4/esp32p4-tab5/src/CMakeLists.txt 
b/boards/risc-v/esp32p4/esp32p4-tab5/src/CMakeLists.txt
index 1461f115824..7635e1315ed 100644
--- a/boards/risc-v/esp32p4/esp32p4-tab5/src/CMakeLists.txt
+++ b/boards/risc-v/esp32p4/esp32p4-tab5/src/CMakeLists.txt
@@ -39,6 +39,10 @@ if(CONFIG_ESP32P4_TAB5_LCD)
   endif()
 endif()
 
+if(CONFIG_ESP32P4_TAB5_TOUCHSCREEN)
+  list(APPEND SRCS esp32p4_touch.c)
+endif()
+
 if(CONFIG_BOARDCTL)
   if(CONFIG_BOARDCTL_RESET)
     list(APPEND SRCS esp32p4_reset.c)
diff --git a/boards/risc-v/esp32p4/esp32p4-tab5/src/Make.defs 
b/boards/risc-v/esp32p4/esp32p4-tab5/src/Make.defs
index 46f7f7281fb..2a64509de49 100644
--- a/boards/risc-v/esp32p4/esp32p4-tab5/src/Make.defs
+++ b/boards/risc-v/esp32p4/esp32p4-tab5/src/Make.defs
@@ -41,6 +41,10 @@ ifeq ($(CONFIG_ESP32P4_TAB5_LCD),y)
   endif
 endif
 
+ifeq ($(CONFIG_ESP32P4_TAB5_TOUCHSCREEN),y)
+  CSRCS += esp32p4_touch.c
+endif
+
 ifeq ($(CONFIG_BOARDCTL),y)
   ifeq ($(CONFIG_BOARDCTL_RESET),y)
     CSRCS += esp32p4_reset.c
diff --git a/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4-tab5.h 
b/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4-tab5.h
index 5c7950cda82..7fc4a47672f 100644
--- a/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4-tab5.h
+++ b/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4-tab5.h
@@ -221,5 +221,39 @@ int tab5_pi4ioe_low_write_pin(uint8_t pin, bool enable);
 #endif
 #endif /* CONFIG_ESP32P4_TAB5_IOEXPANDER */
 
+#ifdef CONFIG_ESP32P4_TAB5_TOUCHSCREEN
+/****************************************************************************
+ * Name: tab5_touchscreen_power_init
+ *
+ * Description:
+ *   Enable or disable the Touch Screen Controller rail.
+ *
+ * Input Parameters:
+ *   None.
+ *
+ * Returned Value:
+ *   Zero on success, -1 on failure.
+ *
+ ****************************************************************************/
+
+int tab5_touchscreen_power_init(void);
+
+/****************************************************************************
+ * Name: tab5_touchscreen_init
+ *
+ * Description:
+ *   Initialize the touch screen controller.
+ *
+ * Input Parameters:
+ *   None.
+ *
+ * Returned Value:
+ *   Zero on success, -1 on failure.
+ *
+ ****************************************************************************/
+
+int tab5_touchscreen_init(void);
+#endif /* CONFIG_ESP32P4_TAB5_TOUCHSCREEN */
+
 #endif /* __ASSEMBLY__ */
 #endif /* __BOARDS_RISCV_ESP32P4_ESP32P4_TAB5_SRC_ESP32P4_TAB5_H */
diff --git a/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_bringup.c 
b/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_bringup.c
index ebfae61ee92..bf7fb985d7b 100644
--- a/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_bringup.c
+++ b/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_bringup.c
@@ -127,6 +127,17 @@ int esp_bringup(void)
     }
 #endif
 
+#ifdef CONFIG_ESP32P4_TAB5_TOUCHSCREEN
+  /* Reset the touchscreen by pulsing the TOUCH_EN pin */
+
+  ret = tab5_touchscreen_power_init();
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: failed to reset touchscreen: %d\n", ret);
+      return ret;
+    }
+#endif
+
 #ifdef CONFIG_ESP32P4_TAB5_MIPI_DSI
   /* Tab5 ST712x bus: 2 lanes @ board.h bitrate. */
 
@@ -171,6 +182,16 @@ int esp_bringup(void)
     }
 #endif
 
+#ifdef CONFIG_ESP32P4_TAB5_TOUCHSCREEN
+  /* Touch screen controller init. Must come after LCD and power init. */
+
+  ret = tab5_touchscreen_init();
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: failed to initialize touchscreen: %d\n", ret);
+    }
+#endif
+
 #ifdef CONFIG_FS_TMPFS
   /* Mount the tmpfs file system */
 
diff --git a/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_hmi_power.c 
b/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_hmi_power.c
index 267a3a16976..525c8f2984a 100644
--- a/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_hmi_power.c
+++ b/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_hmi_power.c
@@ -63,6 +63,41 @@ static struct esp_ldo_config_t g_mipi_phy_ldo_config =
  * Public Functions
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: tab5_touchscreen_power_init
+ *
+ * Description:
+ *   Reset the touchscreen by pulsing the TOUCH_EN pin
+ *   via PI4IOE P5 (BSP_TOUCH_EN). Datasheet suggests 2 ms low pulse to
+ *   reset the controller and at least 20 ms in high state to stabilize the
+ *   controller.
+ *
+ * Returned Value:
+ *   Zero on success, -1 on failure.
+ *
+ ****************************************************************************/
+
+int tab5_touchscreen_power_init(void)
+{
+  int ret;
+
+  ret = tab5_pi4ioe_low_write_pin(TAB5_TOUCH_EN_PIN, true);
+  nxsched_msleep(10);
+  ret |= tab5_pi4ioe_low_write_pin(TAB5_TOUCH_EN_PIN, false);
+  nxsched_msleep(30);
+  ret |= tab5_pi4ioe_low_write_pin(TAB5_TOUCH_EN_PIN, true);
+  if (ret != OK)
+    {
+      syslog(LOG_ERR, "ERROR: failed to reset touchscreen: %d\n", ret);
+      return ret;
+    }
+
+  nxsched_msleep(100);
+
+  syslog(LOG_INFO, "Touchscreen reset complete\n");
+  return OK;
+}
+
 /****************************************************************************
  * Name: tab5_mipi_phy_power
  *
diff --git a/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_ioexpander.c 
b/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_ioexpander.c
index 71200944fb8..7218cebc5ea 100644
--- a/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_ioexpander.c
+++ b/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_ioexpander.c
@@ -29,6 +29,7 @@
 #include <stdbool.h>
 #include <stdint.h>
 #include <syslog.h>
+#include <errno.h>
 
 #include <nuttx/i2c/i2c_master.h>
 #include <nuttx/ioexpander/ioexpander.h>
diff --git a/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_ioexpander.c 
b/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_touch.c
similarity index 52%
copy from boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_ioexpander.c
copy to boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_touch.c
index 71200944fb8..0de9e51e22f 100644
--- a/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_ioexpander.c
+++ b/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_touch.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_ioexpander.c
+ * boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_touch.c
  *
  * SPDX-License-Identifier: Apache-2.0
  *
@@ -26,138 +26,113 @@
 
 #include <nuttx/config.h>
 
-#include <stdbool.h>
-#include <stdint.h>
+#include <errno.h>
 #include <syslog.h>
 
 #include <nuttx/i2c/i2c_master.h>
-#include <nuttx/ioexpander/ioexpander.h>
-#include <nuttx/ioexpander/pi4ioe5v6408.h>
+#include <nuttx/input/st7123.h>
 
+#include <arch/board/board.h>
+
+#include "espressif/esp_gpio.h"
 #include "espressif/esp_i2c.h"
 
-#include <arch/board/board.h>
+#include "esp32p4-tab5.h"
 
 /****************************************************************************
- * Pre-processor Definitions
+ * Private Function Prototypes
  ****************************************************************************/
 
-#define TAB5_PI4IOE_FREQUENCY       400000
+static int board_st7123_attach(FAR const struct st7123_config_s *config,
+                               xcpt_t isr, FAR void *arg);
 
 /****************************************************************************
  * Private Data
  ****************************************************************************/
 
-#ifdef CONFIG_ESP32P4_TAB5_IOEXPANDER_LOW
-static struct pi4ioe5v6408_config_s g_pi4ioe_config_low =
-{
-  .address   = PI4IOE5V6408_I2C_ADDRESS_LOW,
-  .frequency = TAB5_PI4IOE_FREQUENCY,
-};
-static FAR struct ioexpander_dev_s *g_pi4ioe_low;
-#endif
-
-#ifdef CONFIG_ESP32P4_TAB5_IOEXPANDER_HIGH
-static struct pi4ioe5v6408_config_s g_pi4ioe_config_high =
+static const struct st7123_config_s g_st7123_config =
 {
-  .address   = PI4IOE5V6408_I2C_ADDRESS_HIGH,
-  .frequency = TAB5_PI4IOE_FREQUENCY,
+  .attach = board_st7123_attach,
 };
-static FAR struct ioexpander_dev_s *g_pi4ioe_high;
-#endif
 
 /****************************************************************************
- * Public Functions
+ * Private Functions
  ****************************************************************************/
 
 /****************************************************************************
- * Name: tab5_pi4ioe_init
+ * Name: board_st7123_attach
  *
  * Description:
- *   Initialize the IO expanders.
+ *   Configure TAB5_GPIO_TP_INT, wire it to the ST7123 driver interrupt
+ *   handler, and enable the pin.
+ *
+ * Input Parameters:
+ *   config - Pointer to the ST7123 configuration structure.
+ *   isr - The interrupt service routine to call.
+ *   arg - The argument to pass to the interrupt service routine.
  *
  * Returned Value:
  *   Zero on success, -1 on failure.
  *
  ****************************************************************************/
 
-int tab5_pi4ioe_init(void)
+static int board_st7123_attach(FAR const struct st7123_config_s *config,
+                               xcpt_t isr, FAR void *arg)
 {
-  FAR struct i2c_master_s *i2c;
+  int ret;
 
-  i2c = esp_i2cbus_initialize(ESPRESSIF_I2C0);
-  if (i2c == NULL)
-    {
-      syslog(LOG_ERR, "tab5_pi4ioe_init: failed to get I2C0\n");
-      return -ENODEV;
-    }
+  UNUSED(config);
 
-#ifdef CONFIG_ESP32P4_TAB5_IOEXPANDER_LOW
-  g_pi4ioe_low = pi4ioe5v6408_initialize(i2c, &g_pi4ioe_config_low);
-  if (g_pi4ioe_low == NULL)
-    {
-      syslog(LOG_ERR, "tab5_pi4ioe_init: expander (low) init failed\n");
-      return -ENODEV;
-    }
+  /* Input with pull-up, falling-edge interrupt (active-low INT). */
 
-  syslog(LOG_INFO, "tab5_pi4ioe_init: PI4IOE5V6408 (low) initialized\n");
-  #endif
+  esp_configgpio(TAB5_GPIO_TP_INT, INPUT_FUNCTION_2 | PULLUP | FALLING);
+  esp_gpioirqdisable(TAB5_GPIO_TP_INT);
 
-#ifdef CONFIG_ESP32P4_TAB5_IOEXPANDER_HIGH
-  g_pi4ioe_high = pi4ioe5v6408_initialize(i2c, &g_pi4ioe_config_high);
-  if (g_pi4ioe_high == NULL)
+  ret = esp_gpio_irq(TAB5_GPIO_TP_INT, isr, arg);
+  if (ret < 0)
     {
-      syslog(LOG_ERR, "tab5_pi4ioe_init: expander (high) init failed\n");
-      return -ENODEV;
+      syslog(LOG_ERR, "ERROR: failed to attach interrupt: %d\n", ret);
+      return ret;
     }
 
-  syslog(LOG_INFO, "tab5_pi4ioe_init: PI4IOE5V6408 (high) initialized\n");
-#endif
-
+  esp_gpioirqenable(TAB5_GPIO_TP_INT);
   return OK;
 }
 
 /****************************************************************************
- * Name: tab5_pi4ioe_low_write_pin
- *
- * Description:
- *   Write a pin on the IO expander (low).
- *
- * Input Parameters:
- *   pin - The pin to write on the IO expander (low).
- *   enable - True to set the pin high, false to set the pin low.
- *
- * Returned Value:
- *   Zero on success, -1 on failure.
- *
+ * Public Functions
  ****************************************************************************/
 
-#ifdef CONFIG_ESP32P4_TAB5_IOEXPANDER_LOW
-int tab5_pi4ioe_low_write_pin(uint8_t pin, bool enable)
-{
-  IOEXP_SETDIRECTION(g_pi4ioe_low, pin, IOEXPANDER_DIRECTION_OUT);
-  return IOEXP_WRITEPIN(g_pi4ioe_low, pin, enable);
-}
-#endif
-
 /****************************************************************************
- * Name: tab5_pi4ioe_high_write_pin
+ * Name: tab5_touchscreen_init
  *
  * Description:
- *   Write a pin on the IO expander (high).
- *
- * Input Parameters:
- *   pin - The pin to write on the IO expander (high).
- *   enable - True to set the pin high, false to set the pin low.
+ *   Initialize the touch screen controller.
  *
  * Returned Value:
  *   Zero on success, -1 on failure.
  *
  ****************************************************************************/
 
-#ifdef CONFIG_ESP32P4_TAB5_IOEXPANDER_HIGH
-int tab5_pi4ioe_high_write_pin(uint8_t pin, bool enable)
+int tab5_touchscreen_init(void)
 {
-  return IOEXP_WRITEPIN(g_pi4ioe_high, pin, enable);
+  FAR struct i2c_master_s *i2c;
+  int ret;
+
+  i2c = esp_i2cbus_initialize(ESPRESSIF_I2C0);
+  if (i2c == NULL)
+    {
+      syslog(LOG_ERR, "ERROR: failed to get I2C0 bus\n");
+      return -ENODEV;
+    }
+
+  ret = st7123_register(i2c, 0, &g_st7123_config);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: failed to register ST7123: %d\n", ret);
+      return ret;
+    }
+
+  syslog(LOG_INFO, "ST7123 touchscreen controller initialized!\n");
+  return OK;
 }
-#endif

Reply via email to