LibDriver MPU6500
Loading...
Searching...
No Matches
driver_mpu6500.c
Go to the documentation of this file.
1
36
37#include "driver_mpu6500.h"
38#include "driver_mpu6500_code.h"
39#include <math.h>
40
44#define CHIP_NAME "TDK MPU6500"
45#define MANUFACTURER_NAME "TDK"
46#define SUPPLY_VOLTAGE_MIN 1.71f
47#define SUPPLY_VOLTAGE_MAX 3.45f
48#define MAX_CURRENT 3.2f
49#define TEMPERATURE_MIN -40.0f
50#define TEMPERATURE_MAX 85.0f
51#define DRIVER_VERSION 1000
52
56#define MPU6500_REG_SELF_TEST_X_GYRO 0x00
57#define MPU6500_REG_SELF_TEST_Y_GYRO 0x01
58#define MPU6500_REG_SELF_TEST_Z_GYRO 0x02
59#define MPU6500_REG_SELF_TEST_X_ACCEL 0x0D
60#define MPU6500_REG_SELF_TEST_Y_ACCEL 0x0E
61#define MPU6500_REG_SELF_TEST_Z_ACCEL 0x0F
62#define MPU6500_REG_XG_OFFSET_H 0x13
63#define MPU6500_REG_XG_OFFSET_L 0x14
64#define MPU6500_REG_YG_OFFSET_H 0x15
65#define MPU6500_REG_YG_OFFSET_L 0x16
66#define MPU6500_REG_ZG_OFFSET_H 0x17
67#define MPU6500_REG_ZG_OFFSET_L 0x18
68#define MPU6500_REG_SMPRT_DIV 0x19
69#define MPU6500_REG_CONFIG 0x1A
70#define MPU6500_REG_GYRO_CONFIG 0x1B
71#define MPU6500_REG_ACCEL_CONFIG 0x1C
72#define MPU6500_REG_ACCEL_CONFIG2 0x1D
73#define MPU6500_REG_LP_ACCEL_ODR 0x1E
74#define MPU6500_REG_WOM_THR 0x1F
75#define MPU6500_REG_MOTION_DURATION 0x20
76#define MPU6500_REG_FIFO_EN 0x23
77#define MPU6500_REG_I2C_MST_CTRL 0x24
78#define MPU6500_REG_I2C_MST_STATUS 0x36
79#define MPU6500_REG_I2C_MST_DELAY_CTRL 0x67
80#define MPU6500_REG_I2C_SLV0_ADDR 0x25
81#define MPU6500_REG_I2C_SLV0_REG 0x26
82#define MPU6500_REG_I2C_SLV0_CTRL 0x27
83#define MPU6500_REG_I2C_SLV0_DO 0x63
84#define MPU6500_REG_I2C_SLV1_ADDR 0x28
85#define MPU6500_REG_I2C_SLV1_REG 0x29
86#define MPU6500_REG_I2C_SLV1_CTRL 0x2A
87#define MPU6500_REG_I2C_SLV1_DO 0x64
88#define MPU6500_REG_I2C_SLV2_ADDR 0x2B
89#define MPU6500_REG_I2C_SLV2_REG 0x2C
90#define MPU6500_REG_I2C_SLV2_CTRL 0x2D
91#define MPU6500_REG_I2C_SLV2_DO 0x65
92#define MPU6500_REG_I2C_SLV3_ADDR 0x2E
93#define MPU6500_REG_I2C_SLV3_REG 0x2F
94#define MPU6500_REG_I2C_SLV3_CTRL 0x30
95#define MPU6500_REG_I2C_SLV3_DO 0x66
96#define MPU6500_REG_I2C_SLV4_ADDR 0x31
97#define MPU6500_REG_I2C_SLV4_REG 0x32
98#define MPU6500_REG_I2C_SLV4_CTRL 0x34
99#define MPU6500_REG_I2C_SLV4_DO 0x33
100#define MPU6500_REG_I2C_SLV4_DI 0x35
101#define MPU6500_REG_EXT_SENS_DATA_00 0x49
102#define MPU6500_REG_INT_PIN_CFG 0x37
103#define MPU6500_REG_INT_ENABLE 0x38
104#define MPU6500_REG_INT_STATUS 0x3A
105#define MPU6500_REG_ACCEL_XOUT_H 0x3B
106#define MPU6500_REG_ACCEL_XOUT_L 0x3C
107#define MPU6500_REG_ACCEL_YOUT_H 0x3D
108#define MPU6500_REG_ACCEL_YOUT_L 0x3E
109#define MPU6500_REG_ACCEL_ZOUT_H 0x3F
110#define MPU6500_REG_ACCEL_ZOUT_L 0x40
111#define MPU6500_REG_TEMP_OUT_H 0x41
112#define MPU6500_REG_TEMP_OUT_L 0x42
113#define MPU6500_REG_GYRO_XOUT_H 0x43
114#define MPU6500_REG_GYRO_XOUT_L 0x44
115#define MPU6500_REG_GYRO_YOUT_H 0x45
116#define MPU6500_REG_GYRO_YOUT_L 0x46
117#define MPU6500_REG_GYRO_ZOUT_H 0x47
118#define MPU6500_REG_GYRO_ZOUT_L 0x48
119#define MPU6500_REG_SIGNAL_PATH_RESET 0x68
120#define MPU6500_REG_MOT_DETECT_CTRL 0x69
121#define MPU6500_REG_USER_CTRL 0x6A
122#define MPU6500_REG_PWR_MGMT_1 0x6B
123#define MPU6500_REG_PWR_MGMT_2 0x6C
124#define MPU6500_REG_BANK_SEL 0x6D
125#define MPU6500_REG_MEM 0x6F
126#define MPU6500_REG_PROGRAM_START 0x70
127#define MPU6500_REG_FIFO_COUNTH 0x72
128#define MPU6500_REG_FIFO_COUNTL 0x73
129#define MPU6500_REG_R_W 0x74
130#define MPU6500_REG_WHO_AM_I 0x75
131#define MPU6500_REG_XA_OFFSET_H 0x77
132#define MPU6500_REG_XA_OFFSET_L 0x78
133#define MPU6500_REG_YA_OFFSET_H 0x7A
134#define MPU6500_REG_YA_OFFSET_L 0x7B
135#define MPU6500_REG_ZA_OFFSET_H 0x7D
136#define MPU6500_REG_ZA_OFFSET_L 0x7E
137
141#define MPU6500_DMP_SAMPLE_RATE 200
142#define MPU6500_DMP_GYRO_SF (46850825LL * 200 / MPU6500_DMP_SAMPLE_RATE)
143#define MPU6500_DMP_D_PEDSTD_TIMECTR 964
144#define MPU6500_DMP_D_PEDSTD_STEPCTR (768 + 0x60)
145#define MPU6500_DMP_D_1_36 (256 + 36)
146#define MPU6500_DMP_D_1_40 (256 + 40)
147#define MPU6500_DMP_D_1_44 (256 + 44)
148#define MPU6500_DMP_D_1_72 (256 + 72)
149#define MPU6500_DMP_D_1_79 (256 + 79)
150#define MPU6500_DMP_D_1_88 (256 + 88)
151#define MPU6500_DMP_D_1_90 (256 + 90)
152#define MPU6500_DMP_D_1_92 (256 + 92)
153#define MPU6500_DMP_D_1_218 (256 + 218)
154#define MPU6500_DMP_D_0_22 (512 + 22)
155#define MPU6500_DMP_D_0_104 104
156#define MPU6500_DMP_TAPW_MIN 478
157#define MPU6500_DMP_TAP_THX 468
158#define MPU6500_DMP_TAP_THY 472
159#define MPU6500_DMP_TAP_THZ 476
160#define MPU6500_DMP_CFG_6 2753
161#define MPU6500_DMP_CFG_8 2718
162#define MPU6500_DMP_CFG_MOTION_BIAS 1208
163#define MPU6500_DMP_CFG_LP_QUAT 2712
164#define MPU6500_DMP_CFG_FIFO_ON_EVENT 2690
165#define MPU6500_DMP_FCFG_1 1062
166#define MPU6500_DMP_FCFG_2 1066
167#define MPU6500_DMP_FCFG_3 1088
168#define MPU6500_DMP_FCFG_7 1073
169#define MPU6500_DMP_D_EXT_GYRO_BIAS_X (61 * 16)
170#define MPU6500_DMP_D_EXT_GYRO_BIAS_Y (61 * 16 + 4)
171#define MPU6500_DMP_D_EXT_GYRO_BIAS_Z (61 * 16 + 8)
172#define MPU6500_DMP_D_ACCEL_BIAS 660
173#define MPU6500_DMP_FEATURE_SEND_ANY_GYRO (MPU6500_DMP_FEATURE_SEND_RAW_GYRO | \
174 MPU6500_DMP_FEATURE_SEND_CAL_GYRO)
175#define MPU6500_DMP_CFG_15 2727
176#define MPU6500_DMP_CFG_27 2742
177#define MPU6500_DMP_CFG_GYRO_RAW_DATA 2722
178#define MPU6500_DMP_CFG_20 2224
179#define MPU6500_DMP_CFG_ORIENT_INT 1853
180#define MPU6500_DMP_QUAT_ERROR_THRESH (1L << 24)
181#define MPU6500_DMP_QUAT_MAG_SQ_NORMALIZED (1L << 28)
182#define MPU6500_DMP_QUAT_MAG_SQ_MIN (MPU6500_DMP_QUAT_MAG_SQ_NORMALIZED - \
183 MPU6500_DMP_QUAT_ERROR_THRESH)
184#define MPU6500_DMP_QUAT_MAG_SQ_MAX (MPU6500_DMP_QUAT_MAG_SQ_NORMALIZED + \
185 MPU6500_DMP_QUAT_ERROR_THRESH)
186#define MPU6500_DMP_INT_SRC_TAP 0x01
187#define MPU6500_DMP_INT_SRC_ORIENT 0x08
188#define MPU6500_DMP_TAP_THRESH 250
189#define MPU6500_DMP_TAP_MIN_TAP_COUNT 1
190#define MPU6500_DMP_TAP_TIME 100
191#define MPU6500_DMP_TAP_TIME_MULTI 200
192#define MPU6500_DMP_SHAKE_REJECT_THRESH 200
193#define MPU6500_DMP_SHAKE_REJECT_TIME 40
194#define MPU6500_DMP_SHAKE_REJECT_TIMEOUT 10
195
199#define MIN(a, b) (((a) < (b)) ? (a) : (b))
200
204static uint16_t gs_st_tb[256] =
205{
206 2620, 2646, 2672, 2699, 2726, 2753, 2781, 2808,
207 2837, 2865, 2894, 2923, 2952, 2981, 3011, 3041,
208 3072, 3102, 3133, 3165, 3196, 3228, 3261, 3293,
209 3326, 3359, 3393, 3427, 3461, 3496, 3531, 3566,
210 3602, 3638, 3674, 3711, 3748, 3786, 3823, 3862,
211 3900, 3939, 3979, 4019, 4059, 4099, 4140, 4182,
212 4224, 4266, 4308, 4352, 4395, 4439, 4483, 4528,
213 4574, 4619, 4665, 4712, 4759, 4807, 4855, 4903,
214 4953, 5002, 5052, 5103, 5154, 5205, 5257, 5310,
215 5363, 5417, 5471, 5525, 5581, 5636, 5693, 5750,
216 5807, 5865, 5924, 5983, 6043, 6104, 6165, 6226,
217 6289, 6351, 6415, 6479, 6544, 6609, 6675, 6742,
218 6810, 6878, 6946, 7016, 7086, 7157, 7229, 7301,
219 7374, 7448, 7522, 7597, 7673, 7750, 7828, 7906,
220 7985, 8065, 8145, 8227, 8309, 8392, 8476, 8561,
221 8647, 8733, 8820, 8909, 8998, 9088, 9178, 9270,
222 9363, 9457, 9551, 9647, 9743, 9841, 9939, 10038,
223 10139, 10240, 10343, 10446, 10550, 10656, 10763, 10870,
224 10979, 11089, 11200, 11312, 11425, 11539, 11654, 11771,
225 11889, 12008, 12128, 12249, 12371, 12495, 12620, 12746,
226 12874, 13002, 13132, 13264, 13396, 13530, 13666, 13802,
227 13940, 14080, 14221, 14363, 14506, 14652, 14798, 14946,
228 15096, 15247, 15399, 15553, 15709, 15866, 16024, 16184,
229 16346, 16510, 16675, 16842, 17010, 17180, 17352, 17526,
230 17701, 17878, 18057, 18237, 18420, 18604, 18790, 18978,
231 19167, 19359, 19553, 19748, 19946, 20145, 20347, 20550,
232 20756, 20963, 21173, 21385, 21598, 21814, 22033, 22253,
233 22475, 22700, 22927, 23156, 23388, 23622, 23858, 24097,
234 24338, 24581, 24827, 25075, 25326, 25579, 25835, 26093,
235 26354, 26618, 26884, 27153, 27424, 27699, 27976, 28255,
236 28538, 28823, 29112, 29403, 29697, 29994, 30294, 30597,
237 30903, 31212, 31524, 31839, 32157, 32479, 32804, 33132,
238};
239
251static uint8_t a_mpu6500_read(mpu6500_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
252{
253 if (handle->iic_spi == MPU6500_INTERFACE_IIC) /* if iic interface */
254 {
255 if (handle->iic_read(handle->iic_addr, reg, (uint8_t *)buf, len) != 0) /* read data */
256 {
257 return 1; /* return error */
258 }
259 else
260 {
261 return 0; /* success return 0 */
262 }
263 }
264 else /* spi interface */
265 {
266 if (handle->spi_read(reg | 0x80, (uint8_t *)buf, len) != 0) /* read data */
267 {
268 return 1; /* return error */
269 }
270 else
271 {
272 return 0; /* success return 0 */
273 }
274 }
275}
276
288static uint8_t a_mpu6500_write(mpu6500_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
289{
290 if (handle->iic_spi == MPU6500_INTERFACE_IIC) /* if iic interface */
291 {
292 if (handle->iic_write(handle->iic_addr, reg, (uint8_t *)buf, len) != 0) /* write data */
293 {
294 return 1; /* return error */
295 }
296 else
297 {
298 return 0; /* success return 0 */
299 }
300 }
301 else /* spi interface */
302 {
303 if (handle->spi_write(reg & (~0x80), (uint8_t *)buf, len) != 0) /* write data */
304 {
305 return 1; /* return error */
306 }
307 else
308 {
309 return 0; /* success return 0 */
310 }
311 }
312}
313
326static uint8_t a_mpu6500_write_mem(mpu6500_handle_t *handle, uint16_t addr, uint8_t *buf, uint16_t len)
327{
328 uint8_t tmp[2];
329
330 tmp[0] = (addr >> 8) & 0xFF; /* set the addr high */
331 tmp[1] = (addr >> 0) & 0xFF; /* set the addr low */
332
333 if (tmp[1] + len > 256) /* check the range */
334 {
335 return 2; /* return error */
336 }
337
338 if (handle->iic_spi == MPU6500_INTERFACE_IIC) /* if iic interface */
339 {
340 if (handle->iic_write(handle->iic_addr, MPU6500_REG_BANK_SEL, (uint8_t *)tmp, 2) != 0) /* write data */
341 {
342 return 1; /* return error */
343 }
344 if (handle->iic_write(handle->iic_addr, MPU6500_REG_MEM, (uint8_t *)buf, len) != 0) /* write data */
345 {
346 return 1; /* return error */
347 }
348 }
349 else /* if spi interface */
350 {
351 if (handle->spi_write(MPU6500_REG_BANK_SEL & (~0x80), (uint8_t *)tmp, 2) != 0) /* write data */
352 {
353 return 1; /* return error */
354 }
355 if (handle->spi_write(MPU6500_REG_MEM & (~0x80), (uint8_t *)buf, len) != 0) /* write data */
356 {
357 return 1; /* return error */
358 }
359 }
360
361 return 0; /* success return 0 */
362}
363
376static uint8_t a_mpu6500_read_mem(mpu6500_handle_t *handle, uint16_t addr, uint8_t *buf, uint16_t len)
377{
378 uint8_t tmp[2];
379
380 tmp[0] = (addr >> 8) & 0xFF; /* set the addr high */
381 tmp[1] = (addr >> 0) & 0xFF; /* set the addr low */
382
383 if (tmp[1] + len > 256) /* check the range */
384 {
385 return 2; /* return error */
386 }
387
388 if (handle->iic_spi == MPU6500_INTERFACE_IIC) /* if iic interface */
389 {
390 if (handle->iic_write(handle->iic_addr, MPU6500_REG_BANK_SEL, (uint8_t *)tmp, 2) != 0) /* write data */
391 {
392 return 1; /* return error */
393 }
394 if (handle->iic_read(handle->iic_addr, MPU6500_REG_MEM, (uint8_t *)buf, len) != 0) /* read data */
395 {
396 return 1; /* return error */
397 }
398 }
399 else /* if spi interface */
400 {
401 if (handle->spi_write(MPU6500_REG_BANK_SEL & (~0x80), (uint8_t *)tmp, 2) != 0) /* write data */
402 {
403 return 1; /* return error */
404 }
405 if (handle->spi_read(MPU6500_REG_MEM | 0x80, (uint8_t *)buf, len) != 0) /* read data */
406 {
407 return 1; /* return error */
408 }
409 }
410
411 return 0; /* success return 0 */
412}
413
421static uint8_t a_mpu6500_reset_fifo(mpu6500_handle_t *handle)
422{
423 uint8_t res;
424 uint8_t prev;
425 uint8_t int_enable;
426 uint8_t fifo_enable;
427 uint8_t user_ctrl;
428
429 res = a_mpu6500_read(handle, MPU6500_REG_INT_ENABLE, &int_enable, 1); /* read the int enable */
430 if (res != 0) /* check the result */
431 {
432 handle->debug_print("mpu6500: read int enable register failed.\n"); /* read int enable register failed */
433
434 return 1; /* return error */
435 }
436 res = a_mpu6500_read(handle, MPU6500_REG_FIFO_EN, &fifo_enable, 1); /* read the fifo enable */
437 if (res != 0) /* check the result */
438 {
439 handle->debug_print("mpu6500: read fifo enable register failed.\n"); /* read fifo enable register failed */
440
441 return 1; /* return error */
442 }
443 res = a_mpu6500_read(handle, MPU6500_REG_USER_CTRL, &user_ctrl, 1); /* read the user ctrl */
444 if (res != 0) /* check the result */
445 {
446 handle->debug_print("mpu6500: read user ctrl register failed.\n"); /* read user ctrl register failed */
447
448 return 1; /* return error */
449 }
450
451 prev = 0; /* set 0 */
452 res = a_mpu6500_write(handle, MPU6500_REG_INT_ENABLE, &prev, 1); /* disable all interrupt */
453 if (res != 0) /* check the result */
454 {
455 handle->debug_print("mpu6500: write int enable register failed.\n"); /* write int enable register failed */
456
457 return 1; /* return error */
458 }
459 prev = 0; /* set 0 */
460 res = a_mpu6500_write(handle, MPU6500_REG_FIFO_EN, &prev, 1); /* disable all fifo */
461 if (res != 0) /* check the result */
462 {
463 handle->debug_print("mpu6500: write fifo enable register failed.\n"); /* write fifo enable register failed */
464
465 return 1; /* return error */
466 }
467 user_ctrl &= ~(1 << 6); /* disable the fifo */
468 user_ctrl &= ~(1 << 7); /* disable the dmp */
469 if (handle->dmp_inited == 1) /* if we use dmp */
470 {
471 user_ctrl |= (1 << 2) | (1 << 3); /* reset the fifo and dmp */
472 }
473 else
474 {
475 user_ctrl |= 1 << 2; /* reset the fifo */
476 }
477 res = a_mpu6500_write(handle, MPU6500_REG_USER_CTRL, &user_ctrl, 1); /* write the user ctrl */
478 if (res != 0) /* check the result */
479 {
480 handle->debug_print("mpu6500: write user ctrl register failed.\n"); /* write user ctrl register failed */
481
482 return 1; /* return error */
483 }
484 handle->delay_ms(50); /* delay 50 ms */
485 if (handle->dmp_inited == 1) /* if we use dmp */
486 {
487 user_ctrl |= (1 << 6) | (1 << 7); /* enable fifo and dmp */
488 }
489 else
490 {
491 user_ctrl |= 1 << 6; /* enable fifo */
492 }
493 res = a_mpu6500_write(handle, MPU6500_REG_USER_CTRL, &user_ctrl, 1); /* write the user ctrl */
494 if (res != 0) /* check the result */
495 {
496 handle->debug_print("mpu6500: write user ctrl register failed.\n"); /* write user ctrl register failed */
497
498 return 1; /* return error */
499 }
500
501 res = a_mpu6500_write(handle, MPU6500_REG_INT_ENABLE, &int_enable, 1); /* restore the int enable */
502 if (res != 0) /* check the result */
503 {
504 handle->debug_print("mpu6500: write int enable register failed.\n"); /* write int enable register failed */
505
506 return 1; /* return error */
507 }
508 res = a_mpu6500_write(handle, MPU6500_REG_FIFO_EN, &fifo_enable, 1); /* restore the fifo enable */
509 if (res != 0) /* check the result */
510 {
511 handle->debug_print("mpu6500: write fifo enable register failed.\n"); /* write fifo enable register failed */
512
513 return 1; /* return error */
514 }
515
516 return 0; /* success return 0 */
517}
518
525static uint16_t a_mpu6500_inv_row_2_scale(int8_t *row)
526{
527 uint16_t b;
528
529 if (row[0] > 0) /* check row 0 */
530 {
531 b = 0; /* set 0 */
532 }
533 else if (row[0] < 0) /* check row 0 */
534 {
535 b = 4; /* set 4 */
536 }
537 else if (row[1] > 0) /* check row 1 */
538 {
539 b = 1; /* set 1 */
540 }
541 else if (row[1] < 0) /* check row 1 */
542 {
543 b = 5; /* set 5 */
544 }
545 else if (row[2] > 0) /* check row 2 */
546 {
547 b = 2; /* set 2 */
548 }
549 else if (row[2] < 0) /* check row 2 */
550 {
551 b = 6; /* set 6 */
552 }
553 else
554 {
555 b = 7; /* set 7 */
556 }
557
558 return b; /* return scale */
559}
560
567static uint16_t a_mpu6500_inv_orientation_matrix_to_scalar(int8_t *mtx)
568{
569 uint16_t scalar;
570
571 scalar = a_mpu6500_inv_row_2_scale(mtx); /* convert the part 0 */
572 scalar |= a_mpu6500_inv_row_2_scale(mtx + 3) << 3; /* convert the part 1 */
573 scalar |= a_mpu6500_inv_row_2_scale(mtx + 6) << 6; /* convert the part 2 */
574
575 return scalar; /* return the scalar */
576}
577
583static void a_mpu6500_dmp_decode_gesture(mpu6500_handle_t *handle, uint8_t gesture[4])
584{
585 uint8_t tap;
586 uint8_t orient;
587
588 orient = gesture[3] & 0xC0; /* set the orient */
589 tap = 0x3F & gesture[3]; /* set the tap */
590 if ((gesture[1] & MPU6500_DMP_INT_SRC_TAP) != 0) /* check the tap output */
591 {
592 uint8_t direction, count;
593
594 direction = tap >> 3; /* get the direction */
595 count = (tap % 8) + 1; /* get the count */
596 if (handle->dmp_tap_callback != NULL) /* check the dmp tap callback */
597 {
598 handle->dmp_tap_callback(direction, count); /* run the dmp tap callback */
599 }
600 }
601 if ((gesture[1] & MPU6500_DMP_INT_SRC_ORIENT) != 0) /* check the orient output */
602 {
603 if (handle->dmp_orient_callback != NULL) /* check the dmp orient callback */
604 {
605 handle->dmp_orient_callback(orient >> 6); /* run the dmp orient callback */
606 }
607 }
608}
609
620static uint8_t a_mpu6500_accel_self_test(mpu6500_handle_t *handle, int32_t *bias_regular, int32_t *bias_st)
621{
622 uint8_t res;
623 uint8_t i;
624 uint8_t otp_value_zero;
625 uint8_t regs[3];
626 float accel_st_al_min;
627 float accel_st_al_max;
628 float accel_offset_max;
629 float st_shift_cust[3];
630 float st_shift_ratio[3];
631 float ct_shift_prod[3];
632
633 res = a_mpu6500_read(handle, MPU6500_REG_SELF_TEST_X_ACCEL, regs, 3); /* read the tmp */
634 if (res != 0) /* check the result */
635 {
636 return 1; /* return error */
637 }
638
639 otp_value_zero = 0;
640 for (i = 0; i < 3; i++) /* 3 times */
641 {
642 if (regs[i] != 0) /* check the regs */
643 {
644 ct_shift_prod[i] = (float)gs_st_tb[regs[i] - 1]; /* get the table */
645 ct_shift_prod[i] *= 65536.f; /* x65535.0f */
646 ct_shift_prod[i] /= 16384.0f; /* 2g */
647 }
648 else
649 {
650 ct_shift_prod[i] = 0.0f; /* init 0.0f */
651 otp_value_zero = 1; /* check otp value zero */
652 }
653 }
654 if (otp_value_zero == 0) /* check otp value zero */
655 {
656 for (i = 0; i < 3; i++) /* 3 times */
657 {
658 st_shift_cust[i] = (float)(bias_st[i] - bias_regular[i]); /* set the shift cust */
659 st_shift_ratio[i] = st_shift_cust[i] / ct_shift_prod[i] - 1.f; /* set the shift ratio */
660 if (fabsf(st_shift_ratio[i]) > 0.5f) /* check the shift ratio */
661 {
662 return 1; /* return error */
663 }
664 }
665 }
666 else
667 {
668 accel_st_al_min = 0.225f * 65536.f; /* set the st al min */
669 accel_st_al_max = 0.675f * 65536.f; /* set the st al max */
670 for (i = 0; i < 3; i++) /* 3 times */
671 {
672 st_shift_cust[i] = (float)(bias_st[i] - bias_regular[i]); /* shift cust */
673 if (st_shift_cust[i] < accel_st_al_min
674 || st_shift_cust[i] > accel_st_al_max) /* check the result */
675 {
676 return 1; /* return error */
677 }
678 }
679 }
680
681 accel_offset_max = 0.5f * 65536.f; /* set the offset max */
682 for (i = 0; i < 3; i++) /* 3 times */
683 {
684 if (fabsf((float)bias_regular[i]) > accel_offset_max) /* check offset */
685 {
686 return 1; /* return error */
687 }
688 }
689
690 return 0; /* success return 0 */
691}
692
703static uint8_t a_mpu6500_gyro_self_test(mpu6500_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 float gyro_st_al_max;
709 float gyro_offset_max;
710 float st_shift_cust[3];
711 float st_shift_ratio[3];
712 float ct_shift_prod[3];
713 uint8_t regs[3];
714
715 res = a_mpu6500_read(handle, MPU6500_REG_SELF_TEST_X_GYRO, regs, 3); /* read the tmp */
716 if (res != 0) /* check the result */
717 {
718 return 1; /* return error */
719 }
720
721 otp_value_zero = 0; /* init otp value zero 0.0f */
722 for (i = 0; i < 3; i++) /* 3 times */
723 {
724 if (regs[i] != 0) /* check regs */
725 {
726 ct_shift_prod[i] = (float)gs_st_tb[regs[i] - 1]; /* set shift prod */
727 ct_shift_prod[i] *= 65536.f; /* x65536.0f */
728 ct_shift_prod[i] /= 131.0f; /* 250dps */
729 }
730 else
731 {
732 ct_shift_prod[i] = 0; /* init 0.0f */
733 otp_value_zero = 1; /* set otp value zero 1 */
734 }
735 }
736
737 if (otp_value_zero == 0) /* if otp value zero == 0 */
738 {
739 for (i = 0; i < 3; i++) /* 3 times */
740 {
741 st_shift_cust[i] = (float)(bias_st[i] - bias_regular[i]); /* shift cust */
742 st_shift_ratio[i] = st_shift_cust[i] / ct_shift_prod[i]; /* shift ratio */
743 if (fabsf(st_shift_ratio[i]) < 0.5f) /* check ratio */
744 {
745 return 1; /* return error */
746 }
747 }
748 }
749 else
750 {
751 gyro_st_al_max = 60.f * 65536.f; /* set st al max */
752 for (i = 0; i < 3; i++) /* 3 times */
753 {
754 st_shift_cust[i] = (float)(bias_st[i] - bias_regular[i]); /* set cust */
755 if (st_shift_cust[i] < gyro_st_al_max) /* check st al max */
756 {
757 return 1; /* return error */
758 }
759 }
760 }
761
762 gyro_offset_max = 20.f * 65536.f; /* set gyro offset max */
763 for (i = 0; i < 3; i++) /* 3 times */
764 {
765 if( fabsf((float)bias_regular[i]) > gyro_offset_max) /* check gyro offset max */
766 {
767 return 1; /* return error */
768 }
769 }
770
771 return 0; /* success return 0 */
772}
773
785static uint8_t a_mpu6500_get_st_biases(mpu6500_handle_t *handle,
786 int32_t gyro_offset[3], int32_t accel_offset[3],
787 uint8_t hw_test_enable)
788{
789 uint8_t res;
790 uint16_t cnt;
791 uint16_t pack_cnt;
792 uint16_t i;
793 uint8_t data[12];
794
795 data[0] = 0x01; /* set 0x01 */
796 data[1] = 0x00; /* set 0x00 */
797 res = a_mpu6500_write(handle, MPU6500_REG_PWR_MGMT_1, data, 2); /* write pwr mgmt1 */
798 if (res != 0) /* check the result */
799 {
800 return 1; /* return error */
801 }
802 handle->delay_ms(200); /* delay 200ms */
803 data[0] = 0; /* set 0 */
804 res = a_mpu6500_write(handle, MPU6500_REG_INT_ENABLE, data, 1); /* write int enable */
805 if (res != 0) /* check the result */
806 {
807 return 1; /* return error */
808 }
809 res = a_mpu6500_write(handle, MPU6500_REG_FIFO_EN, data, 1); /* write the fifo enable */
810 if (res != 0) /* check the result */
811 {
812 return 1; /* return error */
813 }
814 res = a_mpu6500_write(handle, MPU6500_REG_PWR_MGMT_1, data, 1); /* write the pwr mgmt 1 */
815 if (res != 0) /* check the result */
816 {
817 return 1; /* return error */
818 }
819 res = a_mpu6500_write(handle, MPU6500_REG_I2C_MST_CTRL, data, 1); /* write the i2c mst ctrl */
820 if (res != 0) /* check the result */
821 {
822 return 1; /* return error */
823 }
824 res = a_mpu6500_write(handle, MPU6500_REG_USER_CTRL, data, 1); /* write the user ctrl */
825 if (res != 0) /* check the result */
826 {
827 return 1; /* return error */
828 }
829
830 data[0] = 1 << 3 | 1 << 2; /* set fifo and dmp reset */
831 res = a_mpu6500_write(handle, MPU6500_REG_USER_CTRL, data, 1); /* write user ctrl */
832 if (res != 0) /* check the result */
833 {
834 return 1; /* return error */
835 }
836 handle->delay_ms(15); /* delay 15 ms */
837 data[0] = 0x01; /* set 0x01 */
838 res = a_mpu6500_write(handle, MPU6500_REG_CONFIG, data, 1); /* write config */
839 if (res != 0) /* check the result */
840 {
841 return 1; /* return error */
842 }
843 data[0] = 0x00; /* set 0 */
844 res = a_mpu6500_write(handle, MPU6500_REG_SMPRT_DIV, data, 1); /* write div */
845 if (res != 0) /* check the result */
846 {
847 return 1; /* return error */
848 }
849 if (hw_test_enable != 0) /* if enable */
850 {
851 data[0] = 0x00 | 0xE0; /* set 250dps and test */
852 }
853 else
854 {
855 data[0] = 0x00; /* set 250dps */
856 }
857 res = a_mpu6500_write(handle, MPU6500_REG_GYRO_CONFIG, data, 1); /* read the gyro config */
858 if (res != 0) /* check the result */
859 {
860 return 1; /* return error */
861 }
862 if (hw_test_enable != 0) /* if enable */
863 {
864 data[0] = 0x18 | 0xE0; /* enable 2g and test */
865 }
866 else
867 {
868 data[0] = 0x18; /* enable 2g */
869 }
870 res = a_mpu6500_write(handle, MPU6500_REG_ACCEL_CONFIG, data, 1); /* read the accel config */
871 if (res != 0) /* check the result */
872 {
873 return 1; /* return error */
874 }
875 if (hw_test_enable != 0) /* if enable */
876 {
877 handle->delay_ms(200); /* delay 200ms */
878 }
879
880 data[0] = 1 << 6; /* enable fifo */
881 res = a_mpu6500_write(handle, MPU6500_REG_USER_CTRL, data, 1); /* write user ctrl */
882 if (res != 0) /* check the result */
883 {
884 return 1; /* return error */
885 }
886 data[0] = 0x78; /* enable xyz */
887 res = a_mpu6500_write(handle, MPU6500_REG_FIFO_EN, data, 1); /* write fifo enable */
888 if (res != 0) /* check the result */
889 {
890 return 1; /* return error */
891 }
892 handle->delay_ms(50); /* delay 50 ms */
893 data[0] = 0x00; /* set disable */
894 res = a_mpu6500_write(handle, MPU6500_REG_FIFO_EN, data, 1); /* write fifo enable */
895 if (res != 0) /* check the result */
896 {
897 return 1; /* return error */
898 }
899
900 res = a_mpu6500_read(handle, MPU6500_REG_FIFO_COUNTH, data, 2); /* read fifo counter */
901 if (res != 0) /* check the result */
902 {
903 return 1; /* return error */
904 }
905 cnt = ((uint16_t)data[0] << 8) | data[1]; /* set the counter */
906 pack_cnt = cnt / 12; /* set the packet counter */
907
908 gyro_offset[0] = 0; /* gyro offset 0 */
909 gyro_offset[1] = 0; /* gyro offset 1 */
910 gyro_offset[2] = 0; /* gyro offset 2 */
911 accel_offset[0] = 0; /* accel offset 0 */
912 accel_offset[1] = 0; /* accel offset 1 */
913 accel_offset[2] = 0; /* accel offset 2 */
914 for (i = 0; i < pack_cnt; i++) /* packet counter */
915 {
916 int16_t accel_cur[3];
917 int16_t gyro_cur[3];
918
919 res = a_mpu6500_read(handle, MPU6500_REG_R_W, data, 12); /* read data */
920 if (res != 0) /* check the result */
921 {
922 return 1; /* return error */
923 }
924
925 accel_cur[0] = ((int16_t)data[0] << 8) | data[1]; /* accel cur 0 */
926 accel_cur[1] = ((int16_t)data[2] << 8) | data[3]; /* accel cur 1 */
927 accel_cur[2] = ((int16_t)data[4] << 8) | data[5]; /* accel cur 2 */
928 accel_offset[0] += (int32_t)accel_cur[0]; /* accel offset 0 */
929 accel_offset[1] += (int32_t)accel_cur[1]; /* accel offset 1 */
930 accel_offset[2] += (int32_t)accel_cur[2]; /* accel offset 2 */
931 gyro_cur[0] = (((int16_t)data[6] << 8) | data[7]); /* gyro cur 0 */
932 gyro_cur[1] = (((int16_t)data[8] << 8) | data[9]); /* gyro cur 1 */
933 gyro_cur[2] = (((int16_t)data[10] << 8) | data[11]); /* gyro cur 2 */
934 gyro_offset[0] += (int32_t)gyro_cur[0]; /* gyro offset 0 */
935 gyro_offset[1] += (int32_t)gyro_cur[1]; /* gyro offset 1 */
936 gyro_offset[2] += (int32_t)gyro_cur[2]; /* gyro offset 2 */
937 }
938
939 gyro_offset[0] = (int32_t)(((int64_t)gyro_offset[0] << 16) / (32768 / 250) / pack_cnt); /* set the gyro offset 0 */
940 gyro_offset[1] = (int32_t)(((int64_t)gyro_offset[1] << 16) / (32768 / 250) / pack_cnt); /* set the gyro offset 1 */
941 gyro_offset[2] = (int32_t)(((int64_t)gyro_offset[2] << 16) / (32768 / 250) / pack_cnt); /* set the gyro offset 2 */
942 accel_offset[0] = (int32_t)(((int64_t)accel_offset[0] << 16) / (32768 / 16) / pack_cnt); /* set the accel offset 0 */
943 accel_offset[1] = (int32_t)(((int64_t)accel_offset[1] << 16) / (32768 / 16) / pack_cnt); /* set the accel offset 1 */
944 accel_offset[2] = (int32_t)(((int64_t)accel_offset[2] << 16) / (32768 / 16) / pack_cnt); /* set the accel offset 2 */
945 if (accel_offset[2] > 0L) /* check the accel offset */
946 {
947 accel_offset[2] -= 65536L; /* -65536 */
948 }
949 else
950 {
951 accel_offset[2] += 65536L; /* +65536 */
952 }
953
954 return 0; /* success return 0 */
955}
956
965static uint8_t a_mpu6500_deinit(mpu6500_handle_t *handle)
966{
967 if (handle->iic_spi == MPU6500_INTERFACE_IIC) /* if iic interface */
968 {
969 if (handle->iic_deinit() != 0) /* iic deinit */
970 {
971 return 1; /* return error */
972 }
973 else
974 {
975 return 0; /* success return 0 */
976 }
977 }
978 else
979 {
980 if (handle->spi_deinit() != 0) /* if spi interface */
981 {
982 return 1; /* return error */
983 }
984 else
985 {
986 return 0; /* success return 0 */
987 }
988 }
989}
990
1005{
1006 uint8_t res;
1007 uint16_t i;
1008 uint16_t size;
1009 uint16_t this_write;
1010 uint8_t tmp[2];
1011 uint8_t cur[16];
1012
1013 if (handle == NULL) /* check handle */
1014 {
1015 return 2; /* return error */
1016 }
1017 if (handle->inited != 1) /* check handle initialization */
1018 {
1019 return 3; /* return error */
1020 }
1021 if (handle->dmp_inited != 0) /* check dmp initialization */
1022 {
1023 handle->debug_print("mpu6500: dmp is running.\n"); /* dmp is running */
1024
1025 return 4; /* return error */
1026 }
1027
1028 size = MPU6500_DMP_CODE_SIZE; /* set the code size */
1029 for (i = 0; i < size; i += this_write) /* code size times */
1030 {
1031 this_write = MIN(16, size - i); /* get the written size */
1032
1033 res = a_mpu6500_write_mem(handle, i, (uint8_t *)(gs_mpu6500_dmp_code + i),
1034 this_write); /* write data */
1035 if (res != 0) /* check result */
1036 {
1037 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
1038
1039 return 1; /* return error */
1040 }
1041 res = a_mpu6500_read_mem(handle, i, cur, this_write); /* read data */
1042 if (res != 0) /* check result */
1043 {
1044 handle->debug_print("mpu6500: read mem failed.\n"); /* read mem failed */
1045
1046 return 1; /* return error */
1047 }
1048 if (memcmp(gs_mpu6500_dmp_code + i, cur, this_write) != 0) /* check the code */
1049 {
1050 handle->debug_print("mpu6500: code compare error.\n"); /* code compare error */
1051
1052 return 5; /* return error */
1053 }
1054 }
1055 tmp[0] = (0x0400 >> 8) & 0xFF; /* set the addr high */
1056 tmp[1] = (0x0400 >> 0) & 0xFF; /* set the addr low */
1057
1058 if (a_mpu6500_write(handle, MPU6500_REG_PROGRAM_START, (uint8_t *)tmp, 2) != 0) /* write data */
1059 {
1060 handle->debug_print("mpu6500: set program start failed.\n"); /* set program start failed */
1061
1062 return 6; /* return error */
1063 }
1064 handle->dmp_inited = 1; /* flag the dmp inited bit */
1065
1066 return 0; /* success return 0 */
1067}
1068
1082{
1083 uint8_t res;
1084 uint8_t tmp[4];
1085
1086 if (handle == NULL) /* check handle */
1087 {
1088 return 2; /* return error */
1089 }
1090 if (handle->inited != 1) /* check handle initialization */
1091 {
1092 return 3; /* return error */
1093 }
1094 if (handle->dmp_inited != 1) /* check dmp initialization */
1095 {
1096 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1097
1098 return 4; /* return error */
1099 }
1100
1101 ms /= 20; /* div 20 */
1102 tmp[0] = (uint8_t)((ms >> 24) & 0xFF); /* set part 0 */
1103 tmp[1] = (uint8_t)((ms >> 16) & 0xFF); /* set part 1 */
1104 tmp[2] = (uint8_t)((ms >> 8) & 0xFF); /* set part 2 */
1105 tmp[3] = (uint8_t)(ms & 0xFF); /* set part 3 */
1106
1107 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_PEDSTD_TIMECTR, tmp, 4); /* write data */
1108 if (res != 0) /* check result */
1109 {
1110 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
1111
1112 return 1; /* return error */
1113 }
1114
1115 return 0; /* success return 0 */
1116}
1117
1131{
1132 uint8_t res;
1133 uint8_t tmp[4];
1134
1135 if (handle == NULL) /* check handle */
1136 {
1137 return 2; /* return error */
1138 }
1139 if (handle->inited != 1) /* check handle initialization */
1140 {
1141 return 3; /* return error */
1142 }
1143 if (handle->dmp_inited != 1) /* check dmp initialization */
1144 {
1145 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1146
1147 return 4; /* return error */
1148 }
1149
1150 res = a_mpu6500_read_mem(handle, MPU6500_DMP_D_PEDSTD_TIMECTR, tmp, 4); /* read data */
1151 if (res != 0) /* check result */
1152 {
1153 handle->debug_print("mpu6500: read mem failed.\n"); /* read mem failed */
1154
1155 return 1; /* return error */
1156 }
1157 *ms = (((uint32_t)tmp[0] << 24) | ((uint32_t)tmp[1] << 16) |
1158 ((uint32_t)tmp[2] << 8) | tmp[3]) * 20; /* get the ms */
1159
1160 return 0; /* success return 0 */
1161}
1162
1176{
1177 uint8_t res;
1178 uint8_t tmp[4];
1179
1180 if (handle == NULL) /* check handle */
1181 {
1182 return 2; /* return error */
1183 }
1184 if (handle->inited != 1) /* check handle initialization */
1185 {
1186 return 3; /* return error */
1187 }
1188 if (handle->dmp_inited != 1) /* check dmp initialization */
1189 {
1190 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1191
1192 return 4; /* return error */
1193 }
1194
1195 tmp[0] = (uint8_t)((count >> 24) & 0xFF); /* set part 0 */
1196 tmp[1] = (uint8_t)((count >> 16) & 0xFF); /* set part 1 */
1197 tmp[2] = (uint8_t)((count >> 8) & 0xFF); /* set part 2 */
1198 tmp[3] = (uint8_t)(count & 0xFF); /* set part 3 */
1199
1200 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_PEDSTD_STEPCTR, tmp, 4); /* write data */
1201 if (res != 0) /* check result */
1202 {
1203 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
1204
1205 return 1; /* return error */
1206 }
1207
1208 return 0; /* success return 0 */
1209}
1210
1224{
1225 uint8_t res;
1226 uint8_t tmp[4];
1227
1228 if (handle == NULL) /* check handle */
1229 {
1230 return 2; /* return error */
1231 }
1232 if (handle->inited != 1) /* check handle initialization */
1233 {
1234 return 3; /* return error */
1235 }
1236 if (handle->dmp_inited != 1) /* check dmp initialization */
1237 {
1238 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1239
1240 return 4; /* return error */
1241 }
1242
1243 res = a_mpu6500_read_mem(handle, MPU6500_DMP_D_PEDSTD_STEPCTR, tmp, 4); /* read data */
1244 if (res != 0) /* check result */
1245 {
1246 handle->debug_print("mpu6500: read mem failed.\n"); /* read mem failed */
1247
1248 return 1; /* return error */
1249 }
1250 *count = (((uint32_t)tmp[0] << 24) | ((uint32_t)tmp[1] << 16) |
1251 ((uint32_t)tmp[2] << 8) | tmp[3]); /* get the ms */
1252
1253 return 0; /* success return 0 */
1254}
1255
1269{
1270 uint8_t res;
1271 uint8_t tmp[2];
1272
1273 if (handle == NULL) /* check handle */
1274 {
1275 return 2; /* return error */
1276 }
1277 if (handle->inited != 1) /* check handle initialization */
1278 {
1279 return 3; /* return error */
1280 }
1281 if (handle->dmp_inited != 1) /* check dmp initialization */
1282 {
1283 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1284
1285 return 4; /* return error */
1286 }
1287
1288 ms /= (1000 / MPU6500_DMP_SAMPLE_RATE); /* convert time */
1289 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
1290 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
1291
1292 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_1_88, tmp, 2); /* write data */
1293 if (res != 0) /* check result */
1294 {
1295 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
1296
1297 return 1; /* return error */
1298 }
1299
1300 return 0; /* success return 0 */
1301}
1302
1316{
1317 uint8_t res;
1318 uint8_t tmp[2];
1319
1320 if (handle == NULL) /* check handle */
1321 {
1322 return 2; /* return error */
1323 }
1324 if (handle->inited != 1) /* check handle initialization */
1325 {
1326 return 3; /* return error */
1327 }
1328 if (handle->dmp_inited != 1) /* check dmp initialization */
1329 {
1330 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1331
1332 return 4; /* return error */
1333 }
1334
1335 res = a_mpu6500_read_mem(handle, MPU6500_DMP_D_1_88, tmp, 2); /* read data */
1336 if (res != 0) /* check result */
1337 {
1338 handle->debug_print("mpu6500: read mem failed.\n"); /* read mem failed */
1339
1340 return 1; /* return error */
1341 }
1342 *ms = (uint16_t)((uint16_t)tmp[0] << 8) | tmp[1]; /* get the raw time */
1343 *ms *= (1000 / MPU6500_DMP_SAMPLE_RATE); /* convert time */
1344
1345 return 0; /* success return 0 */
1346}
1347
1361{
1362 uint8_t res;
1363 uint8_t tmp[2];
1364
1365 if (handle == NULL) /* check handle */
1366 {
1367 return 2; /* return error */
1368 }
1369 if (handle->inited != 1) /* check handle initialization */
1370 {
1371 return 3; /* return error */
1372 }
1373 if (handle->dmp_inited != 1) /* check dmp initialization */
1374 {
1375 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1376
1377 return 4; /* return error */
1378 }
1379
1380 ms /= (1000 / MPU6500_DMP_SAMPLE_RATE); /* convert time */
1381 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
1382 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
1383
1384 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_1_90, tmp, 2); /* write data */
1385 if (res != 0) /* check result */
1386 {
1387 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
1388
1389 return 1; /* return error */
1390 }
1391
1392 return 0; /* success return 0 */
1393}
1394
1408{
1409 uint8_t res;
1410 uint8_t tmp[2];
1411
1412 if (handle == NULL) /* check handle */
1413 {
1414 return 2; /* return error */
1415 }
1416 if (handle->inited != 1) /* check handle initialization */
1417 {
1418 return 3; /* return error */
1419 }
1420 if (handle->dmp_inited != 1) /* check dmp initialization */
1421 {
1422 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1423
1424 return 4; /* return error */
1425 }
1426
1427 res = a_mpu6500_read_mem(handle, MPU6500_DMP_D_1_90, tmp, 2); /* read data */
1428 if (res != 0) /* check result */
1429 {
1430 handle->debug_print("mpu6500: read mem failed.\n"); /* read mem failed */
1431
1432 return 1; /* return error */
1433 }
1434 *ms = (uint16_t)((uint16_t)tmp[0] << 8) | tmp[1]; /* get the raw time */
1435 *ms *= (1000 / MPU6500_DMP_SAMPLE_RATE); /* convert time */
1436
1437 return 0; /* success return 0 */
1438}
1439
1453{
1454 uint8_t res;
1455 uint8_t tmp[4];
1456 uint32_t thresh_scaled;
1457
1458 if (handle == NULL) /* check handle */
1459 {
1460 return 2; /* return error */
1461 }
1462 if (handle->inited != 1) /* check handle initialization */
1463 {
1464 return 3; /* return error */
1465 }
1466 if (handle->dmp_inited != 1) /* check dmp initialization */
1467 {
1468 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1469
1470 return 4; /* return error */
1471 }
1472
1473 thresh_scaled = MPU6500_DMP_GYRO_SF / 1000 * dps; /* convert to thresh scaled */
1474 tmp[0] = (uint8_t)(((uint32_t)thresh_scaled >> 24) & 0xFF); /* set the part 3 */
1475 tmp[1] = (uint8_t)(((uint32_t)thresh_scaled >> 16) & 0xFF); /* set the part 2 */
1476 tmp[2] = (uint8_t)(((uint32_t)thresh_scaled >> 8) & 0xFF); /* set the part 1 */
1477 tmp[3] = (uint8_t)((uint32_t)thresh_scaled & 0xFF); /* set the part 0 */
1478
1479 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_1_92, tmp, 4); /* write data */
1480 if (res != 0) /* check result */
1481 {
1482 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
1483
1484 return 1; /* return error */
1485 }
1486
1487 return 0; /* success return 0 */
1488}
1489
1503{
1504 uint8_t res;
1505 uint8_t tmp[4];
1506 uint32_t thresh_scaled;
1507
1508 if (handle == NULL) /* check handle */
1509 {
1510 return 2; /* return error */
1511 }
1512 if (handle->inited != 1) /* check handle initialization */
1513 {
1514 return 3; /* return error */
1515 }
1516 if (handle->dmp_inited != 1) /* check dmp initialization */
1517 {
1518 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1519
1520 return 4; /* return error */
1521 }
1522
1523 res = a_mpu6500_read_mem(handle, MPU6500_DMP_D_1_92, tmp, 4); /* read data */
1524 if (res != 0) /* check result */
1525 {
1526 handle->debug_print("mpu6500: read mem failed.\n"); /* read mem failed */
1527
1528 return 1; /* return error */
1529 }
1530 thresh_scaled = (((uint32_t)tmp[0] << 24) | ((uint32_t)tmp[1] << 16) |
1531 ((uint32_t)tmp[2] << 8) | tmp[3]); /* get the thresh scaled */
1532 *dps = (uint16_t)((float)(thresh_scaled) /
1533 ((float)(MPU6500_DMP_GYRO_SF) / 1000.0f)); /* convert the thresh scaled */
1534
1535 return 0; /* success return 0 */
1536}
1537
1551{
1552 uint8_t res;
1553 uint8_t tmp[2];
1554
1555 if (handle == NULL) /* check handle */
1556 {
1557 return 2; /* return error */
1558 }
1559 if (handle->inited != 1) /* check handle initialization */
1560 {
1561 return 3; /* return error */
1562 }
1563 if (handle->dmp_inited != 1) /* check dmp initialization */
1564 {
1565 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1566
1567 return 4; /* return error */
1568 }
1569
1570 ms /= (1000 / MPU6500_DMP_SAMPLE_RATE); /* convert time */
1571 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
1572 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
1573
1574 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_1_218, tmp, 2); /* write data */
1575 if (res != 0) /* check result */
1576 {
1577 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
1578
1579 return 1; /* return error */
1580 }
1581
1582 return 0; /* success return 0 */
1583}
1584
1598{
1599 uint8_t res;
1600 uint8_t tmp[2];
1601
1602 if (handle == NULL) /* check handle */
1603 {
1604 return 2; /* return error */
1605 }
1606 if (handle->inited != 1) /* check handle initialization */
1607 {
1608 return 3; /* return error */
1609 }
1610 if (handle->dmp_inited != 1) /* check dmp initialization */
1611 {
1612 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1613
1614 return 4; /* return error */
1615 }
1616
1617 res = a_mpu6500_read_mem(handle, MPU6500_DMP_D_1_218, tmp, 2); /* read data */
1618 if (res != 0) /* check result */
1619 {
1620 handle->debug_print("mpu6500: read mem failed.\n"); /* read mem failed */
1621
1622 return 1; /* return error */
1623 }
1624 *ms = (uint16_t)((uint16_t)tmp[0] << 8) | tmp[1]; /* get the raw time */
1625 *ms *= (1000 / MPU6500_DMP_SAMPLE_RATE); /* convert time */
1626
1627 return 0; /* success return 0 */
1628}
1629
1642uint8_t mpu6500_dmp_set_tap_time(mpu6500_handle_t *handle, uint16_t ms)
1643{
1644 uint8_t res;
1645 uint8_t tmp[2];
1646
1647 if (handle == NULL) /* check handle */
1648 {
1649 return 2; /* return error */
1650 }
1651 if (handle->inited != 1) /* check handle initialization */
1652 {
1653 return 3; /* return error */
1654 }
1655 if (handle->dmp_inited != 1) /* check dmp initialization */
1656 {
1657 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1658
1659 return 4; /* return error */
1660 }
1661
1662 ms /= (1000 / MPU6500_DMP_SAMPLE_RATE); /* convert time */
1663 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
1664 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
1665
1666 res = a_mpu6500_write_mem(handle, MPU6500_DMP_TAPW_MIN, tmp, 2); /* write data */
1667 if (res != 0) /* check result */
1668 {
1669 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
1670
1671 return 1; /* return error */
1672 }
1673
1674 return 0; /* success return 0 */
1675}
1676
1689uint8_t mpu6500_dmp_get_tap_time(mpu6500_handle_t *handle, uint16_t *ms)
1690{
1691 uint8_t res;
1692 uint8_t tmp[2];
1693
1694 if (handle == NULL) /* check handle */
1695 {
1696 return 2; /* return error */
1697 }
1698 if (handle->inited != 1) /* check handle initialization */
1699 {
1700 return 3; /* return error */
1701 }
1702 if (handle->dmp_inited != 1) /* check dmp initialization */
1703 {
1704 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1705
1706 return 4; /* return error */
1707 }
1708
1709 res = a_mpu6500_read_mem(handle, MPU6500_DMP_TAPW_MIN, tmp, 2); /* read data */
1710 if (res != 0) /* check result */
1711 {
1712 handle->debug_print("mpu6500: read mem failed.\n"); /* read mem failed */
1713
1714 return 1; /* return error */
1715 }
1716 *ms = (uint16_t)((uint16_t)tmp[0] << 8) | tmp[1]; /* get the raw time */
1717 *ms *= (1000 / MPU6500_DMP_SAMPLE_RATE); /* convert time */
1718
1719 return 0; /* success return 0 */
1720}
1721
1736{
1737 uint8_t res;
1738 uint8_t tmp;
1739
1740 if (handle == NULL) /* check handle */
1741 {
1742 return 2; /* return error */
1743 }
1744 if (handle->inited != 1) /* check handle initialization */
1745 {
1746 return 3; /* return error */
1747 }
1748 if (handle->dmp_inited != 1) /* check dmp initialization */
1749 {
1750 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1751
1752 return 4; /* return error */
1753 }
1754 if ((cnt < 1) || (cnt > 4)) /* check cnt */
1755 {
1756 handle->debug_print("mpu6500: cnt must be between 1 and 4.\n"); /* cnt must be between 1 and 4 */
1757
1758 return 5; /* return error */
1759 }
1760
1761 tmp = cnt - 1; /* set the counter */
1762 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_1_79, &tmp, 1); /* write data */
1763 if (res != 0) /* check result */
1764 {
1765 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
1766
1767 return 1; /* return error */
1768 }
1769
1770 return 0; /* success return 0 */
1771}
1772
1786{
1787 uint8_t res;
1788 uint8_t tmp;
1789
1790 if (handle == NULL) /* check handle */
1791 {
1792 return 2; /* return error */
1793 }
1794 if (handle->inited != 1) /* check handle initialization */
1795 {
1796 return 3; /* return error */
1797 }
1798 if (handle->dmp_inited != 1) /* check dmp initialization */
1799 {
1800 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1801
1802 return 4; /* return error */
1803 }
1804
1805 res = a_mpu6500_read_mem(handle, MPU6500_DMP_D_1_79, &tmp, 1); /* read data */
1806 if (res != 0) /* check result */
1807 {
1808 handle->debug_print("mpu6500: read mem failed.\n"); /* read mem failed */
1809
1810 return 1; /* return error */
1811 }
1812 *cnt = tmp + 1; /* set the counter */
1813
1814 return 0; /* success return 0 */
1815}
1816
1830{
1831 uint8_t res;
1832
1833 if (handle == NULL) /* check handle */
1834 {
1835 return 2; /* return error */
1836 }
1837 if (handle->inited != 1) /* check handle initialization */
1838 {
1839 return 3; /* return error */
1840 }
1841 if (handle->dmp_inited != 1) /* check dmp initialization */
1842 {
1843 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1844
1845 return 4; /* return error */
1846 }
1847
1848 if (enable != 0) /* enable */
1849 {
1850 uint8_t regs[9] = {0xb8, 0xaa, 0xb3, 0x8d, 0xb4, 0x98, 0x0d, 0x35, 0x5d};
1851
1852 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_MOTION_BIAS, regs, 9); /* write data */
1853 if (res != 0) /* check result */
1854 {
1855 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
1856
1857 return 1; /* return error */
1858 }
1859 handle->mask |= MPU6500_DMP_FEATURE_GYRO_CAL; /* set the mask */
1860
1861 return 0; /* success return 0 */
1862 }
1863 else /* disable */
1864 {
1865 uint8_t regs[9] = {0xb8, 0xaa, 0xaa, 0xaa, 0xb0, 0x88, 0xc3, 0xc5, 0xc7};
1866
1867 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_MOTION_BIAS, regs, 9); /* write data */
1868 if (res != 0) /* check result */
1869 {
1870 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
1871
1872 return 1; /* return error */
1873 }
1874 handle->mask &= ~MPU6500_DMP_FEATURE_GYRO_CAL; /* set the mask */
1875
1876 return 0; /* success return 0 */
1877 }
1878}
1879
1893{
1894 uint8_t res;
1895
1896 if (handle == NULL) /* check handle */
1897 {
1898 return 2; /* return error */
1899 }
1900 if (handle->inited != 1) /* check handle initialization */
1901 {
1902 return 3; /* return error */
1903 }
1904 if (handle->dmp_inited != 1) /* check dmp initialization */
1905 {
1906 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1907
1908 return 4; /* return error */
1909 }
1910
1911 if (enable != 0) /* enable */
1912 {
1913 uint8_t regs[4] = {0xC0, 0xC2, 0xC4, 0xC6};
1914
1915 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_LP_QUAT, regs, 4); /* write data */
1916 if (res != 0) /* check result */
1917 {
1918 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
1919
1920 return 1; /* return error */
1921 }
1922 res = a_mpu6500_reset_fifo(handle); /* reset the fifo */
1923 if (res != 0) /* check result */
1924 {
1925 handle->debug_print("mpu6500: reset fifo failed.\n"); /* reset fifo failed */
1926
1927 return 1; /* return error */
1928 }
1929 handle->mask |= MPU6500_DMP_FEATURE_3X_QUAT; /* set the mask */
1930
1931 return 0; /* success return 0 */
1932 }
1933 else /* disable */
1934 {
1935 uint8_t regs[4] = {0x8B, 0x8B, 0x8B, 0x8B};
1936
1937 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_LP_QUAT, regs, 4); /* write data */
1938 if (res != 0) /* check result */
1939 {
1940 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
1941
1942 return 1; /* return error */
1943 }
1944 res = a_mpu6500_reset_fifo(handle); /* reset the fifo */
1945 if (res != 0) /* check result */
1946 {
1947 handle->debug_print("mpu6500: reset fifo failed.\n"); /* reset fifo failed */
1948
1949 return 1; /* return error */
1950 }
1951 handle->mask &= ~MPU6500_DMP_FEATURE_3X_QUAT; /* set the mask */
1952
1953 return 0; /* success return 0 */
1954 }
1955}
1956
1970{
1971 uint8_t res;
1972
1973 if (handle == NULL) /* check handle */
1974 {
1975 return 2; /* return error */
1976 }
1977 if (handle->inited != 1) /* check handle initialization */
1978 {
1979 return 3; /* return error */
1980 }
1981 if (handle->dmp_inited != 1) /* check dmp initialization */
1982 {
1983 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
1984
1985 return 4; /* return error */
1986 }
1987
1988 if (enable != 0) /* enable */
1989 {
1990 uint8_t regs[4] = {0x20, 0x28, 0x30, 0x38};
1991
1992 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_8, regs, 4); /* write data */
1993 if (res != 0) /* check result */
1994 {
1995 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
1996
1997 return 1; /* return error */
1998 }
1999 res = a_mpu6500_reset_fifo(handle); /* reset the fifo */
2000 if (res != 0) /* check result */
2001 {
2002 handle->debug_print("mpu6500: reset fifo failed.\n"); /* reset fifo failed */
2003
2004 return 1; /* return error */
2005 }
2006 handle->mask |= MPU6500_DMP_FEATURE_6X_QUAT; /* set the mask */
2007
2008 return 0; /* success return 0 */
2009 }
2010 else /* disable */
2011 {
2012 uint8_t regs[4] = {0xA3, 0xA3, 0xA3, 0xA3};
2013
2014 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_8, regs, 4); /* write data */
2015 if (res != 0) /* check result */
2016 {
2017 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2018
2019 return 1; /* return error */
2020 }
2021 res = a_mpu6500_reset_fifo(handle); /* reset the fifo */
2022 if (res != 0) /* check result */
2023 {
2024 handle->debug_print("mpu6500: reset fifo failed.\n"); /* reset fifo failed */
2025
2026 return 1; /* return error */
2027 }
2028 handle->mask &= ~MPU6500_DMP_FEATURE_6X_QUAT; /* set the mask */
2029
2030 return 0; /* success return 0 */
2031 }
2032}
2033
2047{
2048 uint8_t res;
2049
2050 if (handle == NULL) /* check handle */
2051 {
2052 return 2; /* return error */
2053 }
2054 if (handle->inited != 1) /* check handle initialization */
2055 {
2056 return 3; /* return error */
2057 }
2058 if (handle->dmp_inited != 1) /* check dmp initialization */
2059 {
2060 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
2061
2062 return 4; /* return error */
2063 }
2064
2065 if (mode == MPU6500_DMP_INTERRUPT_MODE_CONTINUOUS) /* continuous */
2066 {
2067 uint8_t regs_continuous[11] = {0xd8, 0xb1, 0xb9,
2068 0xf3, 0x8b, 0xa3,
2069 0x91, 0xb6, 0x09,
2070 0xb4, 0xd9};
2071
2072 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_FIFO_ON_EVENT,
2073 (uint8_t *)regs_continuous, 11); /* write data */
2074 if (res != 0) /* check result */
2075 {
2076 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2077
2078 return 1; /* return error */
2079 }
2080
2081 return 0; /* success return 0 */
2082 }
2083 else /* disable */
2084 {
2085 uint8_t regs_gesture[11] = {0xda, 0xb1, 0xb9,
2086 0xf3, 0x8b, 0xa3,
2087 0x91, 0xb6, 0xda,
2088 0xb4, 0xda};
2089
2090 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_FIFO_ON_EVENT,
2091 (uint8_t *)regs_gesture, 11); /* write data */
2092 if (res != 0) /* check result */
2093 {
2094 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2095
2096 return 1; /* return error */
2097 }
2098
2099 return 0; /* success return 0 */
2100 }
2101}
2102
2115uint8_t mpu6500_dmp_set_gyro_bias(mpu6500_handle_t *handle, int32_t bias[3])
2116{
2117 uint8_t res;
2118 uint8_t regs[4];
2119 int32_t gyro_bias_body[3];
2120
2121 if (handle == NULL) /* check handle */
2122 {
2123 return 2; /* return error */
2124 }
2125 if (handle->inited != 1) /* check handle initialization */
2126 {
2127 return 3; /* return error */
2128 }
2129 if (handle->dmp_inited != 1) /* check dmp initialization */
2130 {
2131 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
2132
2133 return 4; /* return error */
2134 }
2135
2136 gyro_bias_body[0] = bias[handle->orient & 3]; /* set the body 0 */
2137 if ((handle->orient & 4) != 0) /* check bit 3 */
2138 {
2139 gyro_bias_body[0] *= -1; /* *(-1) */
2140 }
2141 gyro_bias_body[1] = bias[(handle->orient >> 3) & 3]; /* set the body 1 */
2142 if ((handle->orient & 0x20) != 0) /* check bit 6 */
2143 {
2144 gyro_bias_body[1] *= -1; /* *(-1) */
2145 }
2146 gyro_bias_body[2] = bias[(handle->orient >> 6) & 3]; /* set the body 2 */
2147 if ((handle->orient & 0x100) != 0) /* check bit 9 */
2148 {
2149 gyro_bias_body[2] *= -1; /* *(-1) */
2150 }
2151
2152 gyro_bias_body[0] = (int32_t)(((int64_t)gyro_bias_body[0] * MPU6500_DMP_GYRO_SF) >> 30); /* set body 0 */
2153 gyro_bias_body[1] = (int32_t)(((int64_t)gyro_bias_body[1] * MPU6500_DMP_GYRO_SF) >> 30); /* set body 1 */
2154 gyro_bias_body[2] = (int32_t)(((int64_t)gyro_bias_body[2] * MPU6500_DMP_GYRO_SF) >> 30); /* set body 2 */
2155
2156 regs[0] = (uint8_t)((gyro_bias_body[0] >> 24) & 0xFF); /* set part 0 */
2157 regs[1] = (uint8_t)((gyro_bias_body[0] >> 16) & 0xFF); /* set part 1 */
2158 regs[2] = (uint8_t)((gyro_bias_body[0] >> 8) & 0xFF); /* set part 2 */
2159 regs[3] = (uint8_t)(gyro_bias_body[0] & 0xFF); /* set part 3 */
2160 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_EXT_GYRO_BIAS_X, (uint8_t *)regs, 4); /* write data */
2161 if (res != 0) /* check result */
2162 {
2163 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2164
2165 return 1; /* return error */
2166 }
2167 regs[0] = (uint8_t)((gyro_bias_body[1] >> 24) & 0xFF); /* set part 0 */
2168 regs[1] = (uint8_t)((gyro_bias_body[1] >> 16) & 0xFF); /* set part 1 */
2169 regs[2] = (uint8_t)((gyro_bias_body[1] >> 8) & 0xFF); /* set part 2 */
2170 regs[3] = (uint8_t)(gyro_bias_body[1] & 0xFF); /* set part 3 */
2171 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_EXT_GYRO_BIAS_Y, (uint8_t *)regs, 4); /* write data */
2172 if (res != 0) /* check result */
2173 {
2174 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2175
2176 return 1; /* return error */
2177 }
2178 regs[0] = (uint8_t)((gyro_bias_body[2] >> 24) & 0xFF); /* set part 0 */
2179 regs[1] = (uint8_t)((gyro_bias_body[2] >> 16) & 0xFF); /* set part 1 */
2180 regs[2] = (uint8_t)((gyro_bias_body[2] >> 8) & 0xFF); /* set part 2 */
2181 regs[3] = (uint8_t)(gyro_bias_body[2] & 0xFF); /* set part 3 */
2182 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_EXT_GYRO_BIAS_Z, (uint8_t *)regs, 4); /* write data */
2183 if (res != 0) /* check result */
2184 {
2185 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2186
2187 return 1; /* return error */
2188 }
2189
2190 return 0; /* success return 0 */
2191}
2192
2205uint8_t mpu6500_dmp_set_accel_bias(mpu6500_handle_t *handle, int32_t bias[3])
2206{
2207 uint8_t res;
2208 uint8_t prev;
2209 uint8_t range;
2210 int32_t accel_bias_body[3];
2211 uint8_t regs[12];
2212 int64_t accel_sf;
2213
2214 if (handle == NULL) /* check handle */
2215 {
2216 return 2; /* return error */
2217 }
2218 if (handle->inited != 1) /* check handle initialization */
2219 {
2220 return 3; /* return error */
2221 }
2222 if (handle->dmp_inited != 1) /* check dmp initialization */
2223 {
2224 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
2225
2226 return 4; /* return error */
2227 }
2228
2229 res = a_mpu6500_read(handle, MPU6500_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* read accelerometer config */
2230 if (res != 0) /* check result */
2231 {
2232 handle->debug_print("mpu6500: read accelerometer config failed.\n"); /* read accelerometer config failed */
2233
2234 return 1; /* return error */
2235 }
2236 range = ((prev >> 3) & 0x3); /* get the range */
2237 if (range == 0) /* if 2g */
2238 {
2239 accel_sf = (int64_t)16384 << 15; /* set the accel sf */
2240 }
2241 else if (range == 1) /* if 4g */
2242 {
2243 accel_sf = (int64_t)8192 << 15; /* set the accel sf */
2244 }
2245 else if (range == 2) /* if 8g */
2246 {
2247 accel_sf = (int64_t)4096 << 15; /* set the accel sf */
2248 }
2249 else /* if 16g */
2250 {
2251 accel_sf = (int64_t)2048 << 15; /* set the accel sf */
2252 }
2253
2254 accel_bias_body[0] = bias[handle->orient & 3]; /* set the bias body 0 */
2255 if ((handle->orient & 4) != 0) /* check the orient */
2256 {
2257 accel_bias_body[0] *= -1; /* *(-1) */
2258 }
2259 accel_bias_body[1] = bias[(handle->orient >> 3) & 3]; /* set the bias body 1 */
2260 if ((handle->orient & 0x20) != 0) /* check the orient */
2261 {
2262 accel_bias_body[1] *= -1; /* *(-1) */
2263 }
2264 accel_bias_body[2] = bias[(handle->orient >> 6) & 3]; /* set the bias body 2 */
2265 if ((handle->orient & 0x100) != 0) /* check the orient */
2266 {
2267 accel_bias_body[2] *= -1; /* *(-1) */
2268 }
2269
2270 accel_bias_body[0] = (int32_t)(((int64_t)accel_bias_body[0] * accel_sf) >> 30); /* set the bias body 0 */
2271 accel_bias_body[1] = (int32_t)(((int64_t)accel_bias_body[1] * accel_sf) >> 30); /* set the bias body 1 */
2272 accel_bias_body[2] = (int32_t)(((int64_t)accel_bias_body[2] * accel_sf) >> 30); /* set the bias body 2 */
2273 regs[0] = (uint8_t)((accel_bias_body[0] >> 24) & 0xFF); /* set reg 0 */
2274 regs[1] = (uint8_t)((accel_bias_body[0] >> 16) & 0xFF); /* set reg 1 */
2275 regs[2] = (uint8_t)((accel_bias_body[0] >> 8) & 0xFF); /* set reg 2 */
2276 regs[3] = (uint8_t)(accel_bias_body[0] & 0xFF); /* set reg 3 */
2277 regs[4] = (uint8_t)((accel_bias_body[1] >> 24) & 0xFF); /* set reg 4 */
2278 regs[5] = (uint8_t)((accel_bias_body[1] >> 16) & 0xFF); /* set reg 5 */
2279 regs[6] = (uint8_t)((accel_bias_body[1] >> 8) & 0xFF); /* set reg 6 */
2280 regs[7] = (uint8_t)(accel_bias_body[1] & 0xFF); /* set reg 7 */
2281 regs[8] = (uint8_t)((accel_bias_body[2] >> 24) & 0xFF); /* set reg 8 */
2282 regs[9] = (uint8_t)((accel_bias_body[2] >> 16) & 0xFF); /* set reg 9 */
2283 regs[10] = (uint8_t)((accel_bias_body[2] >> 8) & 0xFF); /* set reg 10 */
2284 regs[11] = (uint8_t)(accel_bias_body[2] & 0xFF); /* set reg 11 */
2285 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_ACCEL_BIAS, (uint8_t *)regs, 12); /* write data */
2286 if (res != 0) /* check result */
2287 {
2288 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2289
2290 return 1; /* return error */
2291 }
2292
2293 return 0; /* success return 0 */
2294}
2295
2308uint8_t mpu6500_dmp_set_orientation(mpu6500_handle_t *handle, int8_t mat[9])
2309{
2310 uint8_t gyro_axes[4] = {0x4C, 0xCD, 0x6C, 0x00};
2311 uint8_t accel_axes[4] = {0x0C, 0xC9, 0x2C, 0x00 };
2312 uint8_t gyro_sign[4] = {0x36, 0x56, 0x76, 0x00 };
2313 uint8_t accel_sign[4] = {0x26, 0x46, 0x66, 0x00 };
2314 uint8_t res;
2315 uint8_t gyro_regs[3];
2316 uint8_t accel_regs[3];
2317 uint16_t orient;
2318
2319 if (handle == NULL) /* check handle */
2320 {
2321 return 2; /* return error */
2322 }
2323 if (handle->inited != 1) /* check handle initialization */
2324 {
2325 return 3; /* return error */
2326 }
2327 if (handle->dmp_inited != 1) /* check dmp initialization */
2328 {
2329 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
2330
2331 return 4; /* return error */
2332 }
2333
2334 orient = a_mpu6500_inv_orientation_matrix_to_scalar(mat); /* inv orientation matrix to scalar */
2335 gyro_regs[0] = gyro_axes[orient & 3]; /* set the gyro regs 0 */
2336 gyro_regs[1] = gyro_axes[(orient >> 3) & 3]; /* set the gyro regs 1 */
2337 gyro_regs[2] = gyro_axes[(orient >> 6) & 3]; /* set the gyro regs 2 */
2338 accel_regs[0] = accel_axes[orient & 3]; /* set the accel regs 0 */
2339 accel_regs[1] = accel_axes[(orient >> 3) & 3]; /* set the accel regs 1 */
2340 accel_regs[2] = accel_axes[(orient >> 6) & 3]; /* set the accel regs 2 */
2341 res = a_mpu6500_write_mem(handle, MPU6500_DMP_FCFG_1,
2342 (uint8_t *)gyro_regs, 3); /* write data */
2343 if (res != 0) /* check result */
2344 {
2345 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2346
2347 return 1; /* return error */
2348 }
2349 res = a_mpu6500_write_mem(handle, MPU6500_DMP_FCFG_2,
2350 (uint8_t *)accel_regs, 3); /* write data */
2351 if (res != 0) /* check result */
2352 {
2353 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2354
2355 return 1; /* return error */
2356 }
2357
2358 memcpy(gyro_regs, gyro_sign, 3); /* copy the gyro regs */
2359 memcpy(accel_regs, accel_sign, 3); /* copy the accel regs */
2360 if ((orient & 4) != 0) /* bit 3 */
2361 {
2362 gyro_regs[0] |= 1; /* set 1 */
2363 accel_regs[0] |= 1; /* set 1 */
2364 }
2365 if ((orient & 0x20) != 0) /* bit 6 */
2366 {
2367 gyro_regs[1] |= 1; /* set 1 */
2368 accel_regs[1] |= 1; /* set 1 */
2369 }
2370 if ((orient & 0x100) != 0) /* bit 9 */
2371 {
2372 gyro_regs[2] |= 1; /* set 1 */
2373 accel_regs[2] |= 1; /* set 1 */
2374 }
2375 res = a_mpu6500_write_mem(handle, MPU6500_DMP_FCFG_3,
2376 (uint8_t *)gyro_regs, 3); /* write data */
2377 if (res != 0) /* check result */
2378 {
2379 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2380
2381 return 1; /* return error */
2382 }
2383 res = a_mpu6500_write_mem(handle, MPU6500_DMP_FCFG_7,
2384 (uint8_t *)accel_regs, 3); /* write data */
2385 if (res != 0) /* check result */
2386 {
2387 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2388
2389 return 1; /* return error */
2390 }
2391 handle->orient = orient; /* set the orient */
2392
2393 return 0; /* success return 0 */
2394}
2395
2412uint8_t mpu6500_dmp_set_feature(mpu6500_handle_t *handle, uint16_t mask)
2413{
2414 uint8_t res;
2415 uint8_t tmp[10];
2416
2417 if (handle == NULL) /* check handle */
2418 {
2419 return 2; /* return error */
2420 }
2421 if (handle->inited != 1) /* check handle initialization */
2422 {
2423 return 3; /* return error */
2424 }
2425 if (handle->dmp_inited != 1) /* check dmp initialization */
2426 {
2427 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
2428
2429 return 4; /* return error */
2430 }
2431
2432 tmp[0] = (uint8_t)((MPU6500_DMP_GYRO_SF >> 24) & 0xFF); /* set the param 0 */
2433 tmp[1] = (uint8_t)((MPU6500_DMP_GYRO_SF >> 16) & 0xFF); /* set the param 1 */
2434 tmp[2] = (uint8_t)((MPU6500_DMP_GYRO_SF >> 8) & 0xFF); /* set the param 2 */
2435 tmp[3] = (uint8_t)(MPU6500_DMP_GYRO_SF & 0xFF); /* set the param 3 */
2436 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_0_104, tmp, 4); /* write data */
2437 if (res != 0) /* check result */
2438 {
2439 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2440
2441 return 1; /* return error */
2442 }
2443
2444 tmp[0] = 0xA3;
2445 if ((mask & MPU6500_DMP_FEATURE_SEND_RAW_ACCEL) != 0) /* set the raw accel */
2446 {
2447 tmp[1] = 0xC0; /* set the param 1 */
2448 tmp[2] = 0xC8; /* set the param 2 */
2449 tmp[3] = 0xC2; /* set the param 3 */
2450 }
2451 else
2452 {
2453 tmp[1] = 0xA3; /* set the param 1 */
2454 tmp[2] = 0xA3; /* set the param 2 */
2455 tmp[3] = 0xA3; /* set the param 3 */
2456 }
2457 if ((mask & MPU6500_DMP_FEATURE_SEND_ANY_GYRO) != 0) /* set any gyro */
2458 {
2459 tmp[4] = 0xC4; /* set the param 4 */
2460 tmp[5] = 0xCC; /* set the param 5 */
2461 tmp[6] = 0xC6; /* set the param 6 */
2462 }
2463 else
2464 {
2465 tmp[4] = 0xA3; /* set the param 4 */
2466 tmp[5] = 0xA3; /* set the param 5 */
2467 tmp[6] = 0xA3; /* set the param 6 */
2468 }
2469 tmp[7] = 0xA3; /* set the param 7 */
2470 tmp[8] = 0xA3; /* set the param 8 */
2471 tmp[9] = 0xA3; /* set the param 9 */
2472 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_15, tmp, 10); /* write data */
2473 if (res != 0) /* check result */
2474 {
2475 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2476
2477 return 1; /* return error */
2478 }
2479
2480 if ((mask & (MPU6500_DMP_FEATURE_TAP | MPU6500_DMP_FEATURE_ORIENT)) != 0) /* set the cfg */
2481 {
2482 tmp[0] = 0x20; /* set the param */
2483 }
2484 else
2485 {
2486 tmp[0] = 0xD8; /* set the param */
2487 }
2488 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_27, tmp, 1); /* write data */
2489 if (res != 0) /* check result */
2490 {
2491 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2492
2493 return 1; /* return error */
2494 }
2495
2496 if ((mask & MPU6500_DMP_FEATURE_GYRO_CAL) != 0) /* if true */
2497 {
2498 uint8_t regs[9] = {0xb8, 0xaa, 0xb3, 0x8d, 0xb4, 0x98, 0x0d, 0x35, 0x5d};
2499
2500 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_MOTION_BIAS, regs, 9); /* write data */
2501 if (res != 0) /* check result */
2502 {
2503 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2504
2505 return 1; /* return error */
2506 }
2507 }
2508 else
2509 {
2510 uint8_t regs[9] = {0xb8, 0xaa, 0xaa, 0xaa, 0xb0, 0x88, 0xc3, 0xc5, 0xc7};
2511
2512 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_MOTION_BIAS, regs, 9); /* write data */
2513 if (res != 0) /* check result */
2514 {
2515 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2516
2517 return 1; /* return error */
2518 }
2519 }
2520
2521 if ((mask & MPU6500_DMP_FEATURE_SEND_ANY_GYRO) != 0) /* check the gyro */
2522 {
2523 if ((mask & MPU6500_DMP_FEATURE_SEND_CAL_GYRO) != 0) /* set the cal gyro */
2524 {
2525 tmp[0] = 0xB2; /* set the param 0 */
2526 tmp[1] = 0x8B; /* set the param 1 */
2527 tmp[2] = 0xB6; /* set the param 2 */
2528 tmp[3] = 0x9B; /* set the param 3 */
2529 }
2530 else
2531 {
2532 tmp[0] = 0xC0; /* set the param 0 */
2533 tmp[1] = 0x80; /* set the param 1 */
2534 tmp[2] = 0xC2; /* set the param 2 */
2535 tmp[3] = 0x90; /* set the param 3 */
2536 }
2537 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_GYRO_RAW_DATA, tmp, 4); /* write data */
2538 if (res != 0) /* check result */
2539 {
2540 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2541
2542 return 1; /* return error */
2543 }
2544 }
2545
2546 if ((mask & MPU6500_DMP_FEATURE_TAP) != 0) /* check the tap */
2547 {
2548 uint8_t prev;
2549 uint16_t ms;
2550 uint16_t dps;
2551 uint32_t thresh_scaled;
2552 uint8_t range;
2553 uint16_t dmp_thresh;
2554 uint16_t dmp_thresh_2;
2555 float scaled_thresh;
2556
2557 tmp[0] = 0xF8; /* set the param */
2558 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_20, tmp, 1); /* write data */
2559 if (res != 0) /* check result */
2560 {
2561 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2562
2563 return 1; /* return error */
2564 }
2565
2566 scaled_thresh = (float)MPU6500_DMP_TAP_THRESH / MPU6500_DMP_SAMPLE_RATE; /* get the scaled thresh */
2567 res = a_mpu6500_read(handle, MPU6500_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* read accelerometer config */
2568 if (res != 0) /* check result */
2569 {
2570 handle->debug_print("mpu6500: read accelerometer config failed.\n"); /* read accelerometer config failed */
2571
2572 return 1; /* return error */
2573 }
2574 range = ((prev >> 3) & 0x3); /* get the range */
2575 if (range == 0) /* if 2g */
2576 {
2577 dmp_thresh = (uint16_t)(scaled_thresh * 16384); /* set dmp thresh */
2578 dmp_thresh_2 = (uint16_t)(scaled_thresh * 12288); /* set dmp thresh2 */
2579 }
2580 else if (range == 1) /* if 4g */
2581 {
2582 dmp_thresh = (uint16_t)(scaled_thresh * 8192); /* set dmp thresh */
2583 dmp_thresh_2 = (uint16_t)(scaled_thresh * 6144); /* set dmp thresh2 */
2584 }
2585 else if (range == 2) /* if 8g */
2586 {
2587 dmp_thresh = (uint16_t)(scaled_thresh * 4096); /* set dmp thresh */
2588 dmp_thresh_2 = (uint16_t)(scaled_thresh * 3072); /* set dmp thresh2 */
2589 }
2590 else /* if 16g */
2591 {
2592 dmp_thresh = (uint16_t)(scaled_thresh * 2048); /* set dmp thresh */
2593 dmp_thresh_2 = (uint16_t)(scaled_thresh * 1536); /* set dmp thresh2 */
2594 }
2595 tmp[0] = (uint8_t)(dmp_thresh >> 8); /* set part 0 */
2596 tmp[1] = (uint8_t)(dmp_thresh & 0xFF); /* set part 1 */
2597 tmp[2] = (uint8_t)(dmp_thresh_2 >> 8); /* set part 2 */
2598 tmp[3] = (uint8_t)(dmp_thresh_2 & 0xFF); /* set part 3 */
2599
2600 res = a_mpu6500_write_mem(handle, MPU6500_DMP_TAP_THX, tmp, 2); /* write tap threshold x */
2601 if (res != 0) /* check result */
2602 {
2603 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2604
2605 return 1; /* return error */
2606 }
2607 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_1_36, tmp + 2, 2); /* write register 36 */
2608 if (res != 0) /* check result */
2609 {
2610 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2611
2612 return 1; /* return error */
2613 }
2614
2615 res = a_mpu6500_write_mem(handle, MPU6500_DMP_TAP_THY, tmp, 2); /* write tap threshold y */
2616 if (res != 0) /* check result */
2617 {
2618 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2619
2620 return 1; /* return error */
2621 }
2622 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_1_40, tmp + 2, 2); /* write register 40 */
2623 if (res != 0) /* check result */
2624 {
2625 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2626
2627 return 1; /* return error */
2628 }
2629
2630 res = a_mpu6500_write_mem(handle, MPU6500_DMP_TAP_THZ, tmp, 2); /* write tap threshold z */
2631 if (res != 0) /* check result */
2632 {
2633 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2634
2635 return 1; /* return error */
2636 }
2637 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_1_44, tmp + 2, 2); /* write register 44 */
2638 if (res != 0) /* check result */
2639 {
2640 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2641
2642 return 1; /* return error */
2643 }
2644
2645 tmp[0] = 0x3F; /* enable all tap axis */
2646 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_1_72, tmp, 1); /* write data */
2647 if (res != 0) /* check result */
2648 {
2649 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2650
2651 return 1; /* return error */
2652 }
2653
2654 tmp[0] = MPU6500_DMP_TAP_MIN_TAP_COUNT - 1; /* set the counter */
2655 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_1_79, tmp, 1); /* write data */
2656 if (res != 0) /* check result */
2657 {
2658 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2659
2660 return 1; /* return error */
2661 }
2662
2663 ms = MPU6500_DMP_TAP_TIME; /* set tap time */
2664 ms /= (1000 / MPU6500_DMP_SAMPLE_RATE); /* convert time */
2665 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
2666 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
2667
2668 res = a_mpu6500_write_mem(handle, MPU6500_DMP_TAPW_MIN, tmp, 2); /* write data */
2669 if (res != 0) /* check result */
2670 {
2671 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2672
2673 return 1; /* return error */
2674 }
2675
2676 ms = MPU6500_DMP_TAP_TIME_MULTI; /* set tap time multi */
2677 ms /= (1000 / MPU6500_DMP_SAMPLE_RATE); /* convert time */
2678 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
2679 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
2680
2681 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_1_218, tmp, 2); /* write data */
2682 if (res != 0) /* check result */
2683 {
2684 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2685
2686 return 1; /* return error */
2687 }
2688
2689 dps = MPU6500_DMP_SHAKE_REJECT_THRESH; /* set the shake reject thresh */
2690 thresh_scaled = MPU6500_DMP_GYRO_SF / 1000 * dps; /* convert to thresh scaled */
2691 tmp[0] = (uint8_t)(((uint32_t)thresh_scaled >> 24) & 0xFF); /* set the part 3 */
2692 tmp[1] = (uint8_t)(((uint32_t)thresh_scaled >> 16) & 0xFF); /* set the part 2 */
2693 tmp[2] = (uint8_t)(((uint32_t)thresh_scaled >> 8) & 0xFF); /* set the part 1 */
2694 tmp[3] = (uint8_t)((uint32_t)thresh_scaled & 0xFF); /* set the part 0 */
2695
2696 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_1_92, tmp, 4); /* write data */
2697 if (res != 0) /* check result */
2698 {
2699 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2700
2701 return 1; /* return error */
2702 }
2703
2704 ms = MPU6500_DMP_SHAKE_REJECT_TIME; /* set the reject time */
2705 ms /= (1000 / MPU6500_DMP_SAMPLE_RATE); /* convert time */
2706 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
2707 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
2708
2709 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_1_90, tmp, 2); /* write data */
2710 if (res != 0) /* check result */
2711 {
2712 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2713
2714 return 1; /* return error */
2715 }
2716
2717 ms = MPU6500_DMP_SHAKE_REJECT_TIMEOUT; /* set the reject timeout */
2718 ms /= (1000 / MPU6500_DMP_SAMPLE_RATE); /* convert time */
2719 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
2720 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
2721
2722 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_1_88, tmp, 2); /* write data */
2723 if (res != 0) /* check result */
2724 {
2725 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2726
2727 return 1; /* return error */
2728 }
2729 }
2730 else
2731 {
2732 tmp[0] = 0xD8; /* set the param */
2733 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_20, tmp, 1); /* write data */
2734 if (res != 0) /* check result */
2735 {
2736 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2737
2738 return 1; /* return error */
2739 }
2740 }
2741
2742 if ((mask & MPU6500_DMP_FEATURE_ORIENT) != 0) /* set the orient */
2743 {
2744 tmp[0] = 0xD9; /* set the param */
2745 }
2746 else
2747 {
2748 tmp[0] = 0xD8; /* set the param */
2749 }
2750 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_ORIENT_INT, tmp, 1); /* write data */
2751 if (res != 0) /* check result */
2752 {
2753 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2754
2755 return 1; /* return error */
2756 }
2757
2758 if ((mask & MPU6500_DMP_FEATURE_3X_QUAT) != 0) /* true */
2759 {
2760 uint8_t regs[4] = {0xC0, 0xC2, 0xC4, 0xC6};
2761
2762 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_LP_QUAT, regs, 4); /* write data */
2763 if (res != 0) /* check result */
2764 {
2765 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2766
2767 return 1; /* return error */
2768 }
2769 res = a_mpu6500_reset_fifo(handle); /* reset the fifo */
2770 if (res != 0) /* check result */
2771 {
2772 handle->debug_print("mpu6500: reset fifo failed.\n"); /* reset fifo failed */
2773
2774 return 1; /* return error */
2775 }
2776 }
2777 else
2778 {
2779 uint8_t regs[4] = {0x8B, 0x8B, 0x8B, 0x8B};
2780
2781 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_LP_QUAT, regs, 4); /* write data */
2782 if (res != 0) /* check result */
2783 {
2784 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2785
2786 return 1; /* return error */
2787 }
2788 res = a_mpu6500_reset_fifo(handle); /* reset the fifo */
2789 if (res != 0) /* check result */
2790 {
2791 handle->debug_print("mpu6500: reset fifo failed.\n"); /* reset fifo failed */
2792
2793 return 1; /* return error */
2794 }
2795 }
2796
2797 if ((mask & MPU6500_DMP_FEATURE_6X_QUAT) != 0) /* enable */
2798 {
2799 uint8_t regs[4] = {0x20, 0x28, 0x30, 0x38};
2800
2801 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_8, regs, 4); /* write data */
2802 if (res != 0) /* check result */
2803 {
2804 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2805
2806 return 1; /* return error */
2807 }
2808 res = a_mpu6500_reset_fifo(handle); /* reset the fifo */
2809 if (res != 0) /* check result */
2810 {
2811 handle->debug_print("mpu6500: reset fifo failed.\n"); /* reset fifo failed */
2812
2813 return 1; /* return error */
2814 }
2815 }
2816 else
2817 {
2818 uint8_t regs[4] = {0xA3, 0xA3, 0xA3, 0xA3};
2819
2820 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_8, regs, 4); /* write data */
2821 if (res != 0) /* check result */
2822 {
2823 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2824
2825 return 1; /* return error */
2826 }
2827 res = a_mpu6500_reset_fifo(handle); /* reset the fifo */
2828 if (res != 0) /* check result */
2829 {
2830 handle->debug_print("mpu6500: reset fifo failed.\n"); /* reset fifo failed */
2831
2832 return 1; /* return error */
2833 }
2834 }
2835
2836 handle->mask = mask | MPU6500_DMP_FEATURE_PEDOMETER; /* set the mask */
2837
2838 return a_mpu6500_reset_fifo(handle); /* reset the fifo */
2839}
2840
2854uint8_t mpu6500_dmp_set_fifo_rate(mpu6500_handle_t *handle, uint16_t rate)
2855{
2856 uint8_t regs_end[12] = {0xFE, 0xF2, 0xAB,
2857 0xC4, 0xAA, 0xF1,
2858 0xDF, 0xDF, 0xBB,
2859 0xAF, 0xDF, 0xDF};
2860 uint8_t res;
2861 uint16_t d;
2862 uint8_t tmp[2];
2863
2864 if (handle == NULL) /* check handle */
2865 {
2866 return 2; /* return error */
2867 }
2868 if (handle->inited != 1) /* check handle initialization */
2869 {
2870 return 3; /* return error */
2871 }
2872 if (handle->dmp_inited != 1) /* check dmp initialization */
2873 {
2874 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
2875
2876 return 4; /* return error */
2877 }
2878 if (rate > MPU6500_DMP_SAMPLE_RATE) /* check rate */
2879 {
2880 handle->debug_print("mpu6500: rate > 200.\n"); /* rate > 200 */
2881
2882 return 5; /* return error */
2883 }
2884
2885 d = MPU6500_DMP_SAMPLE_RATE / rate - 1; /* set div */
2886 tmp[0] = (uint8_t)((d >> 8) & 0xFF); /* set tmp part0 */
2887 tmp[1] = (uint8_t)(d & 0xFF); /* set tmp part1 */
2888
2889 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_0_22, tmp, 2); /* write data */
2890 if (res != 0) /* check result */
2891 {
2892 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2893
2894 return 1; /* return error */
2895 }
2896 res = a_mpu6500_write_mem(handle, MPU6500_DMP_CFG_6,
2897 (uint8_t *)regs_end, 12); /* write data */
2898 if (res != 0) /* check result */
2899 {
2900 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
2901
2902 return 1; /* return error */
2903 }
2904
2905 return 0; /* success return 0 */
2906}
2907
2920uint8_t mpu6500_dmp_get_fifo_rate(mpu6500_handle_t *handle, uint16_t *rate)
2921{
2922 uint8_t res;
2923 uint16_t d;
2924 uint8_t tmp[2];
2925
2926 if (handle == NULL) /* check handle */
2927 {
2928 return 2; /* return error */
2929 }
2930 if (handle->inited != 1) /* check handle initialization */
2931 {
2932 return 3; /* return error */
2933 }
2934 if (handle->dmp_inited != 1) /* check dmp initialization */
2935 {
2936 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
2937
2938 return 4; /* return error */
2939 }
2940
2941 res = a_mpu6500_read_mem(handle, MPU6500_DMP_D_0_22, tmp, 2); /* read data */
2942 if (res != 0) /* check result */
2943 {
2944 handle->debug_print("mpu6500: read mem failed.\n"); /* read mem failed */
2945
2946 return 1; /* return error */
2947 }
2948 d = (uint16_t)tmp[0] << 8 | tmp[1]; /* get the div */
2949 *rate = MPU6500_DMP_SAMPLE_RATE / (d + 1); /* set the rate */
2950
2951 return 0; /* success return 0 */
2952}
2953
2968{
2969 uint8_t res;
2970 uint8_t tmp;
2971 uint8_t pos;
2972
2973 if (handle == NULL) /* check handle */
2974 {
2975 return 2; /* return error */
2976 }
2977 if (handle->inited != 1) /* check handle initialization */
2978 {
2979 return 3; /* return error */
2980 }
2981 if (handle->dmp_inited != 1) /* check dmp initialization */
2982 {
2983 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
2984
2985 return 4; /* return error */
2986 }
2987
2988 res = a_mpu6500_read_mem(handle, MPU6500_DMP_D_1_72, &tmp, 1); /* read data */
2989 if (res != 0) /* check result */
2990 {
2991 handle->debug_print("mpu6500: read mem failed.\n"); /* read mem failed */
2992
2993 return 1; /* return error */
2994 }
2995 pos = (uint8_t)((axis - 5) * 2); /* get the pos */
2996 if (enable == MPU6500_BOOL_TRUE) /* if enable */
2997 {
2998 tmp |= (3 << pos); /* enable */
2999 }
3000 else
3001 {
3002 tmp &= ~(3 << pos); /* disable */
3003 }
3004 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_1_72, &tmp, 1); /* write data */
3005 if (res != 0) /* check result */
3006 {
3007 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
3008
3009 return 1; /* return error */
3010 }
3011
3012 return 0; /* success return 0 */
3013}
3014
3029{
3030 uint8_t res;
3031 uint8_t tmp;
3032 uint8_t pos;
3033
3034 if (handle == NULL) /* check handle */
3035 {
3036 return 2; /* return error */
3037 }
3038 if (handle->inited != 1) /* check handle initialization */
3039 {
3040 return 3; /* return error */
3041 }
3042 if (handle->dmp_inited != 1) /* check dmp initialization */
3043 {
3044 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
3045
3046 return 4; /* return error */
3047 }
3048
3049 res = a_mpu6500_read_mem(handle, MPU6500_DMP_D_1_72, &tmp, 1); /* read data */
3050 if (res != 0) /* check result */
3051 {
3052 handle->debug_print("mpu6500: read mem failed.\n"); /* read mem failed */
3053
3054 return 1; /* return error */
3055 }
3056 pos = (uint8_t)((axis - 5) * 2); /* get the pos */
3057 if (((tmp >> pos) & 0x3) == 0x3) /* if enable */
3058 {
3059 *enable = MPU6500_BOOL_TRUE; /* set enable */
3060 }
3061 else
3062 {
3063 *enable = MPU6500_BOOL_FALSE; /* set disable */
3064 }
3065
3066 return 0; /* success return 0 */
3067}
3068
3084uint8_t mpu6500_dmp_set_tap_thresh(mpu6500_handle_t *handle, mpu6500_axis_t axis, uint16_t mg_ms)
3085{
3086 uint8_t res;
3087 uint8_t prev;
3088 uint8_t range;
3089 uint8_t tmp[4];
3090 uint16_t dmp_thresh;
3091 uint16_t dmp_thresh_2;
3092 float scaled_thresh;
3093
3094 if (handle == NULL) /* check handle */
3095 {
3096 return 2; /* return error */
3097 }
3098 if (handle->inited != 1) /* check handle initialization */
3099 {
3100 return 3; /* return error */
3101 }
3102 if (handle->dmp_inited != 1) /* check dmp initialization */
3103 {
3104 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
3105
3106 return 4; /* return error */
3107 }
3108 if (mg_ms > 1600) /* check the mg/ms */
3109 {
3110 handle->debug_print("mpu6500: mg/ms > 1600.\n"); /* mg/ms > 1600 */
3111
3112 return 5; /* return error */
3113 }
3114
3115 scaled_thresh = (float)mg_ms / MPU6500_DMP_SAMPLE_RATE; /* get the scaled thresh */
3116 res = a_mpu6500_read(handle, MPU6500_REG_ACCEL_CONFIG,
3117 (uint8_t *)&prev, 1); /* read accelerometer config */
3118 if (res != 0) /* check result */
3119 {
3120 handle->debug_print("mpu6500: read accelerometer config failed.\n"); /* read accelerometer config failed */
3121
3122 return 1; /* return error */
3123 }
3124 range = ((prev >> 3) & 0x3); /* get the range */
3125 if (range == 0) /* if 2g */
3126 {
3127 dmp_thresh = (uint16_t)(scaled_thresh * 16384); /* set dmp thresh */
3128 dmp_thresh_2 = (uint16_t)(scaled_thresh * 12288); /* set dmp thresh2 */
3129 }
3130 else if (range == 1) /* if 4g */
3131 {
3132 dmp_thresh = (uint16_t)(scaled_thresh * 8192); /* set dmp thresh */
3133 dmp_thresh_2 = (uint16_t)(scaled_thresh * 6144); /* set dmp thresh2 */
3134 }
3135 else if (range == 2) /* if 8g */
3136 {
3137 dmp_thresh = (uint16_t)(scaled_thresh * 4096); /* set dmp thresh */
3138 dmp_thresh_2 = (uint16_t)(scaled_thresh * 3072); /* set dmp thresh2 */
3139 }
3140 else /* if 16g */
3141 {
3142 dmp_thresh = (uint16_t)(scaled_thresh * 2048); /* set dmp thresh */
3143 dmp_thresh_2 = (uint16_t)(scaled_thresh * 1536); /* set dmp thresh2 */
3144 }
3145 tmp[0] = (uint8_t)(dmp_thresh >> 8); /* set part 0 */
3146 tmp[1] = (uint8_t)(dmp_thresh & 0xFF); /* set part 1 */
3147 tmp[2] = (uint8_t)(dmp_thresh_2 >> 8); /* set part 2 */
3148 tmp[3] = (uint8_t)(dmp_thresh_2 & 0xFF); /* set part 3 */
3149
3150 if (axis == MPU6500_AXIS_X) /* if axis x */
3151 {
3152 res = a_mpu6500_write_mem(handle, MPU6500_DMP_TAP_THX, tmp, 2); /* write tap threshold x */
3153 if (res != 0) /* check result */
3154 {
3155 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
3156
3157 return 1; /* return error */
3158 }
3159 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_1_36, tmp + 2, 2); /* write register 36 */
3160 if (res != 0) /* check result */
3161 {
3162 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
3163
3164 return 1; /* return error */
3165 }
3166
3167 return 0; /* success return 0 */
3168 }
3169 else if (axis == MPU6500_AXIS_Y) /* if axis y */
3170 {
3171 res = a_mpu6500_write_mem(handle, MPU6500_DMP_TAP_THY, tmp, 2); /* write tap threshold y */
3172 if (res != 0) /* check result */
3173 {
3174 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
3175
3176 return 1; /* return error */
3177 }
3178 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_1_40, tmp + 2, 2); /* write register 40 */
3179 if (res != 0) /* check result */
3180 {
3181 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
3182
3183 return 1; /* return error */
3184 }
3185
3186 return 0; /* success return 0 */
3187 }
3188 else if (axis == MPU6500_AXIS_Z) /* if axis z */
3189 {
3190 res = a_mpu6500_write_mem(handle, MPU6500_DMP_TAP_THZ, tmp, 2); /* write tap threshold z */
3191 if (res != 0) /* check result */
3192 {
3193 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
3194
3195 return 1; /* return error */
3196 }
3197 res = a_mpu6500_write_mem(handle, MPU6500_DMP_D_1_44, tmp + 2, 2); /* write register 44 */
3198 if (res != 0) /* check result */
3199 {
3200 handle->debug_print("mpu6500: write mem failed.\n"); /* write mem failed */
3201
3202 return 1; /* return error */
3203 }
3204
3205 return 0; /* success return 0 */
3206 }
3207 else
3208 {
3209 handle->debug_print("mpu6500: invalid axis.\n"); /* invalid axis */
3210
3211 return 6; /* return error */
3212 }
3213}
3214
3229uint8_t mpu6500_dmp_get_tap_thresh(mpu6500_handle_t *handle, mpu6500_axis_t axis, uint16_t *mg_ms)
3230{
3231 uint8_t res;
3232 uint8_t prev;
3233 uint8_t range;
3234 uint8_t tmp[2];
3235 uint16_t dmp_thresh;
3236 float scaled_thresh;
3237
3238 if (handle == NULL) /* check handle */
3239 {
3240 return 2; /* return error */
3241 }
3242 if (handle->inited != 1) /* check handle initialization */
3243 {
3244 return 3; /* return error */
3245 }
3246 if (handle->dmp_inited != 1) /* check dmp initialization */
3247 {
3248 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
3249
3250 return 4; /* return error */
3251 }
3252
3253 if (axis == MPU6500_AXIS_X) /* if axis x */
3254 {
3255 res = a_mpu6500_read_mem(handle, MPU6500_DMP_TAP_THX, tmp, 2); /* read tap threshold x */
3256 if (res != 0) /* check result */
3257 {
3258 handle->debug_print("mpu6500: read mem failed.\n"); /* read mem failed */
3259
3260 return 1; /* return error */
3261 }
3262 }
3263 else if (axis == MPU6500_AXIS_Y) /* if axis y */
3264 {
3265 res = a_mpu6500_read_mem(handle, MPU6500_DMP_TAP_THY, tmp, 2); /* read tap threshold y */
3266 if (res != 0) /* check result */
3267 {
3268 handle->debug_print("mpu6500: read mem failed.\n"); /* read mem failed */
3269
3270 return 1; /* return error */
3271 }
3272 }
3273 else if (axis == MPU6500_AXIS_Z) /* if axis z */
3274 {
3275 res = a_mpu6500_read_mem(handle, MPU6500_DMP_TAP_THZ, tmp, 2); /* read tap threshold z */
3276 if (res != 0) /* check result */
3277 {
3278 handle->debug_print("mpu6500: read mem failed.\n"); /* read mem failed */
3279
3280 return 1; /* return error */
3281 }
3282 }
3283 else
3284 {
3285 handle->debug_print("mpu6500: invalid axis.\n"); /* invalid axis */
3286
3287 return 5; /* return error */
3288 }
3289 dmp_thresh = (uint16_t)tmp[0] << 8 | tmp[1]; /* set the dmp thresh */
3290
3291 res = a_mpu6500_read(handle, MPU6500_REG_ACCEL_CONFIG,
3292 (uint8_t *)&prev, 1); /* read accelerometer config */
3293 if (res != 0) /* check result */
3294 {
3295 handle->debug_print("mpu6500: read accelerometer config failed.\n"); /* read accelerometer config failed */
3296
3297 return 1; /* return error */
3298 }
3299 range = ((prev >> 3) & 0x3); /* get the range */
3300 if (range == 0) /* if 2g */
3301 {
3302 scaled_thresh = dmp_thresh / 16384.0f; /* set dmp thresh */
3303 }
3304 else if (range == 1) /* if 4g */
3305 {
3306 scaled_thresh = dmp_thresh / 8192.0f; /* set dmp thresh */
3307 }
3308 else if (range == 2) /* if 8g */
3309 {
3310 scaled_thresh = dmp_thresh / 4096.0f; /* set dmp thresh */
3311 }
3312 else /* if 16g */
3313 {
3314 scaled_thresh = dmp_thresh / 2048.0f; /* set dmp thresh */
3315 }
3316 *mg_ms = (uint16_t)(scaled_thresh * MPU6500_DMP_SAMPLE_RATE); /* set the mg/ms */
3317
3318 return 0; /* success return 0 */
3319}
3320
3346 int16_t (*accel_raw)[3], float (*accel_g)[3],
3347 int16_t (*gyro_raw)[3], float (*gyro_dps)[3],
3348 int32_t (*quat)[4],
3349 float *pitch, float *roll, float *yaw,
3350 uint16_t *l
3351 )
3352{
3353 uint8_t res;
3354 uint8_t i = 0;
3355 uint16_t len;
3356 uint8_t buf[2];
3357 uint8_t prev;
3358 uint16_t count;
3359 uint16_t j;
3360
3361 if (handle == NULL) /* check handle */
3362 {
3363 return 2; /* return error */
3364 }
3365 if (handle->inited != 1) /* check handle initialization */
3366 {
3367 return 3; /* return error */
3368 }
3369 if (handle->dmp_inited != 1) /* check dmp initialization */
3370 {
3371 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
3372
3373 return 4; /* return error */
3374 }
3375
3376 res = a_mpu6500_read(handle, MPU6500_REG_INT_STATUS, (uint8_t *)&prev, 1); /* read config */
3377 if (res != 0) /* check result */
3378 {
3379 handle->debug_print("mpu6500: read int status failed.\n"); /* read int status failed */
3380
3381 return 1; /* return error */
3382 }
3383 if ((prev & (1 << MPU6500_INTERRUPT_FIFO_OVERFLOW)) != 0) /* if fifo overflow */
3384 {
3385 handle->debug_print("mpu6500: fifo overflow.\n"); /* fifo overflow */
3386 (void)a_mpu6500_reset_fifo(handle); /* reset the fifo */
3387
3388 return 6; /* return error */
3389 }
3390
3391 len = 0; /* set len 0 */
3392 if ((handle->mask & MPU6500_DMP_FEATURE_SEND_RAW_ACCEL) != 0) /* check the accel */
3393 {
3394 len += 6; /* size += 6 */
3395 }
3396 if ((handle->mask & MPU6500_DMP_FEATURE_SEND_ANY_GYRO) != 0) /* check the gyro */
3397 {
3398 len += 6; /* size += 6 */
3399 }
3400 if ((handle->mask & (MPU6500_DMP_FEATURE_3X_QUAT | MPU6500_DMP_FEATURE_6X_QUAT)) != 0) /* check the quat */
3401 {
3402 len += 16; /* size += 16 */
3403 }
3404 if ((handle->mask & (MPU6500_DMP_FEATURE_TAP | MPU6500_DMP_FEATURE_ORIENT)) != 0) /* check the tap and orient */
3405 {
3406 len += 4; /* size += 4 */
3407 }
3408 if (len == 0) /* check the len */
3409 {
3410 handle->debug_print("mpu6500: no data.\n"); /* no data */
3411
3412 return 8; /* return error */
3413 }
3414
3415 res = a_mpu6500_read(handle, MPU6500_REG_FIFO_COUNTH, (uint8_t *)buf, 2); /* read fifo count */
3416 if (res != 0) /* check result */
3417 {
3418 handle->debug_print("mpu6500: read fifo count failed.\n"); /* read fifo count failed */
3419
3420 return 1; /* return error */
3421 }
3422 count = (uint16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set count */
3423 count = (count < 1024) ? count : 1024; /* just the counter */
3424 count = (count < (*l) * len) ? count : ((*l) *len); /* just outer buffer size */
3425 count = (count / len) * len; /* len times */
3426 *l = count / len; /* set the output length */
3427 res = a_mpu6500_read(handle, MPU6500_REG_R_W, handle->buf, count); /* read data */
3428 if (res != 0) /* check result */
3429 {
3430 handle->debug_print("mpu6500: read failed.\n"); /* read failed */
3431
3432 return 1; /* return error */
3433 }
3434 if (count < len) /* check the count */
3435 {
3436 handle->debug_print("mpu6500: fifo data is too little.\n"); /* fifo data is too little */
3437
3438 return 7; /* return error */
3439 }
3440
3441 for (j = 0; j < (*l); j++) /* (*l) times */
3442 {
3443 if ((handle->mask & (MPU6500_DMP_FEATURE_3X_QUAT | MPU6500_DMP_FEATURE_6X_QUAT)) != 0) /* check the quat */
3444 {
3445 int32_t quat_q14[4];
3446 int32_t quat_mag_sq;
3447 float q0 = 1.0f, q1 = 0.0f, q2 = 0.0f, q3 = 0.0f;
3448
3449 i = 0; /* set 0 */
3450 quat[j][0] = ((int32_t)handle->buf[0 + len * j] << 24) | ((int32_t)handle->buf[1 + len * j] << 16) |
3451 ((int32_t)handle->buf[2 + len * j] << 8) | handle->buf[3 + len * j]; /* set the quat 0 */
3452 quat[j][1] = ((int32_t)handle->buf[4 + len * j] << 24) | ((int32_t)handle->buf[5 + len * j] << 16) |
3453 ((int32_t)handle->buf[6 + len * j] << 8) | handle->buf[7 + len * j]; /* set the quat 1 */
3454 quat[j][2] = ((int32_t)handle->buf[8 + len * j] << 24) | ((int32_t)handle->buf[9 + len * j] << 16) |
3455 ((int32_t)handle->buf[10 + len * j] << 8) | handle->buf[11 + len * j]; /* set the quat 2 */
3456 quat[j][3] = ((int32_t)handle->buf[12 + len * j] << 24) | ((int32_t)handle->buf[13 + len * j] << 16) |
3457 ((int32_t)handle->buf[14 + len * j] << 8) | handle->buf[15 + len * j]; /* set the quat 3 */
3458 i += 16; /* size += 16 */
3459
3460 quat_q14[0] = quat[j][0] >> 16; /* set the quat q14[0] */
3461 quat_q14[1] = quat[j][1] >> 16; /* set the quat q14[1] */
3462 quat_q14[2] = quat[j][2] >> 16; /* set the quat q14[2] */
3463 quat_q14[3] = quat[j][3] >> 16; /* set the quat q14[3] */
3464 quat_mag_sq = quat_q14[0] * quat_q14[0] + quat_q14[1] * quat_q14[1] +
3465 quat_q14[2] * quat_q14[2] + quat_q14[3] * quat_q14[3]; /* get the quat mag sq */
3466 if ((quat_mag_sq < MPU6500_DMP_QUAT_MAG_SQ_MIN) ||
3467 (quat_mag_sq > MPU6500_DMP_QUAT_MAG_SQ_MAX)) /* check the size */
3468 {
3469 handle->debug_print("mpu6500: quat check error.\n"); /* quat check error */
3470 (void)a_mpu6500_reset_fifo(handle); /* reset the fifo */
3471
3472 return 5; /* return error */
3473 }
3474 q0 = quat[j][0] / 1073741824.0f; /* set q0 */
3475 q1 = quat[j][1] / 1073741824.0f; /* set q1 */
3476 q2 = quat[j][2] / 1073741824.0f; /* set q2 */
3477 q3 = quat[j][3] / 1073741824.0f; /* set q3 */
3478 pitch[j] = asinf(-2 * q1 * q3 + 2 * q0* q2)* 57.3f; /* set pitch */
3479 roll[j] = atan2f(2 * q2 * q3 + 2 * q0 * q1, -2 * q1 * q1 - 2 * q2 * q2 + 1)* 57.3f; /* set roll */
3480 yaw[j] = atan2f(2 * (q1 * q2 + q0 * q3), q0 * q0 + q1 * q1 - q2 * q2 - q3 * q3) * 57.3f; /* set yaw */
3481 }
3482 else
3483 {
3484 quat[j][0] = 0; /* set 0 */
3485 quat[j][1] = 0; /* set 0 */
3486 quat[j][2] = 0; /* set 0 */
3487 quat[j][3] = 0; /* set 0 */
3488 pitch[j] = 0.0f; /* set 0.0f */
3489 roll[j] = 0.0f; /* set 0.0f */
3490 yaw[j] = 0.0f; /* set 0.0f */
3491 }
3492 if ((handle->mask & MPU6500_DMP_FEATURE_SEND_RAW_ACCEL) != 0) /* check the accel */
3493 {
3494 uint8_t accel_conf;
3495
3496 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 */
3497 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 */
3498 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 */
3499 i += 6; /* size += 6 */
3500
3501 res = a_mpu6500_read(handle, MPU6500_REG_ACCEL_CONFIG, (uint8_t *)&accel_conf, 1); /* read accel config */
3502 if (res != 0) /* check result */
3503 {
3504 handle->debug_print("mpu6500: read accel config failed.\n"); /* read accel config failed */
3505
3506 return 1; /* return error */
3507 }
3508 accel_conf = (accel_conf >> 3) & 0x3; /* get the accel conf */
3509 if (accel_conf == 0) /* ±2g */
3510 {
3511 accel_g[j][0] = (float)(accel_raw[j][0]) / 16384.0f; /* set accel x */
3512 accel_g[j][1] = (float)(accel_raw[j][1]) / 16384.0f; /* set accel y */
3513 accel_g[j][2] = (float)(accel_raw[j][2]) / 16384.0f; /* set accel z */
3514 }
3515 else if (accel_conf == 1) /* ±4g */
3516 {
3517 accel_g[j][0] = (float)(accel_raw[j][0]) / 8192.0f; /* set accel x */
3518 accel_g[j][1] = (float)(accel_raw[j][1]) / 8192.0f; /* set accel y */
3519 accel_g[j][2] = (float)(accel_raw[j][2]) / 8192.0f; /* set accel z */
3520 }
3521 else if (accel_conf == 2) /* ±8g */
3522 {
3523 accel_g[j][0] = (float)(accel_raw[j][0]) / 4096.0f; /* set accel x */
3524 accel_g[j][1] = (float)(accel_raw[j][1]) / 4096.0f; /* set accel y */
3525 accel_g[j][2] = (float)(accel_raw[j][2]) / 4096.0f; /* set accel z */
3526 }
3527 else /* ±16g */
3528 {
3529 accel_g[j][0] = (float)(accel_raw[j][0]) / 2048.0f; /* set accel x */
3530 accel_g[j][1] = (float)(accel_raw[j][1]) / 2048.0f; /* set accel y */
3531 accel_g[j][2] = (float)(accel_raw[j][2]) / 2048.0f; /* set accel z */
3532 }
3533 }
3534 else
3535 {
3536 accel_raw[j][0] = 0; /* set 0 */
3537 accel_raw[j][1] = 0; /* set 0 */
3538 accel_raw[j][2] = 0; /* set 0 */
3539 accel_g[j][0] = 0.0f; /* set 0.0f */
3540 accel_g[j][1] = 0.0f; /* set 0.0f */
3541 accel_g[j][2] = 0.0f; /* set 0.0f */
3542 }
3543 if ((handle->mask & MPU6500_DMP_FEATURE_SEND_ANY_GYRO) != 0) /* check the gyro */
3544 {
3545 uint8_t gyro_conf;
3546
3547 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 */
3548 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 */
3549 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 */
3550 i += 6; /* size += 6 */
3551
3552 res = a_mpu6500_read(handle, MPU6500_REG_GYRO_CONFIG, (uint8_t *)&gyro_conf, 1); /* read gyro config */
3553 if (res != 0) /* check result */
3554 {
3555 handle->debug_print("mpu6500: read gyro config failed.\n"); /* read gyro config failed */
3556
3557 return 1; /* return error */
3558 }
3559 gyro_conf = (gyro_conf >> 3) & 0x3; /* get the gyro conf */
3560 if (gyro_conf == 0) /* ±250dps */
3561 {
3562 gyro_dps[j][0] = (float)(gyro_raw[j][0]) / 131.0f; /* set gyro x */
3563 gyro_dps[j][1] = (float)(gyro_raw[j][1]) / 131.0f; /* set gyro y */
3564 gyro_dps[j][2] = (float)(gyro_raw[j][2]) / 131.0f; /* set gyro z */
3565 }
3566 else if (gyro_conf == 1) /* ±500dps */
3567 {
3568 gyro_dps[j][0] = (float)(gyro_raw[j][0]) / 65.5f; /* set gyro x */
3569 gyro_dps[j][1] = (float)(gyro_raw[j][1]) / 65.5f; /* set gyro y */
3570 gyro_dps[j][2] = (float)(gyro_raw[j][2]) / 65.5f; /* set gyro z */
3571 }
3572 else if (gyro_conf == 2) /* ±1000dps */
3573 {
3574 gyro_dps[j][0] = (float)(gyro_raw[j][0]) / 32.8f; /* set gyro x */
3575 gyro_dps[j][1] = (float)(gyro_raw[j][1]) / 32.8f; /* set gyro y */
3576 gyro_dps[j][2] = (float)(gyro_raw[j][2]) / 32.8f; /* set gyro z */
3577 }
3578 else /* ±2000dps */
3579 {
3580 gyro_dps[j][0] = (float)(gyro_raw[j][0]) / 16.4f; /* set gyro x */
3581 gyro_dps[j][1] = (float)(gyro_raw[j][1]) / 16.4f; /* set gyro y */
3582 gyro_dps[j][2] = (float)(gyro_raw[j][2]) / 16.4f; /* set gyro z */
3583 }
3584 }
3585 else
3586 {
3587 gyro_raw[j][0] = 0; /* set 0 */
3588 gyro_raw[j][1] = 0; /* set 0 */
3589 gyro_raw[j][2] = 0; /* set 0 */
3590 gyro_dps[j][0] = 0.0f; /* set 0.0f */
3591 gyro_dps[j][1] = 0.0f; /* set 0.0f */
3592 gyro_dps[j][2] = 0.0f; /* set 0.0f */
3593 }
3594 if ((handle->mask & (MPU6500_DMP_FEATURE_TAP | MPU6500_DMP_FEATURE_ORIENT)) != 0) /* check the tap and orient */
3595 {
3596 a_mpu6500_dmp_decode_gesture(handle, handle->buf + i + len * j); /* run the decode gesture */
3597 }
3598 }
3599
3600 return 0; /* success return 0 */
3601}
3602
3615uint8_t mpu6500_dmp_set_tap_callback(mpu6500_handle_t *handle, void (*callback)(uint8_t count, uint8_t direction))
3616{
3617 if (handle == NULL) /* check handle */
3618 {
3619 return 2; /* return error */
3620 }
3621 if (handle->inited != 1) /* check handle initialization */
3622 {
3623 return 3; /* return error */
3624 }
3625 if (handle->dmp_inited != 1) /* check dmp initialization */
3626 {
3627 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
3628
3629 return 4; /* return error */
3630 }
3631
3632 handle->dmp_tap_callback = callback; /* set the callback */
3633
3634 return 0; /* success return 0 */
3635}
3636
3649uint8_t mpu6500_dmp_set_orient_callback(mpu6500_handle_t *handle, void (*callback)(uint8_t orientation))
3650{
3651 if (handle == NULL) /* check handle */
3652 {
3653 return 2; /* return error */
3654 }
3655 if (handle->inited != 1) /* check handle initialization */
3656 {
3657 return 3; /* return error */
3658 }
3659 if (handle->dmp_inited != 1) /* check dmp initialization */
3660 {
3661 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
3662
3663 return 4; /* return error */
3664 }
3665
3666 handle->dmp_orient_callback = callback; /* set the callback */
3667
3668 return 0; /* success return 0 */
3669}
3670
3684{
3685 uint8_t res;
3686 uint8_t prev;
3687
3688 if (handle == NULL) /* check handle */
3689 {
3690 return 2; /* return error */
3691 }
3692 if (handle->inited != 1) /* check handle initialization */
3693 {
3694 return 3; /* return error */
3695 }
3696 if (handle->dmp_inited != 1) /* check dmp initialization */
3697 {
3698 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
3699
3700 return 4; /* return error */
3701 }
3702
3703 res = a_mpu6500_read(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
3704 if (res != 0) /* check result */
3705 {
3706 handle->debug_print("mpu6500: read user ctrl failed.\n"); /* read user ctrl failed */
3707
3708 return 1; /* return error */
3709 }
3710 prev &= ~(1 << 7); /* clear config */
3711 prev |= enable << 7; /* set config */
3712 res = a_mpu6500_write(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
3713 if (res != 0) /* check result */
3714 {
3715 handle->debug_print("mpu6500: write user ctrl failed.\n"); /* write user ctrl failed */
3716
3717 return 1; /* return error */
3718 }
3719
3720 return 0; /* success return 0 */
3721}
3722
3739 int32_t gyro_offset_raw[3], int32_t accel_offset_raw[3],
3740 int32_t gyro_offset[3], int32_t accel_offset[3])
3741{
3742 uint8_t res;
3743 uint8_t accel_conf;
3744 uint8_t gyro_conf;
3745
3746 if (handle == NULL) /* check handle */
3747 {
3748 return 2; /* return error */
3749 }
3750 if (handle->inited != 1) /* check handle initialization */
3751 {
3752 return 3; /* return error */
3753 }
3754 if (handle->dmp_inited != 1) /* check dmp initialization */
3755 {
3756 handle->debug_print("mpu6500: dmp is not inited.\n"); /* dmp is not inited */
3757
3758 return 4; /* return error */
3759 }
3760
3761 res = a_mpu6500_read(handle, MPU6500_REG_ACCEL_CONFIG, (uint8_t *)&accel_conf, 1); /* read accel config */
3762 if (res != 0) /* check result */
3763 {
3764 handle->debug_print("mpu6500: read accel config failed.\n"); /* read accel config failed */
3765
3766 return 1; /* return error */
3767 }
3768 res = a_mpu6500_read(handle, MPU6500_REG_GYRO_CONFIG, (uint8_t *)&gyro_conf, 1); /* read gyro config */
3769 if (res != 0) /* check result */
3770 {
3771 handle->debug_print("mpu6500: read gyro config failed.\n"); /* read gyro config failed */
3772
3773 return 1; /* return error */
3774 }
3775 accel_conf = (accel_conf >> 3) & 0x3; /* get the accel conf */
3776 gyro_conf = (gyro_conf >> 3) & 0x3; /* get the gyro conf */
3777 if (accel_conf == 0) /* ±2g */
3778 {
3779 accel_offset[0] = (int32_t)(accel_offset_raw[0] * 16384.0f); /* set accel offset 0 */
3780 accel_offset[1] = (int32_t)(accel_offset_raw[1] * 16384.0f); /* set accel offset 1 */
3781 accel_offset[2] = (int32_t)(accel_offset_raw[2] * 16384.0f); /* set accel offset 2 */
3782 }
3783 else if (accel_conf == 1) /* ±4g */
3784 {
3785 accel_offset[0] = (int32_t)(accel_offset_raw[0] * 8192.0f); /* set accel offset 0 */
3786 accel_offset[1] = (int32_t)(accel_offset_raw[1] * 8192.0f); /* set accel offset 1 */
3787 accel_offset[2] = (int32_t)(accel_offset_raw[2] * 8192.0f); /* set accel offset 2 */
3788 }
3789 else if (accel_conf == 2) /* ±8g */
3790 {
3791 accel_offset[0] = (int32_t)(accel_offset_raw[0] * 4096.0f); /* set accel offset 0 */
3792 accel_offset[1] = (int32_t)(accel_offset_raw[1] * 4096.0f); /* set accel offset 1 */
3793 accel_offset[2] = (int32_t)(accel_offset_raw[2] * 4096.0f); /* set accel offset 2 */
3794 }
3795 else /* ±16g */
3796 {
3797 accel_offset[0] = (int32_t)(accel_offset_raw[0] * 2048.0f); /* set accel offset 0 */
3798 accel_offset[1] = (int32_t)(accel_offset_raw[1] * 2048.0f); /* set accel offset 1 */
3799 accel_offset[2] = (int32_t)(accel_offset_raw[2] * 2048.0f); /* set accel offset 2 */
3800 }
3801 if (gyro_conf == 0) /* ±250dps */
3802 {
3803 gyro_offset[0] = (int32_t)(gyro_offset_raw[0] * 131.f); /* set gyro offset 0 */
3804 gyro_offset[1] = (int32_t)(gyro_offset_raw[1] * 131.f); /* set gyro offset 1 */
3805 gyro_offset[2] = (int32_t)(gyro_offset_raw[2] * 131.f); /* set gyro offset 2 */
3806 }
3807 else if (gyro_conf == 1) /* ±500dps */
3808 {
3809 gyro_offset[0] = (int32_t)(gyro_offset_raw[0] * 65.5f); /* set gyro offset 0 */
3810 gyro_offset[1] = (int32_t)(gyro_offset_raw[1] * 65.5f); /* set gyro offset 1 */
3811 gyro_offset[2] = (int32_t)(gyro_offset_raw[2] * 65.5f); /* set gyro offset 2 */
3812 }
3813 else if (gyro_conf == 2) /* ±1000dps */
3814 {
3815 gyro_offset[0] = (int32_t)(gyro_offset_raw[0] * 32.8f); /* set gyro offset 0 */
3816 gyro_offset[1] = (int32_t)(gyro_offset_raw[1] * 32.8f); /* set gyro offset 1 */
3817 gyro_offset[2] = (int32_t)(gyro_offset_raw[2] * 32.8f); /* set gyro offset 2 */
3818 }
3819 else /* ±2000dps */
3820 {
3821 gyro_offset[0] = (int32_t)(gyro_offset_raw[0] * 16.4f); /* set gyro offset 0 */
3822 gyro_offset[1] = (int32_t)(gyro_offset_raw[1] * 16.4f); /* set gyro offset 1 */
3823 gyro_offset[2] = (int32_t)(gyro_offset_raw[2] * 16.4f); /* set gyro offset 2 */
3824 }
3825
3826 return 0; /* success return 0 */
3827}
3828
3839{
3840 if (handle == NULL) /* check handle */
3841 {
3842 return 2; /* return error */
3843 }
3844
3845 handle->iic_spi = (uint8_t)interface; /* set interface */
3846
3847 return 0; /* success return 0 */
3848}
3849
3860{
3861 if (handle == NULL) /* check handle */
3862 {
3863 return 2; /* return error */
3864 }
3865
3866 *interface = (mpu6500_interface_t)(handle->iic_spi); /* get interface */
3867
3868 return 0; /* success return 0 */
3869}
3870
3881{
3882 if (handle == NULL) /* check handle */
3883 {
3884 return 2; /* return error */
3885 }
3886
3887 handle->iic_addr = (uint8_t)addr_pin; /* set iic addr */
3888
3889 return 0; /* success return 0 */
3890}
3891
3902{
3903 if (handle == NULL) /* check handle */
3904 {
3905 return 2; /* return error */
3906 }
3907
3908 *addr_pin = (mpu6500_address_t)(handle->iic_addr); /* get iic addr */
3909
3910 return 0; /* success return 0 */
3911}
3912
3926{
3927 uint8_t res, prev;
3928 uint32_t timeout;
3929
3930 if (handle == NULL) /* check handle */
3931 {
3932 return 2; /* return error */
3933 }
3934 if (handle->debug_print == NULL) /* check debug_print */
3935 {
3936 return 3; /* return error */
3937 }
3938 if (handle->iic_init == NULL) /* check iic_init */
3939 {
3940 handle->debug_print("mpu6500: iic_init is null.\n"); /* iic_init is null */
3941
3942 return 3; /* return error */
3943 }
3944 if (handle->iic_deinit == NULL) /* check iic_deinit */
3945 {
3946 handle->debug_print("mpu6500: iic_deinit is null.\n"); /* iic_deinit is null */
3947
3948 return 3; /* return error */
3949 }
3950 if (handle->iic_read == NULL) /* check iic_read */
3951 {
3952 handle->debug_print("mpu6500: iic_read is null.\n"); /* iic_read is null */
3953
3954 return 3; /* return error */
3955 }
3956 if (handle->iic_write == NULL) /* check iic_write */
3957 {
3958 handle->debug_print("mpu6500: iic_write is null.\n"); /* iic_write is null */
3959
3960 return 3; /* return error */
3961 }
3962 if (handle->spi_init == NULL) /* check spi_init */
3963 {
3964 handle->debug_print("mpu6500: spi_init is null.\n"); /* spi_init is null */
3965
3966 return 3; /* return error */
3967 }
3968 if (handle->spi_deinit == NULL) /* check spi_deinit */
3969 {
3970 handle->debug_print("mpu6500: spi_deinit is null.\n"); /* spi_deinit is null */
3971
3972 return 3; /* return error */
3973 }
3974 if (handle->spi_read == NULL) /* check spi_read */
3975 {
3976 handle->debug_print("mpu6500: spi_read is null.\n"); /* spi_read is null */
3977
3978 return 3; /* return error */
3979 }
3980 if (handle->spi_write == NULL) /* check spi_write */
3981 {
3982 handle->debug_print("mpu6500: spi_write is null.\n"); /* spi_write is null */
3983
3984 return 3; /* return error */
3985 }
3986 if (handle->delay_ms == NULL) /* check delay_ms */
3987 {
3988 handle->debug_print("mpu6500: delay_ms is null.\n"); /* delay_ms is null */
3989
3990 return 3; /* return error */
3991 }
3992 if (handle->receive_callback == NULL) /* check receive_callback */
3993 {
3994 handle->debug_print("mpu6500: receive_callback is null.\n"); /* receive_callback is null */
3995
3996 return 3; /* return error */
3997 }
3998
3999 if (handle->iic_spi == MPU6500_INTERFACE_IIC) /* if iic interface */
4000 {
4001 res = handle->iic_init(); /* iic init */
4002 if (res != 0) /* check the result */
4003 {
4004 handle->debug_print("mpu6500: iic init failed.\n"); /* iic init failed */
4005
4006 return 1; /* return error */
4007 }
4008 }
4009 else /* if spi interface */
4010 {
4011 res = handle->spi_init(); /* spi init */
4012 if (res != 0) /* check the result */
4013 {
4014 handle->debug_print("mpu6500: spi init failed.\n"); /* spi init failed */
4015
4016 return 1; /* return error */
4017 }
4018 }
4019
4020 res = a_mpu6500_read(handle, MPU6500_REG_WHO_AM_I, &prev, 1); /* read who am I */
4021 if (res != 0) /* check the result */
4022 {
4023 handle->debug_print("mpu6500: read who am i failed.\n"); /* read who am I failed */
4024 (void)a_mpu6500_deinit(handle); /* iic or spi deinit */
4025
4026 return 5; /* return error */
4027 }
4028 if (prev != 0x70) /* check the id */
4029 {
4030 handle->debug_print("mpu6500: id is invalid.\n"); /* id is invalid */
4031 (void)a_mpu6500_deinit(handle); /* iic or spi deinit */
4032
4033 return 5; /* return error */
4034 }
4035
4036 prev = 1 << 7; /* reset the device */
4037 res = a_mpu6500_write(handle, MPU6500_REG_PWR_MGMT_1, &prev, 1); /* write pwr mgmt 1 */
4038 if (res != 0) /* check the result */
4039 {
4040 handle->debug_print("mpu6500: write pwr mgmt 1 failed.\n"); /* write pwr mgmt 1 failed */
4041 (void)a_mpu6500_deinit(handle); /* iic or spi deinit */
4042
4043 return 4; /* return error */
4044 }
4045 handle->delay_ms(10); /* delay 10 ms */
4046 timeout = 100; /* set the timeout 1000 ms */
4047 while (timeout != 0) /* check the timeout */
4048 {
4049 res = a_mpu6500_read(handle, MPU6500_REG_PWR_MGMT_1, &prev, 1); /* read pwr mgmt 1 */
4050 if (res != 0) /* check the result */
4051 {
4052 handle->debug_print("mpu6500: read pwr mgmt 1 failed.\n"); /* read pwr mgmt 1 failed */
4053 (void)a_mpu6500_deinit(handle); /* iic or spi deinit */
4054
4055 return 4; /* return error */
4056 }
4057 if ((prev & (1 << 7)) == 0) /* check the result */
4058 {
4059 handle->inited = 1; /* flag the inited bit */
4060 handle->dmp_inited = 0; /* flag closed */
4061
4062 return 0; /* success return 0 */
4063 }
4064 handle->delay_ms(10); /* delay 10 ms */
4065 timeout--; /* timeout-- */
4066 }
4067
4068 handle->debug_print("mpu6500: reset failed.\n"); /* reset failed */
4069
4070 return 4; /* return error */
4071}
4072
4085{
4086 uint8_t res;
4087 uint8_t prev;
4088
4089 if (handle == NULL) /* check handle */
4090 {
4091 return 2; /* return error */
4092 }
4093 if (handle->inited != 1) /* check handle initialization */
4094 {
4095 return 3; /* return error */
4096 }
4097
4098 prev = (1 << 6) | (1 << 3) | (7 << 0); /* enter sleep mode */
4099 res = a_mpu6500_write(handle, MPU6500_REG_PWR_MGMT_1, &prev, 1); /* write pwr mgmt 1 */
4100 if (res != 0) /* check the result */
4101 {
4102 handle->debug_print("mpu6500: write pwr mgmt 1 failed.\n"); /* write pwr mgmt 1 failed */
4103
4104 return 4; /* return error */
4105 }
4106 res = a_mpu6500_deinit(handle); /* deinit */
4107 if (res != 0) /* check the result */
4108 {
4109 handle->debug_print("mpu6500: deinit failed.\n"); /* deinit failed */
4110
4111 return 1; /* return error */
4112 }
4113 handle->inited = 0; /* flag closed */
4114 handle->dmp_inited = 0; /* flag closed */
4115
4116 return 0; /* success return 0 */
4117}
4118
4138 int16_t (*accel_raw)[3], float (*accel_g)[3],
4139 int16_t (*gyro_raw)[3], float (*gyro_dps)[3],
4140 uint16_t *len
4141 )
4142{
4143 uint8_t res;
4144 uint8_t prev;
4145 uint8_t accel_conf;
4146 uint8_t gyro_conf;
4147
4148 if (handle == NULL) /* check handle */
4149 {
4150 return 2; /* return error */
4151 }
4152 if (handle->inited != 1) /* check handle initialization */
4153 {
4154 return 3; /* return error */
4155 }
4156 if ((*len) == 0) /* check length */
4157 {
4158 handle->debug_print("mpu6500: length is zero.\n"); /* length is zero */
4159
4160 return 4; /* return error */
4161 }
4162 if (handle->dmp_inited != 0) /* check dmp initialization */
4163 {
4164 handle->debug_print("mpu6500: dmp is running.\n"); /* dmp is running */
4165
4166 return 5; /* return error */
4167 }
4168
4169 res = a_mpu6500_read(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4170 if (res != 0) /* check result */
4171 {
4172 handle->debug_print("mpu6500: read user ctrl failed.\n"); /* read user ctrl failed */
4173
4174 return 1; /* return error */
4175 }
4176 res = a_mpu6500_read(handle, MPU6500_REG_ACCEL_CONFIG, (uint8_t *)&accel_conf, 1); /* read accel config */
4177 if (res != 0) /* check result */
4178 {
4179 handle->debug_print("mpu6500: read accel config failed.\n"); /* read accel config failed */
4180
4181 return 1; /* return error */
4182 }
4183 res = a_mpu6500_read(handle, MPU6500_REG_GYRO_CONFIG, (uint8_t *)&gyro_conf, 1); /* read gyro config */
4184 if (res != 0) /* check result */
4185 {
4186 handle->debug_print("mpu6500: read gyro config failed.\n"); /* read gyro config failed */
4187
4188 return 1; /* return error */
4189 }
4190 accel_conf = (accel_conf >> 3) & 0x3; /* get the accel conf */
4191 gyro_conf = (gyro_conf >> 3) & 0x3; /* get the gyro conf */
4192 if ((prev & (1 << 6)) != 0) /* if fifo mode */
4193 {
4194 uint8_t conf;
4195 uint8_t buf[2];
4196 uint16_t count;
4197 uint16_t i;
4198
4199 res = a_mpu6500_read(handle, MPU6500_REG_FIFO_EN, (uint8_t *)&conf, 1); /* read fifo enable */
4200 if (res != 0) /* check result */
4201 {
4202 handle->debug_print("mpu6500: read fifo enable failed.\n"); /* read fifo enable failed */
4203
4204 return 1; /* return error */
4205 }
4206 if (conf != 0x78) /* check the conf */
4207 {
4208 handle->debug_print("mpu6500: fifo conf is error.\n"); /* fifo conf is error */
4209
4210 return 6; /* return error */
4211 }
4212
4213 res = a_mpu6500_read(handle, MPU6500_REG_FIFO_COUNTH, (uint8_t *)buf, 2); /* read fifo count */
4214 if (res != 0) /* check result */
4215 {
4216 handle->debug_print("mpu6500: read fifo count failed.\n"); /* read fifo count failed */
4217
4218 return 1; /* return error */
4219 }
4220
4221 count = (uint16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set count */
4222 count = (count < 1024) ? count : 1024; /* just the counter */
4223 count = (count < ((*len) * 12)) ? count : ((*len) * 12); /* just outer buffer size */
4224 count = (count / 12) * 12; /* 12 times */
4225 *len = count / 12; /* set the output length */
4226 res = a_mpu6500_read(handle, MPU6500_REG_R_W, handle->buf, count); /* read data */
4227 if (res != 0) /* check result */
4228 {
4229 handle->debug_print("mpu6500: read failed.\n"); /* read failed */
4230
4231 return 1; /* return error */
4232 }
4233 for (i = 0; i < (*len); i++) /* *len times */
4234 {
4235 accel_raw[i][0] = (int16_t)((uint16_t)handle->buf[i * 12 + 0] << 8) |
4236 handle->buf[i * 12 + 1]; /* set raw accel x */
4237 accel_raw[i][1] = (int16_t)((uint16_t)handle->buf[i * 12 + 2] << 8) |
4238 handle->buf[i * 12 + 3]; /* set raw accel y */
4239 accel_raw[i][2] = (int16_t)((uint16_t)handle->buf[i * 12 + 4] << 8) |
4240 handle->buf[i * 12 + 5]; /* set raw accel z */
4241 gyro_raw[i][0] = (int16_t)((uint16_t)handle->buf[i * 12 + 6] << 8) |
4242 handle->buf[i * 12 + 7]; /* set raw gyro x */
4243 gyro_raw[i][1] = (int16_t)((uint16_t)handle->buf[i * 12 + 8] << 8) |
4244 handle->buf[i * 12 + 9]; /* set raw gyro y */
4245 gyro_raw[i][2] = (int16_t)((uint16_t)handle->buf[i * 12 + 10] << 8) |
4246 handle->buf[i * 12 + 11]; /* set raw gyro z */
4247
4248 if (accel_conf == 0) /* ±2g */
4249 {
4250 accel_g[i][0] = (float)(accel_raw[i][0]) / 16384.0f; /* set accel x */
4251 accel_g[i][1] = (float)(accel_raw[i][1]) / 16384.0f; /* set accel y */
4252 accel_g[i][2] = (float)(accel_raw[i][2]) / 16384.0f; /* set accel z */
4253 }
4254 else if (accel_conf == 1) /* ±4g */
4255 {
4256 accel_g[i][0] = (float)(accel_raw[i][0]) / 8192.0f; /* set accel x */
4257 accel_g[i][1] = (float)(accel_raw[i][1]) / 8192.0f; /* set accel y */
4258 accel_g[i][2] = (float)(accel_raw[i][2]) / 8192.0f; /* set accel z */
4259 }
4260 else if (accel_conf == 2) /* ±8g */
4261 {
4262 accel_g[i][0] = (float)(accel_raw[i][0]) / 4096.0f; /* set accel x */
4263 accel_g[i][1] = (float)(accel_raw[i][1]) / 4096.0f; /* set accel y */
4264 accel_g[i][2] = (float)(accel_raw[i][2]) / 4096.0f; /* set accel z */
4265 }
4266 else /* ±16g */
4267 {
4268 accel_g[i][0] = (float)(accel_raw[i][0]) / 2048.0f; /* set accel x */
4269 accel_g[i][1] = (float)(accel_raw[i][1]) / 2048.0f; /* set accel y */
4270 accel_g[i][2] = (float)(accel_raw[i][2]) / 2048.0f; /* set accel z */
4271 }
4272
4273 if (gyro_conf == 0) /* ±250dps */
4274 {
4275 gyro_dps[i][0] = (float)(gyro_raw[i][0]) / 131.0f; /* set gyro x */
4276 gyro_dps[i][1] = (float)(gyro_raw[i][1]) / 131.0f; /* set gyro y */
4277 gyro_dps[i][2] = (float)(gyro_raw[i][2]) / 131.0f; /* set gyro z */
4278 }
4279 else if (gyro_conf == 1) /* ±500dps */
4280 {
4281 gyro_dps[i][0] = (float)(gyro_raw[i][0]) / 65.5f; /* set gyro x */
4282 gyro_dps[i][1] = (float)(gyro_raw[i][1]) / 65.5f; /* set gyro y */
4283 gyro_dps[i][2] = (float)(gyro_raw[i][2]) / 65.5f; /* set gyro z */
4284 }
4285 else if (gyro_conf == 2) /* ±1000dps */
4286 {
4287 gyro_dps[i][0] = (float)(gyro_raw[i][0]) / 32.8f; /* set gyro x */
4288 gyro_dps[i][1] = (float)(gyro_raw[i][1]) / 32.8f; /* set gyro y */
4289 gyro_dps[i][2] = (float)(gyro_raw[i][2]) / 32.8f; /* set gyro z */
4290 }
4291 else /* ±2000dps */
4292 {
4293 gyro_dps[i][0] = (float)(gyro_raw[i][0]) / 16.4f; /* set gyro x */
4294 gyro_dps[i][1] = (float)(gyro_raw[i][1]) / 16.4f; /* set gyro y */
4295 gyro_dps[i][2] = (float)(gyro_raw[i][2]) / 16.4f; /* set gyro z */
4296 }
4297 }
4298
4299 return 0; /* success return 0 */
4300 }
4301 else /* if normal mode */
4302 {
4303 *len = 1; /* set 1 */
4304 res = a_mpu6500_read(handle, MPU6500_REG_ACCEL_XOUT_H, handle->buf, 14); /* read data */
4305 if (res != 0) /* check result */
4306 {
4307 handle->debug_print("mpu6500: read failed.\n"); /* read failed */
4308
4309 return 1; /* return error */
4310 }
4311 accel_raw[0][0] = (int16_t)((uint16_t)handle->buf[0] << 8) | handle->buf[1]; /* set raw accel x */
4312 accel_raw[0][1] = (int16_t)((uint16_t)handle->buf[2] << 8) | handle->buf[3]; /* set raw accel y */
4313 accel_raw[0][2] = (int16_t)((uint16_t)handle->buf[4] << 8) | handle->buf[5]; /* set raw accel z */
4314 gyro_raw[0][0] = (int16_t)((uint16_t)handle->buf[8] << 8) | handle->buf[9]; /* set raw gyro x */
4315 gyro_raw[0][1] = (int16_t)((uint16_t)handle->buf[10] << 8) | handle->buf[11]; /* set raw gyro y */
4316 gyro_raw[0][2] = (int16_t)((uint16_t)handle->buf[12] << 8) | handle->buf[13]; /* set raw gyro z */
4317
4318 if (accel_conf == 0) /* ±2g */
4319 {
4320 accel_g[0][0] = (float)(accel_raw[0][0]) / 16384.0f; /* set accel x */
4321 accel_g[0][1] = (float)(accel_raw[0][1]) / 16384.0f; /* set accel y */
4322 accel_g[0][2] = (float)(accel_raw[0][2]) / 16384.0f; /* set accel z */
4323 }
4324 else if (accel_conf == 1) /* ±4g */
4325 {
4326 accel_g[0][0] = (float)(accel_raw[0][0]) / 8192.0f; /* set accel x */
4327 accel_g[0][1] = (float)(accel_raw[0][1]) / 8192.0f; /* set accel y */
4328 accel_g[0][2] = (float)(accel_raw[0][2]) / 8192.0f; /* set accel z */
4329 }
4330 else if (accel_conf == 2) /* ±8g */
4331 {
4332 accel_g[0][0] = (float)(accel_raw[0][0]) / 4096.0f; /* set accel x */
4333 accel_g[0][1] = (float)(accel_raw[0][1]) / 4096.0f; /* set accel y */
4334 accel_g[0][2] = (float)(accel_raw[0][2]) / 4096.0f; /* set accel z */
4335 }
4336 else /* ±16g */
4337 {
4338 accel_g[0][0] = (float)(accel_raw[0][0]) / 2048.0f; /* set accel x */
4339 accel_g[0][1] = (float)(accel_raw[0][1]) / 2048.0f; /* set accel y */
4340 accel_g[0][2] = (float)(accel_raw[0][2]) / 2048.0f; /* set accel z */
4341 }
4342
4343 if (gyro_conf == 0) /* ±250dps */
4344 {
4345 gyro_dps[0][0] = (float)(gyro_raw[0][0]) / 131.0f; /* set gyro x */
4346 gyro_dps[0][1] = (float)(gyro_raw[0][1]) / 131.0f; /* set gyro y */
4347 gyro_dps[0][2] = (float)(gyro_raw[0][2]) / 131.0f; /* set gyro z */
4348 }
4349 else if (gyro_conf == 1) /* ±500dps */
4350 {
4351 gyro_dps[0][0] = (float)(gyro_raw[0][0]) / 65.5f; /* set gyro x */
4352 gyro_dps[0][1] = (float)(gyro_raw[0][1]) / 65.5f; /* set gyro y */
4353 gyro_dps[0][2] = (float)(gyro_raw[0][2]) / 65.5f; /* set gyro z */
4354 }
4355 else if (gyro_conf == 2) /* ±1000dps */
4356 {
4357 gyro_dps[0][0] = (float)(gyro_raw[0][0]) / 32.8f; /* set gyro x */
4358 gyro_dps[0][1] = (float)(gyro_raw[0][1]) / 32.8f; /* set gyro y */
4359 gyro_dps[0][2] = (float)(gyro_raw[0][2]) / 32.8f; /* set gyro z */
4360 }
4361 else /* ±2000dps */
4362 {
4363 gyro_dps[0][0] = (float)(gyro_raw[0][0]) / 16.4f; /* set gyro x */
4364 gyro_dps[0][1] = (float)(gyro_raw[0][1]) / 16.4f; /* set gyro y */
4365 gyro_dps[0][2] = (float)(gyro_raw[0][2]) / 16.4f; /* set gyro z */
4366 }
4367
4368 return 0; /* success return 0 */
4369 }
4370}
4371
4384uint8_t mpu6500_read_temperature(mpu6500_handle_t *handle, int16_t (*raw), float *degrees)
4385{
4386 uint8_t res;
4387 uint8_t buf[2];
4388
4389 if (handle == NULL) /* check handle */
4390 {
4391 return 2; /* return error */
4392 }
4393 if (handle->inited != 1) /* check handle initialization */
4394 {
4395 return 3; /* return error */
4396 }
4397
4398 res = a_mpu6500_read(handle, MPU6500_REG_TEMP_OUT_H, buf, 2); /* read data */
4399 if (res != 0) /* check result */
4400 {
4401 handle->debug_print("mpu6500: read failed.\n"); /* read failed */
4402
4403 return 1; /* return error */
4404 }
4405 *raw = (int16_t)((uint16_t)buf[0] << 8) | buf[1]; /* get the raw */
4406 *degrees = (float)(*raw) / 321.0f + 21.0f; /* convert the degrees */
4407
4408 return 0; /* success return 0 */
4409}
4410
4422{
4423 uint8_t res;
4424 uint8_t prev;
4425
4426 if (handle == NULL) /* check handle */
4427 {
4428 return 2; /* return error */
4429 }
4430 if (handle->inited != 1) /* check handle initialization */
4431 {
4432 return 3; /* return error */
4433 }
4434
4435 res = a_mpu6500_read(handle, MPU6500_REG_INT_STATUS, (uint8_t *)&prev, 1); /* read config */
4436 if (res != 0) /* check result */
4437 {
4438 handle->debug_print("mpu6500: read int status failed.\n"); /* read int status failed */
4439
4440 return 1; /* return error */
4441 }
4442 if ((prev & (1 << MPU6500_INTERRUPT_MOTION)) != 0) /* if motion */
4443 {
4444 if (handle->receive_callback != NULL) /* if receive callback */
4445 {
4446 handle->receive_callback(MPU6500_INTERRUPT_MOTION); /* run callback */
4447 }
4448 }
4449 if ((prev & (1 << MPU6500_INTERRUPT_FIFO_OVERFLOW)) != 0) /* if fifo overflow */
4450 {
4451 if (handle->receive_callback != NULL) /* if receive callback */
4452 {
4453 handle->receive_callback(MPU6500_INTERRUPT_FIFO_OVERFLOW); /* run callback */
4454 }
4455 (void)a_mpu6500_reset_fifo(handle); /* reset the fifo */
4456 }
4457 if ((prev & (1 << MPU6500_INTERRUPT_FSYNC_INT)) != 0) /* if fsync int */
4458 {
4459 if (handle->receive_callback != NULL) /* if receive callback */
4460 {
4461 handle->receive_callback(MPU6500_INTERRUPT_FSYNC_INT); /* run callback */
4462 }
4463 }
4464 if ((prev & (1 << MPU6500_INTERRUPT_DMP)) != 0) /* if dmp */
4465 {
4466 if (handle->receive_callback != NULL) /* if receive callback */
4467 {
4468 handle->receive_callback(MPU6500_INTERRUPT_DMP); /* run callback */
4469 }
4470 }
4471 if ((prev & (1 << MPU6500_INTERRUPT_DATA_READY)) != 0) /* if data ready */
4472 {
4473 if (handle->receive_callback != NULL) /* if receive callback */
4474 {
4475 handle->receive_callback(MPU6500_INTERRUPT_DATA_READY); /* run callback */
4476 }
4477 }
4478
4479 return 0; /* success return 0 */
4480}
4481
4494{
4495 uint8_t res;
4496 uint8_t prev;
4497
4498 if (handle == NULL) /* check handle */
4499 {
4500 return 2; /* return error */
4501 }
4502 if (handle->inited != 1) /* check handle initialization */
4503 {
4504 return 3; /* return error */
4505 }
4506
4507 res = a_mpu6500_read(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4508 if (res != 0) /* check result */
4509 {
4510 handle->debug_print("mpu6500: read user ctrl failed.\n"); /* read user ctrl failed */
4511
4512 return 1; /* return error */
4513 }
4514 prev &= ~(1 << 6); /* clear config */
4515 prev |= enable << 6; /* set config */
4516 res = a_mpu6500_write(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
4517 if (res != 0) /* check result */
4518 {
4519 handle->debug_print("mpu6500: write user ctrl failed.\n"); /* write user ctrl failed */
4520
4521 return 1; /* return error */
4522 }
4523
4524 return 0; /* success return 0 */
4525}
4526
4539{
4540 uint8_t res;
4541 uint8_t prev;
4542
4543 if (handle == NULL) /* check handle */
4544 {
4545 return 2; /* return error */
4546 }
4547 if (handle->inited != 1) /* check handle initialization */
4548 {
4549 return 3; /* return error */
4550 }
4551
4552 res = a_mpu6500_read(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4553 if (res != 0) /* check result */
4554 {
4555 handle->debug_print("mpu6500: read user ctrl failed.\n"); /* read user ctrl failed */
4556
4557 return 1; /* return error */
4558 }
4559 *enable = (mpu6500_bool_t)((prev >> 6) & 0x01); /* get bool */
4560
4561 return 0; /* success return 0 */
4562}
4563
4575{
4576 uint8_t res;
4577
4578 if (handle == NULL) /* check handle */
4579 {
4580 return 2; /* return error */
4581 }
4582 if (handle->inited != 1) /* check handle initialization */
4583 {
4584 return 3; /* return error */
4585 }
4586
4587 res = a_mpu6500_reset_fifo(handle); /* reset the fifo */
4588 if (res != 0) /* check result */
4589 {
4590 handle->debug_print("mpu6500: force reset fifo failed.\n"); /* force reset fifo failed */
4591
4592 return 1; /* return error */
4593 }
4594
4595 return 0; /* success return 0 */
4596}
4597
4610{
4611 uint8_t res;
4612 uint8_t prev;
4613
4614 if (handle == NULL) /* check handle */
4615 {
4616 return 2; /* return error */
4617 }
4618 if (handle->inited != 1) /* check handle initialization */
4619 {
4620 return 3; /* return error */
4621 }
4622
4623 res = a_mpu6500_read(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4624 if (res != 0) /* check result */
4625 {
4626 handle->debug_print("mpu6500: read user ctrl failed.\n"); /* read user ctrl failed */
4627
4628 return 1; /* return error */
4629 }
4630 prev &= ~(1 << 5); /* clear config */
4631 prev |= enable << 5; /* set config */
4632 res = a_mpu6500_write(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
4633 if (res != 0) /* check result */
4634 {
4635 handle->debug_print("mpu6500: write user ctrl failed.\n"); /* write user ctrl failed */
4636
4637 return 1; /* return error */
4638 }
4639
4640 return 0; /* success return 0 */
4641}
4642
4655{
4656 uint8_t res;
4657 uint8_t prev;
4658
4659 if (handle == NULL) /* check handle */
4660 {
4661 return 2; /* return error */
4662 }
4663 if (handle->inited != 1) /* check handle initialization */
4664 {
4665 return 3; /* return error */
4666 }
4667
4668 res = a_mpu6500_read(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4669 if (res != 0) /* check result */
4670 {
4671 handle->debug_print("mpu6500: read user ctrl failed.\n"); /* read user ctrl failed */
4672
4673 return 1; /* return error */
4674 }
4675 *enable = (mpu6500_bool_t)((prev >> 5) & 0x01); /* get bool */
4676
4677 return 0; /* success return 0 */
4678}
4679
4692{
4693 uint8_t res;
4694 uint8_t prev;
4695
4696 if (handle == NULL) /* check handle */
4697 {
4698 return 2; /* return error */
4699 }
4700 if (handle->inited != 1) /* check handle initialization */
4701 {
4702 return 3; /* return error */
4703 }
4704
4705 res = a_mpu6500_read(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4706 if (res != 0) /* check result */
4707 {
4708 handle->debug_print("mpu6500: read user ctrl failed.\n"); /* read user ctrl failed */
4709
4710 return 1; /* return error */
4711 }
4712 prev &= ~(1 << 4); /* clear config */
4713 prev |= enable << 4; /* set config */
4714 res = a_mpu6500_write(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
4715 if (res != 0) /* check result */
4716 {
4717 handle->debug_print("mpu6500: write user ctrl failed.\n"); /* write user ctrl failed */
4718
4719 return 1; /* return error */
4720 }
4721
4722 return 0; /* success return 0 */
4723}
4724
4737{
4738 uint8_t res;
4739 uint8_t prev;
4740
4741 if (handle == NULL) /* check handle */
4742 {
4743 return 2; /* return error */
4744 }
4745 if (handle->inited != 1) /* check handle initialization */
4746 {
4747 return 3; /* return error */
4748 }
4749
4750 res = a_mpu6500_read(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4751 if (res != 0) /* check result */
4752 {
4753 handle->debug_print("mpu6500: read user ctrl failed.\n"); /* read user ctrl failed */
4754
4755 return 1; /* return error */
4756 }
4757 *enable = (mpu6500_bool_t)((prev >> 4) & 0x01); /* get bool */
4758
4759 return 0; /* success return 0 */
4760}
4761
4773{
4774 uint8_t res;
4775 uint8_t prev;
4776
4777 if (handle == NULL) /* check handle */
4778 {
4779 return 2; /* return error */
4780 }
4781 if (handle->inited != 1) /* check handle initialization */
4782 {
4783 return 3; /* return error */
4784 }
4785
4786 res = a_mpu6500_read(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4787 if (res != 0) /* check result */
4788 {
4789 handle->debug_print("mpu6500: read user ctrl failed.\n"); /* read user ctrl failed */
4790
4791 return 1; /* return error */
4792 }
4793 prev &= ~(1 << 2); /* clear config */
4794 prev |= 1 << 2; /* set config */
4795 res = a_mpu6500_write(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
4796 if (res != 0) /* check result */
4797 {
4798 handle->debug_print("mpu6500: write user ctrl failed.\n"); /* write user ctrl failed */
4799
4800 return 1; /* return error */
4801 }
4802
4803 return 0; /* success return 0 */
4804}
4805
4818{
4819 uint8_t res;
4820 uint8_t prev;
4821
4822 if (handle == NULL) /* check handle */
4823 {
4824 return 2; /* return error */
4825 }
4826 if (handle->inited != 1) /* check handle initialization */
4827 {
4828 return 3; /* return error */
4829 }
4830
4831 res = a_mpu6500_read(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4832 if (res != 0) /* check result */
4833 {
4834 handle->debug_print("mpu6500: read user ctrl failed.\n"); /* read user ctrl failed */
4835
4836 return 1; /* return error */
4837 }
4838 *enable = (mpu6500_bool_t)((prev >> 2) & 0x01); /* get bool */
4839
4840 return 0; /* success return 0 */
4841}
4842
4854{
4855 uint8_t res;
4856 uint8_t prev;
4857
4858 if (handle == NULL) /* check handle */
4859 {
4860 return 2; /* return error */
4861 }
4862 if (handle->inited != 1) /* check handle initialization */
4863 {
4864 return 3; /* return error */
4865 }
4866
4867 res = a_mpu6500_read(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4868 if (res != 0) /* check result */
4869 {
4870 handle->debug_print("mpu6500: read user ctrl failed.\n"); /* read user ctrl failed */
4871
4872 return 1; /* return error */
4873 }
4874 prev &= ~(1 << 1); /* clear config */
4875 prev |= 1 << 1; /* set config */
4876 res = a_mpu6500_write(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
4877 if (res != 0) /* check result */
4878 {
4879 handle->debug_print("mpu6500: write user ctrl failed.\n"); /* write user ctrl failed */
4880
4881 return 1; /* return error */
4882 }
4883
4884 return 0; /* success return 0 */
4885}
4886
4899{
4900 uint8_t res;
4901 uint8_t prev;
4902
4903 if (handle == NULL) /* check handle */
4904 {
4905 return 2; /* return error */
4906 }
4907 if (handle->inited != 1) /* check handle initialization */
4908 {
4909 return 3; /* return error */
4910 }
4911
4912 res = a_mpu6500_read(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4913 if (res != 0) /* check result */
4914 {
4915 handle->debug_print("mpu6500: read user ctrl failed.\n"); /* read user ctrl failed */
4916
4917 return 1; /* return error */
4918 }
4919 *enable = (mpu6500_bool_t)((prev >> 1) & 0x01); /* get bool */
4920
4921 return 0; /* success return 0 */
4922}
4923
4935{
4936 uint8_t res;
4937 uint8_t prev;
4938
4939 if (handle == NULL) /* check handle */
4940 {
4941 return 2; /* return error */
4942 }
4943 if (handle->inited != 1) /* check handle initialization */
4944 {
4945 return 3; /* return error */
4946 }
4947
4948 res = a_mpu6500_read(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4949 if (res != 0) /* check result */
4950 {
4951 handle->debug_print("mpu6500: read user ctrl failed.\n"); /* read user ctrl failed */
4952
4953 return 1; /* return error */
4954 }
4955 prev &= ~(1 << 0); /* clear config */
4956 prev |= 1 << 0; /* set config */
4957 res = a_mpu6500_write(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
4958 if (res != 0) /* check result */
4959 {
4960 handle->debug_print("mpu6500: write user ctrl failed.\n"); /* write user ctrl failed */
4961
4962 return 1; /* return error */
4963 }
4964
4965 return 0; /* success return 0 */
4966}
4967
4980{
4981 uint8_t res;
4982 uint8_t prev;
4983
4984 if (handle == NULL) /* check handle */
4985 {
4986 return 2; /* return error */
4987 }
4988 if (handle->inited != 1) /* check handle initialization */
4989 {
4990 return 3; /* return error */
4991 }
4992
4993 res = a_mpu6500_read(handle, MPU6500_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4994 if (res != 0) /* check result */
4995 {
4996 handle->debug_print("mpu6500: read user ctrl failed.\n"); /* read user ctrl failed */
4997
4998 return 1; /* return error */
4999 }
5000 *enable = (mpu6500_bool_t)((prev >> 0) & 0x01); /* get bool */
5001
5002 return 0; /* success return 0 */
5003}
5004
5016{
5017 uint8_t res;
5018 uint8_t prev;
5019
5020 if (handle == NULL) /* check handle */
5021 {
5022 return 2; /* return error */
5023 }
5024 if (handle->inited != 1) /* check handle initialization */
5025 {
5026 return 3; /* return error */
5027 }
5028
5029 res = a_mpu6500_read(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
5030 if (res != 0) /* check result */
5031 {
5032 handle->debug_print("mpu6500: read power management 1 failed.\n"); /* read power management 1 failed */
5033
5034 return 1; /* return error */
5035 }
5036 prev &= ~(1 << 7); /* clear config */
5037 prev |= 1 << 7; /* set config */
5038 res = a_mpu6500_write(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
5039 if (res != 0) /* check result */
5040 {
5041 handle->debug_print("mpu6500: write power management 1 failed.\n"); /* write power management 1 failed */
5042
5043 return 1; /* return error */
5044 }
5045
5046 return 0; /* success return 0 */
5047}
5048
5061{
5062 uint8_t res;
5063 uint8_t prev;
5064
5065 if (handle == NULL) /* check handle */
5066 {
5067 return 2; /* return error */
5068 }
5069 if (handle->inited != 1) /* check handle initialization */
5070 {
5071 return 3; /* return error */
5072 }
5073
5074 res = a_mpu6500_read(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
5075 if (res != 0) /* check result */
5076 {
5077 handle->debug_print("mpu6500: read power management 1 failed.\n"); /* read power management 1 failed */
5078
5079 return 1; /* return error */
5080 }
5081 *enable = (mpu6500_bool_t)((prev >> 7) & 0x01); /* get bool */
5082
5083 return 0; /* success return 0 */
5084}
5085
5098{
5099 uint8_t res;
5100 uint8_t prev;
5101
5102 if (handle == NULL) /* check handle */
5103 {
5104 return 2; /* return error */
5105 }
5106 if (handle->inited != 1) /* check handle initialization */
5107 {
5108 return 3; /* return error */
5109 }
5110
5111 res = a_mpu6500_read(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
5112 if (res != 0) /* check result */
5113 {
5114 handle->debug_print("mpu6500: read power management 1 failed.\n"); /* read power management 1 failed */
5115
5116 return 1; /* return error */
5117 }
5118 prev &= ~(0x7 << 0); /* clear config */
5119 prev |= clock_source << 0; /* set config */
5120 res = a_mpu6500_write(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
5121 if (res != 0) /* check result */
5122 {
5123 handle->debug_print("mpu6500: write power management 1 failed.\n"); /* write power management 1 failed */
5124
5125 return 1; /* return error */
5126 }
5127
5128 return 0; /* success return 0 */
5129}
5130
5143{
5144 uint8_t res;
5145 uint8_t prev;
5146
5147 if (handle == NULL) /* check handle */
5148 {
5149 return 2; /* return error */
5150 }
5151 if (handle->inited != 1) /* check handle initialization */
5152 {
5153 return 3; /* return error */
5154 }
5155
5156 res = a_mpu6500_read(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
5157 if (res != 0) /* check result */
5158 {
5159 handle->debug_print("mpu6500: read power management 1 failed.\n"); /* read power management 1 failed */
5160
5161 return 1; /* return error */
5162 }
5163 *clock_source = (mpu6500_clock_source_t)((prev >> 0) & (0x7)); /* get clock source */
5164
5165 return 0; /* success return 0 */
5166}
5167
5180{
5181 uint8_t res;
5182 uint8_t prev;
5183
5184 if (handle == NULL) /* check handle */
5185 {
5186 return 2; /* return error */
5187 }
5188 if (handle->inited != 1) /* check handle initialization */
5189 {
5190 return 3; /* return error */
5191 }
5192
5193 res = a_mpu6500_read(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
5194 if (res != 0) /* check result */
5195 {
5196 handle->debug_print("mpu6500: read power management 1 failed.\n"); /* read power management 1 failed */
5197
5198 return 1; /* return error */
5199 }
5200 prev &= ~(1 << 3); /* clear config */
5201 prev |= (!enable) << 3; /* set config */
5202 res = a_mpu6500_write(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
5203 if (res != 0) /* check result */
5204 {
5205 handle->debug_print("mpu6500: write power management 1 failed.\n"); /* write power management 1 failed */
5206
5207 return 1; /* return error */
5208 }
5209
5210 return 0; /* success return 0 */
5211}
5212
5225{
5226 uint8_t res;
5227 uint8_t prev;
5228
5229 if (handle == NULL) /* check handle */
5230 {
5231 return 2; /* return error */
5232 }
5233 if (handle->inited != 1) /* check handle initialization */
5234 {
5235 return 3; /* return error */
5236 }
5237
5238 res = a_mpu6500_read(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
5239 if (res != 0) /* check result */
5240 {
5241 handle->debug_print("mpu6500: read power management 1 failed.\n"); /* read power management 1 failed */
5242
5243 return 1; /* return error */
5244 }
5245 *enable = (mpu6500_bool_t)(!((prev >> 3) & (0x1))); /* get bool */
5246
5247 return 0; /* success return 0 */
5248}
5249
5262{
5263 uint8_t res;
5264 uint8_t prev;
5265
5266 if (handle == NULL) /* check handle */
5267 {
5268 return 2; /* return error */
5269 }
5270 if (handle->inited != 1) /* check handle initialization */
5271 {
5272 return 3; /* return error */
5273 }
5274
5275 res = a_mpu6500_read(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
5276 if (res != 0) /* check result */
5277 {
5278 handle->debug_print("mpu6500: read power management 1 failed.\n"); /* read power management 1 failed */
5279
5280 return 1; /* return error */
5281 }
5282 prev &= ~(1 << 5); /* clear config */
5283 prev |= enable << 5; /* set config */
5284 res = a_mpu6500_write(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
5285 if (res != 0) /* check result */
5286 {
5287 handle->debug_print("mpu6500: write power management 1 failed.\n"); /* write power management 1 failed */
5288
5289 return 1; /* return error */
5290 }
5291
5292 return 0; /* success return 0 */
5293}
5294
5307{
5308 uint8_t res;
5309 uint8_t prev;
5310
5311 if (handle == NULL) /* check handle */
5312 {
5313 return 2; /* return error */
5314 }
5315 if (handle->inited != 1) /* check handle initialization */
5316 {
5317 return 3; /* return error */
5318 }
5319
5320 res = a_mpu6500_read(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
5321 if (res != 0) /* check result */
5322 {
5323 handle->debug_print("mpu6500: read power management 1 failed.\n"); /* read power management 1 failed */
5324
5325 return 1; /* return error */
5326 }
5327 *enable = (mpu6500_bool_t)((prev >> 5) & (0x1)); /* get bool */
5328
5329 return 0; /* success return 0 */
5330}
5331
5344{
5345 uint8_t res;
5346 uint8_t prev;
5347
5348 if (handle == NULL) /* check handle */
5349 {
5350 return 2; /* return error */
5351 }
5352 if (handle->inited != 1) /* check handle initialization */
5353 {
5354 return 3; /* return error */
5355 }
5356
5357 res = a_mpu6500_read(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
5358 if (res != 0) /* check result */
5359 {
5360 handle->debug_print("mpu6500: read power management 1 failed.\n"); /* read power management 1 failed */
5361
5362 return 1; /* return error */
5363 }
5364 prev &= ~(1 << 6); /* clear config */
5365 prev |= enable << 6; /* set config */
5366 res = a_mpu6500_write(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
5367 if (res != 0) /* check result */
5368 {
5369 handle->debug_print("mpu6500: write power management 1 failed.\n"); /* write power management 1 failed */
5370
5371 return 1; /* return error */
5372 }
5373
5374 return 0; /* success return 0 */
5375}
5376
5389{
5390 uint8_t res;
5391 uint8_t prev;
5392
5393 if (handle == NULL) /* check handle */
5394 {
5395 return 2; /* return error */
5396 }
5397 if (handle->inited != 1) /* check handle initialization */
5398 {
5399 return 3; /* return error */
5400 }
5401
5402 res = a_mpu6500_read(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
5403 if (res != 0) /* check result */
5404 {
5405 handle->debug_print("mpu6500: read power management 1 failed.\n"); /* read power management 1 failed */
5406
5407 return 1; /* return error */
5408 }
5409 *enable = (mpu6500_bool_t)((prev >> 6) & (0x1)); /* get bool */
5410
5411 return 0; /* success return 0 */
5412}
5413
5426{
5427 uint8_t res;
5428 uint8_t prev;
5429
5430 if (handle == NULL) /* check handle */
5431 {
5432 return 2; /* return error */
5433 }
5434 if (handle->inited != 1) /* check handle initialization */
5435 {
5436 return 3; /* return error */
5437 }
5438
5439 res = a_mpu6500_read(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
5440 if (res != 0) /* check result */
5441 {
5442 handle->debug_print("mpu6500: read power management 1 failed.\n"); /* read power management 1 failed */
5443
5444 return 1; /* return error */
5445 }
5446 prev &= ~(1 << 4); /* clear config */
5447 prev |= enable << 4; /* set config */
5448 res = a_mpu6500_write(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
5449 if (res != 0) /* check result */
5450 {
5451 handle->debug_print("mpu6500: write power management 1 failed.\n"); /* write power management 1 failed */
5452
5453 return 1; /* return error */
5454 }
5455
5456 return 0; /* success return 0 */
5457}
5458
5471{
5472 uint8_t res;
5473 uint8_t prev;
5474
5475 if (handle == NULL) /* check handle */
5476 {
5477 return 2; /* return error */
5478 }
5479 if (handle->inited != 1) /* check handle initialization */
5480 {
5481 return 3; /* return error */
5482 }
5483
5484 res = a_mpu6500_read(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
5485 if (res != 0) /* check result */
5486 {
5487 handle->debug_print("mpu6500: read power management 1 failed.\n"); /* read power management 1 failed */
5488
5489 return 1; /* return error */
5490 }
5491 *enable = (mpu6500_bool_t)((prev >> 4) & (0x1)); /* get bool */
5492
5493 return 0; /* success return 0 */
5494}
5495
5509{
5510 uint8_t res;
5511 uint8_t prev;
5512
5513 if (handle == NULL) /* check handle */
5514 {
5515 return 2; /* return error */
5516 }
5517 if (handle->inited != 1) /* check handle initialization */
5518 {
5519 return 3; /* return error */
5520 }
5521
5522 res = a_mpu6500_read(handle, MPU6500_REG_PWR_MGMT_2, (uint8_t *)&prev, 1); /* read config */
5523 if (res != 0) /* check result */
5524 {
5525 handle->debug_print("mpu6500: read power management 2 failed.\n"); /* read power management 2 failed */
5526
5527 return 1; /* return error */
5528 }
5529 prev &= ~(1 << source); /* clear config */
5530 prev |= enable << source; /* set config */
5531 res = a_mpu6500_write(handle, MPU6500_REG_PWR_MGMT_2, (uint8_t *)&prev, 1); /* write config */
5532 if (res != 0) /* check result */
5533 {
5534 handle->debug_print("mpu6500: write power management 2 failed.\n"); /* write power management 2 failed */
5535
5536 return 1; /* return error */
5537 }
5538
5539 return 0; /* success return 0 */
5540}
5541
5555{
5556 uint8_t res;
5557 uint8_t prev;
5558
5559 if (handle == NULL) /* check handle */
5560 {
5561 return 2; /* return error */
5562 }
5563 if (handle->inited != 1) /* check handle initialization */
5564 {
5565 return 3; /* return error */
5566 }
5567
5568 res = a_mpu6500_read(handle, MPU6500_REG_PWR_MGMT_2, (uint8_t *)&prev, 1); /* read config */
5569 if (res != 0) /* check result */
5570 {
5571 handle->debug_print("mpu6500: read power management 2 failed.\n"); /* read power management 2 failed */
5572
5573 return 1; /* return error */
5574 }
5575 *enable = (mpu6500_bool_t)((prev >> source) & (0x1)); /* get bool */
5576
5577 return 0; /* success return 0 */
5578}
5579
5591uint8_t mpu6500_get_fifo_count(mpu6500_handle_t *handle, uint16_t* count)
5592{
5593 uint8_t res;
5594 uint8_t buf[2];
5595
5596 if (handle == NULL) /* check handle */
5597 {
5598 return 2; /* return error */
5599 }
5600 if (handle->inited != 1) /* check handle initialization */
5601 {
5602 return 3; /* return error */
5603 }
5604
5605 res = a_mpu6500_read(handle, MPU6500_REG_FIFO_COUNTH, (uint8_t *)buf, 2); /* read fifo count */
5606 if (res != 0) /* check result */
5607 {
5608 handle->debug_print("mpu6500: read fifo count failed.\n"); /* read fifo count failed */
5609
5610 return 1; /* return error */
5611 }
5612 *count = (uint16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set count */
5613
5614 return 0; /* success return 0 */
5615}
5616
5629uint8_t mpu6500_fifo_get(mpu6500_handle_t *handle, uint8_t *buf, uint16_t len)
5630{
5631 uint8_t res;
5632
5633 if (handle == NULL) /* check handle */
5634 {
5635 return 2; /* return error */
5636 }
5637 if (handle->inited != 1) /* check handle initialization */
5638 {
5639 return 3; /* return error */
5640 }
5641
5642 res = a_mpu6500_read(handle, MPU6500_REG_R_W, buf, len); /* read fifo */
5643 if (res != 0) /* check result */
5644 {
5645 handle->debug_print("mpu6500: fifo read failed.\n"); /* fifo read failed */
5646
5647 return 1; /* return error */
5648 }
5649
5650 return 0; /* success return 0 */
5651}
5652
5665uint8_t mpu6500_fifo_set(mpu6500_handle_t *handle, uint8_t *buf, uint16_t len)
5666{
5667 uint8_t res;
5668
5669 if (handle == NULL) /* check handle */
5670 {
5671 return 2; /* return error */
5672 }
5673 if (handle->inited != 1) /* check handle initialization */
5674 {
5675 return 3; /* return error */
5676 }
5677
5678 res = a_mpu6500_write(handle, MPU6500_REG_R_W, buf, len); /* write fifo */
5679 if (res != 0) /* check result */
5680 {
5681 handle->debug_print("mpu6500: fifo write failed.\n"); /* fifo write failed */
5682
5683 return 1; /* return error */
5684 }
5685
5686 return 0; /* success return 0 */
5687}
5688
5701{
5702 uint8_t res;
5703 uint8_t prev;
5704
5705 if (handle == NULL) /* check handle */
5706 {
5707 return 2; /* return error */
5708 }
5709 if (handle->inited != 1) /* check handle initialization */
5710 {
5711 return 3; /* return error */
5712 }
5713
5714 res = a_mpu6500_read(handle, MPU6500_REG_SIGNAL_PATH_RESET, (uint8_t *)&prev, 1); /* read config */
5715 if (res != 0) /* check result */
5716 {
5717 handle->debug_print("mpu6500: read signal path reset failed.\n"); /* read signal path reset failed */
5718
5719 return 1; /* return error */
5720 }
5721 prev &= ~(1 << path); /* clear config */
5722 prev |= 1 << path; /* set config */
5723 res = a_mpu6500_write(handle, MPU6500_REG_SIGNAL_PATH_RESET, (uint8_t *)&prev, 1); /* write config */
5724 if (res != 0) /* check result */
5725 {
5726 handle->debug_print("mpu6500: write signal path reset failed.\n"); /* write signal path reset failed */
5727
5728 return 1; /* return error */
5729 }
5730
5731 return 0; /* success return 0 */
5732}
5733
5746{
5747 uint8_t res;
5748
5749 if (handle == NULL) /* check handle */
5750 {
5751 return 2; /* return error */
5752 }
5753 if (handle->inited != 1) /* check handle initialization */
5754 {
5755 return 3; /* return error */
5756 }
5757
5758 res = a_mpu6500_write(handle, MPU6500_REG_SMPRT_DIV, (uint8_t *)&d, 1); /* write config */
5759 if (res != 0) /* check result */
5760 {
5761 handle->debug_print("mpu6500: write smprt div failed.\n"); /* write smprt div failed */
5762
5763 return 1; /* return error */
5764 }
5765
5766 return 0; /* success return 0 */
5767}
5768
5781{
5782 uint8_t res;
5783
5784 if (handle == NULL) /* check handle */
5785 {
5786 return 2; /* return error */
5787 }
5788 if (handle->inited != 1) /* check handle initialization */
5789 {
5790 return 3; /* return error */
5791 }
5792
5793 res = a_mpu6500_read(handle, MPU6500_REG_SMPRT_DIV, (uint8_t *)d, 1); /* read config */
5794 if (res != 0) /* check result */
5795 {
5796 handle->debug_print("mpu6500: read smprt div failed.\n"); /* read smprt div failed */
5797
5798 return 1; /* return error */
5799 }
5800
5801 return 0; /* success return 0 */
5802}
5803
5816{
5817 uint8_t res;
5818 uint8_t prev;
5819
5820 if (handle == NULL) /* check handle */
5821 {
5822 return 2; /* return error */
5823 }
5824 if (handle->inited != 1) /* check handle initialization */
5825 {
5826 return 3; /* return error */
5827 }
5828
5829 res = a_mpu6500_read(handle, MPU6500_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
5830 if (res != 0) /* check result */
5831 {
5832 handle->debug_print("mpu6500: read config failed.\n"); /* read config failed */
5833
5834 return 1; /* return error */
5835 }
5836 prev &= ~(0x7 << 3); /* clear config */
5837 prev |= sync << 3; /* set config */
5838 res = a_mpu6500_write(handle, MPU6500_REG_CONFIG, (uint8_t *)&prev, 1); /* write config */
5839 if (res != 0) /* check result */
5840 {
5841 handle->debug_print("mpu6500: write config failed.\n"); /* write config failed */
5842
5843 return 1; /* return error */
5844 }
5845
5846 return 0; /* success return 0 */
5847}
5848
5861{
5862 uint8_t res;
5863 uint8_t prev;
5864
5865 if (handle == NULL) /* check handle */
5866 {
5867 return 2; /* return error */
5868 }
5869 if (handle->inited != 1) /* check handle initialization */
5870 {
5871 return 3; /* return error */
5872 }
5873
5874 res = a_mpu6500_read(handle, MPU6500_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
5875 if (res != 0) /* check result */
5876 {
5877 handle->debug_print("mpu6500: read config failed.\n"); /* read config failed */
5878
5879 return 1; /* return error */
5880 }
5881 *sync = (mpu6500_extern_sync_t)((prev >> 3) & 0x7); /* get the extern sync */
5882
5883 return 0; /* success return 0 */
5884}
5885
5898{
5899 uint8_t res;
5900 uint8_t prev;
5901
5902 if (handle == NULL) /* check handle */
5903 {
5904 return 2; /* return error */
5905 }
5906 if (handle->inited != 1) /* check handle initialization */
5907 {
5908 return 3; /* return error */
5909 }
5910
5911 res = a_mpu6500_read(handle, MPU6500_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
5912 if (res != 0) /* check result */
5913 {
5914 handle->debug_print("mpu6500: read config failed.\n"); /* read config failed */
5915
5916 return 1; /* return error */
5917 }
5918 prev &= ~(0x7 << 0); /* clear config */
5919 prev |= filter << 0; /* set config */
5920 res = a_mpu6500_write(handle, MPU6500_REG_CONFIG, (uint8_t *)&prev, 1); /* write config */
5921 if (res != 0) /* check result */
5922 {
5923 handle->debug_print("mpu6500: write config failed.\n"); /* write config failed */
5924
5925 return 1; /* return error */
5926 }
5927
5928 return 0; /* success return 0 */
5929}
5930
5943{
5944 uint8_t res;
5945 uint8_t prev;
5946
5947 if (handle == NULL) /* check handle */
5948 {
5949 return 2; /* return error */
5950 }
5951 if (handle->inited != 1) /* check handle initialization */
5952 {
5953 return 3; /* return error */
5954 }
5955
5956 res = a_mpu6500_read(handle, MPU6500_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
5957 if (res != 0) /* check result */
5958 {
5959 handle->debug_print("mpu6500: read config failed.\n"); /* read config failed */
5960
5961 return 1; /* return error */
5962 }
5963 *filter = (mpu6500_low_pass_filter_t)((prev >> 0) & 0x7); /* get the filter */
5964
5965 return 0; /* success return 0 */
5966}
5967
5980{
5981 uint8_t res;
5982 uint8_t prev;
5983
5984 if (handle == NULL) /* check handle */
5985 {
5986 return 2; /* return error */
5987 }
5988 if (handle->inited != 1) /* check handle initialization */
5989 {
5990 return 3; /* return error */
5991 }
5992
5993 res = a_mpu6500_read(handle, MPU6500_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
5994 if (res != 0) /* check result */
5995 {
5996 handle->debug_print("mpu6500: read config failed.\n"); /* read config failed */
5997
5998 return 1; /* return error */
5999 }
6000 prev &= ~(1 << 6); /* clear config */
6001 prev |= mode << 6; /* set config */
6002 res = a_mpu6500_write(handle, MPU6500_REG_CONFIG, (uint8_t *)&prev, 1); /* write config */
6003 if (res != 0) /* check result */
6004 {
6005 handle->debug_print("mpu6500: write config failed.\n"); /* write config failed */
6006
6007 return 1; /* return error */
6008 }
6009
6010 return 0; /* success return 0 */
6011}
6012
6025{
6026 uint8_t res;
6027 uint8_t prev;
6028
6029 if (handle == NULL) /* check handle */
6030 {
6031 return 2; /* return error */
6032 }
6033 if (handle->inited != 1) /* check handle initialization */
6034 {
6035 return 3; /* return error */
6036 }
6037
6038 res = a_mpu6500_read(handle, MPU6500_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
6039 if (res != 0) /* check result */
6040 {
6041 handle->debug_print("mpu6500: read config failed.\n"); /* read config failed */
6042
6043 return 1; /* return error */
6044 }
6045 *mode = (mpu6500_fifo_mode)((prev >> 6) & 0x1); /* get the mode */
6046
6047 return 0; /* success return 0 */
6048}
6049
6063{
6064 uint8_t res;
6065 uint8_t prev;
6066
6067 if (handle == NULL) /* check handle */
6068 {
6069 return 2; /* return error */
6070 }
6071 if (handle->inited != 1) /* check handle initialization */
6072 {
6073 return 3; /* return error */
6074 }
6075
6076 res = a_mpu6500_read(handle, MPU6500_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* read gyroscope config */
6077 if (res != 0) /* check result */
6078 {
6079 handle->debug_print("mpu6500: read gyroscope config failed.\n"); /* read gyroscope config failed */
6080
6081 return 1; /* return error */
6082 }
6083 prev &= ~(1 << axis); /* clear config */
6084 prev |= enable << axis; /* set config */
6085 res = a_mpu6500_write(handle, MPU6500_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* write gyroscope config */
6086 if (res != 0) /* check result */
6087 {
6088 handle->debug_print("mpu6500: write gyroscope config failed.\n"); /* write gyroscope config failed */
6089
6090 return 1; /* return error */
6091 }
6092
6093 return 0; /* success return 0 */
6094}
6095
6109{
6110 uint8_t res;
6111 uint8_t prev;
6112
6113 if (handle == NULL) /* check handle */
6114 {
6115 return 2; /* return error */
6116 }
6117 if (handle->inited != 1) /* check handle initialization */
6118 {
6119 return 3; /* return error */
6120 }
6121
6122 res = a_mpu6500_read(handle, MPU6500_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* read gyroscope config */
6123 if (res != 0) /* check result */
6124 {
6125 handle->debug_print("mpu6500: read gyroscope config failed.\n"); /* read gyroscope config failed */
6126
6127 return 1; /* return error */
6128 }
6129 *enable = (mpu6500_bool_t)((prev >> axis) & 0x01); /* get the bool */
6130
6131 return 0; /* success return 0 */
6132}
6133
6146{
6147 uint8_t res;
6148 uint8_t prev;
6149
6150 if (handle == NULL) /* check handle */
6151 {
6152 return 2; /* return error */
6153 }
6154 if (handle->inited != 1) /* check handle initialization */
6155 {
6156 return 3; /* return error */
6157 }
6158
6159 res = a_mpu6500_read(handle, MPU6500_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* read gyroscope config */
6160 if (res != 0) /* check result */
6161 {
6162 handle->debug_print("mpu6500: read gyroscope config failed.\n"); /* read gyroscope config failed */
6163
6164 return 1; /* return error */
6165 }
6166 prev &= ~(3 << 3); /* clear config */
6167 prev |= range << 3; /* set config */
6168 res = a_mpu6500_write(handle, MPU6500_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* write gyroscope config */
6169 if (res != 0) /* check result */
6170 {
6171 handle->debug_print("mpu6500: write gyroscope config failed.\n"); /* write gyroscope config failed */
6172
6173 return 1; /* return error */
6174 }
6175
6176 return 0; /* success return 0 */
6177}
6178
6191{
6192 uint8_t res;
6193 uint8_t prev;
6194
6195 if (handle == NULL) /* check handle */
6196 {
6197 return 2; /* return error */
6198 }
6199 if (handle->inited != 1) /* check handle initialization */
6200 {
6201 return 3; /* return error */
6202 }
6203
6204 res = a_mpu6500_read(handle, MPU6500_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* read gyroscope config */
6205 if (res != 0) /* check result */
6206 {
6207 handle->debug_print("mpu6500: read gyroscope config failed.\n"); /* read gyroscope config failed */
6208
6209 return 1; /* return error */
6210 }
6211 *range = (mpu6500_gyroscope_range_t)((prev >> 3) & 0x3); /* get the range */
6212
6213 return 0; /* success return 0 */
6214}
6215
6228uint8_t mpu6500_set_gyroscope_choice(mpu6500_handle_t *handle, uint8_t choice)
6229{
6230 uint8_t res;
6231 uint8_t prev;
6232
6233 if (handle == NULL) /* check handle */
6234 {
6235 return 2; /* return error */
6236 }
6237 if (handle->inited != 1) /* check handle initialization */
6238 {
6239 return 3; /* return error */
6240 }
6241 if (choice > 3) /* check the choice */
6242 {
6243 handle->debug_print("mpu6500: choice > 3.\n"); /* choice > 3 */
6244
6245 return 4; /* return error */
6246 }
6247
6248 res = a_mpu6500_read(handle, MPU6500_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* read gyroscope config */
6249 if (res != 0) /* check result */
6250 {
6251 handle->debug_print("mpu6500: read gyroscope config failed.\n"); /* read gyroscope config failed */
6252
6253 return 1; /* return error */
6254 }
6255 prev &= ~(3 << 0); /* clear config */
6256 prev |= choice << 0; /* set config */
6257 res = a_mpu6500_write(handle, MPU6500_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* write gyroscope config */
6258 if (res != 0) /* check result */
6259 {
6260 handle->debug_print("mpu6500: write gyroscope config failed.\n"); /* write gyroscope config failed */
6261
6262 return 1; /* return error */
6263 }
6264
6265 return 0; /* success return 0 */
6266}
6267
6279uint8_t mpu6500_get_gyroscope_choice(mpu6500_handle_t *handle, uint8_t *choice)
6280{
6281 uint8_t res;
6282 uint8_t prev;
6283
6284 if (handle == NULL) /* check handle */
6285 {
6286 return 2; /* return error */
6287 }
6288 if (handle->inited != 1) /* check handle initialization */
6289 {
6290 return 3; /* return error */
6291 }
6292
6293 res = a_mpu6500_read(handle, MPU6500_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* read gyroscope config */
6294 if (res != 0) /* check result */
6295 {
6296 handle->debug_print("mpu6500: read gyroscope config failed.\n"); /* read gyroscope config failed */
6297
6298 return 1; /* return error */
6299 }
6300 *choice = prev & 0x03; /* get the choice */
6301
6302 return 0; /* success return 0 */
6303}
6304
6318{
6319 uint8_t res;
6320 uint8_t prev;
6321
6322 if (handle == NULL) /* check handle */
6323 {
6324 return 2; /* return error */
6325 }
6326 if (handle->inited != 1) /* check handle initialization */
6327 {
6328 return 3; /* return error */
6329 }
6330
6331 res = a_mpu6500_read(handle, MPU6500_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* read accelerometer config */
6332 if (res != 0) /* check result */
6333 {
6334 handle->debug_print("mpu6500: read accelerometer config failed.\n"); /* read accelerometer config failed */
6335
6336 return 1; /* return error */
6337 }
6338 prev &= ~(1 << axis); /* clear config */
6339 prev |= enable << axis; /* set config */
6340 res = a_mpu6500_write(handle, MPU6500_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* write accelerometer config */
6341 if (res != 0) /* check result */
6342 {
6343 handle->debug_print("mpu6500: write accelerometer config failed.\n"); /* write accelerometer config failed */
6344
6345 return 1; /* return error */
6346 }
6347
6348 return 0; /* success return 0 */
6349}
6350
6364{
6365 uint8_t res;
6366 uint8_t prev;
6367
6368 if (handle == NULL) /* check handle */
6369 {
6370 return 2; /* return error */
6371 }
6372 if (handle->inited != 1) /* check handle initialization */
6373 {
6374 return 3; /* return error */
6375 }
6376
6377 res = a_mpu6500_read(handle, MPU6500_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* read accelerometer config */
6378 if (res != 0) /* check result */
6379 {
6380 handle->debug_print("mpu6500: read accelerometer config failed.\n"); /* read accelerometer config failed */
6381
6382 return 1; /* return error */
6383 }
6384 *enable = (mpu6500_bool_t)((prev >> axis) & 0x01); /* get the bool */
6385
6386 return 0; /* success return 0 */
6387}
6388
6401{
6402 uint8_t res;
6403 uint8_t prev;
6404
6405 if (handle == NULL) /* check handle */
6406 {
6407 return 2; /* return error */
6408 }
6409 if (handle->inited != 1) /* check handle initialization */
6410 {
6411 return 3; /* return error */
6412 }
6413
6414 res = a_mpu6500_read(handle, MPU6500_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* read accelerometer config */
6415 if (res != 0) /* check result */
6416 {
6417 handle->debug_print("mpu6500: read accelerometer config failed.\n"); /* read accelerometer config failed */
6418
6419 return 1; /* return error */
6420 }
6421 prev &= ~(3 << 3); /* clear config */
6422 prev |= range << 3; /* set config */
6423 res = a_mpu6500_write(handle, MPU6500_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* write accelerometer config */
6424 if (res != 0) /* check result */
6425 {
6426 handle->debug_print("mpu6500: write accelerometer config failed.\n"); /* write accelerometer config failed */
6427
6428 return 1; /* return error */
6429 }
6430
6431 return 0; /* success return 0 */
6432}
6433
6446{
6447 uint8_t res;
6448 uint8_t prev;
6449
6450 if (handle == NULL) /* check handle */
6451 {
6452 return 2; /* return error */
6453 }
6454 if (handle->inited != 1) /* check handle initialization */
6455 {
6456 return 3; /* return error */
6457 }
6458
6459 res = a_mpu6500_read(handle, MPU6500_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* read accelerometer config */
6460 if (res != 0) /* check result */
6461 {
6462 handle->debug_print("mpu6500: read accelerometer config failed.\n"); /* read accelerometer config failed */
6463
6464 return 1; /* return error */
6465 }
6466 *range = (mpu6500_accelerometer_range_t)((prev >> 3) & 0x3); /* get the range */
6467
6468 return 0; /* success return 0 */
6469}
6470
6482{
6483 uint8_t res;
6484 uint8_t prev;
6485
6486 if (handle == NULL) /* check handle */
6487 {
6488 return 2; /* return error */
6489 }
6490 if (handle->inited != 1) /* check handle initialization */
6491 {
6492 return 3; /* return error */
6493 }
6494
6495 res = a_mpu6500_read(handle, MPU6500_REG_ACCEL_CONFIG2, (uint8_t *)&prev, 1); /* read config */
6496 if (res != 0) /* check result */
6497 {
6498 handle->debug_print("mpu6500: read accelerometer 2 config failed.\n"); /* read accelerometer 2 config failed */
6499
6500 return 1; /* return error */
6501 }
6502 prev &= ~(1 << 6); /* clear config */
6503 prev |= 1 << 6; /* set config */
6504 res = a_mpu6500_write(handle, MPU6500_REG_ACCEL_CONFIG2, (uint8_t *)&prev, 1); /* write config */
6505 if (res != 0) /* check result */
6506 {
6507 handle->debug_print("mpu6500: write accelerometer 2 config failed.\n"); /* write accelerometer 2 config failed */
6508
6509 return 1; /* return error */
6510 }
6511
6512 return 0; /* success return 0 */
6513}
6514
6528{
6529 uint8_t res;
6530 uint8_t prev;
6531
6532 if (handle == NULL) /* check handle */
6533 {
6534 return 2; /* return error */
6535 }
6536 if (handle->inited != 1) /* check handle initialization */
6537 {
6538 return 3; /* return error */
6539 }
6540 if (choice > 1) /* check the choice */
6541 {
6542 handle->debug_print("mpu6500: choice > 1.\n"); /* choice > 1 */
6543
6544 return 4; /* return error */
6545 }
6546
6547 res = a_mpu6500_read(handle, MPU6500_REG_ACCEL_CONFIG2, (uint8_t *)&prev, 1); /* read accelerometer config */
6548 if (res != 0) /* check result */
6549 {
6550 handle->debug_print("mpu6500: read accelerometer 2 config failed.\n"); /* read accelerometer 2 config failed */
6551
6552 return 1; /* return error */
6553 }
6554 prev &= ~(1 << 3); /* clear config */
6555 prev |= choice << 3; /* set config */
6556 res = a_mpu6500_write(handle, MPU6500_REG_ACCEL_CONFIG2, (uint8_t *)&prev, 1); /* write accelerometer config */
6557 if (res != 0) /* check result */
6558 {
6559 handle->debug_print("mpu6500: write accelerometer 2 config failed.\n"); /* write accelerometer 2 config failed */
6560
6561 return 1; /* return error */
6562 }
6563
6564 return 0; /* success return 0 */
6565}
6566
6580{
6581 uint8_t res;
6582 uint8_t prev;
6583
6584 if (handle == NULL) /* check handle */
6585 {
6586 return 2; /* return error */
6587 }
6588 if (handle->inited != 1) /* check handle initialization */
6589 {
6590 return 3; /* return error */
6591 }
6592
6593 res = a_mpu6500_read(handle, MPU6500_REG_ACCEL_CONFIG2, (uint8_t *)&prev, 1); /* read accelerometer config */
6594 if (res != 0) /* check result */
6595 {
6596 handle->debug_print("mpu6500: read accelerometer 2 config failed.\n"); /* read accelerometer 2 config failed */
6597
6598 return 1; /* return error */
6599 }
6600 *choice = (prev >> 3) & 0x1; /* get the choice */
6601
6602 return 0; /* success return 0 */
6603}
6604
6617{
6618 uint8_t res;
6619 uint8_t prev;
6620
6621 if (handle == NULL) /* check handle */
6622 {
6623 return 2; /* return error */
6624 }
6625 if (handle->inited != 1) /* check handle initialization */
6626 {
6627 return 3; /* return error */
6628 }
6629
6630 res = a_mpu6500_read(handle, MPU6500_REG_ACCEL_CONFIG2, (uint8_t *)&prev, 1); /* read config */
6631 if (res != 0) /* check result */
6632 {
6633 handle->debug_print("mpu6500: read accelerometer 2 config failed.\n"); /* read accelerometer 2 config failed */
6634
6635 return 1; /* return error */
6636 }
6637 prev &= ~(0x7 << 0); /* clear config */
6638 prev |= filter << 0; /* set config */
6639 res = a_mpu6500_write(handle, MPU6500_REG_ACCEL_CONFIG2, (uint8_t *)&prev, 1); /* write config */
6640 if (res != 0) /* check result */
6641 {
6642 handle->debug_print("mpu6500: write accelerometer 2 config failed.\n"); /* write accelerometer 2 config failed */
6643
6644 return 1; /* return error */
6645 }
6646
6647 return 0; /* success return 0 */
6648}
6649
6662{
6663 uint8_t res;
6664 uint8_t prev;
6665
6666 if (handle == NULL) /* check handle */
6667 {
6668 return 2; /* return error */
6669 }
6670 if (handle->inited != 1) /* check handle initialization */
6671 {
6672 return 3; /* return error */
6673 }
6674
6675 res = a_mpu6500_read(handle, MPU6500_REG_ACCEL_CONFIG2, (uint8_t *)&prev, 1); /* read config */
6676 if (res != 0) /* check result */
6677 {
6678 handle->debug_print("mpu6500: read accelerometer 2 config failed.\n"); /* read accelerometer 2 config failed */
6679
6680 return 1; /* return error */
6681 }
6682 *filter = (mpu6500_accelerometer_low_pass_filter_t)(prev & 0x7); /* get the filter */
6683
6684 return 0; /* success return 0 */
6685}
6686
6699{
6700 uint8_t res;
6701 uint8_t prev;
6702
6703 if (handle == NULL) /* check handle */
6704 {
6705 return 2; /* return error */
6706 }
6707 if (handle->inited != 1) /* check handle initialization */
6708 {
6709 return 3; /* return error */
6710 }
6711
6712 res = a_mpu6500_read(handle, MPU6500_REG_LP_ACCEL_ODR, (uint8_t *)&prev, 1); /* read config */
6713 if (res != 0) /* check result */
6714 {
6715 handle->debug_print("mpu6500: read lp accelerometer odr failed.\n"); /* read lp accelerometer odr failed */
6716
6717 return 1; /* return error */
6718 }
6719 prev &= ~(0xF << 0); /* clear config */
6720 prev |= rate << 0; /* set config */
6721 res = a_mpu6500_write(handle, MPU6500_REG_LP_ACCEL_ODR, (uint8_t *)&prev, 1); /* write config */
6722 if (res != 0) /* check result */
6723 {
6724 handle->debug_print("mpu6500: write lp accelerometer odr failed.\n"); /* write lp accelerometer odr failed */
6725
6726 return 1; /* return error */
6727 }
6728
6729 return 0; /* success return 0 */
6730}
6731
6744{
6745 uint8_t res;
6746 uint8_t prev;
6747
6748 if (handle == NULL) /* check handle */
6749 {
6750 return 2; /* return error */
6751 }
6752 if (handle->inited != 1) /* check handle initialization */
6753 {
6754 return 3; /* return error */
6755 }
6756
6757 res = a_mpu6500_read(handle, MPU6500_REG_LP_ACCEL_ODR, (uint8_t *)&prev, 1); /* read config */
6758 if (res != 0) /* check result */
6759 {
6760 handle->debug_print("mpu6500: read lp accelerometer odr failed.\n"); /* read lp accelerometer odr failed */
6761
6762 return 1; /* return error */
6763 }
6764 *rate = (mpu6500_low_power_accel_output_rate_t)(prev & 0xF); /* get the rate */
6765
6766 return 0; /* success return 0 */
6767}
6768
6781{
6782 uint8_t res;
6783 uint8_t prev;
6784
6785 if (handle == NULL) /* check handle */
6786 {
6787 return 2; /* return error */
6788 }
6789 if (handle->inited != 1) /* check handle initialization */
6790 {
6791 return 3; /* return error */
6792 }
6793
6794 res = a_mpu6500_read(handle, MPU6500_REG_MOT_DETECT_CTRL, (uint8_t *)&prev, 1); /* read config */
6795 if (res != 0) /* check result */
6796 {
6797 handle->debug_print("mpu6500: read motion detect ctrl failed.\n"); /* read motion detect ctrl failed */
6798
6799 return 1; /* return error */
6800 }
6801 prev &= ~(1 << 7); /* clear config */
6802 prev |= enable << 7; /* set config */
6803 res = a_mpu6500_write(handle, MPU6500_REG_MOT_DETECT_CTRL, (uint8_t *)&prev, 1); /* write config */
6804 if (res != 0) /* check result */
6805 {
6806 handle->debug_print("mpu6500: write motion detect ctrl failed.\n"); /* write motion detect ctrl failed */
6807
6808 return 1; /* return error */
6809 }
6810
6811 return 0; /* success return 0 */
6812}
6813
6826{
6827 uint8_t res;
6828 uint8_t prev;
6829
6830 if (handle == NULL) /* check handle */
6831 {
6832 return 2; /* return error */
6833 }
6834 if (handle->inited != 1) /* check handle initialization */
6835 {
6836 return 3; /* return error */
6837 }
6838
6839 res = a_mpu6500_read(handle, MPU6500_REG_MOT_DETECT_CTRL, (uint8_t *)&prev, 1); /* read config */
6840 if (res != 0) /* check result */
6841 {
6842 handle->debug_print("mpu6500: read motion detect ctrl failed.\n"); /* read motion detect ctrl failed */
6843
6844 return 1; /* return error */
6845 }
6846 *enable = (mpu6500_bool_t)((prev >> 7) & 0x01); /* get the bool */
6847
6848 return 0; /* success return 0 */
6849}
6850
6863{
6864 uint8_t res;
6865 uint8_t prev;
6866
6867 if (handle == NULL) /* check handle */
6868 {
6869 return 2; /* return error */
6870 }
6871 if (handle->inited != 1) /* check handle initialization */
6872 {
6873 return 3; /* return error */
6874 }
6875
6876 res = a_mpu6500_read(handle, MPU6500_REG_MOT_DETECT_CTRL, (uint8_t *)&prev, 1); /* read config */
6877 if (res != 0) /* check result */
6878 {
6879 handle->debug_print("mpu6500: read motion detect ctrl failed.\n"); /* read motion detect ctrl failed */
6880
6881 return 1; /* return error */
6882 }
6883 prev &= ~(1 << 6); /* clear config */
6884 prev |= enable << 6; /* set config */
6885 res = a_mpu6500_write(handle, MPU6500_REG_MOT_DETECT_CTRL, (uint8_t *)&prev, 1); /* write config */
6886 if (res != 0) /* check result */
6887 {
6888 handle->debug_print("mpu6500: write motion detect ctrl failed.\n"); /* write motion detect ctrl failed */
6889
6890 return 1; /* return error */
6891 }
6892
6893 return 0; /* success return 0 */
6894}
6895
6908{
6909 uint8_t res;
6910 uint8_t prev;
6911
6912 if (handle == NULL) /* check handle */
6913 {
6914 return 2; /* return error */
6915 }
6916 if (handle->inited != 1) /* check handle initialization */
6917 {
6918 return 3; /* return error */
6919 }
6920
6921 res = a_mpu6500_read(handle, MPU6500_REG_MOT_DETECT_CTRL, (uint8_t *)&prev, 1); /* read config */
6922 if (res != 0) /* check result */
6923 {
6924 handle->debug_print("mpu6500: read motion detect ctrl failed.\n"); /* read motion detect ctrl failed */
6925
6926 return 1; /* return error */
6927 }
6928 *enable = (mpu6500_bool_t)((prev >> 6) & 0x01); /* get the bool */
6929
6930 return 0; /* success return 0 */
6931}
6932
6946{
6947 uint8_t res;
6948 uint8_t prev;
6949
6950 if (handle == NULL) /* check handle */
6951 {
6952 return 2; /* return error */
6953 }
6954 if (handle->inited != 1) /* check handle initialization */
6955 {
6956 return 3; /* return error */
6957 }
6958
6959 res = a_mpu6500_read(handle, MPU6500_REG_FIFO_EN, (uint8_t *)&prev, 1); /* read fifo enable config */
6960 if (res != 0) /* check result */
6961 {
6962 handle->debug_print("mpu6500: read fifo enable config failed.\n"); /* read fifo enable config failed */
6963
6964 return 1; /* return error */
6965 }
6966 prev &= ~(1 << fifo); /* clear config */
6967 prev |= enable << fifo; /* set config */
6968 res = a_mpu6500_write(handle, MPU6500_REG_FIFO_EN, (uint8_t *)&prev, 1); /* write fifo enable config */
6969 if (res != 0) /* check result */
6970 {
6971 handle->debug_print("mpu6500: write fifo enable config failed.\n"); /* write fifo enable config failed */
6972
6973 return 1; /* return error */
6974 }
6975
6976 return 0; /* success return 0 */
6977}
6978
6992{
6993 uint8_t res;
6994 uint8_t prev;
6995
6996 if (handle == NULL) /* check handle */
6997 {
6998 return 2; /* return error */
6999 }
7000 if (handle->inited != 1) /* check handle initialization */
7001 {
7002 return 3; /* return error */
7003 }
7004
7005 res = a_mpu6500_read(handle, MPU6500_REG_FIFO_EN, (uint8_t *)&prev, 1); /* read fifo enable config */
7006 if (res != 0) /* check result */
7007 {
7008 handle->debug_print("mpu6500: read fifo enable config failed.\n"); /* read fifo enable config failed */
7009
7010 return 1; /* return error */
7011 }
7012 *enable = (mpu6500_bool_t)((prev >> fifo) & 0x01); /* get the bool */
7013
7014 return 0; /* success return 0 */
7015}
7016
7029{
7030 uint8_t res;
7031 uint8_t prev;
7032
7033 if (handle == NULL) /* check handle */
7034 {
7035 return 2; /* return error */
7036 }
7037 if (handle->inited != 1) /* check handle initialization */
7038 {
7039 return 3; /* return error */
7040 }
7041
7042 res = a_mpu6500_read(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
7043 if (res != 0) /* check result */
7044 {
7045 handle->debug_print("mpu6500: read interrupt pin failed.\n"); /* read interrupt pin failed */
7046
7047 return 1; /* return error */
7048 }
7049 prev &= ~(1 << 7); /* clear config */
7050 prev |= level << 7; /* set config */
7051 res = a_mpu6500_write(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
7052 if (res != 0) /* check result */
7053 {
7054 handle->debug_print("mpu6500: write interrupt pin failed.\n"); /* write interrupt pin failed */
7055
7056 return 1; /* return error */
7057 }
7058
7059 return 0; /* success return 0 */
7060}
7061
7074{
7075 uint8_t res;
7076 uint8_t prev;
7077
7078 if (handle == NULL) /* check handle */
7079 {
7080 return 2; /* return error */
7081 }
7082 if (handle->inited != 1) /* check handle initialization */
7083 {
7084 return 3; /* return error */
7085 }
7086
7087 res = a_mpu6500_read(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
7088 if (res != 0) /* check result */
7089 {
7090 handle->debug_print("mpu6500: read interrupt pin failed.\n"); /* read interrupt pin failed */
7091
7092 return 1; /* return error */
7093 }
7094 *level = (mpu6500_pin_level_t)((prev >> 7) & 0x01); /* get the level */
7095
7096 return 0; /* success return 0 */
7097}
7098
7111{
7112 uint8_t res;
7113 uint8_t prev;
7114
7115 if (handle == NULL) /* check handle */
7116 {
7117 return 2; /* return error */
7118 }
7119 if (handle->inited != 1) /* check handle initialization */
7120 {
7121 return 3; /* return error */
7122 }
7123
7124 res = a_mpu6500_read(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
7125 if (res != 0) /* check result */
7126 {
7127 handle->debug_print("mpu6500: read interrupt pin failed.\n"); /* read interrupt pin failed */
7128
7129 return 1; /* return error */
7130 }
7131 prev &= ~(1 << 6); /* clear config */
7132 prev |= type << 6; /* set config */
7133 res = a_mpu6500_write(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
7134 if (res != 0) /* check result */
7135 {
7136 handle->debug_print("mpu6500: write interrupt pin failed.\n"); /* write interrupt pin failed */
7137
7138 return 1; /* return error */
7139 }
7140
7141 return 0; /* success return 0 */
7142}
7143
7156{
7157 uint8_t res;
7158 uint8_t prev;
7159
7160 if (handle == NULL) /* check handle */
7161 {
7162 return 2; /* return error */
7163 }
7164 if (handle->inited != 1) /* check handle initialization */
7165 {
7166 return 3; /* return error */
7167 }
7168
7169 res = a_mpu6500_read(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
7170 if (res != 0) /* check result */
7171 {
7172 handle->debug_print("mpu6500: read interrupt pin failed.\n"); /* read interrupt pin failed */
7173
7174 return 1; /* return error */
7175 }
7176 *type = (mpu6500_pin_type_t)((prev >> 6) & 0x01); /* get the pin type */
7177
7178 return 0; /* success return 0 */
7179}
7180
7193{
7194 uint8_t res;
7195 uint8_t prev;
7196
7197 if (handle == NULL) /* check handle */
7198 {
7199 return 2; /* return error */
7200 }
7201 if (handle->inited != 1) /* check handle initialization */
7202 {
7203 return 3; /* return error */
7204 }
7205
7206 res = a_mpu6500_read(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
7207 if (res != 0) /* check result */
7208 {
7209 handle->debug_print("mpu6500: read interrupt pin failed.\n"); /* read interrupt pin failed */
7210
7211 return 1; /* return error */
7212 }
7213 prev &= ~(1 << 5); /* clear config */
7214 prev |= (!enable) << 5; /* set config */
7215 res = a_mpu6500_write(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
7216 if (res != 0) /* check result */
7217 {
7218 handle->debug_print("mpu6500: write interrupt pin failed.\n"); /* write interrupt pin failed */
7219
7220 return 1; /* return error */
7221 }
7222
7223 return 0; /* success return 0 */
7224}
7225
7238{
7239 uint8_t res;
7240 uint8_t prev;
7241
7242 if (handle == NULL) /* check handle */
7243 {
7244 return 2; /* return error */
7245 }
7246 if (handle->inited != 1) /* check handle initialization */
7247 {
7248 return 3; /* return error */
7249 }
7250
7251 res = a_mpu6500_read(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
7252 if (res != 0) /* check result */
7253 {
7254 handle->debug_print("mpu6500: read interrupt pin failed.\n"); /* read interrupt pin failed */
7255
7256 return 1; /* return error */
7257 }
7258 *enable = (mpu6500_bool_t)(!((prev >> 5) & 0x01)); /* get the bool */
7259
7260 return 0; /* success return 0 */
7261}
7262
7275{
7276 uint8_t res;
7277 uint8_t prev;
7278
7279 if (handle == NULL) /* check handle */
7280 {
7281 return 2; /* return error */
7282 }
7283 if (handle->inited != 1) /* check handle initialization */
7284 {
7285 return 3; /* return error */
7286 }
7287
7288 res = a_mpu6500_read(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
7289 if (res != 0) /* check result */
7290 {
7291 handle->debug_print("mpu6500: read interrupt pin failed.\n"); /* read interrupt pin failed */
7292
7293 return 1; /* return error */
7294 }
7295 prev &= ~(1 << 4); /* clear config */
7296 prev |= enable << 4; /* set config */
7297 res = a_mpu6500_write(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
7298 if (res != 0) /* check result */
7299 {
7300 handle->debug_print("mpu6500: write interrupt pin failed.\n"); /* write interrupt pin failed */
7301
7302 return 1; /* return error */
7303 }
7304
7305 return 0; /* success return 0 */
7306}
7307
7320{
7321 uint8_t res;
7322 uint8_t prev;
7323
7324 if (handle == NULL) /* check handle */
7325 {
7326 return 2; /* return error */
7327 }
7328 if (handle->inited != 1) /* check handle initialization */
7329 {
7330 return 3; /* return error */
7331 }
7332
7333 res = a_mpu6500_read(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
7334 if (res != 0) /* check result */
7335 {
7336 handle->debug_print("mpu6500: read interrupt pin failed.\n"); /* read interrupt pin failed */
7337
7338 return 1; /* return error */
7339 }
7340 *enable = (mpu6500_bool_t)((prev >> 4) & 0x01); /* get the bool */
7341
7342 return 0; /* success return 0 */
7343}
7344
7357{
7358 uint8_t res;
7359 uint8_t prev;
7360
7361 if (handle == NULL) /* check handle */
7362 {
7363 return 2; /* return error */
7364 }
7365 if (handle->inited != 1) /* check handle initialization */
7366 {
7367 return 3; /* return error */
7368 }
7369
7370 res = a_mpu6500_read(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
7371 if (res != 0) /* check result */
7372 {
7373 handle->debug_print("mpu6500: read interrupt pin failed.\n"); /* read interrupt pin failed */
7374
7375 return 1; /* return error */
7376 }
7377 prev &= ~(1 << 3); /* clear config */
7378 prev |= level << 3; /* set config */
7379 res = a_mpu6500_write(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
7380 if (res != 0) /* check result */
7381 {
7382 handle->debug_print("mpu6500: write interrupt pin failed.\n"); /* write interrupt pin failed */
7383
7384 return 1; /* return error */
7385 }
7386
7387 return 0; /* success return 0 */
7388}
7389
7402{
7403 uint8_t res;
7404 uint8_t prev;
7405
7406 if (handle == NULL) /* check handle */
7407 {
7408 return 2; /* return error */
7409 }
7410 if (handle->inited != 1) /* check handle initialization */
7411 {
7412 return 3; /* return error */
7413 }
7414
7415 res = a_mpu6500_read(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
7416 if (res != 0) /* check result */
7417 {
7418 handle->debug_print("mpu6500: read interrupt pin failed.\n"); /* read interrupt pin failed */
7419
7420 return 1; /* return error */
7421 }
7422 *level = (mpu6500_pin_level_t)((prev >> 3) & 0x01); /* get the level */
7423
7424 return 0; /* success return 0 */
7425}
7426
7439{
7440 uint8_t res;
7441 uint8_t prev;
7442
7443 if (handle == NULL) /* check handle */
7444 {
7445 return 2; /* return error */
7446 }
7447 if (handle->inited != 1) /* check handle initialization */
7448 {
7449 return 3; /* return error */
7450 }
7451
7452 res = a_mpu6500_read(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
7453 if (res != 0) /* check result */
7454 {
7455 handle->debug_print("mpu6500: read interrupt pin failed.\n"); /* read interrupt pin failed */
7456
7457 return 1; /* return error */
7458 }
7459 prev &= ~(1 << 2); /* clear config */
7460 prev |= enable << 2; /* set config */
7461 res = a_mpu6500_write(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
7462 if (res != 0) /* check result */
7463 {
7464 handle->debug_print("mpu6500: write interrupt pin failed.\n"); /* write interrupt pin failed */
7465
7466 return 1; /* return error */
7467 }
7468
7469 return 0; /* success return 0 */
7470}
7471
7484{
7485 uint8_t res;
7486 uint8_t prev;
7487
7488 if (handle == NULL) /* check handle */
7489 {
7490 return 2; /* return error */
7491 }
7492 if (handle->inited != 1) /* check handle initialization */
7493 {
7494 return 3; /* return error */
7495 }
7496
7497 res = a_mpu6500_read(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
7498 if (res != 0) /* check result */
7499 {
7500 handle->debug_print("mpu6500: read interrupt pin failed.\n"); /* read interrupt pin failed */
7501
7502 return 1; /* return error */
7503 }
7504 *enable = (mpu6500_bool_t)((prev >> 2) & 0x01); /* get the bool */
7505
7506 return 0; /* success return 0 */
7507}
7508
7521{
7522 uint8_t res;
7523 uint8_t prev;
7524
7525 if (handle == NULL) /* check handle */
7526 {
7527 return 2; /* return error */
7528 }
7529 if (handle->inited != 1) /* check handle initialization */
7530 {
7531 return 3; /* return error */
7532 }
7533
7534 res = a_mpu6500_read(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin */
7535 if (res != 0) /* check result */
7536 {
7537 handle->debug_print("mpu6500: read interrupt pin failed.\n"); /* read interrupt pin failed */
7538
7539 return 1; /* return error */
7540 }
7541 prev &= ~(1 << 1); /* clear config */
7542 prev |= enable << 1; /* set config */
7543 res = a_mpu6500_write(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
7544 if (res != 0) /* check result */
7545 {
7546 handle->debug_print("mpu6500: write interrupt pin failed.\n"); /* write interrupt pin failed */
7547
7548 return 1; /* return error */
7549 }
7550
7551 return 0; /* success return 0 */
7552}
7553
7566{
7567 uint8_t res;
7568 uint8_t prev;
7569
7570 if (handle == NULL) /* check handle */
7571 {
7572 return 2; /* return error */
7573 }
7574 if (handle->inited != 1) /* check handle initialization */
7575 {
7576 return 3; /* return error */
7577 }
7578
7579 res = a_mpu6500_read(handle, MPU6500_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin */
7580 if (res != 0) /* check result */
7581 {
7582 handle->debug_print("mpu6500: read interrupt pin failed.\n"); /* read interrupt pin failed */
7583
7584 return 1; /* return error */
7585 }
7586 *enable = (mpu6500_bool_t)((prev >> 1) & 0x01); /* get the bool */
7587
7588 return 0; /* success return 0 */
7589}
7590
7604{
7605 uint8_t res;
7606 uint8_t prev;
7607
7608 if (handle == NULL) /* check handle */
7609 {
7610 return 2; /* return error */
7611 }
7612 if (handle->inited != 1) /* check handle initialization */
7613 {
7614 return 3; /* return error */
7615 }
7616
7617 res = a_mpu6500_read(handle, MPU6500_REG_INT_ENABLE, (uint8_t *)&prev, 1); /* read interrupt enable */
7618 if (res != 0) /* check result */
7619 {
7620 handle->debug_print("mpu6500: read interrupt enable failed.\n"); /* read interrupt enable failed */
7621
7622 return 1; /* return error */
7623 }
7624 prev &= ~(1 << type); /* clear config */
7625 prev |= enable << type; /* set config */
7626 res = a_mpu6500_write(handle, MPU6500_REG_INT_ENABLE, (uint8_t *)&prev, 1); /* write interrupt enable */
7627 if (res != 0) /* check result */
7628 {
7629 handle->debug_print("mpu6500: write interrupt enable failed.\n"); /* write interrupt enable failed */
7630
7631 return 1; /* return error */
7632 }
7633
7634 return 0; /* success return 0 */
7635}
7636
7650{
7651 uint8_t res;
7652 uint8_t prev;
7653
7654 if (handle == NULL) /* check handle */
7655 {
7656 return 2; /* return error */
7657 }
7658 if (handle->inited != 1) /* check handle initialization */
7659 {
7660 return 3; /* return error */
7661 }
7662
7663 res = a_mpu6500_read(handle, MPU6500_REG_INT_ENABLE, (uint8_t *)&prev, 1); /* read interrupt enable */
7664 if (res != 0) /* check result */
7665 {
7666 handle->debug_print("mpu6500: read interrupt enable failed.\n"); /* read interrupt enable failed */
7667
7668 return 1; /* return error */
7669 }
7670 *enable = (mpu6500_bool_t)((prev >> type) & 0x01); /* get the bool */
7671
7672 return 0; /* success return 0 */
7673}
7674
7686uint8_t mpu6500_get_interrupt_status(mpu6500_handle_t *handle, uint8_t *status)
7687{
7688 uint8_t res;
7689
7690 if (handle == NULL) /* check handle */
7691 {
7692 return 2; /* return error */
7693 }
7694 if (handle->inited != 1) /* check handle initialization */
7695 {
7696 return 3; /* return error */
7697 }
7698
7699 res = a_mpu6500_read(handle, MPU6500_REG_INT_STATUS, (uint8_t *)status, 1); /* read interrupt status */
7700 if (res != 0) /* check result */
7701 {
7702 handle->debug_print("mpu6500: read interrupt status failed.\n"); /* read interrupt status failed */
7703
7704 return 1; /* return error */
7705 }
7706
7707 return 0; /* success return 0 */
7708}
7709
7722{
7723 uint8_t res;
7724
7725 if (handle == NULL) /* check handle */
7726 {
7727 return 2; /* return error */
7728 }
7729 if (handle->inited != 1) /* check handle initialization */
7730 {
7731 return 3; /* return error */
7732 }
7733
7734 res = a_mpu6500_write(handle, MPU6500_REG_SELF_TEST_X_GYRO, (uint8_t *)&data, 1); /* write self test x */
7735 if (res != 0) /* check result */
7736 {
7737 handle->debug_print("mpu6500: write self test x failed.\n"); /* write self test x failed */
7738
7739 return 1; /* return error */
7740 }
7741
7742 return 0; /* success return 0 */
7743}
7744
7756uint8_t mpu6500_get_gyroscope_x_test(mpu6500_handle_t *handle, uint8_t *data)
7757{
7758 uint8_t res;
7759
7760 if (handle == NULL) /* check handle */
7761 {
7762 return 2; /* return error */
7763 }
7764 if (handle->inited != 1) /* check handle initialization */
7765 {
7766 return 3; /* return error */
7767 }
7768
7769 res = a_mpu6500_read(handle, MPU6500_REG_SELF_TEST_X_GYRO, (uint8_t *)data, 1); /* read self test x */
7770 if (res != 0) /* check result */
7771 {
7772 handle->debug_print("mpu6500: read self test x failed.\n"); /* read self test x failed */
7773
7774 return 1; /* return error */
7775 }
7776
7777 return 0; /* success return 0 */
7778}
7779
7792{
7793 uint8_t res;
7794
7795 if (handle == NULL) /* check handle */
7796 {
7797 return 2; /* return error */
7798 }
7799 if (handle->inited != 1) /* check handle initialization */
7800 {
7801 return 3; /* return error */
7802 }
7803
7804 res = a_mpu6500_write(handle, MPU6500_REG_SELF_TEST_Y_GYRO, (uint8_t *)&data, 1); /* write self test y */
7805 if (res != 0) /* check result */
7806 {
7807 handle->debug_print("mpu6500: write self test y failed.\n"); /* write self test y failed */
7808
7809 return 1; /* return error */
7810 }
7811
7812 return 0; /* success return 0 */
7813}
7814
7826uint8_t mpu6500_get_gyroscope_y_test(mpu6500_handle_t *handle, uint8_t *data)
7827{
7828 uint8_t res;
7829
7830 if (handle == NULL) /* check handle */
7831 {
7832 return 2; /* return error */
7833 }
7834 if (handle->inited != 1) /* check handle initialization */
7835 {
7836 return 3; /* return error */
7837 }
7838
7839 res = a_mpu6500_read(handle, MPU6500_REG_SELF_TEST_Y_GYRO, (uint8_t *)data, 1); /* read self test y */
7840 if (res != 0) /* check result */
7841 {
7842 handle->debug_print("mpu6500: read self test y failed.\n"); /* read self test y failed */
7843
7844 return 1; /* return error */
7845 }
7846
7847 return 0; /* success return 0 */
7848}
7849
7862{
7863 uint8_t res;
7864
7865 if (handle == NULL) /* check handle */
7866 {
7867 return 2; /* return error */
7868 }
7869 if (handle->inited != 1) /* check handle initialization */
7870 {
7871 return 3; /* return error */
7872 }
7873
7874 res = a_mpu6500_write(handle, MPU6500_REG_SELF_TEST_Z_GYRO, (uint8_t *)&data, 1); /* write self test z */
7875 if (res != 0) /* check result */
7876 {
7877 handle->debug_print("mpu6500: write self test z failed.\n"); /* write self test z failed */
7878
7879 return 1; /* return error */
7880 }
7881
7882 return 0; /* success return 0 */
7883}
7884
7896uint8_t mpu6500_get_gyroscope_z_test(mpu6500_handle_t *handle, uint8_t *data)
7897{
7898 uint8_t res;
7899
7900 if (handle == NULL) /* check handle */
7901 {
7902 return 2; /* return error */
7903 }
7904 if (handle->inited != 1) /* check handle initialization */
7905 {
7906 return 3; /* return error */
7907 }
7908
7909 res = a_mpu6500_read(handle, MPU6500_REG_SELF_TEST_Z_GYRO, (uint8_t *)data, 1); /* read self test z */
7910 if (res != 0) /* check result */
7911 {
7912 handle->debug_print("mpu6500: read self test z failed.\n"); /* read self test z failed */
7913
7914 return 1; /* return error */
7915 }
7916
7917 return 0; /* success return 0 */
7918}
7919
7932{
7933 uint8_t res;
7934
7935 if (handle == NULL) /* check handle */
7936 {
7937 return 2; /* return error */
7938 }
7939 if (handle->inited != 1) /* check handle initialization */
7940 {
7941 return 3; /* return error */
7942 }
7943
7944 res = a_mpu6500_write(handle, MPU6500_REG_SELF_TEST_X_ACCEL, (uint8_t *)&data, 1); /* write self test x */
7945 if (res != 0) /* check result */
7946 {
7947 handle->debug_print("mpu6500: write self test x failed.\n"); /* write self test x failed */
7948
7949 return 1; /* return error */
7950 }
7951
7952 return 0; /* success return 0 */
7953}
7954
7967{
7968 uint8_t res;
7969
7970 if (handle == NULL) /* check handle */
7971 {
7972 return 2; /* return error */
7973 }
7974 if (handle->inited != 1) /* check handle initialization */
7975 {
7976 return 3; /* return error */
7977 }
7978
7979 res = a_mpu6500_read(handle, MPU6500_REG_SELF_TEST_X_ACCEL, (uint8_t *)data, 1); /* read self test x */
7980 if (res != 0) /* check result */
7981 {
7982 handle->debug_print("mpu6500: read self test x failed.\n"); /* read self test x failed */
7983
7984 return 1; /* return error */
7985 }
7986
7987 return 0; /* success return 0 */
7988}
7989
8002{
8003 uint8_t res;
8004
8005 if (handle == NULL) /* check handle */
8006 {
8007 return 2; /* return error */
8008 }
8009 if (handle->inited != 1) /* check handle initialization */
8010 {
8011 return 3; /* return error */
8012 }
8013
8014 res = a_mpu6500_write(handle, MPU6500_REG_SELF_TEST_Y_ACCEL, (uint8_t *)&data, 1); /* write self test y */
8015 if (res != 0) /* check result */
8016 {
8017 handle->debug_print("mpu6500: write self test y failed.\n"); /* write self test y failed */
8018
8019 return 1; /* return error */
8020 }
8021
8022 return 0; /* success return 0 */
8023}
8024
8037{
8038 uint8_t res;
8039
8040 if (handle == NULL) /* check handle */
8041 {
8042 return 2; /* return error */
8043 }
8044 if (handle->inited != 1) /* check handle initialization */
8045 {
8046 return 3; /* return error */
8047 }
8048
8049 res = a_mpu6500_read(handle, MPU6500_REG_SELF_TEST_Y_ACCEL, (uint8_t *)data, 1); /* read self test y */
8050 if (res != 0) /* check result */
8051 {
8052 handle->debug_print("mpu6500: read self test y failed.\n"); /* read self test y failed */
8053
8054 return 1; /* return error */
8055 }
8056
8057 return 0; /* success return 0 */
8058}
8059
8072{
8073 uint8_t res;
8074
8075 if (handle == NULL) /* check handle */
8076 {
8077 return 2; /* return error */
8078 }
8079 if (handle->inited != 1) /* check handle initialization */
8080 {
8081 return 3; /* return error */
8082 }
8083
8084 res = a_mpu6500_write(handle, MPU6500_REG_SELF_TEST_Z_ACCEL, (uint8_t *)&data, 1); /* write self test z */
8085 if (res != 0) /* check result */
8086 {
8087 handle->debug_print("mpu6500: write self test z failed.\n"); /* write self test z failed */
8088
8089 return 1; /* return error */
8090 }
8091
8092 return 0; /* success return 0 */
8093}
8094
8107{
8108 uint8_t res;
8109
8110 if (handle == NULL) /* check handle */
8111 {
8112 return 2; /* return error */
8113 }
8114 if (handle->inited != 1) /* check handle initialization */
8115 {
8116 return 3; /* return error */
8117 }
8118
8119 res = a_mpu6500_read(handle, MPU6500_REG_SELF_TEST_Z_ACCEL, (uint8_t *)data, 1); /* read self test z */
8120 if (res != 0) /* check result */
8121 {
8122 handle->debug_print("mpu6500: read self test z failed.\n"); /* read self test z failed */
8123
8124 return 1; /* return error */
8125 }
8126
8127 return 0; /* success return 0 */
8128}
8129
8142{
8143 uint8_t res;
8144 uint8_t buf[2];
8145
8146 if (handle == NULL) /* check handle */
8147 {
8148 return 2; /* return error */
8149 }
8150 if (handle->inited != 1) /* check handle initialization */
8151 {
8152 return 3; /* return error */
8153 }
8154
8155 buf[0] = (offset >> 8) & 0xFF; /* set high */
8156 buf[1] = (offset >> 0) & 0xFF; /* set low */
8157 res = a_mpu6500_write(handle, MPU6500_REG_XA_OFFSET_H, buf, 2); /* write xa offset */
8158 if (res != 0) /* check result */
8159 {
8160 handle->debug_print("mpu6500: write xa offset failed.\n"); /* write xa offset failed*/
8161
8162 return 1; /* return error */
8163 }
8164
8165 return 0; /* success return 0 */
8166}
8167
8180{
8181 uint8_t res;
8182 uint8_t buf[2];
8183
8184 if (handle == NULL) /* check handle */
8185 {
8186 return 2; /* return error */
8187 }
8188 if (handle->inited != 1) /* check handle initialization */
8189 {
8190 return 3; /* return error */
8191 }
8192
8193 res = a_mpu6500_read(handle, MPU6500_REG_XA_OFFSET_H, buf, 2); /* read xa offset */
8194 if (res != 0) /* check result */
8195 {
8196 handle->debug_print("mpu6500: read xa offset failed.\n"); /* read xa offset failed*/
8197
8198 return 1; /* return error */
8199 }
8200 *offset = (int16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set the offset */
8201
8202 return 0; /* success return 0 */
8203}
8204
8217{
8218 uint8_t res;
8219 uint8_t buf[2];
8220
8221 if (handle == NULL) /* check handle */
8222 {
8223 return 2; /* return error */
8224 }
8225 if (handle->inited != 1) /* check handle initialization */
8226 {
8227 return 3; /* return error */
8228 }
8229
8230 buf[0] = (offset >> 8) & 0xFF; /* set high */
8231 buf[1] = (offset >> 0) & 0xFF; /* set low */
8232 res = a_mpu6500_write(handle, MPU6500_REG_YA_OFFSET_H, buf, 2); /* write ya offset */
8233 if (res != 0) /* check result */
8234 {
8235 handle->debug_print("mpu6500: write ya offset failed.\n"); /* write ya offset failed*/
8236
8237 return 1; /* return error */
8238 }
8239
8240 return 0; /* success return 0 */
8241}
8242
8255{
8256 uint8_t res;
8257 uint8_t buf[2];
8258
8259 if (handle == NULL) /* check handle */
8260 {
8261 return 2; /* return error */
8262 }
8263 if (handle->inited != 1) /* check handle initialization */
8264 {
8265 return 3; /* return error */
8266 }
8267
8268 res = a_mpu6500_read(handle, MPU6500_REG_YA_OFFSET_H, buf, 2); /* read ya offset */
8269 if (res != 0) /* check result */
8270 {
8271 handle->debug_print("mpu6500: read ya offset failed.\n"); /* read ya offset failed*/
8272
8273 return 1; /* return error */
8274 }
8275 *offset = (int16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set the offset */
8276
8277 return 0; /* success return 0 */
8278}
8279
8292{
8293 uint8_t res;
8294 uint8_t buf[2];
8295
8296 if (handle == NULL) /* check handle */
8297 {
8298 return 2; /* return error */
8299 }
8300 if (handle->inited != 1) /* check handle initialization */
8301 {
8302 return 3; /* return error */
8303 }
8304
8305 buf[0] = (offset >> 8) & 0xFF; /* set high */
8306 buf[1] = (offset >> 0) & 0xFF; /* set low */
8307 res = a_mpu6500_write(handle, MPU6500_REG_ZA_OFFSET_H, buf, 2); /* write za offset */
8308 if (res != 0) /* check result */
8309 {
8310 handle->debug_print("mpu6500: write za offset failed.\n"); /* write za offset failed*/
8311
8312 return 1; /* return error */
8313 }
8314
8315 return 0; /* success return 0 */
8316}
8317
8330{
8331 uint8_t res;
8332 uint8_t buf[2];
8333
8334 if (handle == NULL) /* check handle */
8335 {
8336 return 2; /* return error */
8337 }
8338 if (handle->inited != 1) /* check handle initialization */
8339 {
8340 return 3; /* return error */
8341 }
8342
8343 res = a_mpu6500_read(handle, MPU6500_REG_ZA_OFFSET_H, buf, 2); /* read za offset */
8344 if (res != 0) /* check result */
8345 {
8346 handle->debug_print("mpu6500: read za offset failed.\n"); /* read za offset failed*/
8347
8348 return 1; /* return error */
8349 }
8350 *offset = (int16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set the offset */
8351
8352 return 0; /* success return 0 */
8353}
8354
8367{
8368 if (handle == NULL) /* check handle */
8369 {
8370 return 2; /* return error */
8371 }
8372 if (handle->inited != 1) /* check handle initialization */
8373 {
8374 return 3; /* return error */
8375 }
8376
8377 *reg = (int16_t)(mg / 0.98f); /* convert real data to register data */
8378
8379 return 0; /* success return 0 */
8380}
8381
8394{
8395 if (handle == NULL) /* check handle */
8396 {
8397 return 2; /* return error */
8398 }
8399 if (handle->inited != 1) /* check handle initialization */
8400 {
8401 return 3; /* return error */
8402 }
8403
8404 *mg = (float)(reg) * 0.98f; /* convert raw data to real data */
8405
8406 return 0; /* success return 0 */
8407}
8408
8420uint8_t mpu6500_set_gyro_x_offset(mpu6500_handle_t *handle, int16_t offset)
8421{
8422 uint8_t res;
8423 uint8_t buf[2];
8424
8425 if (handle == NULL) /* check handle */
8426 {
8427 return 2; /* return error */
8428 }
8429 if (handle->inited != 1) /* check handle initialization */
8430 {
8431 return 3; /* return error */
8432 }
8433
8434 buf[0] = (offset >> 8) & 0xFF; /* set high */
8435 buf[1] = (offset >> 0) & 0xFF; /* set low */
8436 res = a_mpu6500_write(handle, MPU6500_REG_XG_OFFSET_H, buf, 2); /* write xg offset */
8437 if (res != 0) /* check result */
8438 {
8439 handle->debug_print("mpu6500: write xg offset failed.\n"); /* write xg offset failed*/
8440
8441 return 1; /* return error */
8442 }
8443
8444 return 0; /* success return 0 */
8445}
8446
8458uint8_t mpu6500_get_gyro_x_offset(mpu6500_handle_t *handle, int16_t *offset)
8459{
8460 uint8_t res;
8461 uint8_t buf[2];
8462
8463 if (handle == NULL) /* check handle */
8464 {
8465 return 2; /* return error */
8466 }
8467 if (handle->inited != 1) /* check handle initialization */
8468 {
8469 return 3; /* return error */
8470 }
8471
8472 res = a_mpu6500_read(handle, MPU6500_REG_XG_OFFSET_H, buf, 2); /* read xg offset */
8473 if (res != 0) /* check result */
8474 {
8475 handle->debug_print("mpu6500: read xg offset failed.\n"); /* read xg offset failed*/
8476
8477 return 1; /* return error */
8478 }
8479 *offset = (int16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set the offset */
8480
8481 return 0; /* success return 0 */
8482}
8483
8495uint8_t mpu6500_set_gyro_y_offset(mpu6500_handle_t *handle, int16_t offset)
8496{
8497 uint8_t res;
8498 uint8_t buf[2];
8499
8500 if (handle == NULL) /* check handle */
8501 {
8502 return 2; /* return error */
8503 }
8504 if (handle->inited != 1) /* check handle initialization */
8505 {
8506 return 3; /* return error */
8507 }
8508
8509 buf[0] = (offset >> 8) & 0xFF; /* set high */
8510 buf[1] = (offset >> 0) & 0xFF; /* set low */
8511 res = a_mpu6500_write(handle, MPU6500_REG_YG_OFFSET_H, buf, 2); /* write yg offset */
8512 if (res != 0) /* check result */
8513 {
8514 handle->debug_print("mpu6500: write yg offset failed.\n"); /* write yg offset failed*/
8515
8516 return 1; /* return error */
8517 }
8518
8519 return 0; /* success return 0 */
8520}
8521
8533uint8_t mpu6500_get_gyro_y_offset(mpu6500_handle_t *handle, int16_t *offset)
8534{
8535 uint8_t res;
8536 uint8_t buf[2];
8537
8538 if (handle == NULL) /* check handle */
8539 {
8540 return 2; /* return error */
8541 }
8542 if (handle->inited != 1) /* check handle initialization */
8543 {
8544 return 3; /* return error */
8545 }
8546
8547 res = a_mpu6500_read(handle, MPU6500_REG_YG_OFFSET_H, buf, 2); /* read yg offset */
8548 if (res != 0) /* check result */
8549 {
8550 handle->debug_print("mpu6500: read yg offset failed.\n"); /* read yg offset failed*/
8551
8552 return 1; /* return error */
8553 }
8554 *offset = (int16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set the offset */
8555
8556 return 0; /* success return 0 */
8557}
8558
8570uint8_t mpu6500_set_gyro_z_offset(mpu6500_handle_t *handle, int16_t offset)
8571{
8572 uint8_t res;
8573 uint8_t buf[2];
8574
8575 if (handle == NULL) /* check handle */
8576 {
8577 return 2; /* return error */
8578 }
8579 if (handle->inited != 1) /* check handle initialization */
8580 {
8581 return 3; /* return error */
8582 }
8583
8584 buf[0] = (offset >> 8) & 0xFF; /* set high */
8585 buf[1] = (offset >> 0) & 0xFF; /* set low */
8586 res = a_mpu6500_write(handle, MPU6500_REG_ZG_OFFSET_H, buf, 2); /* write zg offset */
8587 if (res != 0) /* check result */
8588 {
8589 handle->debug_print("mpu6500: write zg offset failed.\n"); /* write zg offset failed*/
8590
8591 return 1; /* return error */
8592 }
8593
8594 return 0; /* success return 0 */
8595}
8596
8608uint8_t mpu6500_get_gyro_z_offset(mpu6500_handle_t *handle, int16_t *offset)
8609{
8610 uint8_t res;
8611 uint8_t buf[2];
8612
8613 if (handle == NULL) /* check handle */
8614 {
8615 return 2; /* return error */
8616 }
8617 if (handle->inited != 1) /* check handle initialization */
8618 {
8619 return 3; /* return error */
8620 }
8621
8622 res = a_mpu6500_read(handle, MPU6500_REG_ZG_OFFSET_H, buf, 2); /* read zg offset */
8623 if (res != 0) /* check result */
8624 {
8625 handle->debug_print("mpu6500: read zg offset failed.\n"); /* read zg offset failed*/
8626
8627 return 1; /* return error */
8628 }
8629 *offset = (int16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set the offset */
8630
8631 return 0; /* success return 0 */
8632}
8633
8645uint8_t mpu6500_gyro_offset_convert_to_register(mpu6500_handle_t *handle, float dps, int16_t *reg)
8646{
8647 if (handle == NULL) /* check handle */
8648 {
8649 return 2; /* return error */
8650 }
8651 if (handle->inited != 1) /* check handle initialization */
8652 {
8653 return 3; /* return error */
8654 }
8655
8656 *reg = (int16_t)(dps / 0.0305f); /* convert real data to register data */
8657
8658 return 0; /* success return 0 */
8659}
8660
8672uint8_t mpu6500_gyro_offset_convert_to_data(mpu6500_handle_t *handle, int16_t reg, float *dps)
8673{
8674 if (handle == NULL) /* check handle */
8675 {
8676 return 2; /* return error */
8677 }
8678 if (handle->inited != 1) /* check handle initialization */
8679 {
8680 return 3; /* return error */
8681 }
8682
8683 *dps = (float)(reg) * 0.0305f; /* convert raw data to real data */
8684
8685 return 0; /* success return 0 */
8686}
8687
8699uint8_t mpu6500_set_motion_threshold(mpu6500_handle_t *handle, uint8_t threshold)
8700{
8701 uint8_t res;
8702
8703 if (handle == NULL) /* check handle */
8704 {
8705 return 2; /* return error */
8706 }
8707 if (handle->inited != 1) /* check handle initialization */
8708 {
8709 return 3; /* return error */
8710 }
8711
8712 res = a_mpu6500_write(handle, MPU6500_REG_WOM_THR, (uint8_t *)&threshold, 1); /* write motion threshold */
8713 if (res != 0) /* check result */
8714 {
8715 handle->debug_print("mpu6500: write motion threshold failed.\n"); /* write motion threshold failed*/
8716
8717 return 1; /* return error */
8718 }
8719
8720 return 0; /* success return 0 */
8721}
8722
8734uint8_t mpu6500_get_motion_threshold(mpu6500_handle_t *handle, uint8_t *threshold)
8735{
8736 uint8_t res;
8737
8738 if (handle == NULL) /* check handle */
8739 {
8740 return 2; /* return error */
8741 }
8742 if (handle->inited != 1) /* check handle initialization */
8743 {
8744 return 3; /* return error */
8745 }
8746
8747 res = a_mpu6500_read(handle, MPU6500_REG_WOM_THR, (uint8_t *)threshold, 1); /* read motion threshold */
8748 if (res != 0) /* check result */
8749 {
8750 handle->debug_print("mpu6500: read motion threshold failed.\n"); /* read motion threshold failed*/
8751
8752 return 1; /* return error */
8753 }
8754
8755 return 0; /* success return 0 */
8756}
8757
8770{
8771 if (handle == NULL) /* check handle */
8772 {
8773 return 2; /* return error */
8774 }
8775 if (handle->inited != 1) /* check handle initialization */
8776 {
8777 return 3; /* return error */
8778 }
8779
8780 *reg = (uint8_t)(mg / 4.0f); /* convert real data to register data */
8781
8782 return 0; /* success return 0 */
8783}
8784
8796uint8_t mpu6500_motion_threshold_convert_to_data(mpu6500_handle_t *handle, uint8_t reg, float *mg)
8797{
8798 if (handle == NULL) /* check handle */
8799 {
8800 return 2; /* return error */
8801 }
8802 if (handle->inited != 1) /* check handle initialization */
8803 {
8804 return 3; /* return error */
8805 }
8806
8807 *mg = (float)(reg) * 4.0f; /* convert raw data to real data */
8808
8809 return 0; /* success return 0 */
8810}
8811
8824uint8_t mpu6500_self_test(mpu6500_handle_t *handle, int32_t gyro_offset_raw[3], int32_t accel_offset_raw[3])
8825{
8826 uint8_t res;
8827 uint8_t prev;
8828 int32_t gyro_offset_raw_st[3];
8829 int32_t accel_offset_raw_st[3];
8830
8831 if (handle == NULL) /* check handle */
8832 {
8833 return 2; /* return error */
8834 }
8835 if (handle->inited != 1) /* check handle initialization */
8836 {
8837 return 3; /* return error */
8838 }
8839
8840 res = a_mpu6500_get_st_biases(handle, gyro_offset_raw, accel_offset_raw, 0); /* get st biases */
8841 if (res != 0) /* check result */
8842 {
8843 handle->debug_print("mpu6500: get st biases failed.\n"); /* get st biases failed */
8844
8845 return 1; /* return error */
8846 }
8847 res = a_mpu6500_get_st_biases(handle, gyro_offset_raw_st, accel_offset_raw_st, 1); /* get st biases */
8848 if (res != 0) /* check result */
8849 {
8850 handle->debug_print("mpu6500: get st biases failed.\n"); /* get st biases failed */
8851
8852 return 1; /* return error */
8853 }
8854 res = a_mpu6500_accel_self_test(handle, accel_offset_raw, accel_offset_raw_st); /* accel self test */
8855 if (res != 0) /* check result */
8856 {
8857 handle->debug_print("mpu6500: accel self test failed.\n"); /* accel self test failed */
8858
8859 return 1; /* return error */
8860 }
8861 res = a_mpu6500_gyro_self_test(handle, gyro_offset_raw, gyro_offset_raw_st); /* gyro self test */
8862 if (res != 0) /* check result */
8863 {
8864 handle->debug_print("mpu6500: gyro self test failed.\n"); /* gyro self test failed */
8865
8866 return 1; /* return error */
8867 }
8868
8869 prev = 1 << 7; /* reset the device */
8870 res = a_mpu6500_write(handle, MPU6500_REG_PWR_MGMT_1, &prev, 1); /* write pwr mgmt 1 */
8871 if (res != 0) /* check the result */
8872 {
8873 handle->debug_print("mpu6500: write pwr mgmt 1 failed.\n"); /* write pwr mgmt 1 failed */
8874
8875 return 1; /* return error */
8876 }
8877 handle->delay_ms(100); /* delay 100ms */
8878 res = a_mpu6500_read(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
8879 if (res != 0) /* check result */
8880 {
8881 handle->debug_print("mpu6500: read power management 1 failed.\n"); /* read power management 1 failed */
8882
8883 return 1; /* return error */
8884 }
8885 prev &= ~(1 << 6); /* clear config */
8886 res = a_mpu6500_write(handle, MPU6500_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
8887 if (res != 0) /* check result */
8888 {
8889 handle->debug_print("mpu6500: write power management 1 failed.\n"); /* write power management 1 failed */
8890
8891 return 1; /* return error */
8892 }
8893
8894 return 0; /* success return 0 */
8895}
8896
8909{
8910 uint8_t res;
8911 uint8_t prev;
8912
8913 if (handle == NULL) /* check handle */
8914 {
8915 return 2; /* return error */
8916 }
8917 if (handle->inited != 1) /* check handle initialization */
8918 {
8919 return 3; /* return error */
8920 }
8921
8922 res = a_mpu6500_read(handle, MPU6500_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
8923 if (res != 0) /* check result */
8924 {
8925 handle->debug_print("mpu6500: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
8926
8927 return 1; /* return error */
8928 }
8929 prev &= ~0xF; /* clear the buffer */
8930 prev |= clk; /* set the clock */
8931 res = a_mpu6500_write(handle, MPU6500_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* write i2c mst ctrl */
8932 if (res != 0) /* check result */
8933 {
8934 handle->debug_print("mpu6500: write i2c mst ctrl failed.\n"); /* write i2c mst ctrl failed */
8935
8936 return 1; /* return error */
8937 }
8938
8939 return 0; /* success return 0 */
8940}
8941
8954{
8955 uint8_t res;
8956 uint8_t prev;
8957
8958 if (handle == NULL) /* check handle */
8959 {
8960 return 2; /* return error */
8961 }
8962 if (handle->inited != 1) /* check handle initialization */
8963 {
8964 return 3; /* return error */
8965 }
8966
8967 res = a_mpu6500_read(handle, MPU6500_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
8968 if (res != 0) /* check result */
8969 {
8970 handle->debug_print("mpu6500: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
8971
8972 return 1; /* return error */
8973 }
8974 *clk = (mpu6500_iic_clock_t)(prev & 0x0F); /* get the clock */
8975
8976 return 0; /* success return 0 */
8977}
8978
8991{
8992 uint8_t res;
8993 uint8_t prev;
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_mpu6500_read(handle, MPU6500_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
9005 if (res != 0) /* check result */
9006 {
9007 handle->debug_print("mpu6500: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
9008
9009 return 1; /* return error */
9010 }
9011 prev &= ~(1 << 7); /* clear the settings */
9012 prev |= enable << 7; /* set the bool */
9013 res = a_mpu6500_write(handle, MPU6500_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* write i2c mst ctrl */
9014 if (res != 0) /* check result */
9015 {
9016 handle->debug_print("mpu6500: write i2c mst ctrl failed.\n"); /* write i2c mst ctrl failed */
9017
9018 return 1; /* return error */
9019 }
9020
9021 return 0; /* success return 0 */
9022}
9023
9036{
9037 uint8_t res;
9038 uint8_t prev;
9039
9040 if (handle == NULL) /* check handle */
9041 {
9042 return 2; /* return error */
9043 }
9044 if (handle->inited != 1) /* check handle initialization */
9045 {
9046 return 3; /* return error */
9047 }
9048
9049 res = a_mpu6500_read(handle, MPU6500_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
9050 if (res != 0) /* check result */
9051 {
9052 handle->debug_print("mpu6500: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
9053
9054 return 1; /* return error */
9055 }
9056 *enable = (mpu6500_bool_t)((prev >> 7) & 0x1); /* get the bool */
9057
9058 return 0; /* success return 0 */
9059}
9060
9073{
9074 uint8_t res;
9075 uint8_t prev;
9076
9077 if (handle == NULL) /* check handle */
9078 {
9079 return 2; /* return error */
9080 }
9081 if (handle->inited != 1) /* check handle initialization */
9082 {
9083 return 3; /* return error */
9084 }
9085
9086 res = a_mpu6500_read(handle, MPU6500_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
9087 if (res != 0) /* check result */
9088 {
9089 handle->debug_print("mpu6500: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
9090
9091 return 1; /* return error */
9092 }
9093 prev &= ~(1 << 6); /* clear the settings */
9094 prev |= enable << 6; /* set the bool */
9095 res = a_mpu6500_write(handle, MPU6500_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* write i2c mst ctrl */
9096 if (res != 0) /* check result */
9097 {
9098 handle->debug_print("mpu6500: write i2c mst ctrl failed.\n"); /* write i2c mst ctrl failed */
9099
9100 return 1; /* return error */
9101 }
9102
9103 return 0; /* success return 0 */
9104}
9105
9118{
9119 uint8_t res;
9120 uint8_t prev;
9121
9122 if (handle == NULL) /* check handle */
9123 {
9124 return 2; /* return error */
9125 }
9126 if (handle->inited != 1) /* check handle initialization */
9127 {
9128 return 3; /* return error */
9129 }
9130
9131 res = a_mpu6500_read(handle, MPU6500_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
9132 if (res != 0) /* check result */
9133 {
9134 handle->debug_print("mpu6500: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
9135
9136 return 1; /* return error */
9137 }
9138 *enable = (mpu6500_bool_t)((prev >> 6) & 0x1); /* get the bool */
9139
9140 return 0; /* success return 0 */
9141}
9142
9155{
9156 uint8_t res;
9157 uint8_t prev;
9158
9159 if (handle == NULL) /* check handle */
9160 {
9161 return 2; /* return error */
9162 }
9163 if (handle->inited != 1) /* check handle initialization */
9164 {
9165 return 3; /* return error */
9166 }
9167
9168 res = a_mpu6500_read(handle, MPU6500_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
9169 if (res != 0) /* check result */
9170 {
9171 handle->debug_print("mpu6500: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
9172
9173 return 1; /* return error */
9174 }
9175 prev &= ~(1 << 4); /* clear the settings */
9176 prev |= mode << 4; /* set the mode */
9177 res = a_mpu6500_write(handle, MPU6500_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* write i2c mst ctrl */
9178 if (res != 0) /* check result */
9179 {
9180 handle->debug_print("mpu6500: write i2c mst ctrl failed.\n"); /* write i2c mst ctrl failed */
9181
9182 return 1; /* return error */
9183 }
9184
9185 return 0; /* success return 0 */
9186}
9187
9200{
9201 uint8_t res;
9202 uint8_t prev;
9203
9204 if (handle == NULL) /* check handle */
9205 {
9206 return 2; /* return error */
9207 }
9208 if (handle->inited != 1) /* check handle initialization */
9209 {
9210 return 3; /* return error */
9211 }
9212
9213 res = a_mpu6500_read(handle, MPU6500_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
9214 if (res != 0) /* check result */
9215 {
9216 handle->debug_print("mpu6500: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
9217
9218 return 1; /* return error */
9219 }
9220 *mode = (mpu6500_iic_read_mode_t)((prev >> 4) & 0x1); /* get the mode */
9221
9222 return 0; /* success return 0 */
9223}
9224
9239{
9240 uint8_t res;
9241 uint8_t prev;
9242
9243 if (handle == NULL) /* check handle */
9244 {
9245 return 2; /* return error */
9246 }
9247 if (handle->inited != 1) /* check handle initialization */
9248 {
9249 return 3; /* return error */
9250 }
9251
9252 if ((slave == MPU6500_IIC_SLAVE_0) ||
9253 (slave == MPU6500_IIC_SLAVE_1) ||
9254 (slave == MPU6500_IIC_SLAVE_2)
9255 ) /* slave0-2 */
9256 {
9257 res = a_mpu6500_read(handle, MPU6500_REG_FIFO_EN, (uint8_t *)&prev, 1); /* read fifo enable */
9258 if (res != 0) /* check result */
9259 {
9260 handle->debug_print("mpu6500: read fifo enable failed.\n"); /* read fifo enable failed */
9261
9262 return 1; /* return error */
9263 }
9264 prev &= ~(1 << slave); /* clear the settings */
9265 prev |= enable << slave; /* set the bool */
9266 res = a_mpu6500_write(handle, MPU6500_REG_FIFO_EN, (uint8_t *)&prev, 1); /* write fifo enable ctrl */
9267 if (res != 0) /* check result */
9268 {
9269 handle->debug_print("mpu6500: write fifo enable failed.\n"); /* write fifo enable failed */
9270
9271 return 1; /* return error */
9272 }
9273 }
9274 else if (slave == MPU6500_IIC_SLAVE_3) /* slave3 */
9275 {
9276 res = a_mpu6500_read(handle, MPU6500_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
9277 if (res != 0) /* check result */
9278 {
9279 handle->debug_print("mpu6500: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
9280
9281 return 1; /* return error */
9282 }
9283 prev &= ~(1 << 5); /* clear the settings */
9284 prev |= enable << 5; /* set the bool */
9285 res = a_mpu6500_write(handle, MPU6500_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* write i2c mst ctrl */
9286 if (res != 0) /* check result */
9287 {
9288 handle->debug_print("mpu6500: write i2c mst ctrl failed.\n"); /* write i2c mst ctrl failed */
9289
9290 return 1; /* return error */
9291 }
9292 }
9293 else
9294 {
9295 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
9296
9297 return 4; /* return error */
9298 }
9299
9300 return 0; /* success return 0 */
9301}
9302
9317{
9318 uint8_t res;
9319 uint8_t prev;
9320
9321 if (handle == NULL) /* check handle */
9322 {
9323 return 2; /* return error */
9324 }
9325 if (handle->inited != 1) /* check handle initialization */
9326 {
9327 return 3; /* return error */
9328 }
9329
9330 if ((slave == MPU6500_IIC_SLAVE_0) ||
9331 (slave == MPU6500_IIC_SLAVE_1) ||
9332 (slave == MPU6500_IIC_SLAVE_2)
9333 ) /* slave0-2 */
9334 {
9335 res = a_mpu6500_read(handle, MPU6500_REG_FIFO_EN, (uint8_t *)&prev, 1); /* read fifo enable */
9336 if (res != 0) /* check result */
9337 {
9338 handle->debug_print("mpu6500: read fifo enable failed.\n"); /* read fifo enable failed */
9339
9340 return 1; /* return error */
9341 }
9342 *enable = (mpu6500_bool_t)((prev >> slave) & 0x1); /* get the bool */
9343 }
9344 else if (slave == MPU6500_IIC_SLAVE_3) /* slave3 */
9345 {
9346 res = a_mpu6500_read(handle, MPU6500_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
9347 if (res != 0) /* check result */
9348 {
9349 handle->debug_print("mpu6500: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
9350
9351 return 1; /* return error */
9352 }
9353 *enable = (mpu6500_bool_t)((prev >> 5) & 0x01); /* get the bool */
9354 }
9355 else
9356 {
9357 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
9358
9359 return 4; /* return error */
9360 }
9361
9362 return 0; /* success return 0 */
9363}
9364
9379{
9380 uint8_t res;
9381 uint8_t prev;
9382
9383 if (handle == NULL) /* check handle */
9384 {
9385 return 2; /* return error */
9386 }
9387 if (handle->inited != 1) /* check handle initialization */
9388 {
9389 return 3; /* return error */
9390 }
9391
9392 if (slave == MPU6500_IIC_SLAVE_0) /* slave0 */
9393 {
9394 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* read i2c slv0 addr */
9395 if (res != 0) /* check result */
9396 {
9397 handle->debug_print("mpu6500: read i2c slv0 addr failed.\n"); /* read i2c slv0 addr failed */
9398
9399 return 1; /* return error */
9400 }
9401 prev &= ~(1 << 7); /* clear the settings */
9402 prev |= mode << 7; /* set the bool */
9403 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* write i2c slv0 addr */
9404 if (res != 0) /* check result */
9405 {
9406 handle->debug_print("mpu6500: write i2c slv0 addr failed.\n"); /* write i2c slv0 addr failed */
9407
9408 return 1; /* return error */
9409 }
9410 }
9411 else if (slave == MPU6500_IIC_SLAVE_1) /* slave1 */
9412 {
9413 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV1_ADDR, (uint8_t *)&prev, 1); /* read i2c slv1 addr */
9414 if (res != 0) /* check result */
9415 {
9416 handle->debug_print("mpu6500: read i2c slv1 addr failed.\n"); /* read i2c slv1 addr failed */
9417
9418 return 1; /* return error */
9419 }
9420 prev &= ~(1 << 7); /* clear the settings */
9421 prev |= mode << 7; /* set the bool */
9422 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV1_ADDR, (uint8_t *)&prev, 1); /* write i2c slv1 addr */
9423 if (res != 0) /* check result */
9424 {
9425 handle->debug_print("mpu6500: write i2c slv1 addr failed.\n"); /* write i2c slv1 addr failed */
9426
9427 return 1; /* return error */
9428 }
9429 }
9430 else if (slave == MPU6500_IIC_SLAVE_2) /* slave2 */
9431 {
9432 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV2_ADDR, (uint8_t *)&prev, 1); /* read i2c slv2 addr */
9433 if (res != 0) /* check result */
9434 {
9435 handle->debug_print("mpu6500: read i2c slv2 addr failed.\n"); /* read i2c slv2 addr failed */
9436
9437 return 1; /* return error */
9438 }
9439 prev &= ~(1 << 7); /* clear the settings */
9440 prev |= mode << 7; /* set the bool */
9441 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV2_ADDR, (uint8_t *)&prev, 1); /* write i2c slv2 addr */
9442 if (res != 0) /* check result */
9443 {
9444 handle->debug_print("mpu6500: write i2c slv2 addr failed.\n"); /* write i2c slv2 addr failed */
9445
9446 return 1; /* return error */
9447 }
9448 }
9449 else if (slave == MPU6500_IIC_SLAVE_3) /* slave2 */
9450 {
9451 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV3_ADDR, (uint8_t *)&prev, 1); /* read i2c slv3 addr */
9452 if (res != 0) /* check result */
9453 {
9454 handle->debug_print("mpu6500: read i2c slv3 addr failed.\n"); /* read i2c slv3 addr failed */
9455
9456 return 1; /* return error */
9457 }
9458 prev &= ~(1 << 7); /* clear the settings */
9459 prev |= mode << 7; /* set the bool */
9460 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV3_ADDR, (uint8_t *)&prev, 1); /* write i2c slv3 addr */
9461 if (res != 0) /* check result */
9462 {
9463 handle->debug_print("mpu6500: write i2c slv3 addr failed.\n"); /* write i2c slv3 addr failed */
9464
9465 return 1; /* return error */
9466 }
9467 }
9468 else if (slave == MPU6500_IIC_SLAVE_4) /* slave4 */
9469 {
9470 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV4_ADDR, (uint8_t *)&prev, 1); /* read i2c slv4 addr */
9471 if (res != 0) /* check result */
9472 {
9473 handle->debug_print("mpu6500: read i2c slv4 addr failed.\n"); /* read i2c slv4 addr failed */
9474
9475 return 1; /* return error */
9476 }
9477 prev &= ~(1 << 7); /* clear the settings */
9478 prev |= mode << 7; /* set the bool */
9479 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV4_ADDR, (uint8_t *)&prev, 1); /* write i2c slv4 addr */
9480 if (res != 0) /* check result */
9481 {
9482 handle->debug_print("mpu6500: write i2c slv4 addr failed.\n"); /* write i2c slv4 addr failed */
9483
9484 return 1; /* return error */
9485 }
9486 }
9487 else
9488 {
9489 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
9490
9491 return 4; /* return error */
9492 }
9493
9494 return 0; /* success return 0 */
9495}
9496
9511{
9512 uint8_t res;
9513 uint8_t prev;
9514
9515 if (handle == NULL) /* check handle */
9516 {
9517 return 2; /* return error */
9518 }
9519 if (handle->inited != 1) /* check handle initialization */
9520 {
9521 return 3; /* return error */
9522 }
9523
9524 if (slave == MPU6500_IIC_SLAVE_0) /* slave0 */
9525 {
9526 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* read i2c slv0 addr */
9527 if (res != 0) /* check result */
9528 {
9529 handle->debug_print("mpu6500: read i2c slv0 addr failed.\n"); /* read i2c slv0 addr failed */
9530
9531 return 1; /* return error */
9532 }
9533 *mode = (mpu6500_iic_mode_t)((prev >> 7) & 0x1); /* get the mode */
9534 }
9535 else if (slave == MPU6500_IIC_SLAVE_1) /* slave1 */
9536 {
9537 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV1_ADDR, (uint8_t *)&prev, 1); /* read i2c slv1 addr */
9538 if (res != 0) /* check result */
9539 {
9540 handle->debug_print("mpu6500: read i2c slv1 addr failed.\n"); /* read i2c slv1 addr failed */
9541
9542 return 1; /* return error */
9543 }
9544 *mode = (mpu6500_iic_mode_t)((prev >> 7) & 0x1); /* get the mode */
9545 }
9546 else if (slave == MPU6500_IIC_SLAVE_2) /* slave2 */
9547 {
9548 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV2_ADDR, (uint8_t *)&prev, 1); /* read i2c slv2 addr */
9549 if (res != 0) /* check result */
9550 {
9551 handle->debug_print("mpu6500: read i2c slv2 addr failed.\n"); /* read i2c slv2 addr failed */
9552
9553 return 1; /* return error */
9554 }
9555 *mode = (mpu6500_iic_mode_t)((prev >> 7) & 0x1); /* get the mode */
9556 }
9557 else if (slave == MPU6500_IIC_SLAVE_3) /* slave2 */
9558 {
9559 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV3_ADDR, (uint8_t *)&prev, 1); /* read i2c slv3 addr */
9560 if (res != 0) /* check result */
9561 {
9562 handle->debug_print("mpu6500: read i2c slv3 addr failed.\n"); /* read i2c slv3 addr failed */
9563
9564 return 1; /* return error */
9565 }
9566 *mode = (mpu6500_iic_mode_t)((prev >> 7) & 0x1); /* get the mode */
9567 }
9568 else if (slave == MPU6500_IIC_SLAVE_4) /* slave4 */
9569 {
9570 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV4_ADDR, (uint8_t *)&prev, 1); /* read i2c slv4 addr */
9571 if (res != 0) /* check result */
9572 {
9573 handle->debug_print("mpu6500: read i2c slv4 addr failed.\n"); /* read i2c slv4 addr failed */
9574
9575 return 1; /* return error */
9576 }
9577 *mode = (mpu6500_iic_mode_t)((prev >> 7) & 0x1); /* get the mode */
9578 }
9579 else
9580 {
9581 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
9582
9583 return 4; /* return error */
9584 }
9585
9586 return 0; /* success return 0 */
9587}
9588
9602uint8_t mpu6500_set_iic_address(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, uint8_t addr_7bit)
9603{
9604 uint8_t res;
9605 uint8_t prev;
9606
9607 if (handle == NULL) /* check handle */
9608 {
9609 return 2; /* return error */
9610 }
9611 if (handle->inited != 1) /* check handle initialization */
9612 {
9613 return 3; /* return error */
9614 }
9615
9616 if (slave == MPU6500_IIC_SLAVE_0) /* slave0 */
9617 {
9618 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* read i2c slv0 addr */
9619 if (res != 0) /* check result */
9620 {
9621 handle->debug_print("mpu6500: read i2c slv0 addr failed.\n"); /* read i2c slv0 addr failed */
9622
9623 return 1; /* return error */
9624 }
9625 prev &= ~0x7F; /* clear the settings */
9626 prev |= addr_7bit & 0x7F; /* set the address */
9627 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* write i2c slv0 addr */
9628 if (res != 0) /* check result */
9629 {
9630 handle->debug_print("mpu6500: write i2c slv0 addr failed.\n"); /* write i2c slv0 addr failed */
9631
9632 return 1; /* return error */
9633 }
9634 }
9635 else if (slave == MPU6500_IIC_SLAVE_1) /* slave1 */
9636 {
9637 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV1_ADDR, (uint8_t *)&prev, 1); /* read i2c slv1 addr */
9638 if (res != 0) /* check result */
9639 {
9640 handle->debug_print("mpu6500: read i2c slv1 addr failed.\n"); /* read i2c slv1 addr failed */
9641
9642 return 1; /* return error */
9643 }
9644 prev &= ~0x7F; /* clear the settings */
9645 prev |= addr_7bit & 0x7F; /* set the address */
9646 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV1_ADDR, (uint8_t *)&prev, 1); /* write i2c slv1 addr */
9647 if (res != 0) /* check result */
9648 {
9649 handle->debug_print("mpu6500: write i2c slv1 addr failed.\n"); /* write i2c slv1 addr failed */
9650
9651 return 1; /* return error */
9652 }
9653 }
9654 else if (slave == MPU6500_IIC_SLAVE_2) /* slave2 */
9655 {
9656 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV2_ADDR, (uint8_t *)&prev, 1); /* read i2c slv2 addr */
9657 if (res != 0) /* check result */
9658 {
9659 handle->debug_print("mpu6500: read i2c slv2 addr failed.\n"); /* read i2c slv2 addr failed */
9660
9661 return 1; /* return error */
9662 }
9663 prev &= ~0x7F; /* clear the settings */
9664 prev |= addr_7bit & 0x7F; /* set the address */
9665 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV2_ADDR, (uint8_t *)&prev, 1); /* write i2c slv2 addr */
9666 if (res != 0) /* check result */
9667 {
9668 handle->debug_print("mpu6500: write i2c slv2 addr failed.\n"); /* write i2c slv2 addr failed */
9669
9670 return 1; /* return error */
9671 }
9672 }
9673 else if (slave == MPU6500_IIC_SLAVE_3) /* slave2 */
9674 {
9675 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV3_ADDR, (uint8_t *)&prev, 1); /* read i2c slv3 addr */
9676 if (res != 0) /* check result */
9677 {
9678 handle->debug_print("mpu6500: read i2c slv3 addr failed.\n"); /* read i2c slv3 addr failed */
9679
9680 return 1; /* return error */
9681 }
9682 prev &= ~0x7F; /* clear the settings */
9683 prev |= addr_7bit & 0x7F; /* set the address */
9684 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV3_ADDR, (uint8_t *)&prev, 1); /* write i2c slv3 addr */
9685 if (res != 0) /* check result */
9686 {
9687 handle->debug_print("mpu6500: write i2c slv3 addr failed.\n"); /* write i2c slv3 addr failed */
9688
9689 return 1; /* return error */
9690 }
9691 }
9692 else if (slave == MPU6500_IIC_SLAVE_4) /* slave4 */
9693 {
9694 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV4_ADDR, (uint8_t *)&prev, 1); /* read i2c slv4 addr */
9695 if (res != 0) /* check result */
9696 {
9697 handle->debug_print("mpu6500: read i2c slv4 addr failed.\n"); /* read i2c slv4 addr failed */
9698
9699 return 1; /* return error */
9700 }
9701 prev &= ~0x7F; /* clear the settings */
9702 prev |= addr_7bit & 0x7F; /* set the address */
9703 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV4_ADDR, (uint8_t *)&prev, 1); /* write i2c slv4 addr */
9704 if (res != 0) /* check result */
9705 {
9706 handle->debug_print("mpu6500: write i2c slv4 addr failed.\n"); /* write i2c slv4 addr failed */
9707
9708 return 1; /* return error */
9709 }
9710 }
9711 else
9712 {
9713 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
9714
9715 return 4; /* return error */
9716 }
9717
9718 return 0; /* success return 0 */
9719}
9720
9734uint8_t mpu6500_get_iic_address(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, uint8_t *addr_7bit)
9735{
9736 uint8_t res;
9737 uint8_t prev;
9738
9739 if (handle == NULL) /* check handle */
9740 {
9741 return 2; /* return error */
9742 }
9743 if (handle->inited != 1) /* check handle initialization */
9744 {
9745 return 3; /* return error */
9746 }
9747
9748 if (slave == MPU6500_IIC_SLAVE_0) /* slave0 */
9749 {
9750 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* read i2c slv0 addr */
9751 if (res != 0) /* check result */
9752 {
9753 handle->debug_print("mpu6500: read i2c slv0 addr failed.\n"); /* read i2c slv0 addr failed */
9754
9755 return 1; /* return error */
9756 }
9757 *addr_7bit = prev & 0x7F; /* get the address */
9758 }
9759 else if (slave == MPU6500_IIC_SLAVE_1) /* slave1 */
9760 {
9761 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV1_ADDR, (uint8_t *)&prev, 1); /* read i2c slv1 addr */
9762 if (res != 0) /* check result */
9763 {
9764 handle->debug_print("mpu6500: read i2c slv1 addr failed.\n"); /* read i2c slv1 addr failed */
9765
9766 return 1; /* return error */
9767 }
9768 *addr_7bit = prev & 0x7F; /* get the address */
9769 }
9770 else if (slave == MPU6500_IIC_SLAVE_2) /* slave2 */
9771 {
9772 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV2_ADDR, (uint8_t *)&prev, 1); /* read i2c slv2 addr */
9773 if (res != 0) /* check result */
9774 {
9775 handle->debug_print("mpu6500: read i2c slv2 addr failed.\n"); /* read i2c slv2 addr failed */
9776
9777 return 1; /* return error */
9778 }
9779 *addr_7bit = prev & 0x7F; /* get the address */
9780 }
9781 else if (slave == MPU6500_IIC_SLAVE_3) /* slave2 */
9782 {
9783 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV3_ADDR, (uint8_t *)&prev, 1); /* read i2c slv3 addr */
9784 if (res != 0) /* check result */
9785 {
9786 handle->debug_print("mpu6500: read i2c slv3 addr failed.\n"); /* read i2c slv3 addr failed */
9787
9788 return 1; /* return error */
9789 }
9790 *addr_7bit = prev & 0x7F; /* get the address */
9791 }
9792 else if (slave == MPU6500_IIC_SLAVE_4) /* slave4 */
9793 {
9794 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV4_ADDR, (uint8_t *)&prev, 1); /* read i2c slv4 addr */
9795 if (res != 0) /* check result */
9796 {
9797 handle->debug_print("mpu6500: read i2c slv4 addr failed.\n"); /* read i2c slv4 addr failed */
9798
9799 return 1; /* return error */
9800 }
9801 *addr_7bit = prev & 0x7F; /* get the address */
9802 }
9803 else
9804 {
9805 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
9806
9807 return 4; /* return error */
9808 }
9809
9810 return 0; /* success return 0 */
9811}
9812
9827{
9828 uint8_t res;
9829
9830 if (handle == NULL) /* check handle */
9831 {
9832 return 2; /* return error */
9833 }
9834 if (handle->inited != 1) /* check handle initialization */
9835 {
9836 return 3; /* return error */
9837 }
9838
9839 if (slave == MPU6500_IIC_SLAVE_0) /* slave0 */
9840 {
9841 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV0_REG, (uint8_t *)&reg, 1); /* write i2c slv0 reg */
9842 if (res != 0) /* check result */
9843 {
9844 handle->debug_print("mpu6500: write i2c slv0 reg failed.\n"); /* write i2c slv0 reg failed */
9845
9846 return 1; /* return error */
9847 }
9848 }
9849 else if (slave == MPU6500_IIC_SLAVE_1) /* slave1 */
9850 {
9851 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV1_REG, (uint8_t *)&reg, 1); /* write i2c slv1 reg */
9852 if (res != 0) /* check result */
9853 {
9854 handle->debug_print("mpu6500: write i2c slv1 reg failed.\n"); /* write i2c slv1 reg failed */
9855
9856 return 1; /* return error */
9857 }
9858 }
9859 else if (slave == MPU6500_IIC_SLAVE_2) /* slave2 */
9860 {
9861 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV2_REG, (uint8_t *)&reg, 1); /* write i2c slv2 reg */
9862 if (res != 0) /* check result */
9863 {
9864 handle->debug_print("mpu6500: write i2c slv2 reg failed.\n"); /* write i2c slv2 reg failed */
9865
9866 return 1; /* return error */
9867 }
9868 }
9869 else if (slave == MPU6500_IIC_SLAVE_3) /* slave2 */
9870 {
9871 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV3_REG, (uint8_t *)&reg, 1); /* write i2c slv3 reg */
9872 if (res != 0) /* check result */
9873 {
9874 handle->debug_print("mpu6500: write i2c slv3 reg failed.\n"); /* write i2c slv3 reg failed */
9875
9876 return 1; /* return error */
9877 }
9878 }
9879 else if (slave == MPU6500_IIC_SLAVE_4) /* slave4 */
9880 {
9881 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV4_REG, (uint8_t *)&reg, 1); /* write i2c slv4 reg */
9882 if (res != 0) /* check result */
9883 {
9884 handle->debug_print("mpu6500: write i2c slv4 reg failed.\n"); /* write i2c slv4 reg failed */
9885
9886 return 1; /* return error */
9887 }
9888 }
9889 else
9890 {
9891 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
9892
9893 return 4; /* return error */
9894 }
9895
9896 return 0; /* success return 0 */
9897}
9898
9913{
9914 uint8_t res;
9915
9916 if (handle == NULL) /* check handle */
9917 {
9918 return 2; /* return error */
9919 }
9920 if (handle->inited != 1) /* check handle initialization */
9921 {
9922 return 3; /* return error */
9923 }
9924
9925 if (slave == MPU6500_IIC_SLAVE_0) /* slave0 */
9926 {
9927 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV0_REG, (uint8_t *)reg, 1); /* read i2c slv0 reg */
9928 if (res != 0) /* check result */
9929 {
9930 handle->debug_print("mpu6500: read i2c slv0 reg failed.\n"); /* read i2c slv0 reg failed */
9931
9932 return 1; /* return error */
9933 }
9934 }
9935 else if (slave == MPU6500_IIC_SLAVE_1) /* slave1 */
9936 {
9937 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV1_REG, (uint8_t *)reg, 1); /* read i2c slv1 reg */
9938 if (res != 0) /* check result */
9939 {
9940 handle->debug_print("mpu6500: read i2c slv1 reg failed.\n"); /* read i2c slv1 reg failed */
9941
9942 return 1; /* return error */
9943 }
9944 }
9945 else if (slave == MPU6500_IIC_SLAVE_2) /* slave2 */
9946 {
9947 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV2_REG, (uint8_t *)reg, 1); /* read i2c slv2 reg */
9948 if (res != 0) /* check result */
9949 {
9950 handle->debug_print("mpu6500: read i2c slv2 reg failed.\n"); /* read i2c slv2 reg failed */
9951
9952 return 1; /* return error */
9953 }
9954 }
9955 else if (slave == MPU6500_IIC_SLAVE_3) /* slave2 */
9956 {
9957 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV3_REG, (uint8_t *)reg, 1); /* read i2c slv3 reg */
9958 if (res != 0) /* check result */
9959 {
9960 handle->debug_print("mpu6500: read i2c slv3 reg failed.\n"); /* read i2c slv3 reg failed */
9961
9962 return 1; /* return error */
9963 }
9964 }
9965 else if (slave == MPU6500_IIC_SLAVE_4) /* slave4 */
9966 {
9967 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV4_REG, (uint8_t *)reg, 1); /* read i2c slv4 reg */
9968 if (res != 0) /* check result */
9969 {
9970 handle->debug_print("mpu6500: read i2c slv4 reg failed.\n"); /* read i2c slv4 reg failed */
9971
9972 return 1; /* return error */
9973 }
9974 }
9975 else
9976 {
9977 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
9978
9979 return 4; /* return error */
9980 }
9981
9982 return 0; /* success return 0 */
9983}
9984
9999{
10000 uint8_t res;
10001
10002 if (handle == NULL) /* check handle */
10003 {
10004 return 2; /* return error */
10005 }
10006 if (handle->inited != 1) /* check handle initialization */
10007 {
10008 return 3; /* return error */
10009 }
10010
10011 if (slave == MPU6500_IIC_SLAVE_0) /* slave0 */
10012 {
10013 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV0_DO, (uint8_t *)&data, 1); /* write i2c slv0 do */
10014 if (res != 0) /* check result */
10015 {
10016 handle->debug_print("mpu6500: write i2c slv0 do failed.\n"); /* write i2c slv0 do fail */
10017
10018 return 1; /* return error */
10019 }
10020 }
10021 else if (slave == MPU6500_IIC_SLAVE_1) /* slave1 */
10022 {
10023 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV1_DO, (uint8_t *)&data, 1); /* write i2c slv1 do */
10024 if (res != 0) /* check result */
10025 {
10026 handle->debug_print("mpu6500: write i2c slv1 do failed.\n"); /* write i2c slv1 do fail */
10027
10028 return 1; /* return error */
10029 }
10030 }
10031 else if (slave == MPU6500_IIC_SLAVE_2) /* slave2 */
10032 {
10033 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV2_DO, (uint8_t *)&data, 1); /* write i2c slv2 do */
10034 if (res != 0) /* check result */
10035 {
10036 handle->debug_print("mpu6500: write i2c slv2 do failed.\n"); /* write i2c slv2 do fail */
10037
10038 return 1; /* return error */
10039 }
10040 }
10041 else if (slave == MPU6500_IIC_SLAVE_3) /* slave2 */
10042 {
10043 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV3_DO, (uint8_t *)&data, 1); /* write i2c slv3 do */
10044 if (res != 0) /* check result */
10045 {
10046 handle->debug_print("mpu6500: write i2c slv3 do failed.\n"); /* write i2c slv3 do fail */
10047
10048 return 1; /* return error */
10049 }
10050 }
10051 else
10052 {
10053 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
10054
10055 return 4; /* return error */
10056 }
10057
10058 return 0; /* success return 0 */
10059}
10060
10075{
10076 uint8_t res;
10077
10078 if (handle == NULL) /* check handle */
10079 {
10080 return 2; /* return error */
10081 }
10082 if (handle->inited != 1) /* check handle initialization */
10083 {
10084 return 3; /* return error */
10085 }
10086
10087 if (slave == MPU6500_IIC_SLAVE_0) /* slave0 */
10088 {
10089 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV0_DO, (uint8_t *)data, 1); /* read i2c slv0 do */
10090 if (res != 0) /* check result */
10091 {
10092 handle->debug_print("mpu6500: read i2c slv0 do failed.\n"); /* read i2c slv0 do failed */
10093
10094 return 1; /* return error */
10095 }
10096 }
10097 else if (slave == MPU6500_IIC_SLAVE_1) /* slave1 */
10098 {
10099 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV1_DO, (uint8_t *)data, 1); /* read i2c slv1 do */
10100 if (res != 0) /* check result */
10101 {
10102 handle->debug_print("mpu6500: read i2c slv1 do failed.\n"); /* read i2c slv1 do failed */
10103
10104 return 1; /* return error */
10105 }
10106 }
10107 else if (slave == MPU6500_IIC_SLAVE_2) /* slave2 */
10108 {
10109 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV2_DO, (uint8_t *)data, 1); /* read i2c slv2 do */
10110 if (res != 0) /* check result */
10111 {
10112 handle->debug_print("mpu6500: read i2c slv2 do failed.\n"); /* read i2c slv2 do failed */
10113
10114 return 1; /* return error */
10115 }
10116 }
10117 else if (slave == MPU6500_IIC_SLAVE_3) /* slave2 */
10118 {
10119 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV3_DO, (uint8_t *)data, 1); /* read i2c slv3 do */
10120 if (res != 0) /* check result */
10121 {
10122 handle->debug_print("mpu6500: read i2c slv3 do failed.\n"); /* read i2c slv3 do failed */
10123
10124 return 1; /* return error */
10125 }
10126 }
10127 else
10128 {
10129 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
10130
10131 return 4; /* return error */
10132 }
10133
10134 return 0; /* success return 0 */
10135}
10136
10151{
10152 uint8_t res;
10153 uint8_t prev;
10154
10155 if (handle == NULL) /* check handle */
10156 {
10157 return 2; /* return error */
10158 }
10159 if (handle->inited != 1) /* check handle initialization */
10160 {
10161 return 3; /* return error */
10162 }
10163
10164 if (slave == MPU6500_IIC_SLAVE_0) /* slave0 */
10165 {
10166 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
10167 if (res != 0) /* check result */
10168 {
10169 handle->debug_print("mpu6500: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
10170
10171 return 1; /* return error */
10172 }
10173 prev &= ~(1 << 7); /* clear the settings */
10174 prev |= enable << 7; /* set the bool */
10175 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* write i2c slv0 ctrl */
10176 if (res != 0) /* check result */
10177 {
10178 handle->debug_print("mpu6500: write i2c slv0 ctrl failed.\n"); /* write i2c slv0 ctrl failed */
10179
10180 return 1; /* return error */
10181 }
10182 }
10183 else if (slave == MPU6500_IIC_SLAVE_1) /* slave1 */
10184 {
10185 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
10186 if (res != 0) /* check result */
10187 {
10188 handle->debug_print("mpu6500: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
10189
10190 return 1; /* return error */
10191 }
10192 prev &= ~(1 << 7); /* clear the settings */
10193 prev |= enable << 7; /* set the bool */
10194 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* write i2c slv1 ctrl */
10195 if (res != 0) /* check result */
10196 {
10197 handle->debug_print("mpu6500: write i2c slv1 ctrl failed.\n"); /* write i2c slv1 ctrl failed */
10198
10199 return 1; /* return error */
10200 }
10201 }
10202 else if (slave == MPU6500_IIC_SLAVE_2) /* slave2 */
10203 {
10204 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
10205 if (res != 0) /* check result */
10206 {
10207 handle->debug_print("mpu6500: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
10208
10209 return 1; /* return error */
10210 }
10211 prev &= ~(1 << 7); /* clear the settings */
10212 prev |= enable << 7; /* set the bool */
10213 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* write i2c slv2 ctrl */
10214 if (res != 0) /* check result */
10215 {
10216 handle->debug_print("mpu6500: write i2c slv2 ctrl failed.\n"); /* write i2c slv2 ctrl failed */
10217
10218 return 1; /* return error */
10219 }
10220 }
10221 else if (slave == MPU6500_IIC_SLAVE_3) /* slave2 */
10222 {
10223 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
10224 if (res != 0) /* check result */
10225 {
10226 handle->debug_print("mpu6500: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
10227
10228 return 1; /* return error */
10229 }
10230 prev &= ~(1 << 7); /* clear the settings */
10231 prev |= enable << 7; /* set the bool */
10232 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* write i2c slv3 ctrl */
10233 if (res != 0) /* check result */
10234 {
10235 handle->debug_print("mpu6500: write i2c slv3 ctrl failed.\n"); /* write i2c slv3 ctrl failed */
10236
10237 return 1; /* return error */
10238 }
10239 }
10240 else
10241 {
10242 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
10243
10244 return 4; /* return error */
10245 }
10246
10247 return 0; /* success return 0 */
10248}
10249
10264{
10265 uint8_t res;
10266 uint8_t prev;
10267
10268 if (handle == NULL) /* check handle */
10269 {
10270 return 2; /* return error */
10271 }
10272 if (handle->inited != 1) /* check handle initialization */
10273 {
10274 return 3; /* return error */
10275 }
10276
10277 if (slave == MPU6500_IIC_SLAVE_0) /* slave0 */
10278 {
10279 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
10280 if (res != 0) /* check result */
10281 {
10282 handle->debug_print("mpu6500: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
10283
10284 return 1; /* return error */
10285 }
10286 *enable = (mpu6500_bool_t)((prev >> 7) & 0x1); /* get the bool */
10287 }
10288 else if (slave == MPU6500_IIC_SLAVE_1) /* slave1 */
10289 {
10290 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
10291 if (res != 0) /* check result */
10292 {
10293 handle->debug_print("mpu6500: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
10294
10295 return 1; /* return error */
10296 }
10297 *enable = (mpu6500_bool_t)((prev >> 7) & 0x1); /* get the bool */
10298 }
10299 else if (slave == MPU6500_IIC_SLAVE_2) /* slave2 */
10300 {
10301 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
10302 if (res != 0) /* check result */
10303 {
10304 handle->debug_print("mpu6500: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
10305
10306 return 1; /* return error */
10307 }
10308 *enable = (mpu6500_bool_t)((prev >> 7) & 0x1); /* get the bool */
10309 }
10310 else if (slave == MPU6500_IIC_SLAVE_3) /* slave2 */
10311 {
10312 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
10313 if (res != 0) /* check result */
10314 {
10315 handle->debug_print("mpu6500: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
10316
10317 return 1; /* return error */
10318 }
10319 *enable = (mpu6500_bool_t)((prev >> 7) & 0x1); /* get the bool */
10320 }
10321 else
10322 {
10323 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
10324
10325 return 4; /* return error */
10326 }
10327
10328 return 0; /* success return 0 */
10329}
10330
10345{
10346 uint8_t res;
10347 uint8_t prev;
10348
10349 if (handle == NULL) /* check handle */
10350 {
10351 return 2; /* return error */
10352 }
10353 if (handle->inited != 1) /* check handle initialization */
10354 {
10355 return 3; /* return error */
10356 }
10357
10358 if (slave == MPU6500_IIC_SLAVE_0) /* slave0 */
10359 {
10360 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
10361 if (res != 0) /* check result */
10362 {
10363 handle->debug_print("mpu6500: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
10364
10365 return 1; /* return error */
10366 }
10367 prev &= ~(1 << 6); /* clear the settings */
10368 prev |= enable << 6; /* set the bool */
10369 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* write i2c slv0 ctrl */
10370 if (res != 0) /* check result */
10371 {
10372 handle->debug_print("mpu6500: write i2c slv0 ctrl failed.\n"); /* write i2c slv0 ctrl failed */
10373
10374 return 1; /* return error */
10375 }
10376 }
10377 else if (slave == MPU6500_IIC_SLAVE_1) /* slave1 */
10378 {
10379 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
10380 if (res != 0) /* check result */
10381 {
10382 handle->debug_print("mpu6500: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
10383
10384 return 1; /* return error */
10385 }
10386 prev &= ~(1 << 6); /* clear the settings */
10387 prev |= enable << 6; /* set the bool */
10388 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* write i2c slv1 ctrl */
10389 if (res != 0) /* check result */
10390 {
10391 handle->debug_print("mpu6500: write i2c slv1 ctrl failed.\n"); /* write i2c slv1 ctrl failed */
10392
10393 return 1; /* return error */
10394 }
10395 }
10396 else if (slave == MPU6500_IIC_SLAVE_2) /* slave2 */
10397 {
10398 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
10399 if (res != 0) /* check result */
10400 {
10401 handle->debug_print("mpu6500: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
10402
10403 return 1; /* return error */
10404 }
10405 prev &= ~(1 << 6); /* clear the settings */
10406 prev |= enable << 6; /* set the bool */
10407 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* write i2c slv2 ctrl */
10408 if (res != 0) /* check result */
10409 {
10410 handle->debug_print("mpu6500: write i2c slv2 ctrl failed.\n"); /* write i2c slv2 ctrl failed */
10411
10412 return 1; /* return error */
10413 }
10414 }
10415 else if (slave == MPU6500_IIC_SLAVE_3) /* slave2 */
10416 {
10417 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
10418 if (res != 0) /* check result */
10419 {
10420 handle->debug_print("mpu6500: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
10421
10422 return 1; /* return error */
10423 }
10424 prev &= ~(1 << 6); /* clear the settings */
10425 prev |= enable << 6; /* set the bool */
10426 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* write i2c slv3 ctrl */
10427 if (res != 0) /* check result */
10428 {
10429 handle->debug_print("mpu6500: write i2c slv3 ctrl failed.\n"); /* write i2c slv3 ctrl failed */
10430
10431 return 1; /* return error */
10432 }
10433 }
10434 else
10435 {
10436 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
10437
10438 return 4; /* return error */
10439 }
10440
10441 return 0; /* success return 0 */
10442}
10443
10458{
10459 uint8_t res;
10460 uint8_t prev;
10461
10462 if (handle == NULL) /* check handle */
10463 {
10464 return 2; /* return error */
10465 }
10466 if (handle->inited != 1) /* check handle initialization */
10467 {
10468 return 3; /* return error */
10469 }
10470
10471 if (slave == MPU6500_IIC_SLAVE_0) /* slave0 */
10472 {
10473 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
10474 if (res != 0) /* check result */
10475 {
10476 handle->debug_print("mpu6500: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
10477
10478 return 1; /* return error */
10479 }
10480 *enable = (mpu6500_bool_t)((prev >> 6) & 0x1); /* get the bool */
10481 }
10482 else if (slave == MPU6500_IIC_SLAVE_1) /* slave1 */
10483 {
10484 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
10485 if (res != 0) /* check result */
10486 {
10487 handle->debug_print("mpu6500: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
10488
10489 return 1; /* return error */
10490 }
10491 *enable = (mpu6500_bool_t)((prev >> 6) & 0x1); /* get the bool */
10492 }
10493 else if (slave == MPU6500_IIC_SLAVE_2) /* slave2 */
10494 {
10495 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
10496 if (res != 0) /* check result */
10497 {
10498 handle->debug_print("mpu6500: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
10499
10500 return 1; /* return error */
10501 }
10502 *enable = (mpu6500_bool_t)((prev >> 6) & 0x1); /* get the bool */
10503 }
10504 else if (slave == MPU6500_IIC_SLAVE_3) /* slave2 */
10505 {
10506 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
10507 if (res != 0) /* check result */
10508 {
10509 handle->debug_print("mpu6500: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
10510
10511 return 1; /* return error */
10512 }
10513 *enable = (mpu6500_bool_t)((prev >> 6) & 0x1); /* get the bool */
10514 }
10515 else
10516 {
10517 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
10518
10519 return 4; /* return error */
10520 }
10521
10522 return 0; /* success return 0 */
10523}
10524
10539{
10540 uint8_t res;
10541 uint8_t prev;
10542
10543 if (handle == NULL) /* check handle */
10544 {
10545 return 2; /* return error */
10546 }
10547 if (handle->inited != 1) /* check handle initialization */
10548 {
10549 return 3; /* return error */
10550 }
10551
10552 if (slave == MPU6500_IIC_SLAVE_0) /* slave0 */
10553 {
10554 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
10555 if (res != 0) /* check result */
10556 {
10557 handle->debug_print("mpu6500: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
10558
10559 return 1; /* return error */
10560 }
10561 prev &= ~(1 << 5); /* clear the settings */
10562 prev |= mode << 5; /* set the bool */
10563 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* write i2c slv0 ctrl */
10564 if (res != 0) /* check result */
10565 {
10566 handle->debug_print("mpu6500: write i2c slv0 ctrl failed.\n"); /* write i2c slv0 ctrl failed */
10567
10568 return 1; /* return error */
10569 }
10570 }
10571 else if (slave == MPU6500_IIC_SLAVE_1) /* slave1 */
10572 {
10573 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
10574 if (res != 0) /* check result */
10575 {
10576 handle->debug_print("mpu6500: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
10577
10578 return 1; /* return error */
10579 }
10580 prev &= ~(1 << 5); /* clear the settings */
10581 prev |= mode << 5; /* set the bool */
10582 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* write i2c slv1 ctrl */
10583 if (res != 0) /* check result */
10584 {
10585 handle->debug_print("mpu6500: write i2c slv1 ctrl failed.\n"); /* write i2c slv1 ctrl failed */
10586
10587 return 1; /* return error */
10588 }
10589 }
10590 else if (slave == MPU6500_IIC_SLAVE_2) /* slave2 */
10591 {
10592 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
10593 if (res != 0) /* check result */
10594 {
10595 handle->debug_print("mpu6500: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
10596
10597 return 1; /* return error */
10598 }
10599 prev &= ~(1 << 5); /* clear the settings */
10600 prev |= mode << 5; /* set the bool */
10601 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* write i2c slv2 ctrl */
10602 if (res != 0) /* check result */
10603 {
10604 handle->debug_print("mpu6500: write i2c slv2 ctrl failed.\n"); /* write i2c slv2 ctrl failed */
10605
10606 return 1; /* return error */
10607 }
10608 }
10609 else if (slave == MPU6500_IIC_SLAVE_3) /* slave2 */
10610 {
10611 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
10612 if (res != 0) /* check result */
10613 {
10614 handle->debug_print("mpu6500: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
10615
10616 return 1; /* return error */
10617 }
10618 prev &= ~(1 << 5); /* clear the settings */
10619 prev |= mode << 5; /* set the bool */
10620 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* write i2c slv3 ctrl */
10621 if (res != 0) /* check result */
10622 {
10623 handle->debug_print("mpu6500: write i2c slv3 ctrl failed.\n"); /* write i2c slv3 ctrl failed */
10624
10625 return 1; /* return error */
10626 }
10627 }
10628 else
10629 {
10630 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
10631
10632 return 4; /* return error */
10633 }
10634
10635 return 0; /* success return 0 */
10636}
10637
10652{
10653 uint8_t res;
10654 uint8_t prev;
10655
10656 if (handle == NULL) /* check handle */
10657 {
10658 return 2; /* return error */
10659 }
10660 if (handle->inited != 1) /* check handle initialization */
10661 {
10662 return 3; /* return error */
10663 }
10664
10665 if (slave == MPU6500_IIC_SLAVE_0) /* slave0 */
10666 {
10667 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
10668 if (res != 0) /* check result */
10669 {
10670 handle->debug_print("mpu6500: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
10671
10672 return 1; /* return error */
10673 }
10674 *mode = (mpu6500_iic_transaction_mode_t)((prev >> 5) & 0x1); /* get the bool */
10675 }
10676 else if (slave == MPU6500_IIC_SLAVE_1) /* slave1 */
10677 {
10678 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
10679 if (res != 0) /* check result */
10680 {
10681 handle->debug_print("mpu6500: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
10682
10683 return 1; /* return error */
10684 }
10685 *mode = (mpu6500_iic_transaction_mode_t)((prev >> 5) & 0x1); /* get the bool */
10686 }
10687 else if (slave == MPU6500_IIC_SLAVE_2) /* slave2 */
10688 {
10689 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
10690 if (res != 0) /* check result */
10691 {
10692 handle->debug_print("mpu6500: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
10693
10694 return 1; /* return error */
10695 }
10696 *mode = (mpu6500_iic_transaction_mode_t)((prev >> 5) & 0x1); /* get the bool */
10697 }
10698 else if (slave == MPU6500_IIC_SLAVE_3) /* slave2 */
10699 {
10700 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
10701 if (res != 0) /* check result */
10702 {
10703 handle->debug_print("mpu6500: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
10704
10705 return 1; /* return error */
10706 }
10707 *mode = (mpu6500_iic_transaction_mode_t)((prev >> 5) & 0x1); /* get the bool */
10708 }
10709 else
10710 {
10711 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
10712
10713 return 4; /* return error */
10714 }
10715
10716 return 0; /* success return 0 */
10717}
10718
10733{
10734 uint8_t res;
10735 uint8_t prev;
10736
10737 if (handle == NULL) /* check handle */
10738 {
10739 return 2; /* return error */
10740 }
10741 if (handle->inited != 1) /* check handle initialization */
10742 {
10743 return 3; /* return error */
10744 }
10745
10746 if (slave == MPU6500_IIC_SLAVE_0) /* slave0 */
10747 {
10748 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
10749 if (res != 0) /* check result */
10750 {
10751 handle->debug_print("mpu6500: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
10752
10753 return 1; /* return error */
10754 }
10755 prev &= ~(1 << 4); /* clear the settings */
10756 prev |= order << 4; /* set the order */
10757 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* write i2c slv0 ctrl */
10758 if (res != 0) /* check result */
10759 {
10760 handle->debug_print("mpu6500: write i2c slv0 ctrl failed.\n"); /* write i2c slv0 ctrl failed */
10761
10762 return 1; /* return error */
10763 }
10764 }
10765 else if (slave == MPU6500_IIC_SLAVE_1) /* slave1 */
10766 {
10767 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
10768 if (res != 0) /* check result */
10769 {
10770 handle->debug_print("mpu6500: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
10771
10772 return 1; /* return error */
10773 }
10774 prev &= ~(1 << 4); /* clear the settings */
10775 prev |= order << 4; /* set the order */
10776 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* write i2c slv1 ctrl */
10777 if (res != 0) /* check result */
10778 {
10779 handle->debug_print("mpu6500: write i2c slv1 ctrl failed.\n"); /* write i2c slv1 ctrl failed */
10780
10781 return 1; /* return error */
10782 }
10783 }
10784 else if (slave == MPU6500_IIC_SLAVE_2) /* slave2 */
10785 {
10786 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
10787 if (res != 0) /* check result */
10788 {
10789 handle->debug_print("mpu6500: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
10790
10791 return 1; /* return error */
10792 }
10793 prev &= ~(1 << 4); /* clear the settings */
10794 prev |= order << 4; /* set the order */
10795 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* write i2c slv2 ctrl */
10796 if (res != 0) /* check result */
10797 {
10798 handle->debug_print("mpu6500: write i2c slv2 ctrl failed.\n"); /* write i2c slv2 ctrl failed */
10799
10800 return 1; /* return error */
10801 }
10802 }
10803 else if (slave == MPU6500_IIC_SLAVE_3) /* slave2 */
10804 {
10805 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
10806 if (res != 0) /* check result */
10807 {
10808 handle->debug_print("mpu6500: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
10809
10810 return 1; /* return error */
10811 }
10812 prev &= ~(1 << 4); /* clear the settings */
10813 prev |= order << 4; /* set the order */
10814 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* write i2c slv3 ctrl */
10815 if (res != 0) /* check result */
10816 {
10817 handle->debug_print("mpu6500: write i2c slv3 ctrl failed.\n"); /* write i2c slv3 ctrl failed */
10818
10819 return 1; /* return error */
10820 }
10821 }
10822 else
10823 {
10824 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
10825
10826 return 4; /* return error */
10827 }
10828
10829 return 0; /* success return 0 */
10830}
10831
10846{
10847 uint8_t res;
10848 uint8_t prev;
10849
10850 if (handle == NULL) /* check handle */
10851 {
10852 return 2; /* return error */
10853 }
10854 if (handle->inited != 1) /* check handle initialization */
10855 {
10856 return 3; /* return error */
10857 }
10858
10859 if (slave == MPU6500_IIC_SLAVE_0) /* slave0 */
10860 {
10861 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
10862 if (res != 0) /* check result */
10863 {
10864 handle->debug_print("mpu6500: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
10865
10866 return 1; /* return error */
10867 }
10868 *order = (mpu6500_iic_group_order_t)((prev >> 4) & 0x1); /* get the order */
10869 }
10870 else if (slave == MPU6500_IIC_SLAVE_1) /* slave1 */
10871 {
10872 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
10873 if (res != 0) /* check result */
10874 {
10875 handle->debug_print("mpu6500: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
10876
10877 return 1; /* return error */
10878 }
10879 *order = (mpu6500_iic_group_order_t)((prev >> 4) & 0x1); /* get the order */
10880 }
10881 else if (slave == MPU6500_IIC_SLAVE_2) /* slave2 */
10882 {
10883 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
10884 if (res != 0) /* check result */
10885 {
10886 handle->debug_print("mpu6500: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
10887
10888 return 1; /* return error */
10889 }
10890 *order = (mpu6500_iic_group_order_t)((prev >> 4) & 0x1); /* get the order */
10891 }
10892 else if (slave == MPU6500_IIC_SLAVE_3) /* slave2 */
10893 {
10894 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
10895 if (res != 0) /* check result */
10896 {
10897 handle->debug_print("mpu6500: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
10898
10899 return 1; /* return error */
10900 }
10901 *order = (mpu6500_iic_group_order_t)((prev >> 4) & 0x1); /* get the order */
10902 }
10903 else
10904 {
10905 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
10906
10907 return 4; /* return error */
10908 }
10909
10910 return 0; /* success return 0 */
10911}
10912
10928{
10929 uint8_t res;
10930 uint8_t prev;
10931
10932 if (handle == NULL) /* check handle */
10933 {
10934 return 2; /* return error */
10935 }
10936 if (handle->inited != 1) /* check handle initialization */
10937 {
10938 return 3; /* return error */
10939 }
10940 if (len > 0xF) /* check handle initialization */
10941 {
10942 handle->debug_print("mpu6500: len > 0xF.\n"); /* len > 0xF */
10943
10944 return 5; /* return error */
10945 }
10946
10947 if (slave == MPU6500_IIC_SLAVE_0) /* slave0 */
10948 {
10949 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
10950 if (res != 0) /* check result */
10951 {
10952 handle->debug_print("mpu6500: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
10953
10954 return 1; /* return error */
10955 }
10956 prev &= ~0xF; /* clear the settings */
10957 prev |= len; /* set the len */
10958 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* write i2c slv0 ctrl */
10959 if (res != 0) /* check result */
10960 {
10961 handle->debug_print("mpu6500: write i2c slv0 ctrl failed.\n"); /* write i2c slv0 ctrl failed */
10962
10963 return 1; /* return error */
10964 }
10965 }
10966 else if (slave == MPU6500_IIC_SLAVE_1) /* slave1 */
10967 {
10968 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
10969 if (res != 0) /* check result */
10970 {
10971 handle->debug_print("mpu6500: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
10972
10973 return 1; /* return error */
10974 }
10975 prev &= ~0xF; /* clear the settings */
10976 prev |= len; /* set the len */
10977 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* write i2c slv1 ctrl */
10978 if (res != 0) /* check result */
10979 {
10980 handle->debug_print("mpu6500: write i2c slv1 ctrl failed.\n"); /* write i2c slv1 ctrl failed */
10981
10982 return 1; /* return error */
10983 }
10984 }
10985 else if (slave == MPU6500_IIC_SLAVE_2) /* slave2 */
10986 {
10987 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
10988 if (res != 0) /* check result */
10989 {
10990 handle->debug_print("mpu6500: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
10991
10992 return 1; /* return error */
10993 }
10994 prev &= ~0xF; /* clear the settings */
10995 prev |= len; /* set the len */
10996 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* write i2c slv2 ctrl */
10997 if (res != 0) /* check result */
10998 {
10999 handle->debug_print("mpu6500: write i2c slv2 ctrl failed.\n"); /* write i2c slv2 ctrl failed */
11000
11001 return 1; /* return error */
11002 }
11003 }
11004 else if (slave == MPU6500_IIC_SLAVE_3) /* slave2 */
11005 {
11006 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
11007 if (res != 0) /* check result */
11008 {
11009 handle->debug_print("mpu6500: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
11010
11011 return 1; /* return error */
11012 }
11013 prev &= ~0xF; /* clear the settings */
11014 prev |= len; /* set the len */
11015 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* write i2c slv3 ctrl */
11016 if (res != 0) /* check result */
11017 {
11018 handle->debug_print("mpu6500: write i2c slv3 ctrl failed.\n"); /* write i2c slv3 ctrl failed */
11019
11020 return 1; /* return error */
11021 }
11022 }
11023 else
11024 {
11025 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
11026
11027 return 4; /* return error */
11028 }
11029
11030 return 0; /* success return 0 */
11031}
11032
11047{
11048 uint8_t res;
11049 uint8_t prev;
11050
11051 if (handle == NULL) /* check handle */
11052 {
11053 return 2; /* return error */
11054 }
11055 if (handle->inited != 1) /* check handle initialization */
11056 {
11057 return 3; /* return error */
11058 }
11059
11060 if (slave == MPU6500_IIC_SLAVE_0) /* slave0 */
11061 {
11062 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
11063 if (res != 0) /* check result */
11064 {
11065 handle->debug_print("mpu6500: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
11066
11067 return 1; /* return error */
11068 }
11069 *len = prev & 0x0F; /* get the len */
11070 }
11071 else if (slave == MPU6500_IIC_SLAVE_1) /* slave1 */
11072 {
11073 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
11074 if (res != 0) /* check result */
11075 {
11076 handle->debug_print("mpu6500: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
11077
11078 return 1; /* return error */
11079 }
11080 *len = prev & 0x0F; /* get the len */
11081 }
11082 else if (slave == MPU6500_IIC_SLAVE_2) /* slave2 */
11083 {
11084 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
11085 if (res != 0) /* check result */
11086 {
11087 handle->debug_print("mpu6500: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
11088
11089 return 1; /* return error */
11090 }
11091 *len = prev & 0x0F; /* get the len */
11092 }
11093 else if (slave == MPU6500_IIC_SLAVE_3) /* slave2 */
11094 {
11095 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
11096 if (res != 0) /* check result */
11097 {
11098 handle->debug_print("mpu6500: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
11099
11100 return 1; /* return error */
11101 }
11102 *len = prev & 0x0F; /* get the len */
11103 }
11104 else
11105 {
11106 handle->debug_print("mpu6500: invalid slave.\n"); /* invalid slave */
11107
11108 return 4; /* return error */
11109 }
11110
11111 return 0; /* success return 0 */
11112}
11113
11125uint8_t mpu6500_get_iic_status(mpu6500_handle_t *handle, uint8_t *status)
11126{
11127 uint8_t res;
11128
11129 if (handle == NULL) /* check handle */
11130 {
11131 return 2; /* return error */
11132 }
11133 if (handle->inited != 1) /* check handle initialization */
11134 {
11135 return 3; /* return error */
11136 }
11137
11138 res = a_mpu6500_read(handle, MPU6500_REG_I2C_MST_STATUS, (uint8_t *)status, 1); /* read i2c mst status */
11139 if (res != 0) /* check result */
11140 {
11141 handle->debug_print("mpu6500: read i2c mst status failed.\n"); /* read i2c mst status failed */
11142
11143 return 1; /* return error */
11144 }
11145
11146 return 0; /* success return 0 */
11147}
11148
11162{
11163 uint8_t res;
11164 uint8_t prev;
11165
11166 if (handle == NULL) /* check handle */
11167 {
11168 return 2; /* return error */
11169 }
11170 if (handle->inited != 1) /* check handle initialization */
11171 {
11172 return 3; /* return error */
11173 }
11174
11175 res = a_mpu6500_read(handle, MPU6500_REG_I2C_MST_DELAY_CTRL, (uint8_t *)&prev, 1); /* read i2c mst delay ctrl */
11176 if (res != 0) /* check result */
11177 {
11178 handle->debug_print("mpu6500: read i2c mst delay ctrl failed.\n"); /* read i2c mst delay ctrl failed */
11179
11180 return 1; /* return error */
11181 }
11182 prev &= ~(1 << delay); /* clear the settings */
11183 prev |= enable << delay; /* set the bool */
11184 res = a_mpu6500_write(handle, MPU6500_REG_I2C_MST_DELAY_CTRL, (uint8_t *)&prev, 1); /* write i2c mst delay ctrl */
11185 if (res != 0) /* check result */
11186 {
11187 handle->debug_print("mpu6500: write i2c mst delay ctrl failed.\n"); /* write i2c mst delay ctrl failed */
11188
11189 return 1; /* return error */
11190 }
11191
11192 return 0; /* success return 0 */
11193}
11194
11208{
11209 uint8_t res;
11210 uint8_t prev;
11211
11212 if (handle == NULL) /* check handle */
11213 {
11214 return 2; /* return error */
11215 }
11216 if (handle->inited != 1) /* check handle initialization */
11217 {
11218 return 3; /* return error */
11219 }
11220
11221 res = a_mpu6500_read(handle, MPU6500_REG_I2C_MST_DELAY_CTRL, (uint8_t *)&prev, 1); /* read i2c mst delay ctrl */
11222 if (res != 0) /* check result */
11223 {
11224 handle->debug_print("mpu6500: read i2c mst delay ctrl failed.\n"); /* read i2c mst delay ctrl failed */
11225
11226 return 1; /* return error */
11227 }
11228 *enable = (mpu6500_bool_t)((prev >> delay) & 0x1); /* get the bool */
11229
11230 return 0; /* success return 0 */
11231}
11232
11245{
11246 uint8_t res;
11247 uint8_t prev;
11248
11249 if (handle == NULL) /* check handle */
11250 {
11251 return 2; /* return error */
11252 }
11253 if (handle->inited != 1) /* check handle initialization */
11254 {
11255 return 3; /* return error */
11256 }
11257
11258 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
11259 if (res != 0) /* check result */
11260 {
11261 handle->debug_print("mpu6500: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
11262
11263 return 1; /* return error */
11264 }
11265 prev &= ~(1 << 7); /* clear the settings */
11266 prev |= enable << 7; /* set the bool */
11267 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* write i2c slv4 ctrl */
11268 if (res != 0) /* check result */
11269 {
11270 handle->debug_print("mpu6500: write i2c slv4 ctrl failed.\n"); /* write i2c slv4 ctrl failed */
11271
11272 return 1; /* return error */
11273 }
11274
11275 return 0; /* success return 0 */
11276}
11277
11290{
11291 uint8_t res;
11292 uint8_t prev;
11293
11294 if (handle == NULL) /* check handle */
11295 {
11296 return 2; /* return error */
11297 }
11298 if (handle->inited != 1) /* check handle initialization */
11299 {
11300 return 3; /* return error */
11301 }
11302
11303 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
11304 if (res != 0) /* check result */
11305 {
11306 handle->debug_print("mpu6500: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
11307
11308 return 1; /* return error */
11309 }
11310 *enable = (mpu6500_bool_t)((prev >> 7) & 0x1); /* get the bool */
11311
11312 return 0; /* success return 0 */
11313}
11314
11327{
11328 uint8_t res;
11329 uint8_t prev;
11330
11331 if (handle == NULL) /* check handle */
11332 {
11333 return 2; /* return error */
11334 }
11335 if (handle->inited != 1) /* check handle initialization */
11336 {
11337 return 3; /* return error */
11338 }
11339
11340 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
11341 if (res != 0) /* check result */
11342 {
11343 handle->debug_print("mpu6500: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
11344
11345 return 1; /* return error */
11346 }
11347 prev &= ~(1 << 6); /* clear the settings */
11348 prev |= enable << 6; /* set the bool */
11349 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* write i2c slv4 ctrl */
11350 if (res != 0) /* check result */
11351 {
11352 handle->debug_print("mpu6500: write i2c slv4 ctrl failed.\n"); /* write i2c slv4 ctrl failed */
11353
11354 return 1; /* return error */
11355 }
11356
11357 return 0; /* success return 0 */
11358}
11359
11372{
11373 uint8_t res;
11374 uint8_t prev;
11375
11376 if (handle == NULL) /* check handle */
11377 {
11378 return 2; /* return error */
11379 }
11380 if (handle->inited != 1) /* check handle initialization */
11381 {
11382 return 3; /* return error */
11383 }
11384
11385 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
11386 if (res != 0) /* check result */
11387 {
11388 handle->debug_print("mpu6500: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
11389
11390 return 1; /* return error */
11391 }
11392 *enable = (mpu6500_bool_t)((prev >> 6) & 0x1); /* get the bool */
11393
11394 return 0; /* success return 0 */
11395}
11396
11409{
11410 uint8_t res;
11411 uint8_t prev;
11412
11413 if (handle == NULL) /* check handle */
11414 {
11415 return 2; /* return error */
11416 }
11417 if (handle->inited != 1) /* check handle initialization */
11418 {
11419 return 3; /* return error */
11420 }
11421
11422 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
11423 if (res != 0) /* check result */
11424 {
11425 handle->debug_print("mpu6500: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
11426
11427 return 1; /* return error */
11428 }
11429 prev &= ~(1 << 5); /* clear the settings */
11430 prev |= mode << 5; /* set the mode */
11431 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* write i2c slv4 ctrl */
11432 if (res != 0) /* check result */
11433 {
11434 handle->debug_print("mpu6500: write i2c slv4 ctrl failed.\n"); /* write i2c slv4 ctrl failed */
11435
11436 return 1; /* return error */
11437 }
11438
11439 return 0; /* success return 0 */
11440}
11441
11454{
11455 uint8_t res;
11456 uint8_t prev;
11457
11458 if (handle == NULL) /* check handle */
11459 {
11460 return 2; /* return error */
11461 }
11462 if (handle->inited != 1) /* check handle initialization */
11463 {
11464 return 3; /* return error */
11465 }
11466
11467 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
11468 if (res != 0) /* check result */
11469 {
11470 handle->debug_print("mpu6500: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
11471
11472 return 1; /* return error */
11473 }
11474 *mode = (mpu6500_iic4_transaction_mode_t)((prev >> 5) & 0x1); /* get the mode */
11475
11476 return 0; /* success return 0 */
11477}
11478
11491uint8_t mpu6500_set_iic_delay(mpu6500_handle_t *handle, uint8_t delay)
11492{
11493 uint8_t res;
11494 uint8_t prev;
11495
11496 if (handle == NULL) /* check handle */
11497 {
11498 return 2; /* return error */
11499 }
11500 if (handle->inited != 1) /* check handle initialization */
11501 {
11502 return 3; /* return error */
11503 }
11504 if (delay > 0x1F) /* check the delay */
11505 {
11506 handle->debug_print("mpu6500: delay > 0x1F.\n"); /* delay > 0x1F */
11507
11508 return 4; /* return error */
11509 }
11510
11511 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
11512 if (res != 0) /* check result */
11513 {
11514 handle->debug_print("mpu6500: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
11515
11516 return 1; /* return error */
11517 }
11518 prev &= ~0x1F; /* clear the settings */
11519 prev |= delay; /* set the delay */
11520 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* write i2c slv4 ctrl */
11521 if (res != 0) /* check result */
11522 {
11523 handle->debug_print("mpu6500: write i2c slv4 ctrl failed.\n"); /* write i2c slv4 ctrl failed */
11524
11525 return 1; /* return error */
11526 }
11527
11528 return 0; /* success return 0 */
11529}
11530
11542uint8_t mpu6500_get_iic_delay(mpu6500_handle_t *handle, uint8_t *delay)
11543{
11544 uint8_t res;
11545 uint8_t prev;
11546
11547 if (handle == NULL) /* check handle */
11548 {
11549 return 2; /* return error */
11550 }
11551 if (handle->inited != 1) /* check handle initialization */
11552 {
11553 return 3; /* return error */
11554 }
11555
11556 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
11557 if (res != 0) /* check result */
11558 {
11559 handle->debug_print("mpu6500: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
11560
11561 return 1; /* return error */
11562 }
11563 *delay = prev & 0x1F; /* get the delay */
11564
11565 return 0; /* success return 0 */
11566}
11567
11579uint8_t mpu6500_set_iic4_data_out(mpu6500_handle_t *handle, uint8_t data)
11580{
11581 uint8_t res;
11582
11583 if (handle == NULL) /* check handle */
11584 {
11585 return 2; /* return error */
11586 }
11587 if (handle->inited != 1) /* check handle initialization */
11588 {
11589 return 3; /* return error */
11590 }
11591
11592 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV4_DO, (uint8_t *)&data, 1); /* write i2c slv4 do */
11593 if (res != 0) /* check result */
11594 {
11595 handle->debug_print("mpu6500: write i2c slv4 do failed.\n"); /* write i2c slv4 do fail */
11596
11597 return 1; /* return error */
11598 }
11599
11600 return 0; /* success return 0 */
11601}
11602
11614uint8_t mpu6500_get_iic4_data_out(mpu6500_handle_t *handle, uint8_t *data)
11615{
11616 uint8_t res;
11617
11618 if (handle == NULL) /* check handle */
11619 {
11620 return 2; /* return error */
11621 }
11622 if (handle->inited != 1) /* check handle initialization */
11623 {
11624 return 3; /* return error */
11625 }
11626
11627 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV4_DO, (uint8_t *)data, 1); /* read i2c slv4 do */
11628 if (res != 0) /* check result */
11629 {
11630 handle->debug_print("mpu6500: read i2c slv4 do failed.\n"); /* read i2c slv4 do failed */
11631
11632 return 1; /* return error */
11633 }
11634
11635 return 0; /* success return 0 */
11636}
11637
11649uint8_t mpu6500_set_iic4_data_in(mpu6500_handle_t *handle, uint8_t data)
11650{
11651 uint8_t res;
11652
11653 if (handle == NULL) /* check handle */
11654 {
11655 return 2; /* return error */
11656 }
11657 if (handle->inited != 1) /* check handle initialization */
11658 {
11659 return 3; /* return error */
11660 }
11661
11662 res = a_mpu6500_write(handle, MPU6500_REG_I2C_SLV4_DI, (uint8_t *)&data, 1); /* write i2c slv4 di */
11663 if (res != 0) /* check result */
11664 {
11665 handle->debug_print("mpu6500: write i2c slv4 di failed.\n"); /* write i2c slv4 di failed */
11666
11667 return 1; /* return error */
11668 }
11669
11670 return 0; /* success return 0 */
11671}
11672
11684uint8_t mpu6500_get_iic4_data_in(mpu6500_handle_t *handle, uint8_t *data)
11685{
11686 uint8_t res;
11687
11688 if (handle == NULL) /* check handle */
11689 {
11690 return 2; /* return error */
11691 }
11692 if (handle->inited != 1) /* check handle initialization */
11693 {
11694 return 3; /* return error */
11695 }
11696
11697 res = a_mpu6500_read(handle, MPU6500_REG_I2C_SLV4_DI, (uint8_t *)data, 1); /* read i2c slv4 di */
11698 if (res != 0) /* check result */
11699 {
11700 handle->debug_print("mpu6500: read i2c slv4 di failed.\n"); /* read i2c slv4 di failed */
11701
11702 return 1; /* return error */
11703 }
11704
11705 return 0; /* success return 0 */
11706}
11707
11721uint8_t mpu6500_read_extern_sensor_data(mpu6500_handle_t *handle, uint8_t *data, uint8_t len)
11722{
11723 uint8_t res;
11724
11725 if (handle == NULL) /* check handle */
11726 {
11727 return 2; /* return error */
11728 }
11729 if (handle->inited != 1) /* check handle initialization */
11730 {
11731 return 3; /* return error */
11732 }
11733 if (len > 24) /* check handle initialization */
11734 {
11735 handle->debug_print("mpu6500: len > 24.\n"); /* len > 24 */
11736
11737 return 4; /* return error */
11738 }
11739
11740 res = a_mpu6500_read(handle, MPU6500_REG_EXT_SENS_DATA_00, (uint8_t *)data, len); /* read ext sens data 00 */
11741 if (res != 0) /* check result */
11742 {
11743 handle->debug_print("mpu6500: read ext sens data 00 failed.\n"); /* read ext sens data 00 failed */
11744
11745 return 1; /* return error */
11746 }
11747
11748 return 0; /* success return 0 */
11749}
11750
11764uint8_t mpu6500_set_reg(mpu6500_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
11765{
11766 if (handle == NULL) /* check handle */
11767 {
11768 return 2; /* return error */
11769 }
11770 if (handle->inited != 1) /* check handle initialization */
11771 {
11772 return 3; /* return error */
11773 }
11774
11775 return a_mpu6500_write(handle, reg, buf, len); /* write data */
11776}
11777
11791uint8_t mpu6500_get_reg(mpu6500_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
11792{
11793 if (handle == NULL) /* check handle */
11794 {
11795 return 2; /* return error */
11796 }
11797 if (handle->inited != 1) /* check handle initialization */
11798 {
11799 return 3; /* return error */
11800 }
11801
11802 return a_mpu6500_read(handle, reg, buf, len); /* read data */
11803}
11804
11814{
11815 if (info == NULL) /* check handle */
11816 {
11817 return 2; /* return error */
11818 }
11819
11820 memset(info, 0, sizeof(mpu6500_info_t)); /* initialize mpu6500 info structure */
11821 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
11822 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
11823 strncpy(info->interface, "IIC SPI", 8); /* copy interface name */
11824 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
11825 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
11826 info->max_current_ma = MAX_CURRENT; /* set maximum current */
11827 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
11828 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
11829 info->driver_version = DRIVER_VERSION; /* set driver version */
11830
11831 return 0; /* success return 0 */
11832}
#define MPU6500_REG_I2C_SLV2_REG
#define MPU6500_REG_R_W
#define MPU6500_REG_SIGNAL_PATH_RESET
#define MPU6500_DMP_TAP_MIN_TAP_COUNT
#define MPU6500_REG_TEMP_OUT_H
#define MPU6500_REG_CONFIG
#define MPU6500_REG_I2C_SLV4_DI
#define MPU6500_REG_I2C_SLV2_CTRL
#define MPU6500_REG_INT_STATUS
#define MPU6500_REG_I2C_SLV0_CTRL
#define MPU6500_DMP_TAP_THZ
#define MPU6500_DMP_CFG_6
#define MPU6500_DMP_D_0_104
#define MAX_CURRENT
#define MPU6500_REG_INT_PIN_CFG
#define MPU6500_REG_ACCEL_XOUT_H
#define MPU6500_DMP_TAP_THX
#define MPU6500_DMP_D_0_22
#define MPU6500_DMP_CFG_15
#define MPU6500_REG_SELF_TEST_X_ACCEL
#define MPU6500_REG_SELF_TEST_Y_GYRO
#define MPU6500_REG_I2C_SLV1_ADDR
#define MIN(a, b)
inner function definition
#define MPU6500_DMP_FCFG_2
#define MPU6500_REG_I2C_SLV1_DO
#define MPU6500_REG_PROGRAM_START
#define MPU6500_DMP_D_1_218
#define MPU6500_REG_PWR_MGMT_2
#define MPU6500_REG_I2C_SLV0_REG
#define MPU6500_DMP_TAPW_MIN
#define MPU6500_REG_I2C_SLV4_REG
#define MPU6500_REG_I2C_SLV0_DO
#define MPU6500_DMP_D_1_79
#define MPU6500_REG_I2C_MST_CTRL
#define MPU6500_REG_MOT_DETECT_CTRL
#define MPU6500_REG_I2C_SLV4_ADDR
#define MPU6500_DMP_D_1_36
#define MPU6500_DMP_D_1_88
#define MPU6500_DMP_INT_SRC_ORIENT
#define MPU6500_REG_ZG_OFFSET_H
#define SUPPLY_VOLTAGE_MAX
#define MPU6500_DMP_FCFG_3
#define MPU6500_REG_PWR_MGMT_1
#define MPU6500_DMP_SHAKE_REJECT_TIME
#define MPU6500_REG_SMPRT_DIV
#define MPU6500_REG_FIFO_COUNTH
#define MPU6500_REG_MEM
#define MPU6500_REG_INT_ENABLE
#define MPU6500_DMP_SHAKE_REJECT_THRESH
#define MPU6500_REG_WOM_THR
#define MPU6500_REG_SELF_TEST_Z_ACCEL
#define MPU6500_REG_I2C_SLV0_ADDR
#define MPU6500_REG_EXT_SENS_DATA_00
#define MPU6500_REG_I2C_MST_DELAY_CTRL
#define MPU6500_DMP_CFG_27
#define TEMPERATURE_MAX
#define MPU6500_DMP_CFG_ORIENT_INT
#define MPU6500_REG_ACCEL_CONFIG
#define MPU6500_REG_SELF_TEST_Z_GYRO
#define MPU6500_REG_BANK_SEL
#define MPU6500_DMP_D_1_90
#define MPU6500_REG_I2C_SLV2_ADDR
#define MPU6500_DMP_FCFG_7
#define MPU6500_REG_I2C_SLV3_DO
#define MPU6500_REG_I2C_SLV4_DO
#define MPU6500_DMP_SHAKE_REJECT_TIMEOUT
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define MPU6500_DMP_CFG_GYRO_RAW_DATA
#define SUPPLY_VOLTAGE_MIN
#define MPU6500_DMP_CFG_8
#define MPU6500_REG_I2C_SLV1_CTRL
#define MPU6500_DMP_D_PEDSTD_STEPCTR
#define MPU6500_REG_I2C_SLV2_DO
#define MPU6500_DMP_SAMPLE_RATE
mpu6500 dmp code definition
#define MPU6500_DMP_TAP_TIME
#define MPU6500_DMP_D_1_44
#define MPU6500_DMP_D_EXT_GYRO_BIAS_Z
#define MPU6500_DMP_D_EXT_GYRO_BIAS_X
#define MPU6500_REG_SELF_TEST_X_GYRO
chip register definition
#define MPU6500_REG_GYRO_CONFIG
#define MPU6500_DMP_D_EXT_GYRO_BIAS_Y
#define MPU6500_DMP_INT_SRC_TAP
#define MPU6500_REG_XG_OFFSET_H
#define MPU6500_REG_FIFO_EN
#define MPU6500_REG_YG_OFFSET_H
#define MPU6500_REG_I2C_SLV4_CTRL
#define MPU6500_DMP_D_PEDSTD_TIMECTR
#define MPU6500_DMP_CFG_LP_QUAT
#define MPU6500_DMP_TAP_THY
#define MPU6500_REG_I2C_SLV1_REG
#define MPU6500_DMP_D_1_92
#define MPU6500_REG_I2C_SLV3_CTRL
#define MPU6500_REG_I2C_SLV3_ADDR
#define MPU6500_REG_YA_OFFSET_H
#define CHIP_NAME
chip information definition
#define MPU6500_DMP_GYRO_SF
#define MPU6500_REG_WHO_AM_I
#define DRIVER_VERSION
#define MPU6500_REG_SELF_TEST_Y_ACCEL
#define MPU6500_REG_USER_CTRL
#define MPU6500_REG_XA_OFFSET_H
#define MPU6500_DMP_D_ACCEL_BIAS
#define MPU6500_DMP_QUAT_MAG_SQ_MAX
#define MPU6500_REG_ACCEL_CONFIG2
#define MPU6500_DMP_TAP_TIME_MULTI
#define MPU6500_DMP_D_1_72
#define MPU6500_DMP_CFG_MOTION_BIAS
#define MPU6500_DMP_D_1_40
#define MPU6500_DMP_TAP_THRESH
#define MPU6500_DMP_CFG_20
#define MPU6500_REG_I2C_MST_STATUS
#define MPU6500_REG_LP_ACCEL_ODR
#define MPU6500_DMP_QUAT_MAG_SQ_MIN
#define MPU6500_DMP_FCFG_1
#define MPU6500_DMP_CFG_FIFO_ON_EVENT
#define MPU6500_REG_ZA_OFFSET_H
#define MPU6500_REG_I2C_SLV3_REG
#define MPU6500_DMP_FEATURE_SEND_ANY_GYRO
driver mpu6500 header file
driver mpu6500 code header file
uint8_t mpu6500_set_motion_threshold(mpu6500_handle_t *handle, uint8_t threshold)
set the motion_threshold
uint8_t mpu6500_get_gyroscope_y_test(mpu6500_handle_t *handle, uint8_t *data)
get the gyroscope y test
uint8_t mpu6500_get_fsync_interrupt_level(mpu6500_handle_t *handle, mpu6500_pin_level_t *level)
get the fsync interrupt level
uint8_t mpu6500_set_ptat(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the temperature sensor
mpu6500_accelerometer_low_pass_filter_t
mpu6500 accelerometer low pass filter enumeration definition
uint8_t mpu6500_set_accelerometer_choice(mpu6500_handle_t *handle, uint8_t choice)
set the accelerometer choice
uint8_t mpu6500_set_iic_address(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, uint8_t addr_7bit)
set the iic address
uint8_t mpu6500_set_interface(mpu6500_handle_t *handle, mpu6500_interface_t interface)
set the chip interface
mpu6500_address_t
mpu6500 address enumeration definition
uint8_t mpu6500_get_iic_group_order(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, mpu6500_iic_group_order_t *order)
get the iic group order
uint8_t mpu6500_get_gyroscope_x_test(mpu6500_handle_t *handle, uint8_t *data)
get the gyroscope x test
uint8_t mpu6500_read_extern_sensor_data(mpu6500_handle_t *handle, uint8_t *data, uint8_t len)
read the extern sensor data
uint8_t mpu6500_set_gyro_standby(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the gyro standby
struct mpu6500_info_s mpu6500_info_t
mpu6500 information structure definition
mpu6500_bool_t
mpu6500 bool enumeration definition
uint8_t mpu6500_set_accelerometer_x_offset(mpu6500_handle_t *handle, int16_t offset)
set the accelerometer x offset
uint8_t mpu6500_get_iic_multi_master(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the iic multi master status
uint8_t mpu6500_get_low_pass_filter(mpu6500_handle_t *handle, mpu6500_low_pass_filter_t *filter)
get the low pass filter
uint8_t mpu6500_set_iic_multi_master(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable iic multi master
uint8_t mpu6500_fifo_get(mpu6500_handle_t *handle, uint8_t *buf, uint16_t len)
fifo read bytes
uint8_t mpu6500_set_addr_pin(mpu6500_handle_t *handle, mpu6500_address_t addr_pin)
set the chip address pin
uint8_t mpu6500_accelerometer_offset_convert_to_data(mpu6500_handle_t *handle, int16_t reg, float *mg)
convert the register raw data to the accelerometer offset
uint8_t mpu6500_get_accelerometer_x_offset(mpu6500_handle_t *handle, int16_t *offset)
get the accelerometer x offset
uint8_t mpu6500_get_iic4_interrupt(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the iic4 interrupt status
uint8_t mpu6500_get_gyro_z_offset(mpu6500_handle_t *handle, int16_t *offset)
get the gyro z offset
uint8_t mpu6500_set_iic_wait_for_external_sensor(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable iic wait for external sensor
mpu6500_iic_mode_t
mpu6500 iic mode enumeration definition
uint8_t mpu6500_get_iic_data_out(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, uint8_t *data)
get the iic data out
mpu6500_pin_level_t
mpu6500 pin level enumeration definition
uint8_t mpu6500_set_iic_bypass(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the iic bypass
uint8_t mpu6500_get_gyroscope_choice(mpu6500_handle_t *handle, uint8_t *choice)
get the gyroscope choice
uint8_t mpu6500_get_interrupt_read_clear(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the interrupt reading clear status
uint8_t mpu6500_force_fifo_reset(mpu6500_handle_t *handle)
force reset the fifo
uint8_t mpu6500_set_iic4_data_out(mpu6500_handle_t *handle, uint8_t data)
set the iic4 data out
mpu6500_interrupt_t
mpu6500 interrupt enumeration definition
uint8_t mpu6500_set_accel_compare_with_previous_sample(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable accel compare with previous sample
uint8_t mpu6500_get_accelerometer_z_test(mpu6500_handle_t *handle, uint8_t *data)
get the accelerometer z test
uint8_t mpu6500_set_iic_group_order(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, mpu6500_iic_group_order_t order)
set the iic group order
uint8_t mpu6500_get_iic_register(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, uint8_t *reg)
get the iic register
uint8_t mpu6500_get_accelerometer_range(mpu6500_handle_t *handle, mpu6500_accelerometer_range_t *range)
get the accelerometer range
mpu6500_iic_transaction_mode_t
mpu6500 iic transaction mode enumeration definition
mpu6500_iic_read_mode_t
mpu6500 iic read mode enumeration definition
uint8_t mpu6500_get_iic_bypass(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the iic bypass status
uint8_t mpu6500_set_accelerometer_y_offset(mpu6500_handle_t *handle, int16_t offset)
set the accelerometer y offset
uint8_t mpu6500_set_accelerometer_z_offset(mpu6500_handle_t *handle, int16_t offset)
set the accelerometer z offset
uint8_t mpu6500_accelerometer_offset_convert_to_register(mpu6500_handle_t *handle, float mg, int16_t *reg)
convert the accelerometer offset to the register raw data
uint8_t mpu6500_set_iic_transaction_mode(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, mpu6500_iic_transaction_mode_t mode)
set the iic transaction mode
uint8_t mpu6500_get_accelerometer_test(mpu6500_handle_t *handle, mpu6500_axis_t axis, mpu6500_bool_t *enable)
get the accelerometer test
uint8_t mpu6500_set_fifo(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable fifo
uint8_t mpu6500_get_fifo(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the fifo status
uint8_t mpu6500_get_sleep(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the sleep status
uint8_t mpu6500_get_sample_rate_divider(mpu6500_handle_t *handle, uint8_t *d)
get the sample rate divider
uint8_t mpu6500_get_device_reset(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the device reset status
uint8_t mpu6500_set_interrupt_level(mpu6500_handle_t *handle, mpu6500_pin_level_t level)
set the interrupt level
uint8_t mpu6500_set_iic4_data_in(mpu6500_handle_t *handle, uint8_t data)
set the iic4 data in
uint8_t mpu6500_get_fifo_enable(mpu6500_handle_t *handle, mpu6500_fifo_t fifo, mpu6500_bool_t *enable)
get the fifo function status
uint8_t mpu6500_get_disable_iic_slave(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the iic slave status
uint8_t mpu6500_get_gyroscope_test(mpu6500_handle_t *handle, mpu6500_axis_t axis, mpu6500_bool_t *enable)
get the gyroscope test
mpu6500_clock_source_t
mpu6500 clock source enumeration definition
uint8_t mpu6500_set_fsync_interrupt_level(mpu6500_handle_t *handle, mpu6500_pin_level_t level)
set the fsync interrupt level
uint8_t mpu6500_get_accelerometer_low_pass_filter(mpu6500_handle_t *handle, mpu6500_accelerometer_low_pass_filter_t *filter)
get the accelerometer low pass filter
uint8_t mpu6500_read(mpu6500_handle_t *handle, int16_t(*accel_raw)[3], float(*accel_g)[3], int16_t(*gyro_raw)[3], float(*gyro_dps)[3], uint16_t *len)
read the data
mpu6500_iic_group_order_t
mpu6500 iic group order enumeration definition
uint8_t mpu6500_get_iic_master_reset(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the iic master reset status
uint8_t mpu6500_get_iic4_data_out(mpu6500_handle_t *handle, uint8_t *data)
get the iic4 data out
uint8_t mpu6500_set_iic_clock(mpu6500_handle_t *handle, mpu6500_iic_clock_t clk)
set the iic clock
uint8_t mpu6500_get_clock_source(mpu6500_handle_t *handle, mpu6500_clock_source_t *clock_source)
get the chip clock source
mpu6500_gyroscope_range_t
mpu6500 gyroscope range enumeration definition
uint8_t mpu6500_get_wake_on_motion(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the wake on motion status
uint8_t mpu6500_gyro_offset_convert_to_data(mpu6500_handle_t *handle, int16_t reg, float *dps)
convert the register raw data to the gyro offset
uint8_t mpu6500_get_iic_master(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the iic master status
uint8_t mpu6500_get_accelerometer_y_test(mpu6500_handle_t *handle, uint8_t *data)
get the accelerometer y test
uint8_t mpu6500_get_addr_pin(mpu6500_handle_t *handle, mpu6500_address_t *addr_pin)
get the chip address pin
struct mpu6500_handle_s mpu6500_handle_t
mpu6500 handle structure definition
mpu6500_source_t
mpu6500 source enumeration definition
uint8_t mpu6500_get_iic4_enable(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the iic4 status
uint8_t mpu6500_set_gyroscope_choice(mpu6500_handle_t *handle, uint8_t choice)
set the gyroscope choice
mpu6500_iic_clock_t
mpu6500 iic clock enumeration definition
uint8_t mpu6500_get_fsync_interrupt(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the fsync interrupt status
uint8_t mpu6500_set_iic_read_mode(mpu6500_handle_t *handle, mpu6500_iic_read_mode_t mode)
set the iic read mode
uint8_t mpu6500_get_cycle_wake_up(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the cycle wake up mode status
uint8_t mpu6500_set_iic_delay(mpu6500_handle_t *handle, uint8_t delay)
set the iic delay
uint8_t mpu6500_get_fifo_count(mpu6500_handle_t *handle, uint16_t *count)
get the fifo counter value
uint8_t mpu6500_get_gyro_x_offset(mpu6500_handle_t *handle, int16_t *offset)
get the gyro x offset
uint8_t mpu6500_set_fsync_interrupt(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the fsync interrupt
uint8_t mpu6500_get_interrupt(mpu6500_handle_t *handle, mpu6500_interrupt_t type, mpu6500_bool_t *enable)
get the interrupt status
uint8_t mpu6500_get_iic4_data_in(mpu6500_handle_t *handle, uint8_t *data)
get the iic4 data in
uint8_t mpu6500_get_gyroscope_z_test(mpu6500_handle_t *handle, uint8_t *data)
get the gyroscope z test
uint8_t mpu6500_get_accelerometer_z_offset(mpu6500_handle_t *handle, int16_t *offset)
get the accelerometer z offset
uint8_t mpu6500_get_iic_delay_enable(mpu6500_handle_t *handle, mpu6500_iic_delay_t delay, mpu6500_bool_t *enable)
get the iic delay status
mpu6500_iic_delay_t
mpu6500 iic delay enumeration definition
uint8_t mpu6500_get_ptat(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the temperature sensor status
uint8_t mpu6500_get_iic_byte_swap(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, mpu6500_bool_t *enable)
get the iic byte swap status
uint8_t mpu6500_set_sleep(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the sleep mode
uint8_t mpu6500_set_gyroscope_x_test(mpu6500_handle_t *handle, uint8_t data)
set the gyroscope x test
uint8_t mpu6500_motion_threshold_convert_to_data(mpu6500_handle_t *handle, uint8_t reg, float *mg)
convert the register raw data to the motion threshold
uint8_t mpu6500_sensor_reset(mpu6500_handle_t *handle)
reset all sensors
uint8_t mpu6500_read_temperature(mpu6500_handle_t *handle, int16_t(*raw), float *degrees)
read the temperature
uint8_t mpu6500_set_interrupt_latch(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the interrupt latch
uint8_t mpu6500_get_interrupt_level(mpu6500_handle_t *handle, mpu6500_pin_level_t *level)
get the interrupt level
mpu6500_axis_t
mpu6500 axis enumeration definition
uint8_t mpu6500_get_iic_read_mode(mpu6500_handle_t *handle, mpu6500_iic_read_mode_t *mode)
get the iic read mode
uint8_t mpu6500_get_interface(mpu6500_handle_t *handle, mpu6500_interface_t *interface)
get the chip interface
mpu6500_iic_slave_t
mpu6500 iic slave enumeration definition
uint8_t mpu6500_gyro_offset_convert_to_register(mpu6500_handle_t *handle, float dps, int16_t *reg)
convert the gyro offset to the register raw data
uint8_t mpu6500_get_iic_transaction_mode(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, mpu6500_iic_transaction_mode_t *mode)
get the iic transaction mode
uint8_t mpu6500_get_iic_status(mpu6500_handle_t *handle, uint8_t *status)
get the iic status
uint8_t mpu6500_set_gyroscope_range(mpu6500_handle_t *handle, mpu6500_gyroscope_range_t range)
set the gyroscope range
uint8_t mpu6500_get_iic_enable(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, mpu6500_bool_t *enable)
get the iic status
uint8_t mpu6500_info(mpu6500_info_t *info)
get the chip's information
uint8_t mpu6500_set_clock_source(mpu6500_handle_t *handle, mpu6500_clock_source_t clock_source)
set the chip clock source
uint8_t mpu6500_get_iic_transferred_len(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, uint8_t *len)
get the iic transferred length
uint8_t mpu6500_get_iic_wait_for_external_sensor(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the iic wait for external sensor status
uint8_t mpu6500_set_wake_on_motion(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable wake on motion
uint8_t mpu6500_set_signal_path_reset(mpu6500_handle_t *handle, mpu6500_signal_path_reset_t path)
set the signal path reset
uint8_t mpu6500_set_gyro_x_offset(mpu6500_handle_t *handle, int16_t offset)
set the gyro x offset
uint8_t mpu6500_get_fifo_reset(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the fifo reset status
uint8_t mpu6500_set_interrupt_read_clear(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the interrupt reading clear
uint8_t mpu6500_get_accel_compare_with_previous_sample(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the accel compare with previous sample status
mpu6500_iic4_transaction_mode_t
mpu6500 iic4 transaction mode enumeration definition
uint8_t mpu6500_set_gyro_z_offset(mpu6500_handle_t *handle, int16_t offset)
set the gyro z offset
uint8_t mpu6500_set_gyroscope_z_test(mpu6500_handle_t *handle, uint8_t data)
set the gyroscope z test
mpu6500_fifo_mode
mpu6500 fifo mode enumeration definition
uint8_t mpu6500_set_accelerometer_y_test(mpu6500_handle_t *handle, uint8_t data)
set the accelerometer y test
uint8_t mpu6500_set_iic_byte_swap(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, mpu6500_bool_t enable)
enable or disable the iic byte swap
uint8_t mpu6500_get_gyroscope_range(mpu6500_handle_t *handle, mpu6500_gyroscope_range_t *range)
get the gyroscope range
uint8_t mpu6500_set_interrupt(mpu6500_handle_t *handle, mpu6500_interrupt_t type, mpu6500_bool_t enable)
enable or disable the interrupt
mpu6500_signal_path_reset_t
mpu6500 signal path reset enumeration definition
uint8_t mpu6500_set_gyro_y_offset(mpu6500_handle_t *handle, int16_t offset)
set the gyro y offset
uint8_t mpu6500_set_iic_transferred_len(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, uint8_t len)
set the iic transferred length
uint8_t mpu6500_set_fifo_enable(mpu6500_handle_t *handle, mpu6500_fifo_t fifo, mpu6500_bool_t enable)
enable or disable the fifo function
uint8_t mpu6500_set_accelerometer_x_test(mpu6500_handle_t *handle, uint8_t data)
set the accelerometer x test
uint8_t mpu6500_set_iic4_transaction_mode(mpu6500_handle_t *handle, mpu6500_iic4_transaction_mode_t mode)
set the iic4 transaction mode
uint8_t mpu6500_deinit(mpu6500_handle_t *handle)
close the chip
uint8_t mpu6500_iic_master_reset(mpu6500_handle_t *handle)
reset the iic master controller
uint8_t mpu6500_get_accelerometer_y_offset(mpu6500_handle_t *handle, int16_t *offset)
get the accelerometer y offset
uint8_t mpu6500_set_low_pass_filter(mpu6500_handle_t *handle, mpu6500_low_pass_filter_t filter)
set the low pass filter
uint8_t mpu6500_irq_handler(mpu6500_handle_t *handle)
irq handler
uint8_t mpu6500_get_accelerometer_x_test(mpu6500_handle_t *handle, uint8_t *data)
get the accelerometer x test
uint8_t mpu6500_get_motion_threshold(mpu6500_handle_t *handle, uint8_t *threshold)
get the motion_threshold
mpu6500_extern_sync_t
mpu6500 extern sync enumeration definition
uint8_t mpu6500_get_iic_address(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, uint8_t *addr_7bit)
get the iic address
uint8_t mpu6500_set_extern_sync(mpu6500_handle_t *handle, mpu6500_extern_sync_t sync)
set the extern sync type
uint8_t mpu6500_set_low_power_accel_output_rate(mpu6500_handle_t *handle, mpu6500_low_power_accel_output_rate_t rate)
set the low power accel output rate
uint8_t mpu6500_get_low_power_accel_output_rate(mpu6500_handle_t *handle, mpu6500_low_power_accel_output_rate_t *rate)
get the low power accel output rate
uint8_t mpu6500_set_iic_mode(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, mpu6500_iic_mode_t mode)
set the iic mode
uint8_t mpu6500_get_iic_fifo_enable(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, mpu6500_bool_t *enable)
get the iic fifo status
uint8_t mpu6500_get_iic4_transaction_mode(mpu6500_handle_t *handle, mpu6500_iic4_transaction_mode_t *mode)
get the iic4 transaction mode
uint8_t mpu6500_set_iic4_enable(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the iic4
uint8_t mpu6500_get_iic_delay(mpu6500_handle_t *handle, uint8_t *delay)
get the iic delay
mpu6500_low_power_accel_output_rate_t
mpu6500 low power accel output rate enumeration definition
uint8_t mpu6500_get_sensor_reset(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the sensor reset status
uint8_t mpu6500_set_iic4_interrupt(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the iic4 interrupt
uint8_t mpu6500_set_iic_register(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, uint8_t reg)
set the iic register
uint8_t mpu6500_set_fifo_mode(mpu6500_handle_t *handle, mpu6500_fifo_mode mode)
set the fifo mode
uint8_t mpu6500_set_disable_iic_slave(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the iic slave mode
uint8_t mpu6500_get_gyro_standby(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the gyro standby status
mpu6500_fifo_t
mpu6500 fifo enumeration definition
uint8_t mpu6500_set_iic_master(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the iic master mode
uint8_t mpu6500_set_cycle_wake_up(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the cycle wake up mode
uint8_t mpu6500_get_fifo_mode(mpu6500_handle_t *handle, mpu6500_fifo_mode *mode)
get the fifo mode
mpu6500_accelerometer_range_t
mpu6500 accelerometer range enumeration definition
uint8_t mpu6500_motion_threshold_convert_to_register(mpu6500_handle_t *handle, float mg, uint8_t *reg)
convert the motion threshold to the register raw data
uint8_t mpu6500_init(mpu6500_handle_t *handle)
initialize the chip
uint8_t mpu6500_set_accelerometer_range(mpu6500_handle_t *handle, mpu6500_accelerometer_range_t range)
set the accelerometer range
uint8_t mpu6500_set_accelerometer_test(mpu6500_handle_t *handle, mpu6500_axis_t axis, mpu6500_bool_t enable)
set the accelerometer test
uint8_t mpu6500_set_iic_fifo_enable(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, mpu6500_bool_t enable)
enable or disable the iic fifo
uint8_t mpu6500_fifo_reset(mpu6500_handle_t *handle)
reset the fifo
uint8_t mpu6500_get_interrupt_latch(mpu6500_handle_t *handle, mpu6500_bool_t *enable)
get the interrupt latch status
uint8_t mpu6500_get_extern_sync(mpu6500_handle_t *handle, mpu6500_extern_sync_t *sync)
get the extern sync type
uint8_t mpu6500_get_gyro_y_offset(mpu6500_handle_t *handle, int16_t *offset)
get the gyro y offset
uint8_t mpu6500_device_reset(mpu6500_handle_t *handle)
reset the chip
uint8_t mpu6500_set_gyroscope_y_test(mpu6500_handle_t *handle, uint8_t data)
set the gyroscope y test
uint8_t mpu6500_get_iic_clock(mpu6500_handle_t *handle, mpu6500_iic_clock_t *clk)
get the iic clock
uint8_t mpu6500_get_interrupt_pin_type(mpu6500_handle_t *handle, mpu6500_pin_type_t *type)
get the interrupt pin type
uint8_t mpu6500_get_standby_mode(mpu6500_handle_t *handle, mpu6500_source_t source, mpu6500_bool_t *enable)
get the source mode
uint8_t mpu6500_set_accelerometer_z_test(mpu6500_handle_t *handle, uint8_t data)
set the accelerometer z test
mpu6500_pin_type_t
mpu6500 pin type enumeration definition
uint8_t mpu6500_set_iic_data_out(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, uint8_t data)
set the iic data out
mpu6500_interface_t
mpu6500 interface enumeration definition
uint8_t mpu6500_get_accelerometer_choice(mpu6500_handle_t *handle, uint8_t *choice)
get the accelerometer choice
uint8_t mpu6500_set_iic_delay_enable(mpu6500_handle_t *handle, mpu6500_iic_delay_t delay, mpu6500_bool_t enable)
enable or disable the iic delay
uint8_t mpu6500_set_fifo_1024kb(mpu6500_handle_t *handle)
set fifo 1024kb
uint8_t mpu6500_set_standby_mode(mpu6500_handle_t *handle, mpu6500_source_t source, mpu6500_bool_t enable)
set source into standby mode
uint8_t mpu6500_get_iic_mode(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, mpu6500_iic_mode_t *mode)
get the iic mode
uint8_t mpu6500_fifo_set(mpu6500_handle_t *handle, uint8_t *buf, uint16_t len)
fifo write bytes
uint8_t mpu6500_set_accelerometer_low_pass_filter(mpu6500_handle_t *handle, mpu6500_accelerometer_low_pass_filter_t filter)
set the accelerometer low pass filter
uint8_t mpu6500_get_interrupt_status(mpu6500_handle_t *handle, uint8_t *status)
get the interrupt status
mpu6500_low_pass_filter_t
mpu6500 low pass filter enumeration definition
uint8_t mpu6500_set_interrupt_pin_type(mpu6500_handle_t *handle, mpu6500_pin_type_t type)
set the interrupt pin type
uint8_t mpu6500_set_gyroscope_test(mpu6500_handle_t *handle, mpu6500_axis_t axis, mpu6500_bool_t enable)
set the gyroscope test
uint8_t mpu6500_set_iic_enable(mpu6500_handle_t *handle, mpu6500_iic_slave_t slave, mpu6500_bool_t enable)
enable or disable the iic
uint8_t mpu6500_self_test(mpu6500_handle_t *handle, int32_t gyro_offset_raw[3], int32_t accel_offset_raw[3])
run the self test
uint8_t mpu6500_set_sample_rate_divider(mpu6500_handle_t *handle, uint8_t d)
set the sample rate divider
@ MPU6500_BOOL_FALSE
@ MPU6500_BOOL_TRUE
@ MPU6500_INTERRUPT_DATA_READY
@ MPU6500_INTERRUPT_FIFO_OVERFLOW
@ MPU6500_INTERRUPT_MOTION
@ MPU6500_INTERRUPT_FSYNC_INT
@ MPU6500_INTERRUPT_DMP
@ MPU6500_AXIS_Y
@ MPU6500_AXIS_Z
@ MPU6500_AXIS_X
@ MPU6500_IIC_SLAVE_4
@ MPU6500_IIC_SLAVE_1
@ MPU6500_IIC_SLAVE_2
@ MPU6500_IIC_SLAVE_0
@ MPU6500_IIC_SLAVE_3
@ MPU6500_INTERFACE_IIC
#define MPU6500_DMP_CODE_SIZE
mpu6500 dmp code definition
uint8_t mpu6500_dmp_set_tap_time(mpu6500_handle_t *handle, uint16_t ms)
dmp set the tap time
uint8_t mpu6500_dmp_get_shake_reject_thresh(mpu6500_handle_t *handle, uint16_t *dps)
dmp get the shake reject thresh
uint8_t mpu6500_dmp_get_tap_time(mpu6500_handle_t *handle, uint16_t *ms)
dmp get the tap time
uint8_t mpu6500_dmp_get_fifo_rate(mpu6500_handle_t *handle, uint16_t *rate)
dmp get the fifo rate
uint8_t mpu6500_dmp_set_accel_bias(mpu6500_handle_t *handle, int32_t bias[3])
dmp set the accel bias
uint8_t mpu6500_dmp_get_min_tap_count(mpu6500_handle_t *handle, uint8_t *cnt)
dmp get the min tap count
uint8_t mpu6500_dmp_set_gyro_bias(mpu6500_handle_t *handle, int32_t bias[3])
dmp set the gyro bias
uint8_t mpu6500_dmp_gyro_accel_raw_offset_convert(mpu6500_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
uint8_t mpu6500_dmp_set_tap_thresh(mpu6500_handle_t *handle, mpu6500_axis_t axis, uint16_t mg_ms)
dmp set the tap thresh
uint8_t mpu6500_dmp_set_shake_reject_time(mpu6500_handle_t *handle, uint16_t ms)
dmp set the shake reject time
uint8_t mpu6500_dmp_set_min_tap_count(mpu6500_handle_t *handle, uint8_t cnt)
dmp set the min tap count
uint8_t mpu6500_dmp_set_fifo_rate(mpu6500_handle_t *handle, uint16_t rate)
dmp set the fifo rate
uint8_t mpu6500_dmp_set_orient_callback(mpu6500_handle_t *handle, void(*callback)(uint8_t orientation))
dmp set the orient callback
uint8_t mpu6500_dmp_read(mpu6500_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
uint8_t mpu6500_dmp_set_shake_reject_timeout(mpu6500_handle_t *handle, uint16_t ms)
dmp set the shake reject timeout
mpu6500_dmp_interrupt_mode_t
mpu6500 dmp interrupt mode enumeration definition
uint8_t mpu6500_dmp_get_shake_reject_timeout(mpu6500_handle_t *handle, uint16_t *ms)
dmp get the shake reject timeout
uint8_t mpu6500_dmp_set_tap_callback(mpu6500_handle_t *handle, void(*callback)(uint8_t count, uint8_t direction))
dmp set the tap callback
uint8_t mpu6500_dmp_get_tap_axes(mpu6500_handle_t *handle, mpu6500_axis_t axis, mpu6500_bool_t *enable)
dmp get the tap axes status
uint8_t mpu6500_dmp_set_pedometer_step_count(mpu6500_handle_t *handle, uint32_t count)
dmp set the pedometer step count
uint8_t mpu6500_dmp_set_tap_axes(mpu6500_handle_t *handle, mpu6500_axis_t axis, mpu6500_bool_t enable)
dmp enable or disable the tap axes
uint8_t mpu6500_dmp_get_shake_reject_time(mpu6500_handle_t *handle, uint16_t *ms)
dmp get the shake reject time
uint8_t mpu6500_dmp_load_firmware(mpu6500_handle_t *handle)
load the dmp firmware
uint8_t mpu6500_dmp_get_pedometer_walk_time(mpu6500_handle_t *handle, uint32_t *ms)
dmp get the pedometer walk time
uint8_t mpu6500_dmp_set_feature(mpu6500_handle_t *handle, uint16_t mask)
dmp enable or disable the dmp feature
uint8_t mpu6500_dmp_set_gyro_calibrate(mpu6500_handle_t *handle, mpu6500_bool_t enable)
dmp enable or disable gyro calibrate
uint8_t mpu6500_dmp_get_tap_time_multi(mpu6500_handle_t *handle, uint16_t *ms)
dmp get max time between taps to register as a multi tap
uint8_t mpu6500_dmp_get_tap_thresh(mpu6500_handle_t *handle, mpu6500_axis_t axis, uint16_t *mg_ms)
dmp get the tap thresh
uint8_t mpu6500_dmp_set_orientation(mpu6500_handle_t *handle, int8_t mat[9])
dmp set the orientation
uint8_t mpu6500_dmp_set_pedometer_walk_time(mpu6500_handle_t *handle, uint32_t ms)
dmp set the pedometer walk time
uint8_t mpu6500_dmp_set_interrupt_mode(mpu6500_handle_t *handle, mpu6500_dmp_interrupt_mode_t mode)
dmp set the interrupt mode
uint8_t mpu6500_dmp_set_tap_time_multi(mpu6500_handle_t *handle, uint16_t ms)
dmp set max time between taps to register as a multi tap
uint8_t mpu6500_dmp_set_shake_reject_thresh(mpu6500_handle_t *handle, uint16_t dps)
dmp set the shake reject thresh
uint8_t mpu6500_dmp_set_enable(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the dmp
uint8_t mpu6500_dmp_set_6x_quaternion(mpu6500_handle_t *handle, mpu6500_bool_t enable)
dmp enable or disable generate 6 axis quaternions from dmp
uint8_t mpu6500_dmp_set_3x_quaternion(mpu6500_handle_t *handle, mpu6500_bool_t enable)
dmp enable or disable generate 3 axis quaternions from dmp
uint8_t mpu6500_dmp_get_pedometer_step_count(mpu6500_handle_t *handle, uint32_t *count)
dmp get the pedometer step count
@ MPU6500_DMP_FEATURE_GYRO_CAL
@ MPU6500_DMP_FEATURE_PEDOMETER
@ MPU6500_DMP_FEATURE_SEND_CAL_GYRO
@ MPU6500_DMP_FEATURE_TAP
@ MPU6500_DMP_FEATURE_ORIENT
@ MPU6500_DMP_FEATURE_SEND_RAW_ACCEL
@ MPU6500_DMP_FEATURE_6X_QUAT
@ MPU6500_DMP_FEATURE_3X_QUAT
@ MPU6500_DMP_INTERRUPT_MODE_CONTINUOUS
uint8_t mpu6500_get_reg(mpu6500_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t mpu6500_set_reg(mpu6500_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t buf[1024]
void(* dmp_tap_callback)(uint8_t count, uint8_t direction)
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* spi_read)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* receive_callback)(uint8_t type)
uint8_t(* spi_write)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* spi_deinit)(void)
void(* dmp_orient_callback)(uint8_t orientation)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
uint32_t driver_version
char manufacturer_name[32]