Icm20948DataBaseControl.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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_control base_control
  13. @ingroup SmartSensor_driver
  14. @{
  15. */
  16. #ifndef INV_ICM20948_BASE_CONTROL_H__HWDFWQ__
  17. #define INV_ICM20948_BASE_CONTROL_H__HWDFWQ__
  18. #include "Icm20948DataBaseDriver.h"
  19. #include "Icm20948Defs.h"
  20. #ifdef __cplusplus
  21. extern "C"
  22. {
  23. #endif
  24. /* forward declaration */
  25. struct inv_icm20948;
  26. /** @brief Define the Hardware engine*/
  27. enum INV_HW_ENGINE {
  28. HW_ENGINE_GYRO = 0,
  29. HW_ENGINE_ACCEL,
  30. HW_ENGINE_CPASS,
  31. HW_ENGINE_PRESSURE,
  32. HW_ENGINE_LIGHT,
  33. HW_ENGINE_TEMPERATURE,
  34. HW_ENGINE_HUMIDITY,
  35. HW_ENGINE_NUM_MAX,
  36. };
  37. #define INV_ODR_MIN_DELAY 200 // Limited by 8-bit HW Gyro rate divider register "GYRO_SMPLRT_DIV"
  38. #define INV_ODR_DEFAULT_BAC 18 // Default odr for sensor related to BAC algorithm which should run to 56Hz
  39. #define INV_ODR_DEFAULT_B2S 18 // Default odr for sensor related to B2S algorithm which should run to 56Hz
  40. #define INV_MIN_ODR 5
  41. #define INV_MAX_ODR 1000
  42. #define INV_MIN_ODR_CPASS 14
  43. #define INV_MAX_ODR_CPASS 1000
  44. #define INV_MIN_ODR_GRV 5
  45. #define INV_MAX_ODR_GRV 20
  46. // Determines which base sensor needs to be on based upon inv_androidSensorsOn_mask[0]
  47. #define INV_NEEDS_ACCEL_MASK ((1L<<1)| (1L<<3)| (1L<<9)|(1L<<10)|(1L<<11)| (1L<<15)| (1L<<17)|(1L<<18)|(1L<<19)|(1L<<20)|(1<<23)| (1<<25)| (1<<29)|(1<<30)|(1<<31))
  48. #define INV_NEEDS_GYRO_MASK ( (1L<<3)|(1L<<4)|(1L<<9)|(1L<<10)|(1L<<11)| (1L<<15)|(1L<<16)| (1<<25)|(1<<26)|(1<<29)|(1<<30)|(1<<31))
  49. #define INV_NEEDS_COMPASS_MASK ( (1L<<2)|(1L<<3)| (1L<<11)|(1L<<14)| (1L<<20)| (1<<24)|(1<<25)| (1<<31))
  50. #define INV_NEEDS_PRESSURE ((1L<<6)|(1<<28))
  51. // Determines which base sensor needs to be on based upon inv_androidSensorsOn_mask[1]
  52. #define INV_NEEDS_ACCEL_MASK1 ( (1<<3)| (1<<5)|(1<<6)|(1<<7)|(1<<9)|(1<<10))
  53. #define INV_NEEDS_GYRO_MASK1 ( (1<<3)|(1<<4) |(1<<11))
  54. #define INV_NEEDS_COMPASS_MASK1 ((1<<2)| (1<<7))
  55. #define GYRO_AVAILABLE 0x1
  56. #define ACCEL_AVAILABLE 0x2
  57. #define SECONDARY_COMPASS_AVAILABLE 0x8
  58. // data output control reg 1
  59. #define ACCEL_SET 0x8000
  60. #define GYRO_SET 0x4000
  61. #define CPASS_SET 0x2000
  62. #define ALS_SET 0x1000
  63. #define QUAT6_SET 0x0800
  64. #define QUAT9_SET 0x0400
  65. #define PQUAT6_SET 0x0200
  66. #define GEOMAG_SET 0x0100
  67. #define PRESSURE_SET 0x0080
  68. #define GYRO_CALIBR_SET 0x0040
  69. #define CPASS_CALIBR_SET 0x0020
  70. #define PED_STEPDET_SET 0x0010
  71. #define HEADER2_SET 0x0008
  72. #define PED_STEPIND_SET 0x0007
  73. // data output control reg 2
  74. #define ACCEL_ACCURACY_SET 0x4000
  75. #define GYRO_ACCURACY_SET 0x2000
  76. #define CPASS_ACCURACY_SET 0x1000
  77. #define COMPASS_CAL_INPUT_SET 0x1000
  78. #define FLIP_PICKUP_SET 0x0400
  79. #define ACT_RECOG_SET 0x0080
  80. #define BATCH_MODE_EN 0x0100
  81. // motion event control reg
  82. #define INV_BAC_WEARABLE_EN 0x8000
  83. #define INV_PEDOMETER_EN 0x4000
  84. #define INV_PEDOMETER_INT_EN 0x2000
  85. #define INV_SMD_EN 0x0800
  86. #define INV_BTS_EN 0x0020
  87. #define FLIP_PICKUP_EN 0x0010
  88. #define GEOMAG_EN 0x0008
  89. #define INV_ACCEL_CAL_EN 0x0200
  90. #define INV_GYRO_CAL_EN 0x0100
  91. #define INV_COMPASS_CAL_EN 0x0080
  92. #define INV_NINE_AXIS_EN 0x0040
  93. #define INV_BRING_AND_LOOK_T0_SEE_EN 0x0004 // Aded by ONn for 20648
  94. // data packet size reg 1
  95. #define HEADER_SZ 2
  96. #define ACCEL_DATA_SZ 6
  97. #define GYRO_DATA_SZ 6
  98. #define CPASS_DATA_SZ 6
  99. #define ALS_DATA_SZ 8
  100. #define QUAT6_DATA_SZ 12
  101. #define QUAT9_DATA_SZ 14
  102. #define PQUAT6_DATA_SZ 6
  103. #define GEOMAG_DATA_SZ 14
  104. #define PRESSURE_DATA_SZ 6
  105. #define GYRO_BIAS_DATA_SZ 6
  106. #define CPASS_CALIBR_DATA_SZ 12
  107. #define PED_STEPDET_TIMESTAMP_SZ 4
  108. #define FOOTER_SZ 2
  109. // data packet size reg 2
  110. #define HEADER2_SZ 2
  111. #define ACCEL_ACCURACY_SZ 2
  112. #define GYRO_ACCURACY_SZ 2
  113. #define CPASS_ACCURACY_SZ 2
  114. #define FSYNC_SZ 2
  115. #define FLIP_PICKUP_SZ 2
  116. #define ACT_RECOG_SZ 6
  117. #define ODR_CNT_GYRO_SZ 2
  118. /** @brief Initialize structure values
  119. * @param[in] base state structre
  120. */
  121. int INV_EXPORT inv_icm20948_base_control_init(struct inv_icm20948 * s);
  122. /** @brief Sets the odr for a sensor
  123. * @param[in] androidSensor Sensor Identity
  124. * @param[in] delayInMs the delay between two values in ms
  125. * @return 0 in case of success, -1 for any error
  126. */
  127. int INV_EXPORT inv_icm20948_set_odr(struct inv_icm20948 * s, unsigned char androidSensor, unsigned short delayInMs);
  128. /** @brief Enables / disables a sensor
  129. * @param[in] androidSensor Sensor Identity
  130. * @param[in] enable 0=off, 1=on
  131. * @return 0 in case of success, -1 for any error
  132. */
  133. int INV_EXPORT inv_icm20948_ctrl_enable_sensor(struct inv_icm20948 * s, unsigned char androidSensor, unsigned char enable);
  134. /** @brief Enables / disables batch for the sensors
  135. * @param[in] enable 0=off, 1=on
  136. * @return 0 in case of success, -1 for any error
  137. */
  138. int INV_EXPORT inv_icm20948_ctrl_enable_batch(struct inv_icm20948 * s, unsigned char enable);
  139. /** @brief Set batch mode status
  140. * @param[in] enable 0=off, 1=on
  141. */
  142. void INV_EXPORT inv_icm20948_ctrl_set_batch_mode_status(struct inv_icm20948 * s, unsigned char enable);
  143. /** @brief Get batch mode status
  144. * @return 0=batch mode disable, 1=batch mode enable
  145. */
  146. unsigned char INV_EXPORT inv_icm20948_ctrl_get_batch_mode_status(struct inv_icm20948 * s);
  147. /** @brief Sets the timeout for the batch in second
  148. * @param[in] batch_time_in_seconds time in second
  149. * @return 0 in case of success, -1 for any error
  150. */
  151. int INV_EXPORT inv_icm20948_ctrl_set_batch_timeout(struct inv_icm20948 * s, unsigned short batch_time_in_seconds);
  152. /** @brief Sets the timeout for the batch in millisecond
  153. * @param[in] batch_time_in_ms time in millisecond
  154. * @return 0 in case of success, -1 for any error
  155. */
  156. int INV_EXPORT inv_icm20948_ctrl_set_batch_timeout_ms(struct inv_icm20948 * s, unsigned short batch_time_in_ms);
  157. /** @brief Enables / disables BAC
  158. * @param[in] enable 0=off, 1=on
  159. */
  160. void INV_EXPORT inv_icm20948_ctrl_enable_activity_classifier(struct inv_icm20948 * s, unsigned char enable);
  161. /** @brief Enables / disables tilt
  162. * @param[in] enable 0=off, 1=on
  163. */
  164. void INV_EXPORT inv_icm20948_ctrl_enable_tilt(struct inv_icm20948 * s, unsigned char enable);
  165. /** @brief Enables / disables bring to see
  166. * @param[in] enable 0=off, 1=on
  167. */
  168. void INV_EXPORT inv_icm20948_ctrl_enable_b2s(unsigned char enable);
  169. /** @brief Returns the mask for the different sensors enabled
  170. * @return the mask
  171. */
  172. unsigned long INV_EXPORT *inv_icm20948_ctrl_get_androidSensorsOn_mask(struct inv_icm20948 * s);
  173. /** @brief Check if a sensor is enabled
  174. * @return 1 if sensor is enabled
  175. */
  176. unsigned long INV_EXPORT inv_icm20948_ctrl_androidSensor_enabled(struct inv_icm20948 * s, unsigned char androidSensor);
  177. /** @brief Returns a flag to know if the BAC is running
  178. * @return 1 if started, 0 if stopped
  179. */
  180. unsigned short INV_EXPORT inv_icm20948_ctrl_get_activitiy_classifier_on_flag(struct inv_icm20948 * s);
  181. /** @brief Enumeration for the Type of ODR : Millisecondes / Microsecondes / Ticks */
  182. enum INV_ODR_TYPE {
  183. ODR_IN_Ms,
  184. ODR_IN_Us,
  185. ODR_IN_Ticks
  186. };
  187. /** @brief Gets the odr for a sensor
  188. * @param[in] SensorId Sensor Identity
  189. * @param[out] odr pointer to the ODR for this sensor
  190. * @param[in] odr_units unit expected for odr, one of INV_ODR_TYPE
  191. * @return 0 in case of success, -1 for any error
  192. */
  193. int INV_EXPORT inv_icm20948_ctrl_get_odr(struct inv_icm20948 * s, unsigned char SensorId, uint32_t *odr, enum INV_ODR_TYPE odr_units);
  194. /** @brief Sets accel quaternion gain according to accel engine rate.
  195. * @param[in] hw_smplrt_divider hardware sample rate divider such that accel engine rate = 1125Hz/hw_smplrt_divider
  196. * @return 0 in case of success, -1 for any error
  197. */
  198. int INV_EXPORT inv_icm20948_ctrl_set_accel_quaternion_gain(struct inv_icm20948 * s, unsigned short hw_smplrt_divider);
  199. /** @brief Sets accel cal parameters according to accel engine rate.
  200. * @param[in] hw_smplrt_divider hardware sample rate divider such that accel engine rate = 1125Hz/hw_smplrt_divider
  201. * @return 0 in case of success, -1 for any error
  202. */
  203. int INV_EXPORT inv_icm20948_ctrl_set_accel_cal_params(struct inv_icm20948 * s, unsigned short hw_smplrt_divider);
  204. /** @brief Enables / disables pickup gesture
  205. * @param(in) enable: 1 for enable, 0 for disable
  206. * @return 0 in case of success, -1 for any error
  207. */
  208. int INV_EXPORT inv_icm20948_ctrl_enable_pickup(struct inv_icm20948 * s, unsigned char enable);
  209. /** @brief get acc bias from dmp driver
  210. * @param(in/out) acc_bias: tab of 3 int value
  211. * @return 0 in case of success, -1 for any error
  212. */
  213. int inv_icm20948_ctrl_get_acc_bias(struct inv_icm20948 * s, int * acc_bias);
  214. /** @brief get gyr bias from dmp driver
  215. * @param(in/out) gyr_bias: tab of 3 int value
  216. * @return 0 in case of success, -1 for any error
  217. */
  218. int inv_icm20948_ctrl_get_gyr_bias(struct inv_icm20948 * s, int * gyr_bias);
  219. /** @brief get mag bias from dmp driver
  220. * @param(in/out) mag_bias: tab of 3 int value
  221. * @return 0 in case of success, -1 for any error
  222. */
  223. int INV_EXPORT inv_icm20948_ctrl_get_mag_bias(struct inv_icm20948 * s, int * mag_bias);
  224. /** @brief set acc bias from dmp driver
  225. * @param(in/out) acc_bias: tab of 3 int value
  226. * @return 0 in case of success, -1 for any error
  227. */
  228. int inv_icm20948_ctrl_set_acc_bias(struct inv_icm20948 * s, int * acc_bias);
  229. /** @brief set gyr bias from dmp driver
  230. * @param(in/out) gyr_bias: tab of 3 int value
  231. * @return 0 in case of success, -1 for any error
  232. */
  233. int inv_icm20948_ctrl_set_gyr_bias(struct inv_icm20948 * s, int * gyr_bias);
  234. /** @brief set mag bias from dmp driver
  235. * @param(in/out) mag_bias: tab of 3 int value
  236. * @return 0 in case of success, -1 for any error
  237. */
  238. int INV_EXPORT inv_icm20948_ctrl_set_mag_bias(struct inv_icm20948 * s, int * mag_bias);
  239. #ifdef __cplusplus
  240. }
  241. #endif
  242. #endif // INV_ICM20948_BASE_CONTROL_H__HWDFWQ__
  243. /** @} */