Sync betaflight to Gitea
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= accel.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,200 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Earth's gravity in m/s^2 */
|
||||
#define GRAVITY_EARTH (9.80665f)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] g_range : Gravity range.
|
||||
* @param[in] bit_width : Resolution for accel.
|
||||
*
|
||||
* @return Gravity.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to define limit to print accel data. */
|
||||
uint8_t limit = 20;
|
||||
|
||||
/* Assign accel sensor to variable. */
|
||||
uint8_t sensor_list = BMI2_ACCEL;
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Create an instance of sensor data structure. */
|
||||
struct bmi2_sensor_data sensor_data = { 0 };
|
||||
|
||||
/* Initialize the interrupt status of accel. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint8_t indx = 0;
|
||||
float x = 0, y = 0, z = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the accel sensor. */
|
||||
rslt = bmi270_sensor_enable(&sensor_list, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Accel configuration settings. */
|
||||
rslt = set_accel_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Assign accel sensor. */
|
||||
sensor_data.type = BMI2_ACCEL;
|
||||
printf("Accel and m/s2 data \n");
|
||||
printf("Accel data collected at 2G Range with 16-bit resolution\n");
|
||||
|
||||
/* Loop to print the accel data when interrupt occurs. */
|
||||
while (indx <= limit)
|
||||
{
|
||||
/* To get the status of accel data ready interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the accel data ready interrupt status and print the status for 10 samples. */
|
||||
if (int_status & BMI2_ACC_DRDY_INT_MASK)
|
||||
{
|
||||
/* Get accelerometer data for x, y and z axis. */
|
||||
rslt = bmi270_get_sensor_data(&sensor_data, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
printf("\nAcc_X = %d\t", sensor_data.sens_data.acc.x);
|
||||
printf("Acc_Y = %d\t", sensor_data.sens_data.acc.y);
|
||||
printf("Acc_Z = %d\r\n", sensor_data.sens_data.acc.z);
|
||||
|
||||
/* Converting lsb to meter per second squared for 16 bit accelerometer at 2G range. */
|
||||
x = lsb_to_mps2(sensor_data.sens_data.acc.x, 2, bmi2_dev.resolution);
|
||||
y = lsb_to_mps2(sensor_data.sens_data.acc.y, 2, bmi2_dev.resolution);
|
||||
z = lsb_to_mps2(sensor_data.sens_data.acc.z, 2, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in m/s2. */
|
||||
printf("\nAcc_ms2_X = %4.2f, Acc_ms2_Y = %4.2f, Acc_ms2_Z = %4.2f\n", x, y, z);
|
||||
|
||||
indx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*/
|
||||
static int8_t set_accel_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accelerometer configuration. */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config.type = BMI2_ACCEL;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_get_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config.cfg.acc.odr = BMI2_ACC_ODR_200HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config.cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples.
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config.cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config.cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set the accel configurations. */
|
||||
rslt = bmi270_set_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Map data ready interrupt to interrupt pin. */
|
||||
rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (GRAVITY_EARTH * val * g_range) / half_scale;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= accel_gyro.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,268 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Earth's gravity in m/s^2 */
|
||||
#define GRAVITY_EARTH (9.80665f)
|
||||
|
||||
/*! Macros to select the sensors */
|
||||
#define ACCEL UINT8_C(0x00)
|
||||
#define GYRO UINT8_C(0x01)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] g_range : Gravity range.
|
||||
* @param[in] bit_width : Resolution for accel.
|
||||
*
|
||||
* @return Gravity.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] dps : Degree per second.
|
||||
* @param[in] bit_width : Resolution for gyro.
|
||||
*
|
||||
* @return Degree per second.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to define limit to print accel data. */
|
||||
uint8_t limit = 10;
|
||||
|
||||
/* Assign accel and gyro sensor to variable. */
|
||||
uint8_t sensor_list[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Create an instance of sensor data structure. */
|
||||
struct bmi2_sensor_data sensor_data[2] = { { 0 } };
|
||||
|
||||
/* Initialize the interrupt status of accel and gyro. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint8_t indx = 1;
|
||||
|
||||
float x = 0, y = 0, z = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_SPI_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the accel and gyro sensor. */
|
||||
rslt = bmi270_sensor_enable(sensor_list, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Accel and gyro configuration settings. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Assign accel and gyro sensor. */
|
||||
sensor_data[ACCEL].type = BMI2_ACCEL;
|
||||
sensor_data[GYRO].type = BMI2_GYRO;
|
||||
|
||||
/* Loop to print accel and gyro data when interrupt occurs. */
|
||||
while (indx <= limit)
|
||||
{
|
||||
/* To get the data ready interrupt status of accel and gyro. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the data ready interrupt status and print the status for 10 samples. */
|
||||
if ((int_status & BMI2_ACC_DRDY_INT_MASK) && (int_status & BMI2_GYR_DRDY_INT_MASK))
|
||||
{
|
||||
/* Get accel and gyro data for x, y and z axis. */
|
||||
rslt = bmi270_get_sensor_data(sensor_data, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("\n******* Accel(Raw and m/s2) Gyro(Raw and dps) data : %d *******\n", indx);
|
||||
|
||||
printf("\nAcc_x = %d\t", sensor_data[ACCEL].sens_data.acc.x);
|
||||
printf("Acc_y = %d\t", sensor_data[ACCEL].sens_data.acc.y);
|
||||
printf("Acc_z = %d", sensor_data[ACCEL].sens_data.acc.z);
|
||||
|
||||
/* Converting lsb to meter per second squared for 16 bit accelerometer at 2G range. */
|
||||
x = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.x, 2, bmi2_dev.resolution);
|
||||
y = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.y, 2, bmi2_dev.resolution);
|
||||
z = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.z, 2, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in m/s2. */
|
||||
printf("\nAcc_ms2_X = %4.2f, Acc_ms2_Y = %4.2f, Acc_ms2_Z = %4.2f\n", x, y, z);
|
||||
|
||||
printf("\nGyr_X = %d\t", sensor_data[GYRO].sens_data.gyr.x);
|
||||
printf("Gyr_Y = %d\t", sensor_data[GYRO].sens_data.gyr.y);
|
||||
printf("Gyr_Z= %d\n", sensor_data[GYRO].sens_data.gyr.z);
|
||||
|
||||
/* Converting lsb to degree per second for 16 bit gyro at 2000dps range. */
|
||||
x = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.x, 2000, bmi2_dev.resolution);
|
||||
y = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.y, 2000, bmi2_dev.resolution);
|
||||
z = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.z, 2000, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in dps. */
|
||||
printf("Gyro_DPS_X = %4.2f, Gyro_DPS_Y = %4.2f, Gyro_DPS_Z = %4.2f\n", x, y, z);
|
||||
|
||||
indx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accelerometer and gyro configuration. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[ACCEL].type = BMI2_ACCEL;
|
||||
config[GYRO].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_get_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Map data ready interrupt to interrupt pin. */
|
||||
rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config[ACCEL].cfg.acc.odr = BMI2_ACC_ODR_200HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[ACCEL].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples.
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[ACCEL].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[ACCEL].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config[GYRO].cfg.gyr.odr = BMI2_GYR_ODR_200HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[GYRO].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[GYRO].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[GYRO].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[GYRO].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set the accel and gyro configurations. */
|
||||
rslt = bmi270_set_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (GRAVITY_EARTH * val * g_range) / half_scale;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (dps / ((half_scale) + BMI2_GYR_RANGE_2000)) * (val);
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= any_motion_interrupt.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for any-motion.
|
||||
*
|
||||
* @param[in] bmi2_dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_feature_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Accel sensor and any-motion feature are listed in array. */
|
||||
uint8_t sens_list[2] = { BMI2_ACCEL, BMI2_ANY_MOTION };
|
||||
|
||||
/* Variable to get any-motion interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Select features and their pins to be mapped to. */
|
||||
struct bmi2_sens_int_config sens_int = { .type = BMI2_ANY_MOTION, .hw_int_pin = BMI2_INT1 };
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the selected sensors. */
|
||||
rslt = bmi270_sensor_enable(sens_list, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Set feature configurations for any-motion. */
|
||||
rslt = set_feature_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Map the feature interrupt for any-motion. */
|
||||
rslt = bmi270_map_feat_int(&sens_int, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
printf("Move the board\n");
|
||||
|
||||
/* Loop to get any-motion interrupt. */
|
||||
do
|
||||
{
|
||||
/* Clear buffer. */
|
||||
int_status = 0;
|
||||
|
||||
/* To get the interrupt status of any-motion. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the interrupt status of any-motion. */
|
||||
if (int_status & BMI270_ANY_MOT_STATUS_MASK)
|
||||
{
|
||||
printf("Any-motion interrupt is generated\n");
|
||||
break;
|
||||
}
|
||||
} while (rslt == BMI2_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for any-motion.
|
||||
*/
|
||||
static int8_t set_feature_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define the type of sensor and its configurations. */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config.type = BMI2_ANY_MOTION;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_get_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* 1LSB equals 20ms. Default is 100ms, setting to 80ms. */
|
||||
config.cfg.any_motion.duration = 0x04;
|
||||
|
||||
/* 1LSB equals to 0.48mg. Default is 83mg, setting to 50mg. */
|
||||
config.cfg.any_motion.threshold = 0x68;
|
||||
|
||||
/* Set new configurations. */
|
||||
rslt = bmi270_set_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,372 @@
|
||||
/**
|
||||
* Copyright (C) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "coines.h"
|
||||
#include "bmi2_defs.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definitions */
|
||||
#define BMI2XY_SHUTTLE_ID UINT16_C(0x1B8)
|
||||
|
||||
/*! Macro that defines read write length */
|
||||
#define READ_WRITE_LEN UINT8_C(46)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static variable definition */
|
||||
|
||||
/*! Variable that holds the I2C device address or SPI chip selection */
|
||||
static uint8_t dev_addr;
|
||||
|
||||
/******************************************************************************/
|
||||
/*! User interface functions */
|
||||
|
||||
/*!
|
||||
* I2C read function map to COINES platform
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_addr = *(uint8_t*)intf_ptr;
|
||||
|
||||
return coines_read_i2c(dev_addr, reg_addr, reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* I2C write function map to COINES platform
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_addr = *(uint8_t*)intf_ptr;
|
||||
|
||||
return coines_write_i2c(dev_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* SPI read function map to COINES platform
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_addr = *(uint8_t*)intf_ptr;
|
||||
|
||||
return coines_read_spi(dev_addr, reg_addr, reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* SPI write function map to COINES platform
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_addr = *(uint8_t*)intf_ptr;
|
||||
|
||||
return coines_write_spi(dev_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Delay function map to COINES platform
|
||||
*/
|
||||
void bmi2_delay_us(uint32_t period, void *intf_ptr)
|
||||
{
|
||||
coines_delay_usec(period);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Function to select the interface between SPI and I2C.
|
||||
* Also to initialize coines platform
|
||||
*/
|
||||
int8_t bmi2_interface_init(struct bmi2_dev *bmi, uint8_t intf)
|
||||
{
|
||||
int8_t rslt = BMI2_OK;
|
||||
struct coines_board_info board_info;
|
||||
|
||||
if (bmi != NULL)
|
||||
{
|
||||
int16_t result = coines_open_comm_intf(COINES_COMM_INTF_USB);
|
||||
if (result < COINES_SUCCESS)
|
||||
{
|
||||
printf(
|
||||
"\n Unable to connect with Application Board ! \n" " 1. Check if the board is connected and powered on. \n" " 2. Check if Application Board USB driver is installed. \n"
|
||||
" 3. Check if board is in use by another application. (Insufficient permissions to access USB) \n");
|
||||
exit(result);
|
||||
}
|
||||
|
||||
result = coines_get_board_info(&board_info);
|
||||
|
||||
#if defined(PC)
|
||||
setbuf(stdout, NULL);
|
||||
#endif
|
||||
|
||||
if (result == COINES_SUCCESS)
|
||||
{
|
||||
if ((board_info.shuttle_id != BMI2XY_SHUTTLE_ID))
|
||||
{
|
||||
printf("! Warning invalid sensor shuttle \n ," "This application will not support this sensor \n");
|
||||
exit(COINES_E_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
coines_set_shuttleboard_vdd_vddio_config(0, 0);
|
||||
coines_delay_msec(100);
|
||||
|
||||
/* Bus configuration : I2C */
|
||||
if (intf == BMI2_I2C_INTF)
|
||||
{
|
||||
printf("I2C Interface \n");
|
||||
|
||||
/* To initialize the user I2C function */
|
||||
dev_addr = BMI2_I2C_PRIM_ADDR;
|
||||
bmi->intf = BMI2_I2C_INTF;
|
||||
bmi->read = bmi2_i2c_read;
|
||||
bmi->write = bmi2_i2c_write;
|
||||
coines_config_i2c_bus(COINES_I2C_BUS_0, COINES_I2C_FAST_MODE);
|
||||
}
|
||||
/* Bus configuration : SPI */
|
||||
else if (intf == BMI2_SPI_INTF)
|
||||
{
|
||||
printf("SPI Interface \n");
|
||||
|
||||
/* To initialize the user SPI function */
|
||||
dev_addr = COINES_SHUTTLE_PIN_7;
|
||||
bmi->intf = BMI2_SPI_INTF;
|
||||
bmi->read = bmi2_spi_read;
|
||||
bmi->write = bmi2_spi_write;
|
||||
coines_config_spi_bus(COINES_SPI_BUS_0, COINES_SPI_SPEED_5_MHZ, COINES_SPI_MODE3);
|
||||
coines_set_pin_config(COINES_SHUTTLE_PIN_7, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_HIGH);
|
||||
}
|
||||
|
||||
/* Assign device address to interface pointer */
|
||||
bmi->intf_ptr = &dev_addr;
|
||||
|
||||
/* Configure delay in microseconds */
|
||||
bmi->delay_us = bmi2_delay_us;
|
||||
|
||||
/* Configure max read/write length (in bytes) ( Supported length depends on target machine) */
|
||||
bmi->read_write_len = READ_WRITE_LEN;
|
||||
|
||||
/* Assign to NULL to load the default config file. */
|
||||
bmi->config_file_ptr = NULL;
|
||||
|
||||
coines_delay_usec(10000);
|
||||
|
||||
coines_set_shuttleboard_vdd_vddio_config(3300, 3300);
|
||||
|
||||
coines_delay_usec(10000);
|
||||
}
|
||||
else
|
||||
{
|
||||
rslt = BMI2_E_NULL_PTR;
|
||||
}
|
||||
|
||||
return rslt;
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Prints the execution status of the APIs.
|
||||
*/
|
||||
void bmi2_error_codes_print_result(int8_t rslt)
|
||||
{
|
||||
switch (rslt)
|
||||
{
|
||||
case BMI2_OK:
|
||||
|
||||
/* Do nothing */
|
||||
break;
|
||||
|
||||
case BMI2_W_FIFO_EMPTY:
|
||||
printf("Warning [%d] : FIFO empty\r\n", rslt);
|
||||
break;
|
||||
case BMI2_W_PARTIAL_READ:
|
||||
printf("Warning [%d] : FIFO partial read\r\n", rslt);
|
||||
break;
|
||||
case BMI2_E_NULL_PTR:
|
||||
printf(
|
||||
"Error [%d] : Null pointer error. It occurs when the user tries to assign value (not address) to a pointer," " which has been initialized to NULL.\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_COM_FAIL:
|
||||
printf(
|
||||
"Error [%d] : Communication failure error. It occurs due to read/write operation failure and also due " "to power failure during communication\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_DEV_NOT_FOUND:
|
||||
printf("Error [%d] : Device not found error. It occurs when the device chip id is incorrectly read\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_SENSOR:
|
||||
printf(
|
||||
"Error [%d] : Invalid sensor error. It occurs when there is a mismatch in the requested feature with the " "available one\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_SELF_TEST_FAIL:
|
||||
printf(
|
||||
"Error [%d] : Self-test failed error. It occurs when the validation of accel self-test data is " "not satisfied\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_INT_PIN:
|
||||
printf(
|
||||
"Error [%d] : Invalid interrupt pin error. It occurs when the user tries to configure interrupt pins " "apart from INT1 and INT2\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_OUT_OF_RANGE:
|
||||
printf(
|
||||
"Error [%d] : Out of range error. It occurs when the data exceeds from filtered or unfiltered data from " "fifo and also when the range exceeds the maximum range for accel and gyro while performing FOC\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ACC_INVALID_CFG:
|
||||
printf(
|
||||
"Error [%d] : Invalid Accel configuration error. It occurs when there is an error in accel configuration" " register which could be one among range, BW or filter performance in reg address 0x40\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_GYRO_INVALID_CFG:
|
||||
printf(
|
||||
"Error [%d] : Invalid Gyro configuration error. It occurs when there is a error in gyro configuration" "register which could be one among range, BW or filter performance in reg address 0x42\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ACC_GYR_INVALID_CFG:
|
||||
printf(
|
||||
"Error [%d] : Invalid Accel-Gyro configuration error. It occurs when there is a error in accel and gyro" " configuration registers which could be one among range, BW or filter performance in reg address 0x40 " "and 0x42\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_CONFIG_LOAD:
|
||||
printf(
|
||||
"Error [%d] : Configuration load error. It occurs when failure observed while loading the configuration " "into the sensor\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_PAGE:
|
||||
printf(
|
||||
"Error [%d] : Invalid page error. It occurs due to failure in writing the correct feature configuration " "from selected page\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_SET_APS_FAIL:
|
||||
printf(
|
||||
"Error [%d] : APS failure error. It occurs due to failure in write of advance power mode configuration " "register\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_AUX_INVALID_CFG:
|
||||
printf(
|
||||
"Error [%d] : Invalid AUX configuration error. It occurs when the auxiliary interface settings are not " "enabled properly\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_AUX_BUSY:
|
||||
printf(
|
||||
"Error [%d] : AUX busy error. It occurs when the auxiliary interface buses are engaged while configuring" " the AUX\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_REMAP_ERROR:
|
||||
printf(
|
||||
"Error [%d] : Remap error. It occurs due to failure in assigning the remap axes data for all the axes " "after change in axis position\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_GYR_USER_GAIN_UPD_FAIL:
|
||||
printf(
|
||||
"Error [%d] : Gyro user gain update fail error. It occurs when the reading of user gain update status " "fails\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_SELF_TEST_NOT_DONE:
|
||||
printf(
|
||||
"Error [%d] : Self-test not done error. It occurs when the self-test process is ongoing or not " "completed\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_INPUT:
|
||||
printf("Error [%d] : Invalid input error. It occurs when the sensor input validity fails\r\n", rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_STATUS:
|
||||
printf("Error [%d] : Invalid status error. It occurs when the feature/sensor validity fails\r\n", rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_CRT_ERROR:
|
||||
printf("Error [%d] : CRT error. It occurs when the CRT test has failed\r\n", rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ST_ALREADY_RUNNING:
|
||||
printf(
|
||||
"Error [%d] : Self-test already running error. It occurs when the self-test is already running and " "another has been initiated\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_CRT_READY_FOR_DL_FAIL_ABORT:
|
||||
printf(
|
||||
"Error [%d] : CRT ready for download fail abort error. It occurs when download in CRT fails due to wrong " "address location\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_DL_ERROR:
|
||||
printf(
|
||||
"Error [%d] : Download error. It occurs when write length exceeds that of the maximum burst length\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_PRECON_ERROR:
|
||||
printf(
|
||||
"Error [%d] : Pre-conditional error. It occurs when precondition to start the feature was not " "completed\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ABORT_ERROR:
|
||||
printf("Error [%d] : Abort error. It occurs when the device was shaken during CRT test\r\n", rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_WRITE_CYCLE_ONGOING:
|
||||
printf(
|
||||
"Error [%d] : Write cycle ongoing error. It occurs when the write cycle is already running and another " "has been initiated\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ST_NOT_RUNING:
|
||||
printf(
|
||||
"Error [%d] : Self-test is not running error. It occurs when self-test running is disabled while it's " "running\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_DATA_RDY_INT_FAILED:
|
||||
printf(
|
||||
"Error [%d] : Data ready interrupt error. It occurs when the sample count exceeds the FOC sample limit " "and data ready status is not updated\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_FOC_POSITION:
|
||||
printf(
|
||||
"Error [%d] : Invalid FOC position error. It occurs when average FOC data is obtained for the wrong" " axes\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Error [%d] : Unknown error code\r\n", rslt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Deinitializes coines platform
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
void bmi2_coines_deinit(void)
|
||||
{
|
||||
coines_close_comm_intf(COINES_COMM_INTF_USB);
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#ifndef _COMMON_H
|
||||
#define _COMMON_H
|
||||
|
||||
/*! CPP guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "bmi2.h"
|
||||
|
||||
/*!
|
||||
* @brief Function for reading the sensor's registers through I2C bus.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[out] reg_data : Pointer to the data buffer to store the read data.
|
||||
* @param[in] length : No of bytes to read.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval = BMI2_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMI2_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Function for writing the sensor's registers through I2C bus.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[in] reg_data : Pointer to the data buffer whose value is to be written.
|
||||
* @param[in] length : No of bytes to write.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval = BMI2_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMI2_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Function for reading the sensor's registers through SPI bus.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[out] reg_data : Pointer to the data buffer to store the read data.
|
||||
* @param[in] length : No of bytes to read.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval = BMI2_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMI2_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Function for writing the sensor's registers through SPI bus.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[in] reg_data : Pointer to the data buffer whose data has to be written.
|
||||
* @param[in] length : No of bytes to write.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval = BMI2_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMI2_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief This function provides the delay for required time (Microsecond) as per the input provided in some of the
|
||||
* APIs.
|
||||
*
|
||||
* @param[in] period_us : The required wait time in microsecond.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return void.
|
||||
*
|
||||
*/
|
||||
void bmi2_delay_us(uint32_t period, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Function to select the interface between SPI and I2C.
|
||||
*
|
||||
* @param[in] bma : Structure instance of bmi2_dev
|
||||
* @param[in] intf : Interface selection parameter
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval 0 -> Success
|
||||
* @retval < 0 -> Failure Info
|
||||
*/
|
||||
int8_t bmi2_interface_init(struct bmi2_dev *bma, uint8_t intf);
|
||||
|
||||
/*!
|
||||
* @brief Prints the execution status of the APIs.
|
||||
*
|
||||
* @param[in] rslt : Error code returned by the API whose execution status has to be printed.
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
void bmi2_error_codes_print_result(int8_t rslt);
|
||||
|
||||
/*!
|
||||
* @brief Deinitializes coines platform
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
void bmi2_coines_deinit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* End of CPP guard */
|
||||
|
||||
#endif /* _COMMON_H */
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= component_retrim.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* This API runs the CRT process. */
|
||||
rslt = bmi2_do_crt(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Do not move the board while doing CRT. If so, it will throw an abort error. */
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("CRT successfully completed.");
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_full_header_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+315
@@ -0,0 +1,315 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macros */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data. */
|
||||
#define BMI2_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(2048)
|
||||
|
||||
/*! Length of data to be read from FIFO. */
|
||||
#define BMI2_FIFO_RAW_DATA_USER_LENGTH UINT16_C(2048)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO. */
|
||||
|
||||
/*! Calculation for frame count: Total frame count = Fifo buffer size(2048)/ Total frames(6 Accel, 6 Gyro and 1 header,
|
||||
* totaling to 13) which equals to 157.
|
||||
*/
|
||||
#define BMI2_FIFO_ACCEL_FRAME_COUNT UINT8_C(157)
|
||||
|
||||
/*! Number of gyro frames to be extracted from FIFO. */
|
||||
#define BMI2_FIFO_GYRO_FRAME_COUNT UINT8_C(157)
|
||||
|
||||
/*! Macro to read sensortime byte in FIFO. */
|
||||
#define SENSORTIME_OVERHEAD_BYTE UINT8_C(3)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
uint16_t index = 0;
|
||||
uint16_t fifo_length = 0;
|
||||
uint16_t config = 0;
|
||||
|
||||
/* To read sensortime, extra 3 bytes are added to fifo buffer. */
|
||||
uint16_t fifo_buffer_size = BMI2_FIFO_RAW_DATA_BUFFER_SIZE + SENSORTIME_OVERHEAD_BYTE;
|
||||
|
||||
/* Variable to get fifo full interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint16_t accel_frame_length = BMI2_FIFO_ACCEL_FRAME_COUNT;
|
||||
|
||||
uint16_t gyro_frame_length = BMI2_FIFO_GYRO_FRAME_COUNT;
|
||||
|
||||
/* Variable to store the available frame length count in FIFO */
|
||||
uint8_t frame_count;
|
||||
|
||||
int8_t try = 1;
|
||||
|
||||
/* Number of bytes of FIFO data. */
|
||||
uint8_t fifo_data[fifo_buffer_size];
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 157 * (6 axes + 1 header bytes) = 1099 bytes */
|
||||
struct bmi2_sens_axes_data fifo_accel_data[BMI2_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Array of gyro frames -> Total bytes =
|
||||
* 157 * (6 axes + 1 header bytes) = 1099 bytes */
|
||||
struct bmi2_sens_axes_data fifo_gyro_data[BMI2_FIFO_GYRO_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure. */
|
||||
struct bmi2_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Accel and gyro sensor are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Enable accel and gyro sensor. */
|
||||
rslt = bmi270_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Configuration settings for accel and gyro. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Before setting FIFO, disable the advance power save mode. */
|
||||
rslt = bmi2_set_adv_power_save(BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initially disable all configurations in fifo. */
|
||||
rslt = bmi2_get_fifo_config(&config, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initially disable all configurations in fifo. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ALL_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Update FIFO structure. */
|
||||
/* Mapping the buffer to store the fifo data. */
|
||||
fifoframe.data = fifo_data;
|
||||
|
||||
/* Length of FIFO frame. */
|
||||
/* To read sensortime, extra 3 bytes are added to fifo user length. */
|
||||
fifoframe.length = BMI2_FIFO_RAW_DATA_USER_LENGTH + SENSORTIME_OVERHEAD_BYTE;
|
||||
|
||||
/* Set FIFO configuration by enabling accel, gyro and timestamp.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is in FIFO mode.
|
||||
* NOTE 3: Sensortime is enabled by default */
|
||||
printf("FIFO is configured in header mode\n");
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ACC_EN | BMI2_FIFO_GYR_EN, BMI2_ENABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Map FIFO full interrupt. */
|
||||
fifoframe.data_int_map = BMI2_FFULL_INT;
|
||||
rslt = bmi2_map_data_int(fifoframe.data_int_map, BMI2_INT1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
while (try <= 10)
|
||||
{
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if ((rslt == BMI2_OK) && (int_status & BMI2_FFULL_INT_STATUS_MASK))
|
||||
{
|
||||
printf("\nIteration : %d\n", try);
|
||||
|
||||
accel_frame_length = BMI2_FIFO_ACCEL_FRAME_COUNT;
|
||||
|
||||
gyro_frame_length = BMI2_FIFO_GYRO_FRAME_COUNT;
|
||||
|
||||
rslt = bmi2_get_fifo_length(&fifo_length, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("\nFIFO data bytes available : %d \n", fifo_length);
|
||||
printf("\nFIFO data bytes requested : %d \n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data. */
|
||||
rslt = bmi2_read_fifo_data(&fifoframe, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("\nFIFO accel frames requested : %d \n", accel_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_accel(fifo_accel_data, &accel_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO accel frames extracted : %d \n", accel_frame_length);
|
||||
|
||||
printf("\nFIFO gyro frames requested : %d \n", gyro_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract gyro data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_gyro(fifo_gyro_data, &gyro_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO gyro frames extracted : %d \n", gyro_frame_length);
|
||||
|
||||
/* Calculating the frame count from the available bytes in FIFO
|
||||
* frame_length = (available_fifo_bytes / (acc_frame_len + gyro_frame_len + header_byte)) */
|
||||
frame_count = (fifo_length / (BMI2_FIFO_ACC_GYR_LENGTH + 1));
|
||||
printf("\nAvailable frame count from available bytes: %d\n", frame_count);
|
||||
|
||||
printf("\nExtracted accel frames\n");
|
||||
|
||||
if (accel_frame_length > frame_count)
|
||||
{
|
||||
accel_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer. */
|
||||
for (index = 0; index < accel_frame_length; index++)
|
||||
{
|
||||
printf("ACCEL[%d] X : %d\t Y : %d\t Z : %d\n", index, fifo_accel_data[index].x,
|
||||
fifo_accel_data[index].y, fifo_accel_data[index].z);
|
||||
}
|
||||
|
||||
printf("\nExtracted gyro frames\n");
|
||||
|
||||
if (gyro_frame_length > frame_count)
|
||||
{
|
||||
gyro_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed gyro data from the FIFO buffer. */
|
||||
for (index = 0; index < gyro_frame_length; index++)
|
||||
{
|
||||
printf("GYRO[%d] X : %d\t Y : %d\t Z : %d\n",
|
||||
index,
|
||||
fifo_gyro_data[index].x,
|
||||
fifo_gyro_data[index].y,
|
||||
fifo_gyro_data[index].z);
|
||||
}
|
||||
|
||||
/* Print control frames like sensor time and skipped frame count. */
|
||||
printf("\nSkipped frame count = %d\n", fifoframe.skipped_frame_count);
|
||||
|
||||
printf("Sensor time = %lu\r\n", fifoframe.sensor_time);
|
||||
|
||||
try++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accel and gyro configurations. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[0].type = BMI2_ACCEL;
|
||||
config[1].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_get_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Accel configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[0].cfg.acc.odr = BMI2_ACC_ODR_25HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[0].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[0].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Gyro configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[1].cfg.gyr.odr = BMI2_GYR_ODR_25HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope Bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[1].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[1].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set new configurations. */
|
||||
rslt = bmi270_set_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_full_headerless_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+304
@@ -0,0 +1,304 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macros */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMI2_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(2048)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMI2_FIFO_RAW_DATA_USER_LENGTH UINT16_C(2048)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO */
|
||||
|
||||
/*! Calculation for frame count: Total frame count = Fifo buffer size(2048)/ Total frames(6 Accel, 6 Gyro totaling to
|
||||
* 12) which equals to 170.
|
||||
*/
|
||||
#define BMI2_FIFO_ACCEL_FRAME_COUNT UINT8_C(169)
|
||||
|
||||
/*! Number of gyro frames to be extracted from FIFO */
|
||||
#define BMI2_FIFO_GYRO_FRAME_COUNT UINT8_C(169)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
uint16_t index = 0;
|
||||
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
uint8_t try = 1;
|
||||
|
||||
/* Variable to get fifo full interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint16_t accel_frame_length;
|
||||
|
||||
uint16_t gyro_frame_length;
|
||||
|
||||
/* Variable to store the available frame length count in FIFO */
|
||||
uint8_t frame_count;
|
||||
|
||||
/* Number of bytes of FIFO data. */
|
||||
uint8_t fifo_data[BMI2_FIFO_RAW_DATA_BUFFER_SIZE] = { 0 };
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 170 * (6 axes bytes) = 1020 bytes */
|
||||
struct bmi2_sens_axes_data fifo_accel_data[BMI2_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Array of gyro frames -> Total bytes =
|
||||
* 170 * (6 axes bytes) = 1020 bytes */
|
||||
struct bmi2_sens_axes_data fifo_gyro_data[BMI2_FIFO_GYRO_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure. */
|
||||
struct bmi2_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Accel and gyro sensor are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Enable accel and gyro sensor. */
|
||||
rslt = bmi270_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Configuration settings for accel and gyro. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Before setting FIFO, disable the advance power save mode. */
|
||||
rslt = bmi2_set_adv_power_save(BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initially disable all configurations in fifo. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ALL_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Update FIFO structure. */
|
||||
/* Mapping the buffer to store the fifo data. */
|
||||
fifoframe.data = fifo_data;
|
||||
|
||||
/* Length of FIFO frame. */
|
||||
fifoframe.length = BMI2_FIFO_RAW_DATA_USER_LENGTH;
|
||||
|
||||
/* Set FIFO configuration by enabling accel, gyro.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ACC_EN | BMI2_FIFO_GYR_EN, BMI2_ENABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("FIFO is configured in headerless mode\n");
|
||||
|
||||
/* To enable headerless mode, disable the header. */
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_HEADER_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
}
|
||||
|
||||
/* Map FIFO full interrupt. */
|
||||
fifoframe.data_int_map = BMI2_FFULL_INT;
|
||||
rslt = bmi2_map_data_int(fifoframe.data_int_map, BMI2_INT1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
while (try <= 10)
|
||||
{
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if ((rslt == BMI2_OK) && (int_status & BMI2_FFULL_INT_STATUS_MASK))
|
||||
{
|
||||
printf("\nIteration : %d\n", try);
|
||||
|
||||
rslt = bmi2_get_fifo_length(&fifo_length, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
accel_frame_length = BMI2_FIFO_ACCEL_FRAME_COUNT;
|
||||
gyro_frame_length = BMI2_FIFO_GYRO_FRAME_COUNT;
|
||||
|
||||
printf("\nFIFO data bytes available : %d \n", fifo_length);
|
||||
printf("\nFIFO data bytes requested : %d \n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data. */
|
||||
rslt = bmi2_read_fifo_data(&fifoframe, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("\nFIFO accel frames requested : %d \n", accel_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_accel(fifo_accel_data, &accel_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO accel frames extracted : %d \n", accel_frame_length);
|
||||
|
||||
printf("\nFIFO gyro frames requested : %d \n", gyro_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract gyro data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_gyro(fifo_gyro_data, &gyro_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO gyro frames extracted : %d \n", gyro_frame_length);
|
||||
|
||||
/* Calculating the frame count from the available bytes in FIFO
|
||||
* frame_length = (available_fifo_bytes / (acc_frame_len + gyro_frame_len)) */
|
||||
frame_count = (fifo_length / (BMI2_FIFO_ACC_GYR_LENGTH));
|
||||
printf("\nAvailable frame count from available bytes: %d\n", frame_count);
|
||||
|
||||
printf("\nExtracted accel frames\n");
|
||||
|
||||
if (accel_frame_length > frame_count)
|
||||
{
|
||||
accel_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer. */
|
||||
for (index = 0; index < accel_frame_length; index++)
|
||||
{
|
||||
printf("ACCEL[%d] X : %d\t Y : %d\t Z : %d\n", index, fifo_accel_data[index].x,
|
||||
fifo_accel_data[index].y, fifo_accel_data[index].z);
|
||||
}
|
||||
|
||||
printf("\nExtracted gyro frames\n");
|
||||
|
||||
if (gyro_frame_length > frame_count)
|
||||
{
|
||||
gyro_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed gyro data from the FIFO buffer. */
|
||||
for (index = 0; index < gyro_frame_length; index++)
|
||||
{
|
||||
printf("GYRO[%d] X : %d\t Y : %d\t Z : %d\n",
|
||||
index,
|
||||
fifo_gyro_data[index].x,
|
||||
fifo_gyro_data[index].y,
|
||||
fifo_gyro_data[index].z);
|
||||
}
|
||||
}
|
||||
|
||||
try++;
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accel and gyro configurations. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[0].type = BMI2_ACCEL;
|
||||
config[1].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_get_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Accel configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[0].cfg.acc.odr = BMI2_ACC_ODR_100HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[0].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[0].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Gyro configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[1].cfg.gyr.odr = BMI2_GYR_ODR_100HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope Bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[1].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[1].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set new configurations. */
|
||||
rslt = bmi270_set_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_watermark_header_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+335
@@ -0,0 +1,335 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macros */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMI2_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(2048)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMI2_FIFO_RAW_DATA_USER_LENGTH UINT16_C(2048)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO */
|
||||
|
||||
/*!
|
||||
* Calculation:
|
||||
* fifo_watermark_level = 650, accel_frame_len = 6, gyro_frame_len = 6 header_byte = 1.
|
||||
* fifo_accel_frame_count = (650 / (6 + 6 + 1 )) = 50 frames
|
||||
* NOTE: Extra frames are read in order to get sensor time
|
||||
*/
|
||||
#define BMI2_FIFO_ACCEL_FRAME_COUNT UINT8_C(55)
|
||||
|
||||
/*! Number of gyro frames to be extracted from FIFO */
|
||||
#define BMI2_FIFO_GYRO_FRAME_COUNT UINT8_C(55)
|
||||
|
||||
/*! Setting a watermark level in FIFO */
|
||||
#define BMI270_FIFO_WATERMARK_LEVEL UINT16_C(650)
|
||||
|
||||
/*! Macro to read sensortime byte in FIFO */
|
||||
#define SENSORTIME_OVERHEAD_BYTE UINT8_C(3)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to store the available frame length count in FIFO */
|
||||
uint8_t frame_count;
|
||||
|
||||
/* Variable to index bytes. */
|
||||
uint16_t index = 0;
|
||||
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
uint16_t accel_frame_length;
|
||||
|
||||
uint16_t gyro_frame_length;
|
||||
|
||||
uint8_t try = 1;
|
||||
|
||||
/* To read sensortime, extra 3 bytes are added to fifo buffer */
|
||||
uint16_t fifo_buffer_size = BMI2_FIFO_RAW_DATA_BUFFER_SIZE + SENSORTIME_OVERHEAD_BYTE;
|
||||
|
||||
/* Number of bytes of FIFO data. */
|
||||
uint8_t fifo_data[fifo_buffer_size];
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 55 * (6 axes bytes) = 330 bytes */
|
||||
struct bmi2_sens_axes_data fifo_accel_data[BMI2_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Array of gyro frames -> Total bytes =
|
||||
* 55 * (6 axes bytes) = 330 bytes */
|
||||
struct bmi2_sens_axes_data fifo_gyro_data[BMI2_FIFO_GYRO_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure. */
|
||||
struct bmi2_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Accel and gyro sensor are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Variable to get fifo water-mark interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint16_t watermark = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Enable accel and gyro sensor. */
|
||||
rslt = bmi270_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Configuration settings for accel and gyro. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Before setting FIFO, disable the advance power save mode. */
|
||||
rslt = bmi2_set_adv_power_save(BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initially disable all configurations in fifo. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ALL_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Update FIFO structure. */
|
||||
/* Mapping the buffer to store the fifo data. */
|
||||
fifoframe.data = fifo_data;
|
||||
|
||||
/* Length of FIFO frame. */
|
||||
/* To read sensortime, extra 3 bytes are added to fifo user length. */
|
||||
fifoframe.length = BMI2_FIFO_RAW_DATA_USER_LENGTH + SENSORTIME_OVERHEAD_BYTE;
|
||||
|
||||
/* Set FIFO configuration by enabling accel, gyro and timestamp.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode.
|
||||
* NOTE 3: Sensortime is enabled by default */
|
||||
printf("FIFO is configured in header mode\n");
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ACC_EN | BMI2_FIFO_GYR_EN, BMI2_ENABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* FIFO water-mark interrupt is enabled. */
|
||||
fifoframe.data_int_map = BMI2_FWM_INT;
|
||||
|
||||
/* Map water-mark interrupt to the required interrupt pin. */
|
||||
rslt = bmi2_map_data_int(fifoframe.data_int_map, BMI2_INT1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Set water-mark level. */
|
||||
fifoframe.wm_lvl = BMI270_FIFO_WATERMARK_LEVEL;
|
||||
|
||||
/* Set the water-mark level if water-mark interrupt is mapped. */
|
||||
rslt = bmi2_set_fifo_wm(fifoframe.wm_lvl, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
rslt = bmi2_get_fifo_wm(&watermark, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
printf("\nFIFO watermark level is %d\n", watermark);
|
||||
|
||||
while (try <= 10)
|
||||
{
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the status of FIFO watermark interrupt. */
|
||||
if ((rslt == BMI2_OK) && (int_status & BMI2_FWM_INT_STATUS_MASK))
|
||||
{
|
||||
printf("\nIteration : %d\n", try);
|
||||
|
||||
printf("\nWatermark interrupt occurred\n");
|
||||
|
||||
rslt = bmi2_get_fifo_length(&fifo_length, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
accel_frame_length = BMI2_FIFO_ACCEL_FRAME_COUNT;
|
||||
gyro_frame_length = BMI2_FIFO_GYRO_FRAME_COUNT;
|
||||
|
||||
printf("\nFIFO data bytes available : %d \n", fifo_length);
|
||||
printf("\nFIFO data bytes requested : %d \n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data. */
|
||||
rslt = bmi2_read_fifo_data(&fifoframe, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("\nFIFO accel frames requested : %d \n", accel_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_accel(fifo_accel_data, &accel_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO accel frames extracted : %d \n", accel_frame_length);
|
||||
|
||||
printf("\nFIFO gyro frames requested : %d \n", gyro_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract gyro data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_gyro(fifo_gyro_data, &gyro_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO gyro frames extracted : %d \n", gyro_frame_length);
|
||||
|
||||
/* Calculating the frame count from the available bytes in FIFO
|
||||
* frame_length = (available_fifo_bytes / (acc_frame_len + gyro_frame_len + header_byte)) */
|
||||
frame_count = (fifo_length / (BMI2_FIFO_ACC_GYR_LENGTH + 1));
|
||||
printf("\nAvailable frame count from available bytes: %d\n", frame_count);
|
||||
|
||||
printf("\nExracted accel frames\n");
|
||||
|
||||
if (accel_frame_length > frame_count)
|
||||
{
|
||||
accel_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer. */
|
||||
for (index = 0; index < accel_frame_length; index++)
|
||||
{
|
||||
printf("ACCEL[%d] X : %d\t Y : %d\t Z : %d\n", index, fifo_accel_data[index].x,
|
||||
fifo_accel_data[index].y, fifo_accel_data[index].z);
|
||||
}
|
||||
|
||||
printf("\nExtracted gyro frames\n");
|
||||
|
||||
if (gyro_frame_length > frame_count)
|
||||
{
|
||||
gyro_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed gyro data from the FIFO buffer. */
|
||||
for (index = 0; index < gyro_frame_length; index++)
|
||||
{
|
||||
printf("GYRO[%d] X : %d\t Y : %d\t Z : %d\n",
|
||||
index,
|
||||
fifo_gyro_data[index].x,
|
||||
fifo_gyro_data[index].y,
|
||||
fifo_gyro_data[index].z);
|
||||
}
|
||||
|
||||
/* Print control frames like sensor time and skipped frame count. */
|
||||
printf("Skipped frame count = %d\n", fifoframe.skipped_frame_count);
|
||||
printf("Sensor time = %lu\r\n", fifoframe.sensor_time);
|
||||
|
||||
try++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accel and gyro configurations. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[0].type = BMI2_ACCEL;
|
||||
config[1].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_get_sensor_config(config, 2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Accel configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[0].cfg.acc.odr = BMI2_ACC_ODR_25HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[0].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[0].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Gyro configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[1].cfg.gyr.odr = BMI2_GYR_ODR_25HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope Bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[1].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[1].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set new configurations. */
|
||||
rslt = bmi270_set_sensor_config(config, 2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_watermark_headerless_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+331
@@ -0,0 +1,331 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macros */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMI2_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(2048)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMI2_FIFO_RAW_DATA_USER_LENGTH UINT16_C(2048)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO */
|
||||
|
||||
/*!
|
||||
* Calculation:
|
||||
* fifo_watermark_level = 650, accel_frame_len = 6, gyro_frame_len = 6.
|
||||
* fifo_accel_frame_count = (650 / (6 + 6 )) = 54 frames
|
||||
*/
|
||||
#define BMI2_FIFO_ACCEL_FRAME_COUNT UINT8_C(55)
|
||||
|
||||
/*! Number of gyro frames to be extracted from FIFO */
|
||||
#define BMI2_FIFO_GYRO_FRAME_COUNT UINT8_C(55)
|
||||
|
||||
/*! Setting a watermark level in FIFO */
|
||||
#define BMI270_FIFO_WATERMARK_LEVEL UINT16_C(650)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to index bytes. */
|
||||
uint16_t index = 0;
|
||||
|
||||
/* Variable to store the available frame length count in FIFO */
|
||||
uint8_t frame_count;
|
||||
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
uint16_t accel_frame_length;
|
||||
|
||||
uint16_t gyro_frame_length;
|
||||
|
||||
uint8_t try = 1;
|
||||
|
||||
/* Number of bytes of FIFO data. */
|
||||
uint8_t fifo_data[BMI2_FIFO_RAW_DATA_BUFFER_SIZE] = { 0 };
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 50 * (6 axes bytes) = 300 bytes */
|
||||
struct bmi2_sens_axes_data fifo_accel_data[BMI2_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Array of gyro frames -> Total bytes =
|
||||
* 50 * (6 axes bytes) = 300 bytes */
|
||||
struct bmi2_sens_axes_data fifo_gyro_data[BMI2_FIFO_GYRO_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure. */
|
||||
struct bmi2_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Accel and gyro sensor are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Variable to get fifo water-mark interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint16_t watermark = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Enable accel and gyro sensor. */
|
||||
rslt = bmi270_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Configuration settings for accel and gyro. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Before setting FIFO, disable the advance power save mode. */
|
||||
rslt = bmi2_set_adv_power_save(BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initially disable all configurations in fifo. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ALL_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Update FIFO structure. */
|
||||
/* Mapping the buffer to store the fifo data. */
|
||||
fifoframe.data = fifo_data;
|
||||
|
||||
/* Length of FIFO frame. */
|
||||
fifoframe.length = BMI2_FIFO_RAW_DATA_USER_LENGTH;
|
||||
|
||||
/* Set FIFO configuration by enabling accel, gyro.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ACC_EN | BMI2_FIFO_GYR_EN, BMI2_ENABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("FIFO is configured in headerless mode\n");
|
||||
|
||||
/* To enable headerless mode, disable the header. */
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_HEADER_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
}
|
||||
|
||||
/* FIFO water-mark interrupt is enabled. */
|
||||
fifoframe.data_int_map = BMI2_FWM_INT;
|
||||
|
||||
/* Map water-mark interrupt to the required interrupt pin. */
|
||||
rslt = bmi2_map_data_int(fifoframe.data_int_map, BMI2_INT1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Set water-mark level. */
|
||||
fifoframe.wm_lvl = BMI270_FIFO_WATERMARK_LEVEL;
|
||||
|
||||
fifoframe.length = BMI2_FIFO_RAW_DATA_USER_LENGTH;
|
||||
|
||||
/* Set the water-mark level if water-mark interrupt is mapped. */
|
||||
rslt = bmi2_set_fifo_wm(fifoframe.wm_lvl, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
rslt = bmi2_get_fifo_wm(&watermark, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
printf("\nFIFO watermark level is %d\n", watermark);
|
||||
|
||||
while (try <= 10)
|
||||
{
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the status of FIFO watermark interrupt. */
|
||||
if ((rslt == BMI2_OK) && (int_status & BMI2_FWM_INT_STATUS_MASK))
|
||||
{
|
||||
printf("\nIteration : %d\n", try);
|
||||
|
||||
printf("\nWatermark interrupt occurred\n");
|
||||
|
||||
rslt = bmi2_get_fifo_length(&fifo_length, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
accel_frame_length = BMI2_FIFO_ACCEL_FRAME_COUNT;
|
||||
gyro_frame_length = BMI2_FIFO_GYRO_FRAME_COUNT;
|
||||
|
||||
printf("\nFIFO data bytes available : %d \n", fifo_length);
|
||||
printf("\nFIFO data bytes requested : %d \n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data. */
|
||||
rslt = bmi2_read_fifo_data(&fifoframe, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("\nFIFO accel frames requested : %d \n", accel_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_accel(fifo_accel_data, &accel_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO accel frames extracted : %d \n", accel_frame_length);
|
||||
|
||||
printf("\nFIFO gyro frames requested : %d \n", gyro_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract gyro data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_gyro(fifo_gyro_data, &gyro_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO gyro frames extracted : %d \n", gyro_frame_length);
|
||||
|
||||
/* Calculating the frame count from the available bytes in FIFO
|
||||
* frame_length = (available_fifo_bytes / (acc_frame_len + gyro_frame_len)) */
|
||||
frame_count = (fifo_length / (BMI2_FIFO_ACC_GYR_LENGTH));
|
||||
printf("\nAvailable frame count from available bytes: %d\n", frame_count);
|
||||
|
||||
printf("\nExracted accel frames\n");
|
||||
|
||||
if (accel_frame_length > frame_count)
|
||||
{
|
||||
accel_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer. */
|
||||
for (index = 0; index < accel_frame_length; index++)
|
||||
{
|
||||
printf("ACCEL[%d] X : %d\t Y : %d\t Z : %d\n", index, fifo_accel_data[index].x,
|
||||
fifo_accel_data[index].y, fifo_accel_data[index].z);
|
||||
}
|
||||
|
||||
printf("\nExtracted gyro frames\n");
|
||||
|
||||
if (gyro_frame_length > frame_count)
|
||||
{
|
||||
gyro_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed gyro data from the FIFO buffer. */
|
||||
for (index = 0; index < gyro_frame_length; index++)
|
||||
{
|
||||
printf("GYRO[%d] X : %d\t Y : %d\t Z : %d\n",
|
||||
index,
|
||||
fifo_gyro_data[index].x,
|
||||
fifo_gyro_data[index].y,
|
||||
fifo_gyro_data[index].z);
|
||||
}
|
||||
}
|
||||
|
||||
try++;
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accel and gyro configurations. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[0].type = BMI2_ACCEL;
|
||||
config[1].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_get_sensor_config(config, 2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameter according to their requirement. */
|
||||
/* Accel configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[0].cfg.acc.odr = BMI2_ACC_ODR_100HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[0].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[0].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Gyro configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[1].cfg.gyr.odr = BMI2_GYR_ODR_100HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope Bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[1].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[1].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set new configurations. */
|
||||
rslt = bmi270_set_sensor_config(config, 2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= gyro.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,195 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for gyro.
|
||||
*
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_gyro_config(struct bmi2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] dps : Degree per second.
|
||||
* @param[in] bit_width : Resolution for gyro.
|
||||
*
|
||||
* @return Degree per second.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to define limit to print gyro data. */
|
||||
uint8_t limit = 10;
|
||||
|
||||
uint8_t indx = 0;
|
||||
|
||||
float x = 0, y = 0, z = 0;
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Create an instance of sensor data structure. */
|
||||
struct bmi2_sensor_data sensor_data = { 0 };
|
||||
|
||||
/* Assign gyro sensor to variable. */
|
||||
uint8_t sens_list = BMI2_GYRO;
|
||||
|
||||
/* Initialize the interrupt status of gyro. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the selected sensors. */
|
||||
rslt = bmi270_sensor_enable(&sens_list, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Gyro configuration settings. */
|
||||
rslt = set_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Select gyro sensor. */
|
||||
sensor_data.type = BMI2_GYRO;
|
||||
printf("Gyro and DPS data\n");
|
||||
printf("Gyro data collected at Range 2000 dps with 16-bit resolution\n");
|
||||
|
||||
/* Loop to print gyro data when interrupt occurs. */
|
||||
while (indx <= limit)
|
||||
{
|
||||
/* To get the data ready interrupt status of gyro. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the data ready interrupt status and print the status for 10 samples. */
|
||||
if (int_status & BMI2_GYR_DRDY_INT_MASK)
|
||||
{
|
||||
/* Get gyro data for x, y and z axis. */
|
||||
rslt = bmi270_get_sensor_data(&sensor_data, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("\nGyr_X = %d\t", sensor_data.sens_data.gyr.x);
|
||||
printf("Gyr_Y = %d\t", sensor_data.sens_data.gyr.y);
|
||||
printf("Gyr_Z = %d\r\n", sensor_data.sens_data.gyr.z);
|
||||
|
||||
/* Converting lsb to degree per second for 16 bit gyro at 2000dps range. */
|
||||
x = lsb_to_dps(sensor_data.sens_data.gyr.x, 2000, bmi2_dev.resolution);
|
||||
y = lsb_to_dps(sensor_data.sens_data.gyr.y, 2000, bmi2_dev.resolution);
|
||||
z = lsb_to_dps(sensor_data.sens_data.gyr.z, 2000, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in dps. */
|
||||
printf("Gyr_DPS_X = %4.2f, Gyr_DPS_Y = %4.2f, Gyr_DPS_Z = %4.2f\n", x, y, z);
|
||||
|
||||
indx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for gyro.
|
||||
*/
|
||||
static int8_t set_gyro_config(struct bmi2_dev *dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define the type of sensor and its configurations. */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config.type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_get_sensor_config(&config, 1, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Map data ready interrupt to interrupt pin. */
|
||||
rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config.cfg.gyr.odr = BMI2_GYR_ODR_100HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config.cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config.cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config.cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config.cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set the gyro configurations. */
|
||||
rslt = bmi270_set_sensor_config(&config, 1, dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (dps / ((half_scale) + BMI2_GYR_RANGE_2000)) * (val);
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= no_motion_interrupt.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for no-motion.
|
||||
*
|
||||
* @param[in] bmi2_dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_feature_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Accel sensor and no-motion feature are listed in array. */
|
||||
uint8_t sens_list[2] = { BMI2_ACCEL, BMI2_NO_MOTION };
|
||||
|
||||
/* Variable to get no-motion interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Select features and their pins to be mapped to. */
|
||||
struct bmi2_sens_int_config sens_int = { .type = BMI2_NO_MOTION, .hw_int_pin = BMI2_INT1 };
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the selected sensors. */
|
||||
rslt = bmi270_sensor_enable(sens_list, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Set feature configurations for no-motion. */
|
||||
rslt = set_feature_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Map the feature interrupt for no-motion. */
|
||||
rslt = bmi270_map_feat_int(&sens_int, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
printf("Do not move the board\n");
|
||||
|
||||
/* Loop to get no-motion interrupt. */
|
||||
do
|
||||
{
|
||||
/* Clear buffer. */
|
||||
int_status = 0;
|
||||
|
||||
/* To get the interrupt status of no-motion. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the interrupt status of no-motion. */
|
||||
if (int_status & BMI270_NO_MOT_STATUS_MASK)
|
||||
{
|
||||
printf("No-motion interrupt is generated\n");
|
||||
break;
|
||||
}
|
||||
} while (rslt == BMI2_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for no-motion.
|
||||
*/
|
||||
static int8_t set_feature_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define the type of sensor and its configurations. */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config.type = BMI2_NO_MOTION;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_get_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* 1LSB equals 20ms. Default is 100ms, setting to 80ms. */
|
||||
config.cfg.no_motion.duration = 0x04;
|
||||
|
||||
/* 1LSB equals to 0.48mg. Default is 83mg, setting to 50mg. */
|
||||
config.cfg.no_motion.threshold = 0x68;
|
||||
|
||||
/* Set new configurations. */
|
||||
rslt = bmi270_set_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= read_aux_data_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
BMM150_SOURCE ?= ../../../bmm150
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270.c \
|
||||
$(BMM150_SOURCE)/bmm150.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(BMM150_SOURCE) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+327
@@ -0,0 +1,327 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270.h"
|
||||
#include "bmm150.h"
|
||||
#include "coines.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Macros to select the sensors */
|
||||
#define ACCEL UINT8_C(0x00)
|
||||
#define GYRO UINT8_C(0x01)
|
||||
#define AUX UINT8_C(0x02)
|
||||
|
||||
/*! Earth's gravity in m/s^2 */
|
||||
#define GRAVITY_EARTH (9.80665f)
|
||||
|
||||
/*****************************************************************************/
|
||||
/*! Structure declaration */
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/*******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/**
|
||||
* user_aux_read - Reads data from auxiliary sensor in manual mode.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[out] aux_data : Aux data pointer to store the read data.
|
||||
* @param[in] length : No of bytes to read.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval 0 -> Success
|
||||
* @retval < 0 -> Failure Info
|
||||
*/
|
||||
static int8_t user_aux_read(uint8_t reg_addr, uint8_t *aux_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/**
|
||||
* user_aux_write - Writes data to the auxiliary sensor in manual mode.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[out] aux_data : Aux data pointer to store the data being written.
|
||||
* @param[in] length : No of bytes to read.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval 0 -> Success
|
||||
* @retval < 0 -> Failure Info
|
||||
*/
|
||||
static int8_t user_aux_write(uint8_t reg_addr, const uint8_t *aux_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief This function provides the delay for required time (Microsecond) as per the input provided in some of the
|
||||
* APIs.
|
||||
*
|
||||
* @param[in] period_us : The required wait time in microsecond.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
static void user_delay_us(uint32_t period, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] g_range : Gravity range.
|
||||
* @param[in] bit_width : Resolution for accel.
|
||||
*
|
||||
* @return Gravity.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] dps : Degree per second.
|
||||
* @param[in] bit_width : Resolution for gyro.
|
||||
*
|
||||
* @return Degree per second.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width);
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to select the pull-up resistor which is set to trim register */
|
||||
uint8_t regdata;
|
||||
|
||||
/* Variable to define limit to print aux data. */
|
||||
uint8_t limit = 20;
|
||||
|
||||
/* Accel, Gyro and Aux sensors are listed in array. */
|
||||
uint8_t sensor_list[3] = { BMI2_ACCEL, BMI2_GYRO, BMI2_AUX };
|
||||
|
||||
/* Structure to define the type of the sensor and its configurations. */
|
||||
struct bmi2_sens_config config[3];
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmm150_dev bmm150_dev;
|
||||
|
||||
/* bmm150 settings configuration */
|
||||
struct bmm150_settings settings;
|
||||
|
||||
/* bmm150 magnetometer data */
|
||||
struct bmm150_mag_data mag_data;
|
||||
|
||||
/* Structure to define type of sensor and their respective data. */
|
||||
struct bmi2_sensor_data sensor_data[3];
|
||||
|
||||
/* Variables to define read the accel and gyro data in float */
|
||||
float x = 0, y = 0, z = 0;
|
||||
|
||||
config[ACCEL].type = BMI2_ACCEL;
|
||||
config[GYRO].type = BMI2_GYRO;
|
||||
config[AUX].type = BMI2_AUX;
|
||||
|
||||
/* To enable the i2c interface settings for bmm150. */
|
||||
uint8_t bmm150_dev_addr = BMM150_DEFAULT_I2C_ADDRESS;
|
||||
bmm150_dev.intf_ptr = &bmm150_dev_addr;
|
||||
bmm150_dev.read = user_aux_read;
|
||||
bmm150_dev.write = user_aux_write;
|
||||
bmm150_dev.delay_us = user_delay_us;
|
||||
|
||||
/* As per datasheet, aux interface with bmi270 will support only for I2C */
|
||||
bmm150_dev.intf = BMM150_I2C_INTF;
|
||||
|
||||
sensor_data[ACCEL].type = BMI2_ACCEL;
|
||||
sensor_data[GYRO].type = BMI2_GYRO;
|
||||
sensor_data[AUX].type = BMI2_AUX;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Pull-up resistor 2k is set to the trim regiter */
|
||||
regdata = BMI2_ASDA_PUPSEL_2K;
|
||||
rslt = bmi2_set_regs(BMI2_AUX_IF_TRIM, ®data, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Enable the accel, gyro and aux sensor. */
|
||||
rslt = bmi270_sensor_enable(sensor_list, 3, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_get_sensor_config(config, 3, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Configurations for accel. */
|
||||
config[ACCEL].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
config[ACCEL].cfg.acc.bwp = BMI2_ACC_OSR2_AVG2;
|
||||
config[ACCEL].cfg.acc.odr = BMI2_ACC_ODR_100HZ;
|
||||
config[ACCEL].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* Configurations for gyro. */
|
||||
config[GYRO].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
config[GYRO].cfg.gyr.noise_perf = BMI2_GYR_RANGE_2000;
|
||||
config[GYRO].cfg.gyr.bwp = BMI2_GYR_OSR2_MODE;
|
||||
config[GYRO].cfg.gyr.odr = BMI2_GYR_ODR_100HZ;
|
||||
config[GYRO].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
config[GYRO].cfg.gyr.ois_range = BMI2_GYR_OIS_2000;
|
||||
|
||||
/* Configurations for aux. */
|
||||
config[AUX].cfg.aux.odr = BMI2_AUX_ODR_100HZ;
|
||||
config[AUX].cfg.aux.aux_en = BMI2_ENABLE;
|
||||
config[AUX].cfg.aux.i2c_device_addr = BMM150_DEFAULT_I2C_ADDRESS;
|
||||
config[AUX].cfg.aux.manual_en = BMI2_ENABLE;
|
||||
config[AUX].cfg.aux.fcu_write_en = BMI2_ENABLE;
|
||||
config[AUX].cfg.aux.man_rd_burst = BMI2_AUX_READ_LEN_3;
|
||||
config[AUX].cfg.aux.read_addr = BMM150_REG_DATA_X_LSB;
|
||||
|
||||
/* Set new configurations for accel, gyro and aux. */
|
||||
rslt = bmi270_set_sensor_config(config, 3, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmm150. */
|
||||
rslt = bmm150_init(&bmm150_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Set the power mode to normal mode. */
|
||||
settings.pwr_mode = BMM150_POWERMODE_NORMAL;
|
||||
rslt = bmm150_set_op_mode(&settings, &bmm150_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
rslt = bmi270_get_sensor_config(config, 3, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Disable manual mode so that the data mode is enabled. */
|
||||
config[AUX].cfg.aux.manual_en = BMI2_DISABLE;
|
||||
|
||||
/* Set the aux configurations. */
|
||||
rslt = bmi270_set_sensor_config(config, 3, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("MAGNETOMETER, ACCEL, AND GYRO DATA IN DATA MODE\n");
|
||||
|
||||
if (bmm150_dev.chip_id == BMM150_CHIP_ID)
|
||||
{
|
||||
while (limit--)
|
||||
{
|
||||
/* Delay has been added to get aux, accel and gyro data at the interval of every 0.05 second. */
|
||||
bmi2_dev.delay_us(50000, bmi2_dev.intf_ptr);
|
||||
|
||||
rslt = bmi270_get_sensor_data(sensor_data, 3, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("\nAcc_x = %d\t", sensor_data[ACCEL].sens_data.acc.x);
|
||||
printf("Acc_y = %d\t", sensor_data[ACCEL].sens_data.acc.y);
|
||||
printf("Acc_z = %d", sensor_data[ACCEL].sens_data.acc.z);
|
||||
|
||||
/* Converting lsb to meter per second squared for 16 bit accelerometer at 2G range. */
|
||||
x = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.x, 2, bmi2_dev.resolution);
|
||||
y = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.y, 2, bmi2_dev.resolution);
|
||||
z = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.z, 2, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in m/s2. */
|
||||
printf("\nAcc_ms2_X = %4.2f, Acc_ms2_Y = %4.2f, Acc_ms2_Z = %4.2f\n", x, y, z);
|
||||
|
||||
printf("\nGyr_X = %d\t", sensor_data[GYRO].sens_data.gyr.x);
|
||||
printf("Gyr_Y = %d\t", sensor_data[GYRO].sens_data.gyr.y);
|
||||
printf("Gyr_Z= %d", sensor_data[GYRO].sens_data.gyr.z);
|
||||
|
||||
/* Converting lsb to degree per second for 16 bit gyro at 2000dps range. */
|
||||
x = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.x, 2000, bmi2_dev.resolution);
|
||||
y = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.y, 2000, bmi2_dev.resolution);
|
||||
z = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.z, 2000, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in dps. */
|
||||
printf("\nGyro_DPS_X = %4.2f, Gyro_DPS_Y = %4.2f, Gyro_DPS_Z = %4.2f\n", x, y, z);
|
||||
|
||||
/* Compensating the raw auxiliary data available from the BMM150 API. */
|
||||
rslt = bmm150_aux_mag_data(sensor_data[AUX].sens_data.aux_data, &mag_data, &bmm150_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
printf("\nMag_x_axis = %d \t Mag_y_axis = %d \t Mag_z_axis = %d \t\n",
|
||||
mag_data.x,
|
||||
mag_data.y,
|
||||
mag_data.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function reads the data from auxiliary sensor in manual mode.
|
||||
*/
|
||||
static int8_t user_aux_read(uint8_t reg_addr, uint8_t *aux_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
int8_t rslt;
|
||||
|
||||
/* Discarding the parameter id as it is redundant */
|
||||
rslt = bmi2_read_aux_man_mode(reg_addr, aux_data, len, &bmi2_dev);
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function writes the data to auxiliary sensor in manual mode.
|
||||
*/
|
||||
static int8_t user_aux_write(uint8_t reg_addr, const uint8_t *aux_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
int8_t rslt;
|
||||
|
||||
/* Discarding the parameter id as it is redundant */
|
||||
rslt = bmi2_write_aux_man_mode(reg_addr, aux_data, len, &bmi2_dev);
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Delay function map to COINES platform
|
||||
*/
|
||||
static void user_delay_us(uint32_t period, void *intf_ptr)
|
||||
{
|
||||
coines_delay_usec(period);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (GRAVITY_EARTH * val * g_range) / half_scale;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (dps / ((half_scale) + BMI2_GYR_RANGE_2000)) * (val);
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= read_aux_manual_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
BMM150_SOURCE ?= ../../../bmm150
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270.c \
|
||||
$(BMM150_SOURCE)/bmm150.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(BMM150_SOURCE) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+322
@@ -0,0 +1,322 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270.h"
|
||||
#include "bmm150.h"
|
||||
#include "coines.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Macros to select the sensors */
|
||||
#define ACCEL UINT8_C(0x00)
|
||||
#define GYRO UINT8_C(0x01)
|
||||
#define AUX UINT8_C(0x02)
|
||||
|
||||
/*! Earth's gravity in m/s^2 */
|
||||
#define GRAVITY_EARTH (9.80665f)
|
||||
|
||||
/*****************************************************************************/
|
||||
/*! Structure declaration */
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/**
|
||||
* user_aux_read - Reads data from auxiliary sensor in manual mode.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[out] aux_data : Aux data pointer to store the read data.
|
||||
* @param[in] length : No of bytes to read.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval 0 -> Success
|
||||
* @retval < 0 -> Failure Info
|
||||
*/
|
||||
static int8_t user_aux_read(uint8_t reg_addr, uint8_t *aux_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/**
|
||||
* user_aux_write - Writes data to the auxiliary sensor in manual mode.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[out] aux_data : Aux data pointer to store the data being written.
|
||||
* @param[in] length : No of bytes to read.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval 0 -> Success
|
||||
* @retval < 0 -> Failure Info
|
||||
*/
|
||||
static int8_t user_aux_write(uint8_t reg_addr, const uint8_t *aux_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief This function provides the delay for required time (Microsecond) as per the input provided in some of the
|
||||
* APIs.
|
||||
*
|
||||
* @param[in] period_us : The required wait time in microsecond.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
static void user_delay_us(uint32_t period, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] g_range : Gravity range.
|
||||
* @param[in] bit_width : Resolution for accel.
|
||||
*
|
||||
* @return Gravity.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] dps : Degree per second.
|
||||
* @param[in] bit_width : Resolution for gyro.
|
||||
*
|
||||
* @return Degree per second.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width);
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to select the pull-up resistor which is set to trim register */
|
||||
uint8_t regdata;
|
||||
|
||||
/* Variable to define limit to print aux data. */
|
||||
uint8_t limit = 20;
|
||||
|
||||
/* Accel, Gyro and Aux sensors are listed in array. */
|
||||
uint8_t sensor_list[3] = { BMI2_ACCEL, BMI2_GYRO, BMI2_AUX };
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmm150_dev bmm150_dev;
|
||||
|
||||
/* bmm150 settings configuration */
|
||||
struct bmm150_settings settings;
|
||||
|
||||
/* bmm150 magnetometer data */
|
||||
struct bmm150_mag_data mag_data;
|
||||
|
||||
/* Structure to define the type of the sensor and its configurations. */
|
||||
struct bmi2_sens_config config[3];
|
||||
|
||||
/* Structure to define type of sensor and their respective data. */
|
||||
struct bmi2_sensor_data sensor_data[2];
|
||||
|
||||
/* Variables to define read the accel and gyro data in float */
|
||||
float x = 0, y = 0, z = 0;
|
||||
|
||||
config[ACCEL].type = BMI2_ACCEL;
|
||||
config[GYRO].type = BMI2_GYRO;
|
||||
config[AUX].type = BMI2_AUX;
|
||||
|
||||
sensor_data[ACCEL].type = BMI2_ACCEL;
|
||||
sensor_data[GYRO].type = BMI2_GYRO;
|
||||
|
||||
/* Array of eight bytes to store x, y, z and r axis aux data. */
|
||||
uint8_t aux_data[8] = { 0 };
|
||||
|
||||
/* To enable the i2c interface settings for bmm150. */
|
||||
uint8_t bmm150_dev_addr = BMM150_DEFAULT_I2C_ADDRESS;
|
||||
bmm150_dev.intf_ptr = &bmm150_dev_addr;
|
||||
bmm150_dev.read = user_aux_read;
|
||||
bmm150_dev.write = user_aux_write;
|
||||
bmm150_dev.delay_us = user_delay_us;
|
||||
|
||||
/* As per datasheet, aux interface with bmi270 will support only for I2C */
|
||||
bmm150_dev.intf = BMM150_I2C_INTF;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Pull-up resistor 2k is set to the trim register */
|
||||
regdata = BMI2_ASDA_PUPSEL_2K;
|
||||
rslt = bmi2_set_regs(BMI2_AUX_IF_TRIM, ®data, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Enable the accel, gyro and aux sensor. */
|
||||
rslt = bmi270_sensor_enable(sensor_list, 3, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_get_sensor_config(config, 3, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Configurations for accel. */
|
||||
config[ACCEL].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
config[ACCEL].cfg.acc.bwp = BMI2_ACC_OSR2_AVG2;
|
||||
config[ACCEL].cfg.acc.odr = BMI2_ACC_ODR_100HZ;
|
||||
config[ACCEL].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* Configurations for gyro. */
|
||||
config[GYRO].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
config[GYRO].cfg.gyr.noise_perf = BMI2_GYR_RANGE_2000;
|
||||
config[GYRO].cfg.gyr.bwp = BMI2_GYR_OSR2_MODE;
|
||||
config[GYRO].cfg.gyr.odr = BMI2_GYR_ODR_100HZ;
|
||||
config[GYRO].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
config[GYRO].cfg.gyr.ois_range = BMI2_GYR_OIS_2000;
|
||||
|
||||
/* Configurations for aux. */
|
||||
config[AUX].cfg.aux.odr = BMI2_AUX_ODR_100HZ;
|
||||
config[AUX].cfg.aux.aux_en = BMI2_ENABLE;
|
||||
config[AUX].cfg.aux.i2c_device_addr = BMM150_DEFAULT_I2C_ADDRESS;
|
||||
config[AUX].cfg.aux.manual_en = BMI2_ENABLE;
|
||||
config[AUX].cfg.aux.fcu_write_en = BMI2_ENABLE;
|
||||
config[AUX].cfg.aux.man_rd_burst = BMI2_AUX_READ_LEN_3;
|
||||
|
||||
/* Set new configurations for accel, gyro and aux. */
|
||||
rslt = bmi270_set_sensor_config(config, 3, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmm150. */
|
||||
rslt = bmm150_init(&bmm150_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Set the power mode to normal mode. */
|
||||
settings.pwr_mode = BMM150_POWERMODE_NORMAL;
|
||||
rslt = bmm150_set_op_mode(&settings, &bmm150_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("MAGNETOMETER, ACCEL AND GYRO DATA IN MANUAL MODE\n");
|
||||
|
||||
if (bmm150_dev.chip_id == BMM150_CHIP_ID)
|
||||
{
|
||||
while (limit--)
|
||||
{
|
||||
/* Delay has been added to get aux, accel and gyro data at the interval of every 0.05 second. */
|
||||
bmi2_dev.delay_us(50000, bmi2_dev.intf_ptr);
|
||||
|
||||
rslt = bmi270_get_sensor_data(sensor_data, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("\nAcc_x = %d\t", sensor_data[ACCEL].sens_data.acc.x);
|
||||
printf("Acc_y = %d\t", sensor_data[ACCEL].sens_data.acc.y);
|
||||
printf("Acc_z = %d", sensor_data[ACCEL].sens_data.acc.z);
|
||||
|
||||
/* Converting lsb to meter per second squared for 16 bit accelerometer at 2G range. */
|
||||
x = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.x, 2, bmi2_dev.resolution);
|
||||
y = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.y, 2, bmi2_dev.resolution);
|
||||
z = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.z, 2, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in m/s2. */
|
||||
printf("\nAcc_ms2_X = %4.2f, Acc_ms2_Y = %4.2f, Acc_ms2_Z = %4.2f\n", x, y, z);
|
||||
|
||||
printf("\nGyr_X = %d\t", sensor_data[GYRO].sens_data.gyr.x);
|
||||
printf("Gyr_Y = %d\t", sensor_data[GYRO].sens_data.gyr.y);
|
||||
printf("Gyr_Z = %d", sensor_data[GYRO].sens_data.gyr.z);
|
||||
|
||||
/* Converting lsb to degree per second for 16 bit gyro at 2000dps range. */
|
||||
x = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.x, 2000, bmi2_dev.resolution);
|
||||
y = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.y, 2000, bmi2_dev.resolution);
|
||||
z = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.z, 2000, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in dps. */
|
||||
printf("\nGyro_DPS_X = %4.2f, Gyro_DPS_Y = %4.2f, Gyro_DPS_Z = %4.2f\n", x, y, z);
|
||||
}
|
||||
|
||||
/* Read aux data from the bmm150 data registers. */
|
||||
rslt = bmi2_read_aux_man_mode(BMM150_REG_DATA_X_LSB, aux_data, 8, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Compensating the raw auxiliary data available from the BMM150 API. */
|
||||
rslt = bmm150_aux_mag_data(aux_data, &mag_data, &bmm150_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
printf("Mag_x_axis = %d \t Mag_y_axis = %d \t Mag_z_axis = %d \t\n", mag_data.x, mag_data.y,
|
||||
mag_data.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function reads the data from auxiliary sensor in manual mode.
|
||||
*/
|
||||
int8_t user_aux_read(uint8_t reg_addr, uint8_t *aux_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
int8_t rslt;
|
||||
|
||||
/* Discarding the parameter id as it is redundant */
|
||||
rslt = bmi2_read_aux_man_mode(reg_addr, aux_data, len, &bmi2_dev);
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function writes the data to auxiliary sensor in manual mode.
|
||||
*/
|
||||
int8_t user_aux_write(uint8_t reg_addr, const uint8_t *aux_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
int8_t rslt;
|
||||
|
||||
/* Discarding the parameter id as it is redundant */
|
||||
rslt = bmi2_write_aux_man_mode(reg_addr, aux_data, len, &bmi2_dev);
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Delay function map to COINES platform
|
||||
*/
|
||||
static void user_delay_us(uint32_t period, void *intf_ptr)
|
||||
{
|
||||
coines_delay_usec(period);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (GRAVITY_EARTH * val * g_range) / half_scale;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (dps / ((half_scale) + BMI2_GYR_RANGE_2000)) * (val);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= sig_motion.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,93 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define the type of sensor and its configurations. */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Accel sensor and significant-motion feature are listed in array. */
|
||||
uint8_t sens_list[2] = { BMI2_ACCEL, BMI2_SIG_MOTION };
|
||||
|
||||
/* Variable to get significant-motion interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Select features and their pins to be mapped to. */
|
||||
struct bmi2_sens_int_config sens_int = { .type = BMI2_SIG_MOTION, .hw_int_pin = BMI2_INT1 };
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the selected sensors. */
|
||||
rslt = bmi270_sensor_enable(sens_list, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config.type = BMI2_SIG_MOTION;
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_get_sensor_config(&config, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Map the feature interrupt for significant-motion. */
|
||||
rslt = bmi270_map_feat_int(&sens_int, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* By default the significant-motion interrupt occurs when the sensor is in motion for about 5 seconds.
|
||||
* */
|
||||
printf("Move the board for 5 secs in any direction\n");
|
||||
|
||||
do
|
||||
{
|
||||
/* To get the interrupt status of significant-motion. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the interrupt status of significant-motion. */
|
||||
if (int_status & BMI270_SIG_MOT_STATUS_MASK)
|
||||
{
|
||||
printf("Significant motion interrupt is generated\n");
|
||||
break;
|
||||
}
|
||||
} while (rslt == BMI2_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= step_activity.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Structure to define the type of sensor and their respective data. */
|
||||
struct bmi2_sensor_data sensor_data;
|
||||
|
||||
/* Structure to define the type of sensor and its configurations. */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Accel sensor and step activity feature are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_STEP_ACTIVITY };
|
||||
|
||||
/* Type of sensor to get step activity data. */
|
||||
sensor_data.type = BMI2_STEP_ACTIVITY;
|
||||
|
||||
/* Variable to get step activity interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint16_t loop = 10;
|
||||
|
||||
/* Select features and their pins to be mapped to. */
|
||||
struct bmi2_sens_int_config sens_int = { .type = BMI2_STEP_ACTIVITY, .hw_int_pin = BMI2_INT2 };
|
||||
|
||||
/* The step activities are listed in array. */
|
||||
const char *activity_output[4] = { "BMI2_STILL", "BMI2_WALK", "BMI2_RUN", "BMI2_UNKNOWN" };
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the selected sensor. */
|
||||
rslt = bmi270_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Configure the type of sensor. */
|
||||
config.type = BMI2_STEP_ACTIVITY;
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_get_sensor_config(&config, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Map the feature interrupt for step activity. */
|
||||
rslt = bmi270_map_feat_int(&sens_int, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("\nMove the board in steps to perform step activity:\n");
|
||||
|
||||
/* Loop to get step activity. */
|
||||
while (loop)
|
||||
{
|
||||
/* To get the interrupt status of step detector. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the interrupt status of step detector. */
|
||||
if (int_status & BMI270_STEP_ACT_STATUS_MASK)
|
||||
{
|
||||
printf("Step detected\n");
|
||||
|
||||
/* Get step activity output. */
|
||||
rslt = bmi270_get_sensor_data(&sensor_data, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Print the step activity output. */
|
||||
printf("Step activity = %s\n", activity_output[sensor_data.sens_data.activity_output]);
|
||||
|
||||
loop--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= step_counter.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static function declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for step counter.
|
||||
*
|
||||
* @param[in] bmi2_dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_feature_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Structure to define type of sensor and their respective data. */
|
||||
struct bmi2_sensor_data sensor_data;
|
||||
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Accel sensor and step counter feature are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_STEP_COUNTER };
|
||||
|
||||
/* Variable to get step counter interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Select features and their pins to be mapped to. */
|
||||
struct bmi2_sens_int_config sens_int = { .type = BMI2_STEP_COUNTER, .hw_int_pin = BMI2_INT2 };
|
||||
|
||||
/* Type of sensor to get step counter data. */
|
||||
sensor_data.type = BMI2_STEP_COUNTER;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the selected sensor. */
|
||||
rslt = bmi270_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Set the feature configuration for step counter. */
|
||||
rslt = set_feature_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("Step counter watermark level set to 1 (20 steps)\n");
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Map the step counter feature interrupt. */
|
||||
rslt = bmi270_map_feat_int(&sens_int, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Move the board in steps for 20 times to get step counter interrupt. */
|
||||
printf("Move the board in steps\n");
|
||||
|
||||
/* Loop to get number of steps counted. */
|
||||
do
|
||||
{
|
||||
/* To get the interrupt status of the step counter. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the interrupt status of the step counter. */
|
||||
if (int_status & BMI270_STEP_CNT_STATUS_MASK)
|
||||
{
|
||||
printf("Step counter interrupt occurred when watermark level (20 steps) is reached\n");
|
||||
|
||||
/* Get step counter output. */
|
||||
rslt = bmi270_get_sensor_data(&sensor_data, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Print the step counter output. */
|
||||
printf("No of steps counted = %ld", sensor_data.sens_data.step_counter_output);
|
||||
break;
|
||||
}
|
||||
} while (rslt == BMI2_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for step counter.
|
||||
*/
|
||||
static int8_t set_feature_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define the type of sensor and its configurations. */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Configure the type of sensor. */
|
||||
config.type = BMI2_STEP_COUNTER;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_get_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Setting water-mark level to 1 for step counter to get interrupt after 20 step counts. Every 20 steps once
|
||||
* output triggers. */
|
||||
config.cfg.step_counter.watermark_level = 1;
|
||||
|
||||
/* Set new configuration. */
|
||||
rslt = bmi270_set_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= wrist_gesture.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static function declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set the sensor configuration.
|
||||
*
|
||||
* @param[in] bmi2_dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t bmi2_set_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program */
|
||||
int main(void)
|
||||
{
|
||||
/* Variable to define result */
|
||||
int8_t rslt;
|
||||
|
||||
/* Initialize status of wrist gesture interrupt */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Select features and their pins to be mapped to */
|
||||
struct bmi2_sens_int_config sens_int = { .type = BMI2_WRIST_GESTURE, .hw_int_pin = BMI2_INT1 };
|
||||
|
||||
/* Sensor data structure */
|
||||
struct bmi2_sensor_data sens_data = { 0 };
|
||||
|
||||
/* The gesture movements are listed in array */
|
||||
const char *gesture_output[6] =
|
||||
{ "unknown_gesture", "push_arm_down", "pivot_up", "wrist_shake_jiggle", "flick_in", "flick_out" };
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
sens_data.type = BMI2_WRIST_GESTURE;
|
||||
|
||||
/* Set the sensor configuration */
|
||||
rslt = bmi2_set_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Map the feature interrupt */
|
||||
rslt = bmi270_map_feat_int(&sens_int, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("Flip the board in portrait/landscape mode:\n");
|
||||
|
||||
/* Loop to print the wrist gesture data when interrupt occurs */
|
||||
while (1)
|
||||
{
|
||||
/* Get the interrupt status of the wrist gesture */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if ((rslt == BMI2_OK) && (int_status & BMI270_WRIST_GEST_STATUS_MASK))
|
||||
{
|
||||
printf("Wrist gesture detected\n");
|
||||
|
||||
/* Get wrist gesture output */
|
||||
rslt = bmi270_get_sensor_data(&sens_data, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("Wrist gesture = %d\r\n", sens_data.sens_data.wrist_gesture_output);
|
||||
|
||||
printf("Gesture output = %s\n", gesture_output[sens_data.sens_data.wrist_gesture_output]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API sets the sensor configuration
|
||||
*/
|
||||
static int8_t bmi2_set_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Variable to define result */
|
||||
int8_t rslt;
|
||||
|
||||
/* List the sensors which are required to enable */
|
||||
uint8_t sens_list[2] = { BMI2_ACCEL, BMI2_WRIST_GESTURE };
|
||||
|
||||
/* Structure to define the type of the sensor and its configurations */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Configure type of feature */
|
||||
config.type = BMI2_WRIST_GESTURE;
|
||||
|
||||
/* Enable the selected sensors */
|
||||
rslt = bmi270_sensor_enable(sens_list, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Get default configurations for the type of feature selected */
|
||||
rslt = bmi270_get_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
config.cfg.wrist_gest.wearable_arm = BMI2_ARM_LEFT;
|
||||
|
||||
/* Set the new configuration along with interrupt mapping */
|
||||
rslt = bmi270_set_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= wrist_wear_wakeup.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static function declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set the sensor configuration.
|
||||
*
|
||||
* @param[in] bmi2_dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t bmi2_set_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program */
|
||||
int main(void)
|
||||
{
|
||||
/* Variable to define result */
|
||||
int8_t rslt;
|
||||
|
||||
/* Initialize status of wrist wear wakeup interrupt */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Select features and their pins to be mapped to */
|
||||
struct bmi2_sens_int_config sens_int = { .type = BMI2_WRIST_WEAR_WAKE_UP, .hw_int_pin = BMI2_INT1 };
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Set the sensor configuration */
|
||||
rslt = bmi2_set_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Map the feature interrupt */
|
||||
rslt = bmi270_map_feat_int(&sens_int, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("Tilt the board in landscape position to trigger wrist wear wakeup\n");
|
||||
|
||||
/* Loop to print the wrist wear wakeup data when interrupt occurs */
|
||||
while (1)
|
||||
{
|
||||
int_status = 0;
|
||||
|
||||
/* To get the interrupt status of the wrist wear wakeup */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the interrupt status of the wrist gesture */
|
||||
if ((rslt == BMI2_OK) && (int_status & BMI270_WRIST_WAKE_UP_STATUS_MASK))
|
||||
{
|
||||
printf("Wrist wear wakeup detected\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API sets the sensor configuration
|
||||
*/
|
||||
static int8_t bmi2_set_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Variable to define result */
|
||||
int8_t rslt;
|
||||
|
||||
/* List the sensors which are required to enable */
|
||||
uint8_t sens_list[2] = { BMI2_ACCEL, BMI2_WRIST_WEAR_WAKE_UP };
|
||||
|
||||
/* Structure to define the type of the sensor and its configurations */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Configure type of feature */
|
||||
config.type = BMI2_WRIST_WEAR_WAKE_UP;
|
||||
|
||||
/* Enable the selected sensors */
|
||||
rslt = bmi270_sensor_enable(sens_list, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Get default configurations for the type of feature selected */
|
||||
rslt = bmi270_get_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Set the new configuration */
|
||||
rslt = bmi270_set_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= accel.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_context.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,200 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_context.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Earth's gravity in m/s^2 */
|
||||
#define GRAVITY_EARTH (9.80665f)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] g_range : Gravity range.
|
||||
* @param[in] bit_width : Resolution for accel.
|
||||
*
|
||||
* @return Gravity.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to define limit to print accel data. */
|
||||
uint8_t limit = 20;
|
||||
|
||||
/* Assign accel sensor to variable. */
|
||||
uint8_t sensor_list = BMI2_ACCEL;
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Create an instance of sensor data structure. */
|
||||
struct bmi2_sensor_data sensor_data = { 0 };
|
||||
|
||||
/* Initialize the interrupt status of accel. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint8_t indx = 0;
|
||||
float x = 0, y = 0, z = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_context. */
|
||||
rslt = bmi270_context_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the accel sensor. */
|
||||
rslt = bmi270_context_sensor_enable(&sensor_list, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Accel configuration settings. */
|
||||
rslt = set_accel_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Assign accel sensor. */
|
||||
sensor_data.type = BMI2_ACCEL;
|
||||
printf("Accel and m/s2 data \n");
|
||||
printf("Accel data collected at 2G Range with 16-bit resolution\n");
|
||||
|
||||
/* Loop to print the accel data when interrupt occurs. */
|
||||
while (indx <= limit)
|
||||
{
|
||||
/* To get the status of accel data ready interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the accel data ready interrupt status and print the status for 10 samples. */
|
||||
if (int_status & BMI2_ACC_DRDY_INT_MASK)
|
||||
{
|
||||
/* Get accelerometer data for x, y and z axis. */
|
||||
rslt = bmi270_context_get_sensor_data(&sensor_data, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
printf("\nAcc_X = %d\t", sensor_data.sens_data.acc.x);
|
||||
printf("Acc_Y = %d\t", sensor_data.sens_data.acc.y);
|
||||
printf("Acc_Z = %d\r\n", sensor_data.sens_data.acc.z);
|
||||
|
||||
/* Converting lsb to meter per second squared for 16 bit accelerometer at 2G range. */
|
||||
x = lsb_to_mps2(sensor_data.sens_data.acc.x, 2, bmi2_dev.resolution);
|
||||
y = lsb_to_mps2(sensor_data.sens_data.acc.y, 2, bmi2_dev.resolution);
|
||||
z = lsb_to_mps2(sensor_data.sens_data.acc.z, 2, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in m/s2. */
|
||||
printf("\nAcc_ms2_X = %4.2f, Acc_ms2_Y = %4.2f, Acc_ms2_Z = %4.2f\n", x, y, z);
|
||||
|
||||
indx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*/
|
||||
static int8_t set_accel_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accelerometer configuration. */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config.type = BMI2_ACCEL;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_context_get_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config.cfg.acc.odr = BMI2_ACC_ODR_200HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config.cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples.
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config.cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config.cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set the accel configurations. */
|
||||
rslt = bmi270_context_set_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Map data ready interrupt to interrupt pin. */
|
||||
rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (GRAVITY_EARTH * val * g_range) / half_scale;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= accel_gyro.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_context.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+268
@@ -0,0 +1,268 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_context.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Earth's gravity in m/s^2 */
|
||||
#define GRAVITY_EARTH (9.80665f)
|
||||
|
||||
/*! Macros to select the sensors */
|
||||
#define ACCEL UINT8_C(0x00)
|
||||
#define GYRO UINT8_C(0x01)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] g_range : Gravity range.
|
||||
* @param[in] bit_width : Resolution for accel.
|
||||
*
|
||||
* @return Gravity.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] dps : Degree per second.
|
||||
* @param[in] bit_width : Resolution for gyro.
|
||||
*
|
||||
* @return Degree per second.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to define limit to print accel data. */
|
||||
uint8_t limit = 10;
|
||||
|
||||
/* Assign accel and gyro sensor to variable. */
|
||||
uint8_t sensor_list[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Create an instance of sensor data structure. */
|
||||
struct bmi2_sensor_data sensor_data[2] = { { 0 } };
|
||||
|
||||
/* Initialize the interrupt status of accel and gyro. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint8_t indx = 1;
|
||||
|
||||
float x = 0, y = 0, z = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_context. */
|
||||
rslt = bmi270_context_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the accel and gyro sensor. */
|
||||
rslt = bmi270_context_sensor_enable(sensor_list, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Accel and gyro configuration settings. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Assign accel and gyro sensor. */
|
||||
sensor_data[ACCEL].type = BMI2_ACCEL;
|
||||
sensor_data[GYRO].type = BMI2_GYRO;
|
||||
|
||||
/* Loop to print accel and gyro data when interrupt occurs. */
|
||||
while (indx <= limit)
|
||||
{
|
||||
/* To get the data ready interrupt status of accel and gyro. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the data ready interrupt status and print the status for 10 samples. */
|
||||
if ((int_status & BMI2_ACC_DRDY_INT_MASK) && (int_status & BMI2_GYR_DRDY_INT_MASK))
|
||||
{
|
||||
/* Get accel and gyro data for x, y and z axis. */
|
||||
rslt = bmi270_context_get_sensor_data(sensor_data, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("\n******* Accel(Raw and m/s2) Gyro(Raw and dps) data : %d *******\n", indx);
|
||||
|
||||
printf("\nAcc_x = %d\t", sensor_data[ACCEL].sens_data.acc.x);
|
||||
printf("Acc_y = %d\t", sensor_data[ACCEL].sens_data.acc.y);
|
||||
printf("Acc_z = %d", sensor_data[ACCEL].sens_data.acc.z);
|
||||
|
||||
/* Converting lsb to meter per second squared for 16 bit accelerometer at 2G range. */
|
||||
x = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.x, 2, bmi2_dev.resolution);
|
||||
y = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.y, 2, bmi2_dev.resolution);
|
||||
z = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.z, 2, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in m/s2. */
|
||||
printf("\nAcc_ms2_X = %4.2f, Acc_ms2_Y = %4.2f, Acc_ms2_Z = %4.2f\n", x, y, z);
|
||||
|
||||
printf("\nGyr_X = %d\t", sensor_data[GYRO].sens_data.gyr.x);
|
||||
printf("Gyr_Y = %d\t", sensor_data[GYRO].sens_data.gyr.y);
|
||||
printf("Gyr_Z = %d\n", sensor_data[GYRO].sens_data.gyr.z);
|
||||
|
||||
/* Converting lsb to degree per second for 16 bit gyro at 2000dps range. */
|
||||
x = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.x, 2000, bmi2_dev.resolution);
|
||||
y = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.y, 2000, bmi2_dev.resolution);
|
||||
z = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.z, 2000, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in dps. */
|
||||
printf("Gyro_DPS_X = %4.2f, Gyro_DPS_Y = %4.2f, Gyro_DPS_Z = %4.2f\n", x, y, z);
|
||||
|
||||
indx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accelerometer and gyro configuration. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[ACCEL].type = BMI2_ACCEL;
|
||||
config[GYRO].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_context_get_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Map data ready interrupt to interrupt pin. */
|
||||
rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config[ACCEL].cfg.acc.odr = BMI2_ACC_ODR_200HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[ACCEL].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples.
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[ACCEL].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[ACCEL].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config[GYRO].cfg.gyr.odr = BMI2_GYR_ODR_200HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[GYRO].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[GYRO].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[GYRO].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[GYRO].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set the accel and gyro configurations. */
|
||||
rslt = bmi270_context_set_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (GRAVITY_EARTH * val * g_range) / half_scale;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (dps / ((half_scale) + BMI2_GYR_RANGE_2000)) * (val);
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= activity_recognition.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_context.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_context.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static function declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for step counter.
|
||||
*
|
||||
* @param[in] bmi2_dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to define index for FIFO data */
|
||||
uint8_t count;
|
||||
|
||||
/* Various Activity recognitions are listed in array. */
|
||||
const char *activity_reg_output[6] = { "OTHERS", "STILL", "WALKING", "RUNNING", "ON_BICYCLE", "IN_VEHICLE" };
|
||||
|
||||
/* Accel sensor and step activity feature are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_ACTIVITY_RECOGNITION };
|
||||
|
||||
/* Array to define FIFO data */
|
||||
uint8_t fifo_data[516] = { 0 };
|
||||
|
||||
/* Variable to store number of activity frames */
|
||||
uint16_t act_frames;
|
||||
|
||||
/* Structure to define a FIFO */
|
||||
struct bmi2_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Structure to define output for activity recognition */
|
||||
struct bmi2_act_recog_output act_recog_data[5] = { { 0 } };
|
||||
|
||||
uint16_t fifo_length;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_context. */
|
||||
rslt = bmi270_context_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the selected sensor. */
|
||||
rslt = bmi270_context_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
rslt = set_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Update FIFO structure */
|
||||
fifoframe.data = fifo_data;
|
||||
fifoframe.length = 516;
|
||||
|
||||
rslt = bmi2_get_fifo_length(&fifo_length, &bmi2_dev);
|
||||
printf("Fifo length = %d \n", fifo_length);
|
||||
|
||||
/* Read FIFO data */
|
||||
rslt = bmi2_read_fifo_data(&fifoframe, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
while (rslt != BMI2_W_FIFO_EMPTY)
|
||||
{
|
||||
/* Provide the number of frames to be read */
|
||||
act_frames = 5;
|
||||
|
||||
printf("Requested FIFO data frames : %d\n", act_frames);
|
||||
|
||||
/* Get the activity output */
|
||||
rslt = bmi270_context_get_act_recog_output(act_recog_data, &act_frames, &fifoframe, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("Parsed FIFO data frames : %d\r\n", act_frames);
|
||||
|
||||
for (count = 0; count < act_frames; count++)
|
||||
{
|
||||
printf(
|
||||
"Activity Recognition output[%d]:Sensor time: %lu\t Previous activity: %s\t current: %s\n",
|
||||
count,
|
||||
act_recog_data[count].time_stamp,
|
||||
activity_reg_output[act_recog_data[count].prev_act],
|
||||
activity_reg_output[act_recog_data[count].curr_act]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
static int8_t set_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
uint8_t temp_data[2];
|
||||
|
||||
/* Disable advanced power save */
|
||||
rslt = bmi2_set_adv_power_save(BMI2_DISABLE, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Reset FIFO */
|
||||
rslt = bmi2_set_command_register(BMI2_FIFO_FLUSH_CMD, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("Move the board for activity recognition for 30 sec :\n");
|
||||
bmi2_dev->delay_us(30000000, bmi2_dev->intf_ptr);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
rslt = bmi2_get_regs(BMI2_FIFO_CONFIG_0_ADDR, temp_data, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,372 @@
|
||||
/**
|
||||
* Copyright (C) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "coines.h"
|
||||
#include "bmi2_defs.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definitions */
|
||||
#define BMI2XY_SHUTTLE_ID UINT16_C(0x1B8)
|
||||
|
||||
/*! Macro that defines read write length */
|
||||
#define READ_WRITE_LEN UINT8_C(46)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static variable definition */
|
||||
|
||||
/*! Variable that holds the I2C device address or SPI chip selection */
|
||||
static uint8_t dev_addr;
|
||||
|
||||
/******************************************************************************/
|
||||
/*! User interface functions */
|
||||
|
||||
/*!
|
||||
* I2C read function map to COINES platform
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_addr = *(uint8_t*)intf_ptr;
|
||||
|
||||
return coines_read_i2c(dev_addr, reg_addr, reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* I2C write function map to COINES platform
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_addr = *(uint8_t*)intf_ptr;
|
||||
|
||||
return coines_write_i2c(dev_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* SPI read function map to COINES platform
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_addr = *(uint8_t*)intf_ptr;
|
||||
|
||||
return coines_read_spi(dev_addr, reg_addr, reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* SPI write function map to COINES platform
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_addr = *(uint8_t*)intf_ptr;
|
||||
|
||||
return coines_write_spi(dev_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Delay function map to COINES platform
|
||||
*/
|
||||
void bmi2_delay_us(uint32_t period, void *intf_ptr)
|
||||
{
|
||||
coines_delay_usec(period);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Function to select the interface between SPI and I2C.
|
||||
* Also to initialize coines platform
|
||||
*/
|
||||
int8_t bmi2_interface_init(struct bmi2_dev *bmi, uint8_t intf)
|
||||
{
|
||||
int8_t rslt = BMI2_OK;
|
||||
struct coines_board_info board_info;
|
||||
|
||||
if (bmi != NULL)
|
||||
{
|
||||
int16_t result = coines_open_comm_intf(COINES_COMM_INTF_USB);
|
||||
if (result < COINES_SUCCESS)
|
||||
{
|
||||
printf(
|
||||
"\n Unable to connect with Application Board ! \n" " 1. Check if the board is connected and powered on. \n" " 2. Check if Application Board USB driver is installed. \n"
|
||||
" 3. Check if board is in use by another application. (Insufficient permissions to access USB) \n");
|
||||
exit(result);
|
||||
}
|
||||
|
||||
result = coines_get_board_info(&board_info);
|
||||
|
||||
#if defined(PC)
|
||||
setbuf(stdout, NULL);
|
||||
#endif
|
||||
|
||||
if (result == COINES_SUCCESS)
|
||||
{
|
||||
if ((board_info.shuttle_id != BMI2XY_SHUTTLE_ID))
|
||||
{
|
||||
printf("! Warning invalid sensor shuttle \n ," "This application will not support this sensor \n");
|
||||
exit(COINES_E_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
coines_set_shuttleboard_vdd_vddio_config(0, 0);
|
||||
coines_delay_msec(100);
|
||||
|
||||
/* Bus configuration : I2C */
|
||||
if (intf == BMI2_I2C_INTF)
|
||||
{
|
||||
printf("I2C Interface \n");
|
||||
|
||||
/* To initialize the user I2C function */
|
||||
dev_addr = BMI2_I2C_PRIM_ADDR;
|
||||
bmi->intf = BMI2_I2C_INTF;
|
||||
bmi->read = bmi2_i2c_read;
|
||||
bmi->write = bmi2_i2c_write;
|
||||
coines_config_i2c_bus(COINES_I2C_BUS_0, COINES_I2C_FAST_MODE);
|
||||
}
|
||||
/* Bus configuration : SPI */
|
||||
else if (intf == BMI2_SPI_INTF)
|
||||
{
|
||||
printf("SPI Interface \n");
|
||||
|
||||
/* To initialize the user SPI function */
|
||||
dev_addr = COINES_SHUTTLE_PIN_7;
|
||||
bmi->intf = BMI2_SPI_INTF;
|
||||
bmi->read = bmi2_spi_read;
|
||||
bmi->write = bmi2_spi_write;
|
||||
coines_config_spi_bus(COINES_SPI_BUS_0, COINES_SPI_SPEED_5_MHZ, COINES_SPI_MODE3);
|
||||
coines_set_pin_config(COINES_SHUTTLE_PIN_7, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_HIGH);
|
||||
}
|
||||
|
||||
/* Assign device address to interface pointer */
|
||||
bmi->intf_ptr = &dev_addr;
|
||||
|
||||
/* Configure delay in microseconds */
|
||||
bmi->delay_us = bmi2_delay_us;
|
||||
|
||||
/* Configure max read/write length (in bytes) ( Supported length depends on target machine) */
|
||||
bmi->read_write_len = READ_WRITE_LEN;
|
||||
|
||||
/* Assign to NULL to load the default config file. */
|
||||
bmi->config_file_ptr = NULL;
|
||||
|
||||
coines_delay_usec(10000);
|
||||
|
||||
coines_set_shuttleboard_vdd_vddio_config(3300, 3300);
|
||||
|
||||
coines_delay_usec(10000);
|
||||
}
|
||||
else
|
||||
{
|
||||
rslt = BMI2_E_NULL_PTR;
|
||||
}
|
||||
|
||||
return rslt;
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Prints the execution status of the APIs.
|
||||
*/
|
||||
void bmi2_error_codes_print_result(int8_t rslt)
|
||||
{
|
||||
switch (rslt)
|
||||
{
|
||||
case BMI2_OK:
|
||||
|
||||
/* Do nothing */
|
||||
break;
|
||||
|
||||
case BMI2_W_FIFO_EMPTY:
|
||||
printf("Warning [%d] : FIFO empty\r\n", rslt);
|
||||
break;
|
||||
case BMI2_W_PARTIAL_READ:
|
||||
printf("Warning [%d] : FIFO partial read\r\n", rslt);
|
||||
break;
|
||||
case BMI2_E_NULL_PTR:
|
||||
printf(
|
||||
"Error [%d] : Null pointer error. It occurs when the user tries to assign value (not address) to a pointer," " which has been initialized to NULL.\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_COM_FAIL:
|
||||
printf(
|
||||
"Error [%d] : Communication failure error. It occurs due to read/write operation failure and also due " "to power failure during communication\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_DEV_NOT_FOUND:
|
||||
printf("Error [%d] : Device not found error. It occurs when the device chip id is incorrectly read\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_SENSOR:
|
||||
printf(
|
||||
"Error [%d] : Invalid sensor error. It occurs when there is a mismatch in the requested feature with the " "available one\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_SELF_TEST_FAIL:
|
||||
printf(
|
||||
"Error [%d] : Self-test failed error. It occurs when the validation of accel self-test data is " "not satisfied\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_INT_PIN:
|
||||
printf(
|
||||
"Error [%d] : Invalid interrupt pin error. It occurs when the user tries to configure interrupt pins " "apart from INT1 and INT2\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_OUT_OF_RANGE:
|
||||
printf(
|
||||
"Error [%d] : Out of range error. It occurs when the data exceeds from filtered or unfiltered data from " "fifo and also when the range exceeds the maximum range for accel and gyro while performing FOC\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ACC_INVALID_CFG:
|
||||
printf(
|
||||
"Error [%d] : Invalid Accel configuration error. It occurs when there is an error in accel configuration" " register which could be one among range, BW or filter performance in reg address 0x40\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_GYRO_INVALID_CFG:
|
||||
printf(
|
||||
"Error [%d] : Invalid Gyro configuration error. It occurs when there is a error in gyro configuration" "register which could be one among range, BW or filter performance in reg address 0x42\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ACC_GYR_INVALID_CFG:
|
||||
printf(
|
||||
"Error [%d] : Invalid Accel-Gyro configuration error. It occurs when there is a error in accel and gyro" " configuration registers which could be one among range, BW or filter performance in reg address 0x40 " "and 0x42\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_CONFIG_LOAD:
|
||||
printf(
|
||||
"Error [%d] : Configuration load error. It occurs when failure observed while loading the configuration " "into the sensor\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_PAGE:
|
||||
printf(
|
||||
"Error [%d] : Invalid page error. It occurs due to failure in writing the correct feature configuration " "from selected page\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_SET_APS_FAIL:
|
||||
printf(
|
||||
"Error [%d] : APS failure error. It occurs due to failure in write of advance power mode configuration " "register\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_AUX_INVALID_CFG:
|
||||
printf(
|
||||
"Error [%d] : Invalid AUX configuration error. It occurs when the auxiliary interface settings are not " "enabled properly\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_AUX_BUSY:
|
||||
printf(
|
||||
"Error [%d] : AUX busy error. It occurs when the auxiliary interface buses are engaged while configuring" " the AUX\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_REMAP_ERROR:
|
||||
printf(
|
||||
"Error [%d] : Remap error. It occurs due to failure in assigning the remap axes data for all the axes " "after change in axis position\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_GYR_USER_GAIN_UPD_FAIL:
|
||||
printf(
|
||||
"Error [%d] : Gyro user gain update fail error. It occurs when the reading of user gain update status " "fails\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_SELF_TEST_NOT_DONE:
|
||||
printf(
|
||||
"Error [%d] : Self-test not done error. It occurs when the self-test process is ongoing or not " "completed\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_INPUT:
|
||||
printf("Error [%d] : Invalid input error. It occurs when the sensor input validity fails\r\n", rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_STATUS:
|
||||
printf("Error [%d] : Invalid status error. It occurs when the feature/sensor validity fails\r\n", rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_CRT_ERROR:
|
||||
printf("Error [%d] : CRT error. It occurs when the CRT test has failed\r\n", rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ST_ALREADY_RUNNING:
|
||||
printf(
|
||||
"Error [%d] : Self-test already running error. It occurs when the self-test is already running and " "another has been initiated\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_CRT_READY_FOR_DL_FAIL_ABORT:
|
||||
printf(
|
||||
"Error [%d] : CRT ready for download fail abort error. It occurs when download in CRT fails due to wrong " "address location\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_DL_ERROR:
|
||||
printf(
|
||||
"Error [%d] : Download error. It occurs when write length exceeds that of the maximum burst length\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_PRECON_ERROR:
|
||||
printf(
|
||||
"Error [%d] : Pre-conditional error. It occurs when precondition to start the feature was not " "completed\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ABORT_ERROR:
|
||||
printf("Error [%d] : Abort error. It occurs when the device was shaken during CRT test\r\n", rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_WRITE_CYCLE_ONGOING:
|
||||
printf(
|
||||
"Error [%d] : Write cycle ongoing error. It occurs when the write cycle is already running and another " "has been initiated\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ST_NOT_RUNING:
|
||||
printf(
|
||||
"Error [%d] : Self-test is not running error. It occurs when self-test running is disabled while it's " "running\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_DATA_RDY_INT_FAILED:
|
||||
printf(
|
||||
"Error [%d] : Data ready interrupt error. It occurs when the sample count exceeds the FOC sample limit " "and data ready status is not updated\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_FOC_POSITION:
|
||||
printf(
|
||||
"Error [%d] : Invalid FOC position error. It occurs when average FOC data is obtained for the wrong" " axes\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Error [%d] : Unknown error code\r\n", rslt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Deinitializes coines platform
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
void bmi2_coines_deinit(void)
|
||||
{
|
||||
coines_close_comm_intf(COINES_COMM_INTF_USB);
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#ifndef _COMMON_H
|
||||
#define _COMMON_H
|
||||
|
||||
/*! CPP guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "bmi2.h"
|
||||
|
||||
/*!
|
||||
* @brief Function for reading the sensor's registers through I2C bus.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[out] reg_data : Pointer to the data buffer to store the read data.
|
||||
* @param[in] length : No of bytes to read.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval = BMI2_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMI2_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Function for writing the sensor's registers through I2C bus.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[in] reg_data : Pointer to the data buffer whose value is to be written.
|
||||
* @param[in] length : No of bytes to write.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval = BMI2_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMI2_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Function for reading the sensor's registers through SPI bus.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[out] reg_data : Pointer to the data buffer to store the read data.
|
||||
* @param[in] length : No of bytes to read.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval = BMI2_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMI2_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Function for writing the sensor's registers through SPI bus.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[in] reg_data : Pointer to the data buffer whose data has to be written.
|
||||
* @param[in] length : No of bytes to write.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval = BMI2_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMI2_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief This function provides the delay for required time (Microsecond) as per the input provided in some of the
|
||||
* APIs.
|
||||
*
|
||||
* @param[in] period_us : The required wait time in microsecond.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return void.
|
||||
*
|
||||
*/
|
||||
void bmi2_delay_us(uint32_t period, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Function to select the interface between SPI and I2C.
|
||||
*
|
||||
* @param[in] bma : Structure instance of bmi2_dev
|
||||
* @param[in] intf : Interface selection parameter
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval 0 -> Success
|
||||
* @retval < 0 -> Failure Info
|
||||
*/
|
||||
int8_t bmi2_interface_init(struct bmi2_dev *bma, uint8_t intf);
|
||||
|
||||
/*!
|
||||
* @brief Prints the execution status of the APIs.
|
||||
*
|
||||
* @param[in] rslt : Error code returned by the API whose execution status has to be printed.
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
void bmi2_error_codes_print_result(int8_t rslt);
|
||||
|
||||
/*!
|
||||
* @brief Deinitializes coines platform
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
void bmi2_coines_deinit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* End of CPP guard */
|
||||
|
||||
#endif /* _COMMON_H */
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= component_retrim.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_context.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_context.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_context. */
|
||||
rslt = bmi270_context_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* This API runs the CRT process. */
|
||||
rslt = bmi2_do_crt(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Do not move the board while doing CRT. If so, it will throw an abort error. */
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("CRT successfully completed.");
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_full_header_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_context.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+315
@@ -0,0 +1,315 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_context.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macros */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data. */
|
||||
#define BMI2_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(2048)
|
||||
|
||||
/*! Length of data to be read from FIFO. */
|
||||
#define BMI2_FIFO_RAW_DATA_USER_LENGTH UINT16_C(2048)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO. */
|
||||
|
||||
/*! Calculation for frame count: Total frame count = Fifo buffer size(2048)/ Total frames(6 Accel, 6 Gyro and 1 header,
|
||||
* totaling to 13) which equals to 157.
|
||||
*/
|
||||
#define BMI2_FIFO_ACCEL_FRAME_COUNT UINT8_C(157)
|
||||
|
||||
/*! Number of gyro frames to be extracted from FIFO. */
|
||||
#define BMI2_FIFO_GYRO_FRAME_COUNT UINT8_C(157)
|
||||
|
||||
/*! Macro to read sensortime byte in FIFO. */
|
||||
#define SENSORTIME_OVERHEAD_BYTE UINT8_C(3)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
uint16_t index = 0;
|
||||
uint16_t fifo_length = 0;
|
||||
uint16_t config = 0;
|
||||
|
||||
/* To read sensortime, extra 3 bytes are added to fifo buffer. */
|
||||
uint16_t fifo_buffer_size = BMI2_FIFO_RAW_DATA_BUFFER_SIZE + SENSORTIME_OVERHEAD_BYTE;
|
||||
|
||||
/* Variable to get fifo full interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint16_t accel_frame_length = BMI2_FIFO_ACCEL_FRAME_COUNT;
|
||||
|
||||
uint16_t gyro_frame_length = BMI2_FIFO_GYRO_FRAME_COUNT;
|
||||
|
||||
/* Variable to store the available frame length count in FIFO */
|
||||
uint8_t frame_count;
|
||||
|
||||
int8_t try = 1;
|
||||
|
||||
/* Number of bytes of FIFO data. */
|
||||
uint8_t fifo_data[fifo_buffer_size];
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 157 * (6 axes + 1 header bytes) = 1099 bytes */
|
||||
struct bmi2_sens_axes_data fifo_accel_data[BMI2_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Array of gyro frames -> Total bytes =
|
||||
* 157 * (6 axes + 1 header bytes) = 1099 bytes */
|
||||
struct bmi2_sens_axes_data fifo_gyro_data[BMI2_FIFO_GYRO_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure. */
|
||||
struct bmi2_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Accel and gyro sensor are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_context. */
|
||||
rslt = bmi270_context_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Enable accel and gyro sensor. */
|
||||
rslt = bmi270_context_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Configuration settings for accel and gyro. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Before setting FIFO, disable the advance power save mode. */
|
||||
rslt = bmi2_set_adv_power_save(BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initially disable all configurations in fifo. */
|
||||
rslt = bmi2_get_fifo_config(&config, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initially disable all configurations in fifo. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ALL_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Update FIFO structure. */
|
||||
/* Mapping the buffer to store the fifo data. */
|
||||
fifoframe.data = fifo_data;
|
||||
|
||||
/* Length of FIFO frame. */
|
||||
/* To read sensortime, extra 3 bytes are added to fifo user length. */
|
||||
fifoframe.length = BMI2_FIFO_RAW_DATA_USER_LENGTH + SENSORTIME_OVERHEAD_BYTE;
|
||||
|
||||
/* Set FIFO configuration by enabling accel, gyro and timestamp.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is in FIFO mode.
|
||||
* NOTE 3: Sensortime is enabled by default */
|
||||
printf("FIFO is configured in header mode\n");
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ACC_EN | BMI2_FIFO_GYR_EN, BMI2_ENABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Map FIFO full interrupt. */
|
||||
fifoframe.data_int_map = BMI2_FFULL_INT;
|
||||
rslt = bmi2_map_data_int(fifoframe.data_int_map, BMI2_INT1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
while (try <= 10)
|
||||
{
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if ((rslt == BMI2_OK) && (int_status & BMI2_FFULL_INT_STATUS_MASK))
|
||||
{
|
||||
printf("\nIteration : %d\n", try);
|
||||
|
||||
accel_frame_length = BMI2_FIFO_ACCEL_FRAME_COUNT;
|
||||
|
||||
gyro_frame_length = BMI2_FIFO_GYRO_FRAME_COUNT;
|
||||
|
||||
rslt = bmi2_get_fifo_length(&fifo_length, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("\nFIFO data bytes available : %d \n", fifo_length);
|
||||
printf("\nFIFO data bytes requested : %d \n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data. */
|
||||
rslt = bmi2_read_fifo_data(&fifoframe, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("\nFIFO accel frames requested : %d \n", accel_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_accel(fifo_accel_data, &accel_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO accel frames extracted : %d \n", accel_frame_length);
|
||||
|
||||
printf("\nFIFO gyro frames requested : %d \n", gyro_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract gyro data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_gyro(fifo_gyro_data, &gyro_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO gyro frames extracted : %d \n", gyro_frame_length);
|
||||
|
||||
/* Calculating the frame count from the available bytes in FIFO
|
||||
* frame_length = (available_fifo_bytes / (acc_frame_len + gyro_frame_len + header_byte)) */
|
||||
frame_count = (fifo_length / (BMI2_FIFO_ACC_GYR_LENGTH + 1));
|
||||
printf("\nAvailable frame count from available bytes: %d\n", frame_count);
|
||||
|
||||
printf("\nExtracted accel frames\n");
|
||||
|
||||
if (accel_frame_length > frame_count)
|
||||
{
|
||||
accel_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer. */
|
||||
for (index = 0; index < accel_frame_length; index++)
|
||||
{
|
||||
printf("ACCEL[%d] X : %d\t Y : %d\t Z : %d\n", index, fifo_accel_data[index].x,
|
||||
fifo_accel_data[index].y, fifo_accel_data[index].z);
|
||||
}
|
||||
|
||||
printf("\nExtracted gyro frames\n");
|
||||
|
||||
if (gyro_frame_length > frame_count)
|
||||
{
|
||||
gyro_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed gyro data from the FIFO buffer. */
|
||||
for (index = 0; index < gyro_frame_length; index++)
|
||||
{
|
||||
printf("GYRO[%d] X : %d\t Y : %d\t Z : %d\n",
|
||||
index,
|
||||
fifo_gyro_data[index].x,
|
||||
fifo_gyro_data[index].y,
|
||||
fifo_gyro_data[index].z);
|
||||
}
|
||||
|
||||
/* Print control frames like sensor time and skipped frame count. */
|
||||
printf("\nSkipped frame count = %d\n", fifoframe.skipped_frame_count);
|
||||
|
||||
printf("Sensor time = %lu\r\n", fifoframe.sensor_time);
|
||||
|
||||
try++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accel and gyro configurations. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[0].type = BMI2_ACCEL;
|
||||
config[1].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_context_get_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Accel configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[0].cfg.acc.odr = BMI2_ACC_ODR_25HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[0].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[0].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Gyro configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[1].cfg.gyr.odr = BMI2_GYR_ODR_50HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope Bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[1].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[1].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set new configurations. */
|
||||
rslt = bmi270_context_set_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_full_headerless_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_context.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+304
@@ -0,0 +1,304 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_context.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macros */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMI2_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(2048)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMI2_FIFO_RAW_DATA_USER_LENGTH UINT16_C(2048)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO */
|
||||
|
||||
/*! Calculation for frame count: Total frame count = Fifo buffer size(2048)/ Total frames(6 Accel, 6 Gyro totaling to
|
||||
* 12) which equals to 170.
|
||||
*/
|
||||
#define BMI2_FIFO_ACCEL_FRAME_COUNT UINT8_C(169)
|
||||
|
||||
/*! Number of gyro frames to be extracted from FIFO */
|
||||
#define BMI2_FIFO_GYRO_FRAME_COUNT UINT8_C(169)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
uint16_t index = 0;
|
||||
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
uint8_t try = 1;
|
||||
|
||||
/* Variable to get fifo full interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint16_t accel_frame_length;
|
||||
|
||||
uint16_t gyro_frame_length;
|
||||
|
||||
/* Variable to store the available frame length count in FIFO */
|
||||
uint8_t frame_count;
|
||||
|
||||
/* Number of bytes of FIFO data. */
|
||||
uint8_t fifo_data[BMI2_FIFO_RAW_DATA_BUFFER_SIZE] = { 0 };
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 170 * (6 axes bytes) = 1020 bytes */
|
||||
struct bmi2_sens_axes_data fifo_accel_data[BMI2_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Array of gyro frames -> Total bytes =
|
||||
* 170 * (6 axes bytes) = 1020 bytes */
|
||||
struct bmi2_sens_axes_data fifo_gyro_data[BMI2_FIFO_GYRO_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure. */
|
||||
struct bmi2_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Accel and gyro sensor are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_context. */
|
||||
rslt = bmi270_context_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Enable accel and gyro sensor. */
|
||||
rslt = bmi270_context_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Configuration settings for accel and gyro. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Before setting FIFO, disable the advance power save mode. */
|
||||
rslt = bmi2_set_adv_power_save(BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initially disable all configurations in fifo. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ALL_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Update FIFO structure. */
|
||||
/* Mapping the buffer to store the fifo data. */
|
||||
fifoframe.data = fifo_data;
|
||||
|
||||
/* Length of FIFO frame. */
|
||||
fifoframe.length = BMI2_FIFO_RAW_DATA_USER_LENGTH;
|
||||
|
||||
/* Set FIFO configuration by enabling accel, gyro.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ACC_EN | BMI2_FIFO_GYR_EN, BMI2_ENABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("FIFO is configured in headerless mode\n");
|
||||
|
||||
/* To enable headerless mode, disable the header. */
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_HEADER_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
}
|
||||
|
||||
/* Map FIFO full interrupt. */
|
||||
fifoframe.data_int_map = BMI2_FFULL_INT;
|
||||
rslt = bmi2_map_data_int(fifoframe.data_int_map, BMI2_INT1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
while (try <= 10)
|
||||
{
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if ((rslt == BMI2_OK) && (int_status & BMI2_FFULL_INT_STATUS_MASK))
|
||||
{
|
||||
printf("\nIteration : %d\n", try);
|
||||
|
||||
rslt = bmi2_get_fifo_length(&fifo_length, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
accel_frame_length = BMI2_FIFO_ACCEL_FRAME_COUNT;
|
||||
gyro_frame_length = BMI2_FIFO_GYRO_FRAME_COUNT;
|
||||
|
||||
printf("\nFIFO data bytes available : %d \n", fifo_length);
|
||||
printf("\nFIFO data bytes requested : %d \n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data. */
|
||||
rslt = bmi2_read_fifo_data(&fifoframe, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("\nFIFO accel frames requested : %d \n", accel_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_accel(fifo_accel_data, &accel_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO accel frames extracted : %d \n", accel_frame_length);
|
||||
|
||||
printf("\nFIFO gyro frames requested : %d \n", gyro_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract gyro data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_gyro(fifo_gyro_data, &gyro_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO gyro frames extracted : %d \n", gyro_frame_length);
|
||||
|
||||
/* Calculating the frame count from the available bytes in FIFO
|
||||
* frame_length = (available_fifo_bytes / (acc_frame_len + gyro_frame_len)) */
|
||||
frame_count = (fifo_length / (BMI2_FIFO_ACC_GYR_LENGTH));
|
||||
printf("\nAvailable frame count from available bytes: %d\n", frame_count);
|
||||
|
||||
printf("\nExtracted accel frames\n");
|
||||
|
||||
if (accel_frame_length > frame_count)
|
||||
{
|
||||
accel_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer. */
|
||||
for (index = 0; index < accel_frame_length; index++)
|
||||
{
|
||||
printf("ACCEL[%d] X : %d\t Y : %d\t Z : %d\n", index, fifo_accel_data[index].x,
|
||||
fifo_accel_data[index].y, fifo_accel_data[index].z);
|
||||
}
|
||||
|
||||
printf("\nExtracted gyro frames\n");
|
||||
|
||||
if (gyro_frame_length > frame_count)
|
||||
{
|
||||
gyro_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed gyro data from the FIFO buffer. */
|
||||
for (index = 0; index < gyro_frame_length; index++)
|
||||
{
|
||||
printf("GYRO[%d] X : %d\t Y : %d\t Z : %d\n",
|
||||
index,
|
||||
fifo_gyro_data[index].x,
|
||||
fifo_gyro_data[index].y,
|
||||
fifo_gyro_data[index].z);
|
||||
}
|
||||
}
|
||||
|
||||
try++;
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accel and gyro configurations. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[0].type = BMI2_ACCEL;
|
||||
config[1].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_context_get_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Accel configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[0].cfg.acc.odr = BMI2_ACC_ODR_100HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[0].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[0].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Gyro configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[1].cfg.gyr.odr = BMI2_GYR_ODR_100HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope Bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[1].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[1].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set new configurations. */
|
||||
rslt = bmi270_context_set_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_watermark_header_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_context.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+335
@@ -0,0 +1,335 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_context.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macros */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMI2_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(2048)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMI2_FIFO_RAW_DATA_USER_LENGTH UINT16_C(2048)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO */
|
||||
|
||||
/*!
|
||||
* Calculation:
|
||||
* fifo_watermark_level = 650, accel_frame_len = 6, gyro_frame_len = 6 header_byte = 1.
|
||||
* fifo_accel_frame_count = (650 / (6 + 6 + 1 )) = 50 frames
|
||||
* NOTE: Extra frames are read in order to get sensor time
|
||||
*/
|
||||
#define BMI2_FIFO_ACCEL_FRAME_COUNT UINT8_C(55)
|
||||
|
||||
/*! Number of gyro frames to be extracted from FIFO */
|
||||
#define BMI2_FIFO_GYRO_FRAME_COUNT UINT8_C(55)
|
||||
|
||||
/*! Setting a watermark level in FIFO */
|
||||
#define BMI270_FIFO_WATERMARK_LEVEL UINT16_C(650)
|
||||
|
||||
/*! Macro to read sensortime byte in FIFO */
|
||||
#define SENSORTIME_OVERHEAD_BYTE UINT8_C(3)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to store the available frame length count in FIFO */
|
||||
uint8_t frame_count;
|
||||
|
||||
/* Variable to index bytes. */
|
||||
uint16_t index = 0;
|
||||
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
uint16_t accel_frame_length;
|
||||
|
||||
uint16_t gyro_frame_length;
|
||||
|
||||
uint8_t try = 1;
|
||||
|
||||
/* To read sensortime, extra 3 bytes are added to fifo buffer */
|
||||
uint16_t fifo_buffer_size = BMI2_FIFO_RAW_DATA_BUFFER_SIZE + SENSORTIME_OVERHEAD_BYTE;
|
||||
|
||||
/* Number of bytes of FIFO data. */
|
||||
uint8_t fifo_data[fifo_buffer_size];
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 55 * (6 axes bytes) = 330 bytes */
|
||||
struct bmi2_sens_axes_data fifo_accel_data[BMI2_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Array of gyro frames -> Total bytes =
|
||||
* 55 * (6 axes bytes) = 330 bytes */
|
||||
struct bmi2_sens_axes_data fifo_gyro_data[BMI2_FIFO_GYRO_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure. */
|
||||
struct bmi2_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Accel and gyro sensor are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Variable to get fifo water-mark interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint16_t watermark = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_context. */
|
||||
rslt = bmi270_context_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Enable accel and gyro sensor. */
|
||||
rslt = bmi270_context_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Configuration settings for accel and gyro. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Before setting FIFO, disable the advance power save mode. */
|
||||
rslt = bmi2_set_adv_power_save(BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initially disable all configurations in fifo. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ALL_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Update FIFO structure. */
|
||||
/* Mapping the buffer to store the fifo data. */
|
||||
fifoframe.data = fifo_data;
|
||||
|
||||
/* Length of FIFO frame. */
|
||||
/* To read sensortime, extra 3 bytes are added to fifo user length. */
|
||||
fifoframe.length = BMI2_FIFO_RAW_DATA_USER_LENGTH + SENSORTIME_OVERHEAD_BYTE;
|
||||
|
||||
/* Set FIFO configuration by enabling accel, gyro and timestamp.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode.
|
||||
* NOTE 3: Sensortime is enabled by default */
|
||||
printf("FIFO is configured in header mode\n");
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ACC_EN | BMI2_FIFO_GYR_EN, BMI2_ENABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* FIFO water-mark interrupt is enabled. */
|
||||
fifoframe.data_int_map = BMI2_FWM_INT;
|
||||
|
||||
/* Map water-mark interrupt to the required interrupt pin. */
|
||||
rslt = bmi2_map_data_int(fifoframe.data_int_map, BMI2_INT1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Set water-mark level. */
|
||||
fifoframe.wm_lvl = BMI270_FIFO_WATERMARK_LEVEL;
|
||||
|
||||
/* Set the water-mark level if water-mark interrupt is mapped. */
|
||||
rslt = bmi2_set_fifo_wm(fifoframe.wm_lvl, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
rslt = bmi2_get_fifo_wm(&watermark, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
printf("\nFIFO watermark level is %d\n", watermark);
|
||||
|
||||
while (try <= 10)
|
||||
{
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the status of FIFO watermark interrupt. */
|
||||
if ((rslt == BMI2_OK) && (int_status & BMI2_FWM_INT_STATUS_MASK))
|
||||
{
|
||||
printf("\nIteration : %d\n", try);
|
||||
|
||||
printf("\nWatermark interrupt occurred\n");
|
||||
|
||||
rslt = bmi2_get_fifo_length(&fifo_length, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
accel_frame_length = BMI2_FIFO_ACCEL_FRAME_COUNT;
|
||||
gyro_frame_length = BMI2_FIFO_GYRO_FRAME_COUNT;
|
||||
|
||||
printf("\nFIFO data bytes available : %d \n", fifo_length);
|
||||
printf("\nFIFO data bytes requested : %d \n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data. */
|
||||
rslt = bmi2_read_fifo_data(&fifoframe, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("\nFIFO accel frames requested : %d \n", accel_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_accel(fifo_accel_data, &accel_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO accel frames extracted : %d \n", accel_frame_length);
|
||||
|
||||
printf("\nFIFO gyro frames requested : %d \n", gyro_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract gyro data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_gyro(fifo_gyro_data, &gyro_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO gyro frames extracted : %d \n", gyro_frame_length);
|
||||
|
||||
/* Calculating the frame count from the available bytes in FIFO
|
||||
* frame_length = (available_fifo_bytes / (acc_frame_len + gyro_frame_len + header_byte)) */
|
||||
frame_count = (fifo_length / (BMI2_FIFO_ACC_GYR_LENGTH + 1));
|
||||
printf("\nAvailable frame count from available bytes: %d\n", frame_count);
|
||||
|
||||
printf("\nExracted accel frames\n");
|
||||
|
||||
if (accel_frame_length > frame_count)
|
||||
{
|
||||
accel_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer. */
|
||||
for (index = 0; index < accel_frame_length; index++)
|
||||
{
|
||||
printf("ACCEL[%d] X : %d\t Y : %d\t Z : %d\n", index, fifo_accel_data[index].x,
|
||||
fifo_accel_data[index].y, fifo_accel_data[index].z);
|
||||
}
|
||||
|
||||
printf("\nExtracted gyro frames\n");
|
||||
|
||||
if (gyro_frame_length > frame_count)
|
||||
{
|
||||
gyro_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed gyro data from the FIFO buffer. */
|
||||
for (index = 0; index < gyro_frame_length; index++)
|
||||
{
|
||||
printf("GYRO[%d] X : %d\t Y : %d\t Z : %d\n",
|
||||
index,
|
||||
fifo_gyro_data[index].x,
|
||||
fifo_gyro_data[index].y,
|
||||
fifo_gyro_data[index].z);
|
||||
}
|
||||
|
||||
/* Print control frames like sensor time and skipped frame count. */
|
||||
printf("Skipped frame count = %d\n", fifoframe.skipped_frame_count);
|
||||
printf("Sensor time = %lu\r\n", fifoframe.sensor_time);
|
||||
|
||||
try++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accel and gyro configurations. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[0].type = BMI2_ACCEL;
|
||||
config[1].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_context_get_sensor_config(config, 2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Accel configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[0].cfg.acc.odr = BMI2_ACC_ODR_25HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[0].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[0].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Gyro configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[1].cfg.gyr.odr = BMI2_GYR_ODR_25HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope Bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[1].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[1].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set new configurations. */
|
||||
rslt = bmi270_context_set_sensor_config(config, 2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_watermark_headerless_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_context.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+331
@@ -0,0 +1,331 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_context.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macros */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMI2_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(2048)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMI2_FIFO_RAW_DATA_USER_LENGTH UINT16_C(2048)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO */
|
||||
|
||||
/*!
|
||||
* Calculation:
|
||||
* fifo_watermark_level = 650, accel_frame_len = 6, gyro_frame_len = 6.
|
||||
* fifo_accel_frame_count = (650 / (6 + 6 )) = 54 frames
|
||||
*/
|
||||
#define BMI2_FIFO_ACCEL_FRAME_COUNT UINT8_C(55)
|
||||
|
||||
/*! Number of gyro frames to be extracted from FIFO */
|
||||
#define BMI2_FIFO_GYRO_FRAME_COUNT UINT8_C(55)
|
||||
|
||||
/*! Setting a watermark level in FIFO */
|
||||
#define BMI270_FIFO_WATERMARK_LEVEL UINT16_C(650)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to index bytes. */
|
||||
uint16_t index = 0;
|
||||
|
||||
/* Variable to store the available frame length count in FIFO */
|
||||
uint8_t frame_count;
|
||||
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
uint16_t accel_frame_length;
|
||||
|
||||
uint16_t gyro_frame_length;
|
||||
|
||||
uint8_t try = 1;
|
||||
|
||||
/* Number of bytes of FIFO data. */
|
||||
uint8_t fifo_data[BMI2_FIFO_RAW_DATA_BUFFER_SIZE] = { 0 };
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 50 * (6 axes bytes) = 300 bytes */
|
||||
struct bmi2_sens_axes_data fifo_accel_data[BMI2_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Array of gyro frames -> Total bytes =
|
||||
* 50 * (6 axes bytes) = 300 bytes */
|
||||
struct bmi2_sens_axes_data fifo_gyro_data[BMI2_FIFO_GYRO_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure. */
|
||||
struct bmi2_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Accel and gyro sensor are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Variable to get fifo water-mark interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint16_t watermark = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_context. */
|
||||
rslt = bmi270_context_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Enable accel and gyro sensor. */
|
||||
rslt = bmi270_context_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Configuration settings for accel and gyro. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Before setting FIFO, disable the advance power save mode. */
|
||||
rslt = bmi2_set_adv_power_save(BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initially disable all configurations in fifo. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ALL_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Update FIFO structure. */
|
||||
/* Mapping the buffer to store the fifo data. */
|
||||
fifoframe.data = fifo_data;
|
||||
|
||||
/* Length of FIFO frame. */
|
||||
fifoframe.length = BMI2_FIFO_RAW_DATA_USER_LENGTH;
|
||||
|
||||
/* Set FIFO configuration by enabling accel, gyro.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ACC_EN | BMI2_FIFO_GYR_EN, BMI2_ENABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("FIFO is configured in headerless mode\n");
|
||||
|
||||
/* To enable headerless mode, disable the header. */
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_HEADER_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
}
|
||||
|
||||
/* FIFO water-mark interrupt is enabled. */
|
||||
fifoframe.data_int_map = BMI2_FWM_INT;
|
||||
|
||||
/* Map water-mark interrupt to the required interrupt pin. */
|
||||
rslt = bmi2_map_data_int(fifoframe.data_int_map, BMI2_INT1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Set water-mark level. */
|
||||
fifoframe.wm_lvl = BMI270_FIFO_WATERMARK_LEVEL;
|
||||
|
||||
fifoframe.length = BMI2_FIFO_RAW_DATA_USER_LENGTH;
|
||||
|
||||
/* Set the water-mark level if water-mark interrupt is mapped. */
|
||||
rslt = bmi2_set_fifo_wm(fifoframe.wm_lvl, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
rslt = bmi2_get_fifo_wm(&watermark, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
printf("\nFIFO watermark level is %d\n", watermark);
|
||||
|
||||
while (try <= 10)
|
||||
{
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the status of FIFO watermark interrupt. */
|
||||
if ((rslt == BMI2_OK) && (int_status & BMI2_FWM_INT_STATUS_MASK))
|
||||
{
|
||||
printf("\nIteration : %d\n", try);
|
||||
|
||||
printf("\nWatermark interrupt occurred\n");
|
||||
|
||||
rslt = bmi2_get_fifo_length(&fifo_length, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
accel_frame_length = BMI2_FIFO_ACCEL_FRAME_COUNT;
|
||||
gyro_frame_length = BMI2_FIFO_GYRO_FRAME_COUNT;
|
||||
|
||||
printf("\nFIFO data bytes available : %d \n", fifo_length);
|
||||
printf("\nFIFO data bytes requested : %d \n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data. */
|
||||
rslt = bmi2_read_fifo_data(&fifoframe, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("\nFIFO accel frames requested : %d \n", accel_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_accel(fifo_accel_data, &accel_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO accel frames extracted : %d \n", accel_frame_length);
|
||||
|
||||
printf("\nFIFO gyro frames requested : %d \n", gyro_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract gyro data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_gyro(fifo_gyro_data, &gyro_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO gyro frames extracted : %d \n", gyro_frame_length);
|
||||
|
||||
/* Calculating the frame count from the available bytes in FIFO
|
||||
* frame_length = (available_fifo_bytes / (acc_frame_len + gyro_frame_len)) */
|
||||
frame_count = (fifo_length / (BMI2_FIFO_ACC_GYR_LENGTH));
|
||||
printf("\nAvailable frame count from available bytes: %d\n", frame_count);
|
||||
|
||||
printf("\nExracted accel frames\n");
|
||||
|
||||
if (accel_frame_length > frame_count)
|
||||
{
|
||||
accel_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer. */
|
||||
for (index = 0; index < accel_frame_length; index++)
|
||||
{
|
||||
printf("ACCEL[%d] X : %d\t Y : %d\t Z : %d\n", index, fifo_accel_data[index].x,
|
||||
fifo_accel_data[index].y, fifo_accel_data[index].z);
|
||||
}
|
||||
|
||||
printf("\nExtracted gyro frames\n");
|
||||
|
||||
if (gyro_frame_length > frame_count)
|
||||
{
|
||||
gyro_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed gyro data from the FIFO buffer. */
|
||||
for (index = 0; index < gyro_frame_length; index++)
|
||||
{
|
||||
printf("GYRO[%d] X : %d\t Y : %d\t Z : %d\n",
|
||||
index,
|
||||
fifo_gyro_data[index].x,
|
||||
fifo_gyro_data[index].y,
|
||||
fifo_gyro_data[index].z);
|
||||
}
|
||||
}
|
||||
|
||||
try++;
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accel and gyro configurations. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[0].type = BMI2_ACCEL;
|
||||
config[1].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_context_get_sensor_config(config, 2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameter according to their requirement. */
|
||||
/* Accel configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[0].cfg.acc.odr = BMI2_ACC_ODR_100HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[0].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[0].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Gyro configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[1].cfg.gyr.odr = BMI2_GYR_ODR_100HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope Bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[1].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[1].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set new configurations. */
|
||||
rslt = bmi270_context_set_sensor_config(config, 2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= gyro.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_context.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,195 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_context.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for gyro.
|
||||
*
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_gyro_config(struct bmi2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] dps : Degree per second.
|
||||
* @param[in] bit_width : Resolution for gyro.
|
||||
*
|
||||
* @return Degree per second.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to define limit to print gyro data. */
|
||||
uint8_t limit = 10;
|
||||
|
||||
uint8_t indx = 0;
|
||||
|
||||
float x = 0, y = 0, z = 0;
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Create an instance of sensor data structure. */
|
||||
struct bmi2_sensor_data sensor_data = { 0 };
|
||||
|
||||
/* Assign gyro sensor to variable. */
|
||||
uint8_t sens_list = BMI2_GYRO;
|
||||
|
||||
/* Initialize the interrupt status of gyro. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_context. */
|
||||
rslt = bmi270_context_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the selected sensors. */
|
||||
rslt = bmi270_context_sensor_enable(&sens_list, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Gyro configuration settings. */
|
||||
rslt = set_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Select gyro sensor. */
|
||||
sensor_data.type = BMI2_GYRO;
|
||||
printf("Gyro and DPS data\n");
|
||||
printf("Gyro data collected at Range 2000 dps with 16-bit resolution\n");
|
||||
|
||||
/* Loop to print gyro data when interrupt occurs. */
|
||||
while (indx <= limit)
|
||||
{
|
||||
/* To get the data ready interrupt status of gyro. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the data ready interrupt status and print the status for 10 samples. */
|
||||
if (int_status & BMI2_GYR_DRDY_INT_MASK)
|
||||
{
|
||||
/* Get gyro data for x, y and z axis. */
|
||||
rslt = bmi270_context_get_sensor_data(&sensor_data, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("\nGyr_X = %d\t", sensor_data.sens_data.gyr.x);
|
||||
printf("Gyr_Y = %d\t", sensor_data.sens_data.gyr.y);
|
||||
printf("Gyr_Z = %d\r\n", sensor_data.sens_data.gyr.z);
|
||||
|
||||
/* Converting lsb to degree per second for 16 bit gyro at 2000dps range. */
|
||||
x = lsb_to_dps(sensor_data.sens_data.gyr.x, 2000, bmi2_dev.resolution);
|
||||
y = lsb_to_dps(sensor_data.sens_data.gyr.y, 2000, bmi2_dev.resolution);
|
||||
z = lsb_to_dps(sensor_data.sens_data.gyr.z, 2000, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in dps. */
|
||||
printf("Gyr_DPS_X = %4.2f, Gyr_DPS_Y = %4.2f, Gyr_DPS_Z = %4.2f\n", x, y, z);
|
||||
|
||||
indx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for gyro.
|
||||
*/
|
||||
static int8_t set_gyro_config(struct bmi2_dev *dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define the type of sensor and its configurations. */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config.type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_context_get_sensor_config(&config, 1, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Map data ready interrupt to interrupt pin. */
|
||||
rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config.cfg.gyr.odr = BMI2_GYR_ODR_200HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config.cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config.cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config.cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config.cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set the gyro configurations. */
|
||||
rslt = bmi270_context_set_sensor_config(&config, 1, dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (dps / ((half_scale) + BMI2_GYR_RANGE_2000)) * (val);
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= step_counter.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_context.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_context.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static function declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for step counter.
|
||||
*
|
||||
* @param[in] bmi2_dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_feature_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Structure to define type of sensor and their respective data. */
|
||||
struct bmi2_sensor_data sensor_data;
|
||||
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Accel sensor and step counter feature are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_STEP_COUNTER };
|
||||
|
||||
/* Variable to get step counter interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Select features and their pins to be mapped to. */
|
||||
struct bmi2_sens_int_config sens_int = { .type = BMI2_STEP_COUNTER, .hw_int_pin = BMI2_INT2 };
|
||||
|
||||
/* Type of sensor to get step counter data. */
|
||||
sensor_data.type = BMI2_STEP_COUNTER;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_context. */
|
||||
rslt = bmi270_context_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the selected sensor. */
|
||||
rslt = bmi270_context_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Set the feature configuration for step counter. */
|
||||
rslt = set_feature_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("Step counter watermark level set to 1 (20 steps)\n");
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Map the step counter feature interrupt. */
|
||||
rslt = bmi270_context_map_feat_int(&sens_int, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Move the board in steps for 20 times to get step counter interrupt. */
|
||||
printf("Move the board in steps\n");
|
||||
|
||||
/* Loop to get number of steps counted. */
|
||||
do
|
||||
{
|
||||
/* To get the interrupt status of the step counter. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the interrupt status of the step counter. */
|
||||
if (int_status & BMI270_CONTEXT_STEP_CNT_STATUS_MASK)
|
||||
{
|
||||
printf("Step counter interrupt occurred when watermark level (20 steps) is reached\n");
|
||||
|
||||
/* Get step counter output. */
|
||||
rslt = bmi270_context_get_sensor_data(&sensor_data, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Print the step counter output. */
|
||||
printf("No of steps counted = %ld", sensor_data.sens_data.step_counter_output);
|
||||
break;
|
||||
}
|
||||
} while (rslt == BMI2_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for step counter.
|
||||
*/
|
||||
static int8_t set_feature_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define the type of sensor and its configurations. */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Configure the type of sensor. */
|
||||
config.type = BMI2_STEP_COUNTER;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_context_get_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Setting water-mark level to 1 for step counter to get interrupt after 20 step counts. Every 20 steps once
|
||||
* output triggers. */
|
||||
config.cfg.step_counter.watermark_level = 1;
|
||||
|
||||
/* Set new configuration. */
|
||||
rslt = bmi270_context_set_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= accel.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_hc.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,201 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_hc.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Earth's gravity in m/s^2 */
|
||||
#define GRAVITY_EARTH (9.80665f)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] g_range : Gravity range.
|
||||
* @param[in] bit_width : Resolution for accel.
|
||||
*
|
||||
* @return Gravity.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to define limit to print accel data. */
|
||||
uint8_t limit = 20;
|
||||
|
||||
/* Assign accel sensor to variable. */
|
||||
uint8_t sensor_list = BMI2_ACCEL;
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Create an instance of sensor data structure. */
|
||||
struct bmi2_sensor_data sensor_data = { 0 };
|
||||
|
||||
/* Initialize the interrupt status of accel. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint8_t indx = 0;
|
||||
float x = 0, y = 0, z = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_hc. */
|
||||
rslt = bmi270_hc_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the accel sensor. */
|
||||
rslt = bmi270_hc_sensor_enable(&sensor_list, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Accel configuration settings. */
|
||||
rslt = set_accel_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Assign accel sensor. */
|
||||
sensor_data.type = BMI2_ACCEL;
|
||||
printf("Accel and m/s2 data \n");
|
||||
printf("Accel data collected at 2G Range with 16-bit resolution\n");
|
||||
|
||||
/* Loop to print the accel data when interrupt occurs. */
|
||||
while (indx <= limit)
|
||||
{
|
||||
/* To get the status of accel data ready interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the accel data ready interrupt status and print the status for 10 samples. */
|
||||
if (int_status & BMI2_ACC_DRDY_INT_MASK)
|
||||
{
|
||||
/* Get accelerometer data for x, y and z axis. */
|
||||
rslt = bmi270_hc_get_sensor_data(&sensor_data, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
printf("\nAcc_X = %d\t", sensor_data.sens_data.acc.x);
|
||||
printf("Acc_Y = %d\t", sensor_data.sens_data.acc.y);
|
||||
printf("Acc_Z = %d\r\n", sensor_data.sens_data.acc.z);
|
||||
|
||||
/* Converting lsb to meter per second squared for 16 bit accelerometer at 2G range. */
|
||||
x = lsb_to_mps2(sensor_data.sens_data.acc.x, 2, bmi2_dev.resolution);
|
||||
y = lsb_to_mps2(sensor_data.sens_data.acc.y, 2, bmi2_dev.resolution);
|
||||
z = lsb_to_mps2(sensor_data.sens_data.acc.z, 2, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in m/s2. */
|
||||
printf("\nAcc_ms2_X = %4.2f, Acc_ms2_Y = %4.2f, Acc_ms2_Z = %4.2f\n", x, y, z);
|
||||
|
||||
indx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*/
|
||||
static int8_t set_accel_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accelerometer configuration. */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config.type = BMI2_ACCEL;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_hc_get_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config.cfg.acc.odr = BMI2_ACC_ODR_200HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config.cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples.
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config.cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config.cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set the accel configurations. */
|
||||
rslt = bmi270_hc_set_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Map data ready interrupt to interrupt pin. */
|
||||
rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (GRAVITY_EARTH * val * g_range) / half_scale;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= accel_gyro.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_hc.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,268 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_hc.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Earth's gravity in m/s^2 */
|
||||
#define GRAVITY_EARTH (9.80665f)
|
||||
|
||||
/*! Macros to select the sensors */
|
||||
#define ACCEL UINT8_C(0x00)
|
||||
#define GYRO UINT8_C(0x01)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] g_range : Gravity range.
|
||||
* @param[in] bit_width : Resolution for accel.
|
||||
*
|
||||
* @return Gravity.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] dps : Degree per second.
|
||||
* @param[in] bit_width : Resolution for gyro.
|
||||
*
|
||||
* @return Degree per second.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to define limit to print accel data. */
|
||||
uint8_t limit = 10;
|
||||
|
||||
/* Assign accel and gyro sensor to variable. */
|
||||
uint8_t sensor_list[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Create an instance of sensor data structure. */
|
||||
struct bmi2_sensor_data sensor_data[2] = { { 0 } };
|
||||
|
||||
/* Initialize the interrupt status of accel and gyro. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint8_t indx = 1;
|
||||
|
||||
float x = 0, y = 0, z = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_hc. */
|
||||
rslt = bmi270_hc_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the accel and gyro sensor. */
|
||||
rslt = bmi270_hc_sensor_enable(sensor_list, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Accel and gyro configuration settings. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Assign accel and gyro sensor. */
|
||||
sensor_data[ACCEL].type = BMI2_ACCEL;
|
||||
sensor_data[GYRO].type = BMI2_GYRO;
|
||||
|
||||
/* Loop to print accel and gyro data when interrupt occurs. */
|
||||
while (indx <= limit)
|
||||
{
|
||||
/* To get the data ready interrupt status of accel and gyro. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the data ready interrupt status and print the status for 10 samples. */
|
||||
if ((int_status & BMI2_ACC_DRDY_INT_MASK) && (int_status & BMI2_GYR_DRDY_INT_MASK))
|
||||
{
|
||||
/* Get accel and gyro data for x, y and z axis. */
|
||||
rslt = bmi270_hc_get_sensor_data(sensor_data, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("\n******* Accel(Raw and m/s2) Gyro(Raw and dps) data : %d *******\n", indx);
|
||||
|
||||
printf("\nAcc_x = %d\t", sensor_data[ACCEL].sens_data.acc.x);
|
||||
printf("Acc_y = %d\t", sensor_data[ACCEL].sens_data.acc.y);
|
||||
printf("Acc_z = %d", sensor_data[ACCEL].sens_data.acc.z);
|
||||
|
||||
/* Converting lsb to meter per second squared for 16 bit accelerometer at 2G range. */
|
||||
x = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.x, 2, bmi2_dev.resolution);
|
||||
y = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.y, 2, bmi2_dev.resolution);
|
||||
z = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.z, 2, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in m/s2. */
|
||||
printf("\nAcc_ms2_X = %4.2f, Acc_ms2_Y = %4.2f, Acc_ms2_Z = %4.2f\n", x, y, z);
|
||||
|
||||
printf("\nGyr_X = %d\t", sensor_data[GYRO].sens_data.gyr.x);
|
||||
printf("Gyr_Y = %d\t", sensor_data[GYRO].sens_data.gyr.y);
|
||||
printf("Gyr_Z = %d\n", sensor_data[GYRO].sens_data.gyr.z);
|
||||
|
||||
/* Converting lsb to degree per second for 16 bit gyro at 2000dps range. */
|
||||
x = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.x, 2000, bmi2_dev.resolution);
|
||||
y = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.y, 2000, bmi2_dev.resolution);
|
||||
z = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.z, 2000, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in dps. */
|
||||
printf("Gyro_DPS_X = %4.2f, Gyro_DPS_Y = %4.2f, Gyro_DPS_Z = %4.2f\n", x, y, z);
|
||||
|
||||
indx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accelerometer and gyro configuration. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[ACCEL].type = BMI2_ACCEL;
|
||||
config[GYRO].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_hc_get_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Map data ready interrupt to interrupt pin. */
|
||||
rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config[ACCEL].cfg.acc.odr = BMI2_ACC_ODR_200HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[ACCEL].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples.
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[ACCEL].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[ACCEL].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config[GYRO].cfg.gyr.odr = BMI2_GYR_ODR_200HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[GYRO].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[GYRO].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[GYRO].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[GYRO].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set the accel and gyro configurations. */
|
||||
rslt = bmi270_hc_set_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (GRAVITY_EARTH * val * g_range) / half_scale;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (dps / ((half_scale) + BMI2_GYR_RANGE_2000)) * (val);
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= activity_recognition.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_hc.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_hc.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static function declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for step counter.
|
||||
*
|
||||
* @param[in] bmi2_dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to define index for FIFO data */
|
||||
uint8_t count;
|
||||
|
||||
/* Various Activity recognitions are listed in array. */
|
||||
const char *activity_reg_output[6] = { "OTHERS", "STILL", "WALKING", "RUNNING", "ON_BICYCLE", "IN_VEHICLE" };
|
||||
|
||||
/* Accel sensor and step activity feature are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_ACTIVITY_RECOGNITION };
|
||||
|
||||
/* Array to define FIFO data */
|
||||
uint8_t fifo_data[516] = { 0 };
|
||||
|
||||
/* Variable to store number of activity frames */
|
||||
uint16_t act_frames;
|
||||
|
||||
/* Structure to define a FIFO */
|
||||
struct bmi2_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Structure to define output for activity recognition */
|
||||
struct bmi2_act_recog_output act_recog_data[5] = { { 0 } };
|
||||
|
||||
uint16_t fifo_length;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_hc. */
|
||||
rslt = bmi270_hc_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the selected sensor. */
|
||||
rslt = bmi270_hc_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
rslt = set_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Update FIFO structure */
|
||||
fifoframe.data = fifo_data;
|
||||
fifoframe.length = 516;
|
||||
|
||||
rslt = bmi2_get_fifo_length(&fifo_length, &bmi2_dev);
|
||||
printf("Fifo length = %d \n", fifo_length);
|
||||
|
||||
/* Read FIFO data */
|
||||
rslt = bmi2_read_fifo_data(&fifoframe, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
while (rslt != BMI2_W_FIFO_EMPTY)
|
||||
{
|
||||
/* Provide the number of frames to be read */
|
||||
act_frames = 5;
|
||||
|
||||
printf("Requested FIFO data frames : %d\n", act_frames);
|
||||
|
||||
/* Get the activity output */
|
||||
rslt = bmi270_hc_get_act_recog_output(act_recog_data, &act_frames, &fifoframe, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("Parsed FIFO data frames : %d\r\n", act_frames);
|
||||
|
||||
for (count = 0; count < act_frames; count++)
|
||||
{
|
||||
printf(
|
||||
"Activity Recognition output[%d]:Sensor time: %lu\t Previous activity: %s\t current: %s\n",
|
||||
count,
|
||||
act_recog_data[count].time_stamp,
|
||||
activity_reg_output[act_recog_data[count].prev_act],
|
||||
activity_reg_output[act_recog_data[count].curr_act]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
static int8_t set_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
uint8_t temp_data[2];
|
||||
|
||||
/* Disable advanced power save */
|
||||
rslt = bmi2_set_adv_power_save(BMI2_DISABLE, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Reset FIFO */
|
||||
rslt = bmi2_set_command_register(BMI2_FIFO_FLUSH_CMD, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("Move the board for activity recognition for 30 sec :\n");
|
||||
bmi2_dev->delay_us(30000000, bmi2_dev->intf_ptr);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
rslt = bmi2_get_regs(BMI2_FIFO_CONFIG_0_ADDR, temp_data, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,372 @@
|
||||
/**
|
||||
* Copyright (C) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "coines.h"
|
||||
#include "bmi2_defs.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definitions */
|
||||
#define BMI2XY_SHUTTLE_ID UINT16_C(0x1B8)
|
||||
|
||||
/*! Macro that defines read write length */
|
||||
#define READ_WRITE_LEN UINT8_C(46)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static variable definition */
|
||||
|
||||
/*! Variable that holds the I2C device address or SPI chip selection */
|
||||
static uint8_t dev_addr;
|
||||
|
||||
/******************************************************************************/
|
||||
/*! User interface functions */
|
||||
|
||||
/*!
|
||||
* I2C read function map to COINES platform
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_addr = *(uint8_t*)intf_ptr;
|
||||
|
||||
return coines_read_i2c(dev_addr, reg_addr, reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* I2C write function map to COINES platform
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_addr = *(uint8_t*)intf_ptr;
|
||||
|
||||
return coines_write_i2c(dev_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* SPI read function map to COINES platform
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_addr = *(uint8_t*)intf_ptr;
|
||||
|
||||
return coines_read_spi(dev_addr, reg_addr, reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* SPI write function map to COINES platform
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_addr = *(uint8_t*)intf_ptr;
|
||||
|
||||
return coines_write_spi(dev_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Delay function map to COINES platform
|
||||
*/
|
||||
void bmi2_delay_us(uint32_t period, void *intf_ptr)
|
||||
{
|
||||
coines_delay_usec(period);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Function to select the interface between SPI and I2C.
|
||||
* Also to initialize coines platform
|
||||
*/
|
||||
int8_t bmi2_interface_init(struct bmi2_dev *bmi, uint8_t intf)
|
||||
{
|
||||
int8_t rslt = BMI2_OK;
|
||||
struct coines_board_info board_info;
|
||||
|
||||
if (bmi != NULL)
|
||||
{
|
||||
int16_t result = coines_open_comm_intf(COINES_COMM_INTF_USB);
|
||||
if (result < COINES_SUCCESS)
|
||||
{
|
||||
printf(
|
||||
"\n Unable to connect with Application Board ! \n" " 1. Check if the board is connected and powered on. \n" " 2. Check if Application Board USB driver is installed. \n"
|
||||
" 3. Check if board is in use by another application. (Insufficient permissions to access USB) \n");
|
||||
exit(result);
|
||||
}
|
||||
|
||||
result = coines_get_board_info(&board_info);
|
||||
|
||||
#if defined(PC)
|
||||
setbuf(stdout, NULL);
|
||||
#endif
|
||||
|
||||
if (result == COINES_SUCCESS)
|
||||
{
|
||||
if ((board_info.shuttle_id != BMI2XY_SHUTTLE_ID))
|
||||
{
|
||||
printf("! Warning invalid sensor shuttle \n ," "This application will not support this sensor \n");
|
||||
exit(COINES_E_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
coines_set_shuttleboard_vdd_vddio_config(0, 0);
|
||||
coines_delay_msec(100);
|
||||
|
||||
/* Bus configuration : I2C */
|
||||
if (intf == BMI2_I2C_INTF)
|
||||
{
|
||||
printf("I2C Interface \n");
|
||||
|
||||
/* To initialize the user I2C function */
|
||||
dev_addr = BMI2_I2C_PRIM_ADDR;
|
||||
bmi->intf = BMI2_I2C_INTF;
|
||||
bmi->read = bmi2_i2c_read;
|
||||
bmi->write = bmi2_i2c_write;
|
||||
coines_config_i2c_bus(COINES_I2C_BUS_0, COINES_I2C_FAST_MODE);
|
||||
}
|
||||
/* Bus configuration : SPI */
|
||||
else if (intf == BMI2_SPI_INTF)
|
||||
{
|
||||
printf("SPI Interface \n");
|
||||
|
||||
/* To initialize the user SPI function */
|
||||
dev_addr = COINES_SHUTTLE_PIN_7;
|
||||
bmi->intf = BMI2_SPI_INTF;
|
||||
bmi->read = bmi2_spi_read;
|
||||
bmi->write = bmi2_spi_write;
|
||||
coines_config_spi_bus(COINES_SPI_BUS_0, COINES_SPI_SPEED_5_MHZ, COINES_SPI_MODE3);
|
||||
coines_set_pin_config(COINES_SHUTTLE_PIN_7, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_HIGH);
|
||||
}
|
||||
|
||||
/* Assign device address to interface pointer */
|
||||
bmi->intf_ptr = &dev_addr;
|
||||
|
||||
/* Configure delay in microseconds */
|
||||
bmi->delay_us = bmi2_delay_us;
|
||||
|
||||
/* Configure max read/write length (in bytes) ( Supported length depends on target machine) */
|
||||
bmi->read_write_len = READ_WRITE_LEN;
|
||||
|
||||
/* Assign to NULL to load the default config file. */
|
||||
bmi->config_file_ptr = NULL;
|
||||
|
||||
coines_delay_usec(10000);
|
||||
|
||||
coines_set_shuttleboard_vdd_vddio_config(3300, 3300);
|
||||
|
||||
coines_delay_usec(10000);
|
||||
}
|
||||
else
|
||||
{
|
||||
rslt = BMI2_E_NULL_PTR;
|
||||
}
|
||||
|
||||
return rslt;
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Prints the execution status of the APIs.
|
||||
*/
|
||||
void bmi2_error_codes_print_result(int8_t rslt)
|
||||
{
|
||||
switch (rslt)
|
||||
{
|
||||
case BMI2_OK:
|
||||
|
||||
/* Do nothing */
|
||||
break;
|
||||
|
||||
case BMI2_W_FIFO_EMPTY:
|
||||
printf("Warning [%d] : FIFO empty\r\n", rslt);
|
||||
break;
|
||||
case BMI2_W_PARTIAL_READ:
|
||||
printf("Warning [%d] : FIFO partial read\r\n", rslt);
|
||||
break;
|
||||
case BMI2_E_NULL_PTR:
|
||||
printf(
|
||||
"Error [%d] : Null pointer error. It occurs when the user tries to assign value (not address) to a pointer," " which has been initialized to NULL.\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_COM_FAIL:
|
||||
printf(
|
||||
"Error [%d] : Communication failure error. It occurs due to read/write operation failure and also due " "to power failure during communication\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_DEV_NOT_FOUND:
|
||||
printf("Error [%d] : Device not found error. It occurs when the device chip id is incorrectly read\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_SENSOR:
|
||||
printf(
|
||||
"Error [%d] : Invalid sensor error. It occurs when there is a mismatch in the requested feature with the " "available one\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_SELF_TEST_FAIL:
|
||||
printf(
|
||||
"Error [%d] : Self-test failed error. It occurs when the validation of accel self-test data is " "not satisfied\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_INT_PIN:
|
||||
printf(
|
||||
"Error [%d] : Invalid interrupt pin error. It occurs when the user tries to configure interrupt pins " "apart from INT1 and INT2\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_OUT_OF_RANGE:
|
||||
printf(
|
||||
"Error [%d] : Out of range error. It occurs when the data exceeds from filtered or unfiltered data from " "fifo and also when the range exceeds the maximum range for accel and gyro while performing FOC\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ACC_INVALID_CFG:
|
||||
printf(
|
||||
"Error [%d] : Invalid Accel configuration error. It occurs when there is an error in accel configuration" " register which could be one among range, BW or filter performance in reg address 0x40\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_GYRO_INVALID_CFG:
|
||||
printf(
|
||||
"Error [%d] : Invalid Gyro configuration error. It occurs when there is a error in gyro configuration" "register which could be one among range, BW or filter performance in reg address 0x42\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ACC_GYR_INVALID_CFG:
|
||||
printf(
|
||||
"Error [%d] : Invalid Accel-Gyro configuration error. It occurs when there is a error in accel and gyro" " configuration registers which could be one among range, BW or filter performance in reg address 0x40 " "and 0x42\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_CONFIG_LOAD:
|
||||
printf(
|
||||
"Error [%d] : Configuration load error. It occurs when failure observed while loading the configuration " "into the sensor\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_PAGE:
|
||||
printf(
|
||||
"Error [%d] : Invalid page error. It occurs due to failure in writing the correct feature configuration " "from selected page\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_SET_APS_FAIL:
|
||||
printf(
|
||||
"Error [%d] : APS failure error. It occurs due to failure in write of advance power mode configuration " "register\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_AUX_INVALID_CFG:
|
||||
printf(
|
||||
"Error [%d] : Invalid AUX configuration error. It occurs when the auxiliary interface settings are not " "enabled properly\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_AUX_BUSY:
|
||||
printf(
|
||||
"Error [%d] : AUX busy error. It occurs when the auxiliary interface buses are engaged while configuring" " the AUX\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_REMAP_ERROR:
|
||||
printf(
|
||||
"Error [%d] : Remap error. It occurs due to failure in assigning the remap axes data for all the axes " "after change in axis position\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_GYR_USER_GAIN_UPD_FAIL:
|
||||
printf(
|
||||
"Error [%d] : Gyro user gain update fail error. It occurs when the reading of user gain update status " "fails\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_SELF_TEST_NOT_DONE:
|
||||
printf(
|
||||
"Error [%d] : Self-test not done error. It occurs when the self-test process is ongoing or not " "completed\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_INPUT:
|
||||
printf("Error [%d] : Invalid input error. It occurs when the sensor input validity fails\r\n", rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_STATUS:
|
||||
printf("Error [%d] : Invalid status error. It occurs when the feature/sensor validity fails\r\n", rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_CRT_ERROR:
|
||||
printf("Error [%d] : CRT error. It occurs when the CRT test has failed\r\n", rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ST_ALREADY_RUNNING:
|
||||
printf(
|
||||
"Error [%d] : Self-test already running error. It occurs when the self-test is already running and " "another has been initiated\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_CRT_READY_FOR_DL_FAIL_ABORT:
|
||||
printf(
|
||||
"Error [%d] : CRT ready for download fail abort error. It occurs when download in CRT fails due to wrong " "address location\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_DL_ERROR:
|
||||
printf(
|
||||
"Error [%d] : Download error. It occurs when write length exceeds that of the maximum burst length\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_PRECON_ERROR:
|
||||
printf(
|
||||
"Error [%d] : Pre-conditional error. It occurs when precondition to start the feature was not " "completed\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ABORT_ERROR:
|
||||
printf("Error [%d] : Abort error. It occurs when the device was shaken during CRT test\r\n", rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_WRITE_CYCLE_ONGOING:
|
||||
printf(
|
||||
"Error [%d] : Write cycle ongoing error. It occurs when the write cycle is already running and another " "has been initiated\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ST_NOT_RUNING:
|
||||
printf(
|
||||
"Error [%d] : Self-test is not running error. It occurs when self-test running is disabled while it's " "running\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_DATA_RDY_INT_FAILED:
|
||||
printf(
|
||||
"Error [%d] : Data ready interrupt error. It occurs when the sample count exceeds the FOC sample limit " "and data ready status is not updated\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_FOC_POSITION:
|
||||
printf(
|
||||
"Error [%d] : Invalid FOC position error. It occurs when average FOC data is obtained for the wrong" " axes\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Error [%d] : Unknown error code\r\n", rslt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Deinitializes coines platform
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
void bmi2_coines_deinit(void)
|
||||
{
|
||||
coines_close_comm_intf(COINES_COMM_INTF_USB);
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#ifndef _COMMON_H
|
||||
#define _COMMON_H
|
||||
|
||||
/*! CPP guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "bmi2.h"
|
||||
|
||||
/*!
|
||||
* @brief Function for reading the sensor's registers through I2C bus.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[out] reg_data : Pointer to the data buffer to store the read data.
|
||||
* @param[in] length : No of bytes to read.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval = BMI2_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMI2_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Function for writing the sensor's registers through I2C bus.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[in] reg_data : Pointer to the data buffer whose value is to be written.
|
||||
* @param[in] length : No of bytes to write.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval = BMI2_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMI2_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Function for reading the sensor's registers through SPI bus.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[out] reg_data : Pointer to the data buffer to store the read data.
|
||||
* @param[in] length : No of bytes to read.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval = BMI2_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMI2_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Function for writing the sensor's registers through SPI bus.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[in] reg_data : Pointer to the data buffer whose data has to be written.
|
||||
* @param[in] length : No of bytes to write.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval = BMI2_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMI2_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief This function provides the delay for required time (Microsecond) as per the input provided in some of the
|
||||
* APIs.
|
||||
*
|
||||
* @param[in] period_us : The required wait time in microsecond.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return void.
|
||||
*
|
||||
*/
|
||||
void bmi2_delay_us(uint32_t period, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Function to select the interface between SPI and I2C.
|
||||
*
|
||||
* @param[in] bma : Structure instance of bmi2_dev
|
||||
* @param[in] intf : Interface selection parameter
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval 0 -> Success
|
||||
* @retval < 0 -> Failure Info
|
||||
*/
|
||||
int8_t bmi2_interface_init(struct bmi2_dev *bma, uint8_t intf);
|
||||
|
||||
/*!
|
||||
* @brief Prints the execution status of the APIs.
|
||||
*
|
||||
* @param[in] rslt : Error code returned by the API whose execution status has to be printed.
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
void bmi2_error_codes_print_result(int8_t rslt);
|
||||
|
||||
/*!
|
||||
* @brief Deinitializes coines platform
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
void bmi2_coines_deinit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* End of CPP guard */
|
||||
|
||||
#endif /* _COMMON_H */
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= component_retrim.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_hc.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_hc.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_hc. */
|
||||
rslt = bmi270_hc_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* This API runs the CRT process. */
|
||||
rslt = bmi2_do_crt(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Do not move the board while doing CRT. If so, it will throw an abort error. */
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("CRT successfully completed.");
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_full_header_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_hc.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+316
@@ -0,0 +1,316 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_hc.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macros */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data. */
|
||||
#define BMI2_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(2048)
|
||||
|
||||
/*! Length of data to be read from FIFO. */
|
||||
#define BMI2_FIFO_RAW_DATA_USER_LENGTH UINT16_C(2048)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO. */
|
||||
|
||||
/*! Calculation for frame count: Total frame count = Fifo buffer size(2048)/ Total frames(6 Accel, 6 Gyro and 1 header,
|
||||
* totaling to 13) which equals to 157.
|
||||
*/
|
||||
#define BMI2_FIFO_ACCEL_FRAME_COUNT UINT8_C(157)
|
||||
|
||||
/*! Number of gyro frames to be extracted from FIFO. */
|
||||
#define BMI2_FIFO_GYRO_FRAME_COUNT UINT8_C(157)
|
||||
|
||||
/*! Macro to read sensortime byte in FIFO. */
|
||||
#define SENSORTIME_OVERHEAD_BYTE UINT8_C(3)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
uint16_t index = 0;
|
||||
uint16_t fifo_length = 0;
|
||||
uint16_t config = 0;
|
||||
|
||||
/* To read sensortime, extra 3 bytes are added to fifo buffer. */
|
||||
uint16_t fifo_buffer_size = BMI2_FIFO_RAW_DATA_BUFFER_SIZE + SENSORTIME_OVERHEAD_BYTE;
|
||||
|
||||
/* Variable to get fifo full interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint16_t accel_frame_length = BMI2_FIFO_ACCEL_FRAME_COUNT;
|
||||
|
||||
uint16_t gyro_frame_length = BMI2_FIFO_GYRO_FRAME_COUNT;
|
||||
|
||||
/* Variable to store the available frame length count in FIFO */
|
||||
uint8_t frame_count;
|
||||
|
||||
int8_t try = 1;
|
||||
|
||||
/* Number of bytes of FIFO data. */
|
||||
uint8_t fifo_data[fifo_buffer_size];
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 157 * (6 axes + 1 header bytes) = 1099 bytes */
|
||||
struct bmi2_sens_axes_data fifo_accel_data[BMI2_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Array of gyro frames -> Total bytes =
|
||||
* 157 * (6 axes + 1 header bytes) = 1099 bytes */
|
||||
struct bmi2_sens_axes_data fifo_gyro_data[BMI2_FIFO_GYRO_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure. */
|
||||
struct bmi2_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Accel and gyro sensor are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_hc. */
|
||||
rslt = bmi270_hc_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Enable accel and gyro sensor. */
|
||||
rslt = bmi270_hc_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Configuration settings for accel and gyro. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Before setting FIFO, disable the advance power save mode. */
|
||||
rslt = bmi2_set_adv_power_save(BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initially disable all configurations in fifo. */
|
||||
rslt = bmi2_get_fifo_config(&config, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initially disable all configurations in fifo. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ALL_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Update FIFO structure. */
|
||||
/* Mapping the buffer to store the fifo data. */
|
||||
fifoframe.data = fifo_data;
|
||||
|
||||
/* Length of FIFO frame. */
|
||||
/* To read sensortime, extra 3 bytes are added to fifo user length. */
|
||||
fifoframe.length = BMI2_FIFO_RAW_DATA_USER_LENGTH + SENSORTIME_OVERHEAD_BYTE;
|
||||
|
||||
/* Set FIFO configuration by enabling accel, gyro and timestamp.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is in FIFO mode.
|
||||
* NOTE 3: Sensortime is enabled by default */
|
||||
printf("FIFO is configured in header mode\n");
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ACC_EN | BMI2_FIFO_GYR_EN, BMI2_ENABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Map FIFO full interrupt. */
|
||||
fifoframe.data_int_map = BMI2_FFULL_INT;
|
||||
rslt = bmi2_map_data_int(fifoframe.data_int_map, BMI2_INT1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
while (try <= 10)
|
||||
{
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if ((rslt == BMI2_OK) && (int_status & BMI2_FFULL_INT_STATUS_MASK))
|
||||
{
|
||||
printf("\nIteration : %d\n", try);
|
||||
|
||||
accel_frame_length = BMI2_FIFO_ACCEL_FRAME_COUNT;
|
||||
|
||||
gyro_frame_length = BMI2_FIFO_GYRO_FRAME_COUNT;
|
||||
|
||||
rslt = bmi2_get_fifo_length(&fifo_length, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("\nFIFO data bytes available : %d \n", fifo_length);
|
||||
printf("\nFIFO data bytes requested : %d \n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data. */
|
||||
rslt = bmi2_read_fifo_data(&fifoframe, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("\nFIFO accel frames requested : %d \n", accel_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_accel(fifo_accel_data, &accel_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO accel frames extracted : %d \n", accel_frame_length);
|
||||
|
||||
printf("\nFIFO gyro frames requested : %d \n", gyro_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract gyro data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_gyro(fifo_gyro_data, &gyro_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO gyro frames extracted : %d \n", gyro_frame_length);
|
||||
|
||||
/* Calculating the frame count from the available bytes in FIFO
|
||||
* frame_length = (available_fifo_bytes / (acc_frame_len + gyro_frame_len + header_byte)) */
|
||||
frame_count = (fifo_length / (BMI2_FIFO_ACC_GYR_LENGTH + 1));
|
||||
printf("\nAvailable frame count from available bytes: %d\n", frame_count);
|
||||
|
||||
printf("\nExtracted accel frames\n");
|
||||
|
||||
if (accel_frame_length > frame_count)
|
||||
{
|
||||
accel_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer. */
|
||||
for (index = 0; index < accel_frame_length; index++)
|
||||
{
|
||||
printf("ACCEL[%d] X : %d\t Y : %d\t Z : %d\n", index, fifo_accel_data[index].x,
|
||||
fifo_accel_data[index].y, fifo_accel_data[index].z);
|
||||
}
|
||||
|
||||
printf("\nExtracted gyro frames\n");
|
||||
|
||||
if (gyro_frame_length > frame_count)
|
||||
{
|
||||
gyro_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed gyro data from the FIFO buffer. */
|
||||
for (index = 0; index < gyro_frame_length; index++)
|
||||
{
|
||||
printf("GYRO[%d] X : %d\t Y : %d\t Z : %d\n",
|
||||
index,
|
||||
fifo_gyro_data[index].x,
|
||||
fifo_gyro_data[index].y,
|
||||
fifo_gyro_data[index].z);
|
||||
}
|
||||
|
||||
/* Print control frames like sensor time and skipped frame count. */
|
||||
printf("\nSkipped frame count = %d\n", fifoframe.skipped_frame_count);
|
||||
|
||||
printf("Sensor time = %lu\r\n", fifoframe.sensor_time);
|
||||
|
||||
try++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accel and gyro configurations. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[0].type = BMI2_ACCEL;
|
||||
config[1].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_hc_get_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Accel configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[0].cfg.acc.odr = BMI2_ACC_ODR_25HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[0].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[0].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Gyro configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[1].cfg.gyr.odr = BMI2_GYR_ODR_25HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope Bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[1].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[1].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set new configurations. */
|
||||
rslt = bmi270_hc_set_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_full_headerless_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_hc.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+304
@@ -0,0 +1,304 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_hc.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macros */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMI2_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(2048)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMI2_FIFO_RAW_DATA_USER_LENGTH UINT16_C(2048)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO */
|
||||
|
||||
/*! Calculation for frame count: Total frame count = Fifo buffer size(2048)/ Total frames(6 Accel, 6 Gyro totaling to
|
||||
* 12) which equals to 170.
|
||||
*/
|
||||
#define BMI2_FIFO_ACCEL_FRAME_COUNT UINT8_C(169)
|
||||
|
||||
/*! Number of gyro frames to be extracted from FIFO */
|
||||
#define BMI2_FIFO_GYRO_FRAME_COUNT UINT8_C(169)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
uint16_t index = 0;
|
||||
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
uint8_t try = 1;
|
||||
|
||||
/* Variable to get fifo full interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint16_t accel_frame_length;
|
||||
|
||||
uint16_t gyro_frame_length;
|
||||
|
||||
/* Variable to store the available frame length count in FIFO */
|
||||
uint8_t frame_count;
|
||||
|
||||
/* Number of bytes of FIFO data. */
|
||||
uint8_t fifo_data[BMI2_FIFO_RAW_DATA_BUFFER_SIZE] = { 0 };
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 170 * (6 axes bytes) = 1020 bytes */
|
||||
struct bmi2_sens_axes_data fifo_accel_data[BMI2_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Array of gyro frames -> Total bytes =
|
||||
* 170 * (6 axes bytes) = 1020 bytes */
|
||||
struct bmi2_sens_axes_data fifo_gyro_data[BMI2_FIFO_GYRO_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure. */
|
||||
struct bmi2_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Accel and gyro sensor are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_hc. */
|
||||
rslt = bmi270_hc_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Enable accel and gyro sensor. */
|
||||
rslt = bmi270_hc_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Configuration settings for accel and gyro. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Before setting FIFO, disable the advance power save mode. */
|
||||
rslt = bmi2_set_adv_power_save(BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initially disable all configurations in fifo. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ALL_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Update FIFO structure. */
|
||||
/* Mapping the buffer to store the fifo data. */
|
||||
fifoframe.data = fifo_data;
|
||||
|
||||
/* Length of FIFO frame. */
|
||||
fifoframe.length = BMI2_FIFO_RAW_DATA_USER_LENGTH;
|
||||
|
||||
/* Set FIFO configuration by enabling accel, gyro.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ACC_EN | BMI2_FIFO_GYR_EN, BMI2_ENABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("FIFO is configured in headerless mode\n");
|
||||
|
||||
/* To enable headerless mode, disable the header. */
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_HEADER_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
}
|
||||
|
||||
/* Map FIFO full interrupt. */
|
||||
fifoframe.data_int_map = BMI2_FFULL_INT;
|
||||
rslt = bmi2_map_data_int(fifoframe.data_int_map, BMI2_INT1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
while (try <= 10)
|
||||
{
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if ((rslt == BMI2_OK) && (int_status & BMI2_FFULL_INT_STATUS_MASK))
|
||||
{
|
||||
printf("\nIteration : %d\n", try);
|
||||
|
||||
rslt = bmi2_get_fifo_length(&fifo_length, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
accel_frame_length = BMI2_FIFO_ACCEL_FRAME_COUNT;
|
||||
gyro_frame_length = BMI2_FIFO_GYRO_FRAME_COUNT;
|
||||
|
||||
printf("\nFIFO data bytes available : %d \n", fifo_length);
|
||||
printf("\nFIFO data bytes requested : %d \n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data. */
|
||||
rslt = bmi2_read_fifo_data(&fifoframe, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("\nFIFO accel frames requested : %d \n", accel_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_accel(fifo_accel_data, &accel_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO accel frames extracted : %d \n", accel_frame_length);
|
||||
|
||||
printf("\nFIFO gyro frames requested : %d \n", gyro_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract gyro data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_gyro(fifo_gyro_data, &gyro_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO gyro frames extracted : %d \n", gyro_frame_length);
|
||||
|
||||
/* Calculating the frame count from the available bytes in FIFO
|
||||
* frame_length = (available_fifo_bytes / (acc_frame_len + gyro_frame_len)) */
|
||||
frame_count = (fifo_length / (BMI2_FIFO_ACC_GYR_LENGTH));
|
||||
printf("\nAvailable frame count from available bytes: %d\n", frame_count);
|
||||
|
||||
printf("\nExtracted accel frames\n");
|
||||
|
||||
if (accel_frame_length > frame_count)
|
||||
{
|
||||
accel_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer. */
|
||||
for (index = 0; index < accel_frame_length; index++)
|
||||
{
|
||||
printf("ACCEL[%d] X : %d\t Y : %d\t Z : %d\n", index, fifo_accel_data[index].x,
|
||||
fifo_accel_data[index].y, fifo_accel_data[index].z);
|
||||
}
|
||||
|
||||
printf("\nExtracted gyro frames\n");
|
||||
|
||||
if (gyro_frame_length > frame_count)
|
||||
{
|
||||
gyro_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed gyro data from the FIFO buffer. */
|
||||
for (index = 0; index < gyro_frame_length; index++)
|
||||
{
|
||||
printf("GYRO[%d] X : %d\t Y : %d\t Z : %d\n",
|
||||
index,
|
||||
fifo_gyro_data[index].x,
|
||||
fifo_gyro_data[index].y,
|
||||
fifo_gyro_data[index].z);
|
||||
}
|
||||
}
|
||||
|
||||
try++;
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accel and gyro configurations. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[0].type = BMI2_ACCEL;
|
||||
config[1].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_hc_get_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Accel configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[0].cfg.acc.odr = BMI2_ACC_ODR_100HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[0].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[0].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Gyro configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[1].cfg.gyr.odr = BMI2_GYR_ODR_100HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope Bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[1].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[1].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set new configurations. */
|
||||
rslt = bmi270_hc_set_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_watermark_header_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_hc.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+335
@@ -0,0 +1,335 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_hc.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macros */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMI2_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(2048)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMI2_FIFO_RAW_DATA_USER_LENGTH UINT16_C(2048)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO */
|
||||
|
||||
/*!
|
||||
* Calculation:
|
||||
* fifo_watermark_level = 650, accel_frame_len = 6, gyro_frame_len = 6 header_byte = 1.
|
||||
* fifo_accel_frame_count = (650 / (6 + 6 + 1 )) = 50 frames
|
||||
* NOTE: Extra frames are read in order to get sensor time
|
||||
*/
|
||||
#define BMI2_FIFO_ACCEL_FRAME_COUNT UINT8_C(55)
|
||||
|
||||
/*! Number of gyro frames to be extracted from FIFO */
|
||||
#define BMI2_FIFO_GYRO_FRAME_COUNT UINT8_C(55)
|
||||
|
||||
/*! Setting a watermark level in FIFO */
|
||||
#define BMI270_FIFO_WATERMARK_LEVEL UINT16_C(650)
|
||||
|
||||
/*! Macro to read sensortime byte in FIFO */
|
||||
#define SENSORTIME_OVERHEAD_BYTE UINT8_C(3)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to store the available frame length count in FIFO */
|
||||
uint8_t frame_count;
|
||||
|
||||
/* Variable to index bytes. */
|
||||
uint16_t index = 0;
|
||||
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
uint16_t accel_frame_length;
|
||||
|
||||
uint16_t gyro_frame_length;
|
||||
|
||||
uint8_t try = 1;
|
||||
|
||||
/* To read sensortime, extra 3 bytes are added to fifo buffer */
|
||||
uint16_t fifo_buffer_size = BMI2_FIFO_RAW_DATA_BUFFER_SIZE + SENSORTIME_OVERHEAD_BYTE;
|
||||
|
||||
/* Number of bytes of FIFO data. */
|
||||
uint8_t fifo_data[fifo_buffer_size];
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 55 * (6 axes bytes) = 330 bytes */
|
||||
struct bmi2_sens_axes_data fifo_accel_data[BMI2_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Array of gyro frames -> Total bytes =
|
||||
* 55 * (6 axes bytes) = 330 bytes */
|
||||
struct bmi2_sens_axes_data fifo_gyro_data[BMI2_FIFO_GYRO_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure. */
|
||||
struct bmi2_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Accel and gyro sensor are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Variable to get fifo water-mark interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint16_t watermark = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_hc. */
|
||||
rslt = bmi270_hc_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Enable accel and gyro sensor. */
|
||||
rslt = bmi270_hc_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Configuration settings for accel and gyro. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Before setting FIFO, disable the advance power save mode. */
|
||||
rslt = bmi2_set_adv_power_save(BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initially disable all configurations in fifo. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ALL_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Update FIFO structure. */
|
||||
/* Mapping the buffer to store the fifo data. */
|
||||
fifoframe.data = fifo_data;
|
||||
|
||||
/* Length of FIFO frame. */
|
||||
/* To read sensortime, extra 3 bytes are added to fifo user length. */
|
||||
fifoframe.length = BMI2_FIFO_RAW_DATA_USER_LENGTH + SENSORTIME_OVERHEAD_BYTE;
|
||||
|
||||
/* Set FIFO configuration by enabling accel, gyro and timestamp.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode.
|
||||
* NOTE 3: Sensortime is enabled by default */
|
||||
printf("FIFO is configured in header mode\n");
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ACC_EN | BMI2_FIFO_GYR_EN, BMI2_ENABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* FIFO water-mark interrupt is enabled. */
|
||||
fifoframe.data_int_map = BMI2_FWM_INT;
|
||||
|
||||
/* Map water-mark interrupt to the required interrupt pin. */
|
||||
rslt = bmi2_map_data_int(fifoframe.data_int_map, BMI2_INT1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Set water-mark level. */
|
||||
fifoframe.wm_lvl = BMI270_FIFO_WATERMARK_LEVEL;
|
||||
|
||||
/* Set the water-mark level if water-mark interrupt is mapped. */
|
||||
rslt = bmi2_set_fifo_wm(fifoframe.wm_lvl, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
rslt = bmi2_get_fifo_wm(&watermark, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
printf("\nFIFO watermark level is %d\n", watermark);
|
||||
|
||||
while (try <= 10)
|
||||
{
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the status of FIFO watermark interrupt. */
|
||||
if ((rslt == BMI2_OK) && (int_status & BMI2_FWM_INT_STATUS_MASK))
|
||||
{
|
||||
printf("\nIteration : %d\n", try);
|
||||
|
||||
printf("\nWatermark interrupt occurred\n");
|
||||
|
||||
rslt = bmi2_get_fifo_length(&fifo_length, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
accel_frame_length = BMI2_FIFO_ACCEL_FRAME_COUNT;
|
||||
gyro_frame_length = BMI2_FIFO_GYRO_FRAME_COUNT;
|
||||
|
||||
printf("\nFIFO data bytes available : %d \n", fifo_length);
|
||||
printf("\nFIFO data bytes requested : %d \n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data. */
|
||||
rslt = bmi2_read_fifo_data(&fifoframe, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("\nFIFO accel frames requested : %d \n", accel_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_accel(fifo_accel_data, &accel_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO accel frames extracted : %d \n", accel_frame_length);
|
||||
|
||||
printf("\nFIFO gyro frames requested : %d \n", gyro_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract gyro data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_gyro(fifo_gyro_data, &gyro_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO gyro frames extracted : %d \n", gyro_frame_length);
|
||||
|
||||
/* Calculating the frame count from the available bytes in FIFO
|
||||
* frame_length = (available_fifo_bytes / (acc_frame_len + gyro_frame_len + header_byte)) */
|
||||
frame_count = (fifo_length / (BMI2_FIFO_ACC_GYR_LENGTH + 1));
|
||||
printf("\nAvailable frame count from available bytes: %d\n", frame_count);
|
||||
|
||||
printf("\nExracted accel frames\n");
|
||||
|
||||
if (accel_frame_length > frame_count)
|
||||
{
|
||||
accel_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer. */
|
||||
for (index = 0; index < accel_frame_length; index++)
|
||||
{
|
||||
printf("ACCEL[%d] X : %d\t Y : %d\t Z : %d\n", index, fifo_accel_data[index].x,
|
||||
fifo_accel_data[index].y, fifo_accel_data[index].z);
|
||||
}
|
||||
|
||||
printf("\nExtracted gyro frames\n");
|
||||
|
||||
if (gyro_frame_length > frame_count)
|
||||
{
|
||||
gyro_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed gyro data from the FIFO buffer. */
|
||||
for (index = 0; index < gyro_frame_length; index++)
|
||||
{
|
||||
printf("GYRO[%d] X : %d\t Y : %d\t Z : %d\n",
|
||||
index,
|
||||
fifo_gyro_data[index].x,
|
||||
fifo_gyro_data[index].y,
|
||||
fifo_gyro_data[index].z);
|
||||
}
|
||||
|
||||
/* Print control frames like sensor time and skipped frame count. */
|
||||
printf("Skipped frame count = %d\n", fifoframe.skipped_frame_count);
|
||||
printf("Sensor time = %lu\r\n", fifoframe.sensor_time);
|
||||
|
||||
try++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accel and gyro configurations. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[0].type = BMI2_ACCEL;
|
||||
config[1].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_hc_get_sensor_config(config, 2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Accel configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[0].cfg.acc.odr = BMI2_ACC_ODR_25HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[0].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[0].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Gyro configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[1].cfg.gyr.odr = BMI2_GYR_ODR_25HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope Bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[1].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[1].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set new configurations. */
|
||||
rslt = bmi270_hc_set_sensor_config(config, 2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_watermark_headerless_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_hc.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+331
@@ -0,0 +1,331 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_hc.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macros */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMI2_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(2048)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMI2_FIFO_RAW_DATA_USER_LENGTH UINT16_C(2048)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO */
|
||||
|
||||
/*!
|
||||
* Calculation:
|
||||
* fifo_watermark_level = 650, accel_frame_len = 6, gyro_frame_len = 6.
|
||||
* fifo_accel_frame_count = (650 / (6 + 6 )) = 54 frames
|
||||
*/
|
||||
#define BMI2_FIFO_ACCEL_FRAME_COUNT UINT8_C(55)
|
||||
|
||||
/*! Number of gyro frames to be extracted from FIFO */
|
||||
#define BMI2_FIFO_GYRO_FRAME_COUNT UINT8_C(55)
|
||||
|
||||
/*! Setting a watermark level in FIFO */
|
||||
#define BMI270_FIFO_WATERMARK_LEVEL UINT16_C(650)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to index bytes. */
|
||||
uint16_t index = 0;
|
||||
|
||||
/* Variable to store the available frame length count in FIFO */
|
||||
uint8_t frame_count;
|
||||
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
uint16_t accel_frame_length;
|
||||
|
||||
uint16_t gyro_frame_length;
|
||||
|
||||
uint8_t try = 1;
|
||||
|
||||
/* Number of bytes of FIFO data. */
|
||||
uint8_t fifo_data[BMI2_FIFO_RAW_DATA_BUFFER_SIZE] = { 0 };
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 50 * (6 axes bytes) = 300 bytes */
|
||||
struct bmi2_sens_axes_data fifo_accel_data[BMI2_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Array of gyro frames -> Total bytes =
|
||||
* 50 * (6 axes bytes) = 300 bytes */
|
||||
struct bmi2_sens_axes_data fifo_gyro_data[BMI2_FIFO_GYRO_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure. */
|
||||
struct bmi2_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Accel and gyro sensor are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Variable to get fifo water-mark interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint16_t watermark = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_hc. */
|
||||
rslt = bmi270_hc_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Enable accel and gyro sensor. */
|
||||
rslt = bmi270_hc_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Configuration settings for accel and gyro. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Before setting FIFO, disable the advance power save mode. */
|
||||
rslt = bmi2_set_adv_power_save(BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initially disable all configurations in fifo. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ALL_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Update FIFO structure. */
|
||||
/* Mapping the buffer to store the fifo data. */
|
||||
fifoframe.data = fifo_data;
|
||||
|
||||
/* Length of FIFO frame. */
|
||||
fifoframe.length = BMI2_FIFO_RAW_DATA_USER_LENGTH;
|
||||
|
||||
/* Set FIFO configuration by enabling accel, gyro.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ACC_EN | BMI2_FIFO_GYR_EN, BMI2_ENABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("FIFO is configured in headerless mode\n");
|
||||
|
||||
/* To enable headerless mode, disable the header. */
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_HEADER_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
}
|
||||
|
||||
/* FIFO water-mark interrupt is enabled. */
|
||||
fifoframe.data_int_map = BMI2_FWM_INT;
|
||||
|
||||
/* Map water-mark interrupt to the required interrupt pin. */
|
||||
rslt = bmi2_map_data_int(fifoframe.data_int_map, BMI2_INT1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Set water-mark level. */
|
||||
fifoframe.wm_lvl = BMI270_FIFO_WATERMARK_LEVEL;
|
||||
|
||||
fifoframe.length = BMI2_FIFO_RAW_DATA_USER_LENGTH;
|
||||
|
||||
/* Set the water-mark level if water-mark interrupt is mapped. */
|
||||
rslt = bmi2_set_fifo_wm(fifoframe.wm_lvl, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
rslt = bmi2_get_fifo_wm(&watermark, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
printf("\nFIFO watermark level is %d\n", watermark);
|
||||
|
||||
while (try <= 10)
|
||||
{
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the status of FIFO watermark interrupt. */
|
||||
if ((rslt == BMI2_OK) && (int_status & BMI2_FWM_INT_STATUS_MASK))
|
||||
{
|
||||
printf("\nIteration : %d\n", try);
|
||||
|
||||
printf("\nWatermark interrupt occurred\n");
|
||||
|
||||
rslt = bmi2_get_fifo_length(&fifo_length, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
accel_frame_length = BMI2_FIFO_ACCEL_FRAME_COUNT;
|
||||
gyro_frame_length = BMI2_FIFO_GYRO_FRAME_COUNT;
|
||||
|
||||
printf("\nFIFO data bytes available : %d \n", fifo_length);
|
||||
printf("\nFIFO data bytes requested : %d \n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data. */
|
||||
rslt = bmi2_read_fifo_data(&fifoframe, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("\nFIFO accel frames requested : %d \n", accel_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_accel(fifo_accel_data, &accel_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO accel frames extracted : %d \n", accel_frame_length);
|
||||
|
||||
printf("\nFIFO gyro frames requested : %d \n", gyro_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract gyro data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_gyro(fifo_gyro_data, &gyro_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO gyro frames extracted : %d \n", gyro_frame_length);
|
||||
|
||||
/* Calculating the frame count from the available bytes in FIFO
|
||||
* frame_length = (available_fifo_bytes / (acc_frame_len + gyro_frame_len)) */
|
||||
frame_count = (fifo_length / (BMI2_FIFO_ACC_GYR_LENGTH));
|
||||
printf("\nAvailable frame count from available bytes: %d\n", frame_count);
|
||||
|
||||
printf("\nExracted accel frames\n");
|
||||
|
||||
if (accel_frame_length > frame_count)
|
||||
{
|
||||
accel_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer. */
|
||||
for (index = 0; index < accel_frame_length; index++)
|
||||
{
|
||||
printf("ACCEL[%d] X : %d\t Y : %d\t Z : %d\n", index, fifo_accel_data[index].x,
|
||||
fifo_accel_data[index].y, fifo_accel_data[index].z);
|
||||
}
|
||||
|
||||
printf("\nExtracted gyro frames\n");
|
||||
|
||||
if (gyro_frame_length > frame_count)
|
||||
{
|
||||
gyro_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed gyro data from the FIFO buffer. */
|
||||
for (index = 0; index < gyro_frame_length; index++)
|
||||
{
|
||||
printf("GYRO[%d] X : %d\t Y : %d\t Z : %d\n",
|
||||
index,
|
||||
fifo_gyro_data[index].x,
|
||||
fifo_gyro_data[index].y,
|
||||
fifo_gyro_data[index].z);
|
||||
}
|
||||
}
|
||||
|
||||
try++;
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accel and gyro configurations. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[0].type = BMI2_ACCEL;
|
||||
config[1].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_hc_get_sensor_config(config, 2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameter according to their requirement. */
|
||||
/* Accel configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[0].cfg.acc.odr = BMI2_ACC_ODR_100HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[0].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[0].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Gyro configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[1].cfg.gyr.odr = BMI2_GYR_ODR_100HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope Bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[1].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[1].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set new configurations. */
|
||||
rslt = bmi270_hc_set_sensor_config(config, 2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= gyro.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_hc.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,195 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_hc.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for gyro.
|
||||
*
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_gyro_config(struct bmi2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] dps : Degree per second.
|
||||
* @param[in] bit_width : Resolution for gyro.
|
||||
*
|
||||
* @return Degree per second.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to define limit to print gyro data. */
|
||||
uint8_t limit = 10;
|
||||
|
||||
uint8_t indx = 0;
|
||||
|
||||
float x = 0, y = 0, z = 0;
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Create an instance of sensor data structure. */
|
||||
struct bmi2_sensor_data sensor_data = { 0 };
|
||||
|
||||
/* Assign gyro sensor to variable. */
|
||||
uint8_t sens_list = BMI2_GYRO;
|
||||
|
||||
/* Initialize the interrupt status of gyro. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_hc. */
|
||||
rslt = bmi270_hc_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the selected sensors. */
|
||||
rslt = bmi270_hc_sensor_enable(&sens_list, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Gyro configuration settings. */
|
||||
rslt = set_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Select gyro sensor. */
|
||||
sensor_data.type = BMI2_GYRO;
|
||||
printf("Gyro and DPS data\n");
|
||||
printf("Gyro data collected at Range 2000 dps with 16-bit resolution\n");
|
||||
|
||||
/* Loop to print gyro data when interrupt occurs. */
|
||||
while (indx <= limit)
|
||||
{
|
||||
/* To get the data ready interrupt status of gyro. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the data ready interrupt status and print the status for 10 samples. */
|
||||
if (int_status & BMI2_GYR_DRDY_INT_MASK)
|
||||
{
|
||||
/* Get gyro data for x, y and z axis. */
|
||||
rslt = bmi270_hc_get_sensor_data(&sensor_data, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("\nGyr_X = %d\t", sensor_data.sens_data.gyr.x);
|
||||
printf("Gyr_Y = %d\t", sensor_data.sens_data.gyr.y);
|
||||
printf("Gyr_Z = %d\r\n", sensor_data.sens_data.gyr.z);
|
||||
|
||||
/* Converting lsb to degree per second for 16 bit gyro at 2000dps range. */
|
||||
x = lsb_to_dps(sensor_data.sens_data.gyr.x, 2000, bmi2_dev.resolution);
|
||||
y = lsb_to_dps(sensor_data.sens_data.gyr.y, 2000, bmi2_dev.resolution);
|
||||
z = lsb_to_dps(sensor_data.sens_data.gyr.z, 2000, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in dps. */
|
||||
printf("Gyr_DPS_X = %4.2f, Gyr_DPS_Y = %4.2f, Gyr_DPS_Z = %4.2f\n", x, y, z);
|
||||
|
||||
indx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for gyro.
|
||||
*/
|
||||
static int8_t set_gyro_config(struct bmi2_dev *dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define the type of sensor and its configurations. */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config.type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_hc_get_sensor_config(&config, 1, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Map data ready interrupt to interrupt pin. */
|
||||
rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config.cfg.gyr.odr = BMI2_GYR_ODR_200HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config.cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config.cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config.cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config.cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set the gyro configurations. */
|
||||
rslt = bmi270_hc_set_sensor_config(&config, 1, dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (dps / ((half_scale) + BMI2_GYR_RANGE_2000)) * (val);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= step_counter.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_hc.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_hc.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static function declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for step counter.
|
||||
*
|
||||
* @param[in] bmi2_dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_feature_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Structure to define type of sensor and their respective data. */
|
||||
struct bmi2_sensor_data sensor_data;
|
||||
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Accel sensor and step counter feature are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_STEP_COUNTER };
|
||||
|
||||
/* Variable to get step counter interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Select features and their pins to be mapped to. */
|
||||
struct bmi2_sens_int_config sens_int = { .type = BMI2_STEP_COUNTER, .hw_int_pin = BMI2_INT2 };
|
||||
|
||||
/* Type of sensor to get step counter data. */
|
||||
sensor_data.type = BMI2_STEP_COUNTER;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_hc. */
|
||||
rslt = bmi270_hc_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the selected sensor. */
|
||||
rslt = bmi270_hc_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Set the feature configuration for step counter. */
|
||||
rslt = set_feature_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("Step counter watermark level set to 1 (20 steps)\n");
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Map the step counter feature interrupt. */
|
||||
rslt = bmi270_hc_map_feat_int(&sens_int, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Move the board in steps for 20 times to get step counter interrupt. */
|
||||
printf("Move the board in steps\n");
|
||||
|
||||
/* Loop to get number of steps counted. */
|
||||
do
|
||||
{
|
||||
/* To get the interrupt status of the step counter. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the interrupt status of the step counter. */
|
||||
if (int_status & BMI270_HC_STEP_CNT_STATUS_MASK)
|
||||
{
|
||||
printf("Step counter interrupt occurred when watermark level (20 steps) is reached\n");
|
||||
|
||||
/* Get step counter output. */
|
||||
rslt = bmi270_hc_get_sensor_data(&sensor_data, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Print the step counter output. */
|
||||
printf("No of steps counted = %ld", sensor_data.sens_data.step_counter_output);
|
||||
break;
|
||||
}
|
||||
} while (rslt == BMI2_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for step counter.
|
||||
*/
|
||||
static int8_t set_feature_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define the type of sensor and its configurations. */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Configure the type of sensor. */
|
||||
config.type = BMI2_STEP_COUNTER;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_hc_get_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Setting water-mark level to 1 for step counter to get interrupt after 20 step counts. Every 20 steps once
|
||||
* output triggers. */
|
||||
config.cfg.step_counter.watermark_level = 1;
|
||||
|
||||
/* Set new configuration. */
|
||||
rslt = bmi270_hc_set_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= accel.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_maximum_fifo.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,200 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_maximum_fifo.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Earth's gravity in m/s^2 */
|
||||
#define GRAVITY_EARTH (9.80665f)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] g_range : Gravity range.
|
||||
* @param[in] bit_width : Resolution for accel.
|
||||
*
|
||||
* @return Gravity.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to define limit to print accel data. */
|
||||
uint8_t limit = 20;
|
||||
|
||||
/* Assign accel sensor to variable. */
|
||||
uint8_t sensor_list = BMI2_ACCEL;
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Create an instance of sensor data structure. */
|
||||
struct bmi2_sensor_data sensor_data = { 0 };
|
||||
|
||||
/* Initialize the interrupt status of accel. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint8_t indx = 0;
|
||||
float x = 0, y = 0, z = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_maximum_fifo. */
|
||||
rslt = bmi270_maximum_fifo_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the accel sensor. */
|
||||
rslt = bmi2_sensor_enable(&sensor_list, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Accel configuration settings. */
|
||||
rslt = set_accel_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Assign accel sensor. */
|
||||
sensor_data.type = BMI2_ACCEL;
|
||||
printf("Accel and m/s2 data \n");
|
||||
printf("Accel data collected at 2G Range with 16-bit resolution\n");
|
||||
|
||||
/* Loop to print the accel data when interrupt occurs. */
|
||||
while (indx <= limit)
|
||||
{
|
||||
/* To get the status of accel data ready interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the accel data ready interrupt status and print the status for 10 samples. */
|
||||
if (int_status & BMI2_ACC_DRDY_INT_MASK)
|
||||
{
|
||||
/* Get accelerometer data for x, y and z axis. */
|
||||
rslt = bmi2_get_sensor_data(&sensor_data, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
printf("\nAcc_X = %d\t", sensor_data.sens_data.acc.x);
|
||||
printf("Acc_Y = %d\t", sensor_data.sens_data.acc.y);
|
||||
printf("Acc_Z = %d\r\n", sensor_data.sens_data.acc.z);
|
||||
|
||||
/* Converting lsb to meter per second squared for 16 bit accelerometer at 2G range. */
|
||||
x = lsb_to_mps2(sensor_data.sens_data.acc.x, 2, bmi2_dev.resolution);
|
||||
y = lsb_to_mps2(sensor_data.sens_data.acc.y, 2, bmi2_dev.resolution);
|
||||
z = lsb_to_mps2(sensor_data.sens_data.acc.z, 2, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in m/s2. */
|
||||
printf("\nAcc_ms2_X = %4.2f, Acc_ms2_Y = %4.2f, Acc_ms2_Z = %4.2f\n", x, y, z);
|
||||
|
||||
indx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*/
|
||||
static int8_t set_accel_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accelerometer configuration. */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config.type = BMI2_ACCEL;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi2_get_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config.cfg.acc.odr = BMI2_ACC_ODR_200HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config.cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples.
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config.cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config.cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set the accel configurations. */
|
||||
rslt = bmi2_set_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Map data ready interrupt to interrupt pin. */
|
||||
rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (GRAVITY_EARTH * val * g_range) / half_scale;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= accel_gyro.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_maximum_fifo.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+268
@@ -0,0 +1,268 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_maximum_fifo.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Earth's gravity in m/s^2 */
|
||||
#define GRAVITY_EARTH (9.80665f)
|
||||
|
||||
/*! Macros to select the sensors */
|
||||
#define ACCEL UINT8_C(0x00)
|
||||
#define GYRO UINT8_C(0x01)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] g_range : Gravity range.
|
||||
* @param[in] bit_width : Resolution for accel.
|
||||
*
|
||||
* @return Gravity.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] dps : Degree per second.
|
||||
* @param[in] bit_width : Resolution for gyro.
|
||||
*
|
||||
* @return Degree per second.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to define limit to print accel data. */
|
||||
uint8_t limit = 10;
|
||||
|
||||
/* Assign accel and gyro sensor to variable. */
|
||||
uint8_t sensor_list[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Create an instance of sensor data structure. */
|
||||
struct bmi2_sensor_data sensor_data[2] = { { 0 } };
|
||||
|
||||
/* Initialize the interrupt status of accel and gyro. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint8_t indx = 1;
|
||||
|
||||
float x = 0, y = 0, z = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_maximum_fifo. */
|
||||
rslt = bmi270_maximum_fifo_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the accel and gyro sensor. */
|
||||
rslt = bmi2_sensor_enable(sensor_list, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Accel and gyro configuration settings. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Assign accel and gyro sensor. */
|
||||
sensor_data[ACCEL].type = BMI2_ACCEL;
|
||||
sensor_data[GYRO].type = BMI2_GYRO;
|
||||
|
||||
/* Loop to print accel and gyro data when interrupt occurs. */
|
||||
while (indx <= limit)
|
||||
{
|
||||
/* To get the data ready interrupt status of accel and gyro. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the data ready interrupt status and print the status for 10 samples. */
|
||||
if ((int_status & BMI2_ACC_DRDY_INT_MASK) && (int_status & BMI2_GYR_DRDY_INT_MASK))
|
||||
{
|
||||
/* Get accel and gyro data for x, y and z axis. */
|
||||
rslt = bmi2_get_sensor_data(sensor_data, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("\n******* Accel(Raw and m/s2) Gyro(Raw and dps) data : %d *******\n", indx);
|
||||
|
||||
printf("\nAcc_x = %d\t", sensor_data[ACCEL].sens_data.acc.x);
|
||||
printf("Acc_y = %d\t", sensor_data[ACCEL].sens_data.acc.y);
|
||||
printf("Acc_z = %d", sensor_data[ACCEL].sens_data.acc.z);
|
||||
|
||||
/* Converting lsb to meter per second squared for 16 bit accelerometer at 2G range. */
|
||||
x = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.x, 2, bmi2_dev.resolution);
|
||||
y = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.y, 2, bmi2_dev.resolution);
|
||||
z = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.z, 2, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in m/s2. */
|
||||
printf("\nAcc_ms2_X = %4.2f, Acc_ms2_Y = %4.2f, Acc_ms2_Z = %4.2f\n", x, y, z);
|
||||
|
||||
printf("\nGyr_X = %d\t", sensor_data[GYRO].sens_data.gyr.x);
|
||||
printf("Gyr_Y = %d\t", sensor_data[GYRO].sens_data.gyr.y);
|
||||
printf("Gyr_Z= %d\n", sensor_data[GYRO].sens_data.gyr.z);
|
||||
|
||||
/* Converting lsb to degree per second for 16 bit gyro at 2000dps range. */
|
||||
x = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.x, 2000, bmi2_dev.resolution);
|
||||
y = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.y, 2000, bmi2_dev.resolution);
|
||||
z = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.z, 2000, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in dps. */
|
||||
printf("Gyro_DPS_X = %4.2f, Gyro_DPS_Y = %4.2f, Gyro_DPS_Z = %4.2f\n", x, y, z);
|
||||
|
||||
indx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accelerometer and gyro configuration. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[ACCEL].type = BMI2_ACCEL;
|
||||
config[GYRO].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi2_get_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Map data ready interrupt to interrupt pin. */
|
||||
rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config[ACCEL].cfg.acc.odr = BMI2_ACC_ODR_200HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[ACCEL].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples.
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[ACCEL].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[ACCEL].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config[GYRO].cfg.gyr.odr = BMI2_GYR_ODR_200HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[GYRO].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[GYRO].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[GYRO].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[GYRO].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set the accel and gyro configurations. */
|
||||
rslt = bmi2_set_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (GRAVITY_EARTH * val * g_range) / half_scale;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (dps / ((half_scale) + BMI2_GYR_RANGE_2000)) * (val);
|
||||
}
|
||||
+372
@@ -0,0 +1,372 @@
|
||||
/**
|
||||
* Copyright (C) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "coines.h"
|
||||
#include "bmi2_defs.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definitions */
|
||||
#define BMI2XY_SHUTTLE_ID UINT16_C(0x1B8)
|
||||
|
||||
/*! Macro that defines read write length */
|
||||
#define READ_WRITE_LEN UINT8_C(46)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static variable definition */
|
||||
|
||||
/*! Variable that holds the I2C device address or SPI chip selection */
|
||||
static uint8_t dev_addr;
|
||||
|
||||
/******************************************************************************/
|
||||
/*! User interface functions */
|
||||
|
||||
/*!
|
||||
* I2C read function map to COINES platform
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_addr = *(uint8_t*)intf_ptr;
|
||||
|
||||
return coines_read_i2c(dev_addr, reg_addr, reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* I2C write function map to COINES platform
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_addr = *(uint8_t*)intf_ptr;
|
||||
|
||||
return coines_write_i2c(dev_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* SPI read function map to COINES platform
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_addr = *(uint8_t*)intf_ptr;
|
||||
|
||||
return coines_read_spi(dev_addr, reg_addr, reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* SPI write function map to COINES platform
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_addr = *(uint8_t*)intf_ptr;
|
||||
|
||||
return coines_write_spi(dev_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Delay function map to COINES platform
|
||||
*/
|
||||
void bmi2_delay_us(uint32_t period, void *intf_ptr)
|
||||
{
|
||||
coines_delay_usec(period);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Function to select the interface between SPI and I2C.
|
||||
* Also to initialize coines platform
|
||||
*/
|
||||
int8_t bmi2_interface_init(struct bmi2_dev *bmi, uint8_t intf)
|
||||
{
|
||||
int8_t rslt = BMI2_OK;
|
||||
struct coines_board_info board_info;
|
||||
|
||||
if (bmi != NULL)
|
||||
{
|
||||
int16_t result = coines_open_comm_intf(COINES_COMM_INTF_USB);
|
||||
if (result < COINES_SUCCESS)
|
||||
{
|
||||
printf(
|
||||
"\n Unable to connect with Application Board ! \n" " 1. Check if the board is connected and powered on. \n" " 2. Check if Application Board USB driver is installed. \n"
|
||||
" 3. Check if board is in use by another application. (Insufficient permissions to access USB) \n");
|
||||
exit(result);
|
||||
}
|
||||
|
||||
result = coines_get_board_info(&board_info);
|
||||
|
||||
#if defined(PC)
|
||||
setbuf(stdout, NULL);
|
||||
#endif
|
||||
|
||||
if (result == COINES_SUCCESS)
|
||||
{
|
||||
if ((board_info.shuttle_id != BMI2XY_SHUTTLE_ID))
|
||||
{
|
||||
printf("! Warning invalid sensor shuttle \n ," "This application will not support this sensor \n");
|
||||
exit(COINES_E_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
coines_set_shuttleboard_vdd_vddio_config(0, 0);
|
||||
coines_delay_msec(100);
|
||||
|
||||
/* Bus configuration : I2C */
|
||||
if (intf == BMI2_I2C_INTF)
|
||||
{
|
||||
printf("I2C Interface \n");
|
||||
|
||||
/* To initialize the user I2C function */
|
||||
dev_addr = BMI2_I2C_PRIM_ADDR;
|
||||
bmi->intf = BMI2_I2C_INTF;
|
||||
bmi->read = bmi2_i2c_read;
|
||||
bmi->write = bmi2_i2c_write;
|
||||
coines_config_i2c_bus(COINES_I2C_BUS_0, COINES_I2C_FAST_MODE);
|
||||
}
|
||||
/* Bus configuration : SPI */
|
||||
else if (intf == BMI2_SPI_INTF)
|
||||
{
|
||||
printf("SPI Interface \n");
|
||||
|
||||
/* To initialize the user SPI function */
|
||||
dev_addr = COINES_SHUTTLE_PIN_7;
|
||||
bmi->intf = BMI2_SPI_INTF;
|
||||
bmi->read = bmi2_spi_read;
|
||||
bmi->write = bmi2_spi_write;
|
||||
coines_config_spi_bus(COINES_SPI_BUS_0, COINES_SPI_SPEED_5_MHZ, COINES_SPI_MODE3);
|
||||
coines_set_pin_config(COINES_SHUTTLE_PIN_7, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_HIGH);
|
||||
}
|
||||
|
||||
/* Assign device address to interface pointer */
|
||||
bmi->intf_ptr = &dev_addr;
|
||||
|
||||
/* Configure delay in microseconds */
|
||||
bmi->delay_us = bmi2_delay_us;
|
||||
|
||||
/* Configure max read/write length (in bytes) ( Supported length depends on target machine) */
|
||||
bmi->read_write_len = READ_WRITE_LEN;
|
||||
|
||||
/* Assign to NULL to load the default config file. */
|
||||
bmi->config_file_ptr = NULL;
|
||||
|
||||
coines_delay_usec(10000);
|
||||
|
||||
coines_set_shuttleboard_vdd_vddio_config(3300, 3300);
|
||||
|
||||
coines_delay_usec(10000);
|
||||
}
|
||||
else
|
||||
{
|
||||
rslt = BMI2_E_NULL_PTR;
|
||||
}
|
||||
|
||||
return rslt;
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Prints the execution status of the APIs.
|
||||
*/
|
||||
void bmi2_error_codes_print_result(int8_t rslt)
|
||||
{
|
||||
switch (rslt)
|
||||
{
|
||||
case BMI2_OK:
|
||||
|
||||
/* Do nothing */
|
||||
break;
|
||||
|
||||
case BMI2_W_FIFO_EMPTY:
|
||||
printf("Warning [%d] : FIFO empty\r\n", rslt);
|
||||
break;
|
||||
case BMI2_W_PARTIAL_READ:
|
||||
printf("Warning [%d] : FIFO partial read\r\n", rslt);
|
||||
break;
|
||||
case BMI2_E_NULL_PTR:
|
||||
printf(
|
||||
"Error [%d] : Null pointer error. It occurs when the user tries to assign value (not address) to a pointer," " which has been initialized to NULL.\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_COM_FAIL:
|
||||
printf(
|
||||
"Error [%d] : Communication failure error. It occurs due to read/write operation failure and also due " "to power failure during communication\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_DEV_NOT_FOUND:
|
||||
printf("Error [%d] : Device not found error. It occurs when the device chip id is incorrectly read\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_SENSOR:
|
||||
printf(
|
||||
"Error [%d] : Invalid sensor error. It occurs when there is a mismatch in the requested feature with the " "available one\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_SELF_TEST_FAIL:
|
||||
printf(
|
||||
"Error [%d] : Self-test failed error. It occurs when the validation of accel self-test data is " "not satisfied\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_INT_PIN:
|
||||
printf(
|
||||
"Error [%d] : Invalid interrupt pin error. It occurs when the user tries to configure interrupt pins " "apart from INT1 and INT2\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_OUT_OF_RANGE:
|
||||
printf(
|
||||
"Error [%d] : Out of range error. It occurs when the data exceeds from filtered or unfiltered data from " "fifo and also when the range exceeds the maximum range for accel and gyro while performing FOC\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ACC_INVALID_CFG:
|
||||
printf(
|
||||
"Error [%d] : Invalid Accel configuration error. It occurs when there is an error in accel configuration" " register which could be one among range, BW or filter performance in reg address 0x40\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_GYRO_INVALID_CFG:
|
||||
printf(
|
||||
"Error [%d] : Invalid Gyro configuration error. It occurs when there is a error in gyro configuration" "register which could be one among range, BW or filter performance in reg address 0x42\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ACC_GYR_INVALID_CFG:
|
||||
printf(
|
||||
"Error [%d] : Invalid Accel-Gyro configuration error. It occurs when there is a error in accel and gyro" " configuration registers which could be one among range, BW or filter performance in reg address 0x40 " "and 0x42\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_CONFIG_LOAD:
|
||||
printf(
|
||||
"Error [%d] : Configuration load error. It occurs when failure observed while loading the configuration " "into the sensor\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_PAGE:
|
||||
printf(
|
||||
"Error [%d] : Invalid page error. It occurs due to failure in writing the correct feature configuration " "from selected page\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_SET_APS_FAIL:
|
||||
printf(
|
||||
"Error [%d] : APS failure error. It occurs due to failure in write of advance power mode configuration " "register\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_AUX_INVALID_CFG:
|
||||
printf(
|
||||
"Error [%d] : Invalid AUX configuration error. It occurs when the auxiliary interface settings are not " "enabled properly\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_AUX_BUSY:
|
||||
printf(
|
||||
"Error [%d] : AUX busy error. It occurs when the auxiliary interface buses are engaged while configuring" " the AUX\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_REMAP_ERROR:
|
||||
printf(
|
||||
"Error [%d] : Remap error. It occurs due to failure in assigning the remap axes data for all the axes " "after change in axis position\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_GYR_USER_GAIN_UPD_FAIL:
|
||||
printf(
|
||||
"Error [%d] : Gyro user gain update fail error. It occurs when the reading of user gain update status " "fails\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_SELF_TEST_NOT_DONE:
|
||||
printf(
|
||||
"Error [%d] : Self-test not done error. It occurs when the self-test process is ongoing or not " "completed\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_INPUT:
|
||||
printf("Error [%d] : Invalid input error. It occurs when the sensor input validity fails\r\n", rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_STATUS:
|
||||
printf("Error [%d] : Invalid status error. It occurs when the feature/sensor validity fails\r\n", rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_CRT_ERROR:
|
||||
printf("Error [%d] : CRT error. It occurs when the CRT test has failed\r\n", rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ST_ALREADY_RUNNING:
|
||||
printf(
|
||||
"Error [%d] : Self-test already running error. It occurs when the self-test is already running and " "another has been initiated\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_CRT_READY_FOR_DL_FAIL_ABORT:
|
||||
printf(
|
||||
"Error [%d] : CRT ready for download fail abort error. It occurs when download in CRT fails due to wrong " "address location\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_DL_ERROR:
|
||||
printf(
|
||||
"Error [%d] : Download error. It occurs when write length exceeds that of the maximum burst length\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_PRECON_ERROR:
|
||||
printf(
|
||||
"Error [%d] : Pre-conditional error. It occurs when precondition to start the feature was not " "completed\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ABORT_ERROR:
|
||||
printf("Error [%d] : Abort error. It occurs when the device was shaken during CRT test\r\n", rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_WRITE_CYCLE_ONGOING:
|
||||
printf(
|
||||
"Error [%d] : Write cycle ongoing error. It occurs when the write cycle is already running and another " "has been initiated\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_ST_NOT_RUNING:
|
||||
printf(
|
||||
"Error [%d] : Self-test is not running error. It occurs when self-test running is disabled while it's " "running\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_DATA_RDY_INT_FAILED:
|
||||
printf(
|
||||
"Error [%d] : Data ready interrupt error. It occurs when the sample count exceeds the FOC sample limit " "and data ready status is not updated\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
case BMI2_E_INVALID_FOC_POSITION:
|
||||
printf(
|
||||
"Error [%d] : Invalid FOC position error. It occurs when average FOC data is obtained for the wrong" " axes\r\n",
|
||||
rslt);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Error [%d] : Unknown error code\r\n", rslt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Deinitializes coines platform
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
void bmi2_coines_deinit(void)
|
||||
{
|
||||
coines_close_comm_intf(COINES_COMM_INTF_USB);
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#ifndef _COMMON_H
|
||||
#define _COMMON_H
|
||||
|
||||
/*! CPP guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "bmi2.h"
|
||||
|
||||
/*!
|
||||
* @brief Function for reading the sensor's registers through I2C bus.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[out] reg_data : Pointer to the data buffer to store the read data.
|
||||
* @param[in] length : No of bytes to read.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval = BMI2_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMI2_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Function for writing the sensor's registers through I2C bus.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[in] reg_data : Pointer to the data buffer whose value is to be written.
|
||||
* @param[in] length : No of bytes to write.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval = BMI2_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMI2_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Function for reading the sensor's registers through SPI bus.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[out] reg_data : Pointer to the data buffer to store the read data.
|
||||
* @param[in] length : No of bytes to read.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval = BMI2_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMI2_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Function for writing the sensor's registers through SPI bus.
|
||||
*
|
||||
* @param[in] reg_addr : Register address.
|
||||
* @param[in] reg_data : Pointer to the data buffer whose data has to be written.
|
||||
* @param[in] length : No of bytes to write.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval = BMI2_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMI2_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMI2_INTF_RETURN_TYPE bmi2_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief This function provides the delay for required time (Microsecond) as per the input provided in some of the
|
||||
* APIs.
|
||||
*
|
||||
* @param[in] period_us : The required wait time in microsecond.
|
||||
* @param[in] intf_ptr : Interface pointer
|
||||
*
|
||||
* @return void.
|
||||
*
|
||||
*/
|
||||
void bmi2_delay_us(uint32_t period, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Function to select the interface between SPI and I2C.
|
||||
*
|
||||
* @param[in] bma : Structure instance of bmi2_dev
|
||||
* @param[in] intf : Interface selection parameter
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval 0 -> Success
|
||||
* @retval < 0 -> Failure Info
|
||||
*/
|
||||
int8_t bmi2_interface_init(struct bmi2_dev *bma, uint8_t intf);
|
||||
|
||||
/*!
|
||||
* @brief Prints the execution status of the APIs.
|
||||
*
|
||||
* @param[in] rslt : Error code returned by the API whose execution status has to be printed.
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
void bmi2_error_codes_print_result(int8_t rslt);
|
||||
|
||||
/*!
|
||||
* @brief Deinitializes coines platform
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
void bmi2_coines_deinit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* End of CPP guard */
|
||||
|
||||
#endif /* _COMMON_H */
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= component_retrim.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_maximum_fifo.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_maximum_fifo.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_maximum_fifo. */
|
||||
rslt = bmi270_maximum_fifo_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* This API runs the CRT process. */
|
||||
rslt = bmi2_do_crt(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Do not move the board while doing CRT. If so, it will throw an abort error. */
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("CRT successfully completed.");
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_watermark_header_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_maximum_fifo.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+335
@@ -0,0 +1,335 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_maximum_fifo.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macros */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMI2_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(2048)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMI2_FIFO_RAW_DATA_USER_LENGTH UINT16_C(2048)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO */
|
||||
|
||||
/*!
|
||||
* Calculation:
|
||||
* fifo_watermark_level = 650, accel_frame_len = 6, gyro_frame_len = 6 header_byte = 1.
|
||||
* fifo_accel_frame_count = (650 / (6 + 6 + 1 )) = 50 frames
|
||||
* NOTE: Extra frames are read in order to get sensor time
|
||||
*/
|
||||
#define BMI2_FIFO_ACCEL_FRAME_COUNT UINT8_C(55)
|
||||
|
||||
/*! Number of gyro frames to be extracted from FIFO */
|
||||
#define BMI2_FIFO_GYRO_FRAME_COUNT UINT8_C(55)
|
||||
|
||||
/*! Setting a watermark level in FIFO */
|
||||
#define BMI270_FIFO_WATERMARK_LEVEL UINT16_C(650)
|
||||
|
||||
/*! Macro to read sensortime byte in FIFO */
|
||||
#define SENSORTIME_OVERHEAD_BYTE UINT8_C(3)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to store the available frame length count in FIFO */
|
||||
uint8_t frame_count;
|
||||
|
||||
/* Variable to index bytes. */
|
||||
uint16_t index = 0;
|
||||
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
uint16_t accel_frame_length;
|
||||
|
||||
uint16_t gyro_frame_length;
|
||||
|
||||
uint8_t try = 1;
|
||||
|
||||
/* To read sensortime, extra 3 bytes are added to fifo buffer */
|
||||
uint16_t fifo_buffer_size = BMI2_FIFO_RAW_DATA_BUFFER_SIZE + SENSORTIME_OVERHEAD_BYTE;
|
||||
|
||||
/* Number of bytes of FIFO data. */
|
||||
uint8_t fifo_data[fifo_buffer_size];
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 55 * (6 axes bytes) = 330 bytes */
|
||||
struct bmi2_sens_axes_data fifo_accel_data[BMI2_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Array of gyro frames -> Total bytes =
|
||||
* 55 * (6 axes bytes) = 330 bytes */
|
||||
struct bmi2_sens_axes_data fifo_gyro_data[BMI2_FIFO_GYRO_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure. */
|
||||
struct bmi2_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Accel and gyro sensor are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Variable to get fifo water-mark interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint16_t watermark = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_maximum_fifo. */
|
||||
rslt = bmi270_maximum_fifo_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Enable accel and gyro sensor. */
|
||||
rslt = bmi2_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Configuration settings for accel and gyro. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Before setting FIFO, disable the advance power save mode. */
|
||||
rslt = bmi2_set_adv_power_save(BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initially disable all configurations in fifo. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ALL_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Update FIFO structure. */
|
||||
/* Mapping the buffer to store the fifo data. */
|
||||
fifoframe.data = fifo_data;
|
||||
|
||||
/* Length of FIFO frame. */
|
||||
/* To read sensortime, extra 3 bytes are added to fifo user length. */
|
||||
fifoframe.length = BMI2_FIFO_RAW_DATA_USER_LENGTH + SENSORTIME_OVERHEAD_BYTE;
|
||||
|
||||
/* Set FIFO configuration by enabling accel, gyro and timestamp.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode.
|
||||
* NOTE 3: Sensortime is enabled by default */
|
||||
printf("FIFO is configured in header mode\n");
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ACC_EN | BMI2_FIFO_GYR_EN, BMI2_ENABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* FIFO water-mark interrupt is enabled. */
|
||||
fifoframe.data_int_map = BMI2_FWM_INT;
|
||||
|
||||
/* Map water-mark interrupt to the required interrupt pin. */
|
||||
rslt = bmi2_map_data_int(fifoframe.data_int_map, BMI2_INT1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Set water-mark level. */
|
||||
fifoframe.wm_lvl = BMI270_FIFO_WATERMARK_LEVEL;
|
||||
|
||||
/* Set the water-mark level if water-mark interrupt is mapped. */
|
||||
rslt = bmi2_set_fifo_wm(fifoframe.wm_lvl, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
rslt = bmi2_get_fifo_wm(&watermark, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
printf("\nFIFO watermark level is %d\n", watermark);
|
||||
|
||||
while (try <= 10)
|
||||
{
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the status of FIFO watermark interrupt. */
|
||||
if ((rslt == BMI2_OK) && (int_status & BMI2_FWM_INT_STATUS_MASK))
|
||||
{
|
||||
printf("\nIteration : %d\n", try);
|
||||
|
||||
printf("\nWatermark interrupt occurred\n");
|
||||
|
||||
rslt = bmi2_get_fifo_length(&fifo_length, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
accel_frame_length = BMI2_FIFO_ACCEL_FRAME_COUNT;
|
||||
gyro_frame_length = BMI2_FIFO_GYRO_FRAME_COUNT;
|
||||
|
||||
printf("\nFIFO data bytes available : %d \n", fifo_length);
|
||||
printf("\nFIFO data bytes requested : %d \n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data. */
|
||||
rslt = bmi2_read_fifo_data(&fifoframe, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("\nFIFO accel frames requested : %d \n", accel_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_accel(fifo_accel_data, &accel_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO accel frames extracted : %d \n", accel_frame_length);
|
||||
|
||||
printf("\nFIFO gyro frames requested : %d \n", gyro_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract gyro data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_gyro(fifo_gyro_data, &gyro_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO gyro frames extracted : %d \n", gyro_frame_length);
|
||||
|
||||
/* Calculating the frame count from the available bytes in FIFO
|
||||
* frame_length = (available_fifo_bytes / (acc_frame_len + gyro_frame_len + header_byte)) */
|
||||
frame_count = (fifo_length / (BMI2_FIFO_ACC_GYR_LENGTH + 1));
|
||||
printf("\nAvailable frame count from available bytes: %d\n", frame_count);
|
||||
|
||||
printf("\nExracted accel frames\n");
|
||||
|
||||
if (accel_frame_length > frame_count)
|
||||
{
|
||||
accel_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer. */
|
||||
for (index = 0; index < accel_frame_length; index++)
|
||||
{
|
||||
printf("ACCEL[%d] X : %d\t Y : %d\t Z : %d\n", index, fifo_accel_data[index].x,
|
||||
fifo_accel_data[index].y, fifo_accel_data[index].z);
|
||||
}
|
||||
|
||||
printf("\nExtracted gyro frames\n");
|
||||
|
||||
if (gyro_frame_length > frame_count)
|
||||
{
|
||||
gyro_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed gyro data from the FIFO buffer. */
|
||||
for (index = 0; index < gyro_frame_length; index++)
|
||||
{
|
||||
printf("GYRO[%d] X : %d\t Y : %d\t Z : %d\n",
|
||||
index,
|
||||
fifo_gyro_data[index].x,
|
||||
fifo_gyro_data[index].y,
|
||||
fifo_gyro_data[index].z);
|
||||
}
|
||||
|
||||
/* Print control frames like sensor time and skipped frame count. */
|
||||
printf("Skipped frame count = %d\n", fifoframe.skipped_frame_count);
|
||||
printf("Sensor time = %lu\r\n", fifoframe.sensor_time);
|
||||
|
||||
try++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accel and gyro configurations. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[0].type = BMI2_ACCEL;
|
||||
config[1].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi2_get_sensor_config(config, 2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Accel configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[0].cfg.acc.odr = BMI2_ACC_ODR_25HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[0].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[0].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Gyro configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[1].cfg.gyr.odr = BMI2_GYR_ODR_25HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope Bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[1].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[1].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set new configurations. */
|
||||
rslt = bmi2_set_sensor_config(config, 2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_watermark_headerless_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_maximum_fifo.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+331
@@ -0,0 +1,331 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_maximum_fifo.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macros */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMI2_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(2048)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMI2_FIFO_RAW_DATA_USER_LENGTH UINT16_C(2048)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO */
|
||||
|
||||
/*!
|
||||
* Calculation:
|
||||
* fifo_watermark_level = 650, accel_frame_len = 6, gyro_frame_len = 6.
|
||||
* fifo_accel_frame_count = (650 / (6 + 6 )) = 54 frames
|
||||
*/
|
||||
#define BMI2_FIFO_ACCEL_FRAME_COUNT UINT8_C(55)
|
||||
|
||||
/*! Number of gyro frames to be extracted from FIFO */
|
||||
#define BMI2_FIFO_GYRO_FRAME_COUNT UINT8_C(55)
|
||||
|
||||
/*! Setting a watermark level in FIFO */
|
||||
#define BMI270_FIFO_WATERMARK_LEVEL UINT16_C(650)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to index bytes. */
|
||||
uint16_t index = 0;
|
||||
|
||||
/* Variable to store the available frame length count in FIFO */
|
||||
uint8_t frame_count;
|
||||
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
uint16_t accel_frame_length;
|
||||
|
||||
uint16_t gyro_frame_length;
|
||||
|
||||
uint8_t try = 1;
|
||||
|
||||
/* Number of bytes of FIFO data. */
|
||||
uint8_t fifo_data[BMI2_FIFO_RAW_DATA_BUFFER_SIZE] = { 0 };
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 50 * (6 axes bytes) = 300 bytes */
|
||||
struct bmi2_sens_axes_data fifo_accel_data[BMI2_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Array of gyro frames -> Total bytes =
|
||||
* 50 * (6 axes bytes) = 300 bytes */
|
||||
struct bmi2_sens_axes_data fifo_gyro_data[BMI2_FIFO_GYRO_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure. */
|
||||
struct bmi2_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Accel and gyro sensor are listed in array. */
|
||||
uint8_t sensor_sel[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Variable to get fifo water-mark interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint16_t watermark = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_maximum_fifo_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Enable accel and gyro sensor. */
|
||||
rslt = bmi2_sensor_enable(sensor_sel, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Configuration settings for accel and gyro. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Before setting FIFO, disable the advance power save mode. */
|
||||
rslt = bmi2_set_adv_power_save(BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initially disable all configurations in fifo. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ALL_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Update FIFO structure. */
|
||||
/* Mapping the buffer to store the fifo data. */
|
||||
fifoframe.data = fifo_data;
|
||||
|
||||
/* Length of FIFO frame. */
|
||||
fifoframe.length = BMI2_FIFO_RAW_DATA_USER_LENGTH;
|
||||
|
||||
/* Set FIFO configuration by enabling accel, gyro.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode. */
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_ACC_EN | BMI2_FIFO_GYR_EN, BMI2_ENABLE, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("FIFO is configured in headerless mode\n");
|
||||
|
||||
/* To enable headerless mode, disable the header. */
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
rslt = bmi2_set_fifo_config(BMI2_FIFO_HEADER_EN, BMI2_DISABLE, &bmi2_dev);
|
||||
}
|
||||
|
||||
/* FIFO water-mark interrupt is enabled. */
|
||||
fifoframe.data_int_map = BMI2_FWM_INT;
|
||||
|
||||
/* Map water-mark interrupt to the required interrupt pin. */
|
||||
rslt = bmi2_map_data_int(fifoframe.data_int_map, BMI2_INT1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Set water-mark level. */
|
||||
fifoframe.wm_lvl = BMI270_FIFO_WATERMARK_LEVEL;
|
||||
|
||||
fifoframe.length = BMI2_FIFO_RAW_DATA_USER_LENGTH;
|
||||
|
||||
/* Set the water-mark level if water-mark interrupt is mapped. */
|
||||
rslt = bmi2_set_fifo_wm(fifoframe.wm_lvl, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
rslt = bmi2_get_fifo_wm(&watermark, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
printf("\nFIFO watermark level is %d\n", watermark);
|
||||
|
||||
while (try <= 10)
|
||||
{
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the status of FIFO watermark interrupt. */
|
||||
if ((rslt == BMI2_OK) && (int_status & BMI2_FWM_INT_STATUS_MASK))
|
||||
{
|
||||
printf("\nIteration : %d\n", try);
|
||||
|
||||
printf("\nWatermark interrupt occurred\n");
|
||||
|
||||
rslt = bmi2_get_fifo_length(&fifo_length, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
accel_frame_length = BMI2_FIFO_ACCEL_FRAME_COUNT;
|
||||
gyro_frame_length = BMI2_FIFO_GYRO_FRAME_COUNT;
|
||||
|
||||
printf("\nFIFO data bytes available : %d \n", fifo_length);
|
||||
printf("\nFIFO data bytes requested : %d \n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data. */
|
||||
rslt = bmi2_read_fifo_data(&fifoframe, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Read FIFO data on interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
printf("\nFIFO accel frames requested : %d \n", accel_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_accel(fifo_accel_data, &accel_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO accel frames extracted : %d \n", accel_frame_length);
|
||||
|
||||
printf("\nFIFO gyro frames requested : %d \n", gyro_frame_length);
|
||||
|
||||
/* Parse the FIFO data to extract gyro data from the FIFO buffer. */
|
||||
rslt = bmi2_extract_gyro(fifo_gyro_data, &gyro_frame_length, &fifoframe, &bmi2_dev);
|
||||
printf("\nFIFO gyro frames extracted : %d \n", gyro_frame_length);
|
||||
|
||||
/* Calculating the frame count from the available bytes in FIFO
|
||||
* frame_length = (available_fifo_bytes / (acc_frame_len + gyro_frame_len)) */
|
||||
frame_count = (fifo_length / (BMI2_FIFO_ACC_GYR_LENGTH));
|
||||
printf("\nAvailable frame count from available bytes: %d\n", frame_count);
|
||||
|
||||
printf("\nExracted accel frames\n");
|
||||
|
||||
if (accel_frame_length > frame_count)
|
||||
{
|
||||
accel_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer. */
|
||||
for (index = 0; index < accel_frame_length; index++)
|
||||
{
|
||||
printf("ACCEL[%d] X : %d\t Y : %d\t Z : %d\n", index, fifo_accel_data[index].x,
|
||||
fifo_accel_data[index].y, fifo_accel_data[index].z);
|
||||
}
|
||||
|
||||
printf("\nExtracted gyro frames\n");
|
||||
|
||||
if (gyro_frame_length > frame_count)
|
||||
{
|
||||
gyro_frame_length = frame_count;
|
||||
}
|
||||
|
||||
/* Print the parsed gyro data from the FIFO buffer. */
|
||||
for (index = 0; index < gyro_frame_length; index++)
|
||||
{
|
||||
printf("GYRO[%d] X : %d\t Y : %d\t Z : %d\n",
|
||||
index,
|
||||
fifo_gyro_data[index].x,
|
||||
fifo_gyro_data[index].y,
|
||||
fifo_gyro_data[index].z);
|
||||
}
|
||||
}
|
||||
|
||||
try++;
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accel and gyro configurations. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[0].type = BMI2_ACCEL;
|
||||
config[1].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi2_get_sensor_config(config, 2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameter according to their requirement. */
|
||||
/* Accel configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[0].cfg.acc.odr = BMI2_ACC_ODR_100HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[0].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[0].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Gyro configuration settings. */
|
||||
/* Set Output Data Rate */
|
||||
config[1].cfg.gyr.odr = BMI2_GYR_ODR_100HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope Bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[1].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[1].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set new configurations. */
|
||||
rslt = bmi2_set_sensor_config(config, 2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= gyro.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_maximum_fifo.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,195 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_maximum_fifo.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for gyro.
|
||||
*
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_gyro_config(struct bmi2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] dps : Degree per second.
|
||||
* @param[in] bit_width : Resolution for gyro.
|
||||
*
|
||||
* @return Degree per second.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to define limit to print gyro data. */
|
||||
uint8_t limit = 10;
|
||||
|
||||
uint8_t indx = 0;
|
||||
|
||||
float x = 0, y = 0, z = 0;
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Create an instance of sensor data structure. */
|
||||
struct bmi2_sensor_data sensor_data = { 0 };
|
||||
|
||||
/* Assign gyro sensor to variable. */
|
||||
uint8_t sens_list = BMI2_GYRO;
|
||||
|
||||
/* Initialize the interrupt status of gyro. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_maximum_fifo_init */
|
||||
rslt = bmi270_maximum_fifo_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the selected sensors. */
|
||||
rslt = bmi2_sensor_enable(&sens_list, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Gyro configuration settings. */
|
||||
rslt = set_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Select gyro sensor. */
|
||||
sensor_data.type = BMI2_GYRO;
|
||||
printf("Gyro and DPS data\n");
|
||||
printf("Gyro data collected at Range 2000 dps with 16-bit resolution\n");
|
||||
|
||||
/* Loop to print gyro data when interrupt occurs. */
|
||||
while (indx <= limit)
|
||||
{
|
||||
/* To get the data ready interrupt status of gyro. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the data ready interrupt status and print the status for 10 samples. */
|
||||
if (int_status & BMI2_GYR_DRDY_INT_MASK)
|
||||
{
|
||||
/* Get gyro data for x, y and z axis. */
|
||||
rslt = bmi2_get_sensor_data(&sensor_data, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("\nGyr_X = %d\t", sensor_data.sens_data.gyr.x);
|
||||
printf("Gyr_Y = %d\t", sensor_data.sens_data.gyr.y);
|
||||
printf("Gyr_Z = %d\r\n", sensor_data.sens_data.gyr.z);
|
||||
|
||||
/* Converting lsb to degree per second for 16 bit gyro at 2000dps range. */
|
||||
x = lsb_to_dps(sensor_data.sens_data.gyr.x, 2000, bmi2_dev.resolution);
|
||||
y = lsb_to_dps(sensor_data.sens_data.gyr.y, 2000, bmi2_dev.resolution);
|
||||
z = lsb_to_dps(sensor_data.sens_data.gyr.z, 2000, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in dps. */
|
||||
printf("Gyr_DPS_X = %4.2f, Gyr_DPS_Y = %4.2f, Gyr_DPS_Z = %4.2f\n", x, y, z);
|
||||
|
||||
indx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for gyro.
|
||||
*/
|
||||
static int8_t set_gyro_config(struct bmi2_dev *dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define the type of sensor and its configurations. */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config.type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi2_get_sensor_config(&config, 1, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Map data ready interrupt to interrupt pin. */
|
||||
rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT2, dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config.cfg.gyr.odr = BMI2_GYR_ODR_200HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config.cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config.cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config.cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config.cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set the gyro configurations. */
|
||||
rslt = bmi2_set_sensor_config(&config, 1, dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (dps / ((half_scale) + BMI2_GYR_RANGE_2000)) * (val);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= accel.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_wh.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,201 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_wh.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Earth's gravity in m/s^2 */
|
||||
#define GRAVITY_EARTH (9.80665f)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] g_range : Gravity range.
|
||||
* @param[in] bit_width : Resolution for accel.
|
||||
*
|
||||
* @return Gravity.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to define limit to print accel data. */
|
||||
uint8_t limit = 20;
|
||||
|
||||
/* Assign accel sensor to variable. */
|
||||
uint8_t sensor_list = BMI2_ACCEL;
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Create an instance of sensor data structure. */
|
||||
struct bmi2_sensor_data sensor_data = { 0 };
|
||||
|
||||
/* Initialize the interrupt status of accel. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint8_t indx = 0;
|
||||
float x = 0, y = 0, z = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_wh. */
|
||||
rslt = bmi270_wh_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the accel sensor. */
|
||||
rslt = bmi270_wh_sensor_enable(&sensor_list, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Accel configuration settings. */
|
||||
rslt = set_accel_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Assign accel sensor. */
|
||||
sensor_data.type = BMI2_ACCEL;
|
||||
printf("Accel and m/s2 data \n");
|
||||
printf("Accel data collected at 2G Range with 16-bit resolution\n");
|
||||
|
||||
/* Loop to print the accel data when interrupt occurs. */
|
||||
while (indx <= limit)
|
||||
{
|
||||
/* To get the status of accel data ready interrupt. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the accel data ready interrupt status and print the status for 10 samples. */
|
||||
if (int_status & BMI2_ACC_DRDY_INT_MASK)
|
||||
{
|
||||
/* Get accelerometer data for x, y and z axis. */
|
||||
rslt = bmi270_wh_get_sensor_data(&sensor_data, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
printf("\nAcc_X = %d\t", sensor_data.sens_data.acc.x);
|
||||
printf("Acc_Y = %d\t", sensor_data.sens_data.acc.y);
|
||||
printf("Acc_Z = %d\r\n", sensor_data.sens_data.acc.z);
|
||||
|
||||
/* Converting lsb to meter per second squared for 16 bit accelerometer at 2G range. */
|
||||
x = lsb_to_mps2(sensor_data.sens_data.acc.x, 2, bmi2_dev.resolution);
|
||||
y = lsb_to_mps2(sensor_data.sens_data.acc.y, 2, bmi2_dev.resolution);
|
||||
z = lsb_to_mps2(sensor_data.sens_data.acc.z, 2, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in m/s2. */
|
||||
printf("\nAcc_ms2_X = %4.2f, Acc_ms2_Y = %4.2f, Acc_ms2_Z = %4.2f\n", x, y, z);
|
||||
|
||||
indx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*/
|
||||
static int8_t set_accel_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accelerometer configuration. */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config.type = BMI2_ACCEL;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_wh_get_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config.cfg.acc.odr = BMI2_ACC_ODR_200HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config.cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples.
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config.cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config.cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set the accel configurations. */
|
||||
rslt = bmi270_wh_set_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Map data ready interrupt to interrupt pin. */
|
||||
rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (GRAVITY_EARTH * val * g_range) / half_scale;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= accel_gyro.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_wh.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,268 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_wh.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Earth's gravity in m/s^2 */
|
||||
#define GRAVITY_EARTH (9.80665f)
|
||||
|
||||
/*! Macros to select the sensors */
|
||||
#define ACCEL UINT8_C(0x00)
|
||||
#define GYRO UINT8_C(0x01)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel.
|
||||
*
|
||||
* @param[in] dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] g_range : Gravity range.
|
||||
* @param[in] bit_width : Resolution for accel.
|
||||
*
|
||||
* @return Gravity.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width);
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*
|
||||
* @param[in] val : LSB from each axis.
|
||||
* @param[in] dps : Degree per second.
|
||||
* @param[in] bit_width : Resolution for gyro.
|
||||
*
|
||||
* @return Degree per second.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to define limit to print accel data. */
|
||||
uint8_t limit = 10;
|
||||
|
||||
/* Assign accel and gyro sensor to variable. */
|
||||
uint8_t sensor_list[2] = { BMI2_ACCEL, BMI2_GYRO };
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Create an instance of sensor data structure. */
|
||||
struct bmi2_sensor_data sensor_data[2] = { { 0 } };
|
||||
|
||||
/* Initialize the interrupt status of accel and gyro. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
uint8_t indx = 1;
|
||||
|
||||
float x = 0, y = 0, z = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270. */
|
||||
rslt = bmi270_wh_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the accel and gyro sensor. */
|
||||
rslt = bmi270_wh_sensor_enable(sensor_list, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Accel and gyro configuration settings. */
|
||||
rslt = set_accel_gyro_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Assign accel and gyro sensor. */
|
||||
sensor_data[ACCEL].type = BMI2_ACCEL;
|
||||
sensor_data[GYRO].type = BMI2_GYRO;
|
||||
|
||||
/* Loop to print accel and gyro data when interrupt occurs. */
|
||||
while (indx <= limit)
|
||||
{
|
||||
/* To get the data ready interrupt status of accel and gyro. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the data ready interrupt status and print the status for 10 samples. */
|
||||
if ((int_status & BMI2_ACC_DRDY_INT_MASK) && (int_status & BMI2_GYR_DRDY_INT_MASK))
|
||||
{
|
||||
/* Get accel and gyro data for x, y and z axis. */
|
||||
rslt = bmi270_wh_get_sensor_data(sensor_data, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
printf("\n******* Accel(Raw and m/s2) Gyro(Raw and dps) data : %d *******\n", indx);
|
||||
|
||||
printf("\nAcc_x = %d\t", sensor_data[ACCEL].sens_data.acc.x);
|
||||
printf("Acc_y = %d\t", sensor_data[ACCEL].sens_data.acc.y);
|
||||
printf("Acc_z = %d", sensor_data[ACCEL].sens_data.acc.z);
|
||||
|
||||
/* Converting lsb to meter per second squared for 16 bit accelerometer at 2G range. */
|
||||
x = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.x, 2, bmi2_dev.resolution);
|
||||
y = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.y, 2, bmi2_dev.resolution);
|
||||
z = lsb_to_mps2(sensor_data[ACCEL].sens_data.acc.z, 2, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in m/s2. */
|
||||
printf("\nAcc_ms2_X = %4.2f, Acc_ms2_Y = %4.2f, Acc_ms2_Z = %4.2f\n", x, y, z);
|
||||
|
||||
printf("\nGyr_X = %d\t", sensor_data[GYRO].sens_data.gyr.x);
|
||||
printf("Gyr_Y = %d\t", sensor_data[GYRO].sens_data.gyr.y);
|
||||
printf("Gyr_Z= %d\n", sensor_data[GYRO].sens_data.gyr.z);
|
||||
|
||||
/* Converting lsb to degree per second for 16 bit gyro at 2000dps range. */
|
||||
x = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.x, 2000, bmi2_dev.resolution);
|
||||
y = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.y, 2000, bmi2_dev.resolution);
|
||||
z = lsb_to_dps(sensor_data[GYRO].sens_data.gyr.z, 2000, bmi2_dev.resolution);
|
||||
|
||||
/* Print the data in dps. */
|
||||
printf("Gyro_DPS_X = %4.2f, Gyro_DPS_Y = %4.2f, Gyro_DPS_Z = %4.2f\n", x, y, z);
|
||||
|
||||
indx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for accel and gyro.
|
||||
*/
|
||||
static int8_t set_accel_gyro_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define accelerometer and gyro configuration. */
|
||||
struct bmi2_sens_config config[2];
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config[ACCEL].type = BMI2_ACCEL;
|
||||
config[GYRO].type = BMI2_GYRO;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_wh_get_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Map data ready interrupt to interrupt pin. */
|
||||
rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config[ACCEL].cfg.acc.odr = BMI2_ACC_ODR_200HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G). */
|
||||
config[ACCEL].cfg.acc.range = BMI2_ACC_RANGE_2G;
|
||||
|
||||
/* The bandwidth parameter is used to configure the number of sensor samples that are averaged
|
||||
* if it is set to 2, then 2^(bandwidth parameter) samples
|
||||
* are averaged, resulting in 4 averaged samples.
|
||||
* Note1 : For more information, refer the datasheet.
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
config[ACCEL].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
|
||||
|
||||
/* Enable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
* For more info refer datasheet.
|
||||
*/
|
||||
config[ACCEL].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* The user can change the following configuration parameters according to their requirement. */
|
||||
/* Set Output Data Rate */
|
||||
config[GYRO].cfg.gyr.odr = BMI2_GYR_ODR_200HZ;
|
||||
|
||||
/* Gyroscope Angular Rate Measurement Range.By default the range is 2000dps. */
|
||||
config[GYRO].cfg.gyr.range = BMI2_GYR_RANGE_2000;
|
||||
|
||||
/* Gyroscope bandwidth parameters. By default the gyro bandwidth is in normal mode. */
|
||||
config[GYRO].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
|
||||
|
||||
/* Enable/Disable the noise performance mode for precision yaw rate sensing
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode(Default)
|
||||
* 1 -> High performance mode
|
||||
*/
|
||||
config[GYRO].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;
|
||||
|
||||
/* Enable/Disable the filter performance mode where averaging of samples
|
||||
* will be done based on above set bandwidth and ODR.
|
||||
* There are two modes
|
||||
* 0 -> Ultra low power mode
|
||||
* 1 -> High performance mode(Default)
|
||||
*/
|
||||
config[GYRO].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
|
||||
|
||||
/* Set the accel and gyro configurations. */
|
||||
rslt = bmi270_wh_set_sensor_config(config, 2, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to meter per second squared for 16 bit accelerometer at
|
||||
* range 2G, 4G, 8G or 16G.
|
||||
*/
|
||||
static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (GRAVITY_EARTH * val * g_range) / half_scale;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function converts lsb to degree per second for 16 bit gyro at
|
||||
* range 125, 250, 500, 1000 or 2000dps.
|
||||
*/
|
||||
static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width)
|
||||
{
|
||||
float half_scale = ((float)(1 << bit_width) / 2.0f);
|
||||
|
||||
return (dps / ((half_scale) + BMI2_GYR_RANGE_2000)) * (val);
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= any_motion_interrupt.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bmi2.c \
|
||||
$(API_LOCATION)/bmi270_wh.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
/**\
|
||||
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdio.h>
|
||||
#include "bmi270_wh.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for any-motion.
|
||||
*
|
||||
* @param[in] bmi2_dev : Structure instance of bmi2_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t set_feature_config(struct bmi2_dev *bmi2_dev);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Accel sensor and any-motion feature are listed in array. */
|
||||
uint8_t sens_list[2] = { BMI2_ACCEL, BMI2_ANY_MOTION };
|
||||
|
||||
/* Variable to get any-motion interrupt status. */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Sensor initialization configuration. */
|
||||
struct bmi2_dev bmi2_dev;
|
||||
|
||||
/* Select features and their pins to be mapped to. */
|
||||
struct bmi2_sens_int_config sens_int = { .type = BMI2_ANY_MOTION, .hw_int_pin = BMI2_INT1 };
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMI2_I2C_INTF
|
||||
* For SPI : BMI2_SPI_INTF
|
||||
*/
|
||||
rslt = bmi2_interface_init(&bmi2_dev, BMI2_I2C_INTF);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* Initialize bmi270_wh. */
|
||||
rslt = bmi270_wh_init(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Enable the selected sensors. */
|
||||
rslt = bmi270_wh_sensor_enable(sens_list, 2, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Set feature configurations for any-motion. */
|
||||
rslt = set_feature_config(&bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* Map the feature interrupt for any-motion. */
|
||||
rslt = bmi270_wh_map_feat_int(&sens_int, 1, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
printf("Move the board\n");
|
||||
|
||||
/* Loop to get any-motion interrupt. */
|
||||
do
|
||||
{
|
||||
/* Clear buffer. */
|
||||
int_status = 0;
|
||||
|
||||
/* To get the interrupt status of any-motion. */
|
||||
rslt = bmi2_get_int_status(&int_status, &bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
|
||||
/* To check the interrupt status of any-motion. */
|
||||
if (int_status & BMI270_WH_ANY_MOT_STATUS_MASK)
|
||||
{
|
||||
printf("Any-motion interrupt is generated\n");
|
||||
break;
|
||||
}
|
||||
} while (rslt == BMI2_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bmi2_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set configurations for any-motion.
|
||||
*/
|
||||
static int8_t set_feature_config(struct bmi2_dev *bmi2_dev)
|
||||
{
|
||||
/* Status of api are returned to this variable. */
|
||||
int8_t rslt;
|
||||
|
||||
/* Structure to define the type of sensor and its configurations. */
|
||||
struct bmi2_sens_config config;
|
||||
|
||||
/* Configure the type of feature. */
|
||||
config.type = BMI2_ANY_MOTION;
|
||||
|
||||
/* Get default configurations for the type of feature selected. */
|
||||
rslt = bmi270_wh_get_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
if (rslt == BMI2_OK)
|
||||
{
|
||||
/* NOTE: The user can change the following configuration parameters according to their requirement. */
|
||||
/* 1LSB equals 20ms. Default is 100ms, setting to 80ms. */
|
||||
config.cfg.any_motion.duration = 0x04;
|
||||
|
||||
/* 1LSB equals to 0.48mg. Default is 83mg, setting to 50mg. */
|
||||
config.cfg.any_motion.threshold = 0x68;
|
||||
|
||||
/* Set new configurations. */
|
||||
rslt = bmi270_wh_set_sensor_config(&config, 1, bmi2_dev);
|
||||
bmi2_error_codes_print_result(rslt);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user