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

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

commit a015aa4fca69518b935bb3e59c65b28320dd9e6c
Author: SPRESENSE <[email protected]>
AuthorDate: Tue Aug 29 19:49:52 2023 +0900

    boards: cxd56xx: Add board-specific driver for bmi270
---
 boards/arm/cxd56xx/common/CMakeLists.txt           |  4 ++
 boards/arm/cxd56xx/common/src/Make.defs            |  4 ++
 boards/arm/cxd56xx/common/src/cxd56_bmi270_i2c.c   | 69 ++++++++++++++++++++++
 boards/arm/cxd56xx/common/src/cxd56_sensors.c      | 15 ++++-
 boards/arm/cxd56xx/spresense/include/board.h       |  1 +
 .../arm/cxd56xx/spresense/include/cxd56_bmi270.h   | 69 ++++++++++++++++++++++
 drivers/sensors/bmi270.c                           |  2 +-
 7 files changed, 162 insertions(+), 2 deletions(-)

diff --git a/boards/arm/cxd56xx/common/CMakeLists.txt 
b/boards/arm/cxd56xx/common/CMakeLists.txt
index 3f7e4165ec..4ed42aa228 100644
--- a/boards/arm/cxd56xx/common/CMakeLists.txt
+++ b/boards/arm/cxd56xx/common/CMakeLists.txt
@@ -79,6 +79,10 @@ if(CONFIG_ARCH_BOARD_COMMON)
     list(APPEND SRCS src/cxd56_bmi160_i2c.c)
   endif()
 
+  if(CONFIG_SENSORS_BMI270_I2C)
+    list(APPEND SRCS src/cxd56_bmi270_i2c.c)
+  endif()
+
   if(CONFIG_SENSORS_BMI160_SCU)
     list(APPEND SRCS src/cxd56_bmi160_scu.c)
   endif()
diff --git a/boards/arm/cxd56xx/common/src/Make.defs 
b/boards/arm/cxd56xx/common/src/Make.defs
index f518d2d630..f118b89607 100644
--- a/boards/arm/cxd56xx/common/src/Make.defs
+++ b/boards/arm/cxd56xx/common/src/Make.defs
@@ -88,6 +88,10 @@ ifeq ($(CONFIG_SENSORS_BMI160_SPI),y)
 CSRCS += cxd56_bmi160_spi.c
 endif
 
+ifeq ($(CONFIG_SENSORS_BMI270_I2C),y)
+CSRCS += cxd56_bmi270_i2c.c
+endif
+
 ifeq ($(CONFIG_SENSORS_BMP280),y)
 CSRCS += cxd56_bmp280_i2c.c
 endif
diff --git a/boards/arm/cxd56xx/common/src/cxd56_bmi270_i2c.c 
b/boards/arm/cxd56xx/common/src/cxd56_bmi270_i2c.c
new file mode 100644
index 0000000000..9ba10d364a
--- /dev/null
+++ b/boards/arm/cxd56xx/common/src/cxd56_bmi270_i2c.c
@@ -0,0 +1,69 @@
+/****************************************************************************
+ * boards/arm/cxd56xx/common/src/cxd56_bmi270_i2c.c
+ *
+ * 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 <errno.h>
+
+#include <nuttx/board.h>
+#include <nuttx/sensors/bmi270.h>
+
+#include "cxd56_i2c.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BMI270_I2C_ADDRESS  (0x69)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int board_bmi270_initialize(int bus)
+{
+  int ret;
+  struct i2c_master_s *i2c;
+
+  sninfo("Initializing BMI270..\n");
+
+  /* Initialize i2c device */
+
+  i2c = cxd56_i2cbus_initialize(bus);
+  if (!i2c)
+    {
+      snerr("ERROR: Failed to initialize i2c%d.\n", bus);
+      return -ENODEV;
+    }
+
+  ret = bmi270_register("/dev/accel0", i2c, BMI270_I2C_ADDRESS);
+  if (ret < 0)
+    {
+      snerr("Error registering BMI270\n");
+    }
+
+  return ret;
+}
diff --git a/boards/arm/cxd56xx/common/src/cxd56_sensors.c 
b/boards/arm/cxd56xx/common/src/cxd56_sensors.c
index 741d07dc40..407906887a 100644
--- a/boards/arm/cxd56xx/common/src/cxd56_sensors.c
+++ b/boards/arm/cxd56xx/common/src/cxd56_sensors.c
@@ -53,6 +53,12 @@
 #  define _BMI160  0
 #endif
 
