inv_mpu_dmp_motion_driver.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371
  1. /*
  2. $License:
  3. Copyright (C) 2011-2012 InvenSense Corporation, All Rights Reserved.
  4. See included License.txt for License information.
  5. $
  6. */
  7. /**
  8. * @addtogroup DRIVERS Sensor Driver Layer
  9. * @brief Hardware drivers to communicate with sensors via I2C.
  10. *
  11. * @{
  12. * @file inv_mpu_dmp_motion_driver.c
  13. * @brief DMP image and interface functions.
  14. * @details All functions are preceded by the dmp_ prefix to
  15. * differentiate among MPL and general driver function calls.
  16. */
  17. #include <stdio.h>
  18. #include <stdint.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <math.h>
  22. #include "inv_mpu.h"
  23. #include "inv_mpu_dmp_motion_driver.h"
  24. #include "dmpKey.h"
  25. #include "dmpmap.h"
  26. /* The following functions must be defined for this platform:
  27. * i2c_write(unsigned char slave_addr, unsigned char reg_addr,
  28. * unsigned char length, unsigned char const *data)
  29. * i2c_read(unsigned char slave_addr, unsigned char reg_addr,
  30. * unsigned char length, unsigned char *data)
  31. * delay_ms(unsigned long num_ms)
  32. * get_ms(unsigned long *count)
  33. */
  34. #if defined MOTION_DRIVER_TARGET_MSP430
  35. //#include "msp430.h" /* 注释MSP430包含的头文件 */
  36. //#include "msp430_clock.h"
  37. #include "cmsis_os.h" /* 包含相关头文件 */
  38. #define delay_ms osDelay /* 毫秒级延时函数 */
  39. #define get_ms atk_ms6050_get_clock_ms /* 获取毫秒级时间戳函数 */
  40. #define log_i(...) do {} while (0) /* 打印LOG普通信息 */
  41. #define log_e(...) do {} while (0) /* 打印LOG错误信息 */
  42. #elif defined EMPL_TARGET_MSP430
  43. #include "msp430.h"
  44. #include "msp430_clock.h"
  45. #include "log.h"
  46. #define delay_ms msp430_delay_ms
  47. #define get_ms msp430_get_clock_ms
  48. #define log_i MPL_LOGI
  49. #define log_e MPL_LOGE
  50. #elif defined EMPL_TARGET_UC3L0
  51. /* Instead of using the standard TWI driver from the ASF library, we're using
  52. * a TWI driver that follows the slave address + register address convention.
  53. */
  54. #include "delay.h"
  55. #include "sysclk.h"
  56. #include "log.h"
  57. #include "uc3l0_clock.h"
  58. /* delay_ms is a function already defined in ASF. */
  59. #define get_ms uc3l0_get_clock_ms
  60. #define log_i MPL_LOGI
  61. #define log_e MPL_LOGE
  62. #else
  63. #error Gyro driver is missing the system layer implementations.
  64. #endif
  65. /* These defines are copied from dmpDefaultMPU6050.c in the general MPL
  66. * releases. These defines may change for each DMP image, so be sure to modify
  67. * these values when switching to a new image.
  68. */
  69. #define CFG_LP_QUAT (2712)
  70. #define END_ORIENT_TEMP (1866)
  71. #define CFG_27 (2742)
  72. #define CFG_20 (2224)
  73. #define CFG_23 (2745)
  74. #define CFG_FIFO_ON_EVENT (2690)
  75. #define END_PREDICTION_UPDATE (1761)
  76. #define CGNOTICE_INTR (2620)
  77. #define X_GRT_Y_TMP (1358)
  78. #define CFG_DR_INT (1029)
  79. #define CFG_AUTH (1035)
  80. #define UPDATE_PROP_ROT (1835)
  81. #define END_COMPARE_Y_X_TMP2 (1455)
  82. #define SKIP_X_GRT_Y_TMP (1359)
  83. #define SKIP_END_COMPARE (1435)
  84. #define FCFG_3 (1088)
  85. #define FCFG_2 (1066)
  86. #define FCFG_1 (1062)
  87. #define END_COMPARE_Y_X_TMP3 (1434)
  88. #define FCFG_7 (1073)
  89. #define FCFG_6 (1106)
  90. #define FLAT_STATE_END (1713)
  91. #define SWING_END_4 (1616)
  92. #define SWING_END_2 (1565)
  93. #define SWING_END_3 (1587)
  94. #define SWING_END_1 (1550)
  95. #define CFG_8 (2718)
  96. #define CFG_15 (2727)
  97. #define CFG_16 (2746)
  98. #define CFG_EXT_GYRO_BIAS (1189)
  99. #define END_COMPARE_Y_X_TMP (1407)
  100. #define DO_NOT_UPDATE_PROP_ROT (1839)
  101. #define CFG_7 (1205)
  102. #define FLAT_STATE_END_TEMP (1683)
  103. #define END_COMPARE_Y_X (1484)
  104. #define SKIP_SWING_END_1 (1551)
  105. #define SKIP_SWING_END_3 (1588)
  106. #define SKIP_SWING_END_2 (1566)
  107. #define TILTG75_START (1672)
  108. #define CFG_6 (2753)
  109. #define TILTL75_END (1669)
  110. #define END_ORIENT (1884)
  111. #define CFG_FLICK_IN (2573)
  112. #define TILTL75_START (1643)
  113. #define CFG_MOTION_BIAS (1208)
  114. #define X_GRT_Y (1408)
  115. #define TEMPLABEL (2324)
  116. #define CFG_ANDROID_ORIENT_INT (1853)
  117. #define CFG_GYRO_RAW_DATA (2722)
  118. #define X_GRT_Y_TMP2 (1379)
  119. #define D_0_22 (22+512)
  120. #define D_0_24 (24+512)
  121. #define D_0_36 (36)
  122. #define D_0_52 (52)
  123. #define D_0_96 (96)
  124. #define D_0_104 (104)
  125. #define D_0_108 (108)
  126. #define D_0_163 (163)
  127. #define D_0_188 (188)
  128. #define D_0_192 (192)
  129. #define D_0_224 (224)
  130. #define D_0_228 (228)
  131. #define D_0_232 (232)
  132. #define D_0_236 (236)
  133. #define D_1_2 (256 + 2)
  134. #define D_1_4 (256 + 4)
  135. #define D_1_8 (256 + 8)
  136. #define D_1_10 (256 + 10)
  137. #define D_1_24 (256 + 24)
  138. #define D_1_28 (256 + 28)
  139. #define D_1_36 (256 + 36)
  140. #define D_1_40 (256 + 40)
  141. #define D_1_44 (256 + 44)
  142. #define D_1_72 (256 + 72)
  143. #define D_1_74 (256 + 74)
  144. #define D_1_79 (256 + 79)
  145. #define D_1_88 (256 + 88)
  146. #define D_1_90 (256 + 90)
  147. #define D_1_92 (256 + 92)
  148. #define D_1_96 (256 + 96)
  149. #define D_1_98 (256 + 98)
  150. #define D_1_106 (256 + 106)
  151. #define D_1_108 (256 + 108)
  152. #define D_1_112 (256 + 112)
  153. #define D_1_128 (256 + 144)
  154. #define D_1_152 (256 + 12)
  155. #define D_1_160 (256 + 160)
  156. #define D_1_176 (256 + 176)
  157. #define D_1_178 (256 + 178)
  158. #define D_1_218 (256 + 218)
  159. #define D_1_232 (256 + 232)
  160. #define D_1_236 (256 + 236)
  161. #define D_1_240 (256 + 240)
  162. #define D_1_244 (256 + 244)
  163. #define D_1_250 (256 + 250)
  164. #define D_1_252 (256 + 252)
  165. #define D_2_12 (512 + 12)
  166. #define D_2_96 (512 + 96)
  167. #define D_2_108 (512 + 108)
  168. #define D_2_208 (512 + 208)
  169. #define D_2_224 (512 + 224)
  170. #define D_2_236 (512 + 236)
  171. #define D_2_244 (512 + 244)
  172. #define D_2_248 (512 + 248)
  173. #define D_2_252 (512 + 252)
  174. #define CPASS_BIAS_X (35 * 16 + 4)
  175. #define CPASS_BIAS_Y (35 * 16 + 8)
  176. #define CPASS_BIAS_Z (35 * 16 + 12)
  177. #define CPASS_MTX_00 (36 * 16)
  178. #define CPASS_MTX_01 (36 * 16 + 4)
  179. #define CPASS_MTX_02 (36 * 16 + 8)
  180. #define CPASS_MTX_10 (36 * 16 + 12)
  181. #define CPASS_MTX_11 (37 * 16)
  182. #define CPASS_MTX_12 (37 * 16 + 4)
  183. #define CPASS_MTX_20 (37 * 16 + 8)
  184. #define CPASS_MTX_21 (37 * 16 + 12)
  185. #define CPASS_MTX_22 (43 * 16 + 12)
  186. #define D_EXT_GYRO_BIAS_X (61 * 16)
  187. #define D_EXT_GYRO_BIAS_Y (61 * 16) + 4
  188. #define D_EXT_GYRO_BIAS_Z (61 * 16) + 8
  189. #define D_ACT0 (40 * 16)
  190. #define D_ACSX (40 * 16 + 4)
  191. #define D_ACSY (40 * 16 + 8)
  192. #define D_ACSZ (40 * 16 + 12)
  193. #define FLICK_MSG (45 * 16 + 4)
  194. #define FLICK_COUNTER (45 * 16 + 8)
  195. #define FLICK_LOWER (45 * 16 + 12)
  196. #define FLICK_UPPER (46 * 16 + 12)
  197. #define D_AUTH_OUT (992)
  198. #define D_AUTH_IN (996)
  199. #define D_AUTH_A (1000)
  200. #define D_AUTH_B (1004)
  201. #define D_PEDSTD_BP_B (768 + 0x1C)
  202. #define D_PEDSTD_HP_A (768 + 0x78)
  203. #define D_PEDSTD_HP_B (768 + 0x7C)
  204. #define D_PEDSTD_BP_A4 (768 + 0x40)
  205. #define D_PEDSTD_BP_A3 (768 + 0x44)
  206. #define D_PEDSTD_BP_A2 (768 + 0x48)
  207. #define D_PEDSTD_BP_A1 (768 + 0x4C)
  208. #define D_PEDSTD_INT_THRSH (768 + 0x68)
  209. #define D_PEDSTD_CLIP (768 + 0x6C)
  210. #define D_PEDSTD_SB (768 + 0x28)
  211. #define D_PEDSTD_SB_TIME (768 + 0x2C)
  212. #define D_PEDSTD_PEAKTHRSH (768 + 0x98)
  213. #define D_PEDSTD_TIML (768 + 0x2A)
  214. #define D_PEDSTD_TIMH (768 + 0x2E)
  215. #define D_PEDSTD_PEAK (768 + 0X94)
  216. #define D_PEDSTD_STEPCTR (768 + 0x60)
  217. #define D_PEDSTD_TIMECTR (964)
  218. #define D_PEDSTD_DECI (768 + 0xA0)
  219. #define D_HOST_NO_MOT (976)
  220. #define D_ACCEL_BIAS (660)
  221. #define D_ORIENT_GAP (76)
  222. #define D_TILT0_H (48)
  223. #define D_TILT0_L (50)
  224. #define D_TILT1_H (52)
  225. #define D_TILT1_L (54)
  226. #define D_TILT2_H (56)
  227. #define D_TILT2_L (58)
  228. #define D_TILT3_H (60)
  229. #define D_TILT3_L (62)
  230. #define DMP_CODE_SIZE (3062) // 3062
  231. static const unsigned char dmp_memory[DMP_CODE_SIZE] = {
  232. /* bank # 0 */
  233. 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00,
  234. 0x00, 0x65, 0x00, 0x54, 0xff, 0xef, 0x00, 0x00, 0xfa, 0x80, 0x00, 0x0b, 0x12, 0x82, 0x00, 0x01,
  235. 0x03, 0x0c, 0x30, 0xc3, 0x0e, 0x8c, 0x8c, 0xe9, 0x14, 0xd5, 0x40, 0x02, 0x13, 0x71, 0x0f, 0x8e,
  236. 0x38, 0x83, 0xf8, 0x83, 0x30, 0x00, 0xf8, 0x83, 0x25, 0x8e, 0xf8, 0x83, 0x30, 0x00, 0xf8, 0x83,
  237. 0xff, 0xff, 0xff, 0xff, 0x0f, 0xfe, 0xa9, 0xd6, 0x24, 0x00, 0x04, 0x00, 0x1a, 0x82, 0x79, 0xa1,
  238. 0x00, 0x00, 0x00, 0x3c, 0xff, 0xff, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x38, 0x83, 0x6f, 0xa2,
  239. 0x00, 0x3e, 0x03, 0x30, 0x40, 0x00, 0x00, 0x00, 0x02, 0xca, 0xe3, 0x09, 0x3e, 0x80, 0x00, 0x00,
  240. 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
  241. 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x6e, 0x00, 0x00, 0x06, 0x92, 0x0a, 0x16, 0xc0, 0xdf,
  242. 0xff, 0xff, 0x02, 0x56, 0xfd, 0x8c, 0xd3, 0x77, 0xff, 0xe1, 0xc4, 0x96, 0xe0, 0xc5, 0xbe, 0xaa,
  243. 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0b, 0x2b, 0x00, 0x00, 0x16, 0x57, 0x00, 0x00, 0x03, 0x59,
  244. 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0xfa, 0x00, 0x02, 0x6c, 0x1d, 0x00, 0x00, 0x00, 0x00,
  245. 0x3f, 0xff, 0xdf, 0xeb, 0x00, 0x3e, 0xb3, 0xb6, 0x00, 0x0d, 0x22, 0x78, 0x00, 0x00, 0x2f, 0x3c,
  246. 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x42, 0xb5, 0x00, 0x00, 0x39, 0xa2, 0x00, 0x00, 0xb3, 0x65,
  247. 0xd9, 0x0e, 0x9f, 0xc9, 0x1d, 0xcf, 0x4c, 0x34, 0x30, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00,
  248. 0x3b, 0xb6, 0x7a, 0xe8, 0x00, 0x64, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  249. /* bank # 1 */
  250. 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0xfa, 0x92, 0x10, 0x00, 0x22, 0x5e, 0x00, 0x0d, 0x22, 0x9f,
  251. 0x00, 0x01, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0xff, 0x46, 0x00, 0x00, 0x63, 0xd4, 0x00, 0x00,
  252. 0x10, 0x00, 0x00, 0x00, 0x04, 0xd6, 0x00, 0x00, 0x04, 0xcc, 0x00, 0x00, 0x04, 0xcc, 0x00, 0x00,
  253. 0x00, 0x00, 0x10, 0x72, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  254. 0x00, 0x06, 0x00, 0x02, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00,
  255. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x64, 0x00, 0x20, 0x00, 0x00,
  256. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x03, 0x00,
  257. 0x00, 0x00, 0x00, 0x32, 0xf8, 0x98, 0x00, 0x00, 0xff, 0x65, 0x00, 0x00, 0x83, 0x0f, 0x00, 0x00,
  258. 0xff, 0x9b, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  259. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  260. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
  261. 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0xb2, 0x6a, 0x00, 0x02, 0x00, 0x00,
  262. 0x00, 0x01, 0xfb, 0x83, 0x00, 0x68, 0x00, 0x00, 0x00, 0xd9, 0xfc, 0x00, 0x7c, 0xf1, 0xff, 0x83,
  263. 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x64, 0x03, 0xe8, 0x00, 0x64, 0x00, 0x28,
  264. 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x00, 0x16, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
  265. 0x00, 0x00, 0x10, 0x00, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf4, 0x00, 0x00, 0x10, 0x00,
  266. /* bank # 2 */
  267. 0x00, 0x28, 0x00, 0x00, 0xff, 0xff, 0x45, 0x81, 0xff, 0xff, 0xfa, 0x72, 0x00, 0x00, 0x00, 0x00,
  268. 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0x05, 0x00, 0x05, 0xba, 0xc6, 0x00, 0x47, 0x78, 0xa2,
  269. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x14,
  270. 0x00, 0x00, 0x25, 0x4d, 0x00, 0x2f, 0x70, 0x6d, 0x00, 0x00, 0x05, 0xae, 0x00, 0x0c, 0x02, 0xd0,
  271. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  272. 0x00, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  273. 0x00, 0x64, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  274. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  275. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  276. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  277. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  278. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  279. 0x00, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x0e,
  280. 0x00, 0x00, 0x0a, 0xc7, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0xff, 0xff, 0xff, 0x9c,
  281. 0x00, 0x00, 0x0b, 0x2b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x64,
  282. 0xff, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  283. /* bank # 3 */
  284. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  285. 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x24, 0x26, 0xd3,
  286. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x10, 0x00, 0x96, 0x00, 0x3c,
  287. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  288. 0x0c, 0x0a, 0x4e, 0x68, 0xcd, 0xcf, 0x77, 0x09, 0x50, 0x16, 0x67, 0x59, 0xc6, 0x19, 0xce, 0x82,
  289. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  290. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0xd7, 0x84, 0x00, 0x03, 0x00, 0x00, 0x00,
  291. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc7, 0x93, 0x8f, 0x9d, 0x1e, 0x1b, 0x1c, 0x19,
  292. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  293. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x18, 0x85, 0x00, 0x00, 0x40, 0x00,
  294. 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  295. 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  296. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  297. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  298. 0x00, 0x00, 0x00, 0x00, 0x67, 0x7d, 0xdf, 0x7e, 0x72, 0x90, 0x2e, 0x55, 0x4c, 0xf6, 0xe6, 0x88,
  299. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  300. /* bank # 4 */
  301. 0xd8, 0xdc, 0xb4, 0xb8, 0xb0, 0xd8, 0xb9, 0xab, 0xf3, 0xf8, 0xfa, 0xb3, 0xb7, 0xbb, 0x8e, 0x9e,
  302. 0xae, 0xf1, 0x32, 0xf5, 0x1b, 0xf1, 0xb4, 0xb8, 0xb0, 0x80, 0x97, 0xf1, 0xa9, 0xdf, 0xdf, 0xdf,
  303. 0xaa, 0xdf, 0xdf, 0xdf, 0xf2, 0xaa, 0xc5, 0xcd, 0xc7, 0xa9, 0x0c, 0xc9, 0x2c, 0x97, 0xf1, 0xa9,
  304. 0x89, 0x26, 0x46, 0x66, 0xb2, 0x89, 0x99, 0xa9, 0x2d, 0x55, 0x7d, 0xb0, 0xb0, 0x8a, 0xa8, 0x96,
  305. 0x36, 0x56, 0x76, 0xf1, 0xba, 0xa3, 0xb4, 0xb2, 0x80, 0xc0, 0xb8, 0xa8, 0x97, 0x11, 0x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, 0x92, 0x50, 0x97, 0x88, 0xf1, 0x09, 0xf4, 0x1c,
  329. 0xd8, 0x84, 0xa8, 0xf3, 0xc0, 0xf8, 0xf9, 0xd1, 0xd9, 0x97, 0x82, 0xf1, 0x49, 0xf4, 0x0d, 0xd8,
  330. 0xf3, 0xf9, 0xf9, 0xd1, 0xd9, 0x82, 0xf4, 0xc4, 0x03, 0xd8, 0xde, 0xdf, 0xd8, 0xf1, 0xad, 0x88,
  331. 0x98, 0xcc, 0xa8, 0x09, 0xf9, 0xd9, 0x82, 0x92, 0xa8, 0xf5, 0x7c, 0xf1, 0x88, 0x3a, 0xcf, 0x94,
  332. 0x4a, 0x6e, 0x98, 0xdb, 0x69, 0x31, 0xda, 0xad, 0xf2, 0xde, 0xf9, 0xd8, 0x87, 0x95, 0xa8, 0xf2,
  333. 0x21, 0xd1, 0xda, 0xa5, 0xf9, 0xf4, 0x17, 0xd9, 0xf1, 0xae, 0x8e, 0xd0, 0xc0, 0xc3, 0xae, 0x82,
  334. /* bank # 6 */
  335. 0xc6, 0x84, 0xc3, 0xa8, 0x85, 0x95, 0xc8, 0xa5, 0x88, 0xf2, 0xc0, 0xf1, 0xf4, 0x01, 0x0e, 0xf1,
  336. 0x8e, 0x9e, 0xa8, 0xc6, 0x3e, 0x56, 0xf5, 0x54, 0xf1, 0x88, 0x72, 0xf4, 0x01, 0x15, 0xf1, 0x98,
  337. 0x45, 0x85, 0x6e, 0xf5, 0x8e, 0x9e, 0x04, 0x88, 0xf1, 0x42, 0x98, 0x5a, 0x8e, 0x9e, 0x06, 0x88,
  338. 0x69, 0xf4, 0x01, 0x1c, 0xf1, 0x98, 0x1e, 0x11, 0x08, 0xd0, 0xf5, 0x04, 0xf1, 0x1e, 0x97, 0x02,
  339. 0x02, 0x98, 0x36, 0x25, 0xdb, 0xf9, 0xd9, 0x85, 0xa5, 0xf3, 0xc1, 0xda, 0x85, 0xa5, 0xf3, 0xdf,
  340. 0xd8, 0x85, 0x95, 0xa8, 0xf3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, 0xb8,
  385. /* bank # 9 */
  386. 0xb4, 0xb0, 0x97, 0x86, 0xa8, 0x31, 0x9b, 0x06, 0x99, 0x07, 0xab, 0x97, 0x28, 0x88, 0x9b, 0xf0,
  387. 0x0c, 0x20, 0x14, 0x40, 0xb0, 0xb4, 0xb8, 0xf0, 0xa8, 0x8a, 0x9a, 0x28, 0x50, 0x78, 0xb7, 0x9b,
  388. 0xa8, 0x29, 0x51, 0x79, 0x24, 0x70, 0x59, 0x44, 0x69, 0x38, 0x64, 0x48, 0x31, 0xf1, 0xbb, 0xab,
  389. 0x88, 0x00, 0x2c, 0x54, 0x7c, 0xf0, 0xb3, 0x8b, 0xb8, 0xa8, 0x04, 0x28, 0x50, 0x78, 0xf1, 0xb0,
  390. 0x88, 0xb4, 0x97, 0x26, 0xa8, 0x59, 0x98, 0xbb, 0xab, 0xb3, 0x8b, 0x02, 0x26, 0x46, 0x66, 0xb0,
  391. 0xb8, 0xf0, 0x8a, 0x9c, 0xa8, 0x29, 0x51, 0x79, 0x8b, 0x29, 0x51, 0x79, 0x8a, 0x24, 0x70, 0x59,
  392. 0x8b, 0x20, 0x58, 0x71, 0x8a, 0x44, 0x69, 0x38, 0x8b, 0x39, 0x40, 0x68, 0x8a, 0x64, 0x48, 0x31,
  393. 0x8b, 0x30, 0x49, 0x60, 0x88, 0xf1, 0xac, 0x00, 0x2c, 0x54, 0x7c, 0xf0, 0x8c, 0xa8, 0x04, 0x28,
  394. 0x50, 0x78, 0xf1, 0x88, 0x97, 0x26, 0xa8, 0x59, 0x98, 0xac, 0x8c, 0x02, 0x26, 0x46, 0x66, 0xf0,
  395. 0x89, 0x9c, 0xa8, 0x29, 0x51, 0x79, 0x24, 0x70, 0x59, 0x44, 0x69, 0x38, 0x64, 0x48, 0x31, 0xa9,
  396. 0x88, 0x09, 0x20, 0x59, 0x70, 0xab, 0x11, 0x38, 0x40, 0x69, 0xa8, 0x19, 0x31, 0x48, 0x60, 0x8c,
  397. 0xa8, 0x3c, 0x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x4c, 0x6c, 0x87, 0x0c, 0x95, 0x18, 0x85, 0x78, 0xa3, 0x83,
  421. 0x90, 0x28, 0x4c, 0x6c, 0x88, 0x6c, 0xd8, 0xf3, 0xa2, 0x82, 0x00, 0xf2, 0x10, 0xa8, 0x92, 0x19,
  422. 0x80, 0xa2, 0xf2, 0xd9, 0x26, 0xd8, 0xf1, 0x88, 0xa8, 0x4d, 0xd9, 0x48, 0xd8, 0x96, 0xa8, 0x39,
  423. 0x80, 0xd9, 0x3c, 0xd8, 0x95, 0x80, 0xa8, 0x39, 0xa6, 0x86, 0x98, 0xd9, 0x2c, 0xda, 0x87, 0xa7,
  424. 0x2c, 0xd8, 0xa8, 0x89, 0x95, 0x19, 0xa9, 0x80, 0xd9, 0x38, 0xd8, 0xa8, 0x89, 0x39, 0xa9, 0x80,
  425. 0xda, 0x3c, 0xd8, 0xa8, 0x2e, 0xa8, 0x39, 0x90, 0xd9, 0x0c, 0xd8, 0xa8, 0x95, 0x31, 0x98, 0xd9,
  426. 0x0c, 0xd8, 0xa8, 0x09, 0xd9, 0xff, 0xd8, 0x01, 0xda, 0xff, 0xd8, 0x95, 0x39, 0xa9, 0xda, 0x26,
  427. 0xff, 0xd8, 0x90, 0xa8, 0x0d, 0x89, 0x99, 0xa8, 0x10, 0x80, 0x98, 0x21, 0xda, 0x2e, 0xd8, 0x89,
  428. 0x99, 0xa8, 0x31, 0x80, 0xda, 0x2e, 0xd8, 0xa8, 0x86, 0x96, 0x31, 0x80, 0xda, 0x2e, 0xd8, 0xa8,
  429. 0x87, 0x31, 0x80, 0xda, 0x2e, 0xd8, 0xa8, 0x82, 0x92, 0xf3, 0x41, 0x80, 0xf1, 0xd9, 0x2e, 0xd8,
  430. 0xa8, 0x82, 0xf3, 0x19, 0x80, 0xf1, 0xd9, 0x2e, 0xd8, 0x82, 0xac, 0xf3, 0xc0, 0xa2, 0x80, 0x22,
  431. 0xf1, 0xa6, 0x2e, 0xa7, 0x2e, 0xa9, 0x22, 0x98, 0xa8, 0x29, 0xda, 0xac, 0xde, 0xff, 0xd8, 0xa2,
  432. 0xf2, 0x2a, 0xf1, 0xa9, 0x2e, 0x82, 0x92, 0xa8, 0xf2, 0x31, 0x80, 0xa6, 0x96, 0xf1, 0xd9, 0x00,
  433. 0xac, 0x8c, 0x9c, 0x0c, 0x30, 0xac, 0xde, 0xd0, 0xde, 0xff, 0xd8, 0x8c, 0x9c, 0xac, 0xd0, 0x10,
  434. 0xac, 0xde, 0x80, 0x92, 0xa2, 0xf2, 0x4c, 0x82, 0xa8, 0xf1, 0xca, 0xf2, 0x35, 0xf1, 0x96, 0x88,
  435. 0xa6, 0xd9, 0x00, 0xd8, 0xf1, 0xff
  436. };
  437. static const unsigned short sStartAddress = 0x0400;
  438. /* END OF SECTION COPIED FROM dmpDefaultMPU6050.c */
  439. #define INT_SRC_TAP (0x01)
  440. #define INT_SRC_ANDROID_ORIENT (0x08)
  441. #define DMP_FEATURE_SEND_ANY_GYRO (DMP_FEATURE_SEND_RAW_GYRO | \
  442. DMP_FEATURE_SEND_CAL_GYRO)
  443. #define MAX_PACKET_LENGTH (32)
  444. #define DMP_SAMPLE_RATE (200)
  445. #define GYRO_SF (46850825LL * 200 / DMP_SAMPLE_RATE)
  446. #define FIFO_CORRUPTION_CHECK
  447. #ifdef FIFO_CORRUPTION_CHECK
  448. #define QUAT_ERROR_THRESH (1L<<24)
  449. #define QUAT_MAG_SQ_NORMALIZED (1L<<28)
  450. #define QUAT_MAG_SQ_MIN (QUAT_MAG_SQ_NORMALIZED - QUAT_ERROR_THRESH)
  451. #define QUAT_MAG_SQ_MAX (QUAT_MAG_SQ_NORMALIZED + QUAT_ERROR_THRESH)
  452. #endif
  453. struct dmp_s {
  454. void (*tap_cb)(unsigned char count, unsigned char direction);
  455. void (*android_orient_cb)(unsigned char orientation);
  456. unsigned short orient;
  457. unsigned short feature_mask;
  458. unsigned short fifo_rate;
  459. unsigned char packet_length;
  460. };
  461. static struct dmp_s dmp = {
  462. .tap_cb = NULL,
  463. .android_orient_cb = NULL,
  464. .orient = 0,
  465. .feature_mask = 0,
  466. .fifo_rate = 0,
  467. .packet_length = 0
  468. };
  469. /**
  470. * @brief Load the DMP with this image.
  471. * @return 0 if successful.
  472. */
  473. int dmp_load_motion_driver_firmware(void)
  474. {
  475. return mpu_load_firmware(DMP_CODE_SIZE, dmp_memory, sStartAddress,
  476. DMP_SAMPLE_RATE);
  477. }
  478. /**
  479. * @brief Push gyro and accel orientation to the DMP.
  480. * The orientation is represented here as the output of
  481. * @e inv_orientation_matrix_to_scalar.
  482. * @param[in] orient Gyro and accel orientation in body frame.
  483. * @return 0 if successful.
  484. */
  485. int dmp_set_orientation(unsigned short orient)
  486. {
  487. unsigned char gyro_regs[3], accel_regs[3];
  488. const unsigned char gyro_axes[3] = {DINA4C, DINACD, DINA6C};
  489. const unsigned char accel_axes[3] = {DINA0C, DINAC9, DINA2C};
  490. const unsigned char gyro_sign[3] = {DINA36, DINA56, DINA76};
  491. const unsigned char accel_sign[3] = {DINA26, DINA46, DINA66};
  492. gyro_regs[0] = gyro_axes[orient & 3];
  493. gyro_regs[1] = gyro_axes[(orient >> 3) & 3];
  494. gyro_regs[2] = gyro_axes[(orient >> 6) & 3];
  495. accel_regs[0] = accel_axes[orient & 3];
  496. accel_regs[1] = accel_axes[(orient >> 3) & 3];
  497. accel_regs[2] = accel_axes[(orient >> 6) & 3];
  498. /* Chip-to-body, axes only. */
  499. if (mpu_write_mem(FCFG_1, 3, gyro_regs))
  500. return -1;
  501. if (mpu_write_mem(FCFG_2, 3, accel_regs))
  502. return -1;
  503. memcpy(gyro_regs, gyro_sign, 3);
  504. memcpy(accel_regs, accel_sign, 3);
  505. if (orient & 4) {
  506. gyro_regs[0] |= 1;
  507. accel_regs[0] |= 1;
  508. }
  509. if (orient & 0x20) {
  510. gyro_regs[1] |= 1;
  511. accel_regs[1] |= 1;
  512. }
  513. if (orient & 0x100) {
  514. gyro_regs[2] |= 1;
  515. accel_regs[2] |= 1;
  516. }
  517. /* Chip-to-body, sign only. */
  518. if (mpu_write_mem(FCFG_3, 3, gyro_regs))
  519. return -1;
  520. if (mpu_write_mem(FCFG_7, 3, accel_regs))
  521. return -1;
  522. dmp.orient = orient;
  523. return 0;
  524. }
  525. /**
  526. * @brief Push gyro biases to the DMP.
  527. * Because the gyro integration is handled in the DMP, any gyro biases
  528. * calculated by the MPL should be pushed down to DMP memory to remove
  529. * 3-axis quaternion drift.
  530. * \n NOTE: If the DMP-based gyro calibration is enabled, the DMP will
  531. * overwrite the biases written to this location once a new one is computed.
  532. * @param[in] bias Gyro biases in q16.
  533. * @return 0 if successful.
  534. */
  535. int dmp_set_gyro_bias(long *bias)
  536. {
  537. long gyro_bias_body[3];
  538. unsigned char regs[4];
  539. gyro_bias_body[0] = bias[dmp.orient & 3];
  540. if (dmp.orient & 4)
  541. gyro_bias_body[0] *= -1;
  542. gyro_bias_body[1] = bias[(dmp.orient >> 3) & 3];
  543. if (dmp.orient & 0x20)
  544. gyro_bias_body[1] *= -1;
  545. gyro_bias_body[2] = bias[(dmp.orient >> 6) & 3];
  546. if (dmp.orient & 0x100)
  547. gyro_bias_body[2] *= -1;
  548. #ifdef EMPL_NO_64BIT
  549. gyro_bias_body[0] = (long)(((float)gyro_bias_body[0] * GYRO_SF) / 1073741824.f);
  550. gyro_bias_body[1] = (long)(((float)gyro_bias_body[1] * GYRO_SF) / 1073741824.f);
  551. gyro_bias_body[2] = (long)(((float)gyro_bias_body[2] * GYRO_SF) / 1073741824.f);
  552. #else
  553. gyro_bias_body[0] = (long)(((long long)gyro_bias_body[0] * GYRO_SF) >> 30);
  554. gyro_bias_body[1] = (long)(((long long)gyro_bias_body[1] * GYRO_SF) >> 30);
  555. gyro_bias_body[2] = (long)(((long long)gyro_bias_body[2] * GYRO_SF) >> 30);
  556. #endif
  557. regs[0] = (unsigned char)((gyro_bias_body[0] >> 24) & 0xFF);
  558. regs[1] = (unsigned char)((gyro_bias_body[0] >> 16) & 0xFF);
  559. regs[2] = (unsigned char)((gyro_bias_body[0] >> 8) & 0xFF);
  560. regs[3] = (unsigned char)(gyro_bias_body[0] & 0xFF);
  561. if (mpu_write_mem(D_EXT_GYRO_BIAS_X, 4, regs))
  562. return -1;
  563. regs[0] = (unsigned char)((gyro_bias_body[1] >> 24) & 0xFF);
  564. regs[1] = (unsigned char)((gyro_bias_body[1] >> 16) & 0xFF);
  565. regs[2] = (unsigned char)((gyro_bias_body[1] >> 8) & 0xFF);
  566. regs[3] = (unsigned char)(gyro_bias_body[1] & 0xFF);
  567. if (mpu_write_mem(D_EXT_GYRO_BIAS_Y, 4, regs))
  568. return -1;
  569. regs[0] = (unsigned char)((gyro_bias_body[2] >> 24) & 0xFF);
  570. regs[1] = (unsigned char)((gyro_bias_body[2] >> 16) & 0xFF);
  571. regs[2] = (unsigned char)((gyro_bias_body[2] >> 8) & 0xFF);
  572. regs[3] = (unsigned char)(gyro_bias_body[2] & 0xFF);
  573. return mpu_write_mem(D_EXT_GYRO_BIAS_Z, 4, regs);
  574. }
  575. /**
  576. * @brief Push accel biases to the DMP.
  577. * These biases will be removed from the DMP 6-axis quaternion.
  578. * @param[in] bias Accel biases in q16.
  579. * @return 0 if successful.
  580. */
  581. int dmp_set_accel_bias(long *bias)
  582. {
  583. long accel_bias_body[3];
  584. unsigned char regs[12];
  585. long long accel_sf;
  586. unsigned short accel_sens;
  587. mpu_get_accel_sens(&accel_sens);
  588. accel_sf = (long long)accel_sens << 15;
  589. // __no_operation();
  590. __nop();
  591. accel_bias_body[0] = bias[dmp.orient & 3];
  592. if (dmp.orient & 4)
  593. accel_bias_body[0] *= -1;
  594. accel_bias_body[1] = bias[(dmp.orient >> 3) & 3];
  595. if (dmp.orient & 0x20)
  596. accel_bias_body[1] *= -1;
  597. accel_bias_body[2] = bias[(dmp.orient >> 6) & 3];
  598. if (dmp.orient & 0x100)
  599. accel_bias_body[2] *= -1;
  600. #ifdef EMPL_NO_64BIT
  601. accel_bias_body[0] = (long)(((float)accel_bias_body[0] * accel_sf) / 1073741824.f);
  602. accel_bias_body[1] = (long)(((float)accel_bias_body[1] * accel_sf) / 1073741824.f);
  603. accel_bias_body[2] = (long)(((float)accel_bias_body[2] * accel_sf) / 1073741824.f);
  604. #else
  605. accel_bias_body[0] = (long)(((long long)accel_bias_body[0] * accel_sf) >> 30);
  606. accel_bias_body[1] = (long)(((long long)accel_bias_body[1] * accel_sf) >> 30);
  607. accel_bias_body[2] = (long)(((long long)accel_bias_body[2] * accel_sf) >> 30);
  608. #endif
  609. regs[0] = (unsigned char)((accel_bias_body[0] >> 24) & 0xFF);
  610. regs[1] = (unsigned char)((accel_bias_body[0] >> 16) & 0xFF);
  611. regs[2] = (unsigned char)((accel_bias_body[0] >> 8) & 0xFF);
  612. regs[3] = (unsigned char)(accel_bias_body[0] & 0xFF);
  613. regs[4] = (unsigned char)((accel_bias_body[1] >> 24) & 0xFF);
  614. regs[5] = (unsigned char)((accel_bias_body[1] >> 16) & 0xFF);
  615. regs[6] = (unsigned char)((accel_bias_body[1] >> 8) & 0xFF);
  616. regs[7] = (unsigned char)(accel_bias_body[1] & 0xFF);
  617. regs[8] = (unsigned char)((accel_bias_body[2] >> 24) & 0xFF);
  618. regs[9] = (unsigned char)((accel_bias_body[2] >> 16) & 0xFF);
  619. regs[10] = (unsigned char)((accel_bias_body[2] >> 8) & 0xFF);
  620. regs[11] = (unsigned char)(accel_bias_body[2] & 0xFF);
  621. return mpu_write_mem(D_ACCEL_BIAS, 12, regs);
  622. }
  623. /**
  624. * @brief Set DMP output rate.
  625. * Only used when DMP is on.
  626. * @param[in] rate Desired fifo rate (Hz).
  627. * @return 0 if successful.
  628. */
  629. int dmp_set_fifo_rate(unsigned short rate)
  630. {
  631. const unsigned char regs_end[12] = {DINAFE, DINAF2, DINAAB,
  632. 0xc4, DINAAA, DINAF1, DINADF, DINADF, 0xBB, 0xAF, DINADF, DINADF};
  633. unsigned short div;
  634. unsigned char tmp[8];
  635. if (rate > DMP_SAMPLE_RATE)
  636. return -1;
  637. div = DMP_SAMPLE_RATE / rate - 1;
  638. tmp[0] = (unsigned char)((div >> 8) & 0xFF);
  639. tmp[1] = (unsigned char)(div & 0xFF);
  640. if (mpu_write_mem(D_0_22, 2, tmp))
  641. return -1;
  642. if (mpu_write_mem(CFG_6, 12, (unsigned char*)regs_end))
  643. return -1;
  644. dmp.fifo_rate = rate;
  645. return 0;
  646. }
  647. /**
  648. * @brief Get DMP output rate.
  649. * @param[out] rate Current fifo rate (Hz).
  650. * @return 0 if successful.
  651. */
  652. int dmp_get_fifo_rate(unsigned short *rate)
  653. {
  654. rate[0] = dmp.fifo_rate;
  655. return 0;
  656. }
  657. /**
  658. * @brief Set tap threshold for a specific axis.
  659. * @param[in] axis 1, 2, and 4 for XYZ accel, respectively.
  660. * @param[in] thresh Tap threshold, in mg/ms.
  661. * @return 0 if successful.
  662. */
  663. int dmp_set_tap_thresh(unsigned char axis, unsigned short thresh)
  664. {
  665. unsigned char tmp[4], accel_fsr;
  666. float scaled_thresh;
  667. unsigned short dmp_thresh, dmp_thresh_2;
  668. if (!(axis & TAP_XYZ) || thresh > 1600)
  669. return -1;
  670. scaled_thresh = (float)thresh / DMP_SAMPLE_RATE;
  671. mpu_get_accel_fsr(&accel_fsr);
  672. switch (accel_fsr) {
  673. case 2:
  674. dmp_thresh = (unsigned short)(scaled_thresh * 16384);
  675. /* dmp_thresh * 0.75 */
  676. dmp_thresh_2 = (unsigned short)(scaled_thresh * 12288);
  677. break;
  678. case 4:
  679. dmp_thresh = (unsigned short)(scaled_thresh * 8192);
  680. /* dmp_thresh * 0.75 */
  681. dmp_thresh_2 = (unsigned short)(scaled_thresh * 6144);
  682. break;
  683. case 8:
  684. dmp_thresh = (unsigned short)(scaled_thresh * 4096);
  685. /* dmp_thresh * 0.75 */
  686. dmp_thresh_2 = (unsigned short)(scaled_thresh * 3072);
  687. break;
  688. case 16:
  689. dmp_thresh = (unsigned short)(scaled_thresh * 2048);
  690. /* dmp_thresh * 0.75 */
  691. dmp_thresh_2 = (unsigned short)(scaled_thresh * 1536);
  692. break;
  693. default:
  694. return -1;
  695. }
  696. tmp[0] = (unsigned char)(dmp_thresh >> 8);
  697. tmp[1] = (unsigned char)(dmp_thresh & 0xFF);
  698. tmp[2] = (unsigned char)(dmp_thresh_2 >> 8);
  699. tmp[3] = (unsigned char)(dmp_thresh_2 & 0xFF);
  700. if (axis & TAP_X) {
  701. if (mpu_write_mem(DMP_TAP_THX, 2, tmp))
  702. return -1;
  703. if (mpu_write_mem(D_1_36, 2, tmp+2))
  704. return -1;
  705. }
  706. if (axis & TAP_Y) {
  707. if (mpu_write_mem(DMP_TAP_THY, 2, tmp))
  708. return -1;
  709. if (mpu_write_mem(D_1_40, 2, tmp+2))
  710. return -1;
  711. }
  712. if (axis & TAP_Z) {
  713. if (mpu_write_mem(DMP_TAP_THZ, 2, tmp))
  714. return -1;
  715. if (mpu_write_mem(D_1_44, 2, tmp+2))
  716. return -1;
  717. }
  718. return 0;
  719. }
  720. /**
  721. * @brief Set which axes will register a tap.
  722. * @param[in] axis 1, 2, and 4 for XYZ, respectively.
  723. * @return 0 if successful.
  724. */
  725. int dmp_set_tap_axes(unsigned char axis)
  726. {
  727. unsigned char tmp = 0;
  728. if (axis & TAP_X)
  729. tmp |= 0x30;
  730. if (axis & TAP_Y)
  731. tmp |= 0x0C;
  732. if (axis & TAP_Z)
  733. tmp |= 0x03;
  734. return mpu_write_mem(D_1_72, 1, &tmp);
  735. }
  736. /**
  737. * @brief Set minimum number of taps needed for an interrupt.
  738. * @param[in] min_taps Minimum consecutive taps (1-4).
  739. * @return 0 if successful.
  740. */
  741. int dmp_set_tap_count(unsigned char min_taps)
  742. {
  743. unsigned char tmp;
  744. if (min_taps < 1)
  745. min_taps = 1;
  746. else if (min_taps > 4)
  747. min_taps = 4;
  748. tmp = min_taps - 1;
  749. return mpu_write_mem(D_1_79, 1, &tmp);
  750. }
  751. /**
  752. * @brief Set length between valid taps.
  753. * @param[in] time Milliseconds between taps.
  754. * @return 0 if successful.
  755. */
  756. int dmp_set_tap_time(unsigned short time)
  757. {
  758. unsigned short dmp_time;
  759. unsigned char tmp[2];
  760. dmp_time = time / (1000 / DMP_SAMPLE_RATE);
  761. tmp[0] = (unsigned char)(dmp_time >> 8);
  762. tmp[1] = (unsigned char)(dmp_time & 0xFF);
  763. return mpu_write_mem(DMP_TAPW_MIN, 2, tmp);
  764. }
  765. /**
  766. * @brief Set max time between taps to register as a multi-tap.
  767. * @param[in] time Max milliseconds between taps.
  768. * @return 0 if successful.
  769. */
  770. int dmp_set_tap_time_multi(unsigned short time)
  771. {
  772. unsigned short dmp_time;
  773. unsigned char tmp[2];
  774. dmp_time = time / (1000 / DMP_SAMPLE_RATE);
  775. tmp[0] = (unsigned char)(dmp_time >> 8);
  776. tmp[1] = (unsigned char)(dmp_time & 0xFF);
  777. return mpu_write_mem(D_1_218, 2, tmp);
  778. }
  779. /**
  780. * @brief Set shake rejection threshold.
  781. * If the DMP detects a gyro sample larger than @e thresh, taps are rejected.
  782. * @param[in] sf Gyro scale factor.
  783. * @param[in] thresh Gyro threshold in dps.
  784. * @return 0 if successful.
  785. */
  786. int dmp_set_shake_reject_thresh(long sf, unsigned short thresh)
  787. {
  788. unsigned char tmp[4];
  789. long thresh_scaled = sf / 1000 * thresh;
  790. tmp[0] = (unsigned char)(((long)thresh_scaled >> 24) & 0xFF);
  791. tmp[1] = (unsigned char)(((long)thresh_scaled >> 16) & 0xFF);
  792. tmp[2] = (unsigned char)(((long)thresh_scaled >> 8) & 0xFF);
  793. tmp[3] = (unsigned char)((long)thresh_scaled & 0xFF);
  794. return mpu_write_mem(D_1_92, 4, tmp);
  795. }
  796. /**
  797. * @brief Set shake rejection time.
  798. * Sets the length of time that the gyro must be outside of the threshold set
  799. * by @e gyro_set_shake_reject_thresh before taps are rejected. A mandatory
  800. * 60 ms is added to this parameter.
  801. * @param[in] time Time in milliseconds.
  802. * @return 0 if successful.
  803. */
  804. int dmp_set_shake_reject_time(unsigned short time)
  805. {
  806. unsigned char tmp[2];
  807. time /= (1000 / DMP_SAMPLE_RATE);
  808. tmp[0] = time >> 8;
  809. tmp[1] = time & 0xFF;
  810. return mpu_write_mem(D_1_90,2,tmp);
  811. }
  812. /**
  813. * @brief Set shake rejection timeout.
  814. * Sets the length of time after a shake rejection that the gyro must stay
  815. * inside of the threshold before taps can be detected again. A mandatory
  816. * 60 ms is added to this parameter.
  817. * @param[in] time Time in milliseconds.
  818. * @return 0 if successful.
  819. */
  820. int dmp_set_shake_reject_timeout(unsigned short time)
  821. {
  822. unsigned char tmp[2];
  823. time /= (1000 / DMP_SAMPLE_RATE);
  824. tmp[0] = time >> 8;
  825. tmp[1] = time & 0xFF;
  826. return mpu_write_mem(D_1_88,2,tmp);
  827. }
  828. /**
  829. * @brief Get current step count.
  830. * @param[out] count Number of steps detected.
  831. * @return 0 if successful.
  832. */
  833. int dmp_get_pedometer_step_count(unsigned long *count)
  834. {
  835. unsigned char tmp[4];
  836. if (!count)
  837. return -1;
  838. if (mpu_read_mem(D_PEDSTD_STEPCTR, 4, tmp))
  839. return -1;
  840. count[0] = ((unsigned long)tmp[0] << 24) | ((unsigned long)tmp[1] << 16) |
  841. ((unsigned long)tmp[2] << 8) | tmp[3];
  842. return 0;
  843. }
  844. /**
  845. * @brief Overwrite current step count.
  846. * WARNING: This function writes to DMP memory and could potentially encounter
  847. * a race condition if called while the pedometer is enabled.
  848. * @param[in] count New step count.
  849. * @return 0 if successful.
  850. */
  851. int dmp_set_pedometer_step_count(unsigned long count)
  852. {
  853. unsigned char tmp[4];
  854. tmp[0] = (unsigned char)((count >> 24) & 0xFF);
  855. tmp[1] = (unsigned char)((count >> 16) & 0xFF);
  856. tmp[2] = (unsigned char)((count >> 8) & 0xFF);
  857. tmp[3] = (unsigned char)(count & 0xFF);
  858. return mpu_write_mem(D_PEDSTD_STEPCTR, 4, tmp);
  859. }
  860. /**
  861. * @brief Get duration of walking time.
  862. * @param[in] time Walk time in milliseconds.
  863. * @return 0 if successful.
  864. */
  865. int dmp_get_pedometer_walk_time(unsigned long *time)
  866. {
  867. unsigned char tmp[4];
  868. if (!time)
  869. return -1;
  870. if (mpu_read_mem(D_PEDSTD_TIMECTR, 4, tmp))
  871. return -1;
  872. time[0] = (((unsigned long)tmp[0] << 24) | ((unsigned long)tmp[1] << 16) |
  873. ((unsigned long)tmp[2] << 8) | tmp[3]) * 20;
  874. return 0;
  875. }
  876. /**
  877. * @brief Overwrite current walk time.
  878. * WARNING: This function writes to DMP memory and could potentially encounter
  879. * a race condition if called while the pedometer is enabled.
  880. * @param[in] time New walk time in milliseconds.
  881. */
  882. int dmp_set_pedometer_walk_time(unsigned long time)
  883. {
  884. unsigned char tmp[4];
  885. time /= 20;
  886. tmp[0] = (unsigned char)((time >> 24) & 0xFF);
  887. tmp[1] = (unsigned char)((time >> 16) & 0xFF);
  888. tmp[2] = (unsigned char)((time >> 8) & 0xFF);
  889. tmp[3] = (unsigned char)(time & 0xFF);
  890. return mpu_write_mem(D_PEDSTD_TIMECTR, 4, tmp);
  891. }
  892. /**
  893. * @brief Enable DMP features.
  894. * The following \#define's are used in the input mask:
  895. * \n DMP_FEATURE_TAP
  896. * \n DMP_FEATURE_ANDROID_ORIENT
  897. * \n DMP_FEATURE_LP_QUAT
  898. * \n DMP_FEATURE_6X_LP_QUAT
  899. * \n DMP_FEATURE_GYRO_CAL
  900. * \n DMP_FEATURE_SEND_RAW_ACCEL
  901. * \n DMP_FEATURE_SEND_RAW_GYRO
  902. * \n NOTE: DMP_FEATURE_LP_QUAT and DMP_FEATURE_6X_LP_QUAT are mutually
  903. * exclusive.
  904. * \n NOTE: DMP_FEATURE_SEND_RAW_GYRO and DMP_FEATURE_SEND_CAL_GYRO are also
  905. * mutually exclusive.
  906. * @param[in] mask Mask of features to enable.
  907. * @return 0 if successful.
  908. */
  909. int dmp_enable_feature(unsigned short mask)
  910. {
  911. unsigned char tmp[10];
  912. /* TODO: All of these settings can probably be integrated into the default
  913. * DMP image.
  914. */
  915. /* Set integration scale factor. */
  916. tmp[0] = (unsigned char)((GYRO_SF >> 24) & 0xFF);
  917. tmp[1] = (unsigned char)((GYRO_SF >> 16) & 0xFF);
  918. tmp[2] = (unsigned char)((GYRO_SF >> 8) & 0xFF);
  919. tmp[3] = (unsigned char)(GYRO_SF & 0xFF);
  920. mpu_write_mem(D_0_104, 4, tmp);
  921. /* Send sensor data to the FIFO. */
  922. tmp[0] = 0xA3;
  923. if (mask & DMP_FEATURE_SEND_RAW_ACCEL) {
  924. tmp[1] = 0xC0;
  925. tmp[2] = 0xC8;
  926. tmp[3] = 0xC2;
  927. } else {
  928. tmp[1] = 0xA3;
  929. tmp[2] = 0xA3;
  930. tmp[3] = 0xA3;
  931. }
  932. if (mask & DMP_FEATURE_SEND_ANY_GYRO) {
  933. tmp[4] = 0xC4;
  934. tmp[5] = 0xCC;
  935. tmp[6] = 0xC6;
  936. } else {
  937. tmp[4] = 0xA3;
  938. tmp[5] = 0xA3;
  939. tmp[6] = 0xA3;
  940. }
  941. tmp[7] = 0xA3;
  942. tmp[8] = 0xA3;
  943. tmp[9] = 0xA3;
  944. mpu_write_mem(CFG_15,10,tmp);
  945. /* Send gesture data to the FIFO. */
  946. if (mask & (DMP_FEATURE_TAP | DMP_FEATURE_ANDROID_ORIENT))
  947. tmp[0] = DINA20;
  948. else
  949. tmp[0] = 0xD8;
  950. mpu_write_mem(CFG_27,1,tmp);
  951. if (mask & DMP_FEATURE_GYRO_CAL)
  952. dmp_enable_gyro_cal(1);
  953. else
  954. dmp_enable_gyro_cal(0);
  955. if (mask & DMP_FEATURE_SEND_ANY_GYRO) {
  956. if (mask & DMP_FEATURE_SEND_CAL_GYRO) {
  957. tmp[0] = 0xB2;
  958. tmp[1] = 0x8B;
  959. tmp[2] = 0xB6;
  960. tmp[3] = 0x9B;
  961. } else {
  962. tmp[0] = DINAC0;
  963. tmp[1] = DINA80;
  964. tmp[2] = DINAC2;
  965. tmp[3] = DINA90;
  966. }
  967. mpu_write_mem(CFG_GYRO_RAW_DATA, 4, tmp);
  968. }
  969. if (mask & DMP_FEATURE_TAP) {
  970. /* Enable tap. */
  971. tmp[0] = 0xF8;
  972. mpu_write_mem(CFG_20, 1, tmp);
  973. dmp_set_tap_thresh(TAP_XYZ, 250);
  974. dmp_set_tap_axes(TAP_XYZ);
  975. dmp_set_tap_count(1);
  976. dmp_set_tap_time(100);
  977. dmp_set_tap_time_multi(500);
  978. dmp_set_shake_reject_thresh(GYRO_SF, 200);
  979. dmp_set_shake_reject_time(40);
  980. dmp_set_shake_reject_timeout(10);
  981. } else {
  982. tmp[0] = 0xD8;
  983. mpu_write_mem(CFG_20, 1, tmp);
  984. }
  985. if (mask & DMP_FEATURE_ANDROID_ORIENT) {
  986. tmp[0] = 0xD9;
  987. } else
  988. tmp[0] = 0xD8;
  989. mpu_write_mem(CFG_ANDROID_ORIENT_INT, 1, tmp);
  990. if (mask & DMP_FEATURE_LP_QUAT)
  991. dmp_enable_lp_quat(1);
  992. else
  993. dmp_enable_lp_quat(0);
  994. if (mask & DMP_FEATURE_6X_LP_QUAT)
  995. dmp_enable_6x_lp_quat(1);
  996. else
  997. dmp_enable_6x_lp_quat(0);
  998. /* Pedometer is always enabled. */
  999. dmp.feature_mask = mask | DMP_FEATURE_PEDOMETER;
  1000. mpu_reset_fifo();
  1001. dmp.packet_length = 0;
  1002. if (mask & DMP_FEATURE_SEND_RAW_ACCEL)
  1003. dmp.packet_length += 6;
  1004. if (mask & DMP_FEATURE_SEND_ANY_GYRO)
  1005. dmp.packet_length += 6;
  1006. if (mask & (DMP_FEATURE_LP_QUAT | DMP_FEATURE_6X_LP_QUAT))
  1007. dmp.packet_length += 16;
  1008. if (mask & (DMP_FEATURE_TAP | DMP_FEATURE_ANDROID_ORIENT))
  1009. dmp.packet_length += 4;
  1010. return 0;
  1011. }
  1012. /**
  1013. * @brief Get list of currently enabled DMP features.
  1014. * @param[out] Mask of enabled features.
  1015. * @return 0 if successful.
  1016. */
  1017. int dmp_get_enabled_features(unsigned short *mask)
  1018. {
  1019. mask[0] = dmp.feature_mask;
  1020. return 0;
  1021. }
  1022. /**
  1023. * @brief Calibrate the gyro data in the DMP.
  1024. * After eight seconds of no motion, the DMP will compute gyro biases and
  1025. * subtract them from the quaternion output. If @e dmp_enable_feature is
  1026. * called with @e DMP_FEATURE_SEND_CAL_GYRO, the biases will also be
  1027. * subtracted from the gyro output.
  1028. * @param[in] enable 1 to enable gyro calibration.
  1029. * @return 0 if successful.
  1030. */
  1031. int dmp_enable_gyro_cal(unsigned char enable)
  1032. {
  1033. if (enable) {
  1034. unsigned char regs[9] = {0xb8, 0xaa, 0xb3, 0x8d, 0xb4, 0x98, 0x0d, 0x35, 0x5d};
  1035. return mpu_write_mem(CFG_MOTION_BIAS, 9, regs);
  1036. } else {
  1037. unsigned char regs[9] = {0xb8, 0xaa, 0xaa, 0xaa, 0xb0, 0x88, 0xc3, 0xc5, 0xc7};
  1038. return mpu_write_mem(CFG_MOTION_BIAS, 9, regs);
  1039. }
  1040. }
  1041. /**
  1042. * @brief Generate 3-axis quaternions from the DMP.
  1043. * In this driver, the 3-axis and 6-axis DMP quaternion features are mutually
  1044. * exclusive.
  1045. * @param[in] enable 1 to enable 3-axis quaternion.
  1046. * @return 0 if successful.
  1047. */
  1048. int dmp_enable_lp_quat(unsigned char enable)
  1049. {
  1050. unsigned char regs[4];
  1051. if (enable) {
  1052. regs[0] = DINBC0;
  1053. regs[1] = DINBC2;
  1054. regs[2] = DINBC4;
  1055. regs[3] = DINBC6;
  1056. }
  1057. else
  1058. memset(regs, 0x8B, 4);
  1059. mpu_write_mem(CFG_LP_QUAT, 4, regs);
  1060. return mpu_reset_fifo();
  1061. }
  1062. /**
  1063. * @brief Generate 6-axis quaternions from the DMP.
  1064. * In this driver, the 3-axis and 6-axis DMP quaternion features are mutually
  1065. * exclusive.
  1066. * @param[in] enable 1 to enable 6-axis quaternion.
  1067. * @return 0 if successful.
  1068. */
  1069. int dmp_enable_6x_lp_quat(unsigned char enable)
  1070. {
  1071. unsigned char regs[4];
  1072. if (enable) {
  1073. regs[0] = DINA20;
  1074. regs[1] = DINA28;
  1075. regs[2] = DINA30;
  1076. regs[3] = DINA38;
  1077. } else
  1078. memset(regs, 0xA3, 4);
  1079. mpu_write_mem(CFG_8, 4, regs);
  1080. return mpu_reset_fifo();
  1081. }
  1082. /**
  1083. * @brief Decode the four-byte gesture data and execute any callbacks.
  1084. * @param[in] gesture Gesture data from DMP packet.
  1085. * @return 0 if successful.
  1086. */
  1087. static int decode_gesture(unsigned char *gesture)
  1088. {
  1089. unsigned char tap, android_orient;
  1090. android_orient = gesture[3] & 0xC0;
  1091. tap = 0x3F & gesture[3];
  1092. if (gesture[1] & INT_SRC_TAP) {
  1093. unsigned char direction, count;
  1094. direction = tap >> 3;
  1095. count = (tap % 8) + 1;
  1096. if (dmp.tap_cb)
  1097. dmp.tap_cb(direction, count);
  1098. }
  1099. if (gesture[1] & INT_SRC_ANDROID_ORIENT) {
  1100. if (dmp.android_orient_cb)
  1101. dmp.android_orient_cb(android_orient >> 6);
  1102. }
  1103. return 0;
  1104. }
  1105. /**
  1106. * @brief Specify when a DMP interrupt should occur.
  1107. * A DMP interrupt can be configured to trigger on either of the two
  1108. * conditions below:
  1109. * \n a. One FIFO period has elapsed (set by @e mpu_set_sample_rate).
  1110. * \n b. A tap event has been detected.
  1111. * @param[in] mode DMP_INT_GESTURE or DMP_INT_CONTINUOUS.
  1112. * @return 0 if successful.
  1113. */
  1114. int dmp_set_interrupt_mode(unsigned char mode)
  1115. {
  1116. const unsigned char regs_continuous[11] =
  1117. {0xd8, 0xb1, 0xb9, 0xf3, 0x8b, 0xa3, 0x91, 0xb6, 0x09, 0xb4, 0xd9};
  1118. const unsigned char regs_gesture[11] =
  1119. {0xda, 0xb1, 0xb9, 0xf3, 0x8b, 0xa3, 0x91, 0xb6, 0xda, 0xb4, 0xda};
  1120. switch (mode) {
  1121. case DMP_INT_CONTINUOUS:
  1122. return mpu_write_mem(CFG_FIFO_ON_EVENT, 11,
  1123. (unsigned char*)regs_continuous);
  1124. case DMP_INT_GESTURE:
  1125. return mpu_write_mem(CFG_FIFO_ON_EVENT, 11,
  1126. (unsigned char*)regs_gesture);
  1127. default:
  1128. return -1;
  1129. }
  1130. }
  1131. /**
  1132. * @brief Get one packet from the FIFO.
  1133. * If @e sensors does not contain a particular sensor, disregard the data
  1134. * returned to that pointer.
  1135. * \n @e sensors can contain a combination of the following flags:
  1136. * \n INV_X_GYRO, INV_Y_GYRO, INV_Z_GYRO
  1137. * \n INV_XYZ_GYRO
  1138. * \n INV_XYZ_ACCEL
  1139. * \n INV_WXYZ_QUAT
  1140. * \n If the FIFO has no new data, @e sensors will be zero.
  1141. * \n If the FIFO is disabled, @e sensors will be zero and this function will
  1142. * return a non-zero error code.
  1143. * @param[out] gyro Gyro data in hardware units.
  1144. * @param[out] accel Accel data in hardware units.
  1145. * @param[out] quat 3-axis quaternion data in hardware units.
  1146. * @param[out] timestamp Timestamp in milliseconds.
  1147. * @param[out] sensors Mask of sensors read from FIFO.
  1148. * @param[out] more Number of remaining packets.
  1149. * @return 0 if successful.
  1150. */
  1151. int dmp_read_fifo(short *gyro, short *accel, long *quat,
  1152. unsigned long *timestamp, short *sensors, unsigned char *more)
  1153. {
  1154. unsigned char fifo_data[MAX_PACKET_LENGTH];
  1155. unsigned char ii = 0;
  1156. /* TODO: sensors[0] only changes when dmp_enable_feature is called. We can
  1157. * cache this value and save some cycles.
  1158. */
  1159. sensors[0] = 0;
  1160. /* Get a packet. */
  1161. if (mpu_read_fifo_stream(dmp.packet_length, fifo_data, more))
  1162. return -1;
  1163. /* Parse DMP packet. */
  1164. if (dmp.feature_mask & (DMP_FEATURE_LP_QUAT | DMP_FEATURE_6X_LP_QUAT)) {
  1165. #ifdef FIFO_CORRUPTION_CHECK
  1166. long quat_q14[4], quat_mag_sq;
  1167. #endif
  1168. quat[0] = ((long)fifo_data[0] << 24) | ((long)fifo_data[1] << 16) |
  1169. ((long)fifo_data[2] << 8) | fifo_data[3];
  1170. quat[1] = ((long)fifo_data[4] << 24) | ((long)fifo_data[5] << 16) |
  1171. ((long)fifo_data[6] << 8) | fifo_data[7];
  1172. quat[2] = ((long)fifo_data[8] << 24) | ((long)fifo_data[9] << 16) |
  1173. ((long)fifo_data[10] << 8) | fifo_data[11];
  1174. quat[3] = ((long)fifo_data[12] << 24) | ((long)fifo_data[13] << 16) |
  1175. ((long)fifo_data[14] << 8) | fifo_data[15];
  1176. ii += 16;
  1177. #ifdef FIFO_CORRUPTION_CHECK
  1178. /* We can detect a corrupted FIFO by monitoring the quaternion data and
  1179. * ensuring that the magnitude is always normalized to one. This
  1180. * shouldn't happen in normal operation, but if an I2C error occurs,
  1181. * the FIFO reads might become misaligned.
  1182. *
  1183. * Let's start by scaling down the quaternion data to avoid long long
  1184. * math.
  1185. */
  1186. quat_q14[0] = quat[0] >> 16;
  1187. quat_q14[1] = quat[1] >> 16;
  1188. quat_q14[2] = quat[2] >> 16;
  1189. quat_q14[3] = quat[3] >> 16;
  1190. quat_mag_sq = quat_q14[0] * quat_q14[0] + quat_q14[1] * quat_q14[1] +
  1191. quat_q14[2] * quat_q14[2] + quat_q14[3] * quat_q14[3];
  1192. if ((quat_mag_sq < QUAT_MAG_SQ_MIN) ||
  1193. (quat_mag_sq > QUAT_MAG_SQ_MAX)) {
  1194. /* Quaternion is outside of the acceptable threshold. */
  1195. mpu_reset_fifo();
  1196. sensors[0] = 0;
  1197. return -1;
  1198. }
  1199. sensors[0] |= INV_WXYZ_QUAT;
  1200. #endif
  1201. }
  1202. if (dmp.feature_mask & DMP_FEATURE_SEND_RAW_ACCEL) {
  1203. accel[0] = ((short)fifo_data[ii+0] << 8) | fifo_data[ii+1];
  1204. accel[1] = ((short)fifo_data[ii+2] << 8) | fifo_data[ii+3];
  1205. accel[2] = ((short)fifo_data[ii+4] << 8) | fifo_data[ii+5];
  1206. ii += 6;
  1207. sensors[0] |= INV_XYZ_ACCEL;
  1208. }
  1209. if (dmp.feature_mask & DMP_FEATURE_SEND_ANY_GYRO) {
  1210. gyro[0] = ((short)fifo_data[ii+0] << 8) | fifo_data[ii+1];
  1211. gyro[1] = ((short)fifo_data[ii+2] << 8) | fifo_data[ii+3];
  1212. gyro[2] = ((short)fifo_data[ii+4] << 8) | fifo_data[ii+5];
  1213. ii += 6;
  1214. sensors[0] |= INV_XYZ_GYRO;
  1215. }
  1216. /* Gesture data is at the end of the DMP packet. Parse it and call
  1217. * the gesture callbacks (if registered).
  1218. */
  1219. if (dmp.feature_mask & (DMP_FEATURE_TAP | DMP_FEATURE_ANDROID_ORIENT))
  1220. decode_gesture(fifo_data + ii);
  1221. get_ms(timestamp);
  1222. return 0;
  1223. }
  1224. /**
  1225. * @brief Register a function to be executed on a tap event.
  1226. * The tap direction is represented by one of the following:
  1227. * \n TAP_X_UP
  1228. * \n TAP_X_DOWN
  1229. * \n TAP_Y_UP
  1230. * \n TAP_Y_DOWN
  1231. * \n TAP_Z_UP
  1232. * \n TAP_Z_DOWN
  1233. * @param[in] func Callback function.
  1234. * @return 0 if successful.
  1235. */
  1236. int dmp_register_tap_cb(void (*func)(unsigned char, unsigned char))
  1237. {
  1238. dmp.tap_cb = func;
  1239. return 0;
  1240. }
  1241. /**
  1242. * @brief Register a function to be executed on a android orientation event.
  1243. * @param[in] func Callback function.
  1244. * @return 0 if successful.
  1245. */
  1246. int dmp_register_android_orient_cb(void (*func)(unsigned char))
  1247. {
  1248. dmp.android_orient_cb = func;
  1249. return 0;
  1250. }
  1251. /**
  1252. * @}
  1253. */