bmi160_support.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. *
  3. ****************************************************************************
  4. * Copyright (C) 2014 Bosch Sensortec GmbH
  5. *
  6. * File : bmi160_support.h
  7. *
  8. * Date : 2014/12/12
  9. *
  10. * Revision : 1.0.5 $
  11. *
  12. * Usage: Sensor Driver support file for BMI160 sensor
  13. *
  14. ****************************************************************************
  15. *
  16. * \section License
  17. *
  18. * Redistribution and use in source and binary forms, with or without
  19. * modification, are permitted provided that the following conditions are met:
  20. *
  21. * Redistributions of source code must retain the above copyright
  22. * notice, this list of conditions and the following disclaimer.
  23. *
  24. * Redistributions in binary form must reproduce the above copyright
  25. * notice, this list of conditions and the following disclaimer in the
  26. * documentation and/or other materials provided with the distribution.
  27. *
  28. * Neither the name of the copyright holder nor the names of the
  29. * contributors may be used to endorse or promote products derived from
  30. * this software without specific prior written permission.
  31. *
  32. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  33. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  34. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  35. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  36. * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
  37. * OR CONTRIBUTORS BE LIABLE FOR ANY
  38. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  39. * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
  40. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  41. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  42. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  43. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  45. * ANY WAY OUT OF THE USE OF THIS
  46. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  47. *
  48. * The information provided is believed to be accurate and reliable.
  49. * The copyright holder assumes no responsibility
  50. * for the consequences of use
  51. * of such information nor for any infringement of patents or
  52. * other rights of third parties which may result from its use.
  53. * No license is granted by implication or otherwise under any patent or
  54. * patent rights of the copyright holder.
  55. **************************************************************************/
  56. /*! \file bmi160_support.h
  57. \brief BMI160 Sensor Driver Support Header File */
  58. /* user defined code to be added here ... */
  59. #ifndef __BMI160_SUPPORT_H__
  60. #define __BMI160_SUPPORT_H__
  61. #include "bmi160.h"
  62. #include "bsp_spi.h"
  63. #include "nrf_delay.h"
  64. #ifndef INCLUDE_BMI160API
  65. #define INCLUDE_BMI160API
  66. #endif
  67. #define SPI_BUFFER_LEN 260
  68. #define BMI160_WRITE_FOUR 0x04
  69. #define BMI160_WRITE_TWO 0x02
  70. #define BMI160_WRITE_ZERO 0x00
  71. #define BMI160_WRITE_ONE 0x01
  72. /*!
  73. * @brief struct used for assign the value for
  74. * gyro sleep configuration
  75. */
  76. struct gyro_sleep_setting {
  77. u8 sleep_trigger;/**< gyro sleep trigger configuration*/
  78. u8 wakeup_trigger;/**< gyro wakeup trigger configuration*/
  79. u8 sleep_state;/**< gyro sleep state configuration*/
  80. u8 wakeup_int;/**< gyro wakeup interrupt configuration*/
  81. };
  82. /********************************/
  83. /**\name POWE MODES DEFINITION */
  84. /*******************************/
  85. #define ACCEL_MODE_NORMAL 0x11
  86. #define GYRO_MODE_NORMAL 0x15
  87. #define ACCEL_LOWPOWER 0X12
  88. #define MAG_SUSPEND_MODE 1
  89. #define C_BMI160_THIRTY_U8X 30
  90. /********************************/
  91. /**\name RETURN TYPE */
  92. /*******************************/
  93. /* return type of communication routine*/
  94. #define BMI160_RETURN_FUNCTION_TYPE s8
  95. /********************************/
  96. /**\name RUNNING MODE DEFINITIONS */
  97. /*******************************/
  98. #define STANDARD_UI_9DOF_FIFO 0
  99. #define STANDARD_UI_IMU_FIFO 1
  100. #define STANDARD_UI_IMU 2
  101. #define STANDARD_UI_ADVANCEPOWERSAVE 3
  102. #define ACCEL_PEDOMETER 4
  103. #define ACCEL_PEDOMETER_FIFO 5
  104. #define APPLICATION_HEAD_TRACKING 6
  105. #define APPLICATION_NAVIGATION 7
  106. #define APPLICATION_REMOTE_CONTROL 8
  107. #define APPLICATION_INDOOR_NAVIGATION 9
  108. #define ALL_SUSPEND 10
  109. /********************************/
  110. /**\name MAG INTERFACE */
  111. /*******************************/
  112. #define BMI160_MAG_INTERFACE_OFF_PRIMARY_ON 0x00
  113. #define BMI160_MAG_INTERFACE_ON_PRIMARY_ON 0x02
  114. /*!
  115. * @brief This function used for initialize the sensor
  116. *
  117. *
  118. * @return results of bus communication function
  119. * @retval 0 -> Success
  120. * @retval 1 -> Error
  121. *
  122. *
  123. */
  124. BMI160_RETURN_FUNCTION_TYPE bmi160_initialize_sensor(u8 v_running_mode_u8);
  125. /*!
  126. * @brief This Function used to read the sensor data using
  127. * different running mode
  128. * @param v_running_mode_u8 : The value of running mode
  129. * Description | value
  130. * --------------------------------|----------
  131. * STANDARD_UI_9DOF_FIFO | 0
  132. * STANDARD_UI_IMU_FIFO | 1
  133. * STANDARD_UI_IMU | 2
  134. * STANDARD_UI_ADVANCEPOWERSAVE | 3
  135. * ACCEL_PEDOMETER | 4
  136. * APPLICATION_HEAD_TRACKING | 5
  137. * APPLICATION_NAVIGATION | 6
  138. * APPLICATION_REMOTE_CONTROL | 7
  139. * APPLICATION_INDOOR_NAVIGATION | 8
  140. *
  141. *
  142. * @return results of bus communication function
  143. * @retval 0 -> Success
  144. * @retval 1 -> Error
  145. *
  146. *
  147. */
  148. BMI160_RETURN_FUNCTION_TYPE bmi160_config_running_mode(u8 v_running_mode_u8);
  149. /*!
  150. * @brief This function used for interrupt configuration
  151. *
  152. *
  153. * @return results of bus communication function
  154. * @retval 0 -> Success
  155. * @retval 1 -> Error
  156. *
  157. *
  158. */
  159. BMI160_RETURN_FUNCTION_TYPE bmi160_interrupt_configuration(void);
  160. /*!
  161. * @brief This function is an example for delay
  162. * @param msek: delay in milli seconds
  163. * @return : communication result
  164. */
  165. void bmi160_delay_ms(u32 msek);
  166. #ifdef INCLUDE_BMI160API
  167. /*!
  168. * @brief Used for SPI initialization
  169. */
  170. s8 spi_routine(void);
  171. /*!
  172. * @brief : The function is used as SPI bus read
  173. * @return : Status of the SPI read
  174. * @param dev_addr : The device address of the sensor
  175. * @param reg_addr : Address of the first register,
  176. * will data is going to be read
  177. * @param reg_data : This data read from the sensor,
  178. * which is hold in an array
  179. * @param cnt : The no of byte of data to be read
  180. */
  181. s8 bmi160_spi_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt);
  182. /*!
  183. * @brief : The function is used as SPI bus write
  184. * @return : Status of the SPI write
  185. * @param dev_addr : The device address of the sensor
  186. * @param reg_addr : Address of the first register,
  187. * will data is going to be written
  188. * @param reg_data : It is a value hold in the array,
  189. * will be used for write the value into the register
  190. * @param cnt : The no of byte of data to be write
  191. */
  192. s8 bmi160_spi_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt);
  193. //add by lwy
  194. s8 bmi160_spi_burst_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u32 cnt);
  195. #endif
  196. #endif