nrf52840-dk: add lsm9ds1 sensor support

This commit is contained in:
raiden00pl 2023-08-26 15:46:03 +02:00 committed by Xiang Xiao
parent 8665acaffa
commit af4a065efb
5 changed files with 166 additions and 1 deletions

View File

@ -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 */

View File

@ -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()

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}