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


The following commit(s) were added to refs/heads/master by this push:
     new 9e8197ad49 boards/risc-v: add MPU60x0 bringup support to ESP32C6
9e8197ad49 is described below

commit 9e8197ad499f626895e50aa70e453140c1f943b7
Author: Filipe Cavalcanti <filipe.cavalca...@espressif.com>
AuthorDate: Tue Apr 15 21:44:33 2025 -0300

    boards/risc-v: add MPU60x0 bringup support to ESP32C6
    
    Adds a defconfig for using MPU60x0 and implement the bringup sequence for 
the I2C IMU.
    
    Signed-off-by: Filipe Cavalcanti <filipe.cavalca...@espressif.com>
---
 .../esp32c6/common/include/esp_board_mpu60x0.h     |  75 ++++++++++++++
 boards/risc-v/esp32c6/common/src/Make.defs         |   4 +
 .../risc-v/esp32c6/common/src/esp_board_mpu60x0.c  | 108 +++++++++++++++++++++
 .../esp32c6-devkitc/configs/mpu60x0/defconfig      |  51 ++++++++++
 .../esp32c6/esp32c6-devkitc/src/esp32c6_bringup.c  |  16 +++
 5 files changed, 254 insertions(+)

diff --git a/boards/risc-v/esp32c6/common/include/esp_board_mpu60x0.h 
b/boards/risc-v/esp32c6/common/include/esp_board_mpu60x0.h
new file mode 100644
index 0000000000..91fb8db9e6
--- /dev/null
+++ b/boards/risc-v/esp32c6/common/include/esp_board_mpu60x0.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+ * boards/risc-v/esp32c6/common/include/esp_board_mpu60x0.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_ESP32C6_COMMON_INCLUDE_ESP_BOARD_MPU60X0_H
+#define __BOARDS_RISCV_ESP32C6_COMMON_INCLUDE_ESP_BOARD_MPU60X0_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_mpu60x0_initialize
+ *
+ * Description:
+ *   Initialize and register the MPU60x0 IMU Sensor driver.
+ *
+ * Input Parameters:
+ *   devno - The device number, used to build the device path as /dev/imuN
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SENSORS_MPU60X0
+int board_mpu60x0_initialize(int devno);
+#endif
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* __BOARDS_RISCV_ESP32C6_COMMON_INCLUDE_ESP_BOARD_MPU60X0_H */
diff --git a/boards/risc-v/esp32c6/common/src/Make.defs 
b/boards/risc-v/esp32c6/common/src/Make.defs
index d3b3f4c483..8e59200c65 100644
--- a/boards/risc-v/esp32c6/common/src/Make.defs
+++ b/boards/risc-v/esp32c6/common/src/Make.defs
@@ -82,6 +82,10 @@ ifeq ($(CONFIG_ESP_PCNT),y)
   CSRCS += esp_board_pcnt.c
 endif
 
