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 af4a065efb43e547e5e6efc1aef7960dda16e382
Author: raiden00pl <[email protected]>
AuthorDate: Sat Aug 26 15:46:03 2023 +0200

    nrf52840-dk: add lsm9ds1 sensor support
---
 boards/arm/nrf52/common/include/nrf52_lsm9ds1.h  | 46 +++++++++++
 boards/arm/nrf52/common/src/CMakeLists.txt       |  4 +
 boards/arm/nrf52/common/src/Make.defs            |  4 +
 boards/arm/nrf52/common/src/nrf52_lsm9ds1.c      | 97 ++++++++++++++++++++++++
 boards/arm/nrf52/nrf52840-dk/src/nrf52_bringup.c | 16 +++-
 5 files changed, 166 insertions(+), 1 deletion(-)

diff --git a/boards/arm/nrf52/common/include/nrf52_lsm9ds1.h 
b/boards/arm/nrf52/common/include/nrf52_lsm9ds1.h
new file mode 100644
index 0000000000..80f79c9c51
--- /dev/null
+++ b/boards/arm/nrf52/common/include/nrf52_lsm9ds1.h
@@ -0,0 +1,46 @@
+/****************************************************************************
+ * boards/arm/nrf52/common/include/nrf52_lsm9ds1.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_NRF52_COMMON_INCLUDE_NRF52_LSM9DS1_H
+#define __BOARDS_ARM_NRF52_COMMON_INCLUDE_NRF52_LSM9DS1_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Public Functions Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nrf52_lsm9ds1_initialize
+ *
+ * Description:
+ *   Initialize I2C-based LSM9DS1.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SENSORS_LSM9DS1
+int nrf52_lsm9ds1_initialize(int bus);
+#endif
+
+#endif /* __BOARDS_ARM_NRF52_COMMON_INCLUDE_NRF52_LSM9DS1_H */
diff --git a/boards/arm/nrf52/common/src/CMakeLists.txt 
b/boards/arm/nrf52/common/src/CMakeLists.txt
index 5a2844de3e..7c3d75b759 100644
--- a/boards/arm/nrf52/common/src/CMakeLists.txt
+++ b/boards/arm/nrf52/common/src/CMakeLists.txt
@@ -32,6 +32,10 @@ if(CONFIG_ARCH_BOARD_COMMON)
     list(APPEND SRCS nrf52_progmem.c)
   endif()
 
+  if(CONFIG_SENSORS_LSM9DS1)
+    list(APPEND SRCS nrf52_lsm9ds1.c)
+  endif()
+
   target_sources(board PRIVATE ${SRCS})
 
 endif()
diff --git a/boards/arm/nrf52/common/src/Make.defs 
b/boards/arm/nrf52/common/src/Make.defs
index 7656988081..07994dc14a 100644
--- a/boards/arm/nrf52/common/src/Make.defs
+++ b/boards/arm/nrf52/common/src/Make.defs
@@ -32,6 +32,10 @@ ifeq ($(CONFIG_NRF52_PROGMEM),y)
   CSRCS += nrf52_progmem.c
 endif
 
+ifeq ($(CONFIG_SENSORS_LSM9DS1),y)
+CSRCS += nrf52_lsm9ds1.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/arm/nrf52/common/src/nrf52_lsm9ds1.c 
b/boards/arm/nrf52/common/src/nrf52_lsm9ds1.c
new file mode 100644
index 0000000000..af6ba01b3d
--- /dev/null
+++ b/boards/arm/nrf52/common/src/nrf52_lsm9ds1.c
@@ -0,0 +1,97 @@
+/****************************************************************************
+ * boards/arm/nrf52/common/src/nrf52_lsm9ds1.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 <nuttx/arch.h>
+
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/board.h>
+#include "nrf52_i2c.h"
+#include <nuttx/sensors/lsm9ds1.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define LSM9DS1MAG_DEVPATH "/dev/lsm9ds1mag0"
+#define LSM9DS1ACC_DEVPATH "/dev/lsm9ds1acc0"
+#define LSM9DS1GYR_DEVPATH "/dev/lsm9ds1gyr0"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nrf52_lsm9ds1_initialize
+ *
+ * Description:
+ *   Initialize I2C-based LSM9DS1.
+ *
+ ****************************************************************************/
+
+int nrf52_lsm9ds1_initialize(int bus)
+{
+  struct i2c_master_s *i2c;
+  int ret = OK;
+
+  sninfo("Initializing LMS6DSL!\n");
+
+  i2c = nrf52_i2cbus_initialize(bus);
+  if (i2c == NULL)
+    {
+      return -ENODEV;
+    }
+
+  sninfo("INFO: Initializing LMS9DS1 9DoF sensor over I2C%d\n", bus);
+
+  /* Register snesors as character devices */
+
+  ret = lsm9ds1mag_register(LSM9DS1MAG_DEVPATH, i2c, LSM9DS1MAG_ADDR1);
+  if (ret < 0)
+    {
+      snerr("ERROR: Failed to initialize LMS9DS1 mag driver %s\n",
+            LSM9DS1MAG_DEVPATH);
+      return -ENODEV;
+    }
+
+  ret = lsm9ds1gyro_register(LSM9DS1GYR_DEVPATH, i2c, LSM9DS1GYRO_ADDR1);
+  if (ret < 0)
+    {
+      snerr("ERROR: Failed to initialize LMS9DS1 gyro driver %s\n",
+            LSM9DS1MAG_DEVPATH);
+      return -ENODEV;
+    }
+
+  ret = lsm9ds1accel_register(LSM9DS1ACC_DEVPATH, i2c, LSM9DS1ACCEL_ADDR1);
+  if (ret < 0)
+    {
+      snerr("ERROR: Failed to initialize LMS9DS1 accel driver %s\n",
+            LSM9DS1MAG_DEVPATH);
+      return -ENODEV;
+    }
+
+  return ret;
+}
diff --git a/boards/arm/nrf52/nrf52840-dk/src/nrf52_bringup.c 
b/boards/arm/nrf52/nrf52840-dk/src/nrf52_bringup.c
index cc2ceac865..f59b7b7a97 100644
--- a/boards/arm/nrf52/nrf52840-dk/src/nrf52_bringup.c
+++ b/boards/arm/nrf52/nrf52840-dk/src/nrf52_bringup.c
@@ -57,13 +57,18 @@
 #  include "nrf52_sdc.h"
 #endif
 
+#ifdef CONFIG_SENSORS_LSM9DS1
+#  include "nrf52_lsm9ds1.h"
+#endif
+
 #include "nrf52840-dk.h"
 
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define NRF52_TIMER (0)
+#define NRF52_TIMER    (0)
+#define LMS9DS1_I2CBUS (0)
 
 /****************************************************************************
  * Public Functions
@@ -295,6 +300,15 @@ int nrf52_bringup(void)
     }
 #endif /* CONFIG_MTD */
 
+#ifdef CONFIG_SENSORS_LSM9DS1
+  ret = nrf52_lsm9ds1_initialize(LMS9DS1_I2CBUS);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to initialize LSM9DS1 driver: %d\n",
+             ret);
+    }
+#endif /* CONFIG_SENSORS_LSM6DSL */
+
   UNUSED(ret);
   return OK;
 }

Reply via email to