mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 22:20:01 +08:00
Merged in alinjerpelea/nuttx (pull request #912)
configs: spresense: enable BMI160_I2C sensor
* drivers: sensors: add BMI160 driver
Enable driver support for the Bosch BMI160 Inertial
Measurement sensor
This driver can be used with the BMI160 sensor connected over
SPI or I2C bus
Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
* configs: spresense: enable BMI160_I2C sensor
Enable BMI160 sensor connected over I2C on spresense board
Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
committed by
Gregory Nutt
parent
af9b70ca5d
commit
977893d5a7
@@ -49,6 +49,7 @@
|
||||
#include "cxd56_power.h"
|
||||
#include "cxd56_flash.h"
|
||||
#include "cxd56_gs2200m.h"
|
||||
#include "cxd56_bmi160.h"
|
||||
#include "cxd56_sdcard.h"
|
||||
#include "cxd56_wdt.h"
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
* configs/spresense/include/cxd56_bmi160.h
|
||||
*
|
||||
* Copyright 2018 Sony Semiconductor Solutions Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name of Sony Semiconductor Solutions Corporation nor
|
||||
* the names of its contributors may be used to endorse or promote
|
||||
* products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __BOARD_COMMON_INCLUDE_CXD56_BMI160_H
|
||||
#define __BOARD_COMMON_INCLUDE_CXD56_BMI160_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_bmi160_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize BMI160 i2c driver and register the BMI160 device.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_bmi160_initialize(int bus);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __BOARD_COMMON_INCLUDE_CXD56_BMI160_H */
|
||||
@@ -92,4 +92,8 @@ ifeq ($(CONFIG_WL_GS2200M),y)
|
||||
CSRCS += cxd56_gs2200m.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_BMI160_I2C),y)
|
||||
CSRCS += cxd56_bmi160_i2c.c
|
||||
endif
|
||||
|
||||
include $(TOPDIR)/configs/Board.mk
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/****************************************************************************
|
||||
* configs/spresense/src/cxd56_bmi160_i2c.c
|
||||
*
|
||||
* Copyright 2018 Sony Semiconductor Solutions Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name of Sony Semiconductor Solutions Corporation nor
|
||||
* the names of its contributors may be used to endorse or promote
|
||||
* products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/board.h>
|
||||
#include <nuttx/sensors/bmi160.h>
|
||||
|
||||
#include "cxd56_i2c.h"
|
||||
|
||||
#ifdef CONFIG_CXD56_DECI_GYRO
|
||||
#define GYRO_NR_SEQS 3
|
||||
#else
|
||||
#define GYRO_NR_SEQS 1
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CXD56_DECI_ACCEL
|
||||
#define ACCEL_NR_SEQS 3
|
||||
#else
|
||||
#define ACCEL_NR_SEQS 1
|
||||
#endif
|
||||
|
||||
int board_bmi160_initialize(int bus)
|
||||
{
|
||||
int ret;
|
||||
FAR struct i2c_master_s *i2c;
|
||||
|
||||
sninfo("Initializing BMI160..\n");
|
||||
|
||||
/* Initialize i2c deivce */
|
||||
|
||||
i2c = cxd56_i2cbus_initialize(bus);
|
||||
if (!i2c)
|
||||
{
|
||||
snerr("ERROR: Failed to initialize i2c%d.\n", bus);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = bmi160_register("/dev/accel0", i2c);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("Error registering BMI160\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -346,5 +346,13 @@ int cxd56_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SENSORS_BMI160_I2C
|
||||
ret = board_bmi160_initialize(0);
|
||||
if (ret < 0)
|
||||
{
|
||||
_err("ERROR: Failed to initialze BMI160. \n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,36 @@ config SENSORS_BMG160
|
||||
---help---
|
||||
Enable driver support for the Bosch BMG160 gyroscope sensor.
|
||||
|
||||
|
||||
config SENSORS_BMI160
|
||||
bool "Bosch BMI160 Inertial Measurement Sensor support"
|
||||
default n
|
||||
select I2C
|
||||
---help---
|
||||
Enable driver support for the Bosch BMI160 Inertial
|
||||
Measurement sensor
|
||||
|
||||
if SENSORS_BMI160
|
||||
|
||||
choice
|
||||
prompt "BMI160 Interface"
|
||||
default SENSORS_BMI160_SPI
|
||||
|
||||
config SENSORS_BMI160_I2C
|
||||
bool "BMI160 I2C Interface"
|
||||
select I2C
|
||||
---help---
|
||||
Enables support for the I2C interface
|
||||
|
||||
config SENSORS_BMI160_SPI
|
||||
bool "BMI160 SPI Interface"
|
||||
select SPI
|
||||
---help---
|
||||
Enables support for the SPI interface
|
||||
|
||||
endchoice
|
||||
endif
|
||||
|
||||
config SENSORS_BMP180
|
||||
bool "Bosch BMP180 Barometer Sensor support"
|
||||
default n
|
||||
|
||||
@@ -105,6 +105,10 @@ ifeq ($(CONFIG_SENSORS_BMG160),y)
|
||||
CSRCS += bmg160.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_BMI160),y)
|
||||
CSRCS += bmi160.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_BMP180),y)
|
||||
CSRCS += bmp180.c
|
||||
endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,148 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/sensors/bmi160.h
|
||||
*
|
||||
* Copyright 2018 Sony Semiconductor Solutions Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name of Sony Semiconductor Solutions Corporation nor
|
||||
* the names of its contributors may be used to endorse or promote
|
||||
* products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_SENSORS_BMI160_H
|
||||
#define __INCLUDE_NUTTX_SENSORS_BMI160_H
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define BMI160_SPI_MAXFREQUENCY 10000000
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
/* Power mode */
|
||||
|
||||
#define BMI160_PM_SUSPEND (0x00)
|
||||
#define BMI160_PM_NORMAL (0x01)
|
||||
#define BMI160_PM_LOWPOWER (0x02)
|
||||
#define BMI160_PM_FASTSTARTUP (0x03)
|
||||
|
||||
/* Output data rate */
|
||||
|
||||
#define BMI160_ACCEL_ODR_0_78HZ (0x01)
|
||||
#define BMI160_ACCEL_ODR_1_56HZ (0x02)
|
||||
#define BMI160_ACCEL_ODR_3_12HZ (0x03)
|
||||
#define BMI160_ACCEL_ODR_6_25HZ (0x04)
|
||||
#define BMI160_ACCEL_ODR_12_5HZ (0x05)
|
||||
#define BMI160_ACCEL_ODR_25HZ (0x06)
|
||||
#define BMI160_ACCEL_ODR_50HZ (0x07)
|
||||
#define BMI160_ACCEL_ODR_100HZ (0x08)
|
||||
#define BMI160_ACCEL_ODR_200HZ (0x09)
|
||||
#define BMI160_ACCEL_ODR_400HZ (0x0A)
|
||||
#define BMI160_ACCEL_ODR_800HZ (0x0B)
|
||||
#define BMI160_ACCEL_ODR_1600HZ (0x0C)
|
||||
|
||||
/* IOCTL Commands ***********************************************************/
|
||||
|
||||
#define SNIOC_ENABLESC _SNIOC(0x0001) /* Arg: uint8_t value */
|
||||
#define SNIOC_READSC _SNIOC(0x0002) /* Arg: int16_t* pointer */
|
||||
#define SNIOC_SETACCPM _SNIOC(0x0003) /* Arg: uint8_t value */
|
||||
#define SNIOC_SETACCODR _SNIOC(0x0004) /* Arg: uint8_t value */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
* struct 6-axis data
|
||||
****************************************************************************/
|
||||
struct accel_t
|
||||
{
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
int16_t z;
|
||||
};
|
||||
|
||||
struct gyro_t
|
||||
{
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
int16_t z;
|
||||
};
|
||||
|
||||
struct accel_gyro_st_s
|
||||
{
|
||||
struct gyro_t gyro;
|
||||
struct accel_t accel;
|
||||
uint32_t sensor_time;
|
||||
};
|
||||
|
||||
struct spi_dev_s;
|
||||
struct i2c_master_s;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bmi160_register
|
||||
*
|
||||
* Description:
|
||||
* Register the BMI160 character device as 'devpath'
|
||||
*
|
||||
* Input Parameters:
|
||||
* devpath - The full path to the driver to register. E.g., "/dev/accel0"
|
||||
* dev - An instance of the SPI or I2C interface to use to communicate
|
||||
* with BMI160
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
# ifdef CONFIG_SENSORS_BMI160_I2C
|
||||
int bmi160_register(FAR const char *devpath, FAR struct i2c_master_s *dev);
|
||||
# else
|
||||
int bmi160_register(FAR const char *devpath, FAR struct spi_dev_s *dev);
|
||||
# endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_SENSORS_BMI160_H */
|
||||
Reference in New Issue
Block a user