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 8b73477c5eca17d4af225be7c3847eb19cfd21ae
Author: Filipe Cavalcanti <[email protected]>
AuthorDate: Wed Aug 5 21:44:11 2026 -0300

    boards/risc-v: support pio4ioe IO Expander on esp32p4-tab5
    
    Adds support for bringup of the two IO Expanders available on the
    esp32p4-tab5 board. Those IO Expanders allow for control of many
    peripherals such as radio, camera, display and touch.
    
    Signed-off-by: Filipe Cavalcanti <[email protected]>
---
 boards/risc-v/esp32p4/esp32p4-tab5/Kconfig         |  26 ++++
 boards/risc-v/esp32p4/esp32p4-tab5/include/board.h |  19 +++
 .../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 |  56 +++++++
 .../esp32p4/esp32p4-tab5/src/esp32p4_bringup.c     |  13 ++
 .../esp32p4/esp32p4-tab5/src/esp32p4_ioexpander.c  | 163 +++++++++++++++++++++
 7 files changed, 285 insertions(+)

diff --git a/boards/risc-v/esp32p4/esp32p4-tab5/Kconfig 
b/boards/risc-v/esp32p4/esp32p4-tab5/Kconfig
index e5bcf1d57fb..ed922979b37 100644
--- a/boards/risc-v/esp32p4/esp32p4-tab5/Kconfig
+++ b/boards/risc-v/esp32p4/esp32p4-tab5/Kconfig
@@ -5,4 +5,30 @@
 
 if ARCH_BOARD_ESP32P4_TAB5
 
+config ESP32P4_TAB5_IOEXPANDER
+       bool "Enable the Tab5 board IO Expander"
+       default n
+       select ESPRESSIF_I2C0
+       select IOEXPANDER
+       select IOEXPANDER_PI4IOE5V6408
+       ---help---
+               Enable support for the Tab5 board IO Expander.
+               There are two IO Expanders on the this board.
+               The first IO Expander is at address 0x43 (address pin low) and
+               the second is at address 0x44 (address pin high).
+
+if ESP32P4_TAB5_IOEXPANDER
+       config ESP32P4_TAB5_IOEXPANDER_LOW
+               bool "Enable the first IO Expander"
+               default y
+               ---help---
+                       Enable the first IO Expander.
+
+       config ESP32P4_TAB5_IOEXPANDER_HIGH
+               bool "Enable the second IO Expander"
+               default n
+               ---help---
+                       Enable the second IO Expander.
+endif
+
 endif # ARCH_BOARD_ESP32P4_TAB5
diff --git a/boards/risc-v/esp32p4/esp32p4-tab5/include/board.h 
b/boards/risc-v/esp32p4/esp32p4-tab5/include/board.h
index 9f2fa626c0a..7dea43e0b41 100644
--- a/boards/risc-v/esp32p4/esp32p4-tab5/include/board.h
+++ b/boards/risc-v/esp32p4/esp32p4-tab5/include/board.h
@@ -108,6 +108,25 @@
 #define TAB5_GPIO_M5_RXD0      38
 #define TAB5_GPIO_M5_PB_OUT    52
 
+/* PI4IOE5V6408 (1st) IO Expander (address pin low). */
+
+#define TAB5_RF_PTH_L_INT_H_EXT_PIN  0
+#define TAB5_SPK_EN_PIN              1
+#define TAB5_EXT_5V_EN_PIN           2
+#define TAB5_LCD_EN_PIN              4
+#define TAB5_TOUCH_EN_PIN            5
+#define TAB5_CAM_EN_PIN              6
+#define TAB5_HP_DET_PIN              7
+
+/* PI4IOE5V6408 (2nd) IO Expander (address pin high). */
+
+#define TAB5_WLAN_PWR_EN_PIN         0
+#define TAB5_USB_5V_EN_PIN           3
+#define TAB5_PWROFF_PULSE_PIN        4
+#define TAB5_nCHG_QC_EN_PIN          5
+#define TAB5_CHG_STAT_PIN            6
+#define TAB5_CHG_EN_PIN              7
+
 /* ESP32-C6 (Wi-Fi/BT companion) - SDIO2 bus GPIO8..15 (pins only)
  *
  * GPIO8-15 carry D3..D0, IO2, RST, CK, CMD of the SDIO2 link to the C6.
diff --git a/boards/risc-v/esp32p4/esp32p4-tab5/src/CMakeLists.txt 
b/boards/risc-v/esp32p4/esp32p4-tab5/src/CMakeLists.txt
index 30d104ba394..3ee63748b93 100644
--- a/boards/risc-v/esp32p4/esp32p4-tab5/src/CMakeLists.txt
+++ b/boards/risc-v/esp32p4/esp32p4-tab5/src/CMakeLists.txt
@@ -22,6 +22,10 @@
 
 set(SRCS esp32p4_boot.c esp32p4_bringup.c)
 
+if(CONFIG_ESP32P4_TAB5_IOEXPANDER)
+  list(APPEND SRCS esp32p4_ioexpander.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 257ea5bef7f..7a99aee61fc 100644
--- a/boards/risc-v/esp32p4/esp32p4-tab5/src/Make.defs
+++ b/boards/risc-v/esp32p4/esp32p4-tab5/src/Make.defs
@@ -24,6 +24,10 @@ include $(TOPDIR)/Make.defs
 
 CSRCS = esp32p4_boot.c esp32p4_bringup.c
 
+ifeq ($(CONFIG_ESP32P4_TAB5_IOEXPANDER),y)
+  CSRCS += esp32p4_ioexpander.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 db80c3db30a..8718f84a56f 100644
--- a/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4-tab5.h
+++ b/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4-tab5.h
@@ -56,5 +56,61 @@
 
 int esp_bringup(void);
 
+#ifdef CONFIG_ESP32P4_TAB5_IOEXPANDER
+/****************************************************************************
+ * Name: tab5_pi4ioe_init
+ *
+ * Description:
+ *   Initialize the IO expanders.
+ *
+ * Input Parameters:
+ *   None.
+ *
+ * Returned Value:
+ *   Zero on success, -1 on failure.
+ *
+ ****************************************************************************/
+
+int tab5_pi4ioe_init(void);
+
+/****************************************************************************
+ * Name: tab5_pi4ioe_high_write_pin
+ *
+ * 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.
+ *
+ * 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);
+#endif
+
+/****************************************************************************
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ESP32P4_TAB5_IOEXPANDER_LOW
+int tab5_pi4ioe_low_write_pin(uint8_t pin, bool enable);
+#endif
+#endif /* CONFIG_ESP32P4_TAB5_IOEXPANDER */
+
 #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 6d45a9c1b69..8de05b13a2d 100644
