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

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

commit 106273a3700087f1e2e4fbf58a8d3524c96711ad
Author: Marcio Ribeiro <[email protected]>
AuthorDate: Wed Sep 9 17:50:58 2026 -0300

    boards/risc-v/esp32c2/common: add sensor and ROMFS board helpers
    
    Add BMP180/BMP280 helpers and ROMFS init scripts used by non-SoC
    board features.
    
    Assisted-by: Claude:claude-opus-5
    Signed-off-by: Marcio Ribeiro <[email protected]>
---
 .../esp32c2/common/include/esp_board_bmp180.h      | 76 +++++++++++++++++
 .../esp32c2/common/include/esp_board_bmp280.h      | 76 +++++++++++++++++
 boards/risc-v/esp32c2/common/src/CMakeLists.txt    | 24 ++++++
 boards/risc-v/esp32c2/common/src/Make.defs         | 12 +++
 .../risc-v/esp32c2/common/src/esp_board_bmp180.c   | 96 ++++++++++++++++++++++
 .../risc-v/esp32c2/common/src/esp_board_bmp280.c   | 94 +++++++++++++++++++++
 .../esp32c2/common/src/etc/init.d/rc.sysinit       | 27 ++++++
 boards/risc-v/esp32c2/common/src/etc/init.d/rcS    | 29 +++++++
 8 files changed, 434 insertions(+)

diff --git a/boards/risc-v/esp32c2/common/include/esp_board_bmp180.h 
b/boards/risc-v/esp32c2/common/include/esp_board_bmp180.h
new file mode 100644
index 00000000000..c9cb0402413
--- /dev/null
+++ b/boards/risc-v/esp32c2/common/include/esp_board_bmp180.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+ * boards/risc-v/esp32c2/common/include/esp_board_bmp180.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __BOARDS_RISCV_ESP32C2_COMMON_INCLUDE_ESP_BOARD_BMP180_H
+#define __BOARDS_RISCV_ESP32C2_COMMON_INCLUDE_ESP_BOARD_BMP180_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_bmp180_initialize
+ *
+ * Description:
+ *   Initialize and register the BMP180 Pressure Sensor driver.
+ *
+ * Input Parameters:
+ *   devno - The device number, used to build the device path as /dev/pressN
+ *
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SENSORS_BMP180
+int board_bmp180_initialize(int devno);
+#endif
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* __BOARDS_RISCV_ESP32C2_COMMON_INCLUDE_ESP_BOARD_BMP180_H */
diff --git a/boards/risc-v/esp32c2/common/include/esp_board_bmp280.h 
b/boards/risc-v/esp32c2/common/include/esp_board_bmp280.h
new file mode 100644
index 00000000000..3fa0d304492
--- /dev/null
+++ b/boards/risc-v/esp32c2/common/include/esp_board_bmp280.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+ * boards/risc-v/esp32c2/common/include/esp_board_bmp280.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __BOARDS_RISCV_ESP32C2_COMMON_INCLUDE_ESP_BOARD_BMP280_H
+#define __BOARDS_RISCV_ESP32C2_COMMON_INCLUDE_ESP_BOARD_BMP280_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_bmp280_initialize
+ *
+ * Description:
+ *   Initialize and register the BMP280 Pressure Sensor driver.
+ *
+ * Input Parameters:
+ *   devno - The device number, used to build the device path as /dev/pressN
+ *
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SENSORS_BMP280
+int board_bmp280_initialize(int devno);
+#endif
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* __BOARDS_RISCV_ESP32C2_COMMON_INCLUDE_ESP_BOARD_BMP280_H */
diff --git a/boards/risc-v/esp32c2/common/src/CMakeLists.txt 
b/boards/risc-v/esp32c2/common/src/CMakeLists.txt
index ba812a0a202..db66719071f 100644
--- a/boards/risc-v/esp32c2/common/src/CMakeLists.txt
+++ b/boards/risc-v/esp32c2/common/src/CMakeLists.txt
@@ -52,6 +52,14 @@ if(CONFIG_ARCH_BOARD_COMMON)
     list(APPEND SRCS esp_board_spiflash.c)
   endif()
 
