Add optional BMA456 accelerometer init on shared I2C bus.
Probe and configure the sensor when present; log and continue boot if init fails so boards without BMA456 still run normally. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= accel_foc.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,741 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Header Files */
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
#include "coines.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro Definitions */
|
||||
|
||||
#define ACCEL_SAMPLE_COUNT UINT8_C(100)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Global Variable Declaration */
|
||||
|
||||
/* Structure to store temporary axes data values */
|
||||
struct temp_axes_val
|
||||
{
|
||||
/* X data */
|
||||
int32_t x;
|
||||
|
||||
/* Y data */
|
||||
int32_t y;
|
||||
|
||||
/* Z data */
|
||||
int32_t z;
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used perform accel foc and determine limits based on range
|
||||
*
|
||||
* @param[in] range : Range of Accel
|
||||
* @param[in] input_axis : Axis selected for Accel FOC
|
||||
* @param[in,out] dev : Structure instance of bma4_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t perform_foc_range_test(uint8_t range, uint8_t input_axis, struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This internal API is to determine if average accel FOC data is within limits
|
||||
*
|
||||
* @param[in] avg_accel_foc_data : Average Accel FOC value
|
||||
* @param[in] reference : Reference LSB based on Accel Range
|
||||
* @param[in] foc_sign : Input sign of performed Accel FOC
|
||||
* @param[in] min_val : Minimum acceptable LSB limit
|
||||
* @param[in] max_val : Maximum acceptable LSB limit
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t accel_foc_report(int16_t avg_accel_foc_data,
|
||||
int16_t reference,
|
||||
uint8_t foc_sign,
|
||||
int16_t min_val,
|
||||
int16_t max_val);
|
||||
|
||||
/*!
|
||||
* @brief This internal API is to collect and verify accel sensor data
|
||||
*
|
||||
* @param[in] range : Value of Accel range
|
||||
* @param[in] reference : Reference LSB based on Accel Range
|
||||
* @param[in] matched_axis : Input Axis to perform Accel FOC
|
||||
* @param[in] foc_sign : Input sign to perform Accel FOC
|
||||
* @param[in,out] dev : Structure instance of bma4_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t verify_accel_foc_data(uint8_t range,
|
||||
int16_t reference,
|
||||
int8_t matched_axis,
|
||||
uint8_t foc_sign,
|
||||
struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This internal API is to calculate noise level for Accel FOC data
|
||||
*
|
||||
* @param[in] matched_axis : Input Axis to perform accel FOC
|
||||
* @param[in] accel_foc_data : Array of Accel FOC data
|
||||
* @param[in] avg_accel_foc_data : Average Accel FOC data
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static void calculate_noise(int8_t matched_axis,
|
||||
const struct bma4_accel *accel_foc_data,
|
||||
const struct bma4_accel avg_accel_foc_data);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Sensor initialization configuration. */
|
||||
struct bma4_dev dev;
|
||||
|
||||
uint8_t try = 0, j;
|
||||
int8_t rslt;
|
||||
struct bma4_accel_config accel_conf = { 0 };
|
||||
uint8_t data = 0, range, input_axis = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&dev, BMA4_I2C_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
printf("Functional test for accel foc start..\n\n");
|
||||
|
||||
printf("Choose the axis for accel FOC to be done\n");
|
||||
printf("Press '1' to choose X axis\n");
|
||||
printf("Press '2' to choose Y axis\n");
|
||||
printf("Press '3' to choose Z axis\n");
|
||||
|
||||
printf("Press '4' to choose -X axis\n");
|
||||
printf("Press '5' to choose -Y axis\n");
|
||||
printf("Press '6' to choose -Z axis\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
scanf("%u", (unsigned int *)&input_axis);
|
||||
if (input_axis > 0 && input_axis < 7)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (input_axis == 1)
|
||||
{
|
||||
printf("The choosen input axis for FOC is : X\n");
|
||||
}
|
||||
else if (input_axis == 2)
|
||||
{
|
||||
printf("The choosen input axis for FOC is : Y\n");
|
||||
}
|
||||
else if (input_axis == 3)
|
||||
{
|
||||
printf("The choosen input axis for FOC is : Z\n");
|
||||
}
|
||||
else if (input_axis == 4)
|
||||
{
|
||||
printf("The choosen input axis for FOC is : -X\n");
|
||||
}
|
||||
else if (input_axis == 5)
|
||||
{
|
||||
printf("The choosen input axis for FOC is : -Y\n");
|
||||
}
|
||||
else if (input_axis == 6)
|
||||
{
|
||||
printf("The choosen input axis for FOC is : -Z\n");
|
||||
}
|
||||
|
||||
printf("Confirm your chosen axis and the sensor keeping position are same before doing FOC\n");
|
||||
|
||||
for (j = 0; j < 2; j++)
|
||||
{
|
||||
try = 0;
|
||||
|
||||
if (j == 1)
|
||||
{
|
||||
printf("Keep sensor in wrong position and press 5\n");
|
||||
}
|
||||
else if (j == 0)
|
||||
{
|
||||
printf("Keep sensor in right position and press 5\n");
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
scanf("%hu", (short unsigned int *)&try);
|
||||
if (try == 5)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (range = BMA4_ACCEL_RANGE_2G; range <= BMA4_ACCEL_RANGE_16G; range++)
|
||||
{
|
||||
/****************************************************************/
|
||||
/* Initialize by enabling configuration load */
|
||||
printf("#########################################################\n\n");
|
||||
|
||||
rslt = bma456w_init(&dev);
|
||||
bma4_error_codes_print_result("bma4_init", rslt);
|
||||
|
||||
/* Upload the configuration file to enable the features of the sensor. */
|
||||
rslt = bma456w_write_config_file(&dev);
|
||||
bma4_error_codes_print_result("bma4_write_config", rslt);
|
||||
|
||||
/* Enable the accelerometer */
|
||||
rslt = bma4_set_accel_enable(BMA4_ENABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
/* Accelerometer Configuration Settings */
|
||||
/* Output Data Rate */
|
||||
accel_conf.odr = BMA4_OUTPUT_DATA_RATE_50HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G) */
|
||||
accel_conf.range = range;
|
||||
|
||||
/* 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 less noisier signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
accel_conf.bandwidth = BMA4_ACCEL_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 -> Averaging samples (Default)
|
||||
* 1 -> No averaging
|
||||
* For more info on No Averaging mode refer datasheet.
|
||||
*/
|
||||
accel_conf.perf_mode = BMA4_CIC_AVG_MODE;
|
||||
|
||||
/* Set the accel configurations */
|
||||
rslt = bma4_set_accel_config(&accel_conf, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_accel_config status", rslt);
|
||||
|
||||
/* Delay to set accel sensor configurations (20ms for 50HZ) */
|
||||
dev.delay_us(20000, dev.intf_ptr);
|
||||
|
||||
/* Mapping data ready interrupt with interrupt1 to get interrupt status once getting new accel data */
|
||||
rslt = bma456w_map_interrupt(BMA4_INTR1_MAP, BMA4_DATA_RDY_INT, BMA4_ENABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_map_interrupt status", rslt);
|
||||
|
||||
printf("ODR = %d, RANGE = %d, BANDWIDTH = %d\n", accel_conf.odr, accel_conf.range, accel_conf.bandwidth);
|
||||
|
||||
/* Perform FOC for different ranges */
|
||||
rslt = perform_foc_range_test(range, input_axis, &dev);
|
||||
|
||||
if ((j == 1) && (rslt == BMA4_E_OUT_OF_RANGE))
|
||||
{
|
||||
printf("\n######### Valid input - Wrong position #########\n\n");
|
||||
bma4_error_codes_print_result("perform_foc_range_test", rslt);
|
||||
}
|
||||
else if ((j == 0) && (rslt == BMA4_OK))
|
||||
{
|
||||
printf("\n######### Valid input - Right position #########\n\n");
|
||||
bma4_error_codes_print_result("perform_foc_range_test", rslt);
|
||||
}
|
||||
else if ((j == 1) && (rslt == BMA4_OK))
|
||||
{
|
||||
printf("\n######### Invalid input - Right position #########\n\n");
|
||||
bma4_error_codes_print_result("perform_foc_range_test", rslt);
|
||||
}
|
||||
else if ((j == 0) && (rslt == BMA4_E_OUT_OF_RANGE))
|
||||
{
|
||||
printf("\n######### Invalid input - Wrong position #########\n\n");
|
||||
bma4_error_codes_print_result("perform_foc_range_test", rslt);
|
||||
}
|
||||
else if ((j == 0) && (rslt == BMA4_E_OUT_OF_RANGE))
|
||||
{
|
||||
printf("\n######### Valid input - Right position #########\n\n");
|
||||
printf("\n######### Before FOC is better than after FOC #########\n\n");
|
||||
bma4_error_codes_print_result("perform_foc_range_test", rslt);
|
||||
}
|
||||
else if ((j == 1) && (rslt == BMA4_E_OUT_OF_RANGE))
|
||||
{
|
||||
printf("\n######### Invalid input - Right position #########\n\n");
|
||||
printf("\n######### Before FOC is better than after FOC #########\n\n");
|
||||
bma4_error_codes_print_result("perform_foc_range_test", rslt);
|
||||
}
|
||||
}
|
||||
|
||||
/* Disable offset compensation */
|
||||
rslt = bma4_read_regs(BMA4_NV_CONFIG_ADDR, &data, 1, &dev);
|
||||
bma4_error_codes_print_result("bma4_read_regs", rslt);
|
||||
|
||||
data = BMA4_SET_BIT_VAL_0(data, BMA4_NV_ACCEL_OFFSET);
|
||||
|
||||
rslt = bma4_write_regs(BMA4_NV_CONFIG_ADDR, &data, 1, &dev);
|
||||
bma4_error_codes_print_result("bma4_write_regs", rslt);
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
static int8_t accel_foc_report(int16_t avg_accel_foc_data,
|
||||
int16_t reference,
|
||||
uint8_t foc_sign,
|
||||
int16_t min_val,
|
||||
int16_t max_val)
|
||||
{
|
||||
int8_t rslt = BMA4_OK;
|
||||
int16_t diff_after = 0;
|
||||
|
||||
if (foc_sign == 0)
|
||||
{
|
||||
if ((avg_accel_foc_data >= (min_val)) && (avg_accel_foc_data <= (max_val)))
|
||||
{
|
||||
if (avg_accel_foc_data >= reference)
|
||||
{
|
||||
diff_after = avg_accel_foc_data - reference;
|
||||
}
|
||||
else
|
||||
{
|
||||
diff_after = reference - avg_accel_foc_data;
|
||||
}
|
||||
|
||||
printf("\n# ********** PASS | Difference = %d **********\n", diff_after);
|
||||
printf("\n# Avg_FOC %d in range\n", avg_accel_foc_data);
|
||||
rslt = BMA4_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (avg_accel_foc_data >= reference)
|
||||
{
|
||||
diff_after = avg_accel_foc_data - reference;
|
||||
}
|
||||
else
|
||||
{
|
||||
diff_after = reference - avg_accel_foc_data;
|
||||
}
|
||||
|
||||
printf("\n# ********** FAIL | Difference = %d **********\n", diff_after);
|
||||
printf("\n# Avg_FOC %d not in range\n", avg_accel_foc_data);
|
||||
rslt = BMA4_E_OUT_OF_RANGE;
|
||||
}
|
||||
}
|
||||
|
||||
if (foc_sign == 1)
|
||||
{
|
||||
if ((avg_accel_foc_data <= (min_val)) && (avg_accel_foc_data >= (max_val)))
|
||||
{
|
||||
if (avg_accel_foc_data <= reference)
|
||||
{
|
||||
diff_after = avg_accel_foc_data - reference;
|
||||
}
|
||||
else
|
||||
{
|
||||
diff_after = reference - avg_accel_foc_data;
|
||||
}
|
||||
|
||||
printf("\n# ********** PASS | Difference = %d **********\n", diff_after);
|
||||
printf("\n# Avg_FOC %d in range\n", avg_accel_foc_data);
|
||||
rslt = BMA4_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (avg_accel_foc_data <= reference)
|
||||
{
|
||||
diff_after = avg_accel_foc_data - reference;
|
||||
}
|
||||
else
|
||||
{
|
||||
diff_after = reference - avg_accel_foc_data;
|
||||
}
|
||||
|
||||
printf("\n# ********** FAIL | Difference = %d **********\n", diff_after);
|
||||
printf("\n# Avg_FOC %d not in range\n", avg_accel_foc_data);
|
||||
rslt = BMA4_E_OUT_OF_RANGE;
|
||||
}
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
static void calculate_noise(int8_t matched_axis,
|
||||
const struct bma4_accel *accel_foc_data,
|
||||
const struct bma4_accel avg_accel_foc_data)
|
||||
{
|
||||
int32_t variance = 0;
|
||||
double noise_level;
|
||||
uint16_t idx = 0;
|
||||
|
||||
if (matched_axis == 'X')
|
||||
{
|
||||
for (idx = 0; idx < ACCEL_SAMPLE_COUNT; idx++)
|
||||
{
|
||||
variance +=
|
||||
((accel_foc_data[idx].x - avg_accel_foc_data.x) * (accel_foc_data[idx].x - avg_accel_foc_data.x));
|
||||
}
|
||||
}
|
||||
else if (matched_axis == 'Y')
|
||||
{
|
||||
for (idx = 0; idx < ACCEL_SAMPLE_COUNT; idx++)
|
||||
{
|
||||
variance +=
|
||||
((accel_foc_data[idx].y - avg_accel_foc_data.y) * (accel_foc_data[idx].y - avg_accel_foc_data.y));
|
||||
}
|
||||
}
|
||||
else if (matched_axis == 'Z')
|
||||
{
|
||||
for (idx = 0; idx < ACCEL_SAMPLE_COUNT; idx++)
|
||||
{
|
||||
variance +=
|
||||
((accel_foc_data[idx].z - avg_accel_foc_data.z) * (accel_foc_data[idx].z - avg_accel_foc_data.z));
|
||||
}
|
||||
}
|
||||
|
||||
noise_level = sqrt((double)variance);
|
||||
|
||||
printf("\n# ********** NOISE LEVEL = %lf **********\n", noise_level);
|
||||
}
|
||||
|
||||
static int8_t verify_accel_foc_data(uint8_t range,
|
||||
int16_t reference,
|
||||
int8_t matched_axis,
|
||||
uint8_t foc_sign,
|
||||
struct bma4_dev *dev)
|
||||
{
|
||||
int8_t rslt = BMA4_E_INVALID_STATUS;
|
||||
uint8_t i;
|
||||
uint16_t reg_status = 0;
|
||||
int16_t xl, yl, zl;
|
||||
int16_t xh, yh, zh;
|
||||
int16_t min_val = 0;
|
||||
int16_t max_val = 0;
|
||||
struct bma4_accel accel_foc_data[ACCEL_SAMPLE_COUNT] = { { 0 } };
|
||||
struct temp_axes_val temp_foc_data = { 0 };
|
||||
struct bma4_accel avg_accel_foc_data = { 0 };
|
||||
struct bma4_accel sensor_data = { 0 };
|
||||
|
||||
/* Setting initial values */
|
||||
xl = yl = zl = 32767;
|
||||
xh = yh = zh = -32768;
|
||||
|
||||
/* Read accelerometer values before/after FOC */
|
||||
for (i = 0; i < ACCEL_SAMPLE_COUNT; i++)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
/* To get the data ready interrupt status */
|
||||
rslt = bma4_read_int_status(®_status, dev);
|
||||
bma4_error_codes_print_result("bma4_read_int_status", rslt);
|
||||
|
||||
/* Read accelerometer data based on data ready interrupt */
|
||||
if ((rslt == BMA4_OK) && (reg_status & BMA4_ACCEL_DATA_RDY_INT))
|
||||
{
|
||||
rslt = bma4_read_accel_xyz(&sensor_data, dev);
|
||||
bma4_error_codes_print_result("bma4_read_accel_xyz", rslt);
|
||||
|
||||
memcpy(&accel_foc_data[i], &sensor_data, sizeof(struct bma4_accel));
|
||||
|
||||
printf("X[%d] = %5d Y[%d] = %5d Z[%d] = %5d\n",
|
||||
i,
|
||||
accel_foc_data[i].x,
|
||||
i,
|
||||
accel_foc_data[i].y,
|
||||
i,
|
||||
accel_foc_data[i].z);
|
||||
|
||||
if (xl > accel_foc_data[i].x)
|
||||
{
|
||||
xl = accel_foc_data[i].x;
|
||||
}
|
||||
|
||||
if (xh < accel_foc_data[i].x)
|
||||
{
|
||||
xh = accel_foc_data[i].x;
|
||||
}
|
||||
|
||||
if (yl > accel_foc_data[i].y)
|
||||
{
|
||||
yl = accel_foc_data[i].y;
|
||||
}
|
||||
|
||||
if (yh < accel_foc_data[i].y)
|
||||
{
|
||||
yh = accel_foc_data[i].y;
|
||||
}
|
||||
|
||||
if (zl > accel_foc_data[i].z)
|
||||
{
|
||||
zl = accel_foc_data[i].z;
|
||||
}
|
||||
|
||||
if (zh < accel_foc_data[i].z)
|
||||
{
|
||||
zh = accel_foc_data[i].z;
|
||||
}
|
||||
|
||||
temp_foc_data.x += accel_foc_data[i].x;
|
||||
temp_foc_data.y += accel_foc_data[i].y;
|
||||
temp_foc_data.z += accel_foc_data[i].z;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Taking average values to calculate percentage deviation */
|
||||
avg_accel_foc_data.x = (int16_t)(temp_foc_data.x / ACCEL_SAMPLE_COUNT);
|
||||
avg_accel_foc_data.y = (int16_t)(temp_foc_data.y / ACCEL_SAMPLE_COUNT);
|
||||
avg_accel_foc_data.z = (int16_t)(temp_foc_data.z / ACCEL_SAMPLE_COUNT);
|
||||
|
||||
printf("********* MIN & MAX VALUES ********\n");
|
||||
|
||||
printf("XL = %5d YL = %5d ZL = %5d\n", xl, yl, zl);
|
||||
printf("XH = %5d YH = %5d ZH = %5d\n", xh, yh, zh);
|
||||
|
||||
printf("***** AVERAGE AFTER FOC *****\n");
|
||||
printf("Avg-X = %d Avg-Y = %d Avg-Z = %d\n",
|
||||
avg_accel_foc_data.x,
|
||||
avg_accel_foc_data.y,
|
||||
avg_accel_foc_data.z);
|
||||
|
||||
/* Calculate noise level */
|
||||
calculate_noise(matched_axis, accel_foc_data, avg_accel_foc_data);
|
||||
|
||||
/* "zero-g offset" of accel is +/- 20 mg for all ranges as per datasheet (for 16-bit resolution) */
|
||||
if (range == 0)
|
||||
{
|
||||
/* Min and Max limits for Range 2G */
|
||||
min_val = BMA4_16BIT_ACC_2G_MIN_NOISE_LIMIT;
|
||||
max_val = BMA4_16BIT_ACC_2G_MAX_NOISE_LIMIT;
|
||||
}
|
||||
else if (range == 1)
|
||||
{
|
||||
/* Min and Max limits for Range 4G */
|
||||
min_val = BMA4_16BIT_ACC_4G_MIN_NOISE_LIMIT;
|
||||
max_val = BMA4_16BIT_ACC_4G_MAX_NOISE_LIMIT;
|
||||
}
|
||||
else if (range == 2)
|
||||
{
|
||||
/* Min and Max limits for Range 8G */
|
||||
min_val = BMA4_16BIT_ACC_8G_MIN_NOISE_LIMIT;
|
||||
max_val = BMA4_16BIT_ACC_8G_MAX_NOISE_LIMIT;
|
||||
}
|
||||
else if (range == 3)
|
||||
{
|
||||
/* Min and Max limits for Range 16G */
|
||||
min_val = BMA4_16BIT_ACC_16G_MIN_NOISE_LIMIT;
|
||||
max_val = BMA4_16BIT_ACC_16G_MAX_NOISE_LIMIT;
|
||||
}
|
||||
|
||||
if ((matched_axis == 'X') && (foc_sign == 0))
|
||||
{
|
||||
rslt = accel_foc_report(avg_accel_foc_data.x, reference, foc_sign, min_val, max_val);
|
||||
printf("Range : %u Avg_FOC-X : %d Reference : %d Min_Value : %d Max_Value : %d\n",
|
||||
range,
|
||||
avg_accel_foc_data.x,
|
||||
reference,
|
||||
min_val,
|
||||
max_val);
|
||||
}
|
||||
else if ((matched_axis == 'Y') && (foc_sign == 0))
|
||||
{
|
||||
rslt = accel_foc_report(avg_accel_foc_data.y, reference, foc_sign, min_val, max_val);
|
||||
printf("Range : %u Avg_FOC-X : %d Reference : %d Min_Value : %d Max_Value : %d\n",
|
||||
range,
|
||||
avg_accel_foc_data.y,
|
||||
reference,
|
||||
min_val,
|
||||
max_val);
|
||||
}
|
||||
else if ((matched_axis == 'Z') && (foc_sign == 0))
|
||||
{
|
||||
rslt = accel_foc_report(avg_accel_foc_data.z, reference, foc_sign, min_val, max_val);
|
||||
printf("Range : %u Avg_FOC-X : %d Reference : %d Min_Value : %d Max_Value : %d\n",
|
||||
range,
|
||||
avg_accel_foc_data.z,
|
||||
reference,
|
||||
min_val,
|
||||
max_val);
|
||||
}
|
||||
else if ((matched_axis == 'X') && (foc_sign == 1))
|
||||
{
|
||||
rslt = accel_foc_report(avg_accel_foc_data.x,
|
||||
(int16_t)(reference * (-1)),
|
||||
foc_sign,
|
||||
(int16_t)(min_val * (-1)),
|
||||
(int16_t)(max_val * (-1)));
|
||||
printf("Range : %u Avg_FOC-X : %d Reference : %d Min_Value : %d Max_Value : %d\n",
|
||||
range,
|
||||
avg_accel_foc_data.x,
|
||||
(reference * (-1)),
|
||||
(min_val * (-1)),
|
||||
(max_val * (-1)));
|
||||
}
|
||||
else if ((matched_axis == 'Y') && (foc_sign == 1))
|
||||
{
|
||||
rslt = accel_foc_report(avg_accel_foc_data.y,
|
||||
(int16_t)(reference * (-1)),
|
||||
foc_sign,
|
||||
(int16_t)(min_val * (-1)),
|
||||
(int16_t)(max_val * (-1)));
|
||||
printf("Range : %u Avg_FOC-X : %d Reference : %d Min_Value : %d Max_Value : %d\n",
|
||||
range,
|
||||
avg_accel_foc_data.y,
|
||||
(reference * (-1)),
|
||||
(min_val * (-1)),
|
||||
(max_val * (-1)));
|
||||
}
|
||||
else if ((matched_axis == 'Z') && (foc_sign == 1))
|
||||
{
|
||||
rslt = accel_foc_report(avg_accel_foc_data.z,
|
||||
(int16_t)(reference * (-1)),
|
||||
foc_sign,
|
||||
(int16_t)(min_val * (-1)),
|
||||
(int16_t)(max_val * (-1)));
|
||||
printf("Range : %u Avg_FOC-X : %d Reference : %d Min_Value : %d Max_Value : %d\n",
|
||||
range,
|
||||
avg_accel_foc_data.z,
|
||||
(reference * (-1)),
|
||||
(min_val * (-1)),
|
||||
(max_val * (-1)));
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/* Perform FOC for different range and resolutions */
|
||||
static int8_t perform_foc_range_test(uint8_t range, uint8_t input_axis, struct bma4_dev *dev)
|
||||
{
|
||||
int8_t rslt;
|
||||
int8_t matched_axis = 0;
|
||||
int16_t reference = 0;
|
||||
|
||||
/* Set accel foc axis and it's sign (x, y, z, sign)*/
|
||||
struct bma4_accel_foc_g_value g_value_foc = { 0, 0, 0, 0 };
|
||||
|
||||
if (input_axis == 1)
|
||||
{
|
||||
g_value_foc.x = 1;
|
||||
g_value_foc.y = 0;
|
||||
g_value_foc.z = 0;
|
||||
g_value_foc.sign = 0;
|
||||
}
|
||||
else if (input_axis == 2)
|
||||
{
|
||||
g_value_foc.x = 0;
|
||||
g_value_foc.y = 1;
|
||||
g_value_foc.z = 0;
|
||||
g_value_foc.sign = 0;
|
||||
}
|
||||
else if (input_axis == 3)
|
||||
{
|
||||
g_value_foc.x = 0;
|
||||
g_value_foc.y = 0;
|
||||
g_value_foc.z = 1;
|
||||
g_value_foc.sign = 0;
|
||||
}
|
||||
else if (input_axis == 4)
|
||||
{
|
||||
g_value_foc.x = 1;
|
||||
g_value_foc.y = 0;
|
||||
g_value_foc.z = 0;
|
||||
g_value_foc.sign = 1;
|
||||
}
|
||||
else if (input_axis == 5)
|
||||
{
|
||||
g_value_foc.x = 0;
|
||||
g_value_foc.y = 1;
|
||||
g_value_foc.z = 0;
|
||||
g_value_foc.sign = 1;
|
||||
}
|
||||
else if (input_axis == 6)
|
||||
{
|
||||
g_value_foc.x = 0;
|
||||
g_value_foc.y = 0;
|
||||
g_value_foc.z = 1;
|
||||
g_value_foc.sign = 1;
|
||||
}
|
||||
|
||||
switch (range)
|
||||
{
|
||||
/* Reference LSB value of 2G */
|
||||
case 0:
|
||||
reference = BMA4_16BIT_ACC_FOC_2G_REF;
|
||||
break;
|
||||
|
||||
/* Reference LSB value of 4G */
|
||||
case 1:
|
||||
reference = BMA4_16BIT_ACC_FOC_4G_REF;
|
||||
break;
|
||||
|
||||
/* Reference LSB value of 8G */
|
||||
case 2:
|
||||
reference = BMA4_16BIT_ACC_FOC_8G_REF;
|
||||
break;
|
||||
|
||||
/* Reference LSB value of 16G */
|
||||
case 3:
|
||||
reference = BMA4_16BIT_ACC_FOC_16G_REF;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (g_value_foc.x == 1)
|
||||
{
|
||||
matched_axis = 'X';
|
||||
}
|
||||
else if (g_value_foc.y == 1)
|
||||
{
|
||||
matched_axis = 'Y';
|
||||
}
|
||||
else if (g_value_foc.z == 1)
|
||||
{
|
||||
matched_axis = 'Z';
|
||||
}
|
||||
|
||||
if (g_value_foc.sign == 1)
|
||||
{
|
||||
printf("MATCHED AXIS is = -%c\n", matched_axis);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("MATCHED AXIS is = %c\n", matched_axis);
|
||||
}
|
||||
|
||||
printf("\n\n# Before FOC\n");
|
||||
rslt = verify_accel_foc_data(range, reference, matched_axis, g_value_foc.sign, dev);
|
||||
bma4_error_codes_print_result("bma4_perform_accel_foc", rslt);
|
||||
|
||||
printf("\n\n######### Perform Accel FOC #########\n\n");
|
||||
|
||||
/* Perform accelerometer FOC */
|
||||
rslt = bma4_perform_accel_foc(&g_value_foc, dev);
|
||||
bma4_error_codes_print_result("bma4_perform_accel_foc", rslt);
|
||||
|
||||
/* Delay after performing Accel FOC */
|
||||
dev->delay_us(30000, dev->intf_ptr);
|
||||
|
||||
printf("\n\n# After FOC\n");
|
||||
rslt = verify_accel_foc_data(range, reference, matched_axis, g_value_foc.sign, dev);
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= accelerometer.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,163 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Earth's gravity in m/s^2 */
|
||||
#define GRAVITY_EARTH (9.80665f)
|
||||
|
||||
/*! Macro that holds the total number of accel x,y and z axes sample counts to be printed */
|
||||
#define ACCEL_SAMPLE_COUNT UINT8_C(100)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API converts raw sensor values(LSB) to meters per seconds square.
|
||||
*
|
||||
* @param[in] val : Raw sensor value.
|
||||
* @param[in] g_range : Accel Range selected (2G, 4G, 8G, 16G).
|
||||
* @param[in] bit_width : Resolution of the sensor.
|
||||
*
|
||||
* @return Accel values in meters per second square.
|
||||
*
|
||||
*/
|
||||
static float lsb_to_ms2(int16_t val, float g_range, uint8_t bit_width);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Variable to store the status of API */
|
||||
int8_t rslt;
|
||||
|
||||
/* Sensor initialization configuration */
|
||||
struct bma4_dev bma = { 0 };
|
||||
|
||||
/* Variable to store accel data ready interrupt status */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Variable that holds the accelerometer sample count */
|
||||
uint8_t n_data = 1;
|
||||
|
||||
struct bma4_accel sens_data = { 0 };
|
||||
float x = 0, y = 0, z = 0;
|
||||
struct bma4_accel_config accel_conf = { 0 };
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&bma, BMA4_I2C_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Sensor initialization */
|
||||
rslt = bma456w_init(&bma);
|
||||
bma4_error_codes_print_result("bma456w_init status", rslt);
|
||||
|
||||
/* Upload the configuration file to enable the features of the sensor. */
|
||||
rslt = bma456w_write_config_file(&bma);
|
||||
bma4_error_codes_print_result("bma456w_write_config status", rslt);
|
||||
|
||||
/* Accelerometer configuration settings */
|
||||
/* Output data Rate */
|
||||
accel_conf.odr = BMA4_OUTPUT_DATA_RATE_50HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G) */
|
||||
accel_conf.range = BMA4_ACCEL_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 less noisier signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
accel_conf.bandwidth = BMA4_ACCEL_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 -> Averaging samples (Default)
|
||||
* 1 -> No averaging
|
||||
* For more info on No Averaging mode refer datasheet.
|
||||
*/
|
||||
accel_conf.perf_mode = BMA4_CIC_AVG_MODE;
|
||||
|
||||
/* Set the accel configurations */
|
||||
rslt = bma4_set_accel_config(&accel_conf, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_accel_config status", rslt);
|
||||
|
||||
/* NOTE : Enable accel after set of configurations */
|
||||
rslt = bma4_set_accel_enable(1, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
/* Mapping data ready interrupt with interrupt pin 1 to get interrupt status once getting new accel data */
|
||||
rslt = bma456w_map_interrupt(BMA4_INTR1_MAP, BMA4_DATA_RDY_INT, BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma456w_map_interrupt status", rslt);
|
||||
|
||||
printf("Data, Acc_Raw_X, Acc_Raw_Y, Acc_Raw_Z, Acc_ms2_X, Acc_ms2_Y, Acc_ms2_Z\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Read interrupt status */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status", rslt);
|
||||
|
||||
/* Filtering only the accel data ready interrupt */
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_ACCEL_DATA_RDY_INT))
|
||||
{
|
||||
/* Read the accel x, y, z data */
|
||||
rslt = bma4_read_accel_xyz(&sens_data, &bma);
|
||||
bma4_error_codes_print_result("bma4_read_accel_xyz status", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
|
||||
/* Converting lsb to meter per second squared for 16 bit resolution at 2G range */
|
||||
x = lsb_to_ms2(sens_data.x, (float)2, bma.resolution);
|
||||
y = lsb_to_ms2(sens_data.y, (float)2, bma.resolution);
|
||||
z = lsb_to_ms2(sens_data.z, (float)2, bma.resolution);
|
||||
|
||||
/* Print the data in m/s2 */
|
||||
printf("%d, %d, %d, %d, %4.2f, %4.2f, %4.2f\n", n_data, sens_data.x, sens_data.y, sens_data.z, x, y, z);
|
||||
}
|
||||
|
||||
/* Increment the count that determines the number of samples to be printed */
|
||||
n_data++;
|
||||
|
||||
/* When the count reaches more than ACCEL_SAMPLE_COUNT, break and exit the loop */
|
||||
if (n_data > ACCEL_SAMPLE_COUNT)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API converts raw sensor values(LSB) to meters per seconds square.
|
||||
*/
|
||||
static float lsb_to_ms2(int16_t val, float g_range, uint8_t bit_width)
|
||||
{
|
||||
double power = 2;
|
||||
|
||||
float half_scale = (float)((pow((double)power, (double)bit_width) / 2.0f));
|
||||
|
||||
return (GRAVITY_EARTH * val * g_range) / half_scale;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= accelerometer_hw_int.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
TARGET = MCU_APP30
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,297 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
#include "coines.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Global variable Declaration */
|
||||
|
||||
volatile uint8_t drdy_int_status = 0;
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Earth's gravity in m/s^2 */
|
||||
#define GRAVITY_EARTH (9.80665f)
|
||||
|
||||
/*! Macro that holds the total number of accel x,y and z axes sample counts to be printed */
|
||||
#define ACCEL_SAMPLE_COUNT UINT8_C(100)
|
||||
|
||||
/*! APP20 Board number */
|
||||
#define BOARD_MCU_APP20 UINT8_C(0x03)
|
||||
|
||||
/*! APP30 Board number */
|
||||
#define BOARD_MCU_APP30 UINT8_C(0x05)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API converts raw sensor values(LSB) to meters per seconds square.
|
||||
*
|
||||
* @param[in] val : Raw sensor value.
|
||||
* @param[in] g_range : Accel Range selected (2G, 4G, 8G, 16G).
|
||||
* @param[in] bit_width : Resolution of the sensor.
|
||||
*
|
||||
* @return Accel values in meters per second square.
|
||||
*
|
||||
*/
|
||||
static float lsb_to_ms2(int16_t val, float g_range, uint8_t bit_width);
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*
|
||||
* @param[out] board : Board value to determine as APP2.0 or APP3.0
|
||||
*/
|
||||
static void get_board_info(uint8_t *board);
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set the interrupt status
|
||||
*/
|
||||
static void interrupt_callback(uint32_t param1, uint32_t param2)
|
||||
{
|
||||
(void)param1;
|
||||
(void)param2;
|
||||
drdy_int_status = 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Variable to store the status of API */
|
||||
int8_t rslt;
|
||||
|
||||
/* Sensor initialization configuration */
|
||||
struct bma4_dev bma = { 0 };
|
||||
|
||||
/* Variable to store accel data ready interrupt status */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Variable that holds the accelerometer sample count */
|
||||
uint8_t n_data = 1;
|
||||
|
||||
struct bma4_accel sens_data = { 0 };
|
||||
float x = 0, y = 0, z = 0;
|
||||
struct bma4_accel_config accel_conf = { 0 };
|
||||
|
||||
struct bma4_int_pin_config pin_config = { 0 };
|
||||
|
||||
/* Variable for interrupt line selection */
|
||||
uint8_t int_line;
|
||||
|
||||
uint8_t intf;
|
||||
uint8_t board = 0;
|
||||
|
||||
/* intf: Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
|
||||
intf = BMA4_I2C_INTF;
|
||||
rslt = bma4_interface_init(&bma, intf, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Sensor initialization */
|
||||
rslt = bma456w_init(&bma);
|
||||
bma4_error_codes_print_result("bma456w_init status", rslt);
|
||||
|
||||
/* Accelerometer configuration settings */
|
||||
/* Output data Rate */
|
||||
accel_conf.odr = BMA4_OUTPUT_DATA_RATE_50HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G) */
|
||||
accel_conf.range = BMA4_ACCEL_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 less noisier signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
accel_conf.bandwidth = BMA4_ACCEL_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 -> Averaging samples (Default)
|
||||
* 1 -> No averaging
|
||||
* For more info on No Averaging mode refer datasheet.
|
||||
*/
|
||||
accel_conf.perf_mode = BMA4_CIC_AVG_MODE;
|
||||
|
||||
/* Set the accel configurations */
|
||||
rslt = bma4_set_accel_config(&accel_conf, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_accel_config status", rslt);
|
||||
|
||||
/* Hardware interrupt configuration */
|
||||
int_line = BMA4_INTR1_MAP;
|
||||
|
||||
rslt = bma456w_map_interrupt(int_line, BMA4_DATA_RDY_INT, BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma456w_map_interrupt status", rslt);
|
||||
|
||||
/* Get board information */
|
||||
get_board_info(&board);
|
||||
|
||||
/*
|
||||
* Attach interrupt based on board
|
||||
*/
|
||||
if (board == BOARD_MCU_APP20)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_20, interrupt_callback, COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_21, interrupt_callback, COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(MCU_APP20)
|
||||
else if (board == BOARD_MCU_APP30)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_6,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_7,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Latch mode to be set for I2C to read Drdy interrupt with 100kHz Speed */
|
||||
switch (intf)
|
||||
{
|
||||
case BMA4_I2C_INTF:
|
||||
rslt = bma4_set_interrupt_mode(BMA4_LATCH_MODE, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_interrupt_mode status", rslt);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
rslt = bma4_get_int_pin_config(&pin_config, int_line, &bma);
|
||||
bma4_error_codes_print_result("bma4_get_int_pin_config status", rslt);
|
||||
|
||||
pin_config.edge_ctrl = BMA4_EDGE_TRIGGER;
|
||||
pin_config.output_en = BMA4_OUTPUT_ENABLE;
|
||||
pin_config.lvl = BMA4_ACTIVE_HIGH;
|
||||
pin_config.od = BMA4_PUSH_PULL;
|
||||
pin_config.input_en = BMA4_INPUT_DISABLE;
|
||||
|
||||
rslt = bma4_set_int_pin_config(&pin_config, int_line, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_int_pin_config status", rslt);
|
||||
|
||||
/* NOTE : Enable accel after set of configurations */
|
||||
rslt = bma4_set_accel_enable(1, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
printf("Data, Acc_Raw_X, Acc_Raw_Y, Acc_Raw_Z, Acc_ms2_X, Acc_ms2_Y, Acc_ms2_Z\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (drdy_int_status == 1)
|
||||
{
|
||||
drdy_int_status = 0;
|
||||
|
||||
/* Read interrupt status */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status", rslt);
|
||||
|
||||
/* Filtering only the accel data ready interrupt */
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_ACCEL_DATA_RDY_INT))
|
||||
{
|
||||
/* Read the accel x, y, z data */
|
||||
rslt = bma4_read_accel_xyz(&sens_data, &bma);
|
||||
bma4_error_codes_print_result("bma4_read_accel_xyz status", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
|
||||
/* Converting lsb to meter per second squared for 16 bit resolution at 2G range */
|
||||
x = lsb_to_ms2(sens_data.x, (float)2, bma.resolution);
|
||||
y = lsb_to_ms2(sens_data.y, (float)2, bma.resolution);
|
||||
z = lsb_to_ms2(sens_data.z, (float)2, bma.resolution);
|
||||
|
||||
/* Print the data in m/s2 */
|
||||
printf("%d, %d, %d, %d, %4.2f, %4.2f, %4.2f\n",
|
||||
n_data,
|
||||
sens_data.x,
|
||||
sens_data.y,
|
||||
sens_data.z,
|
||||
x,
|
||||
y,
|
||||
z);
|
||||
}
|
||||
|
||||
/* Increment the count that determines the number of samples to be printed */
|
||||
n_data++;
|
||||
|
||||
/* When the count reaches more than ACCEL_SAMPLE_COUNT, break and exit the loop */
|
||||
if (n_data > ACCEL_SAMPLE_COUNT)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API converts raw sensor values(LSB) to meters per seconds square.
|
||||
*/
|
||||
static float lsb_to_ms2(int16_t val, float g_range, uint8_t bit_width)
|
||||
{
|
||||
double power = 2;
|
||||
|
||||
float half_scale = (float)((pow((double)power, (double)bit_width) / 2.0f));
|
||||
|
||||
return (GRAVITY_EARTH * val * g_range) / half_scale;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*/
|
||||
static void get_board_info(uint8_t *board)
|
||||
{
|
||||
struct coines_board_info board_info;
|
||||
int16_t result;
|
||||
|
||||
result = coines_get_board_info(&board_info);
|
||||
|
||||
if (result == COINES_SUCCESS)
|
||||
{
|
||||
(*board) = board_info.board;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE = axis_remap.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,362 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "coines.h"
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
|
||||
/*********************************************************************/
|
||||
/* functions */
|
||||
/*********************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief Main Function where the execution getting started to test the code.
|
||||
*
|
||||
* @param[in] argc
|
||||
* @param[in] argv
|
||||
*
|
||||
* @return status
|
||||
*
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
int8_t rslt;
|
||||
struct bma4_dev bma4;
|
||||
struct bma4_remap remap_data = { 0 };
|
||||
struct bma4_accel accel = { 0 };
|
||||
struct bma4_accel_config accel_conf = { 0 };
|
||||
uint16_t int_status = 0;
|
||||
|
||||
char data_array[13][11] =
|
||||
{ { 0 }, { "BMA4_X" }, { "BMA4_Y" }, { 0 }, { "BMA4_Z" }, { 0 }, { 0 }, { 0 }, { 0 }, { "BMA4_NEG_X" },
|
||||
{ "BMA4_NEG_Y" }, { 0 }, { "BMA4_NEG_Z" } };
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&bma4, BMA4_I2C_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Sensor initialization */
|
||||
rslt = bma456w_init(&bma4);
|
||||
bma4_error_codes_print_result("bma456w_init", rslt);
|
||||
|
||||
/* Upload the configuration file to enable the features of the sensor. */
|
||||
rslt = bma456w_write_config_file(&bma4);
|
||||
bma4_error_codes_print_result("bma456w_write_config_file", rslt);
|
||||
|
||||
/* Accelerometer configuration Setting */
|
||||
/* Output data Rate */
|
||||
accel_conf.odr = BMA4_OUTPUT_DATA_RATE_50HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G) */
|
||||
accel_conf.range = BMA4_ACCEL_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 less noisier signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
accel_conf.bandwidth = BMA4_ACCEL_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 -> Averaging samples (Default)
|
||||
* 1 -> No averaging
|
||||
* For more info on No Averaging mode refer datasheet.
|
||||
*/
|
||||
accel_conf.perf_mode = BMA4_CIC_AVG_MODE;
|
||||
|
||||
/* Set the accel configurations */
|
||||
rslt = bma4_set_accel_config(&accel_conf, &bma4);
|
||||
bma4_error_codes_print_result("bma4_set_accel_config status", rslt);
|
||||
|
||||
/* NOTE : Enable accel after set of configurations */
|
||||
rslt = bma4_set_accel_enable(1, &bma4);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
/* Mapping data ready interrupt with interrupt pin 1 to get interrupt status once getting new accel data */
|
||||
rslt = bma456w_map_interrupt(BMA4_INTR1_MAP, BMA4_DATA_RDY_INT, BMA4_ENABLE, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_map_interrupt status", rslt);
|
||||
|
||||
printf("\nAXIS_REMAP_FUNC_TEST 1\n");
|
||||
printf("Get sensor data of re-mapped axes\n");
|
||||
|
||||
rslt = bma456w_get_remap_axes(&remap_data, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_get_remap_axes", rslt);
|
||||
|
||||
printf("Re-mapped x value = %s\n", data_array[remap_data.x]);
|
||||
printf("Re-mapped y value = %s\n", data_array[remap_data.y]);
|
||||
printf("Re-mapped z value = %s\n", data_array[remap_data.z]);
|
||||
|
||||
printf("Expected Re-mapped x value = BMA4_X\n");
|
||||
printf("Expected Re-mapped y value = BMA4_Y\n");
|
||||
printf("Expected Re-mapped z value = BMA4_Z\n");
|
||||
|
||||
if ((remap_data.x == BMA4_X) && (remap_data.y == BMA4_Y) && (remap_data.z == BMA4_Z))
|
||||
{
|
||||
printf(">> PASS\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(">> FAIL\n");
|
||||
}
|
||||
|
||||
printf("Print mapped data\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Read interrupt status */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status", rslt);
|
||||
|
||||
/* Filtering only the accel data ready interrupt */
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_ACCEL_DATA_RDY_INT))
|
||||
{
|
||||
rslt = bma4_read_accel_xyz(&accel, &bma4);
|
||||
bma4_error_codes_print_result("bma4_read_accel_xyz", rslt);
|
||||
|
||||
printf("Accel :: X = %d Y = %d Z = %d\n", accel.x, accel.y, accel.z);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\nAXIS_REMAP_FUNC_TEST 2\n");
|
||||
printf("Get sensor data of re-mapped axes\n");
|
||||
|
||||
remap_data.x = BMA4_NEG_Y;
|
||||
remap_data.y = BMA4_Z;
|
||||
remap_data.z = BMA4_NEG_X;
|
||||
|
||||
rslt = bma456w_set_remap_axes(&remap_data, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_set_remap_axes", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
rslt = bma456w_get_remap_axes(&remap_data, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_get_remap_axes", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("Re-mapped x value = %s\n", data_array[remap_data.x]);
|
||||
printf("Re-mapped y value = %s\n", data_array[remap_data.y]);
|
||||
printf("Re-mapped z value = %s\n", data_array[remap_data.z]);
|
||||
}
|
||||
|
||||
printf("Expected Re-mapped x value = BMA4_NEG_Y\n");
|
||||
printf("Expected Re-mapped y value = BMA4_Z\n");
|
||||
printf("Expected Re-mapped z value = BMA4_NEG_X\n");
|
||||
|
||||
if ((remap_data.x == BMA4_NEG_Y) && (remap_data.y == BMA4_Z) && (remap_data.z == BMA4_NEG_X))
|
||||
{
|
||||
printf(">> PASS\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(">> FAIL\n");
|
||||
}
|
||||
}
|
||||
|
||||
printf("Print mapped data\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Read interrupt status */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status", rslt);
|
||||
|
||||
/* Filtering only the accel data ready interrupt */
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_ACCEL_DATA_RDY_INT))
|
||||
{
|
||||
rslt = bma4_read_accel_xyz(&accel, &bma4);
|
||||
bma4_error_codes_print_result("bma4_read_accel_xyz", rslt);
|
||||
|
||||
printf("Accel :: X = %d Y = %d Z = %d\n", accel.x, accel.y, accel.z);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\nAXIS_REMAP_FUNC_TEST 3\n");
|
||||
printf("Get sensor data of re-mapped axes - 2nd combination\n");
|
||||
|
||||
remap_data.x = BMA4_NEG_Z;
|
||||
remap_data.y = BMA4_NEG_X;
|
||||
remap_data.z = BMA4_Y;
|
||||
|
||||
rslt = bma456w_set_remap_axes(&remap_data, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_set_remap_axes", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
rslt = bma456w_get_remap_axes(&remap_data, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_get_remap_axes", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("Re-mapped x value = %s\n", data_array[remap_data.x]);
|
||||
printf("Re-mapped y value = %s\n", data_array[remap_data.y]);
|
||||
printf("Re-mapped z value = %s\n", data_array[remap_data.z]);
|
||||
}
|
||||
|
||||
printf("Expected Re-mapped x value = BMA4_NEG_Z\n");
|
||||
printf("Expected Re-mapped y value = BMA4_NEG_X\n");
|
||||
printf("Expected Re-mapped z value = BMA4_Y\n");
|
||||
|
||||
if ((remap_data.x == BMA4_NEG_Z) && (remap_data.y == BMA4_NEG_X) && (remap_data.z == BMA4_Y))
|
||||
{
|
||||
printf(">> PASS\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(">> FAIL\n");
|
||||
}
|
||||
}
|
||||
|
||||
printf("Print mapped data\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Read interrupt status */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status", rslt);
|
||||
|
||||
/* Filtering only the accel data ready interrupt */
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_ACCEL_DATA_RDY_INT))
|
||||
{
|
||||
rslt = bma4_read_accel_xyz(&accel, &bma4);
|
||||
bma4_error_codes_print_result("bma4_read_accel_xyz", rslt);
|
||||
|
||||
printf("Accel :: X = %d Y = %d Z = %d\n", accel.x, accel.y, accel.z);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\nAXIS_REMAP_FUNC_TEST 4\n");
|
||||
printf("Get sensor data of re-mapped axes - 3rd combination\n");
|
||||
|
||||
remap_data.x = BMA4_Y;
|
||||
remap_data.y = BMA4_Z;
|
||||
remap_data.z = BMA4_X;
|
||||
|
||||
rslt = bma456w_set_remap_axes(&remap_data, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_set_remap_axes", rslt);
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
rslt = bma456w_get_remap_axes(&remap_data, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_get_remap_axes", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("Re-mapped x value = %s\n", data_array[remap_data.x]);
|
||||
printf("Re-mapped y value = %s\n", data_array[remap_data.y]);
|
||||
printf("Re-mapped z value = %s\n", data_array[remap_data.z]);
|
||||
}
|
||||
|
||||
printf("Expected Re-mapped x value = BMA4_Y\n");
|
||||
printf("Expected Re-mapped y value = BMA4_Z\n");
|
||||
printf("Expected Re-mapped z value = BMA4_X\n");
|
||||
|
||||
if ((remap_data.x == BMA4_Y) && (remap_data.y == BMA4_Z) && (remap_data.z == BMA4_X))
|
||||
{
|
||||
printf(">> PASS\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(">> FAIL\n");
|
||||
}
|
||||
}
|
||||
|
||||
printf("Print mapped data\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Read interrupt status */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status", rslt);
|
||||
|
||||
/* Filtering only the accel data ready interrupt */
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_ACCEL_DATA_RDY_INT))
|
||||
{
|
||||
rslt = bma4_read_accel_xyz(&accel, &bma4);
|
||||
bma4_error_codes_print_result("bma4_read_accel_xyz", rslt);
|
||||
|
||||
printf("Accel :: X = %d Y = %d Z = %d\n", accel.x, accel.y, accel.z);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\nAXIS_REMAP_FUNC_TEST 5\n");
|
||||
printf("Get sensor data of re-mapped axes - 4th combination\n");
|
||||
|
||||
remap_data.x = BMA4_NEG_X;
|
||||
remap_data.y = BMA4_NEG_Y;
|
||||
remap_data.z = BMA4_NEG_Z;
|
||||
|
||||
rslt = bma456w_set_remap_axes(&remap_data, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_set_remap_axes", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
rslt = bma456w_get_remap_axes(&remap_data, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_get_remap_axes", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("Re-mapped x value = %s\n", data_array[remap_data.x]);
|
||||
printf("Re-mapped y value = %s\n", data_array[remap_data.y]);
|
||||
printf("Re-mapped z value = %s\n", data_array[remap_data.z]);
|
||||
}
|
||||
|
||||
printf("Expected Re-mapped x value = BMA4_NEG_X\n");
|
||||
printf("Expected Re-mapped y value = BMA4_NEG_Y\n");
|
||||
printf("Expected Re-mapped z value = BMA4_NEG_Z\n");
|
||||
|
||||
if ((remap_data.x == BMA4_NEG_X) && (remap_data.y == BMA4_NEG_Y) && (remap_data.z == BMA4_NEG_Z))
|
||||
{
|
||||
printf(">> PASS\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(">> FAIL\n");
|
||||
}
|
||||
}
|
||||
|
||||
printf("Print mapped data\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Read interrupt status */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status", rslt);
|
||||
|
||||
/* Filtering only the accel data ready interrupt */
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_ACCEL_DATA_RDY_INT))
|
||||
{
|
||||
rslt = bma4_read_accel_xyz(&accel, &bma4);
|
||||
bma4_error_codes_print_result("bma4_read_accel_xyz", rslt);
|
||||
|
||||
printf("Accel :: X = %d Y = %d Z = %d\n", accel.x, accel.y, accel.z);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE = axis_remap_hw_int.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
TARGET = MCU_APP30
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,507 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "coines.h"
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Global variable Declaration */
|
||||
|
||||
volatile uint8_t drdy_int_status = 0;
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! APP20 Board number */
|
||||
#define BOARD_MCU_APP20 UINT8_C(0x03)
|
||||
|
||||
/*! APP30 Board number */
|
||||
#define BOARD_MCU_APP30 UINT8_C(0x05)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*
|
||||
* @param[out] board : Board value to determine as APP2.0 or APP3.0
|
||||
*/
|
||||
static void get_board_info(uint8_t *board);
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set the interrupt status
|
||||
*/
|
||||
static void interrupt_callback(uint32_t param1, uint32_t param2)
|
||||
{
|
||||
(void)param1;
|
||||
(void)param2;
|
||||
drdy_int_status = 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
int8_t rslt;
|
||||
struct bma4_dev bma4;
|
||||
struct bma4_remap remap_data = { 0 };
|
||||
struct bma4_accel accel = { 0 };
|
||||
struct bma4_accel_config accel_conf = { 0 };
|
||||
uint16_t int_status = 0;
|
||||
struct bma4_int_pin_config pin_config = { 0 };
|
||||
|
||||
/* Variable for interrupt line selection*/
|
||||
uint8_t int_line;
|
||||
|
||||
uint8_t intf;
|
||||
uint8_t board = 0;
|
||||
|
||||
char data_array[13][11] =
|
||||
{ { 0 }, { "BMA4_X" }, { "BMA4_Y" }, { 0 }, { "BMA4_Z" }, { 0 }, { 0 }, { 0 }, { 0 }, { "BMA4_NEG_X" },
|
||||
{ "BMA4_NEG_Y" }, { 0 }, { "BMA4_NEG_Z" } };
|
||||
|
||||
/* intf: Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
|
||||
intf = BMA4_I2C_INTF;
|
||||
rslt = bma4_interface_init(&bma4, intf, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Sensor initialization */
|
||||
rslt = bma456w_init(&bma4);
|
||||
bma4_error_codes_print_result("bma456w_init", rslt);
|
||||
|
||||
/* Upload the configuration file to enable the features of the sensor. */
|
||||
rslt = bma456w_write_config_file(&bma4);
|
||||
bma4_error_codes_print_result("bma456w_write_config_file", rslt);
|
||||
|
||||
/* Accelerometer configuration Setting */
|
||||
/* Output data Rate */
|
||||
accel_conf.odr = BMA4_OUTPUT_DATA_RATE_50HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G) */
|
||||
accel_conf.range = BMA4_ACCEL_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 less noisier signal, but
|
||||
* this has an adverse effect on the power consumed.
|
||||
*/
|
||||
accel_conf.bandwidth = BMA4_ACCEL_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 -> Averaging samples (Default)
|
||||
* 1 -> No averaging
|
||||
* For more info on No Averaging mode refer datasheet.
|
||||
*/
|
||||
accel_conf.perf_mode = BMA4_CIC_AVG_MODE;
|
||||
|
||||
/* Set the accel configurations */
|
||||
rslt = bma4_set_accel_config(&accel_conf, &bma4);
|
||||
bma4_error_codes_print_result("bma4_set_accel_config status", rslt);
|
||||
|
||||
/* Hardware interrupt configuration */
|
||||
int_line = BMA4_INTR2_MAP;
|
||||
|
||||
rslt = bma456w_map_interrupt(int_line, BMA4_DATA_RDY_INT, BMA4_ENABLE, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_map_interrupt status", rslt);
|
||||
|
||||
/* Get board information */
|
||||
get_board_info(&board);
|
||||
|
||||
/*
|
||||
* Attach interrupt based on board
|
||||
*/
|
||||
if (board == BOARD_MCU_APP20)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_20, interrupt_callback, COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_21, interrupt_callback, COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(MCU_APP20)
|
||||
else if (board == BOARD_MCU_APP30)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_6,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_7,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Latch mode to be set for I2C to read Drdy interrupt with 100kHz Speed */
|
||||
switch (intf)
|
||||
{
|
||||
case BMA4_I2C_INTF:
|
||||
rslt = bma4_set_interrupt_mode(BMA4_LATCH_MODE, &bma4);
|
||||
bma4_error_codes_print_result("bma4_set_interrupt_mode status", rslt);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
rslt = bma4_get_int_pin_config(&pin_config, int_line, &bma4);
|
||||
bma4_error_codes_print_result("bma4_get_int_pin_config status", rslt);
|
||||
|
||||
pin_config.edge_ctrl = BMA4_EDGE_TRIGGER;
|
||||
pin_config.output_en = BMA4_OUTPUT_ENABLE;
|
||||
pin_config.lvl = BMA4_ACTIVE_HIGH;
|
||||
pin_config.od = BMA4_PUSH_PULL;
|
||||
pin_config.input_en = BMA4_INPUT_DISABLE;
|
||||
|
||||
rslt = bma4_set_int_pin_config(&pin_config, int_line, &bma4);
|
||||
bma4_error_codes_print_result("bma4_set_int_pin_config status", rslt);
|
||||
|
||||
/* NOTE : Enable accel after set of configurations */
|
||||
rslt = bma4_set_accel_enable(1, &bma4);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
printf("\nAXIS_REMAP_FUNC_TEST 1\n");
|
||||
printf("Get sensor data of re-mapped axes\n");
|
||||
|
||||
rslt = bma456w_get_remap_axes(&remap_data, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_get_remap_axes", rslt);
|
||||
|
||||
printf("Re-mapped x value = %s\n", data_array[remap_data.x]);
|
||||
printf("Re-mapped y value = %s\n", data_array[remap_data.y]);
|
||||
printf("Re-mapped z value = %s\n", data_array[remap_data.z]);
|
||||
|
||||
printf("Expected Re-mapped x value = BMA4_X\n");
|
||||
printf("Expected Re-mapped y value = BMA4_Y\n");
|
||||
printf("Expected Re-mapped z value = BMA4_Z\n");
|
||||
|
||||
if ((remap_data.x == BMA4_X) && (remap_data.y == BMA4_Y) && (remap_data.z == BMA4_Z))
|
||||
{
|
||||
printf(">> PASS\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(">> FAIL\n");
|
||||
}
|
||||
|
||||
printf("Print mapped data\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (drdy_int_status == 1)
|
||||
{
|
||||
drdy_int_status = 0;
|
||||
|
||||
/* Read interrupt status */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status", rslt);
|
||||
|
||||
/* Filtering only the accel data ready interrupt */
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_ACCEL_DATA_RDY_INT))
|
||||
{
|
||||
rslt = bma4_read_accel_xyz(&accel, &bma4);
|
||||
bma4_error_codes_print_result("bma4_read_accel_xyz", rslt);
|
||||
|
||||
printf("Accel :: X = %d Y = %d Z = %d\n", accel.x, accel.y, accel.z);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("\nAXIS_REMAP_FUNC_TEST 2\n");
|
||||
printf("Get sensor data of re-mapped axes\n");
|
||||
|
||||
remap_data.x = BMA4_NEG_Y;
|
||||
remap_data.y = BMA4_Z;
|
||||
remap_data.z = BMA4_NEG_X;
|
||||
|
||||
rslt = bma456w_set_remap_axes(&remap_data, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_set_remap_axes", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
rslt = bma456w_get_remap_axes(&remap_data, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_get_remap_axes", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("Re-mapped x value = %s\n", data_array[remap_data.x]);
|
||||
printf("Re-mapped y value = %s\n", data_array[remap_data.y]);
|
||||
printf("Re-mapped z value = %s\n", data_array[remap_data.z]);
|
||||
}
|
||||
|
||||
printf("Expected Re-mapped x value = BMA4_NEG_Y\n");
|
||||
printf("Expected Re-mapped y value = BMA4_Z\n");
|
||||
printf("Expected Re-mapped z value = BMA4_NEG_X\n");
|
||||
|
||||
if ((remap_data.x == BMA4_NEG_Y) && (remap_data.y == BMA4_Z) && (remap_data.z == BMA4_NEG_X))
|
||||
{
|
||||
printf(">> PASS\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(">> FAIL\n");
|
||||
}
|
||||
}
|
||||
|
||||
printf("Print mapped data\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (drdy_int_status == 1)
|
||||
{
|
||||
drdy_int_status = 0;
|
||||
|
||||
/* Read interrupt status */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status", rslt);
|
||||
|
||||
/* Filtering only the accel data ready interrupt */
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_ACCEL_DATA_RDY_INT))
|
||||
{
|
||||
rslt = bma4_read_accel_xyz(&accel, &bma4);
|
||||
bma4_error_codes_print_result("bma4_read_accel_xyz", rslt);
|
||||
|
||||
printf("Accel :: X = %d Y = %d Z = %d\n", accel.x, accel.y, accel.z);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("\nAXIS_REMAP_FUNC_TEST 3\n");
|
||||
printf("Get sensor data of re-mapped axes - 2nd combination\n");
|
||||
|
||||
remap_data.x = BMA4_NEG_Z;
|
||||
remap_data.y = BMA4_NEG_X;
|
||||
remap_data.z = BMA4_Y;
|
||||
|
||||
rslt = bma456w_set_remap_axes(&remap_data, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_set_remap_axes", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
rslt = bma456w_get_remap_axes(&remap_data, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_get_remap_axes", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("Re-mapped x value = %s\n", data_array[remap_data.x]);
|
||||
printf("Re-mapped y value = %s\n", data_array[remap_data.y]);
|
||||
printf("Re-mapped z value = %s\n", data_array[remap_data.z]);
|
||||
}
|
||||
|
||||
printf("Expected Re-mapped x value = BMA4_NEG_Z\n");
|
||||
printf("Expected Re-mapped y value = BMA4_NEG_X\n");
|
||||
printf("Expected Re-mapped z value = BMA4_Y\n");
|
||||
|
||||
if ((remap_data.x == BMA4_NEG_Z) && (remap_data.y == BMA4_NEG_X) && (remap_data.z == BMA4_Y))
|
||||
{
|
||||
printf(">> PASS\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(">> FAIL\n");
|
||||
}
|
||||
}
|
||||
|
||||
printf("Print mapped data\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (drdy_int_status == 1)
|
||||
{
|
||||
drdy_int_status = 0;
|
||||
|
||||
/* Read interrupt status */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status", rslt);
|
||||
|
||||
/* Filtering only the accel data ready interrupt */
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_ACCEL_DATA_RDY_INT))
|
||||
{
|
||||
rslt = bma4_read_accel_xyz(&accel, &bma4);
|
||||
bma4_error_codes_print_result("bma4_read_accel_xyz", rslt);
|
||||
|
||||
printf("Accel :: X = %d Y = %d Z = %d\n", accel.x, accel.y, accel.z);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("\nAXIS_REMAP_FUNC_TEST 4\n");
|
||||
printf("Get sensor data of re-mapped axes - 3rd combination\n");
|
||||
|
||||
remap_data.x = BMA4_Y;
|
||||
remap_data.y = BMA4_Z;
|
||||
remap_data.z = BMA4_X;
|
||||
|
||||
rslt = bma456w_set_remap_axes(&remap_data, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_set_remap_axes", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
rslt = bma456w_get_remap_axes(&remap_data, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_get_remap_axes", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("Re-mapped x value = %s\n", data_array[remap_data.x]);
|
||||
printf("Re-mapped y value = %s\n", data_array[remap_data.y]);
|
||||
printf("Re-mapped z value = %s\n", data_array[remap_data.z]);
|
||||
}
|
||||
|
||||
printf("Expected Re-mapped x value = BMA4_Y\n");
|
||||
printf("Expected Re-mapped y value = BMA4_Z\n");
|
||||
printf("Expected Re-mapped z value = BMA4_X\n");
|
||||
|
||||
if ((remap_data.x == BMA4_Y) && (remap_data.y == BMA4_Z) && (remap_data.z == BMA4_X))
|
||||
{
|
||||
printf(">> PASS\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(">> FAIL\n");
|
||||
}
|
||||
}
|
||||
|
||||
printf("Print mapped data\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (drdy_int_status == 1)
|
||||
{
|
||||
drdy_int_status = 0;
|
||||
|
||||
/* Read interrupt status */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status", rslt);
|
||||
|
||||
/* Filtering only the accel data ready interrupt */
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_ACCEL_DATA_RDY_INT))
|
||||
{
|
||||
rslt = bma4_read_accel_xyz(&accel, &bma4);
|
||||
bma4_error_codes_print_result("bma4_read_accel_xyz", rslt);
|
||||
|
||||
printf("Accel :: X = %d Y = %d Z = %d\n", accel.x, accel.y, accel.z);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("\nAXIS_REMAP_FUNC_TEST 5\n");
|
||||
printf("Get sensor data of re-mapped axes - 4th combination\n");
|
||||
|
||||
remap_data.x = BMA4_NEG_X;
|
||||
remap_data.y = BMA4_NEG_Y;
|
||||
remap_data.z = BMA4_NEG_Z;
|
||||
|
||||
rslt = bma456w_set_remap_axes(&remap_data, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_set_remap_axes", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
rslt = bma456w_get_remap_axes(&remap_data, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_get_remap_axes", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("Re-mapped x value = %s\n", data_array[remap_data.x]);
|
||||
printf("Re-mapped y value = %s\n", data_array[remap_data.y]);
|
||||
printf("Re-mapped z value = %s\n", data_array[remap_data.z]);
|
||||
}
|
||||
|
||||
printf("Expected Re-mapped x value = BMA4_NEG_X\n");
|
||||
printf("Expected Re-mapped y value = BMA4_NEG_Y\n");
|
||||
printf("Expected Re-mapped z value = BMA4_NEG_Z\n");
|
||||
|
||||
if ((remap_data.x == BMA4_NEG_X) && (remap_data.y == BMA4_NEG_Y) && (remap_data.z == BMA4_NEG_Z))
|
||||
{
|
||||
printf(">> PASS\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(">> FAIL\n");
|
||||
}
|
||||
}
|
||||
|
||||
printf("Print mapped data\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (drdy_int_status == 1)
|
||||
{
|
||||
drdy_int_status = 0;
|
||||
|
||||
/* Read interrupt status */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma4);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status", rslt);
|
||||
|
||||
/* Filtering only the accel data ready interrupt */
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_ACCEL_DATA_RDY_INT))
|
||||
{
|
||||
rslt = bma4_read_accel_xyz(&accel, &bma4);
|
||||
bma4_error_codes_print_result("bma4_read_accel_xyz", rslt);
|
||||
|
||||
printf("Accel :: X = %d Y = %d Z = %d\n", accel.x, accel.y, accel.z);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*/
|
||||
static void get_board_info(uint8_t *board)
|
||||
{
|
||||
struct coines_board_info board_info;
|
||||
int16_t result;
|
||||
|
||||
result = coines_get_board_info(&board_info);
|
||||
|
||||
if (result == COINES_SUCCESS)
|
||||
{
|
||||
(*board) = board_info.board;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
/**
|
||||
* Copyright (C) 2023 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "bma4_defs.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definitions */
|
||||
|
||||
/*! Read write length varies based on user requirement */
|
||||
#define BMA4_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
|
||||
*/
|
||||
BMA4_INTF_RET_TYPE bma4_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_address = *(uint8_t*)intf_ptr;
|
||||
|
||||
(void)intf_ptr;
|
||||
|
||||
return coines_read_i2c(COINES_I2C_BUS_0, dev_address, reg_addr, reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* I2C write function map to COINES platform
|
||||
*/
|
||||
BMA4_INTF_RET_TYPE bma4_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_address = *(uint8_t*)intf_ptr;
|
||||
|
||||
(void)intf_ptr;
|
||||
|
||||
return coines_write_i2c(COINES_I2C_BUS_0, dev_address, reg_addr, (uint8_t *)reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* SPI read function map to COINES platform
|
||||
*/
|
||||
BMA4_INTF_RET_TYPE bma4_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_address = *(uint8_t*)intf_ptr;
|
||||
|
||||
(void)intf_ptr;
|
||||
|
||||
return coines_read_spi(COINES_SPI_BUS_0, dev_address, reg_addr, reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* SPI write function map to COINES platform
|
||||
*/
|
||||
BMA4_INTF_RET_TYPE bma4_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
|
||||
{
|
||||
uint8_t dev_address = *(uint8_t*)intf_ptr;
|
||||
|
||||
(void)intf_ptr;
|
||||
|
||||
return coines_write_spi(COINES_SPI_BUS_0, dev_address, reg_addr, (uint8_t *)reg_data, (uint16_t)len);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Delay function map to COINES platform
|
||||
*/
|
||||
void bma4_delay_us(uint32_t period, void *intf_ptr)
|
||||
{
|
||||
(void) intf_ptr;
|
||||
coines_delay_usec(period);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Function to select the interface between SPI and I2C.
|
||||
* Also to initialize coines platform
|
||||
*/
|
||||
int8_t bma4_interface_init(struct bma4_dev *bma, uint8_t intf, enum bma4_variant variant)
|
||||
{
|
||||
int8_t rslt = BMA4_OK;
|
||||
|
||||
if (bma != NULL)
|
||||
{
|
||||
int16_t result = coines_open_comm_intf(COINES_COMM_INTF_USB, NULL);
|
||||
struct coines_board_info board_info;
|
||||
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
|
||||
|
||||
(void)coines_set_shuttleboard_vdd_vddio_config(0, 0);
|
||||
coines_delay_usec(10000);
|
||||
|
||||
/* Bus configuration : I2C */
|
||||
if (intf == BMA4_I2C_INTF)
|
||||
{
|
||||
printf("I2C Interface \n");
|
||||
|
||||
/* To initialize the user I2C function */
|
||||
dev_addr = BMA4_I2C_ADDR_PRIMARY;
|
||||
bma->intf = BMA4_I2C_INTF;
|
||||
bma->bus_read = bma4_i2c_read;
|
||||
bma->bus_write = bma4_i2c_write;
|
||||
|
||||
/* SDO to Ground */
|
||||
(void)coines_set_pin_config(COINES_SHUTTLE_PIN_22, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_LOW);
|
||||
|
||||
/* Make CSB pin HIGH */
|
||||
(void)coines_set_pin_config(COINES_SHUTTLE_PIN_21, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_HIGH);
|
||||
coines_delay_msec(100);
|
||||
|
||||
/* SDO pin is made low */
|
||||
(void)coines_set_pin_config(COINES_SHUTTLE_PIN_SDO, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_LOW);
|
||||
|
||||
(void)coines_config_i2c_bus(COINES_I2C_BUS_0, COINES_I2C_STANDARD_MODE);
|
||||
}
|
||||
/* Bus configuration : SPI */
|
||||
else if (intf == BMA4_SPI_INTF)
|
||||
{
|
||||
printf("SPI Interface \n");
|
||||
|
||||
/* To initialize the user SPI function */
|
||||
dev_addr = COINES_SHUTTLE_PIN_7;
|
||||
bma->intf = BMA4_SPI_INTF;
|
||||
bma->bus_read = bma4_spi_read;
|
||||
bma->bus_write = bma4_spi_write;
|
||||
(void)coines_config_spi_bus(COINES_SPI_BUS_0, COINES_SPI_SPEED_7_5_MHZ, COINES_SPI_MODE0);
|
||||
}
|
||||
|
||||
/* Assign variant information */
|
||||
bma->variant = variant;
|
||||
|
||||
/* Assign device address to interface pointer */
|
||||
bma->intf_ptr = &dev_addr;
|
||||
|
||||
/* Configure delay in microseconds */
|
||||
bma->delay_us = bma4_delay_us;
|
||||
|
||||
/* Configure max read/write length (in bytes) ( Supported length depends on target machine) */
|
||||
bma->read_write_len = BMA4_READ_WRITE_LEN;
|
||||
|
||||
/* Set Performance mode status */
|
||||
bma->perf_mode_status = BMA4_DISABLE;
|
||||
|
||||
coines_delay_msec(100);
|
||||
|
||||
(void)coines_set_shuttleboard_vdd_vddio_config(3300, 3300);
|
||||
|
||||
coines_delay_msec(200);
|
||||
}
|
||||
else
|
||||
{
|
||||
rslt = BMA4_E_NULL_PTR;
|
||||
}
|
||||
|
||||
return rslt;
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Prints the execution status of the APIs.
|
||||
*/
|
||||
void bma4_error_codes_print_result(const char api_name[], int8_t rslt)
|
||||
{
|
||||
if (rslt != BMA4_OK)
|
||||
{
|
||||
printf("%s\t", api_name);
|
||||
if (rslt == BMA4_E_NULL_PTR)
|
||||
{
|
||||
printf("Error [%d] : Null pointer\r\n", rslt);
|
||||
}
|
||||
else if (rslt == BMA4_E_COM_FAIL)
|
||||
{
|
||||
printf("Error [%d] : Communication failure\r\n", rslt);
|
||||
}
|
||||
else if (rslt == BMA4_E_CONFIG_STREAM_ERROR)
|
||||
{
|
||||
printf("Error [%d] : Invalid configuration stream\r\n", rslt);
|
||||
}
|
||||
else if (rslt == BMA4_E_SELF_TEST_FAIL)
|
||||
{
|
||||
printf("Error [%d] : Self test failed\r\n", rslt);
|
||||
}
|
||||
else if (rslt == BMA4_E_INVALID_SENSOR)
|
||||
{
|
||||
printf("Error [%d] : Device not found\r\n", rslt);
|
||||
}
|
||||
else if (rslt == BMA4_E_OUT_OF_RANGE)
|
||||
{
|
||||
printf("Error [%d] : Out of Range\r\n", rslt);
|
||||
}
|
||||
else if (rslt == BMA4_E_AVG_MODE_INVALID_CONF)
|
||||
{
|
||||
printf("Error [%d] : Invalid bandwidth and ODR combination in Accel Averaging mode\r\n", rslt);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* For more error codes refer "*_defs.h" */
|
||||
printf("Error [%d] : Unknown error code\r\n", rslt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Deinitializes coines platform
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
void bma4_coines_deinit(void)
|
||||
{
|
||||
(void)fflush(stdout);
|
||||
coines_delay_msec(200);
|
||||
|
||||
(void)coines_set_shuttleboard_vdd_vddio_config(0, 0);
|
||||
coines_delay_msec(1000);
|
||||
|
||||
/* Coines interface reset */
|
||||
coines_soft_reset();
|
||||
coines_delay_msec(1000);
|
||||
(void)coines_close_comm_intf(COINES_COMM_INTF_USB, NULL);
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/**\
|
||||
* Copyright (c) 2023 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 "bma4.h"
|
||||
#include "coines.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 = BMA4_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMA4_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMA4_INTF_RET_TYPE bma4_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 = BMA4_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMA4_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMA4_INTF_RET_TYPE bma4_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 = BMA4_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMA4_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMA4_INTF_RET_TYPE bma4_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 = BMA4_INTF_RET_SUCCESS -> Success
|
||||
* @retval != BMA4_INTF_RET_SUCCESS -> Failure Info
|
||||
*
|
||||
*/
|
||||
BMA4_INTF_RET_TYPE bma4_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 bma4_delay_us(uint32_t period, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Function to select the interface between SPI and I2C.
|
||||
*
|
||||
* @param[in] bma : Structure instance of bma4_dev
|
||||
* @param[in] intf : Interface selection parameter
|
||||
* @param[in] variant : Variant information of the sensor
|
||||
* ( BMA42x variants values - BMA42X_VARIANT / BMA42X_B_VARIANT )
|
||||
* ( BMA45x variants values - BMA45X_VARIANT )
|
||||
*
|
||||
* @return Status of execution
|
||||
* @retval 0 -> Success
|
||||
* @retval < 0 -> Failure Info
|
||||
*/
|
||||
int8_t bma4_interface_init(struct bma4_dev *bma, uint8_t intf, enum bma4_variant variant);
|
||||
|
||||
/*!
|
||||
* @brief Prints the execution status of the APIs.
|
||||
*
|
||||
* @param[in] api_name : Name of the API whose execution status has to be printed.
|
||||
* @param[in] rslt : Error code returned by the API whose execution status has to be printed.
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
void bma4_error_codes_print_result(const char api_name[], int8_t rslt);
|
||||
|
||||
/*!
|
||||
* @brief Deinitializes coines platform
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
void bma4_coines_deinit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* End of CPP guard */
|
||||
|
||||
#endif /* COMMON_H */
|
||||
@@ -0,0 +1,20 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_full_header_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
TARGET=MCU_APP30
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,173 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMA456W_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(1024)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMA456W_FIFO_RAW_DATA_USER_LENGTH UINT16_C(1024)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO
|
||||
* Calculation:
|
||||
* fifo_buffer = 1024, accel_frame_len = 6, header_byte = 1.
|
||||
* fifo_accel_frame_count = (1024 / (6 + 1)) = 147 frames
|
||||
*
|
||||
* Extra frames to parse sensortime data
|
||||
*/
|
||||
#define BMA456W_FIFO_ACCEL_FRAME_COUNT UINT8_C(170)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Function */
|
||||
|
||||
/* This function starts the execution of program */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of API are returned to this variable */
|
||||
int8_t rslt;
|
||||
|
||||
/* Accelerometer configuration structure */
|
||||
struct bma4_accel_config acc_conf = { 0 };
|
||||
|
||||
/* Sensor initialization configuration */
|
||||
struct bma4_dev dev = { 0 };
|
||||
|
||||
/* Number of accelerometer frames */
|
||||
uint16_t accel_length;
|
||||
|
||||
/* Variable to idx bytes */
|
||||
uint16_t idx = 0;
|
||||
|
||||
/* Variable to maintain count of loop to run FIFO read */
|
||||
uint8_t loop = 1;
|
||||
|
||||
/* Number of bytes of FIFO data
|
||||
* NOTE : Dummy byte (for SPI Interface) required for FIFO data read must be given as part of array size
|
||||
*/
|
||||
uint8_t fifo_data[BMA456W_FIFO_RAW_DATA_BUFFER_SIZE + BMA4_SENSORTIME_OVERHEAD_BYTE] = { 0 };
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 147 * (6 axes bytes(+/- x,y,z) + 1 header byte) = 1029 bytes */
|
||||
struct bma4_accel fifo_accel_data[BMA456W_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure */
|
||||
struct bma4_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Variable that contains interrupt status value */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Variable to hold the length of FIFO data */
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&dev, BMA4_I2C_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Initialize BMA456W */
|
||||
rslt = bma456w_init(&dev);
|
||||
bma4_error_codes_print_result("bma456w_init status", rslt);
|
||||
|
||||
/* Accelerometer configuration settings */
|
||||
acc_conf.odr = BMA4_OUTPUT_DATA_RATE_100HZ;
|
||||
acc_conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4;
|
||||
acc_conf.range = BMA4_ACCEL_RANGE_2G;
|
||||
acc_conf.perf_mode = BMA4_CIC_AVG_MODE;
|
||||
|
||||
/* Set the accel configurations */
|
||||
rslt = bma4_set_accel_config(&acc_conf, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_accel_config status", rslt);
|
||||
|
||||
/* NOTE : Enable accel after set of configurations */
|
||||
rslt = bma4_set_accel_enable(1, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
/* Disabling advance power save mode as FIFO data is not accessible in advance low power mode */
|
||||
rslt = bma4_set_advance_power_save(BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_advance_power_save status", rslt);
|
||||
|
||||
/* Clear FIFO configuration register */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_ALL, BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config disable status", rslt);
|
||||
|
||||
/* Set FIFO configuration by enabling accel.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode. */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_ACCEL | BMA4_FIFO_HEADER | BMA4_FIFO_TIME, BMA4_ENABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config enable status", rslt);
|
||||
|
||||
/* Update FIFO structure */
|
||||
fifoframe.data = fifo_data;
|
||||
fifoframe.length = BMA456W_FIFO_RAW_DATA_USER_LENGTH + BMA4_SENSORTIME_OVERHEAD_BYTE;
|
||||
|
||||
printf("FIFO is configured in header mode\n");
|
||||
|
||||
rslt = bma456w_map_interrupt(BMA4_INTR1_MAP, BMA4_FIFO_FULL_INT, BMA4_ENABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_map_interrupt status", rslt);
|
||||
|
||||
while (loop <= 10)
|
||||
{
|
||||
rslt = bma456w_read_int_status(&int_status, &dev);
|
||||
bma4_error_codes_print_result("bma4_read_int_status", rslt);
|
||||
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_FIFO_FULL_INT))
|
||||
{
|
||||
printf("\nIteration : %d\n", loop);
|
||||
|
||||
rslt = bma4_get_fifo_length(&fifo_length, &dev);
|
||||
bma4_error_codes_print_result("bma4_get_fifo_length status", rslt);
|
||||
|
||||
printf("FIFO data bytes available : %d\n", fifo_length);
|
||||
printf("FIFO data bytes requested : %d\n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data */
|
||||
rslt = bma4_read_fifo_data(&fifoframe, &dev);
|
||||
bma4_error_codes_print_result("bma4_read_fifo_data status", rslt);
|
||||
|
||||
accel_length = BMA456W_FIFO_ACCEL_FRAME_COUNT;
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("Requested data frames before parsing: %d\n", accel_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer */
|
||||
rslt = bma4_extract_accel(fifo_accel_data, &accel_length, &fifoframe, &dev);
|
||||
printf("Parsed accelerometer data frames: %d\n", accel_length);
|
||||
|
||||
printf("ACCEL, X, Y, Z\n");
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer */
|
||||
for (idx = 0; idx < accel_length; idx++)
|
||||
{
|
||||
printf("%d, %d, %d, %d\n",
|
||||
idx,
|
||||
fifo_accel_data[idx].x,
|
||||
fifo_accel_data[idx].y,
|
||||
fifo_accel_data[idx].z);
|
||||
}
|
||||
|
||||
/* Print control frames like sensor time and skipped frame count */
|
||||
printf("Skipped frame count = %d\n", fifoframe.skipped_frame_count);
|
||||
printf("Sensor time(in seconds) = %.4lf s\r\n", (fifoframe.sensor_time * BMA4_SENSORTIME_RESOLUTION));
|
||||
}
|
||||
|
||||
loop++;
|
||||
}
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_full_header_mode_hw_int.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
TARGET = MCU_APP30
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+290
@@ -0,0 +1,290 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
#include "coines.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Global variable Declaration */
|
||||
|
||||
volatile uint8_t interrupt_status = 0;
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMA456W_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(1024)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMA456W_FIFO_RAW_DATA_USER_LENGTH UINT16_C(1024)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO
|
||||
* Calculation:
|
||||
* fifo_buffer = 1024, accel_frame_len = 6, header_byte = 1.
|
||||
* fifo_accel_frame_count = (1024 / (6 + 1)) = 147 frames
|
||||
*
|
||||
* Extra frames to parse sensortime data
|
||||
*/
|
||||
#define BMA456W_FIFO_ACCEL_FRAME_COUNT UINT8_C(170)
|
||||
|
||||
/*! APP20 Board number */
|
||||
#define BOARD_MCU_APP20 UINT8_C(0x03)
|
||||
|
||||
/*! APP30 Board number */
|
||||
#define BOARD_MCU_APP30 UINT8_C(0x05)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*
|
||||
* @param[out] board : Board value to determine as APP2.0 or APP3.0
|
||||
*/
|
||||
static void get_board_info(uint8_t *board);
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set the interrupt status
|
||||
*/
|
||||
static void interrupt_callback(uint32_t param1, uint32_t param2)
|
||||
{
|
||||
(void)param1;
|
||||
(void)param2;
|
||||
interrupt_status = 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Function */
|
||||
|
||||
/* This function starts the execution of program */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of API are returned to this variable */
|
||||
int8_t rslt;
|
||||
|
||||
/* Accelerometer configuration structure */
|
||||
struct bma4_accel_config acc_conf = { 0 };
|
||||
|
||||
/* Sensor initialization configuration */
|
||||
struct bma4_dev dev = { 0 };
|
||||
|
||||
/* Number of accelerometer frames */
|
||||
uint16_t accel_length;
|
||||
|
||||
/* Variable to idx bytes */
|
||||
uint16_t idx = 0;
|
||||
|
||||
/* Variable to maintain count of loop to run FIFO read */
|
||||
uint8_t loop = 1;
|
||||
|
||||
/* Number of bytes of FIFO data
|
||||
* NOTE : Dummy byte (for SPI Interface) required for FIFO data read must be given as part of array size
|
||||
*/
|
||||
uint8_t fifo_data[BMA456W_FIFO_RAW_DATA_BUFFER_SIZE + BMA4_SENSORTIME_OVERHEAD_BYTE] = { 0 };
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 147 * (6 axes bytes(+/- x,y,z) + 1 header byte) = 1029 bytes */
|
||||
struct bma4_accel fifo_accel_data[BMA456W_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure */
|
||||
struct bma4_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Variable that contains interrupt status value */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Variable to hold the length of FIFO data */
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
struct bma4_int_pin_config pin_config = { 0 };
|
||||
uint8_t board = 0;
|
||||
|
||||
/* Variable for interrupt line selection*/
|
||||
uint8_t int_line;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&dev, BMA4_I2C_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Initialize BMA456W */
|
||||
rslt = bma456w_init(&dev);
|
||||
bma4_error_codes_print_result("bma456w_init status", rslt);
|
||||
|
||||
/* Accelerometer configuration settings */
|
||||
acc_conf.odr = BMA4_OUTPUT_DATA_RATE_100HZ;
|
||||
acc_conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4;
|
||||
acc_conf.range = BMA4_ACCEL_RANGE_2G;
|
||||
acc_conf.perf_mode = BMA4_CIC_AVG_MODE;
|
||||
|
||||
/* Set the accel configurations */
|
||||
rslt = bma4_set_accel_config(&acc_conf, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_accel_config status", rslt);
|
||||
|
||||
/* NOTE : Enable accel after set of configurations */
|
||||
rslt = bma4_set_accel_enable(1, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
/* Disabling advance power save mode as FIFO data is not accessible in advance low power mode */
|
||||
rslt = bma4_set_advance_power_save(BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_advance_power_save status", rslt);
|
||||
|
||||
/* Clear FIFO configuration register */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_ALL, BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config disable status", rslt);
|
||||
|
||||
/* Set FIFO configuration by enabling accel.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode. */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_ACCEL | BMA4_FIFO_HEADER | BMA4_FIFO_TIME, BMA4_ENABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config enable status", rslt);
|
||||
|
||||
/* Update FIFO structure */
|
||||
fifoframe.data = fifo_data;
|
||||
fifoframe.length = BMA456W_FIFO_RAW_DATA_USER_LENGTH + BMA4_SENSORTIME_OVERHEAD_BYTE;
|
||||
|
||||
printf("FIFO is configured in header mode\n");
|
||||
|
||||
/* Hardware interrupt configuration */
|
||||
int_line = BMA4_INTR1_MAP;
|
||||
|
||||
rslt = bma456w_map_interrupt(int_line, BMA4_FIFO_FULL_INT, BMA4_ENABLE, &dev);
|
||||
bma4_error_codes_print_result("bma456w_map_interrupt status", rslt);
|
||||
|
||||
pin_config.edge_ctrl = BMA4_EDGE_TRIGGER;
|
||||
pin_config.output_en = BMA4_OUTPUT_ENABLE;
|
||||
pin_config.lvl = BMA4_ACTIVE_HIGH;
|
||||
pin_config.od = BMA4_PUSH_PULL;
|
||||
pin_config.input_en = BMA4_INPUT_DISABLE;
|
||||
|
||||
rslt = bma4_set_int_pin_config(&pin_config, int_line, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_int_pin_config status", rslt);
|
||||
|
||||
/* Get board information */
|
||||
get_board_info(&board);
|
||||
|
||||
/*
|
||||
* Attach interrupt based on board
|
||||
*/
|
||||
if (board == BOARD_MCU_APP20)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_20, interrupt_callback, COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_21, interrupt_callback, COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(MCU_APP20)
|
||||
else if (board == BOARD_MCU_APP30)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_6,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_7,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
while (loop <= 10)
|
||||
{
|
||||
if (interrupt_status == 1)
|
||||
{
|
||||
interrupt_status = 0;
|
||||
|
||||
rslt = bma456w_read_int_status(&int_status, &dev);
|
||||
bma4_error_codes_print_result("bma4_read_int_status", rslt);
|
||||
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_FIFO_FULL_INT))
|
||||
{
|
||||
printf("\nIteration : %d\n", loop);
|
||||
|
||||
rslt = bma4_get_fifo_length(&fifo_length, &dev);
|
||||
bma4_error_codes_print_result("bma4_get_fifo_length status", rslt);
|
||||
|
||||
printf("FIFO data bytes available : %d\n", fifo_length);
|
||||
printf("FIFO data bytes requested : %d\n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data */
|
||||
rslt = bma4_read_fifo_data(&fifoframe, &dev);
|
||||
bma4_error_codes_print_result("bma4_read_fifo_data status", rslt);
|
||||
|
||||
accel_length = BMA456W_FIFO_ACCEL_FRAME_COUNT;
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("Requested data frames before parsing: %d\n", accel_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer */
|
||||
rslt = bma4_extract_accel(fifo_accel_data, &accel_length, &fifoframe, &dev);
|
||||
printf("Parsed accelerometer data frames: %d\n", accel_length);
|
||||
|
||||
printf("ACCEL, X, Y, Z\n");
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer */
|
||||
for (idx = 0; idx < accel_length; idx++)
|
||||
{
|
||||
printf("%d, %d, %d, %d\n", idx, fifo_accel_data[idx].x, fifo_accel_data[idx].y,
|
||||
fifo_accel_data[idx].z);
|
||||
}
|
||||
|
||||
/* Print control frames like sensor time and skipped frame count */
|
||||
printf("Skipped frame count = %d\n", fifoframe.skipped_frame_count);
|
||||
printf("Sensor time(in seconds) = %.4lf s\r\n",
|
||||
(fifoframe.sensor_time * BMA4_SENSORTIME_RESOLUTION));
|
||||
}
|
||||
|
||||
loop++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*/
|
||||
static void get_board_info(uint8_t *board)
|
||||
{
|
||||
struct coines_board_info board_info;
|
||||
int16_t result;
|
||||
|
||||
result = coines_get_board_info(&board_info);
|
||||
|
||||
if (result == COINES_SUCCESS)
|
||||
{
|
||||
(*board) = board_info.board;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_full_headerless_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+171
@@ -0,0 +1,171 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMA456W_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(1024)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMA456W_FIFO_RAW_DATA_USER_LENGTH UINT16_C(1024)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO
|
||||
* Calculation:
|
||||
* fifo_buffer = 1024, accel_frame_len = 6.
|
||||
* fifo_accel_frame_count = (1024 / 6) = 170 frames
|
||||
*/
|
||||
#define BMA456W_FIFO_ACCEL_FRAME_COUNT UINT8_C(170)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Function */
|
||||
|
||||
/* This function starts the execution of program */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of API are returned to this variable */
|
||||
int8_t rslt;
|
||||
|
||||
/* Accelerometer configuration structure */
|
||||
struct bma4_accel_config acc_conf = { 0 };
|
||||
|
||||
/* Sensor initialization configuration */
|
||||
struct bma4_dev dev = { 0 };
|
||||
|
||||
/* Number of accelerometer frames */
|
||||
uint16_t accel_length;
|
||||
|
||||
/* Variable to idx bytes */
|
||||
uint16_t idx = 0;
|
||||
|
||||
/* Variable to maintain count of loop to run FIFO read */
|
||||
uint8_t loop = 1;
|
||||
|
||||
/* Number of bytes of FIFO data
|
||||
* NOTE : Dummy byte (for SPI Interface) required for FIFO data read must be given as part of array size
|
||||
*/
|
||||
uint8_t fifo_data[BMA456W_FIFO_RAW_DATA_BUFFER_SIZE] = { 0 };
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 170 * (6 axes bytes(+/- x,y,z)) = 1020 bytes */
|
||||
struct bma4_accel fifo_accel_data[BMA456W_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure */
|
||||
struct bma4_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Variable that contains interrupt status value */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Variable to hold the length of FIFO data */
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&dev, BMA4_I2C_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Initialize BMA456W */
|
||||
rslt = bma456w_init(&dev);
|
||||
bma4_error_codes_print_result("bma456w_init status", rslt);
|
||||
|
||||
/* Accelerometer configuration settings */
|
||||
acc_conf.odr = BMA4_OUTPUT_DATA_RATE_100HZ;
|
||||
acc_conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4;
|
||||
acc_conf.range = BMA4_ACCEL_RANGE_2G;
|
||||
acc_conf.perf_mode = BMA4_CIC_AVG_MODE;
|
||||
|
||||
/* Set the accel configurations */
|
||||
rslt = bma4_set_accel_config(&acc_conf, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_accel_config status", rslt);
|
||||
|
||||
/* NOTE : Enable accel after set of configurations */
|
||||
rslt = bma4_set_accel_enable(1, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
/* Disabling advance power save mode as FIFO data is not accessible in advance low power mode */
|
||||
rslt = bma4_set_advance_power_save(BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_advance_power_save status", rslt);
|
||||
|
||||
/* Clear FIFO configuration register */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_ALL, BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config disable status", rslt);
|
||||
|
||||
/* Set FIFO configuration by enabling accel.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode. */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_ACCEL, BMA4_ENABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config enable status", rslt);
|
||||
|
||||
/* Update FIFO structure */
|
||||
fifoframe.data = fifo_data;
|
||||
fifoframe.length = BMA456W_FIFO_RAW_DATA_USER_LENGTH;
|
||||
|
||||
/* To enable headerless mode, disable the header. */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_HEADER, BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config status", rslt);
|
||||
|
||||
printf("FIFO is configured in headerless mode\n");
|
||||
|
||||
rslt = bma456w_map_interrupt(BMA4_INTR1_MAP, BMA4_FIFO_FULL_INT, BMA4_ENABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_map_interrupt status", rslt);
|
||||
|
||||
while (loop <= 10)
|
||||
{
|
||||
rslt = bma456w_read_int_status(&int_status, &dev);
|
||||
bma4_error_codes_print_result("bma4_read_int_status", rslt);
|
||||
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_FIFO_FULL_INT))
|
||||
{
|
||||
printf("\nIteration : %d\n", loop);
|
||||
|
||||
rslt = bma4_get_fifo_length(&fifo_length, &dev);
|
||||
bma4_error_codes_print_result("bma4_get_fifo_length status", rslt);
|
||||
|
||||
printf("FIFO data bytes available : %d\n", fifo_length);
|
||||
printf("FIFO data bytes requested : %d\n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data */
|
||||
rslt = bma4_read_fifo_data(&fifoframe, &dev);
|
||||
bma4_error_codes_print_result("bma4_read_fifo_data status", rslt);
|
||||
|
||||
accel_length = BMA456W_FIFO_ACCEL_FRAME_COUNT;
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("Requested data frames before parsing: %d\n", accel_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer */
|
||||
rslt = bma4_extract_accel(fifo_accel_data, &accel_length, &fifoframe, &dev);
|
||||
printf("Parsed accelerometer data frames: %d\n", accel_length);
|
||||
|
||||
printf("ACCEL, X, Y, Z\n");
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer */
|
||||
for (idx = 0; idx < accel_length; idx++)
|
||||
{
|
||||
printf("%d, %d, %d, %d\n",
|
||||
idx,
|
||||
fifo_accel_data[idx].x,
|
||||
fifo_accel_data[idx].y,
|
||||
fifo_accel_data[idx].z);
|
||||
}
|
||||
}
|
||||
|
||||
loop++;
|
||||
}
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_full_headerless_mode_hw_int.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
TARGET = MCU_APP30
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+286
@@ -0,0 +1,286 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
#include "coines.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Global variable Declaration */
|
||||
|
||||
volatile uint8_t interrupt_status = 0;
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMA456W_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(1024)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMA456W_FIFO_RAW_DATA_USER_LENGTH UINT16_C(1024)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO
|
||||
* Calculation:
|
||||
* fifo_buffer = 1024, accel_frame_len = 6.
|
||||
* fifo_accel_frame_count = (1024 / 6) = 170 frames
|
||||
*/
|
||||
#define BMA456W_FIFO_ACCEL_FRAME_COUNT UINT8_C(170)
|
||||
|
||||
/*! APP20 Board number */
|
||||
#define BOARD_MCU_APP20 UINT8_C(0x03)
|
||||
|
||||
/*! APP30 Board number */
|
||||
#define BOARD_MCU_APP30 UINT8_C(0x05)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*
|
||||
* @param[out] board : Board value to determine as APP2.0 or APP3.0
|
||||
*/
|
||||
static void get_board_info(uint8_t *board);
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set the interrupt status
|
||||
*/
|
||||
static void interrupt_callback(uint32_t param1, uint32_t param2)
|
||||
{
|
||||
(void)param1;
|
||||
(void)param2;
|
||||
interrupt_status = 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Function */
|
||||
|
||||
/* This function starts the execution of program */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of API are returned to this variable */
|
||||
int8_t rslt;
|
||||
|
||||
/* Accelerometer configuration structure */
|
||||
struct bma4_accel_config acc_conf = { 0 };
|
||||
|
||||
/* Sensor initialization configuration */
|
||||
struct bma4_dev dev = { 0 };
|
||||
|
||||
/* Number of accelerometer frames */
|
||||
uint16_t accel_length;
|
||||
|
||||
/* Variable to idx bytes */
|
||||
uint16_t idx = 0;
|
||||
|
||||
/* Variable to maintain count of loop to run FIFO read */
|
||||
uint8_t loop = 1;
|
||||
|
||||
/* Number of bytes of FIFO data
|
||||
* NOTE : Dummy byte (for SPI Interface) required for FIFO data read must be given as part of array size
|
||||
*/
|
||||
uint8_t fifo_data[BMA456W_FIFO_RAW_DATA_BUFFER_SIZE] = { 0 };
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 170 * (6 axes bytes(+/- x,y,z)) = 1020 bytes */
|
||||
struct bma4_accel fifo_accel_data[BMA456W_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure */
|
||||
struct bma4_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Variable that contains interrupt status value */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Variable to hold the length of FIFO data */
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
struct bma4_int_pin_config pin_config = { 0 };
|
||||
uint8_t board = 0;
|
||||
|
||||
/* Variable for interrupt line selection*/
|
||||
uint8_t int_line;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&dev, BMA4_I2C_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Initialize BMA456W */
|
||||
rslt = bma456w_init(&dev);
|
||||
bma4_error_codes_print_result("bma456w_init status", rslt);
|
||||
|
||||
/* Accelerometer configuration settings */
|
||||
acc_conf.odr = BMA4_OUTPUT_DATA_RATE_100HZ;
|
||||
acc_conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4;
|
||||
acc_conf.range = BMA4_ACCEL_RANGE_2G;
|
||||
acc_conf.perf_mode = BMA4_CIC_AVG_MODE;
|
||||
|
||||
/* Set the accel configurations */
|
||||
rslt = bma4_set_accel_config(&acc_conf, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_accel_config status", rslt);
|
||||
|
||||
/* NOTE : Enable accel after set of configurations */
|
||||
rslt = bma4_set_accel_enable(1, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
/* Disabling advance power save mode as FIFO data is not accessible in advance low power mode */
|
||||
rslt = bma4_set_advance_power_save(BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_advance_power_save status", rslt);
|
||||
|
||||
/* Clear FIFO configuration register */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_ALL, BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config disable status", rslt);
|
||||
|
||||
/* Set FIFO configuration by enabling accel.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode. */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_ACCEL, BMA4_ENABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config enable status", rslt);
|
||||
|
||||
/* Update FIFO structure */
|
||||
fifoframe.data = fifo_data;
|
||||
fifoframe.length = BMA456W_FIFO_RAW_DATA_USER_LENGTH;
|
||||
|
||||
/* To enable headerless mode, disable the header. */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_HEADER, BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config status", rslt);
|
||||
|
||||
printf("FIFO is configured in headerless mode\n");
|
||||
|
||||
/* Hardware interrupt configuration */
|
||||
int_line = BMA4_INTR2_MAP;
|
||||
|
||||
rslt = bma456w_map_interrupt(int_line, BMA4_FIFO_FULL_INT, BMA4_ENABLE, &dev);
|
||||
bma4_error_codes_print_result("bma456w_map_interrupt status", rslt);
|
||||
|
||||
pin_config.edge_ctrl = BMA4_EDGE_TRIGGER;
|
||||
pin_config.output_en = BMA4_OUTPUT_ENABLE;
|
||||
pin_config.lvl = BMA4_ACTIVE_HIGH;
|
||||
pin_config.od = BMA4_PUSH_PULL;
|
||||
pin_config.input_en = BMA4_INPUT_DISABLE;
|
||||
|
||||
rslt = bma4_set_int_pin_config(&pin_config, int_line, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_int_pin_config status", rslt);
|
||||
|
||||
/* Get board information */
|
||||
get_board_info(&board);
|
||||
|
||||
/*
|
||||
* Attach interrupt based on board
|
||||
*/
|
||||
if (board == BOARD_MCU_APP20)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_20, interrupt_callback, COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_21, interrupt_callback, COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(MCU_APP20)
|
||||
else if (board == BOARD_MCU_APP30)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_6,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_7,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
while (loop <= 10)
|
||||
{
|
||||
if (interrupt_status == 1)
|
||||
{
|
||||
interrupt_status = 0;
|
||||
|
||||
rslt = bma456w_read_int_status(&int_status, &dev);
|
||||
bma4_error_codes_print_result("bma4_read_int_status", rslt);
|
||||
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_FIFO_FULL_INT))
|
||||
{
|
||||
printf("\nIteration : %d\n", loop);
|
||||
|
||||
rslt = bma4_get_fifo_length(&fifo_length, &dev);
|
||||
bma4_error_codes_print_result("bma4_get_fifo_length status", rslt);
|
||||
|
||||
printf("FIFO data bytes available : %d\n", fifo_length);
|
||||
printf("FIFO data bytes requested : %d\n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data */
|
||||
rslt = bma4_read_fifo_data(&fifoframe, &dev);
|
||||
bma4_error_codes_print_result("bma4_read_fifo_data status", rslt);
|
||||
|
||||
accel_length = BMA456W_FIFO_ACCEL_FRAME_COUNT;
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("Requested data frames before parsing: %d\n", accel_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer */
|
||||
rslt = bma4_extract_accel(fifo_accel_data, &accel_length, &fifoframe, &dev);
|
||||
printf("Parsed accelerometer data frames: %d\n", accel_length);
|
||||
|
||||
printf("ACCEL, X, Y, Z\n");
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer */
|
||||
for (idx = 0; idx < accel_length; idx++)
|
||||
{
|
||||
printf("%d, %d, %d, %d\n", idx, fifo_accel_data[idx].x, fifo_accel_data[idx].y,
|
||||
fifo_accel_data[idx].z);
|
||||
}
|
||||
}
|
||||
|
||||
loop++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*/
|
||||
static void get_board_info(uint8_t *board)
|
||||
{
|
||||
struct coines_board_info board_info;
|
||||
int16_t result;
|
||||
|
||||
result = coines_get_board_info(&board_info);
|
||||
|
||||
if (result == COINES_SUCCESS)
|
||||
{
|
||||
(*board) = board_info.board;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_watermark_header_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
TARGET=MCU_APP30
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMA456W_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(1024)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMA456W_FIFO_RAW_DATA_USER_LENGTH UINT16_C(1024)
|
||||
|
||||
/*! Setting a watermark level in FIFO */
|
||||
#define BMA456W_FIFO_WATERMARK_LEVEL UINT16_C(650)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO
|
||||
* Calculation:
|
||||
* fifo_watermark_level = 650, accel_frame_len = 6, header_byte = 1.
|
||||
* fifo_accel_frame_count = (650 / (6 + 1)) = 93 frames
|
||||
* NOTE: Extra frames are read in order to get sensor time
|
||||
*/
|
||||
#define BMA456W_FIFO_ACCEL_FRAME_COUNT UINT8_C(200)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Function */
|
||||
|
||||
/* This function starts the execution of program */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of API are returned to this variable */
|
||||
int8_t rslt;
|
||||
|
||||
/* Accelerometer configuration structure */
|
||||
struct bma4_accel_config acc_conf = { 0 };
|
||||
|
||||
/* Sensor initialization configuration */
|
||||
struct bma4_dev dev = { 0 };
|
||||
|
||||
/* Number of accelerometer frames */
|
||||
uint16_t accel_length;
|
||||
|
||||
/* Variable to idx bytes */
|
||||
uint16_t idx = 0;
|
||||
|
||||
/* Variable to maintain count of loop to run FIFO read */
|
||||
uint8_t loop = 1;
|
||||
|
||||
/* Number of bytes of FIFO data
|
||||
* NOTE : Dummy byte (for SPI Interface) required for FIFO data read must be given as part of array size
|
||||
*/
|
||||
uint8_t fifo_data[BMA456W_FIFO_RAW_DATA_BUFFER_SIZE + BMA4_SENSORTIME_OVERHEAD_BYTE] = { 0 };
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 100 * (6 axes bytes(+/- x,y,z) + 1 header byte) = 700 bytes */
|
||||
struct bma4_accel fifo_accel_data[BMA456W_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure */
|
||||
struct bma4_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Variable that contains interrupt status value */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Variable to hold the length of FIFO data */
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
uint16_t watermark = 0;
|
||||
|
||||
/* To set the watermark level in FIFO */
|
||||
uint16_t wm_lvl;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&dev, BMA4_I2C_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Initialize BMA456W */
|
||||
rslt = bma456w_init(&dev);
|
||||
bma4_error_codes_print_result("bma456w_init status", rslt);
|
||||
|
||||
/* Accelerometer configuration settings */
|
||||
acc_conf.odr = BMA4_OUTPUT_DATA_RATE_100HZ;
|
||||
acc_conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4;
|
||||
acc_conf.range = BMA4_ACCEL_RANGE_2G;
|
||||
acc_conf.perf_mode = BMA4_CIC_AVG_MODE;
|
||||
|
||||
/* Set the accel configurations */
|
||||
rslt = bma4_set_accel_config(&acc_conf, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_accel_config status", rslt);
|
||||
|
||||
/* NOTE : Enable accel after set of configurations */
|
||||
rslt = bma4_set_accel_enable(1, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
/* Disabling advance power save mode as FIFO data is not accessible in advance low power mode */
|
||||
rslt = bma4_set_advance_power_save(BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_advance_power_save status", rslt);
|
||||
|
||||
/* Clear FIFO configuration register */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_ALL, BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config disable status", rslt);
|
||||
|
||||
/* Set FIFO configuration by enabling accel.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode. */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_ACCEL | BMA4_FIFO_HEADER | BMA4_FIFO_TIME, BMA4_ENABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config enable status", rslt);
|
||||
|
||||
/* Update FIFO structure */
|
||||
fifoframe.data = fifo_data;
|
||||
fifoframe.length = BMA456W_FIFO_RAW_DATA_USER_LENGTH + BMA4_SENSORTIME_OVERHEAD_BYTE;
|
||||
|
||||
printf("FIFO is configured in header mode\n");
|
||||
|
||||
rslt = bma456w_map_interrupt(BMA4_INTR1_MAP, BMA4_FIFO_WM_INT, BMA4_ENABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_map_interrupt status", rslt);
|
||||
|
||||
wm_lvl = BMA456W_FIFO_WATERMARK_LEVEL;
|
||||
rslt = bma4_set_fifo_wm(wm_lvl, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_wm status", rslt);
|
||||
|
||||
while (loop <= 10)
|
||||
{
|
||||
rslt = bma456w_read_int_status(&int_status, &dev);
|
||||
bma4_error_codes_print_result("bma4_read_int_status", rslt);
|
||||
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_FIFO_WM_INT))
|
||||
{
|
||||
printf("\nIteration : %d\n", loop);
|
||||
|
||||
rslt = bma4_get_fifo_wm(&watermark, &dev);
|
||||
bma4_error_codes_print_result("bma4_get_fifo_wm status", rslt);
|
||||
printf("FIFO watermark level : %d\n", watermark);
|
||||
|
||||
rslt = bma4_get_fifo_length(&fifo_length, &dev);
|
||||
bma4_error_codes_print_result("bma4_get_fifo_length status", rslt);
|
||||
|
||||
printf("FIFO data bytes available : %d\n", fifo_length);
|
||||
printf("FIFO data bytes requested : %d\n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data */
|
||||
rslt = bma4_read_fifo_data(&fifoframe, &dev);
|
||||
bma4_error_codes_print_result("bma4_read_fifo_data status", rslt);
|
||||
|
||||
accel_length = BMA456W_FIFO_ACCEL_FRAME_COUNT;
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("Requested data frames before parsing: %d\n", accel_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer */
|
||||
rslt = bma4_extract_accel(fifo_accel_data, &accel_length, &fifoframe, &dev);
|
||||
printf("Parsed accelerometer data frames: %d\n", accel_length);
|
||||
|
||||
printf("ACCEL, X, Y, Z\n");
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer */
|
||||
for (idx = 0; idx < accel_length; idx++)
|
||||
{
|
||||
printf("%d, %d, %d, %d\n",
|
||||
idx,
|
||||
fifo_accel_data[idx].x,
|
||||
fifo_accel_data[idx].y,
|
||||
fifo_accel_data[idx].z);
|
||||
}
|
||||
|
||||
/* Print control frames like sensor time and skipped frame count */
|
||||
printf("Skipped frame count = %d\n", fifoframe.skipped_frame_count);
|
||||
printf("Sensor time(in seconds) = %.4lf s\r\n", (fifoframe.sensor_time * BMA4_SENSORTIME_RESOLUTION));
|
||||
}
|
||||
|
||||
loop++;
|
||||
}
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_watermark_header_mode_hw_int.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
TARGET = MCU_APP30
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+303
@@ -0,0 +1,303 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "bma456w.h"
|
||||
#include <math.h>
|
||||
#include "common.h"
|
||||
#include "coines.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Global variable Declaration */
|
||||
|
||||
volatile uint8_t interrupt_status = 0;
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMA456W_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(1024)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMA456W_FIFO_RAW_DATA_USER_LENGTH UINT16_C(1024)
|
||||
|
||||
/*! Setting a watermark level in FIFO */
|
||||
#define BMA456W_FIFO_WATERMARK_LEVEL UINT16_C(650)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO
|
||||
* Calculation:
|
||||
* fifo_watermark_level = 650, accel_frame_len = 6, header_byte = 1.
|
||||
* fifo_accel_frame_count = (650 / (6 + 1)) = 93 frames
|
||||
* NOTE: Extra frames are read in order to get sensor time
|
||||
*/
|
||||
#define BMA456W_FIFO_ACCEL_FRAME_COUNT UINT8_C(100)
|
||||
|
||||
/*! APP20 Board number */
|
||||
#define BOARD_MCU_APP20 UINT8_C(0x03)
|
||||
|
||||
/*! APP30 Board number */
|
||||
#define BOARD_MCU_APP30 UINT8_C(0x05)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*
|
||||
* @param[out] board : Board value to determine as APP2.0 or APP3.0
|
||||
*/
|
||||
static void get_board_info(uint8_t *board);
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set the interrupt status
|
||||
*/
|
||||
static void interrupt_callback(uint32_t param1, uint32_t param2)
|
||||
{
|
||||
(void)param1;
|
||||
(void)param2;
|
||||
interrupt_status = 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Function */
|
||||
|
||||
/* This function starts the execution of program */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of API are returned to this variable */
|
||||
int8_t rslt;
|
||||
|
||||
/* Accelerometer configuration structure */
|
||||
struct bma4_accel_config acc_conf = { 0 };
|
||||
|
||||
/* Sensor initialization configuration */
|
||||
struct bma4_dev dev = { 0 };
|
||||
|
||||
/* Number of accelerometer frames */
|
||||
uint16_t accel_length;
|
||||
|
||||
/* Variable to idx bytes */
|
||||
uint16_t idx = 0;
|
||||
|
||||
/* Variable to maintain count of loop to run FIFO read */
|
||||
uint8_t loop = 1;
|
||||
|
||||
/* Number of bytes of FIFO data
|
||||
* NOTE : Dummy byte (for SPI Interface) required for FIFO data read must be given as part of array size
|
||||
*/
|
||||
uint8_t fifo_data[BMA456W_FIFO_RAW_DATA_BUFFER_SIZE + BMA4_SENSORTIME_OVERHEAD_BYTE] = { 0 };
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 100 * (6 axes bytes(+/- x,y,z) + 1 header byte) = 700 bytes */
|
||||
struct bma4_accel fifo_accel_data[BMA456W_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure */
|
||||
struct bma4_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Variable that contains interrupt status value */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Variable to hold the length of FIFO data */
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
uint16_t watermark = 0;
|
||||
|
||||
/* To set the watermark level in FIFO */
|
||||
uint16_t wm_lvl;
|
||||
|
||||
struct bma4_int_pin_config pin_config = { 0 };
|
||||
uint8_t board = 0;
|
||||
|
||||
/* Variable for interrupt line selection*/
|
||||
uint8_t int_line;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&dev, BMA4_I2C_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Initialize BMA456W */
|
||||
rslt = bma456w_init(&dev);
|
||||
bma4_error_codes_print_result("bma456w_init status", rslt);
|
||||
|
||||
/* Accelerometer configuration settings */
|
||||
acc_conf.odr = BMA4_OUTPUT_DATA_RATE_100HZ;
|
||||
acc_conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4;
|
||||
acc_conf.range = BMA4_ACCEL_RANGE_2G;
|
||||
acc_conf.perf_mode = BMA4_CIC_AVG_MODE;
|
||||
|
||||
/* Set the accel configurations */
|
||||
rslt = bma4_set_accel_config(&acc_conf, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_accel_config status", rslt);
|
||||
|
||||
/* NOTE : Enable accel after set of configurations */
|
||||
rslt = bma4_set_accel_enable(1, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
/* Disabling advance power save mode as FIFO data is not accessible in advance low power mode */
|
||||
rslt = bma4_set_advance_power_save(BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_advance_power_save status", rslt);
|
||||
|
||||
/* Clear FIFO configuration register */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_ALL, BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config disable status", rslt);
|
||||
|
||||
/* Set FIFO configuration by enabling accel.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode. */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_ACCEL | BMA4_FIFO_HEADER | BMA4_FIFO_TIME, BMA4_ENABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config enable status", rslt);
|
||||
|
||||
/* Update FIFO structure */
|
||||
fifoframe.data = fifo_data;
|
||||
fifoframe.length = BMA456W_FIFO_RAW_DATA_USER_LENGTH + BMA4_SENSORTIME_OVERHEAD_BYTE;
|
||||
|
||||
printf("FIFO is configured in header mode\n");
|
||||
|
||||
/* Hardware interrupt configuration */
|
||||
int_line = BMA4_INTR1_MAP;
|
||||
|
||||
rslt = bma456w_map_interrupt(int_line, BMA4_FIFO_WM_INT, BMA4_ENABLE, &dev);
|
||||
bma4_error_codes_print_result("bma456w_map_interrupt status", rslt);
|
||||
|
||||
wm_lvl = BMA456W_FIFO_WATERMARK_LEVEL;
|
||||
rslt = bma4_set_fifo_wm(wm_lvl, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_wm status", rslt);
|
||||
|
||||
pin_config.edge_ctrl = BMA4_EDGE_TRIGGER;
|
||||
pin_config.output_en = BMA4_OUTPUT_ENABLE;
|
||||
pin_config.lvl = BMA4_ACTIVE_HIGH;
|
||||
pin_config.od = BMA4_PUSH_PULL;
|
||||
pin_config.input_en = BMA4_INPUT_DISABLE;
|
||||
|
||||
rslt = bma4_set_int_pin_config(&pin_config, int_line, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_int_pin_config status", rslt);
|
||||
|
||||
/* Get board information */
|
||||
get_board_info(&board);
|
||||
|
||||
/*
|
||||
* Attach interrupt based on board
|
||||
*/
|
||||
if (board == BOARD_MCU_APP20)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_20, interrupt_callback, COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_21, interrupt_callback, COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(MCU_APP20)
|
||||
else if (board == BOARD_MCU_APP30)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_6,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_7,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
while (loop <= 10)
|
||||
{
|
||||
if (interrupt_status == 1)
|
||||
{
|
||||
interrupt_status = 0;
|
||||
rslt = bma456w_read_int_status(&int_status, &dev);
|
||||
bma4_error_codes_print_result("bma4_read_int_status", rslt);
|
||||
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_FIFO_WM_INT))
|
||||
{
|
||||
printf("\nIteration : %d\n", loop);
|
||||
|
||||
rslt = bma4_get_fifo_wm(&watermark, &dev);
|
||||
bma4_error_codes_print_result("bma4_get_fifo_wm status", rslt);
|
||||
printf("FIFO watermark level : %d\n", watermark);
|
||||
|
||||
rslt = bma4_get_fifo_length(&fifo_length, &dev);
|
||||
bma4_error_codes_print_result("bma4_get_fifo_length status", rslt);
|
||||
|
||||
printf("FIFO data bytes available : %d\n", fifo_length);
|
||||
printf("FIFO data bytes requested : %d\n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data */
|
||||
rslt = bma4_read_fifo_data(&fifoframe, &dev);
|
||||
bma4_error_codes_print_result("bma4_read_fifo_data status", rslt);
|
||||
|
||||
accel_length = BMA456W_FIFO_ACCEL_FRAME_COUNT;
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("Requested data frames before parsing: %d\n", accel_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer */
|
||||
rslt = bma4_extract_accel(fifo_accel_data, &accel_length, &fifoframe, &dev);
|
||||
printf("Parsed accelerometer data frames: %d\n", accel_length);
|
||||
|
||||
printf("ACCEL, X, Y, Z\n");
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer */
|
||||
for (idx = 0; idx < accel_length; idx++)
|
||||
{
|
||||
printf("%d, %d, %d, %d\n", idx, fifo_accel_data[idx].x, fifo_accel_data[idx].y,
|
||||
fifo_accel_data[idx].z);
|
||||
}
|
||||
|
||||
/* Print control frames like sensor time and skipped frame count */
|
||||
printf("Skipped frame count = %d\n", fifoframe.skipped_frame_count);
|
||||
printf("Sensor time(in seconds) = %.4lf s\r\n",
|
||||
(fifoframe.sensor_time * BMA4_SENSORTIME_RESOLUTION));
|
||||
}
|
||||
|
||||
loop++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*/
|
||||
static void get_board_info(uint8_t *board)
|
||||
{
|
||||
struct coines_board_info board_info;
|
||||
int16_t result;
|
||||
|
||||
result = coines_get_board_info(&board_info);
|
||||
|
||||
if (result == COINES_SUCCESS)
|
||||
{
|
||||
(*board) = board_info.board;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_watermark_headerless_mode.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMA456W_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(1024)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMA456W_FIFO_RAW_DATA_USER_LENGTH UINT16_C(1024)
|
||||
|
||||
/*! Setting a watermark level in FIFO */
|
||||
#define BMA456W_FIFO_WATERMARK_LEVEL UINT16_C(600)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO
|
||||
* Calculation:
|
||||
* fifo_watermark_level = 600, accel_frame_len = 6.
|
||||
* fifo_accel_frame_count = (600 / 6) = 100 frames
|
||||
*/
|
||||
#define BMA456W_FIFO_ACCEL_FRAME_COUNT UINT8_C(100)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Function */
|
||||
|
||||
/* This function starts the execution of program */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of API are returned to this variable */
|
||||
int8_t rslt;
|
||||
|
||||
/* Accelerometer configuration structure */
|
||||
struct bma4_accel_config acc_conf = { 0 };
|
||||
|
||||
/* Sensor initialization configuration */
|
||||
struct bma4_dev dev = { 0 };
|
||||
|
||||
/* Number of accelerometer frames */
|
||||
uint16_t accel_length;
|
||||
|
||||
/* Variable to idx bytes */
|
||||
uint16_t idx = 0;
|
||||
|
||||
/* Variable to maintain count of loop to run FIFO read */
|
||||
uint8_t loop = 1;
|
||||
|
||||
/* Number of bytes of FIFO data
|
||||
* NOTE : Dummy byte (for SPI Interface) required for FIFO data read must be given as part of array size
|
||||
*/
|
||||
uint8_t fifo_data[BMA456W_FIFO_RAW_DATA_BUFFER_SIZE] = { 0 };
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 100 * (6 axes bytes(+/- x,y,z)) = 600 bytes */
|
||||
struct bma4_accel fifo_accel_data[BMA456W_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure */
|
||||
struct bma4_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Variable that contains interrupt status value */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Variable to hold the length of FIFO data */
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
uint16_t watermark = 0;
|
||||
|
||||
/* To set the watermark level in FIFO */
|
||||
uint16_t wm_lvl;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&dev, BMA4_I2C_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Initialize BMA456W */
|
||||
rslt = bma456w_init(&dev);
|
||||
bma4_error_codes_print_result("bma456w_init status", rslt);
|
||||
|
||||
/* Accelerometer configuration settings */
|
||||
acc_conf.odr = BMA4_OUTPUT_DATA_RATE_100HZ;
|
||||
acc_conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4;
|
||||
acc_conf.range = BMA4_ACCEL_RANGE_2G;
|
||||
acc_conf.perf_mode = BMA4_CIC_AVG_MODE;
|
||||
|
||||
/* Set the accel configurations */
|
||||
rslt = bma4_set_accel_config(&acc_conf, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_accel_config status", rslt);
|
||||
|
||||
/* NOTE : Enable accel after set of configurations */
|
||||
rslt = bma4_set_accel_enable(1, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
/* Disabling advance power save mode as FIFO data is not accessible in advance low power mode */
|
||||
rslt = bma4_set_advance_power_save(BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_advance_power_save status", rslt);
|
||||
|
||||
/* Clear FIFO configuration register */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_ALL, BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config disable status", rslt);
|
||||
|
||||
/* Set FIFO configuration by enabling accel.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode. */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_ACCEL, BMA4_ENABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config enable status", rslt);
|
||||
|
||||
/* Update FIFO structure */
|
||||
fifoframe.data = fifo_data;
|
||||
fifoframe.length = BMA456W_FIFO_RAW_DATA_USER_LENGTH;
|
||||
|
||||
/* To enable headerless mode, disable the header. */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_HEADER, BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config status", rslt);
|
||||
|
||||
printf("FIFO is configured in headerless mode\n");
|
||||
|
||||
rslt = bma456w_map_interrupt(BMA4_INTR1_MAP, BMA4_FIFO_WM_INT, BMA4_ENABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_map_interrupt status", rslt);
|
||||
|
||||
wm_lvl = BMA456W_FIFO_WATERMARK_LEVEL;
|
||||
rslt = bma4_set_fifo_wm(wm_lvl, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_wm status", rslt);
|
||||
|
||||
while (loop <= 10)
|
||||
{
|
||||
rslt = bma456w_read_int_status(&int_status, &dev);
|
||||
bma4_error_codes_print_result("bma4_read_int_status", rslt);
|
||||
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_FIFO_WM_INT))
|
||||
{
|
||||
printf("\nIteration : %d\n", loop);
|
||||
|
||||
rslt = bma4_get_fifo_wm(&watermark, &dev);
|
||||
bma4_error_codes_print_result("bma4_get_fifo_wm status", rslt);
|
||||
|
||||
printf("FIFO watermark level : %d\n", watermark);
|
||||
|
||||
rslt = bma4_get_fifo_length(&fifo_length, &dev);
|
||||
bma4_error_codes_print_result("bma4_get_fifo_length status", rslt);
|
||||
|
||||
printf("FIFO data bytes available : %d\n", fifo_length);
|
||||
printf("FIFO data bytes requested : %d\n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data */
|
||||
rslt = bma4_read_fifo_data(&fifoframe, &dev);
|
||||
bma4_error_codes_print_result("bma4_read_fifo_data status", rslt);
|
||||
|
||||
accel_length = BMA456W_FIFO_ACCEL_FRAME_COUNT;
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("Requested data frames before parsing: %d\n", accel_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer */
|
||||
rslt = bma4_extract_accel(fifo_accel_data, &accel_length, &fifoframe, &dev);
|
||||
printf("Parsed accelerometer data frames: %d\n", accel_length);
|
||||
|
||||
printf("ACCEL, X, Y, Z\n");
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer */
|
||||
for (idx = 0; idx < accel_length; idx++)
|
||||
{
|
||||
printf("%d, %d, %d, %d\n",
|
||||
idx,
|
||||
fifo_accel_data[idx].x,
|
||||
fifo_accel_data[idx].y,
|
||||
fifo_accel_data[idx].z);
|
||||
}
|
||||
}
|
||||
|
||||
loop++;
|
||||
}
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= fifo_watermark_headerless_mode_hw_int.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
TARGET = MCU_APP30
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+302
@@ -0,0 +1,302 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
#include "coines.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Global variable Declaration */
|
||||
|
||||
volatile uint8_t interrupt_status = 0;
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! Buffer size allocated to store raw FIFO data */
|
||||
#define BMA456W_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(1024)
|
||||
|
||||
/*! Length of data to be read from FIFO */
|
||||
#define BMA456W_FIFO_RAW_DATA_USER_LENGTH UINT16_C(1024)
|
||||
|
||||
/*! Setting a watermark level in FIFO */
|
||||
#define BMA456W_FIFO_WATERMARK_LEVEL UINT16_C(600)
|
||||
|
||||
/*! Number of accel frames to be extracted from FIFO
|
||||
* Calculation:
|
||||
* fifo_watermark_level = 600, accel_frame_len = 6.
|
||||
* fifo_accel_frame_count = (600 / 6) = 100 frames
|
||||
*/
|
||||
#define BMA456W_FIFO_ACCEL_FRAME_COUNT UINT8_C(100)
|
||||
|
||||
/*! APP20 Board number */
|
||||
#define BOARD_MCU_APP20 UINT8_C(0x03)
|
||||
|
||||
/*! APP30 Board number */
|
||||
#define BOARD_MCU_APP30 UINT8_C(0x05)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*
|
||||
* @param[out] board : Board value to determine as APP2.0 or APP3.0
|
||||
*/
|
||||
static void get_board_info(uint8_t *board);
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set the interrupt status
|
||||
*/
|
||||
static void interrupt_callback(uint32_t param1, uint32_t param2)
|
||||
{
|
||||
(void)param1;
|
||||
(void)param2;
|
||||
interrupt_status = 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Function */
|
||||
|
||||
/* This function starts the execution of program */
|
||||
int main(void)
|
||||
{
|
||||
/* Status of API are returned to this variable */
|
||||
int8_t rslt;
|
||||
|
||||
/* Accelerometer configuration structure */
|
||||
struct bma4_accel_config acc_conf = { 0 };
|
||||
|
||||
/* Sensor initialization configuration */
|
||||
struct bma4_dev dev = { 0 };
|
||||
|
||||
/* Number of accelerometer frames */
|
||||
uint16_t accel_length;
|
||||
|
||||
/* Variable to idx bytes */
|
||||
uint16_t idx = 0;
|
||||
|
||||
/* Variable to maintain count of loop to run FIFO read */
|
||||
uint8_t loop = 1;
|
||||
|
||||
/* Number of bytes of FIFO data
|
||||
* NOTE : Dummy byte (for SPI Interface) required for FIFO data read must be given as part of array size
|
||||
*/
|
||||
uint8_t fifo_data[BMA456W_FIFO_RAW_DATA_BUFFER_SIZE] = { 0 };
|
||||
|
||||
/* Array of accelerometer frames -> Total bytes =
|
||||
* 100 * (6 axes bytes(+/- x,y,z)) = 600 bytes */
|
||||
struct bma4_accel fifo_accel_data[BMA456W_FIFO_ACCEL_FRAME_COUNT] = { { 0 } };
|
||||
|
||||
/* Initialize FIFO frame structure */
|
||||
struct bma4_fifo_frame fifoframe = { 0 };
|
||||
|
||||
/* Variable that contains interrupt status value */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Variable to hold the length of FIFO data */
|
||||
uint16_t fifo_length = 0;
|
||||
|
||||
uint16_t watermark = 0;
|
||||
|
||||
/* To set the watermark level in FIFO */
|
||||
uint16_t wm_lvl;
|
||||
|
||||
struct bma4_int_pin_config pin_config = { 0 };
|
||||
uint8_t board = 0;
|
||||
|
||||
/* Variable for interrupt line selection*/
|
||||
uint8_t int_line;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&dev, BMA4_I2C_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Initialize BMA456W */
|
||||
rslt = bma456w_init(&dev);
|
||||
bma4_error_codes_print_result("bma456w_init status", rslt);
|
||||
|
||||
/* Accelerometer configuration settings */
|
||||
acc_conf.odr = BMA4_OUTPUT_DATA_RATE_100HZ;
|
||||
acc_conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4;
|
||||
acc_conf.range = BMA4_ACCEL_RANGE_2G;
|
||||
acc_conf.perf_mode = BMA4_CIC_AVG_MODE;
|
||||
|
||||
/* Set the accel configurations */
|
||||
rslt = bma4_set_accel_config(&acc_conf, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_accel_config status", rslt);
|
||||
|
||||
/* NOTE : Enable accel after set of configurations */
|
||||
rslt = bma4_set_accel_enable(1, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
/* Disabling advance power save mode as FIFO data is not accessible in advance low power mode */
|
||||
rslt = bma4_set_advance_power_save(BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_advance_power_save status", rslt);
|
||||
|
||||
/* Clear FIFO configuration register */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_ALL, BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config disable status", rslt);
|
||||
|
||||
/* Set FIFO configuration by enabling accel.
|
||||
* NOTE 1: The header mode is enabled by default.
|
||||
* NOTE 2: By default the FIFO operating mode is FIFO mode. */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_ACCEL, BMA4_ENABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config enable status", rslt);
|
||||
|
||||
/* Update FIFO structure */
|
||||
fifoframe.data = fifo_data;
|
||||
fifoframe.length = BMA456W_FIFO_RAW_DATA_USER_LENGTH;
|
||||
|
||||
/* To enable headerless mode, disable the header. */
|
||||
rslt = bma4_set_fifo_config(BMA4_FIFO_HEADER, BMA4_DISABLE, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_config status", rslt);
|
||||
|
||||
printf("FIFO is configured in headerless mode\n");
|
||||
|
||||
/* Hardware interrupt configuration */
|
||||
int_line = BMA4_INTR1_MAP;
|
||||
|
||||
rslt = bma456w_map_interrupt(int_line, BMA4_FIFO_WM_INT, BMA4_ENABLE, &dev);
|
||||
bma4_error_codes_print_result("bma456w_map_interrupt status", rslt);
|
||||
|
||||
wm_lvl = BMA456W_FIFO_WATERMARK_LEVEL;
|
||||
rslt = bma4_set_fifo_wm(wm_lvl, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_fifo_wm status", rslt);
|
||||
|
||||
pin_config.edge_ctrl = BMA4_EDGE_TRIGGER;
|
||||
pin_config.output_en = BMA4_OUTPUT_ENABLE;
|
||||
pin_config.lvl = BMA4_ACTIVE_HIGH;
|
||||
pin_config.od = BMA4_PUSH_PULL;
|
||||
pin_config.input_en = BMA4_INPUT_DISABLE;
|
||||
|
||||
rslt = bma4_set_int_pin_config(&pin_config, int_line, &dev);
|
||||
bma4_error_codes_print_result("bma4_set_int_pin_config status", rslt);
|
||||
|
||||
/* Get board information */
|
||||
get_board_info(&board);
|
||||
|
||||
/*
|
||||
* Attach interrupt based on board
|
||||
*/
|
||||
if (board == BOARD_MCU_APP20)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_20, interrupt_callback, COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_21, interrupt_callback, COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(MCU_APP20)
|
||||
else if (board == BOARD_MCU_APP30)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_6,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_7,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
while (loop <= 10)
|
||||
{
|
||||
if (interrupt_status == 1)
|
||||
{
|
||||
interrupt_status = 0;
|
||||
rslt = bma456w_read_int_status(&int_status, &dev);
|
||||
bma4_error_codes_print_result("bma4_read_int_status", rslt);
|
||||
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA4_FIFO_WM_INT))
|
||||
{
|
||||
printf("\nIteration : %d\n", loop);
|
||||
|
||||
rslt = bma4_get_fifo_wm(&watermark, &dev);
|
||||
bma4_error_codes_print_result("bma4_get_fifo_wm status", rslt);
|
||||
|
||||
printf("FIFO watermark level : %d\n", watermark);
|
||||
|
||||
rslt = bma4_get_fifo_length(&fifo_length, &dev);
|
||||
bma4_error_codes_print_result("bma4_get_fifo_length status", rslt);
|
||||
|
||||
printf("FIFO data bytes available : %d\n", fifo_length);
|
||||
printf("FIFO data bytes requested : %d\n", fifoframe.length);
|
||||
|
||||
/* Read FIFO data */
|
||||
rslt = bma4_read_fifo_data(&fifoframe, &dev);
|
||||
bma4_error_codes_print_result("bma4_read_fifo_data status", rslt);
|
||||
|
||||
accel_length = BMA456W_FIFO_ACCEL_FRAME_COUNT;
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("Requested data frames before parsing: %d\n", accel_length);
|
||||
|
||||
/* Parse the FIFO data to extract accelerometer data from the FIFO buffer */
|
||||
rslt = bma4_extract_accel(fifo_accel_data, &accel_length, &fifoframe, &dev);
|
||||
printf("Parsed accelerometer data frames: %d\n", accel_length);
|
||||
|
||||
printf("ACCEL, X, Y, Z\n");
|
||||
|
||||
/* Print the parsed accelerometer data from the FIFO buffer */
|
||||
for (idx = 0; idx < accel_length; idx++)
|
||||
{
|
||||
printf("%d, %d, %d, %d\n", idx, fifo_accel_data[idx].x, fifo_accel_data[idx].y,
|
||||
fifo_accel_data[idx].z);
|
||||
}
|
||||
}
|
||||
|
||||
loop++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*/
|
||||
static void get_board_info(uint8_t *board)
|
||||
{
|
||||
struct coines_board_info board_info;
|
||||
int16_t result;
|
||||
|
||||
result = coines_get_board_info(&board_info);
|
||||
|
||||
if (result == COINES_SUCCESS)
|
||||
{
|
||||
(*board) = board_info.board;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= motion.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,186 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/*! Global variable */
|
||||
|
||||
/*! Structure to define any/no-motion configurations */
|
||||
struct bma456w_any_no_mot_config any_no_mot = { 0 };
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to get any/no-motion configurations.
|
||||
*
|
||||
* @param[in] bma : Structure instance of bma4_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t get_any_no_mot_config(struct bma4_dev *bma);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Variable to store the status of API */
|
||||
int8_t rslt;
|
||||
|
||||
/* Sensor initialization configuration */
|
||||
struct bma4_dev bma = { 0 };
|
||||
|
||||
/* Variable to store any/no-motion interrupt status */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Loop variable */
|
||||
uint8_t iteration = 20;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&bma, BMA4_I2C_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Sensor initialization */
|
||||
rslt = bma456w_init(&bma);
|
||||
bma4_error_codes_print_result("bma456w_init status", rslt);
|
||||
|
||||
/* Upload the configuration file to enable the features of the sensor. */
|
||||
rslt = bma456w_write_config_file(&bma);
|
||||
bma4_error_codes_print_result("bma456w_write_config status", rslt);
|
||||
|
||||
/* Enable the accelerometer */
|
||||
rslt = bma4_set_accel_enable(BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
/* Map the interrupt 1 for any/no-motion */
|
||||
rslt = bma456w_map_interrupt(BMA4_INTR1_MAP, (BMA456W_ANY_MOT_INT | BMA456W_NO_MOT_INT), BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma456w_map_interrupt status", rslt);
|
||||
|
||||
/* Get any-motion and no-motion configurations */
|
||||
rslt = get_any_no_mot_config(&bma);
|
||||
bma4_error_codes_print_result("get_any_no_mot_config status", rslt);
|
||||
|
||||
printf("Shake the board for any-motion interrupt whereas do not shake the board for no-motion interrupt\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Read interrupt status */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
/* Enters only if the obtained interrupt is any-motion */
|
||||
if (int_status & BMA456W_ANY_MOT_INT)
|
||||
{
|
||||
printf("Any-motion interrupt occurred\n");
|
||||
iteration--;
|
||||
}
|
||||
|
||||
/* Enters only if the obtained interrupt is no-motion */
|
||||
else if (int_status & BMA456W_NO_MOT_INT)
|
||||
{
|
||||
printf("No-motion interrupt occurred\n");
|
||||
iteration--;
|
||||
}
|
||||
|
||||
int_status = 0;
|
||||
|
||||
/* Break out of the loop when iteration has reached zero */
|
||||
if (iteration == 0)
|
||||
{
|
||||
printf("Iterations are done. Exiting !");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to get any/no-motion configurations.
|
||||
*/
|
||||
static int8_t get_any_no_mot_config(struct bma4_dev *bma)
|
||||
{
|
||||
/* Variable to store the status of API */
|
||||
int8_t rslt;
|
||||
|
||||
/* Getting any-motion configuration to get default configuration */
|
||||
rslt = bma456w_get_any_mot_config(&any_no_mot, bma);
|
||||
bma4_error_codes_print_result("bma456w_get_any_mot_config status", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
/*
|
||||
* Set the slope threshold:
|
||||
* Interrupt will be generated if the slope of all the axis exceeds the threshold (1 bit = 0.48mG)
|
||||
*/
|
||||
any_no_mot.threshold = 10;
|
||||
|
||||
/*
|
||||
* Set the duration for any-motion interrupt:
|
||||
* Duration defines the number of consecutive data points for which threshold condition must be true(1
|
||||
* bit =
|
||||
* 20ms)
|
||||
*/
|
||||
any_no_mot.duration = 4;
|
||||
|
||||
/* Enabling X, Y, and Z axis for Any-motion feature */
|
||||
any_no_mot.axes_en = BMA456W_EN_ALL_AXIS;
|
||||
|
||||
/* Like threshold and duration, we can also change the config of int_bhvr and slope */
|
||||
|
||||
/* Set the threshold and duration configuration */
|
||||
rslt = bma456w_set_any_mot_config(&any_no_mot, bma);
|
||||
bma4_error_codes_print_result("bma456w_set_any_mot_config status", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
/* Getting no-motion configuration to get default configuration */
|
||||
rslt = bma456w_get_no_mot_config(&any_no_mot, bma);
|
||||
bma4_error_codes_print_result("bma456w_get_no_mot_config status", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
/*
|
||||
* Set the slope threshold:
|
||||
* Interrupt will be generated if the slope of all the axis exceeds the threshold (1 bit = 0.48mG)
|
||||
*/
|
||||
any_no_mot.threshold = 10;
|
||||
|
||||
/*
|
||||
* Set the duration for no-motion interrupt:
|
||||
* Duration defines the number of consecutive data points for which threshold condition must be
|
||||
* true(1 bit = 20ms)
|
||||
*/
|
||||
any_no_mot.duration = 4;
|
||||
|
||||
/* Enabling X, Y, and Z axis for no-motion feature */
|
||||
any_no_mot.axes_en = BMA456W_EN_ALL_AXIS;
|
||||
|
||||
/* Like threshold and duration, we can also change the config of int_bhvr */
|
||||
|
||||
/* Set the threshold and duration configuration */
|
||||
rslt = bma456w_set_no_mot_config(&any_no_mot, bma);
|
||||
bma4_error_codes_print_result("bma456w_set_no_mot_config status", rslt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= motion_hw_int.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
TARGET = MCU_APP30
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,301 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/*! Global variable */
|
||||
|
||||
/*! Structure to define any/no-motion configurations */
|
||||
struct bma456w_any_no_mot_config any_no_mot = { 0 };
|
||||
|
||||
volatile uint8_t interrupt_status = 0;
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! APP20 Board number */
|
||||
#define BOARD_MCU_APP20 UINT8_C(0x03)
|
||||
|
||||
/*! APP30 Board number */
|
||||
#define BOARD_MCU_APP30 UINT8_C(0x05)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to get any/no-motion configurations.
|
||||
*
|
||||
* @param[in] bma : Structure instance of bma4_dev.
|
||||
*
|
||||
* @return Status of execution.
|
||||
*/
|
||||
static int8_t get_any_no_mot_config(struct bma4_dev *bma);
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*
|
||||
* @param[out] board : Board value to determine as APP2.0 or APP3.0
|
||||
*/
|
||||
static void get_board_info(uint8_t *board);
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set the interrupt status
|
||||
*/
|
||||
static void interrupt_callback(uint32_t param1, uint32_t param2)
|
||||
{
|
||||
(void)param1;
|
||||
(void)param2;
|
||||
interrupt_status = 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Functions */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Variable to store the status of API */
|
||||
int8_t rslt;
|
||||
|
||||
/* Sensor initialization configuration */
|
||||
struct bma4_dev bma = { 0 };
|
||||
|
||||
/* Variable to store any/no-motion interrupt status */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Loop variable */
|
||||
uint8_t iteration = 20;
|
||||
|
||||
struct bma4_int_pin_config pin_config = { 0 };
|
||||
uint8_t board = 0;
|
||||
|
||||
/* Variable for interrupt line selection*/
|
||||
uint8_t int_line;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&bma, BMA4_I2C_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Sensor initialization */
|
||||
rslt = bma456w_init(&bma);
|
||||
bma4_error_codes_print_result("bma456w_init status", rslt);
|
||||
|
||||
/* Upload the configuration file to enable the features of the sensor. */
|
||||
rslt = bma456w_write_config_file(&bma);
|
||||
bma4_error_codes_print_result("bma456w_write_config status", rslt);
|
||||
|
||||
/* Enable the accelerometer */
|
||||
rslt = bma4_set_accel_enable(BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
/* Get any-motion and no-motion configurations */
|
||||
rslt = get_any_no_mot_config(&bma);
|
||||
bma4_error_codes_print_result("get_any_no_mot_config status", rslt);
|
||||
|
||||
/* Hardware interrupt configuration */
|
||||
int_line = BMA4_INTR2_MAP;
|
||||
|
||||
rslt = bma4_get_int_pin_config(&pin_config, int_line, &bma);
|
||||
bma4_error_codes_print_result("bma4_get_int_pin_config status", rslt);
|
||||
|
||||
rslt = bma456w_map_interrupt(int_line, (BMA456W_ANY_MOT_INT | BMA456W_NO_MOT_INT), BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma456w_map_interrupt status", rslt);
|
||||
|
||||
pin_config.edge_ctrl = BMA4_EDGE_TRIGGER;
|
||||
pin_config.output_en = BMA4_OUTPUT_ENABLE;
|
||||
pin_config.lvl = BMA4_ACTIVE_HIGH;
|
||||
pin_config.od = BMA4_PUSH_PULL;
|
||||
pin_config.input_en = BMA4_INPUT_DISABLE;
|
||||
|
||||
rslt = bma4_set_int_pin_config(&pin_config, int_line, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_int_pin_config status", rslt);
|
||||
|
||||
/* Get board information */
|
||||
get_board_info(&board);
|
||||
|
||||
/*
|
||||
* Attach interrupt based on board
|
||||
*/
|
||||
if (board == BOARD_MCU_APP20)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_20, interrupt_callback, COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_21, interrupt_callback, COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(MCU_APP20)
|
||||
else if (board == BOARD_MCU_APP30)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_6,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_7,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
printf("Shake the board for any-motion interrupt whereas do not shake the board for no-motion interrupt\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (interrupt_status == 1)
|
||||
{
|
||||
interrupt_status = 0;
|
||||
|
||||
/* Read interrupt status */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
/* Enters only if the obtained interrupt is any-motion */
|
||||
if (int_status & BMA456W_ANY_MOT_INT)
|
||||
{
|
||||
printf("Any-motion interrupt occurred\n");
|
||||
iteration--;
|
||||
}
|
||||
/* Enters only if the obtained interrupt is no-motion */
|
||||
else if (int_status & BMA456W_NO_MOT_INT)
|
||||
{
|
||||
printf("No-motion interrupt occurred\n");
|
||||
iteration--;
|
||||
}
|
||||
|
||||
int_status = 0;
|
||||
|
||||
/* Break out of the loop when iteration has reached zero */
|
||||
if (iteration == 0)
|
||||
{
|
||||
printf("Iterations are done. Exiting !");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to get any/no-motion configurations.
|
||||
*/
|
||||
static int8_t get_any_no_mot_config(struct bma4_dev *bma)
|
||||
{
|
||||
/* Variable to store the status of API */
|
||||
int8_t rslt;
|
||||
|
||||
/* Getting any-motion configuration to get default configuration */
|
||||
rslt = bma456w_get_any_mot_config(&any_no_mot, bma);
|
||||
bma4_error_codes_print_result("bma456w_get_any_mot_config status", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
/*
|
||||
* Set the slope threshold:
|
||||
* Interrupt will be generated if the slope of all the axis exceeds the threshold (1 bit = 0.48mG)
|
||||
*/
|
||||
any_no_mot.threshold = 10;
|
||||
|
||||
/*
|
||||
* Set the duration for any-motion interrupt:
|
||||
* Duration defines the number of consecutive data points for which threshold condition must be true(1
|
||||
* bit =
|
||||
* 20ms)
|
||||
*/
|
||||
any_no_mot.duration = 4;
|
||||
|
||||
/* Enabling X, Y, and Z axis for Any-motion feature */
|
||||
any_no_mot.axes_en = BMA456W_EN_ALL_AXIS;
|
||||
|
||||
/* Like threshold and duration, we can also change the config of int_bhvr and slope */
|
||||
|
||||
/* Set the threshold and duration configuration */
|
||||
rslt = bma456w_set_any_mot_config(&any_no_mot, bma);
|
||||
bma4_error_codes_print_result("bma456w_set_any_mot_config status", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
/* Getting no-motion configuration to get default configuration */
|
||||
rslt = bma456w_get_no_mot_config(&any_no_mot, bma);
|
||||
bma4_error_codes_print_result("bma456w_get_no_mot_config status", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
/*
|
||||
* Set the slope threshold:
|
||||
* Interrupt will be generated if the slope of all the axis exceeds the threshold (1 bit = 0.48mG)
|
||||
*/
|
||||
any_no_mot.threshold = 10;
|
||||
|
||||
/*
|
||||
* Set the duration for no-motion interrupt:
|
||||
* Duration defines the number of consecutive data points for which threshold condition must be
|
||||
* true(1 bit = 20ms)
|
||||
*/
|
||||
any_no_mot.duration = 4;
|
||||
|
||||
/* Enabling X, Y, and Z axis for no-motion feature */
|
||||
any_no_mot.axes_en = BMA456W_EN_ALL_AXIS;
|
||||
|
||||
/* Like threshold and duration, we can also change the config of int_bhvr */
|
||||
|
||||
/* Set the threshold and duration configuration */
|
||||
rslt = bma456w_set_no_mot_config(&any_no_mot, bma);
|
||||
bma4_error_codes_print_result("bma456w_set_no_mot_config status", rslt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*/
|
||||
static void get_board_info(uint8_t *board)
|
||||
{
|
||||
struct coines_board_info board_info;
|
||||
int16_t result;
|
||||
|
||||
result = coines_get_board_info(&board_info);
|
||||
|
||||
if (result == COINES_SUCCESS)
|
||||
{
|
||||
(*board) = board_info.board;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= step_activity.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,127 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Function */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Variable to store the status of API */
|
||||
int8_t rslt;
|
||||
|
||||
/* Sensor initialization configuration */
|
||||
struct bma4_dev bma = { 0 };
|
||||
|
||||
/* Variable to store step activity interrupt status */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Variable to hold iteration value */
|
||||
uint8_t loop = 1;
|
||||
|
||||
/* Variable to store activity status */
|
||||
uint8_t activity_output = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&bma, BMA4_I2C_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Sensor initialization */
|
||||
rslt = bma456w_init(&bma);
|
||||
bma4_error_codes_print_result("bma456w_init status", rslt);
|
||||
|
||||
/* Upload the configuration file to enable the features of the sensor. */
|
||||
rslt = bma456w_write_config_file(&bma);
|
||||
bma4_error_codes_print_result("bma456w_write_config status", rslt);
|
||||
|
||||
/* Enable the accelerometer */
|
||||
rslt = bma4_set_accel_enable(BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
/* Map the interrupt 1 for step activity */
|
||||
rslt = bma456w_map_interrupt(BMA4_INTR1_MAP, BMA456W_ACTIVITY_INT, BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma456w_map_interrupt status", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
/* Setting watermark level 1, the output step resolution is 20 steps.
|
||||
* Eg: 1 means, 1 * 20 = 20. Every 20 steps once output triggers
|
||||
*/
|
||||
rslt = bma456w_step_counter_set_watermark(1, &bma);
|
||||
bma4_error_codes_print_result("bma456w_step_counter_set_watermark status", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
/* Enabling step detector feature */
|
||||
rslt = bma456w_feature_enable(BMA456W_STEP_ACT, BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma456w_feature_enable status", rslt);
|
||||
}
|
||||
}
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("Move the board in steps to perform step activity\n");
|
||||
|
||||
while (loop <= 5)
|
||||
{
|
||||
/* Read interrupt status */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status", rslt);
|
||||
|
||||
/* Filtering only the activity interrupt */
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA456W_ACTIVITY_INT))
|
||||
{
|
||||
printf("\nIteration : %d\n", loop);
|
||||
|
||||
/* Get step activity output */
|
||||
rslt = bma456w_activity_output(&activity_output, &bma);
|
||||
bma4_error_codes_print_result("bma456w_activity_output status", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("The Activity output is %d\n", activity_output);
|
||||
|
||||
switch (activity_output)
|
||||
{
|
||||
case BMA456W_USER_STATIONARY:
|
||||
printf("User state is stationary\n");
|
||||
break;
|
||||
case BMA456W_USER_WALKING:
|
||||
printf("User state is walking\n");
|
||||
break;
|
||||
case BMA456W_USER_RUNNING:
|
||||
printf("User state is running\n");
|
||||
break;
|
||||
case BMA456W_STATE_INVALID:
|
||||
printf("User state is invalid state\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
loop++;
|
||||
}
|
||||
}
|
||||
|
||||
int_status = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= step_activity_hw_int.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
TARGET = MCU_APP30
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,251 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Global variable Declaration */
|
||||
|
||||
volatile uint8_t interrupt_status = 0;
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! APP20 Board number */
|
||||
#define BOARD_MCU_APP20 UINT8_C(0x03)
|
||||
|
||||
/*! APP30 Board number */
|
||||
#define BOARD_MCU_APP30 UINT8_C(0x05)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*
|
||||
* @param[out] board : Board value to determine as APP2.0 or APP3.0
|
||||
*/
|
||||
static void get_board_info(uint8_t *board);
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set the interrupt status
|
||||
*/
|
||||
static void interrupt_callback(uint32_t param1, uint32_t param2)
|
||||
{
|
||||
(void)param1;
|
||||
(void)param2;
|
||||
interrupt_status = 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Function */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Variable to store the status of API */
|
||||
int8_t rslt;
|
||||
|
||||
/* Sensor initialization configuration */
|
||||
struct bma4_dev bma = { 0 };
|
||||
|
||||
/* Variable to store step activity interrupt status */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Variable to hold iteration value */
|
||||
uint8_t loop = 1;
|
||||
|
||||
/* Variable to store activity status */
|
||||
uint8_t activity_output = 0;
|
||||
|
||||
struct bma4_int_pin_config pin_config = { 0 };
|
||||
uint8_t board = 0;
|
||||
|
||||
/* Variable for interrupt line selection*/
|
||||
uint8_t int_line;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&bma, BMA4_I2C_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Sensor initialization */
|
||||
rslt = bma456w_init(&bma);
|
||||
bma4_error_codes_print_result("bma456w_init status", rslt);
|
||||
|
||||
/* Upload the configuration file to enable the features of the sensor. */
|
||||
rslt = bma456w_write_config_file(&bma);
|
||||
bma4_error_codes_print_result("bma456w_write_config status", rslt);
|
||||
|
||||
/* Enable the accelerometer */
|
||||
rslt = bma4_set_accel_enable(BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
/* Setting watermark level 1, the output step resolution is 20 steps.
|
||||
* Eg: 1 means, 1 * 20 = 20. Every 20 steps once output triggers
|
||||
*/
|
||||
rslt = bma456w_step_counter_set_watermark(1, &bma);
|
||||
bma4_error_codes_print_result("bma456w_step_counter_set_watermark status", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
/* Enabling step detector feature */
|
||||
rslt = bma456w_feature_enable(BMA456W_STEP_ACT, BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma456w_feature_enable status", rslt);
|
||||
}
|
||||
}
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
/* Hardware interrupt configuration */
|
||||
int_line = BMA4_INTR1_MAP;
|
||||
|
||||
rslt = bma4_get_int_pin_config(&pin_config, int_line, &bma);
|
||||
bma4_error_codes_print_result("bma4_get_int_pin_config status", rslt);
|
||||
|
||||
rslt = bma456w_map_interrupt(int_line, BMA456W_ACTIVITY_INT, BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma456w_map_interrupt status", rslt);
|
||||
|
||||
pin_config.edge_ctrl = BMA4_EDGE_TRIGGER;
|
||||
pin_config.output_en = BMA4_OUTPUT_ENABLE;
|
||||
pin_config.lvl = BMA4_ACTIVE_HIGH;
|
||||
pin_config.od = BMA4_PUSH_PULL;
|
||||
pin_config.input_en = BMA4_INPUT_DISABLE;
|
||||
|
||||
rslt = bma4_set_int_pin_config(&pin_config, int_line, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_int_pin_config status", rslt);
|
||||
|
||||
/* Get board information */
|
||||
get_board_info(&board);
|
||||
|
||||
/*
|
||||
* Attach interrupt based on board
|
||||
*/
|
||||
if (board == BOARD_MCU_APP20)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_20, interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_21, interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(MCU_APP20)
|
||||
else if (board == BOARD_MCU_APP30)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_6,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_7,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("Move the board in steps to perform step activity\n");
|
||||
|
||||
while (loop <= 5)
|
||||
{
|
||||
if (interrupt_status == 1)
|
||||
{
|
||||
interrupt_status = 0;
|
||||
|
||||
/* Read interrupt status */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status", rslt);
|
||||
|
||||
/* Filtering only the activity interrupt */
|
||||
if ((rslt == BMA4_OK) && (int_status & BMA456W_ACTIVITY_INT))
|
||||
{
|
||||
printf("\nIteration : %d\n", loop);
|
||||
|
||||
/* Get step activity output */
|
||||
rslt = bma456w_activity_output(&activity_output, &bma);
|
||||
bma4_error_codes_print_result("bma456w_activity_output status", rslt);
|
||||
|
||||
if (rslt == BMA4_OK)
|
||||
{
|
||||
printf("The Activity output is %d\n", activity_output);
|
||||
|
||||
switch (activity_output)
|
||||
{
|
||||
case BMA456W_USER_STATIONARY:
|
||||
printf("User state is stationary\n");
|
||||
break;
|
||||
case BMA456W_USER_WALKING:
|
||||
printf("User state is walking\n");
|
||||
break;
|
||||
case BMA456W_USER_RUNNING:
|
||||
printf("User state is running\n");
|
||||
break;
|
||||
case BMA456W_STATE_INVALID:
|
||||
printf("User state is invalid state\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
loop++;
|
||||
}
|
||||
}
|
||||
|
||||
int_status = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*/
|
||||
static void get_board_info(uint8_t *board)
|
||||
{
|
||||
struct coines_board_info board_info;
|
||||
int16_t result;
|
||||
|
||||
result = coines_get_board_info(&board_info);
|
||||
|
||||
if (result == COINES_SUCCESS)
|
||||
{
|
||||
(*board) = board_info.board;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= step_counter.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,91 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Function */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Variable to store the status of API */
|
||||
int8_t rslt;
|
||||
|
||||
/* Sensor initialization configuration */
|
||||
struct bma4_dev bma = { 0 };
|
||||
|
||||
/* Variable to store step counter interrupt status */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Variable to store step counter status */
|
||||
uint32_t step_out = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&bma, BMA4_I2C_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Sensor initialization */
|
||||
rslt = bma456w_init(&bma);
|
||||
bma4_error_codes_print_result("bma456w_init status", rslt);
|
||||
|
||||
/* Upload the configuration file to enable the features of the sensor. */
|
||||
rslt = bma456w_write_config_file(&bma);
|
||||
bma4_error_codes_print_result("bma456w_write_config status", rslt);
|
||||
|
||||
/* Enable accelerometer to perform feature testing */
|
||||
rslt = bma4_set_accel_enable(BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
rslt = bma456w_feature_enable(BMA456W_STEP_CNTR, BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma456w_feature_enable status", rslt);
|
||||
|
||||
rslt = bma456w_map_interrupt(BMA4_INTR1_MAP, BMA456W_STEP_CNTR_INT, BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma456w_map_interrupt status", rslt);
|
||||
|
||||
/* Setting watermark level 1, the output step resolution is 20 steps.
|
||||
* Eg: 1 means, 1 * 20 = 20. Every 20 steps once output triggers
|
||||
*/
|
||||
rslt = bma456w_step_counter_set_watermark(1, &bma);
|
||||
bma4_error_codes_print_result("bma456w_step_counter_set_watermark status", rslt);
|
||||
|
||||
printf("Step counter feature is enabled\n");
|
||||
|
||||
printf("Step counter watermark level is 1 (Output resolution is 20 steps)\n");
|
||||
|
||||
printf("Move the board in steps for greater than 3 seconds\n");
|
||||
|
||||
/* Loop over until step counter interrupt occurs */
|
||||
for (;;)
|
||||
{
|
||||
/* Read the interrupt status (After 20 steps, generates interrupt) */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status", rslt);
|
||||
|
||||
if ((BMA4_OK == rslt) && (int_status & BMA456W_STEP_CNTR_INT))
|
||||
{
|
||||
printf("Step counter interrupt received when watermark level is reached (20 steps)\n");
|
||||
|
||||
/* Get the step counter output after reset */
|
||||
rslt = bma456w_step_counter_output(&step_out, &bma);
|
||||
bma4_error_codes_print_result("bma456w_step_counter_output status", rslt);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("The step counter output is %lu \n", (long unsigned int)step_out);
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= step_counter_hw_int.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
TARGET = MCU_APP30
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,214 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Global variable Declaration */
|
||||
|
||||
volatile uint8_t interrupt_status = 0;
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! APP20 Board number */
|
||||
#define BOARD_MCU_APP20 UINT8_C(0x03)
|
||||
|
||||
/*! APP30 Board number */
|
||||
#define BOARD_MCU_APP30 UINT8_C(0x05)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*
|
||||
* @param[out] board : Board value to determine as APP2.0 or APP3.0
|
||||
*/
|
||||
static void get_board_info(uint8_t *board);
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set the interrupt status
|
||||
*/
|
||||
static void interrupt_callback(uint32_t param1, uint32_t param2)
|
||||
{
|
||||
(void)param1;
|
||||
(void)param2;
|
||||
interrupt_status = 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Function */
|
||||
|
||||
/* This function starts the execution of program. */
|
||||
int main(void)
|
||||
{
|
||||
/* Variable to store the status of API */
|
||||
int8_t rslt;
|
||||
|
||||
/* Sensor initialization configuration */
|
||||
struct bma4_dev bma = { 0 };
|
||||
|
||||
/* Variable to store step counter interrupt status */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Variable to store step counter status */
|
||||
uint32_t step_out = 0;
|
||||
|
||||
struct bma4_int_pin_config pin_config = { 0 };
|
||||
uint8_t board = 0;
|
||||
|
||||
/* Variable for interrupt line selection*/
|
||||
uint8_t int_line;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&bma, BMA4_SPI_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Sensor initialization */
|
||||
rslt = bma456w_init(&bma);
|
||||
bma4_error_codes_print_result("bma456w_init status", rslt);
|
||||
|
||||
/* Upload the configuration file to enable the features of the sensor. */
|
||||
rslt = bma456w_write_config_file(&bma);
|
||||
bma4_error_codes_print_result("bma456w_write_config status", rslt);
|
||||
|
||||
/* Enable accelerometer to perform feature testing */
|
||||
rslt = bma4_set_accel_enable(BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
rslt = bma456w_feature_enable(BMA456W_STEP_CNTR, BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma456w_feature_enable status", rslt);
|
||||
|
||||
/* Setting watermark level 1, the output step resolution is 20 steps.
|
||||
* Eg: 1 means, 1 * 20 = 20. Every 20 steps once output triggers
|
||||
*/
|
||||
rslt = bma456w_step_counter_set_watermark(1, &bma);
|
||||
bma4_error_codes_print_result("bma456w_step_counter_set_watermark status", rslt);
|
||||
|
||||
/* Hardware interrupt configuration */
|
||||
int_line = BMA4_INTR2_MAP;
|
||||
|
||||
rslt = bma4_get_int_pin_config(&pin_config, int_line, &bma);
|
||||
bma4_error_codes_print_result("bma4_get_int_pin_config status", rslt);
|
||||
|
||||
rslt = bma456w_map_interrupt(int_line, BMA456W_STEP_CNTR_INT, BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma456w_map_interrupt status", rslt);
|
||||
|
||||
pin_config.edge_ctrl = BMA4_EDGE_TRIGGER;
|
||||
pin_config.output_en = BMA4_OUTPUT_ENABLE;
|
||||
pin_config.lvl = BMA4_ACTIVE_HIGH;
|
||||
pin_config.od = BMA4_PUSH_PULL;
|
||||
pin_config.input_en = BMA4_INPUT_DISABLE;
|
||||
|
||||
rslt = bma4_set_int_pin_config(&pin_config, int_line, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_int_pin_config status", rslt);
|
||||
|
||||
/* Get board information */
|
||||
get_board_info(&board);
|
||||
|
||||
/*
|
||||
* Attach interrupt based on board
|
||||
*/
|
||||
if (board == BOARD_MCU_APP20)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_20, interrupt_callback, COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_21, interrupt_callback, COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(MCU_APP20)
|
||||
else if (board == BOARD_MCU_APP30)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_6,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_7,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
printf("Step counter feature is enabled\n");
|
||||
|
||||
printf("Step counter watermark level is 1 (Output resolution is 20 steps)\n");
|
||||
|
||||
printf("Move the board in steps for greater than 3 seconds\n");
|
||||
|
||||
/* Loop over until step counter interrupt occurs */
|
||||
for (;;)
|
||||
{
|
||||
if (interrupt_status == 1)
|
||||
{
|
||||
interrupt_status = 0;
|
||||
|
||||
/* Read the interrupt status (After 20 steps, generates interrupt) */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status", rslt);
|
||||
|
||||
if ((BMA4_OK == rslt) && (int_status & BMA456W_STEP_CNTR_INT))
|
||||
{
|
||||
printf("Step counter interrupt received when watermark level is reached (20 steps)\n");
|
||||
|
||||
/* Get the step counter output after reset */
|
||||
rslt = bma456w_step_counter_output(&step_out, &bma);
|
||||
bma4_error_codes_print_result("bma456w_step_counter_output status", rslt);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("The step counter output is %lu \n", (long unsigned int)step_out);
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*/
|
||||
static void get_board_info(uint8_t *board)
|
||||
{
|
||||
struct coines_board_info board_info;
|
||||
int16_t result;
|
||||
|
||||
result = coines_get_board_info(&board_info);
|
||||
|
||||
if (result == COINES_SUCCESS)
|
||||
{
|
||||
(*board) = board_info.board;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= wrist_wear_wakeup.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
@@ -0,0 +1,127 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct bma4_dev bma;
|
||||
struct bma4_accel_config accel_conf;
|
||||
struct bma456w_wrist_wear_wakeup_params setting;
|
||||
uint8_t try = 10;
|
||||
int8_t rslt;
|
||||
|
||||
/* Variable to get the interrupt status */
|
||||
uint16_t int_status = 0;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&bma, BMA4_I2C_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Sensor initialization */
|
||||
rslt = bma456w_init(&bma);
|
||||
bma4_error_codes_print_result("bma456w_init", rslt);
|
||||
|
||||
/* Upload the configuration file to enable the features of the sensor. */
|
||||
rslt = bma456w_write_config_file(&bma);
|
||||
bma4_error_codes_print_result("bma456w_write_config", rslt);
|
||||
|
||||
/* Accelerometer Configuration Setting */
|
||||
/* Output data Rate */
|
||||
accel_conf.odr = BMA4_OUTPUT_DATA_RATE_100HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G) */
|
||||
accel_conf.range = BMA4_ACCEL_RANGE_2G;
|
||||
|
||||
/* Bandwidth configure number of sensor samples required to average
|
||||
* if value = 2, then 4 samples are averaged
|
||||
* averaged samples = 2^(val(accel bandwidth))
|
||||
* Note1 : More info refer datasheets
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but since the
|
||||
* performance power mode phase is increased, the power consumption will also rise.
|
||||
*/
|
||||
accel_conf.bandwidth = BMA4_ACCEL_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 -> Averaging samples (Default)
|
||||
* 1 -> No averaging
|
||||
* For more info on No Averaging mode refer datasheets.
|
||||
*/
|
||||
accel_conf.perf_mode = BMA4_CIC_AVG_MODE;
|
||||
|
||||
/* Set the accel configurations */
|
||||
rslt = bma4_set_accel_config(&accel_conf, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_accel_config status", rslt);
|
||||
|
||||
/* NOTE : Enable accel after set of configurations */
|
||||
rslt = bma4_set_accel_enable(1, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
printf("\nEnable wear feature\n");
|
||||
|
||||
rslt = bma456w_feature_enable(BMA456W_WRIST_WEAR_WAKEUP, 1, &bma);
|
||||
bma4_error_codes_print_result("bma456w_feature_enable status", rslt);
|
||||
|
||||
rslt = bma456w_get_wrist_wear_wakeup_param_config(&setting, &bma);
|
||||
bma4_error_codes_print_result("bma456w_get_wrist_wear_wakeup_param_config status", rslt);
|
||||
|
||||
rslt = bma456w_map_interrupt(BMA4_INTR1_MAP, BMA456W_WRIST_WEAR_WAKEUP_INT, BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma456w_map_interrupt status", rslt);
|
||||
|
||||
printf("Do wear movement\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Read the interrupt register to check whether wrist wear interrupt is received. */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status status", rslt);
|
||||
|
||||
/* Check if step counter interrupt is triggered */
|
||||
if ((BMA4_OK == rslt) && (int_status & BMA456W_WRIST_WEAR_WAKEUP_INT))
|
||||
{
|
||||
printf("\nWear interrupt is received\n\n");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\nDisable wear feature\n");
|
||||
rslt = bma456w_feature_enable(BMA456W_WRIST_WEAR_WAKEUP, BMA4_DISABLE, &bma);
|
||||
bma4_error_codes_print_result("bma456w_feature_enable status", rslt);
|
||||
|
||||
rslt = bma456w_map_interrupt(BMA4_INTR1_MAP, BMA456W_WRIST_WEAR_WAKEUP_INT, BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma456w_map_interrupt status", rslt);
|
||||
|
||||
printf("Do wear movement\n\n");
|
||||
|
||||
while (try--)
|
||||
{
|
||||
rslt = bma456w_read_int_status(&int_status, &bma);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status status", rslt);
|
||||
|
||||
if (int_status & BMA456W_WRIST_WEAR_WAKEUP_INT)
|
||||
{
|
||||
printf("Wear interrupt is received, Test is failed\n");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Wear feature disable and wear interrupt not received\n");
|
||||
}
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
COINES_INSTALL_PATH ?= ../../../..
|
||||
|
||||
EXAMPLE_FILE ?= wrist_wear_wakeup_hw_int.c
|
||||
|
||||
API_LOCATION ?= ../..
|
||||
|
||||
COMMON_LOCATION ?= ..
|
||||
|
||||
C_SRCS += \
|
||||
$(API_LOCATION)/bma4.c \
|
||||
$(API_LOCATION)/bma456w.c \
|
||||
$(COMMON_LOCATION)/common/common.c
|
||||
|
||||
INCLUDEPATHS += \
|
||||
$(API_LOCATION) \
|
||||
$(COMMON_LOCATION)/common
|
||||
|
||||
TARGET = MCU_APP30
|
||||
|
||||
include $(COINES_INSTALL_PATH)/coines.mk
|
||||
+251
@@ -0,0 +1,251 @@
|
||||
/**\
|
||||
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "bma456w.h"
|
||||
#include "common.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Global variable Declaration */
|
||||
|
||||
volatile uint8_t interrupt_status = 0;
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Macro definition */
|
||||
|
||||
/*! APP20 Board number */
|
||||
#define BOARD_MCU_APP20 UINT8_C(0x03)
|
||||
|
||||
/*! APP30 Board number */
|
||||
#define BOARD_MCU_APP30 UINT8_C(0x05)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Static Function Declaration */
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*
|
||||
* @param[out] board : Board value to determine as APP2.0 or APP3.0
|
||||
*/
|
||||
static void get_board_info(uint8_t *board);
|
||||
|
||||
/*!
|
||||
* @brief This internal API is used to set the interrupt status
|
||||
*/
|
||||
static void interrupt_callback(uint32_t param1, uint32_t param2)
|
||||
{
|
||||
(void)param1;
|
||||
(void)param2;
|
||||
interrupt_status = 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*! Function */
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct bma4_dev bma;
|
||||
struct bma4_accel_config accel_conf;
|
||||
struct bma456w_wrist_wear_wakeup_params setting;
|
||||
uint8_t try = 10;
|
||||
int8_t rslt;
|
||||
|
||||
uint16_t int_status = 0;
|
||||
uint8_t board = 0;
|
||||
struct bma4_int_pin_config pin_config = { 0 };
|
||||
|
||||
/* Variable for interrupt line selection*/
|
||||
uint8_t int_line;
|
||||
|
||||
/* Interface reference is given as a parameter
|
||||
* For I2C : BMA4_I2C_INTF
|
||||
* For SPI : BMA4_SPI_INTF
|
||||
* Variant information given as parameter - BMA45X_VARIANT
|
||||
*/
|
||||
rslt = bma4_interface_init(&bma, BMA4_I2C_INTF, BMA45X_VARIANT);
|
||||
bma4_error_codes_print_result("bma4_interface_init", rslt);
|
||||
|
||||
/* Sensor initialization */
|
||||
rslt = bma456w_init(&bma);
|
||||
bma4_error_codes_print_result("bma456w_init", rslt);
|
||||
|
||||
/* Upload the configuration file to enable the features of the sensor. */
|
||||
rslt = bma456w_write_config_file(&bma);
|
||||
bma4_error_codes_print_result("bma456w_write_config", rslt);
|
||||
|
||||
/* Accelerometer Configuration Setting */
|
||||
/* Output data Rate */
|
||||
accel_conf.odr = BMA4_OUTPUT_DATA_RATE_100HZ;
|
||||
|
||||
/* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G) */
|
||||
accel_conf.range = BMA4_ACCEL_RANGE_2G;
|
||||
|
||||
/* Bandwidth configure number of sensor samples required to average
|
||||
* if value = 2, then 4 samples are averaged
|
||||
* averaged samples = 2^(val(accel bandwidth))
|
||||
* Note1 : More info refer datasheets
|
||||
* Note2 : A higher number of averaged samples will result in a lower noise level of the signal, but since the
|
||||
* performance power mode phase is increased, the power consumption will also rise.
|
||||
*/
|
||||
accel_conf.bandwidth = BMA4_ACCEL_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 -> Averaging samples (Default)
|
||||
* 1 -> No averaging
|
||||
* For more info on No Averaging mode refer datasheets.
|
||||
*/
|
||||
accel_conf.perf_mode = BMA4_CIC_AVG_MODE;
|
||||
|
||||
/* Set the accel configurations */
|
||||
rslt = bma4_set_accel_config(&accel_conf, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_accel_config status", rslt);
|
||||
|
||||
/* NOTE : Enable accel after set of configurations */
|
||||
rslt = bma4_set_accel_enable(1, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
|
||||
|
||||
printf("\nEnable wear feature\n");
|
||||
|
||||
rslt = bma456w_feature_enable(BMA456W_WRIST_WEAR_WAKEUP, 1, &bma);
|
||||
bma4_error_codes_print_result("bma456w_feature_enable status", rslt);
|
||||
|
||||
rslt = bma456w_get_wrist_wear_wakeup_param_config(&setting, &bma);
|
||||
bma4_error_codes_print_result("bma456w_get_wrist_wear_wakeup_param_config status", rslt);
|
||||
|
||||
/* Hardware interrupt configuration */
|
||||
int_line = BMA4_INTR1_MAP;
|
||||
|
||||
rslt = bma4_get_int_pin_config(&pin_config, int_line, &bma);
|
||||
bma4_error_codes_print_result("bma4_get_int_pin_config status", rslt);
|
||||
|
||||
rslt = bma456w_map_interrupt(int_line, BMA456W_WRIST_WEAR_WAKEUP_INT, BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma456w_map_interrupt status", rslt);
|
||||
|
||||
pin_config.edge_ctrl = BMA4_EDGE_TRIGGER;
|
||||
pin_config.output_en = BMA4_OUTPUT_ENABLE;
|
||||
pin_config.lvl = BMA4_ACTIVE_HIGH;
|
||||
pin_config.od = BMA4_PUSH_PULL;
|
||||
pin_config.input_en = BMA4_INPUT_DISABLE;
|
||||
|
||||
rslt = bma4_set_int_pin_config(&pin_config, int_line, &bma);
|
||||
bma4_error_codes_print_result("bma4_set_int_pin_config status", rslt);
|
||||
|
||||
/* Get board information */
|
||||
get_board_info(&board);
|
||||
|
||||
/*
|
||||
* Attach interrupt based on board
|
||||
*/
|
||||
if (board == BOARD_MCU_APP20)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_20, interrupt_callback, COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_SHUTTLE_PIN_21, interrupt_callback, COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(MCU_APP20)
|
||||
else if (board == BOARD_MCU_APP30)
|
||||
{
|
||||
switch (int_line)
|
||||
{
|
||||
case BMA4_INTR1_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_6,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
case BMA4_INTR2_MAP:
|
||||
coines_attach_interrupt(COINES_MINI_SHUTTLE_PIN_1_7,
|
||||
interrupt_callback,
|
||||
COINES_PIN_INTERRUPT_RISING_EDGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
printf("Do wear movement\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (interrupt_status == 1)
|
||||
{
|
||||
interrupt_status = 0;
|
||||
|
||||
/* Read the interrupt register to check whether wrist wear interrupt is received. */
|
||||
rslt = bma456w_read_int_status(&int_status, &bma);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status status", rslt);
|
||||
|
||||
/* Check if step counter interrupt is triggered */
|
||||
if ((BMA4_OK == rslt) && (int_status & BMA456W_WRIST_WEAR_WAKEUP_INT))
|
||||
{
|
||||
printf("\nWear interrupt is received\n\n");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("\nDisable wear feature\n");
|
||||
rslt = bma456w_feature_enable(BMA456W_WRIST_WEAR_WAKEUP, BMA4_DISABLE, &bma);
|
||||
bma4_error_codes_print_result("bma456w_feature_enable status", rslt);
|
||||
|
||||
rslt = bma456w_map_interrupt(BMA4_INTR1_MAP, BMA456W_WRIST_WEAR_WAKEUP_INT, BMA4_ENABLE, &bma);
|
||||
bma4_error_codes_print_result("bma456w_map_interrupt status", rslt);
|
||||
|
||||
printf("Do wear movement\n\n");
|
||||
|
||||
while (try--)
|
||||
{
|
||||
rslt = bma456w_read_int_status(&int_status, &bma);
|
||||
bma4_error_codes_print_result("bma456w_read_int_status status", rslt);
|
||||
|
||||
if (int_status & BMA456W_WRIST_WEAR_WAKEUP_INT)
|
||||
{
|
||||
printf("Wear interrupt is received, Test is failed\n");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Wear feature disable and wear interrupt not received\n");
|
||||
}
|
||||
}
|
||||
|
||||
bma4_coines_deinit();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This function gets board information
|
||||
*/
|
||||
static void get_board_info(uint8_t *board)
|
||||
{
|
||||
struct coines_board_info board_info;
|
||||
int16_t result;
|
||||
|
||||
result = coines_get_board_info(&board_info);
|
||||
|
||||
if (result == COINES_SUCCESS)
|
||||
{
|
||||
(*board) = board_info.board;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user