+ifeq ($(CONFIG_SENSORS_MPU60X0),y)
+  CSRCS += esp_board_mpu60x0.c
+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/esp32c6/common/src/esp_board_mpu60x0.c 
b/boards/risc-v/esp32c6/common/src/esp_board_mpu60x0.c
new file mode 100644
index 0000000000..3e279d33b9
--- /dev/null
+++ b/boards/risc-v/esp32c6/common/src/esp_board_mpu60x0.c
@@ -0,0 +1,108 @@
+/****************************************************************************
+ * boards/risc-v/esp32c6/common/src/esp_board_mpu60x0.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 <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/sensors/mpu60x0.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_mpu60x0.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_mpu60x0_initialize
+ *
+ * Description:
+ *   Initialize and register the MPU60x0 IMU Sensor driver.
+ *
+ * Input Parameters:
+ *   devno - The device number, used to build the device path as /dev/imuN
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int board_mpu60x0_initialize(int devno)
+{
+  struct i2c_master_s *i2c;
+  struct mpu_config_s *config;
+  char devpath[12];
+  int ret;
+
+  sninfo("Initializing MPU60x0!\n");
+
+  /* Initialize MPU60x0 */
+
+#ifndef CONFIG_ESPRESSIF_I2C_BITBANG
+  i2c = esp_i2cbus_initialize(ESPRESSIF_I2C0);
+#else
+  i2c = esp_i2cbus_bitbang_initialize();
+#endif
+
+  config = kmm_zalloc(sizeof(struct mpu_config_s));
+  if (config == NULL)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to allocate mpu60x0 driver\n");
+      return -ENOMEM;
+    }
+  else
+    {
+      config->i2c = i2c;
+      config->addr = 0x68;
+    }
+
+  if (i2c != NULL)
+    {
+      /* Then try to register the barometer sensor in I2C0 */
+
+      snprintf(devpath, sizeof(devpath), "/dev/imu%d", devno);
+      ret = mpu60x0_register(devpath, config);
+      if (ret < 0)
+        {
+          syslog(LOG_ERR, "ERROR: Error registering MPU60x0 in I2C0\n");
+        }
+    }
+  else
+    {
+      ret = -ENODEV;
+    }
+
+  return ret;
+}
diff --git a/boards/risc-v/esp32c6/esp32c6-devkitc/configs/mpu60x0/defconfig 
b/boards/risc-v/esp32c6/esp32c6-devkitc/configs/mpu60x0/defconfig
new file mode 100644
index 0000000000..159e38da45
--- /dev/null
+++ b/boards/risc-v/esp32c6/esp32c6-devkitc/configs/mpu60x0/defconfig
@@ -0,0 +1,51 @@
+#
+# 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="risc-v"
+CONFIG_ARCH_BOARD="esp32c6-devkitc"
+CONFIG_ARCH_BOARD_COMMON=y
+CONFIG_ARCH_BOARD_ESP32C6_DEVKITC=y
+CONFIG_ARCH_CHIP="esp32c6"
+CONFIG_ARCH_CHIP_ESP32C6=y
+CONFIG_ARCH_CHIP_ESP32C6WROOM1=y
+CONFIG_ARCH_INTERRUPTSTACK=2048
+CONFIG_ARCH_RISCV=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_BOARDCTL_RESET=y
+CONFIG_BOARD_LOOPSPERMSEC=15000
+CONFIG_BUILTIN=y
+CONFIG_ESPRESSIF_ESP32C6=y
+CONFIG_ESPRESSIF_I2C0=y
+CONFIG_FS_PROCFS=y
+CONFIG_IDLETHREAD_STACKSIZE=2048
+CONFIG_INIT_ENTRYPOINT="nsh_main"
+CONFIG_INTELHEX_BINARY=y
+CONFIG_LIBC_PERROR_STDOUT=y
+CONFIG_LIBC_STRERROR=y
+CONFIG_MPU60X0_I2C=y
+CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
+CONFIG_NSH_ARCHINIT=y
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_READLINE=y
+CONFIG_NSH_STRERROR=y
+CONFIG_PREALLOC_TIMERS=0
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_BACKTRACE=y
+CONFIG_SCHED_WAITPID=y
+CONFIG_SENSORS=y
+CONFIG_SENSORS_MPU60X0=y
+CONFIG_START_DAY=29
+CONFIG_START_MONTH=11
+CONFIG_START_YEAR=2019
+CONFIG_SYSTEM_DUMPSTACK=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_TESTING_GETPRIME=y
+CONFIG_TESTING_OSTEST=y
+CONFIG_UART0_SERIAL_CONSOLE=y
diff --git a/boards/risc-v/esp32c6/esp32c6-devkitc/src/esp32c6_bringup.c 
b/boards/risc-v/esp32c6/esp32c6-devkitc/src/esp32c6_bringup.c
index 51bd4161b2..4f06e70d32 100644
--- a/boards/risc-v/esp32c6/esp32c6-devkitc/src/esp32c6_bringup.c
+++ b/boards/risc-v/esp32c6/esp32c6-devkitc/src/esp32c6_bringup.c
@@ -113,6 +113,10 @@
 #  include "esp_board_pcnt.h"
 #endif
 
+#ifdef CONFIG_SENSORS_MPU60X0
+#  include "esp_board_mpu60x0.h"
+#endif
+
 #ifdef CONFIG_SYSTEM_NXDIAG_ESPRESSIF_CHIP_WO_TOOL
 #  include "espressif/esp_nxdiag.h"
 #endif
@@ -311,6 +315,18 @@ int esp_bringup(void)
     }
 #endif
 
+#ifdef CONFIG_SENSORS_MPU60X0
+  /* Try to register MPU60x0 device in I2C0 */
+
+  ret = board_mpu60x0_initialize(0);
+
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "Failed to initialize MPU60x0 "
+             "Driver for I2C0: %d\n", ret);
+    }
+#endif
+
 #ifdef CONFIG_ESPRESSIF_TEMP
   struct esp_temp_sensor_config_t cfg = TEMPERATURE_SENSOR_CONFIG(10, 50);
   ret = esp_temperature_sensor_initialize(cfg);

Reply via email to