inv_mpu_dmp_motion_driver.c 56 KB

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