Icm20948.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * ________________________________________________________________________________________________________
  3. * Copyright (c) 2015-2015 InvenSense Inc. All rights reserved.
  4. *
  5. * This software, related documentation and any modifications thereto (collectively “Software”) is subject
  6. * to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
  7. * and other intellectual property rights laws.
  8. *
  9. * InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
  10. * and any use, reproduction, disclosure or distribution of the Software without an express license agreement
  11. * from InvenSense is strictly prohibited.
  12. *
  13. * EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
  14. * PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  15. * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  16. * EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
  17. * INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
  18. * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  19. * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  20. * OF THE SOFTWARE.
  21. * ________________________________________________________________________________________________________
  22. */
  23. /** @defgroup DriverIcm20948 Icm20948 driver
  24. * @brief Low-level driver for ICM20948 devices
  25. * @ingroup Drivers
  26. * @{
  27. */
  28. #ifndef _INV_ICM20948_H_
  29. #define _INV_ICM20948_H_
  30. #include "InvExport.h"
  31. #include "InvBool.h"
  32. #include "InvError.h"
  33. #include "Icm20948Setup.h"
  34. #include "Icm20948Serif.h"
  35. #include "Icm20948Transport.h"
  36. #include "Icm20948DataConverter.h"
  37. #include "Icm20948AuxCompassAkm.h"
  38. #include "Icm20948SelfTest.h"
  39. #include <stdint.h>
  40. #include <assert.h>
  41. #include <string.h>
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. /** @brief States for the secondary device
  46. */
  47. typedef enum inv_icm20948_compass_state
  48. {
  49. INV_ICM20948_COMPASS_RESET = 0,
  50. INV_ICM20948_COMPASS_INITED,
  51. INV_ICM20948_COMPASS_SETUP,
  52. }inv_icm20948_compass_state_t;
  53. /** @brief ICM20948 driver states definition
  54. */
  55. typedef struct sensor_type_icm20948{
  56. uint64_t odr_applied_us;
  57. uint64_t odr_us;
  58. }sensor_type_icm20948_t;
  59. typedef enum {
  60. CHIP_LOW_NOISE_ICM20948,
  61. CHIP_LOW_POWER_ICM20948,
  62. }chip_lp_ln_mode_icm20948_t;
  63. typedef struct inv_icm20948 {
  64. struct inv_icm20948_serif serif;
  65. /** @brief struct for the base_driver : this contains the Mems information */
  66. struct base_driver_t
  67. {
  68. unsigned char wake_state;
  69. chip_lp_ln_mode_icm20948_t chip_lp_ln_mode;
  70. unsigned char pwr_mgmt_1;
  71. unsigned char pwr_mgmt_2;
  72. unsigned char user_ctrl;
  73. unsigned char gyro_div;
  74. unsigned short secondary_div;
  75. short accel_div;
  76. unsigned char gyro_averaging;
  77. unsigned char accel_averaging;
  78. uint8_t gyro_fullscale;
  79. uint8_t accel_fullscale;
  80. uint8_t lp_en_support:1;
  81. uint8_t firmware_loaded:1;
  82. uint8_t serial_interface;
  83. uint8_t timebase_correction_pll;
  84. }base_state;
  85. /* secondary device support */
  86. struct inv_icm20948_secondary_states {
  87. struct inv_icm20948_secondary_reg {
  88. uint16_t addr;
  89. uint16_t reg;
  90. uint16_t ctrl;
  91. uint16_t d0;
  92. } slv_reg[4];
  93. unsigned char sSavedI2cOdr;
  94. /* compass support */
  95. uint8_t compass_sens[3];
  96. long final_matrix[9];
  97. const int16_t *st_upper;
  98. const int16_t *st_lower;
  99. int scale;
  100. uint8_t dmp_on;
  101. uint8_t secondary_resume_compass_state;
  102. uint8_t mode_reg_addr;
  103. int compass_chip_addr;
  104. int compass_slave_id;
  105. inv_icm20948_compass_state_t compass_state;
  106. } secondary_state;
  107. /* self test */
  108. uint8_t selftest_done;
  109. uint8_t offset_done;
  110. uint8_t gyro_st_data[3];
  111. uint8_t accel_st_data[3];
  112. /* mpu fifo control */
  113. struct fifo_info_t
  114. {
  115. int fifoError;
  116. unsigned char fifo_overflow;
  117. } fifo_info;
  118. /* interface mapping */
  119. unsigned long sStepCounterToBeSubtracted;
  120. unsigned long sOldSteps;
  121. /* data converter */
  122. long s_quat_chip_to_body[4];
  123. /* base driver */
  124. uint8_t sAllowLpEn;
  125. uint8_t s_compass_available;
  126. uint8_t s_proximity_available;
  127. /* base sensor ctrl*/
  128. unsigned short inv_dmp_odr_dividers[37];//INV_SENSOR_NUM_MAX /!\ if the size change
  129. unsigned short inv_dmp_odr_delays[37];//INV_SENSOR_NUM_MAX /!\ if the size change
  130. unsigned short bac_on; // indicates if ANDROID_SENSOR_ACTIVITY_CLASSIFICATON is on
  131. unsigned short pickup;
  132. unsigned short bac_status;
  133. unsigned short b2s_status;
  134. unsigned short flip_pickup_status;
  135. unsigned short inv_sensor_control;
  136. unsigned short inv_sensor_control2;
  137. unsigned long inv_androidSensorsOn_mask[2] ;// Each bit corresponds to a sensor being on
  138. unsigned short inv_androidSensorsOdr_boundaries[51][2];//GENERAL_SENSORS_MAX /!\ if the size change
  139. unsigned char sGmrvIsOn; // indicates if GMRV was requested to be ON by end-user. Once this variable is set, it is either GRV or GMRV which is enabled internally
  140. unsigned short lLastHwSmplrtDividerAcc;
  141. unsigned short lLastHwSmplrtDividerGyr;
  142. unsigned char sBatchMode;
  143. uint8_t header2_count;
  144. char mems_put_to_sleep;
  145. unsigned short smd_status;
  146. unsigned short ped_int_status;
  147. unsigned short bac_request;
  148. uint8_t go_back_lp_when_odr_low; // set to 1 when we forced a switch from LP to LN mode to be able to reach 1kHz ODR, so we will need to go back to LP mode ASAP
  149. unsigned short odr_acc_ms; // ODR in ms requested for ANDROID_SENSOR_ACCELEROMETER
  150. //unsigned short odr_acc_wom_ms; // ODR in ms requested for ANDROID_SENSOR_WOM when using ACC
  151. unsigned short odr_racc_ms; // ODR in ms requested for ANDROID_SENSOR_RAW_ACCELEROMETER
  152. unsigned short odr_gyr_ms; // ODR in ms requested for ANDROID_SENSOR_GYROSCOPE_UNCALIBRATED
  153. unsigned short odr_rgyr_ms; // ODR in ms requested for ANDROID_SENSOR_RAW_GYROSCOPE
  154. int bias[9];// dmp bias [0-2]:acc,[3-5]:gyr,[6-8]:mag
  155. /* Icm20948Fifo usage */
  156. signed char mounting_matrix[9];
  157. signed char mounting_matrix_secondary_compass[9];
  158. long soft_iron_matrix[9];
  159. uint8_t skip_sample[INV_ICM20948_SENSOR_MAX+1];
  160. uint64_t timestamp[INV_ICM20948_SENSOR_MAX+1];
  161. uint8_t sFirstBatch[INV_ICM20948_SENSOR_MAX+1];
  162. sensor_type_icm20948_t sensorlist[INV_ICM20948_SENSOR_MAX+1];
  163. unsigned short saved_count;
  164. /* Icm20948Transport*/
  165. unsigned char reg;
  166. unsigned char lastBank;
  167. unsigned char lLastBankSelected;
  168. /* augmented sensors*/
  169. unsigned short sGravityOdrMs;
  170. unsigned short sGrvOdrMs;
  171. unsigned short sLinAccOdrMs;
  172. unsigned short sGravityWuOdrMs;
  173. unsigned short sGrvWuOdrMs;
  174. unsigned short sLinAccWuOdrMs;
  175. unsigned short sRvOdrMs;
  176. unsigned short sOriOdrMs;
  177. unsigned short sRvWuOdrMs;
  178. unsigned short sOriWuOdrMs;
  179. /* Icm20649Setup */
  180. short set_accuracy;
  181. int new_accuracy;
  182. } inv_icm20948_t;
  183. /** @brief ICM20948 driver states singleton declaration
  184. * Because of Low-level driver limitation only one insance of the driver is allowed
  185. */
  186. extern struct inv_icm20948 * icm20948_instance;
  187. /** @brief Hook for low-level system sleep() function to be implemented by upper layer
  188. * @param[in] ms number of millisecond the calling thread should sleep
  189. */
  190. extern void inv_icm20948_sleep_us(int us);
  191. extern void inv_icm20948_sleep(int ms);
  192. /** @brief Hook for low-level system time() function to be implemented by upper layer
  193. * @return monotonic timestamp in us
  194. */
  195. extern uint64_t inv_icm20948_get_time_us(void);
  196. /** @brief Reset and initialize driver states
  197. * @param[in] s handle to driver states structure
  198. */
  199. static inline void inv_icm20948_reset_states(struct inv_icm20948 * s,
  200. const struct inv_icm20948_serif * serif)
  201. {
  202. assert(icm20948_instance == 0);
  203. memset(s, 0, sizeof(*s));
  204. s->serif = *serif;
  205. icm20948_instance = s;
  206. }
  207. #ifdef __cplusplus
  208. }
  209. #endif
  210. #endif /* _INV_ICM20948_H_ */
  211. /** @} */