--- a/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_bringup.c
+++ b/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_bringup.c
@@ -42,6 +42,8 @@
 #  include "esp_board_i2c.h"
 #endif
 
+#include <arch/board/board.h>
+
 #include "esp32p4-tab5.h"
 
 /****************************************************************************
@@ -95,6 +97,17 @@ int esp_bringup(void)
     }
 #endif
 
+#ifdef CONFIG_ESP32P4_TAB5_IOEXPANDER
+  /* Initialize the IO expanders */
+
+  ret = tab5_pi4ioe_init();
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "Failed to initialize Tab5 IO expanders: %d\n", ret);
+      return ret;
+    }
+#endif
+
 #ifdef CONFIG_FS_TMPFS
   /* Mount the tmpfs file system */
 
diff --git a/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_ioexpander.c 
b/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_ioexpander.c
new file mode 100644
index 00000000000..71200944fb8
--- /dev/null
+++ b/boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_ioexpander.c
@@ -0,0 +1,163 @@
+/****************************************************************************
+ * boards/risc-v/esp32p4/esp32p4-tab5/src/esp32p4_ioexpander.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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <syslog.h>
+
+#include <nuttx/i2c/i2c_master.h>
+#include <nuttx/ioexpander/ioexpander.h>
+#include <nuttx/ioexpander/pi4ioe5v6408.h>
+
+#include "espressif/esp_i2c.h"
+
+#include <arch/board/board.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define TAB5_PI4IOE_FREQUENCY       400000
+
+/****************************************************************************
+ * 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 =
+{
+  .address   = PI4IOE5V6408_I2C_ADDRESS_HIGH,
+  .frequency = TAB5_PI4IOE_FREQUENCY,
+};
+static FAR struct ioexpander_dev_s *g_pi4ioe_high;
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: tab5_pi4ioe_init
+ *
+ * Description:
+ *   Initialize the IO expanders.
+ *
+ * Returned Value:
+ *   Zero on success, -1 on failure.
+ *
+ ****************************************************************************/
+
+int tab5_pi4ioe_init(void)
+{
+  FAR struct i2c_master_s *i2c;
+
+  i2c = esp_i2cbus_initialize(ESPRESSIF_I2C0);
+  if (i2c == NULL)
+    {
+      syslog(LOG_ERR, "tab5_pi4ioe_init: failed to get I2C0\n");
+      return -ENODEV;
+    }
+
+#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;
+    }
+
+  syslog(LOG_INFO, "tab5_pi4ioe_init: PI4IOE5V6408 (low) initialized\n");
+  #endif
+
+#ifdef CONFIG_ESP32P4_TAB5_IOEXPANDER_HIGH
+  g_pi4ioe_high = pi4ioe5v6408_initialize(i2c, &g_pi4ioe_config_high);
+  if (g_pi4ioe_high == NULL)
+    {
+      syslog(LOG_ERR, "tab5_pi4ioe_init: expander (high) init failed\n");
+      return -ENODEV;
+    }
+
+  syslog(LOG_INFO, "tab5_pi4ioe_init: PI4IOE5V6408 (high) initialized\n");
+#endif
+
+  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.
+ *
+ ****************************************************************************/
+
+#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
+ *
+ * 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.
+ *
+ * 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)
+{
+  return IOEXP_WRITEPIN(g_pi4ioe_high, pin, enable);
+}
+#endif

Reply via email to