Icm20948DataBaseDriver.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * ________________________________________________________________________________________________________
  3. * Copyright © 2014-2015 InvenSense Inc. Portions Copyright © 2014-2015 Movea. All rights reserved.
  4. * This software, related documentation and any modifications thereto (collectively “Software”) is subject
  5. * to InvenSense and its licensors' intellectual property rights under U.S. and international copyright and
  6. * other intellectual property rights laws.
  7. * InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
  8. * and any use, reproduction, disclosure or distribution of the Software without an express license
  9. * agreement from InvenSense is strictly prohibited.
  10. * ________________________________________________________________________________________________________
  11. */
  12. /** @defgroup icm20948_base_driver base_driver
  13. @ingroup SmartSensor_driver
  14. @{
  15. */
  16. #ifndef INV_ICM20948_BASE_DRIVER_H__HWDFWQ__
  17. #define INV_ICM20948_BASE_DRIVER_H__HWDFWQ__
  18. #include "Icm20948Defs.h"
  19. #ifdef __cplusplus
  20. extern "C"
  21. {
  22. #endif
  23. /* forward declaration */
  24. struct inv_icm20948;
  25. // Standard Functions
  26. /** @brief Initializes the platform
  27. * @param[in] type Define the interface for communicate : SERIAL_INTERFACE_I2C or SERIAL_INTERFACE_SPI
  28. * @param[out] dmp_image_sram 4 The image to be load
  29. * @return 0 on success, negative value on error.
  30. */
  31. int INV_EXPORT inv_icm20948_initialize_lower_driver(struct inv_icm20948 * s, enum SMARTSENSOR_SERIAL_INTERFACE type,
  32. const uint8_t *dmp3_image, uint32_t dmp3_image_size);
  33. /** @brief Initializes the compass and the id address
  34. * @param[in] id address of compass component
  35. * @return 0 on success, negative value on error.
  36. */
  37. int INV_EXPORT inv_icm20948_set_slave_compass_id(struct inv_icm20948 * s, int id);
  38. /** @brief Selects the interface of communication with the board
  39. * @param[in] type Define the interface for communicate : SERIAL_INTERFACE_I2C or SERIAL_INTERFACE_SPI
  40. * @return 0 on success, negative value on error.
  41. */
  42. int INV_EXPORT inv_icm20948_set_serial_comm(struct inv_icm20948 * s, enum SMARTSENSOR_SERIAL_INTERFACE type);
  43. /** @brief Wakes up mems platform
  44. * @return 0 on success, negative value on error.
  45. */
  46. int INV_EXPORT inv_icm20948_wakeup_mems(struct inv_icm20948 * s);
  47. /** @brief Sleeps up mems platform
  48. * @return 0 on success, negative value on error.
  49. */
  50. int INV_EXPORT inv_icm20948_sleep_mems(struct inv_icm20948 * s);
  51. /** @brief Sets the power state of the Ivory chip loop
  52. * @param[in] func CHIP_AWAKE, CHIP_LP_ENABLE
  53. * @param[in] on_off The functions are enabled if previously disabled and
  54. * disabled if previously enabled based on the value of On/Off.
  55. * @return 0 on success, negative value on error.
  56. */
  57. int INV_EXPORT inv_icm20948_set_chip_power_state(struct inv_icm20948 * s, unsigned char func, unsigned char on_off);
  58. /** @brief Current wake status of the Mems chip
  59. * @return the wake status
  60. */
  61. uint8_t INV_EXPORT inv_icm20948_get_chip_power_state(struct inv_icm20948 * s);
  62. /** @brief Sets up dmp start address and firmware
  63. * @return 0 on success, negative value on error.
  64. */
  65. int INV_EXPORT inv_icm20948_set_dmp_address(struct inv_icm20948 * s);
  66. /** @brief Sets up the secondary i2c bus
  67. * @return 0 on success, negative value on error.
  68. */
  69. int INV_EXPORT inv_icm20948_set_secondary(struct inv_icm20948 * s);
  70. /** @brief Enables accel and/or gyro and/or pressure if integrated with gyro and accel.
  71. * @param[in] bit_mask A mask where 2 means turn on accel, 1 means turn on gyro, 4 is for pressure.
  72. * By default, this only turns on a sensor if all sensors are off otherwise the DMP controls
  73. * this register including turning off a sensor. To override this behavior add in a mask of 128.
  74. * @return 0 on success, negative value on error.
  75. */
  76. int INV_EXPORT inv_icm20948_enable_hw_sensors(struct inv_icm20948 * s, int bit_mask);
  77. /** @brief Sets the dmp for a particular gyro configuration.
  78. * @param[in] gyro_div Value written to GYRO_SMPLRT_DIV register, where
  79. * 0=1125Hz sample rate, 1=562.5Hz sample rate, ... 4=225Hz sample rate, ...
  80. * 10=102.2727Hz sample rate, ... etc.
  81. * @param[in] gyro_level 0=250 dps, 1=500 dps, 2=1000 dps, 3=2000 dps
  82. * @return 0 on success, negative value on error.
  83. */
  84. int INV_EXPORT inv_icm20948_set_gyro_sf(struct inv_icm20948 * s, unsigned char div, int gyro_level);
  85. /** @brief Sets the gyro sample rate
  86. * @param[in] div Value written to GYRO_SMPLRT_DIV register
  87. * @return 0 on success, negative value on error.
  88. */
  89. int INV_EXPORT inv_icm20948_set_gyro_divider(struct inv_icm20948 * s, unsigned char div);
  90. /** @brief Returns the gyro sample rate
  91. * @return Value written to GYRO_SMPLRT_DIV register.
  92. */
  93. unsigned char INV_EXPORT inv_icm20948_get_gyro_divider(struct inv_icm20948 * s);
  94. /** @brief Returns the real odr in Milliseconds, Micro Seconds or Ticks.
  95. * @param[in] odrInDivider Odr In divider
  96. * @param[in] odr_units Use the enum values: ODR_IN_Ms, ODR_IN_Us or ODR_IN_Ticks
  97. * @return Odr in fucntion of enum.
  98. */
  99. uint32_t INV_EXPORT inv_icm20948_get_odr_in_units(struct inv_icm20948 * s, unsigned short odrInDivider, unsigned char odr_units );
  100. /** @brief Sets the accel sample rate
  101. * @param[in] div Value written to ACCEL_SMPLRT_DIV register
  102. * @return 0 on success, negative value on error.
  103. */
  104. int INV_EXPORT inv_icm20948_set_accel_divider(struct inv_icm20948 * s, short div);
  105. /** @brief Returns the accel sample rate
  106. * @return the divider for the accel
  107. */
  108. short INV_EXPORT inv_icm20948_get_accel_divider(struct inv_icm20948 * s);
  109. /** @brief Sets the I2C secondary device sample rate
  110. * @param[in] div Value written to REG_I2C_MST_ODR_CONFIG register
  111. * @return 0 on success, negative value on error.
  112. */
  113. int INV_EXPORT inv_icm20948_set_secondary_divider(struct inv_icm20948 * s, unsigned char div);
  114. /** @brief Returns the I2C secondary device sample rate
  115. * @return the divider for the I2C secondary device interface
  116. */
  117. unsigned short INV_EXPORT inv_icm20948_get_secondary_divider(struct inv_icm20948 * s);
  118. /** @brief Sets fullscale range of gyro in hardware.
  119. * @param[in] level See mpu_gyro_fs.
  120. * @return 0 on success, negative value on error.
  121. */
  122. int INV_EXPORT inv_icm20948_set_gyro_fullscale(struct inv_icm20948 * s, int level);
  123. /** @brief Returns fullscale range of gyrometer in hardware
  124. * @return the fullscale range
  125. */
  126. uint8_t INV_EXPORT inv_icm20948_get_gyro_fullscale(struct inv_icm20948 * s);
  127. /** @brief Sets fullscale range of gyro in hardware.
  128. * @param[in] level See mpu_gyro_fs.
  129. * @return 0 on success, negative value on error.
  130. */
  131. int INV_EXPORT inv_icm20948_set_icm20948_gyro_fullscale(struct inv_icm20948 * s, int level);
  132. /** @brief Sets fullscale range of accel in hardware.
  133. * @param[in] level See mpu_accel_fs.
  134. * @return 0 on success, negative value on error.
  135. */
  136. int INV_EXPORT inv_icm20948_set_accel_fullscale(struct inv_icm20948 * s, int level);
  137. /** @brief Returns fullscale range of accelerometer in hardware
  138. * @return the fullscale range
  139. */
  140. uint8_t INV_EXPORT inv_icm20948_get_accel_fullscale(struct inv_icm20948 * s);
  141. /** @brief Sets fullscale range of accel in hardware.
  142. * @param[in] level See mpu_accel_fs.
  143. * @return 0 on success, negative value on error.
  144. */
  145. int INV_EXPORT inv_icm20948_set_icm20948_accel_fullscale(struct inv_icm20948 * s, int level);
  146. /** @brief Asserts int1 interrupt when DMP execute INT1 cmd
  147. * @param[in] enable 0=off, 1=on
  148. * @return 0 on success, negative value on error.
  149. */
  150. int INV_EXPORT inv_icm20948_set_int1_assertion(struct inv_icm20948 * s, int enable);
  151. /** @brief Reads accelerometer data stored in hardware register
  152. * @param[in] accel_hw_reg_data variable to be recuperated the accelerometer data
  153. * @return 0 on success, negative value on error.
  154. */
  155. int INV_EXPORT inv_icm20948_accel_read_hw_reg_data(struct inv_icm20948 * s, short accel_hw_reg_data[3]);
  156. /** @brief Prevent LP_EN from being set to 1 again, this speeds up transaction
  157. */
  158. void INV_EXPORT inv_icm20948_prevent_lpen_control(struct inv_icm20948 * s);
  159. /** @brief Allow LP_EN to be set to 1 again and sets it to 1 again if supported by chip
  160. */
  161. void INV_EXPORT inv_icm20948_allow_lpen_control(struct inv_icm20948 * s);
  162. /** @brief Determine if compass could be successfully found and inited on board
  163. * @return 1 on success, 0 if not available.
  164. */
  165. int INV_EXPORT inv_icm20948_get_compass_availability(struct inv_icm20948 * s);
  166. /** @brief Determine if pressure could be successfully found and inited on board
  167. * @return 1 on success, 0 if not available.
  168. */
  169. int INV_EXPORT inv_icm20948_get_pressure_availability(struct inv_icm20948 * s);
  170. /** @brief Determine if proximity could be successfully found and inited on board
  171. * @return 1 on success, 0 if not available.
  172. */
  173. int INV_EXPORT inv_icm20948_get_proximity_availability(struct inv_icm20948 * s);
  174. /** @brief Have the chip to enter stand duty cycled mode, also called low-power mode
  175. * where max reporting frequency is 562Hz
  176. */
  177. int INV_EXPORT inv_icm20948_enter_duty_cycle_mode(struct inv_icm20948 * s);
  178. /** @brief Have the chip to enter low-noise mode
  179. */
  180. int INV_EXPORT inv_icm20948_enter_low_noise_mode(struct inv_icm20948 * s);
  181. #ifdef __cplusplus
  182. }
  183. #endif
  184. #endif // INV_ICM20948_BASE_DRIVER_H__HWDFWQ__
  185. /** @} */