1 # Sensor API for the BMI2's OIS interface
4 - [Introduction](#Intro)
5 - [Integration details](#Integration)
6 - [Driver files information](#file)
7 - [Sensor interfaces](#interface)
8 - [Integration Examples](#examples)
10 ### Introduction<a name=Intro></a>
11 This package contains Bosch Sensortec's BMI2 Sensor API.
13 ### Integration details<a name=Integration></a>
14 - Integrate _bmi2.c_, _bmi2.h_, _bmi2_ois.c_, _bmi2_ois.h_, _bmi2_defs.h_ and the required variant files in your project.
15 - User has to include _bmi2_ois.h_ in the code to call OIS related APIs and a _variant header_ for initialization as
16 well as BMI2 related API calls, as shown below:
21 ### Driver files information<a name=file></a>
23 * This file has function definitions of OIS related API interfaces.
25 * This header file has necessary include files, function declarations, required to make OIS related API calls.
27 ### Sensor interfaces<a name=interface></a>
31 _Note: By default, the interface is I2C._
36 ### Integration examples<a name=examples></a>
37 #### Configuring SPI/I2C for host interface.
38 To configure host interface, an instance of the bmi2_dev structure should be
39 created for initializing BMI2 sensor. "_Refer **README** for initializing BMI2
42 #### Configuring SPI for OIS interface.
43 To configure OIS interface, an instance of the bmi2_ois_dev structure should be
44 created. The following parameters are required to be updated in the structure,
48 --------------|-----------------------------------
49 _intf_ptr_ | device address reference of SPI interface
50 _ois_read_ | read through SPI interface
51 _ois_write_ | read through SPI interface
52 _ois_delay_us_| delay in micro seconds
53 _acc_en_ | for enabling accelerometer
54 _gyr_en_ | for enabling gyroscope
59 struct bmi2_ois_dev ois_dev = {
60 .intf_ptr = intf_ptr will contain the chip selection info of SPI CS pin,
61 .ois_read = user_spi_reg_read,
62 .ois_write = user_spi_reg_write,
63 .ois_delay_us = user_delay_us
66 >**_Important Note_**: For initializing and configuring BMI2 sensors, which is
67 done through host interface, the API's are to be used from bmi2.c file. Rest
68 of the API's, for OIS configurations and the reading of OIS data, which is done
69 through OIS interface, are to be used from bmi2_ois.c file.
71 ##### Get accelerometer and gyroscope data through OIS interface
74 /* Array to enable sensor through host interface */
75 uint8_t sens_list[2] = {BMI2_ACCEL, BMI2_GYRO};
76 /* Array to enable sensor through OIS interface */
77 uint8_t sens_sel[2] = {BMI2_OIS_ACCEL, BMI2_OIS_GYRO};
78 /* Initialize the configuration structure */
79 struct bmi2_sens_config sens_cfg = {0};
82 rslt = bmi2_init(&dev);
83 if (rslt != BMI2_OK) {
84 printf("Error: %d\n", rslt);
88 /* Enable accelerometer and gyroscope through host interface */
89 rslt = bmi270_sensor_enable(sens_list, 2, &dev);
90 if (rslt != BMI2_OK) {
91 printf("Error: %d\n", rslt);
95 /* Setting of OIS Range is done through host interface */
96 /* Select the gyroscope sensor for OIS Range configuration */
97 sens_cfg.type = BMI2_GYRO;
99 /* Get gyroscope configuration */
100 rslt = bmi2_get_sensor_config(&sens_cfg, 1, &dev);
101 if (rslt != BMI2_OK) {
102 printf("Error: %d\n", rslt);
106 /* Set the desired OIS Range */
107 sens_cfg.cfg.gyr.ois_range = BMI2_GYR_OIS_2000;
109 /* Set gyroscope configuration for default values */
110 rslt = bmi2_set_sensor_config(&sens_cfg, 1, &dev);
111 if (rslt != BMI2_OK) {
112 printf("Error: %d\n", rslt);
116 /* Enable OIS through host interface */
117 rslt = bmi2_set_ois_interface(BMI2_ENABLE, &dev);
118 if (rslt != BMI2_OK) {
119 printf("Error: %d\n", rslt);
123 /* Disable Advance Power Save Mode through host interface */
124 rslt = bmi2_set_adv_power_save(BMI2_DISABLE, &dev);
125 if (rslt != BMI2_OK) {
126 printf("Error: %d\n", rslt);
130 /* Get configurations for OIS through OIS interface for default values */
131 rslt = bmi2_ois_get_config(&ois_dev);
132 if (rslt != BMI2_OK) {
133 printf("Error: %d\n", rslt);
137 /* Enable accelerometer and gyroscope for reading OIS data */
138 ois_dev.acc_en = BMI2_ENABLE;
139 ois_dev.gyr_en = BMI2_ENABLE;
141 /* Set configurations for OIS through OIS interface */
142 rslt = bmi2_ois_set_config(&ois_dev);
143 if (rslt == BMI2_OK) {
144 /* Get OIS accelerometer and gyroscope data through OIS interface */
145 rslt = bmi2_ois_read_data(sens_sel, 2, &ois_dev);
146 if (rslt == BMI2_OK) {
147 /* Print accelerometer data */
148 printf("OIS Accel x-axis = %d\t", ois_dev.acc_data.x);
149 printf("OIS Accel y-axis= %d\t", ois_dev.acc_data.y);
150 printf("OIS Accel z-axis = %d\r\n", ois_dev.acc_data.z);
152 /* Print gyroscope data */
153 printf("OIS Gyro x-axis = %d\t", ois_dev.gyr_data.x);
154 printf("OIS Gyro y-axis= %d\t", ois_dev.gyr_data.y);
155 printf("OIS Gyro z-axis = %d\r\n", ois_dev.gyr_data.z);
159 if (rslt != BMI2_OK) {
160 printf("Error code: %d\n", rslt);
164 /* Enable Advance Power Save Mode through host interface */
165 rslt = bmi2_set_adv_power_save(BMI2_ENABLE, &dev);
166 if (rslt != BMI2_OK) {
167 printf("Error: %d\n", rslt);