123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721 |
- /*
- ****************************************************************************
- * Copyright (C) 2014 Bosch Sensortec GmbH
- *
- * bmi160_support.c
- * Date: 2014/12/12
- * Revision: 1.0.5 $
- *
- * Usage: Sensor Driver support file for BMI160 sensor
- *
- ****************************************************************************
- * License:
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 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.
- *
- * Neither the name of the copyright holder nor the names of the
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
- * OR CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
- * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
- *
- * The information provided is believed to be accurate and reliable.
- * The copyright holder assumes no responsibility
- * for the consequences of use
- * of such information nor for any infringement of patents or
- * other rights of third parties which may result from its use.
- * No license is granted by implication or otherwise under any patent or
- * patent rights of the copyright holder.
- **************************************************************************/
- #include "bmi160_support.h"
- #include "bmi160.h"
- /* Mapping the structure*/
- struct bmi160_t s_bmi160;
- /* Read the sensor data of accel, gyro and mag*/
- struct bmi160_gyro_t gyroxyz;
- struct bmi160_accel_t accelxyz;
- struct bmi160_mag_t magxyzr;
- struct trim_data *mag_trim;
- /*!
- * @brief This function used for initialize the sensor
- *
- *
- * @return results of bus communication function
- * @retval 0 -> Success
- * @retval 1 -> Error
- *
- *
- */
- BMI160_RETURN_FUNCTION_TYPE bmi160_initialize_sensor(u8 v_running_mode_u8)
- {
- BMI160_RETURN_FUNCTION_TYPE com_rslt = C_BMI160_ZERO_U8X;
- /* Based on the user need configure I2C or SPI interface.
- * It is sample code to explain how to use the bmi160 API*/
- #ifdef INCLUDE_BMI160API
- com_rslt = spi_routine();
- /*SPI_routine(); */
- #endif
- /*
- * This function used to assign the value/reference of
- * the following parameters
- * I2C address
- * Bus Write
- * Bus read
- * company_id
- */
- com_rslt += bmi160_init(&s_bmi160);
-
- if(s_bmi160.chip_id == 0)return -1;
- uint8_t acc_mode = 0xFF,gryo_mode = 0xFF;
- uint32_t count = 0;
- do{
- com_rslt += bmi160_set_command_register(0xB6);//reset
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- bmi160_get_accel_power_mode_stat(&acc_mode);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);
- bmi160_get_gyro_power_mode_stat(&gryo_mode);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);
- if(count++ > 10)break;
- }while(acc_mode != 0x00 && gryo_mode != 0x00);
- /**** STANDARD_UI_IMU output****/
- com_rslt += bmi160_config_running_mode(v_running_mode_u8);
- return com_rslt;
- }
- /*!
- * @brief This Function used to read the sensor data using
- * different running mode
- * @param v_running_mode_u8 : The value of running mode
- * Description | value
- * --------------------------------|----------
- * STANDARD_UI_9DOF_FIFO | 0
- * STANDARD_UI_IMU_FIFO | 1
- * STANDARD_UI_IMU | 2
- * STANDARD_UI_ADVANCEPOWERSAVE | 3
- * ACCEL_PEDOMETER | 4
- * ACCEL_PEDOMETER_FIFO | 5
- * APPLICATION_HEAD_TRACKING | 6
- * APPLICATION_NAVIGATION | 7
- * APPLICATION_REMOTE_CONTROL | 8
- * APPLICATION_INDOOR_NAVIGATION | 9
- *
- *
- * @return results of bus communication function
- * @retval 0 -> Success
- * @retval 1 -> Error
- *
- *
- */
- BMI160_RETURN_FUNCTION_TYPE bmi160_config_running_mode(
- u8 v_running_mode_u8)
- {
- struct gyro_sleep_setting gyr_setting;
- struct bmi160_mag_xyz_s32_t magxyz;
- /* Variable used for get the status of mag interface*/
- u8 v_mag_interface_u8 = C_BMI160_ZERO_U8X;
- BMI160_RETURN_FUNCTION_TYPE com_rslt = ERROR;
- /* Configure the gyro sleep setting based on your need*/
- if (v_running_mode_u8 == STANDARD_UI_ADVANCEPOWERSAVE) {
- gyr_setting. sleep_trigger = BMI160_WRITE_FOUR;
- gyr_setting. wakeup_trigger = BMI160_WRITE_TWO;
- gyr_setting. sleep_state = BMI160_WRITE_ZERO;
- gyr_setting. wakeup_int = BMI160_WRITE_ZERO;
- }
- /* The below code used for enable and
- disable the secondary mag interface*/
- com_rslt = bmi160_get_if_mode(&v_mag_interface_u8);
- if (((v_running_mode_u8 == STANDARD_UI_IMU_FIFO) ||
- (v_running_mode_u8 == STANDARD_UI_IMU) ||
- (v_running_mode_u8 == STANDARD_UI_ADVANCEPOWERSAVE) ||
- (v_running_mode_u8 == APPLICATION_NAVIGATION) ||
- (v_running_mode_u8 == ACCEL_PEDOMETER) ||
- (v_running_mode_u8 == APPLICATION_REMOTE_CONTROL) ||
- (v_running_mode_u8 == APPLICATION_INDOOR_NAVIGATION))
- && (v_mag_interface_u8 == BMI160_MAG_INTERFACE_ON_PRIMARY_ON)) {
- com_rslt +=
- bmi160_set_bmm150_mag_and_secondary_if_power_mode(
- MAG_SUSPEND_MODE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- com_rslt += bmi160_set_if_mode(
- BMI160_MAG_INTERFACE_OFF_PRIMARY_ON);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- }
- if (((v_running_mode_u8 == STANDARD_UI_9DOF_FIFO)
- || (v_running_mode_u8 == APPLICATION_HEAD_TRACKING) ||
- (v_running_mode_u8 == APPLICATION_NAVIGATION)) &&
- (v_mag_interface_u8 == BMI160_MAG_INTERFACE_OFF_PRIMARY_ON)) {
- /* Init the magnetometer */
- com_rslt += bmi160_bmm150_mag_interface_init();
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);
- }
- switch (v_running_mode_u8) {
- case STANDARD_UI_9DOF_FIFO:
- /*Set the accel mode as Normal write in the register 0x7E*/
- com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- /*Set the gyro mode as Normal write in the register 0x7E*/
- com_rslt += bmi160_set_command_register(GYRO_MODE_NORMAL);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- /* Set the accel bandwidth as Normal */
- com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_NORMAL_AVG4);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Set the gryo bandwidth as Normal */
- com_rslt += bmi160_set_gyro_bw(BMI160_GYRO_NORMAL_MODE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set gyro data rate as 100Hz*/
- com_rslt += bmi160_set_gyro_output_data_rate(
- BMI160_GYRO_OUTPUT_DATA_RATE_100HZ);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set accel data rate as 100Hz*/
- com_rslt += bmi160_set_accel_output_data_rate(
- BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /***** read FIFO data based on interrupt*****/
- com_rslt += bmi160_interrupt_configuration();
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable the FIFO header*/
- com_rslt += bmi160_set_fifo_header_enable(FIFO_HEADER_ENABLE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable the FIFO mag*/
- com_rslt += bmi160_set_fifo_mag_enable(FIFO_MAG_ENABLE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable the FIFO accel*/
- com_rslt += bmi160_set_fifo_accel_enable(FIFO_ACCEL_ENABLE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable the FIFO gyro*/
- com_rslt += bmi160_set_fifo_gyro_enable(FIFO_GYRO_ENABLE);
- /* Enable the FIFO time*/
- com_rslt += bmi160_set_fifo_time_enable(FIFO_TIME_ENABLE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable the FIFO stop on full*/
- com_rslt += bmi160_set_fifo_stop_on_full(
- FIFO_STOPONFULL_ENABLE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable the FIFO water mark interrupt1*/
- com_rslt += bmi160_set_intr_fifo_wm(C_BMI160_ZERO_U8X,
- FIFO_WM_INTERRUPT_ENABLE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable the FIFO water mark interrupt2*/
- com_rslt += bmi160_set_intr_fifo_wm(C_BMI160_ONE_U8X,
- FIFO_WM_INTERRUPT_ENABLE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set the fifo water mark*/
- com_rslt += bmi160_set_fifo_wm(BMI160_WRITE_TWO);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* read the FIFO data*/
- com_rslt += bmi160_read_fifo_header_data(FIFO_FRAME);
- break;
- case STANDARD_UI_IMU_FIFO:
- com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- /*Set the gyro mode as Normal write in the register 0x7E*/
- com_rslt += bmi160_set_command_register(GYRO_MODE_NORMAL);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- /* Set the accel bandwidth as Normal */
- com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_NORMAL_AVG4);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Set the gryo bandwidth as Normal */
- com_rslt += bmi160_set_gyro_bw(BMI160_GYRO_NORMAL_MODE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set gyro data rate as 100Hz*/
- com_rslt += bmi160_set_gyro_output_data_rate(
- BMI160_GYRO_OUTPUT_DATA_RATE_100HZ);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set accel data rate as 100Hz*/
- com_rslt += bmi160_set_accel_output_data_rate(
- BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /***** read FIFO data based on interrupt*****/
- com_rslt += bmi160_interrupt_configuration();
- /* Enable the FIFO header*/
- com_rslt += bmi160_set_fifo_header_enable(FIFO_HEADER_ENABLE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable the FIFO accel*/
- com_rslt += bmi160_set_fifo_accel_enable(FIFO_ACCEL_ENABLE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable the FIFO gyro*/
- com_rslt += bmi160_set_fifo_gyro_enable(FIFO_GYRO_ENABLE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable the FIFO time*/
- com_rslt += bmi160_set_fifo_time_enable(FIFO_TIME_ENABLE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable the FIFO stop on full*/
- com_rslt += bmi160_set_fifo_stop_on_full(
- FIFO_STOPONFULL_ENABLE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable the FIFO water mark interrupt1*/
- com_rslt += bmi160_set_intr_fifo_wm(C_BMI160_ZERO_U8X,
- FIFO_WM_INTERRUPT_ENABLE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable the FIFO water mark interrupt2*/
- com_rslt += bmi160_set_intr_fifo_wm(C_BMI160_ONE_U8X,
- FIFO_WM_INTERRUPT_ENABLE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set the fifo water mark as 10*/
- com_rslt += bmi160_set_fifo_wm(BMI160_WRITE_TWO);
- // /* read the FIFO data*/
- // com_rslt += bmi160_read_fifo_header_data(FIFO_FRAME);
- break;
- case STANDARD_UI_IMU:
- /*Set the accel mode as Normal write in the register 0x7E*/
- com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- /*Set the gyro mode as Normal write in the register 0x7E*/
- com_rslt += bmi160_set_command_register(GYRO_MODE_NORMAL);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- /* Set the accel range as BMI160_ACCEL_RANGE_16G */
- com_rslt += bmi160_set_accel_range(BMI160_ACCEL_RANGE_16G);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- com_rslt += bmi160_set_gyro_range(BMI160_GYRO_RANGE_2000_DEG_SEC);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- /* Set the accel bandwidth as Normal */
- com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_NORMAL_AVG4);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Set the gryo bandwidth as Normal */
- com_rslt += bmi160_set_gyro_bw(BMI160_GYRO_NORMAL_MODE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set gyro data rate as 100Hz*/
- com_rslt += bmi160_set_gyro_output_data_rate(
- BMI160_GYRO_OUTPUT_DATA_RATE_100HZ);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set accel data rate as 100Hz*/
- com_rslt += bmi160_set_accel_output_data_rate(
- BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* read gyro data*/
- com_rslt += bmi160_read_gyro_xyz(&gyroxyz);
- /* read accel data*/
- com_rslt += bmi160_read_accel_xyz(&accelxyz);
-
- u8 acc_range,gryo_range;
- com_rslt += bmi160_get_gyro_range(&gryo_range);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);
- com_rslt += bmi160_get_accel_range(&acc_range);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);
- if(acc_range != BMI160_ACCEL_RANGE_16G || gryo_range != BMI160_GYRO_RANGE_2000_DEG_SEC)com_rslt += -1;
- if(gyroxyz.x == 0 && gyroxyz.y == 0 && gyroxyz.z == 0)com_rslt += -1;
- if(accelxyz.x == 0 && accelxyz.y == 0 && accelxyz.z == 0)com_rslt += -1;
- break;
- case STANDARD_UI_ADVANCEPOWERSAVE:
- /*Set the accel mode as Normal write in the register 0x7E*/
- com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- /* Set the accel bandwidth as Normal */
- com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_NORMAL_AVG4);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Set the gryo bandwidth as Normal */
- com_rslt += bmi160_set_gyro_bw(BMI160_GYRO_NORMAL_MODE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set gyro data rate as 100Hz*/
- com_rslt += bmi160_set_gyro_output_data_rate(
- BMI160_GYRO_OUTPUT_DATA_RATE_100HZ);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set accel data rate as 100Hz*/
- com_rslt += bmi160_set_accel_output_data_rate(
- BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable any motion interrupt - x axis*/
- com_rslt += bmi160_set_intr_enable_0(C_BMI160_ZERO_U8X,
- BMI160_WRITE_ONE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable any motion interrupt - y axis*/
- com_rslt += bmi160_set_intr_enable_0(C_BMI160_ONE_U8X,
- BMI160_WRITE_ONE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable any motion interrupt - z axis*/
- com_rslt += bmi160_set_intr_enable_0(C_BMI160_TWO_U8X,
- BMI160_WRITE_ONE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable no motion interrupt - x axis*/
- com_rslt += bmi160_set_intr_enable_2(C_BMI160_ZERO_U8X,
- BMI160_WRITE_ONE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable no motion interrupt - y axis*/
- com_rslt += bmi160_set_intr_enable_2(C_BMI160_ONE_U8X,
- BMI160_WRITE_ONE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable no motion interrupt - z axis*/
- com_rslt += bmi160_set_intr_enable_2(C_BMI160_TWO_U8X,
- BMI160_WRITE_ONE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set the gyro sleep trigger*/
- com_rslt += bmi160_set_gyro_sleep_trigger(
- gyr_setting.sleep_trigger);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set the gyro wakeup trigger*/
- com_rslt += bmi160_set_gyro_wakeup_trigger(
- gyr_setting.wakeup_trigger);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set the gyro sleep state*/
- com_rslt += bmi160_set_gyro_sleep_state(
- gyr_setting.sleep_state);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set the gyro wakeup interrupt*/
- com_rslt += bmi160_set_gyro_wakeup_intr(gyr_setting.wakeup_int);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* read gyro data*/
- com_rslt += bmi160_read_gyro_xyz(&gyroxyz);
- /* read accel data*/
- com_rslt += bmi160_read_accel_xyz(&accelxyz);
- break;
- case ACCEL_PEDOMETER:
- com_rslt = bmi160_set_accel_under_sampling_parameter(BMI160_ENABLE);//¨°a?a??1y2¨¦?¨´?¡ê¨º?¡ê?2?¨¨???2?¨¢?¦Ì¨ª1|o??¡ê¨º?
- /*Set the accel mode as Normal write in the register 0x7E*/
- com_rslt = bmi160_set_command_register(ACCEL_LOWPOWER);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
-
- com_rslt += bmi160_set_accel_range(BMI160_ACCEL_RANGE_16G);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
-
- com_rslt = bmi160_set_accel_under_sampling_parameter(BMI160_ENABLE);//¨°a?a??1y2¨¦?¨´?¡ê¨º?¡ê?2?¨¨???2?¨¢?¦Ì¨ª1|o??¡ê¨º?
-
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
-
-
- /*Set the gyro mode as SUSPEND write in the register 0x7E*/
- com_rslt += bmi160_set_command_register(GYRO_MODE_SUSPEND);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- /* Set the accel bandwidth as OSR4 */
- com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_OSR4_AVG1);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set accel data rate as 25Hz*/
- com_rslt += bmi160_set_accel_output_data_rate(
- BMI160_ACCEL_OUTPUT_DATA_RATE_25HZ);
- /* 10 not available*/
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* read accel data*/
- com_rslt += bmi160_read_accel_xyz(&accelxyz);
- if(accelxyz.x == 0 && accelxyz.y == 0 && accelxyz.z == 0)com_rslt += -1;
- break;
- case ALL_SUSPEND:
- com_rslt += bmi160_set_command_register(GYRO_MODE_SUSPEND);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- com_rslt += bmi160_set_command_register(ACCEL_SUSPEND);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
-
- break;
- case ACCEL_PEDOMETER_FIFO:
- /*Set the accel mode as Normal write in the register 0x7E*/
- com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- /*Set the gyro mode as SUSPEND write in the register 0x7E*/
- com_rslt += bmi160_set_command_register(GYRO_MODE_SUSPEND);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- /* Set the accel range as BMI160_ACCEL_RANGE_16G */
- com_rslt += bmi160_set_accel_range(BMI160_ACCEL_RANGE_16G);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- /* Set the accel bandwidth as Normal */
- com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_NORMAL_AVG4);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set accel data rate as 100Hz*/
- com_rslt += bmi160_set_accel_output_data_rate(
- BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable the FIFO header*/
- com_rslt += bmi160_set_fifo_header_enable(FIFO_HEADER_ENABLE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable the FIFO accel*/
- com_rslt += bmi160_set_fifo_accel_enable(FIFO_ACCEL_ENABLE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Enable the FIFO stop on full*/
- com_rslt += bmi160_set_fifo_stop_on_full(
- FIFO_STOPONFULL_ENABLE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- // /* read the FIFO data*/
- // com_rslt += bmi160_read_fifo_header_data(FIFO_FRAME);
- break;
- case APPLICATION_HEAD_TRACKING:
- /*Set the accel mode as Normal write in the register 0x7E*/
- com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- /*Set the gyro mode as Normal write in the register 0x7E*/
- com_rslt += bmi160_set_command_register(GYRO_MODE_NORMAL);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- /* Set the accel bandwidth as Normal */
- com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_NORMAL_AVG4);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Set the gryo bandwidth as Normal */
- com_rslt += bmi160_set_gyro_bw(BMI160_GYRO_NORMAL_MODE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set gyro data rate as 1600Hz*/
- com_rslt += bmi160_set_gyro_output_data_rate(
- BMI160_GYRO_OUTPUT_DATA_RATE_1600HZ);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set accel data rate as 1600Hz*/
- com_rslt += bmi160_set_accel_output_data_rate(
- BMI160_ACCEL_OUTPUT_DATA_RATE_1600HZ);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* read gyro data*/
- com_rslt += bmi160_read_gyro_xyz(&gyroxyz);
- /* read accel data */
- com_rslt += bmi160_read_accel_xyz(&accelxyz);
- /* read mag data */
- com_rslt += bmi160_bmm150_mag_compensate_xyz(&magxyz);
- break;
- case APPLICATION_NAVIGATION:
- /*Set the accel mode as Normal write in the register 0x7E*/
- com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- /*Set the gyro mode as Normal write in the register 0x7E*/
- com_rslt += bmi160_set_command_register(GYRO_MODE_NORMAL);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- /* Set the accel bandwidth as OSRS4 */
- com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_OSR4_AVG1);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Set the gryo bandwidth as Normal */
- com_rslt += bmi160_set_gyro_bw(BMI160_GYRO_NORMAL_MODE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set gyro data rate as 200Hz*/
- com_rslt += bmi160_set_gyro_output_data_rate(
- BMI160_GYRO_OUTPUT_DATA_RATE_200HZ);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set accel data rate as 200Hz*/
- com_rslt += bmi160_set_accel_output_data_rate(
- BMI160_ACCEL_OUTPUT_DATA_RATE_200HZ);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* read gyro data*/
- com_rslt += bmi160_read_gyro_xyz(&gyroxyz);
- /* read accel data */
- com_rslt += bmi160_read_accel_xyz(&accelxyz);
- /* read mag data*/
- com_rslt += bmi160_bmm150_mag_compensate_xyz(&magxyz);
- break;
- case APPLICATION_REMOTE_CONTROL:
- /*Set the accel mode as Normal write in the register 0x7E*/
- com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- /*Set the gyro mode as Normal write in the register 0x7E*/
- com_rslt += bmi160_set_command_register(GYRO_MODE_NORMAL);
- /* bmi160_delay_ms in ms*/
- s_bmi160.delay_msec(C_BMI160_THIRTY_U8X);
- /* Set the accel bandwidth as OSRS4 */
- com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_OSR4_AVG1);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Set the gryo bandwidth as OSR4 */
- com_rslt += bmi160_set_gyro_bw(BMI160_GYRO_OSR4_MODE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set gyro data rate as 200Hz*/
- com_rslt += bmi160_set_gyro_output_data_rate(
- BMI160_GYRO_OUTPUT_DATA_RATE_200HZ);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set accel data rate as 200Hz*/
- com_rslt += bmi160_set_accel_output_data_rate(
- BMI160_ACCEL_OUTPUT_DATA_RATE_200HZ);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* read gyro data */
- com_rslt += bmi160_read_gyro_xyz(&gyroxyz);
- /* read accel data*/
- com_rslt += bmi160_read_accel_xyz(&accelxyz);
- break;
- case APPLICATION_INDOOR_NAVIGATION:
- /*Set the accel mode as Normal write in the register 0x7E*/
- com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /*Set the gyro mode as Normal write in the register 0x7E*/
- com_rslt += bmi160_set_command_register(GYRO_MODE_NORMAL);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Set the accel bandwidth as OSRS4 */
- com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_OSR4_AVG1);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* Set the gryo bandwidth as OSR4 */
- com_rslt += bmi160_set_gyro_bw(BMI160_GYRO_OSR4_MODE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set gyro data rate as 200Hz*/
- com_rslt += bmi160_set_gyro_output_data_rate(
- BMI160_GYRO_OUTPUT_DATA_RATE_400HZ);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* set accel data rate as 200Hz*/
- com_rslt += bmi160_set_accel_output_data_rate(
- BMI160_ACCEL_OUTPUT_DATA_RATE_400HZ);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);/* bmi160_delay_ms in ms*/
- /* read gyro data*/
- com_rslt += bmi160_read_gyro_xyz(&gyroxyz);
- /* read accel data */
- com_rslt += bmi160_read_accel_xyz(&accelxyz);
- break;
- }
- return com_rslt;
- }
- /*!
- * @brief This function used for interrupt configuration
- *
- *
- * @return results of bus communication function
- * @retval 0 -> Success
- * @retval 1 -> Error
- *
- *
- */
- BMI160_RETURN_FUNCTION_TYPE bmi160_interrupt_configuration(void)
- {
- /* This variable used for provide the communication
- results*/
- BMI160_RETURN_FUNCTION_TYPE com_rslt = ERROR;
- /* Configure the in/out control of interrupt1*/
- com_rslt = bmi160_set_output_enable(C_BMI160_ZERO_U8X,
- BMI160_WRITE_ONE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);
- /* Configure the in/out control of interrupt2*/
- com_rslt += bmi160_set_output_enable(C_BMI160_ONE_U8X,
- BMI160_WRITE_ONE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);
- /* Configure the interrupt1 active high
- 0x00 - Active low
- 0x01 - Active high*/
- com_rslt += bmi160_set_intr_level(C_BMI160_ZERO_U8X,
- BMI160_WRITE_ONE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);
- /* Configure the interrupt2 active high
- 0x00 - Active low
- 0x01 - Active high*/
- com_rslt += bmi160_set_intr_level(C_BMI160_ONE_U8X,
- BMI160_WRITE_ONE);
- s_bmi160.delay_msec(C_BMI160_ONE_U8X);
- return com_rslt;
- }
- #ifdef INCLUDE_BMI160API
- #define MASK_DATA1 0xFF
- #define MASK_DATA2 0x80
- #define MASK_DATA3 0x7F
- /*!
- * @brief Used for SPI initialization
- * @note
- * The following function is used to map the
- * SPI bus read, write and bmi160_delay_ms
- * with global structure bmi160
- */
- s8 spi_routine(void)
- {
- /*--------------------------------------------------------------------------*
- * By using bmi160 the following structure parameter can be accessed
- * Bus write function pointer: BMI160_WR_FUNC_PTR
- * Bus read function pointer: BMI160_RD_FUNC_PTR
- * bmi160_delay_ms function pointer: bmi160_delay_ms_msec
- *--------------------------------------------------------------------------*/
-
- s_bmi160.bus_write = bmi160_spi_bus_write;
- s_bmi160.bus_read = bmi160_spi_bus_read;
- s_bmi160.burst_read = bmi160_spi_burst_read;
- s_bmi160.delay_msec = bmi160_delay_ms;
- return C_BMI160_ZERO_U8X;
- }
- /**************************************************************/
- /**\name I2C/SPI read write function */
- /**************************************************************/
- /*-------------------------------------------------------------------*
- *
- * This is a sample code for read and write the data by using I2C/SPI
- * Use either I2C or SPI based on your need
- * Configure the below code to your SPI or I2C driver
- *
- *-----------------------------------------------------------------------*/
- /*!
- * @brief : The function is used as SPI bus read
- * @return : Status of the SPI read
- * @param dev_addr : The device address of the sensor
- * @param reg_addr : Address of the first register,
- * will data is going to be read
- * @param reg_data : This data read from the sensor,
- * which is hold in an array
- * @param cnt : The no of byte of data to be read
- */
- s8 bmi160_spi_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
- {
- s32 ierror = C_BMI160_ZERO_U8X;
-
- if(SPI_OnlyReadReg(BOARD_SPI0_CS0_IO, reg_addr, reg_data, cnt))
- {
- ierror = -1;
- }
-
- return (s8)ierror;
- }
- /*!
- * @brief : The function is used as SPI bus write
- * @return : Status of the SPI write
- * @param dev_addr : The device address of the sensor
- * @param reg_addr : Address of the first register,
- * will data is going to be written
- * @param reg_data : It is a value hold in the array,
- * will be used for write the value into the register
- * @param cnt : The no of byte of data to be write
- */
- s8 bmi160_spi_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
- {
- s32 ierror = C_BMI160_ZERO_U8X;
-
- if(SPI_OnlyWriteReg(BOARD_SPI0_CS0_IO, reg_addr, reg_data, cnt))
- {
- ierror = -1;
- }
-
- return (s8)ierror;
- }
- //add by lwy
- s8 bmi160_spi_burst_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u32 cnt)
- {
- return -1;
- }
- #endif
- /*!
- * @brief This function is an example for delay
- * @param msek: delay in milli seconds
- * @return : communication result
- */
- void bmi160_delay_ms(u32 msek)
- {
- nrf_delay_ms(msek);
- }
|