+  if(CONFIG_SENSORS_BMP180)
+    list(APPEND SRCS esp_board_bmp180.c)
+  endif()
+
+  if(CONFIG_SENSORS_BMP280)
+    list(APPEND SRCS esp_board_bmp280.c)
+  endif()
+
   if(CONFIG_DEV_RNG90)
     list(APPEND SRCS esp_board_rng90.c)
   endif()
@@ -60,6 +68,22 @@ if(CONFIG_ARCH_BOARD_COMMON)
     list(APPEND SRCS esp_board_mmcsd.c)
   endif()
 
+  # Handle ROMFS init scripts
+  if(CONFIG_ETC_ROMFS)
+    nuttx_add_romfs(
+      NAME
+      etc
+      MOUNTPOINT
+      etc
+      RCSRCS
+      etc/init.d/rcS
+      etc/init.d/rc.sysinit
+      PATH
+      ${CMAKE_CURRENT_BINARY_DIR}/etc)
+
+    target_link_libraries(board PRIVATE romfs_etc)
+  endif()
+
 endif()
 
 target_sources(board PRIVATE ${SRCS})
diff --git a/boards/risc-v/esp32c2/common/src/Make.defs 
b/boards/risc-v/esp32c2/common/src/Make.defs
index 313eb74f283..3cec1ba59e8 100644
--- a/boards/risc-v/esp32c2/common/src/Make.defs
+++ b/boards/risc-v/esp32c2/common/src/Make.defs
@@ -50,6 +50,14 @@ ifeq ($(CONFIG_ESPRESSIF_SPIFLASH),y)
   CSRCS += esp_board_spiflash.c
 endif
 
+ifeq ($(CONFIG_SENSORS_BMP180),y)
+  CSRCS += esp_board_bmp180.c
+endif
+
+ifeq ($(CONFIG_SENSORS_BMP280),y)
+  CSRCS += esp_board_bmp280.c
+endif
+
 ifeq ($(CONFIG_DEV_RNG90),y)
   CSRCS += esp_board_rng90.c
 endif
@@ -58,6 +66,10 @@ ifeq ($(CONFIG_MMCSD_SPI),y)
   CSRCS += esp_board_mmcsd.c
 endif
 
+ifeq ($(CONFIG_ETC_ROMFS),y)
+  RCSRCS  = etc/init.d/rc.sysinit etc/init.d/rcS
+endif
+
 DEPPATH += --dep-path src
 VPATH += :src
 CFLAGS += 
