| LibDriver MPU9250 1.0.0 MPU9250 full function driver

driver_mpu9250.c
Go to the documentation of this file.
1
37 #include "driver_mpu9250.h"
38 #include "driver_mpu9250_code.h"
39 #include <math.h>
40
44 #define CHIP_NAME "TDK MPU9250"
45 #define MANUFACTURER_NAME "TDK"
46 #define SUPPLY_VOLTAGE_MIN 2.4f
47 #define SUPPLY_VOLTAGE_MAX 3.6f
48 #define MAX_CURRENT 3.7f
49 #define TEMPERATURE_MIN -40.0f
50 #define TEMPERATURE_MAX 85.0f
51 #define DRIVER_VERSION 1000
56 #define AK8963_IIC_ADDRESS 0x0C
61 #define MPU9250_REG_SELF_TEST_X_GYRO 0x00
62 #define MPU9250_REG_SELF_TEST_Y_GYRO 0x01
63 #define MPU9250_REG_SELF_TEST_Z_GYRO 0x02
64 #define MPU9250_REG_SELF_TEST_X_ACCEL 0x0D
65 #define MPU9250_REG_SELF_TEST_Y_ACCEL 0x0E
66 #define MPU9250_REG_SELF_TEST_Z_ACCEL 0x0F
67 #define MPU9250_REG_XG_OFFSET_H 0x13
68 #define MPU9250_REG_XG_OFFSET_L 0x14
69 #define MPU9250_REG_YG_OFFSET_H 0x15
70 #define MPU9250_REG_YG_OFFSET_L 0x16
71 #define MPU9250_REG_ZG_OFFSET_H 0x17
72 #define MPU9250_REG_ZG_OFFSET_L 0x18
73 #define MPU9250_REG_SMPRT_DIV 0x19
74 #define MPU9250_REG_CONFIG 0x1A
75 #define MPU9250_REG_GYRO_CONFIG 0x1B
76 #define MPU9250_REG_ACCEL_CONFIG 0x1C
77 #define MPU9250_REG_ACCEL_CONFIG2 0x1D
78 #define MPU9250_REG_LP_ACCEL_ODR 0x1E
79 #define MPU9250_REG_WOM_THR 0x1F
80 #define MPU9250_REG_MOTION_DURATION 0x20
81 #define MPU9250_REG_FIFO_EN 0x23
82 #define MPU9250_REG_I2C_MST_CTRL 0x24
83 #define MPU9250_REG_I2C_MST_STATUS 0x36
84 #define MPU9250_REG_I2C_MST_DELAY_CTRL 0x67
85 #define MPU9250_REG_I2C_SLV0_ADDR 0x25
86 #define MPU9250_REG_I2C_SLV0_REG 0x26
87 #define MPU9250_REG_I2C_SLV0_CTRL 0x27
88 #define MPU9250_REG_I2C_SLV0_DO 0x63
89 #define MPU9250_REG_I2C_SLV1_ADDR 0x28
90 #define MPU9250_REG_I2C_SLV1_REG 0x29
91 #define MPU9250_REG_I2C_SLV1_CTRL 0x2A
92 #define MPU9250_REG_I2C_SLV1_DO 0x64
93 #define MPU9250_REG_I2C_SLV2_ADDR 0x2B
94 #define MPU9250_REG_I2C_SLV2_REG 0x2C
95 #define MPU9250_REG_I2C_SLV2_CTRL 0x2D
96 #define MPU9250_REG_I2C_SLV2_DO 0x65
97 #define MPU9250_REG_I2C_SLV3_ADDR 0x2E
98 #define MPU9250_REG_I2C_SLV3_REG 0x2F
99 #define MPU9250_REG_I2C_SLV3_CTRL 0x30
100 #define MPU9250_REG_I2C_SLV3_DO 0x66
101 #define MPU9250_REG_I2C_SLV4_ADDR 0x31
102 #define MPU9250_REG_I2C_SLV4_REG 0x32
103 #define MPU9250_REG_I2C_SLV4_CTRL 0x34
104 #define MPU9250_REG_I2C_SLV4_DO 0x33
105 #define MPU9250_REG_I2C_SLV4_DI 0x35
106 #define MPU9250_REG_EXT_SENS_DATA_00 0x49
107 #define MPU9250_REG_INT_PIN_CFG 0x37
108 #define MPU9250_REG_INT_ENABLE 0x38
109 #define MPU9250_REG_INT_STATUS 0x3A
110 #define MPU9250_REG_ACCEL_XOUT_H 0x3B
111 #define MPU9250_REG_ACCEL_XOUT_L 0x3C
112 #define MPU9250_REG_ACCEL_YOUT_H 0x3D
113 #define MPU9250_REG_ACCEL_YOUT_L 0x3E
114 #define MPU9250_REG_ACCEL_ZOUT_H 0x3F
115 #define MPU9250_REG_ACCEL_ZOUT_L 0x40
116 #define MPU9250_REG_TEMP_OUT_H 0x41
117 #define MPU9250_REG_TEMP_OUT_L 0x42
118 #define MPU9250_REG_GYRO_XOUT_H 0x43
119 #define MPU9250_REG_GYRO_XOUT_L 0x44
120 #define MPU9250_REG_GYRO_YOUT_H 0x45
121 #define MPU9250_REG_GYRO_YOUT_L 0x46
122 #define MPU9250_REG_GYRO_ZOUT_H 0x47
123 #define MPU9250_REG_GYRO_ZOUT_L 0x48
124 #define MPU9250_REG_SIGNAL_PATH_RESET 0x68
125 #define MPU9250_REG_MOT_DETECT_CTRL 0x69
126 #define MPU9250_REG_USER_CTRL 0x6A
127 #define MPU9250_REG_PWR_MGMT_1 0x6B
128 #define MPU9250_REG_PWR_MGMT_2 0x6C
129 #define MPU9250_REG_BANK_SEL 0x6D
130 #define MPU9250_REG_MEM 0x6F
131 #define MPU9250_REG_PROGRAM_START 0x70
132 #define MPU9250_REG_FIFO_COUNTH 0x72
133 #define MPU9250_REG_FIFO_COUNTL 0x73
134 #define MPU9250_REG_R_W 0x74
135 #define MPU9250_REG_WHO_AM_I 0x75
136 #define MPU9250_REG_XA_OFFSET_H 0x77
137 #define MPU9250_REG_XA_OFFSET_L 0x78
138 #define MPU9250_REG_YA_OFFSET_H 0x7A
139 #define MPU9250_REG_YA_OFFSET_L 0x7B
140 #define MPU9250_REG_ZA_OFFSET_H 0x7D
141 #define MPU9250_REG_ZA_OFFSET_L 0x7E
142 #define AK8963_REG_WIA 0x00
143 #define AK8963_REG_INFO 0x01
144 #define AK8963_REG_ST1 0x02
145 #define AK8963_REG_HXL 0x03
146 #define AK8963_REG_HXH 0x04
147 #define AK8963_REG_HYL 0x05
148 #define AK8963_REG_HYH 0x06
149 #define AK8963_REG_HZL 0x07
150 #define AK8963_REG_HZH 0x08
151 #define AK8963_REG_ST2 0x09
152 #define AK8963_REG_CNTL1 0x0A
153 #define AK8963_REG_CNTL2 0x0B
154 #define AK8963_REG_ASTC 0x0C
155 #define AK8963_REG_TS1 0x0D
156 #define AK8963_REG_TS2 0x0E
157 #define AK8963_REG_I2CDIS 0x0F
158 #define AK8963_REG_ASAX 0x10
159 #define AK8963_REG_ASAY 0x11
160 #define AK8963_REG_ASAZ 0x12
165 #define MPU9250_DMP_SAMPLE_RATE 200
166 #define MPU9250_DMP_GYRO_SF (46850825LL * 200 / MPU9250_DMP_SAMPLE_RATE)
167 #define MPU9250_DMP_D_PEDSTD_TIMECTR 964
168 #define MPU9250_DMP_D_PEDSTD_STEPCTR (768 + 0x60)
169 #define MPU9250_DMP_D_1_36 (256 + 36)
170 #define MPU9250_DMP_D_1_40 (256 + 40)
171 #define MPU9250_DMP_D_1_44 (256 + 44)
172 #define MPU9250_DMP_D_1_72 (256 + 72)
173 #define MPU9250_DMP_D_1_79 (256 + 79)
174 #define MPU9250_DMP_D_1_88 (256 + 88)
175 #define MPU9250_DMP_D_1_90 (256 + 90)
176 #define MPU9250_DMP_D_1_92 (256 + 92)
177 #define MPU9250_DMP_D_1_218 (256 + 218)
178 #define MPU9250_DMP_D_0_22 (512 + 22)
179 #define MPU9250_DMP_D_0_104 104
180 #define MPU9250_DMP_TAPW_MIN 478
181 #define MPU9250_DMP_TAP_THX 468
182 #define MPU9250_DMP_TAP_THY 472
183 #define MPU9250_DMP_TAP_THZ 476
184 #define MPU9250_DMP_CFG_6 2753
185 #define MPU9250_DMP_CFG_8 2718
186 #define MPU9250_DMP_CFG_MOTION_BIAS 1208
187 #define MPU9250_DMP_CFG_LP_QUAT 2712
188 #define MPU9250_DMP_CFG_FIFO_ON_EVENT 2690
189 #define MPU9250_DMP_FCFG_1 1062
190 #define MPU9250_DMP_FCFG_2 1066
191 #define MPU9250_DMP_FCFG_3 1088
192 #define MPU9250_DMP_FCFG_7 1073
193 #define MPU9250_DMP_D_EXT_GYRO_BIAS_X (61 * 16)
194 #define MPU9250_DMP_D_EXT_GYRO_BIAS_Y (61 * 16 + 4)
195 #define MPU9250_DMP_D_EXT_GYRO_BIAS_Z (61 * 16 + 8)
196 #define MPU9250_DMP_D_ACCEL_BIAS 660
197 #define MPU9250_DMP_FEATURE_SEND_ANY_GYRO (MPU9250_DMP_FEATURE_SEND_RAW_GYRO | \
198 MPU9250_DMP_FEATURE_SEND_CAL_GYRO)
199 #define MPU9250_DMP_CFG_15 2727
200 #define MPU9250_DMP_CFG_27 2742
201 #define MPU9250_DMP_CFG_GYRO_RAW_DATA 2722
202 #define MPU9250_DMP_CFG_20 2224
203 #define MPU9250_DMP_CFG_ORIENT_INT 1853
204 #define MPU9250_DMP_QUAT_ERROR_THRESH (1L << 24)
205 #define MPU9250_DMP_QUAT_MAG_SQ_NORMALIZED (1L << 28)
206 #define MPU9250_DMP_QUAT_MAG_SQ_MIN (MPU9250_DMP_QUAT_MAG_SQ_NORMALIZED - \
207 MPU9250_DMP_QUAT_ERROR_THRESH)
208 #define MPU9250_DMP_QUAT_MAG_SQ_MAX (MPU9250_DMP_QUAT_MAG_SQ_NORMALIZED + \
209 MPU9250_DMP_QUAT_ERROR_THRESH)
210 #define MPU9250_DMP_INT_SRC_TAP 0x01
211 #define MPU9250_DMP_INT_SRC_ORIENT 0x08
212 #define MPU9250_DMP_TAP_THRESH 250
213 #define MPU9250_DMP_TAP_MIN_TAP_COUNT 1
214 #define MPU9250_DMP_TAP_TIME 100
215 #define MPU9250_DMP_TAP_TIME_MULTI 200
216 #define MPU9250_DMP_SHAKE_REJECT_THRESH 200
217 #define MPU9250_DMP_SHAKE_REJECT_TIME 40
218 #define MPU9250_DMP_SHAKE_REJECT_TIMEOUT 10
223 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
228 static uint16_t gs_st_tb[256] =
229 {
230 2620, 2646, 2672, 2699, 2726, 2753, 2781, 2808,
231 2837, 2865, 2894, 2923, 2952, 2981, 3011, 3041,
232 3072, 3102, 3133, 3165, 3196, 3228, 3261, 3293,
233 3326, 3359, 3393, 3427, 3461, 3496, 3531, 3566,
234 3602, 3638, 3674, 3711, 3748, 3786, 3823, 3862,
235 3900, 3939, 3979, 4019, 4059, 4099, 4140, 4182,
236 4224, 4266, 4308, 4352, 4395, 4439, 4483, 4528,
237 4574, 4619, 4665, 4712, 4759, 4807, 4855, 4903,
238 4953, 5002, 5052, 5103, 5154, 5205, 5257, 5310,
239 5363, 5417, 5471, 5525, 5581, 5636, 5693, 5750,
240 5807, 5865, 5924, 5983, 6043, 6104, 6165, 6226,
241 6289, 6351, 6415, 6479, 6544, 6609, 6675, 6742,
242 6810, 6878, 6946, 7016, 7086, 7157, 7229, 7301,
243 7374, 7448, 7522, 7597, 7673, 7750, 7828, 7906,
244 7985, 8065, 8145, 8227, 8309, 8392, 8476, 8561,
245 8647, 8733, 8820, 8909, 8998, 9088, 9178, 9270,
246 9363, 9457, 9551, 9647, 9743, 9841, 9939, 10038,
247 10139, 10240, 10343, 10446, 10550, 10656, 10763, 10870,
248 10979, 11089, 11200, 11312, 11425, 11539, 11654, 11771,
249 11889, 12008, 12128, 12249, 12371, 12495, 12620, 12746,
250 12874, 13002, 13132, 13264, 13396, 13530, 13666, 13802,
251 13940, 14080, 14221, 14363, 14506, 14652, 14798, 14946,
252 15096, 15247, 15399, 15553, 15709, 15866, 16024, 16184,
253 16346, 16510, 16675, 16842, 17010, 17180, 17352, 17526,
254 17701, 17878, 18057, 18237, 18420, 18604, 18790, 18978,
255 19167, 19359, 19553, 19748, 19946, 20145, 20347, 20550,
256 20756, 20963, 21173, 21385, 21598, 21814, 22033, 22253,
257 22475, 22700, 22927, 23156, 23388, 23622, 23858, 24097,
258 24338, 24581, 24827, 25075, 25326, 25579, 25835, 26093,
259 26354, 26618, 26884, 27153, 27424, 27699, 27976, 28255,
260 28538, 28823, 29112, 29403, 29697, 29994, 30294, 30597,
261 30903, 31212, 31524, 31839, 32157, 32479, 32804, 33132,
262 };
263
275 static uint8_t a_mpu9250_read(mpu9250_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
276 {
277 if (handle->iic_spi == MPU9250_INTERFACE_IIC) /* if iic interface */
278 {
279 if (handle->iic_read(handle->iic_addr, reg, (uint8_t *)buf, len) != 0) /* read data */
280 {
281 return 1; /* return error */
282 }
283 else
284 {
285 return 0; /* success return 0 */
286 }
287 }
288 else /* spi interface */
289 {
290 if (handle->spi_read(reg | 0x80, (uint8_t *)buf, len) != 0) /* read data */
291 {
292 return 1; /* return error */
293 }
294 else
295 {
296 return 0; /* success return 0 */
297 }
298 }
299 }
300
312 static uint8_t a_mpu9250_write(mpu9250_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
313 {
314 if (handle->iic_spi == MPU9250_INTERFACE_IIC) /* if iic interface */
315 {
316 if (handle->iic_write(handle->iic_addr, reg, (uint8_t *)buf, len) != 0) /* write data */
317 {
318 return 1; /* return error */
319 }
320 else
321 {
322 return 0; /* success return 0 */
323 }
324 }
325 else /* spi interface */
326 {
327 if (handle->spi_write(reg & (~0x80), (uint8_t *)buf, len) != 0) /* write data */
328 {
329 return 1; /* return error */
330 }
331 else
332 {
333 return 0; /* success return 0 */
334 }
335 }
336 }
337
348 static uint8_t a_mpu9250_mag_write(mpu9250_handle_t *handle, uint8_t reg, uint8_t *data)
349 {
350 if (handle->iic_spi == MPU9250_INTERFACE_IIC) /* if iic interface */
351 {
352 if (handle->iic_write(AK8963_IIC_ADDRESS << 1, reg, (uint8_t *)data, 1) != 0) /* write data */
353 {
354 return 1; /* return error */
355 }
356 else
357 {
358 return 0; /* success return 0 */
359 }
360 }
361 else /* spi interface */
362 {
363 return 1;
364 }
365 }
366
378 static uint8_t a_mpu9250_mag_read(mpu9250_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
379 {
380 if (handle->iic_spi == MPU9250_INTERFACE_IIC) /* if iic interface */
381 {
382 if (handle->iic_read(AK8963_IIC_ADDRESS << 1, reg, (uint8_t *)buf, len) != 0) /* read data */
383 {
384 return 1; /* return error */
385 }
386 else
387 {
388 return 0; /* success return 0 */
389 }
390 }
391 else /* spi interface */
392 {
393 return 1;
394 }
395 }
396
409 static uint8_t a_mpu9250_write_mem(mpu9250_handle_t *handle, uint16_t addr, uint8_t *buf, uint16_t len)
410 {
411 uint8_t tmp[2];
412
413 tmp[0] = (addr >> 8) & 0xFF; /* set the addr high */
414 tmp[1] = (addr >> 0) & 0xFF; /* set the addr low */
415
416 if (tmp[1] + len > 256) /* check the range */
417 {
418 return 2; /* return error */
419 }
420
421 if (handle->iic_spi == MPU9250_INTERFACE_IIC) /* if iic interface */
422 {
423 if (handle->iic_write(handle->iic_addr, MPU9250_REG_BANK_SEL, (uint8_t *)tmp, 2) != 0) /* write data */
424 {
425 return 1; /* return error */
426 }
427 if (handle->iic_write(handle->iic_addr, MPU9250_REG_MEM, (uint8_t *)buf, len) != 0) /* write data */
428 {
429 return 1; /* return error */
430 }
431 }
432 else /* if spi interface */
433 {
434 if (handle->spi_write(MPU9250_REG_BANK_SEL & (~0x80), (uint8_t *)tmp, 2) != 0) /* write data */
435 {
436 return 1; /* return error */
437 }
438 if (handle->spi_write(MPU9250_REG_MEM & (~0x80), (uint8_t *)buf, len) != 0) /* write data */
439 {
440 return 1; /* return error */
441 }
442 }
443
444 return 0; /* success return 0 */
445 }
446
459 static uint8_t a_mpu9250_read_mem(mpu9250_handle_t *handle, uint16_t addr, uint8_t *buf, uint16_t len)
460 {
461 uint8_t tmp[2];
462
463 tmp[0] = (addr >> 8) & 0xFF; /* set the addr high */
464 tmp[1] = (addr >> 0) & 0xFF; /* set the addr low */
465
466 if (tmp[1] + len > 256) /* check the range */
467 {
468 return 2; /* return error */
469 }
470
471 if (handle->iic_spi == MPU9250_INTERFACE_IIC) /* if iic interface */
472 {
473 if (handle->iic_write(handle->iic_addr, MPU9250_REG_BANK_SEL, (uint8_t *)tmp, 2) != 0) /* write data */
474 {
475 return 1; /* return error */
476 }
477 if (handle->iic_read(handle->iic_addr, MPU9250_REG_MEM, (uint8_t *)buf, len) != 0) /* read data */
478 {
479 return 1; /* return error */
480 }
481 }
482 else /* if spi interface */
483 {
484 if (handle->spi_write(MPU9250_REG_BANK_SEL & (~0x80), (uint8_t *)tmp, 2) != 0) /* write data */
485 {
486 return 1; /* return error */
487 }
488 if (handle->spi_read(MPU9250_REG_MEM | 0x80, (uint8_t *)buf, len) != 0) /* read data */
489 {
490 return 1; /* return error */
491 }
492 }
493
494 return 0; /* success return 0 */
495 }
496
504 static uint8_t a_mpu9250_reset_fifo(mpu9250_handle_t *handle)
505 {
506 uint8_t res;
507 uint8_t prev;
508 uint8_t int_enable;
509 uint8_t fifo_enable;
510 uint8_t user_ctrl;
511
512 res = a_mpu9250_read(handle, MPU9250_REG_INT_ENABLE, &int_enable, 1); /* read the int enable */
513 if (res != 0) /* check the result */
514 {
515 handle->debug_print("mpu9250: read int enable register failed.\n"); /* read int enable register failed */
516
517 return 1; /* return error */
518 }
519 res = a_mpu9250_read(handle, MPU9250_REG_FIFO_EN, &fifo_enable, 1); /* read the fifo enable */
520 if (res != 0) /* check the result */
521 {
522 handle->debug_print("mpu9250: read fifo enable register failed.\n"); /* read fifo enable register failed */
523
524 return 1; /* return error */
525 }
526 res = a_mpu9250_read(handle, MPU9250_REG_USER_CTRL, &user_ctrl, 1); /* read the user ctrl */
527 if (res != 0) /* check the result */
528 {
529 handle->debug_print("mpu9250: read user ctrl register failed.\n"); /* read user ctrl register failed */
530
531 return 1; /* return error */
532 }
533
534 prev = 0; /* set 0 */
535 res = a_mpu9250_write(handle, MPU9250_REG_INT_ENABLE, &prev, 1); /* disable all interrupt */
536 if (res != 0) /* check the result */
537 {
538 handle->debug_print("mpu9250: write int enable register failed.\n"); /* write int enable register failed */
539
540 return 1; /* return error */
541 }
542 prev = 0; /* set 0 */
543 res = a_mpu9250_write(handle, MPU9250_REG_FIFO_EN, &prev, 1); /* disable all fifo */
544 if (res != 0) /* check the result */
545 {
546 handle->debug_print("mpu9250: write fifo enable register failed.\n"); /* write fifo enable register failed */
547
548 return 1; /* return error */
549 }
550 user_ctrl &= ~(1 << 6); /* disable the fifo */
551 user_ctrl &= ~(1 << 7); /* disable the dmp */
552 if (handle->dmp_inited == 1) /* if we use dmp */
553 {
554 user_ctrl |= (1 << 2) | (1 << 3); /* reset the fifo and dmp */
555 }
556 else
557 {
558 user_ctrl |= 1 << 2; /* reset the fifo */
559 }
560 res = a_mpu9250_write(handle, MPU9250_REG_USER_CTRL, &user_ctrl, 1); /* write the user ctrl */
561 if (res != 0) /* check the result */
562 {
563 handle->debug_print("mpu9250: write user ctrl register failed.\n"); /* write user ctrl register failed */
564
565 return 1; /* return error */
566 }
567 handle->delay_ms(50); /* delay 50 ms */
568 if (handle->dmp_inited == 1) /* if we use dmp */
569 {
570 user_ctrl |= (1 << 6) | (1 << 7); /* enable fifo and dmp */
571 }
572 else
573 {
574 user_ctrl |= 1 << 6; /* enable fifo */
575 }
576 res = a_mpu9250_write(handle, MPU9250_REG_USER_CTRL, &user_ctrl, 1); /* write the user ctrl */
577 if (res != 0) /* check the result */
578 {
579 handle->debug_print("mpu9250: write user ctrl register failed.\n"); /* write user ctrl register failed */
580
581 return 1; /* return error */
582 }
583
584 res = a_mpu9250_write(handle, MPU9250_REG_INT_ENABLE, &int_enable, 1); /* restore the int enable */
585 if (res != 0) /* check the result */
586 {
587 handle->debug_print("mpu9250: write int enable register failed.\n"); /* write int enable register failed */
588
589 return 1; /* return error */
590 }
591 res = a_mpu9250_write(handle, MPU9250_REG_FIFO_EN, &fifo_enable, 1); /* restore the fifo enable */
592 if (res != 0) /* check the result */
593 {
594 handle->debug_print("mpu9250: write fifo enable register failed.\n"); /* write fifo enable register failed */
595
596 return 1; /* return error */
597 }
598
599 return 0; /* success return 0 */
600 }
601
608 static uint16_t a_mpu9250_inv_row_2_scale(int8_t *row)
609 {
610 uint16_t b;
611
612 if (row[0] > 0) /* check row 0 */
613 {
614 b = 0; /* set 0 */
615 }
616 else if (row[0] < 0) /* check row 0 */
617 {
618 b = 4; /* set 4 */
619 }
620 else if (row[1] > 0) /* check row 1 */
621 {
622 b = 1; /* set 1 */
623 }
624 else if (row[1] < 0) /* check row 1 */
625 {
626 b = 5; /* set 5 */
627 }
628 else if (row[2] > 0) /* check row 2 */
629 {
630 b = 2; /* set 2 */
631 }
632 else if (row[2] < 0) /* check row 2 */
633 {
634 b = 6; /* set 6 */
635 }
636 else
637 {
638 b = 7; /* set 7 */
639 }
640
641 return b; /* return scale */
642 }
643
650 static uint16_t a_mpu9250_inv_orientation_matrix_to_scalar(int8_t *mtx)
651 {
652 uint16_t scalar;
653
654 scalar = a_mpu9250_inv_row_2_scale(mtx); /* convert the part 0 */
655 scalar |= a_mpu9250_inv_row_2_scale(mtx + 3) << 3; /* convert the part 1 */
656 scalar |= a_mpu9250_inv_row_2_scale(mtx + 6) << 6; /* convert the part 2 */
657
658 return scalar; /* return the scalar */
659 }
660
666 static void a_mpu9250_dmp_decode_gesture(mpu9250_handle_t *handle, uint8_t gesture[4])
667 {
668 uint8_t tap;
669 uint8_t orient;
670
671 orient = gesture[3] & 0xC0; /* set the orient */
672 tap = 0x3F & gesture[3]; /* set the tap */
673 if ((gesture[1] & MPU9250_DMP_INT_SRC_TAP) != 0) /* check the tap output */
674 {
675 uint8_t direction, count;
676
677 direction = tap >> 3; /* get the direction */
678 count = (tap % 8) + 1; /* get the count */
679 if (handle->dmp_tap_callback != NULL) /* check the dmp tap callback */
680 {
681 handle->dmp_tap_callback(direction, count); /* run the dmp tap callback */
682 }
683 }
684 if ((gesture[1] & MPU9250_DMP_INT_SRC_ORIENT) != 0) /* check the orient output */
685 {
686 if (handle->dmp_orient_callback != NULL) /* check the dmp orient callback */
687 {
688 handle->dmp_orient_callback(orient >> 6); /* run the dmp orient callback */
689 }
690 }
691 }
692
703 static uint8_t a_mpu9250_accel_self_test(mpu9250_handle_t *handle, int32_t *bias_regular, int32_t *bias_st)
704 {
705 uint8_t res;
706 uint8_t i;
707 uint8_t otp_value_zero;
708 uint8_t regs[3];
709 float accel_st_al_min;
710 float accel_st_al_max;
711 float accel_offset_max;
712 float st_shift_cust[3];
713 float st_shift_ratio[3];
714 float ct_shift_prod[3];
715
716 res = a_mpu9250_read(handle, MPU9250_REG_SELF_TEST_X_ACCEL, regs, 3); /* read the tmp */
717 if (res != 0) /* check the result */
718 {
719 return 1; /* return error */
720 }
721
722 otp_value_zero = 0;
723 for (i = 0; i < 3; i++) /* 3 times */
724 {
725 if (regs[i] != 0) /* check the regs */
726 {
727 ct_shift_prod[i] = (float)gs_st_tb[regs[i] - 1]; /* get the table */
728 ct_shift_prod[i] *= 65536.f; /* x65535.0f */
729 ct_shift_prod[i] /= 16384.0f; /* 2g */
730 }
731 else
732 {
733 ct_shift_prod[i] = 0.0f; /* init 0.0f */
734 otp_value_zero = 1; /* check otp value zero */
735 }
736 }
737 if (otp_value_zero == 0) /* check otp value zero */
738 {
739 for (i = 0; i < 3; i++) /* 3 times */
740 {
741 st_shift_cust[i] = (float)(bias_st[i] - bias_regular[i]); /* set the shift cust */
742 st_shift_ratio[i] = st_shift_cust[i] / ct_shift_prod[i] - 1.f; /* set the shift ratio */
743 if (fabsf(st_shift_ratio[i]) > 0.5f) /* check the shift ratio */
744 {
745 return 1; /* return error */
746 }
747 }
748 }
749 else
750 {
751 accel_st_al_min = 0.225f * 65536.f; /* set the st al min */
752 accel_st_al_max = 0.675f * 65536.f; /* set the st al max */
753 for (i = 0; i < 3; i++) /* 3 times */
754 {
755 st_shift_cust[i] = (float)(bias_st[i] - bias_regular[i]); /* shift cust */
756 if (st_shift_cust[i] < accel_st_al_min
757 || st_shift_cust[i] > accel_st_al_max) /* check the result */
758 {
759 return 1; /* return error */
760 }
761 }
762 }
763
764 accel_offset_max = 0.5f * 65536.f; /* set the offset max */
765 for (i = 0; i < 3; i++) /* 3 times */
766 {
767 if (fabsf((float)bias_regular[i]) > accel_offset_max) /* check offset */
768 {
769 return 1; /* return error */
770 }
771 }
772
773 return 0; /* success return 0 */
774 }
775
786 static uint8_t a_mpu9250_gyro_self_test(mpu9250_handle_t *handle, int32_t *bias_regular, int32_t *bias_st)
787 {
788 uint8_t res;
789 uint8_t i;
790 uint8_t otp_value_zero;
791 float gyro_st_al_max;
792 float gyro_offset_max;
793 float st_shift_cust[3];
794 float st_shift_ratio[3];
795 float ct_shift_prod[3];
796 uint8_t regs[3];
797
798 res = a_mpu9250_read(handle, MPU9250_REG_SELF_TEST_X_GYRO, regs, 3); /* read the tmp */
799 if (res != 0) /* check the result */
800 {
801 return 1; /* return error */
802 }
803
804 otp_value_zero = 0; /* init otp value zero 0.0f */
805 for (i = 0; i < 3; i++) /* 3 times */
806 {
807 if (regs[i] != 0) /* check regs */
808 {
809 ct_shift_prod[i] = (float)gs_st_tb[regs[i] - 1]; /* set shift prod */
810 ct_shift_prod[i] *= 65536.f; /* x65536.0f */
811 ct_shift_prod[i] /= 131.0f; /* 250dps */
812 }
813 else
814 {
815 ct_shift_prod[i] = 0; /* init 0.0f */
816 otp_value_zero = 1; /* set otp value zero 1 */
817 }
818 }
819
820 if (otp_value_zero == 0) /* if otp value zero == 0 */
821 {
822 for (i = 0; i < 3; i++) /* 3 times */
823 {
824 st_shift_cust[i] = (float)(bias_st[i] - bias_regular[i]); /* shift cust */
825 st_shift_ratio[i] = st_shift_cust[i] / ct_shift_prod[i]; /* shift ratio */
826 if (fabsf(st_shift_ratio[i]) < 0.5f) /* check ratio */
827 {
828 return 1; /* return error */
829 }
830 }
831 }
832 else
833 {
834 gyro_st_al_max = 60.f * 65536.f; /* set st al max */
835 for (i = 0; i < 3; i++) /* 3 times */
836 {
837 st_shift_cust[i] = (float)(bias_st[i] - bias_regular[i]); /* set cust */
838 if (st_shift_cust[i] < gyro_st_al_max) /* check st al max */
839 {
840 return 1; /* return error */
841 }
842 }
843 }
844
845 gyro_offset_max = 20.f * 65536.f; /* set gyro offset max */
846 for (i = 0; i < 3; i++) /* 3 times */
847 {
848 if( fabsf((float)bias_regular[i]) > gyro_offset_max) /* check gyro offset max */
849 {
850 return 1; /* return error */
851 }
852 }
853
854 return 0; /* success return 0 */
855 }
856
868 static uint8_t a_mpu9250_get_st_biases(mpu9250_handle_t *handle,
869 int32_t gyro_offset[3], int32_t accel_offset[3],
870 uint8_t hw_test_enable)
871 {
872 uint8_t res;
873 uint16_t cnt;
874 uint16_t pack_cnt;
875 uint16_t i;
876 uint8_t data[12];
877
878 data[0] = 0x01; /* set 0x01 */
879 data[1] = 0x00; /* set 0x00 */
880 res = a_mpu9250_write(handle, MPU9250_REG_PWR_MGMT_1, data, 2); /* write pwr mgmt1 */
881 if (res != 0) /* check the result */
882 {
883 return 1; /* return error */
884 }
885 handle->delay_ms(200); /* delay 200ms */
886 data[0] = 0; /* set 0 */
887 res = a_mpu9250_write(handle, MPU9250_REG_INT_ENABLE, data, 1); /* write int enable */
888 if (res != 0) /* check the result */
889 {
890 return 1; /* return error */
891 }
892 res = a_mpu9250_write(handle, MPU9250_REG_FIFO_EN, data, 1); /* write the fifo enable */
893 if (res != 0) /* check the result */
894 {
895 return 1; /* return error */
896 }
897 res = a_mpu9250_write(handle, MPU9250_REG_PWR_MGMT_1, data, 1); /* write the pwr mgmt 1 */
898 if (res != 0) /* check the result */
899 {
900 return 1; /* return error */
901 }
902 res = a_mpu9250_write(handle, MPU9250_REG_I2C_MST_CTRL, data, 1); /* write the i2c mst ctrl */
903 if (res != 0) /* check the result */
904 {
905 return 1; /* return error */
906 }
907 res = a_mpu9250_write(handle, MPU9250_REG_USER_CTRL, data, 1); /* write the user ctrl */
908 if (res != 0) /* check the result */
909 {
910 return 1; /* return error */
911 }
912
913 data[0] = 1 << 3 | 1 << 2; /* set fifo and dmp reset */
914 res = a_mpu9250_write(handle, MPU9250_REG_USER_CTRL, data, 1); /* write user ctrl */
915 if (res != 0) /* check the result */
916 {
917 return 1; /* return error */
918 }
919 handle->delay_ms(15); /* delay 15 ms */
920 data[0] = 0x01; /* set 0x01 */
921 res = a_mpu9250_write(handle, MPU9250_REG_CONFIG, data, 1); /* write config */
922 if (res != 0) /* check the result */
923 {
924 return 1; /* return error */
925 }
926 data[0] = 0x00; /* set 0 */
927 res = a_mpu9250_write(handle, MPU9250_REG_SMPRT_DIV, data, 1); /* write div */
928 if (res != 0) /* check the result */
929 {
930 return 1; /* return error */
931 }
932 if (hw_test_enable != 0) /* if enable */
933 {
934 data[0] = 0x00 | 0xE0; /* set 250dps and test */
935 }
936 else
937 {
938 data[0] = 0x00; /* set 250dps */
939 }
940 res = a_mpu9250_write(handle, MPU9250_REG_GYRO_CONFIG, data, 1); /* read the gyro config */
941 if (res != 0) /* check the result */
942 {
943 return 1; /* return error */
944 }
945 if (hw_test_enable != 0) /* if enable */
946 {
947 data[0] = 0x18 | 0xE0; /* enable 2g and test */
948 }
949 else
950 {
951 data[0] = 0x18; /* enable 2g */
952 }
953 res = a_mpu9250_write(handle, MPU9250_REG_ACCEL_CONFIG, data, 1); /* read the accel config */
954 if (res != 0) /* check the result */
955 {
956 return 1; /* return error */
957 }
958 if (hw_test_enable != 0) /* if enable */
959 {
960 handle->delay_ms(200); /* delay 200ms */
961 }
962
963 data[0] = 1 << 6; /* enable fifo */
964 res = a_mpu9250_write(handle, MPU9250_REG_USER_CTRL, data, 1); /* write user ctrl */
965 if (res != 0) /* check the result */
966 {
967 return 1; /* return error */
968 }
969 data[0] = 0x78; /* enable xyz */
970 res = a_mpu9250_write(handle, MPU9250_REG_FIFO_EN, data, 1); /* write fifo enable */
971 if (res != 0) /* check the result */
972 {
973 return 1; /* return error */
974 }
975 handle->delay_ms(50); /* delay 50 ms */
976 data[0] = 0x00; /* set disable */
977 res = a_mpu9250_write(handle, MPU9250_REG_FIFO_EN, data, 1); /* write fifo enable */
978 if (res != 0) /* check the result */
979 {
980 return 1; /* return error */
981 }
982
983 res = a_mpu9250_read(handle, MPU9250_REG_FIFO_COUNTH, data, 2); /* read fifo counter */
984 if (res != 0) /* check the result */
985 {
986 return 1; /* return error */
987 }
988 cnt = ((uint16_t)data[0] << 8) | data[1]; /* set the counter */
989 pack_cnt = cnt / 12; /* set the packet counter */
990
991 gyro_offset[0] = 0; /* gyro offset 0 */
992 gyro_offset[1] = 0; /* gyro offset 1 */
993 gyro_offset[2] = 0; /* gyro offset 2 */
994 accel_offset[0] = 0; /* accel offset 0 */
995 accel_offset[1] = 0; /* accel offset 1 */
996 accel_offset[2] = 0; /* accel offset 2 */
997 for (i = 0; i < pack_cnt; i++) /* packet counter */
998 {
999 int16_t accel_cur[3];
1000 int16_t gyro_cur[3];
1001
1002 res = a_mpu9250_read(handle, MPU9250_REG_R_W, data, 12); /* read data */
1003 if (res != 0) /* check the result */
1004 {
1005 return 1; /* return error */
1006 }
1007
1008 accel_cur[0] = ((int16_t)data[0] << 8) | data[1]; /* accel cur 0 */
1009 accel_cur[1] = ((int16_t)data[2] << 8) | data[3]; /* accel cur 1 */
1010 accel_cur[2] = ((int16_t)data[4] << 8) | data[5]; /* accel cur 2 */
1011 accel_offset[0] += (int32_t)accel_cur[0]; /* accel offset 0 */
1012 accel_offset[1] += (int32_t)accel_cur[1]; /* accel offset 1 */
1013 accel_offset[2] += (int32_t)accel_cur[2]; /* accel offset 2 */
1014 gyro_cur[0] = (((int16_t)data[6] << 8) | data[7]); /* gyro cur 0 */
1015 gyro_cur[1] = (((int16_t)data[8] << 8) | data[9]); /* gyro cur 1 */
1016 gyro_cur[2] = (((int16_t)data[10] << 8) | data[11]); /* gyro cur 2 */
1017 gyro_offset[0] += (int32_t)gyro_cur[0]; /* gyro offset 0 */
1018 gyro_offset[1] += (int32_t)gyro_cur[1]; /* gyro offset 1 */
1019 gyro_offset[2] += (int32_t)gyro_cur[2]; /* gyro offset 2 */
1020 }
1021
1022 gyro_offset[0] = (int32_t)(((int64_t)gyro_offset[0] << 16) / (32768 / 250) / pack_cnt); /* set the gyro offset 0 */
1023 gyro_offset[1] = (int32_t)(((int64_t)gyro_offset[1] << 16) / (32768 / 250) / pack_cnt); /* set the gyro offset 1 */
1024 gyro_offset[2] = (int32_t)(((int64_t)gyro_offset[2] << 16) / (32768 / 250) / pack_cnt); /* set the gyro offset 2 */
1025 accel_offset[0] = (int32_t)(((int64_t)accel_offset[0] << 16) / (32768 / 16) / pack_cnt); /* set the accel offset 0 */
1026 accel_offset[1] = (int32_t)(((int64_t)accel_offset[1] << 16) / (32768 / 16) / pack_cnt); /* set the accel offset 1 */
1027 accel_offset[2] = (int32_t)(((int64_t)accel_offset[2] << 16) / (32768 / 16) / pack_cnt); /* set the accel offset 2 */
1028 if (accel_offset[2] > 0L) /* check the accel offset */
1029 {
1030 accel_offset[2] -= 65536L; /* -65536 */
1031 }
1032 else
1033 {
1034 accel_offset[2] += 65536L; /* +65536 */
1035 }
1036
1037 return 0; /* success return 0 */
1038 }
1039
1048 static uint8_t a_mpu9250_deinit(mpu9250_handle_t *handle)
1049 {
1050 if (handle->iic_spi == MPU9250_INTERFACE_IIC) /* if iic interface */
1051 {
1052 if (handle->iic_deinit() != 0) /* iic deinit */
1053 {
1054 return 1; /* return error */
1055 }
1056 else
1057 {
1058 return 0; /* success return 0 */
1059 }
1060 }
1061 else
1062 {
1063 if (handle->spi_deinit() != 0) /* if spi interface */
1064 {
1065 return 1; /* return error */
1066 }
1067 else
1068 {
1069 return 0; /* success return 0 */
1070 }
1071 }
1072 }
1073
1087 uint8_t mpu9250_dmp_load_firmware(mpu9250_handle_t *handle)
1088 {
1089 uint8_t res;
1090 uint16_t i;
1091 uint16_t size;
1092 uint16_t this_write;
1093 uint8_t tmp[2];
1094 uint8_t cur[16];
1095
1096 if (handle == NULL) /* check handle */
1097 {
1098 return 2; /* return error */
1099 }
1100 if (handle->inited != 1) /* check handle initialization */
1101 {
1102 return 3; /* return error */
1103 }
1104 if (handle->dmp_inited != 0) /* check dmp initialization */
1105 {
1106 handle->debug_print("mpu9250: dmp is running.\n"); /* dmp is running */
1107
1108 return 4; /* return error */
1109 }
1110
1111 size = MPU9250_DMP_CODE_SIZE; /* set the code size */
1112 for (i = 0; i < size; i += this_write) /* code size times */
1113 {
1114 this_write = MIN(16, size - i); /* get the written size */
1115
1116 res = a_mpu9250_write_mem(handle, i, (uint8_t *)(gs_mpu9250_dmp_code + i),
1117 this_write); /* write data */
1118 if (res != 0) /* check result */
1119 {
1120 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
1121
1122 return 1; /* return error */
1123 }
1124 res = a_mpu9250_read_mem(handle, i, cur, this_write); /* read data */
1125 if (res != 0) /* check result */
1126 {
1127 handle->debug_print("mpu9250: read mem failed.\n"); /* read mem failed */
1128
1129 return 1; /* return error */
1130 }
1131 if (memcmp(gs_mpu9250_dmp_code + i, cur, this_write) != 0) /* check the code */
1132 {
1133 handle->debug_print("mpu9250: code compare error.\n"); /* code compare error */
1134
1135 return 5; /* return error */
1136 }
1137 }
1138 tmp[0] = (0x0400 >> 8) & 0xFF; /* set the addr high */
1139 tmp[1] = (0x0400 >> 0) & 0xFF; /* set the addr low */
1140
1141 if (handle->iic_write(handle->iic_addr, MPU9250_REG_PROGRAM_START,
1142 (uint8_t *)tmp, 2) != 0) /* write data */
1143 {
1144 handle->debug_print("mpu9250: set program start failed.\n"); /* set program start failed */
1145
1146 return 6; /* return error */
1147 }
1148 handle->dmp_inited = 1; /* flag the dmp inited bit */
1149
1150 return 0; /* success return 0 */
1151 }
1152
1165 uint8_t mpu9250_dmp_set_pedometer_walk_time(mpu9250_handle_t *handle, uint32_t ms)
1166 {
1167 uint8_t res;
1168 uint8_t tmp[4];
1169
1170 if (handle == NULL) /* check handle */
1171 {
1172 return 2; /* return error */
1173 }
1174 if (handle->inited != 1) /* check handle initialization */
1175 {
1176 return 3; /* return error */
1177 }
1178 if (handle->dmp_inited != 1) /* check dmp initialization */
1179 {
1180 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
1181
1182 return 4; /* return error */
1183 }
1184
1185 ms /= 20; /* div 20 */
1186 tmp[0] = (uint8_t)((ms >> 24) & 0xFF); /* set part 0 */
1187 tmp[1] = (uint8_t)((ms >> 16) & 0xFF); /* set part 1 */
1188 tmp[2] = (uint8_t)((ms >> 8) & 0xFF); /* set part 2 */
1189 tmp[3] = (uint8_t)(ms & 0xFF); /* set part 3 */
1190
1191 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_PEDSTD_TIMECTR, tmp, 4); /* write data */
1192 if (res != 0) /* check result */
1193 {
1194 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
1195
1196 return 1; /* return error */
1197 }
1198
1199 return 0; /* success return 0 */
1200 }
1201
1214 uint8_t mpu9250_dmp_get_pedometer_walk_time(mpu9250_handle_t *handle, uint32_t *ms)
1215 {
1216 uint8_t res;
1217 uint8_t tmp[4];
1218
1219 if (handle == NULL) /* check handle */
1220 {
1221 return 2; /* return error */
1222 }
1223 if (handle->inited != 1) /* check handle initialization */
1224 {
1225 return 3; /* return error */
1226 }
1227 if (handle->dmp_inited != 1) /* check dmp initialization */
1228 {
1229 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
1230
1231 return 4; /* return error */
1232 }
1233
1234 res = a_mpu9250_read_mem(handle, MPU9250_DMP_D_PEDSTD_TIMECTR, tmp, 4); /* read data */
1235 if (res != 0) /* check result */
1236 {
1237 handle->debug_print("mpu9250: read mem failed.\n"); /* read mem failed */
1238
1239 return 1; /* return error */
1240 }
1241 *ms = (((uint32_t)tmp[0] << 24) | ((uint32_t)tmp[1] << 16) |
1242 ((uint32_t)tmp[2] << 8) | tmp[3]) * 20; /* get the ms */
1243
1244 return 0; /* success return 0 */
1245 }
1246
1259 uint8_t mpu9250_dmp_set_pedometer_step_count(mpu9250_handle_t *handle, uint32_t count)
1260 {
1261 uint8_t res;
1262 uint8_t tmp[4];
1263
1264 if (handle == NULL) /* check handle */
1265 {
1266 return 2; /* return error */
1267 }
1268 if (handle->inited != 1) /* check handle initialization */
1269 {
1270 return 3; /* return error */
1271 }
1272 if (handle->dmp_inited != 1) /* check dmp initialization */
1273 {
1274 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
1275
1276 return 4; /* return error */
1277 }
1278
1279 tmp[0] = (uint8_t)((count >> 24) & 0xFF); /* set part 0 */
1280 tmp[1] = (uint8_t)((count >> 16) & 0xFF); /* set part 1 */
1281 tmp[2] = (uint8_t)((count >> 8) & 0xFF); /* set part 2 */
1282 tmp[3] = (uint8_t)(count & 0xFF); /* set part 3 */
1283
1284 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_PEDSTD_STEPCTR, tmp, 4); /* write data */
1285 if (res != 0) /* check result */
1286 {
1287 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
1288
1289 return 1; /* return error */
1290 }
1291
1292 return 0; /* success return 0 */
1293 }
1294
1307 uint8_t mpu9250_dmp_get_pedometer_step_count(mpu9250_handle_t *handle, uint32_t *count)
1308 {
1309 uint8_t res;
1310 uint8_t tmp[4];
1311
1312 if (handle == NULL) /* check handle */
1313 {
1314 return 2; /* return error */
1315 }
1316 if (handle->inited != 1) /* check handle initialization */
1317 {
1318 return 3; /* return error */
1319 }
1320 if (handle->dmp_inited != 1) /* check dmp initialization */
1321 {
1322 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
1323
1324 return 4; /* return error */
1325 }
1326
1327 res = a_mpu9250_read_mem(handle, MPU9250_DMP_D_PEDSTD_STEPCTR, tmp, 4); /* read data */
1328 if (res != 0) /* check result */
1329 {
1330 handle->debug_print("mpu9250: read mem failed.\n"); /* read mem failed */
1331
1332 return 1; /* return error */
1333 }
1334 *count = (((uint32_t)tmp[0] << 24) | ((uint32_t)tmp[1] << 16) |
1335 ((uint32_t)tmp[2] << 8) | tmp[3]); /* get the ms */
1336
1337 return 0; /* success return 0 */
1338 }
1339
1352 uint8_t mpu9250_dmp_set_shake_reject_timeout(mpu9250_handle_t *handle, uint16_t ms)
1353 {
1354 uint8_t res;
1355 uint8_t tmp[2];
1356
1357 if (handle == NULL) /* check handle */
1358 {
1359 return 2; /* return error */
1360 }
1361 if (handle->inited != 1) /* check handle initialization */
1362 {
1363 return 3; /* return error */
1364 }
1365 if (handle->dmp_inited != 1) /* check dmp initialization */
1366 {
1367 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
1368
1369 return 4; /* return error */
1370 }
1371
1372 ms /= (1000 / MPU9250_DMP_SAMPLE_RATE); /* convert time */
1373 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
1374 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
1375
1376 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_1_88, tmp, 2); /* write data */
1377 if (res != 0) /* check result */
1378 {
1379 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
1380
1381 return 1; /* return error */
1382 }
1383
1384 return 0; /* success return 0 */
1385 }
1386
1399 uint8_t mpu9250_dmp_get_shake_reject_timeout(mpu9250_handle_t *handle, uint16_t *ms)
1400 {
1401 uint8_t res;
1402 uint8_t tmp[2];
1403
1404 if (handle == NULL) /* check handle */
1405 {
1406 return 2; /* return error */
1407 }
1408 if (handle->inited != 1) /* check handle initialization */
1409 {
1410 return 3; /* return error */
1411 }
1412 if (handle->dmp_inited != 1) /* check dmp initialization */
1413 {
1414 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
1415
1416 return 4; /* return error */
1417 }
1418
1419 res = a_mpu9250_read_mem(handle, MPU9250_DMP_D_1_88, tmp, 2); /* read data */
1420 if (res != 0) /* check result */
1421 {
1422 handle->debug_print("mpu9250: read mem failed.\n"); /* read mem failed */
1423
1424 return 1; /* return error */
1425 }
1426 *ms = (uint16_t)((uint16_t)tmp[0] << 8) | tmp[1]; /* get the raw time */
1427 *ms *= (1000 / MPU9250_DMP_SAMPLE_RATE); /* convert time */
1428
1429 return 0; /* success return 0 */
1430 }
1431
1444 uint8_t mpu9250_dmp_set_shake_reject_time(mpu9250_handle_t *handle, uint16_t ms)
1445 {
1446 uint8_t res;
1447 uint8_t tmp[2];
1448
1449 if (handle == NULL) /* check handle */
1450 {
1451 return 2; /* return error */
1452 }
1453 if (handle->inited != 1) /* check handle initialization */
1454 {
1455 return 3; /* return error */
1456 }
1457 if (handle->dmp_inited != 1) /* check dmp initialization */
1458 {
1459 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
1460
1461 return 4; /* return error */
1462 }
1463
1464 ms /= (1000 / MPU9250_DMP_SAMPLE_RATE); /* convert time */
1465 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
1466 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
1467
1468 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_1_90, tmp, 2); /* write data */
1469 if (res != 0) /* check result */
1470 {
1471 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
1472
1473 return 1; /* return error */
1474 }
1475
1476 return 0; /* success return 0 */
1477 }
1478
1491 uint8_t mpu9250_dmp_get_shake_reject_time(mpu9250_handle_t *handle, uint16_t *ms)
1492 {
1493 uint8_t res;
1494 uint8_t tmp[2];
1495
1496 if (handle == NULL) /* check handle */
1497 {
1498 return 2; /* return error */
1499 }
1500 if (handle->inited != 1) /* check handle initialization */
1501 {
1502 return 3; /* return error */
1503 }
1504 if (handle->dmp_inited != 1) /* check dmp initialization */
1505 {
1506 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
1507
1508 return 4; /* return error */
1509 }
1510
1511 res = a_mpu9250_read_mem(handle, MPU9250_DMP_D_1_90, tmp, 2); /* read data */
1512 if (res != 0) /* check result */
1513 {
1514 handle->debug_print("mpu9250: read mem failed.\n"); /* read mem failed */
1515
1516 return 1; /* return error */
1517 }
1518 *ms = (uint16_t)((uint16_t)tmp[0] << 8) | tmp[1]; /* get the raw time */
1519 *ms *= (1000 / MPU9250_DMP_SAMPLE_RATE); /* convert time */
1520
1521 return 0; /* success return 0 */
1522 }
1523
1536 uint8_t mpu9250_dmp_set_shake_reject_thresh(mpu9250_handle_t *handle, uint16_t dps)
1537 {
1538 uint8_t res;
1539 uint8_t tmp[4];
1540 uint32_t thresh_scaled;
1541
1542 if (handle == NULL) /* check handle */
1543 {
1544 return 2; /* return error */
1545 }
1546 if (handle->inited != 1) /* check handle initialization */
1547 {
1548 return 3; /* return error */
1549 }
1550 if (handle->dmp_inited != 1) /* check dmp initialization */
1551 {
1552 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
1553
1554 return 4; /* return error */
1555 }
1556
1557 thresh_scaled = MPU9250_DMP_GYRO_SF / 1000 * dps; /* convert to thresh scaled */
1558 tmp[0] = (uint8_t)(((uint32_t)thresh_scaled >> 24) & 0xFF); /* set the part 3 */
1559 tmp[1] = (uint8_t)(((uint32_t)thresh_scaled >> 16) & 0xFF); /* set the part 2 */
1560 tmp[2] = (uint8_t)(((uint32_t)thresh_scaled >> 8) & 0xFF); /* set the part 1 */
1561 tmp[3] = (uint8_t)((uint32_t)thresh_scaled & 0xFF); /* set the part 0 */
1562
1563 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_1_92, tmp, 4); /* write data */
1564 if (res != 0) /* check result */
1565 {
1566 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
1567
1568 return 1; /* return error */
1569 }
1570
1571 return 0; /* success return 0 */
1572 }
1573
1586 uint8_t mpu9250_dmp_get_shake_reject_thresh(mpu9250_handle_t *handle, uint16_t *dps)
1587 {
1588 uint8_t res;
1589 uint8_t tmp[4];
1590 uint32_t thresh_scaled;
1591
1592 if (handle == NULL) /* check handle */
1593 {
1594 return 2; /* return error */
1595 }
1596 if (handle->inited != 1) /* check handle initialization */
1597 {
1598 return 3; /* return error */
1599 }
1600 if (handle->dmp_inited != 1) /* check dmp initialization */
1601 {
1602 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
1603
1604 return 4; /* return error */
1605 }
1606
1607 res = a_mpu9250_read_mem(handle, MPU9250_DMP_D_1_92, tmp, 4); /* read data */
1608 if (res != 0) /* check result */
1609 {
1610 handle->debug_print("mpu9250: read mem failed.\n"); /* read mem failed */
1611
1612 return 1; /* return error */
1613 }
1614 thresh_scaled = (((uint32_t)tmp[0] << 24) | ((uint32_t)tmp[1] << 16) |
1615 ((uint32_t)tmp[2] << 8) | tmp[3]); /* get the thresh scaled */
1616 *dps = (uint16_t)((float)(thresh_scaled) /
1617 ((float)(MPU9250_DMP_GYRO_SF) / 1000.0f)); /* convert the thresh scaled */
1618
1619 return 0; /* success return 0 */
1620 }
1621
1634 uint8_t mpu9250_dmp_set_tap_time_multi(mpu9250_handle_t *handle, uint16_t ms)
1635 {
1636 uint8_t res;
1637 uint8_t tmp[2];
1638
1639 if (handle == NULL) /* check handle */
1640 {
1641 return 2; /* return error */
1642 }
1643 if (handle->inited != 1) /* check handle initialization */
1644 {
1645 return 3; /* return error */
1646 }
1647 if (handle->dmp_inited != 1) /* check dmp initialization */
1648 {
1649 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
1650
1651 return 4; /* return error */
1652 }
1653
1654 ms /= (1000 / MPU9250_DMP_SAMPLE_RATE); /* convert time */
1655 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
1656 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
1657
1658 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_1_218, tmp, 2); /* write data */
1659 if (res != 0) /* check result */
1660 {
1661 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
1662
1663 return 1; /* return error */
1664 }
1665
1666 return 0; /* success return 0 */
1667 }
1668
1681 uint8_t mpu9250_dmp_get_tap_time_multi(mpu9250_handle_t *handle, uint16_t *ms)
1682 {
1683 uint8_t res;
1684 uint8_t tmp[2];
1685
1686 if (handle == NULL) /* check handle */
1687 {
1688 return 2; /* return error */
1689 }
1690 if (handle->inited != 1) /* check handle initialization */
1691 {
1692 return 3; /* return error */
1693 }
1694 if (handle->dmp_inited != 1) /* check dmp initialization */
1695 {
1696 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
1697
1698 return 4; /* return error */
1699 }
1700
1701 res = a_mpu9250_read_mem(handle, MPU9250_DMP_D_1_218, tmp, 2); /* read data */
1702 if (res != 0) /* check result */
1703 {
1704 handle->debug_print("mpu9250: read mem failed.\n"); /* read mem failed */
1705
1706 return 1; /* return error */
1707 }
1708 *ms = (uint16_t)((uint16_t)tmp[0] << 8) | tmp[1]; /* get the raw time */
1709 *ms *= (1000 / MPU9250_DMP_SAMPLE_RATE); /* convert time */
1710
1711 return 0; /* success return 0 */
1712 }
1713
1726 uint8_t mpu9250_dmp_set_tap_time(mpu9250_handle_t *handle, uint16_t ms)
1727 {
1728 uint8_t res;
1729 uint8_t tmp[2];
1730
1731 if (handle == NULL) /* check handle */
1732 {
1733 return 2; /* return error */
1734 }
1735 if (handle->inited != 1) /* check handle initialization */
1736 {
1737 return 3; /* return error */
1738 }
1739 if (handle->dmp_inited != 1) /* check dmp initialization */
1740 {
1741 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
1742
1743 return 4; /* return error */
1744 }
1745
1746 ms /= (1000 / MPU9250_DMP_SAMPLE_RATE); /* convert time */
1747 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
1748 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
1749
1750 res = a_mpu9250_write_mem(handle, MPU9250_DMP_TAPW_MIN, tmp, 2); /* write data */
1751 if (res != 0) /* check result */
1752 {
1753 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
1754
1755 return 1; /* return error */
1756 }
1757
1758 return 0; /* success return 0 */
1759 }
1760
1773 uint8_t mpu9250_dmp_get_tap_time(mpu9250_handle_t *handle, uint16_t *ms)
1774 {
1775 uint8_t res;
1776 uint8_t tmp[2];
1777
1778 if (handle == NULL) /* check handle */
1779 {
1780 return 2; /* return error */
1781 }
1782 if (handle->inited != 1) /* check handle initialization */
1783 {
1784 return 3; /* return error */
1785 }
1786 if (handle->dmp_inited != 1) /* check dmp initialization */
1787 {
1788 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
1789
1790 return 4; /* return error */
1791 }
1792
1793 res = a_mpu9250_read_mem(handle, MPU9250_DMP_TAPW_MIN, tmp, 2); /* read data */
1794 if (res != 0) /* check result */
1795 {
1796 handle->debug_print("mpu9250: read mem failed.\n"); /* read mem failed */
1797
1798 return 1; /* return error */
1799 }
1800 *ms = (uint16_t)((uint16_t)tmp[0] << 8) | tmp[1]; /* get the raw time */
1801 *ms *= (1000 / MPU9250_DMP_SAMPLE_RATE); /* convert time */
1802
1803 return 0; /* success return 0 */
1804 }
1805
1819 uint8_t mpu9250_dmp_set_min_tap_count(mpu9250_handle_t *handle, uint8_t cnt)
1820 {
1821 uint8_t res;
1822 uint8_t tmp;
1823
1824 if (handle == NULL) /* check handle */
1825 {
1826 return 2; /* return error */
1827 }
1828 if (handle->inited != 1) /* check handle initialization */
1829 {
1830 return 3; /* return error */
1831 }
1832 if (handle->dmp_inited != 1) /* check dmp initialization */
1833 {
1834 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
1835
1836 return 4; /* return error */
1837 }
1838 if ((cnt < 1) || (cnt > 4)) /* check cnt */
1839 {
1840 handle->debug_print("mpu9250: cnt must be between 1 and 4.\n"); /* cnt must be between 1 and 4 */
1841
1842 return 5; /* return error */
1843 }
1844
1845 tmp = cnt - 1; /* set the counter */
1846 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_1_79, &tmp, 1); /* write data */
1847 if (res != 0) /* check result */
1848 {
1849 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
1850
1851 return 1; /* return error */
1852 }
1853
1854 return 0; /* success return 0 */
1855 }
1856
1869 uint8_t mpu9250_dmp_get_min_tap_count(mpu9250_handle_t *handle, uint8_t *cnt)
1870 {
1871 uint8_t res;
1872 uint8_t tmp;
1873
1874 if (handle == NULL) /* check handle */
1875 {
1876 return 2; /* return error */
1877 }
1878 if (handle->inited != 1) /* check handle initialization */
1879 {
1880 return 3; /* return error */
1881 }
1882 if (handle->dmp_inited != 1) /* check dmp initialization */
1883 {
1884 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
1885
1886 return 4; /* return error */
1887 }
1888
1889 res = a_mpu9250_read_mem(handle, MPU9250_DMP_D_1_79, &tmp, 1); /* read data */
1890 if (res != 0) /* check result */
1891 {
1892 handle->debug_print("mpu9250: read mem failed.\n"); /* read mem failed */
1893
1894 return 1; /* return error */
1895 }
1896 *cnt = tmp + 1; /* set the counter */
1897
1898 return 0; /* success return 0 */
1899 }
1900
1913 uint8_t mpu9250_dmp_set_gyro_calibrate(mpu9250_handle_t *handle, mpu9250_bool_t enable)
1914 {
1915 uint8_t res;
1916
1917 if (handle == NULL) /* check handle */
1918 {
1919 return 2; /* return error */
1920 }
1921 if (handle->inited != 1) /* check handle initialization */
1922 {
1923 return 3; /* return error */
1924 }
1925 if (handle->dmp_inited != 1) /* check dmp initialization */
1926 {
1927 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
1928
1929 return 4; /* return error */
1930 }
1931
1932 if (enable != 0) /* enable */
1933 {
1934 uint8_t regs[9] = {0xb8, 0xaa, 0xb3, 0x8d, 0xb4, 0x98, 0x0d, 0x35, 0x5d};
1935
1936 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_MOTION_BIAS, regs, 9); /* write data */
1937 if (res != 0) /* check result */
1938 {
1939 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
1940
1941 return 1; /* return error */
1942 }
1943 handle->mask |= MPU9250_DMP_FEATURE_GYRO_CAL; /* set the mask */
1944
1945 return 0; /* success return 0 */
1946 }
1947 else /* disable */
1948 {
1949 uint8_t regs[9] = {0xb8, 0xaa, 0xaa, 0xaa, 0xb0, 0x88, 0xc3, 0xc5, 0xc7};
1950
1951 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_MOTION_BIAS, regs, 9); /* write data */
1952 if (res != 0) /* check result */
1953 {
1954 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
1955
1956 return 1; /* return error */
1957 }
1958 handle->mask &= ~MPU9250_DMP_FEATURE_GYRO_CAL; /* set the mask */
1959
1960 return 0; /* success return 0 */
1961 }
1962 }
1963
1976 uint8_t mpu9250_dmp_set_3x_quaternion(mpu9250_handle_t *handle, mpu9250_bool_t enable)
1977 {
1978 uint8_t res;
1979
1980 if (handle == NULL) /* check handle */
1981 {
1982 return 2; /* return error */
1983 }
1984 if (handle->inited != 1) /* check handle initialization */
1985 {
1986 return 3; /* return error */
1987 }
1988 if (handle->dmp_inited != 1) /* check dmp initialization */
1989 {
1990 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
1991
1992 return 4; /* return error */
1993 }
1994
1995 if (enable != 0) /* enable */
1996 {
1997 uint8_t regs[4] = {0xC0, 0xC2, 0xC4, 0xC6};
1998
1999 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_LP_QUAT, regs, 4); /* write data */
2000 if (res != 0) /* check result */
2001 {
2002 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2003
2004 return 1; /* return error */
2005 }
2006 res = a_mpu9250_reset_fifo(handle); /* reset the fifo */
2007 if (res != 0) /* check result */
2008 {
2009 handle->debug_print("mpu9250: reset fifo failed.\n"); /* reset fifo failed */
2010
2011 return 1; /* return error */
2012 }
2013 handle->mask |= MPU9250_DMP_FEATURE_3X_QUAT; /* set the mask */
2014
2015 return 0; /* success return 0 */
2016 }
2017 else /* disable */
2018 {
2019 uint8_t regs[4] = {0x8B, 0x8B, 0x8B, 0x8B};
2020
2021 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_LP_QUAT, regs, 4); /* write data */
2022 if (res != 0) /* check result */
2023 {
2024 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2025
2026 return 1; /* return error */
2027 }
2028 res = a_mpu9250_reset_fifo(handle); /* reset the fifo */
2029 if (res != 0) /* check result */
2030 {
2031 handle->debug_print("mpu9250: reset fifo failed.\n"); /* reset fifo failed */
2032
2033 return 1; /* return error */
2034 }
2035 handle->mask &= ~MPU9250_DMP_FEATURE_3X_QUAT; /* set the mask */
2036
2037 return 0; /* success return 0 */
2038 }
2039 }
2040
2053 uint8_t mpu9250_dmp_set_6x_quaternion(mpu9250_handle_t *handle, mpu9250_bool_t enable)
2054 {
2055 uint8_t res;
2056
2057 if (handle == NULL) /* check handle */
2058 {
2059 return 2; /* return error */
2060 }
2061 if (handle->inited != 1) /* check handle initialization */
2062 {
2063 return 3; /* return error */
2064 }
2065 if (handle->dmp_inited != 1) /* check dmp initialization */
2066 {
2067 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
2068
2069 return 4; /* return error */
2070 }
2071
2072 if (enable != 0) /* enable */
2073 {
2074 uint8_t regs[4] = {0x20, 0x28, 0x30, 0x38};
2075
2076 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_8, regs, 4); /* write data */
2077 if (res != 0) /* check result */
2078 {
2079 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2080
2081 return 1; /* return error */
2082 }
2083 res = a_mpu9250_reset_fifo(handle); /* reset the fifo */
2084 if (res != 0) /* check result */
2085 {
2086 handle->debug_print("mpu9250: reset fifo failed.\n"); /* reset fifo failed */
2087
2088 return 1; /* return error */
2089 }
2090 handle->mask |= MPU9250_DMP_FEATURE_6X_QUAT; /* set the mask */
2091
2092 return 0; /* success return 0 */
2093 }
2094 else /* disable */
2095 {
2096 uint8_t regs[4] = {0xA3, 0xA3, 0xA3, 0xA3};
2097
2098 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_8, regs, 4); /* write data */
2099 if (res != 0) /* check result */
2100 {
2101 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2102
2103 return 1; /* return error */
2104 }
2105 res = a_mpu9250_reset_fifo(handle); /* reset the fifo */
2106 if (res != 0) /* check result */
2107 {
2108 handle->debug_print("mpu9250: reset fifo failed.\n"); /* reset fifo failed */
2109
2110 return 1; /* return error */
2111 }
2112 handle->mask &= ~MPU9250_DMP_FEATURE_6X_QUAT; /* set the mask */
2113
2114 return 0; /* success return 0 */
2115 }
2116 }
2117
2130 uint8_t mpu9250_dmp_set_interrupt_mode(mpu9250_handle_t *handle, mpu9250_dmp_interrupt_mode_t mode)
2131 {
2132 uint8_t res;
2133
2134 if (handle == NULL) /* check handle */
2135 {
2136 return 2; /* return error */
2137 }
2138 if (handle->inited != 1) /* check handle initialization */
2139 {
2140 return 3; /* return error */
2141 }
2142 if (handle->dmp_inited != 1) /* check dmp initialization */
2143 {
2144 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
2145
2146 return 4; /* return error */
2147 }
2148
2149 if (mode == MPU9250_DMP_INTERRUPT_MODE_CONTINUOUS) /* continuous */
2150 {
2151 uint8_t regs_continuous[11] = {0xd8, 0xb1, 0xb9,
2152 0xf3, 0x8b, 0xa3,
2153 0x91, 0xb6, 0x09,
2154 0xb4, 0xd9};
2155
2156 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_FIFO_ON_EVENT,
2157 (uint8_t *)regs_continuous, 11); /* write data */
2158 if (res != 0) /* check result */
2159 {
2160 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2161
2162 return 1; /* return error */
2163 }
2164
2165 return 0; /* success return 0 */
2166 }
2167 else /* disable */
2168 {
2169 uint8_t regs_gesture[11] = {0xda, 0xb1, 0xb9,
2170 0xf3, 0x8b, 0xa3,
2171 0x91, 0xb6, 0xda,
2172 0xb4, 0xda};
2173
2174 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_FIFO_ON_EVENT,
2175 (uint8_t *)regs_gesture, 11); /* write data */
2176 if (res != 0) /* check result */
2177 {
2178 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2179
2180 return 1; /* return error */
2181 }
2182
2183 return 0; /* success return 0 */
2184 }
2185 }
2186
2199 uint8_t mpu9250_dmp_set_gyro_bias(mpu9250_handle_t *handle, int32_t bias[3])
2200 {
2201 uint8_t res;
2202 uint8_t regs[4];
2203 int32_t gyro_bias_body[3];
2204
2205 if (handle == NULL) /* check handle */
2206 {
2207 return 2; /* return error */
2208 }
2209 if (handle->inited != 1) /* check handle initialization */
2210 {
2211 return 3; /* return error */
2212 }
2213 if (handle->dmp_inited != 1) /* check dmp initialization */
2214 {
2215 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
2216
2217 return 4; /* return error */
2218 }
2219
2220 gyro_bias_body[0] = bias[handle->orient & 3]; /* set the body 0 */
2221 if ((handle->orient & 4) != 0) /* check bit 3 */
2222 {
2223 gyro_bias_body[0] *= -1; /* *(-1) */
2224 }
2225 gyro_bias_body[1] = bias[(handle->orient >> 3) & 3]; /* set the body 1 */
2226 if ((handle->orient & 0x20) != 0) /* check bit 6 */
2227 {
2228 gyro_bias_body[1] *= -1; /* *(-1) */
2229 }
2230 gyro_bias_body[2] = bias[(handle->orient >> 6) & 3]; /* set the body 2 */
2231 if ((handle->orient & 0x100) != 0) /* check bit 9 */
2232 {
2233 gyro_bias_body[2] *= -1; /* *(-1) */
2234 }
2235
2236 gyro_bias_body[0] = (int32_t)(((int64_t)gyro_bias_body[0] * MPU9250_DMP_GYRO_SF) >> 30); /* set body 0 */
2237 gyro_bias_body[1] = (int32_t)(((int64_t)gyro_bias_body[1] * MPU9250_DMP_GYRO_SF) >> 30); /* set body 1 */
2238 gyro_bias_body[2] = (int32_t)(((int64_t)gyro_bias_body[2] * MPU9250_DMP_GYRO_SF) >> 30); /* set body 2 */
2239
2240 regs[0] = (uint8_t)((gyro_bias_body[0] >> 24) & 0xFF); /* set part 0 */
2241 regs[1] = (uint8_t)((gyro_bias_body[0] >> 16) & 0xFF); /* set part 1 */
2242 regs[2] = (uint8_t)((gyro_bias_body[0] >> 8) & 0xFF); /* set part 2 */
2243 regs[3] = (uint8_t)(gyro_bias_body[0] & 0xFF); /* set part 3 */
2244 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_EXT_GYRO_BIAS_X, (uint8_t *)regs, 4); /* write data */
2245 if (res != 0) /* check result */
2246 {
2247 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2248
2249 return 1; /* return error */
2250 }
2251 regs[0] = (uint8_t)((gyro_bias_body[1] >> 24) & 0xFF); /* set part 0 */
2252 regs[1] = (uint8_t)((gyro_bias_body[1] >> 16) & 0xFF); /* set part 1 */
2253 regs[2] = (uint8_t)((gyro_bias_body[1] >> 8) & 0xFF); /* set part 2 */
2254 regs[3] = (uint8_t)(gyro_bias_body[1] & 0xFF); /* set part 3 */
2255 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_EXT_GYRO_BIAS_Y, (uint8_t *)regs, 4); /* write data */
2256 if (res != 0) /* check result */
2257 {
2258 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2259
2260 return 1; /* return error */
2261 }
2262 regs[0] = (uint8_t)((gyro_bias_body[2] >> 24) & 0xFF); /* set part 0 */
2263 regs[1] = (uint8_t)((gyro_bias_body[2] >> 16) & 0xFF); /* set part 1 */
2264 regs[2] = (uint8_t)((gyro_bias_body[2] >> 8) & 0xFF); /* set part 2 */
2265 regs[3] = (uint8_t)(gyro_bias_body[2] & 0xFF); /* set part 3 */
2266 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_EXT_GYRO_BIAS_Z, (uint8_t *)regs, 4); /* write data */
2267 if (res != 0) /* check result */
2268 {
2269 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2270
2271 return 1; /* return error */
2272 }
2273
2274 return 0; /* success return 0 */
2275 }
2276
2289 uint8_t mpu9250_dmp_set_accel_bias(mpu9250_handle_t *handle, int32_t bias[3])
2290 {
2291 uint8_t res;
2292 uint8_t prev;
2293 uint8_t range;
2294 int32_t accel_bias_body[3];
2295 uint8_t regs[12];
2296 int64_t accel_sf;
2297
2298 if (handle == NULL) /* check handle */
2299 {
2300 return 2; /* return error */
2301 }
2302 if (handle->inited != 1) /* check handle initialization */
2303 {
2304 return 3; /* return error */
2305 }
2306 if (handle->dmp_inited != 1) /* check dmp initialization */
2307 {
2308 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
2309
2310 return 4; /* return error */
2311 }
2312
2313 res = a_mpu9250_read(handle, MPU9250_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* read accelerometer config */
2314 if (res != 0) /* check result */
2315 {
2316 handle->debug_print("mpu9250: read accelerometer config failed.\n"); /* read accelerometer config failed */
2317
2318 return 1; /* return error */
2319 }
2320 range = ((prev >> 3) & 0x3); /* get the range */
2321 if (range == 0) /* if 2g */
2322 {
2323 accel_sf = (int64_t)16384 << 15; /* set the accel sf */
2324 }
2325 else if (range == 1) /* if 4g */
2326 {
2327 accel_sf = (int64_t)8192 << 15; /* set the accel sf */
2328 }
2329 else if (range == 2) /* if 8g */
2330 {
2331 accel_sf = (int64_t)4096 << 15; /* set the accel sf */
2332 }
2333 else /* if 16g */
2334 {
2335 accel_sf = (int64_t)2048 << 15; /* set the accel sf */
2336 }
2337
2338 accel_bias_body[0] = bias[handle->orient & 3]; /* set the bias body 0 */
2339 if ((handle->orient & 4) != 0) /* check the orient */
2340 {
2341 accel_bias_body[0] *= -1; /* *(-1) */
2342 }
2343 accel_bias_body[1] = bias[(handle->orient >> 3) & 3]; /* set the bias body 1 */
2344 if ((handle->orient & 0x20) != 0) /* check the orient */
2345 {
2346 accel_bias_body[1] *= -1; /* *(-1) */
2347 }
2348 accel_bias_body[2] = bias[(handle->orient >> 6) & 3]; /* set the bias body 2 */
2349 if ((handle->orient & 0x100) != 0) /* check the orient */
2350 {
2351 accel_bias_body[2] *= -1; /* *(-1) */
2352 }
2353
2354 accel_bias_body[0] = (int32_t)(((int64_t)accel_bias_body[0] * accel_sf) >> 30); /* set the bias body 0 */
2355 accel_bias_body[1] = (int32_t)(((int64_t)accel_bias_body[1] * accel_sf) >> 30); /* set the bias body 1 */
2356 accel_bias_body[2] = (int32_t)(((int64_t)accel_bias_body[2] * accel_sf) >> 30); /* set the bias body 2 */
2357 regs[0] = (uint8_t)((accel_bias_body[0] >> 24) & 0xFF); /* set reg 0 */
2358 regs[1] = (uint8_t)((accel_bias_body[0] >> 16) & 0xFF); /* set reg 1 */
2359 regs[2] = (uint8_t)((accel_bias_body[0] >> 8) & 0xFF); /* set reg 2 */
2360 regs[3] = (uint8_t)(accel_bias_body[0] & 0xFF); /* set reg 3 */
2361 regs[4] = (uint8_t)((accel_bias_body[1] >> 24) & 0xFF); /* set reg 4 */
2362 regs[5] = (uint8_t)((accel_bias_body[1] >> 16) & 0xFF); /* set reg 5 */
2363 regs[6] = (uint8_t)((accel_bias_body[1] >> 8) & 0xFF); /* set reg 6 */
2364 regs[7] = (uint8_t)(accel_bias_body[1] & 0xFF); /* set reg 7 */
2365 regs[8] = (uint8_t)((accel_bias_body[2] >> 24) & 0xFF); /* set reg 8 */
2366 regs[9] = (uint8_t)((accel_bias_body[2] >> 16) & 0xFF); /* set reg 9 */
2367 regs[10] = (uint8_t)((accel_bias_body[2] >> 8) & 0xFF); /* set reg 10 */
2368 regs[11] = (uint8_t)(accel_bias_body[2] & 0xFF); /* set reg 11 */
2369 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_ACCEL_BIAS, (uint8_t *)regs, 12); /* write data */
2370 if (res != 0) /* check result */
2371 {
2372 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2373
2374 return 1; /* return error */
2375 }
2376
2377 return 0; /* success return 0 */
2378 }
2379
2392 uint8_t mpu9250_dmp_set_orientation(mpu9250_handle_t *handle, int8_t mat[9])
2393 {
2394 uint8_t gyro_axes[4] = {0x4C, 0xCD, 0x6C, 0x00};
2395 uint8_t accel_axes[4] = {0x0C, 0xC9, 0x2C, 0x00 };
2396 uint8_t gyro_sign[4] = {0x36, 0x56, 0x76, 0x00 };
2397 uint8_t accel_sign[4] = {0x26, 0x46, 0x66, 0x00 };
2398 uint8_t res;
2399 uint8_t gyro_regs[3];
2400 uint8_t accel_regs[3];
2401 uint16_t orient;
2402
2403 if (handle == NULL) /* check handle */
2404 {
2405 return 2; /* return error */
2406 }
2407 if (handle->inited != 1) /* check handle initialization */
2408 {
2409 return 3; /* return error */
2410 }
2411 if (handle->dmp_inited != 1) /* check dmp initialization */
2412 {
2413 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
2414
2415 return 4; /* return error */
2416 }
2417
2418 orient = a_mpu9250_inv_orientation_matrix_to_scalar(mat); /* inv orientation matrix to scalar */
2419 gyro_regs[0] = gyro_axes[orient & 3]; /* set the gyro regs 0 */
2420 gyro_regs[1] = gyro_axes[(orient >> 3) & 3]; /* set the gyro regs 1 */
2421 gyro_regs[2] = gyro_axes[(orient >> 6) & 3]; /* set the gyro regs 2 */
2422 accel_regs[0] = accel_axes[orient & 3]; /* set the accel regs 0 */
2423 accel_regs[1] = accel_axes[(orient >> 3) & 3]; /* set the accel regs 1 */
2424 accel_regs[2] = accel_axes[(orient >> 6) & 3]; /* set the accel regs 2 */
2425 res = a_mpu9250_write_mem(handle, MPU9250_DMP_FCFG_1,
2426 (uint8_t *)gyro_regs, 3); /* write data */
2427 if (res != 0) /* check result */
2428 {
2429 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2430
2431 return 1; /* return error */
2432 }
2433 res = a_mpu9250_write_mem(handle, MPU9250_DMP_FCFG_2,
2434 (uint8_t *)accel_regs, 3); /* write data */
2435 if (res != 0) /* check result */
2436 {
2437 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2438
2439 return 1; /* return error */
2440 }
2441
2442 memcpy(gyro_regs, gyro_sign, 3); /* copy the gyro regs */
2443 memcpy(accel_regs, accel_sign, 3); /* copy the accel regs */
2444 if ((orient & 4) != 0) /* bit 3 */
2445 {
2446 gyro_regs[0] |= 1; /* set 1 */
2447 accel_regs[0] |= 1; /* set 1 */
2448 }
2449 if ((orient & 0x20) != 0) /* bit 6 */
2450 {
2451 gyro_regs[1] |= 1; /* set 1 */
2452 accel_regs[1] |= 1; /* set 1 */
2453 }
2454 if ((orient & 0x100) != 0) /* bit 9 */
2455 {
2456 gyro_regs[2] |= 1; /* set 1 */
2457 accel_regs[2] |= 1; /* set 1 */
2458 }
2459 res = a_mpu9250_write_mem(handle, MPU9250_DMP_FCFG_3,
2460 (uint8_t *)gyro_regs, 3); /* write data */
2461 if (res != 0) /* check result */
2462 {
2463 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2464
2465 return 1; /* return error */
2466 }
2467 res = a_mpu9250_write_mem(handle, MPU9250_DMP_FCFG_7,
2468 (uint8_t *)accel_regs, 3); /* write data */
2469 if (res != 0) /* check result */
2470 {
2471 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2472
2473 return 1; /* return error */
2474 }
2475 handle->orient = orient; /* set the orient */
2476
2477 return 0; /* success return 0 */
2478 }
2479
2496 uint8_t mpu9250_dmp_set_feature(mpu9250_handle_t *handle, uint16_t mask)
2497 {
2498 uint8_t res;
2499 uint8_t tmp[10];
2500
2501 if (handle == NULL) /* check handle */
2502 {
2503 return 2; /* return error */
2504 }
2505 if (handle->inited != 1) /* check handle initialization */
2506 {
2507 return 3; /* return error */
2508 }
2509 if (handle->dmp_inited != 1) /* check dmp initialization */
2510 {
2511 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
2512
2513 return 4; /* return error */
2514 }
2515
2516 tmp[0] = (uint8_t)((MPU9250_DMP_GYRO_SF >> 24) & 0xFF); /* set the param 0 */
2517 tmp[1] = (uint8_t)((MPU9250_DMP_GYRO_SF >> 16) & 0xFF); /* set the param 1 */
2518 tmp[2] = (uint8_t)((MPU9250_DMP_GYRO_SF >> 8) & 0xFF); /* set the param 2 */
2519 tmp[3] = (uint8_t)(MPU9250_DMP_GYRO_SF & 0xFF); /* set the param 3 */
2520 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_0_104, tmp, 4); /* write data */
2521 if (res != 0) /* check result */
2522 {
2523 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2524
2525 return 1; /* return error */
2526 }
2527
2528 tmp[0] = 0xA3;
2529 if ((mask & MPU9250_DMP_FEATURE_SEND_RAW_ACCEL) != 0) /* set the raw accel */
2530 {
2531 tmp[1] = 0xC0; /* set the param 1 */
2532 tmp[2] = 0xC8; /* set the param 2 */
2533 tmp[3] = 0xC2; /* set the param 3 */
2534 }
2535 else
2536 {
2537 tmp[1] = 0xA3; /* set the param 1 */
2538 tmp[2] = 0xA3; /* set the param 2 */
2539 tmp[3] = 0xA3; /* set the param 3 */
2540 }
2541 if ((mask & MPU9250_DMP_FEATURE_SEND_ANY_GYRO) != 0) /* set any gyro */
2542 {
2543 tmp[4] = 0xC4; /* set the param 4 */
2544 tmp[5] = 0xCC; /* set the param 5 */
2545 tmp[6] = 0xC6; /* set the param 6 */
2546 }
2547 else
2548 {
2549 tmp[4] = 0xA3; /* set the param 4 */
2550 tmp[5] = 0xA3; /* set the param 5 */
2551 tmp[6] = 0xA3; /* set the param 6 */
2552 }
2553 tmp[7] = 0xA3; /* set the param 7 */
2554 tmp[8] = 0xA3; /* set the param 8 */
2555 tmp[9] = 0xA3; /* set the param 9 */
2556 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_15, tmp, 10); /* write data */
2557 if (res != 0) /* check result */
2558 {
2559 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2560
2561 return 1; /* return error */
2562 }
2563
2564 if ((mask & (MPU9250_DMP_FEATURE_TAP | MPU9250_DMP_FEATURE_ORIENT)) != 0) /* set the cfg */
2565 {
2566 tmp[0] = 0x20; /* set the param */
2567 }
2568 else
2569 {
2570 tmp[0] = 0xD8; /* set the param */
2571 }
2572 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_27, tmp, 1); /* write data */
2573 if (res != 0) /* check result */
2574 {
2575 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2576
2577 return 1; /* return error */
2578 }
2579
2580 if ((mask & MPU9250_DMP_FEATURE_GYRO_CAL) != 0) /* if true */
2581 {
2582 uint8_t regs[9] = {0xb8, 0xaa, 0xb3, 0x8d, 0xb4, 0x98, 0x0d, 0x35, 0x5d};
2583
2584 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_MOTION_BIAS, regs, 9); /* write data */
2585 if (res != 0) /* check result */
2586 {
2587 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2588
2589 return 1; /* return error */
2590 }
2591 }
2592 else
2593 {
2594 uint8_t regs[9] = {0xb8, 0xaa, 0xaa, 0xaa, 0xb0, 0x88, 0xc3, 0xc5, 0xc7};
2595
2596 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_MOTION_BIAS, regs, 9); /* write data */
2597 if (res != 0) /* check result */
2598 {
2599 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2600
2601 return 1; /* return error */
2602 }
2603 }
2604
2605 if ((mask & MPU9250_DMP_FEATURE_SEND_ANY_GYRO) != 0) /* check the gyro */
2606 {
2607 if ((mask & MPU9250_DMP_FEATURE_SEND_CAL_GYRO) != 0) /* set the cal gyro */
2608 {
2609 tmp[0] = 0xB2; /* set the param 0 */
2610 tmp[1] = 0x8B; /* set the param 1 */
2611 tmp[2] = 0xB6; /* set the param 2 */
2612 tmp[3] = 0x9B; /* set the param 3 */
2613 }
2614 else
2615 {
2616 tmp[0] = 0xC0; /* set the param 0 */
2617 tmp[1] = 0x80; /* set the param 1 */
2618 tmp[2] = 0xC2; /* set the param 2 */
2619 tmp[3] = 0x90; /* set the param 3 */
2620 }
2621 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_GYRO_RAW_DATA, tmp, 4); /* write data */
2622 if (res != 0) /* check result */
2623 {
2624 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2625
2626 return 1; /* return error */
2627 }
2628 }
2629
2630 if ((mask & MPU9250_DMP_FEATURE_TAP) != 0) /* check the tap */
2631 {
2632 uint8_t prev;
2633 uint16_t ms;
2634 uint16_t dps;
2635 uint32_t thresh_scaled;
2636 uint8_t range;
2637 uint16_t dmp_thresh;
2638 uint16_t dmp_thresh_2;
2639 float scaled_thresh;
2640
2641 tmp[0] = 0xF8; /* set the param */
2642 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_20, tmp, 1); /* write data */
2643 if (res != 0) /* check result */
2644 {
2645 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2646
2647 return 1; /* return error */
2648 }
2649
2650 scaled_thresh = (float)MPU9250_DMP_TAP_THRESH / MPU9250_DMP_SAMPLE_RATE; /* get the scaled thresh */
2651 res = a_mpu9250_read(handle, MPU9250_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* read accelerometer config */
2652 if (res != 0) /* check result */
2653 {
2654 handle->debug_print("mpu9250: read accelerometer config failed.\n"); /* read accelerometer config failed */
2655
2656 return 1; /* return error */
2657 }
2658 range = ((prev >> 3) & 0x3); /* get the range */
2659 if (range == 0) /* if 2g */
2660 {
2661 dmp_thresh = (uint16_t)(scaled_thresh * 16384); /* set dmp thresh */
2662 dmp_thresh_2 = (uint16_t)(scaled_thresh * 12288); /* set dmp thresh2 */
2663 }
2664 else if (range == 1) /* if 4g */
2665 {
2666 dmp_thresh = (uint16_t)(scaled_thresh * 8192); /* set dmp thresh */
2667 dmp_thresh_2 = (uint16_t)(scaled_thresh * 6144); /* set dmp thresh2 */
2668 }
2669 else if (range == 2) /* if 8g */
2670 {
2671 dmp_thresh = (uint16_t)(scaled_thresh * 4096); /* set dmp thresh */
2672 dmp_thresh_2 = (uint16_t)(scaled_thresh * 3072); /* set dmp thresh2 */
2673 }
2674 else /* if 16g */
2675 {
2676 dmp_thresh = (uint16_t)(scaled_thresh * 2048); /* set dmp thresh */
2677 dmp_thresh_2 = (uint16_t)(scaled_thresh * 1536); /* set dmp thresh2 */
2678 }
2679 tmp[0] = (uint8_t)(dmp_thresh >> 8); /* set part 0 */
2680 tmp[1] = (uint8_t)(dmp_thresh & 0xFF); /* set part 1 */
2681 tmp[2] = (uint8_t)(dmp_thresh_2 >> 8); /* set part 2 */
2682 tmp[3] = (uint8_t)(dmp_thresh_2 & 0xFF); /* set part 3 */
2683
2684 res = a_mpu9250_write_mem(handle, MPU9250_DMP_TAP_THX, tmp, 2); /* write tap threshold x */
2685 if (res != 0) /* check result */
2686 {
2687 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2688
2689 return 1; /* return error */
2690 }
2691 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_1_36, tmp + 2, 2); /* write register 36 */
2692 if (res != 0) /* check result */
2693 {
2694 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2695
2696 return 1; /* return error */
2697 }
2698
2699 res = a_mpu9250_write_mem(handle, MPU9250_DMP_TAP_THY, tmp, 2); /* write tap threshold y */
2700 if (res != 0) /* check result */
2701 {
2702 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2703
2704 return 1; /* return error */
2705 }
2706 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_1_40, tmp + 2, 2); /* write register 40 */
2707 if (res != 0) /* check result */
2708 {
2709 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2710
2711 return 1; /* return error */
2712 }
2713
2714 res = a_mpu9250_write_mem(handle, MPU9250_DMP_TAP_THZ, tmp, 2); /* write tap threshold z */
2715 if (res != 0) /* check result */
2716 {
2717 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2718
2719 return 1; /* return error */
2720 }
2721 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_1_44, tmp + 2, 2); /* write register 44 */
2722 if (res != 0) /* check result */
2723 {
2724 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2725
2726 return 1; /* return error */
2727 }
2728
2729 tmp[0] = 0x3F; /* enable all tap axis */
2730 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_1_72, tmp, 1); /* write data */
2731 if (res != 0) /* check result */
2732 {
2733 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2734
2735 return 1; /* return error */
2736 }
2737
2738 tmp[0] = MPU9250_DMP_TAP_MIN_TAP_COUNT - 1; /* set the counter */
2739 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_1_79, tmp, 1); /* write data */
2740 if (res != 0) /* check result */
2741 {
2742 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2743
2744 return 1; /* return error */
2745 }
2746
2747 ms = MPU9250_DMP_TAP_TIME; /* set tap time */
2748 ms /= (1000 / MPU9250_DMP_SAMPLE_RATE); /* convert time */
2749 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
2750 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
2751
2752 res = a_mpu9250_write_mem(handle, MPU9250_DMP_TAPW_MIN, tmp, 2); /* write data */
2753 if (res != 0) /* check result */
2754 {
2755 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2756
2757 return 1; /* return error */
2758 }
2759
2760 ms = MPU9250_DMP_TAP_TIME_MULTI; /* set tap time multi */
2761 ms /= (1000 / MPU9250_DMP_SAMPLE_RATE); /* convert time */
2762 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
2763 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
2764
2765 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_1_218, tmp, 2); /* write data */
2766 if (res != 0) /* check result */
2767 {
2768 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2769
2770 return 1; /* return error */
2771 }
2772
2773 dps = MPU9250_DMP_SHAKE_REJECT_THRESH; /* set the shake reject thresh */
2774 thresh_scaled = MPU9250_DMP_GYRO_SF / 1000 * dps; /* convert to thresh scaled */
2775 tmp[0] = (uint8_t)(((uint32_t)thresh_scaled >> 24) & 0xFF); /* set the part 3 */
2776 tmp[1] = (uint8_t)(((uint32_t)thresh_scaled >> 16) & 0xFF); /* set the part 2 */
2777 tmp[2] = (uint8_t)(((uint32_t)thresh_scaled >> 8) & 0xFF); /* set the part 1 */
2778 tmp[3] = (uint8_t)((uint32_t)thresh_scaled & 0xFF); /* set the part 0 */
2779
2780 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_1_92, tmp, 4); /* write data */
2781 if (res != 0) /* check result */
2782 {
2783 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2784
2785 return 1; /* return error */
2786 }
2787
2788 ms = MPU9250_DMP_SHAKE_REJECT_TIME; /* set the reject time */
2789 ms /= (1000 / MPU9250_DMP_SAMPLE_RATE); /* convert time */
2790 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
2791 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
2792
2793 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_1_90, tmp, 2); /* write data */
2794 if (res != 0) /* check result */
2795 {
2796 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2797
2798 return 1; /* return error */
2799 }
2800
2801 ms = MPU9250_DMP_SHAKE_REJECT_TIMEOUT; /* set the reject timeout */
2802 ms /= (1000 / MPU9250_DMP_SAMPLE_RATE); /* convert time */
2803 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
2804 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
2805
2806 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_1_88, tmp, 2); /* write data */
2807 if (res != 0) /* check result */
2808 {
2809 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2810
2811 return 1; /* return error */
2812 }
2813 }
2814 else
2815 {
2816 tmp[0] = 0xD8; /* set the param */
2817 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_20, tmp, 1); /* write data */
2818 if (res != 0) /* check result */
2819 {
2820 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2821
2822 return 1; /* return error */
2823 }
2824 }
2825
2826 if ((mask & MPU9250_DMP_FEATURE_ORIENT) != 0) /* set the orient */
2827 {
2828 tmp[0] = 0xD9; /* set the param */
2829 }
2830 else
2831 {
2832 tmp[0] = 0xD8; /* set the param */
2833 }
2834 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_ORIENT_INT, tmp, 1); /* write data */
2835 if (res != 0) /* check result */
2836 {
2837 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2838
2839 return 1; /* return error */
2840 }
2841
2842 if ((mask & MPU9250_DMP_FEATURE_3X_QUAT) != 0) /* true */
2843 {
2844 uint8_t regs[4] = {0xC0, 0xC2, 0xC4, 0xC6};
2845
2846 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_LP_QUAT, regs, 4); /* write data */
2847 if (res != 0) /* check result */
2848 {
2849 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2850
2851 return 1; /* return error */
2852 }
2853 res = a_mpu9250_reset_fifo(handle); /* reset the fifo */
2854 if (res != 0) /* check result */
2855 {
2856 handle->debug_print("mpu9250: reset fifo failed.\n"); /* reset fifo failed */
2857
2858 return 1; /* return error */
2859 }
2860 }
2861 else
2862 {
2863 uint8_t regs[4] = {0x8B, 0x8B, 0x8B, 0x8B};
2864
2865 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_LP_QUAT, regs, 4); /* write data */
2866 if (res != 0) /* check result */
2867 {
2868 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2869
2870 return 1; /* return error */
2871 }
2872 res = a_mpu9250_reset_fifo(handle); /* reset the fifo */
2873 if (res != 0) /* check result */
2874 {
2875 handle->debug_print("mpu9250: reset fifo failed.\n"); /* reset fifo failed */
2876
2877 return 1; /* return error */
2878 }
2879 }
2880
2881 if ((mask & MPU9250_DMP_FEATURE_6X_QUAT) != 0) /* enable */
2882 {
2883 uint8_t regs[4] = {0x20, 0x28, 0x30, 0x38};
2884
2885 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_8, regs, 4); /* write data */
2886 if (res != 0) /* check result */
2887 {
2888 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2889
2890 return 1; /* return error */
2891 }
2892 res = a_mpu9250_reset_fifo(handle); /* reset the fifo */
2893 if (res != 0) /* check result */
2894 {
2895 handle->debug_print("mpu9250: reset fifo failed.\n"); /* reset fifo failed */
2896
2897 return 1; /* return error */
2898 }
2899 }
2900 else
2901 {
2902 uint8_t regs[4] = {0xA3, 0xA3, 0xA3, 0xA3};
2903
2904 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_8, regs, 4); /* write data */
2905 if (res != 0) /* check result */
2906 {
2907 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2908
2909 return 1; /* return error */
2910 }
2911 res = a_mpu9250_reset_fifo(handle); /* reset the fifo */
2912 if (res != 0) /* check result */
2913 {
2914 handle->debug_print("mpu9250: reset fifo failed.\n"); /* reset fifo failed */
2915
2916 return 1; /* return error */
2917 }
2918 }
2919
2920 handle->mask = mask | MPU9250_DMP_FEATURE_PEDOMETER; /* set the mask */
2921
2922 return a_mpu9250_reset_fifo(handle); /* reset the fifo */
2923 }
2924
2938 uint8_t mpu9250_dmp_set_fifo_rate(mpu9250_handle_t *handle, uint16_t rate)
2939 {
2940 uint8_t regs_end[12] = {0xFE, 0xF2, 0xAB,
2941 0xC4, 0xAA, 0xF1,
2942 0xDF, 0xDF, 0xBB,
2943 0xAF, 0xDF, 0xDF};
2944 uint8_t res;
2945 uint16_t d;
2946 uint8_t tmp[2];
2947
2948 if (handle == NULL) /* check handle */
2949 {
2950 return 2; /* return error */
2951 }
2952 if (handle->inited != 1) /* check handle initialization */
2953 {
2954 return 3; /* return error */
2955 }
2956 if (handle->dmp_inited != 1) /* check dmp initialization */
2957 {
2958 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
2959
2960 return 4; /* return error */
2961 }
2962 if (rate > MPU9250_DMP_SAMPLE_RATE) /* check rate */
2963 {
2964 handle->debug_print("mpu9250: rate > 200.\n"); /* rate > 200 */
2965
2966 return 5; /* return error */
2967 }
2968
2969 d = MPU9250_DMP_SAMPLE_RATE / rate - 1; /* set div */
2970 tmp[0] = (uint8_t)((d >> 8) & 0xFF); /* set tmp part0 */
2971 tmp[1] = (uint8_t)(d & 0xFF); /* set tmp part1 */
2972
2973 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_0_22, tmp, 2); /* write data */
2974 if (res != 0) /* check result */
2975 {
2976 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2977
2978 return 1; /* return error */
2979 }
2980 res = a_mpu9250_write_mem(handle, MPU9250_DMP_CFG_6,
2981 (uint8_t *)regs_end, 12); /* write data */
2982 if (res != 0) /* check result */
2983 {
2984 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
2985
2986 return 1; /* return error */
2987 }
2988
2989 return 0; /* success return 0 */
2990 }
2991
3004 uint8_t mpu9250_dmp_get_fifo_rate(mpu9250_handle_t *handle, uint16_t *rate)
3005 {
3006 uint8_t res;
3007 uint16_t d;
3008 uint8_t tmp[2];
3009
3010 if (handle == NULL) /* check handle */
3011 {
3012 return 2; /* return error */
3013 }
3014 if (handle->inited != 1) /* check handle initialization */
3015 {
3016 return 3; /* return error */
3017 }
3018 if (handle->dmp_inited != 1) /* check dmp initialization */
3019 {
3020 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
3021
3022 return 4; /* return error */
3023 }
3024
3025 res = a_mpu9250_read_mem(handle, MPU9250_DMP_D_0_22, tmp, 2); /* read data */
3026 if (res != 0) /* check result */
3027 {
3028 handle->debug_print("mpu9250: read mem failed.\n"); /* read mem failed */
3029
3030 return 1; /* return error */
3031 }
3032 d = (uint16_t)tmp[0] << 8 | tmp[1]; /* get the div */
3033 *rate = MPU9250_DMP_SAMPLE_RATE / (d + 1); /* set the rate */
3034
3035 return 0; /* success return 0 */
3036 }
3037
3051 uint8_t mpu9250_dmp_set_tap_axes(mpu9250_handle_t *handle, mpu9250_axis_t axis, mpu9250_bool_t enable)
3052 {
3053 uint8_t res;
3054 uint8_t tmp;
3055 uint8_t pos;
3056
3057 if (handle == NULL) /* check handle */
3058 {
3059 return 2; /* return error */
3060 }
3061 if (handle->inited != 1) /* check handle initialization */
3062 {
3063 return 3; /* return error */
3064 }
3065 if (handle->dmp_inited != 1) /* check dmp initialization */
3066 {
3067 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
3068
3069 return 4; /* return error */
3070 }
3071
3072 res = a_mpu9250_read_mem(handle, MPU9250_DMP_D_1_72, &tmp, 1); /* read data */
3073 if (res != 0) /* check result */
3074 {
3075 handle->debug_print("mpu9250: read mem failed.\n"); /* read mem failed */
3076
3077 return 1; /* return error */
3078 }
3079 pos = (uint8_t)((axis - 5) * 2); /* get the pos */
3080 if (enable == MPU9250_BOOL_TRUE) /* if enable */
3081 {
3082 tmp |= (3 << pos); /* enable */
3083 }
3084 else
3085 {
3086 tmp &= ~(3 << pos); /* disable */
3087 }
3088 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_1_72, &tmp, 1); /* write data */
3089 if (res != 0) /* check result */
3090 {
3091 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
3092
3093 return 1; /* return error */
3094 }
3095
3096 return 0; /* success return 0 */
3097 }
3098
3112 uint8_t mpu9250_dmp_get_tap_axes(mpu9250_handle_t *handle, mpu9250_axis_t axis, mpu9250_bool_t *enable)
3113 {
3114 uint8_t res;
3115 uint8_t tmp;
3116 uint8_t pos;
3117
3118 if (handle == NULL) /* check handle */
3119 {
3120 return 2; /* return error */
3121 }
3122 if (handle->inited != 1) /* check handle initialization */
3123 {
3124 return 3; /* return error */
3125 }
3126 if (handle->dmp_inited != 1) /* check dmp initialization */
3127 {
3128 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
3129
3130 return 4; /* return error */
3131 }
3132
3133 res = a_mpu9250_read_mem(handle, MPU9250_DMP_D_1_72, &tmp, 1); /* read data */
3134 if (res != 0) /* check result */
3135 {
3136 handle->debug_print("mpu9250: read mem failed.\n"); /* read mem failed */
3137
3138 return 1; /* return error */
3139 }
3140 pos = (uint8_t)((axis - 5) * 2); /* get the pos */
3141 if (((tmp >> pos) & 0x3) == 0x3) /* if enable */
3142 {
3143 *enable = MPU9250_BOOL_TRUE; /* set enable */
3144 }
3145 else
3146 {
3147 *enable = MPU9250_BOOL_FALSE; /* set disable */
3148 }
3149
3150 return 0; /* success return 0 */
3151 }
3152
3168 uint8_t mpu9250_dmp_set_tap_thresh(mpu9250_handle_t *handle, mpu9250_axis_t axis, uint16_t mg_ms)
3169 {
3170 uint8_t res;
3171 uint8_t prev;
3172 uint8_t range;
3173 uint8_t tmp[4];
3174 uint16_t dmp_thresh;
3175 uint16_t dmp_thresh_2;
3176 float scaled_thresh;
3177
3178 if (handle == NULL) /* check handle */
3179 {
3180 return 2; /* return error */
3181 }
3182 if (handle->inited != 1) /* check handle initialization */
3183 {
3184 return 3; /* return error */
3185 }
3186 if (handle->dmp_inited != 1) /* check dmp initialization */
3187 {
3188 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
3189
3190 return 4; /* return error */
3191 }
3192 if (mg_ms > 1600) /* check the mg/ms */
3193 {
3194 handle->debug_print("mpu9250: mg/ms > 1600.\n"); /* mg/ms > 1600 */
3195
3196 return 5; /* return error */
3197 }
3198
3199 scaled_thresh = (float)mg_ms / MPU9250_DMP_SAMPLE_RATE; /* get the scaled thresh */
3200 res = a_mpu9250_read(handle, MPU9250_REG_ACCEL_CONFIG,
3201 (uint8_t *)&prev, 1); /* read accelerometer config */
3202 if (res != 0) /* check result */
3203 {
3204 handle->debug_print("mpu9250: read accelerometer config failed.\n"); /* read accelerometer config failed */
3205
3206 return 1; /* return error */
3207 }
3208 range = ((prev >> 3) & 0x3); /* get the range */
3209 if (range == 0) /* if 2g */
3210 {
3211 dmp_thresh = (uint16_t)(scaled_thresh * 16384); /* set dmp thresh */
3212 dmp_thresh_2 = (uint16_t)(scaled_thresh * 12288); /* set dmp thresh2 */
3213 }
3214 else if (range == 1) /* if 4g */
3215 {
3216 dmp_thresh = (uint16_t)(scaled_thresh * 8192); /* set dmp thresh */
3217 dmp_thresh_2 = (uint16_t)(scaled_thresh * 6144); /* set dmp thresh2 */
3218 }
3219 else if (range == 2) /* if 8g */
3220 {
3221 dmp_thresh = (uint16_t)(scaled_thresh * 4096); /* set dmp thresh */
3222 dmp_thresh_2 = (uint16_t)(scaled_thresh * 3072); /* set dmp thresh2 */
3223 }
3224 else /* if 16g */
3225 {
3226 dmp_thresh = (uint16_t)(scaled_thresh * 2048); /* set dmp thresh */
3227 dmp_thresh_2 = (uint16_t)(scaled_thresh * 1536); /* set dmp thresh2 */
3228 }
3229 tmp[0] = (uint8_t)(dmp_thresh >> 8); /* set part 0 */
3230 tmp[1] = (uint8_t)(dmp_thresh & 0xFF); /* set part 1 */
3231 tmp[2] = (uint8_t)(dmp_thresh_2 >> 8); /* set part 2 */
3232 tmp[3] = (uint8_t)(dmp_thresh_2 & 0xFF); /* set part 3 */
3233
3234 if (axis == MPU9250_AXIS_X) /* if axis x */
3235 {
3236 res = a_mpu9250_write_mem(handle, MPU9250_DMP_TAP_THX, tmp, 2); /* write tap threshold x */
3237 if (res != 0) /* check result */
3238 {
3239 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
3240
3241 return 1; /* return error */
3242 }
3243 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_1_36, tmp + 2, 2); /* write register 36 */
3244 if (res != 0) /* check result */
3245 {
3246 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
3247
3248 return 1; /* return error */
3249 }
3250
3251 return 0; /* success return 0 */
3252 }
3253 else if (axis == MPU9250_AXIS_Y) /* if axis y */
3254 {
3255 res = a_mpu9250_write_mem(handle, MPU9250_DMP_TAP_THY, tmp, 2); /* write tap threshold y */
3256 if (res != 0) /* check result */
3257 {
3258 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
3259
3260 return 1; /* return error */
3261 }
3262 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_1_40, tmp + 2, 2); /* write register 40 */
3263 if (res != 0) /* check result */
3264 {
3265 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
3266
3267 return 1; /* return error */
3268 }
3269
3270 return 0; /* success return 0 */
3271 }
3272 else if (axis == MPU9250_AXIS_Z) /* if axis z */
3273 {
3274 res = a_mpu9250_write_mem(handle, MPU9250_DMP_TAP_THZ, tmp, 2); /* write tap threshold z */
3275 if (res != 0) /* check result */
3276 {
3277 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
3278
3279 return 1; /* return error */
3280 }
3281 res = a_mpu9250_write_mem(handle, MPU9250_DMP_D_1_44, tmp + 2, 2); /* write register 44 */
3282 if (res != 0) /* check result */
3283 {
3284 handle->debug_print("mpu9250: write mem failed.\n"); /* write mem failed */
3285
3286 return 1; /* return error */
3287 }
3288
3289 return 0; /* success return 0 */
3290 }
3291 else
3292 {
3293 handle->debug_print("mpu9250: invalid axis.\n"); /* invalid axis */
3294
3295 return 6; /* return error */
3296 }
3297 }
3298
3313 uint8_t mpu9250_dmp_get_tap_thresh(mpu9250_handle_t *handle, mpu9250_axis_t axis, uint16_t *mg_ms)
3314 {
3315 uint8_t res;
3316 uint8_t prev;
3317 uint8_t range;
3318 uint8_t tmp[2];
3319 uint16_t dmp_thresh;
3320 float scaled_thresh;
3321
3322 if (handle == NULL) /* check handle */
3323 {
3324 return 2; /* return error */
3325 }
3326 if (handle->inited != 1) /* check handle initialization */
3327 {
3328 return 3; /* return error */
3329 }
3330 if (handle->dmp_inited != 1) /* check dmp initialization */
3331 {
3332 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
3333
3334 return 4; /* return error */
3335 }
3336
3337 if (axis == MPU9250_AXIS_X) /* if axis x */
3338 {
3339 res = a_mpu9250_read_mem(handle, MPU9250_DMP_TAP_THX, tmp, 2); /* read tap threshold x */
3340 if (res != 0) /* check result */
3341 {
3342 handle->debug_print("mpu9250: read mem failed.\n"); /* read mem failed */
3343
3344 return 1; /* return error */
3345 }
3346 }
3347 else if (axis == MPU9250_AXIS_Y) /* if axis y */
3348 {
3349 res = a_mpu9250_read_mem(handle, MPU9250_DMP_TAP_THY, tmp, 2); /* read tap threshold y */
3350 if (res != 0) /* check result */
3351 {
3352 handle->debug_print("mpu9250: read mem failed.\n"); /* read mem failed */
3353
3354 return 1; /* return error */
3355 }
3356 }
3357 else if (axis == MPU9250_AXIS_Z) /* if axis z */
3358 {
3359 res = a_mpu9250_read_mem(handle, MPU9250_DMP_TAP_THZ, tmp, 2); /* read tap threshold z */
3360 if (res != 0) /* check result */
3361 {
3362 handle->debug_print("mpu9250: read mem failed.\n"); /* read mem failed */
3363
3364 return 1; /* return error */
3365 }
3366 }
3367 else
3368 {
3369 handle->debug_print("mpu9250: invalid axis.\n"); /* invalid axis */
3370
3371 return 5; /* return error */
3372 }
3373 dmp_thresh = (uint16_t)tmp[0] << 8 | tmp[1]; /* set the dmp thresh */
3374
3375 res = a_mpu9250_read(handle, MPU9250_REG_ACCEL_CONFIG,
3376 (uint8_t *)&prev, 1); /* read accelerometer config */
3377 if (res != 0) /* check result */
3378 {
3379 handle->debug_print("mpu9250: read accelerometer config failed.\n"); /* read accelerometer config failed */
3380
3381 return 1; /* return error */
3382 }
3383 range = ((prev >> 3) & 0x3); /* get the range */
3384 if (range == 0) /* if 2g */
3385 {
3386 scaled_thresh = dmp_thresh / 16384.0f; /* set dmp thresh */
3387 }
3388 else if (range == 1) /* if 4g */
3389 {
3390 scaled_thresh = dmp_thresh / 8192.0f; /* set dmp thresh */
3391 }
3392 else if (range == 2) /* if 8g */
3393 {
3394 scaled_thresh = dmp_thresh / 4096.0f; /* set dmp thresh */
3395 }
3396 else /* if 16g */
3397 {
3398 scaled_thresh = dmp_thresh / 2048.0f; /* set dmp thresh */
3399 }
3400 *mg_ms = (uint16_t)(scaled_thresh * MPU9250_DMP_SAMPLE_RATE); /* set the mg/ms */
3401
3402 return 0; /* success return 0 */
3403 }
3404
3429 uint8_t mpu9250_dmp_read(mpu9250_handle_t *handle,
3430 int16_t (*accel_raw)[3], float (*accel_g)[3],
3431 int16_t (*gyro_raw)[3], float (*gyro_dps)[3],
3432 int32_t (*quat)[4],
3433 float *pitch, float *roll, float *yaw,
3434 uint16_t *l
3435 )
3436 {
3437 uint8_t res;
3438 uint8_t i = 0;
3439 uint16_t len;
3440 uint8_t buf[2];
3441 uint8_t prev;
3442 uint16_t count;
3443 uint16_t j;
3444
3445 if (handle == NULL) /* check handle */
3446 {
3447 return 2; /* return error */
3448 }
3449 if (handle->inited != 1) /* check handle initialization */
3450 {
3451 return 3; /* return error */
3452 }
3453 if (handle->dmp_inited != 1) /* check dmp initialization */
3454 {
3455 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
3456
3457 return 4; /* return error */
3458 }
3459
3460 res = a_mpu9250_read(handle, MPU9250_REG_INT_STATUS, (uint8_t *)&prev, 1); /* read config */
3461 if (res != 0) /* check result */
3462 {
3463 handle->debug_print("mpu9250: read int status failed.\n"); /* read int status failed */
3464
3465 return 1; /* return error */
3466 }
3467 if ((prev & (1 << MPU9250_INTERRUPT_FIFO_OVERFLOW)) != 0) /* if fifo overflow */
3468 {
3469 handle->debug_print("mpu9250: fifo overflow.\n"); /* fifo overflow */
3470 (void)a_mpu9250_reset_fifo(handle); /* reset the fifo */
3471
3472 return 6; /* return error */
3473 }
3474
3475 len = 0; /* set len 0 */
3476 if ((handle->mask & MPU9250_DMP_FEATURE_SEND_RAW_ACCEL) != 0) /* check the accel */
3477 {
3478 len += 6; /* size += 6 */
3479 }
3480 if ((handle->mask & MPU9250_DMP_FEATURE_SEND_ANY_GYRO) != 0) /* check the gyro */
3481 {
3482 len += 6; /* size += 6 */
3483 }
3484 if ((handle->mask & (MPU9250_DMP_FEATURE_3X_QUAT | MPU9250_DMP_FEATURE_6X_QUAT)) != 0) /* check the quat */
3485 {
3486 len += 16; /* size += 16 */
3487 }
3488 if ((handle->mask & (MPU9250_DMP_FEATURE_TAP | MPU9250_DMP_FEATURE_ORIENT)) != 0) /* check the tap and orient */
3489 {
3490 len += 4; /* size += 4 */
3491 }
3492 if (len == 0) /* check the len */
3493 {
3494 handle->debug_print("mpu9250: no data.\n"); /* no data */
3495
3496 return 8; /* return error */
3497 }
3498
3499 res = a_mpu9250_read(handle, MPU9250_REG_FIFO_COUNTH, (uint8_t *)buf, 2); /* read fifo count */
3500 if (res != 0) /* check result */
3501 {
3502 handle->debug_print("mpu9250: read fifo count failed.\n"); /* read fifo count failed */
3503
3504 return 1; /* return error */
3505 }
3506 count = (uint16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set count */
3507 count = (count < 1024) ? count : 1024; /* just the counter */
3508 count = (count < (*l) * len) ? count : ((*l) *len); /* just outer buffer size */
3509 count = (count / len) * len; /* len times */
3510 *l = count / len; /* set the output length */
3511 res = a_mpu9250_read(handle, MPU9250_REG_R_W, handle->buf, count); /* read data */
3512 if (res != 0) /* check result */
3513 {
3514 handle->debug_print("mpu9250: read failed.\n"); /* read failed */
3515
3516 return 1; /* return error */
3517 }
3518 if (count < len) /* check the count */
3519 {
3520 handle->debug_print("mpu9250: fifo data is too little.\n"); /* fifo data is too little */
3521
3522 return 7; /* return error */
3523 }
3524
3525 for (j = 0; j < (*l); j++) /* (*l) times */
3526 {
3527 if ((handle->mask & (MPU9250_DMP_FEATURE_3X_QUAT | MPU9250_DMP_FEATURE_6X_QUAT)) != 0) /* check the quat */
3528 {
3529 int32_t quat_q14[4];
3530 int32_t quat_mag_sq;
3531 float q0 = 1.0f, q1 = 0.0f, q2 = 0.0f, q3 = 0.0f;
3532
3533 i = 0; /* set 0 */
3534 quat[j][0] = ((int32_t)handle->buf[0 + len * j] << 24) | ((int32_t)handle->buf[1 + len * j] << 16) |
3535 ((int32_t)handle->buf[2 + len * j] << 8) | handle->buf[3 + len * j]; /* set the quat 0 */
3536 quat[j][1] = ((int32_t)handle->buf[4 + len * j] << 24) | ((int32_t)handle->buf[5 + len * j] << 16) |
3537 ((int32_t)handle->buf[6 + len * j] << 8) | handle->buf[7 + len * j]; /* set the quat 1 */
3538 quat[j][2] = ((int32_t)handle->buf[8 + len * j] << 24) | ((int32_t)handle->buf[9 + len * j] << 16) |
3539 ((int32_t)handle->buf[10 + len * j] << 8) | handle->buf[11 + len * j]; /* set the quat 2 */
3540 quat[j][3] = ((int32_t)handle->buf[12 + len * j] << 24) | ((int32_t)handle->buf[13 + len * j] << 16) |
3541 ((int32_t)handle->buf[14 + len * j] << 8) | handle->buf[15 + len * j]; /* set the quat 3 */
3542 i += 16; /* size += 16 */
3543
3544 quat_q14[0] = quat[j][0] >> 16; /* set the quat q14[0] */
3545 quat_q14[1] = quat[j][1] >> 16; /* set the quat q14[1] */
3546 quat_q14[2] = quat[j][2] >> 16; /* set the quat q14[2] */
3547 quat_q14[3] = quat[j][3] >> 16; /* set the quat q14[3] */
3548 quat_mag_sq = quat_q14[0] * quat_q14[0] + quat_q14[1] * quat_q14[1] +
3549 quat_q14[2] * quat_q14[2] + quat_q14[3] * quat_q14[3]; /* get the quat mag sq */
3550 if ((quat_mag_sq < MPU9250_DMP_QUAT_MAG_SQ_MIN) ||
3551 (quat_mag_sq > MPU9250_DMP_QUAT_MAG_SQ_MAX)) /* check the size */
3552 {
3553 handle->debug_print("mpu9250: quat check error.\n"); /* quat check error */
3554 (void)a_mpu9250_reset_fifo(handle); /* reset the fifo */
3555
3556 return 5; /* return error */
3557 }
3558 q0 = quat[j][0] / 1073741824.0f; /* set q0 */
3559 q1 = quat[j][1] / 1073741824.0f; /* set q1 */
3560 q2 = quat[j][2] / 1073741824.0f; /* set q2 */
3561 q3 = quat[j][3] / 1073741824.0f; /* set q3 */
3562 pitch[j] = asinf(-2 * q1 * q3 + 2 * q0* q2)* 57.3f; /* set pitch */
3563 roll[j] = atan2f(2 * q2 * q3 + 2 * q0 * q1, -2 * q1 * q1 - 2 * q2 * q2 + 1)* 57.3f; /* set roll */
3564 yaw[j] = atan2f(2 * (q1 * q2 + q0 * q3), q0 * q0 + q1 * q1 - q2 * q2 - q3 * q3) * 57.3f; /* set yaw */
3565 }
3566 else
3567 {
3568 quat[j][0] = 0; /* set 0 */
3569 quat[j][1] = 0; /* set 0 */
3570 quat[j][2] = 0; /* set 0 */
3571 quat[j][3] = 0; /* set 0 */
3572 pitch[j] = 0.0f; /* set 0.0f */
3573 roll[j] = 0.0f; /* set 0.0f */
3574 yaw[j] = 0.0f; /* set 0.0f */
3575 }
3576 if ((handle->mask & MPU9250_DMP_FEATURE_SEND_RAW_ACCEL) != 0) /* check the accel */
3577 {
3578 uint8_t accel_conf;
3579
3580 accel_raw[j][0] = ((int16_t)handle->buf[i + 0 + len * j] << 8) | handle->buf[i + 1 + len * j]; /* set the accel x raw data */
3581 accel_raw[j][1] = ((int16_t)handle->buf[i + 2 + len * j] << 8) | handle->buf[i + 3 + len * j]; /* set the accel y raw data */
3582 accel_raw[j][2] = ((int16_t)handle->buf[i + 4 + len * j] << 8) | handle->buf[i + 5 + len * j]; /* set the accel z raw data */
3583 i += 6; /* size += 6 */
3584
3585 res = a_mpu9250_read(handle, MPU9250_REG_ACCEL_CONFIG, (uint8_t *)&accel_conf, 1); /* read accel config */
3586 if (res != 0) /* check result */
3587 {
3588 handle->debug_print("mpu9250: read accel config failed.\n"); /* read accel config failed */
3589
3590 return 1; /* return error */
3591 }
3592 accel_conf = (accel_conf >> 3) & 0x3; /* get the accel conf */
3593 if (accel_conf == 0) /* ±2g */
3594 {
3595 accel_g[j][0] = (float)(accel_raw[j][0]) / 16384.0f; /* set accel x */
3596 accel_g[j][1] = (float)(accel_raw[j][1]) / 16384.0f; /* set accel y */
3597 accel_g[j][2] = (float)(accel_raw[j][2]) / 16384.0f; /* set accel z */
3598 }
3599 else if (accel_conf == 1) /* ±4g */
3600 {
3601 accel_g[j][0] = (float)(accel_raw[j][0]) / 8192.0f; /* set accel x */
3602 accel_g[j][1] = (float)(accel_raw[j][1]) / 8192.0f; /* set accel y */
3603 accel_g[j][2] = (float)(accel_raw[j][2]) / 8192.0f; /* set accel z */
3604 }
3605 else if (accel_conf == 2) /* ±8g */
3606 {
3607 accel_g[j][0] = (float)(accel_raw[j][0]) / 4096.0f; /* set accel x */
3608 accel_g[j][1] = (float)(accel_raw[j][1]) / 4096.0f; /* set accel y */
3609 accel_g[j][2] = (float)(accel_raw[j][2]) / 4096.0f; /* set accel z */
3610 }
3611 else /* ±16g */
3612 {
3613 accel_g[j][0] = (float)(accel_raw[j][0]) / 2048.0f; /* set accel x */
3614 accel_g[j][1] = (float)(accel_raw[j][1]) / 2048.0f; /* set accel y */
3615 accel_g[j][2] = (float)(accel_raw[j][2]) / 2048.0f; /* set accel z */
3616 }
3617 }
3618 else
3619 {
3620 accel_raw[j][0] = 0; /* set 0 */
3621 accel_raw[j][1] = 0; /* set 0 */
3622 accel_raw[j][2] = 0; /* set 0 */
3623 accel_g[j][0] = 0.0f; /* set 0.0f */
3624 accel_g[j][1] = 0.0f; /* set 0.0f */
3625 accel_g[j][2] = 0.0f; /* set 0.0f */
3626 }
3627 if ((handle->mask & MPU9250_DMP_FEATURE_SEND_ANY_GYRO) != 0) /* check the gyro */
3628 {
3629 uint8_t gyro_conf;
3630
3631 gyro_raw[j][0] = ((int16_t)handle->buf[i + 0 + len * j] << 8) | handle->buf[i + 1 + len * j]; /* set the gyro x raw data */
3632 gyro_raw[j][1] = ((int16_t)handle->buf[i + 2 + len * j] << 8) | handle->buf[i + 3 + len * j]; /* set the gyro y raw data */
3633 gyro_raw[j][2] = ((int16_t)handle->buf[i + 4 + len * j] << 8) | handle->buf[i + 5 + len * j]; /* set the gyro z raw data */
3634 i += 6; /* size += 6 */
3635
3636 res = a_mpu9250_read(handle, MPU9250_REG_GYRO_CONFIG, (uint8_t *)&gyro_conf, 1); /* read gyro config */
3637 if (res != 0) /* check result */
3638 {
3639 handle->debug_print("mpu9250: read gyro config failed.\n"); /* read gyro config failed */
3640
3641 return 1; /* return error */
3642 }
3643 gyro_conf = (gyro_conf >> 3) & 0x3; /* get the gyro conf */
3644 if (gyro_conf == 0) /* ±250dps */
3645 {
3646 gyro_dps[j][0] = (float)(gyro_raw[j][0]) / 131.0f; /* set gyro x */
3647 gyro_dps[j][1] = (float)(gyro_raw[j][1]) / 131.0f; /* set gyro y */
3648 gyro_dps[j][2] = (float)(gyro_raw[j][2]) / 131.0f; /* set gyro z */
3649 }
3650 else if (gyro_conf == 1) /* ±500dps */
3651 {
3652 gyro_dps[j][0] = (float)(gyro_raw[j][0]) / 65.5f; /* set gyro x */
3653 gyro_dps[j][1] = (float)(gyro_raw[j][1]) / 65.5f; /* set gyro y */
3654 gyro_dps[j][2] = (float)(gyro_raw[j][2]) / 65.5f; /* set gyro z */
3655 }
3656 else if (gyro_conf == 2) /* ±1000dps */
3657 {
3658 gyro_dps[j][0] = (float)(gyro_raw[j][0]) / 32.8f; /* set gyro x */
3659 gyro_dps[j][1] = (float)(gyro_raw[j][1]) / 32.8f; /* set gyro y */
3660 gyro_dps[j][2] = (float)(gyro_raw[j][2]) / 32.8f; /* set gyro z */
3661 }
3662 else /* ±2000dps */
3663 {
3664 gyro_dps[j][0] = (float)(gyro_raw[j][0]) / 16.4f; /* set gyro x */
3665 gyro_dps[j][1] = (float)(gyro_raw[j][1]) / 16.4f; /* set gyro y */
3666 gyro_dps[j][2] = (float)(gyro_raw[j][2]) / 16.4f; /* set gyro z */
3667 }
3668 }
3669 else
3670 {
3671 gyro_raw[j][0] = 0; /* set 0 */
3672 gyro_raw[j][1] = 0; /* set 0 */
3673 gyro_raw[j][2] = 0; /* set 0 */
3674 gyro_dps[j][0] = 0.0f; /* set 0.0f */
3675 gyro_dps[j][1] = 0.0f; /* set 0.0f */
3676 gyro_dps[j][2] = 0.0f; /* set 0.0f */
3677 }
3678 if ((handle->mask & (MPU9250_DMP_FEATURE_TAP | MPU9250_DMP_FEATURE_ORIENT)) != 0) /* check the tap and orient */
3679 {
3680 a_mpu9250_dmp_decode_gesture(handle, handle->buf + i + len * j); /* run the decode gesture */
3681 }
3682 }
3683
3684 return 0; /* success return 0 */
3685 }
3686
3699 uint8_t mpu9250_dmp_set_tap_callback(mpu9250_handle_t *handle, void (*callback)(uint8_t count, uint8_t direction))
3700 {
3701 if (handle == NULL) /* check handle */
3702 {
3703 return 2; /* return error */
3704 }
3705 if (handle->inited != 1) /* check handle initialization */
3706 {
3707 return 3; /* return error */
3708 }
3709 if (handle->dmp_inited != 1) /* check dmp initialization */
3710 {
3711 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
3712
3713 return 4; /* return error */
3714 }
3715
3716 handle->dmp_tap_callback = callback; /* set the callback */
3717
3718 return 0; /* success return 0 */
3719 }
3720
3733 uint8_t mpu9250_dmp_set_orient_callback(mpu9250_handle_t *handle, void (*callback)(uint8_t orientation))
3734 {
3735 if (handle == NULL) /* check handle */
3736 {
3737 return 2; /* return error */
3738 }
3739 if (handle->inited != 1) /* check handle initialization */
3740 {
3741 return 3; /* return error */
3742 }
3743 if (handle->dmp_inited != 1) /* check dmp initialization */
3744 {
3745 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
3746
3747 return 4; /* return error */
3748 }
3749
3750 handle->dmp_orient_callback = callback; /* set the callback */
3751
3752 return 0; /* success return 0 */
3753 }
3754
3767 uint8_t mpu9250_dmp_set_enable(mpu9250_handle_t *handle, mpu9250_bool_t enable)
3768 {
3769 uint8_t res;
3770 uint8_t prev;
3771
3772 if (handle == NULL) /* check handle */
3773 {
3774 return 2; /* return error */
3775 }
3776 if (handle->inited != 1) /* check handle initialization */
3777 {
3778 return 3; /* return error */
3779 }
3780 if (handle->dmp_inited != 1) /* check dmp initialization */
3781 {
3782 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
3783
3784 return 4; /* return error */
3785 }
3786
3787 res = a_mpu9250_read(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
3788 if (res != 0) /* check result */
3789 {
3790 handle->debug_print("mpu9250: read user ctrl failed.\n"); /* read user ctrl failed */
3791
3792 return 1; /* return error */
3793 }
3794 prev &= ~(1 << 7); /* clear config */
3795 prev |= enable << 7; /* set config */
3796 res = a_mpu9250_write(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
3797 if (res != 0) /* check result */
3798 {
3799 handle->debug_print("mpu9250: write user ctrl failed.\n"); /* write user ctrl failed */
3800
3801 return 1; /* return error */
3802 }
3803
3804 return 0; /* success return 0 */
3805 }
3806
3822 uint8_t mpu9250_dmp_gyro_accel_raw_offset_convert(mpu9250_handle_t *handle,
3823 int32_t gyro_offset_raw[3], int32_t accel_offset_raw[3],
3824 int32_t gyro_offset[3], int32_t accel_offset[3])
3825 {
3826 uint8_t res;
3827 uint8_t accel_conf;
3828 uint8_t gyro_conf;
3829
3830 if (handle == NULL) /* check handle */
3831 {
3832 return 2; /* return error */
3833 }
3834 if (handle->inited != 1) /* check handle initialization */
3835 {
3836 return 3; /* return error */
3837 }
3838 if (handle->dmp_inited != 1) /* check dmp initialization */
3839 {
3840 handle->debug_print("mpu9250: dmp is not inited.\n"); /* dmp is not inited */
3841
3842 return 4; /* return error */
3843 }
3844
3845 res = a_mpu9250_read(handle, MPU9250_REG_ACCEL_CONFIG, (uint8_t *)&accel_conf, 1); /* read accel config */
3846 if (res != 0) /* check result */
3847 {
3848 handle->debug_print("mpu9250: read accel config failed.\n"); /* read accel config failed */
3849
3850 return 1; /* return error */
3851 }
3852 res = a_mpu9250_read(handle, MPU9250_REG_GYRO_CONFIG, (uint8_t *)&gyro_conf, 1); /* read gyro config */
3853 if (res != 0) /* check result */
3854 {
3855 handle->debug_print("mpu9250: read gyro config failed.\n"); /* read gyro config failed */
3856
3857 return 1; /* return error */
3858 }
3859 accel_conf = (accel_conf >> 3) & 0x3; /* get the accel conf */
3860 gyro_conf = (gyro_conf >> 3) & 0x3; /* get the gyro conf */
3861 if (accel_conf == 0) /* ±2g */
3862 {
3863 accel_offset[0] = (int32_t)(accel_offset_raw[0] * 16384.0f); /* set accel offset 0 */
3864 accel_offset[1] = (int32_t)(accel_offset_raw[1] * 16384.0f); /* set accel offset 1 */
3865 accel_offset[2] = (int32_t)(accel_offset_raw[2] * 16384.0f); /* set accel offset 2 */
3866 }
3867 else if (accel_conf == 1) /* ±4g */
3868 {
3869 accel_offset[0] = (int32_t)(accel_offset_raw[0] * 8192.0f); /* set accel offset 0 */
3870 accel_offset[1] = (int32_t)(accel_offset_raw[1] * 8192.0f); /* set accel offset 1 */
3871 accel_offset[2] = (int32_t)(accel_offset_raw[2] * 8192.0f); /* set accel offset 2 */
3872 }
3873 else if (accel_conf == 2) /* ±8g */
3874 {
3875 accel_offset[0] = (int32_t)(accel_offset_raw[0] * 4096.0f); /* set accel offset 0 */
3876 accel_offset[1] = (int32_t)(accel_offset_raw[1] * 4096.0f); /* set accel offset 1 */
3877 accel_offset[2] = (int32_t)(accel_offset_raw[2] * 4096.0f); /* set accel offset 2 */
3878 }
3879 else /* ±16g */
3880 {
3881 accel_offset[0] = (int32_t)(accel_offset_raw[0] * 2048.0f); /* set accel offset 0 */
3882 accel_offset[1] = (int32_t)(accel_offset_raw[1] * 2048.0f); /* set accel offset 1 */
3883 accel_offset[2] = (int32_t)(accel_offset_raw[2] * 2048.0f); /* set accel offset 2 */
3884 }
3885 if (gyro_conf == 0) /* ±250dps */
3886 {
3887 gyro_offset[0] = (int32_t)(gyro_offset_raw[0] * 131.f); /* set gyro offset 0 */
3888 gyro_offset[1] = (int32_t)(gyro_offset_raw[1] * 131.f); /* set gyro offset 1 */
3889 gyro_offset[2] = (int32_t)(gyro_offset_raw[2] * 131.f); /* set gyro offset 2 */
3890 }
3891 else if (gyro_conf == 1) /* ±500dps */
3892 {
3893 gyro_offset[0] = (int32_t)(gyro_offset_raw[0] * 65.5f); /* set gyro offset 0 */
3894 gyro_offset[1] = (int32_t)(gyro_offset_raw[1] * 65.5f); /* set gyro offset 1 */
3895 gyro_offset[2] = (int32_t)(gyro_offset_raw[2] * 65.5f); /* set gyro offset 2 */
3896 }
3897 else if (gyro_conf == 2) /* ±1000dps */
3898 {
3899 gyro_offset[0] = (int32_t)(gyro_offset_raw[0] * 32.8f); /* set gyro offset 0 */
3900 gyro_offset[1] = (int32_t)(gyro_offset_raw[1] * 32.8f); /* set gyro offset 1 */
3901 gyro_offset[2] = (int32_t)(gyro_offset_raw[2] * 32.8f); /* set gyro offset 2 */
3902 }
3903 else /* ±2000dps */
3904 {
3905 gyro_offset[0] = (int32_t)(gyro_offset_raw[0] * 16.4f); /* set gyro offset 0 */
3906 gyro_offset[1] = (int32_t)(gyro_offset_raw[1] * 16.4f); /* set gyro offset 1 */
3907 gyro_offset[2] = (int32_t)(gyro_offset_raw[2] * 16.4f); /* set gyro offset 2 */
3908 }
3909
3910 return 0; /* success return 0 */
3911 }
3912
3922 uint8_t mpu9250_set_interface(mpu9250_handle_t *handle, mpu9250_interface_t interface)
3923 {
3924 if (handle == NULL) /* check handle */
3925 {
3926 return 2; /* return error */
3927 }
3928
3929 handle->iic_spi = (uint8_t)interface; /* set interface */
3930
3931 return 0; /* success return 0 */
3932 }
3933
3943 uint8_t mpu9250_get_interface(mpu9250_handle_t *handle, mpu9250_interface_t *interface)
3944 {
3945 if (handle == NULL) /* check handle */
3946 {
3947 return 2; /* return error */
3948 }
3949
3950 *interface = (mpu9250_interface_t)(handle->iic_spi); /* get interface */
3951
3952 return 0; /* success return 0 */
3953 }
3954
3964 uint8_t mpu9250_set_addr_pin(mpu9250_handle_t *handle, mpu9250_address_t addr_pin)
3965 {
3966 if (handle == NULL) /* check handle */
3967 {
3968 return 2; /* return error */
3969 }
3970
3971 handle->iic_addr = (uint8_t)addr_pin; /* set iic addr */
3972
3973 return 0; /* success return 0 */
3974 }
3975
3985 uint8_t mpu9250_get_addr_pin(mpu9250_handle_t *handle, mpu9250_address_t *addr_pin)
3986 {
3987 if (handle == NULL) /* check handle */
3988 {
3989 return 2; /* return error */
3990 }
3991
3992 *addr_pin = (mpu9250_address_t)(handle->iic_addr); /* get iic addr */
3993
3994 return 0; /* success return 0 */
3995 }
3996
4009 uint8_t mpu9250_init(mpu9250_handle_t *handle)
4010 {
4011 uint8_t res, prev;
4012 uint32_t timeout;
4013
4014 if (handle == NULL) /* check handle */
4015 {
4016 return 2; /* return error */
4017 }
4018 if (handle->debug_print == NULL) /* check debug_print */
4019 {
4020 return 3; /* return error */
4021 }
4022 if (handle->iic_init == NULL) /* check iic_init */
4023 {
4024 handle->debug_print("mpu9250: iic_init is null.\n"); /* iic_init is null */
4025
4026 return 3; /* return error */
4027 }
4028 if (handle->iic_deinit == NULL) /* check iic_deinit */
4029 {
4030 handle->debug_print("mpu9250: iic_deinit is null.\n"); /* iic_deinit is null */
4031
4032 return 3; /* return error */
4033 }
4034 if (handle->iic_read == NULL) /* check iic_read */
4035 {
4036 handle->debug_print("mpu9250: iic_read is null.\n"); /* iic_read is null */
4037
4038 return 3; /* return error */
4039 }
4040 if (handle->iic_write == NULL) /* check iic_write */
4041 {
4042 handle->debug_print("mpu9250: iic_write is null.\n"); /* iic_write is null */
4043
4044 return 3; /* return error */
4045 }
4046 if (handle->spi_init == NULL) /* check spi_init */
4047 {
4048 handle->debug_print("mpu9250: spi_init is null.\n"); /* spi_init is null */
4049
4050 return 3; /* return error */
4051 }
4052 if (handle->spi_deinit == NULL) /* check spi_deinit */
4053 {
4054 handle->debug_print("mpu9250: spi_deinit is null.\n"); /* spi_deinit is null */
4055
4056 return 3; /* return error */
4057 }
4058 if (handle->spi_read == NULL) /* check spi_read */
4059 {
4060 handle->debug_print("mpu9250: spi_read is null.\n"); /* spi_read is null */
4061
4062 return 3; /* return error */
4063 }
4064 if (handle->spi_write == NULL) /* check spi_write */
4065 {
4066 handle->debug_print("mpu9250: spi_write is null.\n"); /* spi_write is null */
4067
4068 return 3; /* return error */
4069 }
4070 if (handle->delay_ms == NULL) /* check delay_ms */
4071 {
4072 handle->debug_print("mpu9250: delay_ms is null.\n"); /* delay_ms is null */
4073
4074 return 3; /* return error */
4075 }
4076 if (handle->receive_callback == NULL) /* check receive_callback */
4077 {
4078 handle->debug_print("mpu9250: receive_callback is null.\n"); /* receive_callback is null */
4079
4080 return 3; /* return error */
4081 }
4082
4083 if (handle->iic_spi == MPU9250_INTERFACE_IIC) /* if iic interface */
4084 {
4085 res = handle->iic_init(); /* iic init */
4086 if (res != 0) /* check the result */
4087 {
4088 handle->debug_print("mpu9250: iic init failed.\n"); /* iic init failed */
4089
4090 return 1; /* return error */
4091 }
4092 }
4093 else /* if spi interface */
4094 {
4095 res = handle->spi_init(); /* spi init */
4096 if (res != 0) /* check the result */
4097 {
4098 handle->debug_print("mpu9250: spi init failed.\n"); /* spi init failed */
4099
4100 return 1; /* return error */
4101 }
4102 }
4103
4104 res = a_mpu9250_read(handle, MPU9250_REG_WHO_AM_I, &prev, 1); /* read who am I */
4105 if (res != 0) /* check the result */
4106 {
4107 handle->debug_print("mpu9250: read who am i failed.\n"); /* read who am I failed */
4108 (void)a_mpu9250_deinit(handle); /* iic or spi deinit */
4109
4110 return 5; /* return error */
4111 }
4112 if (prev != 0x71) /* check the id */
4113 {
4114 handle->debug_print("mpu9250: id is invalid.\n"); /* id is invalid */
4115 (void)a_mpu9250_deinit(handle); /* iic or spi deinit */
4116
4117 return 5; /* return error */
4118 }
4119
4120 prev = 1 << 7; /* reset the device */
4121 res = a_mpu9250_write(handle, MPU9250_REG_PWR_MGMT_1, &prev, 1); /* write pwr mgmt 1 */
4122 if (res != 0) /* check the result */
4123 {
4124 handle->debug_print("mpu9250: write pwr mgmt 1 failed.\n"); /* write pwr mgmt 1 failed */
4125 (void)a_mpu9250_deinit(handle); /* iic or spi deinit */
4126
4127 return 4; /* return error */
4128 }
4129 handle->delay_ms(10); /* delay 10 ms */
4130 timeout = 100; /* set the timeout 1000 ms */
4131 while (timeout != 0) /* check the timeout */
4132 {
4133 res = a_mpu9250_read(handle, MPU9250_REG_PWR_MGMT_1, &prev, 1); /* read pwr mgmt 1 */
4134 if (res != 0) /* check the result */
4135 {
4136 handle->debug_print("mpu9250: read pwr mgmt 1 failed.\n"); /* read pwr mgmt 1 failed */
4137 (void)a_mpu9250_deinit(handle); /* iic or spi deinit */
4138
4139 return 4; /* return error */
4140 }
4141 if ((prev & (1 << 7)) == 0) /* check the result */
4142 {
4143 handle->inited = 1; /* flag the inited bit */
4144 handle->dmp_inited = 0; /* flag closed */
4145
4146 return 0; /* success return 0 */
4147 }
4148 handle->delay_ms(10); /* delay 10 ms */
4149 timeout--; /* timeout-- */
4150 }
4151
4152 handle->debug_print("mpu9250: reset failed.\n"); /* reset failed */
4153
4154 return 4; /* return error */
4155 }
4156
4168 uint8_t mpu9250_deinit(mpu9250_handle_t *handle)
4169 {
4170 uint8_t res;
4171 uint8_t prev;
4172
4173 if (handle == NULL) /* check handle */
4174 {
4175 return 2; /* return error */
4176 }
4177 if (handle->inited != 1) /* check handle initialization */
4178 {
4179 return 3; /* return error */
4180 }
4181
4182 prev = (1 << 6) | (1 << 3) | (7 << 0); /* enter sleep mode */
4183 res = a_mpu9250_write(handle, MPU9250_REG_PWR_MGMT_1, &prev, 1); /* write pwr mgmt 1 */
4184 if (res != 0) /* check the result */
4185 {
4186 handle->debug_print("mpu9250: write pwr mgmt 1 failed.\n"); /* write pwr mgmt 1 failed */
4187
4188 return 4; /* return error */
4189 }
4190 res = a_mpu9250_deinit(handle); /* deinit */
4191 if (res != 0) /* check the result */
4192 {
4193 handle->debug_print("mpu9250: deinit failed.\n"); /* deinit failed */
4194
4195 return 1; /* return error */
4196 }
4197 handle->inited = 0; /* flag closed */
4198 handle->dmp_inited = 0; /* flag closed */
4199
4200 return 0; /* success return 0 */
4201 }
4202
4223 uint8_t mpu9250_read(mpu9250_handle_t *handle,
4224 int16_t (*accel_raw)[3], float (*accel_g)[3],
4225 int16_t (*gyro_raw)[3], float (*gyro_dps)[3],
4226 int16_t (*mag_raw)[3], float (*mag_ut)[3],
4227 uint16_t *len
4228 )
4229 {
4230 uint8_t res;
4231 uint8_t prev;
4232 uint8_t accel_conf;
4233 uint8_t gyro_conf;
4234
4235 if (handle == NULL) /* check handle */
4236 {
4237 return 2; /* return error */
4238 }
4239 if (handle->inited != 1) /* check handle initialization */
4240 {
4241 return 3; /* return error */
4242 }
4243 if ((*len) == 0) /* check length */
4244 {
4245 handle->debug_print("mpu9250: length is zero.\n"); /* length is zero */
4246
4247 return 4; /* return error */
4248 }
4249 if (handle->dmp_inited != 0) /* check dmp initialization */
4250 {
4251 handle->debug_print("mpu9250: dmp is running.\n"); /* dmp is running */
4252
4253 return 5; /* return error */
4254 }
4255
4256 res = a_mpu9250_read(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4257 if (res != 0) /* check result */
4258 {
4259 handle->debug_print("mpu9250: read user ctrl failed.\n"); /* read user ctrl failed */
4260
4261 return 1; /* return error */
4262 }
4263 res = a_mpu9250_read(handle, MPU9250_REG_ACCEL_CONFIG, (uint8_t *)&accel_conf, 1); /* read accel config */
4264 if (res != 0) /* check result */
4265 {
4266 handle->debug_print("mpu9250: read accel config failed.\n"); /* read accel config failed */
4267
4268 return 1; /* return error */
4269 }
4270 res = a_mpu9250_read(handle, MPU9250_REG_GYRO_CONFIG, (uint8_t *)&gyro_conf, 1); /* read gyro config */
4271 if (res != 0) /* check result */
4272 {
4273 handle->debug_print("mpu9250: read gyro config failed.\n"); /* read gyro config failed */
4274
4275 return 1; /* return error */
4276 }
4277 accel_conf = (accel_conf >> 3) & 0x3; /* get the accel conf */
4278 gyro_conf = (gyro_conf >> 3) & 0x3; /* get the gyro conf */
4279 if ((prev & (1 << 6)) != 0) /* if fifo mode */
4280 {
4281 uint8_t conf;
4282 uint8_t buf[2];
4283 uint16_t count;
4284 uint16_t i;
4285
4286 res = a_mpu9250_read(handle, MPU9250_REG_FIFO_EN, (uint8_t *)&conf, 1); /* read fifo enable */
4287 if (res != 0) /* check result */
4288 {
4289 handle->debug_print("mpu9250: read fifo enable failed.\n"); /* read fifo enable failed */
4290
4291 return 1; /* return error */
4292 }
4293 if ((conf != 0x78) && (conf != 0x79)) /* check the conf */
4294 {
4295 handle->debug_print("mpu9250: fifo conf is error.\n"); /* fifo conf is error */
4296
4297 return 6; /* return error */
4298 }
4299
4300 res = a_mpu9250_read(handle, MPU9250_REG_FIFO_COUNTH, (uint8_t *)buf, 2); /* read fifo count */
4301 if (res != 0) /* check result */
4302 {
4303 handle->debug_print("mpu9250: read fifo count failed.\n"); /* read fifo count failed */
4304
4305 return 1; /* return error */
4306 }
4307
4308 if (conf == 0x78) /* only acc and gyro */
4309 {
4310 count = (uint16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set count */
4311 count = (count < 1024) ? count : 1024; /* just the counter */
4312 count = (count < ((*len) * 12)) ? count : ((*len) * 12); /* just outer buffer size */
4313 count = (count / 12) * 12; /* 12 times */
4314 *len = count / 12; /* set the output length */
4315 res = a_mpu9250_read(handle, MPU9250_REG_R_W, handle->buf, count); /* read data */
4316 if (res != 0) /* check result */
4317 {
4318 handle->debug_print("mpu9250: read failed.\n"); /* read failed */
4319
4320 return 1; /* return error */
4321 }
4322 for (i = 0; i < (*len); i++) /* *len times */
4323 {
4324 accel_raw[i][0] = (int16_t)((uint16_t)handle->buf[i * 12 + 0] << 8) |
4325 handle->buf[i * 12 + 1]; /* set raw accel x */
4326 accel_raw[i][1] = (int16_t)((uint16_t)handle->buf[i * 12 + 2] << 8) |
4327 handle->buf[i * 12 + 3]; /* set raw accel y */
4328 accel_raw[i][2] = (int16_t)((uint16_t)handle->buf[i * 12 + 4] << 8) |
4329 handle->buf[i * 12 + 5]; /* set raw accel z */
4330 gyro_raw[i][0] = (int16_t)((uint16_t)handle->buf[i * 12 + 6] << 8) |
4331 handle->buf[i * 12 + 7]; /* set raw gyro x */
4332 gyro_raw[i][1] = (int16_t)((uint16_t)handle->buf[i * 12 + 8] << 8) |
4333 handle->buf[i * 12 + 9]; /* set raw gyro y */
4334 gyro_raw[i][2] = (int16_t)((uint16_t)handle->buf[i * 12 + 10] << 8) |
4335 handle->buf[i * 12 + 11]; /* set raw gyro z */
4336 mag_raw[i][0] = 0; /* set 0 */
4337 mag_raw[i][1] = 0; /* set 0 */
4338 mag_raw[i][2] = 0; /* set 0 */
4339
4340 if (accel_conf == 0) /* ±2g */
4341 {
4342 accel_g[i][0] = (float)(accel_raw[i][0]) / 16384.0f; /* set accel x */
4343 accel_g[i][1] = (float)(accel_raw[i][1]) / 16384.0f; /* set accel y */
4344 accel_g[i][2] = (float)(accel_raw[i][2]) / 16384.0f; /* set accel z */
4345 }
4346 else if (accel_conf == 1) /* ±4g */
4347 {
4348 accel_g[i][0] = (float)(accel_raw[i][0]) / 8192.0f; /* set accel x */
4349 accel_g[i][1] = (float)(accel_raw[i][1]) / 8192.0f; /* set accel y */
4350 accel_g[i][2] = (float)(accel_raw[i][2]) / 8192.0f; /* set accel z */
4351 }
4352 else if (accel_conf == 2) /* ±8g */
4353 {
4354 accel_g[i][0] = (float)(accel_raw[i][0]) / 4096.0f; /* set accel x */
4355 accel_g[i][1] = (float)(accel_raw[i][1]) / 4096.0f; /* set accel y */
4356 accel_g[i][2] = (float)(accel_raw[i][2]) / 4096.0f; /* set accel z */
4357 }
4358 else /* ±16g */
4359 {
4360 accel_g[i][0] = (float)(accel_raw[i][0]) / 2048.0f; /* set accel x */
4361 accel_g[i][1] = (float)(accel_raw[i][1]) / 2048.0f; /* set accel y */
4362 accel_g[i][2] = (float)(accel_raw[i][2]) / 2048.0f; /* set accel z */
4363 }
4364
4365 if (gyro_conf == 0) /* ±250dps */
4366 {
4367 gyro_dps[i][0] = (float)(gyro_raw[i][0]) / 131.0f; /* set gyro x */
4368 gyro_dps[i][1] = (float)(gyro_raw[i][1]) / 131.0f; /* set gyro y */
4369 gyro_dps[i][2] = (float)(gyro_raw[i][2]) / 131.0f; /* set gyro z */
4370 }
4371 else if (gyro_conf == 1) /* ±500dps */
4372 {
4373 gyro_dps[i][0] = (float)(gyro_raw[i][0]) / 65.5f; /* set gyro x */
4374 gyro_dps[i][1] = (float)(gyro_raw[i][1]) / 65.5f; /* set gyro y */
4375 gyro_dps[i][2] = (float)(gyro_raw[i][2]) / 65.5f; /* set gyro z */
4376 }
4377 else if (gyro_conf == 2) /* ±1000dps */
4378 {
4379 gyro_dps[i][0] = (float)(gyro_raw[i][0]) / 32.8f; /* set gyro x */
4380 gyro_dps[i][1] = (float)(gyro_raw[i][1]) / 32.8f; /* set gyro y */
4381 gyro_dps[i][2] = (float)(gyro_raw[i][2]) / 32.8f; /* set gyro z */
4382 }
4383 else /* ±2000dps */
4384 {
4385 gyro_dps[i][0] = (float)(gyro_raw[i][0]) / 16.4f; /* set gyro x */
4386 gyro_dps[i][1] = (float)(gyro_raw[i][1]) / 16.4f; /* set gyro y */
4387 gyro_dps[i][2] = (float)(gyro_raw[i][2]) / 16.4f; /* set gyro z */
4388 }
4389 mag_ut[i][0] = 0.0f; /* set 0.0f */
4390 mag_ut[i][1] = 0.0f; /* set 0.0f */
4391 mag_ut[i][2] = 0.0f; /* set 0.0f */
4392 }
4393
4394 return 0; /* success return 0 */
4395 }
4396 else /* acc, gyro and mag */
4397 {
4398 float mag_k_x;
4399 float mag_k_y;
4400 float mag_k_z;
4401
4402 count = (uint16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set count */
4403 count = (count < 1024) ? count : 1024; /* just the counter */
4404 count = (count < ((*len) * 20)) ? count : ((*len) * 20); /* just outer buffer size */
4405 count = (count / 20) * 20; /* 20 times */
4406 *len = count / 20; /* set the output length */
4407 res = a_mpu9250_read(handle, MPU9250_REG_R_W, handle->buf, count); /* read data */
4408 if (res != 0) /* check result */
4409 {
4410 handle->debug_print("mpu9250: read failed.\n"); /* read failed */
4411
4412 return 1; /* return error */
4413 }
4414
4415 mag_k_x = ((float)handle->mag_asa[0] - 128.0f) * 0.5f / 128.0f + 1.0f; /* get the x sensitivity adjustment */
4416 mag_k_y = ((float)handle->mag_asa[1] - 128.0f) * 0.5f / 128.0f + 1.0f; /* get the y sensitivity adjustment */
4417 mag_k_z = ((float)handle->mag_asa[2] - 128.0f) * 0.5f / 128.0f + 1.0f; /* get the z sensitivity adjustment */
4418
4419 for (i = 0; i < (*len); i++) /* *len times */
4420 {
4421 accel_raw[i][0] = (int16_t)((uint16_t)handle->buf[i * 20 + 0] << 8) |
4422 handle->buf[i * 20 + 1]; /* set raw accel x */
4423 accel_raw[i][1] = (int16_t)((uint16_t)handle->buf[i * 20 + 2] << 8) |
4424 handle->buf[i * 20 + 3]; /* set raw accel y */
4425 accel_raw[i][2] = (int16_t)((uint16_t)handle->buf[i * 20 + 4] << 8) |
4426 handle->buf[i * 20 + 5]; /* set raw accel z */
4427 gyro_raw[i][0] = (int16_t)((uint16_t)handle->buf[i * 20 + 6] << 8) |
4428 handle->buf[i * 20 + 7]; /* set raw gyro x */
4429 gyro_raw[i][1] = (int16_t)((uint16_t)handle->buf[i * 20 + 8] << 8) |
4430 handle->buf[i * 20 + 9]; /* set raw gyro y */
4431 gyro_raw[i][2] = (int16_t)((uint16_t)handle->buf[i * 20 + 10] << 8) |
4432 handle->buf[i * 20 + 11]; /* set raw gyro z */
4433 mag_raw[i][0] = (int16_t)((uint16_t)handle->buf[i * 20 + 14] << 8) |
4434 handle->buf[i * 20 + 13]; /* set raw mag x */
4435 mag_raw[i][1] = (int16_t)((uint16_t)handle->buf[i * 20 + 16] << 8) |
4436 handle->buf[i * 20 + 15]; /* set raw mag y */
4437 mag_raw[i][2] = (int16_t)((uint16_t)handle->buf[i * 20 + 18] << 8) |
4438 handle->buf[i * 20 + 17]; /* set raw mag z */
4439
4440 if (accel_conf == 0) /* ±2g */
4441 {
4442 accel_g[i][0] = (float)(accel_raw[i][0]) / 16384.0f; /* set accel x */
4443 accel_g[i][1] = (float)(accel_raw[i][1]) / 16384.0f; /* set accel y */
4444 accel_g[i][2] = (float)(accel_raw[i][2]) / 16384.0f; /* set accel z */
4445 }
4446 else if (accel_conf == 1) /* ±4g */
4447 {
4448 accel_g[i][0] = (float)(accel_raw[i][0]) / 8192.0f; /* set accel x */
4449 accel_g[i][1] = (float)(accel_raw[i][1]) / 8192.0f; /* set accel y */
4450 accel_g[i][2] = (float)(accel_raw[i][2]) / 8192.0f; /* set accel z */
4451 }
4452 else if (accel_conf == 2) /* ±8g */
4453 {
4454 accel_g[i][0] = (float)(accel_raw[i][0]) / 4096.0f; /* set accel x */
4455 accel_g[i][1] = (float)(accel_raw[i][1]) / 4096.0f; /* set accel y */
4456 accel_g[i][2] = (float)(accel_raw[i][2]) / 4096.0f; /* set accel z */
4457 }
4458 else /* ±16g */
4459 {
4460 accel_g[i][0] = (float)(accel_raw[i][0]) / 2048.0f; /* set accel x */
4461 accel_g[i][1] = (float)(accel_raw[i][1]) / 2048.0f; /* set accel y */
4462 accel_g[i][2] = (float)(accel_raw[i][2]) / 2048.0f; /* set accel z */
4463 }
4464
4465 if (gyro_conf == 0) /* ±250dps */
4466 {
4467 gyro_dps[i][0] = (float)(gyro_raw[i][0]) / 131.0f; /* set gyro x */
4468 gyro_dps[i][1] = (float)(gyro_raw[i][1]) / 131.0f; /* set gyro y */
4469 gyro_dps[i][2] = (float)(gyro_raw[i][2]) / 131.0f; /* set gyro z */
4470 }
4471 else if (gyro_conf == 1) /* ±500dps */
4472 {
4473 gyro_dps[i][0] = (float)(gyro_raw[i][0]) / 65.5f; /* set gyro x */
4474 gyro_dps[i][1] = (float)(gyro_raw[i][1]) / 65.5f; /* set gyro y */
4475 gyro_dps[i][2] = (float)(gyro_raw[i][2]) / 65.5f; /* set gyro z */
4476 }
4477 else if (gyro_conf == 2) /* ±1000dps */
4478 {
4479 gyro_dps[i][0] = (float)(gyro_raw[i][0]) / 32.8f; /* set gyro x */
4480 gyro_dps[i][1] = (float)(gyro_raw[i][1]) / 32.8f; /* set gyro y */
4481 gyro_dps[i][2] = (float)(gyro_raw[i][2]) / 32.8f; /* set gyro z */
4482 }
4483 else /* ±2000dps */
4484 {
4485 gyro_dps[i][0] = (float)(gyro_raw[i][0]) / 16.4f; /* set gyro x */
4486 gyro_dps[i][1] = (float)(gyro_raw[i][1]) / 16.4f; /* set gyro y */
4487 gyro_dps[i][2] = (float)(gyro_raw[i][2]) / 16.4f; /* set gyro z */
4488 }
4489 if ((handle->buf[i * 20 + 19] & (1 << 4)) != 0) /* if 16 bits */
4490 {
4491 mag_ut[i][0] = (float)mag_raw[i][0] * mag_k_x * 0.15f; /* set the mag x */
4492 mag_ut[i][1] = (float)mag_raw[i][1] * mag_k_y * 0.15f; /* set the mag y */
4493 mag_ut[i][2] = (float)mag_raw[i][2] * mag_k_z * 0.15f; /* set the mag z */
4494 }
4495 else /* if 14 bits */
4496 {
4497 mag_ut[i][0] = (float)mag_raw[i][0] * mag_k_x * 0.6f; /* set the mag x */
4498 mag_ut[i][1] = (float)mag_raw[i][1] * mag_k_y * 0.6f; /* set the mag y */
4499 mag_ut[i][2] = (float)mag_raw[i][2] * mag_k_z * 0.6f; /* set the mag z */
4500 }
4501 }
4502
4503 return 0; /* success return 0 */
4504 }
4505 }
4506 else /* if normal mode */
4507 {
4508 *len = 1; /* set 1 */
4509 res = a_mpu9250_read(handle, MPU9250_REG_ACCEL_XOUT_H, handle->buf, 14); /* read data */
4510 if (res != 0) /* check result */
4511 {
4512 handle->debug_print("mpu9250: read failed.\n"); /* read failed */
4513
4514 return 1; /* return error */
4515 }
4516 accel_raw[0][0] = (int16_t)((uint16_t)handle->buf[0] << 8) | handle->buf[1]; /* set raw accel x */
4517 accel_raw[0][1] = (int16_t)((uint16_t)handle->buf[2] << 8) | handle->buf[3]; /* set raw accel y */
4518 accel_raw[0][2] = (int16_t)((uint16_t)handle->buf[4] << 8) | handle->buf[5]; /* set raw accel z */
4519 gyro_raw[0][0] = (int16_t)((uint16_t)handle->buf[8] << 8) | handle->buf[9]; /* set raw gyro x */
4520 gyro_raw[0][1] = (int16_t)((uint16_t)handle->buf[10] << 8) | handle->buf[11]; /* set raw gyro y */
4521 gyro_raw[0][2] = (int16_t)((uint16_t)handle->buf[12] << 8) | handle->buf[13]; /* set raw gyro z */
4522
4523 if (accel_conf == 0) /* ±2g */
4524 {
4525 accel_g[0][0] = (float)(accel_raw[0][0]) / 16384.0f; /* set accel x */
4526 accel_g[0][1] = (float)(accel_raw[0][1]) / 16384.0f; /* set accel y */
4527 accel_g[0][2] = (float)(accel_raw[0][2]) / 16384.0f; /* set accel z */
4528 }
4529 else if (accel_conf == 1) /* ±4g */
4530 {
4531 accel_g[0][0] = (float)(accel_raw[0][0]) / 8192.0f; /* set accel x */
4532 accel_g[0][1] = (float)(accel_raw[0][1]) / 8192.0f; /* set accel y */
4533 accel_g[0][2] = (float)(accel_raw[0][2]) / 8192.0f; /* set accel z */
4534 }
4535 else if (accel_conf == 2) /* ±8g */
4536 {
4537 accel_g[0][0] = (float)(accel_raw[0][0]) / 4096.0f; /* set accel x */
4538 accel_g[0][1] = (float)(accel_raw[0][1]) / 4096.0f; /* set accel y */
4539 accel_g[0][2] = (float)(accel_raw[0][2]) / 4096.0f; /* set accel z */
4540 }
4541 else /* ±16g */
4542 {
4543 accel_g[0][0] = (float)(accel_raw[0][0]) / 2048.0f; /* set accel x */
4544 accel_g[0][1] = (float)(accel_raw[0][1]) / 2048.0f; /* set accel y */
4545 accel_g[0][2] = (float)(accel_raw[0][2]) / 2048.0f; /* set accel z */
4546 }
4547
4548 if (gyro_conf == 0) /* ±250dps */
4549 {
4550 gyro_dps[0][0] = (float)(gyro_raw[0][0]) / 131.0f; /* set gyro x */
4551 gyro_dps[0][1] = (float)(gyro_raw[0][1]) / 131.0f; /* set gyro y */
4552 gyro_dps[0][2] = (float)(gyro_raw[0][2]) / 131.0f; /* set gyro z */
4553 }
4554 else if (gyro_conf == 1) /* ±500dps */
4555 {
4556 gyro_dps[0][0] = (float)(gyro_raw[0][0]) / 65.5f; /* set gyro x */
4557 gyro_dps[0][1] = (float)(gyro_raw[0][1]) / 65.5f; /* set gyro y */
4558 gyro_dps[0][2] = (float)(gyro_raw[0][2]) / 65.5f; /* set gyro z */
4559 }
4560 else if (gyro_conf == 2) /* ±1000dps */
4561 {
4562 gyro_dps[0][0] = (float)(gyro_raw[0][0]) / 32.8f; /* set gyro x */
4563 gyro_dps[0][1] = (float)(gyro_raw[0][1]) / 32.8f; /* set gyro y */
4564 gyro_dps[0][2] = (float)(gyro_raw[0][2]) / 32.8f; /* set gyro z */
4565 }
4566 else /* ±2000dps */
4567 {
4568 gyro_dps[0][0] = (float)(gyro_raw[0][0]) / 16.4f; /* set gyro x */
4569 gyro_dps[0][1] = (float)(gyro_raw[0][1]) / 16.4f; /* set gyro y */
4570 gyro_dps[0][2] = (float)(gyro_raw[0][2]) / 16.4f; /* set gyro z */
4571 }
4572 if (handle->mag_inited == 1) /* if mag is inited */
4573 {
4574 float mag_k_x;
4575 float mag_k_y;
4576 float mag_k_z;
4577
4578 res = a_mpu9250_mag_read(handle, AK8963_REG_ST1, handle->buf, 8); /* read the mag data */
4579 if (res != 0) /* check result */
4580 {
4581 handle->debug_print("mpu9250: mag read failed.\n"); /* mag read failed */
4582
4583 return 1; /* return error */
4584 }
4585 mag_raw[0][0] = (int16_t)((uint16_t)handle->buf[2] << 8) | handle->buf[1]; /* set raw mag x */
4586 mag_raw[0][1] = (int16_t)((uint16_t)handle->buf[4] << 8) | handle->buf[3]; /* set raw mag y */
4587 mag_raw[0][2] = (int16_t)((uint16_t)handle->buf[6] << 8) | handle->buf[5]; /* set raw mag z */
4588
4589 mag_k_x = ((float)handle->mag_asa[0] - 128.0f) * 0.5f / 128.0f + 1.0f; /* get the x sensitivity adjustment */
4590 mag_k_y = ((float)handle->mag_asa[1] - 128.0f) * 0.5f / 128.0f + 1.0f; /* get the y sensitivity adjustment */
4591 mag_k_z = ((float)handle->mag_asa[2] - 128.0f) * 0.5f / 128.0f + 1.0f; /* get the z sensitivity adjustment */
4592 if ((handle->buf[7] & (1 << 4)) != 0) /* if 16 bits */
4593 {
4594 mag_ut[0][0] = (float)mag_raw[0][0] * mag_k_x * 0.15f; /* set the mag x */
4595 mag_ut[0][1] = (float)mag_raw[0][1] * mag_k_y * 0.15f; /* set the mag y */
4596 mag_ut[0][2] = (float)mag_raw[0][2] * mag_k_z * 0.15f; /* set the mag z */
4597 }
4598 else /* if 14 bits */
4599 {
4600 mag_ut[0][0] = (float)mag_raw[0][0] * mag_k_x * 0.6f; /* set the mag x */
4601 mag_ut[0][1] = (float)mag_raw[0][1] * mag_k_y * 0.6f; /* set the mag y */
4602 mag_ut[0][2] = (float)mag_raw[0][2] * mag_k_z * 0.6f; /* set the mag z */
4603 }
4604 }
4605 else
4606 {
4607 mag_raw[0][0] = 0; /* set raw mag x 0 */
4608 mag_raw[0][1] = 0; /* set raw mag y 0 */
4609 mag_raw[0][2] = 0; /* set raw mag z 0 */
4610 mag_ut[0][0] = 0.0f; /* set mag x 0.0f */
4611 mag_ut[0][1] = 0.0f; /* set mag y 0.0f */
4612 mag_ut[0][2] = 0.0f; /* set mag z 0.0f */
4613 }
4614
4615 return 0; /* success return 0 */
4616 }
4617 }
4618
4631 uint8_t mpu9250_read_temperature(mpu9250_handle_t *handle, int16_t (*raw), float *degrees)
4632 {
4633 uint8_t res;
4634 uint8_t buf[2];
4635
4636 if (handle == NULL) /* check handle */
4637 {
4638 return 2; /* return error */
4639 }
4640 if (handle->inited != 1) /* check handle initialization */
4641 {
4642 return 3; /* return error */
4643 }
4644
4645 res = a_mpu9250_read(handle, MPU9250_REG_TEMP_OUT_H, buf, 2); /* read data */
4646 if (res != 0) /* check result */
4647 {
4648 handle->debug_print("mpu9250: read failed.\n"); /* read failed */
4649
4650 return 1; /* return error */
4651 }
4652 *raw = (int16_t)((uint16_t)buf[0] << 8) | buf[1]; /* get the raw */
4653 *degrees = (float)(*raw) / 321.0f + 21.0f; /* convert the degrees */
4654
4655 return 0; /* success return 0 */
4656 }
4657
4668 uint8_t mpu9250_irq_handler(mpu9250_handle_t *handle)
4669 {
4670 uint8_t res;
4671 uint8_t prev;
4672
4673 if (handle == NULL) /* check handle */
4674 {
4675 return 2; /* return error */
4676 }
4677 if (handle->inited != 1) /* check handle initialization */
4678 {
4679 return 3; /* return error */
4680 }
4681
4682 res = a_mpu9250_read(handle, MPU9250_REG_INT_STATUS, (uint8_t *)&prev, 1); /* read config */
4683 if (res != 0) /* check result */
4684 {
4685 handle->debug_print("mpu9250: read int status failed.\n"); /* read int status failed */
4686
4687 return 1; /* return error */
4688 }
4689 if ((prev & (1 << MPU9250_INTERRUPT_MOTION)) != 0) /* if motion */
4690 {
4691 if (handle->receive_callback != NULL) /* if receive callback */
4692 {
4693 handle->receive_callback(MPU9250_INTERRUPT_MOTION); /* run callback */
4694 }
4695 }
4696 if ((prev & (1 << MPU9250_INTERRUPT_FIFO_OVERFLOW)) != 0) /* if fifo overflow */
4697 {
4698 if (handle->receive_callback != NULL) /* if receive callback */
4699 {
4700 handle->receive_callback(MPU9250_INTERRUPT_FIFO_OVERFLOW); /* run callback */
4701 }
4702 (void)a_mpu9250_reset_fifo(handle); /* reset the fifo */
4703 }
4704 if ((prev & (1 << MPU9250_INTERRUPT_FSYNC_INT)) != 0) /* if fsync int */
4705 {
4706 if (handle->receive_callback != NULL) /* if receive callback */
4707 {
4708 handle->receive_callback(MPU9250_INTERRUPT_FSYNC_INT); /* run callback */
4709 }
4710 }
4711 if ((prev & (1 << MPU9250_INTERRUPT_DMP)) != 0) /* if dmp */
4712 {
4713 if (handle->receive_callback != NULL) /* if receive callback */
4714 {
4715 handle->receive_callback(MPU9250_INTERRUPT_DMP); /* run callback */
4716 }
4717 }
4718 if ((prev & (1 << MPU9250_INTERRUPT_DATA_READY)) != 0) /* if data ready */
4719 {
4720 if (handle->receive_callback != NULL) /* if receive callback */
4721 {
4722 handle->receive_callback(MPU9250_INTERRUPT_DATA_READY); /* run callback */
4723 }
4724 }
4725
4726 return 0; /* success return 0 */
4727 }
4728
4742 uint8_t mpu9250_mag_init(mpu9250_handle_t *handle)
4743 {
4744 uint8_t res;
4745 uint8_t prev;
4746 uint32_t timeout;
4747
4748 if (handle == NULL) /* check handle */
4749 {
4750 return 2; /* return error */
4751 }
4752 if (handle->inited != 1) /* check handle initialization */
4753 {
4754 return 3; /* return error */
4755 }
4756
4757 if (handle->iic_spi == MPU9250_INTERFACE_IIC) /* if iic interface */
4758 {
4759 res = a_mpu9250_read(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4760 if (res != 0) /* check result */
4761 {
4762 handle->debug_print("mpu9250: read user ctrl failed.\n"); /* read user ctrl failed */
4763
4764 return 1; /* return error */
4765 }
4766 prev &= ~(1 << 5); /* disable iic master */
4767 res = a_mpu9250_write(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
4768 if (res != 0) /* check result */
4769 {
4770 handle->debug_print("mpu9250: write user ctrl failed.\n"); /* write user ctrl failed */
4771
4772 return 1; /* return error */
4773 }
4774 res = a_mpu9250_read(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read config */
4775 if (res != 0) /* check result */
4776 {
4777 handle->debug_print("mpu9250: read int pin cfg failed.\n"); /* read int pin cfg failed */
4778
4779 return 1; /* return error */
4780 }
4781 prev &= ~(1 << 1); /* clear config */
4782 prev |= 1 << 1; /* enable bypass */
4783 res = a_mpu9250_write(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write config */
4784 if (res != 0) /* check result */
4785 {
4786 handle->debug_print("mpu9250: write int pin cfg failed.\n"); /* write int pin cfg failed */
4787
4788 return 1; /* return error */
4789 }
4790
4791 res = a_mpu9250_mag_read(handle, AK8963_REG_WIA, (uint8_t *)&prev, 1); /* read who am I */
4792 if (res != 0) /* check result */
4793 {
4794 handle->debug_print("mpu9250: mag read who am i failed.\n"); /* mag read who am I failed */
4795
4796 return 1; /* return error */
4797 }
4798 if (prev != 0x48) /* check the id */
4799 {
4800 handle->debug_print("mpu9250: mag id is invalid.\n"); /* mag id is invalid */
4801
4802 return 5; /* return error */
4803 }
4804
4805 prev = 0x01; /* set the reset command */
4806 res = a_mpu9250_mag_write(handle, AK8963_REG_CNTL2, &prev); /* reset the magnetometer */
4807 if (res != 0) /* check result */
4808 {
4809 handle->debug_print("mpu9250: mag write cntl2 failed.\n"); /* mag write cntl2 failed */
4810
4811 return 1; /* return error */
4812 }
4813 timeout = 100; /* set timeout 1000ms */
4814 while (timeout != 0) /* check the timeout */
4815 {
4816 res = a_mpu9250_mag_read(handle, AK8963_REG_CNTL2, (uint8_t *)&prev, 1); /* read cntl2 */
4817 if (res != 0) /* check result */
4818 {
4819 handle->debug_print("mpu9250: mag read cntl2 failed.\n"); /* mag read cntl2 failed */
4820
4821 return 1; /* return error */
4822 }
4823 if ((prev & 0x01) == 0x00) /* check finished */
4824 {
4825 break; /* break */
4826 }
4827 handle->delay_ms(10); /* delay 10ms */
4828 timeout--; /* timeout-- */
4829 }
4830 if (timeout == 0) /* check the timeout */
4831 {
4832 handle->debug_print("mpu9250: reset failed.\n"); /* reset failed */
4833
4834 return 4; /* return error */
4835 }
4836
4837 prev = 0x00; /* power down */
4838 res = a_mpu9250_mag_write(handle, AK8963_REG_CNTL1, &prev); /* set the settings */
4839 if (res != 0) /* check result */
4840 {
4841 handle->debug_print("mpu9250: mag write cntl1 failed.\n"); /* mag write cntl1 failed */
4842
4843 return 1; /* return error */
4844 }
4845 handle->delay_ms(10); /* delay 10ms */
4846 prev = 0x0F; /* fuse rom access mode */
4847 res = a_mpu9250_mag_write(handle, AK8963_REG_CNTL1, &prev); /* set the settings */
4848 if (res != 0) /* check result */
4849 {
4850 handle->debug_print("mpu9250: mag write cntl1 failed.\n"); /* mag write cntl1 failed */
4851
4852 return 1; /* return error */
4853 }
4854 res = a_mpu9250_mag_read(handle, AK8963_REG_ASAX, handle->mag_asa, 3); /* read the asa */
4855 if (res != 0) /* check result */
4856 {
4857 handle->debug_print("mpu9250: mag read asa failed.\n"); /* mag read asa failed */
4858
4859 return 1; /* return error */
4860 }
4861 prev = 0x00; /* power down */
4862 res = a_mpu9250_mag_write(handle, AK8963_REG_CNTL1, &prev); /* set the settings */
4863 if (res != 0) /* check result */
4864 {
4865 handle->debug_print("mpu9250: mag write cntl1 failed.\n"); /* mag write cntl1 failed */
4866
4867 return 1; /* return error */
4868 }
4869 handle->delay_ms(10); /* delay 10ms */
4870
4871 handle->mag_inited = 1; /* flag inited */
4872
4873 return 0; /* success return 0 */
4874 }
4875 else
4876 {
4877 handle->debug_print("mpu9250: spi don't support.\n"); /* spi don't support */
4878
4879 return 6; /* return error */
4880 }
4881 }
4882
4894 uint8_t mpu9250_mag_deinit(mpu9250_handle_t *handle)
4895 {
4896 uint8_t res;
4897 uint8_t prev;
4898
4899 if (handle == NULL) /* check handle */
4900 {
4901 return 2; /* return error */
4902 }
4903 if (handle->inited != 1) /* check handle initialization */
4904 {
4905 return 3; /* return error */
4906 }
4907 if (handle->mag_inited != 1) /* check mag initialization */
4908 {
4909 handle->debug_print("mpu9250: mag is not inited.\n"); /* mag is not inited */
4910
4911 return 4; /* return error */
4912 }
4913
4914 res = a_mpu9250_read(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4915 if (res != 0) /* check result */
4916 {
4917 handle->debug_print("mpu9250: read user ctrl failed.\n"); /* read user ctrl failed */
4918
4919 return 1; /* return error */
4920 }
4921 prev &= ~(1 << 5); /* disable iic master */
4922 res = a_mpu9250_write(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
4923 if (res != 0) /* check result */
4924 {
4925 handle->debug_print("mpu9250: write user ctrl failed.\n"); /* write user ctrl failed */
4926
4927 return 1; /* return error */
4928 }
4929 res = a_mpu9250_read(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read config */
4930 if (res != 0) /* check result */
4931 {
4932 handle->debug_print("mpu9250: read int pin cfg failed.\n"); /* read int pin cfg failed */
4933
4934 return 1; /* return error */
4935 }
4936 prev &= ~(1 << 1); /* clear config */
4937 prev |= 1 << 1; /* enable bypass */
4938 res = a_mpu9250_write(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write config */
4939 if (res != 0) /* check result */
4940 {
4941 handle->debug_print("mpu9250: write int pin cfg failed.\n"); /* write int pin cfg failed */
4942
4943 return 1; /* return error */
4944 }
4945
4946 res = a_mpu9250_mag_read(handle, AK8963_REG_WIA, (uint8_t *)&prev, 1); /* read who am I */
4947 if (res != 0) /* check result */
4948 {
4949 handle->debug_print("mpu9250: mag read who am i failed.\n"); /* mag read who am I failed */
4950
4951 return 1; /* return error */
4952 }
4953 if (prev != 0x48) /* check the id */
4954 {
4955 handle->debug_print("mpu9250: mag id is invalid.\n"); /* mag id is invalid */
4956
4957 return 5; /* return error */
4958 }
4959
4960 res = a_mpu9250_mag_read(handle, AK8963_REG_CNTL1, (uint8_t *)&prev, 1); /* read cntl1 */
4961 if (res != 0) /* check the result */
4962 {
4963 handle->debug_print("mpu9250: mag read cntl1 failed.\n"); /* mag read cntl1 failed */
4964
4965 return 1; /* return error */
4966 }
4967 prev &= ~(0xF << 0); /* clear config */
4968 prev |= 0x00 << 0; /* set the power mode */
4969 res = a_mpu9250_mag_write(handle, AK8963_REG_CNTL1, (uint8_t *)&prev); /* write cntl1 */
4970 if (res != 0) /* check the result */
4971 {
4972 handle->debug_print("mpu9250: mag write cntl1 failed.\n"); /* mag write cntl1 failed */
4973
4974 return 1; /* return error */
4975 }
4976
4977 handle->mag_inited = 0; /* flag closed */
4978
4979 return 0; /* success return 0 */
4980 }
4981
4995 uint8_t mpu9250_mag_read(mpu9250_handle_t *handle, int16_t mag_raw[3], float mag_ut[3])
4996 {
4997 uint8_t res;
4998 uint8_t buf[8];
4999 float mag_k_x;
5000 float mag_k_y;
5001 float mag_k_z;
5002
5003 if (handle == NULL) /* check handle */
5004 {
5005 return 2; /* return error */
5006 }
5007 if (handle->inited != 1) /* check handle initialization */
5008 {
5009 return 3; /* return error */
5010 }
5011 if (handle->mag_inited != 1) /* check mag initialization */
5012 {
5013 handle->debug_print("mpu9250: mag is not inited.\n"); /* mag is not inited */
5014
5015 return 4; /* return error */
5016 }
5017
5018 res = a_mpu9250_mag_read(handle, AK8963_REG_ST1, buf, 8); /* read the mag data */
5019 if (res != 0) /* check result */
5020 {
5021 handle->debug_print("mpu9250: mag read failed.\n"); /* mag read failed */
5022
5023 return 1; /* return error */
5024 }
5025 mag_raw[0] = (int16_t)((uint16_t)buf[2] << 8) | buf[1]; /* set raw mag x */
5026 mag_raw[1] = (int16_t)((uint16_t)buf[4] << 8) | buf[3]; /* set raw mag y */
5027 mag_raw[2] = (int16_t)((uint16_t)buf[6] << 8) | buf[5]; /* set raw mag z */
5028
5029 mag_k_x = ((float)handle->mag_asa[0] - 128.0f) * 0.5f / 128.0f + 1.0f; /* get the x sensitivity adjustment */
5030 mag_k_y = ((float)handle->mag_asa[1] - 128.0f) * 0.5f / 128.0f + 1.0f; /* get the y sensitivity adjustment */
5031 mag_k_z = ((float)handle->mag_asa[2] - 128.0f) * 0.5f / 128.0f + 1.0f; /* get the z sensitivity adjustment */
5032 if ((buf[7] & (1 << 4)) != 0) /* if 16 bits */
5033 {
5034 mag_ut[0] = (float)mag_raw[0] * mag_k_x * 0.15f; /* set the mag x */
5035 mag_ut[1] = (float)mag_raw[1] * mag_k_y * 0.15f; /* set the mag y */
5036 mag_ut[2] = (float)mag_raw[2] * mag_k_z * 0.15f; /* set the mag z */
5037 }
5038 else /* if 14 bits */
5039 {
5040 mag_ut[0] = (float)mag_raw[0] * mag_k_x * 0.6f; /* set the mag x */
5041 mag_ut[1] = (float)mag_raw[1] * mag_k_y * 0.6f; /* set the mag y */
5042 mag_ut[2] = (float)mag_raw[2] * mag_k_z * 0.6f; /* set the mag z */
5043 }
5044
5045 return 0; /* success return 0 */
5046 }
5047
5060 uint8_t mpu9250_mag_get_info(mpu9250_handle_t *handle, uint8_t *info)
5061 {
5062 uint8_t res;
5063
5064 if (handle == NULL) /* check handle */
5065 {
5066 return 2; /* return error */
5067 }
5068 if (handle->inited != 1) /* check handle initialization */
5069 {
5070 return 3; /* return error */
5071 }
5072 if (handle->mag_inited != 1) /* check mag initialization */
5073 {
5074 handle->debug_print("mpu9250: mag is not inited.\n"); /* mag is not inited */
5075
5076 return 4; /* return error */
5077 }
5078
5079 res = a_mpu9250_mag_read(handle, AK8963_REG_INFO, (uint8_t *)info, 1); /* read info */
5080 if (res != 0) /* check the result */
5081 {
5082 handle->debug_print("mpu9250: mag read info failed.\n"); /* mag read info failed */
5083
5084 return 1; /* return error */
5085 }
5086
5087 return 0; /* success return 0 */
5088 }
5089
5102 uint8_t mpu9250_mag_get_status1(mpu9250_handle_t *handle, uint8_t *status)
5103 {
5104 uint8_t res;
5105
5106 if (handle == NULL) /* check handle */
5107 {
5108 return 2; /* return error */
5109 }
5110 if (handle->inited != 1) /* check handle initialization */
5111 {
5112 return 3; /* return error */
5113 }
5114 if (handle->mag_inited != 1) /* check mag initialization */
5115 {
5116 handle->debug_print("mpu9250: mag is not inited.\n"); /* mag is not inited */
5117
5118 return 4; /* return error */
5119 }
5120
5121 res = a_mpu9250_mag_read(handle, AK8963_REG_ST1, (uint8_t *)status, 1); /* read status1 */
5122 if (res != 0) /* check the result */
5123 {
5124 handle->debug_print("mpu9250: mag read status1 failed.\n"); /* mag read status1 failed */
5125
5126 return 1; /* return error */
5127 }
5128
5129 return 0; /* success return 0 */
5130 }
5131
5144 uint8_t mpu9250_mag_get_status2(mpu9250_handle_t *handle, uint8_t *status)
5145 {
5146 uint8_t res;
5147
5148 if (handle == NULL) /* check handle */
5149 {
5150 return 2; /* return error */
5151 }
5152 if (handle->inited != 1) /* check handle initialization */
5153 {
5154 return 3; /* return error */
5155 }
5156 if (handle->mag_inited != 1) /* check mag initialization */
5157 {
5158 handle->debug_print("mpu9250: mag is not inited.\n"); /* mag is not inited */
5159
5160 return 4; /* return error */
5161 }
5162
5163 res = a_mpu9250_mag_read(handle, AK8963_REG_ST2, (uint8_t *)status, 1); /* read status2 */
5164 if (res != 0) /* check the result */
5165 {
5166 handle->debug_print("mpu9250: mag read status2 failed.\n"); /* mag read status2 failed */
5167
5168 return 1; /* return error */
5169 }
5170
5171 return 0; /* success return 0 */
5172 }
5173
5186 uint8_t mpu9250_mag_set_mode(mpu9250_handle_t *handle, mpu9250_magnetometer_mode_t mode)
5187 {
5188 uint8_t res;
5189 uint8_t prev;
5190
5191 if (handle == NULL) /* check handle */
5192 {
5193 return 2; /* return error */
5194 }
5195 if (handle->inited != 1) /* check handle initialization */
5196 {
5197 return 3; /* return error */
5198 }
5199 if (handle->mag_inited != 1) /* check mag initialization */
5200 {
5201 handle->debug_print("mpu9250: mag is not inited.\n"); /* mag is not inited */
5202
5203 return 4; /* return error */
5204 }
5205
5206 res = a_mpu9250_mag_read(handle, AK8963_REG_CNTL1, (uint8_t *)&prev, 1); /* read cntl1 */
5207 if (res != 0) /* check the result */
5208 {
5209 handle->debug_print("mpu9250: mag read cntl1 failed.\n"); /* mag read cntl1 failed */
5210
5211 return 1; /* return error */
5212 }
5213 prev &= ~(0xF << 0); /* clear config */
5214 prev |= mode << 0; /* set the mode */
5215 res = a_mpu9250_mag_write(handle, AK8963_REG_CNTL1, (uint8_t *)&prev); /* write cntl1 */
5216 if (res != 0) /* check the result */
5217 {
5218 handle->debug_print("mpu9250: mag write cntl1 failed.\n"); /* mag write cntl1 failed */
5219
5220 return 1; /* return error */
5221 }
5222
5223 return 0; /* success return 0 */
5224 }
5225
5238 uint8_t mpu9250_mag_get_mode(mpu9250_handle_t *handle, mpu9250_magnetometer_mode_t *mode)
5239 {
5240 uint8_t res;
5241 uint8_t prev;
5242
5243 if (handle == NULL) /* check handle */
5244 {
5245 return 2; /* return error */
5246 }
5247 if (handle->inited != 1) /* check handle initialization */
5248 {
5249 return 3; /* return error */
5250 }
5251 if (handle->mag_inited != 1) /* check mag initialization */
5252 {
5253 handle->debug_print("mpu9250: mag is not inited.\n"); /* mag is not inited */
5254
5255 return 4; /* return error */
5256 }
5257
5258 res = a_mpu9250_mag_read(handle, AK8963_REG_CNTL1, (uint8_t *)&prev, 1); /* read cntl1 */
5259 if (res != 0) /* check the result */
5260 {
5261 handle->debug_print("mpu9250: mag read cntl1 failed.\n"); /* mag read cntl1 failed */
5262
5263 return 1; /* return error */
5264 }
5265 *mode = (mpu9250_magnetometer_mode_t)(prev & 0xF); /* get the mode */
5266
5267 return 0; /* success return 0 */
5268 }
5269
5282 uint8_t mpu9250_mag_set_bits(mpu9250_handle_t *handle, mpu9250_magnetometer_bits_t bits)
5283 {
5284 uint8_t res;
5285 uint8_t prev;
5286
5287 if (handle == NULL) /* check handle */
5288 {
5289 return 2; /* return error */
5290 }
5291 if (handle->inited != 1) /* check handle initialization */
5292 {
5293 return 3; /* return error */
5294 }
5295 if (handle->mag_inited != 1) /* check mag initialization */
5296 {
5297 handle->debug_print("mpu9250: mag is not inited.\n"); /* mag is not inited */
5298
5299 return 4; /* return error */
5300 }
5301
5302 res = a_mpu9250_mag_read(handle, AK8963_REG_CNTL1, (uint8_t *)&prev, 1); /* read cntl1 */
5303 if (res != 0) /* check the result */
5304 {
5305 handle->debug_print("mpu9250: mag read cntl1 failed.\n"); /* mag read cntl1 failed */
5306
5307 return 1; /* return error */
5308 }
5309 prev &= ~(1 << 4); /* clear config */
5310 prev |= bits << 4; /* set the mode */
5311 res = a_mpu9250_mag_write(handle, AK8963_REG_CNTL1, (uint8_t *)&prev); /* write cntl1 */
5312 if (res != 0) /* check the result */
5313 {
5314 handle->debug_print("mpu9250: mag write cntl1 failed.\n"); /* mag write cntl1 failed */
5315
5316 return 1; /* return error */
5317 }
5318
5319 return 0; /* success return 0 */
5320 }
5321
5334 uint8_t mpu9250_mag_get_bits(mpu9250_handle_t *handle, mpu9250_magnetometer_bits_t *bits)
5335 {
5336 uint8_t res;
5337 uint8_t prev;
5338
5339 if (handle == NULL) /* check handle */
5340 {
5341 return 2; /* return error */
5342 }
5343 if (handle->inited != 1) /* check handle initialization */
5344 {
5345 return 3; /* return error */
5346 }
5347 if (handle->mag_inited != 1) /* check mag initialization */
5348 {
5349 handle->debug_print("mpu9250: mag is not inited.\n"); /* mag is not inited */
5350
5351 return 4; /* return error */
5352 }
5353
5354 res = a_mpu9250_mag_read(handle, AK8963_REG_CNTL1, (uint8_t *)&prev, 1); /* read cntl1 */
5355 if (res != 0) /* check the result */
5356 {
5357 handle->debug_print("mpu9250: mag read cntl1 failed.\n"); /* mag read cntl1 failed */
5358
5359 return 1; /* return error */
5360 }
5361 *bits = (mpu9250_magnetometer_bits_t)((prev >> 4) & 0x1); /* get the bits */
5362
5363 return 0; /* success return 0 */
5364 }
5365
5378 uint8_t mpu9250_mag_set_reset(mpu9250_handle_t *handle, mpu9250_bool_t enable)
5379 {
5380 uint8_t res;
5381 uint8_t prev;
5382
5383 if (handle == NULL) /* check handle */
5384 {
5385 return 2; /* return error */
5386 }
5387 if (handle->inited != 1) /* check handle initialization */
5388 {
5389 return 3; /* return error */
5390 }
5391 if (handle->mag_inited != 1) /* check mag initialization */
5392 {
5393 handle->debug_print("mpu9250: mag is not inited.\n"); /* mag is not inited */
5394
5395 return 4; /* return error */
5396 }
5397
5398 res = a_mpu9250_mag_read(handle, AK8963_REG_CNTL2, (uint8_t *)&prev, 1); /* read cntl2 */
5399 if (res != 0) /* check the result */
5400 {
5401 handle->debug_print("mpu9250: mag read cntl2 failed.\n"); /* mag read cntl2 failed */
5402
5403 return 1; /* return error */
5404 }
5405 prev &= ~(1 << 0); /* clear config */
5406 prev |= enable << 0; /* set the bool */
5407 res = a_mpu9250_mag_write(handle, AK8963_REG_CNTL2, (uint8_t *)&prev); /* write cntl2 */
5408 if (res != 0) /* check the result */
5409 {
5410 handle->debug_print("mpu9250: mag write cntl2 failed.\n"); /* mag write cntl2 failed */
5411
5412 return 1; /* return error */
5413 }
5414
5415 return 0; /* success return 0 */
5416 }
5417
5430 uint8_t mpu9250_mag_get_reset(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
5431 {
5432 uint8_t res;
5433 uint8_t prev;
5434
5435 if (handle == NULL) /* check handle */
5436 {
5437 return 2; /* return error */
5438 }
5439 if (handle->inited != 1) /* check handle initialization */
5440 {
5441 return 3; /* return error */
5442 }
5443 if (handle->mag_inited != 1) /* check mag initialization */
5444 {
5445 handle->debug_print("mpu9250: mag is not inited.\n"); /* mag is not inited */
5446
5447 return 4; /* return error */
5448 }
5449
5450 res = a_mpu9250_mag_read(handle, AK8963_REG_CNTL2, (uint8_t *)&prev, 1); /* read cntl2 */
5451 if (res != 0) /* check the result */
5452 {
5453 handle->debug_print("mpu9250: mag read cntl2 failed.\n"); /* mag read cntl2 failed */
5454
5455 return 1; /* return error */
5456 }
5457 *enable = (mpu9250_bool_t)(prev & 0x1); /* get the bool */
5458
5459 return 0; /* success return 0 */
5460 }
5461
5474 uint8_t mpu9250_mag_set_self_test(mpu9250_handle_t *handle, mpu9250_bool_t enable)
5475 {
5476 uint8_t res;
5477 uint8_t prev;
5478
5479 if (handle == NULL) /* check handle */
5480 {
5481 return 2; /* return error */
5482 }
5483 if (handle->inited != 1) /* check handle initialization */
5484 {
5485 return 3; /* return error */
5486 }
5487 if (handle->mag_inited != 1) /* check mag initialization */
5488 {
5489 handle->debug_print("mpu9250: mag is not inited.\n"); /* mag is not inited */
5490
5491 return 4; /* return error */
5492 }
5493
5494 res = a_mpu9250_mag_read(handle, AK8963_REG_ASTC, (uint8_t *)&prev, 1); /* read astc */
5495 if (res != 0) /* check the result */
5496 {
5497 handle->debug_print("mpu9250: mag read astc failed.\n"); /* mag read astc failed */
5498
5499 return 1; /* return error */
5500 }
5501 prev &= ~(1 << 6); /* clear config */
5502 prev |= enable << 6; /* set the bool */
5503 res = a_mpu9250_mag_write(handle, AK8963_REG_ASTC, (uint8_t *)&prev); /* write astc */
5504 if (res != 0) /* check the result */
5505 {
5506 handle->debug_print("mpu9250: mag write astc failed.\n"); /* mag write astc failed */
5507
5508 return 1; /* return error */
5509 }
5510
5511 return 0; /* success return 0 */
5512 }
5513
5526 uint8_t mpu9250_mag_get_self_test(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
5527 {
5528 uint8_t res;
5529 uint8_t prev;
5530
5531 if (handle == NULL) /* check handle */
5532 {
5533 return 2; /* return error */
5534 }
5535 if (handle->inited != 1) /* check handle initialization */
5536 {
5537 return 3; /* return error */
5538 }
5539 if (handle->mag_inited != 1) /* check mag initialization */
5540 {
5541 handle->debug_print("mpu9250: mag is not inited.\n"); /* mag is not inited */
5542
5543 return 4; /* return error */
5544 }
5545
5546 res = a_mpu9250_mag_read(handle, AK8963_REG_ASTC, (uint8_t *)&prev, 1); /* read astc */
5547 if (res != 0) /* check the result */
5548 {
5549 handle->debug_print("mpu9250: mag read astc failed.\n"); /* mag read astc failed */
5550
5551 return 1; /* return error */
5552 }
5553 *enable = (mpu9250_bool_t)((prev >> 6) & 0x1); /* get the bool */
5554
5555 return 0; /* success return 0 */
5556 }
5557
5569 uint8_t mpu9250_mag_iic_disable(mpu9250_handle_t *handle)
5570 {
5571 uint8_t res;
5572 uint8_t prev;
5573
5574 if (handle == NULL) /* check handle */
5575 {
5576 return 2; /* return error */
5577 }
5578 if (handle->inited != 1) /* check handle initialization */
5579 {
5580 return 3; /* return error */
5581 }
5582 if (handle->mag_inited != 1) /* check mag initialization */
5583 {
5584 handle->debug_print("mpu9250: mag is not inited.\n"); /* mag is not inited */
5585
5586 return 4; /* return error */
5587 }
5588
5589 prev = 0x1B; /* set the command */
5590 res = a_mpu9250_mag_write(handle, AK8963_REG_I2CDIS, (uint8_t *)&prev); /* write i2c-dis */
5591 if (res != 0) /* check the result */
5592 {
5593 handle->debug_print("mpu9250: mag write i2cdis failed.\n"); /* mag write i2c-dis failed */
5594
5595 return 1; /* return error */
5596 }
5597
5598 return 0; /* success return 0 */
5599 }
5600
5613 uint8_t mpu9250_mag_get_asa(mpu9250_handle_t *handle, uint8_t asa[3])
5614 {
5615 uint8_t res;
5616
5617 if (handle == NULL) /* check handle */
5618 {
5619 return 2; /* return error */
5620 }
5621 if (handle->inited != 1) /* check handle initialization */
5622 {
5623 return 3; /* return error */
5624 }
5625 if (handle->mag_inited != 1) /* check mag initialization */
5626 {
5627 handle->debug_print("mpu9250: mag is not inited.\n"); /* mag is not inited */
5628
5629 return 4; /* return error */
5630 }
5631
5632 res = a_mpu9250_mag_read(handle, AK8963_REG_ASAX, (uint8_t *)asa, 3); /* read asa */
5633 if (res != 0) /* check the result */
5634 {
5635 handle->debug_print("mpu9250: mag read asa failed.\n"); /* mag read asa failed */
5636
5637 return 1; /* return error */
5638 }
5639
5640 return 0; /* success return 0 */
5641 }
5642
5654 uint8_t mpu9250_mag_set_fifo_mode(mpu9250_handle_t *handle)
5655 {
5656 uint8_t res;
5657 uint8_t prev;
5658
5659 if (handle == NULL) /* check handle */
5660 {
5661 return 2; /* return error */
5662 }
5663 if (handle->inited != 1) /* check handle initialization */
5664 {
5665 return 3; /* return error */
5666 }
5667 if (handle->mag_inited != 1) /* check mag initialization */
5668 {
5669 handle->debug_print("mpu9250: mag is not inited.\n"); /* mag is not inited */
5670
5671 return 4; /* return error */
5672 }
5673
5674 res = a_mpu9250_read(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
5675 if (res != 0) /* check result */
5676 {
5677 handle->debug_print("mpu9250: read user ctrl failed.\n"); /* read user ctrl failed */
5678
5679 return 1; /* return error */
5680 }
5681 prev &= ~(1 << 5); /* disable iic master */
5682 prev |= (1 << 5); /* enable iic master */
5683 res = a_mpu9250_write(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
5684 if (res != 0) /* check result */
5685 {
5686 handle->debug_print("mpu9250: write user ctrl failed.\n"); /* write user ctrl failed */
5687
5688 return 1; /* return error */
5689 }
5690 res = a_mpu9250_read(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read config */
5691 if (res != 0) /* check result */
5692 {
5693 handle->debug_print("mpu9250: read int pin cfg failed.\n"); /* read int pin cfg failed */
5694
5695 return 1; /* return error */
5696 }
5697 prev &= ~(1 << 1); /* disable bypass */
5698 res = a_mpu9250_write(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write config */
5699 if (res != 0) /* check result */
5700 {
5701 handle->debug_print("mpu9250: write int pin cfg failed.\n"); /* write int pin cfg failed */
5702
5703 return 1; /* return error */
5704 }
5705
5706 prev = 0x80 | AK8963_IIC_ADDRESS; /* set the read mode and iic address */
5707 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* write config */
5708 if (res != 0) /* check result */
5709 {
5710 handle->debug_print("mpu9250: write iic slv0 addr failed.\n"); /* write iic slv0 addr failed */
5711
5712 return 1; /* return error */
5713 }
5714 prev = AK8963_REG_ST1; /* set the start register address */
5715 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV0_REG, (uint8_t *)&prev, 1); /* write config */
5716 if (res != 0) /* check result */
5717 {
5718 handle->debug_print("mpu9250: write iic slv0 reg failed.\n"); /* write iic slv0 reg failed */
5719
5720 return 1; /* return error */
5721 }
5722
5723 res = a_mpu9250_read(handle, MPU9250_REG_FIFO_EN, (uint8_t *)&prev, 1); /* read fifo enable */
5724 if (res != 0) /* check result */
5725 {
5726 handle->debug_print("mpu9250: read fifo enable failed.\n"); /* read fifo enable failed */
5727
5728 return 1; /* return error */
5729 }
5730 prev &= ~(1 << 0); /* clear the settings */
5731 prev |= 1 << 0; /* enable slv0 fifo */
5732 res = a_mpu9250_write(handle, MPU9250_REG_FIFO_EN, (uint8_t *)&prev, 1); /* write fifo enable ctrl */
5733 if (res != 0) /* check result */
5734 {
5735 handle->debug_print("mpu9250: write fifo enable failed.\n"); /* write fifo enable failed */
5736
5737 return 1; /* return error */
5738 }
5739
5740 prev = 0x88; /* start and read 8 bytes */
5741 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* write config */
5742 if (res != 0) /* check result */
5743 {
5744 handle->debug_print("mpu9250: write iic slv0 ctrl failed.\n"); /* write iic slv0 ctrl failed */
5745
5746 return 1; /* return error */
5747 }
5748
5749 return 0; /* success return 0 */
5750 }
5751
5763 uint8_t mpu9250_set_fifo(mpu9250_handle_t *handle, mpu9250_bool_t enable)
5764 {
5765 uint8_t res;
5766 uint8_t prev;
5767
5768 if (handle == NULL) /* check handle */
5769 {
5770 return 2; /* return error */
5771 }
5772 if (handle->inited != 1) /* check handle initialization */
5773 {
5774 return 3; /* return error */
5775 }
5776
5777 res = a_mpu9250_read(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
5778 if (res != 0) /* check result */
5779 {
5780 handle->debug_print("mpu9250: read user ctrl failed.\n"); /* read user ctrl failed */
5781
5782 return 1; /* return error */
5783 }
5784 prev &= ~(1 << 6); /* clear config */
5785 prev |= enable << 6; /* set config */
5786 res = a_mpu9250_write(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
5787 if (res != 0) /* check result */
5788 {
5789 handle->debug_print("mpu9250: write user ctrl failed.\n"); /* write user ctrl failed */
5790
5791 return 1; /* return error */
5792 }
5793
5794 return 0; /* success return 0 */
5795 }
5796
5808 uint8_t mpu9250_get_fifo(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
5809 {
5810 uint8_t res;
5811 uint8_t prev;
5812
5813 if (handle == NULL) /* check handle */
5814 {
5815 return 2; /* return error */
5816 }
5817 if (handle->inited != 1) /* check handle initialization */
5818 {
5819 return 3; /* return error */
5820 }
5821
5822 res = a_mpu9250_read(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
5823 if (res != 0) /* check result */
5824 {
5825 handle->debug_print("mpu9250: read user ctrl failed.\n"); /* read user ctrl failed */
5826
5827 return 1; /* return error */
5828 }
5829 *enable = (mpu9250_bool_t)((prev >> 6) & 0x01); /* get bool */
5830
5831 return 0; /* success return 0 */
5832 }
5833
5844 uint8_t mpu9250_force_fifo_reset(mpu9250_handle_t *handle)
5845 {
5846 uint8_t res;
5847
5848 if (handle == NULL) /* check handle */
5849 {
5850 return 2; /* return error */
5851 }
5852 if (handle->inited != 1) /* check handle initialization */
5853 {
5854 return 3; /* return error */
5855 }
5856
5857 res = a_mpu9250_reset_fifo(handle); /* reset the fifo */
5858 if (res != 0) /* check result */
5859 {
5860 handle->debug_print("mpu9250: force reset fifo failed.\n"); /* force reset fifo failed */
5861
5862 return 1; /* return error */
5863 }
5864
5865 return 0; /* success return 0 */
5866 }
5867
5879 uint8_t mpu9250_set_iic_master(mpu9250_handle_t *handle, mpu9250_bool_t enable)
5880 {
5881 uint8_t res;
5882 uint8_t prev;
5883
5884 if (handle == NULL) /* check handle */
5885 {
5886 return 2; /* return error */
5887 }
5888 if (handle->inited != 1) /* check handle initialization */
5889 {
5890 return 3; /* return error */
5891 }
5892
5893 res = a_mpu9250_read(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
5894 if (res != 0) /* check result */
5895 {
5896 handle->debug_print("mpu9250: read user ctrl failed.\n"); /* read user ctrl failed */
5897
5898 return 1; /* return error */
5899 }
5900 prev &= ~(1 << 5); /* clear config */
5901 prev |= enable << 5; /* set config */
5902 res = a_mpu9250_write(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
5903 if (res != 0) /* check result */
5904 {
5905 handle->debug_print("mpu9250: write user ctrl failed.\n"); /* write user ctrl failed */
5906
5907 return 1; /* return error */
5908 }
5909
5910 return 0; /* success return 0 */
5911 }
5912
5924 uint8_t mpu9250_get_iic_master(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
5925 {
5926 uint8_t res;
5927 uint8_t prev;
5928
5929 if (handle == NULL) /* check handle */
5930 {
5931 return 2; /* return error */
5932 }
5933 if (handle->inited != 1) /* check handle initialization */
5934 {
5935 return 3; /* return error */
5936 }
5937
5938 res = a_mpu9250_read(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
5939 if (res != 0) /* check result */
5940 {
5941 handle->debug_print("mpu9250: read user ctrl failed.\n"); /* read user ctrl failed */
5942
5943 return 1; /* return error */
5944 }
5945 *enable = (mpu9250_bool_t)((prev >> 5) & 0x01); /* get bool */
5946
5947 return 0; /* success return 0 */
5948 }
5949
5961 uint8_t mpu9250_set_disable_iic_slave(mpu9250_handle_t *handle, mpu9250_bool_t enable)
5962 {
5963 uint8_t res;
5964 uint8_t prev;
5965
5966 if (handle == NULL) /* check handle */
5967 {
5968 return 2; /* return error */
5969 }
5970 if (handle->inited != 1) /* check handle initialization */
5971 {
5972 return 3; /* return error */
5973 }
5974
5975 res = a_mpu9250_read(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
5976 if (res != 0) /* check result */
5977 {
5978 handle->debug_print("mpu9250: read user ctrl failed.\n"); /* read user ctrl failed */
5979
5980 return 1; /* return error */
5981 }
5982 prev &= ~(1 << 4); /* clear config */
5983 prev |= enable << 4; /* set config */
5984 res = a_mpu9250_write(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
5985 if (res != 0) /* check result */
5986 {
5987 handle->debug_print("mpu9250: write user ctrl failed.\n"); /* write user ctrl failed */
5988
5989 return 1; /* return error */
5990 }
5991
5992 return 0; /* success return 0 */
5993 }
5994
6006 uint8_t mpu9250_get_disable_iic_slave(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
6007 {
6008 uint8_t res;
6009 uint8_t prev;
6010
6011 if (handle == NULL) /* check handle */
6012 {
6013 return 2; /* return error */
6014 }
6015 if (handle->inited != 1) /* check handle initialization */
6016 {
6017 return 3; /* return error */
6018 }
6019
6020 res = a_mpu9250_read(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
6021 if (res != 0) /* check result */
6022 {
6023 handle->debug_print("mpu9250: read user ctrl failed.\n"); /* read user ctrl failed */
6024
6025 return 1; /* return error */
6026 }
6027 *enable = (mpu9250_bool_t)((prev >> 4) & 0x01); /* get bool */
6028
6029 return 0; /* success return 0 */
6030 }
6031
6042 uint8_t mpu9250_fifo_reset(mpu9250_handle_t *handle)
6043 {
6044 uint8_t res;
6045 uint8_t prev;
6046
6047 if (handle == NULL) /* check handle */
6048 {
6049 return 2; /* return error */
6050 }
6051 if (handle->inited != 1) /* check handle initialization */
6052 {
6053 return 3; /* return error */
6054 }
6055
6056 res = a_mpu9250_read(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
6057 if (res != 0) /* check result */
6058 {
6059 handle->debug_print("mpu9250: read user ctrl failed.\n"); /* read user ctrl failed */
6060
6061 return 1; /* return error */
6062 }
6063 prev &= ~(1 << 2); /* clear config */
6064 prev |= 1 << 2; /* set config */
6065 res = a_mpu9250_write(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
6066 if (res != 0) /* check result */
6067 {
6068 handle->debug_print("mpu9250: write user ctrl failed.\n"); /* write user ctrl failed */
6069
6070 return 1; /* return error */
6071 }
6072
6073 return 0; /* success return 0 */
6074 }
6075
6087 uint8_t mpu9250_get_fifo_reset(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
6088 {
6089 uint8_t res;
6090 uint8_t prev;
6091
6092 if (handle == NULL) /* check handle */
6093 {
6094 return 2; /* return error */
6095 }
6096 if (handle->inited != 1) /* check handle initialization */
6097 {
6098 return 3; /* return error */
6099 }
6100
6101 res = a_mpu9250_read(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
6102 if (res != 0) /* check result */
6103 {
6104 handle->debug_print("mpu9250: read user ctrl failed.\n"); /* read user ctrl failed */
6105
6106 return 1; /* return error */
6107 }
6108 *enable = (mpu9250_bool_t)((prev >> 2) & 0x01); /* get bool */
6109
6110 return 0; /* success return 0 */
6111 }
6112
6123 uint8_t mpu9250_iic_master_reset(mpu9250_handle_t *handle)
6124 {
6125 uint8_t res;
6126 uint8_t prev;
6127
6128 if (handle == NULL) /* check handle */
6129 {
6130 return 2; /* return error */
6131 }
6132 if (handle->inited != 1) /* check handle initialization */
6133 {
6134 return 3; /* return error */
6135 }
6136
6137 res = a_mpu9250_read(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
6138 if (res != 0) /* check result */
6139 {
6140 handle->debug_print("mpu9250: read user ctrl failed.\n"); /* read user ctrl failed */
6141
6142 return 1; /* return error */
6143 }
6144 prev &= ~(1 << 1); /* clear config */
6145 prev |= 1 << 1; /* set config */
6146 res = a_mpu9250_write(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
6147 if (res != 0) /* check result */
6148 {
6149 handle->debug_print("mpu9250: write user ctrl failed.\n"); /* write user ctrl failed */
6150
6151 return 1; /* return error */
6152 }
6153
6154 return 0; /* success return 0 */
6155 }
6156
6168 uint8_t mpu9250_get_iic_master_reset(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
6169 {
6170 uint8_t res;
6171 uint8_t prev;
6172
6173 if (handle == NULL) /* check handle */
6174 {
6175 return 2; /* return error */
6176 }
6177 if (handle->inited != 1) /* check handle initialization */
6178 {
6179 return 3; /* return error */
6180 }
6181
6182 res = a_mpu9250_read(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
6183 if (res != 0) /* check result */
6184 {
6185 handle->debug_print("mpu9250: read user ctrl failed.\n"); /* read user ctrl failed */
6186
6187 return 1; /* return error */
6188 }
6189 *enable = (mpu9250_bool_t)((prev >> 1) & 0x01); /* get bool */
6190
6191 return 0; /* success return 0 */
6192 }
6193
6204 uint8_t mpu9250_sensor_reset(mpu9250_handle_t *handle)
6205 {
6206 uint8_t res;
6207 uint8_t prev;
6208
6209 if (handle == NULL) /* check handle */
6210 {
6211 return 2; /* return error */
6212 }
6213 if (handle->inited != 1) /* check handle initialization */
6214 {
6215 return 3; /* return error */
6216 }
6217
6218 res = a_mpu9250_read(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
6219 if (res != 0) /* check result */
6220 {
6221 handle->debug_print("mpu9250: read user ctrl failed.\n"); /* read user ctrl failed */
6222
6223 return 1; /* return error */
6224 }
6225 prev &= ~(1 << 0); /* clear config */
6226 prev |= 1 << 0; /* set config */
6227 res = a_mpu9250_write(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
6228 if (res != 0) /* check result */
6229 {
6230 handle->debug_print("mpu9250: write user ctrl failed.\n"); /* write user ctrl failed */
6231
6232 return 1; /* return error */
6233 }
6234
6235 return 0; /* success return 0 */
6236 }
6237
6249 uint8_t mpu9250_get_sensor_reset(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
6250 {
6251 uint8_t res;
6252 uint8_t prev;
6253
6254 if (handle == NULL) /* check handle */
6255 {
6256 return 2; /* return error */
6257 }
6258 if (handle->inited != 1) /* check handle initialization */
6259 {
6260 return 3; /* return error */
6261 }
6262
6263 res = a_mpu9250_read(handle, MPU9250_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
6264 if (res != 0) /* check result */
6265 {
6266 handle->debug_print("mpu9250: read user ctrl failed.\n"); /* read user ctrl failed */
6267
6268 return 1; /* return error */
6269 }
6270 *enable = (mpu9250_bool_t)((prev >> 0) & 0x01); /* get bool */
6271
6272 return 0; /* success return 0 */
6273 }
6274
6285 uint8_t mpu9250_device_reset(mpu9250_handle_t *handle)
6286 {
6287 uint8_t res;
6288 uint8_t prev;
6289
6290 if (handle == NULL) /* check handle */
6291 {
6292 return 2; /* return error */
6293 }
6294 if (handle->inited != 1) /* check handle initialization */
6295 {
6296 return 3; /* return error */
6297 }
6298
6299 res = a_mpu9250_read(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
6300 if (res != 0) /* check result */
6301 {
6302 handle->debug_print("mpu9250: read power management 1 failed.\n"); /* read power management 1 failed */
6303
6304 return 1; /* return error */
6305 }
6306 prev &= ~(1 << 7); /* clear config */
6307 prev |= 1 << 7; /* set config */
6308 res = a_mpu9250_write(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
6309 if (res != 0) /* check result */
6310 {
6311 handle->debug_print("mpu9250: write power management 1 failed.\n"); /* write power management 1 failed */
6312
6313 return 1; /* return error */
6314 }
6315
6316 return 0; /* success return 0 */
6317 }
6318
6330 uint8_t mpu9250_get_device_reset(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
6331 {
6332 uint8_t res;
6333 uint8_t prev;
6334
6335 if (handle == NULL) /* check handle */
6336 {
6337 return 2; /* return error */
6338 }
6339 if (handle->inited != 1) /* check handle initialization */
6340 {
6341 return 3; /* return error */
6342 }
6343
6344 res = a_mpu9250_read(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
6345 if (res != 0) /* check result */
6346 {
6347 handle->debug_print("mpu9250: read power management 1 failed.\n"); /* read power management 1 failed */
6348
6349 return 1; /* return error */
6350 }
6351 *enable = (mpu9250_bool_t)((prev >> 7) & 0x01); /* get bool */
6352
6353 return 0; /* success return 0 */
6354 }
6355
6367 uint8_t mpu9250_set_clock_source(mpu9250_handle_t *handle, mpu9250_clock_source_t clock_source)
6368 {
6369 uint8_t res;
6370 uint8_t prev;
6371
6372 if (handle == NULL) /* check handle */
6373 {
6374 return 2; /* return error */
6375 }
6376 if (handle->inited != 1) /* check handle initialization */
6377 {
6378 return 3; /* return error */
6379 }
6380
6381 res = a_mpu9250_read(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
6382 if (res != 0) /* check result */
6383 {
6384 handle->debug_print("mpu9250: read power management 1 failed.\n"); /* read power management 1 failed */
6385
6386 return 1; /* return error */
6387 }
6388 prev &= ~(0x7 << 0); /* clear config */
6389 prev |= clock_source << 0; /* set config */
6390 res = a_mpu9250_write(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
6391 if (res != 0) /* check result */
6392 {
6393 handle->debug_print("mpu9250: write power management 1 failed.\n"); /* write power management 1 failed */
6394
6395 return 1; /* return error */
6396 }
6397
6398 return 0; /* success return 0 */
6399 }
6400
6412 uint8_t mpu9250_get_clock_source(mpu9250_handle_t *handle, mpu9250_clock_source_t *clock_source)
6413 {
6414 uint8_t res;
6415 uint8_t prev;
6416
6417 if (handle == NULL) /* check handle */
6418 {
6419 return 2; /* return error */
6420 }
6421 if (handle->inited != 1) /* check handle initialization */
6422 {
6423 return 3; /* return error */
6424 }
6425
6426 res = a_mpu9250_read(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
6427 if (res != 0) /* check result */
6428 {
6429 handle->debug_print("mpu9250: read power management 1 failed.\n"); /* read power management 1 failed */
6430
6431 return 1; /* return error */
6432 }
6433 *clock_source = (mpu9250_clock_source_t)((prev >> 0) & (0x7)); /* get clock source */
6434
6435 return 0; /* success return 0 */
6436 }
6437
6449 uint8_t mpu9250_set_ptat(mpu9250_handle_t *handle, mpu9250_bool_t enable)
6450 {
6451 uint8_t res;
6452 uint8_t prev;
6453
6454 if (handle == NULL) /* check handle */
6455 {
6456 return 2; /* return error */
6457 }
6458 if (handle->inited != 1) /* check handle initialization */
6459 {
6460 return 3; /* return error */
6461 }
6462
6463 res = a_mpu9250_read(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
6464 if (res != 0) /* check result */
6465 {
6466 handle->debug_print("mpu9250: read power management 1 failed.\n"); /* read power management 1 failed */
6467
6468 return 1; /* return error */
6469 }
6470 prev &= ~(1 << 3); /* clear config */
6471 prev |= (!enable) << 3; /* set config */
6472 res = a_mpu9250_write(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
6473 if (res != 0) /* check result */
6474 {
6475 handle->debug_print("mpu9250: write power management 1 failed.\n"); /* write power management 1 failed */
6476
6477 return 1; /* return error */
6478 }
6479
6480 return 0; /* success return 0 */
6481 }
6482
6494 uint8_t mpu9250_get_ptat(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
6495 {
6496 uint8_t res;
6497 uint8_t prev;
6498
6499 if (handle == NULL) /* check handle */
6500 {
6501 return 2; /* return error */
6502 }
6503 if (handle->inited != 1) /* check handle initialization */
6504 {
6505 return 3; /* return error */
6506 }
6507
6508 res = a_mpu9250_read(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
6509 if (res != 0) /* check result */
6510 {
6511 handle->debug_print("mpu9250: read power management 1 failed.\n"); /* read power management 1 failed */
6512
6513 return 1; /* return error */
6514 }
6515 *enable = (mpu9250_bool_t)(!((prev >> 3) & (0x1))); /* get bool */
6516
6517 return 0; /* success return 0 */
6518 }
6519
6531 uint8_t mpu9250_set_cycle_wake_up(mpu9250_handle_t *handle, mpu9250_bool_t enable)
6532 {
6533 uint8_t res;
6534 uint8_t prev;
6535
6536 if (handle == NULL) /* check handle */
6537 {
6538 return 2; /* return error */
6539 }
6540 if (handle->inited != 1) /* check handle initialization */
6541 {
6542 return 3; /* return error */
6543 }
6544
6545 res = a_mpu9250_read(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
6546 if (res != 0) /* check result */
6547 {
6548 handle->debug_print("mpu9250: read power management 1 failed.\n"); /* read power management 1 failed */
6549
6550 return 1; /* return error */
6551 }
6552 prev &= ~(1 << 5); /* clear config */
6553 prev |= enable << 5; /* set config */
6554 res = a_mpu9250_write(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
6555 if (res != 0) /* check result */
6556 {
6557 handle->debug_print("mpu9250: write power management 1 failed.\n"); /* write power management 1 failed */
6558
6559 return 1; /* return error */
6560 }
6561
6562 return 0; /* success return 0 */
6563 }
6564
6576 uint8_t mpu9250_get_cycle_wake_up(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
6577 {
6578 uint8_t res;
6579 uint8_t prev;
6580
6581 if (handle == NULL) /* check handle */
6582 {
6583 return 2; /* return error */
6584 }
6585 if (handle->inited != 1) /* check handle initialization */
6586 {
6587 return 3; /* return error */
6588 }
6589
6590 res = a_mpu9250_read(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
6591 if (res != 0) /* check result */
6592 {
6593 handle->debug_print("mpu9250: read power management 1 failed.\n"); /* read power management 1 failed */
6594
6595 return 1; /* return error */
6596 }
6597 *enable = (mpu9250_bool_t)((prev >> 5) & (0x1)); /* get bool */
6598
6599 return 0; /* success return 0 */
6600 }
6601
6613 uint8_t mpu9250_set_sleep(mpu9250_handle_t *handle, mpu9250_bool_t enable)
6614 {
6615 uint8_t res;
6616 uint8_t prev;
6617
6618 if (handle == NULL) /* check handle */
6619 {
6620 return 2; /* return error */
6621 }
6622 if (handle->inited != 1) /* check handle initialization */
6623 {
6624 return 3; /* return error */
6625 }
6626
6627 res = a_mpu9250_read(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
6628 if (res != 0) /* check result */
6629 {
6630 handle->debug_print("mpu9250: read power management 1 failed.\n"); /* read power management 1 failed */
6631
6632 return 1; /* return error */
6633 }
6634 prev &= ~(1 << 6); /* clear config */
6635 prev |= enable << 6; /* set config */
6636 res = a_mpu9250_write(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
6637 if (res != 0) /* check result */
6638 {
6639 handle->debug_print("mpu9250: write power management 1 failed.\n"); /* write power management 1 failed */
6640
6641 return 1; /* return error */
6642 }
6643
6644 return 0; /* success return 0 */
6645 }
6646
6658 uint8_t mpu9250_get_sleep(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
6659 {
6660 uint8_t res;
6661 uint8_t prev;
6662
6663 if (handle == NULL) /* check handle */
6664 {
6665 return 2; /* return error */
6666 }
6667 if (handle->inited != 1) /* check handle initialization */
6668 {
6669 return 3; /* return error */
6670 }
6671
6672 res = a_mpu9250_read(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
6673 if (res != 0) /* check result */
6674 {
6675 handle->debug_print("mpu9250: read power management 1 failed.\n"); /* read power management 1 failed */
6676
6677 return 1; /* return error */
6678 }
6679 *enable = (mpu9250_bool_t)((prev >> 6) & (0x1)); /* get bool */
6680
6681 return 0; /* success return 0 */
6682 }
6683
6695 uint8_t mpu9250_set_gyro_standby(mpu9250_handle_t *handle, mpu9250_bool_t enable)
6696 {
6697 uint8_t res;
6698 uint8_t prev;
6699
6700 if (handle == NULL) /* check handle */
6701 {
6702 return 2; /* return error */
6703 }
6704 if (handle->inited != 1) /* check handle initialization */
6705 {
6706 return 3; /* return error */
6707 }
6708
6709 res = a_mpu9250_read(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
6710 if (res != 0) /* check result */
6711 {
6712 handle->debug_print("mpu9250: read power management 1 failed.\n"); /* read power management 1 failed */
6713
6714 return 1; /* return error */
6715 }
6716 prev &= ~(1 << 4); /* clear config */
6717 prev |= enable << 4; /* set config */
6718 res = a_mpu9250_write(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
6719 if (res != 0) /* check result */
6720 {
6721 handle->debug_print("mpu9250: write power management 1 failed.\n"); /* write power management 1 failed */
6722
6723 return 1; /* return error */
6724 }
6725
6726 return 0; /* success return 0 */
6727 }
6728
6740 uint8_t mpu9250_get_gyro_standby(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
6741 {
6742 uint8_t res;
6743 uint8_t prev;
6744
6745 if (handle == NULL) /* check handle */
6746 {
6747 return 2; /* return error */
6748 }
6749 if (handle->inited != 1) /* check handle initialization */
6750 {
6751 return 3; /* return error */
6752 }
6753
6754 res = a_mpu9250_read(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
6755 if (res != 0) /* check result */
6756 {
6757 handle->debug_print("mpu9250: read power management 1 failed.\n"); /* read power management 1 failed */
6758
6759 return 1; /* return error */
6760 }
6761 *enable = (mpu9250_bool_t)((prev >> 4) & (0x1)); /* get bool */
6762
6763 return 0; /* success return 0 */
6764 }
6765
6778 uint8_t mpu9250_set_standby_mode(mpu9250_handle_t *handle, mpu9250_source_t source, mpu9250_bool_t enable)
6779 {
6780 uint8_t res;
6781 uint8_t prev;
6782
6783 if (handle == NULL) /* check handle */
6784 {
6785 return 2; /* return error */
6786 }
6787 if (handle->inited != 1) /* check handle initialization */
6788 {
6789 return 3; /* return error */
6790 }
6791
6792 res = a_mpu9250_read(handle, MPU9250_REG_PWR_MGMT_2, (uint8_t *)&prev, 1); /* read config */
6793 if (res != 0) /* check result */
6794 {
6795 handle->debug_print("mpu9250: read power management 2 failed.\n"); /* read power management 2 failed */
6796
6797 return 1; /* return error */
6798 }
6799 prev &= ~(1 << source); /* clear config */
6800 prev |= enable << source; /* set config */
6801 res = a_mpu9250_write(handle, MPU9250_REG_PWR_MGMT_2, (uint8_t *)&prev, 1); /* write config */
6802 if (res != 0) /* check result */
6803 {
6804 handle->debug_print("mpu9250: write power management 2 failed.\n"); /* write power management 2 failed */
6805
6806 return 1; /* return error */
6807 }
6808
6809 return 0; /* success return 0 */
6810 }
6811
6824 uint8_t mpu9250_get_standby_mode(mpu9250_handle_t *handle, mpu9250_source_t source, mpu9250_bool_t *enable)
6825 {
6826 uint8_t res;
6827 uint8_t prev;
6828
6829 if (handle == NULL) /* check handle */
6830 {
6831 return 2; /* return error */
6832 }
6833 if (handle->inited != 1) /* check handle initialization */
6834 {
6835 return 3; /* return error */
6836 }
6837
6838 res = a_mpu9250_read(handle, MPU9250_REG_PWR_MGMT_2, (uint8_t *)&prev, 1); /* read config */
6839 if (res != 0) /* check result */
6840 {
6841 handle->debug_print("mpu9250: read power management 2 failed.\n"); /* read power management 2 failed */
6842
6843 return 1; /* return error */
6844 }
6845 *enable = (mpu9250_bool_t)((prev >> source) & (0x1)); /* get bool */
6846
6847 return 0; /* success return 0 */
6848 }
6849
6861 uint8_t mpu9250_get_fifo_count(mpu9250_handle_t *handle, uint16_t* count)
6862 {
6863 uint8_t res;
6864 uint8_t buf[2];
6865
6866 if (handle == NULL) /* check handle */
6867 {
6868 return 2; /* return error */
6869 }
6870 if (handle->inited != 1) /* check handle initialization */
6871 {
6872 return 3; /* return error */
6873 }
6874
6875 res = a_mpu9250_read(handle, MPU9250_REG_FIFO_COUNTH, (uint8_t *)buf, 2); /* read fifo count */
6876 if (res != 0) /* check result */
6877 {
6878 handle->debug_print("mpu9250: read fifo count failed.\n"); /* read fifo count failed */
6879
6880 return 1; /* return error */
6881 }
6882 *count = (uint16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set count */
6883
6884 return 0; /* success return 0 */
6885 }
6886
6899 uint8_t mpu9250_fifo_get(mpu9250_handle_t *handle, uint8_t *buf, uint16_t len)
6900 {
6901 uint8_t res;
6902
6903 if (handle == NULL) /* check handle */
6904 {
6905 return 2; /* return error */
6906 }
6907 if (handle->inited != 1) /* check handle initialization */
6908 {
6909 return 3; /* return error */
6910 }
6911
6912 res = a_mpu9250_read(handle, MPU9250_REG_R_W, buf, len); /* read fifo */
6913 if (res != 0) /* check result */
6914 {
6915 handle->debug_print("mpu9250: fifo read failed.\n"); /* fifo read failed */
6916
6917 return 1; /* return error */
6918 }
6919
6920 return 0; /* success return 0 */
6921 }
6922
6935 uint8_t mpu9250_fifo_set(mpu9250_handle_t *handle, uint8_t *buf, uint16_t len)
6936 {
6937 uint8_t res;
6938
6939 if (handle == NULL) /* check handle */
6940 {
6941 return 2; /* return error */
6942 }
6943 if (handle->inited != 1) /* check handle initialization */
6944 {
6945 return 3; /* return error */
6946 }
6947
6948 res = a_mpu9250_write(handle, MPU9250_REG_R_W, buf, len); /* write fifo */
6949 if (res != 0) /* check result */
6950 {
6951 handle->debug_print("mpu9250: fifo write failed.\n"); /* fifo write failed */
6952
6953 return 1; /* return error */
6954 }
6955
6956 return 0; /* success return 0 */
6957 }
6958
6970 uint8_t mpu9250_set_signal_path_reset(mpu9250_handle_t *handle, mpu9250_signal_path_reset_t path)
6971 {
6972 uint8_t res;
6973 uint8_t prev;
6974
6975 if (handle == NULL) /* check handle */
6976 {
6977 return 2; /* return error */
6978 }
6979 if (handle->inited != 1) /* check handle initialization */
6980 {
6981 return 3; /* return error */
6982 }
6983
6984 res = a_mpu9250_read(handle, MPU9250_REG_SIGNAL_PATH_RESET, (uint8_t *)&prev, 1); /* read config */
6985 if (res != 0) /* check result */
6986 {
6987 handle->debug_print("mpu9250: read signal path reset failed.\n"); /* read signal path reset failed */
6988
6989 return 1; /* return error */
6990 }
6991 prev &= ~(1 << path); /* clear config */
6992 prev |= 1 << path; /* set config */
6993 res = a_mpu9250_write(handle, MPU9250_REG_SIGNAL_PATH_RESET, (uint8_t *)&prev, 1); /* write config */
6994 if (res != 0) /* check result */
6995 {
6996 handle->debug_print("mpu9250: write signal path reset failed.\n"); /* write signal path reset failed */
6997
6998 return 1; /* return error */
6999 }
7000
7001 return 0; /* success return 0 */
7002 }
7003
7015 uint8_t mpu9250_set_sample_rate_divider(mpu9250_handle_t *handle, uint8_t d)
7016 {
7017 uint8_t res;
7018
7019 if (handle == NULL) /* check handle */
7020 {
7021 return 2; /* return error */
7022 }
7023 if (handle->inited != 1) /* check handle initialization */
7024 {
7025 return 3; /* return error */
7026 }
7027
7028 res = a_mpu9250_write(handle, MPU9250_REG_SMPRT_DIV, (uint8_t *)&d, 1); /* write config */
7029 if (res != 0) /* check result */
7030 {
7031 handle->debug_print("mpu9250: write smprt div failed.\n"); /* write smprt div failed */
7032
7033 return 1; /* return error */
7034 }
7035
7036 return 0; /* success return 0 */
7037 }
7038
7050 uint8_t mpu9250_get_sample_rate_divider(mpu9250_handle_t *handle, uint8_t *d)
7051 {
7052 uint8_t res;
7053
7054 if (handle == NULL) /* check handle */
7055 {
7056 return 2; /* return error */
7057 }
7058 if (handle->inited != 1) /* check handle initialization */
7059 {
7060 return 3; /* return error */
7061 }
7062
7063 res = a_mpu9250_read(handle, MPU9250_REG_SMPRT_DIV, (uint8_t *)d, 1); /* read config */
7064 if (res != 0) /* check result */
7065 {
7066 handle->debug_print("mpu9250: read smprt div failed.\n"); /* read smprt div failed */
7067
7068 return 1; /* return error */
7069 }
7070
7071 return 0; /* success return 0 */
7072 }
7073
7085 uint8_t mpu9250_set_extern_sync(mpu9250_handle_t *handle, mpu9250_extern_sync_t sync)
7086 {
7087 uint8_t res;
7088 uint8_t prev;
7089
7090 if (handle == NULL) /* check handle */
7091 {
7092 return 2; /* return error */
7093 }
7094 if (handle->inited != 1) /* check handle initialization */
7095 {
7096 return 3; /* return error */
7097 }
7098
7099 res = a_mpu9250_read(handle, MPU9250_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
7100 if (res != 0) /* check result */
7101 {
7102 handle->debug_print("mpu9250: read config failed.\n"); /* read config failed */
7103
7104 return 1; /* return error */
7105 }
7106 prev &= ~(0x7 << 3); /* clear config */
7107 prev |= sync << 3; /* set config */
7108 res = a_mpu9250_write(handle, MPU9250_REG_CONFIG, (uint8_t *)&prev, 1); /* write config */
7109 if (res != 0) /* check result */
7110 {
7111 handle->debug_print("mpu9250: write config failed.\n"); /* write config failed */
7112
7113 return 1; /* return error */
7114 }
7115
7116 return 0; /* success return 0 */
7117 }
7118
7130 uint8_t mpu9250_get_extern_sync(mpu9250_handle_t *handle, mpu9250_extern_sync_t *sync)
7131 {
7132 uint8_t res;
7133 uint8_t prev;
7134
7135 if (handle == NULL) /* check handle */
7136 {
7137 return 2; /* return error */
7138 }
7139 if (handle->inited != 1) /* check handle initialization */
7140 {
7141 return 3; /* return error */
7142 }
7143
7144 res = a_mpu9250_read(handle, MPU9250_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
7145 if (res != 0) /* check result */
7146 {
7147 handle->debug_print("mpu9250: read config failed.\n"); /* read config failed */
7148
7149 return 1; /* return error */
7150 }
7151 *sync = (mpu9250_extern_sync_t)((prev >> 3) & 0x7); /* get the extern sync */
7152
7153 return 0; /* success return 0 */
7154 }
7155
7167 uint8_t mpu9250_set_low_pass_filter(mpu9250_handle_t *handle, mpu9250_low_pass_filter_t filter)
7168 {
7169 uint8_t res;
7170 uint8_t prev;
7171
7172 if (handle == NULL) /* check handle */
7173 {
7174 return 2; /* return error */
7175 }
7176 if (handle->inited != 1) /* check handle initialization */
7177 {
7178 return 3; /* return error */
7179 }
7180
7181 res = a_mpu9250_read(handle, MPU9250_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
7182 if (res != 0) /* check result */
7183 {
7184 handle->debug_print("mpu9250: read config failed.\n"); /* read config failed */
7185
7186 return 1; /* return error */
7187 }
7188 prev &= ~(0x7 << 0); /* clear config */
7189 prev |= filter << 0; /* set config */
7190 res = a_mpu9250_write(handle, MPU9250_REG_CONFIG, (uint8_t *)&prev, 1); /* write config */
7191 if (res != 0) /* check result */
7192 {
7193 handle->debug_print("mpu9250: write config failed.\n"); /* write config failed */
7194
7195 return 1; /* return error */
7196 }
7197
7198 return 0; /* success return 0 */
7199 }
7200
7212 uint8_t mpu9250_get_low_pass_filter(mpu9250_handle_t *handle, mpu9250_low_pass_filter_t *filter)
7213 {
7214 uint8_t res;
7215 uint8_t prev;
7216
7217 if (handle == NULL) /* check handle */
7218 {
7219 return 2; /* return error */
7220 }
7221 if (handle->inited != 1) /* check handle initialization */
7222 {
7223 return 3; /* return error */
7224 }
7225
7226 res = a_mpu9250_read(handle, MPU9250_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
7227 if (res != 0) /* check result */
7228 {
7229 handle->debug_print("mpu9250: read config failed.\n"); /* read config failed */
7230
7231 return 1; /* return error */
7232 }
7233 *filter = (mpu9250_low_pass_filter_t)((prev >> 0) & 0x7); /* get the filter */
7234
7235 return 0; /* success return 0 */
7236 }
7237
7249 uint8_t mpu9250_set_fifo_mode(mpu9250_handle_t *handle, mpu9250_fifo_mode mode)
7250 {
7251 uint8_t res;
7252 uint8_t prev;
7253
7254 if (handle == NULL) /* check handle */
7255 {
7256 return 2; /* return error */
7257 }
7258 if (handle->inited != 1) /* check handle initialization */
7259 {
7260 return 3; /* return error */
7261 }
7262
7263 res = a_mpu9250_read(handle, MPU9250_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
7264 if (res != 0) /* check result */
7265 {
7266 handle->debug_print("mpu9250: read config failed.\n"); /* read config failed */
7267
7268 return 1; /* return error */
7269 }
7270 prev &= ~(1 << 6); /* clear config */
7271 prev |= mode << 6; /* set config */
7272 res = a_mpu9250_write(handle, MPU9250_REG_CONFIG, (uint8_t *)&prev, 1); /* write config */
7273 if (res != 0) /* check result */
7274 {
7275 handle->debug_print("mpu9250: write config failed.\n"); /* write config failed */
7276
7277 return 1; /* return error */
7278 }
7279
7280 return 0; /* success return 0 */
7281 }
7282
7294 uint8_t mpu9250_get_fifo_mode(mpu9250_handle_t *handle, mpu9250_fifo_mode *mode)
7295 {
7296 uint8_t res;
7297 uint8_t prev;
7298
7299 if (handle == NULL) /* check handle */
7300 {
7301 return 2; /* return error */
7302 }
7303 if (handle->inited != 1) /* check handle initialization */
7304 {
7305 return 3; /* return error */
7306 }
7307
7308 res = a_mpu9250_read(handle, MPU9250_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
7309 if (res != 0) /* check result */
7310 {
7311 handle->debug_print("mpu9250: read config failed.\n"); /* read config failed */
7312
7313 return 1; /* return error */
7314 }
7315 *mode = (mpu9250_fifo_mode)((prev >> 6) & 0x1); /* get the mode */
7316
7317 return 0; /* success return 0 */
7318 }
7319
7332 uint8_t mpu9250_set_gyroscope_test(mpu9250_handle_t *handle, mpu9250_axis_t axis, mpu9250_bool_t enable)
7333 {
7334 uint8_t res;
7335 uint8_t prev;
7336
7337 if (handle == NULL) /* check handle */
7338 {
7339 return 2; /* return error */
7340 }
7341 if (handle->inited != 1) /* check handle initialization */
7342 {
7343 return 3; /* return error */
7344 }
7345
7346 res = a_mpu9250_read(handle, MPU9250_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* read gyroscope config */
7347 if (res != 0) /* check result */
7348 {
7349 handle->debug_print("mpu9250: read gyroscope config failed.\n"); /* read gyroscope config failed */
7350
7351 return 1; /* return error */
7352 }
7353 prev &= ~(1 << axis); /* clear config */
7354 prev |= enable << axis; /* set config */
7355 res = a_mpu9250_write(handle, MPU9250_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* write gyroscope config */
7356 if (res != 0) /* check result */
7357 {
7358 handle->debug_print("mpu9250: write gyroscope config failed.\n"); /* write gyroscope config failed */
7359
7360 return 1; /* return error */
7361 }
7362
7363 return 0; /* success return 0 */
7364 }
7365
7378 uint8_t mpu9250_get_gyroscope_test(mpu9250_handle_t *handle, mpu9250_axis_t axis, mpu9250_bool_t *enable)
7379 {
7380 uint8_t res;
7381 uint8_t prev;
7382
7383 if (handle == NULL) /* check handle */
7384 {
7385 return 2; /* return error */
7386 }
7387 if (handle->inited != 1) /* check handle initialization */
7388 {
7389 return 3; /* return error */
7390 }
7391
7392 res = a_mpu9250_read(handle, MPU9250_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* read gyroscope config */
7393 if (res != 0) /* check result */
7394 {
7395 handle->debug_print("mpu9250: read gyroscope config failed.\n"); /* read gyroscope config failed */
7396
7397 return 1; /* return error */
7398 }
7399 *enable = (mpu9250_bool_t)((prev >> axis) & 0x01); /* get the bool */
7400
7401 return 0; /* success return 0 */
7402 }
7403
7415 uint8_t mpu9250_set_gyroscope_range(mpu9250_handle_t *handle, mpu9250_gyroscope_range_t range)
7416 {
7417 uint8_t res;
7418 uint8_t prev;
7419
7420 if (handle == NULL) /* check handle */
7421 {
7422 return 2; /* return error */
7423 }
7424 if (handle->inited != 1) /* check handle initialization */
7425 {
7426 return 3; /* return error */
7427 }
7428
7429 res = a_mpu9250_read(handle, MPU9250_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* read gyroscope config */
7430 if (res != 0) /* check result */
7431 {
7432 handle->debug_print("mpu9250: read gyroscope config failed.\n"); /* read gyroscope config failed */
7433
7434 return 1; /* return error */
7435 }
7436 prev &= ~(3 << 3); /* clear config */
7437 prev |= range << 3; /* set config */
7438 res = a_mpu9250_write(handle, MPU9250_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* write gyroscope config */
7439 if (res != 0) /* check result */
7440 {
7441 handle->debug_print("mpu9250: write gyroscope config failed.\n"); /* write gyroscope config failed */
7442
7443 return 1; /* return error */
7444 }
7445
7446 return 0; /* success return 0 */
7447 }
7448
7460 uint8_t mpu9250_get_gyroscope_range(mpu9250_handle_t *handle, mpu9250_gyroscope_range_t *range)
7461 {
7462 uint8_t res;
7463 uint8_t prev;
7464
7465 if (handle == NULL) /* check handle */
7466 {
7467 return 2; /* return error */
7468 }
7469 if (handle->inited != 1) /* check handle initialization */
7470 {
7471 return 3; /* return error */
7472 }
7473
7474 res = a_mpu9250_read(handle, MPU9250_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* read gyroscope config */
7475 if (res != 0) /* check result */
7476 {
7477 handle->debug_print("mpu9250: read gyroscope config failed.\n"); /* read gyroscope config failed */
7478
7479 return 1; /* return error */
7480 }
7481 *range = (mpu9250_gyroscope_range_t)((prev >> 3) & 0x3); /* get the range */
7482
7483 return 0; /* success return 0 */
7484 }
7485
7498 uint8_t mpu9250_set_gyroscope_choice(mpu9250_handle_t *handle, uint8_t choice)
7499 {
7500 uint8_t res;
7501 uint8_t prev;
7502
7503 if (handle == NULL) /* check handle */
7504 {
7505 return 2; /* return error */
7506 }
7507 if (handle->inited != 1) /* check handle initialization */
7508 {
7509 return 3; /* return error */
7510 }
7511 if (choice > 3) /* check the choice */
7512 {
7513 handle->debug_print("mpu9250: choice > 3.\n"); /* choice > 3 */
7514
7515 return 4; /* return error */
7516 }
7517
7518 res = a_mpu9250_read(handle, MPU9250_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* read gyroscope config */
7519 if (res != 0) /* check result */
7520 {
7521 handle->debug_print("mpu9250: read gyroscope config failed.\n"); /* read gyroscope config failed */
7522
7523 return 1; /* return error */
7524 }
7525 prev &= ~(3 << 0); /* clear config */
7526 prev |= choice << 0; /* set config */
7527 res = a_mpu9250_write(handle, MPU9250_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* write gyroscope config */
7528 if (res != 0) /* check result */
7529 {
7530 handle->debug_print("mpu9250: write gyroscope config failed.\n"); /* write gyroscope config failed */
7531
7532 return 1; /* return error */
7533 }
7534
7535 return 0; /* success return 0 */
7536 }
7537
7549 uint8_t mpu9250_get_gyroscope_choice(mpu9250_handle_t *handle, uint8_t *choice)
7550 {
7551 uint8_t res;
7552 uint8_t prev;
7553
7554 if (handle == NULL) /* check handle */
7555 {
7556 return 2; /* return error */
7557 }
7558 if (handle->inited != 1) /* check handle initialization */
7559 {
7560 return 3; /* return error */
7561 }
7562
7563 res = a_mpu9250_read(handle, MPU9250_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* read gyroscope config */
7564 if (res != 0) /* check result */
7565 {
7566 handle->debug_print("mpu9250: read gyroscope config failed.\n"); /* read gyroscope config failed */
7567
7568 return 1; /* return error */
7569 }
7570 *choice = prev & 0x03; /* get the choice */
7571
7572 return 0; /* success return 0 */
7573 }
7574
7587 uint8_t mpu9250_set_accelerometer_test(mpu9250_handle_t *handle, mpu9250_axis_t axis, mpu9250_bool_t enable)
7588 {
7589 uint8_t res;
7590 uint8_t prev;
7591
7592 if (handle == NULL) /* check handle */
7593 {
7594 return 2; /* return error */
7595 }
7596 if (handle->inited != 1) /* check handle initialization */
7597 {
7598 return 3; /* return error */
7599 }
7600
7601 res = a_mpu9250_read(handle, MPU9250_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* read accelerometer config */
7602 if (res != 0) /* check result */
7603 {
7604 handle->debug_print("mpu9250: read accelerometer config failed.\n"); /* read accelerometer config failed */
7605
7606 return 1; /* return error */
7607 }
7608 prev &= ~(1 << axis); /* clear config */
7609 prev |= enable << axis; /* set config */
7610 res = a_mpu9250_write(handle, MPU9250_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* write accelerometer config */
7611 if (res != 0) /* check result */
7612 {
7613 handle->debug_print("mpu9250: write accelerometer config failed.\n"); /* write accelerometer config failed */
7614
7615 return 1; /* return error */
7616 }
7617
7618 return 0; /* success return 0 */
7619 }
7620
7633 uint8_t mpu9250_get_accelerometer_test(mpu9250_handle_t *handle, mpu9250_axis_t axis, mpu9250_bool_t *enable)
7634 {
7635 uint8_t res;
7636 uint8_t prev;
7637
7638 if (handle == NULL) /* check handle */
7639 {
7640 return 2; /* return error */
7641 }
7642 if (handle->inited != 1) /* check handle initialization */
7643 {
7644 return 3; /* return error */
7645 }
7646
7647 res = a_mpu9250_read(handle, MPU9250_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* read accelerometer config */
7648 if (res != 0) /* check result */
7649 {
7650 handle->debug_print("mpu9250: read accelerometer config failed.\n"); /* read accelerometer config failed */
7651
7652 return 1; /* return error */
7653 }
7654 *enable = (mpu9250_bool_t)((prev >> axis) & 0x01); /* get the bool */
7655
7656 return 0; /* success return 0 */
7657 }
7658
7670 uint8_t mpu9250_set_accelerometer_range(mpu9250_handle_t *handle, mpu9250_accelerometer_range_t range)
7671 {
7672 uint8_t res;
7673 uint8_t prev;
7674
7675 if (handle == NULL) /* check handle */
7676 {
7677 return 2; /* return error */
7678 }
7679 if (handle->inited != 1) /* check handle initialization */
7680 {
7681 return 3; /* return error */
7682 }
7683
7684 res = a_mpu9250_read(handle, MPU9250_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* read accelerometer config */
7685 if (res != 0) /* check result */
7686 {
7687 handle->debug_print("mpu9250: read accelerometer config failed.\n"); /* read accelerometer config failed */
7688
7689 return 1; /* return error */
7690 }
7691 prev &= ~(3 << 3); /* clear config */
7692 prev |= range << 3; /* set config */
7693 res = a_mpu9250_write(handle, MPU9250_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* write accelerometer config */
7694 if (res != 0) /* check result */
7695 {
7696 handle->debug_print("mpu9250: write accelerometer config failed.\n"); /* write accelerometer config failed */
7697
7698 return 1; /* return error */
7699 }
7700
7701 return 0; /* success return 0 */
7702 }
7703
7715 uint8_t mpu9250_get_accelerometer_range(mpu9250_handle_t *handle, mpu9250_accelerometer_range_t *range)
7716 {
7717 uint8_t res;
7718 uint8_t prev;
7719
7720 if (handle == NULL) /* check handle */
7721 {
7722 return 2; /* return error */
7723 }
7724 if (handle->inited != 1) /* check handle initialization */
7725 {
7726 return 3; /* return error */
7727 }
7728
7729 res = a_mpu9250_read(handle, MPU9250_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* read accelerometer config */
7730 if (res != 0) /* check result */
7731 {
7732 handle->debug_print("mpu9250: read accelerometer config failed.\n"); /* read accelerometer config failed */
7733
7734 return 1; /* return error */
7735 }
7736 *range = (mpu9250_accelerometer_range_t)((prev >> 3) & 0x3); /* get the range */
7737
7738 return 0; /* success return 0 */
7739 }
7740
7751 uint8_t mpu9250_set_fifo_1024kb(mpu9250_handle_t *handle)
7752 {
7753 uint8_t res;
7754 uint8_t prev;
7755
7756 if (handle == NULL) /* check handle */
7757 {
7758 return 2; /* return error */
7759 }
7760 if (handle->inited != 1) /* check handle initialization */
7761 {
7762 return 3; /* return error */
7763 }
7764
7765 res = a_mpu9250_read(handle, MPU9250_REG_ACCEL_CONFIG2, (uint8_t *)&prev, 1); /* read config */
7766 if (res != 0) /* check result */
7767 {
7768 handle->debug_print("mpu9250: read accelerometer 2 config failed.\n"); /* read accelerometer 2 config failed */
7769
7770 return 1; /* return error */
7771 }
7772 prev &= ~(1 << 6); /* clear config */
7773 prev |= 1 << 6; /* set config */
7774 res = a_mpu9250_write(handle, MPU9250_REG_ACCEL_CONFIG2, (uint8_t *)&prev, 1); /* write config */
7775 if (res != 0) /* check result */
7776 {
7777 handle->debug_print("mpu9250: write accelerometer 2 config failed.\n"); /* write accelerometer 2 config failed */
7778
7779 return 1; /* return error */
7780 }
7781
7782 return 0; /* success return 0 */
7783 }
7784
7797 uint8_t mpu9250_set_accelerometer_choice(mpu9250_handle_t *handle, uint8_t choice)
7798 {
7799 uint8_t res;
7800 uint8_t prev;
7801
7802 if (handle == NULL) /* check handle */
7803 {
7804 return 2; /* return error */
7805 }
7806 if (handle->inited != 1) /* check handle initialization */
7807 {
7808 return 3; /* return error */
7809 }
7810 if (choice > 1) /* check the choice */
7811 {
7812 handle->debug_print("mpu9250: choice > 1.\n"); /* choice > 1 */
7813
7814 return 4; /* return error */
7815 }
7816
7817 res = a_mpu9250_read(handle, MPU9250_REG_ACCEL_CONFIG2, (uint8_t *)&prev, 1); /* read accelerometer config */
7818 if (res != 0) /* check result */
7819 {
7820 handle->debug_print("mpu9250: read accelerometer 2 config failed.\n"); /* read accelerometer 2 config failed */
7821
7822 return 1; /* return error */
7823 }
7824 prev &= ~(1 << 3); /* clear config */
7825 prev |= choice << 3; /* set config */
7826 res = a_mpu9250_write(handle, MPU9250_REG_ACCEL_CONFIG2, (uint8_t *)&prev, 1); /* write accelerometer config */
7827 if (res != 0) /* check result */
7828 {
7829 handle->debug_print("mpu9250: write accelerometer 2 config failed.\n"); /* write accelerometer 2 config failed */
7830
7831 return 1; /* return error */
7832 }
7833
7834 return 0; /* success return 0 */
7835 }
7836
7849 uint8_t mpu9250_get_accelerometer_choice(mpu9250_handle_t *handle, uint8_t *choice)
7850 {
7851 uint8_t res;
7852 uint8_t prev;
7853
7854 if (handle == NULL) /* check handle */
7855 {
7856 return 2; /* return error */
7857 }
7858 if (handle->inited != 1) /* check handle initialization */
7859 {
7860 return 3; /* return error */
7861 }
7862
7863 res = a_mpu9250_read(handle, MPU9250_REG_ACCEL_CONFIG2, (uint8_t *)&prev, 1); /* read accelerometer config */
7864 if (res != 0) /* check result */
7865 {
7866 handle->debug_print("mpu9250: read accelerometer 2 config failed.\n"); /* read accelerometer 2 config failed */
7867
7868 return 1; /* return error */
7869 }
7870 *choice = (prev >> 3) & 0x1; /* get the choice */
7871
7872 return 0; /* success return 0 */
7873 }
7874
7886 uint8_t mpu9250_set_accelerometer_low_pass_filter(mpu9250_handle_t *handle, mpu9250_accelerometer_low_pass_filter_t filter)
7887 {
7888 uint8_t res;
7889 uint8_t prev;
7890
7891 if (handle == NULL) /* check handle */
7892 {
7893 return 2; /* return error */
7894 }
7895 if (handle->inited != 1) /* check handle initialization */
7896 {
7897 return 3; /* return error */
7898 }
7899
7900 res = a_mpu9250_read(handle, MPU9250_REG_ACCEL_CONFIG2, (uint8_t *)&prev, 1); /* read config */
7901 if (res != 0) /* check result */
7902 {
7903 handle->debug_print("mpu9250: read accelerometer 2 config failed.\n"); /* read accelerometer 2 config failed */
7904
7905 return 1; /* return error */
7906 }
7907 prev &= ~(0x7 << 0); /* clear config */
7908 prev |= filter << 0; /* set config */
7909 res = a_mpu9250_write(handle, MPU9250_REG_ACCEL_CONFIG2, (uint8_t *)&prev, 1); /* write config */
7910 if (res != 0) /* check result */
7911 {
7912 handle->debug_print("mpu9250: write accelerometer 2 config failed.\n"); /* write accelerometer 2 config failed */
7913
7914 return 1; /* return error */
7915 }
7916
7917 return 0; /* success return 0 */
7918 }
7919
7931 uint8_t mpu9250_get_accelerometer_low_pass_filter(mpu9250_handle_t *handle, mpu9250_accelerometer_low_pass_filter_t *filter)
7932 {
7933 uint8_t res;
7934 uint8_t prev;
7935
7936 if (handle == NULL) /* check handle */
7937 {
7938 return 2; /* return error */
7939 }
7940 if (handle->inited != 1) /* check handle initialization */
7941 {
7942 return 3; /* return error */
7943 }
7944
7945 res = a_mpu9250_read(handle, MPU9250_REG_ACCEL_CONFIG2, (uint8_t *)&prev, 1); /* read config */
7946 if (res != 0) /* check result */
7947 {
7948 handle->debug_print("mpu9250: read accelerometer 2 config failed.\n"); /* read accelerometer 2 config failed */
7949
7950 return 1; /* return error */
7951 }
7952 *filter = (mpu9250_accelerometer_low_pass_filter_t)(prev & 0x7); /* get the filter */
7953
7954 return 0; /* success return 0 */
7955 }
7956
7968 uint8_t mpu9250_set_low_power_accel_output_rate(mpu9250_handle_t *handle, mpu9250_low_power_accel_output_rate_t rate)
7969 {
7970 uint8_t res;
7971 uint8_t prev;
7972
7973 if (handle == NULL) /* check handle */
7974 {
7975 return 2; /* return error */
7976 }
7977 if (handle->inited != 1) /* check handle initialization */
7978 {
7979 return 3; /* return error */
7980 }
7981
7982 res = a_mpu9250_read(handle, MPU9250_REG_LP_ACCEL_ODR, (uint8_t *)&prev, 1); /* read config */
7983 if (res != 0) /* check result */
7984 {
7985 handle->debug_print("mpu9250: read lp accelerometer odr failed.\n"); /* read lp accelerometer odr failed */
7986
7987 return 1; /* return error */
7988 }
7989 prev &= ~(0xF << 0); /* clear config */
7990 prev |= rate << 0; /* set config */
7991 res = a_mpu9250_write(handle, MPU9250_REG_LP_ACCEL_ODR, (uint8_t *)&prev, 1); /* write config */
7992 if (res != 0) /* check result */
7993 {
7994 handle->debug_print("mpu9250: write lp accelerometer odr failed.\n"); /* write lp accelerometer odr failed */
7995
7996 return 1; /* return error */
7997 }
7998
7999 return 0; /* success return 0 */
8000 }
8001
8013 uint8_t mpu9250_get_low_power_accel_output_rate(mpu9250_handle_t *handle, mpu9250_low_power_accel_output_rate_t *rate)
8014 {
8015 uint8_t res;
8016 uint8_t prev;
8017
8018 if (handle == NULL) /* check handle */
8019 {
8020 return 2; /* return error */
8021 }
8022 if (handle->inited != 1) /* check handle initialization */
8023 {
8024 return 3; /* return error */
8025 }
8026
8027 res = a_mpu9250_read(handle, MPU9250_REG_LP_ACCEL_ODR, (uint8_t *)&prev, 1); /* read config */
8028 if (res != 0) /* check result */
8029 {
8030 handle->debug_print("mpu9250: read lp accelerometer odr failed.\n"); /* read lp accelerometer odr failed */
8031
8032 return 1; /* return error */
8033 }
8034 *rate = (mpu9250_low_power_accel_output_rate_t)(prev & 0xF); /* get the rate */
8035
8036 return 0; /* success return 0 */
8037 }
8038
8050 uint8_t mpu9250_set_wake_on_motion(mpu9250_handle_t *handle, mpu9250_bool_t enable)
8051 {
8052 uint8_t res;
8053 uint8_t prev;
8054
8055 if (handle == NULL) /* check handle */
8056 {
8057 return 2; /* return error */
8058 }
8059 if (handle->inited != 1) /* check handle initialization */
8060 {
8061 return 3; /* return error */
8062 }
8063
8064 res = a_mpu9250_read(handle, MPU9250_REG_MOT_DETECT_CTRL, (uint8_t *)&prev, 1); /* read config */
8065 if (res != 0) /* check result */
8066 {
8067 handle->debug_print("mpu9250: read motion detect ctrl failed.\n"); /* read motion detect ctrl failed */
8068
8069 return 1; /* return error */
8070 }
8071 prev &= ~(1 << 7); /* clear config */
8072 prev |= enable << 7; /* set config */
8073 res = a_mpu9250_write(handle, MPU9250_REG_MOT_DETECT_CTRL, (uint8_t *)&prev, 1); /* write config */
8074 if (res != 0) /* check result */
8075 {
8076 handle->debug_print("mpu9250: write motion detect ctrl failed.\n"); /* write motion detect ctrl failed */
8077
8078 return 1; /* return error */
8079 }
8080
8081 return 0; /* success return 0 */
8082 }
8083
8095 uint8_t mpu9250_get_wake_on_motion(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
8096 {
8097 uint8_t res;
8098 uint8_t prev;
8099
8100 if (handle == NULL) /* check handle */
8101 {
8102 return 2; /* return error */
8103 }
8104 if (handle->inited != 1) /* check handle initialization */
8105 {
8106 return 3; /* return error */
8107 }
8108
8109 res = a_mpu9250_read(handle, MPU9250_REG_MOT_DETECT_CTRL, (uint8_t *)&prev, 1); /* read config */
8110 if (res != 0) /* check result */
8111 {
8112 handle->debug_print("mpu9250: read motion detect ctrl failed.\n"); /* read motion detect ctrl failed */
8113
8114 return 1; /* return error */
8115 }
8116 *enable = (mpu9250_bool_t)((prev >> 7) & 0x01); /* get the bool */
8117
8118 return 0; /* success return 0 */
8119 }
8120
8132 uint8_t mpu9250_set_accel_compare_with_previous_sample(mpu9250_handle_t *handle, mpu9250_bool_t enable)
8133 {
8134 uint8_t res;
8135 uint8_t prev;
8136
8137 if (handle == NULL) /* check handle */
8138 {
8139 return 2; /* return error */
8140 }
8141 if (handle->inited != 1) /* check handle initialization */
8142 {
8143 return 3; /* return error */
8144 }
8145
8146 res = a_mpu9250_read(handle, MPU9250_REG_MOT_DETECT_CTRL, (uint8_t *)&prev, 1); /* read config */
8147 if (res != 0) /* check result */
8148 {
8149 handle->debug_print("mpu9250: read motion detect ctrl failed.\n"); /* read motion detect ctrl failed */
8150
8151 return 1; /* return error */
8152 }
8153 prev &= ~(1 << 6); /* clear config */
8154 prev |= enable << 6; /* set config */
8155 res = a_mpu9250_write(handle, MPU9250_REG_MOT_DETECT_CTRL, (uint8_t *)&prev, 1); /* write config */
8156 if (res != 0) /* check result */
8157 {
8158 handle->debug_print("mpu9250: write motion detect ctrl failed.\n"); /* write motion detect ctrl failed */
8159
8160 return 1; /* return error */
8161 }
8162
8163 return 0; /* success return 0 */
8164 }
8165
8177 uint8_t mpu9250_get_accel_compare_with_previous_sample(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
8178 {
8179 uint8_t res;
8180 uint8_t prev;
8181
8182 if (handle == NULL) /* check handle */
8183 {
8184 return 2; /* return error */
8185 }
8186 if (handle->inited != 1) /* check handle initialization */
8187 {
8188 return 3; /* return error */
8189 }
8190
8191 res = a_mpu9250_read(handle, MPU9250_REG_MOT_DETECT_CTRL, (uint8_t *)&prev, 1); /* read config */
8192 if (res != 0) /* check result */
8193 {
8194 handle->debug_print("mpu9250: read motion detect ctrl failed.\n"); /* read motion detect ctrl failed */
8195
8196 return 1; /* return error */
8197 }
8198 *enable = (mpu9250_bool_t)((prev >> 6) & 0x01); /* get the bool */
8199
8200 return 0; /* success return 0 */
8201 }
8202
8215 uint8_t mpu9250_set_fifo_enable(mpu9250_handle_t *handle, mpu9250_fifo_t fifo, mpu9250_bool_t enable)
8216 {
8217 uint8_t res;
8218 uint8_t prev;
8219
8220 if (handle == NULL) /* check handle */
8221 {
8222 return 2; /* return error */
8223 }
8224 if (handle->inited != 1) /* check handle initialization */
8225 {
8226 return 3; /* return error */
8227 }
8228
8229 res = a_mpu9250_read(handle, MPU9250_REG_FIFO_EN, (uint8_t *)&prev, 1); /* read fifo enable config */
8230 if (res != 0) /* check result */
8231 {
8232 handle->debug_print("mpu9250: read fifo enable config failed.\n"); /* read fifo enable config failed */
8233
8234 return 1; /* return error */
8235 }
8236 prev &= ~(1 << fifo); /* clear config */
8237 prev |= enable << fifo; /* set config */
8238 res = a_mpu9250_write(handle, MPU9250_REG_FIFO_EN, (uint8_t *)&prev, 1); /* write fifo enable config */
8239 if (res != 0) /* check result */
8240 {
8241 handle->debug_print("mpu9250: write fifo enable config failed.\n"); /* write fifo enable config failed */
8242
8243 return 1; /* return error */
8244 }
8245
8246 return 0; /* success return 0 */
8247 }
8248
8261 uint8_t mpu9250_get_fifo_enable(mpu9250_handle_t *handle, mpu9250_fifo_t fifo, mpu9250_bool_t *enable)
8262 {
8263 uint8_t res;
8264 uint8_t prev;
8265
8266 if (handle == NULL) /* check handle */
8267 {
8268 return 2; /* return error */
8269 }
8270 if (handle->inited != 1) /* check handle initialization */
8271 {
8272 return 3; /* return error */
8273 }
8274
8275 res = a_mpu9250_read(handle, MPU9250_REG_FIFO_EN, (uint8_t *)&prev, 1); /* read fifo enable config */
8276 if (res != 0) /* check result */
8277 {
8278 handle->debug_print("mpu9250: read fifo enable config failed.\n"); /* read fifo enable config failed */
8279
8280 return 1; /* return error */
8281 }
8282 *enable = (mpu9250_bool_t)((prev >> fifo) & 0x01); /* get the bool */
8283
8284 return 0; /* success return 0 */
8285 }
8286
8298 uint8_t mpu9250_set_interrupt_level(mpu9250_handle_t *handle, mpu9250_pin_level_t level)
8299 {
8300 uint8_t res;
8301 uint8_t prev;
8302
8303 if (handle == NULL) /* check handle */
8304 {
8305 return 2; /* return error */
8306 }
8307 if (handle->inited != 1) /* check handle initialization */
8308 {
8309 return 3; /* return error */
8310 }
8311
8312 res = a_mpu9250_read(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
8313 if (res != 0) /* check result */
8314 {
8315 handle->debug_print("mpu9250: read interrupt pin failed.\n"); /* read interrupt pin failed */
8316
8317 return 1; /* return error */
8318 }
8319 prev &= ~(1 << 7); /* clear config */
8320 prev |= level << 7; /* set config */
8321 res = a_mpu9250_write(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
8322 if (res != 0) /* check result */
8323 {
8324 handle->debug_print("mpu9250: write interrupt pin failed.\n"); /* write interrupt pin failed */
8325
8326 return 1; /* return error */
8327 }
8328
8329 return 0; /* success return 0 */
8330 }
8331
8343 uint8_t mpu9250_get_interrupt_level(mpu9250_handle_t *handle, mpu9250_pin_level_t *level)
8344 {
8345 uint8_t res;
8346 uint8_t prev;
8347
8348 if (handle == NULL) /* check handle */
8349 {
8350 return 2; /* return error */
8351 }
8352 if (handle->inited != 1) /* check handle initialization */
8353 {
8354 return 3; /* return error */
8355 }
8356
8357 res = a_mpu9250_read(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
8358 if (res != 0) /* check result */
8359 {
8360 handle->debug_print("mpu9250: read interrupt pin failed.\n"); /* read interrupt pin failed */
8361
8362 return 1; /* return error */
8363 }
8364 *level = (mpu9250_pin_level_t)((prev >> 7) & 0x01); /* get the level */
8365
8366 return 0; /* success return 0 */
8367 }
8368
8380 uint8_t mpu9250_set_interrupt_pin_type(mpu9250_handle_t *handle, mpu9250_pin_type_t type)
8381 {
8382 uint8_t res;
8383 uint8_t prev;
8384
8385 if (handle == NULL) /* check handle */
8386 {
8387 return 2; /* return error */
8388 }
8389 if (handle->inited != 1) /* check handle initialization */
8390 {
8391 return 3; /* return error */
8392 }
8393
8394 res = a_mpu9250_read(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
8395 if (res != 0) /* check result */
8396 {
8397 handle->debug_print("mpu9250: read interrupt pin failed.\n"); /* read interrupt pin failed */
8398
8399 return 1; /* return error */
8400 }
8401 prev &= ~(1 << 6); /* clear config */
8402 prev |= type << 6; /* set config */
8403 res = a_mpu9250_write(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
8404 if (res != 0) /* check result */
8405 {
8406 handle->debug_print("mpu9250: write interrupt pin failed.\n"); /* write interrupt pin failed */
8407
8408 return 1; /* return error */
8409 }
8410
8411 return 0; /* success return 0 */
8412 }
8413
8425 uint8_t mpu9250_get_interrupt_pin_type(mpu9250_handle_t *handle, mpu9250_pin_type_t *type)
8426 {
8427 uint8_t res;
8428 uint8_t prev;
8429
8430 if (handle == NULL) /* check handle */
8431 {
8432 return 2; /* return error */
8433 }
8434 if (handle->inited != 1) /* check handle initialization */
8435 {
8436 return 3; /* return error */
8437 }
8438
8439 res = a_mpu9250_read(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
8440 if (res != 0) /* check result */
8441 {
8442 handle->debug_print("mpu9250: read interrupt pin failed.\n"); /* read interrupt pin failed */
8443
8444 return 1; /* return error */
8445 }
8446 *type = (mpu9250_pin_type_t)((prev >> 6) & 0x01); /* get the pin type */
8447
8448 return 0; /* success return 0 */
8449 }
8450
8462 uint8_t mpu9250_set_interrupt_latch(mpu9250_handle_t *handle, mpu9250_bool_t enable)
8463 {
8464 uint8_t res;
8465 uint8_t prev;
8466
8467 if (handle == NULL) /* check handle */
8468 {
8469 return 2; /* return error */
8470 }
8471 if (handle->inited != 1) /* check handle initialization */
8472 {
8473 return 3; /* return error */
8474 }
8475
8476 res = a_mpu9250_read(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
8477 if (res != 0) /* check result */
8478 {
8479 handle->debug_print("mpu9250: read interrupt pin failed.\n"); /* read interrupt pin failed */
8480
8481 return 1; /* return error */
8482 }
8483 prev &= ~(1 << 5); /* clear config */
8484 prev |= (!enable) << 5; /* set config */
8485 res = a_mpu9250_write(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
8486 if (res != 0) /* check result */
8487 {
8488 handle->debug_print("mpu9250: write interrupt pin failed.\n"); /* write interrupt pin failed */
8489
8490 return 1; /* return error */
8491 }
8492
8493 return 0; /* success return 0 */
8494 }
8495
8507 uint8_t mpu9250_get_interrupt_latch(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
8508 {
8509 uint8_t res;
8510 uint8_t prev;
8511
8512 if (handle == NULL) /* check handle */
8513 {
8514 return 2; /* return error */
8515 }
8516 if (handle->inited != 1) /* check handle initialization */
8517 {
8518 return 3; /* return error */
8519 }
8520
8521 res = a_mpu9250_read(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
8522 if (res != 0) /* check result */
8523 {
8524 handle->debug_print("mpu9250: read interrupt pin failed.\n"); /* read interrupt pin failed */
8525
8526 return 1; /* return error */
8527 }
8528 *enable = (mpu9250_bool_t)(!((prev >> 5) & 0x01)); /* get the bool */
8529
8530 return 0; /* success return 0 */
8531 }
8532
8544 uint8_t mpu9250_set_interrupt_read_clear(mpu9250_handle_t *handle, mpu9250_bool_t enable)
8545 {
8546 uint8_t res;
8547 uint8_t prev;
8548
8549 if (handle == NULL) /* check handle */
8550 {
8551 return 2; /* return error */
8552 }
8553 if (handle->inited != 1) /* check handle initialization */
8554 {
8555 return 3; /* return error */
8556 }
8557
8558 res = a_mpu9250_read(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
8559 if (res != 0) /* check result */
8560 {
8561 handle->debug_print("mpu9250: read interrupt pin failed.\n"); /* read interrupt pin failed */
8562
8563 return 1; /* return error */
8564 }
8565 prev &= ~(1 << 4); /* clear config */
8566 prev |= enable << 4; /* set config */
8567 res = a_mpu9250_write(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
8568 if (res != 0) /* check result */
8569 {
8570 handle->debug_print("mpu9250: write interrupt pin failed.\n"); /* write interrupt pin failed */
8571
8572 return 1; /* return error */
8573 }
8574
8575 return 0; /* success return 0 */
8576 }
8577
8589 uint8_t mpu9250_get_interrupt_read_clear(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
8590 {
8591 uint8_t res;
8592 uint8_t prev;
8593
8594 if (handle == NULL) /* check handle */
8595 {
8596 return 2; /* return error */
8597 }
8598 if (handle->inited != 1) /* check handle initialization */
8599 {
8600 return 3; /* return error */
8601 }
8602
8603 res = a_mpu9250_read(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
8604 if (res != 0) /* check result */
8605 {
8606 handle->debug_print("mpu9250: read interrupt pin failed.\n"); /* read interrupt pin failed */
8607
8608 return 1; /* return error */
8609 }
8610 *enable = (mpu9250_bool_t)((prev >> 4) & 0x01); /* get the bool */
8611
8612 return 0; /* success return 0 */
8613 }
8614
8626 uint8_t mpu9250_set_fsync_interrupt_level(mpu9250_handle_t *handle, mpu9250_pin_level_t level)
8627 {
8628 uint8_t res;
8629 uint8_t prev;
8630
8631 if (handle == NULL) /* check handle */
8632 {
8633 return 2; /* return error */
8634 }
8635 if (handle->inited != 1) /* check handle initialization */
8636 {
8637 return 3; /* return error */
8638 }
8639
8640 res = a_mpu9250_read(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
8641 if (res != 0) /* check result */
8642 {
8643 handle->debug_print("mpu9250: read interrupt pin failed.\n"); /* read interrupt pin failed */
8644
8645 return 1; /* return error */
8646 }
8647 prev &= ~(1 << 3); /* clear config */
8648 prev |= level << 3; /* set config */
8649 res = a_mpu9250_write(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
8650 if (res != 0) /* check result */
8651 {
8652 handle->debug_print("mpu9250: write interrupt pin failed.\n"); /* write interrupt pin failed */
8653
8654 return 1; /* return error */
8655 }
8656
8657 return 0; /* success return 0 */
8658 }
8659
8671 uint8_t mpu9250_get_fsync_interrupt_level(mpu9250_handle_t *handle, mpu9250_pin_level_t *level)
8672 {
8673 uint8_t res;
8674 uint8_t prev;
8675
8676 if (handle == NULL) /* check handle */
8677 {
8678 return 2; /* return error */
8679 }
8680 if (handle->inited != 1) /* check handle initialization */
8681 {
8682 return 3; /* return error */
8683 }
8684
8685 res = a_mpu9250_read(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
8686 if (res != 0) /* check result */
8687 {
8688 handle->debug_print("mpu9250: read interrupt pin failed.\n"); /* read interrupt pin failed */
8689
8690 return 1; /* return error */
8691 }
8692 *level = (mpu9250_pin_level_t)((prev >> 3) & 0x01); /* get the level */
8693
8694 return 0; /* success return 0 */
8695 }
8696
8708 uint8_t mpu9250_set_fsync_interrupt(mpu9250_handle_t *handle, mpu9250_bool_t enable)
8709 {
8710 uint8_t res;
8711 uint8_t prev;
8712
8713 if (handle == NULL) /* check handle */
8714 {
8715 return 2; /* return error */
8716 }
8717 if (handle->inited != 1) /* check handle initialization */
8718 {
8719 return 3; /* return error */
8720 }
8721
8722 res = a_mpu9250_read(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
8723 if (res != 0) /* check result */
8724 {
8725 handle->debug_print("mpu9250: read interrupt pin failed.\n"); /* read interrupt pin failed */
8726
8727 return 1; /* return error */
8728 }
8729 prev &= ~(1 << 2); /* clear config */
8730 prev |= enable << 2; /* set config */
8731 res = a_mpu9250_write(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
8732 if (res != 0) /* check result */
8733 {
8734 handle->debug_print("mpu9250: write interrupt pin failed.\n"); /* write interrupt pin failed */
8735
8736 return 1; /* return error */
8737 }
8738
8739 return 0; /* success return 0 */
8740 }
8741
8753 uint8_t mpu9250_get_fsync_interrupt(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
8754 {
8755 uint8_t res;
8756 uint8_t prev;
8757
8758 if (handle == NULL) /* check handle */
8759 {
8760 return 2; /* return error */
8761 }
8762 if (handle->inited != 1) /* check handle initialization */
8763 {
8764 return 3; /* return error */
8765 }
8766
8767 res = a_mpu9250_read(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
8768 if (res != 0) /* check result */
8769 {
8770 handle->debug_print("mpu9250: read interrupt pin failed.\n"); /* read interrupt pin failed */
8771
8772 return 1; /* return error */
8773 }
8774 *enable = (mpu9250_bool_t)((prev >> 2) & 0x01); /* get the bool */
8775
8776 return 0; /* success return 0 */
8777 }
8778
8790 uint8_t mpu9250_set_iic_bypass(mpu9250_handle_t *handle, mpu9250_bool_t enable)
8791 {
8792 uint8_t res;
8793 uint8_t prev;
8794
8795 if (handle == NULL) /* check handle */
8796 {
8797 return 2; /* return error */
8798 }
8799 if (handle->inited != 1) /* check handle initialization */
8800 {
8801 return 3; /* return error */
8802 }
8803
8804 res = a_mpu9250_read(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin */
8805 if (res != 0) /* check result */
8806 {
8807 handle->debug_print("mpu9250: read interrupt pin failed.\n"); /* read interrupt pin failed */
8808
8809 return 1; /* return error */
8810 }
8811 prev &= ~(1 << 1); /* clear config */
8812 prev |= enable << 1; /* set config */
8813 res = a_mpu9250_write(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
8814 if (res != 0) /* check result */
8815 {
8816 handle->debug_print("mpu9250: write interrupt pin failed.\n"); /* write interrupt pin failed */
8817
8818 return 1; /* return error */
8819 }
8820
8821 return 0; /* success return 0 */
8822 }
8823
8835 uint8_t mpu9250_get_iic_bypass(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
8836 {
8837 uint8_t res;
8838 uint8_t prev;
8839
8840 if (handle == NULL) /* check handle */
8841 {
8842 return 2; /* return error */
8843 }
8844 if (handle->inited != 1) /* check handle initialization */
8845 {
8846 return 3; /* return error */
8847 }
8848
8849 res = a_mpu9250_read(handle, MPU9250_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin */
8850 if (res != 0) /* check result */
8851 {
8852 handle->debug_print("mpu9250: read interrupt pin failed.\n"); /* read interrupt pin failed */
8853
8854 return 1; /* return error */
8855 }
8856 *enable = (mpu9250_bool_t)((prev >> 1) & 0x01); /* get the bool */
8857
8858 return 0; /* success return 0 */
8859 }
8860
8873 uint8_t mpu9250_set_interrupt(mpu9250_handle_t *handle, mpu9250_interrupt_t type, mpu9250_bool_t enable)
8874 {
8875 uint8_t res;
8876 uint8_t prev;
8877
8878 if (handle == NULL) /* check handle */
8879 {
8880 return 2; /* return error */
8881 }
8882 if (handle->inited != 1) /* check handle initialization */
8883 {
8884 return 3; /* return error */
8885 }
8886
8887 res = a_mpu9250_read(handle, MPU9250_REG_INT_ENABLE, (uint8_t *)&prev, 1); /* read interrupt enable */
8888 if (res != 0) /* check result */
8889 {
8890 handle->debug_print("mpu9250: read interrupt enable failed.\n"); /* read interrupt enable failed */
8891
8892 return 1; /* return error */
8893 }
8894 prev &= ~(1 << type); /* clear config */
8895 prev |= enable << type; /* set config */
8896 res = a_mpu9250_write(handle, MPU9250_REG_INT_ENABLE, (uint8_t *)&prev, 1); /* write interrupt enable */
8897 if (res != 0) /* check result */
8898 {
8899 handle->debug_print("mpu9250: write interrupt enable failed.\n"); /* write interrupt enable failed */
8900
8901 return 1; /* return error */
8902 }
8903
8904 return 0; /* success return 0 */
8905 }
8906
8919 uint8_t mpu9250_get_interrupt(mpu9250_handle_t *handle, mpu9250_interrupt_t type, mpu9250_bool_t *enable)
8920 {
8921 uint8_t res;
8922 uint8_t prev;
8923
8924 if (handle == NULL) /* check handle */
8925 {
8926 return 2; /* return error */
8927 }
8928 if (handle->inited != 1) /* check handle initialization */
8929 {
8930 return 3; /* return error */
8931 }
8932
8933 res = a_mpu9250_read(handle, MPU9250_REG_INT_ENABLE, (uint8_t *)&prev, 1); /* read interrupt enable */
8934 if (res != 0) /* check result */
8935 {
8936 handle->debug_print("mpu9250: read interrupt enable failed.\n"); /* read interrupt enable failed */
8937
8938 return 1; /* return error */
8939 }
8940 *enable = (mpu9250_bool_t)((prev >> type) & 0x01); /* get the bool */
8941
8942 return 0; /* success return 0 */
8943 }
8944
8956 uint8_t mpu9250_get_interrupt_status(mpu9250_handle_t *handle, uint8_t *status)
8957 {
8958 uint8_t res;
8959
8960 if (handle == NULL) /* check handle */
8961 {
8962 return 2; /* return error */
8963 }
8964 if (handle->inited != 1) /* check handle initialization */
8965 {
8966 return 3; /* return error */
8967 }
8968
8969 res = a_mpu9250_read(handle, MPU9250_REG_INT_STATUS, (uint8_t *)status, 1); /* read interrupt status */
8970 if (res != 0) /* check result */
8971 {
8972 handle->debug_print("mpu9250: read interrupt status failed.\n"); /* read interrupt status failed */
8973
8974 return 1; /* return error */
8975 }
8976
8977 return 0; /* success return 0 */
8978 }
8979
8991 uint8_t mpu9250_set_gyroscope_x_test(mpu9250_handle_t *handle, uint8_t data)
8992 {
8993 uint8_t res;
8994
8995 if (handle == NULL) /* check handle */
8996 {
8997 return 2; /* return error */
8998 }
8999 if (handle->inited != 1) /* check handle initialization */
9000 {
9001 return 3; /* return error */
9002 }
9003
9004 res = a_mpu9250_write(handle, MPU9250_REG_SELF_TEST_X_GYRO, (uint8_t *)&data, 1); /* write self test x */
9005 if (res != 0) /* check result */
9006 {
9007 handle->debug_print("mpu9250: write self test x failed.\n"); /* write self test x failed */
9008
9009 return 1; /* return error */
9010 }
9011
9012 return 0; /* success return 0 */
9013 }
9014
9026 uint8_t mpu9250_get_gyroscope_x_test(mpu9250_handle_t *handle, uint8_t *data)
9027 {
9028 uint8_t res;
9029
9030 if (handle == NULL) /* check handle */
9031 {
9032 return 2; /* return error */
9033 }
9034 if (handle->inited != 1) /* check handle initialization */
9035 {
9036 return 3; /* return error */
9037 }
9038
9039 res = a_mpu9250_read(handle, MPU9250_REG_SELF_TEST_X_GYRO, (uint8_t *)data, 1); /* read self test x */
9040 if (res != 0) /* check result */
9041 {
9042 handle->debug_print("mpu9250: read self test x failed.\n"); /* read self test x failed */
9043
9044 return 1; /* return error */
9045 }
9046
9047 return 0; /* success return 0 */
9048 }
9049
9061 uint8_t mpu9250_set_gyroscope_y_test(mpu9250_handle_t *handle, uint8_t data)
9062 {
9063 uint8_t res;
9064
9065 if (handle == NULL) /* check handle */
9066 {
9067 return 2; /* return error */
9068 }
9069 if (handle->inited != 1) /* check handle initialization */
9070 {
9071 return 3; /* return error */
9072 }
9073
9074 res = a_mpu9250_write(handle, MPU9250_REG_SELF_TEST_Y_GYRO, (uint8_t *)&data, 1); /* write self test y */
9075 if (res != 0) /* check result */
9076 {
9077 handle->debug_print("mpu9250: write self test y failed.\n"); /* write self test y failed */
9078
9079 return 1; /* return error */
9080 }
9081
9082 return 0; /* success return 0 */
9083 }
9084
9096 uint8_t mpu9250_get_gyroscope_y_test(mpu9250_handle_t *handle, uint8_t *data)
9097 {
9098 uint8_t res;
9099
9100 if (handle == NULL) /* check handle */
9101 {
9102 return 2; /* return error */
9103 }
9104 if (handle->inited != 1) /* check handle initialization */
9105 {
9106 return 3; /* return error */
9107 }
9108
9109 res = a_mpu9250_read(handle, MPU9250_REG_SELF_TEST_Y_GYRO, (uint8_t *)data, 1); /* read self test y */
9110 if (res != 0) /* check result */
9111 {
9112 handle->debug_print("mpu9250: read self test y failed.\n"); /* read self test y failed */
9113
9114 return 1; /* return error */
9115 }
9116
9117 return 0; /* success return 0 */
9118 }
9119
9131 uint8_t mpu9250_set_gyroscope_z_test(mpu9250_handle_t *handle, uint8_t data)
9132 {
9133 uint8_t res;
9134
9135 if (handle == NULL) /* check handle */
9136 {
9137 return 2; /* return error */
9138 }
9139 if (handle->inited != 1) /* check handle initialization */
9140 {
9141 return 3; /* return error */
9142 }
9143
9144 res = a_mpu9250_write(handle, MPU9250_REG_SELF_TEST_Z_GYRO, (uint8_t *)&data, 1); /* write self test z */
9145 if (res != 0) /* check result */
9146 {
9147 handle->debug_print("mpu9250: write self test z failed.\n"); /* write self test z failed */
9148
9149 return 1; /* return error */
9150 }
9151
9152 return 0; /* success return 0 */
9153 }
9154
9166 uint8_t mpu9250_get_gyroscope_z_test(mpu9250_handle_t *handle, uint8_t *data)
9167 {
9168 uint8_t res;
9169
9170 if (handle == NULL) /* check handle */
9171 {
9172 return 2; /* return error */
9173 }
9174 if (handle->inited != 1) /* check handle initialization */
9175 {
9176 return 3; /* return error */
9177 }
9178
9179 res = a_mpu9250_read(handle, MPU9250_REG_SELF_TEST_Z_GYRO, (uint8_t *)data, 1); /* read self test z */
9180 if (res != 0) /* check result */
9181 {
9182 handle->debug_print("mpu9250: read self test z failed.\n"); /* read self test z failed */
9183
9184 return 1; /* return error */
9185 }
9186
9187 return 0; /* success return 0 */
9188 }
9189
9201 uint8_t mpu9250_set_accelerometer_x_test(mpu9250_handle_t *handle, uint8_t data)
9202 {
9203 uint8_t res;
9204
9205 if (handle == NULL) /* check handle */
9206 {
9207 return 2; /* return error */
9208 }
9209 if (handle->inited != 1) /* check handle initialization */
9210 {
9211 return 3; /* return error */
9212 }
9213
9214 res = a_mpu9250_write(handle, MPU9250_REG_SELF_TEST_X_ACCEL, (uint8_t *)&data, 1); /* write self test x */
9215 if (res != 0) /* check result */
9216 {
9217 handle->debug_print("mpu9250: write self test x failed.\n"); /* write self test x failed */
9218
9219 return 1; /* return error */
9220 }
9221
9222 return 0; /* success return 0 */
9223 }
9224
9236 uint8_t mpu9250_get_accelerometer_x_test(mpu9250_handle_t *handle, uint8_t *data)
9237 {
9238 uint8_t res;
9239
9240 if (handle == NULL) /* check handle */
9241 {
9242 return 2; /* return error */
9243 }
9244 if (handle->inited != 1) /* check handle initialization */
9245 {
9246 return 3; /* return error */
9247 }
9248
9249 res = a_mpu9250_read(handle, MPU9250_REG_SELF_TEST_X_ACCEL, (uint8_t *)data, 1); /* read self test x */
9250 if (res != 0) /* check result */
9251 {
9252 handle->debug_print("mpu9250: read self test x failed.\n"); /* read self test x failed */
9253
9254 return 1; /* return error */
9255 }
9256
9257 return 0; /* success return 0 */
9258 }
9259
9271 uint8_t mpu9250_set_accelerometer_y_test(mpu9250_handle_t *handle, uint8_t data)
9272 {
9273 uint8_t res;
9274
9275 if (handle == NULL) /* check handle */
9276 {
9277 return 2; /* return error */
9278 }
9279 if (handle->inited != 1) /* check handle initialization */
9280 {
9281 return 3; /* return error */
9282 }
9283
9284 res = a_mpu9250_write(handle, MPU9250_REG_SELF_TEST_Y_ACCEL, (uint8_t *)&data, 1); /* write self test y */
9285 if (res != 0) /* check result */
9286 {
9287 handle->debug_print("mpu9250: write self test y failed.\n"); /* write self test y failed */
9288
9289 return 1; /* return error */
9290 }
9291
9292 return 0; /* success return 0 */
9293 }
9294
9306 uint8_t mpu9250_get_accelerometer_y_test(mpu9250_handle_t *handle, uint8_t *data)
9307 {
9308 uint8_t res;
9309
9310 if (handle == NULL) /* check handle */
9311 {
9312 return 2; /* return error */
9313 }
9314 if (handle->inited != 1) /* check handle initialization */
9315 {
9316 return 3; /* return error */
9317 }
9318
9319 res = a_mpu9250_read(handle, MPU9250_REG_SELF_TEST_Y_ACCEL, (uint8_t *)data, 1); /* read self test y */
9320 if (res != 0) /* check result */
9321 {
9322 handle->debug_print("mpu9250: read self test y failed.\n"); /* read self test y failed */
9323
9324 return 1; /* return error */
9325 }
9326
9327 return 0; /* success return 0 */
9328 }
9329
9341 uint8_t mpu9250_set_accelerometer_z_test(mpu9250_handle_t *handle, uint8_t data)
9342 {
9343 uint8_t res;
9344
9345 if (handle == NULL) /* check handle */
9346 {
9347 return 2; /* return error */
9348 }
9349 if (handle->inited != 1) /* check handle initialization */
9350 {
9351 return 3; /* return error */
9352 }
9353
9354 res = a_mpu9250_write(handle, MPU9250_REG_SELF_TEST_Z_ACCEL, (uint8_t *)&data, 1); /* write self test z */
9355 if (res != 0) /* check result */
9356 {
9357 handle->debug_print("mpu9250: write self test z failed.\n"); /* write self test z failed */
9358
9359 return 1; /* return error */
9360 }
9361
9362 return 0; /* success return 0 */
9363 }
9364
9376 uint8_t mpu9250_get_accelerometer_z_test(mpu9250_handle_t *handle, uint8_t *data)
9377 {
9378 uint8_t res;
9379
9380 if (handle == NULL) /* check handle */
9381 {
9382 return 2; /* return error */
9383 }
9384 if (handle->inited != 1) /* check handle initialization */
9385 {
9386 return 3; /* return error */
9387 }
9388
9389 res = a_mpu9250_read(handle, MPU9250_REG_SELF_TEST_Z_ACCEL, (uint8_t *)data, 1); /* read self test z */
9390 if (res != 0) /* check result */
9391 {
9392 handle->debug_print("mpu9250: read self test z failed.\n"); /* read self test z failed */
9393
9394 return 1; /* return error */
9395 }
9396
9397 return 0; /* success return 0 */
9398 }
9399
9411 uint8_t mpu9250_set_accelerometer_x_offset(mpu9250_handle_t *handle, int16_t offset)
9412 {
9413 uint8_t res;
9414 uint8_t buf[2];
9415
9416 if (handle == NULL) /* check handle */
9417 {
9418 return 2; /* return error */
9419 }
9420 if (handle->inited != 1) /* check handle initialization */
9421 {
9422 return 3; /* return error */
9423 }
9424
9425 buf[0] = (offset >> 8) & 0xFF; /* set high */
9426 buf[1] = (offset >> 0) & 0xFF; /* set low */
9427 res = a_mpu9250_write(handle, MPU9250_REG_XA_OFFSET_H, buf, 2); /* write xa offset */
9428 if (res != 0) /* check result */
9429 {
9430 handle->debug_print("mpu9250: write xa offset failed.\n"); /* write xa offset failed*/
9431
9432 return 1; /* return error */
9433 }
9434
9435 return 0; /* success return 0 */
9436 }
9437
9449 uint8_t mpu9250_get_accelerometer_x_offset(mpu9250_handle_t *handle, int16_t *offset)
9450 {
9451 uint8_t res;
9452 uint8_t buf[2];
9453
9454 if (handle == NULL) /* check handle */
9455 {
9456 return 2; /* return error */
9457 }
9458 if (handle->inited != 1) /* check handle initialization */
9459 {
9460 return 3; /* return error */
9461 }
9462
9463 res = a_mpu9250_read(handle, MPU9250_REG_XA_OFFSET_H, buf, 2); /* read xa offset */
9464 if (res != 0) /* check result */
9465 {
9466 handle->debug_print("mpu9250: read xa offset failed.\n"); /* read xa offset failed*/
9467
9468 return 1; /* return error */
9469 }
9470 *offset = (int16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set the offset */
9471
9472 return 0; /* success return 0 */
9473 }
9474
9486 uint8_t mpu9250_set_accelerometer_y_offset(mpu9250_handle_t *handle, int16_t offset)
9487 {
9488 uint8_t res;
9489 uint8_t buf[2];
9490
9491 if (handle == NULL) /* check handle */
9492 {
9493 return 2; /* return error */
9494 }
9495 if (handle->inited != 1) /* check handle initialization */
9496 {
9497 return 3; /* return error */
9498 }
9499
9500 buf[0] = (offset >> 8) & 0xFF; /* set high */
9501 buf[1] = (offset >> 0) & 0xFF; /* set low */
9502 res = a_mpu9250_write(handle, MPU9250_REG_YA_OFFSET_H, buf, 2); /* write ya offset */
9503 if (res != 0) /* check result */
9504 {
9505 handle->debug_print("mpu9250: write ya offset failed.\n"); /* write ya offset failed*/
9506
9507 return 1; /* return error */
9508 }
9509
9510 return 0; /* success return 0 */
9511 }
9512
9524 uint8_t mpu9250_get_accelerometer_y_offset(mpu9250_handle_t *handle, int16_t *offset)
9525 {
9526 uint8_t res;
9527 uint8_t buf[2];
9528
9529 if (handle == NULL) /* check handle */
9530 {
9531 return 2; /* return error */
9532 }
9533 if (handle->inited != 1) /* check handle initialization */
9534 {
9535 return 3; /* return error */
9536 }
9537
9538 res = a_mpu9250_read(handle, MPU9250_REG_YA_OFFSET_H, buf, 2); /* read ya offset */
9539 if (res != 0) /* check result */
9540 {
9541 handle->debug_print("mpu9250: read ya offset failed.\n"); /* read ya offset failed*/
9542
9543 return 1; /* return error */
9544 }
9545 *offset = (int16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set the offset */
9546
9547 return 0; /* success return 0 */
9548 }
9549
9561 uint8_t mpu9250_set_accelerometer_z_offset(mpu9250_handle_t *handle, int16_t offset)
9562 {
9563 uint8_t res;
9564 uint8_t buf[2];
9565
9566 if (handle == NULL) /* check handle */
9567 {
9568 return 2; /* return error */
9569 }
9570 if (handle->inited != 1) /* check handle initialization */
9571 {
9572 return 3; /* return error */
9573 }
9574
9575 buf[0] = (offset >> 8) & 0xFF; /* set high */
9576 buf[1] = (offset >> 0) & 0xFF; /* set low */
9577 res = a_mpu9250_write(handle, MPU9250_REG_ZA_OFFSET_H, buf, 2); /* write za offset */
9578 if (res != 0) /* check result */
9579 {
9580 handle->debug_print("mpu9250: write za offset failed.\n"); /* write za offset failed*/
9581
9582 return 1; /* return error */
9583 }
9584
9585 return 0; /* success return 0 */
9586 }
9587
9599 uint8_t mpu9250_get_accelerometer_z_offset(mpu9250_handle_t *handle, int16_t *offset)
9600 {
9601 uint8_t res;
9602 uint8_t buf[2];
9603
9604 if (handle == NULL) /* check handle */
9605 {
9606 return 2; /* return error */
9607 }
9608 if (handle->inited != 1) /* check handle initialization */
9609 {
9610 return 3; /* return error */
9611 }
9612
9613 res = a_mpu9250_read(handle, MPU9250_REG_ZA_OFFSET_H, buf, 2); /* read za offset */
9614 if (res != 0) /* check result */
9615 {
9616 handle->debug_print("mpu9250: read za offset failed.\n"); /* read za offset failed*/
9617
9618 return 1; /* return error */
9619 }
9620 *offset = (int16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set the offset */
9621
9622 return 0; /* success return 0 */
9623 }
9624
9636 uint8_t mpu9250_accelerometer_offset_convert_to_register(mpu9250_handle_t *handle, float mg, int16_t *reg)
9637 {
9638 if (handle == NULL) /* check handle */
9639 {
9640 return 2; /* return error */
9641 }
9642 if (handle->inited != 1) /* check handle initialization */
9643 {
9644 return 3; /* return error */
9645 }
9646
9647 *reg = (int16_t)(mg / 0.98f); /* convert real data to register data */
9648
9649 return 0; /* success return 0 */
9650 }
9651
9663 uint8_t mpu9250_accelerometer_offset_convert_to_data(mpu9250_handle_t *handle, int16_t reg, float *mg)
9664 {
9665 if (handle == NULL) /* check handle */
9666 {
9667 return 2; /* return error */
9668 }
9669 if (handle->inited != 1) /* check handle initialization */
9670 {
9671 return 3; /* return error */
9672 }
9673
9674 *mg = (float)(reg) * 0.98f; /* convert raw data to real data */
9675
9676 return 0; /* success return 0 */
9677 }
9678
9690 uint8_t mpu9250_set_gyro_x_offset(mpu9250_handle_t *handle, int16_t offset)
9691 {
9692 uint8_t res;
9693 uint8_t buf[2];
9694
9695 if (handle == NULL) /* check handle */
9696 {
9697 return 2; /* return error */
9698 }
9699 if (handle->inited != 1) /* check handle initialization */
9700 {
9701 return 3; /* return error */
9702 }
9703
9704 buf[0] = (offset >> 8) & 0xFF; /* set high */
9705 buf[1] = (offset >> 0) & 0xFF; /* set low */
9706 res = a_mpu9250_write(handle, MPU9250_REG_XG_OFFSET_H, buf, 2); /* write xg offset */
9707 if (res != 0) /* check result */
9708 {
9709 handle->debug_print("mpu9250: write xg offset failed.\n"); /* write xg offset failed*/
9710
9711 return 1; /* return error */
9712 }
9713
9714 return 0; /* success return 0 */
9715 }
9716
9728 uint8_t mpu9250_get_gyro_x_offset(mpu9250_handle_t *handle, int16_t *offset)
9729 {
9730 uint8_t res;
9731 uint8_t buf[2];
9732
9733 if (handle == NULL) /* check handle */
9734 {
9735 return 2; /* return error */
9736 }
9737 if (handle->inited != 1) /* check handle initialization */
9738 {
9739 return 3; /* return error */
9740 }
9741
9742 res = a_mpu9250_read(handle, MPU9250_REG_XG_OFFSET_H, buf, 2); /* read xg offset */
9743 if (res != 0) /* check result */
9744 {
9745 handle->debug_print("mpu9250: read xg offset failed.\n"); /* read xg offset failed*/
9746
9747 return 1; /* return error */
9748 }
9749 *offset = (int16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set the offset */
9750
9751 return 0; /* success return 0 */
9752 }
9753
9765 uint8_t mpu9250_set_gyro_y_offset(mpu9250_handle_t *handle, int16_t offset)
9766 {
9767 uint8_t res;
9768 uint8_t buf[2];
9769
9770 if (handle == NULL) /* check handle */
9771 {
9772 return 2; /* return error */
9773 }
9774 if (handle->inited != 1) /* check handle initialization */
9775 {
9776 return 3; /* return error */
9777 }
9778
9779 buf[0] = (offset >> 8) & 0xFF; /* set high */
9780 buf[1] = (offset >> 0) & 0xFF; /* set low */
9781 res = a_mpu9250_write(handle, MPU9250_REG_YG_OFFSET_H, buf, 2); /* write yg offset */
9782 if (res != 0) /* check result */
9783 {
9784 handle->debug_print("mpu9250: write yg offset failed.\n"); /* write yg offset failed*/
9785
9786 return 1; /* return error */
9787 }
9788
9789 return 0; /* success return 0 */
9790 }
9791
9803 uint8_t mpu9250_get_gyro_y_offset(mpu9250_handle_t *handle, int16_t *offset)
9804 {
9805 uint8_t res;
9806 uint8_t buf[2];
9807
9808 if (handle == NULL) /* check handle */
9809 {
9810 return 2; /* return error */
9811 }
9812 if (handle->inited != 1) /* check handle initialization */
9813 {
9814 return 3; /* return error */
9815 }
9816
9817 res = a_mpu9250_read(handle, MPU9250_REG_YG_OFFSET_H, buf, 2); /* read yg offset */
9818 if (res != 0) /* check result */
9819 {
9820 handle->debug_print("mpu9250: read yg offset failed.\n"); /* read yg offset failed*/
9821
9822 return 1; /* return error */
9823 }
9824 *offset = (int16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set the offset */
9825
9826 return 0; /* success return 0 */
9827 }
9828
9840 uint8_t mpu9250_set_gyro_z_offset(mpu9250_handle_t *handle, int16_t offset)
9841 {
9842 uint8_t res;
9843 uint8_t buf[2];
9844
9845 if (handle == NULL) /* check handle */
9846 {
9847 return 2; /* return error */
9848 }
9849 if (handle->inited != 1) /* check handle initialization */
9850 {
9851 return 3; /* return error */
9852 }
9853
9854 buf[0] = (offset >> 8) & 0xFF; /* set high */
9855 buf[1] = (offset >> 0) & 0xFF; /* set low */
9856 res = a_mpu9250_write(handle, MPU9250_REG_ZG_OFFSET_H, buf, 2); /* write zg offset */
9857 if (res != 0) /* check result */
9858 {
9859 handle->debug_print("mpu9250: write zg offset failed.\n"); /* write zg offset failed*/
9860
9861 return 1; /* return error */
9862 }
9863
9864 return 0; /* success return 0 */
9865 }
9866
9878 uint8_t mpu9250_get_gyro_z_offset(mpu9250_handle_t *handle, int16_t *offset)
9879 {
9880 uint8_t res;
9881 uint8_t buf[2];
9882
9883 if (handle == NULL) /* check handle */
9884 {
9885 return 2; /* return error */
9886 }
9887 if (handle->inited != 1) /* check handle initialization */
9888 {
9889 return 3; /* return error */
9890 }
9891
9892 res = a_mpu9250_read(handle, MPU9250_REG_ZG_OFFSET_H, buf, 2); /* read zg offset */
9893 if (res != 0) /* check result */
9894 {
9895 handle->debug_print("mpu9250: read zg offset failed.\n"); /* read zg offset failed*/
9896
9897 return 1; /* return error */
9898 }
9899 *offset = (int16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set the offset */
9900
9901 return 0; /* success return 0 */
9902 }
9903
9915 uint8_t mpu9250_gyro_offset_convert_to_register(mpu9250_handle_t *handle, float dps, int16_t *reg)
9916 {
9917 if (handle == NULL) /* check handle */
9918 {
9919 return 2; /* return error */
9920 }
9921 if (handle->inited != 1) /* check handle initialization */
9922 {
9923 return 3; /* return error */
9924 }
9925
9926 *reg = (int16_t)(dps / 0.0305f); /* convert real data to register data */
9927
9928 return 0; /* success return 0 */
9929 }
9930
9942 uint8_t mpu9250_gyro_offset_convert_to_data(mpu9250_handle_t *handle, int16_t reg, float *dps)
9943 {
9944 if (handle == NULL) /* check handle */
9945 {
9946 return 2; /* return error */
9947 }
9948 if (handle->inited != 1) /* check handle initialization */
9949 {
9950 return 3; /* return error */
9951 }
9952
9953 *dps = (float)(reg) * 0.0305f; /* convert raw data to real data */
9954
9955 return 0; /* success return 0 */
9956 }
9957
9969 uint8_t mpu9250_set_motion_threshold(mpu9250_handle_t *handle, uint8_t threshold)
9970 {
9971 uint8_t res;
9972
9973 if (handle == NULL) /* check handle */
9974 {
9975 return 2; /* return error */
9976 }
9977 if (handle->inited != 1) /* check handle initialization */
9978 {
9979 return 3; /* return error */
9980 }
9981
9982 res = a_mpu9250_write(handle, MPU9250_REG_WOM_THR, (uint8_t *)&threshold, 1); /* write motion threshold */
9983 if (res != 0) /* check result */
9984 {
9985 handle->debug_print("mpu9250: write motion threshold failed.\n"); /* write motion threshold failed*/
9986
9987 return 1; /* return error */
9988 }
9989
9990 return 0; /* success return 0 */
9991 }
9992
10004 uint8_t mpu9250_get_motion_threshold(mpu9250_handle_t *handle, uint8_t *threshold)
10005 {
10006 uint8_t res;
10007
10008 if (handle == NULL) /* check handle */
10009 {
10010 return 2; /* return error */
10011 }
10012 if (handle->inited != 1) /* check handle initialization */
10013 {
10014 return 3; /* return error */
10015 }
10016
10017 res = a_mpu9250_read(handle, MPU9250_REG_WOM_THR, (uint8_t *)threshold, 1); /* read motion threshold */
10018 if (res != 0) /* check result */
10019 {
10020 handle->debug_print("mpu9250: read motion threshold failed.\n"); /* read motion threshold failed*/
10021
10022 return 1; /* return error */
10023 }
10024
10025 return 0; /* success return 0 */
10026 }
10027
10039 uint8_t mpu9250_motion_threshold_convert_to_register(mpu9250_handle_t *handle, float mg, uint8_t *reg)
10040 {
10041 if (handle == NULL) /* check handle */
10042 {
10043 return 2; /* return error */
10044 }
10045 if (handle->inited != 1) /* check handle initialization */
10046 {
10047 return 3; /* return error */
10048 }
10049
10050 *reg = (uint8_t)(mg / 4.0f); /* convert real data to register data */
10051
10052 return 0; /* success return 0 */
10053 }
10054
10066 uint8_t mpu9250_motion_threshold_convert_to_data(mpu9250_handle_t *handle, uint8_t reg, float *mg)
10067 {
10068 if (handle == NULL) /* check handle */
10069 {
10070 return 2; /* return error */
10071 }
10072 if (handle->inited != 1) /* check handle initialization */
10073 {
10074 return 3; /* return error */
10075 }
10076
10077 *mg = (float)(reg) * 4.0f; /* convert raw data to real data */
10078
10079 return 0; /* success return 0 */
10080 }
10081
10094 uint8_t mpu9250_self_test(mpu9250_handle_t *handle, int32_t gyro_offset_raw[3], int32_t accel_offset_raw[3])
10095 {
10096 uint8_t res;
10097 uint8_t prev;
10098 int32_t gyro_offset_raw_st[3];
10099 int32_t accel_offset_raw_st[3];
10100
10101 if (handle == NULL) /* check handle */
10102 {
10103 return 2; /* return error */
10104 }
10105 if (handle->inited != 1) /* check handle initialization */
10106 {
10107 return 3; /* return error */
10108 }
10109
10110 res = a_mpu9250_get_st_biases(handle, gyro_offset_raw, accel_offset_raw, 0); /* get st biases */
10111 if (res != 0) /* check result */
10112 {
10113 handle->debug_print("mpu9250: get st biases failed.\n"); /* get st biases failed */
10114
10115 return 1; /* return error */
10116 }
10117 res = a_mpu9250_get_st_biases(handle, gyro_offset_raw_st, accel_offset_raw_st, 1); /* get st biases */
10118 if (res != 0) /* check result */
10119 {
10120 handle->debug_print("mpu9250: get st biases failed.\n"); /* get st biases failed */
10121
10122 return 1; /* return error */
10123 }
10124 res = a_mpu9250_accel_self_test(handle, accel_offset_raw, accel_offset_raw_st); /* accel self test */
10125 if (res != 0) /* check result */
10126 {
10127 handle->debug_print("mpu9250: accel self test failed.\n"); /* accel self test failed */
10128
10129 return 1; /* return error */
10130 }
10131 res = a_mpu9250_gyro_self_test(handle, gyro_offset_raw, gyro_offset_raw_st); /* gyro self test */
10132 if (res != 0) /* check result */
10133 {
10134 handle->debug_print("mpu9250: gyro self test failed.\n"); /* gyro self test failed */
10135
10136 return 1; /* return error */
10137 }
10138
10139 prev = 1 << 7; /* reset the device */
10140 res = a_mpu9250_write(handle, MPU9250_REG_PWR_MGMT_1, &prev, 1); /* write pwr mgmt 1 */
10141 if (res != 0) /* check the result */
10142 {
10143 handle->debug_print("mpu9250: write pwr mgmt 1 failed.\n"); /* write pwr mgmt 1 failed */
10144
10145 return 1; /* return error */
10146 }
10147 handle->delay_ms(100); /* delay 100ms */
10148 res = a_mpu9250_read(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
10149 if (res != 0) /* check result */
10150 {
10151 handle->debug_print("mpu9250: read power management 1 failed.\n"); /* read power management 1 failed */
10152
10153 return 1; /* return error */
10154 }
10155 prev &= ~(1 << 6); /* clear config */
10156 res = a_mpu9250_write(handle, MPU9250_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
10157 if (res != 0) /* check result */
10158 {
10159 handle->debug_print("mpu9250: write power management 1 failed.\n"); /* write power management 1 failed */
10160
10161 return 1; /* return error */
10162 }
10163
10164 return 0; /* success return 0 */
10165 }
10166
10178 uint8_t mpu9250_set_iic_clock(mpu9250_handle_t *handle, mpu9250_iic_clock_t clk)
10179 {
10180 uint8_t res;
10181 uint8_t prev;
10182
10183 if (handle == NULL) /* check handle */
10184 {
10185 return 2; /* return error */
10186 }
10187 if (handle->inited != 1) /* check handle initialization */
10188 {
10189 return 3; /* return error */
10190 }
10191
10192 res = a_mpu9250_read(handle, MPU9250_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
10193 if (res != 0) /* check result */
10194 {
10195 handle->debug_print("mpu9250: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
10196
10197 return 1; /* return error */
10198 }
10199 prev &= ~0xF; /* clear the buffer */
10200 prev |= clk; /* set the clock */
10201 res = a_mpu9250_write(handle, MPU9250_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* write i2c mst ctrl */
10202 if (res != 0) /* check result */
10203 {
10204 handle->debug_print("mpu9250: write i2c mst ctrl failed.\n"); /* write i2c mst ctrl failed */
10205
10206 return 1; /* return error */
10207 }
10208
10209 return 0; /* success return 0 */
10210 }
10211
10223 uint8_t mpu9250_get_iic_clock(mpu9250_handle_t *handle, mpu9250_iic_clock_t *clk)
10224 {
10225 uint8_t res;
10226 uint8_t prev;
10227
10228 if (handle == NULL) /* check handle */
10229 {
10230 return 2; /* return error */
10231 }
10232 if (handle->inited != 1) /* check handle initialization */
10233 {
10234 return 3; /* return error */
10235 }
10236
10237 res = a_mpu9250_read(handle, MPU9250_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
10238 if (res != 0) /* check result */
10239 {
10240 handle->debug_print("mpu9250: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
10241
10242 return 1; /* return error */
10243 }
10244 *clk = (mpu9250_iic_clock_t)(prev & 0x0F); /* get the clock */
10245
10246 return 0; /* success return 0 */
10247 }
10248
10260 uint8_t mpu9250_set_iic_multi_master(mpu9250_handle_t *handle, mpu9250_bool_t enable)
10261 {
10262 uint8_t res;
10263 uint8_t prev;
10264
10265 if (handle == NULL) /* check handle */
10266 {
10267 return 2; /* return error */
10268 }
10269 if (handle->inited != 1) /* check handle initialization */
10270 {
10271 return 3; /* return error */
10272 }
10273
10274 res = a_mpu9250_read(handle, MPU9250_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
10275 if (res != 0) /* check result */
10276 {
10277 handle->debug_print("mpu9250: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
10278
10279 return 1; /* return error */
10280 }
10281 prev &= ~(1 << 7); /* clear the settings */
10282 prev |= enable << 7; /* set the bool */
10283 res = a_mpu9250_write(handle, MPU9250_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* write i2c mst ctrl */
10284 if (res != 0) /* check result */
10285 {
10286 handle->debug_print("mpu9250: write i2c mst ctrl failed.\n"); /* write i2c mst ctrl failed */
10287
10288 return 1; /* return error */
10289 }
10290
10291 return 0; /* success return 0 */
10292 }
10293
10305 uint8_t mpu9250_get_iic_multi_master(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
10306 {
10307 uint8_t res;
10308 uint8_t prev;
10309
10310 if (handle == NULL) /* check handle */
10311 {
10312 return 2; /* return error */
10313 }
10314 if (handle->inited != 1) /* check handle initialization */
10315 {
10316 return 3; /* return error */
10317 }
10318
10319 res = a_mpu9250_read(handle, MPU9250_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
10320 if (res != 0) /* check result */
10321 {
10322 handle->debug_print("mpu9250: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
10323
10324 return 1; /* return error */
10325 }
10326 *enable = (mpu9250_bool_t)((prev >> 7) & 0x1); /* get the bool */
10327
10328 return 0; /* success return 0 */
10329 }
10330
10342 uint8_t mpu9250_set_iic_wait_for_external_sensor(mpu9250_handle_t *handle, mpu9250_bool_t enable)
10343 {
10344 uint8_t res;
10345 uint8_t prev;
10346
10347 if (handle == NULL) /* check handle */
10348 {
10349 return 2; /* return error */
10350 }
10351 if (handle->inited != 1) /* check handle initialization */
10352 {
10353 return 3; /* return error */
10354 }
10355
10356 res = a_mpu9250_read(handle, MPU9250_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
10357 if (res != 0) /* check result */
10358 {
10359 handle->debug_print("mpu9250: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
10360
10361 return 1; /* return error */
10362 }
10363 prev &= ~(1 << 6); /* clear the settings */
10364 prev |= enable << 6; /* set the bool */
10365 res = a_mpu9250_write(handle, MPU9250_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* write i2c mst ctrl */
10366 if (res != 0) /* check result */
10367 {
10368 handle->debug_print("mpu9250: write i2c mst ctrl failed.\n"); /* write i2c mst ctrl failed */
10369
10370 return 1; /* return error */
10371 }
10372
10373 return 0; /* success return 0 */
10374 }
10375
10387 uint8_t mpu9250_get_iic_wait_for_external_sensor(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
10388 {
10389 uint8_t res;
10390 uint8_t prev;
10391
10392 if (handle == NULL) /* check handle */
10393 {
10394 return 2; /* return error */
10395 }
10396 if (handle->inited != 1) /* check handle initialization */
10397 {
10398 return 3; /* return error */
10399 }
10400
10401 res = a_mpu9250_read(handle, MPU9250_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
10402 if (res != 0) /* check result */
10403 {
10404 handle->debug_print("mpu9250: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
10405
10406 return 1; /* return error */
10407 }
10408 *enable = (mpu9250_bool_t)((prev >> 6) & 0x1); /* get the bool */
10409
10410 return 0; /* success return 0 */
10411 }
10412
10424 uint8_t mpu9250_set_iic_read_mode(mpu9250_handle_t *handle, mpu9250_iic_read_mode_t mode)
10425 {
10426 uint8_t res;
10427 uint8_t prev;
10428
10429 if (handle == NULL) /* check handle */
10430 {
10431 return 2; /* return error */
10432 }
10433 if (handle->inited != 1) /* check handle initialization */
10434 {
10435 return 3; /* return error */
10436 }
10437
10438 res = a_mpu9250_read(handle, MPU9250_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
10439 if (res != 0) /* check result */
10440 {
10441 handle->debug_print("mpu9250: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
10442
10443 return 1; /* return error */
10444 }
10445 prev &= ~(1 << 4); /* clear the settings */
10446 prev |= mode << 4; /* set the mode */
10447 res = a_mpu9250_write(handle, MPU9250_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* write i2c mst ctrl */
10448 if (res != 0) /* check result */
10449 {
10450 handle->debug_print("mpu9250: write i2c mst ctrl failed.\n"); /* write i2c mst ctrl failed */
10451
10452 return 1; /* return error */
10453 }
10454
10455 return 0; /* success return 0 */
10456 }
10457
10469 uint8_t mpu9250_get_iic_read_mode(mpu9250_handle_t *handle, mpu9250_iic_read_mode_t *mode)
10470 {
10471 uint8_t res;
10472 uint8_t prev;
10473
10474 if (handle == NULL) /* check handle */
10475 {
10476 return 2; /* return error */
10477 }
10478 if (handle->inited != 1) /* check handle initialization */
10479 {
10480 return 3; /* return error */
10481 }
10482
10483 res = a_mpu9250_read(handle, MPU9250_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
10484 if (res != 0) /* check result */
10485 {
10486 handle->debug_print("mpu9250: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
10487
10488 return 1; /* return error */
10489 }
10490 *mode = (mpu9250_iic_read_mode_t)((prev >> 4) & 0x1); /* get the mode */
10491
10492 return 0; /* success return 0 */
10493 }
10494
10508 uint8_t mpu9250_set_iic_fifo_enable(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_bool_t enable)
10509 {
10510 uint8_t res;
10511 uint8_t prev;
10512
10513 if (handle == NULL) /* check handle */
10514 {
10515 return 2; /* return error */
10516 }
10517 if (handle->inited != 1) /* check handle initialization */
10518 {
10519 return 3; /* return error */
10520 }
10521
10522 if ((slave == MPU9250_IIC_SLAVE_0) ||
10523 (slave == MPU9250_IIC_SLAVE_1) ||
10524 (slave == MPU9250_IIC_SLAVE_2)
10525 ) /* slave0-2 */
10526 {
10527 res = a_mpu9250_read(handle, MPU9250_REG_FIFO_EN, (uint8_t *)&prev, 1); /* read fifo enable */
10528 if (res != 0) /* check result */
10529 {
10530 handle->debug_print("mpu9250: read fifo enable failed.\n"); /* read fifo enable failed */
10531
10532 return 1; /* return error */
10533 }
10534 prev &= ~(1 << slave); /* clear the settings */
10535 prev |= enable << slave; /* set the bool */
10536 res = a_mpu9250_write(handle, MPU9250_REG_FIFO_EN, (uint8_t *)&prev, 1); /* write fifo enable ctrl */
10537 if (res != 0) /* check result */
10538 {
10539 handle->debug_print("mpu9250: write fifo enable failed.\n"); /* write fifo enable failed */
10540
10541 return 1; /* return error */
10542 }
10543 }
10544 else if (slave == MPU9250_IIC_SLAVE_3) /* slave3 */
10545 {
10546 res = a_mpu9250_read(handle, MPU9250_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
10547 if (res != 0) /* check result */
10548 {
10549 handle->debug_print("mpu9250: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
10550
10551 return 1; /* return error */
10552 }
10553 prev &= ~(1 << 5); /* clear the settings */
10554 prev |= enable << 5; /* set the bool */
10555 res = a_mpu9250_write(handle, MPU9250_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* write i2c mst ctrl */
10556 if (res != 0) /* check result */
10557 {
10558 handle->debug_print("mpu9250: write i2c mst ctrl failed.\n"); /* write i2c mst ctrl failed */
10559
10560 return 1; /* return error */
10561 }
10562 }
10563 else
10564 {
10565 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
10566
10567 return 4; /* return error */
10568 }
10569
10570 return 0; /* success return 0 */
10571 }
10572
10586 uint8_t mpu9250_get_iic_fifo_enable(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_bool_t *enable)
10587 {
10588 uint8_t res;
10589 uint8_t prev;
10590
10591 if (handle == NULL) /* check handle */
10592 {
10593 return 2; /* return error */
10594 }
10595 if (handle->inited != 1) /* check handle initialization */
10596 {
10597 return 3; /* return error */
10598 }
10599
10600 if ((slave == MPU9250_IIC_SLAVE_0) ||
10601 (slave == MPU9250_IIC_SLAVE_1) ||
10602 (slave == MPU9250_IIC_SLAVE_2)
10603 ) /* slave0-2 */
10604 {
10605 res = a_mpu9250_read(handle, MPU9250_REG_FIFO_EN, (uint8_t *)&prev, 1); /* read fifo enable */
10606 if (res != 0) /* check result */
10607 {
10608 handle->debug_print("mpu9250: read fifo enable failed.\n"); /* read fifo enable failed */
10609
10610 return 1; /* return error */
10611 }
10612 *enable = (mpu9250_bool_t)((prev >> slave) & 0x1); /* get the bool */
10613 }
10614 else if (slave == MPU9250_IIC_SLAVE_3) /* slave3 */
10615 {
10616 res = a_mpu9250_read(handle, MPU9250_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
10617 if (res != 0) /* check result */
10618 {
10619 handle->debug_print("mpu9250: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
10620
10621 return 1; /* return error */
10622 }
10623 *enable = (mpu9250_bool_t)((prev >> 5) & 0x01); /* get the bool */
10624 }
10625 else
10626 {
10627 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
10628
10629 return 4; /* return error */
10630 }
10631
10632 return 0; /* success return 0 */
10633 }
10634
10648 uint8_t mpu9250_set_iic_mode(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_iic_mode_t mode)
10649 {
10650 uint8_t res;
10651 uint8_t prev;
10652
10653 if (handle == NULL) /* check handle */
10654 {
10655 return 2; /* return error */
10656 }
10657 if (handle->inited != 1) /* check handle initialization */
10658 {
10659 return 3; /* return error */
10660 }
10661
10662 if (slave == MPU9250_IIC_SLAVE_0) /* slave0 */
10663 {
10664 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* read i2c slv0 addr */
10665 if (res != 0) /* check result */
10666 {
10667 handle->debug_print("mpu9250: read i2c slv0 addr failed.\n"); /* read i2c slv0 addr failed */
10668
10669 return 1; /* return error */
10670 }
10671 prev &= ~(1 << 7); /* clear the settings */
10672 prev |= mode << 7; /* set the bool */
10673 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* write i2c slv0 addr */
10674 if (res != 0) /* check result */
10675 {
10676 handle->debug_print("mpu9250: write i2c slv0 addr failed.\n"); /* write i2c slv0 addr failed */
10677
10678 return 1; /* return error */
10679 }
10680 }
10681 else if (slave == MPU9250_IIC_SLAVE_1) /* slave1 */
10682 {
10683 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV1_ADDR, (uint8_t *)&prev, 1); /* read i2c slv1 addr */
10684 if (res != 0) /* check result */
10685 {
10686 handle->debug_print("mpu9250: read i2c slv1 addr failed.\n"); /* read i2c slv1 addr failed */
10687
10688 return 1; /* return error */
10689 }
10690 prev &= ~(1 << 7); /* clear the settings */
10691 prev |= mode << 7; /* set the bool */
10692 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV1_ADDR, (uint8_t *)&prev, 1); /* write i2c slv1 addr */
10693 if (res != 0) /* check result */
10694 {
10695 handle->debug_print("mpu9250: write i2c slv1 addr failed.\n"); /* write i2c slv1 addr failed */
10696
10697 return 1; /* return error */
10698 }
10699 }
10700 else if (slave == MPU9250_IIC_SLAVE_2) /* slave2 */
10701 {
10702 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV2_ADDR, (uint8_t *)&prev, 1); /* read i2c slv2 addr */
10703 if (res != 0) /* check result */
10704 {
10705 handle->debug_print("mpu9250: read i2c slv2 addr failed.\n"); /* read i2c slv2 addr failed */
10706
10707 return 1; /* return error */
10708 }
10709 prev &= ~(1 << 7); /* clear the settings */
10710 prev |= mode << 7; /* set the bool */
10711 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV2_ADDR, (uint8_t *)&prev, 1); /* write i2c slv2 addr */
10712 if (res != 0) /* check result */
10713 {
10714 handle->debug_print("mpu9250: write i2c slv2 addr failed.\n"); /* write i2c slv2 addr failed */
10715
10716 return 1; /* return error */
10717 }
10718 }
10719 else if (slave == MPU9250_IIC_SLAVE_3) /* slave2 */
10720 {
10721 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV3_ADDR, (uint8_t *)&prev, 1); /* read i2c slv3 addr */
10722 if (res != 0) /* check result */
10723 {
10724 handle->debug_print("mpu9250: read i2c slv3 addr failed.\n"); /* read i2c slv3 addr failed */
10725
10726 return 1; /* return error */
10727 }
10728 prev &= ~(1 << 7); /* clear the settings */
10729 prev |= mode << 7; /* set the bool */
10730 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV3_ADDR, (uint8_t *)&prev, 1); /* write i2c slv3 addr */
10731 if (res != 0) /* check result */
10732 {
10733 handle->debug_print("mpu9250: write i2c slv3 addr failed.\n"); /* write i2c slv3 addr failed */
10734
10735 return 1; /* return error */
10736 }
10737 }
10738 else if (slave == MPU9250_IIC_SLAVE_4) /* slave4 */
10739 {
10740 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV4_ADDR, (uint8_t *)&prev, 1); /* read i2c slv4 addr */
10741 if (res != 0) /* check result */
10742 {
10743 handle->debug_print("mpu9250: read i2c slv4 addr failed.\n"); /* read i2c slv4 addr failed */
10744
10745 return 1; /* return error */
10746 }
10747 prev &= ~(1 << 7); /* clear the settings */
10748 prev |= mode << 7; /* set the bool */
10749 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV4_ADDR, (uint8_t *)&prev, 1); /* write i2c slv4 addr */
10750 if (res != 0) /* check result */
10751 {
10752 handle->debug_print("mpu9250: write i2c slv4 addr failed.\n"); /* write i2c slv4 addr failed */
10753
10754 return 1; /* return error */
10755 }
10756 }
10757 else
10758 {
10759 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
10760
10761 return 4; /* return error */
10762 }
10763
10764 return 0; /* success return 0 */
10765 }
10766
10780 uint8_t mpu9250_get_iic_mode(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_iic_mode_t *mode)
10781 {
10782 uint8_t res;
10783 uint8_t prev;
10784
10785 if (handle == NULL) /* check handle */
10786 {
10787 return 2; /* return error */
10788 }
10789 if (handle->inited != 1) /* check handle initialization */
10790 {
10791 return 3; /* return error */
10792 }
10793
10794 if (slave == MPU9250_IIC_SLAVE_0) /* slave0 */
10795 {
10796 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* read i2c slv0 addr */
10797 if (res != 0) /* check result */
10798 {
10799 handle->debug_print("mpu9250: read i2c slv0 addr failed.\n"); /* read i2c slv0 addr failed */
10800
10801 return 1; /* return error */
10802 }
10803 *mode = (mpu9250_iic_mode_t)((prev >> 7) & 0x1); /* get the mode */
10804 }
10805 else if (slave == MPU9250_IIC_SLAVE_1) /* slave1 */
10806 {
10807 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV1_ADDR, (uint8_t *)&prev, 1); /* read i2c slv1 addr */
10808 if (res != 0) /* check result */
10809 {
10810 handle->debug_print("mpu9250: read i2c slv1 addr failed.\n"); /* read i2c slv1 addr failed */
10811
10812 return 1; /* return error */
10813 }
10814 *mode = (mpu9250_iic_mode_t)((prev >> 7) & 0x1); /* get the mode */
10815 }
10816 else if (slave == MPU9250_IIC_SLAVE_2) /* slave2 */
10817 {
10818 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV2_ADDR, (uint8_t *)&prev, 1); /* read i2c slv2 addr */
10819 if (res != 0) /* check result */
10820 {
10821 handle->debug_print("mpu9250: read i2c slv2 addr failed.\n"); /* read i2c slv2 addr failed */
10822
10823 return 1; /* return error */
10824 }
10825 *mode = (mpu9250_iic_mode_t)((prev >> 7) & 0x1); /* get the mode */
10826 }
10827 else if (slave == MPU9250_IIC_SLAVE_3) /* slave2 */
10828 {
10829 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV3_ADDR, (uint8_t *)&prev, 1); /* read i2c slv3 addr */
10830 if (res != 0) /* check result */
10831 {
10832 handle->debug_print("mpu9250: read i2c slv3 addr failed.\n"); /* read i2c slv3 addr failed */
10833
10834 return 1; /* return error */
10835 }
10836 *mode = (mpu9250_iic_mode_t)((prev >> 7) & 0x1); /* get the mode */
10837 }
10838 else if (slave == MPU9250_IIC_SLAVE_4) /* slave4 */
10839 {
10840 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV4_ADDR, (uint8_t *)&prev, 1); /* read i2c slv4 addr */
10841 if (res != 0) /* check result */
10842 {
10843 handle->debug_print("mpu9250: read i2c slv4 addr failed.\n"); /* read i2c slv4 addr failed */
10844
10845 return 1; /* return error */
10846 }
10847 *mode = (mpu9250_iic_mode_t)((prev >> 7) & 0x1); /* get the mode */
10848 }
10849 else
10850 {
10851 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
10852
10853 return 4; /* return error */
10854 }
10855
10856 return 0; /* success return 0 */
10857 }
10858
10872 uint8_t mpu9250_set_iic_address(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, uint8_t addr_7bit)
10873 {
10874 uint8_t res;
10875 uint8_t prev;
10876
10877 if (handle == NULL) /* check handle */
10878 {
10879 return 2; /* return error */
10880 }
10881 if (handle->inited != 1) /* check handle initialization */
10882 {
10883 return 3; /* return error */
10884 }
10885
10886 if (slave == MPU9250_IIC_SLAVE_0) /* slave0 */
10887 {
10888 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* read i2c slv0 addr */
10889 if (res != 0) /* check result */
10890 {
10891 handle->debug_print("mpu9250: read i2c slv0 addr failed.\n"); /* read i2c slv0 addr failed */
10892
10893 return 1; /* return error */
10894 }
10895 prev &= ~0x7F; /* clear the settings */
10896 prev |= addr_7bit & 0x7F; /* set the address */
10897 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* write i2c slv0 addr */
10898 if (res != 0) /* check result */
10899 {
10900 handle->debug_print("mpu9250: write i2c slv0 addr failed.\n"); /* write i2c slv0 addr failed */
10901
10902 return 1; /* return error */
10903 }
10904 }
10905 else if (slave == MPU9250_IIC_SLAVE_1) /* slave1 */
10906 {
10907 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV1_ADDR, (uint8_t *)&prev, 1); /* read i2c slv1 addr */
10908 if (res != 0) /* check result */
10909 {
10910 handle->debug_print("mpu9250: read i2c slv1 addr failed.\n"); /* read i2c slv1 addr failed */
10911
10912 return 1; /* return error */
10913 }
10914 prev &= ~0x7F; /* clear the settings */
10915 prev |= addr_7bit & 0x7F; /* set the address */
10916 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV1_ADDR, (uint8_t *)&prev, 1); /* write i2c slv1 addr */
10917 if (res != 0) /* check result */
10918 {
10919 handle->debug_print("mpu9250: write i2c slv1 addr failed.\n"); /* write i2c slv1 addr failed */
10920
10921 return 1; /* return error */
10922 }
10923 }
10924 else if (slave == MPU9250_IIC_SLAVE_2) /* slave2 */
10925 {
10926 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV2_ADDR, (uint8_t *)&prev, 1); /* read i2c slv2 addr */
10927 if (res != 0) /* check result */
10928 {
10929 handle->debug_print("mpu9250: read i2c slv2 addr failed.\n"); /* read i2c slv2 addr failed */
10930
10931 return 1; /* return error */
10932 }
10933 prev &= ~0x7F; /* clear the settings */
10934 prev |= addr_7bit & 0x7F; /* set the address */
10935 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV2_ADDR, (uint8_t *)&prev, 1); /* write i2c slv2 addr */
10936 if (res != 0) /* check result */
10937 {
10938 handle->debug_print("mpu9250: write i2c slv2 addr failed.\n"); /* write i2c slv2 addr failed */
10939
10940 return 1; /* return error */
10941 }
10942 }
10943 else if (slave == MPU9250_IIC_SLAVE_3) /* slave2 */
10944 {
10945 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV3_ADDR, (uint8_t *)&prev, 1); /* read i2c slv3 addr */
10946 if (res != 0) /* check result */
10947 {
10948 handle->debug_print("mpu9250: read i2c slv3 addr failed.\n"); /* read i2c slv3 addr failed */
10949
10950 return 1; /* return error */
10951 }
10952 prev &= ~0x7F; /* clear the settings */
10953 prev |= addr_7bit & 0x7F; /* set the address */
10954 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV3_ADDR, (uint8_t *)&prev, 1); /* write i2c slv3 addr */
10955 if (res != 0) /* check result */
10956 {
10957 handle->debug_print("mpu9250: write i2c slv3 addr failed.\n"); /* write i2c slv3 addr failed */
10958
10959 return 1; /* return error */
10960 }
10961 }
10962 else if (slave == MPU9250_IIC_SLAVE_4) /* slave4 */
10963 {
10964 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV4_ADDR, (uint8_t *)&prev, 1); /* read i2c slv4 addr */
10965 if (res != 0) /* check result */
10966 {
10967 handle->debug_print("mpu9250: read i2c slv4 addr failed.\n"); /* read i2c slv4 addr failed */
10968
10969 return 1; /* return error */
10970 }
10971 prev &= ~0x7F; /* clear the settings */
10972 prev |= addr_7bit & 0x7F; /* set the address */
10973 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV4_ADDR, (uint8_t *)&prev, 1); /* write i2c slv4 addr */
10974 if (res != 0) /* check result */
10975 {
10976 handle->debug_print("mpu9250: write i2c slv4 addr failed.\n"); /* write i2c slv4 addr failed */
10977
10978 return 1; /* return error */
10979 }
10980 }
10981 else
10982 {
10983 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
10984
10985 return 4; /* return error */
10986 }
10987
10988 return 0; /* success return 0 */
10989 }
10990
11004 uint8_t mpu9250_get_iic_address(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, uint8_t *addr_7bit)
11005 {
11006 uint8_t res;
11007 uint8_t prev;
11008
11009 if (handle == NULL) /* check handle */
11010 {
11011 return 2; /* return error */
11012 }
11013 if (handle->inited != 1) /* check handle initialization */
11014 {
11015 return 3; /* return error */
11016 }
11017
11018 if (slave == MPU9250_IIC_SLAVE_0) /* slave0 */
11019 {
11020 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* read i2c slv0 addr */
11021 if (res != 0) /* check result */
11022 {
11023 handle->debug_print("mpu9250: read i2c slv0 addr failed.\n"); /* read i2c slv0 addr failed */
11024
11025 return 1; /* return error */
11026 }
11027 *addr_7bit = prev & 0x7F; /* get the address */
11028 }
11029 else if (slave == MPU9250_IIC_SLAVE_1) /* slave1 */
11030 {
11031 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV1_ADDR, (uint8_t *)&prev, 1); /* read i2c slv1 addr */
11032 if (res != 0) /* check result */
11033 {
11034 handle->debug_print("mpu9250: read i2c slv1 addr failed.\n"); /* read i2c slv1 addr failed */
11035
11036 return 1; /* return error */
11037 }
11038 *addr_7bit = prev & 0x7F; /* get the address */
11039 }
11040 else if (slave == MPU9250_IIC_SLAVE_2) /* slave2 */
11041 {
11042 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV2_ADDR, (uint8_t *)&prev, 1); /* read i2c slv2 addr */
11043 if (res != 0) /* check result */
11044 {
11045 handle->debug_print("mpu9250: read i2c slv2 addr failed.\n"); /* read i2c slv2 addr failed */
11046
11047 return 1; /* return error */
11048 }
11049 *addr_7bit = prev & 0x7F; /* get the address */
11050 }
11051 else if (slave == MPU9250_IIC_SLAVE_3) /* slave2 */
11052 {
11053 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV3_ADDR, (uint8_t *)&prev, 1); /* read i2c slv3 addr */
11054 if (res != 0) /* check result */
11055 {
11056 handle->debug_print("mpu9250: read i2c slv3 addr failed.\n"); /* read i2c slv3 addr failed */
11057
11058 return 1; /* return error */
11059 }
11060 *addr_7bit = prev & 0x7F; /* get the address */
11061 }
11062 else if (slave == MPU9250_IIC_SLAVE_4) /* slave4 */
11063 {
11064 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV4_ADDR, (uint8_t *)&prev, 1); /* read i2c slv4 addr */
11065 if (res != 0) /* check result */
11066 {
11067 handle->debug_print("mpu9250: read i2c slv4 addr failed.\n"); /* read i2c slv4 addr failed */
11068
11069 return 1; /* return error */
11070 }
11071 *addr_7bit = prev & 0x7F; /* get the address */
11072 }
11073 else
11074 {
11075 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
11076
11077 return 4; /* return error */
11078 }
11079
11080 return 0; /* success return 0 */
11081 }
11082
11096 uint8_t mpu9250_set_iic_register(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, uint8_t reg)
11097 {
11098 uint8_t res;
11099
11100 if (handle == NULL) /* check handle */
11101 {
11102 return 2; /* return error */
11103 }
11104 if (handle->inited != 1) /* check handle initialization */
11105 {
11106 return 3; /* return error */
11107 }
11108
11109 if (slave == MPU9250_IIC_SLAVE_0) /* slave0 */
11110 {
11111 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV0_REG, (uint8_t *)&reg, 1); /* write i2c slv0 reg */
11112 if (res != 0) /* check result */
11113 {
11114 handle->debug_print("mpu9250: write i2c slv0 reg failed.\n"); /* write i2c slv0 reg failed */
11115
11116 return 1; /* return error */
11117 }
11118 }
11119 else if (slave == MPU9250_IIC_SLAVE_1) /* slave1 */
11120 {
11121 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV1_REG, (uint8_t *)&reg, 1); /* write i2c slv1 reg */
11122 if (res != 0) /* check result */
11123 {
11124 handle->debug_print("mpu9250: write i2c slv1 reg failed.\n"); /* write i2c slv1 reg failed */
11125
11126 return 1; /* return error */
11127 }
11128 }
11129 else if (slave == MPU9250_IIC_SLAVE_2) /* slave2 */
11130 {
11131 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV2_REG, (uint8_t *)&reg, 1); /* write i2c slv2 reg */
11132 if (res != 0) /* check result */
11133 {
11134 handle->debug_print("mpu9250: write i2c slv2 reg failed.\n"); /* write i2c slv2 reg failed */
11135
11136 return 1; /* return error */
11137 }
11138 }
11139 else if (slave == MPU9250_IIC_SLAVE_3) /* slave2 */
11140 {
11141 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV3_REG, (uint8_t *)&reg, 1); /* write i2c slv3 reg */
11142 if (res != 0) /* check result */
11143 {
11144 handle->debug_print("mpu9250: write i2c slv3 reg failed.\n"); /* write i2c slv3 reg failed */
11145
11146 return 1; /* return error */
11147 }
11148 }
11149 else if (slave == MPU9250_IIC_SLAVE_4) /* slave4 */
11150 {
11151 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV4_REG, (uint8_t *)&reg, 1); /* write i2c slv4 reg */
11152 if (res != 0) /* check result */
11153 {
11154 handle->debug_print("mpu9250: write i2c slv4 reg failed.\n"); /* write i2c slv4 reg failed */
11155
11156 return 1; /* return error */
11157 }
11158 }
11159 else
11160 {
11161 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
11162
11163 return 4; /* return error */
11164 }
11165
11166 return 0; /* success return 0 */
11167 }
11168
11182 uint8_t mpu9250_get_iic_register(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, uint8_t *reg)
11183 {
11184 uint8_t res;
11185
11186 if (handle == NULL) /* check handle */
11187 {
11188 return 2; /* return error */
11189 }
11190 if (handle->inited != 1) /* check handle initialization */
11191 {
11192 return 3; /* return error */
11193 }
11194
11195 if (slave == MPU9250_IIC_SLAVE_0) /* slave0 */
11196 {
11197 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV0_REG, (uint8_t *)reg, 1); /* read i2c slv0 reg */
11198 if (res != 0) /* check result */
11199 {
11200 handle->debug_print("mpu9250: read i2c slv0 reg failed.\n"); /* read i2c slv0 reg failed */
11201
11202 return 1; /* return error */
11203 }
11204 }
11205 else if (slave == MPU9250_IIC_SLAVE_1) /* slave1 */
11206 {
11207 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV1_REG, (uint8_t *)reg, 1); /* read i2c slv1 reg */
11208 if (res != 0) /* check result */
11209 {
11210 handle->debug_print("mpu9250: read i2c slv1 reg failed.\n"); /* read i2c slv1 reg failed */
11211
11212 return 1; /* return error */
11213 }
11214 }
11215 else if (slave == MPU9250_IIC_SLAVE_2) /* slave2 */
11216 {
11217 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV2_REG, (uint8_t *)reg, 1); /* read i2c slv2 reg */
11218 if (res != 0) /* check result */
11219 {
11220 handle->debug_print("mpu9250: read i2c slv2 reg failed.\n"); /* read i2c slv2 reg failed */
11221
11222 return 1; /* return error */
11223 }
11224 }
11225 else if (slave == MPU9250_IIC_SLAVE_3) /* slave2 */
11226 {
11227 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV3_REG, (uint8_t *)reg, 1); /* read i2c slv3 reg */
11228 if (res != 0) /* check result */
11229 {
11230 handle->debug_print("mpu9250: read i2c slv3 reg failed.\n"); /* read i2c slv3 reg failed */
11231
11232 return 1; /* return error */
11233 }
11234 }
11235 else if (slave == MPU9250_IIC_SLAVE_4) /* slave4 */
11236 {
11237 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV4_REG, (uint8_t *)reg, 1); /* read i2c slv4 reg */
11238 if (res != 0) /* check result */
11239 {
11240 handle->debug_print("mpu9250: read i2c slv4 reg failed.\n"); /* read i2c slv4 reg failed */
11241
11242 return 1; /* return error */
11243 }
11244 }
11245 else
11246 {
11247 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
11248
11249 return 4; /* return error */
11250 }
11251
11252 return 0; /* success return 0 */
11253 }
11254
11268 uint8_t mpu9250_set_iic_data_out(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, uint8_t data)
11269 {
11270 uint8_t res;
11271
11272 if (handle == NULL) /* check handle */
11273 {
11274 return 2; /* return error */
11275 }
11276 if (handle->inited != 1) /* check handle initialization */
11277 {
11278 return 3; /* return error */
11279 }
11280
11281 if (slave == MPU9250_IIC_SLAVE_0) /* slave0 */
11282 {
11283 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV0_DO, (uint8_t *)&data, 1); /* write i2c slv0 do */
11284 if (res != 0) /* check result */
11285 {
11286 handle->debug_print("mpu9250: write i2c slv0 do failed.\n"); /* write i2c slv0 do fail */
11287
11288 return 1; /* return error */
11289 }
11290 }
11291 else if (slave == MPU9250_IIC_SLAVE_1) /* slave1 */
11292 {
11293 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV1_DO, (uint8_t *)&data, 1); /* write i2c slv1 do */
11294 if (res != 0) /* check result */
11295 {
11296 handle->debug_print("mpu9250: write i2c slv1 do failed.\n"); /* write i2c slv1 do fail */
11297
11298 return 1; /* return error */
11299 }
11300 }
11301 else if (slave == MPU9250_IIC_SLAVE_2) /* slave2 */
11302 {
11303 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV2_DO, (uint8_t *)&data, 1); /* write i2c slv2 do */
11304 if (res != 0) /* check result */
11305 {
11306 handle->debug_print("mpu9250: write i2c slv2 do failed.\n"); /* write i2c slv2 do fail */
11307
11308 return 1; /* return error */
11309 }
11310 }
11311 else if (slave == MPU9250_IIC_SLAVE_3) /* slave2 */
11312 {
11313 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV3_DO, (uint8_t *)&data, 1); /* write i2c slv3 do */
11314 if (res != 0) /* check result */
11315 {
11316 handle->debug_print("mpu9250: write i2c slv3 do failed.\n"); /* write i2c slv3 do fail */
11317
11318 return 1; /* return error */
11319 }
11320 }
11321 else
11322 {
11323 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
11324
11325 return 4; /* return error */
11326 }
11327
11328 return 0; /* success return 0 */
11329 }
11330
11344 uint8_t mpu9250_get_iic_data_out(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, uint8_t *data)
11345 {
11346 uint8_t res;
11347
11348 if (handle == NULL) /* check handle */
11349 {
11350 return 2; /* return error */
11351 }
11352 if (handle->inited != 1) /* check handle initialization */
11353 {
11354 return 3; /* return error */
11355 }
11356
11357 if (slave == MPU9250_IIC_SLAVE_0) /* slave0 */
11358 {
11359 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV0_DO, (uint8_t *)data, 1); /* read i2c slv0 do */
11360 if (res != 0) /* check result */
11361 {
11362 handle->debug_print("mpu9250: read i2c slv0 do failed.\n"); /* read i2c slv0 do failed */
11363
11364 return 1; /* return error */
11365 }
11366 }
11367 else if (slave == MPU9250_IIC_SLAVE_1) /* slave1 */
11368 {
11369 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV1_DO, (uint8_t *)data, 1); /* read i2c slv1 do */
11370 if (res != 0) /* check result */
11371 {
11372 handle->debug_print("mpu9250: read i2c slv1 do failed.\n"); /* read i2c slv1 do failed */
11373
11374 return 1; /* return error */
11375 }
11376 }
11377 else if (slave == MPU9250_IIC_SLAVE_2) /* slave2 */
11378 {
11379 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV2_DO, (uint8_t *)data, 1); /* read i2c slv2 do */
11380 if (res != 0) /* check result */
11381 {
11382 handle->debug_print("mpu9250: read i2c slv2 do failed.\n"); /* read i2c slv2 do failed */
11383
11384 return 1; /* return error */
11385 }
11386 }
11387 else if (slave == MPU9250_IIC_SLAVE_3) /* slave2 */
11388 {
11389 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV3_DO, (uint8_t *)data, 1); /* read i2c slv3 do */
11390 if (res != 0) /* check result */
11391 {
11392 handle->debug_print("mpu9250: read i2c slv3 do failed.\n"); /* read i2c slv3 do failed */
11393
11394 return 1; /* return error */
11395 }
11396 }
11397 else
11398 {
11399 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
11400
11401 return 4; /* return error */
11402 }
11403
11404 return 0; /* success return 0 */
11405 }
11406
11420 uint8_t mpu9250_set_iic_enable(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_bool_t enable)
11421 {
11422 uint8_t res;
11423 uint8_t prev;
11424
11425 if (handle == NULL) /* check handle */
11426 {
11427 return 2; /* return error */
11428 }
11429 if (handle->inited != 1) /* check handle initialization */
11430 {
11431 return 3; /* return error */
11432 }
11433
11434 if (slave == MPU9250_IIC_SLAVE_0) /* slave0 */
11435 {
11436 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
11437 if (res != 0) /* check result */
11438 {
11439 handle->debug_print("mpu9250: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
11440
11441 return 1; /* return error */
11442 }
11443 prev &= ~(1 << 7); /* clear the settings */
11444 prev |= enable << 7; /* set the bool */
11445 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* write i2c slv0 ctrl */
11446 if (res != 0) /* check result */
11447 {
11448 handle->debug_print("mpu9250: write i2c slv0 ctrl failed.\n"); /* write i2c slv0 ctrl failed */
11449
11450 return 1; /* return error */
11451 }
11452 }
11453 else if (slave == MPU9250_IIC_SLAVE_1) /* slave1 */
11454 {
11455 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
11456 if (res != 0) /* check result */
11457 {
11458 handle->debug_print("mpu9250: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
11459
11460 return 1; /* return error */
11461 }
11462 prev &= ~(1 << 7); /* clear the settings */
11463 prev |= enable << 7; /* set the bool */
11464 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* write i2c slv1 ctrl */
11465 if (res != 0) /* check result */
11466 {
11467 handle->debug_print("mpu9250: write i2c slv1 ctrl failed.\n"); /* write i2c slv1 ctrl failed */
11468
11469 return 1; /* return error */
11470 }
11471 }
11472 else if (slave == MPU9250_IIC_SLAVE_2) /* slave2 */
11473 {
11474 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
11475 if (res != 0) /* check result */
11476 {
11477 handle->debug_print("mpu9250: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
11478
11479 return 1; /* return error */
11480 }
11481 prev &= ~(1 << 7); /* clear the settings */
11482 prev |= enable << 7; /* set the bool */
11483 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* write i2c slv2 ctrl */
11484 if (res != 0) /* check result */
11485 {
11486 handle->debug_print("mpu9250: write i2c slv2 ctrl failed.\n"); /* write i2c slv2 ctrl failed */
11487
11488 return 1; /* return error */
11489 }
11490 }
11491 else if (slave == MPU9250_IIC_SLAVE_3) /* slave2 */
11492 {
11493 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
11494 if (res != 0) /* check result */
11495 {
11496 handle->debug_print("mpu9250: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
11497
11498 return 1; /* return error */
11499 }
11500 prev &= ~(1 << 7); /* clear the settings */
11501 prev |= enable << 7; /* set the bool */
11502 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* write i2c slv3 ctrl */
11503 if (res != 0) /* check result */
11504 {
11505 handle->debug_print("mpu9250: write i2c slv3 ctrl failed.\n"); /* write i2c slv3 ctrl failed */
11506
11507 return 1; /* return error */
11508 }
11509 }
11510 else
11511 {
11512 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
11513
11514 return 4; /* return error */
11515 }
11516
11517 return 0; /* success return 0 */
11518 }
11519
11533 uint8_t mpu9250_get_iic_enable(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_bool_t *enable)
11534 {
11535 uint8_t res;
11536 uint8_t prev;
11537
11538 if (handle == NULL) /* check handle */
11539 {
11540 return 2; /* return error */
11541 }
11542 if (handle->inited != 1) /* check handle initialization */
11543 {
11544 return 3; /* return error */
11545 }
11546
11547 if (slave == MPU9250_IIC_SLAVE_0) /* slave0 */
11548 {
11549 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
11550 if (res != 0) /* check result */
11551 {
11552 handle->debug_print("mpu9250: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
11553
11554 return 1; /* return error */
11555 }
11556 *enable = (mpu9250_bool_t)((prev >> 7) & 0x1); /* get the bool */
11557 }
11558 else if (slave == MPU9250_IIC_SLAVE_1) /* slave1 */
11559 {
11560 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
11561 if (res != 0) /* check result */
11562 {
11563 handle->debug_print("mpu9250: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
11564
11565 return 1; /* return error */
11566 }
11567 *enable = (mpu9250_bool_t)((prev >> 7) & 0x1); /* get the bool */
11568 }
11569 else if (slave == MPU9250_IIC_SLAVE_2) /* slave2 */
11570 {
11571 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
11572 if (res != 0) /* check result */
11573 {
11574 handle->debug_print("mpu9250: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
11575
11576 return 1; /* return error */
11577 }
11578 *enable = (mpu9250_bool_t)((prev >> 7) & 0x1); /* get the bool */
11579 }
11580 else if (slave == MPU9250_IIC_SLAVE_3) /* slave2 */
11581 {
11582 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
11583 if (res != 0) /* check result */
11584 {
11585 handle->debug_print("mpu9250: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
11586
11587 return 1; /* return error */
11588 }
11589 *enable = (mpu9250_bool_t)((prev >> 7) & 0x1); /* get the bool */
11590 }
11591 else
11592 {
11593 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
11594
11595 return 4; /* return error */
11596 }
11597
11598 return 0; /* success return 0 */
11599 }
11600
11614 uint8_t mpu9250_set_iic_byte_swap(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_bool_t enable)
11615 {
11616 uint8_t res;
11617 uint8_t prev;
11618
11619 if (handle == NULL) /* check handle */
11620 {
11621 return 2; /* return error */
11622 }
11623 if (handle->inited != 1) /* check handle initialization */
11624 {
11625 return 3; /* return error */
11626 }
11627
11628 if (slave == MPU9250_IIC_SLAVE_0) /* slave0 */
11629 {
11630 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
11631 if (res != 0) /* check result */
11632 {
11633 handle->debug_print("mpu9250: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
11634
11635 return 1; /* return error */
11636 }
11637 prev &= ~(1 << 6); /* clear the settings */
11638 prev |= enable << 6; /* set the bool */
11639 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* write i2c slv0 ctrl */
11640 if (res != 0) /* check result */
11641 {
11642 handle->debug_print("mpu9250: write i2c slv0 ctrl failed.\n"); /* write i2c slv0 ctrl failed */
11643
11644 return 1; /* return error */
11645 }
11646 }
11647 else if (slave == MPU9250_IIC_SLAVE_1) /* slave1 */
11648 {
11649 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
11650 if (res != 0) /* check result */
11651 {
11652 handle->debug_print("mpu9250: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
11653
11654 return 1; /* return error */
11655 }
11656 prev &= ~(1 << 6); /* clear the settings */
11657 prev |= enable << 6; /* set the bool */
11658 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* write i2c slv1 ctrl */
11659 if (res != 0) /* check result */
11660 {
11661 handle->debug_print("mpu9250: write i2c slv1 ctrl failed.\n"); /* write i2c slv1 ctrl failed */
11662
11663 return 1; /* return error */
11664 }
11665 }
11666 else if (slave == MPU9250_IIC_SLAVE_2) /* slave2 */
11667 {
11668 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
11669 if (res != 0) /* check result */
11670 {
11671 handle->debug_print("mpu9250: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
11672
11673 return 1; /* return error */
11674 }
11675 prev &= ~(1 << 6); /* clear the settings */
11676 prev |= enable << 6; /* set the bool */
11677 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* write i2c slv2 ctrl */
11678 if (res != 0) /* check result */
11679 {
11680 handle->debug_print("mpu9250: write i2c slv2 ctrl failed.\n"); /* write i2c slv2 ctrl failed */
11681
11682 return 1; /* return error */
11683 }
11684 }
11685 else if (slave == MPU9250_IIC_SLAVE_3) /* slave2 */
11686 {
11687 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
11688 if (res != 0) /* check result */
11689 {
11690 handle->debug_print("mpu9250: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
11691
11692 return 1; /* return error */
11693 }
11694 prev &= ~(1 << 6); /* clear the settings */
11695 prev |= enable << 6; /* set the bool */
11696 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* write i2c slv3 ctrl */
11697 if (res != 0) /* check result */
11698 {
11699 handle->debug_print("mpu9250: write i2c slv3 ctrl failed.\n"); /* write i2c slv3 ctrl failed */
11700
11701 return 1; /* return error */
11702 }
11703 }
11704 else
11705 {
11706 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
11707
11708 return 4; /* return error */
11709 }
11710
11711 return 0; /* success return 0 */
11712 }
11713
11727 uint8_t mpu9250_get_iic_byte_swap(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_bool_t *enable)
11728 {
11729 uint8_t res;
11730 uint8_t prev;
11731
11732 if (handle == NULL) /* check handle */
11733 {
11734 return 2; /* return error */
11735 }
11736 if (handle->inited != 1) /* check handle initialization */
11737 {
11738 return 3; /* return error */
11739 }
11740
11741 if (slave == MPU9250_IIC_SLAVE_0) /* slave0 */
11742 {
11743 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
11744 if (res != 0) /* check result */
11745 {
11746 handle->debug_print("mpu9250: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
11747
11748 return 1; /* return error */
11749 }
11750 *enable = (mpu9250_bool_t)((prev >> 6) & 0x1); /* get the bool */
11751 }
11752 else if (slave == MPU9250_IIC_SLAVE_1) /* slave1 */
11753 {
11754 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
11755 if (res != 0) /* check result */
11756 {
11757 handle->debug_print("mpu9250: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
11758
11759 return 1; /* return error */
11760 }
11761 *enable = (mpu9250_bool_t)((prev >> 6) & 0x1); /* get the bool */
11762 }
11763 else if (slave == MPU9250_IIC_SLAVE_2) /* slave2 */
11764 {
11765 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
11766 if (res != 0) /* check result */
11767 {
11768 handle->debug_print("mpu9250: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
11769
11770 return 1; /* return error */
11771 }
11772 *enable = (mpu9250_bool_t)((prev >> 6) & 0x1); /* get the bool */
11773 }
11774 else if (slave == MPU9250_IIC_SLAVE_3) /* slave2 */
11775 {
11776 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
11777 if (res != 0) /* check result */
11778 {
11779 handle->debug_print("mpu9250: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
11780
11781 return 1; /* return error */
11782 }
11783 *enable = (mpu9250_bool_t)((prev >> 6) & 0x1); /* get the bool */
11784 }
11785 else
11786 {
11787 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
11788
11789 return 4; /* return error */
11790 }
11791
11792 return 0; /* success return 0 */
11793 }
11794
11808 uint8_t mpu9250_set_iic_transaction_mode(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_iic_transaction_mode_t mode)
11809 {
11810 uint8_t res;
11811 uint8_t prev;
11812
11813 if (handle == NULL) /* check handle */
11814 {
11815 return 2; /* return error */
11816 }
11817 if (handle->inited != 1) /* check handle initialization */
11818 {
11819 return 3; /* return error */
11820 }
11821
11822 if (slave == MPU9250_IIC_SLAVE_0) /* slave0 */
11823 {
11824 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
11825 if (res != 0) /* check result */
11826 {
11827 handle->debug_print("mpu9250: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
11828
11829 return 1; /* return error */
11830 }
11831 prev &= ~(1 << 5); /* clear the settings */
11832 prev |= mode << 5; /* set the bool */
11833 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* write i2c slv0 ctrl */
11834 if (res != 0) /* check result */
11835 {
11836 handle->debug_print("mpu9250: write i2c slv0 ctrl failed.\n"); /* write i2c slv0 ctrl failed */
11837
11838 return 1; /* return error */
11839 }
11840 }
11841 else if (slave == MPU9250_IIC_SLAVE_1) /* slave1 */
11842 {
11843 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
11844 if (res != 0) /* check result */
11845 {
11846 handle->debug_print("mpu9250: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
11847
11848 return 1; /* return error */
11849 }
11850 prev &= ~(1 << 5); /* clear the settings */
11851 prev |= mode << 5; /* set the bool */
11852 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* write i2c slv1 ctrl */
11853 if (res != 0) /* check result */
11854 {
11855 handle->debug_print("mpu9250: write i2c slv1 ctrl failed.\n"); /* write i2c slv1 ctrl failed */
11856
11857 return 1; /* return error */
11858 }
11859 }
11860 else if (slave == MPU9250_IIC_SLAVE_2) /* slave2 */
11861 {
11862 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
11863 if (res != 0) /* check result */
11864 {
11865 handle->debug_print("mpu9250: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
11866
11867 return 1; /* return error */
11868 }
11869 prev &= ~(1 << 5); /* clear the settings */
11870 prev |= mode << 5; /* set the bool */
11871 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* write i2c slv2 ctrl */
11872 if (res != 0) /* check result */
11873 {
11874 handle->debug_print("mpu9250: write i2c slv2 ctrl failed.\n"); /* write i2c slv2 ctrl failed */
11875
11876 return 1; /* return error */
11877 }
11878 }
11879 else if (slave == MPU9250_IIC_SLAVE_3) /* slave2 */
11880 {
11881 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
11882 if (res != 0) /* check result */
11883 {
11884 handle->debug_print("mpu9250: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
11885
11886 return 1; /* return error */
11887 }
11888 prev &= ~(1 << 5); /* clear the settings */
11889 prev |= mode << 5; /* set the bool */
11890 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* write i2c slv3 ctrl */
11891 if (res != 0) /* check result */
11892 {
11893 handle->debug_print("mpu9250: write i2c slv3 ctrl failed.\n"); /* write i2c slv3 ctrl failed */
11894
11895 return 1; /* return error */
11896 }
11897 }
11898 else
11899 {
11900 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
11901
11902 return 4; /* return error */
11903 }
11904
11905 return 0; /* success return 0 */
11906 }
11907
11921 uint8_t mpu9250_get_iic_transaction_mode(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_iic_transaction_mode_t *mode)
11922 {
11923 uint8_t res;
11924 uint8_t prev;
11925
11926 if (handle == NULL) /* check handle */
11927 {
11928 return 2; /* return error */
11929 }
11930 if (handle->inited != 1) /* check handle initialization */
11931 {
11932 return 3; /* return error */
11933 }
11934
11935 if (slave == MPU9250_IIC_SLAVE_0) /* slave0 */
11936 {
11937 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
11938 if (res != 0) /* check result */
11939 {
11940 handle->debug_print("mpu9250: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
11941
11942 return 1; /* return error */
11943 }
11944 *mode = (mpu9250_iic_transaction_mode_t)((prev >> 5) & 0x1); /* get the bool */
11945 }
11946 else if (slave == MPU9250_IIC_SLAVE_1) /* slave1 */
11947 {
11948 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
11949 if (res != 0) /* check result */
11950 {
11951 handle->debug_print("mpu9250: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
11952
11953 return 1; /* return error */
11954 }
11955 *mode = (mpu9250_iic_transaction_mode_t)((prev >> 5) & 0x1); /* get the bool */
11956 }
11957 else if (slave == MPU9250_IIC_SLAVE_2) /* slave2 */
11958 {
11959 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
11960 if (res != 0) /* check result */
11961 {
11962 handle->debug_print("mpu9250: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
11963
11964 return 1; /* return error */
11965 }
11966 *mode = (mpu9250_iic_transaction_mode_t)((prev >> 5) & 0x1); /* get the bool */
11967 }
11968 else if (slave == MPU9250_IIC_SLAVE_3) /* slave2 */
11969 {
11970 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
11971 if (res != 0) /* check result */
11972 {
11973 handle->debug_print("mpu9250: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
11974
11975 return 1; /* return error */
11976 }
11977 *mode = (mpu9250_iic_transaction_mode_t)((prev >> 5) & 0x1); /* get the bool */
11978 }
11979 else
11980 {
11981 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
11982
11983 return 4; /* return error */
11984 }
11985
11986 return 0; /* success return 0 */
11987 }
11988
12002 uint8_t mpu9250_set_iic_group_order(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_iic_group_order_t order)
12003 {
12004 uint8_t res;
12005 uint8_t prev;
12006
12007 if (handle == NULL) /* check handle */
12008 {
12009 return 2; /* return error */
12010 }
12011 if (handle->inited != 1) /* check handle initialization */
12012 {
12013 return 3; /* return error */
12014 }
12015
12016 if (slave == MPU9250_IIC_SLAVE_0) /* slave0 */
12017 {
12018 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
12019 if (res != 0) /* check result */
12020 {
12021 handle->debug_print("mpu9250: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
12022
12023 return 1; /* return error */
12024 }
12025 prev &= ~(1 << 4); /* clear the settings */
12026 prev |= order << 4; /* set the order */
12027 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* write i2c slv0 ctrl */
12028 if (res != 0) /* check result */
12029 {
12030 handle->debug_print("mpu9250: write i2c slv0 ctrl failed.\n"); /* write i2c slv0 ctrl failed */
12031
12032 return 1; /* return error */
12033 }
12034 }
12035 else if (slave == MPU9250_IIC_SLAVE_1) /* slave1 */
12036 {
12037 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
12038 if (res != 0) /* check result */
12039 {
12040 handle->debug_print("mpu9250: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
12041
12042 return 1; /* return error */
12043 }
12044 prev &= ~(1 << 4); /* clear the settings */
12045 prev |= order << 4; /* set the order */
12046 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* write i2c slv1 ctrl */
12047 if (res != 0) /* check result */
12048 {
12049 handle->debug_print("mpu9250: write i2c slv1 ctrl failed.\n"); /* write i2c slv1 ctrl failed */
12050
12051 return 1; /* return error */
12052 }
12053 }
12054 else if (slave == MPU9250_IIC_SLAVE_2) /* slave2 */
12055 {
12056 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
12057 if (res != 0) /* check result */
12058 {
12059 handle->debug_print("mpu9250: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
12060
12061 return 1; /* return error */
12062 }
12063 prev &= ~(1 << 4); /* clear the settings */
12064 prev |= order << 4; /* set the order */
12065 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* write i2c slv2 ctrl */
12066 if (res != 0) /* check result */
12067 {
12068 handle->debug_print("mpu9250: write i2c slv2 ctrl failed.\n"); /* write i2c slv2 ctrl failed */
12069
12070 return 1; /* return error */
12071 }
12072 }
12073 else if (slave == MPU9250_IIC_SLAVE_3) /* slave2 */
12074 {
12075 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
12076 if (res != 0) /* check result */
12077 {
12078 handle->debug_print("mpu9250: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
12079
12080 return 1; /* return error */
12081 }
12082 prev &= ~(1 << 4); /* clear the settings */
12083 prev |= order << 4; /* set the order */
12084 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* write i2c slv3 ctrl */
12085 if (res != 0) /* check result */
12086 {
12087 handle->debug_print("mpu9250: write i2c slv3 ctrl failed.\n"); /* write i2c slv3 ctrl failed */
12088
12089 return 1; /* return error */
12090 }
12091 }
12092 else
12093 {
12094 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
12095
12096 return 4; /* return error */
12097 }
12098
12099 return 0; /* success return 0 */
12100 }
12101
12115 uint8_t mpu9250_get_iic_group_order(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_iic_group_order_t *order)
12116 {
12117 uint8_t res;
12118 uint8_t prev;
12119
12120 if (handle == NULL) /* check handle */
12121 {
12122 return 2; /* return error */
12123 }
12124 if (handle->inited != 1) /* check handle initialization */
12125 {
12126 return 3; /* return error */
12127 }
12128
12129 if (slave == MPU9250_IIC_SLAVE_0) /* slave0 */
12130 {
12131 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
12132 if (res != 0) /* check result */
12133 {
12134 handle->debug_print("mpu9250: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
12135
12136 return 1; /* return error */
12137 }
12138 *order = (mpu9250_iic_group_order_t)((prev >> 4) & 0x1); /* get the order */
12139 }
12140 else if (slave == MPU9250_IIC_SLAVE_1) /* slave1 */
12141 {
12142 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
12143 if (res != 0) /* check result */
12144 {
12145 handle->debug_print("mpu9250: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
12146
12147 return 1; /* return error */
12148 }
12149 *order = (mpu9250_iic_group_order_t)((prev >> 4) & 0x1); /* get the order */
12150 }
12151 else if (slave == MPU9250_IIC_SLAVE_2) /* slave2 */
12152 {
12153 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
12154 if (res != 0) /* check result */
12155 {
12156 handle->debug_print("mpu9250: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
12157
12158 return 1; /* return error */
12159 }
12160 *order = (mpu9250_iic_group_order_t)((prev >> 4) & 0x1); /* get the order */
12161 }
12162 else if (slave == MPU9250_IIC_SLAVE_3) /* slave2 */
12163 {
12164 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
12165 if (res != 0) /* check result */
12166 {
12167 handle->debug_print("mpu9250: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
12168
12169 return 1; /* return error */
12170 }
12171 *order = (mpu9250_iic_group_order_t)((prev >> 4) & 0x1); /* get the order */
12172 }
12173 else
12174 {
12175 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
12176
12177 return 4; /* return error */
12178 }
12179
12180 return 0; /* success return 0 */
12181 }
12182
12197 uint8_t mpu9250_set_iic_transferred_len(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, uint8_t len)
12198 {
12199 uint8_t res;
12200 uint8_t prev;
12201
12202 if (handle == NULL) /* check handle */
12203 {
12204 return 2; /* return error */
12205 }
12206 if (handle->inited != 1) /* check handle initialization */
12207 {
12208 return 3; /* return error */
12209 }
12210 if (len > 0xF) /* check handle initialization */
12211 {
12212 handle->debug_print("mpu9250: len > 0xF.\n"); /* len > 0xF */
12213
12214 return 5; /* return error */
12215 }
12216
12217 if (slave == MPU9250_IIC_SLAVE_0) /* slave0 */
12218 {
12219 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
12220 if (res != 0) /* check result */
12221 {
12222 handle->debug_print("mpu9250: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
12223
12224 return 1; /* return error */
12225 }
12226 prev &= ~0xF; /* clear the settings */
12227 prev |= len; /* set the len */
12228 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* write i2c slv0 ctrl */
12229 if (res != 0) /* check result */
12230 {
12231 handle->debug_print("mpu9250: write i2c slv0 ctrl failed.\n"); /* write i2c slv0 ctrl failed */
12232
12233 return 1; /* return error */
12234 }
12235 }
12236 else if (slave == MPU9250_IIC_SLAVE_1) /* slave1 */
12237 {
12238 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
12239 if (res != 0) /* check result */
12240 {
12241 handle->debug_print("mpu9250: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
12242
12243 return 1; /* return error */
12244 }
12245 prev &= ~0xF; /* clear the settings */
12246 prev |= len; /* set the len */
12247 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* write i2c slv1 ctrl */
12248 if (res != 0) /* check result */
12249 {
12250 handle->debug_print("mpu9250: write i2c slv1 ctrl failed.\n"); /* write i2c slv1 ctrl failed */
12251
12252 return 1; /* return error */
12253 }
12254 }
12255 else if (slave == MPU9250_IIC_SLAVE_2) /* slave2 */
12256 {
12257 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
12258 if (res != 0) /* check result */
12259 {
12260 handle->debug_print("mpu9250: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
12261
12262 return 1; /* return error */
12263 }
12264 prev &= ~0xF; /* clear the settings */
12265 prev |= len; /* set the len */
12266 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* write i2c slv2 ctrl */
12267 if (res != 0) /* check result */
12268 {
12269 handle->debug_print("mpu9250: write i2c slv2 ctrl failed.\n"); /* write i2c slv2 ctrl failed */
12270
12271 return 1; /* return error */
12272 }
12273 }
12274 else if (slave == MPU9250_IIC_SLAVE_3) /* slave2 */
12275 {
12276 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
12277 if (res != 0) /* check result */
12278 {
12279 handle->debug_print("mpu9250: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
12280
12281 return 1; /* return error */
12282 }
12283 prev &= ~0xF; /* clear the settings */
12284 prev |= len; /* set the len */
12285 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* write i2c slv3 ctrl */
12286 if (res != 0) /* check result */
12287 {
12288 handle->debug_print("mpu9250: write i2c slv3 ctrl failed.\n"); /* write i2c slv3 ctrl failed */
12289
12290 return 1; /* return error */
12291 }
12292 }
12293 else
12294 {
12295 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
12296
12297 return 4; /* return error */
12298 }
12299
12300 return 0; /* success return 0 */
12301 }
12302
12316 uint8_t mpu9250_get_iic_transferred_len(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, uint8_t *len)
12317 {
12318 uint8_t res;
12319 uint8_t prev;
12320
12321 if (handle == NULL) /* check handle */
12322 {
12323 return 2; /* return error */
12324 }
12325 if (handle->inited != 1) /* check handle initialization */
12326 {
12327 return 3; /* return error */
12328 }
12329
12330 if (slave == MPU9250_IIC_SLAVE_0) /* slave0 */
12331 {
12332 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
12333 if (res != 0) /* check result */
12334 {
12335 handle->debug_print("mpu9250: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
12336
12337 return 1; /* return error */
12338 }
12339 *len = prev & 0x0F; /* get the len */
12340 }
12341 else if (slave == MPU9250_IIC_SLAVE_1) /* slave1 */
12342 {
12343 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
12344 if (res != 0) /* check result */
12345 {
12346 handle->debug_print("mpu9250: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
12347
12348 return 1; /* return error */
12349 }
12350 *len = prev & 0x0F; /* get the len */
12351 }
12352 else if (slave == MPU9250_IIC_SLAVE_2) /* slave2 */
12353 {
12354 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
12355 if (res != 0) /* check result */
12356 {
12357 handle->debug_print("mpu9250: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
12358
12359 return 1; /* return error */
12360 }
12361 *len = prev & 0x0F; /* get the len */
12362 }
12363 else if (slave == MPU9250_IIC_SLAVE_3) /* slave2 */
12364 {
12365 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
12366 if (res != 0) /* check result */
12367 {
12368 handle->debug_print("mpu9250: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
12369
12370 return 1; /* return error */
12371 }
12372 *len = prev & 0x0F; /* get the len */
12373 }
12374 else
12375 {
12376 handle->debug_print("mpu9250: invalid slave.\n"); /* invalid slave */
12377
12378 return 4; /* return error */
12379 }
12380
12381 return 0; /* success return 0 */
12382 }
12383
12395 uint8_t mpu9250_get_iic_status(mpu9250_handle_t *handle, uint8_t *status)
12396 {
12397 uint8_t res;
12398
12399 if (handle == NULL) /* check handle */
12400 {
12401 return 2; /* return error */
12402 }
12403 if (handle->inited != 1) /* check handle initialization */
12404 {
12405 return 3; /* return error */
12406 }
12407
12408 res = a_mpu9250_read(handle, MPU9250_REG_I2C_MST_STATUS, (uint8_t *)status, 1); /* read i2c mst status */
12409 if (res != 0) /* check result */
12410 {
12411 handle->debug_print("mpu9250: read i2c mst status failed.\n"); /* read i2c mst status failed */
12412
12413 return 1; /* return error */
12414 }
12415
12416 return 0; /* success return 0 */
12417 }
12418
12431 uint8_t mpu9250_set_iic_delay_enable(mpu9250_handle_t *handle, mpu9250_iic_delay_t delay, mpu9250_bool_t enable)
12432 {
12433 uint8_t res;
12434 uint8_t prev;
12435
12436 if (handle == NULL) /* check handle */
12437 {
12438 return 2; /* return error */
12439 }
12440 if (handle->inited != 1) /* check handle initialization */
12441 {
12442 return 3; /* return error */
12443 }
12444
12445 res = a_mpu9250_read(handle, MPU9250_REG_I2C_MST_DELAY_CTRL, (uint8_t *)&prev, 1); /* read i2c mst delay ctrl */
12446 if (res != 0) /* check result */
12447 {
12448 handle->debug_print("mpu9250: read i2c mst delay ctrl failed.\n"); /* read i2c mst delay ctrl failed */
12449
12450 return 1; /* return error */
12451 }
12452 prev &= ~(1 << delay); /* clear the settings */
12453 prev |= enable << delay; /* set the bool */
12454 res = a_mpu9250_write(handle, MPU9250_REG_I2C_MST_DELAY_CTRL, (uint8_t *)&prev, 1); /* write i2c mst delay ctrl */
12455 if (res != 0) /* check result */
12456 {
12457 handle->debug_print("mpu9250: write i2c mst delay ctrl failed.\n"); /* write i2c mst delay ctrl failed */
12458
12459 return 1; /* return error */
12460 }
12461
12462 return 0; /* success return 0 */
12463 }
12464
12477 uint8_t mpu9250_get_iic_delay_enable(mpu9250_handle_t *handle, mpu9250_iic_delay_t delay, mpu9250_bool_t *enable)
12478 {
12479 uint8_t res;
12480 uint8_t prev;
12481
12482 if (handle == NULL) /* check handle */
12483 {
12484 return 2; /* return error */
12485 }
12486 if (handle->inited != 1) /* check handle initialization */
12487 {
12488 return 3; /* return error */
12489 }
12490
12491 res = a_mpu9250_read(handle, MPU9250_REG_I2C_MST_DELAY_CTRL, (uint8_t *)&prev, 1); /* read i2c mst delay ctrl */
12492 if (res != 0) /* check result */
12493 {
12494 handle->debug_print("mpu9250: read i2c mst delay ctrl failed.\n"); /* read i2c mst delay ctrl failed */
12495
12496 return 1; /* return error */
12497 }
12498 *enable = (mpu9250_bool_t)((prev >> delay) & 0x1); /* get the bool */
12499
12500 return 0; /* success return 0 */
12501 }
12502
12514 uint8_t mpu9250_set_iic4_enable(mpu9250_handle_t *handle, mpu9250_bool_t enable)
12515 {
12516 uint8_t res;
12517 uint8_t prev;
12518
12519 if (handle == NULL) /* check handle */
12520 {
12521 return 2; /* return error */
12522 }
12523 if (handle->inited != 1) /* check handle initialization */
12524 {
12525 return 3; /* return error */
12526 }
12527
12528 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
12529 if (res != 0) /* check result */
12530 {
12531 handle->debug_print("mpu9250: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
12532
12533 return 1; /* return error */
12534 }
12535 prev &= ~(1 << 7); /* clear the settings */
12536 prev |= enable << 7; /* set the bool */
12537 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* write i2c slv4 ctrl */
12538 if (res != 0) /* check result */
12539 {
12540 handle->debug_print("mpu9250: write i2c slv4 ctrl failed.\n"); /* write i2c slv4 ctrl failed */
12541
12542 return 1; /* return error */
12543 }
12544
12545 return 0; /* success return 0 */
12546 }
12547
12559 uint8_t mpu9250_get_iic4_enable(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
12560 {
12561 uint8_t res;
12562 uint8_t prev;
12563
12564 if (handle == NULL) /* check handle */
12565 {
12566 return 2; /* return error */
12567 }
12568 if (handle->inited != 1) /* check handle initialization */
12569 {
12570 return 3; /* return error */
12571 }
12572
12573 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
12574 if (res != 0) /* check result */
12575 {
12576 handle->debug_print("mpu9250: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
12577
12578 return 1; /* return error */
12579 }
12580 *enable = (mpu9250_bool_t)((prev >> 7) & 0x1); /* get the bool */
12581
12582 return 0; /* success return 0 */
12583 }
12584
12596 uint8_t mpu9250_set_iic4_interrupt(mpu9250_handle_t *handle, mpu9250_bool_t enable)
12597 {
12598 uint8_t res;
12599 uint8_t prev;
12600
12601 if (handle == NULL) /* check handle */
12602 {
12603 return 2; /* return error */
12604 }
12605 if (handle->inited != 1) /* check handle initialization */
12606 {
12607 return 3; /* return error */
12608 }
12609
12610 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
12611 if (res != 0) /* check result */
12612 {
12613 handle->debug_print("mpu9250: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
12614
12615 return 1; /* return error */
12616 }
12617 prev &= ~(1 << 6); /* clear the settings */
12618 prev |= enable << 6; /* set the bool */
12619 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* write i2c slv4 ctrl */
12620 if (res != 0) /* check result */
12621 {
12622 handle->debug_print("mpu9250: write i2c slv4 ctrl failed.\n"); /* write i2c slv4 ctrl failed */
12623
12624 return 1; /* return error */
12625 }
12626
12627 return 0; /* success return 0 */
12628 }
12629
12641 uint8_t mpu9250_get_iic4_interrupt(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
12642 {
12643 uint8_t res;
12644 uint8_t prev;
12645
12646 if (handle == NULL) /* check handle */
12647 {
12648 return 2; /* return error */
12649 }
12650 if (handle->inited != 1) /* check handle initialization */
12651 {
12652 return 3; /* return error */
12653 }
12654
12655 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
12656 if (res != 0) /* check result */
12657 {
12658 handle->debug_print("mpu9250: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
12659
12660 return 1; /* return error */
12661 }
12662 *enable = (mpu9250_bool_t)((prev >> 6) & 0x1); /* get the bool */
12663
12664 return 0; /* success return 0 */
12665 }
12666
12678 uint8_t mpu9250_set_iic4_transaction_mode(mpu9250_handle_t *handle, mpu9250_iic4_transaction_mode_t mode)
12679 {
12680 uint8_t res;
12681 uint8_t prev;
12682
12683 if (handle == NULL) /* check handle */
12684 {
12685 return 2; /* return error */
12686 }
12687 if (handle->inited != 1) /* check handle initialization */
12688 {
12689 return 3; /* return error */
12690 }
12691
12692 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
12693 if (res != 0) /* check result */
12694 {
12695 handle->debug_print("mpu9250: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
12696
12697 return 1; /* return error */
12698 }
12699 prev &= ~(1 << 5); /* clear the settings */
12700 prev |= mode << 5; /* set the mode */
12701 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* write i2c slv4 ctrl */
12702 if (res != 0) /* check result */
12703 {
12704 handle->debug_print("mpu9250: write i2c slv4 ctrl failed.\n"); /* write i2c slv4 ctrl failed */
12705
12706 return 1; /* return error */
12707 }
12708
12709 return 0; /* success return 0 */
12710 }
12711
12723 uint8_t mpu9250_get_iic4_transaction_mode(mpu9250_handle_t *handle, mpu9250_iic4_transaction_mode_t *mode)
12724 {
12725 uint8_t res;
12726 uint8_t prev;
12727
12728 if (handle == NULL) /* check handle */
12729 {
12730 return 2; /* return error */
12731 }
12732 if (handle->inited != 1) /* check handle initialization */
12733 {
12734 return 3; /* return error */
12735 }
12736
12737 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
12738 if (res != 0) /* check result */
12739 {
12740 handle->debug_print("mpu9250: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
12741
12742 return 1; /* return error */
12743 }
12744 *mode = (mpu9250_iic4_transaction_mode_t)((prev >> 5) & 0x1); /* get the mode */
12745
12746 return 0; /* success return 0 */
12747 }
12748
12761 uint8_t mpu9250_set_iic_delay(mpu9250_handle_t *handle, uint8_t delay)
12762 {
12763 uint8_t res;
12764 uint8_t prev;
12765
12766 if (handle == NULL) /* check handle */
12767 {
12768 return 2; /* return error */
12769 }
12770 if (handle->inited != 1) /* check handle initialization */
12771 {
12772 return 3; /* return error */
12773 }
12774 if (delay > 0x1F) /* check the delay */
12775 {
12776 handle->debug_print("mpu9250: delay > 0x1F.\n"); /* delay > 0x1F */
12777
12778 return 4; /* return error */
12779 }
12780
12781 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
12782 if (res != 0) /* check result */
12783 {
12784 handle->debug_print("mpu9250: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
12785
12786 return 1; /* return error */
12787 }
12788 prev &= ~0x1F; /* clear the settings */
12789 prev |= delay; /* set the delay */
12790 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* write i2c slv4 ctrl */
12791 if (res != 0) /* check result */
12792 {
12793 handle->debug_print("mpu9250: write i2c slv4 ctrl failed.\n"); /* write i2c slv4 ctrl failed */
12794
12795 return 1; /* return error */
12796 }
12797
12798 return 0; /* success return 0 */
12799 }
12800
12812 uint8_t mpu9250_get_iic_delay(mpu9250_handle_t *handle, uint8_t *delay)
12813 {
12814 uint8_t res;
12815 uint8_t prev;
12816
12817 if (handle == NULL) /* check handle */
12818 {
12819 return 2; /* return error */
12820 }
12821 if (handle->inited != 1) /* check handle initialization */
12822 {
12823 return 3; /* return error */
12824 }
12825
12826 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
12827 if (res != 0) /* check result */
12828 {
12829 handle->debug_print("mpu9250: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
12830
12831 return 1; /* return error */
12832 }
12833 *delay = prev & 0x1F; /* get the delay */
12834
12835 return 0; /* success return 0 */
12836 }
12837
12849 uint8_t mpu9250_set_iic4_data_out(mpu9250_handle_t *handle, uint8_t data)
12850 {
12851 uint8_t res;
12852
12853 if (handle == NULL) /* check handle */
12854 {
12855 return 2; /* return error */
12856 }
12857 if (handle->inited != 1) /* check handle initialization */
12858 {
12859 return 3; /* return error */
12860 }
12861
12862 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV4_DO, (uint8_t *)&data, 1); /* write i2c slv4 do */
12863 if (res != 0) /* check result */
12864 {
12865 handle->debug_print("mpu9250: write i2c slv4 do failed.\n"); /* write i2c slv4 do fail */
12866
12867 return 1; /* return error */
12868 }
12869
12870 return 0; /* success return 0 */
12871 }
12872
12884 uint8_t mpu9250_get_iic4_data_out(mpu9250_handle_t *handle, uint8_t *data)
12885 {
12886 uint8_t res;
12887
12888 if (handle == NULL) /* check handle */
12889 {
12890 return 2; /* return error */
12891 }
12892 if (handle->inited != 1) /* check handle initialization */
12893 {
12894 return 3; /* return error */
12895 }
12896
12897 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV4_DO, (uint8_t *)data, 1); /* read i2c slv4 do */
12898 if (res != 0) /* check result */
12899 {
12900 handle->debug_print("mpu9250: read i2c slv4 do failed.\n"); /* read i2c slv4 do failed */
12901
12902 return 1; /* return error */
12903 }
12904
12905 return 0; /* success return 0 */
12906 }
12907
12919 uint8_t mpu9250_set_iic4_data_in(mpu9250_handle_t *handle, uint8_t data)
12920 {
12921 uint8_t res;
12922
12923 if (handle == NULL) /* check handle */
12924 {
12925 return 2; /* return error */
12926 }
12927 if (handle->inited != 1) /* check handle initialization */
12928 {
12929 return 3; /* return error */
12930 }
12931
12932 res = a_mpu9250_write(handle, MPU9250_REG_I2C_SLV4_DI, (uint8_t *)&data, 1); /* write i2c slv4 di */
12933 if (res != 0) /* check result */
12934 {
12935 handle->debug_print("mpu9250: write i2c slv4 di failed.\n"); /* write i2c slv4 di failed */
12936
12937 return 1; /* return error */
12938 }
12939
12940 return 0; /* success return 0 */
12941 }
12942
12954 uint8_t mpu9250_get_iic4_data_in(mpu9250_handle_t *handle, uint8_t *data)
12955 {
12956 uint8_t res;
12957
12958 if (handle == NULL) /* check handle */
12959 {
12960 return 2; /* return error */
12961 }
12962 if (handle->inited != 1) /* check handle initialization */
12963 {
12964 return 3; /* return error */
12965 }
12966
12967 res = a_mpu9250_read(handle, MPU9250_REG_I2C_SLV4_DI, (uint8_t *)data, 1); /* read i2c slv4 di */
12968 if (res != 0) /* check result */
12969 {
12970 handle->debug_print("mpu9250: read i2c slv4 di failed.\n"); /* read i2c slv4 di failed */
12971
12972 return 1; /* return error */
12973 }
12974
12975 return 0; /* success return 0 */
12976 }
12977
12991 uint8_t mpu9250_read_extern_sensor_data(mpu9250_handle_t *handle, uint8_t *data, uint8_t len)
12992 {
12993 uint8_t res;
12994
12995 if (handle == NULL) /* check handle */
12996 {
12997 return 2; /* return error */
12998 }
12999 if (handle->inited != 1) /* check handle initialization */
13000 {
13001 return 3; /* return error */
13002 }
13003 if (len > 24) /* check handle initialization */
13004 {
13005 handle->debug_print("mpu9250: len > 24.\n"); /* len > 24 */
13006
13007 return 4; /* return error */
13008 }
13009
13010 res = a_mpu9250_read(handle, MPU9250_REG_EXT_SENS_DATA_00, (uint8_t *)data, len); /* read ext sens data 00 */
13011 if (res != 0) /* check result */
13012 {
13013 handle->debug_print("mpu9250: read ext sens data 00 failed.\n"); /* read ext sens data 00 failed */
13014
13015 return 1; /* return error */
13016 }
13017
13018 return 0; /* success return 0 */
13019 }
13020
13034 uint8_t mpu9250_set_reg(mpu9250_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
13035 {
13036 if (handle == NULL) /* check handle */
13037 {
13038 return 2; /* return error */
13039 }
13040 if (handle->inited != 1) /* check handle initialization */
13041 {
13042 return 3; /* return error */
13043 }
13044
13045 return a_mpu9250_write(handle, reg, buf, len); /* write data */
13046 }
13047
13061 uint8_t mpu9250_get_reg(mpu9250_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
13062 {
13063 if (handle == NULL) /* check handle */
13064 {
13065 return 2; /* return error */
13066 }
13067 if (handle->inited != 1) /* check handle initialization */
13068 {
13069 return 3; /* return error */
13070 }
13071
13072 return a_mpu9250_read(handle, reg, buf, len); /* read data */
13073 }
13074
13083 uint8_t mpu9250_info(mpu9250_info_t *info)
13084 {
13085 if (info == NULL) /* check handle */
13086 {
13087 return 2; /* return error */
13088 }
13089
13090 memset(info, 0, sizeof(mpu9250_info_t)); /* initialize mpu9250 info structure */
13091 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
13092 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
13093 strncpy(info->interface, "IIC SPI", 8); /* copy interface name */
13094 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
13095 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
13096 info->max_current_ma = MAX_CURRENT; /* set maximum current */
13097 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
13098 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
13099 info->driver_version = DRIVER_VERSION; /* set driver version */
13100
13101 return 0; /* success return 0 */
13102 }
MPU9250_REG_MOT_DETECT_CTRL
#define MPU9250_REG_MOT_DETECT_CTRL
Definition: driver_mpu9250.c:125
MPU9250_DMP_D_1_79
#define MPU9250_DMP_D_1_79
Definition: driver_mpu9250.c:173
MPU9250_DMP_TAP_THX
#define MPU9250_DMP_TAP_THX
Definition: driver_mpu9250.c:181
MPU9250_REG_YA_OFFSET_H
#define MPU9250_REG_YA_OFFSET_H
Definition: driver_mpu9250.c:138
AK8963_REG_WIA
#define AK8963_REG_WIA
Definition: driver_mpu9250.c:142
MPU9250_DMP_CFG_FIFO_ON_EVENT
#define MPU9250_DMP_CFG_FIFO_ON_EVENT
Definition: driver_mpu9250.c:188
MPU9250_DMP_FEATURE_SEND_ANY_GYRO
#define MPU9250_DMP_FEATURE_SEND_ANY_GYRO
Definition: driver_mpu9250.c:197
MPU9250_REG_SELF_TEST_Y_ACCEL
#define MPU9250_REG_SELF_TEST_Y_ACCEL
Definition: driver_mpu9250.c:65
MPU9250_REG_SELF_TEST_Y_GYRO
#define MPU9250_REG_SELF_TEST_Y_GYRO
Definition: driver_mpu9250.c:62
MPU9250_DMP_SHAKE_REJECT_TIMEOUT
#define MPU9250_DMP_SHAKE_REJECT_TIMEOUT
Definition: driver_mpu9250.c:218
MPU9250_DMP_CFG_GYRO_RAW_DATA
#define MPU9250_DMP_CFG_GYRO_RAW_DATA
Definition: driver_mpu9250.c:201
MPU9250_REG_WHO_AM_I
#define MPU9250_REG_WHO_AM_I
Definition: driver_mpu9250.c:135
MPU9250_DMP_CFG_8
#define MPU9250_DMP_CFG_8
Definition: driver_mpu9250.c:185
MPU9250_REG_SELF_TEST_Z_ACCEL
#define MPU9250_REG_SELF_TEST_Z_ACCEL
Definition: driver_mpu9250.c:66
MPU9250_REG_SELF_TEST_X_ACCEL
#define MPU9250_REG_SELF_TEST_X_ACCEL
Definition: driver_mpu9250.c:64
MPU9250_DMP_CFG_15
#define MPU9250_DMP_CFG_15
Definition: driver_mpu9250.c:199
MPU9250_REG_I2C_SLV1_ADDR
#define MPU9250_REG_I2C_SLV1_ADDR
Definition: driver_mpu9250.c:89
MPU9250_DMP_CFG_27
#define MPU9250_DMP_CFG_27
Definition: driver_mpu9250.c:200
MPU9250_REG_I2C_SLV3_REG
#define MPU9250_REG_I2C_SLV3_REG
Definition: driver_mpu9250.c:98
MPU9250_REG_I2C_MST_CTRL
#define MPU9250_REG_I2C_MST_CTRL
Definition: driver_mpu9250.c:82
MAX_CURRENT
#define MAX_CURRENT
Definition: driver_mpu9250.c:48
MPU9250_DMP_D_0_22
#define MPU9250_DMP_D_0_22
Definition: driver_mpu9250.c:178
AK8963_REG_CNTL2
#define AK8963_REG_CNTL2
Definition: driver_mpu9250.c:153
MPU9250_DMP_TAP_THZ
#define MPU9250_DMP_TAP_THZ
Definition: driver_mpu9250.c:183
AK8963_REG_ASTC
#define AK8963_REG_ASTC
Definition: driver_mpu9250.c:154
MPU9250_DMP_D_1_218
#define MPU9250_DMP_D_1_218
Definition: driver_mpu9250.c:177
MPU9250_REG_I2C_SLV4_ADDR
#define MPU9250_REG_I2C_SLV4_ADDR
Definition: driver_mpu9250.c:101
MPU9250_REG_I2C_SLV1_REG
#define MPU9250_REG_I2C_SLV1_REG
Definition: driver_mpu9250.c:90
AK8963_REG_CNTL1
#define AK8963_REG_CNTL1
Definition: driver_mpu9250.c:152
MPU9250_REG_I2C_MST_STATUS
#define MPU9250_REG_I2C_MST_STATUS
Definition: driver_mpu9250.c:83
MPU9250_DMP_TAP_TIME_MULTI
#define MPU9250_DMP_TAP_TIME_MULTI
Definition: driver_mpu9250.c:215
MIN
#define MIN(a, b)
inner function definition
Definition: driver_mpu9250.c:223
MPU9250_REG_EXT_SENS_DATA_00
#define MPU9250_REG_EXT_SENS_DATA_00
Definition: driver_mpu9250.c:106
MPU9250_REG_I2C_MST_DELAY_CTRL
#define MPU9250_REG_I2C_MST_DELAY_CTRL
Definition: driver_mpu9250.c:84
MPU9250_REG_I2C_SLV0_ADDR
#define MPU9250_REG_I2C_SLV0_ADDR
Definition: driver_mpu9250.c:85
MPU9250_DMP_GYRO_SF
#define MPU9250_DMP_GYRO_SF
Definition: driver_mpu9250.c:166
MPU9250_DMP_SAMPLE_RATE
#define MPU9250_DMP_SAMPLE_RATE
mpu9250 dmp code definition
Definition: driver_mpu9250.c:165
MPU9250_REG_FIFO_COUNTH
#define MPU9250_REG_FIFO_COUNTH
Definition: driver_mpu9250.c:132
MPU9250_DMP_D_1_92
#define MPU9250_DMP_D_1_92
Definition: driver_mpu9250.c:176
MPU9250_DMP_D_EXT_GYRO_BIAS_Y
#define MPU9250_DMP_D_EXT_GYRO_BIAS_Y
Definition: driver_mpu9250.c:194
MPU9250_REG_R_W
#define MPU9250_REG_R_W
Definition: driver_mpu9250.c:134
MPU9250_REG_INT_ENABLE
#define MPU9250_REG_INT_ENABLE
Definition: driver_mpu9250.c:108
MPU9250_DMP_CFG_6
#define MPU9250_DMP_CFG_6
Definition: driver_mpu9250.c:184
MPU9250_REG_XG_OFFSET_H
#define MPU9250_REG_XG_OFFSET_H
Definition: driver_mpu9250.c:67
MPU9250_DMP_D_1_88
#define MPU9250_DMP_D_1_88
Definition: driver_mpu9250.c:174
MPU9250_DMP_D_1_36
#define MPU9250_DMP_D_1_36
Definition: driver_mpu9250.c:169
MPU9250_DMP_D_1_44
#define MPU9250_DMP_D_1_44
Definition: driver_mpu9250.c:171
SUPPLY_VOLTAGE_MAX
#define SUPPLY_VOLTAGE_MAX
Definition: driver_mpu9250.c:47
MPU9250_REG_FIFO_EN
#define MPU9250_REG_FIFO_EN
Definition: driver_mpu9250.c:81
MPU9250_REG_I2C_SLV1_CTRL
#define MPU9250_REG_I2C_SLV1_CTRL
Definition: driver_mpu9250.c:91
MPU9250_DMP_TAP_MIN_TAP_COUNT
#define MPU9250_DMP_TAP_MIN_TAP_COUNT
Definition: driver_mpu9250.c:213
MPU9250_DMP_INT_SRC_TAP
#define MPU9250_DMP_INT_SRC_TAP
Definition: driver_mpu9250.c:210
MPU9250_REG_INT_PIN_CFG
#define MPU9250_REG_INT_PIN_CFG
Definition: driver_mpu9250.c:107
MPU9250_DMP_TAPW_MIN
#define MPU9250_DMP_TAPW_MIN
Definition: driver_mpu9250.c:180
MPU9250_DMP_CFG_ORIENT_INT
#define MPU9250_DMP_CFG_ORIENT_INT
Definition: driver_mpu9250.c:203
MPU9250_REG_USER_CTRL
#define MPU9250_REG_USER_CTRL
Definition: driver_mpu9250.c:126
AK8963_REG_I2CDIS
#define AK8963_REG_I2CDIS
Definition: driver_mpu9250.c:157
MPU9250_DMP_D_1_90
#define MPU9250_DMP_D_1_90
Definition: driver_mpu9250.c:175
MPU9250_REG_SMPRT_DIV
#define MPU9250_REG_SMPRT_DIV
Definition: driver_mpu9250.c:73
MPU9250_REG_ZA_OFFSET_H
#define MPU9250_REG_ZA_OFFSET_H
Definition: driver_mpu9250.c:140
MPU9250_DMP_QUAT_MAG_SQ_MAX
#define MPU9250_DMP_QUAT_MAG_SQ_MAX
Definition: driver_mpu9250.c:208
MPU9250_DMP_SHAKE_REJECT_THRESH
#define MPU9250_DMP_SHAKE_REJECT_THRESH
Definition: driver_mpu9250.c:216
MPU9250_DMP_D_ACCEL_BIAS
#define MPU9250_DMP_D_ACCEL_BIAS
Definition: driver_mpu9250.c:196
MPU9250_REG_PROGRAM_START
#define MPU9250_REG_PROGRAM_START
Definition: driver_mpu9250.c:131
MPU9250_REG_I2C_SLV1_DO
#define MPU9250_REG_I2C_SLV1_DO
Definition: driver_mpu9250.c:92
MPU9250_REG_SELF_TEST_X_GYRO
#define MPU9250_REG_SELF_TEST_X_GYRO
chip register definition
Definition: driver_mpu9250.c:61
MPU9250_REG_I2C_SLV0_DO
#define MPU9250_REG_I2C_SLV0_DO
Definition: driver_mpu9250.c:88
MPU9250_DMP_FCFG_7
#define MPU9250_DMP_FCFG_7
Definition: driver_mpu9250.c:192
MPU9250_DMP_D_0_104
#define MPU9250_DMP_D_0_104
Definition: driver_mpu9250.c:179
MPU9250_DMP_FCFG_2
#define MPU9250_DMP_FCFG_2
Definition: driver_mpu9250.c:190
MPU9250_REG_YG_OFFSET_H
#define MPU9250_REG_YG_OFFSET_H
Definition: driver_mpu9250.c:69
TEMPERATURE_MAX
#define TEMPERATURE_MAX
Definition: driver_mpu9250.c:50
MPU9250_REG_MEM
#define MPU9250_REG_MEM
Definition: driver_mpu9250.c:130
MPU9250_REG_SELF_TEST_Z_GYRO
#define MPU9250_REG_SELF_TEST_Z_GYRO
Definition: driver_mpu9250.c:63
MPU9250_REG_XA_OFFSET_H
#define MPU9250_REG_XA_OFFSET_H
Definition: driver_mpu9250.c:136
MPU9250_REG_ACCEL_CONFIG
#define MPU9250_REG_ACCEL_CONFIG
Definition: driver_mpu9250.c:76
MPU9250_DMP_D_1_72
#define MPU9250_DMP_D_1_72
Definition: driver_mpu9250.c:172
MPU9250_DMP_SHAKE_REJECT_TIME
#define MPU9250_DMP_SHAKE_REJECT_TIME
Definition: driver_mpu9250.c:217
MPU9250_DMP_TAP_THRESH
#define MPU9250_DMP_TAP_THRESH
Definition: driver_mpu9250.c:212
MPU9250_DMP_TAP_TIME
#define MPU9250_DMP_TAP_TIME
Definition: driver_mpu9250.c:214
MANUFACTURER_NAME
#define MANUFACTURER_NAME
Definition: driver_mpu9250.c:45
MPU9250_REG_WOM_THR
#define MPU9250_REG_WOM_THR
Definition: driver_mpu9250.c:79
TEMPERATURE_MIN
#define TEMPERATURE_MIN
Definition: driver_mpu9250.c:49
SUPPLY_VOLTAGE_MIN
#define SUPPLY_VOLTAGE_MIN
Definition: driver_mpu9250.c:46
MPU9250_REG_GYRO_CONFIG
#define MPU9250_REG_GYRO_CONFIG
Definition: driver_mpu9250.c:75
MPU9250_REG_SIGNAL_PATH_RESET
#define MPU9250_REG_SIGNAL_PATH_RESET
Definition: driver_mpu9250.c:124
MPU9250_REG_I2C_SLV2_REG
#define MPU9250_REG_I2C_SLV2_REG
Definition: driver_mpu9250.c:94
MPU9250_REG_I2C_SLV2_DO
#define MPU9250_REG_I2C_SLV2_DO
Definition: driver_mpu9250.c:96
AK8963_REG_ASAX
#define AK8963_REG_ASAX
Definition: driver_mpu9250.c:158
MPU9250_DMP_D_PEDSTD_STEPCTR
#define MPU9250_DMP_D_PEDSTD_STEPCTR
Definition: driver_mpu9250.c:168
MPU9250_REG_ZG_OFFSET_H
#define MPU9250_REG_ZG_OFFSET_H
Definition: driver_mpu9250.c:71
MPU9250_DMP_TAP_THY
#define MPU9250_DMP_TAP_THY
Definition: driver_mpu9250.c:182
MPU9250_DMP_D_PEDSTD_TIMECTR
#define MPU9250_DMP_D_PEDSTD_TIMECTR
Definition: driver_mpu9250.c:167
MPU9250_DMP_D_EXT_GYRO_BIAS_X
#define MPU9250_DMP_D_EXT_GYRO_BIAS_X
Definition: driver_mpu9250.c:193
MPU9250_DMP_D_1_40
#define MPU9250_DMP_D_1_40
Definition: driver_mpu9250.c:170
MPU9250_REG_I2C_SLV3_CTRL
#define MPU9250_REG_I2C_SLV3_CTRL
Definition: driver_mpu9250.c:99
AK8963_REG_INFO
#define AK8963_REG_INFO
Definition: driver_mpu9250.c:143
MPU9250_REG_CONFIG
#define MPU9250_REG_CONFIG
Definition: driver_mpu9250.c:74
MPU9250_REG_I2C_SLV2_ADDR
#define MPU9250_REG_I2C_SLV2_ADDR
Definition: driver_mpu9250.c:93
MPU9250_DMP_CFG_LP_QUAT
#define MPU9250_DMP_CFG_LP_QUAT
Definition: driver_mpu9250.c:187
MPU9250_REG_I2C_SLV4_DI
#define MPU9250_REG_I2C_SLV4_DI
Definition: driver_mpu9250.c:105
MPU9250_DMP_QUAT_MAG_SQ_MIN
#define MPU9250_DMP_QUAT_MAG_SQ_MIN
Definition: driver_mpu9250.c:206
MPU9250_REG_ACCEL_CONFIG2
#define MPU9250_REG_ACCEL_CONFIG2
Definition: driver_mpu9250.c:77
MPU9250_REG_I2C_SLV2_CTRL
#define MPU9250_REG_I2C_SLV2_CTRL
Definition: driver_mpu9250.c:95
AK8963_REG_ST1
#define AK8963_REG_ST1
Definition: driver_mpu9250.c:144
MPU9250_REG_I2C_SLV3_ADDR
#define MPU9250_REG_I2C_SLV3_ADDR
Definition: driver_mpu9250.c:97
MPU9250_REG_I2C_SLV4_REG
#define MPU9250_REG_I2C_SLV4_REG
Definition: driver_mpu9250.c:102
MPU9250_REG_PWR_MGMT_2
#define MPU9250_REG_PWR_MGMT_2
Definition: driver_mpu9250.c:128
CHIP_NAME
#define CHIP_NAME
chip information definition
Definition: driver_mpu9250.c:44
MPU9250_REG_ACCEL_XOUT_H
#define MPU9250_REG_ACCEL_XOUT_H
Definition: driver_mpu9250.c:110
MPU9250_REG_I2C_SLV4_DO
#define MPU9250_REG_I2C_SLV4_DO
Definition: driver_mpu9250.c:104
MPU9250_REG_LP_ACCEL_ODR
#define MPU9250_REG_LP_ACCEL_ODR
Definition: driver_mpu9250.c:78
MPU9250_REG_I2C_SLV3_DO
#define MPU9250_REG_I2C_SLV3_DO
Definition: driver_mpu9250.c:100
AK8963_IIC_ADDRESS
#define AK8963_IIC_ADDRESS
chip ak8963 iic address definition
Definition: driver_mpu9250.c:56
DRIVER_VERSION
#define DRIVER_VERSION
Definition: driver_mpu9250.c:51
MPU9250_REG_TEMP_OUT_H
#define MPU9250_REG_TEMP_OUT_H
Definition: driver_mpu9250.c:116
MPU9250_DMP_CFG_20
#define MPU9250_DMP_CFG_20
Definition: driver_mpu9250.c:202
MPU9250_DMP_CFG_MOTION_BIAS
#define MPU9250_DMP_CFG_MOTION_BIAS
Definition: driver_mpu9250.c:186
MPU9250_REG_I2C_SLV4_CTRL
#define MPU9250_REG_I2C_SLV4_CTRL
Definition: driver_mpu9250.c:103
MPU9250_REG_I2C_SLV0_CTRL
#define MPU9250_REG_I2C_SLV0_CTRL
Definition: driver_mpu9250.c:87
MPU9250_REG_PWR_MGMT_1
#define MPU9250_REG_PWR_MGMT_1
Definition: driver_mpu9250.c:127
MPU9250_DMP_FCFG_1
#define MPU9250_DMP_FCFG_1
Definition: driver_mpu9250.c:189
MPU9250_DMP_FCFG_3
#define MPU9250_DMP_FCFG_3
Definition: driver_mpu9250.c:191
MPU9250_DMP_INT_SRC_ORIENT
#define MPU9250_DMP_INT_SRC_ORIENT
Definition: driver_mpu9250.c:211
MPU9250_DMP_D_EXT_GYRO_BIAS_Z
#define MPU9250_DMP_D_EXT_GYRO_BIAS_Z
Definition: driver_mpu9250.c:195
MPU9250_REG_INT_STATUS
#define MPU9250_REG_INT_STATUS
Definition: driver_mpu9250.c:109
AK8963_REG_ST2
#define AK8963_REG_ST2
Definition: driver_mpu9250.c:151
MPU9250_REG_I2C_SLV0_REG
#define MPU9250_REG_I2C_SLV0_REG
Definition: driver_mpu9250.c:86
MPU9250_REG_BANK_SEL
#define MPU9250_REG_BANK_SEL
Definition: driver_mpu9250.c:129
driver_mpu9250.h
driver mpu9250 header file
driver_mpu9250_code.h
driver mpu9250 code header file
mpu9250_get_addr_pin
uint8_t mpu9250_get_addr_pin(mpu9250_handle_t *handle, mpu9250_address_t *addr_pin)
get the chip address pin
Definition: driver_mpu9250.c:3985
mpu9250_set_accelerometer_z_test
uint8_t mpu9250_set_accelerometer_z_test(mpu9250_handle_t *handle, uint8_t data)
set the accelerometer z test
Definition: driver_mpu9250.c:9341
mpu9250_get_accel_compare_with_previous_sample
uint8_t mpu9250_get_accel_compare_with_previous_sample(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the accel compare with previous sample status
Definition: driver_mpu9250.c:8177
mpu9250_get_interrupt_pin_type
uint8_t mpu9250_get_interrupt_pin_type(mpu9250_handle_t *handle, mpu9250_pin_type_t *type)
get the interrupt pin type
Definition: driver_mpu9250.c:8425
mpu9250_set_accelerometer_low_pass_filter
uint8_t mpu9250_set_accelerometer_low_pass_filter(mpu9250_handle_t *handle, mpu9250_accelerometer_low_pass_filter_t filter)
set the accelerometer low pass filter
Definition: driver_mpu9250.c:7886
mpu9250_set_wake_on_motion
uint8_t mpu9250_set_wake_on_motion(mpu9250_handle_t *handle, mpu9250_bool_t enable)
enable or disable wake on motion
Definition: driver_mpu9250.c:8050
mpu9250_set_accel_compare_with_previous_sample
uint8_t mpu9250_set_accel_compare_with_previous_sample(mpu9250_handle_t *handle, mpu9250_bool_t enable)
enable or disable accel compare with previous sample
Definition: driver_mpu9250.c:8132
mpu9250_set_fifo_mode
uint8_t mpu9250_set_fifo_mode(mpu9250_handle_t *handle, mpu9250_fifo_mode mode)
set the fifo mode
Definition: driver_mpu9250.c:7249
mpu9250_get_iic_read_mode
uint8_t mpu9250_get_iic_read_mode(mpu9250_handle_t *handle, mpu9250_iic_read_mode_t *mode)
get the iic read mode
Definition: driver_mpu9250.c:10469
mpu9250_self_test
uint8_t mpu9250_self_test(mpu9250_handle_t *handle, int32_t gyro_offset_raw[3], int32_t accel_offset_raw[3])
run the self test
Definition: driver_mpu9250.c:10094
mpu9250_set_addr_pin
uint8_t mpu9250_set_addr_pin(mpu9250_handle_t *handle, mpu9250_address_t addr_pin)
set the chip address pin
Definition: driver_mpu9250.c:3964
mpu9250_set_accelerometer_z_offset
uint8_t mpu9250_set_accelerometer_z_offset(mpu9250_handle_t *handle, int16_t offset)
set the accelerometer z offset
Definition: driver_mpu9250.c:9561
mpu9250_get_interrupt_read_clear
uint8_t mpu9250_get_interrupt_read_clear(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the interrupt reading clear status
Definition: driver_mpu9250.c:8589
mpu9250_set_ptat
uint8_t mpu9250_set_ptat(mpu9250_handle_t *handle, mpu9250_bool_t enable)
enable or disable the temperature sensor
Definition: driver_mpu9250.c:6449
mpu9250_get_iic_master
uint8_t mpu9250_get_iic_master(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the iic master status
Definition: driver_mpu9250.c:5924
mpu9250_get_iic_enable
uint8_t mpu9250_get_iic_enable(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_bool_t *enable)
get the iic status
Definition: driver_mpu9250.c:11533
mpu9250_get_iic4_enable
uint8_t mpu9250_get_iic4_enable(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the iic4 status
Definition: driver_mpu9250.c:12559
mpu9250_get_fsync_interrupt_level
uint8_t mpu9250_get_fsync_interrupt_level(mpu9250_handle_t *handle, mpu9250_pin_level_t *level)
get the fsync interrupt level
Definition: driver_mpu9250.c:8671
mpu9250_set_fifo_enable
uint8_t mpu9250_set_fifo_enable(mpu9250_handle_t *handle, mpu9250_fifo_t fifo, mpu9250_bool_t enable)
enable or disable the fifo function
Definition: driver_mpu9250.c:8215
mpu9250_get_fifo_mode
uint8_t mpu9250_get_fifo_mode(mpu9250_handle_t *handle, mpu9250_fifo_mode *mode)
get the fifo mode
Definition: driver_mpu9250.c:7294
mpu9250_get_accelerometer_low_pass_filter
uint8_t mpu9250_get_accelerometer_low_pass_filter(mpu9250_handle_t *handle, mpu9250_accelerometer_low_pass_filter_t *filter)
get the accelerometer low pass filter
Definition: driver_mpu9250.c:7931
mpu9250_set_standby_mode
uint8_t mpu9250_set_standby_mode(mpu9250_handle_t *handle, mpu9250_source_t source, mpu9250_bool_t enable)
set source into standby mode
Definition: driver_mpu9250.c:6778
mpu9250_set_iic_wait_for_external_sensor
uint8_t mpu9250_set_iic_wait_for_external_sensor(mpu9250_handle_t *handle, mpu9250_bool_t enable)
enable or disable iic wait for external sensor
Definition: driver_mpu9250.c:10342
mpu9250_get_gyro_z_offset
uint8_t mpu9250_get_gyro_z_offset(mpu9250_handle_t *handle, int16_t *offset)
get the gyro z offset
Definition: driver_mpu9250.c:9878
mpu9250_get_iic_mode
uint8_t mpu9250_get_iic_mode(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_iic_mode_t *mode)
get the iic mode
Definition: driver_mpu9250.c:10780
mpu9250_get_iic_bypass
uint8_t mpu9250_get_iic_bypass(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the iic bypass status
Definition: driver_mpu9250.c:8835
mpu9250_get_gyroscope_y_test
uint8_t mpu9250_get_gyroscope_y_test(mpu9250_handle_t *handle, uint8_t *data)
get the gyroscope y test
Definition: driver_mpu9250.c:9096
mpu9250_get_sample_rate_divider
uint8_t mpu9250_get_sample_rate_divider(mpu9250_handle_t *handle, uint8_t *d)
get the sample rate divider
Definition: driver_mpu9250.c:7050
mpu9250_set_cycle_wake_up
uint8_t mpu9250_set_cycle_wake_up(mpu9250_handle_t *handle, mpu9250_bool_t enable)
enable or disable the cycle wake up mode
Definition: driver_mpu9250.c:6531
mpu9250_set_accelerometer_y_test
uint8_t mpu9250_set_accelerometer_y_test(mpu9250_handle_t *handle, uint8_t data)
set the accelerometer y test
Definition: driver_mpu9250.c:9271
mpu9250_get_wake_on_motion
uint8_t mpu9250_get_wake_on_motion(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the wake on motion status
Definition: driver_mpu9250.c:8095
mpu9250_set_interrupt_latch
uint8_t mpu9250_set_interrupt_latch(mpu9250_handle_t *handle, mpu9250_bool_t enable)
enable or disable the interrupt latch
Definition: driver_mpu9250.c:8462
mpu9250_set_iic4_data_in
uint8_t mpu9250_set_iic4_data_in(mpu9250_handle_t *handle, uint8_t data)
set the iic4 data in
Definition: driver_mpu9250.c:12919
mpu9250_get_gyro_y_offset
uint8_t mpu9250_get_gyro_y_offset(mpu9250_handle_t *handle, int16_t *offset)
get the gyro y offset
Definition: driver_mpu9250.c:9803
mpu9250_accelerometer_range_t
mpu9250_accelerometer_range_t
mpu9250 accelerometer range enumeration definition
Definition: driver_mpu9250.h:211
mpu9250_get_accelerometer_z_offset
uint8_t mpu9250_get_accelerometer_z_offset(mpu9250_handle_t *handle, int16_t *offset)
get the accelerometer z offset
Definition: driver_mpu9250.c:9599
mpu9250_get_iic_byte_swap
uint8_t mpu9250_get_iic_byte_swap(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_bool_t *enable)
get the iic byte swap status
Definition: driver_mpu9250.c:11727
mpu9250_get_fifo_count
uint8_t mpu9250_get_fifo_count(mpu9250_handle_t *handle, uint16_t *count)
get the fifo counter value
Definition: driver_mpu9250.c:6861
mpu9250_get_iic_master_reset
uint8_t mpu9250_get_iic_master_reset(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the iic master reset status
Definition: driver_mpu9250.c:6168
mpu9250_set_extern_sync
uint8_t mpu9250_set_extern_sync(mpu9250_handle_t *handle, mpu9250_extern_sync_t sync)
set the extern sync type
Definition: driver_mpu9250.c:7085
mpu9250_accelerometer_offset_convert_to_data
uint8_t mpu9250_accelerometer_offset_convert_to_data(mpu9250_handle_t *handle, int16_t reg, float *mg)
convert the register raw data to the accelerometer offset
Definition: driver_mpu9250.c:9663
mpu9250_get_iic4_interrupt
uint8_t mpu9250_get_iic4_interrupt(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the iic4 interrupt status
Definition: driver_mpu9250.c:12641
mpu9250_fifo_get
uint8_t mpu9250_fifo_get(mpu9250_handle_t *handle, uint8_t *buf, uint16_t len)
fifo read bytes
Definition: driver_mpu9250.c:6899
mpu9250_get_accelerometer_test
uint8_t mpu9250_get_accelerometer_test(mpu9250_handle_t *handle, mpu9250_axis_t axis, mpu9250_bool_t *enable)
get the accelerometer test
Definition: driver_mpu9250.c:7633
mpu9250_pin_type_t
mpu9250_pin_type_t
mpu9250 pin type enumeration definition
Definition: driver_mpu9250.h:253
mpu9250_set_gyro_standby
uint8_t mpu9250_set_gyro_standby(mpu9250_handle_t *handle, mpu9250_bool_t enable)
enable or disable the gyro standby
Definition: driver_mpu9250.c:6695
mpu9250_signal_path_reset_t
mpu9250_signal_path_reset_t
mpu9250 signal path reset enumeration definition
Definition: driver_mpu9250.h:113
mpu9250_set_iic_multi_master
uint8_t mpu9250_set_iic_multi_master(mpu9250_handle_t *handle, mpu9250_bool_t enable)
enable or disable iic multi master
Definition: driver_mpu9250.c:10260
mpu9250_get_sleep
uint8_t mpu9250_get_sleep(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the sleep status
Definition: driver_mpu9250.c:6658
mpu9250_get_accelerometer_z_test
uint8_t mpu9250_get_accelerometer_z_test(mpu9250_handle_t *handle, uint8_t *data)
get the accelerometer z test
Definition: driver_mpu9250.c:9376
mpu9250_set_signal_path_reset
uint8_t mpu9250_set_signal_path_reset(mpu9250_handle_t *handle, mpu9250_signal_path_reset_t path)
set the signal path reset
Definition: driver_mpu9250.c:6970
mpu9250_get_accelerometer_range
uint8_t mpu9250_get_accelerometer_range(mpu9250_handle_t *handle, mpu9250_accelerometer_range_t *range)
get the accelerometer range
Definition: driver_mpu9250.c:7715
mpu9250_get_ptat
uint8_t mpu9250_get_ptat(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the temperature sensor status
Definition: driver_mpu9250.c:6494
mpu9250_get_iic_multi_master
uint8_t mpu9250_get_iic_multi_master(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the iic multi master status
Definition: driver_mpu9250.c:10305
mpu9250_iic_delay_t
mpu9250_iic_delay_t
mpu9250 iic delay enumeration definition
Definition: driver_mpu9250.h:371
mpu9250_get_iic_data_out
uint8_t mpu9250_get_iic_data_out(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, uint8_t *data)
get the iic data out
Definition: driver_mpu9250.c:11344
mpu9250_set_iic_transferred_len
uint8_t mpu9250_set_iic_transferred_len(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, uint8_t len)
set the iic transferred length
Definition: driver_mpu9250.c:12197
mpu9250_fifo_reset
uint8_t mpu9250_fifo_reset(mpu9250_handle_t *handle)
reset the fifo
Definition: driver_mpu9250.c:6042
mpu9250_set_iic_read_mode
uint8_t mpu9250_set_iic_read_mode(mpu9250_handle_t *handle, mpu9250_iic_read_mode_t mode)
set the iic read mode
Definition: driver_mpu9250.c:10424
mpu9250_accelerometer_offset_convert_to_register
uint8_t mpu9250_accelerometer_offset_convert_to_register(mpu9250_handle_t *handle, float mg, int16_t *reg)
convert the accelerometer offset to the register raw data
Definition: driver_mpu9250.c:9636
mpu9250_get_sensor_reset
uint8_t mpu9250_get_sensor_reset(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the sensor reset status
Definition: driver_mpu9250.c:6249
mpu9250_address_t
mpu9250_address_t
mpu9250 address enumeration definition
Definition: driver_mpu9250.h:72
mpu9250_gyroscope_range_t
mpu9250_gyroscope_range_t
mpu9250 gyroscope range enumeration definition
Definition: driver_mpu9250.h:200
mpu9250_set_iic4_data_out
uint8_t mpu9250_set_iic4_data_out(mpu9250_handle_t *handle, uint8_t data)
set the iic4 data out
Definition: driver_mpu9250.c:12849
mpu9250_set_iic_register
uint8_t mpu9250_set_iic_register(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, uint8_t reg)
set the iic register
Definition: driver_mpu9250.c:11096
mpu9250_get_accelerometer_choice
uint8_t mpu9250_get_accelerometer_choice(mpu9250_handle_t *handle, uint8_t *choice)
get the accelerometer choice
Definition: driver_mpu9250.c:7849
mpu9250_set_iic_data_out
uint8_t mpu9250_set_iic_data_out(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, uint8_t data)
set the iic data out
Definition: driver_mpu9250.c:11268
mpu9250_set_fsync_interrupt
uint8_t mpu9250_set_fsync_interrupt(mpu9250_handle_t *handle, mpu9250_bool_t enable)
enable or disable the fsync interrupt
Definition: driver_mpu9250.c:8708
mpu9250_get_iic4_transaction_mode
uint8_t mpu9250_get_iic4_transaction_mode(mpu9250_handle_t *handle, mpu9250_iic4_transaction_mode_t *mode)
get the iic4 transaction mode
Definition: driver_mpu9250.c:12723
mpu9250_get_interrupt
uint8_t mpu9250_get_interrupt(mpu9250_handle_t *handle, mpu9250_interrupt_t type, mpu9250_bool_t *enable)
get the interrupt status
Definition: driver_mpu9250.c:8919
mpu9250_set_accelerometer_y_offset
uint8_t mpu9250_set_accelerometer_y_offset(mpu9250_handle_t *handle, int16_t offset)
set the accelerometer y offset
Definition: driver_mpu9250.c:9486
mpu9250_motion_threshold_convert_to_data
uint8_t mpu9250_motion_threshold_convert_to_data(mpu9250_handle_t *handle, uint8_t reg, float *mg)
convert the register raw data to the motion threshold
Definition: driver_mpu9250.c:10066
mpu9250_set_iic_bypass
uint8_t mpu9250_set_iic_bypass(mpu9250_handle_t *handle, mpu9250_bool_t enable)
enable or disable the iic bypass
Definition: driver_mpu9250.c:8790
mpu9250_get_standby_mode
uint8_t mpu9250_get_standby_mode(mpu9250_handle_t *handle, mpu9250_source_t source, mpu9250_bool_t *enable)
get the source mode
Definition: driver_mpu9250.c:6824
mpu9250_get_clock_source
uint8_t mpu9250_get_clock_source(mpu9250_handle_t *handle, mpu9250_clock_source_t *clock_source)
get the chip clock source
Definition: driver_mpu9250.c:6412
mpu9250_info
uint8_t mpu9250_info(mpu9250_info_t *info)
get the chip's information
Definition: driver_mpu9250.c:13083
mpu9250_set_accelerometer_test
uint8_t mpu9250_set_accelerometer_test(mpu9250_handle_t *handle, mpu9250_axis_t axis, mpu9250_bool_t enable)
set the accelerometer test
Definition: driver_mpu9250.c:7587
mpu9250_set_interrupt_level
uint8_t mpu9250_set_interrupt_level(mpu9250_handle_t *handle, mpu9250_pin_level_t level)
set the interrupt level
Definition: driver_mpu9250.c:8298
mpu9250_set_gyroscope_x_test
uint8_t mpu9250_set_gyroscope_x_test(mpu9250_handle_t *handle, uint8_t data)
set the gyroscope x test
Definition: driver_mpu9250.c:8991
mpu9250_get_iic4_data_out
uint8_t mpu9250_get_iic4_data_out(mpu9250_handle_t *handle, uint8_t *data)
get the iic4 data out
Definition: driver_mpu9250.c:12884
mpu9250_set_interrupt_read_clear
uint8_t mpu9250_set_interrupt_read_clear(mpu9250_handle_t *handle, mpu9250_bool_t enable)
enable or disable the interrupt reading clear
Definition: driver_mpu9250.c:8544
mpu9250_get_extern_sync
uint8_t mpu9250_get_extern_sync(mpu9250_handle_t *handle, mpu9250_extern_sync_t *sync)
get the extern sync type
Definition: driver_mpu9250.c:7130
mpu9250_set_interface
uint8_t mpu9250_set_interface(mpu9250_handle_t *handle, mpu9250_interface_t interface)
set the chip interface
Definition: driver_mpu9250.c:3922
mpu9250_get_interface
uint8_t mpu9250_get_interface(mpu9250_handle_t *handle, mpu9250_interface_t *interface)
get the chip interface
Definition: driver_mpu9250.c:3943
mpu9250_iic_transaction_mode_t
mpu9250_iic_transaction_mode_t
mpu9250 iic transaction mode enumeration definition
Definition: driver_mpu9250.h:327
mpu9250_iic_slave_t
mpu9250_iic_slave_t
mpu9250 iic slave enumeration definition
Definition: driver_mpu9250.h:274
mpu9250_irq_handler
uint8_t mpu9250_irq_handler(mpu9250_handle_t *handle)
irq handler
Definition: driver_mpu9250.c:4668
mpu9250_set_gyroscope_y_test
uint8_t mpu9250_set_gyroscope_y_test(mpu9250_handle_t *handle, uint8_t data)
set the gyroscope y test
Definition: driver_mpu9250.c:9061
mpu9250_get_gyro_standby
uint8_t mpu9250_get_gyro_standby(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the gyro standby status
Definition: driver_mpu9250.c:6740
mpu9250_set_iic_mode
uint8_t mpu9250_set_iic_mode(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_iic_mode_t mode)
set the iic mode
Definition: driver_mpu9250.c:10648
mpu9250_interrupt_t
mpu9250_interrupt_t
mpu9250 interrupt enumeration definition
Definition: driver_mpu9250.h:262
mpu9250_get_gyroscope_x_test
uint8_t mpu9250_get_gyroscope_x_test(mpu9250_handle_t *handle, uint8_t *data)
get the gyroscope x test
Definition: driver_mpu9250.c:9026
mpu9250_get_fsync_interrupt
uint8_t mpu9250_get_fsync_interrupt(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the fsync interrupt status
Definition: driver_mpu9250.c:8753
mpu9250_extern_sync_t
mpu9250_extern_sync_t
mpu9250 extern sync enumeration definition
Definition: driver_mpu9250.h:123
mpu9250_gyro_offset_convert_to_data
uint8_t mpu9250_gyro_offset_convert_to_data(mpu9250_handle_t *handle, int16_t reg, float *dps)
convert the register raw data to the gyro offset
Definition: driver_mpu9250.c:9942
mpu9250_sensor_reset
uint8_t mpu9250_sensor_reset(mpu9250_handle_t *handle)
reset all sensors
Definition: driver_mpu9250.c:6204
mpu9250_source_t
mpu9250_source_t
mpu9250 source enumeration definition
Definition: driver_mpu9250.h:90
mpu9250_set_iic_delay_enable
uint8_t mpu9250_set_iic_delay_enable(mpu9250_handle_t *handle, mpu9250_iic_delay_t delay, mpu9250_bool_t enable)
enable or disable the iic delay
Definition: driver_mpu9250.c:12431
mpu9250_get_iic_transaction_mode
uint8_t mpu9250_get_iic_transaction_mode(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_iic_transaction_mode_t *mode)
get the iic transaction mode
Definition: driver_mpu9250.c:11921
mpu9250_interface_t
mpu9250_interface_t
mpu9250 interface enumeration definition
Definition: driver_mpu9250.h:63
mpu9250_bool_t
mpu9250_bool_t
mpu9250 bool enumeration definition
Definition: driver_mpu9250.h:81
mpu9250_set_iic_transaction_mode
uint8_t mpu9250_set_iic_transaction_mode(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_iic_transaction_mode_t mode)
set the iic transaction mode
Definition: driver_mpu9250.c:11808
mpu9250_get_accelerometer_y_test
uint8_t mpu9250_get_accelerometer_y_test(mpu9250_handle_t *handle, uint8_t *data)
get the accelerometer y test
Definition: driver_mpu9250.c:9306
mpu9250_set_gyro_y_offset
uint8_t mpu9250_set_gyro_y_offset(mpu9250_handle_t *handle, int16_t offset)
set the gyro y offset
Definition: driver_mpu9250.c:9765
mpu9250_get_gyroscope_z_test
uint8_t mpu9250_get_gyroscope_z_test(mpu9250_handle_t *handle, uint8_t *data)
get the gyroscope z test
Definition: driver_mpu9250.c:9166
mpu9250_set_interrupt
uint8_t mpu9250_set_interrupt(mpu9250_handle_t *handle, mpu9250_interrupt_t type, mpu9250_bool_t enable)
enable or disable the interrupt
Definition: driver_mpu9250.c:8873
mpu9250_get_accelerometer_x_test
uint8_t mpu9250_get_accelerometer_x_test(mpu9250_handle_t *handle, uint8_t *data)
get the accelerometer x test
Definition: driver_mpu9250.c:9236
mpu9250_set_motion_threshold
uint8_t mpu9250_set_motion_threshold(mpu9250_handle_t *handle, uint8_t threshold)
set the motion_threshold
Definition: driver_mpu9250.c:9969
mpu9250_set_fsync_interrupt_level
uint8_t mpu9250_set_fsync_interrupt_level(mpu9250_handle_t *handle, mpu9250_pin_level_t level)
set the fsync interrupt level
Definition: driver_mpu9250.c:8626
mpu9250_get_low_pass_filter
uint8_t mpu9250_get_low_pass_filter(mpu9250_handle_t *handle, mpu9250_low_pass_filter_t *filter)
get the low pass filter
Definition: driver_mpu9250.c:7212
mpu9250_get_interrupt_status
uint8_t mpu9250_get_interrupt_status(mpu9250_handle_t *handle, uint8_t *status)
get the interrupt status
Definition: driver_mpu9250.c:8956
mpu9250_set_gyroscope_choice
uint8_t mpu9250_set_gyroscope_choice(mpu9250_handle_t *handle, uint8_t choice)
set the gyroscope choice
Definition: driver_mpu9250.c:7498
mpu9250_set_iic_fifo_enable
uint8_t mpu9250_set_iic_fifo_enable(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_bool_t enable)
enable or disable the iic fifo
Definition: driver_mpu9250.c:10508
mpu9250_deinit
uint8_t mpu9250_deinit(mpu9250_handle_t *handle)
close the chip
Definition: driver_mpu9250.c:4168
mpu9250_read
uint8_t mpu9250_read(mpu9250_handle_t *handle, int16_t(*accel_raw)[3], float(*accel_g)[3], int16_t(*gyro_raw)[3], float(*gyro_dps)[3], int16_t(*mag_raw)[3], float(*mag_ut)[3], uint16_t *len)
read the data
Definition: driver_mpu9250.c:4223
mpu9250_read_temperature
uint8_t mpu9250_read_temperature(mpu9250_handle_t *handle, int16_t(*raw), float *degrees)
read the temperature
Definition: driver_mpu9250.c:4631
mpu9250_get_accelerometer_y_offset
uint8_t mpu9250_get_accelerometer_y_offset(mpu9250_handle_t *handle, int16_t *offset)
get the accelerometer y offset
Definition: driver_mpu9250.c:9524
mpu9250_get_fifo_enable
uint8_t mpu9250_get_fifo_enable(mpu9250_handle_t *handle, mpu9250_fifo_t fifo, mpu9250_bool_t *enable)
get the fifo function status
Definition: driver_mpu9250.c:8261
mpu9250_set_fifo_1024kb
uint8_t mpu9250_set_fifo_1024kb(mpu9250_handle_t *handle)
set fifo 1024kb
Definition: driver_mpu9250.c:7751
mpu9250_get_gyroscope_range
uint8_t mpu9250_get_gyroscope_range(mpu9250_handle_t *handle, mpu9250_gyroscope_range_t *range)
get the gyroscope range
Definition: driver_mpu9250.c:7460
mpu9250_get_interrupt_level
uint8_t mpu9250_get_interrupt_level(mpu9250_handle_t *handle, mpu9250_pin_level_t *level)
get the interrupt level
Definition: driver_mpu9250.c:8343
mpu9250_motion_threshold_convert_to_register
uint8_t mpu9250_motion_threshold_convert_to_register(mpu9250_handle_t *handle, float mg, uint8_t *reg)
convert the motion threshold to the register raw data
Definition: driver_mpu9250.c:10039
mpu9250_set_low_pass_filter
uint8_t mpu9250_set_low_pass_filter(mpu9250_handle_t *handle, mpu9250_low_pass_filter_t filter)
set the low pass filter
Definition: driver_mpu9250.c:7167
mpu9250_set_gyroscope_test
uint8_t mpu9250_set_gyroscope_test(mpu9250_handle_t *handle, mpu9250_axis_t axis, mpu9250_bool_t enable)
set the gyroscope test
Definition: driver_mpu9250.c:7332
mpu9250_set_clock_source
uint8_t mpu9250_set_clock_source(mpu9250_handle_t *handle, mpu9250_clock_source_t clock_source)
set the chip clock source
Definition: driver_mpu9250.c:6367
mpu9250_get_gyroscope_test
uint8_t mpu9250_get_gyroscope_test(mpu9250_handle_t *handle, mpu9250_axis_t axis, mpu9250_bool_t *enable)
get the gyroscope test
Definition: driver_mpu9250.c:7378
mpu9250_device_reset
uint8_t mpu9250_device_reset(mpu9250_handle_t *handle)
reset the chip
Definition: driver_mpu9250.c:6285
mpu9250_set_low_power_accel_output_rate
uint8_t mpu9250_set_low_power_accel_output_rate(mpu9250_handle_t *handle, mpu9250_low_power_accel_output_rate_t rate)
set the low power accel output rate
Definition: driver_mpu9250.c:7968
mpu9250_get_cycle_wake_up
uint8_t mpu9250_get_cycle_wake_up(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the cycle wake up mode status
Definition: driver_mpu9250.c:6576
mpu9250_low_pass_filter_t
mpu9250_low_pass_filter_t
mpu9250 low pass filter enumeration definition
Definition: driver_mpu9250.h:138
mpu9250_get_iic_group_order
uint8_t mpu9250_get_iic_group_order(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_iic_group_order_t *order)
get the iic group order
Definition: driver_mpu9250.c:12115
mpu9250_get_iic4_data_in
uint8_t mpu9250_get_iic4_data_in(mpu9250_handle_t *handle, uint8_t *data)
get the iic4 data in
Definition: driver_mpu9250.c:12954
mpu9250_set_iic_clock
uint8_t mpu9250_set_iic_clock(mpu9250_handle_t *handle, mpu9250_iic_clock_t clk)
set the iic clock
Definition: driver_mpu9250.c:10178
mpu9250_get_disable_iic_slave
uint8_t mpu9250_get_disable_iic_slave(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the iic slave status
Definition: driver_mpu9250.c:6006
mpu9250_get_iic_delay_enable
uint8_t mpu9250_get_iic_delay_enable(mpu9250_handle_t *handle, mpu9250_iic_delay_t delay, mpu9250_bool_t *enable)
get the iic delay status
Definition: driver_mpu9250.c:12477
mpu9250_set_disable_iic_slave
uint8_t mpu9250_set_disable_iic_slave(mpu9250_handle_t *handle, mpu9250_bool_t enable)
enable or disable the iic slave mode
Definition: driver_mpu9250.c:5961
mpu9250_get_iic_transferred_len
uint8_t mpu9250_get_iic_transferred_len(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, uint8_t *len)
get the iic transferred length
Definition: driver_mpu9250.c:12316
mpu9250_get_gyro_x_offset
uint8_t mpu9250_get_gyro_x_offset(mpu9250_handle_t *handle, int16_t *offset)
get the gyro x offset
Definition: driver_mpu9250.c:9728
mpu9250_set_iic_address
uint8_t mpu9250_set_iic_address(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, uint8_t addr_7bit)
set the iic address
Definition: driver_mpu9250.c:10872
mpu9250_fifo_mode
mpu9250_fifo_mode
mpu9250 fifo mode enumeration definition
Definition: driver_mpu9250.h:234
mpu9250_low_power_accel_output_rate_t
mpu9250_low_power_accel_output_rate_t
mpu9250 low power accel output rate enumeration definition
Definition: driver_mpu9250.h:171
mpu9250_get_iic_status
uint8_t mpu9250_get_iic_status(mpu9250_handle_t *handle, uint8_t *status)
get the iic status
Definition: driver_mpu9250.c:12395
mpu9250_read_extern_sensor_data
uint8_t mpu9250_read_extern_sensor_data(mpu9250_handle_t *handle, uint8_t *data, uint8_t len)
read the extern sensor data
Definition: driver_mpu9250.c:12991
mpu9250_set_sample_rate_divider
uint8_t mpu9250_set_sample_rate_divider(mpu9250_handle_t *handle, uint8_t d)
set the sample rate divider
Definition: driver_mpu9250.c:7015
mpu9250_fifo_set
uint8_t mpu9250_fifo_set(mpu9250_handle_t *handle, uint8_t *buf, uint16_t len)
fifo write bytes
Definition: driver_mpu9250.c:6935
mpu9250_get_iic_fifo_enable
uint8_t mpu9250_get_iic_fifo_enable(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_bool_t *enable)
get the iic fifo status
Definition: driver_mpu9250.c:10586
mpu9250_set_gyro_x_offset
uint8_t mpu9250_set_gyro_x_offset(mpu9250_handle_t *handle, int16_t offset)
set the gyro x offset
Definition: driver_mpu9250.c:9690
mpu9250_set_accelerometer_x_offset
uint8_t mpu9250_set_accelerometer_x_offset(mpu9250_handle_t *handle, int16_t offset)
set the accelerometer x offset
Definition: driver_mpu9250.c:9411
mpu9250_iic_read_mode_t
mpu9250_iic_read_mode_t
mpu9250 iic read mode enumeration definition
Definition: driver_mpu9250.h:309
mpu9250_set_accelerometer_x_test
uint8_t mpu9250_set_accelerometer_x_test(mpu9250_handle_t *handle, uint8_t data)
set the accelerometer x test
Definition: driver_mpu9250.c:9201
mpu9250_set_fifo
uint8_t mpu9250_set_fifo(mpu9250_handle_t *handle, mpu9250_bool_t enable)
enable or disable fifo
Definition: driver_mpu9250.c:5763
mpu9250_get_fifo_reset
uint8_t mpu9250_get_fifo_reset(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the fifo reset status
Definition: driver_mpu9250.c:6087
mpu9250_init
uint8_t mpu9250_init(mpu9250_handle_t *handle)
initialize the chip
Definition: driver_mpu9250.c:4009
mpu9250_set_iic_enable
uint8_t mpu9250_set_iic_enable(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_bool_t enable)
enable or disable the iic
Definition: driver_mpu9250.c:11420
mpu9250_get_iic_delay
uint8_t mpu9250_get_iic_delay(mpu9250_handle_t *handle, uint8_t *delay)
get the iic delay
Definition: driver_mpu9250.c:12812
mpu9250_iic4_transaction_mode_t
mpu9250_iic4_transaction_mode_t
mpu9250 iic4 transaction mode enumeration definition
Definition: driver_mpu9250.h:336
mpu9250_set_iic_delay
uint8_t mpu9250_set_iic_delay(mpu9250_handle_t *handle, uint8_t delay)
set the iic delay
Definition: driver_mpu9250.c:12761
mpu9250_set_accelerometer_choice
uint8_t mpu9250_set_accelerometer_choice(mpu9250_handle_t *handle, uint8_t choice)
set the accelerometer choice
Definition: driver_mpu9250.c:7797
mpu9250_iic_clock_t
mpu9250_iic_clock_t
mpu9250 iic clock enumeration definition
Definition: driver_mpu9250.h:286
mpu9250_set_iic4_interrupt
uint8_t mpu9250_set_iic4_interrupt(mpu9250_handle_t *handle, mpu9250_bool_t enable)
enable or disable the iic4 interrupt
Definition: driver_mpu9250.c:12596
mpu9250_set_gyroscope_range
uint8_t mpu9250_set_gyroscope_range(mpu9250_handle_t *handle, mpu9250_gyroscope_range_t range)
set the gyroscope range
Definition: driver_mpu9250.c:7415
mpu9250_iic_group_order_t
mpu9250_iic_group_order_t
mpu9250 iic group order enumeration definition
Definition: driver_mpu9250.h:345
mpu9250_iic_master_reset
uint8_t mpu9250_iic_master_reset(mpu9250_handle_t *handle)
reset the iic master controller
Definition: driver_mpu9250.c:6123
mpu9250_get_device_reset
uint8_t mpu9250_get_device_reset(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the device reset status
Definition: driver_mpu9250.c:6330
mpu9250_get_accelerometer_x_offset
uint8_t mpu9250_get_accelerometer_x_offset(mpu9250_handle_t *handle, int16_t *offset)
get the accelerometer x offset
Definition: driver_mpu9250.c:9449
mpu9250_set_iic_byte_swap
uint8_t mpu9250_set_iic_byte_swap(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_bool_t enable)
enable or disable the iic byte swap
Definition: driver_mpu9250.c:11614
mpu9250_set_gyro_z_offset
uint8_t mpu9250_set_gyro_z_offset(mpu9250_handle_t *handle, int16_t offset)
set the gyro z offset
Definition: driver_mpu9250.c:9840
mpu9250_set_interrupt_pin_type
uint8_t mpu9250_set_interrupt_pin_type(mpu9250_handle_t *handle, mpu9250_pin_type_t type)
set the interrupt pin type
Definition: driver_mpu9250.c:8380
mpu9250_get_fifo
uint8_t mpu9250_get_fifo(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the fifo status
Definition: driver_mpu9250.c:5808
mpu9250_set_iic4_transaction_mode
uint8_t mpu9250_set_iic4_transaction_mode(mpu9250_handle_t *handle, mpu9250_iic4_transaction_mode_t mode)
set the iic4 transaction mode
Definition: driver_mpu9250.c:12678
mpu9250_get_interrupt_latch
uint8_t mpu9250_get_interrupt_latch(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the interrupt latch status
Definition: driver_mpu9250.c:8507
mpu9250_get_gyroscope_choice
uint8_t mpu9250_get_gyroscope_choice(mpu9250_handle_t *handle, uint8_t *choice)
get the gyroscope choice
Definition: driver_mpu9250.c:7549
mpu9250_set_gyroscope_z_test
uint8_t mpu9250_set_gyroscope_z_test(mpu9250_handle_t *handle, uint8_t data)
set the gyroscope z test
Definition: driver_mpu9250.c:9131
mpu9250_set_iic_master
uint8_t mpu9250_set_iic_master(mpu9250_handle_t *handle, mpu9250_bool_t enable)
enable or disable the iic master mode
Definition: driver_mpu9250.c:5879
mpu9250_get_iic_register
uint8_t mpu9250_get_iic_register(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, uint8_t *reg)
get the iic register
Definition: driver_mpu9250.c:11182
mpu9250_set_accelerometer_range
uint8_t mpu9250_set_accelerometer_range(mpu9250_handle_t *handle, mpu9250_accelerometer_range_t range)
set the accelerometer range
Definition: driver_mpu9250.c:7670
mpu9250_gyro_offset_convert_to_register
uint8_t mpu9250_gyro_offset_convert_to_register(mpu9250_handle_t *handle, float dps, int16_t *reg)
convert the gyro offset to the register raw data
Definition: driver_mpu9250.c:9915
mpu9250_get_iic_wait_for_external_sensor
uint8_t mpu9250_get_iic_wait_for_external_sensor(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
get the iic wait for external sensor status
Definition: driver_mpu9250.c:10387
mpu9250_iic_mode_t
mpu9250_iic_mode_t
mpu9250 iic mode enumeration definition
Definition: driver_mpu9250.h:318
mpu9250_axis_t
mpu9250_axis_t
mpu9250 axis enumeration definition
Definition: driver_mpu9250.h:190
mpu9250_get_iic_clock
uint8_t mpu9250_get_iic_clock(mpu9250_handle_t *handle, mpu9250_iic_clock_t *clk)
get the iic clock
Definition: driver_mpu9250.c:10223
mpu9250_accelerometer_low_pass_filter_t
mpu9250_accelerometer_low_pass_filter_t
mpu9250 accelerometer low pass filter enumeration definition
Definition: driver_mpu9250.h:155
mpu9250_set_iic_group_order
uint8_t mpu9250_set_iic_group_order(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, mpu9250_iic_group_order_t order)
set the iic group order
Definition: driver_mpu9250.c:12002
mpu9250_get_motion_threshold
uint8_t mpu9250_get_motion_threshold(mpu9250_handle_t *handle, uint8_t *threshold)
get the motion_threshold
Definition: driver_mpu9250.c:10004
mpu9250_set_sleep
uint8_t mpu9250_set_sleep(mpu9250_handle_t *handle, mpu9250_bool_t enable)
enable or disable the sleep mode
Definition: driver_mpu9250.c:6613
mpu9250_get_iic_address
uint8_t mpu9250_get_iic_address(mpu9250_handle_t *handle, mpu9250_iic_slave_t slave, uint8_t *addr_7bit)
get the iic address
Definition: driver_mpu9250.c:11004
mpu9250_get_low_power_accel_output_rate
uint8_t mpu9250_get_low_power_accel_output_rate(mpu9250_handle_t *handle, mpu9250_low_power_accel_output_rate_t *rate)
get the low power accel output rate
Definition: driver_mpu9250.c:8013
mpu9250_set_iic4_enable
uint8_t mpu9250_set_iic4_enable(mpu9250_handle_t *handle, mpu9250_bool_t enable)
enable or disable the iic4
Definition: driver_mpu9250.c:12514
mpu9250_pin_level_t
mpu9250_pin_level_t
mpu9250 pin level enumeration definition
Definition: driver_mpu9250.h:244
mpu9250_fifo_t
mpu9250_fifo_t
mpu9250 fifo enumeration definition
Definition: driver_mpu9250.h:222
mpu9250_clock_source_t
mpu9250_clock_source_t
mpu9250 clock source enumeration definition
Definition: driver_mpu9250.h:103
mpu9250_force_fifo_reset
uint8_t mpu9250_force_fifo_reset(mpu9250_handle_t *handle)
force reset the fifo
Definition: driver_mpu9250.c:5844
MPU9250_IIC_SLAVE_3
@ MPU9250_IIC_SLAVE_3
Definition: driver_mpu9250.h:278
MPU9250_IIC_SLAVE_2
@ MPU9250_IIC_SLAVE_2
Definition: driver_mpu9250.h:277
MPU9250_IIC_SLAVE_4
@ MPU9250_IIC_SLAVE_4
Definition: driver_mpu9250.h:279
MPU9250_IIC_SLAVE_0
@ MPU9250_IIC_SLAVE_0
Definition: driver_mpu9250.h:275
MPU9250_IIC_SLAVE_1
@ MPU9250_IIC_SLAVE_1
Definition: driver_mpu9250.h:276
MPU9250_INTERRUPT_MOTION
@ MPU9250_INTERRUPT_MOTION
Definition: driver_mpu9250.h:263
MPU9250_INTERRUPT_DATA_READY
@ MPU9250_INTERRUPT_DATA_READY
Definition: driver_mpu9250.h:267
MPU9250_INTERRUPT_FSYNC_INT
@ MPU9250_INTERRUPT_FSYNC_INT
Definition: driver_mpu9250.h:265
MPU9250_INTERRUPT_DMP
@ MPU9250_INTERRUPT_DMP
Definition: driver_mpu9250.h:266
MPU9250_INTERRUPT_FIFO_OVERFLOW
@ MPU9250_INTERRUPT_FIFO_OVERFLOW
Definition: driver_mpu9250.h:264
MPU9250_INTERFACE_IIC
@ MPU9250_INTERFACE_IIC
Definition: driver_mpu9250.h:64
MPU9250_BOOL_TRUE
@ MPU9250_BOOL_TRUE
Definition: driver_mpu9250.h:83
MPU9250_BOOL_FALSE
@ MPU9250_BOOL_FALSE
Definition: driver_mpu9250.h:82
MPU9250_AXIS_X
@ MPU9250_AXIS_X
Definition: driver_mpu9250.h:193
MPU9250_AXIS_Z
@ MPU9250_AXIS_Z
Definition: driver_mpu9250.h:191
MPU9250_AXIS_Y
@ MPU9250_AXIS_Y
Definition: driver_mpu9250.h:192
mpu9250_dmp_set_accel_bias
uint8_t mpu9250_dmp_set_accel_bias(mpu9250_handle_t *handle, int32_t bias[3])
dmp set the accel bias
Definition: driver_mpu9250.c:2289
mpu9250_dmp_set_tap_callback
uint8_t mpu9250_dmp_set_tap_callback(mpu9250_handle_t *handle, void(*callback)(uint8_t count, uint8_t direction))
dmp set the tap callback
Definition: driver_mpu9250.c:3699
mpu9250_dmp_get_fifo_rate
uint8_t mpu9250_dmp_get_fifo_rate(mpu9250_handle_t *handle, uint16_t *rate)
dmp get the fifo rate
Definition: driver_mpu9250.c:3004
mpu9250_dmp_set_gyro_bias
uint8_t mpu9250_dmp_set_gyro_bias(mpu9250_handle_t *handle, int32_t bias[3])
dmp set the gyro bias
Definition: driver_mpu9250.c:2199
mpu9250_dmp_set_shake_reject_timeout
uint8_t mpu9250_dmp_set_shake_reject_timeout(mpu9250_handle_t *handle, uint16_t ms)
dmp set the shake reject timeout
Definition: driver_mpu9250.c:1352
mpu9250_dmp_get_pedometer_walk_time
uint8_t mpu9250_dmp_get_pedometer_walk_time(mpu9250_handle_t *handle, uint32_t *ms)
dmp get the pedometer walk time
Definition: driver_mpu9250.c:1214
mpu9250_dmp_get_tap_time_multi
uint8_t mpu9250_dmp_get_tap_time_multi(mpu9250_handle_t *handle, uint16_t *ms)
dmp get max time between taps to register as a multi tap
Definition: driver_mpu9250.c:1681
mpu9250_dmp_set_6x_quaternion
uint8_t mpu9250_dmp_set_6x_quaternion(mpu9250_handle_t *handle, mpu9250_bool_t enable)
dmp enable or disable generate 6 axis quaternions from dmp
Definition: driver_mpu9250.c:2053
mpu9250_dmp_set_orientation
uint8_t mpu9250_dmp_set_orientation(mpu9250_handle_t *handle, int8_t mat[9])
dmp set the orientation
Definition: driver_mpu9250.c:2392
mpu9250_dmp_set_fifo_rate
uint8_t mpu9250_dmp_set_fifo_rate(mpu9250_handle_t *handle, uint16_t rate)
dmp set the fifo rate
Definition: driver_mpu9250.c:2938
mpu9250_dmp_load_firmware
uint8_t mpu9250_dmp_load_firmware(mpu9250_handle_t *handle)
load the dmp firmware
Definition: driver_mpu9250.c:1087
mpu9250_dmp_set_3x_quaternion
uint8_t mpu9250_dmp_set_3x_quaternion(mpu9250_handle_t *handle, mpu9250_bool_t enable)
dmp enable or disable generate 3 axis quaternions from dmp
Definition: driver_mpu9250.c:1976
mpu9250_dmp_set_tap_axes
uint8_t mpu9250_dmp_set_tap_axes(mpu9250_handle_t *handle, mpu9250_axis_t axis, mpu9250_bool_t enable)
dmp enable or disable the tap axes
Definition: driver_mpu9250.c:3051
mpu9250_dmp_get_tap_axes
uint8_t mpu9250_dmp_get_tap_axes(mpu9250_handle_t *handle, mpu9250_axis_t axis, mpu9250_bool_t *enable)
dmp get the tap axes status
Definition: driver_mpu9250.c:3112
mpu9250_dmp_set_enable
uint8_t mpu9250_dmp_set_enable(mpu9250_handle_t *handle, mpu9250_bool_t enable)
enable or disable the dmp
Definition: driver_mpu9250.c:3767
mpu9250_dmp_set_feature
uint8_t mpu9250_dmp_set_feature(mpu9250_handle_t *handle, uint16_t mask)
dmp enable or disable the dmp feature
Definition: driver_mpu9250.c:2496
mpu9250_dmp_set_shake_reject_thresh
uint8_t mpu9250_dmp_set_shake_reject_thresh(mpu9250_handle_t *handle, uint16_t dps)
dmp set the shake reject thresh
Definition: driver_mpu9250.c:1536
mpu9250_dmp_set_orient_callback
uint8_t mpu9250_dmp_set_orient_callback(mpu9250_handle_t *handle, void(*callback)(uint8_t orientation))
dmp set the orient callback
Definition: driver_mpu9250.c:3733
mpu9250_dmp_set_interrupt_mode
uint8_t mpu9250_dmp_set_interrupt_mode(mpu9250_handle_t *handle, mpu9250_dmp_interrupt_mode_t mode)
dmp set the interrupt mode
Definition: driver_mpu9250.c:2130
mpu9250_dmp_get_shake_reject_time
uint8_t mpu9250_dmp_get_shake_reject_time(mpu9250_handle_t *handle, uint16_t *ms)
dmp get the shake reject time
Definition: driver_mpu9250.c:1491
mpu9250_dmp_get_pedometer_step_count
uint8_t mpu9250_dmp_get_pedometer_step_count(mpu9250_handle_t *handle, uint32_t *count)
dmp get the pedometer step count
Definition: driver_mpu9250.c:1307
mpu9250_dmp_set_pedometer_step_count
uint8_t mpu9250_dmp_set_pedometer_step_count(mpu9250_handle_t *handle, uint32_t count)
dmp set the pedometer step count
Definition: driver_mpu9250.c:1259
mpu9250_dmp_get_tap_thresh
uint8_t mpu9250_dmp_get_tap_thresh(mpu9250_handle_t *handle, mpu9250_axis_t axis, uint16_t *mg_ms)
dmp get the tap thresh
Definition: driver_mpu9250.c:3313
mpu9250_dmp_set_shake_reject_time
uint8_t mpu9250_dmp_set_shake_reject_time(mpu9250_handle_t *handle, uint16_t ms)
dmp set the shake reject time
Definition: driver_mpu9250.c:1444
mpu9250_dmp_get_min_tap_count
uint8_t mpu9250_dmp_get_min_tap_count(mpu9250_handle_t *handle, uint8_t *cnt)
dmp get the min tap count
Definition: driver_mpu9250.c:1869
mpu9250_dmp_get_tap_time
uint8_t mpu9250_dmp_get_tap_time(mpu9250_handle_t *handle, uint16_t *ms)
dmp get the tap time
Definition: driver_mpu9250.c:1773
mpu9250_dmp_interrupt_mode_t
mpu9250_dmp_interrupt_mode_t
mpu9250 dmp interrupt mode enumeration definition
Definition: driver_mpu9250.h:444
mpu9250_dmp_set_gyro_calibrate
uint8_t mpu9250_dmp_set_gyro_calibrate(mpu9250_handle_t *handle, mpu9250_bool_t enable)
dmp enable or disable gyro calibrate
Definition: driver_mpu9250.c:1913
mpu9250_dmp_get_shake_reject_timeout
uint8_t mpu9250_dmp_get_shake_reject_timeout(mpu9250_handle_t *handle, uint16_t *ms)
dmp get the shake reject timeout
Definition: driver_mpu9250.c:1399
mpu9250_dmp_gyro_accel_raw_offset_convert
uint8_t mpu9250_dmp_gyro_accel_raw_offset_convert(mpu9250_handle_t *handle, int32_t gyro_offset_raw[3], int32_t accel_offset_raw[3], int32_t gyro_offset[3], int32_t accel_offset[3])
dmp gyro accel raw offset convert
Definition: driver_mpu9250.c:3822
mpu9250_dmp_set_tap_time
uint8_t mpu9250_dmp_set_tap_time(mpu9250_handle_t *handle, uint16_t ms)
dmp set the tap time
Definition: driver_mpu9250.c:1726
mpu9250_dmp_set_tap_thresh
uint8_t mpu9250_dmp_set_tap_thresh(mpu9250_handle_t *handle, mpu9250_axis_t axis, uint16_t mg_ms)
dmp set the tap thresh
Definition: driver_mpu9250.c:3168
mpu9250_dmp_set_min_tap_count
uint8_t mpu9250_dmp_set_min_tap_count(mpu9250_handle_t *handle, uint8_t cnt)
dmp set the min tap count
Definition: driver_mpu9250.c:1819
mpu9250_dmp_set_pedometer_walk_time
uint8_t mpu9250_dmp_set_pedometer_walk_time(mpu9250_handle_t *handle, uint32_t ms)
dmp set the pedometer walk time
Definition: driver_mpu9250.c:1165
mpu9250_dmp_read
uint8_t mpu9250_dmp_read(mpu9250_handle_t *handle, int16_t(*accel_raw)[3], float(*accel_g)[3], int16_t(*gyro_raw)[3], float(*gyro_dps)[3], int32_t(*quat)[4], float *pitch, float *roll, float *yaw, uint16_t *l)
dmp read the data
Definition: driver_mpu9250.c:3429
mpu9250_dmp_set_tap_time_multi
uint8_t mpu9250_dmp_set_tap_time_multi(mpu9250_handle_t *handle, uint16_t ms)
dmp set max time between taps to register as a multi tap
Definition: driver_mpu9250.c:1634
MPU9250_DMP_CODE_SIZE
#define MPU9250_DMP_CODE_SIZE
mpu9250 dmp code definition
Definition: driver_mpu9250_code.h:56
mpu9250_dmp_get_shake_reject_thresh
uint8_t mpu9250_dmp_get_shake_reject_thresh(mpu9250_handle_t *handle, uint16_t *dps)
dmp get the shake reject thresh
Definition: driver_mpu9250.c:1586
MPU9250_DMP_FEATURE_6X_QUAT
@ MPU9250_DMP_FEATURE_6X_QUAT
Definition: driver_mpu9250.h:458
MPU9250_DMP_FEATURE_3X_QUAT
@ MPU9250_DMP_FEATURE_3X_QUAT
Definition: driver_mpu9250.h:456
MPU9250_DMP_FEATURE_GYRO_CAL
@ MPU9250_DMP_FEATURE_GYRO_CAL
Definition: driver_mpu9250.h:459
MPU9250_DMP_FEATURE_PEDOMETER
@ MPU9250_DMP_FEATURE_PEDOMETER
Definition: driver_mpu9250.h:457
MPU9250_DMP_FEATURE_SEND_CAL_GYRO
@ MPU9250_DMP_FEATURE_SEND_CAL_GYRO
Definition: driver_mpu9250.h:462
MPU9250_DMP_FEATURE_SEND_RAW_ACCEL
@ MPU9250_DMP_FEATURE_SEND_RAW_ACCEL
Definition: driver_mpu9250.h:460
MPU9250_DMP_FEATURE_TAP
@ MPU9250_DMP_FEATURE_TAP
Definition: driver_mpu9250.h:454
MPU9250_DMP_FEATURE_ORIENT
@ MPU9250_DMP_FEATURE_ORIENT
Definition: driver_mpu9250.h:455
MPU9250_DMP_INTERRUPT_MODE_CONTINUOUS
@ MPU9250_DMP_INTERRUPT_MODE_CONTINUOUS
Definition: driver_mpu9250.h:445
mpu9250_set_reg
uint8_t mpu9250_set_reg(mpu9250_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
Definition: driver_mpu9250.c:13034
mpu9250_get_reg
uint8_t mpu9250_get_reg(mpu9250_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
Definition: driver_mpu9250.c:13061
mpu9250_mag_get_status1
uint8_t mpu9250_mag_get_status1(mpu9250_handle_t *handle, uint8_t *status)
magnetometer get the status1
Definition: driver_mpu9250.c:5102
mpu9250_magnetometer_bits_t
mpu9250_magnetometer_bits_t
mpu9250 magnetometer bits enumeration definition
Definition: driver_mpu9250.h:426
mpu9250_mag_get_status2
uint8_t mpu9250_mag_get_status2(mpu9250_handle_t *handle, uint8_t *status)
magnetometer get the status2
Definition: driver_mpu9250.c:5144
mpu9250_mag_set_mode
uint8_t mpu9250_mag_set_mode(mpu9250_handle_t *handle, mpu9250_magnetometer_mode_t mode)
magnetometer set the mode
Definition: driver_mpu9250.c:5186
mpu9250_mag_iic_disable
uint8_t mpu9250_mag_iic_disable(mpu9250_handle_t *handle)
magnetometer disable the iic
Definition: driver_mpu9250.c:5569
mpu9250_mag_get_mode
uint8_t mpu9250_mag_get_mode(mpu9250_handle_t *handle, mpu9250_magnetometer_mode_t *mode)
magnetometer get the mode
Definition: driver_mpu9250.c:5238
mpu9250_mag_get_self_test
uint8_t mpu9250_mag_get_self_test(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
magnetometer get the self test status
Definition: driver_mpu9250.c:5526
mpu9250_mag_get_bits
uint8_t mpu9250_mag_get_bits(mpu9250_handle_t *handle, mpu9250_magnetometer_bits_t *bits)
magnetometer get the bits
Definition: driver_mpu9250.c:5334
mpu9250_mag_set_bits
uint8_t mpu9250_mag_set_bits(mpu9250_handle_t *handle, mpu9250_magnetometer_bits_t bits)
magnetometer set the bits
Definition: driver_mpu9250.c:5282
mpu9250_magnetometer_mode_t
mpu9250_magnetometer_mode_t
mpu9250 magnetometer mode enumeration definition
Definition: driver_mpu9250.h:412
mpu9250_mag_set_reset
uint8_t mpu9250_mag_set_reset(mpu9250_handle_t *handle, mpu9250_bool_t enable)
magnetometer enable or disable reset
Definition: driver_mpu9250.c:5378
mpu9250_mag_get_info
uint8_t mpu9250_mag_get_info(mpu9250_handle_t *handle, uint8_t *info)
magnetometer get the information
Definition: driver_mpu9250.c:5060
mpu9250_mag_get_asa
uint8_t mpu9250_mag_get_asa(mpu9250_handle_t *handle, uint8_t asa[3])
magnetometer get the asa data
Definition: driver_mpu9250.c:5613
mpu9250_mag_get_reset
uint8_t mpu9250_mag_get_reset(mpu9250_handle_t *handle, mpu9250_bool_t *enable)
magnetometer get the reset status
Definition: driver_mpu9250.c:5430
mpu9250_mag_init
uint8_t mpu9250_mag_init(mpu9250_handle_t *handle)
initialize the magnetometer of mpu9250
Definition: driver_mpu9250.c:4742
mpu9250_mag_deinit
uint8_t mpu9250_mag_deinit(mpu9250_handle_t *handle)
magnetometer deinit
Definition: driver_mpu9250.c:4894
mpu9250_mag_set_fifo_mode
uint8_t mpu9250_mag_set_fifo_mode(mpu9250_handle_t *handle)
magnetometer set into fifo mode
Definition: driver_mpu9250.c:5654
mpu9250_mag_set_self_test
uint8_t mpu9250_mag_set_self_test(mpu9250_handle_t *handle, mpu9250_bool_t enable)
magnetometer enable or disable self test
Definition: driver_mpu9250.c:5474
mpu9250_mag_read
uint8_t mpu9250_mag_read(mpu9250_handle_t *handle, int16_t mag_raw[3], float mag_ut[3])
mag read the data
Definition: driver_mpu9250.c:4995
mpu9250_handle_s
mpu9250 handle structure definition
Definition: driver_mpu9250.h:502
mpu9250_handle_s::iic_spi
uint8_t iic_spi
Definition: driver_mpu9250.h:520
mpu9250_handle_s::buf
uint8_t buf[1024]
Definition: driver_mpu9250.h:524
mpu9250_handle_s::dmp_inited
uint8_t dmp_inited
Definition: driver_mpu9250.h:521
mpu9250_handle_s::inited
uint8_t inited
Definition: driver_mpu9250.h:517
mpu9250_handle_s::dmp_tap_callback
void(* dmp_tap_callback)(uint8_t count, uint8_t direction)
Definition: driver_mpu9250.h:515
mpu9250_handle_s::spi_init
uint8_t(* spi_init)(void)
Definition: driver_mpu9250.h:508
mpu9250_handle_s::delay_ms
void(* delay_ms)(uint32_t ms)
Definition: driver_mpu9250.h:512
mpu9250_handle_s::spi_read
uint8_t(* spi_read)(uint8_t reg, uint8_t *buf, uint16_t len)
Definition: driver_mpu9250.h:510
mpu9250_handle_s::receive_callback
void(* receive_callback)(uint8_t type)
Definition: driver_mpu9250.h:514
mpu9250_handle_s::spi_write
uint8_t(* spi_write)(uint8_t reg, uint8_t *buf, uint16_t len)
Definition: driver_mpu9250.h:511
mpu9250_handle_s::mag_asa
uint8_t mag_asa[3]
Definition: driver_mpu9250.h:519
mpu9250_handle_s::mag_inited
uint8_t mag_inited
Definition: driver_mpu9250.h:518
mpu9250_handle_s::debug_print
void(* debug_print)(const char *const fmt,...)
Definition: driver_mpu9250.h:513
mpu9250_handle_s::mask
uint16_t mask
Definition: driver_mpu9250.h:523
mpu9250_handle_s::iic_init
uint8_t(* iic_init)(void)
Definition: driver_mpu9250.h:504
mpu9250_handle_s::spi_deinit
uint8_t(* spi_deinit)(void)
Definition: driver_mpu9250.h:509
mpu9250_handle_s::orient
uint16_t orient
Definition: driver_mpu9250.h:522
mpu9250_handle_s::dmp_orient_callback
void(* dmp_orient_callback)(uint8_t orientation)
Definition: driver_mpu9250.h:516
mpu9250_handle_s::iic_write
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
Definition: driver_mpu9250.h:507
mpu9250_handle_s::iic_addr
uint8_t iic_addr
Definition: driver_mpu9250.h:503
mpu9250_handle_s::iic_read
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
Definition: driver_mpu9250.h:506
mpu9250_handle_s::iic_deinit
uint8_t(* iic_deinit)(void)
Definition: driver_mpu9250.h:505
mpu9250_info_s
mpu9250 information structure definition
Definition: driver_mpu9250.h:531
mpu9250_info_s::temperature_max
float temperature_max
Definition: driver_mpu9250.h:539
mpu9250_info_s::supply_voltage_max_v
float supply_voltage_max_v
Definition: driver_mpu9250.h:536
mpu9250_info_s::driver_version
uint32_t driver_version
Definition: driver_mpu9250.h:540
mpu9250_info_s::temperature_min
float temperature_min
Definition: driver_mpu9250.h:538
mpu9250_info_s::max_current_ma
float max_current_ma
Definition: driver_mpu9250.h:537
mpu9250_info_s::manufacturer_name
char manufacturer_name[32]
Definition: driver_mpu9250.h:533
mpu9250_info_s::supply_voltage_min_v
float supply_voltage_min_v
Definition: driver_mpu9250.h:535
mpu9250_info_s::interface
char interface[8]
Definition: driver_mpu9250.h:534
mpu9250_info_s::chip_name
char chip_name[32]
Definition: driver_mpu9250.h:532