+#if defined(CONFIG_SENSORS_BMI270) || defined(CONFIG_SENSORS_BMI270_SCU)
+#  define _BMI270  1
+#else
+#  define _BMI270  0
+#endif
+
 #if defined(CONFIG_SENSORS_KX022) || defined(CONFIG_SENSORS_KX022_SCU)
 #  define _KX022  1
 #else
@@ -107,7 +113,7 @@
 #  define _RPR0521RS  0
 #endif
 
-#if (_BMI160 + _KX022) > 1
+#if (_BMI160 + _BMI270 + _KX022) > 1
 #  error "Duplicate accelerometer sensor device."
 #endif
 
@@ -183,6 +189,13 @@ static struct sensor_device_s sensor_device[] =
   _SPI_DEVICE_WOPATH(bmi160),
 #  endif
 #endif
+#if defined(CONFIG_SENSORS_BMI270) || defined(CONFIG_SENSORS_BMI270_SCU)
+#  if defined(CONFIG_SENSORS_BMI270_I2C) || 
defined(CONFIG_SENSORS_BMI270_SCU_I2C)
+  _I2C_DEVICE_WOPATH(bmi270),
+#  else /* CONFIG_SENSORS_BMI270_SPI */
+  _SPI_DEVICE_WOPATH(bmi270),
+#  endif
+#endif
 #if defined(CONFIG_SENSORS_KX022) || defined(CONFIG_SENSORS_KX022_SCU)
   _I2C_DEVICE(kx022, "/dev/accel"), /* Accel */
 #endif
diff --git a/boards/arm/cxd56xx/spresense/include/board.h 
b/boards/arm/cxd56xx/spresense/include/board.h
index 64a42cfeb4..76e196faf2 100644
--- a/boards/arm/cxd56xx/spresense/include/board.h
+++ b/boards/arm/cxd56xx/spresense/include/board.h
@@ -57,6 +57,7 @@
 #include "cxd56_bm1383glv.h"
 #include "cxd56_bm1422gmv.h"
 #include "cxd56_bmi160.h"
+#include "cxd56_bmi270.h"
 #include "cxd56_bmp280.h"
 #include "cxd56_emmcdev.h"
 #include "cxd56_spisd.h"
diff --git a/boards/arm/cxd56xx/spresense/include/cxd56_bmi270.h 
b/boards/arm/cxd56xx/spresense/include/cxd56_bmi270.h
new file mode 100644
index 0000000000..4359811f4c
--- /dev/null
+++ b/boards/arm/cxd56xx/spresense/include/cxd56_bmi270.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+ * boards/arm/cxd56xx/spresense/include/cxd56_bmi270.h
+ *
+ * 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_ARM_CXD56XX_SPRESENSE_INCLUDE_CXD56_BMI270_H
+#define __BOARDS_ARM_CXD56XX_SPRESENSE_INCLUDE_CXD56_BMI270_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_bmi270_initialize
+ *
+ * Description:
+ *   Initialize BMI270 i2c driver and register the BMI270 device.
+ *
+ ****************************************************************************/
+
+int board_bmi270_initialize(int bus);
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* __BOARDS_ARM_CXD56XX_SPRESENSE_INCLUDE_CXD56_BMI270_H */
diff --git a/drivers/sensors/bmi270.c b/drivers/sensors/bmi270.c
index 1b3ba7bbcd..59686150e4 100644
--- a/drivers/sensors/bmi270.c
+++ b/drivers/sensors/bmi270.c
@@ -1241,7 +1241,7 @@ static int bmi270_init_seq(FAR struct bmi270_dev_s *priv)
   FAR uint8_t *tmp    = NULL;
   uint8_t      regval = 0;
 
-  /* Check if initalization already done */
+  /* Check if initialization already done */
 
   regval = bmi270_getreg8(priv, BMI270_INTERNAL_STAT);
   if ((regval & INTSTAT_MSG_MASK) == INTSTAT_MSG_INITOK)

Reply via email to