${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src
diff --git a/boards/risc-v/esp32c2/common/src/esp_board_bmp180.c 
b/boards/risc-v/esp32c2/common/src/esp_board_bmp180.c
new file mode 100644
index 00000000000..a3674d3719b
--- /dev/null
+++ b/boards/risc-v/esp32c2/common/src/esp_board_bmp180.c
@@ -0,0 +1,96 @@
+/****************************************************************************
+ * boards/risc-v/esp32c2/common/src/esp_board_bmp180.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 <stdio.h>
+#include <nuttx/debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/sensors/bmp180.h>
+#include <nuttx/i2c/i2c_master.h>
+
+#ifndef CONFIG_ESPRESSIF_I2C_BITBANG
+#include "espressif/esp_i2c.h"
+#else
+#include "espressif/esp_i2c_bitbang.h"
+#endif
+
+#include "esp_board_bmp180.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_bmp180_initialize
+ *
+ * Description:
+ *   Initialize and register the BMP180 Pressure Sensor driver.
+ *
+ * Input Parameters:
+ *   devno - The device number, used to build the device path as /dev/pressN
+ *
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int board_bmp180_initialize(int devno)
+{
+  struct i2c_master_s *i2c;
+  char devpath[12];
+  int ret;
+
+  sninfo("Initializing BMP180!\n");
+
+  /* Initialize BMP180 */
+
+#ifndef CONFIG_ESPRESSIF_I2C_BITBANG
+  i2c = esp_i2cbus_initialize(ESPRESSIF_I2C0);
+#else
+  i2c = esp_i2cbus_bitbang_initialize();
+#endif
+
+  if (i2c)
+    {
+      /* Then try to register the barometer sensor in I2C0 */
+
+      snprintf(devpath, sizeof(devpath), "/dev/press%d", devno);
+      ret = bmp180_register(devpath, i2c);
+      if (ret < 0)
+        {
+          snerr("ERROR: Error registering BMP180 in I2C0\n");
+        }
+    }
+  else
+    {
+      ret = -ENODEV;
+    }
+
+  return ret;
+}
diff --git a/boards/risc-v/esp32c2/common/src/esp_board_bmp280.c 
b/boards/risc-v/esp32c2/common/src/esp_board_bmp280.c
new file mode 100644
index 00000000000..8dfcf326cf5
--- /dev/null
+++ b/boards/risc-v/esp32c2/common/src/esp_board_bmp280.c
@@ -0,0 +1,94 @@
+/****************************************************************************
+ * boards/risc-v/esp32c2/common/src/esp_board_bmp280.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 <stdio.h>
+#include <nuttx/debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/sensors/bmp280.h>
+#include <nuttx/i2c/i2c_master.h>
+
+#ifndef CONFIG_ESPRESSIF_I2C_BITBANG
+#include "espressif/esp_i2c.h"
+#else
+#include "espressif/esp_i2c_bitbang.h"
+#endif
+
+#include "esp_board_bmp280.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_bmp280_initialize
+ *
+ * Description:
+ *   Initialize and register the BMP280 Pressure Sensor driver.
+ *
+ * Input Parameters:
+ *   devno - The device number, used to build the device path as /dev/pressN
+ *
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int board_bmp280_initialize(int devno)
+{
+  struct i2c_master_s *i2c;
+  int ret;
+
+  sninfo("Initializing BMP280!\n");
+
+  /* Initialize I2C */
+
+#ifndef CONFIG_ESPRESSIF_I2C_BITBANG
+  i2c = esp_i2cbus_initialize(ESPRESSIF_I2C0);
+#else
+  i2c = esp_i2cbus_bitbang_initialize();
+#endif
+
+  if (i2c)
+    {
+      /* Then try to register the barometer sensor in I2C0 */
+
+      ret = bmp280_register(devno, i2c);
+      if (ret < 0)
+        {
+          snerr("ERROR: Error registering BMP280 in I2C0\n");
+        }
+    }
+  else
+    {
+      ret = -ENODEV;
+    }
+
+  return ret;
+}
diff --git a/boards/risc-v/esp32c2/common/src/etc/init.d/rc.sysinit 
b/boards/risc-v/esp32c2/common/src/etc/init.d/rc.sysinit
new file mode 100644
index 00000000000..3fcb3d91adb
--- /dev/null
+++ b/boards/risc-v/esp32c2/common/src/etc/init.d/rc.sysinit
@@ -0,0 +1,27 @@
+/****************************************************************************
+ * boards/risc-v/esp32c3/common/src/etc/init.d/rc.sysinit
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/* This script "rc.sysinit" is executed after the board bring up. */
+
+echo "rc.sysinit is called!"
diff --git a/boards/risc-v/esp32c2/common/src/etc/init.d/rcS 
b/boards/risc-v/esp32c2/common/src/etc/init.d/rcS
new file mode 100644
index 00000000000..2a2fa63c13b
--- /dev/null
+++ b/boards/risc-v/esp32c2/common/src/etc/init.d/rcS
@@ -0,0 +1,29 @@
+/****************************************************************************
+ * boards/risc-v/esp32c3/common/src/etc/init.d/rcS
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/* This script "rcS" is executed after the rc.sysinit script.
+ * It should startup some application and other system service.
+ */
+
+echo "rcS file is called!"

Reply via email to