diff --git a/LICENSE b/LICENSE index df241f2..315dfa2 100644 --- a/LICENSE +++ b/LICENSE @@ -6,15 +6,15 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT diff --git a/README.md b/README.md index 473a8f8..a29e977 100644 --- a/README.md +++ b/README.md @@ -1,793 +1,42 @@ -# BMI160 sensor API -## Introduction -This package contains the Bosch Sensortec's BMI160 sensor driver (sensor API) - -The sensor driver package includes bmi160.h, bmi160.c and bmi160_defs.h files - -## Version -File | Version | Date ---------------|---------|--------------- -bmi160.c | 3.8.1 | 11 Jan 2020 -bmi160.h | 3.8.1 | 11 Jan 2020 -bmi160_defs.h | 3.8.1 | 11 Jan 2020 - -## Integration details -* Integrate bmi160.h, bmi160_defs.h and bmi160.c file in to your project. -* Include the bmi160.h file in your code like below. -``` c -#include "bmi160.h" -``` - -## File information -* bmi160_defs.h : This header file has the constants, macros and datatype declarations. -* bmi160.h : This header file contains the declarations of the sensor driver APIs. -* bmi160.c : This source file contains the definitions of the sensor driver APIs. - -## Supported sensor interface -* SPI 4-wire -* I2C - -## Usage guide -### Initializing the sensor -To initialize the sensor, you will first need to create a device structure. You -can do this by creating an instance of the structure bmi160_dev. Then go on to -fill in the various parameters as shown below. - -#### Example for SPI 4-Wire -``` c -struct bmi160_dev sensor; - -/* You may assign a chip select identifier to be handled later */ -sensor.id = 0; -sensor.interface = BMI160_SPI_INTF; -sensor.read = user_spi_read; -sensor.write = user_spi_write; -sensor.delay_ms = user_delay_ms; - - -int8_t rslt = BMI160_OK; -rslt = bmi160_init(&sensor); -/* After the above function call, accel_cfg and gyro_cfg parameters in the device -structure are set with default values, found in the datasheet of the sensor */ -``` - -#### Example for I2C -``` c -struct bmi160_dev sensor; - -sensor.id = BMI160_I2C_ADDR; -sensor.interface = BMI160_I2C_INTF; -sensor.read = user_i2c_read; -sensor.write = user_i2c_write; -sensor.delay_ms = user_delay_ms; - -int8_t rslt = BMI160_OK; -rslt = bmi160_init(&sensor); -/* After the above function call, accel and gyro parameters in the device structure -are set with default values, found in the datasheet of the sensor */ -``` - -### Configuring accel and gyro sensor -#### Example for configuring accel and gyro sensors in normal mode -``` c - -int8_t rslt = BMI160_OK; - -/* Select the Output data rate, range of accelerometer sensor */ -sensor.accel_cfg.odr = BMI160_ACCEL_ODR_1600HZ; -sensor.accel_cfg.range = BMI160_ACCEL_RANGE_2G; -sensor.accel_cfg.bw = BMI160_ACCEL_BW_NORMAL_AVG4; - -/* Select the power mode of accelerometer sensor */ -sensor.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE; - -/* Select the Output data rate, range of Gyroscope sensor */ -sensor.gyro_cfg.odr = BMI160_GYRO_ODR_3200HZ; -sensor.gyro_cfg.range = BMI160_GYRO_RANGE_2000_DPS; -sensor.gyro_cfg.bw = BMI160_GYRO_BW_NORMAL_MODE; - -/* Select the power mode of Gyroscope sensor */ -sensor.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE; - -/* Set the sensor configuration */ -rslt = bmi160_set_sens_conf(&sensor); -``` - -### Reading sensor data -#### Example for reading sensor data -``` c - -int8_t rslt = BMI160_OK; -struct bmi160_sensor_data accel; -struct bmi160_sensor_data gyro; - -/* To read only Accel data */ -rslt = bmi160_get_sensor_data(BMI160_ACCEL_SEL, &accel, NULL, &sensor); - -/* To read only Gyro data */ -rslt = bmi160_get_sensor_data(BMI160_GYRO_SEL, NULL, &gyro, &sensor); - -/* To read both Accel and Gyro data */ -bmi160_get_sensor_data((BMI160_ACCEL_SEL | BMI160_GYRO_SEL), &accel, &gyro, &sensor); - -/* To read Accel data along with time */ -rslt = bmi160_get_sensor_data((BMI160_ACCEL_SEL | BMI160_TIME_SEL) , &accel, NULL, &sensor); - -/* To read Gyro data along with time */ -rslt = bmi160_get_sensor_data((BMI160_GYRO_SEL | BMI160_TIME_SEL), NULL, &gyro, &sensor); - -/* To read both Accel and Gyro data along with time*/ -bmi160_get_sensor_data((BMI160_ACCEL_SEL | BMI160_GYRO_SEL | BMI160_TIME_SEL), &accel, &gyro, &sensor); -``` - -### Setting the power mode of sensors -#### Example for setting power mode of accel and gyro -``` c - -int8_t rslt = BMI160_OK; - -/* Select the power mode */ -sensor.accel_cfg.power = BMI160_ACCEL_SUSPEND_MODE; -sensor.gyro_cfg.power = BMI160_GYRO_FASTSTARTUP_MODE; - -/* Set the Power mode */ -rslt = bmi160_set_power_mode(&sensor); - -/* Select the power mode */ -sensor.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE; -sensor.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE; - -/* Set the Power mode */ -rslt = bmi160_set_power_mode(&sensor); - -``` - -### Reading sensor data register -#### Example for reading Chip Address -``` c - -int8_t rslt = BMI160_OK; -uint8_t reg_addr = BMI160_CHIP_ID_ADDR; -uint8_t data; -uint16_t len = 1; -rslt = bmi160_get_regs(reg_addr, &data, len, &sensor); -``` - - -### Writing to sensor data register -#### Example for writing data to any motion threshold register -``` c - -int8_t rslt = BMI160_OK; -uint8_t reg_addr = BMI160_INT_MOTION_1_ADDR; -uint8_t data = 20; -uint16_t len = 1; -rslt = bmi160_set_regs(reg_addr, &data, len, &sensor); -``` - -### Resetting the device using soft-reset -#### Example for writing soft-reset command to command register -``` c - -int8_t rslt = BMI160_OK; -rslt = bmi160_soft_reset(&sensor); -``` - - -### Configuring interrupts for sensors -To configure the sensor interrupts, you will first need to create an interrupt -structure. You can do this by creating an instance of the structure bmi160_int_settg. -Then go on to fill in the various parameters as shown below - - -### Configuring Any-motion Interrupt -#### Example for configuring Any-motion Interrupt -Note:- User can check the currently active interrupt(any-motion or sig-motion) by checking the **any_sig_sel** of bmi160_dev structure. -``` c - -struct bmi160_int_settg int_config; - -/* Select the Interrupt channel/pin */ -int_config.int_channel = BMI160_INT_CHANNEL_1;// Interrupt channel/pin 1 - -/* Select the Interrupt type */ -int_config.int_type = BMI160_ACC_ANY_MOTION_INT;// Choosing Any motion interrupt -/* Select the interrupt channel/pin settings */ -int_config.int_pin_settg.output_en = BMI160_ENABLE;// Enabling interrupt pins to act as output pin -int_config.int_pin_settg.output_mode = BMI160_DISABLE;// Choosing push-pull mode for interrupt pin -int_config.int_pin_settg.output_type = BMI160_DISABLE;// Choosing active low output -int_config.int_pin_settg.edge_ctrl = BMI160_ENABLE;// Choosing edge triggered output -int_config.int_pin_settg.input_en = BMI160_DISABLE;// Disabling interrupt pin to act as input -int_config.int_pin_settg.latch_dur = BMI160_LATCH_DUR_NONE;// non-latched output - -/* Select the Any-motion interrupt parameters */ -int_config.int_type_cfg.acc_any_motion_int.anymotion_en = BMI160_ENABLE;// 1- Enable the any-motion, 0- disable any-motion -int_config.int_type_cfg.acc_any_motion_int.anymotion_x = BMI160_ENABLE;// Enabling x-axis for any motion interrupt -int_config.int_type_cfg.acc_any_motion_int.anymotion_y = BMI160_ENABLE;// Enabling y-axis for any motion interrupt -int_config.int_type_cfg.acc_any_motion_int.anymotion_z = BMI160_ENABLE;// Enabling z-axis for any motion interrupt -int_config.int_type_cfg.acc_any_motion_int.anymotion_dur = 0;// any-motion duration -int_config.int_type_cfg.acc_any_motion_int.anymotion_thr = 20;// (2-g range) -> (slope_thr) * 3.91 mg, (4-g range) -> (slope_thr) * 7.81 mg, (8-g range) ->(slope_thr) * 15.63 mg, (16-g range) -> (slope_thr) * 31.25 mg - -/* Set the Any-motion interrupt */ -bmi160_set_int_config(&int_config, &sensor); /* sensor is an instance of the structure bmi160_dev */ - -``` -### Configuring Flat Interrupt -#### Example for configuring Flat Interrupt -``` c - -struct bmi160_int_settg int_config; - -/* Select the Interrupt channel/pin */ -int_config.int_channel = BMI160_INT_CHANNEL_1;// Interrupt channel/pin 1 - -/* Select the Interrupt type */ -int_config.int_type = BMI160_ACC_FLAT_INT;// Choosing flat interrupt -/* Select the interrupt channel/pin settings */ -int_config.int_pin_settg.output_en = BMI160_ENABLE;// Enabling interrupt pins to act as output pin -int_config.int_pin_settg.output_mode = BMI160_DISABLE;// Choosing push-pull mode for interrupt pin -int_config.int_pin_settg.output_type = BMI160_DISABLE;// Choosing active low output -int_config.int_pin_settg.edge_ctrl = BMI160_ENABLE;// Choosing edge triggered output -int_config.int_pin_settg.input_en = BMI160_DISABLE;// Disabling interrupt pin to act as input -int_config.int_pin_settg.latch_dur = BMI160_LATCH_DUR_NONE;// non-latched output - -/* Select the Flat interrupt parameters */ -int_config.int_type_cfg.acc_flat_int.flat_en = BMI160_ENABLE;// 1-enable, 0-disable the flat interrupt -int_config.int_type_cfg.acc_flat_int.flat_theta = 8;// threshold for detection of flat position in range from 0° to 44.8°. -int_config.int_type_cfg.acc_flat_int.flat_hy = 1;// Flat hysteresis -int_config.int_type_cfg.acc_flat_int.flat_hold_time = 1;// Flat hold time (0 -> 0 ms, 1 -> 640 ms, 2 -> 1280 ms, 3 -> 2560 ms) - -/* Set the Flat interrupt */ -bmi160_set_int_config(&int_config, &sensor); /* sensor is an instance of the structure bmi160_dev */ - -``` - - -### Configuring Step Detector Interrupt -#### Example for configuring Step Detector Interrupt -``` c - -struct bmi160_int_settg int_config; - -/* Select the Interrupt channel/pin */ -int_config.int_channel = BMI160_INT_CHANNEL_1;// Interrupt channel/pin 1 - -/* Select the Interrupt type */ -int_config.int_type = BMI160_STEP_DETECT_INT;// Choosing Step Detector interrupt -/* Select the interrupt channel/pin settings */ -int_config.int_pin_settg.output_en = BMI160_ENABLE;// Enabling interrupt pins to act as output pin -int_config.int_pin_settg.output_mode = BMI160_DISABLE;// Choosing push-pull mode for interrupt pin -int_config.int_pin_settg.output_type = BMI160_ENABLE;// Choosing active High output -int_config.int_pin_settg.edge_ctrl = BMI160_ENABLE;// Choosing edge triggered output -int_config.int_pin_settg.input_en = BMI160_DISABLE;// Disabling interrupt pin to act as input -int_config.int_pin_settg.latch_dur =BMI160_LATCH_DUR_NONE;// non-latched output - -/* Select the Step Detector interrupt parameters, Kindly use the recommended settings for step detector */ -int_config.int_type_cfg.acc_step_detect_int.step_detector_mode = BMI160_STEP_DETECT_NORMAL; -int_config.int_type_cfg.acc_step_detect_int.step_detector_en = BMI160_ENABLE;// 1-enable, 0-disable the step detector - -/* Set the Step Detector interrupt */ -bmi160_set_int_config(&int_config, &sensor); /* sensor is an instance of the structure bmi160_dev */ - -``` - -### Configuring Step counter -To configure the step counter, user need to configure the step detector interrupt as described in above section. -After configuring step detector, see the below code snippet for user space & ISR - -### User space -``` c -int8_t rslt = BMI160_OK; -uint8_t step_enable = 1;//enable the step counter - -rslt = bmi160_set_step_counter(step_enable, &sensor); -``` - -### ISR -``` c -int8_t rslt = BMI160_OK; -uint16_t step_count = 0;//stores the step counter value - -rslt = bmi160_read_step_counter(&step_count, &sensor); -``` - -### Unmapping Interrupt -#### Example for unmapping Step Detector Interrupt -``` c -struct bmi160_int_settg int_config; - -/* Deselect the Interrupt channel/pin */ -int_config.int_channel = BMI160_INT_CHANNEL_NONE; -/* Select the Interrupt type */ -int_config.int_type = BMI160_STEP_DETECT_INT;// Choosing Step Detector interrupt -/* Set the Step Detector interrupt */ -bmi160_set_int_config(&int_config, &sensor); /* sensor is an instance of the structure bmi160_dev */ -``` - -### Reading interrupt status -#### Example for reading interrupt status for step detector -``` c -union bmi160_int_status interrupt; -enum bmi160_int_status_sel int_status_sel; - -/* Interrupt status selection to read all interrupts */ -int_status_sel = BMI160_INT_STATUS_ALL; -rslt = bmi160_get_int_status(int_status_sel, &interrupt, &sensor); -if (interrupt.bit.step) - printf("Step detector interrupt occured\n"); -``` - -### Configuring the auxiliary sensor BMM150 -It is assumed that secondary interface of bmi160 has external pull-up resistor in order to access the auxiliary sensor bmm150. - -### Accessing auxiliary BMM150 with BMM150 APIs via BMI160 secondary interface. - -## Integration details -* Integrate the souce codes of BMM150 and BMI160 in project. -* Include the bmi160.h and bmm150.h file in your code like below. -* It is mandatory to initialize the bmi160 device structure for primary interface and auxiliary sensor settings. -* Create two wrapper functions , user_aux_read and user_aux_write in order to match the signature as mentioned below. -* Invoke the "bmi160_aux_init" API to initialise the secondary interface in BMI160. -* Invoke the "bmm150_init" API to initialise the BMM150 sensor. -* Now we can use the BMM150 sensor APIs to access the BMM150 via BMI160. - -``` c -/* main.c file */ -#include "bmi160.h" -#include "bmm150.h" -``` -### Initialization of auxiliary sensor BMM150 -``` - -/* main.c file */ -struct bmm150_dev bmm150; - -/* function declaration */ -int8_t user_aux_read(uint8_t id, uint8_t reg_addr, uint8_t *aux_data, uint16_t len); -int8_t user_aux_write(uint8_t id, uint8_t reg_addr, uint8_t *aux_data, uint16_t len); - -/* Configure device structure for auxiliary sensor parameter */ -sensor.aux_cfg.aux_sensor_enable = 1; // auxiliary sensor enable -sensor.aux_cfg.aux_i2c_addr = BMI160_AUX_BMM150_I2C_ADDR; // auxiliary sensor address -sensor.aux_cfg.manual_enable = 1; // setup mode enable -sensor.aux_cfg.aux_rd_burst_len = 2;// burst read of 2 byte - -/* Configure the BMM150 device structure by -mapping user_aux_read and user_aux_write */ -bmm150.read = user_aux_read; -bmm150.write = user_aux_write; -bmm150.id = BMM150_DEFAULT_I2C_ADDRESS; -/* Ensure that sensor.aux_cfg.aux_i2c_addr = bmm150.id - for proper sensor operation */ -bmm150.delay_ms = delay_ms; -bmm150.interface = BMM150_I2C_INTF; - -/* Initialize the auxiliary sensor interface */ -rslt = bmi160_aux_init(&sensor); - -/* Auxiliary sensor is enabled and can be accessed from this point */ - -/* Configure the desired settings in auxiliary BMM150 sensor - * using the bmm150 APIs */ - -/* Initialising the bmm150 sensor */ -rslt = bmm150_init(&bmm150); - -/* Set the power mode and preset mode to enable Mag data sampling */ -bmm150.settings.pwr_mode = BMM150_NORMAL_MODE; -rslt = bmm150_set_op_mode(&bmm150); - -bmm150.settings.preset_mode= BMM150_PRESETMODE_LOWPOWER; -rslt = bmm150_set_presetmode(&bmm150); - -``` -### Wrapper functions -``` - -/*wrapper function to match the signature of bmm150.read */ -int8_t user_aux_read(uint8_t id, uint8_t reg_addr, uint8_t *aux_data, uint16_t len) -{ - int8_t rslt; - - /* Discarding the parameter id as it is redundant*/ - rslt = bmi160_aux_read(reg_addr, aux_data, len, &bmi160); - - return rslt; -} - -/*wrapper function to match the signature of bmm150.write */ -int8_t user_aux_write(uint8_t id, uint8_t reg_addr, uint8_t *aux_data, uint16_t len) -{ - int8_t rslt; - - /* Discarding the parameter id as it is redundant */ - rslt = bmi160_aux_write(reg_addr, aux_data, len, &bmi160); - - return rslt; -} - -``` - -### Initialization of auxiliary BMM150 in auto mode -Any sensor whose data bytes are less than or equal to 8 bytes can be synchronized with the BMI160 -and read out of Accelerometer + Gyroscope + Auxiliary sensor data of that instance is possible -which helps in creating less latency fusion data - -``` -/* Initialize the Auxiliary BMM150 following the above code - * until setting the power mode (Set the power mode as forced mode) - * and preset mode */ - - /* In BMM150 Mag data starts from register address 0x42 */ - uint8_t aux_addr = 0x42; - /* Buffer to store the Mag data from 0x42 to 0x48 */ - uint8_t mag_data[8] = {0}; - - uint8_t index; - - /* Configure the Auxiliary sensor either in auto/manual modes and set the - polling frequency for the Auxiliary interface */ - sensor.aux_cfg.aux_odr = 8; /* Represents polling rate in 100 Hz*/ - rslt = bmi160_config_aux_mode(&sensor) - - /* Set the auxiliary sensor to auto mode */ - rslt = bmi160_set_aux_auto_mode(&aux_addr, &sensor); - - /* Reading data from BMI160 data registers */ - rslt = bmi160_read_aux_data_auto_mode(mag_data, &sensor); - - printf("\n RAW DATA "); - for(index = 0 ; index < 8 ; index++) - { - printf("\n MAG DATA[%d] : %d ", index, mag_data[index]); - } - - /* Compensating the raw mag data available from the BMM150 API */ - rslt = bmm150_aux_mag_data(mag_data, &bmm150); - - printf("\n COMPENSATED DATA "); - printf("\n MAG DATA X : %d Y : %d Z : %d", bmm150.data.x, bmm150.data.y, bmm150.data.z); - - -``` - -### Auxiliary FIFO data parsing -The Auxiliary sensor data can be stored in FIFO , Here we demonstrate an example for -using the Bosch Magnetometer sensor BMM150 and storing its data in FIFO - -``` -/* Initialize the Aux BMM150 following the above - * code and by creating the Wrapper functions */ - - int8_t rslt = 0; - uint8_t aux_instance = 0; - uint16_t fifo_cnt = 0; - uint8_t auto_mode_addr; - uint8_t i; - - /* Setup and configure the FIFO buffer */ - /* Declare memory to store the raw FIFO buffer information */ - uint8_t fifo_buff[1000] = {0}; - - /* Modify the FIFO buffer instance and link to the device instance */ - struct bmi160_fifo_frame fifo_frame; - fifo_frame.data = fifo_buff; - fifo_frame.length = 1000; - dev->fifo = &fifo_frame; - - /* Declare instances of the sensor data structure to store the parsed FIFO data */ - struct bmi160_aux_data aux_data[112]; //1000 / 9 bytes per frame ~ 111 data frames - - rslt = bmi160_init(dev); - printf("\n BMI160 chip ID is : %d ",dev->chip_id); - - rslt = bmi160_aux_init(dev); - - rslt = bmm150_init(&bmm150); - printf("\n BMM150 CHIP ID : %d",bmm150.chip_id); - - bmm150.settings.preset_mode = BMM150_PRESETMODE_LOWPOWER; - rslt = bmm150_set_presetmode(&bmm150); - - bmm150.settings.pwr_mode = BMM150_FORCED_MODE; - rslt = bmm150_set_op_mode(&bmm150); - - /* Enter the data register of BMM150 to "auto_mode_addr" here it is 0x42 */ - auto_mode_addr = 0x42; - printf("\n ENTERING AUX. AUTO MODE "); - dev->aux_cfg.aux_odr = BMI160_AUX_ODR_25HZ; - rslt = bmi160_set_aux_auto_mode(&auto_mode_addr, dev); - - - /* Disable other FIFO settings */ - rslt = bmi160_set_fifo_config(BMI160_FIFO_CONFIG_1_MASK , BMI160_DISABLE, dev); - - /* Enable the required FIFO settings */ - rslt = bmi160_set_fifo_config(BMI160_FIFO_AUX | BMI160_FIFO_HEADER, BMI160_ENABLE, dev); - - /* Delay for the FIFO to get filled */ - dev->delay_ms(400); - - - printf("\n FIFO DATA REQUESTED (in bytes): %d",dev->fifo->length); - rslt = bmi160_get_fifo_data(dev); - printf("\n FIFO DATA AVAILABLE (in bytes): %d",dev->fifo->length); - - /* Print the raw FIFO data obtained */ - for(fifo_cnt = 0; fifo_cnt < dev->fifo->length ; fifo_cnt++) { - printf("\n FIFO DATA [%d] IS : %x ",fifo_cnt ,dev->fifo->data[fifo_cnt]); - } - - printf("\n\n----------------------------------------------------\n"); - - /* Set the number of required sensor data instances */ - aux_instance = 150; - - /* Extract the aux data , 1frame = 8 data bytes */ - printf("\n AUX DATA REQUESTED TO BE EXTRACTED (in frames): %d",aux_instance); - rslt = bmi160_extract_aux(aux_data, &aux_instance, dev); - printf("\n AUX DATA ACTUALLY EXTRACTED (in frames): %d",aux_instance); - - /* Printing the raw aux data */ - for (i = 0; i < aux_instance; i++) { - printf("\n Aux data[%d] : %x",i,aux_data[i].data[0]); - printf("\n Aux data[%d] : %x",i,aux_data[i].data[1]); - printf("\n Aux data[%d] : %x",i,aux_data[i].data[2]); - printf("\n Aux data[%d] : %x",i,aux_data[i].data[3]); - printf("\n Aux data[%d] : %x",i,aux_data[i].data[4]); - printf("\n Aux data[%d] : %x",i,aux_data[i].data[5]); - printf("\n Aux data[%d] : %x",i,aux_data[i].data[6]); - printf("\n Aux data[%d] : %x",i,aux_data[i].data[7]); - } - - printf("\n\n----------------------------------------------------\n"); - - /* Compensate the raw mag data using BMM150 API */ - for (i = 0; i < aux_instance; i++) { - printf("\n----------------------------------------------------"); - printf("\n Aux data[%d] : %x , %x , %x , %x , %x , %x , %x , %x",i - ,aux_data[i].data[0],aux_data[i].data[1] - ,aux_data[i].data[2],aux_data[i].data[3] - ,aux_data[i].data[4],aux_data[i].data[5] - ,aux_data[i].data[6],aux_data[i].data[7]); - - /* Compensated mag data using BMM150 API */ - rslt = bmm150_aux_mag_data(&aux_data[i].data[0], &bmm150); - - /* Printing the Compensated mag data */ - if (rslt == BMM150_OK) { - printf("\n MAG DATA COMPENSATION USING BMM150 APIs"); - printf("\n COMPENSATED DATA "); - printf("\n MAG DATA X : %d Y : %d Z : %d" - , bmm150.data.x, bmm150.data.y, bmm150.data.z); - - } else { - printf("\n MAG DATA COMPENSATION IN BMM150 API is FAILED "); - } - printf("\n----------------------------------------------------\n"); - } - -``` - -## Self-test -#### Example for performing accel self test -``` -/* Call the "bmi160_init" API as a prerequisite before performing self test - * since invoking self-test will reset the sensor */ - - rslt = bmi160_perform_self_test(BMI160_ACCEL_ONLY, sen); - /* Utilize the enum BMI160_GYRO_ONLY instead of BMI160_ACCEL_ONLY - to perform self test for gyro */ - if (rslt == BMI160_OK) { - printf("\n ACCEL SELF TEST RESULT SUCCESS); - } else { - printf("\n ACCEL SELF TEST RESULT FAIL); - } -``` - - -## FIFO -#### Example for reading FIFO and extracting Gyro data in Header mode -``` -/* An example to read the Gyro data in header mode along with sensor time (if available) - * Configure the gyro sensor as prerequisite and follow the below example to read and - * obtain the gyro data from FIFO */ -int8_t fifo_gyro_header_time_data(struct bmi160_dev *dev) -{ - int8_t rslt = 0; - - /* Declare memory to store the raw FIFO buffer information */ - uint8_t fifo_buff[300]; - - /* Modify the FIFO buffer instance and link to the device instance */ - struct bmi160_fifo_frame fifo_frame; - fifo_frame.data = fifo_buff; - fifo_frame.length = 300; - dev->fifo = &fifo_frame; - uint16_t index = 0; - - /* Declare instances of the sensor data structure to store the parsed FIFO data */ - struct bmi160_sensor_data gyro_data[42]; // 300 bytes / ~7bytes per frame ~ 42 data frames - uint8_t gyro_frames_req = 42; - uint8_t gyro_index; - - /* Configure the sensor's FIFO settings */ - rslt = bmi160_set_fifo_config(BMI160_FIFO_GYRO | BMI160_FIFO_HEADER | BMI160_FIFO_TIME, - BMI160_ENABLE, dev); - - if (rslt == BMI160_OK) { - /* At ODR of 100 Hz ,1 frame gets updated in 1/100 = 0.01s - i.e. for 42 frames we need 42 * 0.01 = 0.42s = 420ms delay */ - dev->delay_ms(420); - - /* Read data from the sensor's FIFO and store it the FIFO buffer,"fifo_buff" */ - printf("\n USER REQUESTED FIFO LENGTH : %d\n",dev->fifo->length); - rslt = bmi160_get_fifo_data(dev); - - if (rslt == BMI160_OK) { - printf("\n AVAILABLE FIFO LENGTH : %d\n",dev->fifo->length); - /* Print the raw FIFO data */ - for (index = 0; index < dev->fifo->length; index++) { - printf("\n FIFO DATA INDEX[%d] = %d", index, - dev->fifo->data[index]); - } - /* Parse the FIFO data to extract gyro data from the FIFO buffer */ - printf("\n REQUESTED GYRO DATA FRAMES : %d\n ",gyro_frames_req); - rslt = bmi160_extract_gyro(gyro_data, &gyro_frames_req, dev); - - if (rslt == BMI160_OK) { - printf("\n AVAILABLE GYRO DATA FRAMES : %d\n ",gyro_frames_req); - - /* Print the parsed gyro data from the FIFO buffer */ - for (gyro_index = 0; gyro_index < gyro_frames_req; gyro_index++) { - printf("\nFIFO GYRO FRAME[%d]",gyro_index); - printf("\nGYRO X-DATA : %d \t Y-DATA : %d \t Z-DATA : %d" - ,gyro_data[gyro_index].x ,gyro_data[gyro_index].y - ,gyro_data[gyro_index].z); - } - /* Print the special FIFO frame data like sensortime */ - printf("\n SENSOR TIME DATA : %d \n",dev->fifo->sensor_time); - printf("SKIPPED FRAME COUNT : %d",dev->fifo->skipped_frame_count); - } else { - printf("\n Gyro data extraction failed"); - } - } else { - printf("\n Reading FIFO data failed"); - } - } else { - printf("\n Setting FIFO configuration failed"); - } - - return rslt; -} -``` - -## FOC and offset compensation -> FOC shouldnot be used in Low-power mode -#### Example for configuring FOC for accel and gyro -``` -/* An example for configuring FOC for accel and gyro data */ -int8_t start_foc(struct bmi160_dev *dev) -{ - int8_t rslt = 0; - /* FOC configuration structure */ - struct bmi160_foc_conf foc_conf; - /* Structure to store the offsets */ - struct bmi160_offsets offsets; - - /* Enable FOC for accel with target values of z = 1g ; x,y as 0g */ - foc_conf.acc_off_en = BMI160_ENABLE; - foc_conf.foc_acc_x = BMI160_FOC_ACCEL_0G; - foc_conf.foc_acc_y = BMI160_FOC_ACCEL_0G; - foc_conf.foc_acc_z = BMI160_FOC_ACCEL_POSITIVE_G; - - /* Enable FOC for gyro */ - foc_conf.foc_gyr_en = BMI160_ENABLE; - foc_conf.gyro_off_en = BMI160_ENABLE; - - rslt = bmi160_start_foc(&foc_conf, &offsets, sen); - - if (rslt == BMI160_OK) { - printf("\n FOC DONE SUCCESSFULLY "); - printf("\n OFFSET VALUES AFTER FOC : "); - printf("\n OFFSET VALUES ACCEL X : %d ",offsets.off_acc_x); - printf("\n OFFSET VALUES ACCEL Y : %d ",offsets.off_acc_y); - printf("\n OFFSET VALUES ACCEL Z : %d ",offsets.off_acc_z); - printf("\n OFFSET VALUES GYRO X : %d ",offsets.off_gyro_x); - printf("\n OFFSET VALUES GYRO Y : %d ",offsets.off_gyro_y); - printf("\n OFFSET VALUES GYRO Z : %d ",offsets.off_gyro_z); - } - - /* After start of FOC offsets will be updated automatically and - * the data will be very much close to the target values of measurement */ - - return rslt; -} -``` - -#### Example for updating the offsets manually -> The offsets set by this method will be reset on soft-reset/POR -``` -/* An example for updating manual offsets to sensor */ -int8_t write_offsets(struct bmi160_dev *dev) -{ - int8_t rslt = 0; - /* FOC configuration structure */ - struct bmi160_foc_conf foc_conf; - /* Structure to store the offsets */ - struct bmi160_offsets offsets; - - /* Enable offset update for accel */ - foc_conf.acc_off_en = BMI160_ENABLE; - - /* Enable offset update for gyro */ - foc_conf.gyro_off_en = BMI160_ENABLE; - - /* offset values set by user */ - offsets.off_acc_x = 0x10; - offsets.off_acc_y = 0x10; - offsets.off_acc_z = 0x10; - offsets.off_gyro_x = 0x10; - offsets.off_gyro_y = 0x10; - offsets.off_gyro_z = 0x10; - - rslt = bmi160_set_offsets(&foc_conf, &offsets, sen); - - /* After offset setting the data read from the - * sensor will have the corresponding offset */ - - return rslt; -} -``` - -#### Example for updating the offsets into NVM -> The offsets set by this method will be present in NVM and will be -> restored on POR/soft-reset -``` -/* An example for updating manual offsets to sensor */ -int8_t write_offsets_nvm(struct bmi160_dev *dev) -{ - int8_t rslt = 0; - /* FOC configuration structure */ - struct bmi160_foc_conf foc_conf; - /* Structure to store the offsets */ - struct bmi160_offsets offsets; - - /* Enable offset update for accel */ - foc_conf.acc_off_en = BMI160_ENABLE; - - /* Enable offset update for gyro */ - foc_conf.gyro_off_en = BMI160_ENABLE; - - /* offset values set by user as per their reference - * Resolution of accel = 3.9mg/LSB - * Resolution of gyro = (0.061degrees/second)/LSB */ - offsets.off_acc_x = 10; - offsets.off_acc_y = -15; - offsets.off_acc_z = 20; - offsets.off_gyro_x = 30; - offsets.off_gyro_y = -35; - offsets.off_gyro_z = -40; - - rslt = bmi160_set_offsets(&foc_conf, &offsets, sen); - - if (rslt == BMI160_OK) { - /* Update the NVM */ - rslt = bmi160_update_nvm(dev); - } - - /* After this procedure the offsets are written to - * NVM and restored on POR/soft-reset - * The set values can be removed to ideal case by - * invoking the following APIs - * - bmi160_start_foc() - * - bmi160_update_nvm() - */ - - return rslt; -} -``` - - - -## Copyright (C) 2016 - 2017 Bosch Sensortec GmbH +# BMI160 Sensor API + +### Sensor overview + +The small, low power BMI160 is a low noise 16-bit IMU designed for mobile applications such as AR or indoor navigation, providing highly accurate sensor data and real-time sensor data. The low current consumption of BMI160 enables always-on applications in battery-driven devices. This sensor features a configurable on-chip interrupt engine which provides motion-based gesture recognition and context awareness as always-on background functions. + +### Target Application +- Augmented reality and immersive gaming +- Indoor navigation +- 3D-scanning / indoor mapping +- Advanced gesture recognition +- Immersive gaming +- 9-axis motion detection +- Air mouse applications and pointers +- Pedometer / step counting +- Advanced system power management for mobile applications +- Optical image stabilization of camera modules +- Free-fall detection and warranty logging + +### Features +- Any-motion detection (accelerometer) +- Significant motion detection (accelerometer) +- Step detector (accelerometer) +- Tap sensing (accelerometer) +- Orientation recognition (accelerometer) +- Flat detection (accelerometer) +- Low-G / Free-fall detection (accelerometer) +- High-G detection (accelerometer) +- Slow-motion alert / No-motion interrupt (accelerometer) +- Data ready detection (accelerometer, gyroscope and external sensors) +- PMU trigger (gyroscope) +- FIFO interrupts ((accelerometer, gyroscope and external sensors) + +### Important links + +- [BMI160 product page](https://www.bosch-sensortec.com/products/motion-sensors/imus/bmi160/) +- [BMI160 datasheet](https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmi160-ds000.pdf) +- [BMI160 shuttle board flyer](https://www.bosch-sensortec.com/media/boschsensortec/downloads/shuttle_board_flyer/bst-dhw-fl022.pdf) +- [Community support page](https://community.bosch-sensortec.com) + +--- +#### Copyright (C) 2020 Bosch Sensortec GmbH \ No newline at end of file diff --git a/bmi160.c b/bmi160.c index 9782d41..2a66fbd 100644 --- a/bmi160.c +++ b/bmi160.c @@ -30,17 +30,12 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * -* @file bmi160.c -* @date 10/01/2020 -* @version 3.8.1 +* @file bmi160.c +* @date 2021-03-12 +* @version v3.9.1 * */ -/*! - * @defgroup bmi160 - * @brief - * @{*/ - #include "bmi160.h" /* Below look up table follows the enum bmi160_int_types. @@ -228,6 +223,16 @@ static int8_t null_ptr_check(const struct bmi160_dev *dev); */ static int8_t set_accel_conf(struct bmi160_dev *dev); +/*! + * @brief This API gets the accel configuration. + * + * @param[out] dev : Structure instance of bmi160_dev. + * + * @return Result of API execution status + * @retval zero -> Success / -ve value -> Error. + */ +static int8_t get_accel_conf(struct bmi160_dev *dev); + /*! * @brief This API check the accel configuration. * @@ -288,6 +293,16 @@ static int8_t check_invalid_settg(const struct bmi160_dev *dev); */ static int8_t set_gyro_conf(struct bmi160_dev *dev); +/*! + * @brief This API get the gyro configuration. + * + * @param[out] dev : Structure instance of bmi160_dev. + * + * @return Result of API execution status + * @retval zero -> Success / -ve value -> Error. + */ +static int8_t get_gyro_conf(struct bmi160_dev *dev); + /*! * @brief This API check the gyro configuration. * @@ -1361,15 +1376,6 @@ int8_t bmi160_get_regs(uint8_t reg_addr, uint8_t *data, uint16_t len, const stru { int8_t rslt = BMI160_OK; - /* Variable to define temporary length */ - uint16_t temp_len = len + dev->dummy_byte; - - /* Variable to define temporary buffer */ - uint8_t temp_buf[temp_len]; - - /* Variable to define loop */ - uint16_t indx = 0; - /* Null-pointer check */ if ((dev == NULL) || (dev->read == NULL)) { @@ -1382,25 +1388,12 @@ int8_t bmi160_get_regs(uint8_t reg_addr, uint8_t *data, uint16_t len, const stru else { /* Configuring reg_addr for SPI Interface */ - if (dev->interface == BMI160_SPI_INTF) + if (dev->intf == BMI160_SPI_INTF) { reg_addr = (reg_addr | BMI160_SPI_RD_MASK); } - rslt = dev->read(dev->id, reg_addr, temp_buf, temp_len); - if (rslt == BMI160_OK) - { - /* Read the data from the position next to dummy byte */ - while (indx < len) - { - data[indx] = temp_buf[indx]; - indx++; - } - } - else - { - rslt = BMI160_E_COM_FAIL; - } + rslt = dev->read(dev->id, reg_addr, data, len); } return rslt; @@ -1427,10 +1420,11 @@ int8_t bmi160_set_regs(uint8_t reg_addr, uint8_t *data, uint16_t len, const stru else { /* Configuring reg_addr for SPI Interface */ - if (dev->interface == BMI160_SPI_INTF) + if (dev->intf == BMI160_SPI_INTF) { reg_addr = (reg_addr & BMI160_SPI_WR_MASK); } + if ((dev->prev_accel_cfg.power == BMI160_ACCEL_NORMAL_MODE) || (dev->prev_gyro_cfg.power == BMI160_GYRO_NORMAL_MODE)) { @@ -1454,6 +1448,7 @@ int8_t bmi160_set_regs(uint8_t reg_addr, uint8_t *data, uint16_t len, const stru } } + if (rslt != BMI160_OK) { rslt = BMI160_E_COM_FAIL; @@ -1477,19 +1472,9 @@ int8_t bmi160_init(struct bmi160_dev *dev) /* Null-pointer check */ rslt = null_ptr_check(dev); - /* An extra dummy byte is read during SPI read */ - if (dev->interface == BMI160_SPI_INTF) - { - dev->dummy_byte = 1; - } - else - { - dev->dummy_byte = 0; - } - /* Dummy read of 0x7F register to enable SPI Interface * if SPI is used */ - if ((rslt == BMI160_OK) && (dev->interface == BMI160_SPI_INTF)) + if ((rslt == BMI160_OK) && (dev->intf == BMI160_SPI_INTF)) { rslt = bmi160_get_regs(BMI160_SPI_COMM_TEST_ADDR, &data, 1, dev); } @@ -1504,6 +1489,7 @@ int8_t bmi160_init(struct bmi160_dev *dev) /* Read chip_id */ rslt = bmi160_get_regs(BMI160_CHIP_ID_ADDR, &dev->chip_id, 1, dev); } + if ((rslt == BMI160_OK) && (dev->chip_id == BMI160_CHIP_ID)) { dev->any_sig_sel = BMI160_BOTH_ANY_SIG_MOTION_DISABLED; @@ -1539,12 +1525,13 @@ int8_t bmi160_soft_reset(struct bmi160_dev *dev) /* Reset the device */ rslt = bmi160_set_regs(BMI160_COMMAND_REG_ADDR, &data, 1, dev); dev->delay_ms(BMI160_SOFT_RESET_DELAY_MS); - if ((rslt == BMI160_OK) && (dev->interface == BMI160_SPI_INTF)) + if ((rslt == BMI160_OK) && (dev->intf == BMI160_SPI_INTF)) { /* Dummy read of 0x7F register to enable SPI Interface * if SPI is used */ rslt = bmi160_get_regs(BMI160_SPI_COMM_TEST_ADDR, &data, 1, dev); } + if (rslt == BMI160_OK) { /* Update the default parameters */ @@ -1589,6 +1576,30 @@ int8_t bmi160_set_sens_conf(struct bmi160_dev *dev) return rslt; } +/*! + * @brief This API gets accel and gyro configurations. + */ +int8_t bmi160_get_sens_conf(struct bmi160_dev *dev) +{ + int8_t rslt = BMI160_OK; + + /* Null-pointer check */ + if ((dev == NULL) || (dev->delay_ms == NULL)) + { + rslt = BMI160_E_NULL_PTR; + } + else + { + rslt = get_accel_conf(dev); + if (rslt == BMI160_OK) + { + rslt = get_gyro_conf(dev); + } + } + + return rslt; +} + /*! * @brief This API sets the power mode of the sensor. */ @@ -1680,6 +1691,7 @@ int8_t bmi160_get_sensor_data(uint8_t select_sensor, { rslt = get_accel_data(len, accel, dev); } + break; case BMI160_GYRO_ONLY: @@ -1692,6 +1704,7 @@ int8_t bmi160_get_sensor_data(uint8_t select_sensor, { rslt = get_gyro_data(len, gyro, dev); } + break; case BMI160_BOTH_ACCEL_AND_GYRO: @@ -1704,6 +1717,7 @@ int8_t bmi160_get_sensor_data(uint8_t select_sensor, { rslt = get_accel_gyro_data(len, accel, gyro, dev); } + break; default: rslt = BMI160_E_INVALID_INPUT; @@ -1830,6 +1844,7 @@ int8_t bmi160_set_step_counter(uint8_t step_cnt_enable, const struct bmi160_dev { data &= ~BMI160_STEP_COUNT_EN_BIT_MASK; } + rslt = bmi160_set_regs(BMI160_INT_STEP_CONFIG_1_ADDR, &data, 1, dev); } } @@ -2166,6 +2181,7 @@ int8_t bmi160_get_fifo_data(struct bmi160_dev const *dev) * more data than available in FIFO */ dev->fifo->length = bytes_to_read; } + if ((dev->fifo->fifo_time_enable == BMI160_FIFO_TIME_ENABLE) && (bytes_to_read + BMI160_FIFO_BYTES_OVERREAD <= user_fifo_len)) { @@ -2682,14 +2698,17 @@ int8_t bmi160_get_int_status(enum bmi160_int_status_sel int_status_sel, { rslt = bmi160_get_regs(BMI160_INT_STATUS_ADDR, &int_status->data[0], 1, dev); } + if (int_status_sel & BMI160_INT_STATUS_1) { rslt = bmi160_get_regs(BMI160_INT_STATUS_ADDR + 1, &int_status->data[1], 1, dev); } + if (int_status_sel & BMI160_INT_STATUS_2) { rslt = bmi160_get_regs(BMI160_INT_STATUS_ADDR + 2, &int_status->data[2], 1, dev); } + if (int_status_sel & BMI160_INT_STATUS_3) { rslt = bmi160_get_regs(BMI160_INT_STATUS_ADDR + 3, &int_status->data[3], 1, dev); @@ -3160,6 +3179,26 @@ static int8_t set_accel_conf(struct bmi160_dev *dev) return rslt; } +/*! + * @brief This API gets the accel configuration. + */ +static int8_t get_accel_conf(struct bmi160_dev *dev) +{ + int8_t rslt; + uint8_t data[2] = { 0 }; + + /* Get accel configurations */ + rslt = bmi160_get_regs(BMI160_ACCEL_CONFIG_ADDR, data, 2, dev); + if (rslt == BMI160_OK) + { + dev->accel_cfg.odr = (data[0] & BMI160_ACCEL_ODR_MASK); + dev->accel_cfg.bw = (data[0] & BMI160_ACCEL_BW_MASK) >> BMI160_ACCEL_BW_POS; + dev->accel_cfg.range = (data[1] & BMI160_ACCEL_RANGE_MASK); + } + + return rslt; +} + /*! * @brief This API check the accel configuration. */ @@ -3194,7 +3233,7 @@ static int8_t process_accel_odr(uint8_t *data, const struct bmi160_dev *dev) uint8_t temp = 0; uint8_t odr = 0; - if (dev->accel_cfg.odr <= BMI160_ACCEL_ODR_MAX) + if (dev->accel_cfg.odr <= BMI160_ACCEL_ODR_1600HZ) { if (dev->accel_cfg.odr != dev->prev_accel_cfg.odr) { @@ -3222,7 +3261,7 @@ static int8_t process_accel_bw(uint8_t *data, const struct bmi160_dev *dev) uint8_t temp = 0; uint8_t bw = 0; - if (dev->accel_cfg.bw <= BMI160_ACCEL_BW_MAX) + if (dev->accel_cfg.bw <= BMI160_ACCEL_BW_RES_AVG128) { if (dev->accel_cfg.bw != dev->prev_accel_cfg.bw) { @@ -3230,7 +3269,7 @@ static int8_t process_accel_bw(uint8_t *data, const struct bmi160_dev *dev) temp = *data & ~BMI160_ACCEL_BW_MASK; /* Adding bandwidth */ - *data = temp | ((bw << 4) & BMI160_ACCEL_ODR_MASK); + *data = temp | ((bw << 4) & BMI160_ACCEL_BW_MASK); } } else @@ -3250,7 +3289,7 @@ static int8_t process_accel_range(uint8_t *data, const struct bmi160_dev *dev) uint8_t temp = 0; uint8_t range = 0; - if (dev->accel_cfg.range <= BMI160_ACCEL_RANGE_MAX) + if (dev->accel_cfg.range <= BMI160_ACCEL_RANGE_16G) { if (dev->accel_cfg.range != dev->prev_accel_cfg.range) { @@ -3328,6 +3367,26 @@ static int8_t set_gyro_conf(struct bmi160_dev *dev) return rslt; } +/*! + * @brief This API gets the gyro configuration. + */ +static int8_t get_gyro_conf(struct bmi160_dev *dev) +{ + int8_t rslt; + uint8_t data[2] = { 0 }; + + /* Get accel configurations */ + rslt = bmi160_get_regs(BMI160_GYRO_CONFIG_ADDR, data, 2, dev); + if (rslt == BMI160_OK) + { + dev->gyro_cfg.odr = (data[0] & BMI160_GYRO_ODR_MASK); + dev->gyro_cfg.bw = (data[0] & BMI160_GYRO_BW_MASK) >> BMI160_GYRO_BW_POS; + dev->gyro_cfg.range = (data[1] & BMI160_GYRO_RANGE_MASK); + } + + return rslt; +} + /*! * @brief This API check the gyro configuration. */ @@ -3362,7 +3421,7 @@ static int8_t process_gyro_odr(uint8_t *data, const struct bmi160_dev *dev) uint8_t temp = 0; uint8_t odr = 0; - if (dev->gyro_cfg.odr <= BMI160_GYRO_ODR_MAX) + if (dev->gyro_cfg.odr <= BMI160_GYRO_ODR_3200HZ) { if (dev->gyro_cfg.odr != dev->prev_gyro_cfg.odr) { @@ -3390,7 +3449,7 @@ static int8_t process_gyro_bw(uint8_t *data, const struct bmi160_dev *dev) uint8_t temp = 0; uint8_t bw = 0; - if (dev->gyro_cfg.bw <= BMI160_GYRO_BW_MAX) + if (dev->gyro_cfg.bw <= BMI160_GYRO_BW_NORMAL_MODE) { bw = (uint8_t)dev->gyro_cfg.bw; temp = *data & ~BMI160_GYRO_BW_MASK; @@ -3415,15 +3474,15 @@ static int8_t process_gyro_range(uint8_t *data, const struct bmi160_dev *dev) uint8_t temp = 0; uint8_t range = 0; - if (dev->gyro_cfg.range <= BMI160_GYRO_RANGE_MAX) + if (dev->gyro_cfg.range <= BMI160_GYRO_RANGE_125_DPS) { if (dev->gyro_cfg.range != dev->prev_gyro_cfg.range) { range = (uint8_t)dev->gyro_cfg.range; - temp = *data & ~BMI160_GYRO_RANGE_MSK; + temp = *data & ~BMI160_GYRO_RANGE_MASK; /* Adding range */ - *data = temp | (range & BMI160_GYRO_RANGE_MSK); + *data = temp | (range & BMI160_GYRO_RANGE_MASK); } } else @@ -3457,6 +3516,7 @@ static int8_t set_accel_pwr(struct bmi160_dev *dev) { dev->delay_ms(BMI160_ACCEL_DELAY_MS); } + dev->prev_accel_cfg.power = dev->accel_cfg.power; } } @@ -3545,6 +3605,7 @@ static int8_t set_gyro_pwr(struct bmi160_dev *dev) { /* do nothing */ } + dev->prev_gyro_cfg.power = dev->gyro_cfg.power; } } @@ -4058,6 +4119,7 @@ static int8_t enable_no_motion_int(const struct bmi160_acc_no_motion_int_cfg *no /* Adding No_motion x axis */ data = temp | (1 & BMI160_NO_MOTION_X_INT_EN_MASK); } + if (no_mot_int_cfg->no_motion_y == 1) { temp = data & ~BMI160_NO_MOTION_Y_INT_EN_MASK; @@ -4065,6 +4127,7 @@ static int8_t enable_no_motion_int(const struct bmi160_acc_no_motion_int_cfg *no /* Adding No_motion x axis */ data = temp | ((1 << 1) & BMI160_NO_MOTION_Y_INT_EN_MASK); } + if (no_mot_int_cfg->no_motion_z == 1) { temp = data & ~BMI160_NO_MOTION_Z_INT_EN_MASK; @@ -4514,6 +4577,7 @@ static int8_t config_tap_param(const struct bmi160_int_settg *int_config, * double tap interrupt */ data = temp | (dur & BMI160_TAP_DUR_MASK); } + shock = (uint8_t)tap_int_cfg->tap_shock; temp = data & ~BMI160_TAP_SHOCK_DUR_MASK; data = temp | ((shock << 6) & BMI160_TAP_SHOCK_DUR_MASK); @@ -4675,6 +4739,7 @@ static int8_t extract_aux_read(uint16_t map_len, { aux_data[count + read_count] = data[read_count]; } + reg_addr += (uint8_t)map_len; count += (uint8_t)map_len; } @@ -5049,6 +5114,7 @@ static int8_t config_int_out_ctrl(const struct bmi160_int_settg *int_config, con temp = data & ~BMI160_INT2_EDGE_CTRL_MASK; data = temp | ((intr_pin_sett->edge_ctrl << 4) & BMI160_INT2_EDGE_CTRL_MASK); } + rslt = bmi160_set_regs(BMI160_INT_OUT_CTRL_ADDR, &data, 1, dev); } @@ -5467,6 +5533,7 @@ static void get_accel_len_to_parse(uint16_t *data_index, * so we update the data index as complete */ *data_index = dev->fifo->length; } + if (*data_read_length > dev->fifo->length) { /* Handling the case where more data is requested @@ -5712,6 +5779,7 @@ static void get_gyro_len_to_parse(uint16_t *data_index, * so we update the data index as complete */ *data_index = dev->fifo->length; } + if (*data_read_length > dev->fifo->length) { /* Handling the case where more data is requested @@ -5961,6 +6029,7 @@ static void get_aux_len_to_parse(uint16_t *data_index, * so we update the data index as complete */ *data_index = dev->fifo->length; } + if (*data_read_length > dev->fifo->length) { /* Handling the case where more data is requested @@ -6313,7 +6382,7 @@ static int8_t configure_offset_enable(const struct bmi160_foc_conf *foc_conf, st static int8_t trigger_foc(struct bmi160_offsets *offset, struct bmi160_dev const *dev) { int8_t rslt; - uint8_t foc_status; + uint8_t foc_status = BMI160_ENABLE; uint8_t cmd = BMI160_START_FOC_CMD; uint8_t timeout = 0; uint8_t data_array[20]; @@ -6324,6 +6393,7 @@ static int8_t trigger_foc(struct bmi160_offsets *offset, struct bmi160_dev const { /* Check the FOC status*/ rslt = get_foc_status(&foc_status, dev); + if ((rslt != BMI160_OK) || (foc_status != BMI160_ENABLE)) { while ((foc_status != BMI160_ENABLE) && (timeout < 11)) @@ -6336,6 +6406,7 @@ static int8_t trigger_foc(struct bmi160_offsets *offset, struct bmi160_dev const rslt = get_foc_status(&foc_status, dev); timeout++; } + if ((rslt == BMI160_OK) && (foc_status == BMI160_ENABLE)) { /* Get offset values from sensor */ @@ -6347,6 +6418,7 @@ static int8_t trigger_foc(struct bmi160_offsets *offset, struct bmi160_dev const rslt = BMI160_FOC_FAILURE; } } + if (rslt == BMI160_OK) { /* Read registers 0x04-0x17 */ @@ -6356,5 +6428,3 @@ static int8_t trigger_foc(struct bmi160_offsets *offset, struct bmi160_dev const return rslt; } - -/** @}*/ diff --git a/bmi160.h b/bmi160.h index 8d9d49d..b00c74f 100644 --- a/bmi160.h +++ b/bmi160.h @@ -30,16 +30,15 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * -* @file bmi160.h -* @date 10/01/2020 -* @version 3.8.1 +* @file bmi160.h +* @date 2021-03-12 +* @version v3.9.1 * */ /*! - * @defgroup bmi160 - * @brief - * @{*/ + * @defgroup bmi160 BMI160 + */ #ifndef BMI160_H_ #define BMI160_H_ @@ -60,8 +59,19 @@ extern "C" { /*********************** User function prototypes ************************/ +/** + * \ingroup bmi160 + * \defgroup bmi160ApiInit Initialization + * @brief Initialize the sensor and device structure + */ + /*! - * @brief This API is the entry point for sensor.It performs + * \ingroup bmi160ApiInit + * \page bmi160_api_bmi160_init bmi160_init + * \code + * int8_t bmi160_init(struct bmi160_dev *dev); + * \endcode + * @details This API is the entry point for sensor.It performs * the selection of I2C/SPI read mechanism according to the * selected interface and reads the chip-id of bmi160 sensor. * @@ -69,12 +79,24 @@ extern "C" { * @note : Refer user guide for detailed info. * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error + * @retval Zero Success + * @retval Negative Error */ int8_t bmi160_init(struct bmi160_dev *dev); +/** + * \ingroup bmi160 + * \defgroup bmi160ApiRegs Registers + * @brief Read data from the given register address of sensor + */ + /*! - * @brief This API reads the data from the given register address of sensor. + * \ingroup bmi160ApiRegs + * \page bmi160_api_bmi160_get_regs bmi160_get_regs + * \code + * int8_t bmi160_get_regs(uint8_t reg_addr, uint8_t *data, uint16_t len, const struct bmi160_dev *dev); + * \endcode + * @details This API reads the data from the given register address of sensor. * * @param[in] reg_addr : Register address from where the data to be read * @param[out] data : Pointer to data buffer to store the read data. @@ -86,12 +108,18 @@ int8_t bmi160_init(struct bmi160_dev *dev); * Register address - 0x24(BMI160_FIFO_DATA_ADDR) * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error + * @retval Zero Success + * @retval Negative Error */ int8_t bmi160_get_regs(uint8_t reg_addr, uint8_t *data, uint16_t len, const struct bmi160_dev *dev); /*! - * @brief This API writes the given data to the register address + * \ingroup bmi160ApiRegs + * \page bmi160_api_bmi160_set_regs bmi160_set_regs + * \code + * int8_t bmi160_set_regs(uint8_t reg_addr, uint8_t *data, uint16_t len, const struct bmi160_dev *dev); + * \endcode + * @details This API writes the given data to the register address * of sensor. * * @param[in] reg_addr : Register address from where the data to be written. @@ -101,45 +129,104 @@ int8_t bmi160_get_regs(uint8_t reg_addr, uint8_t *data, uint16_t len, const stru * @param[in] dev : Structure instance of bmi160_dev. * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error + * @retval Zero Success + * @retval Negative Error */ int8_t bmi160_set_regs(uint8_t reg_addr, uint8_t *data, uint16_t len, const struct bmi160_dev *dev); +/** + * \ingroup bmi160 + * \defgroup bmi160ApiSoftreset Soft reset + * @brief Perform soft reset of the sensor + */ + /*! - * @brief This API resets and restarts the device. + * \ingroup bmi160ApiSoftreset + * \page bmi160_api_bmi160_soft_reset bmi160_soft_reset + * \code + * int8_t bmi160_soft_reset(struct bmi160_dev *dev); + * \endcode + * @details This API resets and restarts the device. * All register values are overwritten with default parameters. * * @param[in] dev : Structure instance of bmi160_dev. * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error. + * @retval Zero Success + * @retval Negative Error */ int8_t bmi160_soft_reset(struct bmi160_dev *dev); +/** + * \ingroup bmi160 + * \defgroup bmi160ApiConfig Configuration + * @brief Configuration of the sensor + */ + /*! - * @brief This API configures the power mode, range and bandwidth + * \ingroup bmi160ApiConfig + * \page bmi160_api_bmi160_set_sens_conf bmi160_set_sens_conf + * \code + * int8_t bmi160_set_sens_conf(struct bmi160_dev *dev); + * \endcode + * @details This API configures the power mode, range and bandwidth * of sensor. * * @param[in] dev : Structure instance of bmi160_dev. * @note : Refer user guide for detailed info. * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error. + * @retval Zero Success + * @retval Negative Error */ int8_t bmi160_set_sens_conf(struct bmi160_dev *dev); /*! - * @brief This API sets the power mode of the sensor. + * \ingroup bmi160ApiConfig + * \page bmi160_api_bmi160_get_sens_conf bmi160_get_sens_conf + * \code + * int8_t bmi160_get_sens_conf(struct bmi160_dev *dev); + * \endcode + * @details This API gets accel and gyro configurations. + * + * @param[out] dev : Structure instance of bmi160_dev. + * @note : Refer user guide for detailed info. + * + * @return Result of API execution status + * @retval Zero Success + * @retval Negative Error + */ +int8_t bmi160_get_sens_conf(struct bmi160_dev *dev); + +/** + * \ingroup bmi160 + * \defgroup bmi160ApiPowermode Power mode + * @brief Set / Get power mode of the sensor + */ + +/*! + * \ingroup bmi160ApiPowermode + * \page bmi160_api_bmi160_set_power_mode bmi160_set_power_mode + * \code + * int8_t bmi160_set_power_mode(struct bmi160_dev *dev); + * \endcode + * @details This API sets the power mode of the sensor. * * @param[in] dev : Structure instance of bmi160_dev. * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error. + * @retval Zero Success + * @retval Negative Error */ int8_t bmi160_set_power_mode(struct bmi160_dev *dev); /*! - * @brief This API gets the power mode of the sensor. + * \ingroup bmi160ApiPowermode + * \page bmi160_api_bmi160_get_power_mode bmi160_get_power_mode + * \code + * int8_t bmi160_get_power_mode(struct bmi160_pmu_status *pmu_status, const struct bmi160_dev *dev); + * \endcode + * @details This API gets the power mode of the sensor. * * @param[in] power_mode : Power mode of the sensor * @param[in] dev : Structure instance of bmi160_dev @@ -160,12 +247,28 @@ int8_t bmi160_set_power_mode(struct bmi160_dev *dev); * - BMI160_ACCEL_PMU_LOW_POWER * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error. + * @retval Zero Success + * @retval Negative Error */ int8_t bmi160_get_power_mode(struct bmi160_pmu_status *pmu_status, const struct bmi160_dev *dev); +/** + * \ingroup bmi160 + * \defgroup bmi160ApiData Sensor Data + * @brief Read sensor data + */ + /*! - * @brief This API reads sensor data, stores it in + * \ingroup bmi160ApiData + * \page bmi160_api_bmi160_get_sensor_data bmi160_get_sensor_data + * \code + * int8_t bmi160_get_sensor_data(uint8_t select_sensor, + * struct bmi160_sensor_data *accel, + * struct bmi160_sensor_data *gyro, + * const struct bmi160_dev *dev); + * + * \endcode + * @details This API reads sensor data, stores it in * the bmi160_sensor_data structure pointer passed by the user. * The user can ask for accel data ,gyro data or both sensor * data using bmi160_select_sensor enum @@ -177,15 +280,27 @@ int8_t bmi160_get_power_mode(struct bmi160_pmu_status *pmu_status, const struct * @note : Refer user guide for detailed info. * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error + * @retval Zero Success + * @retval Negative Error */ int8_t bmi160_get_sensor_data(uint8_t select_sensor, struct bmi160_sensor_data *accel, struct bmi160_sensor_data *gyro, const struct bmi160_dev *dev); +/** + * \ingroup bmi160 + * \defgroup bmi160ApiInt Interrupt configuration + * @brief Set interrupt configuration of the sensor + */ + /*! - * @brief This API configures the necessary interrupt based on + * \ingroup bmi160ApiInt + * \page bmi160_api_bmi160_set_int_config bmi160_set_int_config + * \code + * int8_t bmi160_set_int_config(struct bmi160_int_settg *int_config, struct bmi160_dev *dev); + * \endcode + * @details This API configures the necessary interrupt based on * the user settings in the bmi160_int_settg structure instance. * * @param[in] int_config : Structure instance of bmi160_int_settg. @@ -193,36 +308,66 @@ int8_t bmi160_get_sensor_data(uint8_t select_sensor, * @note : Refer user guide for detailed info. * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error + * @retval Zero Success + * @retval Negative Error */ int8_t bmi160_set_int_config(struct bmi160_int_settg *int_config, struct bmi160_dev *dev); +/** + * \ingroup bmi160 + * \defgroup bmi160ApiStepC Step counter + * @brief Step counter operations + */ + /*! - * @brief This API enables the step counter feature. + * \ingroup bmi160ApiStepC + * \page bmi160_api_bmi160_set_step_counter bmi160_set_step_counter + * \code + * int8_t bmi160_set_step_counter(uint8_t step_cnt_enable, const struct bmi160_dev *dev); + * \endcode + * @details This API enables the step counter feature. * * @param[in] step_cnt_enable : value to enable or disable * @param[in] dev : Structure instance of bmi160_dev. * @note : Refer user guide for detailed info. * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error + * @retval Zero Success + * @retval Negative Error */ int8_t bmi160_set_step_counter(uint8_t step_cnt_enable, const struct bmi160_dev *dev); /*! - * @brief This API reads the step counter value. + * \ingroup bmi160ApiStepC + * \page bmi160_api_bmi160_read_step_counter bmi160_read_step_counter + * \code + * int8_t bmi160_read_step_counter(uint16_t *step_val, const struct bmi160_dev *dev); + * \endcode + * @details This API reads the step counter value. * * @param[in] step_val : Pointer to store the step counter value. * @param[in] dev : Structure instance of bmi160_dev. * @note : Refer user guide for detailed info. * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error + * @retval Zero Success + * @retval Negative Error */ int8_t bmi160_read_step_counter(uint16_t *step_val, const struct bmi160_dev *dev); +/** + * \ingroup bmi160 + * \defgroup bmi160ApiAux Auxiliary sensor + * @brief Auxiliary sensor operations + */ + /*! - * @brief This API reads the mention no of byte of data from the given + * \ingroup bmi160ApiAux + * \page bmi160_api_bmi160_aux_read bmi160_aux_read + * \code + * int8_t bmi160_aux_read(uint8_t reg_addr, uint8_t *aux_data, uint16_t len, const struct bmi160_dev *dev); + * \endcode + * @details This API reads the mention no of byte of data from the given * register address of auxiliary sensor. * * @param[in] reg_addr : Address of register to read. @@ -232,12 +377,18 @@ int8_t bmi160_read_step_counter(uint16_t *step_val, const struct bmi160_dev *dev * @note : Refer user guide for detailed info. * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error + * @retval Zero Success + * @retval Negative Error */ int8_t bmi160_aux_read(uint8_t reg_addr, uint8_t *aux_data, uint16_t len, const struct bmi160_dev *dev); /*! - * @brief This API writes the mention no of byte of data to the given + * \ingroup bmi160ApiAux + * \page bmi160_api_bmi160_aux_write bmi160_aux_write + * \code + * int8_t bmi160_aux_write(uint8_t reg_addr, uint8_t *aux_data, uint16_t len, const struct bmi160_dev *dev); + * \endcode + * @details This API writes the mention no of byte of data to the given * register address of auxiliary sensor. * * @param[in] reg_addr : Address of register to write. @@ -247,24 +398,36 @@ int8_t bmi160_aux_read(uint8_t reg_addr, uint8_t *aux_data, uint16_t len, const * @note : Refer user guide for detailed info. * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error + * @retval Zero Success + * @retval Negative Error */ int8_t bmi160_aux_write(uint8_t reg_addr, uint8_t *aux_data, uint16_t len, const struct bmi160_dev *dev); /*! - * @brief This API initialize the auxiliary sensor + * \ingroup bmi160ApiAux + * \page bmi160_api_bmi160_aux_init bmi160_aux_init + * \code + * int8_t bmi160_aux_init(const struct bmi160_dev *dev); + * \endcode + * @details This API initialize the auxiliary sensor * in order to access it. * * @param[in] dev : Structure instance of bmi160_dev. * @note : Refer user guide for detailed info. * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error + * @retval Zero Success + * @retval Negative Error */ int8_t bmi160_aux_init(const struct bmi160_dev *dev); /*! - * @brief This API is used to setup the auxiliary sensor of bmi160 in auto mode + * \ingroup bmi160ApiAux + * \page bmi160_api_bmi160_set_aux_auto_mode bmi160_set_aux_auto_mode + * \code + * int8_t bmi160_set_aux_auto_mode(uint8_t *data_addr, struct bmi160_dev *dev); + * \endcode + * @details This API is used to setup the auxiliary sensor of bmi160 in auto mode * Thus enabling the auto update of 8 bytes of data from auxiliary sensor * to BMI160 register address 0x04 to 0x0B * @@ -278,6 +441,7 @@ int8_t bmi160_aux_init(const struct bmi160_dev *dev); * dev->aux_cfg.aux_odr to the required value from the table * before calling this API * + *@verbatim * dev->aux_cfg.aux_odr | Auxiliary ODR (Hz) * -----------------------|----------------------- * BMI160_AUX_ODR_0_78HZ | 25/32 @@ -291,27 +455,40 @@ int8_t bmi160_aux_init(const struct bmi160_dev *dev); * BMI160_AUX_ODR_200HZ | 200 * BMI160_AUX_ODR_400HZ | 400 * BMI160_AUX_ODR_800HZ | 800 + *@endverbatim * * @note : Other values of dev->aux_cfg.aux_odr are reserved and not for use * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error + * @retval Zero Success + * @retval Negative Error */ int8_t bmi160_set_aux_auto_mode(uint8_t *data_addr, struct bmi160_dev *dev); /*! - * @brief This API configures the 0x4C register and settings like + * \ingroup bmi160ApiAux + * \page bmi160_api_bmi160_config_aux_mode bmi160_config_aux_mode + * \code + * int8_t bmi160_config_aux_mode(const struct bmi160_dev *dev); + * \endcode + * @details This API configures the 0x4C register and settings like * Auxiliary sensor manual enable/ disable and aux burst read length. * * @param[in] dev : Structure instance of bmi160_dev. * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error + * @retval Zero Success + * @retval Negative Error */ int8_t bmi160_config_aux_mode(const struct bmi160_dev *dev); /*! - * @brief This API is used to read the raw uncompensated auxiliary sensor + * \ingroup bmi160ApiAux + * \page bmi160_api_bmi160_read_aux_data_auto_mode bmi160_read_aux_data_auto_mode + * \code + * int8_t bmi160_read_aux_data_auto_mode(uint8_t *aux_data, const struct bmi160_dev *dev); + * \endcode + * @details This API is used to read the raw uncompensated auxiliary sensor * data of 8 bytes from BMI160 register address 0x04 to 0x0B * * @param[in] aux_data : Pointer to user array of length 8 bytes @@ -319,24 +496,38 @@ int8_t bmi160_config_aux_mode(const struct bmi160_dev *dev); * length 8 bytes * @param[in] dev : Structure instance of bmi160_dev * - * @return Result of API execution status * @retval zero -> Success / -ve value -> Error + * @retval Zero Success + * @retval Negative Error */ int8_t bmi160_read_aux_data_auto_mode(uint8_t *aux_data, const struct bmi160_dev *dev); +/** + * \ingroup bmi160 + * \defgroup bmi160ApiSelfTest Self test + * @brief Perform self test of the sensor + */ + /*! - * @brief This is used to perform self test of accel/gyro of the BMI160 sensor + * \ingroup bmi160ApiSelfTest + * \page bmi160_api_bmi160_perform_self_test bmi160_perform_self_test + * \code + * int8_t bmi160_perform_self_test(uint8_t select_sensor, struct bmi160_dev *dev); + * \endcode + * @details This is used to perform self test of accel/gyro of the BMI160 sensor * * @param[in] select_sensor : enum to choose accel or gyro for self test * @param[in] dev : Structure instance of bmi160_dev * * @note self test can be performed either for accel/gyro at any instant. * + *@verbatim * value of select_sensor | Inference *----------------------------------|-------------------------------- * BMI160_ACCEL_ONLY | Accel self test enabled * BMI160_GYRO_ONLY | Gyro self test enabled * BMI160_BOTH_ACCEL_AND_GYRO | NOT TO BE USED + *@endverbatim * * @note The return value of this API gives us the result of self test. * @@ -344,18 +535,25 @@ int8_t bmi160_read_aux_data_auto_mode(uint8_t *aux_data, const struct bmi160_dev * set the desired settings after performing the self test. * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error / +ve value -> Self-test fail - * - * Return value | Result of self test - * --------------------------------|--------------------------------- - * BMI160_OK | Self test success - * BMI160_W_GYRO_SELF_TEST_FAIL | Gyro self test fail - * BMI160_W_ACCEl_SELF_TEST_FAIL | Accel self test fail + * @retval BMI160_OK Self test success + * @retval BMI160_W_GYRO_SELF_TEST_FAIL Gyro self test fail + * @retval BMI160_W_ACCEl_SELF_TEST_FAIL Accel self test fail */ int8_t bmi160_perform_self_test(uint8_t select_sensor, struct bmi160_dev *dev); +/** + * \ingroup bmi160 + * \defgroup bmi160ApiFIFO FIFO + * @brief FIFO operations of the sensor + */ + /*! - * @brief This API reads data from the fifo buffer. + * \ingroup bmi160ApiFIFO + * \page bmi160_api_bmi160_get_fifo_data bmi160_get_fifo_data + * \code + * int8_t bmi160_get_fifo_data(struct bmi160_dev const *dev); + * \endcode + * @details This API reads data from the fifo buffer. * * @note User has to allocate the FIFO buffer along with * corresponding fifo length from his side before calling this API @@ -368,13 +566,18 @@ int8_t bmi160_perform_self_test(uint8_t select_sensor, struct bmi160_dev *dev); * @param[in] dev : Structure instance of bmi160_dev. * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error - * + * @retval Zero Success + * @retval Negative Error */ int8_t bmi160_get_fifo_data(struct bmi160_dev const *dev); /*! - * @brief This API writes fifo_flush command to command register.This + * \ingroup bmi160ApiFIFO + * \page bmi160_api_bmi160_set_fifo_flush bmi160_set_fifo_flush + * \code + * int8_t bmi160_set_fifo_flush(const struct bmi160_dev *dev); + * \endcode + * @details This API writes fifo_flush command to command register.This * action clears all data in the Fifo without changing fifo configuration * settings. * @@ -387,13 +590,21 @@ int8_t bmi160_get_fifo_data(struct bmi160_dev const *dev); */ int8_t bmi160_set_fifo_flush(const struct bmi160_dev *dev); -/*! @brief This API sets the FIFO configuration in the sensor. +/*! + * \ingroup bmi160ApiFIFO + * \page bmi160_api_bmi160_set_fifo_config bmi160_set_fifo_config + * \code + * int8_t bmi160_set_fifo_config(uint8_t config, uint8_t enable, struct bmi160_dev const *dev); + * \endcode + * @details This API sets the FIFO configuration in the sensor. * * @param[in] config : variable used to specify the FIFO * configurations which are to be enabled or disabled in the sensor. * * @note : User can set either set one or more or all FIFO configurations * by ORing the below mentioned macros. + * + *@verbatim * config | Value * ------------------------|--------------------------- * BMI160_FIFO_TIME | 0x02 @@ -401,8 +612,9 @@ int8_t bmi160_set_fifo_flush(const struct bmi160_dev *dev); * BMI160_FIFO_TAG_INT1 | 0x08 * BMI160_FIFO_HEADER | 0x10 * BMI160_FIFO_AUX | 0x20 - * BMI160_FIFO_ACCEL | 0x40 + * BMI160_FIFO_ACCEL | 0x40 * BMI160_FIFO_GYRO | 0x80 + *@endverbatim * * @param[in] enable : Parameter used to enable or disable the above * FIFO configuration @@ -415,7 +627,13 @@ int8_t bmi160_set_fifo_flush(const struct bmi160_dev *dev); */ int8_t bmi160_set_fifo_config(uint8_t config, uint8_t enable, struct bmi160_dev const *dev); -/*! @brief This API is used to configure the down sampling ratios of +/*! + * \ingroup bmi160ApiFIFO + * \page bmi160_api_bmi160_set_fifo_down bmi160_set_fifo_down + * \code + * int8_t bmi160_set_fifo_down(uint8_t fifo_down, const struct bmi160_dev *dev); + * \endcode + * @details This API is used to configure the down sampling ratios of * the accel and gyro data for FIFO.Also, it configures filtered or * pre-filtered data for the fifo for accel and gyro. * @@ -424,6 +642,8 @@ int8_t bmi160_set_fifo_config(uint8_t config, uint8_t enable, struct bmi160_dev * * @note The user must select one among the following macros to * select down-sampling ratio for accel + * + *@verbatim * config | Value * -------------------------------------|--------------------------- * BMI160_ACCEL_FIFO_DOWN_ZERO | 0x00 @@ -434,10 +654,12 @@ int8_t bmi160_set_fifo_config(uint8_t config, uint8_t enable, struct bmi160_dev * BMI160_ACCEL_FIFO_DOWN_FIVE | 0x50 * BMI160_ACCEL_FIFO_DOWN_SIX | 0x60 * BMI160_ACCEL_FIFO_DOWN_SEVEN | 0x70 + *@endverbatim * * @note The user must select one among the following macros to * select down-sampling ratio for gyro * + *@verbatim * config | Value * -------------------------------------|--------------------------- * BMI160_GYRO_FIFO_DOWN_ZERO | 0x00 @@ -448,16 +670,23 @@ int8_t bmi160_set_fifo_config(uint8_t config, uint8_t enable, struct bmi160_dev * BMI160_GYRO_FIFO_DOWN_FIVE | 0x05 * BMI160_GYRO_FIFO_DOWN_SIX | 0x06 * BMI160_GYRO_FIFO_DOWN_SEVEN | 0x07 + *@endverbatim * * @note The user can enable filtered accel data by the following macro + * + *@verbatim * config | Value * -------------------------------------|--------------------------- * BMI160_ACCEL_FIFO_FILT_EN | 0x80 + *@endverbatim * * @note The user can enable filtered gyro data by the following macro + * + *@verbatim * config | Value * -------------------------------------|--------------------------- * BMI160_GYRO_FIFO_FILT_EN | 0x08 + *@endverbatim * * @note : By ORing the above mentioned macros, the user can select * the required FIFO down config settings @@ -472,7 +701,12 @@ int8_t bmi160_set_fifo_config(uint8_t config, uint8_t enable, struct bmi160_dev int8_t bmi160_set_fifo_down(uint8_t fifo_down, const struct bmi160_dev *dev); /*! - * @brief This API sets the FIFO watermark level in the sensor. + * \ingroup bmi160ApiFIFO + * \page bmi160_api_bmi160_set_fifo_wm bmi160_set_fifo_wm + * \code + * int8_t bmi160_set_fifo_wm(uint8_t fifo_wm, const struct bmi160_dev *dev); + * \endcode + * @details This API sets the FIFO watermark level in the sensor. * * @note The FIFO watermark is issued when the FIFO fill level is * equal or above the watermark level and units of watermark is 4 bytes. @@ -488,7 +722,13 @@ int8_t bmi160_set_fifo_down(uint8_t fifo_down, const struct bmi160_dev *dev); int8_t bmi160_set_fifo_wm(uint8_t fifo_wm, const struct bmi160_dev *dev); /*! - * @brief This API parses and extracts the accelerometer frames from + * \ingroup bmi160ApiFIFO + * \page bmi160_api_bmi160_extract_accel bmi160_extract_accel + * \code + * int8_t bmi160_extract_accel(struct bmi160_sensor_data *accel_data, uint8_t *accel_length, struct bmi160_dev const + **dev); + * \endcode + * @details This API parses and extracts the accelerometer frames from * FIFO data read by the "bmi160_get_fifo_data" API and stores it in * the "accel_data" structure instance. * @@ -513,7 +753,12 @@ int8_t bmi160_set_fifo_wm(uint8_t fifo_wm, const struct bmi160_dev *dev); int8_t bmi160_extract_accel(struct bmi160_sensor_data *accel_data, uint8_t *accel_length, struct bmi160_dev const *dev); /*! - * @brief This API parses and extracts the gyro frames from + * \ingroup bmi160ApiFIFO + * \page bmi160_api_bmi160_extract_gyro bmi160_extract_gyro + * \code + * int8_t bmi160_extract_gyro(struct bmi160_sensor_data *gyro_data, uint8_t *gyro_length, struct bmi160_dev const *dev); + * \endcode + * @details This API parses and extracts the gyro frames from * FIFO data read by the "bmi160_get_fifo_data" API and stores it in * the "gyro_data" structure instance. * @@ -538,7 +783,12 @@ int8_t bmi160_extract_accel(struct bmi160_sensor_data *accel_data, uint8_t *acce int8_t bmi160_extract_gyro(struct bmi160_sensor_data *gyro_data, uint8_t *gyro_length, struct bmi160_dev const *dev); /*! - * @brief This API parses and extracts the aux frames from + * \ingroup bmi160ApiFIFO + * \page bmi160_api_bmi160_extract_aux bmi160_extract_aux + * \code + * int8_t bmi160_extract_aux(struct bmi160_aux_data *aux_data, uint8_t *aux_len, struct bmi160_dev const *dev); + * \endcode + * @details This API parses and extracts the aux frames from * FIFO data read by the "bmi160_get_fifo_data" API and stores it in * the bmi160_aux_data structure instance. * @@ -562,8 +812,19 @@ int8_t bmi160_extract_gyro(struct bmi160_sensor_data *gyro_data, uint8_t *gyro_l */ int8_t bmi160_extract_aux(struct bmi160_aux_data *aux_data, uint8_t *aux_len, struct bmi160_dev const *dev); +/** + * \ingroup bmi160 + * \defgroup bmi160ApiFOC FOC + * @brief Start FOC of accel and gyro sensors + */ + /*! - * @brief This API starts the FOC of accel and gyro + * \ingroup bmi160ApiFOC + * \page bmi160_api_bmi160_start_foc bmi160_start_foc + * \code + * int8_t bmi160_start_foc(const struct bmi160_foc_conf *foc_conf, + * \endcode + * @details This API starts the FOC of accel and gyro * * @note FOC should not be used in low-power mode of sensor * @@ -605,8 +866,19 @@ int8_t bmi160_start_foc(const struct bmi160_foc_conf *foc_conf, struct bmi160_offsets *offset, struct bmi160_dev const *dev); +/** + * \ingroup bmi160 + * \defgroup bmi160ApiOffsets Offsets + * @brief Set / Get offset values of accel and gyro sensors + */ + /*! - * @brief This API reads and stores the offset values of accel and gyro + * \ingroup bmi160ApiOffsets + * \page bmi160_api_bmi160_get_offsets bmi160_get_offsets + * \code + * int8_t bmi160_get_offsets(struct bmi160_offsets *offset, const struct bmi160_dev *dev); + * \endcode + * @details This API reads and stores the offset values of accel and gyro * * @param[in,out] offset : Structure instance of bmi160_offsets in which * the offset values are read and stored @@ -619,7 +891,14 @@ int8_t bmi160_start_foc(const struct bmi160_foc_conf *foc_conf, int8_t bmi160_get_offsets(struct bmi160_offsets *offset, const struct bmi160_dev *dev); /*! - * @brief This API writes the offset values of accel and gyro to + * \ingroup bmi160ApiOffsets + * \page bmi160_api_bmi160_set_offsets bmi160_set_offsets + * \code + * int8_t bmi160_set_offsets(const struct bmi160_foc_conf *foc_conf, + * const struct bmi160_offsets *offset, + * struct bmi160_dev const *dev); + * \endcode + * @details This API writes the offset values of accel and gyro to * the sensor but these values will be reset on POR or soft reset. * * @param[in] foc_conf : Structure instance of bmi160_foc_conf which @@ -645,8 +924,19 @@ int8_t bmi160_set_offsets(const struct bmi160_foc_conf *foc_conf, const struct bmi160_offsets *offset, struct bmi160_dev const *dev); +/** + * \ingroup bmi160 + * \defgroup bmi160ApiNVM NVM + * @brief Write image registers values to NVM + */ + /*! - * @brief This API writes the image registers values to NVM which is + * \ingroup bmi160ApiNVM + * \page bmi160_api_bmi160_update_nvm bmi160_update_nvm + * \code + * int8_t bmi160_update_nvm(struct bmi160_dev const *dev); + * \endcode + * @details This API writes the image registers values to NVM which is * stored even after POR or soft reset * * @param[in] dev : Structure instance of bmi160_dev. @@ -657,8 +947,21 @@ int8_t bmi160_set_offsets(const struct bmi160_foc_conf *foc_conf, */ int8_t bmi160_update_nvm(struct bmi160_dev const *dev); +/** + * \ingroup bmi160 + * \defgroup bmi160ApiInts Interrupt status + * @brief Read interrupt status from the sensor + */ + /*! - * @brief This API gets the interrupt status from the sensor. + * \ingroup bmi160ApiInts + * \page bmi160_api_bmi160_get_int_status bmi160_get_int_status + * \code + * int8_t bmi160_get_int_status(enum bmi160_int_status_sel int_status_sel, + * union bmi160_int_status *int_status, + * struct bmi160_dev const *dev); + * \endcode + * @details This API gets the interrupt status from the sensor. * * @param[in] int_status_sel : Enum variable to select either individual or all the * interrupt status bits. @@ -680,4 +983,3 @@ int8_t bmi160_get_int_status(enum bmi160_int_status_sel int_status_sel, #endif #endif /* BMI160_H_ */ -/** @}*/ diff --git a/bmi160_defs.h b/bmi160_defs.h index cc66c56..a0b5c43 100644 --- a/bmi160_defs.h +++ b/bmi160_defs.h @@ -30,17 +30,12 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * -* @file bmi160_defs.h -* @date 10/01/2020 -* @version 3.8.1 +* @file bmi160_defs.h +* @date 2021-03-12 +* @version v3.9.1 * */ -/*! - * @defgroup bmi160_defs - * @brief - * @{*/ - #ifndef BMI160_DEFS_H_ #define BMI160_DEFS_H_ @@ -56,633 +51,628 @@ /*************************** Common macros *****************************/ #if !defined(UINT8_C) && !defined(INT8_C) -#define INT8_C(x) S8_C(x) -#define UINT8_C(x) U8_C(x) +#define INT8_C(x) S8_C(x) +#define UINT8_C(x) U8_C(x) #endif #if !defined(UINT16_C) && !defined(INT16_C) -#define INT16_C(x) S16_C(x) -#define UINT16_C(x) U16_C(x) +#define INT16_C(x) S16_C(x) +#define UINT16_C(x) U16_C(x) #endif #if !defined(INT32_C) && !defined(UINT32_C) -#define INT32_C(x) S32_C(x) -#define UINT32_C(x) U32_C(x) +#define INT32_C(x) S32_C(x) +#define UINT32_C(x) U32_C(x) #endif #if !defined(INT64_C) && !defined(UINT64_C) -#define INT64_C(x) S64_C(x) -#define UINT64_C(x) U64_C(x) +#define INT64_C(x) S64_C(x) +#define UINT64_C(x) U64_C(x) #endif /**@}*/ /**\name C standard macros */ #ifndef NULL #ifdef __cplusplus -#define NULL 0 +#define NULL 0 #else -#define NULL ((void *) 0) +#define NULL ((void *) 0) #endif #endif /*************************** Sensor macros *****************************/ /* Test for an endian machine */ #ifndef __ORDER_LITTLE_ENDIAN__ -#define __ORDER_LITTLE_ENDIAN__ 0 +#define __ORDER_LITTLE_ENDIAN__ 0 #endif #ifndef __BYTE_ORDER__ -#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ +#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ #endif #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #ifndef LITTLE_ENDIAN -#define LITTLE_ENDIAN 1 +#define LITTLE_ENDIAN 1 #endif #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #ifndef BIG_ENDIAN -#define BIG_ENDIAN 1 +#define BIG_ENDIAN 1 #endif #else #error "Code does not support Endian format of the processor" #endif /** Mask definitions */ -#define BMI160_ACCEL_BW_MASK UINT8_C(0x70) -#define BMI160_ACCEL_ODR_MASK UINT8_C(0x0F) -#define BMI160_ACCEL_UNDERSAMPLING_MASK UINT8_C(0x80) -#define BMI160_ACCEL_RANGE_MASK UINT8_C(0x0F) -#define BMI160_GYRO_BW_MASK UINT8_C(0x30) -#define BMI160_GYRO_ODR_MASK UINT8_C(0x0F) -#define BMI160_GYRO_RANGE_MSK UINT8_C(0x07) +#define BMI160_ACCEL_BW_MASK UINT8_C(0x70) +#define BMI160_ACCEL_ODR_MASK UINT8_C(0x0F) +#define BMI160_ACCEL_UNDERSAMPLING_MASK UINT8_C(0x80) +#define BMI160_ACCEL_RANGE_MASK UINT8_C(0x0F) +#define BMI160_GYRO_BW_MASK UINT8_C(0x30) +#define BMI160_GYRO_ODR_MASK UINT8_C(0x0F) +#define BMI160_GYRO_RANGE_MASK UINT8_C(0x07) + +#define BMI160_ACCEL_BW_POS UINT8_C(4) +#define BMI160_GYRO_BW_POS UINT8_C(4) /** Mask definitions for INT_EN registers */ -#define BMI160_ANY_MOTION_X_INT_EN_MASK UINT8_C(0x01) -#define BMI160_HIGH_G_X_INT_EN_MASK UINT8_C(0x01) -#define BMI160_NO_MOTION_X_INT_EN_MASK UINT8_C(0x01) -#define BMI160_ANY_MOTION_Y_INT_EN_MASK UINT8_C(0x02) -#define BMI160_HIGH_G_Y_INT_EN_MASK UINT8_C(0x02) -#define BMI160_NO_MOTION_Y_INT_EN_MASK UINT8_C(0x02) -#define BMI160_ANY_MOTION_Z_INT_EN_MASK UINT8_C(0x04) -#define BMI160_HIGH_G_Z_INT_EN_MASK UINT8_C(0x04) -#define BMI160_NO_MOTION_Z_INT_EN_MASK UINT8_C(0x04) -#define BMI160_SIG_MOTION_INT_EN_MASK UINT8_C(0x07) -#define BMI160_ANY_MOTION_ALL_INT_EN_MASK UINT8_C(0x07) -#define BMI160_STEP_DETECT_INT_EN_MASK UINT8_C(0x08) -#define BMI160_DOUBLE_TAP_INT_EN_MASK UINT8_C(0x10) -#define BMI160_SINGLE_TAP_INT_EN_MASK UINT8_C(0x20) -#define BMI160_FIFO_FULL_INT_EN_MASK UINT8_C(0x20) -#define BMI160_ORIENT_INT_EN_MASK UINT8_C(0x40) -#define BMI160_FIFO_WATERMARK_INT_EN_MASK UINT8_C(0x40) -#define BMI160_LOW_G_INT_EN_MASK UINT8_C(0x08) -#define BMI160_STEP_DETECT_EN_MASK UINT8_C(0x08) -#define BMI160_FLAT_INT_EN_MASK UINT8_C(0x80) -#define BMI160_DATA_RDY_INT_EN_MASK UINT8_C(0x10) +#define BMI160_ANY_MOTION_X_INT_EN_MASK UINT8_C(0x01) +#define BMI160_HIGH_G_X_INT_EN_MASK UINT8_C(0x01) +#define BMI160_NO_MOTION_X_INT_EN_MASK UINT8_C(0x01) +#define BMI160_ANY_MOTION_Y_INT_EN_MASK UINT8_C(0x02) +#define BMI160_HIGH_G_Y_INT_EN_MASK UINT8_C(0x02) +#define BMI160_NO_MOTION_Y_INT_EN_MASK UINT8_C(0x02) +#define BMI160_ANY_MOTION_Z_INT_EN_MASK UINT8_C(0x04) +#define BMI160_HIGH_G_Z_INT_EN_MASK UINT8_C(0x04) +#define BMI160_NO_MOTION_Z_INT_EN_MASK UINT8_C(0x04) +#define BMI160_SIG_MOTION_INT_EN_MASK UINT8_C(0x07) +#define BMI160_ANY_MOTION_ALL_INT_EN_MASK UINT8_C(0x07) +#define BMI160_STEP_DETECT_INT_EN_MASK UINT8_C(0x08) +#define BMI160_DOUBLE_TAP_INT_EN_MASK UINT8_C(0x10) +#define BMI160_SINGLE_TAP_INT_EN_MASK UINT8_C(0x20) +#define BMI160_FIFO_FULL_INT_EN_MASK UINT8_C(0x20) +#define BMI160_ORIENT_INT_EN_MASK UINT8_C(0x40) +#define BMI160_FIFO_WATERMARK_INT_EN_MASK UINT8_C(0x40) +#define BMI160_LOW_G_INT_EN_MASK UINT8_C(0x08) +#define BMI160_STEP_DETECT_EN_MASK UINT8_C(0x08) +#define BMI160_FLAT_INT_EN_MASK UINT8_C(0x80) +#define BMI160_DATA_RDY_INT_EN_MASK UINT8_C(0x10) /** PMU status Macros */ -#define BMI160_AUX_PMU_SUSPEND UINT8_C(0x00) -#define BMI160_AUX_PMU_NORMAL UINT8_C(0x01) -#define BMI160_AUX_PMU_LOW_POWER UINT8_C(0x02) +#define BMI160_AUX_PMU_SUSPEND UINT8_C(0x00) +#define BMI160_AUX_PMU_NORMAL UINT8_C(0x01) +#define BMI160_AUX_PMU_LOW_POWER UINT8_C(0x02) -#define BMI160_GYRO_PMU_SUSPEND UINT8_C(0x00) -#define BMI160_GYRO_PMU_NORMAL UINT8_C(0x01) -#define BMI160_GYRO_PMU_FSU UINT8_C(0x03) +#define BMI160_GYRO_PMU_SUSPEND UINT8_C(0x00) +#define BMI160_GYRO_PMU_NORMAL UINT8_C(0x01) +#define BMI160_GYRO_PMU_FSU UINT8_C(0x03) -#define BMI160_ACCEL_PMU_SUSPEND UINT8_C(0x00) -#define BMI160_ACCEL_PMU_NORMAL UINT8_C(0x01) -#define BMI160_ACCEL_PMU_LOW_POWER UINT8_C(0x02) +#define BMI160_ACCEL_PMU_SUSPEND UINT8_C(0x00) +#define BMI160_ACCEL_PMU_NORMAL UINT8_C(0x01) +#define BMI160_ACCEL_PMU_LOW_POWER UINT8_C(0x02) /** Mask definitions for INT_OUT_CTRL register */ -#define BMI160_INT1_EDGE_CTRL_MASK UINT8_C(0x01) -#define BMI160_INT1_OUTPUT_MODE_MASK UINT8_C(0x04) -#define BMI160_INT1_OUTPUT_TYPE_MASK UINT8_C(0x02) -#define BMI160_INT1_OUTPUT_EN_MASK UINT8_C(0x08) -#define BMI160_INT2_EDGE_CTRL_MASK UINT8_C(0x10) -#define BMI160_INT2_OUTPUT_MODE_MASK UINT8_C(0x40) -#define BMI160_INT2_OUTPUT_TYPE_MASK UINT8_C(0x20) -#define BMI160_INT2_OUTPUT_EN_MASK UINT8_C(0x80) +#define BMI160_INT1_EDGE_CTRL_MASK UINT8_C(0x01) +#define BMI160_INT1_OUTPUT_MODE_MASK UINT8_C(0x04) +#define BMI160_INT1_OUTPUT_TYPE_MASK UINT8_C(0x02) +#define BMI160_INT1_OUTPUT_EN_MASK UINT8_C(0x08) +#define BMI160_INT2_EDGE_CTRL_MASK UINT8_C(0x10) +#define BMI160_INT2_OUTPUT_MODE_MASK UINT8_C(0x40) +#define BMI160_INT2_OUTPUT_TYPE_MASK UINT8_C(0x20) +#define BMI160_INT2_OUTPUT_EN_MASK UINT8_C(0x80) /** Mask definitions for INT_LATCH register */ -#define BMI160_INT1_INPUT_EN_MASK UINT8_C(0x10) -#define BMI160_INT2_INPUT_EN_MASK UINT8_C(0x20) -#define BMI160_INT_LATCH_MASK UINT8_C(0x0F) +#define BMI160_INT1_INPUT_EN_MASK UINT8_C(0x10) +#define BMI160_INT2_INPUT_EN_MASK UINT8_C(0x20) +#define BMI160_INT_LATCH_MASK UINT8_C(0x0F) /** Mask definitions for INT_MAP register */ -#define BMI160_INT1_LOW_G_MASK UINT8_C(0x01) -#define BMI160_INT1_HIGH_G_MASK UINT8_C(0x02) -#define BMI160_INT1_SLOPE_MASK UINT8_C(0x04) -#define BMI160_INT1_NO_MOTION_MASK UINT8_C(0x08) -#define BMI160_INT1_DOUBLE_TAP_MASK UINT8_C(0x10) -#define BMI160_INT1_SINGLE_TAP_MASK UINT8_C(0x20) -#define BMI160_INT1_FIFO_FULL_MASK UINT8_C(0x20) -#define BMI160_INT1_FIFO_WM_MASK UINT8_C(0x40) -#define BMI160_INT1_ORIENT_MASK UINT8_C(0x40) -#define BMI160_INT1_FLAT_MASK UINT8_C(0x80) -#define BMI160_INT1_DATA_READY_MASK UINT8_C(0x80) -#define BMI160_INT2_LOW_G_MASK UINT8_C(0x01) -#define BMI160_INT1_LOW_STEP_DETECT_MASK UINT8_C(0x01) -#define BMI160_INT2_LOW_STEP_DETECT_MASK UINT8_C(0x01) -#define BMI160_INT2_HIGH_G_MASK UINT8_C(0x02) -#define BMI160_INT2_FIFO_FULL_MASK UINT8_C(0x02) -#define BMI160_INT2_FIFO_WM_MASK UINT8_C(0x04) -#define BMI160_INT2_SLOPE_MASK UINT8_C(0x04) -#define BMI160_INT2_DATA_READY_MASK UINT8_C(0x08) -#define BMI160_INT2_NO_MOTION_MASK UINT8_C(0x08) -#define BMI160_INT2_DOUBLE_TAP_MASK UINT8_C(0x10) -#define BMI160_INT2_SINGLE_TAP_MASK UINT8_C(0x20) -#define BMI160_INT2_ORIENT_MASK UINT8_C(0x40) -#define BMI160_INT2_FLAT_MASK UINT8_C(0x80) +#define BMI160_INT1_LOW_G_MASK UINT8_C(0x01) +#define BMI160_INT1_HIGH_G_MASK UINT8_C(0x02) +#define BMI160_INT1_SLOPE_MASK UINT8_C(0x04) +#define BMI160_INT1_NO_MOTION_MASK UINT8_C(0x08) +#define BMI160_INT1_DOUBLE_TAP_MASK UINT8_C(0x10) +#define BMI160_INT1_SINGLE_TAP_MASK UINT8_C(0x20) +#define BMI160_INT1_FIFO_FULL_MASK UINT8_C(0x20) +#define BMI160_INT1_FIFO_WM_MASK UINT8_C(0x40) +#define BMI160_INT1_ORIENT_MASK UINT8_C(0x40) +#define BMI160_INT1_FLAT_MASK UINT8_C(0x80) +#define BMI160_INT1_DATA_READY_MASK UINT8_C(0x80) +#define BMI160_INT2_LOW_G_MASK UINT8_C(0x01) +#define BMI160_INT1_LOW_STEP_DETECT_MASK UINT8_C(0x01) +#define BMI160_INT2_LOW_STEP_DETECT_MASK UINT8_C(0x01) +#define BMI160_INT2_HIGH_G_MASK UINT8_C(0x02) +#define BMI160_INT2_FIFO_FULL_MASK UINT8_C(0x02) +#define BMI160_INT2_FIFO_WM_MASK UINT8_C(0x04) +#define BMI160_INT2_SLOPE_MASK UINT8_C(0x04) +#define BMI160_INT2_DATA_READY_MASK UINT8_C(0x08) +#define BMI160_INT2_NO_MOTION_MASK UINT8_C(0x08) +#define BMI160_INT2_DOUBLE_TAP_MASK UINT8_C(0x10) +#define BMI160_INT2_SINGLE_TAP_MASK UINT8_C(0x20) +#define BMI160_INT2_ORIENT_MASK UINT8_C(0x40) +#define BMI160_INT2_FLAT_MASK UINT8_C(0x80) /** Mask definitions for INT_DATA register */ -#define BMI160_TAP_SRC_INT_MASK UINT8_C(0x08) -#define BMI160_LOW_HIGH_SRC_INT_MASK UINT8_C(0x80) -#define BMI160_MOTION_SRC_INT_MASK UINT8_C(0x80) +#define BMI160_TAP_SRC_INT_MASK UINT8_C(0x08) +#define BMI160_LOW_HIGH_SRC_INT_MASK UINT8_C(0x80) +#define BMI160_MOTION_SRC_INT_MASK UINT8_C(0x80) /** Mask definitions for INT_MOTION register */ -#define BMI160_SLOPE_INT_DUR_MASK UINT8_C(0x03) -#define BMI160_NO_MOTION_INT_DUR_MASK UINT8_C(0xFC) -#define BMI160_NO_MOTION_SEL_BIT_MASK UINT8_C(0x01) +#define BMI160_SLOPE_INT_DUR_MASK UINT8_C(0x03) +#define BMI160_NO_MOTION_INT_DUR_MASK UINT8_C(0xFC) +#define BMI160_NO_MOTION_SEL_BIT_MASK UINT8_C(0x01) /** Mask definitions for INT_TAP register */ -#define BMI160_TAP_DUR_MASK UINT8_C(0x07) -#define BMI160_TAP_SHOCK_DUR_MASK UINT8_C(0x40) -#define BMI160_TAP_QUIET_DUR_MASK UINT8_C(0x80) -#define BMI160_TAP_THRES_MASK UINT8_C(0x1F) +#define BMI160_TAP_DUR_MASK UINT8_C(0x07) +#define BMI160_TAP_SHOCK_DUR_MASK UINT8_C(0x40) +#define BMI160_TAP_QUIET_DUR_MASK UINT8_C(0x80) +#define BMI160_TAP_THRES_MASK UINT8_C(0x1F) /** Mask definitions for INT_FLAT register */ -#define BMI160_FLAT_THRES_MASK UINT8_C(0x3F) -#define BMI160_FLAT_HOLD_TIME_MASK UINT8_C(0x30) -#define BMI160_FLAT_HYST_MASK UINT8_C(0x07) +#define BMI160_FLAT_THRES_MASK UINT8_C(0x3F) +#define BMI160_FLAT_HOLD_TIME_MASK UINT8_C(0x30) +#define BMI160_FLAT_HYST_MASK UINT8_C(0x07) /** Mask definitions for INT_LOWHIGH register */ -#define BMI160_LOW_G_HYST_MASK UINT8_C(0x03) -#define BMI160_LOW_G_LOW_MODE_MASK UINT8_C(0x04) -#define BMI160_HIGH_G_HYST_MASK UINT8_C(0xC0) +#define BMI160_LOW_G_HYST_MASK UINT8_C(0x03) +#define BMI160_LOW_G_LOW_MODE_MASK UINT8_C(0x04) +#define BMI160_HIGH_G_HYST_MASK UINT8_C(0xC0) /** Mask definitions for INT_SIG_MOTION register */ -#define BMI160_SIG_MOTION_SEL_MASK UINT8_C(0x02) -#define BMI160_SIG_MOTION_SKIP_MASK UINT8_C(0x0C) -#define BMI160_SIG_MOTION_PROOF_MASK UINT8_C(0x30) +#define BMI160_SIG_MOTION_SEL_MASK UINT8_C(0x02) +#define BMI160_SIG_MOTION_SKIP_MASK UINT8_C(0x0C) +#define BMI160_SIG_MOTION_PROOF_MASK UINT8_C(0x30) /** Mask definitions for INT_ORIENT register */ -#define BMI160_ORIENT_MODE_MASK UINT8_C(0x03) -#define BMI160_ORIENT_BLOCK_MASK UINT8_C(0x0C) -#define BMI160_ORIENT_HYST_MASK UINT8_C(0xF0) -#define BMI160_ORIENT_THETA_MASK UINT8_C(0x3F) -#define BMI160_ORIENT_UD_ENABLE UINT8_C(0x40) -#define BMI160_AXES_EN_MASK UINT8_C(0x80) +#define BMI160_ORIENT_MODE_MASK UINT8_C(0x03) +#define BMI160_ORIENT_BLOCK_MASK UINT8_C(0x0C) +#define BMI160_ORIENT_HYST_MASK UINT8_C(0xF0) +#define BMI160_ORIENT_THETA_MASK UINT8_C(0x3F) +#define BMI160_ORIENT_UD_ENABLE UINT8_C(0x40) +#define BMI160_AXES_EN_MASK UINT8_C(0x80) /** Mask definitions for FIFO_CONFIG register */ -#define BMI160_FIFO_GYRO UINT8_C(0x80) -#define BMI160_FIFO_ACCEL UINT8_C(0x40) -#define BMI160_FIFO_AUX UINT8_C(0x20) -#define BMI160_FIFO_TAG_INT1 UINT8_C(0x08) -#define BMI160_FIFO_TAG_INT2 UINT8_C(0x04) -#define BMI160_FIFO_TIME UINT8_C(0x02) -#define BMI160_FIFO_HEADER UINT8_C(0x10) -#define BMI160_FIFO_CONFIG_1_MASK UINT8_C(0xFE) +#define BMI160_FIFO_GYRO UINT8_C(0x80) +#define BMI160_FIFO_ACCEL UINT8_C(0x40) +#define BMI160_FIFO_AUX UINT8_C(0x20) +#define BMI160_FIFO_TAG_INT1 UINT8_C(0x08) +#define BMI160_FIFO_TAG_INT2 UINT8_C(0x04) +#define BMI160_FIFO_TIME UINT8_C(0x02) +#define BMI160_FIFO_HEADER UINT8_C(0x10) +#define BMI160_FIFO_CONFIG_1_MASK UINT8_C(0xFE) /** Mask definitions for STEP_CONF register */ -#define BMI160_STEP_COUNT_EN_BIT_MASK UINT8_C(0x08) -#define BMI160_STEP_DETECT_MIN_THRES_MASK UINT8_C(0x18) -#define BMI160_STEP_DETECT_STEPTIME_MIN_MASK UINT8_C(0x07) -#define BMI160_STEP_MIN_BUF_MASK UINT8_C(0x07) +#define BMI160_STEP_COUNT_EN_BIT_MASK UINT8_C(0x08) +#define BMI160_STEP_DETECT_MIN_THRES_MASK UINT8_C(0x18) +#define BMI160_STEP_DETECT_STEPTIME_MIN_MASK UINT8_C(0x07) +#define BMI160_STEP_MIN_BUF_MASK UINT8_C(0x07) /** Mask definition for FIFO Header Data Tag */ -#define BMI160_FIFO_TAG_INTR_MASK UINT8_C(0xFC) +#define BMI160_FIFO_TAG_INTR_MASK UINT8_C(0xFC) /** Fifo byte counter mask definitions */ -#define BMI160_FIFO_BYTE_COUNTER_MASK UINT8_C(0x07) +#define BMI160_FIFO_BYTE_COUNTER_MASK UINT8_C(0x07) /** Enable/disable bit value */ -#define BMI160_ENABLE UINT8_C(0x01) -#define BMI160_DISABLE UINT8_C(0x00) +#define BMI160_ENABLE UINT8_C(0x01) +#define BMI160_DISABLE UINT8_C(0x00) /** Latch Duration */ -#define BMI160_LATCH_DUR_NONE UINT8_C(0x00) -#define BMI160_LATCH_DUR_312_5_MICRO_SEC UINT8_C(0x01) -#define BMI160_LATCH_DUR_625_MICRO_SEC UINT8_C(0x02) -#define BMI160_LATCH_DUR_1_25_MILLI_SEC UINT8_C(0x03) -#define BMI160_LATCH_DUR_2_5_MILLI_SEC UINT8_C(0x04) -#define BMI160_LATCH_DUR_5_MILLI_SEC UINT8_C(0x05) -#define BMI160_LATCH_DUR_10_MILLI_SEC UINT8_C(0x06) -#define BMI160_LATCH_DUR_20_MILLI_SEC UINT8_C(0x07) -#define BMI160_LATCH_DUR_40_MILLI_SEC UINT8_C(0x08) -#define BMI160_LATCH_DUR_80_MILLI_SEC UINT8_C(0x09) -#define BMI160_LATCH_DUR_160_MILLI_SEC UINT8_C(0x0A) -#define BMI160_LATCH_DUR_320_MILLI_SEC UINT8_C(0x0B) -#define BMI160_LATCH_DUR_640_MILLI_SEC UINT8_C(0x0C) -#define BMI160_LATCH_DUR_1_28_SEC UINT8_C(0x0D) -#define BMI160_LATCH_DUR_2_56_SEC UINT8_C(0x0E) -#define BMI160_LATCHED UINT8_C(0x0F) +#define BMI160_LATCH_DUR_NONE UINT8_C(0x00) +#define BMI160_LATCH_DUR_312_5_MICRO_SEC UINT8_C(0x01) +#define BMI160_LATCH_DUR_625_MICRO_SEC UINT8_C(0x02) +#define BMI160_LATCH_DUR_1_25_MILLI_SEC UINT8_C(0x03) +#define BMI160_LATCH_DUR_2_5_MILLI_SEC UINT8_C(0x04) +#define BMI160_LATCH_DUR_5_MILLI_SEC UINT8_C(0x05) +#define BMI160_LATCH_DUR_10_MILLI_SEC UINT8_C(0x06) +#define BMI160_LATCH_DUR_20_MILLI_SEC UINT8_C(0x07) +#define BMI160_LATCH_DUR_40_MILLI_SEC UINT8_C(0x08) +#define BMI160_LATCH_DUR_80_MILLI_SEC UINT8_C(0x09) +#define BMI160_LATCH_DUR_160_MILLI_SEC UINT8_C(0x0A) +#define BMI160_LATCH_DUR_320_MILLI_SEC UINT8_C(0x0B) +#define BMI160_LATCH_DUR_640_MILLI_SEC UINT8_C(0x0C) +#define BMI160_LATCH_DUR_1_28_SEC UINT8_C(0x0D) +#define BMI160_LATCH_DUR_2_56_SEC UINT8_C(0x0E) +#define BMI160_LATCHED UINT8_C(0x0F) /** BMI160 Register map */ -#define BMI160_CHIP_ID_ADDR UINT8_C(0x00) -#define BMI160_ERROR_REG_ADDR UINT8_C(0x02) -#define BMI160_PMU_STATUS_ADDR UINT8_C(0x03) -#define BMI160_AUX_DATA_ADDR UINT8_C(0x04) -#define BMI160_GYRO_DATA_ADDR UINT8_C(0x0C) -#define BMI160_ACCEL_DATA_ADDR UINT8_C(0x12) -#define BMI160_STATUS_ADDR UINT8_C(0x1B) -#define BMI160_INT_STATUS_ADDR UINT8_C(0x1C) -#define BMI160_FIFO_LENGTH_ADDR UINT8_C(0x22) -#define BMI160_FIFO_DATA_ADDR UINT8_C(0x24) -#define BMI160_ACCEL_CONFIG_ADDR UINT8_C(0x40) -#define BMI160_ACCEL_RANGE_ADDR UINT8_C(0x41) -#define BMI160_GYRO_CONFIG_ADDR UINT8_C(0x42) -#define BMI160_GYRO_RANGE_ADDR UINT8_C(0x43) -#define BMI160_AUX_ODR_ADDR UINT8_C(0x44) -#define BMI160_FIFO_DOWN_ADDR UINT8_C(0x45) -#define BMI160_FIFO_CONFIG_0_ADDR UINT8_C(0x46) -#define BMI160_FIFO_CONFIG_1_ADDR UINT8_C(0x47) -#define BMI160_AUX_IF_0_ADDR UINT8_C(0x4B) -#define BMI160_AUX_IF_1_ADDR UINT8_C(0x4C) -#define BMI160_AUX_IF_2_ADDR UINT8_C(0x4D) -#define BMI160_AUX_IF_3_ADDR UINT8_C(0x4E) -#define BMI160_AUX_IF_4_ADDR UINT8_C(0x4F) -#define BMI160_INT_ENABLE_0_ADDR UINT8_C(0x50) -#define BMI160_INT_ENABLE_1_ADDR UINT8_C(0x51) -#define BMI160_INT_ENABLE_2_ADDR UINT8_C(0x52) -#define BMI160_INT_OUT_CTRL_ADDR UINT8_C(0x53) -#define BMI160_INT_LATCH_ADDR UINT8_C(0x54) -#define BMI160_INT_MAP_0_ADDR UINT8_C(0x55) -#define BMI160_INT_MAP_1_ADDR UINT8_C(0x56) -#define BMI160_INT_MAP_2_ADDR UINT8_C(0x57) -#define BMI160_INT_DATA_0_ADDR UINT8_C(0x58) -#define BMI160_INT_DATA_1_ADDR UINT8_C(0x59) -#define BMI160_INT_LOWHIGH_0_ADDR UINT8_C(0x5A) -#define BMI160_INT_LOWHIGH_1_ADDR UINT8_C(0x5B) -#define BMI160_INT_LOWHIGH_2_ADDR UINT8_C(0x5C) -#define BMI160_INT_LOWHIGH_3_ADDR UINT8_C(0x5D) -#define BMI160_INT_LOWHIGH_4_ADDR UINT8_C(0x5E) -#define BMI160_INT_MOTION_0_ADDR UINT8_C(0x5F) -#define BMI160_INT_MOTION_1_ADDR UINT8_C(0x60) -#define BMI160_INT_MOTION_2_ADDR UINT8_C(0x61) -#define BMI160_INT_MOTION_3_ADDR UINT8_C(0x62) -#define BMI160_INT_TAP_0_ADDR UINT8_C(0x63) -#define BMI160_INT_TAP_1_ADDR UINT8_C(0x64) -#define BMI160_INT_ORIENT_0_ADDR UINT8_C(0x65) -#define BMI160_INT_ORIENT_1_ADDR UINT8_C(0x66) -#define BMI160_INT_FLAT_0_ADDR UINT8_C(0x67) -#define BMI160_INT_FLAT_1_ADDR UINT8_C(0x68) -#define BMI160_FOC_CONF_ADDR UINT8_C(0x69) -#define BMI160_CONF_ADDR UINT8_C(0x6A) - -#define BMI160_IF_CONF_ADDR UINT8_C(0x6B) -#define BMI160_SELF_TEST_ADDR UINT8_C(0x6D) -#define BMI160_OFFSET_ADDR UINT8_C(0x71) -#define BMI160_OFFSET_CONF_ADDR UINT8_C(0x77) -#define BMI160_INT_STEP_CNT_0_ADDR UINT8_C(0x78) -#define BMI160_INT_STEP_CONFIG_0_ADDR UINT8_C(0x7A) -#define BMI160_INT_STEP_CONFIG_1_ADDR UINT8_C(0x7B) -#define BMI160_COMMAND_REG_ADDR UINT8_C(0x7E) -#define BMI160_SPI_COMM_TEST_ADDR UINT8_C(0x7F) -#define BMI160_INTL_PULLUP_CONF_ADDR UINT8_C(0x85) +#define BMI160_CHIP_ID_ADDR UINT8_C(0x00) +#define BMI160_ERROR_REG_ADDR UINT8_C(0x02) +#define BMI160_PMU_STATUS_ADDR UINT8_C(0x03) +#define BMI160_AUX_DATA_ADDR UINT8_C(0x04) +#define BMI160_GYRO_DATA_ADDR UINT8_C(0x0C) +#define BMI160_ACCEL_DATA_ADDR UINT8_C(0x12) +#define BMI160_STATUS_ADDR UINT8_C(0x1B) +#define BMI160_INT_STATUS_ADDR UINT8_C(0x1C) +#define BMI160_FIFO_LENGTH_ADDR UINT8_C(0x22) +#define BMI160_FIFO_DATA_ADDR UINT8_C(0x24) +#define BMI160_ACCEL_CONFIG_ADDR UINT8_C(0x40) +#define BMI160_ACCEL_RANGE_ADDR UINT8_C(0x41) +#define BMI160_GYRO_CONFIG_ADDR UINT8_C(0x42) +#define BMI160_GYRO_RANGE_ADDR UINT8_C(0x43) +#define BMI160_AUX_ODR_ADDR UINT8_C(0x44) +#define BMI160_FIFO_DOWN_ADDR UINT8_C(0x45) +#define BMI160_FIFO_CONFIG_0_ADDR UINT8_C(0x46) +#define BMI160_FIFO_CONFIG_1_ADDR UINT8_C(0x47) +#define BMI160_AUX_IF_0_ADDR UINT8_C(0x4B) +#define BMI160_AUX_IF_1_ADDR UINT8_C(0x4C) +#define BMI160_AUX_IF_2_ADDR UINT8_C(0x4D) +#define BMI160_AUX_IF_3_ADDR UINT8_C(0x4E) +#define BMI160_AUX_IF_4_ADDR UINT8_C(0x4F) +#define BMI160_INT_ENABLE_0_ADDR UINT8_C(0x50) +#define BMI160_INT_ENABLE_1_ADDR UINT8_C(0x51) +#define BMI160_INT_ENABLE_2_ADDR UINT8_C(0x52) +#define BMI160_INT_OUT_CTRL_ADDR UINT8_C(0x53) +#define BMI160_INT_LATCH_ADDR UINT8_C(0x54) +#define BMI160_INT_MAP_0_ADDR UINT8_C(0x55) +#define BMI160_INT_MAP_1_ADDR UINT8_C(0x56) +#define BMI160_INT_MAP_2_ADDR UINT8_C(0x57) +#define BMI160_INT_DATA_0_ADDR UINT8_C(0x58) +#define BMI160_INT_DATA_1_ADDR UINT8_C(0x59) +#define BMI160_INT_LOWHIGH_0_ADDR UINT8_C(0x5A) +#define BMI160_INT_LOWHIGH_1_ADDR UINT8_C(0x5B) +#define BMI160_INT_LOWHIGH_2_ADDR UINT8_C(0x5C) +#define BMI160_INT_LOWHIGH_3_ADDR UINT8_C(0x5D) +#define BMI160_INT_LOWHIGH_4_ADDR UINT8_C(0x5E) +#define BMI160_INT_MOTION_0_ADDR UINT8_C(0x5F) +#define BMI160_INT_MOTION_1_ADDR UINT8_C(0x60) +#define BMI160_INT_MOTION_2_ADDR UINT8_C(0x61) +#define BMI160_INT_MOTION_3_ADDR UINT8_C(0x62) +#define BMI160_INT_TAP_0_ADDR UINT8_C(0x63) +#define BMI160_INT_TAP_1_ADDR UINT8_C(0x64) +#define BMI160_INT_ORIENT_0_ADDR UINT8_C(0x65) +#define BMI160_INT_ORIENT_1_ADDR UINT8_C(0x66) +#define BMI160_INT_FLAT_0_ADDR UINT8_C(0x67) +#define BMI160_INT_FLAT_1_ADDR UINT8_C(0x68) +#define BMI160_FOC_CONF_ADDR UINT8_C(0x69) +#define BMI160_CONF_ADDR UINT8_C(0x6A) + +#define BMI160_IF_CONF_ADDR UINT8_C(0x6B) +#define BMI160_SELF_TEST_ADDR UINT8_C(0x6D) +#define BMI160_OFFSET_ADDR UINT8_C(0x71) +#define BMI160_OFFSET_CONF_ADDR UINT8_C(0x77) +#define BMI160_INT_STEP_CNT_0_ADDR UINT8_C(0x78) +#define BMI160_INT_STEP_CONFIG_0_ADDR UINT8_C(0x7A) +#define BMI160_INT_STEP_CONFIG_1_ADDR UINT8_C(0x7B) +#define BMI160_COMMAND_REG_ADDR UINT8_C(0x7E) +#define BMI160_SPI_COMM_TEST_ADDR UINT8_C(0x7F) +#define BMI160_INTL_PULLUP_CONF_ADDR UINT8_C(0x85) /** Error code definitions */ -#define BMI160_OK INT8_C(0) -#define BMI160_E_NULL_PTR INT8_C(-1) -#define BMI160_E_COM_FAIL INT8_C(-2) -#define BMI160_E_DEV_NOT_FOUND INT8_C(-3) -#define BMI160_E_OUT_OF_RANGE INT8_C(-4) -#define BMI160_E_INVALID_INPUT INT8_C(-5) -#define BMI160_E_ACCEL_ODR_BW_INVALID INT8_C(-6) -#define BMI160_E_GYRO_ODR_BW_INVALID INT8_C(-7) -#define BMI160_E_LWP_PRE_FLTR_INT_INVALID INT8_C(-8) -#define BMI160_E_LWP_PRE_FLTR_INVALID INT8_C(-9) -#define BMI160_E_AUX_NOT_FOUND INT8_C(-10) -#define BMI160_FOC_FAILURE INT8_C(-11) -#define BMI160_READ_WRITE_LENGHT_INVALID INT8_C(-12) +#define BMI160_OK INT8_C(0) +#define BMI160_E_NULL_PTR INT8_C(-1) +#define BMI160_E_COM_FAIL INT8_C(-2) +#define BMI160_E_DEV_NOT_FOUND INT8_C(-3) +#define BMI160_E_OUT_OF_RANGE INT8_C(-4) +#define BMI160_E_INVALID_INPUT INT8_C(-5) +#define BMI160_E_ACCEL_ODR_BW_INVALID INT8_C(-6) +#define BMI160_E_GYRO_ODR_BW_INVALID INT8_C(-7) +#define BMI160_E_LWP_PRE_FLTR_INT_INVALID INT8_C(-8) +#define BMI160_E_LWP_PRE_FLTR_INVALID INT8_C(-9) +#define BMI160_E_AUX_NOT_FOUND INT8_C(-10) +#define BMI160_FOC_FAILURE INT8_C(-11) +#define BMI160_READ_WRITE_LENGHT_INVALID INT8_C(-12) /**\name API warning codes */ -#define BMI160_W_GYRO_SELF_TEST_FAIL INT8_C(1) -#define BMI160_W_ACCEl_SELF_TEST_FAIL INT8_C(2) +#define BMI160_W_GYRO_SELF_TEST_FAIL INT8_C(1) +#define BMI160_W_ACCEl_SELF_TEST_FAIL INT8_C(2) /** BMI160 unique chip identifier */ -#define BMI160_CHIP_ID UINT8_C(0xD1) +#define BMI160_CHIP_ID UINT8_C(0xD1) /** Soft reset command */ -#define BMI160_SOFT_RESET_CMD UINT8_C(0xb6) -#define BMI160_SOFT_RESET_DELAY_MS UINT8_C(1) +#define BMI160_SOFT_RESET_CMD UINT8_C(0xb6) +#define BMI160_SOFT_RESET_DELAY_MS UINT8_C(1) /** Start FOC command */ -#define BMI160_START_FOC_CMD UINT8_C(0x03) +#define BMI160_START_FOC_CMD UINT8_C(0x03) /** NVM backup enabling command */ -#define BMI160_NVM_BACKUP_EN UINT8_C(0xA0) +#define BMI160_NVM_BACKUP_EN UINT8_C(0xA0) /* Delay in ms settings */ -#define BMI160_ACCEL_DELAY_MS UINT8_C(5) -#define BMI160_GYRO_DELAY_MS UINT8_C(81) -#define BMI160_ONE_MS_DELAY UINT8_C(1) -#define BMI160_AUX_COM_DELAY UINT8_C(10) -#define BMI160_GYRO_SELF_TEST_DELAY UINT8_C(20) -#define BMI160_ACCEL_SELF_TEST_DELAY UINT8_C(50) +#define BMI160_ACCEL_DELAY_MS UINT8_C(5) +#define BMI160_GYRO_DELAY_MS UINT8_C(81) +#define BMI160_ONE_MS_DELAY UINT8_C(1) +#define BMI160_AUX_COM_DELAY UINT8_C(10) +#define BMI160_GYRO_SELF_TEST_DELAY UINT8_C(20) +#define BMI160_ACCEL_SELF_TEST_DELAY UINT8_C(50) /** Self test configurations */ -#define BMI160_ACCEL_SELF_TEST_CONFIG UINT8_C(0x2C) -#define BMI160_ACCEL_SELF_TEST_POSITIVE_EN UINT8_C(0x0D) -#define BMI160_ACCEL_SELF_TEST_NEGATIVE_EN UINT8_C(0x09) -#define BMI160_ACCEL_SELF_TEST_LIMIT UINT16_C(8192) +#define BMI160_ACCEL_SELF_TEST_CONFIG UINT8_C(0x2C) +#define BMI160_ACCEL_SELF_TEST_POSITIVE_EN UINT8_C(0x0D) +#define BMI160_ACCEL_SELF_TEST_NEGATIVE_EN UINT8_C(0x09) +#define BMI160_ACCEL_SELF_TEST_LIMIT UINT16_C(8192) /** Power mode settings */ /* Accel power mode */ -#define BMI160_ACCEL_NORMAL_MODE UINT8_C(0x11) -#define BMI160_ACCEL_LOWPOWER_MODE UINT8_C(0x12) -#define BMI160_ACCEL_SUSPEND_MODE UINT8_C(0x10) +#define BMI160_ACCEL_NORMAL_MODE UINT8_C(0x11) +#define BMI160_ACCEL_LOWPOWER_MODE UINT8_C(0x12) +#define BMI160_ACCEL_SUSPEND_MODE UINT8_C(0x10) /* Gyro power mode */ -#define BMI160_GYRO_SUSPEND_MODE UINT8_C(0x14) -#define BMI160_GYRO_NORMAL_MODE UINT8_C(0x15) -#define BMI160_GYRO_FASTSTARTUP_MODE UINT8_C(0x17) +#define BMI160_GYRO_SUSPEND_MODE UINT8_C(0x14) +#define BMI160_GYRO_NORMAL_MODE UINT8_C(0x15) +#define BMI160_GYRO_FASTSTARTUP_MODE UINT8_C(0x17) /* Aux power mode */ -#define BMI160_AUX_SUSPEND_MODE UINT8_C(0x18) -#define BMI160_AUX_NORMAL_MODE UINT8_C(0x19) -#define BMI160_AUX_LOWPOWER_MODE UINT8_C(0x1A) +#define BMI160_AUX_SUSPEND_MODE UINT8_C(0x18) +#define BMI160_AUX_NORMAL_MODE UINT8_C(0x19) +#define BMI160_AUX_LOWPOWER_MODE UINT8_C(0x1A) /** Range settings */ /* Accel Range */ -#define BMI160_ACCEL_RANGE_2G UINT8_C(0x03) -#define BMI160_ACCEL_RANGE_4G UINT8_C(0x05) -#define BMI160_ACCEL_RANGE_8G UINT8_C(0x08) -#define BMI160_ACCEL_RANGE_16G UINT8_C(0x0C) +#define BMI160_ACCEL_RANGE_2G UINT8_C(0x03) +#define BMI160_ACCEL_RANGE_4G UINT8_C(0x05) +#define BMI160_ACCEL_RANGE_8G UINT8_C(0x08) +#define BMI160_ACCEL_RANGE_16G UINT8_C(0x0C) /* Gyro Range */ -#define BMI160_GYRO_RANGE_2000_DPS UINT8_C(0x00) -#define BMI160_GYRO_RANGE_1000_DPS UINT8_C(0x01) -#define BMI160_GYRO_RANGE_500_DPS UINT8_C(0x02) -#define BMI160_GYRO_RANGE_250_DPS UINT8_C(0x03) -#define BMI160_GYRO_RANGE_125_DPS UINT8_C(0x04) +#define BMI160_GYRO_RANGE_2000_DPS UINT8_C(0x00) +#define BMI160_GYRO_RANGE_1000_DPS UINT8_C(0x01) +#define BMI160_GYRO_RANGE_500_DPS UINT8_C(0x02) +#define BMI160_GYRO_RANGE_250_DPS UINT8_C(0x03) +#define BMI160_GYRO_RANGE_125_DPS UINT8_C(0x04) /** Bandwidth settings */ /* Accel Bandwidth */ -#define BMI160_ACCEL_BW_OSR4_AVG1 UINT8_C(0x00) -#define BMI160_ACCEL_BW_OSR2_AVG2 UINT8_C(0x01) -#define BMI160_ACCEL_BW_NORMAL_AVG4 UINT8_C(0x02) -#define BMI160_ACCEL_BW_RES_AVG8 UINT8_C(0x03) -#define BMI160_ACCEL_BW_RES_AVG16 UINT8_C(0x04) -#define BMI160_ACCEL_BW_RES_AVG32 UINT8_C(0x05) -#define BMI160_ACCEL_BW_RES_AVG64 UINT8_C(0x06) -#define BMI160_ACCEL_BW_RES_AVG128 UINT8_C(0x07) - -#define BMI160_GYRO_BW_OSR4_MODE UINT8_C(0x00) -#define BMI160_GYRO_BW_OSR2_MODE UINT8_C(0x01) -#define BMI160_GYRO_BW_NORMAL_MODE UINT8_C(0x02) +#define BMI160_ACCEL_BW_OSR4_AVG1 UINT8_C(0x00) +#define BMI160_ACCEL_BW_OSR2_AVG2 UINT8_C(0x01) +#define BMI160_ACCEL_BW_NORMAL_AVG4 UINT8_C(0x02) +#define BMI160_ACCEL_BW_RES_AVG8 UINT8_C(0x03) +#define BMI160_ACCEL_BW_RES_AVG16 UINT8_C(0x04) +#define BMI160_ACCEL_BW_RES_AVG32 UINT8_C(0x05) +#define BMI160_ACCEL_BW_RES_AVG64 UINT8_C(0x06) +#define BMI160_ACCEL_BW_RES_AVG128 UINT8_C(0x07) + +#define BMI160_GYRO_BW_OSR4_MODE UINT8_C(0x00) +#define BMI160_GYRO_BW_OSR2_MODE UINT8_C(0x01) +#define BMI160_GYRO_BW_NORMAL_MODE UINT8_C(0x02) /* Output Data Rate settings */ /* Accel Output data rate */ -#define BMI160_ACCEL_ODR_RESERVED UINT8_C(0x00) -#define BMI160_ACCEL_ODR_0_78HZ UINT8_C(0x01) -#define BMI160_ACCEL_ODR_1_56HZ UINT8_C(0x02) -#define BMI160_ACCEL_ODR_3_12HZ UINT8_C(0x03) -#define BMI160_ACCEL_ODR_6_25HZ UINT8_C(0x04) -#define BMI160_ACCEL_ODR_12_5HZ UINT8_C(0x05) -#define BMI160_ACCEL_ODR_25HZ UINT8_C(0x06) -#define BMI160_ACCEL_ODR_50HZ UINT8_C(0x07) -#define BMI160_ACCEL_ODR_100HZ UINT8_C(0x08) -#define BMI160_ACCEL_ODR_200HZ UINT8_C(0x09) -#define BMI160_ACCEL_ODR_400HZ UINT8_C(0x0A) -#define BMI160_ACCEL_ODR_800HZ UINT8_C(0x0B) -#define BMI160_ACCEL_ODR_1600HZ UINT8_C(0x0C) -#define BMI160_ACCEL_ODR_RESERVED0 UINT8_C(0x0D) -#define BMI160_ACCEL_ODR_RESERVED1 UINT8_C(0x0E) -#define BMI160_ACCEL_ODR_RESERVED2 UINT8_C(0x0F) +#define BMI160_ACCEL_ODR_RESERVED UINT8_C(0x00) +#define BMI160_ACCEL_ODR_0_78HZ UINT8_C(0x01) +#define BMI160_ACCEL_ODR_1_56HZ UINT8_C(0x02) +#define BMI160_ACCEL_ODR_3_12HZ UINT8_C(0x03) +#define BMI160_ACCEL_ODR_6_25HZ UINT8_C(0x04) +#define BMI160_ACCEL_ODR_12_5HZ UINT8_C(0x05) +#define BMI160_ACCEL_ODR_25HZ UINT8_C(0x06) +#define BMI160_ACCEL_ODR_50HZ UINT8_C(0x07) +#define BMI160_ACCEL_ODR_100HZ UINT8_C(0x08) +#define BMI160_ACCEL_ODR_200HZ UINT8_C(0x09) +#define BMI160_ACCEL_ODR_400HZ UINT8_C(0x0A) +#define BMI160_ACCEL_ODR_800HZ UINT8_C(0x0B) +#define BMI160_ACCEL_ODR_1600HZ UINT8_C(0x0C) +#define BMI160_ACCEL_ODR_RESERVED0 UINT8_C(0x0D) +#define BMI160_ACCEL_ODR_RESERVED1 UINT8_C(0x0E) +#define BMI160_ACCEL_ODR_RESERVED2 UINT8_C(0x0F) /* Gyro Output data rate */ -#define BMI160_GYRO_ODR_RESERVED UINT8_C(0x00) -#define BMI160_GYRO_ODR_25HZ UINT8_C(0x06) -#define BMI160_GYRO_ODR_50HZ UINT8_C(0x07) -#define BMI160_GYRO_ODR_100HZ UINT8_C(0x08) -#define BMI160_GYRO_ODR_200HZ UINT8_C(0x09) -#define BMI160_GYRO_ODR_400HZ UINT8_C(0x0A) -#define BMI160_GYRO_ODR_800HZ UINT8_C(0x0B) -#define BMI160_GYRO_ODR_1600HZ UINT8_C(0x0C) -#define BMI160_GYRO_ODR_3200HZ UINT8_C(0x0D) +#define BMI160_GYRO_ODR_RESERVED UINT8_C(0x00) +#define BMI160_GYRO_ODR_25HZ UINT8_C(0x06) +#define BMI160_GYRO_ODR_50HZ UINT8_C(0x07) +#define BMI160_GYRO_ODR_100HZ UINT8_C(0x08) +#define BMI160_GYRO_ODR_200HZ UINT8_C(0x09) +#define BMI160_GYRO_ODR_400HZ UINT8_C(0x0A) +#define BMI160_GYRO_ODR_800HZ UINT8_C(0x0B) +#define BMI160_GYRO_ODR_1600HZ UINT8_C(0x0C) +#define BMI160_GYRO_ODR_3200HZ UINT8_C(0x0D) /* Auxiliary sensor Output data rate */ -#define BMI160_AUX_ODR_RESERVED UINT8_C(0x00) -#define BMI160_AUX_ODR_0_78HZ UINT8_C(0x01) -#define BMI160_AUX_ODR_1_56HZ UINT8_C(0x02) -#define BMI160_AUX_ODR_3_12HZ UINT8_C(0x03) -#define BMI160_AUX_ODR_6_25HZ UINT8_C(0x04) -#define BMI160_AUX_ODR_12_5HZ UINT8_C(0x05) -#define BMI160_AUX_ODR_25HZ UINT8_C(0x06) -#define BMI160_AUX_ODR_50HZ UINT8_C(0x07) -#define BMI160_AUX_ODR_100HZ UINT8_C(0x08) -#define BMI160_AUX_ODR_200HZ UINT8_C(0x09) -#define BMI160_AUX_ODR_400HZ UINT8_C(0x0A) -#define BMI160_AUX_ODR_800HZ UINT8_C(0x0B) - -/* Maximum limits definition */ -#define BMI160_ACCEL_ODR_MAX UINT8_C(15) -#define BMI160_ACCEL_BW_MAX UINT8_C(2) -#define BMI160_ACCEL_RANGE_MAX UINT8_C(12) -#define BMI160_GYRO_ODR_MAX UINT8_C(13) -#define BMI160_GYRO_BW_MAX UINT8_C(2) -#define BMI160_GYRO_RANGE_MAX UINT8_C(4) +#define BMI160_AUX_ODR_RESERVED UINT8_C(0x00) +#define BMI160_AUX_ODR_0_78HZ UINT8_C(0x01) +#define BMI160_AUX_ODR_1_56HZ UINT8_C(0x02) +#define BMI160_AUX_ODR_3_12HZ UINT8_C(0x03) +#define BMI160_AUX_ODR_6_25HZ UINT8_C(0x04) +#define BMI160_AUX_ODR_12_5HZ UINT8_C(0x05) +#define BMI160_AUX_ODR_25HZ UINT8_C(0x06) +#define BMI160_AUX_ODR_50HZ UINT8_C(0x07) +#define BMI160_AUX_ODR_100HZ UINT8_C(0x08) +#define BMI160_AUX_ODR_200HZ UINT8_C(0x09) +#define BMI160_AUX_ODR_400HZ UINT8_C(0x0A) +#define BMI160_AUX_ODR_800HZ UINT8_C(0x0B) /** FIFO_CONFIG Definitions */ -#define BMI160_FIFO_TIME_ENABLE UINT8_C(0x02) -#define BMI160_FIFO_TAG_INT2_ENABLE UINT8_C(0x04) -#define BMI160_FIFO_TAG_INT1_ENABLE UINT8_C(0x08) -#define BMI160_FIFO_HEAD_ENABLE UINT8_C(0x10) -#define BMI160_FIFO_M_ENABLE UINT8_C(0x20) -#define BMI160_FIFO_A_ENABLE UINT8_C(0x40) -#define BMI160_FIFO_M_A_ENABLE UINT8_C(0x60) -#define BMI160_FIFO_G_ENABLE UINT8_C(0x80) -#define BMI160_FIFO_M_G_ENABLE UINT8_C(0xA0) -#define BMI160_FIFO_G_A_ENABLE UINT8_C(0xC0) -#define BMI160_FIFO_M_G_A_ENABLE UINT8_C(0xE0) +#define BMI160_FIFO_TIME_ENABLE UINT8_C(0x02) +#define BMI160_FIFO_TAG_INT2_ENABLE UINT8_C(0x04) +#define BMI160_FIFO_TAG_INT1_ENABLE UINT8_C(0x08) +#define BMI160_FIFO_HEAD_ENABLE UINT8_C(0x10) +#define BMI160_FIFO_M_ENABLE UINT8_C(0x20) +#define BMI160_FIFO_A_ENABLE UINT8_C(0x40) +#define BMI160_FIFO_M_A_ENABLE UINT8_C(0x60) +#define BMI160_FIFO_G_ENABLE UINT8_C(0x80) +#define BMI160_FIFO_M_G_ENABLE UINT8_C(0xA0) +#define BMI160_FIFO_G_A_ENABLE UINT8_C(0xC0) +#define BMI160_FIFO_M_G_A_ENABLE UINT8_C(0xE0) /* Macro to specify the number of bytes over-read from the * FIFO in order to get the sensor time at the end of FIFO */ #ifndef BMI160_FIFO_BYTES_OVERREAD -#define BMI160_FIFO_BYTES_OVERREAD UINT8_C(25) +#define BMI160_FIFO_BYTES_OVERREAD UINT8_C(25) #endif /* Accel, gyro and aux. sensor length and also their combined * length definitions in FIFO */ -#define BMI160_FIFO_G_LENGTH UINT8_C(6) -#define BMI160_FIFO_A_LENGTH UINT8_C(6) -#define BMI160_FIFO_M_LENGTH UINT8_C(8) -#define BMI160_FIFO_GA_LENGTH UINT8_C(12) -#define BMI160_FIFO_MA_LENGTH UINT8_C(14) -#define BMI160_FIFO_MG_LENGTH UINT8_C(14) -#define BMI160_FIFO_MGA_LENGTH UINT8_C(20) +#define BMI160_FIFO_G_LENGTH UINT8_C(6) +#define BMI160_FIFO_A_LENGTH UINT8_C(6) +#define BMI160_FIFO_M_LENGTH UINT8_C(8) +#define BMI160_FIFO_GA_LENGTH UINT8_C(12) +#define BMI160_FIFO_MA_LENGTH UINT8_C(14) +#define BMI160_FIFO_MG_LENGTH UINT8_C(14) +#define BMI160_FIFO_MGA_LENGTH UINT8_C(20) /** FIFO Header Data definitions */ -#define BMI160_FIFO_HEAD_SKIP_FRAME UINT8_C(0x40) -#define BMI160_FIFO_HEAD_SENSOR_TIME UINT8_C(0x44) -#define BMI160_FIFO_HEAD_INPUT_CONFIG UINT8_C(0x48) -#define BMI160_FIFO_HEAD_OVER_READ UINT8_C(0x80) -#define BMI160_FIFO_HEAD_A UINT8_C(0x84) -#define BMI160_FIFO_HEAD_G UINT8_C(0x88) -#define BMI160_FIFO_HEAD_G_A UINT8_C(0x8C) -#define BMI160_FIFO_HEAD_M UINT8_C(0x90) -#define BMI160_FIFO_HEAD_M_A UINT8_C(0x94) -#define BMI160_FIFO_HEAD_M_G UINT8_C(0x98) -#define BMI160_FIFO_HEAD_M_G_A UINT8_C(0x9C) +#define BMI160_FIFO_HEAD_SKIP_FRAME UINT8_C(0x40) +#define BMI160_FIFO_HEAD_SENSOR_TIME UINT8_C(0x44) +#define BMI160_FIFO_HEAD_INPUT_CONFIG UINT8_C(0x48) +#define BMI160_FIFO_HEAD_OVER_READ UINT8_C(0x80) +#define BMI160_FIFO_HEAD_A UINT8_C(0x84) +#define BMI160_FIFO_HEAD_G UINT8_C(0x88) +#define BMI160_FIFO_HEAD_G_A UINT8_C(0x8C) +#define BMI160_FIFO_HEAD_M UINT8_C(0x90) +#define BMI160_FIFO_HEAD_M_A UINT8_C(0x94) +#define BMI160_FIFO_HEAD_M_G UINT8_C(0x98) +#define BMI160_FIFO_HEAD_M_G_A UINT8_C(0x9C) /** FIFO sensor time length definitions */ -#define BMI160_SENSOR_TIME_LENGTH UINT8_C(3) +#define BMI160_SENSOR_TIME_LENGTH UINT8_C(3) /** FIFO DOWN selection */ /* Accel fifo down-sampling values*/ -#define BMI160_ACCEL_FIFO_DOWN_ZERO UINT8_C(0x00) -#define BMI160_ACCEL_FIFO_DOWN_ONE UINT8_C(0x10) -#define BMI160_ACCEL_FIFO_DOWN_TWO UINT8_C(0x20) -#define BMI160_ACCEL_FIFO_DOWN_THREE UINT8_C(0x30) -#define BMI160_ACCEL_FIFO_DOWN_FOUR UINT8_C(0x40) -#define BMI160_ACCEL_FIFO_DOWN_FIVE UINT8_C(0x50) -#define BMI160_ACCEL_FIFO_DOWN_SIX UINT8_C(0x60) -#define BMI160_ACCEL_FIFO_DOWN_SEVEN UINT8_C(0x70) +#define BMI160_ACCEL_FIFO_DOWN_ZERO UINT8_C(0x00) +#define BMI160_ACCEL_FIFO_DOWN_ONE UINT8_C(0x10) +#define BMI160_ACCEL_FIFO_DOWN_TWO UINT8_C(0x20) +#define BMI160_ACCEL_FIFO_DOWN_THREE UINT8_C(0x30) +#define BMI160_ACCEL_FIFO_DOWN_FOUR UINT8_C(0x40) +#define BMI160_ACCEL_FIFO_DOWN_FIVE UINT8_C(0x50) +#define BMI160_ACCEL_FIFO_DOWN_SIX UINT8_C(0x60) +#define BMI160_ACCEL_FIFO_DOWN_SEVEN UINT8_C(0x70) /* Gyro fifo down-smapling values*/ -#define BMI160_GYRO_FIFO_DOWN_ZERO UINT8_C(0x00) -#define BMI160_GYRO_FIFO_DOWN_ONE UINT8_C(0x01) -#define BMI160_GYRO_FIFO_DOWN_TWO UINT8_C(0x02) -#define BMI160_GYRO_FIFO_DOWN_THREE UINT8_C(0x03) -#define BMI160_GYRO_FIFO_DOWN_FOUR UINT8_C(0x04) -#define BMI160_GYRO_FIFO_DOWN_FIVE UINT8_C(0x05) -#define BMI160_GYRO_FIFO_DOWN_SIX UINT8_C(0x06) -#define BMI160_GYRO_FIFO_DOWN_SEVEN UINT8_C(0x07) +#define BMI160_GYRO_FIFO_DOWN_ZERO UINT8_C(0x00) +#define BMI160_GYRO_FIFO_DOWN_ONE UINT8_C(0x01) +#define BMI160_GYRO_FIFO_DOWN_TWO UINT8_C(0x02) +#define BMI160_GYRO_FIFO_DOWN_THREE UINT8_C(0x03) +#define BMI160_GYRO_FIFO_DOWN_FOUR UINT8_C(0x04) +#define BMI160_GYRO_FIFO_DOWN_FIVE UINT8_C(0x05) +#define BMI160_GYRO_FIFO_DOWN_SIX UINT8_C(0x06) +#define BMI160_GYRO_FIFO_DOWN_SEVEN UINT8_C(0x07) /* Accel Fifo filter enable*/ -#define BMI160_ACCEL_FIFO_FILT_EN UINT8_C(0x80) +#define BMI160_ACCEL_FIFO_FILT_EN UINT8_C(0x80) /* Gyro Fifo filter enable*/ -#define BMI160_GYRO_FIFO_FILT_EN UINT8_C(0x08) +#define BMI160_GYRO_FIFO_FILT_EN UINT8_C(0x08) /** Definitions to check validity of FIFO frames */ -#define FIFO_CONFIG_MSB_CHECK UINT8_C(0x80) -#define FIFO_CONFIG_LSB_CHECK UINT8_C(0x00) +#define FIFO_CONFIG_MSB_CHECK UINT8_C(0x80) +#define FIFO_CONFIG_LSB_CHECK UINT8_C(0x00) /*! BMI160 accel FOC configurations */ -#define BMI160_FOC_ACCEL_DISABLED UINT8_C(0x00) -#define BMI160_FOC_ACCEL_POSITIVE_G UINT8_C(0x01) -#define BMI160_FOC_ACCEL_NEGATIVE_G UINT8_C(0x02) -#define BMI160_FOC_ACCEL_0G UINT8_C(0x03) +#define BMI160_FOC_ACCEL_DISABLED UINT8_C(0x00) +#define BMI160_FOC_ACCEL_POSITIVE_G UINT8_C(0x01) +#define BMI160_FOC_ACCEL_NEGATIVE_G UINT8_C(0x02) +#define BMI160_FOC_ACCEL_0G UINT8_C(0x03) /** Array Parameter DefinItions */ -#define BMI160_SENSOR_TIME_LSB_BYTE UINT8_C(0) -#define BMI160_SENSOR_TIME_XLSB_BYTE UINT8_C(1) -#define BMI160_SENSOR_TIME_MSB_BYTE UINT8_C(2) +#define BMI160_SENSOR_TIME_LSB_BYTE UINT8_C(0) +#define BMI160_SENSOR_TIME_XLSB_BYTE UINT8_C(1) +#define BMI160_SENSOR_TIME_MSB_BYTE UINT8_C(2) /** Interface settings */ -#define BMI160_SPI_INTF UINT8_C(1) -#define BMI160_I2C_INTF UINT8_C(0) -#define BMI160_SPI_RD_MASK UINT8_C(0x80) -#define BMI160_SPI_WR_MASK UINT8_C(0x7F) +#define BMI160_SPI_INTF UINT8_C(1) +#define BMI160_I2C_INTF UINT8_C(0) +#define BMI160_SPI_RD_MASK UINT8_C(0x80) +#define BMI160_SPI_WR_MASK UINT8_C(0x7F) /* Sensor & time select definition*/ -#define BMI160_ACCEL_SEL UINT8_C(0x01) -#define BMI160_GYRO_SEL UINT8_C(0x02) -#define BMI160_TIME_SEL UINT8_C(0x04) +#define BMI160_ACCEL_SEL UINT8_C(0x01) +#define BMI160_GYRO_SEL UINT8_C(0x02) +#define BMI160_TIME_SEL UINT8_C(0x04) /* Sensor select mask*/ -#define BMI160_SEN_SEL_MASK UINT8_C(0x07) +#define BMI160_SEN_SEL_MASK UINT8_C(0x07) /* Error code mask */ -#define BMI160_ERR_REG_MASK UINT8_C(0x0F) +#define BMI160_ERR_REG_MASK UINT8_C(0x0F) /* BMI160 I2C address */ -#define BMI160_I2C_ADDR UINT8_C(0x68) +#define BMI160_I2C_ADDR UINT8_C(0x68) /* BMI160 secondary IF address */ -#define BMI160_AUX_BMM150_I2C_ADDR UINT8_C(0x10) +#define BMI160_AUX_BMM150_I2C_ADDR UINT8_C(0x10) /** BMI160 Length definitions */ -#define BMI160_ONE UINT8_C(1) -#define BMI160_TWO UINT8_C(2) -#define BMI160_THREE UINT8_C(3) -#define BMI160_FOUR UINT8_C(4) -#define BMI160_FIVE UINT8_C(5) +#define BMI160_ONE UINT8_C(1) +#define BMI160_TWO UINT8_C(2) +#define BMI160_THREE UINT8_C(3) +#define BMI160_FOUR UINT8_C(4) +#define BMI160_FIVE UINT8_C(5) /** BMI160 fifo level Margin */ -#define BMI160_FIFO_LEVEL_MARGIN UINT8_C(16) +#define BMI160_FIFO_LEVEL_MARGIN UINT8_C(16) /** BMI160 fifo flush Command */ -#define BMI160_FIFO_FLUSH_VALUE UINT8_C(0xB0) +#define BMI160_FIFO_FLUSH_VALUE UINT8_C(0xB0) /** BMI160 offset values for xyz axes of accel */ -#define BMI160_ACCEL_MIN_OFFSET INT8_C(-128) -#define BMI160_ACCEL_MAX_OFFSET INT8_C(127) +#define BMI160_ACCEL_MIN_OFFSET INT8_C(-128) +#define BMI160_ACCEL_MAX_OFFSET INT8_C(127) /** BMI160 offset values for xyz axes of gyro */ -#define BMI160_GYRO_MIN_OFFSET INT16_C(-512) -#define BMI160_GYRO_MAX_OFFSET INT16_C(511) +#define BMI160_GYRO_MIN_OFFSET INT16_C(-512) +#define BMI160_GYRO_MAX_OFFSET INT16_C(511) /** BMI160 fifo full interrupt position and mask */ -#define BMI160_FIFO_FULL_INT_POS UINT8_C(5) -#define BMI160_FIFO_FULL_INT_MSK UINT8_C(0x20) -#define BMI160_FIFO_WTM_INT_POS UINT8_C(6) -#define BMI160_FIFO_WTM_INT_MSK UINT8_C(0x40) +#define BMI160_FIFO_FULL_INT_POS UINT8_C(5) +#define BMI160_FIFO_FULL_INT_MSK UINT8_C(0x20) +#define BMI160_FIFO_WTM_INT_POS UINT8_C(6) +#define BMI160_FIFO_WTM_INT_MSK UINT8_C(0x40) -#define BMI160_FIFO_FULL_INT_PIN1_POS UINT8_C(5) -#define BMI160_FIFO_FULL_INT_PIN1_MSK UINT8_C(0x20) -#define BMI160_FIFO_FULL_INT_PIN2_POS UINT8_C(1) -#define BMI160_FIFO_FULL_INT_PIN2_MSK UINT8_C(0x02) +#define BMI160_FIFO_FULL_INT_PIN1_POS UINT8_C(5) +#define BMI160_FIFO_FULL_INT_PIN1_MSK UINT8_C(0x20) +#define BMI160_FIFO_FULL_INT_PIN2_POS UINT8_C(1) +#define BMI160_FIFO_FULL_INT_PIN2_MSK UINT8_C(0x02) -#define BMI160_FIFO_WTM_INT_PIN1_POS UINT8_C(6) -#define BMI160_FIFO_WTM_INT_PIN1_MSK UINT8_C(0x40) -#define BMI160_FIFO_WTM_INT_PIN2_POS UINT8_C(2) -#define BMI160_FIFO_WTM_INT_PIN2_MSK UINT8_C(0x04) +#define BMI160_FIFO_WTM_INT_PIN1_POS UINT8_C(6) +#define BMI160_FIFO_WTM_INT_PIN1_MSK UINT8_C(0x40) +#define BMI160_FIFO_WTM_INT_PIN2_POS UINT8_C(2) +#define BMI160_FIFO_WTM_INT_PIN2_MSK UINT8_C(0x04) -#define BMI160_MANUAL_MODE_EN_POS UINT8_C(7) -#define BMI160_MANUAL_MODE_EN_MSK UINT8_C(0x80) -#define BMI160_AUX_READ_BURST_POS UINT8_C(0) -#define BMI160_AUX_READ_BURST_MSK UINT8_C(0x03) +#define BMI160_MANUAL_MODE_EN_POS UINT8_C(7) +#define BMI160_MANUAL_MODE_EN_MSK UINT8_C(0x80) +#define BMI160_AUX_READ_BURST_POS UINT8_C(0) +#define BMI160_AUX_READ_BURST_MSK UINT8_C(0x03) -#define BMI160_GYRO_SELF_TEST_POS UINT8_C(4) -#define BMI160_GYRO_SELF_TEST_MSK UINT8_C(0x10) -#define BMI160_GYRO_SELF_TEST_STATUS_POS UINT8_C(1) -#define BMI160_GYRO_SELF_TEST_STATUS_MSK UINT8_C(0x02) +#define BMI160_GYRO_SELF_TEST_POS UINT8_C(4) +#define BMI160_GYRO_SELF_TEST_MSK UINT8_C(0x10) +#define BMI160_GYRO_SELF_TEST_STATUS_POS UINT8_C(1) +#define BMI160_GYRO_SELF_TEST_STATUS_MSK UINT8_C(0x02) -#define BMI160_GYRO_FOC_EN_POS UINT8_C(6) -#define BMI160_GYRO_FOC_EN_MSK UINT8_C(0x40) +#define BMI160_GYRO_FOC_EN_POS UINT8_C(6) +#define BMI160_GYRO_FOC_EN_MSK UINT8_C(0x40) -#define BMI160_ACCEL_FOC_X_CONF_POS UINT8_C(4) -#define BMI160_ACCEL_FOC_X_CONF_MSK UINT8_C(0x30) +#define BMI160_ACCEL_FOC_X_CONF_POS UINT8_C(4) +#define BMI160_ACCEL_FOC_X_CONF_MSK UINT8_C(0x30) -#define BMI160_ACCEL_FOC_Y_CONF_POS UINT8_C(2) -#define BMI160_ACCEL_FOC_Y_CONF_MSK UINT8_C(0x0C) +#define BMI160_ACCEL_FOC_Y_CONF_POS UINT8_C(2) +#define BMI160_ACCEL_FOC_Y_CONF_MSK UINT8_C(0x0C) -#define BMI160_ACCEL_FOC_Z_CONF_MSK UINT8_C(0x03) +#define BMI160_ACCEL_FOC_Z_CONF_MSK UINT8_C(0x03) -#define BMI160_FOC_STATUS_POS UINT8_C(3) -#define BMI160_FOC_STATUS_MSK UINT8_C(0x08) +#define BMI160_FOC_STATUS_POS UINT8_C(3) +#define BMI160_FOC_STATUS_MSK UINT8_C(0x08) -#define BMI160_GYRO_OFFSET_X_MSK UINT8_C(0x03) +#define BMI160_GYRO_OFFSET_X_MSK UINT8_C(0x03) -#define BMI160_GYRO_OFFSET_Y_POS UINT8_C(2) -#define BMI160_GYRO_OFFSET_Y_MSK UINT8_C(0x0C) +#define BMI160_GYRO_OFFSET_Y_POS UINT8_C(2) +#define BMI160_GYRO_OFFSET_Y_MSK UINT8_C(0x0C) -#define BMI160_GYRO_OFFSET_Z_POS UINT8_C(4) -#define BMI160_GYRO_OFFSET_Z_MSK UINT8_C(0x30) +#define BMI160_GYRO_OFFSET_Z_POS UINT8_C(4) +#define BMI160_GYRO_OFFSET_Z_MSK UINT8_C(0x30) -#define BMI160_GYRO_OFFSET_EN_POS UINT8_C(7) -#define BMI160_GYRO_OFFSET_EN_MSK UINT8_C(0x80) +#define BMI160_GYRO_OFFSET_EN_POS UINT8_C(7) +#define BMI160_GYRO_OFFSET_EN_MSK UINT8_C(0x80) -#define BMI160_ACCEL_OFFSET_EN_POS UINT8_C(6) -#define BMI160_ACCEL_OFFSET_EN_MSK UINT8_C(0x40) +#define BMI160_ACCEL_OFFSET_EN_POS UINT8_C(6) +#define BMI160_ACCEL_OFFSET_EN_MSK UINT8_C(0x40) -#define BMI160_GYRO_OFFSET_POS UINT16_C(8) -#define BMI160_GYRO_OFFSET_MSK UINT16_C(0x0300) +#define BMI160_GYRO_OFFSET_POS UINT16_C(8) +#define BMI160_GYRO_OFFSET_MSK UINT16_C(0x0300) -#define BMI160_NVM_UPDATE_POS UINT8_C(1) -#define BMI160_NVM_UPDATE_MSK UINT8_C(0x02) +#define BMI160_NVM_UPDATE_POS UINT8_C(1) +#define BMI160_NVM_UPDATE_MSK UINT8_C(0x02) -#define BMI160_NVM_STATUS_POS UINT8_C(4) -#define BMI160_NVM_STATUS_MSK UINT8_C(0x10) +#define BMI160_NVM_STATUS_POS UINT8_C(4) +#define BMI160_NVM_STATUS_MSK UINT8_C(0x10) -#define BMI160_MAG_POWER_MODE_MSK UINT8_C(0x03) +#define BMI160_MAG_POWER_MODE_MSK UINT8_C(0x03) -#define BMI160_ACCEL_POWER_MODE_MSK UINT8_C(0x30) -#define BMI160_ACCEL_POWER_MODE_POS UINT8_C(4) +#define BMI160_ACCEL_POWER_MODE_MSK UINT8_C(0x30) +#define BMI160_ACCEL_POWER_MODE_POS UINT8_C(4) -#define BMI160_GYRO_POWER_MODE_MSK UINT8_C(0x0C) -#define BMI160_GYRO_POWER_MODE_POS UINT8_C(2) +#define BMI160_GYRO_POWER_MODE_MSK UINT8_C(0x0C) +#define BMI160_GYRO_POWER_MODE_POS UINT8_C(2) /* BIT SLICE GET AND SET FUNCTIONS */ #define BMI160_GET_BITS(regvar, bitname) \ @@ -695,18 +685,29 @@ ((reg_data & ~(bitname##_MSK)) | \ (data & bitname##_MSK)) -#define BMI160_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK)) +#define BMI160_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK)) /**\name UTILITY MACROS */ -#define BMI160_SET_LOW_BYTE UINT16_C(0x00FF) -#define BMI160_SET_HIGH_BYTE UINT16_C(0xFF00) +#define BMI160_SET_LOW_BYTE UINT16_C(0x00FF) +#define BMI160_SET_HIGH_BYTE UINT16_C(0xFF00) -#define BMI160_GET_LSB(var) (uint8_t)(var & BMI160_SET_LOW_BYTE) -#define BMI160_GET_MSB(var) (uint8_t)((var & BMI160_SET_HIGH_BYTE) >> 8) +#define BMI160_GET_LSB(var) (uint8_t)(var & BMI160_SET_LOW_BYTE) +#define BMI160_GET_MSB(var) (uint8_t)((var & BMI160_SET_HIGH_BYTE) >> 8) /*****************************************************************************/ /* type definitions */ -typedef int8_t (*bmi160_com_fptr_t)(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len); + +/*! + * @brief Bus communication function pointer which should be mapped to + * the platform specific read functions of the user + */ +typedef int8_t (*bmi160_read_fptr_t)(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len); + +/*! + * @brief Bus communication function pointer which should be mapped to + * the platform specific write functions of the user + */ +typedef int8_t (*bmi160_write_fptr_t)(uint8_t dev_addr, uint8_t reg_addr, uint8_t *read_data, uint16_t len); typedef void (*bmi160_delay_fptr_t)(uint32_t period); /*************************** Data structures *********************************/ @@ -976,7 +977,7 @@ enum bmi160_step_detect_mode { /*! * @brief enum for auxiliary burst read selection */ -enum bm160_aux_read_len { +enum bmi160_aux_read_len { BMI160_AUX_READ_LEN_0, BMI160_AUX_READ_LEN_1, BMI160_AUX_READ_LEN_2, @@ -1622,7 +1623,7 @@ struct bmi160_dev uint8_t id; /*! 0 - I2C , 1 - SPI Interface */ - uint8_t interface; + uint8_t intf; /*! Hold active interrupts status for any and sig motion * 0 - Any-motion enable, 1 - Sig-motion enable, @@ -1657,19 +1658,16 @@ struct bmi160_dev struct bmi160_fifo_frame *fifo; /*! Read function pointer */ - bmi160_com_fptr_t read; + bmi160_read_fptr_t read; /*! Write function pointer */ - bmi160_com_fptr_t write; + bmi160_write_fptr_t write; /*! Delay function pointer */ bmi160_delay_fptr_t delay_ms; /*! User set read/write length */ uint16_t read_write_len; - - /*! For switching from I2C to SPI */ - uint8_t dummy_byte; }; #endif /* BMI160_DEFS_H_ */ diff --git a/examples/read_chip_id/Makefile b/examples/read_chip_id/Makefile new file mode 100644 index 0000000..41bff4e --- /dev/null +++ b/examples/read_chip_id/Makefile @@ -0,0 +1,13 @@ +COINES_INSTALL_PATH ?= ../../../.. + +EXAMPLE_FILE ?= read_chip_id.c + +API_LOCATION ?= ../.. + +C_SRCS += \ +$(API_LOCATION)/bmi160.c + +INCLUDEPATHS += \ +$(API_LOCATION) + +include $(COINES_INSTALL_PATH)/coines.mk \ No newline at end of file diff --git a/examples/read_chip_id/read_chip_id.c b/examples/read_chip_id/read_chip_id.c new file mode 100644 index 0000000..6c61abd --- /dev/null +++ b/examples/read_chip_id/read_chip_id.c @@ -0,0 +1,241 @@ +/** + * Copyright (C) 2018 Bosch Sensortec GmbH + * + * SPDX-License-Identifier: BSD-3-Clause + * + * @file bmi160_read_chip_id.c + * @brief Sample file how to read bmi160 sensor chip ID using LIB COINES + * + */ + +/*********************************************************************/ +/* system header files */ +/*********************************************************************/ +#include +#include +#include + +/*********************************************************************/ +/* own header files */ +/*********************************************************************/ +#include "coines.h" +#include "bmi160.h" + +/*********************************************************************/ +/* local macro definitions */ +/*! i2c interface communication, 1 - Enable; 0- Disable */ +#define BMI160_INTERFACE_I2C 1 + +/*! spi interface communication, 1 - Enable; 0- Disable */ +#define BMI160_INTERFACE_SPI 0 + +#if (!((BMI160_INTERFACE_I2C == 1) && (BMI160_INTERFACE_SPI == 0)) && \ + (!((BMI160_INTERFACE_I2C == 0) && (BMI160_INTERFACE_SPI == 1)))) +#error "Invalid value given for the macros BMI160_INTERFACE_I2C / BMI160_INTERFACE_SPI" +#endif + +/*! bmi160 shuttle id */ +#define BMI160_SHUTTLE_ID 0x38 + +/*! bmi160 Device address */ +#define BMI160_DEV_ADDR BMI160_I2C_ADDR + +/*********************************************************************/ +/* global variables */ +/*********************************************************************/ + +/*! @brief This structure containing relevant bmi160 info */ +struct bmi160_dev bmi160dev; + +/*! @brief variable to hold the bmi160 accel data */ +struct bmi160_sensor_data bmi160_accel; + +/*! @brief variable to hold the bmi160 gyro data */ +struct bmi160_sensor_data bmi160_gyro; + +/*********************************************************************/ +/* static function declarations */ +/*********************************************************************/ + +/*! + * @brief internal API is used to initialize the sensor interface + */ +static void init_sensor_interface(void); + +/*! + * @brief This internal API is used to initialize the bmi160 sensor with default + */ +static void init_bmi160(void); + +/*! + * @brief This internal API is used to initialize the sensor driver interface + */ +static void init_bmi160_sensor_driver_interface(void); + +/*********************************************************************/ +/* functions */ +/*********************************************************************/ + +/*! + * @brief This internal API is used to initialize the sensor interface depending + * on selection either SPI or I2C. + * + * @param[in] void + * + * @return void + * + */ +static void init_sensor_interface(void) +{ + /* Switch VDD for sensor off */ + coines_set_shuttleboard_vdd_vddio_config(0, 0); + + /* wait until the sensor goes off */ + coines_delay_msec(10); +#if BMI160_INTERFACE_I2C == 1 + + /* SDO pin is made low for selecting I2C address 0x68 */ + coines_set_pin_config(COINES_SHUTTLE_PIN_15, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_LOW); + + /* set the sensor interface as I2C */ + coines_config_i2c_bus(COINES_I2C_BUS_0, COINES_I2C_FAST_MODE); + coines_delay_msec(10); + + /* CSB pin is made high for selecting I2C protocol*/ + coines_set_pin_config(COINES_SHUTTLE_PIN_7, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_HIGH); +#endif +#if BMI160_INTERFACE_SPI == 1 + + /* CSB pin is made low for selecting SPI protocol*/ + coines_set_pin_config(COINES_SHUTTLE_PIN_7, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_LOW); + + coines_delay_msec(10); + coines_config_spi_bus(COINES_SPI_BUS_0, COINES_SPI_SPEED_5_MHZ, COINES_SPI_MODE3); +#endif + coines_delay_msec(10); + + /* Switch VDD for sensor on */ + coines_set_shuttleboard_vdd_vddio_config(3300, 3300); + +#if BMI160_INTERFACE_SPI == 1 + coines_delay_msec(10); + + /* CSB pin is made high for selecting SPI protocol + * Note: CSB has to see rising after power up, to switch to SPI protocol */ + coines_set_pin_config(COINES_SHUTTLE_PIN_7, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_HIGH); +#endif +} + +/*! + * @brief This internal API is used to initializes the bmi160 sensor + * settings like power mode and OSRS settings. + * + * @param[in] void + * + * @return void + * + */ +static void init_bmi160(void) +{ + int8_t rslt; + + rslt = bmi160_init(&bmi160dev); + + if (rslt == BMI160_OK) + { + printf("BMI160 initialization success !\n"); + printf("Chip ID 0x%X\n", bmi160dev.chip_id); + } + else + { + printf("BMI160 initialization failure !\n"); + exit(COINES_E_FAILURE); + } +} + +/*! + * @brief This internal API is used to set the sensor driver interface to + * read/write the data. + * + * @param[in] void + * + * @return void + * + */ +static void init_bmi160_sensor_driver_interface(void) +{ +#if BMI160_INTERFACE_I2C == 1 + + /* I2C setup */ + + /* link read/write/delay function of host system to appropriate + * bmi160 function call prototypes */ + bmi160dev.write = coines_write_i2c; + bmi160dev.read = coines_read_i2c; + bmi160dev.delay_ms = coines_delay_msec; + + /* set correct i2c address */ + bmi160dev.id = BMI160_DEV_ADDR; + bmi160dev.intf = BMI160_I2C_INTF; +#endif +#if BMI160_INTERFACE_SPI == 1 + + /* SPI setup */ + + /* link read/write/delay function of host system to appropriate + * bmi160 function call prototypes */ + bmi160dev.write = coines_write_spi; + bmi160dev.read = coines_read_spi; + bmi160dev.delay_ms = coines_delay_msec; + bmi160dev.id = COINES_SHUTTLE_PIN_7; + bmi160dev.intf = BMI160_SPI_INTF; +#endif +} + +/*! + * @brief Main Function where the execution getting started to test the code. + * + * @param[in] argc + * @param[in] argv + * + * @return status + * + */ +int main(int argc, char *argv[]) +{ + struct coines_board_info board_info; + int16_t rslt; + + init_bmi160_sensor_driver_interface(); + + rslt = coines_open_comm_intf(COINES_COMM_INTF_USB); + + if (rslt < 0) + { + 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(rslt); + } + + rslt = coines_get_board_info(&board_info); + + if (rslt == COINES_SUCCESS) + { + if (board_info.shuttle_id != BMI160_SHUTTLE_ID) + { + + printf("! Warning invalid sensor shuttle \n ," "This application will not support this sensor \n"); + exit(COINES_E_FAILURE); + } + } + + init_sensor_interface(); + + /* After sensor init introduce 200 msec sleep */ + coines_delay_msec(200); + init_bmi160(); + coines_close_comm_intf(COINES_COMM_INTF_USB); + + return EXIT_SUCCESS; +} diff --git a/examples/read_sensor_data/Makefile b/examples/read_sensor_data/Makefile new file mode 100644 index 0000000..fdf2597 --- /dev/null +++ b/examples/read_sensor_data/Makefile @@ -0,0 +1,13 @@ +COINES_INSTALL_PATH ?= ../../../.. + +EXAMPLE_FILE ?= read_sensor_data.c + +API_LOCATION ?= ../.. + +C_SRCS += \ +$(API_LOCATION)/bmi160.c + +INCLUDEPATHS += \ +$(API_LOCATION) + +include $(COINES_INSTALL_PATH)/coines.mk \ No newline at end of file diff --git a/examples/read_sensor_data/read_sensor_data.c b/examples/read_sensor_data/read_sensor_data.c new file mode 100644 index 0000000..6d4d87b --- /dev/null +++ b/examples/read_sensor_data/read_sensor_data.c @@ -0,0 +1,275 @@ +/** + * Copyright (C) 2018 Bosch Sensortec GmbH + * + * SPDX-License-Identifier: BSD-3-Clause + * + * @file bmi160_read_sensor_data.c + * @brief Sample file to read BMI160 sensor data using COINES library + * + */ + +/*********************************************************************/ +/* system header files */ +/*********************************************************************/ +#include +#include +#include + +/*********************************************************************/ +/* own header files */ +/*********************************************************************/ +#include "coines.h" +#include "bmi160.h" + +/*********************************************************************/ +/* local macro definitions */ +/*! I2C interface communication, 1 - Enable; 0- Disable */ +#define BMI160_INTERFACE_I2C 1 + +/*! SPI interface communication, 1 - Enable; 0- Disable */ +#define BMI160_INTERFACE_SPI 0 + +#if (!((BMI160_INTERFACE_I2C == 1) && (BMI160_INTERFACE_SPI == 0)) && \ + (!((BMI160_INTERFACE_I2C == 0) && (BMI160_INTERFACE_SPI == 1)))) +#error "Invalid value given for the macros BMI160_INTERFACE_I2C / BMI160_INTERFACE_SPI" +#endif + +/*! bmi160 shuttle id */ +#define BMI160_SHUTTLE_ID 0x38 + +/*! bmi160 Device address */ +#define BMI160_DEV_ADDR BMI160_I2C_ADDR + +/*********************************************************************/ +/* global variables */ +/*********************************************************************/ + +/*! @brief This structure containing relevant bmi160 info */ +struct bmi160_dev bmi160dev; + +/*! @brief variable to hold the bmi160 accel data */ +struct bmi160_sensor_data bmi160_accel; + +/*! @brief variable to hold the bmi160 gyro data */ +struct bmi160_sensor_data bmi160_gyro; + +/*********************************************************************/ +/* static function declarations */ +/*********************************************************************/ + +/*! + * @brief internal API is used to initialize the sensor interface + */ +static void init_sensor_interface(void); + +/*! + * @brief This internal API is used to initialize the bmi160 sensor with default + */ +static void init_bmi160(void); + +/*! + * @brief This internal API is used to initialize the sensor driver interface + */ +static void init_bmi160_sensor_driver_interface(void); + +/*********************************************************************/ +/* functions */ +/*********************************************************************/ + +/*! + * @brief This internal API is used to initialize the sensor interface depending + * on selection either SPI or I2C. + * + * @param[in] void + * + * @return void + * + */ +static void init_sensor_interface(void) +{ + /* Switch VDD for sensor off */ + coines_set_shuttleboard_vdd_vddio_config(0, 0); + + /* wait until the sensor goes off */ + coines_delay_msec(10); +#if BMI160_INTERFACE_I2C == 1 + + /* SDO pin is made low for selecting I2C address 0x68 */ + coines_set_pin_config(COINES_SHUTTLE_PIN_15, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_LOW); + + /* set the sensor interface as I2C */ + coines_config_i2c_bus(COINES_I2C_BUS_0, COINES_I2C_FAST_MODE); + coines_delay_msec(10); + + /* CSB pin is made high for selecting I2C protocol*/ + coines_set_pin_config(COINES_SHUTTLE_PIN_7, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_HIGH); +#endif +#if BMI160_INTERFACE_SPI == 1 + + /* CSB pin is made low for selecting SPI protocol*/ + coines_set_pin_config(COINES_SHUTTLE_PIN_7, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_LOW); + + coines_delay_msec(10); + coines_config_spi_bus(COINES_SPI_BUS_0, COINES_SPI_SPEED_5_MHZ, COINES_SPI_MODE3); +#endif + coines_delay_msec(10); + + /* Switch VDD for sensor on */ + coines_set_shuttleboard_vdd_vddio_config(3300, 3300); + +#if BMI160_INTERFACE_SPI == 1 + coines_delay_msec(10); + + /* CSB pin is made high for selecting SPI protocol + * Note: CSB has to see rising after power up, to switch to SPI protocol */ + coines_set_pin_config(COINES_SHUTTLE_PIN_7, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_HIGH); +#endif +} + +/*! + * @brief This internal API is used to initializes the bmi160 sensor + * settings like power mode and OSRS settings. + * + * @param[in] void + * + * @return void + * + */ +static void init_bmi160(void) +{ + int8_t rslt; + + rslt = bmi160_init(&bmi160dev); + + if (rslt == BMI160_OK) + { + printf("BMI160 initialization success !\n"); + printf("Chip ID 0x%X\n", bmi160dev.chip_id); + } + else + { + printf("BMI160 initialization failure !\n"); + exit(COINES_E_FAILURE); + } + + /* Select the Output data rate, range of accelerometer sensor */ + bmi160dev.accel_cfg.odr = BMI160_ACCEL_ODR_1600HZ; + bmi160dev.accel_cfg.range = BMI160_ACCEL_RANGE_16G; + bmi160dev.accel_cfg.bw = BMI160_ACCEL_BW_NORMAL_AVG4; + + /* Select the power mode of accelerometer sensor */ + bmi160dev.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE; + + /* Select the Output data rate, range of Gyroscope sensor */ + bmi160dev.gyro_cfg.odr = BMI160_GYRO_ODR_3200HZ; + bmi160dev.gyro_cfg.range = BMI160_GYRO_RANGE_2000_DPS; + bmi160dev.gyro_cfg.bw = BMI160_GYRO_BW_NORMAL_MODE; + + /* Select the power mode of Gyroscope sensor */ + bmi160dev.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE; + + /* Set the sensor configuration */ + rslt = bmi160_set_sens_conf(&bmi160dev); +} + +/*! + * @brief This internal API is used to set the sensor driver interface to + * read/write the data. + * + * @param[in] void + * + * @return void + * + */ +static void init_bmi160_sensor_driver_interface(void) +{ +#if BMI160_INTERFACE_I2C == 1 + + /* I2C setup */ + + /* link read/write/delay function of host system to appropriate + * bmi160 function call prototypes */ + bmi160dev.write = coines_write_i2c; + bmi160dev.read = coines_read_i2c; + bmi160dev.delay_ms = coines_delay_msec; + + /* set correct i2c address */ + bmi160dev.id = BMI160_DEV_ADDR; + bmi160dev.intf = BMI160_I2C_INTF; +#endif +#if BMI160_INTERFACE_SPI == 1 + + /* SPI setup */ + + /* link read/write/delay function of host system to appropriate + * bmi160 function call prototypes */ + bmi160dev.write = coines_write_spi; + bmi160dev.read = coines_read_spi; + bmi160dev.delay_ms = coines_delay_msec; + bmi160dev.id = COINES_SHUTTLE_PIN_7; + bmi160dev.intf = BMI160_SPI_INTF; +#endif +} + +/*! + * @brief Main Function where the execution getting started to test the code. + * + * @param[in] argc + * @param[in] argv + * + * @return status + * + */ +int main(int argc, char *argv[]) +{ + struct coines_board_info board_info; + int16_t rslt; + int times_to_read = 0; + + init_bmi160_sensor_driver_interface(); + + rslt = coines_open_comm_intf(COINES_COMM_INTF_USB); + + if (rslt < 0) + { + 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(rslt); + } + + rslt = coines_get_board_info(&board_info); + + if (rslt == COINES_SUCCESS) + { + if (board_info.shuttle_id != BMI160_SHUTTLE_ID) + { + + printf("! Warning invalid sensor shuttle \n ," "This application will not support this sensor \n"); + exit(COINES_E_FAILURE); + } + } + + init_sensor_interface(); + + /* After sensor init introduce 200 msec sleep */ + coines_delay_msec(200); + init_bmi160(); + + while (times_to_read < 100) + { + /* To read both Accel and Gyro data */ + bmi160_get_sensor_data((BMI160_ACCEL_SEL | BMI160_GYRO_SEL), &bmi160_accel, &bmi160_gyro, &bmi160dev); + + printf("ax:%d\tay:%d\taz:%d\n", bmi160_accel.x, bmi160_accel.y, bmi160_accel.z); + printf("gx:%d\tgy:%d\tgz:%d\n", bmi160_gyro.x, bmi160_gyro.y, bmi160_gyro.z); + fflush(stdout); + + coines_delay_msec(10); + times_to_read = times_to_read + 1; + } + + coines_close_comm_intf(COINES_COMM_INTF_USB); + + return EXIT_SUCCESS; +} diff --git a/examples/tap/Makefile b/examples/tap/Makefile new file mode 100644 index 0000000..4058336 --- /dev/null +++ b/examples/tap/Makefile @@ -0,0 +1,13 @@ +COINES_INSTALL_PATH ?= ../../../.. + +EXAMPLE_FILE ?= tap.c + +API_LOCATION ?= ../.. + +C_SRCS += \ +$(API_LOCATION)/bmi160.c + +INCLUDEPATHS += \ +$(API_LOCATION) + +include $(COINES_INSTALL_PATH)/coines.mk \ No newline at end of file diff --git a/examples/tap/tap.c b/examples/tap/tap.c new file mode 100644 index 0000000..df62ee0 --- /dev/null +++ b/examples/tap/tap.c @@ -0,0 +1,370 @@ +/** + * Copyright (C) 2018 Bosch Sensortec GmbH + * + * SPDX-License-Identifier: BSD-3-Clause + * + * @file bmi160_read_sensor_data.c + * @brief Sample file to read BMI160 sensor data using COINES library + * + */ + +/*********************************************************************/ +/* system header files */ +/*********************************************************************/ +#include +#include +#include + +/*********************************************************************/ +/* own header files */ +/*********************************************************************/ +#include "coines.h" +#include "bmi160.h" + +/*********************************************************************/ +/* local macro definitions */ +/*! i2c interface communication, 1 - Enable; 0- Disable */ +#define BMI160_INTERFACE_I2C 0 + +/*! spi interface communication, 1 - Enable; 0- Disable */ +#define BMI160_INTERFACE_SPI 1 + +#if (!((BMI160_INTERFACE_I2C == 1) && (BMI160_INTERFACE_SPI == 0)) && \ + (!((BMI160_INTERFACE_I2C == 0) && (BMI160_INTERFACE_SPI == 1)))) +#error "Invalid value given for the macros BMI160_INTERFACE_I2C / BMI160_INTERFACE_SPI" +#endif + +/*! bmi160 shuttle id */ +#define BMI160_SHUTTLE_ID 0x38 + +/*! bmi160 Device address */ +#define BMI160_DEV_ADDR BMI160_I2C_ADDR + +/*********************************************************************/ +/* global variables */ +/*********************************************************************/ + +/*! @brief This structure containing relevant bmi160 info */ +struct bmi160_dev bmi160dev; + +/*! @brief variable to hold the bmi160 accel data */ +struct bmi160_sensor_data bmi160_accel; + +/*! @brief variable to hold the bmi160 gyro data */ +struct bmi160_sensor_data bmi160_gyro; + +/*********************************************************************/ +/* static function declarations */ +/*********************************************************************/ + +/*! + * @brief internal API is used to initialize the sensor interface + */ +static void init_sensor_interface(void); + +/*! + * @brief This internal API is used to initialize the bmi160 sensor with default + */ +static void init_bmi160(void); + +/*! + * @brief This internal API is used to initialize the sensor driver interface + */ +static void init_bmi160_sensor_driver_interface(void); + +/*! + * @brief This internal API is used to set tap configurations + */ +static int8_t set_tap_config(uint8_t feature_enable); + +/*********************************************************************/ +/* functions */ +/*********************************************************************/ + +/*! + * @brief This internal API is used to initialize the sensor interface depending + * on selection either SPI or I2C. + * + * @param[in] void + * + * @return void + * + */ +static void init_sensor_interface(void) +{ + /* Switch VDD for sensor off */ + coines_set_shuttleboard_vdd_vddio_config(0, 0); + + /* wait until the sensor goes off */ + coines_delay_msec(10); +#if BMI160_INTERFACE_I2C == 1 + + /* SDO pin is made low for selecting I2C address 0x68 */ + coines_set_pin_config(COINES_SHUTTLE_PIN_15, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_LOW); + + /* set the sensor interface as I2C */ + coines_config_i2c_bus(COINES_I2C_BUS_0, COINES_I2C_FAST_MODE); + coines_delay_msec(10); + + /* CSB pin is made high for selecting I2C protocol*/ + coines_set_pin_config(COINES_SHUTTLE_PIN_7, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_HIGH); +#endif +#if BMI160_INTERFACE_SPI == 1 + + /* CSB pin is made low for selecting SPI protocol*/ + coines_set_pin_config(COINES_SHUTTLE_PIN_7, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_LOW); + + coines_delay_msec(10); + coines_config_spi_bus(COINES_SPI_BUS_0, COINES_SPI_SPEED_5_MHZ, COINES_SPI_MODE3); +#endif + coines_delay_msec(10); + + /* Switch VDD for sensor on */ + coines_set_shuttleboard_vdd_vddio_config(3300, 3300); + +#if BMI160_INTERFACE_SPI == 1 + coines_delay_msec(10); + + /* CSB pin is made high for selecting SPI protocol + * Note: CSB has to see rising after power up, to switch to SPI protocol */ + coines_set_pin_config(COINES_SHUTTLE_PIN_7, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_HIGH); +#endif +} + +/*! + * @brief This internal API is used to initializes the bmi160 sensor + * settings like power mode and OSRS settings. + * + * @param[in] void + * + * @return void + * + */ +static void init_bmi160(void) +{ + int8_t rslt; + + rslt = bmi160_init(&bmi160dev); + + if (rslt == BMI160_OK) + { + printf("BMI160 initialization success !\n"); + printf("Chip ID 0x%X\n", bmi160dev.chip_id); + } + else + { + printf("BMI160 initialization failure !\n"); + exit(COINES_E_FAILURE); + } + + /* Select the Output data rate, range of accelerometer sensor */ + bmi160dev.accel_cfg.odr = BMI160_ACCEL_ODR_100HZ; + bmi160dev.accel_cfg.range = BMI160_ACCEL_RANGE_8G; + bmi160dev.accel_cfg.bw = BMI160_ACCEL_BW_NORMAL_AVG4; + + /* Select the power mode of accelerometer sensor */ + bmi160dev.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE; + + /* Set the sensor configuration */ + rslt = bmi160_set_sens_conf(&bmi160dev); +} + +/*! + * @brief This internal API is used to set the sensor driver interface to + * read/write the data. + * + * @param[in] void + * + * @return void + * + */ +static void init_bmi160_sensor_driver_interface(void) +{ +#if BMI160_INTERFACE_I2C == 1 + + /* I2C setup */ + + /* link read/write/delay function of host system to appropriate + * bmi160 function call prototypes */ + bmi160dev.write = coines_write_i2c; + bmi160dev.read = coines_read_i2c; + bmi160dev.delay_ms = coines_delay_msec; + + /* set correct i2c address */ + bmi160dev.id = BMI160_DEV_ADDR; + bmi160dev.intf = BMI160_I2C_INTF; +#endif +#if BMI160_INTERFACE_SPI == 1 + + /* SPI setup */ + + /* link read/write/delay function of host system to appropriate + * bmi160 function call prototypes */ + bmi160dev.write = coines_write_spi; + bmi160dev.read = coines_read_spi; + bmi160dev.delay_ms = coines_delay_msec; + bmi160dev.id = COINES_SHUTTLE_PIN_7; + bmi160dev.intf = BMI160_SPI_INTF; +#endif +} + +/*! + * @brief Main Function where the execution getting started to test the code. + * + * @param[in] argc + * @param[in] argv + * + * @return status + * + */ +int main(int argc, char *argv[]) +{ + struct coines_board_info board_info; + int16_t rslt; + + init_bmi160_sensor_driver_interface(); + + rslt = coines_open_comm_intf(COINES_COMM_INTF_USB); + + if (rslt < 0) + { + 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(rslt); + } + + rslt = coines_get_board_info(&board_info); + + if (rslt == COINES_SUCCESS) + { + if (board_info.shuttle_id != BMI160_SHUTTLE_ID) + { + + printf("! Warning invalid sensor shuttle \n ," "This application will not support this sensor \n"); + exit(COINES_E_FAILURE); + } + } + + init_sensor_interface(); + + /* after sensor init introduce 200 msec sleep */ + coines_delay_msec(200); + init_bmi160(); + + rslt = set_tap_config(BMI160_ENABLE); + if (rslt == BMI160_OK) + { + union bmi160_int_status int_status; + uint8_t loop = 0; + uint32_t last_time = 0; + uint32_t current_time = 0; + + printf("Do Single or Double Tap the board\n"); + fflush(stdout); + + memset(int_status.data, 0x00, sizeof(int_status.data)); + + while (loop < 10) + { + /* Read interrupt status */ + rslt = bmi160_get_int_status(BMI160_INT_STATUS_ALL, &int_status, &bmi160dev); + current_time = coines_get_millis(); + + /* Enters only if the obtained interrupt is single-tap */ + if (rslt == BMI160_OK) + { + /* Enters only if the obtained interrupt is single-tap */ + if (int_status.bit.s_tap) + { + printf("Single tap, iter:%d, time:%d ms, delta:%d ms, int_status:0x%x\n", + loop++, + current_time, + current_time - last_time, + int_status.data[0]); + } + /* Enters only if the obtained interrupt is double-tap */ + else if (int_status.bit.d_tap) + { + printf("Double tap, iter:%d, time:%d ms, delta:%d ms, int_status:0x%x\n", + loop++, + current_time, + current_time - last_time, + int_status.data[0]); + } + + fflush(stdout); + } + else + { + break; + } + + memset(int_status.data, 0x00, sizeof(int_status.data)); + last_time = current_time; + } + + /* Disable tap feature */ + printf("\nDisable tap test...\n"); + rslt = set_tap_config(BMI160_DISABLE); + printf("bmi160_set_int_config(tap enable) status:%d\n", rslt); + + fflush(stdout); + } + + coines_close_comm_intf(COINES_COMM_INTF_USB); + + return EXIT_SUCCESS; +} + +static int8_t set_tap_config(uint8_t feature_enable) +{ + int8_t rslt = BMI160_OK; + struct bmi160_int_settg int_config; + + if (feature_enable > 0) + { + /* Select the Interrupt channel/pin */ + int_config.int_channel = BMI160_INT_CHANNEL_1; /* Interrupt channel/pin 1 */ + + /* Select the interrupt channel/pin settings */ + int_config.int_pin_settg.output_en = BMI160_ENABLE; /* Enabling interrupt pins to act as output pin */ + int_config.int_pin_settg.output_mode = BMI160_DISABLE; /* Choosing push-pull mode for interrupt pin */ + int_config.int_pin_settg.output_type = BMI160_ENABLE; /* Choosing active low output */ + int_config.int_pin_settg.edge_ctrl = BMI160_DISABLE; /* Choosing edge triggered output */ + int_config.int_pin_settg.input_en = BMI160_DISABLE; /* Disabling interrupt pin to act as input */ + int_config.int_pin_settg.latch_dur = BMI160_LATCH_DUR_NONE; /* non-latched output */ + + /* Select the Interrupt type */ + int_config.int_type = BMI160_ACC_SINGLE_TAP_INT; /* Choosing tap interrupt */ + + /* Select the Any-motion interrupt parameters */ + int_config.int_type_cfg.acc_tap_int.tap_en = BMI160_ENABLE; /* 1- Enable tap, 0- disable tap */ + int_config.int_type_cfg.acc_tap_int.tap_thr = 2; /* Set tap threshold */ + int_config.int_type_cfg.acc_tap_int.tap_dur = 2; /* Set tap duration */ + int_config.int_type_cfg.acc_tap_int.tap_shock = 0; /* Set tap shock value */ + int_config.int_type_cfg.acc_tap_int.tap_quiet = 0; /* Set tap quiet duration */ + int_config.int_type_cfg.acc_tap_int.tap_data_src = 1; /* data source 0 : filter or 1 : pre-filter */ + + /* Set the Any-motion interrupt */ + rslt = bmi160_set_int_config(&int_config, &bmi160dev); /* sensor is an instance of the structure bmi160_dev */ + printf("bmi160_set_int_config(tap enable) status:%d\n", rslt); + } + else + { + /* Select the Interrupt channel/pin */ + int_config.int_channel = BMI160_INT_CHANNEL_1; + int_config.int_pin_settg.output_en = BMI160_DISABLE; /* Disabling interrupt pins to act as output pin */ + int_config.int_pin_settg.edge_ctrl = BMI160_DISABLE; /* Choosing edge triggered output */ + + /* Select the Interrupt type */ + int_config.int_type = BMI160_ACC_SINGLE_TAP_INT; /* Choosing Tap interrupt */ + int_config.int_type_cfg.acc_tap_int.tap_en = BMI160_DISABLE; /* 1- Enable tap, 0- disable tap */ + + /* Set the Data ready interrupt */ + rslt = bmi160_set_int_config(&int_config, &bmi160dev); /* sensor is an instance of the structure bmi160_dev */ + printf("bmi160_set_int_config(tap disable) status:%d\n", rslt); + } + + return rslt; +}