LibDriver MPU6050
Loading...
Searching...
No Matches
driver_mpu6050.c
Go to the documentation of this file.
1
36
37#include "driver_mpu6050.h"
38#include "driver_mpu6050_code.h"
39#include <math.h>
40#include <stdlib.h>
41
45#define CHIP_NAME "TDK MPU6050"
46#define MANUFACTURER_NAME "TDK"
47#define SUPPLY_VOLTAGE_MIN 2.375f
48#define SUPPLY_VOLTAGE_MAX 3.46f
49#define MAX_CURRENT 3.9f
50#define TEMPERATURE_MIN -40.0f
51#define TEMPERATURE_MAX 85.0f
52#define DRIVER_VERSION 1000
53
57#define MPU6050_REG_SELF_TEST_X 0x0D
58#define MPU6050_REG_SELF_TEST_Y 0x0E
59#define MPU6050_REG_SELF_TEST_Z 0x0F
60#define MPU6050_REG_SELF_TEST_A 0x10
61#define MPU6050_REG_SMPRT_DIV 0x19
62#define MPU6050_REG_CONFIG 0x1A
63#define MPU6050_REG_GYRO_CONFIG 0x1B
64#define MPU6050_REG_ACCEL_CONFIG 0x1C
65#define MPU6050_REG_MOTION_THRESHOLD 0x1F
66#define MPU6050_REG_MOTION_DURATION 0x20
67#define MPU6050_REG_FIFO_EN 0x23
68#define MPU6050_REG_I2C_MST_CTRL 0x24
69#define MPU6050_REG_I2C_MST_STATUS 0x36
70#define MPU6050_REG_I2C_MST_DELAY_CTRL 0x67
71#define MPU6050_REG_I2C_SLV0_ADDR 0x25
72#define MPU6050_REG_I2C_SLV0_REG 0x26
73#define MPU6050_REG_I2C_SLV0_CTRL 0x27
74#define MPU6050_REG_I2C_SLV0_DO 0x63
75#define MPU6050_REG_I2C_SLV1_ADDR 0x28
76#define MPU6050_REG_I2C_SLV1_REG 0x29
77#define MPU6050_REG_I2C_SLV1_CTRL 0x2A
78#define MPU6050_REG_I2C_SLV1_DO 0x64
79#define MPU6050_REG_I2C_SLV2_ADDR 0x2B
80#define MPU6050_REG_I2C_SLV2_REG 0x2C
81#define MPU6050_REG_I2C_SLV2_CTRL 0x2D
82#define MPU6050_REG_I2C_SLV2_DO 0x65
83#define MPU6050_REG_I2C_SLV3_ADDR 0x2E
84#define MPU6050_REG_I2C_SLV3_REG 0x2F
85#define MPU6050_REG_I2C_SLV3_CTRL 0x30
86#define MPU6050_REG_I2C_SLV3_DO 0x66
87#define MPU6050_REG_I2C_SLV4_ADDR 0x31
88#define MPU6050_REG_I2C_SLV4_REG 0x32
89#define MPU6050_REG_I2C_SLV4_CTRL 0x34
90#define MPU6050_REG_I2C_SLV4_DO 0x33
91#define MPU6050_REG_I2C_SLV4_DI 0x35
92#define MPU6050_REG_EXT_SENS_DATA_00 0x49
93#define MPU6050_REG_INT_PIN_CFG 0x37
94#define MPU6050_REG_INT_ENABLE 0x38
95#define MPU6050_REG_INT_STATUS 0x3A
96#define MPU6050_REG_ACCEL_XOUT_H 0x3B
97#define MPU6050_REG_ACCEL_XOUT_L 0x3C
98#define MPU6050_REG_ACCEL_YOUT_H 0x3D
99#define MPU6050_REG_ACCEL_YOUT_L 0x3E
100#define MPU6050_REG_ACCEL_ZOUT_H 0x3F
101#define MPU6050_REG_ACCEL_ZOUT_L 0x40
102#define MPU6050_REG_TEMP_OUT_H 0x41
103#define MPU6050_REG_TEMP_OUT_L 0x42
104#define MPU6050_REG_GYRO_XOUT_H 0x43
105#define MPU6050_REG_GYRO_XOUT_L 0x44
106#define MPU6050_REG_GYRO_YOUT_H 0x45
107#define MPU6050_REG_GYRO_YOUT_L 0x46
108#define MPU6050_REG_GYRO_ZOUT_H 0x47
109#define MPU6050_REG_GYRO_ZOUT_L 0x48
110#define MPU6050_REG_SIGNAL_PATH_RESET 0x68
111#define MPU6050_REG_USER_CTRL 0x6A
112#define MPU6050_REG_PWR_MGMT_1 0x6B
113#define MPU6050_REG_PWR_MGMT_2 0x6C
114#define MPU6050_REG_BANK_SEL 0x6D
115#define MPU6050_REG_MEM 0x6F
116#define MPU6050_REG_PROGRAM_START 0x70
117#define MPU6050_REG_FIFO_COUNTH 0x72
118#define MPU6050_REG_FIFO_COUNTL 0x73
119#define MPU6050_REG_R_W 0x74
120#define MPU6050_REG_WHO_AM_I 0x75
121
125#define MPU6050_DMP_SAMPLE_RATE 200
126#define MPU6050_DMP_GYRO_SF (46850825LL * 200 / MPU6050_DMP_SAMPLE_RATE)
127#define MPU6050_DMP_D_PEDSTD_TIMECTR 964
128#define MPU6050_DMP_D_PEDSTD_STEPCTR (768 + 0x60)
129#define MPU6050_DMP_D_1_36 (256 + 36)
130#define MPU6050_DMP_D_1_40 (256 + 40)
131#define MPU6050_DMP_D_1_44 (256 + 44)
132#define MPU6050_DMP_D_1_72 (256 + 72)
133#define MPU6050_DMP_D_1_79 (256 + 79)
134#define MPU6050_DMP_D_1_88 (256 + 88)
135#define MPU6050_DMP_D_1_90 (256 + 90)
136#define MPU6050_DMP_D_1_92 (256 + 92)
137#define MPU6050_DMP_D_1_218 (256 + 218)
138#define MPU6050_DMP_D_0_22 (512 + 22)
139#define MPU6050_DMP_D_0_104 104
140#define MPU6050_DMP_TAPW_MIN 478
141#define MPU6050_DMP_TAP_THX 468
142#define MPU6050_DMP_TAP_THY 472
143#define MPU6050_DMP_TAP_THZ 476
144#define MPU6050_DMP_CFG_6 2753
145#define MPU6050_DMP_CFG_8 2718
146#define MPU6050_DMP_CFG_MOTION_BIAS 1208
147#define MPU6050_DMP_CFG_LP_QUAT 2712
148#define MPU6050_DMP_CFG_FIFO_ON_EVENT 2690
149#define MPU6050_DMP_FCFG_1 1062
150#define MPU6050_DMP_FCFG_2 1066
151#define MPU6050_DMP_FCFG_3 1088
152#define MPU6050_DMP_FCFG_7 1073
153#define MPU6050_DMP_D_EXT_GYRO_BIAS_X (61 * 16)
154#define MPU6050_DMP_D_EXT_GYRO_BIAS_Y (61 * 16 + 4)
155#define MPU6050_DMP_D_EXT_GYRO_BIAS_Z (61 * 16 + 8)
156#define MPU6050_DMP_D_ACCEL_BIAS 660
157#define MPU6050_DMP_FEATURE_SEND_ANY_GYRO (MPU6050_DMP_FEATURE_SEND_RAW_GYRO | \
158 MPU6050_DMP_FEATURE_SEND_CAL_GYRO)
159#define MPU6050_DMP_CFG_15 2727
160#define MPU6050_DMP_CFG_27 2742
161#define MPU6050_DMP_CFG_GYRO_RAW_DATA 2722
162#define MPU6050_DMP_CFG_20 2224
163#define MPU6050_DMP_CFG_ORIENT_INT 1853
164#define MPU6050_DMP_QUAT_ERROR_THRESH (1L << 24)
165#define MPU6050_DMP_QUAT_MAG_SQ_NORMALIZED (1L << 28)
166#define MPU6050_DMP_QUAT_MAG_SQ_MIN (MPU6050_DMP_QUAT_MAG_SQ_NORMALIZED - \
167 MPU6050_DMP_QUAT_ERROR_THRESH)
168#define MPU6050_DMP_QUAT_MAG_SQ_MAX (MPU6050_DMP_QUAT_MAG_SQ_NORMALIZED + \
169 MPU6050_DMP_QUAT_ERROR_THRESH)
170#define MPU6050_DMP_INT_SRC_TAP 0x01
171#define MPU6050_DMP_INT_SRC_ORIENT 0x08
172#define MPU6050_DMP_TAP_THRESH 250
173#define MPU6050_DMP_TAP_MIN_TAP_COUNT 1
174#define MPU6050_DMP_TAP_TIME 100
175#define MPU6050_DMP_TAP_TIME_MULTI 200
176#define MPU6050_DMP_SHAKE_REJECT_THRESH 200
177#define MPU6050_DMP_SHAKE_REJECT_TIME 40
178#define MPU6050_DMP_SHAKE_REJECT_TIMEOUT 10
179
183#define MIN(a, b) (((a) < (b)) ? (a) : (b))
184
196static uint8_t a_mpu6050_iic_read(mpu6050_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
197{
198 if (handle->iic_read(handle->iic_addr, reg, (uint8_t *)buf, len) != 0) /* read data */
199 {
200 return 1; /* return error */
201 }
202 else
203 {
204 return 0; /* success return 0 */
205 }
206}
207
219static uint8_t a_mpu6050_iic_write(mpu6050_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
220{
221 if (handle->iic_write(handle->iic_addr, reg, (uint8_t *)buf, len) != 0) /* write data */
222 {
223 return 1; /* return error */
224 }
225 else
226 {
227 return 0; /* success return 0 */
228 }
229}
230
243static uint8_t a_mpu6050_write_mem(mpu6050_handle_t *handle, uint16_t addr, uint8_t *buf, uint16_t len)
244{
245 uint8_t tmp[2];
246
247 tmp[0] = (addr >> 8) & 0xFF; /* set the addr high */
248 tmp[1] = (addr >> 0) & 0xFF; /* set the addr low */
249
250 if (tmp[1] + len > 256) /* check the range */
251 {
252 return 2; /* return error */
253 }
254
255 if (handle->iic_write(handle->iic_addr, MPU6050_REG_BANK_SEL, (uint8_t *)tmp, 2) != 0) /* write data */
256 {
257 return 1; /* return error */
258 }
259 if (handle->iic_write(handle->iic_addr, MPU6050_REG_MEM, (uint8_t *)buf, len) != 0) /* write data */
260 {
261 return 1; /* return error */
262 }
263
264 return 0; /* success return 0 */
265}
266
279static uint8_t a_mpu6050_read_mem(mpu6050_handle_t *handle, uint16_t addr, uint8_t *buf, uint16_t len)
280{
281 uint8_t tmp[2];
282
283 tmp[0] = (addr >> 8) & 0xFF; /* set the addr high */
284 tmp[1] = (addr >> 0) & 0xFF; /* set the addr low */
285
286 if (tmp[1] + len > 256) /* check the range */
287 {
288 return 2; /* return error */
289 }
290
291 if (handle->iic_write(handle->iic_addr, MPU6050_REG_BANK_SEL, (uint8_t *)tmp, 2) != 0) /* write data */
292 {
293 return 1; /* return error */
294 }
295 if (handle->iic_read(handle->iic_addr, MPU6050_REG_MEM, (uint8_t *)buf, len) != 0) /* read data */
296 {
297 return 1; /* return error */
298 }
299
300 return 0; /* success return 0 */
301}
302
310static uint8_t a_mpu6050_reset_fifo(mpu6050_handle_t *handle)
311{
312 uint8_t res;
313 uint8_t prev;
314 uint8_t int_enable;
315 uint8_t fifo_enable;
316 uint8_t user_ctrl;
317
318 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_ENABLE, &int_enable, 1); /* read the int enable */
319 if (res != 0) /* check the result */
320 {
321 handle->debug_print("mpu6050: read int enable register failed.\n"); /* read int enable register failed */
322
323 return 1; /* return error */
324 }
325 res = a_mpu6050_iic_read(handle, MPU6050_REG_FIFO_EN, &fifo_enable, 1); /* read the fifo enable */
326 if (res != 0) /* check the result */
327 {
328 handle->debug_print("mpu6050: read fifo enable register failed.\n"); /* read fifo enable register failed */
329
330 return 1; /* return error */
331 }
332 res = a_mpu6050_iic_read(handle, MPU6050_REG_USER_CTRL, &user_ctrl, 1); /* read the user ctrl */
333 if (res != 0) /* check the result */
334 {
335 handle->debug_print("mpu6050: read user ctrl register failed.\n"); /* read user ctrl register failed */
336
337 return 1; /* return error */
338 }
339
340 prev = 0; /* set 0 */
341 res = a_mpu6050_iic_write(handle, MPU6050_REG_INT_ENABLE, &prev, 1); /* disable all interrupt */
342 if (res != 0) /* check the result */
343 {
344 handle->debug_print("mpu6050: write int enable register failed.\n"); /* write int enable register failed */
345
346 return 1; /* return error */
347 }
348 prev = 0; /* set 0 */
349 res = a_mpu6050_iic_write(handle, MPU6050_REG_FIFO_EN, &prev, 1); /* disable all fifo */
350 if (res != 0) /* check the result */
351 {
352 handle->debug_print("mpu6050: write fifo enable register failed.\n"); /* write fifo enable register failed */
353
354 return 1; /* return error */
355 }
356 user_ctrl &= ~(1 << 6); /* disable the fifo */
357 user_ctrl &= ~(1 << 7); /* disable the dmp */
358 if (handle->dmp_inited == 1) /* if we use dmp */
359 {
360 user_ctrl |= (1 << 2) | (1 << 3); /* reset the fifo and dmp */
361 }
362 else
363 {
364 user_ctrl |= 1 << 2; /* reset the fifo */
365 }
366 res = a_mpu6050_iic_write(handle, MPU6050_REG_USER_CTRL, &user_ctrl, 1); /* write the user ctrl */
367 if (res != 0) /* check the result */
368 {
369 handle->debug_print("mpu6050: write user ctrl register failed.\n"); /* write user ctrl register failed */
370
371 return 1; /* return error */
372 }
373 handle->delay_ms(50); /* delay 50 ms */
374 if (handle->dmp_inited == 1) /* if we use dmp */
375 {
376 user_ctrl |= (1 << 6) | (1 << 7); /* enable fifo and dmp */
377 }
378 else
379 {
380 user_ctrl |= 1 << 6; /* enable fifo */
381 }
382 res = a_mpu6050_iic_write(handle, MPU6050_REG_USER_CTRL, &user_ctrl, 1); /* write the user ctrl */
383 if (res != 0) /* check the result */
384 {
385 handle->debug_print("mpu6050: write user ctrl register failed.\n"); /* write user ctrl register failed */
386
387 return 1; /* return error */
388 }
389
390 res = a_mpu6050_iic_write(handle, MPU6050_REG_INT_ENABLE, &int_enable, 1); /* restore the int enable */
391 if (res != 0) /* check the result */
392 {
393 handle->debug_print("mpu6050: write int enable register failed.\n"); /* write int enable register failed */
394
395 return 1; /* return error */
396 }
397 res = a_mpu6050_iic_write(handle, MPU6050_REG_FIFO_EN, &fifo_enable, 1); /* restore the fifo enable */
398 if (res != 0) /* check the result */
399 {
400 handle->debug_print("mpu6050: write fifo enable register failed.\n"); /* write fifo enable register failed */
401
402 return 1; /* return error */
403 }
404
405 return 0; /* success return 0 */
406}
407
414static uint16_t a_mpu6050_inv_row_2_scale(int8_t *row)
415{
416 uint16_t b;
417
418 if (row[0] > 0) /* check row 0 */
419 {
420 b = 0; /* set 0 */
421 }
422 else if (row[0] < 0) /* check row 0 */
423 {
424 b = 4; /* set 4 */
425 }
426 else if (row[1] > 0) /* check row 1 */
427 {
428 b = 1; /* set 1 */
429 }
430 else if (row[1] < 0) /* check row 1 */
431 {
432 b = 5; /* set 5 */
433 }
434 else if (row[2] > 0) /* check row 2 */
435 {
436 b = 2; /* set 2 */
437 }
438 else if (row[2] < 0) /* check row 2 */
439 {
440 b = 6; /* set 6 */
441 }
442 else
443 {
444 b = 7; /* set 7 */
445 }
446
447 return b; /* return scale */
448}
449
456static uint16_t a_mpu6050_inv_orientation_matrix_to_scalar(int8_t *mtx)
457{
458 uint16_t scalar;
459
460 scalar = a_mpu6050_inv_row_2_scale(mtx); /* convert the part 0 */
461 scalar |= a_mpu6050_inv_row_2_scale(mtx + 3) << 3; /* convert the part 1 */
462 scalar |= a_mpu6050_inv_row_2_scale(mtx + 6) << 6; /* convert the part 2 */
463
464 return scalar; /* return the scalar */
465}
466
472static void a_mpu6050_dmp_decode_gesture(mpu6050_handle_t *handle, uint8_t gesture[4])
473{
474 uint8_t tap;
475 uint8_t orient;
476
477 orient = gesture[3] & 0xC0; /* set the orient */
478 tap = 0x3F & gesture[3]; /* set the tap */
479 if ((gesture[1] & MPU6050_DMP_INT_SRC_TAP) != 0) /* check the tap output */
480 {
481 uint8_t direction, count;
482
483 direction = tap >> 3; /* get the direction */
484 count = (tap % 8) + 1; /* get the count */
485 if (handle->dmp_tap_callback != NULL) /* check the dmp tap callback */
486 {
487 handle->dmp_tap_callback(direction, count); /* run the dmp tap callback */
488 }
489 }
490 if ((gesture[1] & MPU6050_DMP_INT_SRC_ORIENT) != 0) /* check the orient output */
491 {
492 if (handle->dmp_orient_callback != NULL) /* check the dmp orient callback */
493 {
494 handle->dmp_orient_callback(orient >> 6); /* run the dmp orient callback */
495 }
496 }
497}
498
508static uint8_t a_mpu6050_get_accel_prod_shift(mpu6050_handle_t *handle, float *st_shift)
509{
510 uint8_t res;
511 uint8_t tmp[4];
512 uint8_t shift_code[3];
513 uint8_t i;
514
515 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_X, tmp, 4); /* read the tmp */
516 if (res != 0) /* check the result */
517 {
518 return 1; /* return error */
519 }
520
521 shift_code[0] = ((tmp[0] & 0xE0) >> 3) | ((tmp[3] & 0x30) >> 4); /* shift code 0 */
522 shift_code[1] = ((tmp[1] & 0xE0) >> 3) | ((tmp[3] & 0x0C) >> 2); /* shift code 1 */
523 shift_code[2] = ((tmp[2] & 0xE0) >> 3) | (tmp[3] & 0x03); /* shift code 2 */
524 for (i = 0; i < 3; i++) /* 3 times */
525 {
526 if (!shift_code[i]) /* check the shift code */
527 {
528 st_shift[i] = 0.f; /* set the st shift */
529
530 continue; /* continue */
531 }
532 st_shift[i] = 0.34f; /* set the shift */
533 while ((--shift_code[i]) != 0) /* check the shift code */
534 {
535 st_shift[i] *= 1.034f; /* *1.034f */
536 }
537 }
538
539 return 0; /* success return 0 */
540}
541
552static uint8_t a_mpu6050_accel_self_test(mpu6050_handle_t *handle, int32_t *bias_regular, int32_t *bias_st)
553{
554 uint8_t j, result = 0;
555 float st_shift[3], st_shift_cust, st_shift_var;
556
557 if (a_mpu6050_get_accel_prod_shift(handle, st_shift) != 0) /* get accel prod shift */
558 {
559 return 1; /* return error */
560 }
561 for (j = 0; j < 3; j++) /* 3 times */
562 {
563 st_shift_cust = labs(bias_regular[j] - bias_st[j]) / 65536.f; /* get the st shift cust */
564 if (fabsf(st_shift[j] - 0.0f) > 1e-6f) /* check the st shift */
565 {
566 st_shift_var = st_shift_cust / st_shift[j] - 1.f; /* get the st shift var */
567 if (fabs(st_shift_var) > 0.14f) /* check the st shift var */
568 {
569 result |= 1 << j; /* flag the error */
570 }
571 }
572 else if ((st_shift_cust < 0.3f) || (st_shift_cust > 0.95f)) /* check the result */
573 {
574 result |= 1 << j; /* flag the error */
575 }
576 else
577 {
578 /* do nothing */
579 }
580 }
581
582 return result; /* return the result */
583}
584
595static uint8_t a_mpu6050_gyro_self_test(mpu6050_handle_t *handle, int32_t *bias_regular, int32_t *bias_st)
596{
597 uint8_t res;
598 uint8_t j, result = 0;
599 uint8_t tmp[3];
600 float st_shift, st_shift_cust, st_shift_var;
601
602 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_X, tmp, 3); /* read tmp */
603 if (res != 0) /* check the result */
604 {
605 return 1; /* return error */
606 }
607
608 tmp[0] &= 0x1F; /* set part 0 */
609 tmp[1] &= 0x1F; /* set part 1 */
610 tmp[2] &= 0x1F; /* set part 2 */
611 for (j = 0; j < 3; j++) /* 3 times */
612 {
613 st_shift_cust = labs(bias_regular[j] - bias_st[j]) / 65536.f; /* get the st shift cust */
614 if (tmp[j] != 0) /* check the zero */
615 {
616 st_shift = 3275.f / (32768 / 250); /* set the shift */
617 while ((--tmp[j]) != 0) /* check the zero */
618 {
619 st_shift *= 1.046f; /* *1.046f */
620 }
621 st_shift_var = st_shift_cust / st_shift - 1.f; /* set the shift var */
622 if (fabs(st_shift_var) > 0.14f) /* check the var */
623 {
624 result |= 1 << j; /* flag the error */
625 }
626 }
627 else if ((st_shift_cust < 10.0f) || (st_shift_cust > 105.0f)) /* check the result */
628 {
629 result |= 1 << j; /* flag the error */
630 }
631 else
632 {
633 /* do nothing */
634 }
635 }
636
637 return result; /* return the result */
638}
639
651static uint8_t a_mpu6050_get_st_biases(mpu6050_handle_t *handle,
652 int32_t gyro_offset[3], int32_t accel_offset[3],
653 uint8_t hw_test_enable)
654{
655 uint8_t res;
656 uint16_t cnt;
657 uint16_t pack_cnt;
658 uint16_t i;
659 uint8_t data[12];
660
661 data[0] = 0x01; /* set 0x01 */
662 data[1] = 0x00; /* set 0x00 */
663 res = a_mpu6050_iic_write(handle, MPU6050_REG_PWR_MGMT_1, data, 2); /* write pwr mgmt1 */
664 if (res != 0) /* check the result */
665 {
666 return 1; /* return error */
667 }
668 handle->delay_ms(200); /* delay 200ms */
669 data[0] = 0; /* set 0 */
670 res = a_mpu6050_iic_write(handle, MPU6050_REG_INT_ENABLE, data, 1); /* write int enable */
671 if (res != 0) /* check the result */
672 {
673 return 1; /* return error */
674 }
675 res = a_mpu6050_iic_write(handle, MPU6050_REG_FIFO_EN, data, 1); /* write the fifo enable */
676 if (res != 0) /* check the result */
677 {
678 return 1; /* return error */
679 }
680 res = a_mpu6050_iic_write(handle, MPU6050_REG_PWR_MGMT_1, data, 1); /* write the pwr mgmt 1 */
681 if (res != 0) /* check the result */
682 {
683 return 1; /* return error */
684 }
685 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_MST_CTRL, data, 1); /* write the i2c mst ctrl */
686 if (res != 0) /* check the result */
687 {
688 return 1; /* return error */
689 }
690 res = a_mpu6050_iic_write(handle, MPU6050_REG_USER_CTRL, data, 1); /* write the user ctrl */
691 if (res != 0) /* check the result */
692 {
693 return 1; /* return error */
694 }
695
696 data[0] = 1 << 3 | 1 << 2; /* set fifo and dmp reset */
697 res = a_mpu6050_iic_write(handle, MPU6050_REG_USER_CTRL, data, 1); /* write user ctrl */
698 if (res != 0) /* check the result */
699 {
700 return 1; /* return error */
701 }
702 handle->delay_ms(15); /* delay 15 ms */
703 data[0] = 0x01; /* set 0x01 */
704 res = a_mpu6050_iic_write(handle, MPU6050_REG_CONFIG, data, 1); /* write config */
705 if (res != 0) /* check the result */
706 {
707 return 1; /* return error */
708 }
709 data[0] = 0x00; /* set 0 */
710 res = a_mpu6050_iic_write(handle, MPU6050_REG_SMPRT_DIV, data, 1); /* write div */
711 if (res != 0) /* check the result */
712 {
713 return 1; /* return error */
714 }
715 if (hw_test_enable != 0) /* if enable */
716 {
717 data[0] = 0x00 | 0xE0; /* set 250dps and test */
718 }
719 else
720 {
721 data[0] = 0x00; /* set 250dps */
722 }
723 res = a_mpu6050_iic_write(handle, MPU6050_REG_GYRO_CONFIG, data, 1); /* read the gyro config */
724 if (res != 0) /* check the result */
725 {
726 return 1; /* return error */
727 }
728 if (hw_test_enable != 0) /* if enable */
729 {
730 data[0] = 0x18 | 0xE0; /* enable 2g and test */
731 }
732 else
733 {
734 data[0] = 0x18; /* enable 2g */
735 }
736 res = a_mpu6050_iic_write(handle, MPU6050_REG_ACCEL_CONFIG, data, 1); /* read the accel config */
737 if (res != 0) /* check the result */
738 {
739 return 1; /* return error */
740 }
741 if (hw_test_enable != 0) /* if enable */
742 {
743 handle->delay_ms(200); /* delay 200ms */
744 }
745
746 data[0] = 1 << 6; /* enable fifo */
747 res = a_mpu6050_iic_write(handle, MPU6050_REG_USER_CTRL, data, 1); /* write user ctrl */
748 if (res != 0) /* check the result */
749 {
750 return 1; /* return error */
751 }
752 data[0] = 0x78; /* enable xyz */
753 res = a_mpu6050_iic_write(handle, MPU6050_REG_FIFO_EN, data, 1); /* write fifo enable */
754 if (res != 0) /* check the result */
755 {
756 return 1; /* return error */
757 }
758 handle->delay_ms(50); /* delay 50 ms */
759 data[0] = 0x00; /* set disable */
760 res = a_mpu6050_iic_write(handle, MPU6050_REG_FIFO_EN, data, 1); /* write fifo enable */
761 if (res != 0) /* check the result */
762 {
763 return 1; /* return error */
764 }
765
766 res = a_mpu6050_iic_read(handle, MPU6050_REG_FIFO_COUNTH, data, 2); /* read fifo counter */
767 if (res != 0) /* check the result */
768 {
769 return 1; /* return error */
770 }
771 cnt = ((uint16_t)data[0] << 8) | data[1]; /* set the counter */
772 pack_cnt = cnt / 12; /* set the packet counter */
773
774 gyro_offset[0] = 0; /* gyro offset 0 */
775 gyro_offset[1] = 0; /* gyro offset 1 */
776 gyro_offset[2] = 0; /* gyro offset 2 */
777 accel_offset[0] = 0; /* accel offset 0 */
778 accel_offset[1] = 0; /* accel offset 1 */
779 accel_offset[2] = 0; /* accel offset 2 */
780 for (i = 0; i < pack_cnt; i++) /* packet counter */
781 {
782 int16_t accel_cur[3];
783 int16_t gyro_cur[3];
784
785 res = a_mpu6050_iic_read(handle, MPU6050_REG_R_W, data, 12); /* read data */
786 if (res != 0) /* check the result */
787 {
788 return 1; /* return error */
789 }
790
791 accel_cur[0] = ((int16_t)data[0] << 8) | data[1]; /* accel cur 0 */
792 accel_cur[1] = ((int16_t)data[2] << 8) | data[3]; /* accel cur 1 */
793 accel_cur[2] = ((int16_t)data[4] << 8) | data[5]; /* accel cur 2 */
794 accel_offset[0] += (int32_t)accel_cur[0]; /* accel offset 0 */
795 accel_offset[1] += (int32_t)accel_cur[1]; /* accel offset 1 */
796 accel_offset[2] += (int32_t)accel_cur[2]; /* accel offset 2 */
797 gyro_cur[0] = (((int16_t)data[6] << 8) | data[7]); /* gyro cur 0 */
798 gyro_cur[1] = (((int16_t)data[8] << 8) | data[9]); /* gyro cur 1 */
799 gyro_cur[2] = (((int16_t)data[10] << 8) | data[11]); /* gyro cur 2 */
800 gyro_offset[0] += (int32_t)gyro_cur[0]; /* gyro offset 0 */
801 gyro_offset[1] += (int32_t)gyro_cur[1]; /* gyro offset 1 */
802 gyro_offset[2] += (int32_t)gyro_cur[2]; /* gyro offset 2 */
803 }
804
805 gyro_offset[0] = (int32_t)(((int64_t)gyro_offset[0] << 16) / (32768 / 250) / pack_cnt); /* set the gyro offset 0 */
806 gyro_offset[1] = (int32_t)(((int64_t)gyro_offset[1] << 16) / (32768 / 250) / pack_cnt); /* set the gyro offset 1 */
807 gyro_offset[2] = (int32_t)(((int64_t)gyro_offset[2] << 16) / (32768 / 250) / pack_cnt); /* set the gyro offset 2 */
808 accel_offset[0] = (int32_t)(((int64_t)accel_offset[0] << 16) / (32768 / 16) / pack_cnt); /* set the accel offset 0 */
809 accel_offset[1] = (int32_t)(((int64_t)accel_offset[1] << 16) / (32768 / 16) / pack_cnt); /* set the accel offset 1 */
810 accel_offset[2] = (int32_t)(((int64_t)accel_offset[2] << 16) / (32768 / 16) / pack_cnt); /* set the accel offset 2 */
811 if (accel_offset[2] > 0L) /* check the accel offset */
812 {
813 accel_offset[2] -= 65536L; /* -65536 */
814 }
815 else
816 {
817 accel_offset[2] += 65536L; /* +65536 */
818 }
819
820 return 0; /* success return 0 */
821}
822
837{
838 uint8_t res;
839 uint16_t i;
840 uint16_t size;
841 uint16_t this_write;
842 uint8_t tmp[2];
843 uint8_t cur[16];
844
845 if (handle == NULL) /* check handle */
846 {
847 return 2; /* return error */
848 }
849 if (handle->inited != 1) /* check handle initialization */
850 {
851 return 3; /* return error */
852 }
853 if (handle->dmp_inited != 0) /* check dmp initialization */
854 {
855 handle->debug_print("mpu6050: dmp is running.\n"); /* dmp is running */
856
857 return 4; /* return error */
858 }
859
860 size = MPU6050_DMP_CODE_SIZE; /* set the code size */
861 for (i = 0; i < size; i += this_write) /* code size times */
862 {
863 this_write = MIN(16, size - i); /* get the written size */
864
865 res = a_mpu6050_write_mem(handle, i, (uint8_t *)(gs_mpu6050_dmp_code + i),
866 this_write); /* write data */
867 if (res != 0) /* check result */
868 {
869 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
870
871 return 1; /* return error */
872 }
873 res = a_mpu6050_read_mem(handle, i, cur, this_write); /* read data */
874 if (res != 0) /* check result */
875 {
876 handle->debug_print("mpu6050: read mem failed.\n"); /* read mem failed */
877
878 return 1; /* return error */
879 }
880 if (memcmp(gs_mpu6050_dmp_code + i, cur, this_write) != 0) /* check the code */
881 {
882 handle->debug_print("mpu6050: code compare error.\n"); /* code compare error */
883
884 return 5; /* return error */
885 }
886 }
887 tmp[0] = (0x0400 >> 8) & 0xFF; /* set the addr high */
888 tmp[1] = (0x0400 >> 0) & 0xFF; /* set the addr low */
889
890 if (handle->iic_write(handle->iic_addr, MPU6050_REG_PROGRAM_START,
891 (uint8_t *)tmp, 2) != 0) /* write data */
892 {
893 handle->debug_print("mpu6050: set program start failed.\n"); /* set program start failed */
894
895 return 6; /* return error */
896 }
897 handle->dmp_inited = 1; /* flag the dmp inited bit */
898
899 return 0; /* success return 0 */
900}
901
915{
916 uint8_t res;
917 uint8_t tmp[4];
918
919 if (handle == NULL) /* check handle */
920 {
921 return 2; /* return error */
922 }
923 if (handle->inited != 1) /* check handle initialization */
924 {
925 return 3; /* return error */
926 }
927 if (handle->dmp_inited != 1) /* check dmp initialization */
928 {
929 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
930
931 return 4; /* return error */
932 }
933
934 ms /= 20; /* div 20 */
935 tmp[0] = (uint8_t)((ms >> 24) & 0xFF); /* set part 0 */
936 tmp[1] = (uint8_t)((ms >> 16) & 0xFF); /* set part 1 */
937 tmp[2] = (uint8_t)((ms >> 8) & 0xFF); /* set part 2 */
938 tmp[3] = (uint8_t)(ms & 0xFF); /* set part 3 */
939
940 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_PEDSTD_TIMECTR, tmp, 4); /* write data */
941 if (res != 0) /* check result */
942 {
943 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
944
945 return 1; /* return error */
946 }
947
948 return 0; /* success return 0 */
949}
950
964{
965 uint8_t res;
966 uint8_t tmp[4];
967
968 if (handle == NULL) /* check handle */
969 {
970 return 2; /* return error */
971 }
972 if (handle->inited != 1) /* check handle initialization */
973 {
974 return 3; /* return error */
975 }
976 if (handle->dmp_inited != 1) /* check dmp initialization */
977 {
978 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
979
980 return 4; /* return error */
981 }
982
983 res = a_mpu6050_read_mem(handle, MPU6050_DMP_D_PEDSTD_TIMECTR, tmp, 4); /* read data */
984 if (res != 0) /* check result */
985 {
986 handle->debug_print("mpu6050: read mem failed.\n"); /* read mem failed */
987
988 return 1; /* return error */
989 }
990 *ms = (((uint32_t)tmp[0] << 24) | ((uint32_t)tmp[1] << 16) |
991 ((uint32_t)tmp[2] << 8) | tmp[3]) * 20; /* get the ms */
992
993 return 0; /* success return 0 */
994}
995
1009{
1010 uint8_t res;
1011 uint8_t tmp[4];
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 != 1) /* check dmp initialization */
1022 {
1023 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1024
1025 return 4; /* return error */
1026 }
1027
1028 tmp[0] = (uint8_t)((count >> 24) & 0xFF); /* set part 0 */
1029 tmp[1] = (uint8_t)((count >> 16) & 0xFF); /* set part 1 */
1030 tmp[2] = (uint8_t)((count >> 8) & 0xFF); /* set part 2 */
1031 tmp[3] = (uint8_t)(count & 0xFF); /* set part 3 */
1032
1033 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_PEDSTD_STEPCTR, tmp, 4); /* write data */
1034 if (res != 0) /* check result */
1035 {
1036 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
1037
1038 return 1; /* return error */
1039 }
1040
1041 return 0; /* success return 0 */
1042}
1043
1057{
1058 uint8_t res;
1059 uint8_t tmp[4];
1060
1061 if (handle == NULL) /* check handle */
1062 {
1063 return 2; /* return error */
1064 }
1065 if (handle->inited != 1) /* check handle initialization */
1066 {
1067 return 3; /* return error */
1068 }
1069 if (handle->dmp_inited != 1) /* check dmp initialization */
1070 {
1071 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1072
1073 return 4; /* return error */
1074 }
1075
1076 res = a_mpu6050_read_mem(handle, MPU6050_DMP_D_PEDSTD_STEPCTR, tmp, 4); /* read data */
1077 if (res != 0) /* check result */
1078 {
1079 handle->debug_print("mpu6050: read mem failed.\n"); /* read mem failed */
1080
1081 return 1; /* return error */
1082 }
1083 *count = (((uint32_t)tmp[0] << 24) | ((uint32_t)tmp[1] << 16) |
1084 ((uint32_t)tmp[2] << 8) | tmp[3]); /* get the ms */
1085
1086 return 0; /* success return 0 */
1087}
1088
1102{
1103 uint8_t res;
1104 uint8_t tmp[2];
1105
1106 if (handle == NULL) /* check handle */
1107 {
1108 return 2; /* return error */
1109 }
1110 if (handle->inited != 1) /* check handle initialization */
1111 {
1112 return 3; /* return error */
1113 }
1114 if (handle->dmp_inited != 1) /* check dmp initialization */
1115 {
1116 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1117
1118 return 4; /* return error */
1119 }
1120
1121 ms /= (1000 / MPU6050_DMP_SAMPLE_RATE); /* convert time */
1122 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
1123 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
1124
1125 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_1_88, tmp, 2); /* write data */
1126 if (res != 0) /* check result */
1127 {
1128 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
1129
1130 return 1; /* return error */
1131 }
1132
1133 return 0; /* success return 0 */
1134}
1135
1149{
1150 uint8_t res;
1151 uint8_t tmp[2];
1152
1153 if (handle == NULL) /* check handle */
1154 {
1155 return 2; /* return error */
1156 }
1157 if (handle->inited != 1) /* check handle initialization */
1158 {
1159 return 3; /* return error */
1160 }
1161 if (handle->dmp_inited != 1) /* check dmp initialization */
1162 {
1163 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1164
1165 return 4; /* return error */
1166 }
1167
1168 res = a_mpu6050_read_mem(handle, MPU6050_DMP_D_1_88, tmp, 2); /* read data */
1169 if (res != 0) /* check result */
1170 {
1171 handle->debug_print("mpu6050: read mem failed.\n"); /* read mem failed */
1172
1173 return 1; /* return error */
1174 }
1175 *ms = (uint16_t)((uint16_t)tmp[0] << 8) | tmp[1]; /* get the raw time */
1176 *ms *= (1000 / MPU6050_DMP_SAMPLE_RATE); /* convert time */
1177
1178 return 0; /* success return 0 */
1179}
1180
1194{
1195 uint8_t res;
1196 uint8_t tmp[2];
1197
1198 if (handle == NULL) /* check handle */
1199 {
1200 return 2; /* return error */
1201 }
1202 if (handle->inited != 1) /* check handle initialization */
1203 {
1204 return 3; /* return error */
1205 }
1206 if (handle->dmp_inited != 1) /* check dmp initialization */
1207 {
1208 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1209
1210 return 4; /* return error */
1211 }
1212
1213 ms /= (1000 / MPU6050_DMP_SAMPLE_RATE); /* convert time */
1214 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
1215 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
1216
1217 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_1_90, tmp, 2); /* write data */
1218 if (res != 0) /* check result */
1219 {
1220 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
1221
1222 return 1; /* return error */
1223 }
1224
1225 return 0; /* success return 0 */
1226}
1227
1241{
1242 uint8_t res;
1243 uint8_t tmp[2];
1244
1245 if (handle == NULL) /* check handle */
1246 {
1247 return 2; /* return error */
1248 }
1249 if (handle->inited != 1) /* check handle initialization */
1250 {
1251 return 3; /* return error */
1252 }
1253 if (handle->dmp_inited != 1) /* check dmp initialization */
1254 {
1255 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1256
1257 return 4; /* return error */
1258 }
1259
1260 res = a_mpu6050_read_mem(handle, MPU6050_DMP_D_1_90, tmp, 2); /* read data */
1261 if (res != 0) /* check result */
1262 {
1263 handle->debug_print("mpu6050: read mem failed.\n"); /* read mem failed */
1264
1265 return 1; /* return error */
1266 }
1267 *ms = (uint16_t)((uint16_t)tmp[0] << 8) | tmp[1]; /* get the raw time */
1268 *ms *= (1000 / MPU6050_DMP_SAMPLE_RATE); /* convert time */
1269
1270 return 0; /* success return 0 */
1271}
1272
1286{
1287 uint8_t res;
1288 uint8_t tmp[4];
1289 uint32_t thresh_scaled;
1290
1291 if (handle == NULL) /* check handle */
1292 {
1293 return 2; /* return error */
1294 }
1295 if (handle->inited != 1) /* check handle initialization */
1296 {
1297 return 3; /* return error */
1298 }
1299 if (handle->dmp_inited != 1) /* check dmp initialization */
1300 {
1301 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1302
1303 return 4; /* return error */
1304 }
1305
1306 thresh_scaled = MPU6050_DMP_GYRO_SF / 1000 * dps; /* convert to thresh scaled */
1307 tmp[0] = (uint8_t)(((uint32_t)thresh_scaled >> 24) & 0xFF); /* set the part 3 */
1308 tmp[1] = (uint8_t)(((uint32_t)thresh_scaled >> 16) & 0xFF); /* set the part 2 */
1309 tmp[2] = (uint8_t)(((uint32_t)thresh_scaled >> 8) & 0xFF); /* set the part 1 */
1310 tmp[3] = (uint8_t)((uint32_t)thresh_scaled & 0xFF); /* set the part 0 */
1311
1312 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_1_92, tmp, 4); /* write data */
1313 if (res != 0) /* check result */
1314 {
1315 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
1316
1317 return 1; /* return error */
1318 }
1319
1320 return 0; /* success return 0 */
1321}
1322
1336{
1337 uint8_t res;
1338 uint8_t tmp[4];
1339 uint32_t thresh_scaled;
1340
1341 if (handle == NULL) /* check handle */
1342 {
1343 return 2; /* return error */
1344 }
1345 if (handle->inited != 1) /* check handle initialization */
1346 {
1347 return 3; /* return error */
1348 }
1349 if (handle->dmp_inited != 1) /* check dmp initialization */
1350 {
1351 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1352
1353 return 4; /* return error */
1354 }
1355
1356 res = a_mpu6050_read_mem(handle, MPU6050_DMP_D_1_92, tmp, 4); /* read data */
1357 if (res != 0) /* check result */
1358 {
1359 handle->debug_print("mpu6050: read mem failed.\n"); /* read mem failed */
1360
1361 return 1; /* return error */
1362 }
1363 thresh_scaled = (((uint32_t)tmp[0] << 24) | ((uint32_t)tmp[1] << 16) |
1364 ((uint32_t)tmp[2] << 8) | tmp[3]); /* get the thresh scaled */
1365 *dps = (uint16_t)((float)(thresh_scaled) /
1366 ((float)(MPU6050_DMP_GYRO_SF) / 1000.0f)); /* convert the thresh scaled */
1367
1368 return 0; /* success return 0 */
1369}
1370
1384{
1385 uint8_t res;
1386 uint8_t tmp[2];
1387
1388 if (handle == NULL) /* check handle */
1389 {
1390 return 2; /* return error */
1391 }
1392 if (handle->inited != 1) /* check handle initialization */
1393 {
1394 return 3; /* return error */
1395 }
1396 if (handle->dmp_inited != 1) /* check dmp initialization */
1397 {
1398 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1399
1400 return 4; /* return error */
1401 }
1402
1403 ms /= (1000 / MPU6050_DMP_SAMPLE_RATE); /* convert time */
1404 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
1405 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
1406
1407 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_1_218, tmp, 2); /* write data */
1408 if (res != 0) /* check result */
1409 {
1410 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
1411
1412 return 1; /* return error */
1413 }
1414
1415 return 0; /* success return 0 */
1416}
1417
1431{
1432 uint8_t res;
1433 uint8_t tmp[2];
1434
1435 if (handle == NULL) /* check handle */
1436 {
1437 return 2; /* return error */
1438 }
1439 if (handle->inited != 1) /* check handle initialization */
1440 {
1441 return 3; /* return error */
1442 }
1443 if (handle->dmp_inited != 1) /* check dmp initialization */
1444 {
1445 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1446
1447 return 4; /* return error */
1448 }
1449
1450 res = a_mpu6050_read_mem(handle, MPU6050_DMP_D_1_218, tmp, 2); /* read data */
1451 if (res != 0) /* check result */
1452 {
1453 handle->debug_print("mpu6050: read mem failed.\n"); /* read mem failed */
1454
1455 return 1; /* return error */
1456 }
1457 *ms = (uint16_t)((uint16_t)tmp[0] << 8) | tmp[1]; /* get the raw time */
1458 *ms *= (1000 / MPU6050_DMP_SAMPLE_RATE); /* convert time */
1459
1460 return 0; /* success return 0 */
1461}
1462
1475uint8_t mpu6050_dmp_set_tap_time(mpu6050_handle_t *handle, uint16_t ms)
1476{
1477 uint8_t res;
1478 uint8_t tmp[2];
1479
1480 if (handle == NULL) /* check handle */
1481 {
1482 return 2; /* return error */
1483 }
1484 if (handle->inited != 1) /* check handle initialization */
1485 {
1486 return 3; /* return error */
1487 }
1488 if (handle->dmp_inited != 1) /* check dmp initialization */
1489 {
1490 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1491
1492 return 4; /* return error */
1493 }
1494
1495 ms /= (1000 / MPU6050_DMP_SAMPLE_RATE); /* convert time */
1496 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
1497 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
1498
1499 res = a_mpu6050_write_mem(handle, MPU6050_DMP_TAPW_MIN, tmp, 2); /* write data */
1500 if (res != 0) /* check result */
1501 {
1502 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
1503
1504 return 1; /* return error */
1505 }
1506
1507 return 0; /* success return 0 */
1508}
1509
1522uint8_t mpu6050_dmp_get_tap_time(mpu6050_handle_t *handle, uint16_t *ms)
1523{
1524 uint8_t res;
1525 uint8_t tmp[2];
1526
1527 if (handle == NULL) /* check handle */
1528 {
1529 return 2; /* return error */
1530 }
1531 if (handle->inited != 1) /* check handle initialization */
1532 {
1533 return 3; /* return error */
1534 }
1535 if (handle->dmp_inited != 1) /* check dmp initialization */
1536 {
1537 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1538
1539 return 4; /* return error */
1540 }
1541
1542 res = a_mpu6050_read_mem(handle, MPU6050_DMP_TAPW_MIN, tmp, 2); /* read data */
1543 if (res != 0) /* check result */
1544 {
1545 handle->debug_print("mpu6050: read mem failed.\n"); /* read mem failed */
1546
1547 return 1; /* return error */
1548 }
1549 *ms = (uint16_t)((uint16_t)tmp[0] << 8) | tmp[1]; /* get the raw time */
1550 *ms *= (1000 / MPU6050_DMP_SAMPLE_RATE); /* convert time */
1551
1552 return 0; /* success return 0 */
1553}
1554
1569{
1570 uint8_t res;
1571 uint8_t tmp;
1572
1573 if (handle == NULL) /* check handle */
1574 {
1575 return 2; /* return error */
1576 }
1577 if (handle->inited != 1) /* check handle initialization */
1578 {
1579 return 3; /* return error */
1580 }
1581 if (handle->dmp_inited != 1) /* check dmp initialization */
1582 {
1583 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1584
1585 return 4; /* return error */
1586 }
1587 if ((cnt < 1) || (cnt > 4)) /* check cnt */
1588 {
1589 handle->debug_print("mpu6050: cnt must be between 1 and 4.\n"); /* cnt must be between 1 and 4 */
1590
1591 return 5; /* return error */
1592 }
1593
1594 tmp = cnt - 1; /* set the counter */
1595 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_1_79, &tmp, 1); /* write data */
1596 if (res != 0) /* check result */
1597 {
1598 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
1599
1600 return 1; /* return error */
1601 }
1602
1603 return 0; /* success return 0 */
1604}
1605
1619{
1620 uint8_t res;
1621 uint8_t tmp;
1622
1623 if (handle == NULL) /* check handle */
1624 {
1625 return 2; /* return error */
1626 }
1627 if (handle->inited != 1) /* check handle initialization */
1628 {
1629 return 3; /* return error */
1630 }
1631 if (handle->dmp_inited != 1) /* check dmp initialization */
1632 {
1633 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1634
1635 return 4; /* return error */
1636 }
1637
1638 res = a_mpu6050_read_mem(handle, MPU6050_DMP_D_1_79, &tmp, 1); /* read data */
1639 if (res != 0) /* check result */
1640 {
1641 handle->debug_print("mpu6050: read mem failed.\n"); /* read mem failed */
1642
1643 return 1; /* return error */
1644 }
1645 *cnt = tmp + 1; /* set the counter */
1646
1647 return 0; /* success return 0 */
1648}
1649
1663{
1664 uint8_t res;
1665
1666 if (handle == NULL) /* check handle */
1667 {
1668 return 2; /* return error */
1669 }
1670 if (handle->inited != 1) /* check handle initialization */
1671 {
1672 return 3; /* return error */
1673 }
1674 if (handle->dmp_inited != 1) /* check dmp initialization */
1675 {
1676 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1677
1678 return 4; /* return error */
1679 }
1680
1681 if (enable != 0) /* enable */
1682 {
1683 uint8_t regs[9] = {0xb8, 0xaa, 0xb3, 0x8d, 0xb4, 0x98, 0x0d, 0x35, 0x5d};
1684
1685 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_MOTION_BIAS, regs, 9); /* write data */
1686 if (res != 0) /* check result */
1687 {
1688 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
1689
1690 return 1; /* return error */
1691 }
1692 handle->mask |= MPU6050_DMP_FEATURE_GYRO_CAL; /* set the mask */
1693
1694 return 0; /* success return 0 */
1695 }
1696 else /* disable */
1697 {
1698 uint8_t regs[9] = {0xb8, 0xaa, 0xaa, 0xaa, 0xb0, 0x88, 0xc3, 0xc5, 0xc7};
1699
1700 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_MOTION_BIAS, regs, 9); /* write data */
1701 if (res != 0) /* check result */
1702 {
1703 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
1704
1705 return 1; /* return error */
1706 }
1707 handle->mask &= ~MPU6050_DMP_FEATURE_GYRO_CAL; /* set the mask */
1708
1709 return 0; /* success return 0 */
1710 }
1711}
1712
1726{
1727 uint8_t res;
1728
1729 if (handle == NULL) /* check handle */
1730 {
1731 return 2; /* return error */
1732 }
1733 if (handle->inited != 1) /* check handle initialization */
1734 {
1735 return 3; /* return error */
1736 }
1737 if (handle->dmp_inited != 1) /* check dmp initialization */
1738 {
1739 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1740
1741 return 4; /* return error */
1742 }
1743
1744 if (enable != 0) /* enable */
1745 {
1746 uint8_t regs[4] = {0xC0, 0xC2, 0xC4, 0xC6};
1747
1748 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_LP_QUAT, regs, 4); /* write data */
1749 if (res != 0) /* check result */
1750 {
1751 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
1752
1753 return 1; /* return error */
1754 }
1755 res = a_mpu6050_reset_fifo(handle); /* reset the fifo */
1756 if (res != 0) /* check result */
1757 {
1758 handle->debug_print("mpu6050: reset fifo failed.\n"); /* reset fifo failed */
1759
1760 return 1; /* return error */
1761 }
1762 handle->mask |= MPU6050_DMP_FEATURE_3X_QUAT; /* set the mask */
1763
1764 return 0; /* success return 0 */
1765 }
1766 else /* disable */
1767 {
1768 uint8_t regs[4] = {0x8B, 0x8B, 0x8B, 0x8B};
1769
1770 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_LP_QUAT, regs, 4); /* write data */
1771 if (res != 0) /* check result */
1772 {
1773 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
1774
1775 return 1; /* return error */
1776 }
1777 res = a_mpu6050_reset_fifo(handle); /* reset the fifo */
1778 if (res != 0) /* check result */
1779 {
1780 handle->debug_print("mpu6050: reset fifo failed.\n"); /* reset fifo failed */
1781
1782 return 1; /* return error */
1783 }
1784 handle->mask &= ~MPU6050_DMP_FEATURE_3X_QUAT; /* set the mask */
1785
1786 return 0; /* success return 0 */
1787 }
1788}
1789
1803{
1804 uint8_t res;
1805
1806 if (handle == NULL) /* check handle */
1807 {
1808 return 2; /* return error */
1809 }
1810 if (handle->inited != 1) /* check handle initialization */
1811 {
1812 return 3; /* return error */
1813 }
1814 if (handle->dmp_inited != 1) /* check dmp initialization */
1815 {
1816 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1817
1818 return 4; /* return error */
1819 }
1820
1821 if (enable != 0) /* enable */
1822 {
1823 uint8_t regs[4] = {0x20, 0x28, 0x30, 0x38};
1824
1825 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_8, regs, 4); /* write data */
1826 if (res != 0) /* check result */
1827 {
1828 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
1829
1830 return 1; /* return error */
1831 }
1832 res = a_mpu6050_reset_fifo(handle); /* reset the fifo */
1833 if (res != 0) /* check result */
1834 {
1835 handle->debug_print("mpu6050: reset fifo failed.\n"); /* reset fifo failed */
1836
1837 return 1; /* return error */
1838 }
1839 handle->mask |= MPU6050_DMP_FEATURE_6X_QUAT; /* set the mask */
1840
1841 return 0; /* success return 0 */
1842 }
1843 else /* disable */
1844 {
1845 uint8_t regs[4] = {0xA3, 0xA3, 0xA3, 0xA3};
1846
1847 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_8, regs, 4); /* write data */
1848 if (res != 0) /* check result */
1849 {
1850 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
1851
1852 return 1; /* return error */
1853 }
1854 res = a_mpu6050_reset_fifo(handle); /* reset the fifo */
1855 if (res != 0) /* check result */
1856 {
1857 handle->debug_print("mpu6050: reset fifo failed.\n"); /* reset fifo failed */
1858
1859 return 1; /* return error */
1860 }
1861 handle->mask &= ~MPU6050_DMP_FEATURE_6X_QUAT; /* set the mask */
1862
1863 return 0; /* success return 0 */
1864 }
1865}
1866
1880{
1881 uint8_t res;
1882
1883 if (handle == NULL) /* check handle */
1884 {
1885 return 2; /* return error */
1886 }
1887 if (handle->inited != 1) /* check handle initialization */
1888 {
1889 return 3; /* return error */
1890 }
1891 if (handle->dmp_inited != 1) /* check dmp initialization */
1892 {
1893 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1894
1895 return 4; /* return error */
1896 }
1897
1898 if (mode == MPU6050_DMP_INTERRUPT_MODE_CONTINUOUS) /* continuous */
1899 {
1900 uint8_t regs_continuous[11] = {0xd8, 0xb1, 0xb9,
1901 0xf3, 0x8b, 0xa3,
1902 0x91, 0xb6, 0x09,
1903 0xb4, 0xd9};
1904
1905 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_FIFO_ON_EVENT,
1906 (uint8_t *)regs_continuous, 11); /* write data */
1907 if (res != 0) /* check result */
1908 {
1909 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
1910
1911 return 1; /* return error */
1912 }
1913
1914 return 0; /* success return 0 */
1915 }
1916 else /* disable */
1917 {
1918 uint8_t regs_gesture[11] = {0xda, 0xb1, 0xb9,
1919 0xf3, 0x8b, 0xa3,
1920 0x91, 0xb6, 0xda,
1921 0xb4, 0xda};
1922
1923 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_FIFO_ON_EVENT,
1924 (uint8_t *)regs_gesture, 11); /* write data */
1925 if (res != 0) /* check result */
1926 {
1927 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
1928
1929 return 1; /* return error */
1930 }
1931
1932 return 0; /* success return 0 */
1933 }
1934}
1935
1948uint8_t mpu6050_dmp_set_gyro_bias(mpu6050_handle_t *handle, int32_t bias[3])
1949{
1950 uint8_t res;
1951 uint8_t regs[4];
1952 int32_t gyro_bias_body[3];
1953
1954 if (handle == NULL) /* check handle */
1955 {
1956 return 2; /* return error */
1957 }
1958 if (handle->inited != 1) /* check handle initialization */
1959 {
1960 return 3; /* return error */
1961 }
1962 if (handle->dmp_inited != 1) /* check dmp initialization */
1963 {
1964 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
1965
1966 return 4; /* return error */
1967 }
1968
1969 gyro_bias_body[0] = bias[handle->orient & 3]; /* set the body 0 */
1970 if ((handle->orient & 4) != 0) /* check bit 3 */
1971 {
1972 gyro_bias_body[0] *= -1; /* *(-1) */
1973 }
1974 gyro_bias_body[1] = bias[(handle->orient >> 3) & 3]; /* set the body 1 */
1975 if ((handle->orient & 0x20) != 0) /* check bit 6 */
1976 {
1977 gyro_bias_body[1] *= -1; /* *(-1) */
1978 }
1979 gyro_bias_body[2] = bias[(handle->orient >> 6) & 3]; /* set the body 2 */
1980 if ((handle->orient & 0x100) != 0) /* check bit 9 */
1981 {
1982 gyro_bias_body[2] *= -1; /* *(-1) */
1983 }
1984
1985 gyro_bias_body[0] = (int32_t)(((int64_t)gyro_bias_body[0] * MPU6050_DMP_GYRO_SF) >> 30); /* set body 0 */
1986 gyro_bias_body[1] = (int32_t)(((int64_t)gyro_bias_body[1] * MPU6050_DMP_GYRO_SF) >> 30); /* set body 1 */
1987 gyro_bias_body[2] = (int32_t)(((int64_t)gyro_bias_body[2] * MPU6050_DMP_GYRO_SF) >> 30); /* set body 2 */
1988
1989 regs[0] = (uint8_t)((gyro_bias_body[0] >> 24) & 0xFF); /* set part 0 */
1990 regs[1] = (uint8_t)((gyro_bias_body[0] >> 16) & 0xFF); /* set part 1 */
1991 regs[2] = (uint8_t)((gyro_bias_body[0] >> 8) & 0xFF); /* set part 2 */
1992 regs[3] = (uint8_t)(gyro_bias_body[0] & 0xFF); /* set part 3 */
1993 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_EXT_GYRO_BIAS_X, (uint8_t *)regs, 4); /* write data */
1994 if (res != 0) /* check result */
1995 {
1996 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
1997
1998 return 1; /* return error */
1999 }
2000 regs[0] = (uint8_t)((gyro_bias_body[1] >> 24) & 0xFF); /* set part 0 */
2001 regs[1] = (uint8_t)((gyro_bias_body[1] >> 16) & 0xFF); /* set part 1 */
2002 regs[2] = (uint8_t)((gyro_bias_body[1] >> 8) & 0xFF); /* set part 2 */
2003 regs[3] = (uint8_t)(gyro_bias_body[1] & 0xFF); /* set part 3 */
2004 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_EXT_GYRO_BIAS_Y, (uint8_t *)regs, 4); /* write data */
2005 if (res != 0) /* check result */
2006 {
2007 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2008
2009 return 1; /* return error */
2010 }
2011 regs[0] = (uint8_t)((gyro_bias_body[2] >> 24) & 0xFF); /* set part 0 */
2012 regs[1] = (uint8_t)((gyro_bias_body[2] >> 16) & 0xFF); /* set part 1 */
2013 regs[2] = (uint8_t)((gyro_bias_body[2] >> 8) & 0xFF); /* set part 2 */
2014 regs[3] = (uint8_t)(gyro_bias_body[2] & 0xFF); /* set part 3 */
2015 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_EXT_GYRO_BIAS_Z, (uint8_t *)regs, 4); /* write data */
2016 if (res != 0) /* check result */
2017 {
2018 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2019
2020 return 1; /* return error */
2021 }
2022
2023 return 0; /* success return 0 */
2024}
2025
2038uint8_t mpu6050_dmp_set_accel_bias(mpu6050_handle_t *handle, int32_t bias[3])
2039{
2040 uint8_t res;
2041 uint8_t prev;
2042 uint8_t range;
2043 int32_t accel_bias_body[3];
2044 uint8_t regs[12];
2045 int64_t accel_sf;
2046
2047 if (handle == NULL) /* check handle */
2048 {
2049 return 2; /* return error */
2050 }
2051 if (handle->inited != 1) /* check handle initialization */
2052 {
2053 return 3; /* return error */
2054 }
2055 if (handle->dmp_inited != 1) /* check dmp initialization */
2056 {
2057 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
2058
2059 return 4; /* return error */
2060 }
2061
2062 res = a_mpu6050_iic_read(handle, MPU6050_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* read accelerometer config */
2063 if (res != 0) /* check result */
2064 {
2065 handle->debug_print("mpu6050: read accelerometer config failed.\n"); /* read accelerometer config failed */
2066
2067 return 1; /* return error */
2068 }
2069 range = ((prev >> 3) & 0x3); /* get the range */
2070 if (range == 0) /* if 2g */
2071 {
2072 accel_sf = (int64_t)16384 << 15; /* set the accel sf */
2073 }
2074 else if (range == 1) /* if 4g */
2075 {
2076 accel_sf = (int64_t)8192 << 15; /* set the accel sf */
2077 }
2078 else if (range == 2) /* if 8g */
2079 {
2080 accel_sf = (int64_t)4096 << 15; /* set the accel sf */
2081 }
2082 else /* if 16g */
2083 {
2084 accel_sf = (int64_t)2048 << 15; /* set the accel sf */
2085 }
2086
2087 accel_bias_body[0] = bias[handle->orient & 3]; /* set the bias body 0 */
2088 if ((handle->orient & 4) != 0) /* check the orient */
2089 {
2090 accel_bias_body[0] *= -1; /* *(-1) */
2091 }
2092 accel_bias_body[1] = bias[(handle->orient >> 3) & 3]; /* set the bias body 1 */
2093 if ((handle->orient & 0x20) != 0) /* check the orient */
2094 {
2095 accel_bias_body[1] *= -1; /* *(-1) */
2096 }
2097 accel_bias_body[2] = bias[(handle->orient >> 6) & 3]; /* set the bias body 2 */
2098 if ((handle->orient & 0x100) != 0) /* check the orient */
2099 {
2100 accel_bias_body[2] *= -1; /* *(-1) */
2101 }
2102
2103 accel_bias_body[0] = (int32_t)(((int64_t)accel_bias_body[0] * accel_sf) >> 30); /* set the bias body 0 */
2104 accel_bias_body[1] = (int32_t)(((int64_t)accel_bias_body[1] * accel_sf) >> 30); /* set the bias body 1 */
2105 accel_bias_body[2] = (int32_t)(((int64_t)accel_bias_body[2] * accel_sf) >> 30); /* set the bias body 2 */
2106 regs[0] = (uint8_t)((accel_bias_body[0] >> 24) & 0xFF); /* set reg 0 */
2107 regs[1] = (uint8_t)((accel_bias_body[0] >> 16) & 0xFF); /* set reg 1 */
2108 regs[2] = (uint8_t)((accel_bias_body[0] >> 8) & 0xFF); /* set reg 2 */
2109 regs[3] = (uint8_t)(accel_bias_body[0] & 0xFF); /* set reg 3 */
2110 regs[4] = (uint8_t)((accel_bias_body[1] >> 24) & 0xFF); /* set reg 4 */
2111 regs[5] = (uint8_t)((accel_bias_body[1] >> 16) & 0xFF); /* set reg 5 */
2112 regs[6] = (uint8_t)((accel_bias_body[1] >> 8) & 0xFF); /* set reg 6 */
2113 regs[7] = (uint8_t)(accel_bias_body[1] & 0xFF); /* set reg 7 */
2114 regs[8] = (uint8_t)((accel_bias_body[2] >> 24) & 0xFF); /* set reg 8 */
2115 regs[9] = (uint8_t)((accel_bias_body[2] >> 16) & 0xFF); /* set reg 9 */
2116 regs[10] = (uint8_t)((accel_bias_body[2] >> 8) & 0xFF); /* set reg 10 */
2117 regs[11] = (uint8_t)(accel_bias_body[2] & 0xFF); /* set reg 11 */
2118 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_ACCEL_BIAS, (uint8_t *)regs, 12); /* write data */
2119 if (res != 0) /* check result */
2120 {
2121 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2122
2123 return 1; /* return error */
2124 }
2125
2126 return 0; /* success return 0 */
2127}
2128
2141uint8_t mpu6050_dmp_set_orientation(mpu6050_handle_t *handle, int8_t mat[9])
2142{
2143 uint8_t gyro_axes[4] = {0x4C, 0xCD, 0x6C, 0x00};
2144 uint8_t accel_axes[4] = {0x0C, 0xC9, 0x2C, 0x00 };
2145 uint8_t gyro_sign[4] = {0x36, 0x56, 0x76, 0x00 };
2146 uint8_t accel_sign[4] = {0x26, 0x46, 0x66, 0x00 };
2147 uint8_t res;
2148 uint8_t gyro_regs[3];
2149 uint8_t accel_regs[3];
2150 uint16_t orient;
2151
2152 if (handle == NULL) /* check handle */
2153 {
2154 return 2; /* return error */
2155 }
2156 if (handle->inited != 1) /* check handle initialization */
2157 {
2158 return 3; /* return error */
2159 }
2160 if (handle->dmp_inited != 1) /* check dmp initialization */
2161 {
2162 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
2163
2164 return 4; /* return error */
2165 }
2166
2167 orient = a_mpu6050_inv_orientation_matrix_to_scalar(mat); /* inv orientation matrix to scalar */
2168 gyro_regs[0] = gyro_axes[orient & 3]; /* set the gyro regs 0 */
2169 gyro_regs[1] = gyro_axes[(orient >> 3) & 3]; /* set the gyro regs 1 */
2170 gyro_regs[2] = gyro_axes[(orient >> 6) & 3]; /* set the gyro regs 2 */
2171 accel_regs[0] = accel_axes[orient & 3]; /* set the accel regs 0 */
2172 accel_regs[1] = accel_axes[(orient >> 3) & 3]; /* set the accel regs 1 */
2173 accel_regs[2] = accel_axes[(orient >> 6) & 3]; /* set the accel regs 2 */
2174 res = a_mpu6050_write_mem(handle, MPU6050_DMP_FCFG_1,
2175 (uint8_t *)gyro_regs, 3); /* write data */
2176 if (res != 0) /* check result */
2177 {
2178 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2179
2180 return 1; /* return error */
2181 }
2182 res = a_mpu6050_write_mem(handle, MPU6050_DMP_FCFG_2,
2183 (uint8_t *)accel_regs, 3); /* write data */
2184 if (res != 0) /* check result */
2185 {
2186 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2187
2188 return 1; /* return error */
2189 }
2190
2191 memcpy(gyro_regs, gyro_sign, 3); /* copy the gyro regs */
2192 memcpy(accel_regs, accel_sign, 3); /* copy the accel regs */
2193 if ((orient & 4) != 0) /* bit 3 */
2194 {
2195 gyro_regs[0] |= 1; /* set 1 */
2196 accel_regs[0] |= 1; /* set 1 */
2197 }
2198 if ((orient & 0x20) != 0) /* bit 6 */
2199 {
2200 gyro_regs[1] |= 1; /* set 1 */
2201 accel_regs[1] |= 1; /* set 1 */
2202 }
2203 if ((orient & 0x100) != 0) /* bit 9 */
2204 {
2205 gyro_regs[2] |= 1; /* set 1 */
2206 accel_regs[2] |= 1; /* set 1 */
2207 }
2208 res = a_mpu6050_write_mem(handle, MPU6050_DMP_FCFG_3,
2209 (uint8_t *)gyro_regs, 3); /* write data */
2210 if (res != 0) /* check result */
2211 {
2212 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2213
2214 return 1; /* return error */
2215 }
2216 res = a_mpu6050_write_mem(handle, MPU6050_DMP_FCFG_7,
2217 (uint8_t *)accel_regs, 3); /* write data */
2218 if (res != 0) /* check result */
2219 {
2220 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2221
2222 return 1; /* return error */
2223 }
2224 handle->orient = orient; /* set the orient */
2225
2226 return 0; /* success return 0 */
2227}
2228
2245uint8_t mpu6050_dmp_set_feature(mpu6050_handle_t *handle, uint16_t mask)
2246{
2247 uint8_t res;
2248 uint8_t tmp[10];
2249
2250 if (handle == NULL) /* check handle */
2251 {
2252 return 2; /* return error */
2253 }
2254 if (handle->inited != 1) /* check handle initialization */
2255 {
2256 return 3; /* return error */
2257 }
2258 if (handle->dmp_inited != 1) /* check dmp initialization */
2259 {
2260 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
2261
2262 return 4; /* return error */
2263 }
2264
2265 tmp[0] = (uint8_t)((MPU6050_DMP_GYRO_SF >> 24) & 0xFF); /* set the param 0 */
2266 tmp[1] = (uint8_t)((MPU6050_DMP_GYRO_SF >> 16) & 0xFF); /* set the param 1 */
2267 tmp[2] = (uint8_t)((MPU6050_DMP_GYRO_SF >> 8) & 0xFF); /* set the param 2 */
2268 tmp[3] = (uint8_t)(MPU6050_DMP_GYRO_SF & 0xFF); /* set the param 3 */
2269 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_0_104, tmp, 4); /* write data */
2270 if (res != 0) /* check result */
2271 {
2272 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2273
2274 return 1; /* return error */
2275 }
2276
2277 tmp[0] = 0xA3;
2278 if ((mask & MPU6050_DMP_FEATURE_SEND_RAW_ACCEL) != 0) /* set the raw accel */
2279 {
2280 tmp[1] = 0xC0; /* set the param 1 */
2281 tmp[2] = 0xC8; /* set the param 2 */
2282 tmp[3] = 0xC2; /* set the param 3 */
2283 }
2284 else
2285 {
2286 tmp[1] = 0xA3; /* set the param 1 */
2287 tmp[2] = 0xA3; /* set the param 2 */
2288 tmp[3] = 0xA3; /* set the param 3 */
2289 }
2290 if ((mask & MPU6050_DMP_FEATURE_SEND_ANY_GYRO) != 0) /* set any gyro */
2291 {
2292 tmp[4] = 0xC4; /* set the param 4 */
2293 tmp[5] = 0xCC; /* set the param 5 */
2294 tmp[6] = 0xC6; /* set the param 6 */
2295 }
2296 else
2297 {
2298 tmp[4] = 0xA3; /* set the param 4 */
2299 tmp[5] = 0xA3; /* set the param 5 */
2300 tmp[6] = 0xA3; /* set the param 6 */
2301 }
2302 tmp[7] = 0xA3; /* set the param 7 */
2303 tmp[8] = 0xA3; /* set the param 8 */
2304 tmp[9] = 0xA3; /* set the param 9 */
2305 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_15, tmp, 10); /* write data */
2306 if (res != 0) /* check result */
2307 {
2308 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2309
2310 return 1; /* return error */
2311 }
2312
2313 if ((mask & (MPU6050_DMP_FEATURE_TAP | MPU6050_DMP_FEATURE_ORIENT)) != 0) /* set the cfg */
2314 {
2315 tmp[0] = 0x20; /* set the param */
2316 }
2317 else
2318 {
2319 tmp[0] = 0xD8; /* set the param */
2320 }
2321 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_27, tmp, 1); /* write data */
2322 if (res != 0) /* check result */
2323 {
2324 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2325
2326 return 1; /* return error */
2327 }
2328
2329 if ((mask & MPU6050_DMP_FEATURE_GYRO_CAL) != 0) /* if true */
2330 {
2331 uint8_t regs[9] = {0xb8, 0xaa, 0xb3, 0x8d, 0xb4, 0x98, 0x0d, 0x35, 0x5d};
2332
2333 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_MOTION_BIAS, regs, 9); /* write data */
2334 if (res != 0) /* check result */
2335 {
2336 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2337
2338 return 1; /* return error */
2339 }
2340 }
2341 else
2342 {
2343 uint8_t regs[9] = {0xb8, 0xaa, 0xaa, 0xaa, 0xb0, 0x88, 0xc3, 0xc5, 0xc7};
2344
2345 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_MOTION_BIAS, regs, 9); /* write data */
2346 if (res != 0) /* check result */
2347 {
2348 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2349
2350 return 1; /* return error */
2351 }
2352 }
2353
2354 if ((mask & MPU6050_DMP_FEATURE_SEND_ANY_GYRO) != 0) /* check the gyro */
2355 {
2356 if ((mask & MPU6050_DMP_FEATURE_SEND_CAL_GYRO) != 0) /* set the cal gyro */
2357 {
2358 tmp[0] = 0xB2; /* set the param 0 */
2359 tmp[1] = 0x8B; /* set the param 1 */
2360 tmp[2] = 0xB6; /* set the param 2 */
2361 tmp[3] = 0x9B; /* set the param 3 */
2362 }
2363 else
2364 {
2365 tmp[0] = 0xC0; /* set the param 0 */
2366 tmp[1] = 0x80; /* set the param 1 */
2367 tmp[2] = 0xC2; /* set the param 2 */
2368 tmp[3] = 0x90; /* set the param 3 */
2369 }
2370 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_GYRO_RAW_DATA, tmp, 4); /* write data */
2371 if (res != 0) /* check result */
2372 {
2373 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2374
2375 return 1; /* return error */
2376 }
2377 }
2378
2379 if ((mask & MPU6050_DMP_FEATURE_TAP) != 0) /* check the tap */
2380 {
2381 uint8_t prev;
2382 uint16_t ms;
2383 uint16_t dps;
2384 uint32_t thresh_scaled;
2385 uint8_t range;
2386 uint16_t dmp_thresh;
2387 uint16_t dmp_thresh_2;
2388 float scaled_thresh;
2389
2390 tmp[0] = 0xF8; /* set the param */
2391 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_20, tmp, 1); /* write data */
2392 if (res != 0) /* check result */
2393 {
2394 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2395
2396 return 1; /* return error */
2397 }
2398
2399 scaled_thresh = (float)MPU6050_DMP_TAP_THRESH / MPU6050_DMP_SAMPLE_RATE; /* get the scaled thresh */
2400 res = a_mpu6050_iic_read(handle, MPU6050_REG_ACCEL_CONFIG,
2401 (uint8_t *)&prev, 1); /* read accelerometer config */
2402 if (res != 0) /* check result */
2403 {
2404 handle->debug_print("mpu6050: read accelerometer config failed.\n"); /* read accelerometer config failed */
2405
2406 return 1; /* return error */
2407 }
2408 range = ((prev >> 3) & 0x3); /* get the range */
2409 if (range == 0) /* if 2g */
2410 {
2411 dmp_thresh = (uint16_t)(scaled_thresh * 16384); /* set dmp thresh */
2412 dmp_thresh_2 = (uint16_t)(scaled_thresh * 12288); /* set dmp thresh2 */
2413 }
2414 else if (range == 1) /* if 4g */
2415 {
2416 dmp_thresh = (uint16_t)(scaled_thresh * 8192); /* set dmp thresh */
2417 dmp_thresh_2 = (uint16_t)(scaled_thresh * 6144); /* set dmp thresh2 */
2418 }
2419 else if (range == 2) /* if 8g */
2420 {
2421 dmp_thresh = (uint16_t)(scaled_thresh * 4096); /* set dmp thresh */
2422 dmp_thresh_2 = (uint16_t)(scaled_thresh * 3072); /* set dmp thresh2 */
2423 }
2424 else /* if 16g */
2425 {
2426 dmp_thresh = (uint16_t)(scaled_thresh * 2048); /* set dmp thresh */
2427 dmp_thresh_2 = (uint16_t)(scaled_thresh * 1536); /* set dmp thresh2 */
2428 }
2429 tmp[0] = (uint8_t)(dmp_thresh >> 8); /* set part 0 */
2430 tmp[1] = (uint8_t)(dmp_thresh & 0xFF); /* set part 1 */
2431 tmp[2] = (uint8_t)(dmp_thresh_2 >> 8); /* set part 2 */
2432 tmp[3] = (uint8_t)(dmp_thresh_2 & 0xFF); /* set part 3 */
2433
2434 res = a_mpu6050_write_mem(handle, MPU6050_DMP_TAP_THX, tmp, 2); /* write tap threshold x */
2435 if (res != 0) /* check result */
2436 {
2437 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2438
2439 return 1; /* return error */
2440 }
2441 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_1_36, tmp + 2, 2); /* write register 36 */
2442 if (res != 0) /* check result */
2443 {
2444 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2445
2446 return 1; /* return error */
2447 }
2448
2449 res = a_mpu6050_write_mem(handle, MPU6050_DMP_TAP_THY, tmp, 2); /* write tap threshold y */
2450 if (res != 0) /* check result */
2451 {
2452 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2453
2454 return 1; /* return error */
2455 }
2456 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_1_40, tmp + 2, 2); /* write register 40 */
2457 if (res != 0) /* check result */
2458 {
2459 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2460
2461 return 1; /* return error */
2462 }
2463
2464 res = a_mpu6050_write_mem(handle, MPU6050_DMP_TAP_THZ, tmp, 2); /* write tap threshold z */
2465 if (res != 0) /* check result */
2466 {
2467 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2468
2469 return 1; /* return error */
2470 }
2471 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_1_44, tmp + 2, 2); /* write register 44 */
2472 if (res != 0) /* check result */
2473 {
2474 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2475
2476 return 1; /* return error */
2477 }
2478
2479 tmp[0] = 0x3F; /* enable all tap axis */
2480 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_1_72, tmp, 1); /* write data */
2481 if (res != 0) /* check result */
2482 {
2483 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2484
2485 return 1; /* return error */
2486 }
2487
2488 tmp[0] = MPU6050_DMP_TAP_MIN_TAP_COUNT - 1; /* set the counter */
2489 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_1_79, tmp, 1); /* write data */
2490 if (res != 0) /* check result */
2491 {
2492 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2493
2494 return 1; /* return error */
2495 }
2496
2497 ms = MPU6050_DMP_TAP_TIME; /* set tap time */
2498 ms /= (1000 / MPU6050_DMP_SAMPLE_RATE); /* convert time */
2499 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
2500 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
2501
2502 res = a_mpu6050_write_mem(handle, MPU6050_DMP_TAPW_MIN, tmp, 2); /* write data */
2503 if (res != 0) /* check result */
2504 {
2505 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2506
2507 return 1; /* return error */
2508 }
2509
2510 ms = MPU6050_DMP_TAP_TIME_MULTI; /* set tap time multi */
2511 ms /= (1000 / MPU6050_DMP_SAMPLE_RATE); /* convert time */
2512 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
2513 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
2514
2515 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_1_218, tmp, 2); /* write data */
2516 if (res != 0) /* check result */
2517 {
2518 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2519
2520 return 1; /* return error */
2521 }
2522
2523 dps = MPU6050_DMP_SHAKE_REJECT_THRESH; /* set the shake reject thresh */
2524 thresh_scaled = MPU6050_DMP_GYRO_SF / 1000 * dps; /* convert to thresh scaled */
2525 tmp[0] = (uint8_t)(((uint32_t)thresh_scaled >> 24) & 0xFF); /* set the part 3 */
2526 tmp[1] = (uint8_t)(((uint32_t)thresh_scaled >> 16) & 0xFF); /* set the part 2 */
2527 tmp[2] = (uint8_t)(((uint32_t)thresh_scaled >> 8) & 0xFF); /* set the part 1 */
2528 tmp[3] = (uint8_t)((uint32_t)thresh_scaled & 0xFF); /* set the part 0 */
2529
2530 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_1_92, tmp, 4); /* write data */
2531 if (res != 0) /* check result */
2532 {
2533 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2534
2535 return 1; /* return error */
2536 }
2537
2538 ms = MPU6050_DMP_SHAKE_REJECT_TIME; /* set the reject time */
2539 ms /= (1000 / MPU6050_DMP_SAMPLE_RATE); /* convert time */
2540 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
2541 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
2542
2543 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_1_90, tmp, 2); /* write data */
2544 if (res != 0) /* check result */
2545 {
2546 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2547
2548 return 1; /* return error */
2549 }
2550
2551 ms = MPU6050_DMP_SHAKE_REJECT_TIMEOUT; /* set the reject timeout */
2552 ms /= (1000 / MPU6050_DMP_SAMPLE_RATE); /* convert time */
2553 tmp[0] = (ms >> 8) & 0xFF; /* set part 0 */
2554 tmp[1] = (ms >> 0) & 0xFF; /* set part 1 */
2555
2556 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_1_88, tmp, 2); /* write data */
2557 if (res != 0) /* check result */
2558 {
2559 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2560
2561 return 1; /* return error */
2562 }
2563 }
2564 else
2565 {
2566 tmp[0] = 0xD8; /* set the param */
2567 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_20, tmp, 1); /* write data */
2568 if (res != 0) /* check result */
2569 {
2570 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2571
2572 return 1; /* return error */
2573 }
2574 }
2575
2576 if ((mask & MPU6050_DMP_FEATURE_ORIENT) != 0) /* set the orient */
2577 {
2578 tmp[0] = 0xD9; /* set the param */
2579 }
2580 else
2581 {
2582 tmp[0] = 0xD8; /* set the param */
2583 }
2584 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_ORIENT_INT, tmp, 1); /* write data */
2585 if (res != 0) /* check result */
2586 {
2587 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2588
2589 return 1; /* return error */
2590 }
2591
2592 if ((mask & MPU6050_DMP_FEATURE_3X_QUAT) != 0) /* true */
2593 {
2594 uint8_t regs[4] = {0xC0, 0xC2, 0xC4, 0xC6};
2595
2596 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_LP_QUAT, regs, 4); /* write data */
2597 if (res != 0) /* check result */
2598 {
2599 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2600
2601 return 1; /* return error */
2602 }
2603 res = a_mpu6050_reset_fifo(handle); /* reset the fifo */
2604 if (res != 0) /* check result */
2605 {
2606 handle->debug_print("mpu6050: reset fifo failed.\n"); /* reset fifo failed */
2607
2608 return 1; /* return error */
2609 }
2610 }
2611 else
2612 {
2613 uint8_t regs[4] = {0x8B, 0x8B, 0x8B, 0x8B};
2614
2615 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_LP_QUAT, regs, 4); /* write data */
2616 if (res != 0) /* check result */
2617 {
2618 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2619
2620 return 1; /* return error */
2621 }
2622 res = a_mpu6050_reset_fifo(handle); /* reset the fifo */
2623 if (res != 0) /* check result */
2624 {
2625 handle->debug_print("mpu6050: reset fifo failed.\n"); /* reset fifo failed */
2626
2627 return 1; /* return error */
2628 }
2629 }
2630
2631 if ((mask & MPU6050_DMP_FEATURE_6X_QUAT) != 0) /* enable */
2632 {
2633 uint8_t regs[4] = {0x20, 0x28, 0x30, 0x38};
2634
2635 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_8, regs, 4); /* write data */
2636 if (res != 0) /* check result */
2637 {
2638 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2639
2640 return 1; /* return error */
2641 }
2642 res = a_mpu6050_reset_fifo(handle); /* reset the fifo */
2643 if (res != 0) /* check result */
2644 {
2645 handle->debug_print("mpu6050: reset fifo failed.\n"); /* reset fifo failed */
2646
2647 return 1; /* return error */
2648 }
2649 }
2650 else
2651 {
2652 uint8_t regs[4] = {0xA3, 0xA3, 0xA3, 0xA3};
2653
2654 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_8, regs, 4); /* write data */
2655 if (res != 0) /* check result */
2656 {
2657 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2658
2659 return 1; /* return error */
2660 }
2661 res = a_mpu6050_reset_fifo(handle); /* reset the fifo */
2662 if (res != 0) /* check result */
2663 {
2664 handle->debug_print("mpu6050: reset fifo failed.\n"); /* reset fifo failed */
2665
2666 return 1; /* return error */
2667 }
2668 }
2669
2670 handle->mask = mask | MPU6050_DMP_FEATURE_PEDOMETER; /* set the mask */
2671
2672 return a_mpu6050_reset_fifo(handle); /* reset the fifo */
2673}
2674
2688uint8_t mpu6050_dmp_set_fifo_rate(mpu6050_handle_t *handle, uint16_t rate)
2689{
2690 uint8_t regs_end[12] = {0xFE, 0xF2, 0xAB,
2691 0xC4, 0xAA, 0xF1,
2692 0xDF, 0xDF, 0xBB,
2693 0xAF, 0xDF, 0xDF};
2694 uint8_t res;
2695 uint16_t d;
2696 uint8_t tmp[2];
2697
2698 if (handle == NULL) /* check handle */
2699 {
2700 return 2; /* return error */
2701 }
2702 if (handle->inited != 1) /* check handle initialization */
2703 {
2704 return 3; /* return error */
2705 }
2706 if (handle->dmp_inited != 1) /* check dmp initialization */
2707 {
2708 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
2709
2710 return 4; /* return error */
2711 }
2712 if (rate > MPU6050_DMP_SAMPLE_RATE) /* check rate */
2713 {
2714 handle->debug_print("mpu6050: rate > 200.\n"); /* rate > 200 */
2715
2716 return 5; /* return error */
2717 }
2718
2719 d = MPU6050_DMP_SAMPLE_RATE / rate - 1; /* set div */
2720 tmp[0] = (uint8_t)((d >> 8) & 0xFF); /* set tmp part0 */
2721 tmp[1] = (uint8_t)(d & 0xFF); /* set tmp part1 */
2722
2723 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_0_22, tmp, 2); /* write data */
2724 if (res != 0) /* check result */
2725 {
2726 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2727
2728 return 1; /* return error */
2729 }
2730 res = a_mpu6050_write_mem(handle, MPU6050_DMP_CFG_6,
2731 (uint8_t *)regs_end, 12); /* write data */
2732 if (res != 0) /* check result */
2733 {
2734 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2735
2736 return 1; /* return error */
2737 }
2738
2739 return 0; /* success return 0 */
2740}
2741
2754uint8_t mpu6050_dmp_get_fifo_rate(mpu6050_handle_t *handle, uint16_t *rate)
2755{
2756 uint8_t res;
2757 uint16_t d;
2758 uint8_t tmp[2];
2759
2760 if (handle == NULL) /* check handle */
2761 {
2762 return 2; /* return error */
2763 }
2764 if (handle->inited != 1) /* check handle initialization */
2765 {
2766 return 3; /* return error */
2767 }
2768 if (handle->dmp_inited != 1) /* check dmp initialization */
2769 {
2770 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
2771
2772 return 4; /* return error */
2773 }
2774
2775 res = a_mpu6050_read_mem(handle, MPU6050_DMP_D_0_22, tmp, 2); /* read data */
2776 if (res != 0) /* check result */
2777 {
2778 handle->debug_print("mpu6050: read mem failed.\n"); /* read mem failed */
2779
2780 return 1; /* return error */
2781 }
2782 d = (uint16_t)tmp[0] << 8 | tmp[1]; /* get the div */
2783 *rate = MPU6050_DMP_SAMPLE_RATE / (d + 1); /* set the rate */
2784
2785 return 0; /* success return 0 */
2786}
2787
2802{
2803 uint8_t res;
2804 uint8_t tmp;
2805 uint8_t pos;
2806
2807 if (handle == NULL) /* check handle */
2808 {
2809 return 2; /* return error */
2810 }
2811 if (handle->inited != 1) /* check handle initialization */
2812 {
2813 return 3; /* return error */
2814 }
2815 if (handle->dmp_inited != 1) /* check dmp initialization */
2816 {
2817 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
2818
2819 return 4; /* return error */
2820 }
2821
2822 res = a_mpu6050_read_mem(handle, MPU6050_DMP_D_1_72, &tmp, 1); /* read data */
2823 if (res != 0) /* check result */
2824 {
2825 handle->debug_print("mpu6050: read mem failed.\n"); /* read mem failed */
2826
2827 return 1; /* return error */
2828 }
2829 pos = (uint8_t)((axis - 5) * 2); /* get the pos */
2830 if (enable == MPU6050_BOOL_TRUE) /* if enable */
2831 {
2832 tmp |= (3 << pos); /* enable */
2833 }
2834 else
2835 {
2836 tmp &= ~(3 << pos); /* disable */
2837 }
2838 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_1_72, &tmp, 1); /* write data */
2839 if (res != 0) /* check result */
2840 {
2841 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2842
2843 return 1; /* return error */
2844 }
2845
2846 return 0; /* success return 0 */
2847}
2848
2863{
2864 uint8_t res;
2865 uint8_t tmp;
2866 uint8_t pos;
2867
2868 if (handle == NULL) /* check handle */
2869 {
2870 return 2; /* return error */
2871 }
2872 if (handle->inited != 1) /* check handle initialization */
2873 {
2874 return 3; /* return error */
2875 }
2876 if (handle->dmp_inited != 1) /* check dmp initialization */
2877 {
2878 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
2879
2880 return 4; /* return error */
2881 }
2882
2883 res = a_mpu6050_read_mem(handle, MPU6050_DMP_D_1_72, &tmp, 1); /* read data */
2884 if (res != 0) /* check result */
2885 {
2886 handle->debug_print("mpu6050: read mem failed.\n"); /* read mem failed */
2887
2888 return 1; /* return error */
2889 }
2890 pos = (uint8_t)((axis - 5) * 2); /* get the pos */
2891 if (((tmp >> pos) & 0x3) == 0x3) /* if enable */
2892 {
2893 *enable = MPU6050_BOOL_TRUE; /* set enable */
2894 }
2895 else
2896 {
2897 *enable = MPU6050_BOOL_FALSE; /* set disable */
2898 }
2899
2900 return 0; /* success return 0 */
2901}
2902
2918uint8_t mpu6050_dmp_set_tap_thresh(mpu6050_handle_t *handle, mpu6050_axis_t axis, uint16_t mg_ms)
2919{
2920 uint8_t res;
2921 uint8_t prev;
2922 uint8_t range;
2923 uint8_t tmp[4];
2924 uint16_t dmp_thresh;
2925 uint16_t dmp_thresh_2;
2926 float scaled_thresh;
2927
2928 if (handle == NULL) /* check handle */
2929 {
2930 return 2; /* return error */
2931 }
2932 if (handle->inited != 1) /* check handle initialization */
2933 {
2934 return 3; /* return error */
2935 }
2936 if (handle->dmp_inited != 1) /* check dmp initialization */
2937 {
2938 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
2939
2940 return 4; /* return error */
2941 }
2942 if (mg_ms > 1600) /* check the mg/ms */
2943 {
2944 handle->debug_print("mpu6050: mg/ms > 1600.\n"); /* mg/ms > 1600 */
2945
2946 return 5; /* return error */
2947 }
2948
2949 scaled_thresh = (float)mg_ms / MPU6050_DMP_SAMPLE_RATE; /* get the scaled thresh */
2950 res = a_mpu6050_iic_read(handle, MPU6050_REG_ACCEL_CONFIG,
2951 (uint8_t *)&prev, 1); /* read accelerometer config */
2952 if (res != 0) /* check result */
2953 {
2954 handle->debug_print("mpu6050: read accelerometer config failed.\n"); /* read accelerometer config failed */
2955
2956 return 1; /* return error */
2957 }
2958 range = ((prev >> 3) & 0x3); /* get the range */
2959 if (range == 0) /* if 2g */
2960 {
2961 dmp_thresh = (uint16_t)(scaled_thresh * 16384); /* set dmp thresh */
2962 dmp_thresh_2 = (uint16_t)(scaled_thresh * 12288); /* set dmp thresh2 */
2963 }
2964 else if (range == 1) /* if 4g */
2965 {
2966 dmp_thresh = (uint16_t)(scaled_thresh * 8192); /* set dmp thresh */
2967 dmp_thresh_2 = (uint16_t)(scaled_thresh * 6144); /* set dmp thresh2 */
2968 }
2969 else if (range == 2) /* if 8g */
2970 {
2971 dmp_thresh = (uint16_t)(scaled_thresh * 4096); /* set dmp thresh */
2972 dmp_thresh_2 = (uint16_t)(scaled_thresh * 3072); /* set dmp thresh2 */
2973 }
2974 else /* if 16g */
2975 {
2976 dmp_thresh = (uint16_t)(scaled_thresh * 2048); /* set dmp thresh */
2977 dmp_thresh_2 = (uint16_t)(scaled_thresh * 1536); /* set dmp thresh2 */
2978 }
2979 tmp[0] = (uint8_t)(dmp_thresh >> 8); /* set part 0 */
2980 tmp[1] = (uint8_t)(dmp_thresh & 0xFF); /* set part 1 */
2981 tmp[2] = (uint8_t)(dmp_thresh_2 >> 8); /* set part 2 */
2982 tmp[3] = (uint8_t)(dmp_thresh_2 & 0xFF); /* set part 3 */
2983
2984 if (axis == MPU6050_AXIS_X) /* if axis x */
2985 {
2986 res = a_mpu6050_write_mem(handle, MPU6050_DMP_TAP_THX, tmp, 2); /* write tap threshold x */
2987 if (res != 0) /* check result */
2988 {
2989 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2990
2991 return 1; /* return error */
2992 }
2993 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_1_36, tmp + 2, 2); /* write register 36 */
2994 if (res != 0) /* check result */
2995 {
2996 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
2997
2998 return 1; /* return error */
2999 }
3000
3001 return 0; /* success return 0 */
3002 }
3003 else if (axis == MPU6050_AXIS_Y) /* if axis y */
3004 {
3005 res = a_mpu6050_write_mem(handle, MPU6050_DMP_TAP_THY, tmp, 2); /* write tap threshold y */
3006 if (res != 0) /* check result */
3007 {
3008 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
3009
3010 return 1; /* return error */
3011 }
3012 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_1_40, tmp + 2, 2); /* write register 40 */
3013 if (res != 0) /* check result */
3014 {
3015 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
3016
3017 return 1; /* return error */
3018 }
3019
3020 return 0; /* success return 0 */
3021 }
3022 else if (axis == MPU6050_AXIS_Z) /* if axis z */
3023 {
3024 res = a_mpu6050_write_mem(handle, MPU6050_DMP_TAP_THZ, tmp, 2); /* write tap threshold z */
3025 if (res != 0) /* check result */
3026 {
3027 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
3028
3029 return 1; /* return error */
3030 }
3031 res = a_mpu6050_write_mem(handle, MPU6050_DMP_D_1_44, tmp + 2, 2); /* write register 44 */
3032 if (res != 0) /* check result */
3033 {
3034 handle->debug_print("mpu6050: write mem failed.\n"); /* write mem failed */
3035
3036 return 1; /* return error */
3037 }
3038
3039 return 0; /* success return 0 */
3040 }
3041 else
3042 {
3043 handle->debug_print("mpu6050: invalid axis.\n"); /* invalid axis */
3044
3045 return 6; /* return error */
3046 }
3047}
3048
3063uint8_t mpu6050_dmp_get_tap_thresh(mpu6050_handle_t *handle, mpu6050_axis_t axis, uint16_t *mg_ms)
3064{
3065 uint8_t res;
3066 uint8_t prev;
3067 uint8_t range;
3068 uint8_t tmp[2];
3069 uint16_t dmp_thresh;
3070 float scaled_thresh;
3071
3072 if (handle == NULL) /* check handle */
3073 {
3074 return 2; /* return error */
3075 }
3076 if (handle->inited != 1) /* check handle initialization */
3077 {
3078 return 3; /* return error */
3079 }
3080 if (handle->dmp_inited != 1) /* check dmp initialization */
3081 {
3082 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
3083
3084 return 4; /* return error */
3085 }
3086
3087 if (axis == MPU6050_AXIS_X) /* if axis x */
3088 {
3089 res = a_mpu6050_read_mem(handle, MPU6050_DMP_TAP_THX, tmp, 2); /* read tap threshold x */
3090 if (res != 0) /* check result */
3091 {
3092 handle->debug_print("mpu6050: read mem failed.\n"); /* read mem failed */
3093
3094 return 1; /* return error */
3095 }
3096 }
3097 else if (axis == MPU6050_AXIS_Y) /* if axis y */
3098 {
3099 res = a_mpu6050_read_mem(handle, MPU6050_DMP_TAP_THY, tmp, 2); /* read tap threshold y */
3100 if (res != 0) /* check result */
3101 {
3102 handle->debug_print("mpu6050: read mem failed.\n"); /* read mem failed */
3103
3104 return 1; /* return error */
3105 }
3106 }
3107 else if (axis == MPU6050_AXIS_Z) /* if axis z */
3108 {
3109 res = a_mpu6050_read_mem(handle, MPU6050_DMP_TAP_THZ, tmp, 2); /* read tap threshold z */
3110 if (res != 0) /* check result */
3111 {
3112 handle->debug_print("mpu6050: read mem failed.\n"); /* read mem failed */
3113
3114 return 1; /* return error */
3115 }
3116 }
3117 else
3118 {
3119 handle->debug_print("mpu6050: invalid axis.\n"); /* invalid axis */
3120
3121 return 5; /* return error */
3122 }
3123 dmp_thresh = (uint16_t)tmp[0] << 8 | tmp[1]; /* set the dmp thresh */
3124
3125 res = a_mpu6050_iic_read(handle, MPU6050_REG_ACCEL_CONFIG,
3126 (uint8_t *)&prev, 1); /* read accelerometer config */
3127 if (res != 0) /* check result */
3128 {
3129 handle->debug_print("mpu6050: read accelerometer config failed.\n"); /* read accelerometer config failed */
3130
3131 return 1; /* return error */
3132 }
3133 range = ((prev >> 3) & 0x3); /* get the range */
3134 if (range == 0) /* if 2g */
3135 {
3136 scaled_thresh = dmp_thresh / 16384.0f; /* set dmp thresh */
3137 }
3138 else if (range == 1) /* if 4g */
3139 {
3140 scaled_thresh = dmp_thresh / 8192.0f; /* set dmp thresh */
3141 }
3142 else if (range == 2) /* if 8g */
3143 {
3144 scaled_thresh = dmp_thresh / 4096.0f; /* set dmp thresh */
3145 }
3146 else /* if 16g */
3147 {
3148 scaled_thresh = dmp_thresh / 2048.0f; /* set dmp thresh */
3149 }
3150 *mg_ms = (uint16_t)(scaled_thresh * MPU6050_DMP_SAMPLE_RATE); /* set the mg/ms */
3151
3152 return 0; /* success return 0 */
3153}
3154
3180 int16_t (*accel_raw)[3], float (*accel_g)[3],
3181 int16_t (*gyro_raw)[3], float (*gyro_dps)[3],
3182 int32_t (*quat)[4],
3183 float *pitch, float *roll, float *yaw,
3184 uint16_t *l
3185 )
3186{
3187 uint8_t res;
3188 uint8_t i = 0;
3189 uint16_t len;
3190 uint8_t buf[2];
3191 uint8_t prev;
3192 uint16_t count;
3193 uint16_t j;
3194
3195 if (handle == NULL) /* check handle */
3196 {
3197 return 2; /* return error */
3198 }
3199 if (handle->inited != 1) /* check handle initialization */
3200 {
3201 return 3; /* return error */
3202 }
3203 if (handle->dmp_inited != 1) /* check dmp initialization */
3204 {
3205 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
3206
3207 return 4; /* return error */
3208 }
3209
3210 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_STATUS, (uint8_t *)&prev, 1); /* read config */
3211 if (res != 0) /* check result */
3212 {
3213 handle->debug_print("mpu6050: read int status failed.\n"); /* read int status failed */
3214
3215 return 1; /* return error */
3216 }
3217 if ((prev & (1 << MPU6050_INTERRUPT_FIFO_OVERFLOW)) != 0) /* if fifo overflow */
3218 {
3219 handle->debug_print("mpu6050: fifo overflow.\n"); /* fifo overflow */
3220 (void)a_mpu6050_reset_fifo(handle); /* reset the fifo */
3221
3222 return 6; /* return error */
3223 }
3224
3225 len = 0; /* set len 0 */
3226 if ((handle->mask & MPU6050_DMP_FEATURE_SEND_RAW_ACCEL) != 0) /* check the accel */
3227 {
3228 len += 6; /* size += 6 */
3229 }
3230 if ((handle->mask & MPU6050_DMP_FEATURE_SEND_ANY_GYRO) != 0) /* check the gyro */
3231 {
3232 len += 6; /* size += 6 */
3233 }
3234 if ((handle->mask & (MPU6050_DMP_FEATURE_3X_QUAT | MPU6050_DMP_FEATURE_6X_QUAT)) != 0) /* check the quat */
3235 {
3236 len += 16; /* size += 16 */
3237 }
3238 if ((handle->mask & (MPU6050_DMP_FEATURE_TAP | MPU6050_DMP_FEATURE_ORIENT)) != 0) /* check the tap and orient */
3239 {
3240 len += 4; /* size += 4 */
3241 }
3242 if (len == 0) /* check the len */
3243 {
3244 handle->debug_print("mpu6050: no data.\n"); /* no data */
3245
3246 return 8; /* return error */
3247 }
3248
3249 res = a_mpu6050_iic_read(handle, MPU6050_REG_FIFO_COUNTH, (uint8_t *)buf, 2); /* read fifo count */
3250 if (res != 0) /* check result */
3251 {
3252 handle->debug_print("mpu6050: read fifo count failed.\n"); /* read fifo count failed */
3253
3254 return 1; /* return error */
3255 }
3256 count = (uint16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set count */
3257 count = (count < 1024) ? count : 1024; /* just the counter */
3258 count = (count < (*l) * len) ? count : ((*l) *len); /* just outer buffer size */
3259 count = (count / len) * len; /* len times */
3260 *l = count / len; /* set the output length */
3261 res = a_mpu6050_iic_read(handle, MPU6050_REG_R_W, handle->buf, count); /* read data */
3262 if (res != 0) /* check result */
3263 {
3264 handle->debug_print("mpu6050: read failed.\n"); /* read failed */
3265
3266 return 1; /* return error */
3267 }
3268 if (count < len) /* check the count */
3269 {
3270 handle->debug_print("mpu6050: fifo data is too little.\n"); /* fifo data is too little */
3271
3272 return 7; /* return error */
3273 }
3274
3275 for (j = 0; j < (*l); j++) /* (*l) times */
3276 {
3277 if ((handle->mask & (MPU6050_DMP_FEATURE_3X_QUAT | MPU6050_DMP_FEATURE_6X_QUAT)) != 0) /* check the quat */
3278 {
3279 int32_t quat_q14[4];
3280 int32_t quat_mag_sq;
3281 float q0=1.0f, q1=0.0f, q2=0.0f, q3=0.0f;
3282
3283 i = 0; /* set 0 */
3284 quat[j][0] = ((int32_t)handle->buf[0 + len * j] << 24) | ((int32_t)handle->buf[1 + len * j] << 16) |
3285 ((int32_t)handle->buf[2 + len * j] << 8) | handle->buf[3 + len * j]; /* set the quat 0 */
3286 quat[j][1] = ((int32_t)handle->buf[4 + len * j] << 24) | ((int32_t)handle->buf[5 + len * j] << 16) |
3287 ((int32_t)handle->buf[6 + len * j] << 8) | handle->buf[7 + len * j]; /* set the quat 1 */
3288 quat[j][2] = ((int32_t)handle->buf[8 + len * j] << 24) | ((int32_t)handle->buf[9 + len * j] << 16) |
3289 ((int32_t)handle->buf[10 + len * j] << 8) | handle->buf[11 + len * j]; /* set the quat 2 */
3290 quat[j][3] = ((int32_t)handle->buf[12 + len * j] << 24) | ((int32_t)handle->buf[13 + len * j] << 16) |
3291 ((int32_t)handle->buf[14 + len * j] << 8) | handle->buf[15 + len * j]; /* set the quat 3 */
3292 i += 16; /* size += 16 */
3293
3294 quat_q14[0] = quat[j][0] >> 16; /* set the quat q14[0] */
3295 quat_q14[1] = quat[j][1] >> 16; /* set the quat q14[1] */
3296 quat_q14[2] = quat[j][2] >> 16; /* set the quat q14[2] */
3297 quat_q14[3] = quat[j][3] >> 16; /* set the quat q14[3] */
3298 quat_mag_sq = quat_q14[0] * quat_q14[0] + quat_q14[1] * quat_q14[1] +
3299 quat_q14[2] * quat_q14[2] + quat_q14[3] * quat_q14[3]; /* get the quat mag sq */
3300 if ((quat_mag_sq < MPU6050_DMP_QUAT_MAG_SQ_MIN) ||
3301 (quat_mag_sq > MPU6050_DMP_QUAT_MAG_SQ_MAX)) /* check the size */
3302 {
3303 handle->debug_print("mpu6050: quat check error.\n"); /* quat check error */
3304 (void)a_mpu6050_reset_fifo(handle); /* reset the fifo */
3305
3306 return 5; /* return error */
3307 }
3308 q0 = quat[j][0] / 1073741824.0f; /* set q0 */
3309 q1 = quat[j][1] / 1073741824.0f; /* set q1 */
3310 q2 = quat[j][2] / 1073741824.0f; /* set q2 */
3311 q3 = quat[j][3] / 1073741824.0f; /* set q3 */
3312 pitch[j] = asinf(-2 * q1 * q3 + 2 * q0* q2)* 57.3f; /* set pitch */
3313 roll[j] = atan2f(2 * q2 * q3 + 2 * q0 * q1, -2 * q1 * q1 - 2 * q2 * q2 + 1)* 57.3f; /* set roll */
3314 yaw[j] = atan2f(2 * (q1 * q2 + q0 * q3), q0 * q0 + q1 * q1 - q2 * q2 - q3 * q3) * 57.3f; /* set yaw */
3315 }
3316 else
3317 {
3318 quat[j][0] = 0; /* set 0 */
3319 quat[j][1] = 0; /* set 0 */
3320 quat[j][2] = 0; /* set 0 */
3321 quat[j][3] = 0; /* set 0 */
3322 pitch[j] = 0.0f; /* set 0.0f */
3323 roll[j] = 0.0f; /* set 0.0f */
3324 yaw[j] = 0.0f; /* set 0.0f */
3325 }
3326 if ((handle->mask & MPU6050_DMP_FEATURE_SEND_RAW_ACCEL) != 0) /* check the accel */
3327 {
3328 uint8_t accel_conf;
3329
3330 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 */
3331 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 */
3332 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 */
3333 i += 6; /* size += 6 */
3334
3335 res = a_mpu6050_iic_read(handle, MPU6050_REG_ACCEL_CONFIG, (uint8_t *)&accel_conf, 1); /* read accel config */
3336 if (res != 0) /* check result */
3337 {
3338 handle->debug_print("mpu6050: read accel config failed.\n"); /* read accel config failed */
3339
3340 return 1; /* return error */
3341 }
3342 accel_conf = (accel_conf >> 3) & 0x3; /* get the accel conf */
3343 if (accel_conf == 0) /* ±2g */
3344 {
3345 accel_g[j][0] = (float)(accel_raw[j][0]) / 16384.0f; /* set accel x */
3346 accel_g[j][1] = (float)(accel_raw[j][1]) / 16384.0f; /* set accel y */
3347 accel_g[j][2] = (float)(accel_raw[j][2]) / 16384.0f; /* set accel z */
3348 }
3349 else if (accel_conf == 1) /* ±4g */
3350 {
3351 accel_g[j][0] = (float)(accel_raw[j][0]) / 8192.0f; /* set accel x */
3352 accel_g[j][1] = (float)(accel_raw[j][1]) / 8192.0f; /* set accel y */
3353 accel_g[j][2] = (float)(accel_raw[j][2]) / 8192.0f; /* set accel z */
3354 }
3355 else if (accel_conf == 2) /* ±8g */
3356 {
3357 accel_g[j][0] = (float)(accel_raw[j][0]) / 4096.0f; /* set accel x */
3358 accel_g[j][1] = (float)(accel_raw[j][1]) / 4096.0f; /* set accel y */
3359 accel_g[j][2] = (float)(accel_raw[j][2]) / 4096.0f; /* set accel z */
3360 }
3361 else /* ±16g */
3362 {
3363 accel_g[j][0] = (float)(accel_raw[j][0]) / 2048.0f; /* set accel x */
3364 accel_g[j][1] = (float)(accel_raw[j][1]) / 2048.0f; /* set accel y */
3365 accel_g[j][2] = (float)(accel_raw[j][2]) / 2048.0f; /* set accel z */
3366 }
3367 }
3368 else
3369 {
3370 accel_raw[j][0] = 0; /* set 0 */
3371 accel_raw[j][1] = 0; /* set 0 */
3372 accel_raw[j][2] = 0; /* set 0 */
3373 accel_g[j][0] = 0.0f; /* set 0.0f */
3374 accel_g[j][1] = 0.0f; /* set 0.0f */
3375 accel_g[j][2] = 0.0f; /* set 0.0f */
3376 }
3377 if ((handle->mask & MPU6050_DMP_FEATURE_SEND_ANY_GYRO) != 0) /* check the gyro */
3378 {
3379 uint8_t gyro_conf;
3380
3381 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 */
3382 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 */
3383 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 */
3384 i += 6; /* size += 6 */
3385
3386 res = a_mpu6050_iic_read(handle, MPU6050_REG_GYRO_CONFIG, (uint8_t *)&gyro_conf, 1); /* read gyro config */
3387 if (res != 0) /* check result */
3388 {
3389 handle->debug_print("mpu6050: read gyro config failed.\n"); /* read gyro config failed */
3390
3391 return 1; /* return error */
3392 }
3393 gyro_conf = (gyro_conf >> 3) & 0x3; /* get the gyro conf */
3394 if (gyro_conf == 0) /* ±250dps */
3395 {
3396 gyro_dps[j][0] = (float)(gyro_raw[j][0]) / 131.0f; /* set gyro x */
3397 gyro_dps[j][1] = (float)(gyro_raw[j][1]) / 131.0f; /* set gyro y */
3398 gyro_dps[j][2] = (float)(gyro_raw[j][2]) / 131.0f; /* set gyro z */
3399 }
3400 else if (gyro_conf == 1) /* ±500dps */
3401 {
3402 gyro_dps[j][0] = (float)(gyro_raw[j][0]) / 65.5f; /* set gyro x */
3403 gyro_dps[j][1] = (float)(gyro_raw[j][1]) / 65.5f; /* set gyro y */
3404 gyro_dps[j][2] = (float)(gyro_raw[j][2]) / 65.5f; /* set gyro z */
3405 }
3406 else if (gyro_conf == 2) /* ±1000dps */
3407 {
3408 gyro_dps[j][0] = (float)(gyro_raw[j][0]) / 32.8f; /* set gyro x */
3409 gyro_dps[j][1] = (float)(gyro_raw[j][1]) / 32.8f; /* set gyro y */
3410 gyro_dps[j][2] = (float)(gyro_raw[j][2]) / 32.8f; /* set gyro z */
3411 }
3412 else /* ±2000dps */
3413 {
3414 gyro_dps[j][0] = (float)(gyro_raw[j][0]) / 16.4f; /* set gyro x */
3415 gyro_dps[j][1] = (float)(gyro_raw[j][1]) / 16.4f; /* set gyro y */
3416 gyro_dps[j][2] = (float)(gyro_raw[j][2]) / 16.4f; /* set gyro z */
3417 }
3418 }
3419 else
3420 {
3421 gyro_raw[j][0] = 0; /* set 0 */
3422 gyro_raw[j][1] = 0; /* set 0 */
3423 gyro_raw[j][2] = 0; /* set 0 */
3424 gyro_dps[j][0] = 0.0f; /* set 0.0f */
3425 gyro_dps[j][1] = 0.0f; /* set 0.0f */
3426 gyro_dps[j][2] = 0.0f; /* set 0.0f */
3427 }
3428 if ((handle->mask & (MPU6050_DMP_FEATURE_TAP | MPU6050_DMP_FEATURE_ORIENT)) != 0) /* check the tap and orient */
3429 {
3430 a_mpu6050_dmp_decode_gesture(handle, handle->buf + i + len * j); /* run the decode gesture */
3431 }
3432 }
3433
3434 return 0; /* success return 0 */
3435}
3436
3449uint8_t mpu6050_dmp_set_tap_callback(mpu6050_handle_t *handle, void (*callback)(uint8_t count, uint8_t direction))
3450{
3451 if (handle == NULL) /* check handle */
3452 {
3453 return 2; /* return error */
3454 }
3455 if (handle->inited != 1) /* check handle initialization */
3456 {
3457 return 3; /* return error */
3458 }
3459 if (handle->dmp_inited != 1) /* check dmp initialization */
3460 {
3461 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
3462
3463 return 4; /* return error */
3464 }
3465
3466 handle->dmp_tap_callback = callback; /* set the callback */
3467
3468 return 0; /* success return 0 */
3469}
3470
3483uint8_t mpu6050_dmp_set_orient_callback(mpu6050_handle_t *handle, void (*callback)(uint8_t orientation))
3484{
3485 if (handle == NULL) /* check handle */
3486 {
3487 return 2; /* return error */
3488 }
3489 if (handle->inited != 1) /* check handle initialization */
3490 {
3491 return 3; /* return error */
3492 }
3493 if (handle->dmp_inited != 1) /* check dmp initialization */
3494 {
3495 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
3496
3497 return 4; /* return error */
3498 }
3499
3500 handle->dmp_orient_callback = callback; /* set the callback */
3501
3502 return 0; /* success return 0 */
3503}
3504
3518{
3519 uint8_t res;
3520 uint8_t prev;
3521
3522 if (handle == NULL) /* check handle */
3523 {
3524 return 2; /* return error */
3525 }
3526 if (handle->inited != 1) /* check handle initialization */
3527 {
3528 return 3; /* return error */
3529 }
3530 if (handle->dmp_inited != 1) /* check dmp initialization */
3531 {
3532 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
3533
3534 return 4; /* return error */
3535 }
3536
3537 res = a_mpu6050_iic_read(handle, MPU6050_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
3538 if (res != 0) /* check result */
3539 {
3540 handle->debug_print("mpu6050: read user ctrl failed.\n"); /* read user ctrl failed */
3541
3542 return 1; /* return error */
3543 }
3544 prev &= ~(1 << 7); /* clear config */
3545 prev |= enable << 7; /* set config */
3546 res = a_mpu6050_iic_write(handle, MPU6050_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
3547 if (res != 0) /* check result */
3548 {
3549 handle->debug_print("mpu6050: write user ctrl failed.\n"); /* write user ctrl failed */
3550
3551 return 1; /* return error */
3552 }
3553
3554 return 0; /* success return 0 */
3555}
3556
3573 int32_t gyro_offset_raw[3], int32_t accel_offset_raw[3],
3574 int32_t gyro_offset[3], int32_t accel_offset[3])
3575{
3576 uint8_t res;
3577 uint8_t accel_conf;
3578 uint8_t gyro_conf;
3579
3580 if (handle == NULL) /* check handle */
3581 {
3582 return 2; /* return error */
3583 }
3584 if (handle->inited != 1) /* check handle initialization */
3585 {
3586 return 3; /* return error */
3587 }
3588 if (handle->dmp_inited != 1) /* check dmp initialization */
3589 {
3590 handle->debug_print("mpu6050: dmp is not inited.\n"); /* dmp is not inited */
3591
3592 return 4; /* return error */
3593 }
3594
3595 res = a_mpu6050_iic_read(handle, MPU6050_REG_ACCEL_CONFIG, (uint8_t *)&accel_conf, 1); /* read accel config */
3596 if (res != 0) /* check result */
3597 {
3598 handle->debug_print("mpu6050: read accel config failed.\n"); /* read accel config failed */
3599
3600 return 1; /* return error */
3601 }
3602 res = a_mpu6050_iic_read(handle, MPU6050_REG_GYRO_CONFIG, (uint8_t *)&gyro_conf, 1); /* read gyro config */
3603 if (res != 0) /* check result */
3604 {
3605 handle->debug_print("mpu6050: read gyro config failed.\n"); /* read gyro config failed */
3606
3607 return 1; /* return error */
3608 }
3609 accel_conf = (accel_conf >> 3) & 0x3; /* get the accel conf */
3610 gyro_conf = (gyro_conf >> 3) & 0x3; /* get the gyro conf */
3611 if (accel_conf == 0) /* ±2g */
3612 {
3613 accel_offset[0] = (int32_t)(accel_offset_raw[0] * 16384.0f); /* set accel offset 0 */
3614 accel_offset[1] = (int32_t)(accel_offset_raw[1] * 16384.0f); /* set accel offset 1 */
3615 accel_offset[2] = (int32_t)(accel_offset_raw[2] * 16384.0f); /* set accel offset 2 */
3616 }
3617 else if (accel_conf == 1) /* ±4g */
3618 {
3619 accel_offset[0] = (int32_t)(accel_offset_raw[0] * 8192.0f); /* set accel offset 0 */
3620 accel_offset[1] = (int32_t)(accel_offset_raw[1] * 8192.0f); /* set accel offset 1 */
3621 accel_offset[2] = (int32_t)(accel_offset_raw[2] * 8192.0f); /* set accel offset 2 */
3622 }
3623 else if (accel_conf == 2) /* ±8g */
3624 {
3625 accel_offset[0] = (int32_t)(accel_offset_raw[0] * 4096.0f); /* set accel offset 0 */
3626 accel_offset[1] = (int32_t)(accel_offset_raw[1] * 4096.0f); /* set accel offset 1 */
3627 accel_offset[2] = (int32_t)(accel_offset_raw[2] * 4096.0f); /* set accel offset 2 */
3628 }
3629 else /* ±16g */
3630 {
3631 accel_offset[0] = (int32_t)(accel_offset_raw[0] * 2048.0f); /* set accel offset 0 */
3632 accel_offset[1] = (int32_t)(accel_offset_raw[1] * 2048.0f); /* set accel offset 1 */
3633 accel_offset[2] = (int32_t)(accel_offset_raw[2] * 2048.0f); /* set accel offset 2 */
3634 }
3635 if (gyro_conf == 0) /* ±250dps */
3636 {
3637 gyro_offset[0] = (int32_t)(gyro_offset_raw[0] * 131.f); /* set gyro offset 0 */
3638 gyro_offset[1] = (int32_t)(gyro_offset_raw[1] * 131.f); /* set gyro offset 1 */
3639 gyro_offset[2] = (int32_t)(gyro_offset_raw[2] * 131.f); /* set gyro offset 2 */
3640 }
3641 else if (gyro_conf == 1) /* ±500dps */
3642 {
3643 gyro_offset[0] = (int32_t)(gyro_offset_raw[0] * 65.5f); /* set gyro offset 0 */
3644 gyro_offset[1] = (int32_t)(gyro_offset_raw[1] * 65.5f); /* set gyro offset 1 */
3645 gyro_offset[2] = (int32_t)(gyro_offset_raw[2] * 65.5f); /* set gyro offset 2 */
3646 }
3647 else if (gyro_conf == 2) /* ±1000dps */
3648 {
3649 gyro_offset[0] = (int32_t)(gyro_offset_raw[0] * 32.8f); /* set gyro offset 0 */
3650 gyro_offset[1] = (int32_t)(gyro_offset_raw[1] * 32.8f); /* set gyro offset 1 */
3651 gyro_offset[2] = (int32_t)(gyro_offset_raw[2] * 32.8f); /* set gyro offset 2 */
3652 }
3653 else /* ±2000dps */
3654 {
3655 gyro_offset[0] = (int32_t)(gyro_offset_raw[0] * 16.4f); /* set gyro offset 0 */
3656 gyro_offset[1] = (int32_t)(gyro_offset_raw[1] * 16.4f); /* set gyro offset 1 */
3657 gyro_offset[2] = (int32_t)(gyro_offset_raw[2] * 16.4f); /* set gyro offset 2 */
3658 }
3659
3660 return 0; /* success return 0 */
3661}
3662
3673{
3674 if (handle == NULL) /* check handle */
3675 {
3676 return 2; /* return error */
3677 }
3678
3679 handle->iic_addr = (uint8_t)addr_pin; /* set iic addr */
3680
3681 return 0; /* success return 0 */
3682}
3683
3694{
3695 if (handle == NULL) /* check handle */
3696 {
3697 return 2; /* return error */
3698 }
3699
3700 *addr_pin = (mpu6050_address_t)(handle->iic_addr); /* get iic addr */
3701
3702 return 0; /* success return 0 */
3703}
3704
3718{
3719 uint8_t res, prev;
3720 uint32_t timeout;
3721
3722 if (handle == NULL) /* check handle */
3723 {
3724 return 2; /* return error */
3725 }
3726 if (handle->debug_print == NULL) /* check debug_print */
3727 {
3728 return 3; /* return error */
3729 }
3730 if (handle->iic_init == NULL) /* check iic_init */
3731 {
3732 handle->debug_print("mpu6050: iic_init is null.\n"); /* iic_init is null */
3733
3734 return 3; /* return error */
3735 }
3736 if (handle->iic_deinit == NULL) /* check iic_deinit */
3737 {
3738 handle->debug_print("mpu6050: iic_deinit is null.\n"); /* iic_deinit is null */
3739
3740 return 3; /* return error */
3741 }
3742 if (handle->iic_read == NULL) /* check iic_read */
3743 {
3744 handle->debug_print("mpu6050: iic_read is null.\n"); /* iic_read is null */
3745
3746 return 3; /* return error */
3747 }
3748 if (handle->iic_write == NULL) /* check iic_write */
3749 {
3750 handle->debug_print("mpu6050: iic_write is null.\n"); /* iic_write is null */
3751
3752 return 3; /* return error */
3753 }
3754 if (handle->delay_ms == NULL) /* check delay_ms */
3755 {
3756 handle->debug_print("mpu6050: delay_ms is null.\n"); /* delay_ms is null */
3757
3758 return 3; /* return error */
3759 }
3760 if (handle->receive_callback == NULL) /* check receive_callback */
3761 {
3762 handle->debug_print("mpu6050: receive_callback is null.\n"); /* receive_callback is null */
3763
3764 return 3; /* return error */
3765 }
3766
3767 res = handle->iic_init(); /* iic init */
3768 if (res != 0) /* check the result */
3769 {
3770 handle->debug_print("mpu6050: iic init failed.\n"); /* iic init failed */
3771
3772 return 1; /* return error */
3773 }
3774 res = a_mpu6050_iic_read(handle, MPU6050_REG_WHO_AM_I, &prev, 1); /* read who am I */
3775 if (res != 0) /* check the result */
3776 {
3777 handle->debug_print("mpu6050: read who am i failed.\n"); /* read who am I failed */
3778 (void)handle->iic_deinit(); /* iic deinit */
3779
3780 return 5; /* return error */
3781 }
3782 if (prev != 0x68) /* check the id */
3783 {
3784 handle->debug_print("mpu6050: id is invalid.\n"); /* id is invalid */
3785 (void)handle->iic_deinit(); /* iic deinit */
3786
3787 return 5; /* return error */
3788 }
3789
3790 prev = 1 << 7; /* reset the device */
3791 res = a_mpu6050_iic_write(handle, MPU6050_REG_PWR_MGMT_1, &prev, 1); /* write pwr mgmt 1 */
3792 if (res != 0) /* check the result */
3793 {
3794 handle->debug_print("mpu6050: write pwr mgmt 1 failed.\n"); /* write pwr mgmt 1 failed */
3795 (void)handle->iic_deinit(); /* iic deinit */
3796
3797 return 4; /* return error */
3798 }
3799 timeout = 100; /* set the timeout 1000 ms */
3800 while (timeout != 0) /* check the timeout */
3801 {
3802 handle->delay_ms(10); /* delay 10 ms */
3803 res = a_mpu6050_iic_read(handle, MPU6050_REG_PWR_MGMT_1, &prev, 1); /* read pwr mgmt 1 */
3804 if (res != 0) /* check the result */
3805 {
3806 handle->debug_print("mpu6050: read pwr mgmt 1 failed.\n"); /* read pwr mgmt 1 failed */
3807 (void)handle->iic_deinit(); /* iic deinit */
3808
3809 return 4; /* return error */
3810 }
3811 if ((prev & (1 << 7)) == 0) /* check the result */
3812 {
3813 handle->inited = 1; /* flag the inited bit */
3814 handle->dmp_inited = 0; /* flag closed */
3815
3816 return 0; /* success return 0 */
3817 }
3818 timeout--; /* timeout-- */
3819 }
3820
3821 handle->debug_print("mpu6050: reset failed.\n"); /* reset failed */
3822
3823 return 4; /* return error */
3824}
3825
3838{
3839 uint8_t res;
3840 uint8_t prev;
3841
3842 if (handle == NULL) /* check handle */
3843 {
3844 return 2; /* return error */
3845 }
3846 if (handle->inited != 1) /* check handle initialization */
3847 {
3848 return 3; /* return error */
3849 }
3850
3851 prev = (1 << 6) | (1 << 3) | (7 << 0); /* enter sleep mode */
3852 res = a_mpu6050_iic_write(handle, MPU6050_REG_PWR_MGMT_1, &prev, 1); /* write pwr mgmt 1 */
3853 if (res != 0) /* check the result */
3854 {
3855 handle->debug_print("mpu6050: write pwr mgmt 1 failed.\n"); /* write pwr mgmt 1 failed */
3856
3857 return 4; /* return error */
3858 }
3859 handle->delay_ms(10); /* delay 10 ms */
3860 res = handle->iic_deinit(); /* iic deinit */
3861 if (res != 0) /* check the result */
3862 {
3863 handle->debug_print("mpu6050: iic deinit failed.\n"); /* iic deinit failed */
3864
3865 return 1; /* return error */
3866 }
3867 handle->inited = 0; /* flag closed */
3868 handle->dmp_inited = 0; /* flag closed */
3869
3870 return 0; /* success return 0 */
3871}
3872
3891uint8_t mpu6050_read(mpu6050_handle_t *handle, int16_t (*accel_raw)[3], float (*accel_g)[3],
3892 int16_t (*gyro_raw)[3], float (*gyro_dps)[3], uint16_t *len)
3893{
3894 uint8_t res;
3895 uint8_t prev;
3896 uint8_t accel_conf;
3897 uint8_t gyro_conf;
3898
3899 if (handle == NULL) /* check handle */
3900 {
3901 return 2; /* return error */
3902 }
3903 if (handle->inited != 1) /* check handle initialization */
3904 {
3905 return 3; /* return error */
3906 }
3907 if ((*len) == 0) /* check length */
3908 {
3909 handle->debug_print("mpu6050: length is zero.\n"); /* length is zero */
3910
3911 return 4; /* return error */
3912 }
3913 if (handle->dmp_inited != 0) /* check dmp initialization */
3914 {
3915 handle->debug_print("mpu6050: dmp is running.\n"); /* dmp is running */
3916
3917 return 5; /* return error */
3918 }
3919
3920 res = a_mpu6050_iic_read(handle, MPU6050_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
3921 if (res != 0) /* check result */
3922 {
3923 handle->debug_print("mpu6050: read user ctrl failed.\n"); /* read user ctrl failed */
3924
3925 return 1; /* return error */
3926 }
3927 res = a_mpu6050_iic_read(handle, MPU6050_REG_ACCEL_CONFIG, (uint8_t *)&accel_conf, 1); /* read accel config */
3928 if (res != 0) /* check result */
3929 {
3930 handle->debug_print("mpu6050: read accel config failed.\n"); /* read accel config failed */
3931
3932 return 1; /* return error */
3933 }
3934 res = a_mpu6050_iic_read(handle, MPU6050_REG_GYRO_CONFIG, (uint8_t *)&gyro_conf, 1); /* read gyro config */
3935 if (res != 0) /* check result */
3936 {
3937 handle->debug_print("mpu6050: read gyro config failed.\n"); /* read gyro config failed */
3938
3939 return 1; /* return error */
3940 }
3941 accel_conf = (accel_conf >> 3) & 0x3; /* get the accel conf */
3942 gyro_conf = (gyro_conf >> 3) & 0x3; /* get the gyro conf */
3943 if ((prev & (1 << 6)) != 0) /* if fifo mode */
3944 {
3945 uint8_t conf;
3946 uint8_t buf[2];
3947 uint16_t count;
3948 uint16_t i;
3949
3950 res = a_mpu6050_iic_read(handle, MPU6050_REG_FIFO_EN, (uint8_t *)&conf, 1); /* read fifo enable */
3951 if (res != 0) /* check result */
3952 {
3953 handle->debug_print("mpu6050: read fifo enable failed.\n"); /* read fifo enable failed */
3954
3955 return 1; /* return error */
3956 }
3957 if (conf != 0x78) /* check the conf */
3958 {
3959 handle->debug_print("mpu6050: fifo conf is error.\n"); /* fifo conf is error */
3960
3961 return 6; /* return error */
3962 }
3963
3964 res = a_mpu6050_iic_read(handle, MPU6050_REG_FIFO_COUNTH, (uint8_t *)buf, 2); /* read fifo count */
3965 if (res != 0) /* check result */
3966 {
3967 handle->debug_print("mpu6050: read fifo count failed.\n"); /* read fifo count failed */
3968
3969 return 1; /* return error */
3970 }
3971 count = (uint16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set count */
3972 count = (count < 1024) ? count : 1024; /* just the counter */
3973 count = (count < ((*len) * 12)) ? count : ((*len) * 12); /* just outer buffer size */
3974 count = (count / 12) * 12; /* 12 times */
3975 *len = count / 12; /* set the output length */
3976 res = a_mpu6050_iic_read(handle, MPU6050_REG_R_W, handle->buf, count); /* read data */
3977 if (res != 0) /* check result */
3978 {
3979 handle->debug_print("mpu6050: read failed.\n"); /* read failed */
3980
3981 return 1; /* return error */
3982 }
3983 for (i = 0; i < (*len); i++) /* *len times */
3984 {
3985 accel_raw[i][0] = (int16_t)((uint16_t)handle->buf[i * 12 + 0] << 8) |
3986 handle->buf[i * 12 + 1]; /* set raw accel x */
3987 accel_raw[i][1] = (int16_t)((uint16_t)handle->buf[i * 12 + 2] << 8) |
3988 handle->buf[i * 12 + 3]; /* set raw accel y */
3989 accel_raw[i][2] = (int16_t)((uint16_t)handle->buf[i * 12 + 4] << 8) |
3990 handle->buf[i * 12 + 5]; /* set raw accel z */
3991 gyro_raw[i][0] = (int16_t)((uint16_t)handle->buf[i * 12 + 6] << 8) |
3992 handle->buf[i * 12 + 7]; /* set raw gyro x */
3993 gyro_raw[i][1] = (int16_t)((uint16_t)handle->buf[i * 12 + 8] << 8) |
3994 handle->buf[i * 12 + 9]; /* set raw gyro y */
3995 gyro_raw[i][2] = (int16_t)((uint16_t)handle->buf[i * 12 + 10] << 8) |
3996 handle->buf[i * 12 + 11]; /* set raw gyro z */
3997
3998 if (accel_conf == 0) /* ±2g */
3999 {
4000 accel_g[i][0] = (float)(accel_raw[i][0]) / 16384.0f; /* set accel x */
4001 accel_g[i][1] = (float)(accel_raw[i][1]) / 16384.0f; /* set accel y */
4002 accel_g[i][2] = (float)(accel_raw[i][2]) / 16384.0f; /* set accel z */
4003 }
4004 else if (accel_conf == 1) /* ±4g */
4005 {
4006 accel_g[i][0] = (float)(accel_raw[i][0]) / 8192.0f; /* set accel x */
4007 accel_g[i][1] = (float)(accel_raw[i][1]) / 8192.0f; /* set accel y */
4008 accel_g[i][2] = (float)(accel_raw[i][2]) / 8192.0f; /* set accel z */
4009 }
4010 else if (accel_conf == 2) /* ±8g */
4011 {
4012 accel_g[i][0] = (float)(accel_raw[i][0]) / 4096.0f; /* set accel x */
4013 accel_g[i][1] = (float)(accel_raw[i][1]) / 4096.0f; /* set accel y */
4014 accel_g[i][2] = (float)(accel_raw[i][2]) / 4096.0f; /* set accel z */
4015 }
4016 else /* ±16g */
4017 {
4018 accel_g[i][0] = (float)(accel_raw[i][0]) / 2048.0f; /* set accel x */
4019 accel_g[i][1] = (float)(accel_raw[i][1]) / 2048.0f; /* set accel y */
4020 accel_g[i][2] = (float)(accel_raw[i][2]) / 2048.0f; /* set accel z */
4021 }
4022
4023 if (gyro_conf == 0) /* ±250dps */
4024 {
4025 gyro_dps[i][0] = (float)(gyro_raw[i][0]) / 131.0f; /* set gyro x */
4026 gyro_dps[i][1] = (float)(gyro_raw[i][1]) / 131.0f; /* set gyro y */
4027 gyro_dps[i][2] = (float)(gyro_raw[i][2]) / 131.0f; /* set gyro z */
4028 }
4029 else if (gyro_conf == 1) /* ±500dps */
4030 {
4031 gyro_dps[i][0] = (float)(gyro_raw[i][0]) / 65.5f; /* set gyro x */
4032 gyro_dps[i][1] = (float)(gyro_raw[i][1]) / 65.5f; /* set gyro y */
4033 gyro_dps[i][2] = (float)(gyro_raw[i][2]) / 65.5f; /* set gyro z */
4034 }
4035 else if (gyro_conf == 2) /* ±1000dps */
4036 {
4037 gyro_dps[i][0] = (float)(gyro_raw[i][0]) / 32.8f; /* set gyro x */
4038 gyro_dps[i][1] = (float)(gyro_raw[i][1]) / 32.8f; /* set gyro y */
4039 gyro_dps[i][2] = (float)(gyro_raw[i][2]) / 32.8f; /* set gyro z */
4040 }
4041 else /* ±2000dps */
4042 {
4043 gyro_dps[i][0] = (float)(gyro_raw[i][0]) / 16.4f; /* set gyro x */
4044 gyro_dps[i][1] = (float)(gyro_raw[i][1]) / 16.4f; /* set gyro y */
4045 gyro_dps[i][2] = (float)(gyro_raw[i][2]) / 16.4f; /* set gyro z */
4046 }
4047 }
4048
4049 return 0; /* success return 0 */
4050 }
4051 else /* if normal mode */
4052 {
4053 *len = 1; /* set 1 */
4054 res = a_mpu6050_iic_read(handle, MPU6050_REG_ACCEL_XOUT_H, handle->buf, 14); /* read data */
4055 if (res != 0) /* check result */
4056 {
4057 handle->debug_print("mpu6050: read failed.\n"); /* read failed */
4058
4059 return 1; /* return error */
4060 }
4061 accel_raw[0][0] = (int16_t)((uint16_t)handle->buf[0] << 8) | handle->buf[1]; /* set raw accel x */
4062 accel_raw[0][1] = (int16_t)((uint16_t)handle->buf[2] << 8) | handle->buf[3]; /* set raw accel y */
4063 accel_raw[0][2] = (int16_t)((uint16_t)handle->buf[4] << 8) | handle->buf[5]; /* set raw accel z */
4064 gyro_raw[0][0] = (int16_t)((uint16_t)handle->buf[8] << 8) | handle->buf[9]; /* set raw gyro x */
4065 gyro_raw[0][1] = (int16_t)((uint16_t)handle->buf[10] << 8) | handle->buf[11]; /* set raw gyro y */
4066 gyro_raw[0][2] = (int16_t)((uint16_t)handle->buf[12] << 8) | handle->buf[13]; /* set raw gyro z */
4067
4068 if (accel_conf == 0) /* ±2g */
4069 {
4070 accel_g[0][0] = (float)(accel_raw[0][0]) / 16384.0f; /* set accel x */
4071 accel_g[0][1] = (float)(accel_raw[0][1]) / 16384.0f; /* set accel y */
4072 accel_g[0][2] = (float)(accel_raw[0][2]) / 16384.0f; /* set accel z */
4073 }
4074 else if (accel_conf == 1) /* ±4g */
4075 {
4076 accel_g[0][0] = (float)(accel_raw[0][0]) / 8192.0f; /* set accel x */
4077 accel_g[0][1] = (float)(accel_raw[0][1]) / 8192.0f; /* set accel y */
4078 accel_g[0][2] = (float)(accel_raw[0][2]) / 8192.0f; /* set accel z */
4079 }
4080 else if (accel_conf == 2) /* ±8g */
4081 {
4082 accel_g[0][0] = (float)(accel_raw[0][0]) / 4096.0f; /* set accel x */
4083 accel_g[0][1] = (float)(accel_raw[0][1]) / 4096.0f; /* set accel y */
4084 accel_g[0][2] = (float)(accel_raw[0][2]) / 4096.0f; /* set accel z */
4085 }
4086 else /* ±16g */
4087 {
4088 accel_g[0][0] = (float)(accel_raw[0][0]) / 2048.0f; /* set accel x */
4089 accel_g[0][1] = (float)(accel_raw[0][1]) / 2048.0f; /* set accel y */
4090 accel_g[0][2] = (float)(accel_raw[0][2]) / 2048.0f; /* set accel z */
4091 }
4092
4093 if (gyro_conf == 0) /* ±250dps */
4094 {
4095 gyro_dps[0][0] = (float)(gyro_raw[0][0]) / 131.0f; /* set gyro x */
4096 gyro_dps[0][1] = (float)(gyro_raw[0][1]) / 131.0f; /* set gyro y */
4097 gyro_dps[0][2] = (float)(gyro_raw[0][2]) / 131.0f; /* set gyro z */
4098 }
4099 else if (gyro_conf == 1) /* ±500dps */
4100 {
4101 gyro_dps[0][0] = (float)(gyro_raw[0][0]) / 65.5f; /* set gyro x */
4102 gyro_dps[0][1] = (float)(gyro_raw[0][1]) / 65.5f; /* set gyro y */
4103 gyro_dps[0][2] = (float)(gyro_raw[0][2]) / 65.5f; /* set gyro z */
4104 }
4105 else if (gyro_conf == 2) /* ±1000dps */
4106 {
4107 gyro_dps[0][0] = (float)(gyro_raw[0][0]) / 32.8f; /* set gyro x */
4108 gyro_dps[0][1] = (float)(gyro_raw[0][1]) / 32.8f; /* set gyro y */
4109 gyro_dps[0][2] = (float)(gyro_raw[0][2]) / 32.8f; /* set gyro z */
4110 }
4111 else /* ±2000dps */
4112 {
4113 gyro_dps[0][0] = (float)(gyro_raw[0][0]) / 16.4f; /* set gyro x */
4114 gyro_dps[0][1] = (float)(gyro_raw[0][1]) / 16.4f; /* set gyro y */
4115 gyro_dps[0][2] = (float)(gyro_raw[0][2]) / 16.4f; /* set gyro z */
4116 }
4117
4118 return 0; /* success return 0 */
4119 }
4120}
4121
4134uint8_t mpu6050_read_temperature(mpu6050_handle_t *handle, int16_t (*raw), float *degrees)
4135{
4136 uint8_t res;
4137 uint8_t buf[2];
4138
4139 if (handle == NULL) /* check handle */
4140 {
4141 return 2; /* return error */
4142 }
4143 if (handle->inited != 1) /* check handle initialization */
4144 {
4145 return 3; /* return error */
4146 }
4147
4148 res = a_mpu6050_iic_read(handle, MPU6050_REG_TEMP_OUT_H, buf, 2); /* read data */
4149 if (res != 0) /* check result */
4150 {
4151 handle->debug_print("mpu6050: read failed.\n"); /* read failed */
4152
4153 return 1; /* return error */
4154 }
4155 *raw = (int16_t)((uint16_t)buf[0] << 8) | buf[1]; /* get the raw */
4156 *degrees = (float)(*raw) / 340.0f + 36.53f; /* convert the degrees */
4157
4158 return 0; /* success return 0 */
4159}
4160
4172{
4173 uint8_t res;
4174 uint8_t prev;
4175
4176 if (handle == NULL) /* check handle */
4177 {
4178 return 2; /* return error */
4179 }
4180 if (handle->inited != 1) /* check handle initialization */
4181 {
4182 return 3; /* return error */
4183 }
4184
4185 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_STATUS, (uint8_t *)&prev, 1); /* read config */
4186 if (res != 0) /* check result */
4187 {
4188 handle->debug_print("mpu6050: read int status failed.\n"); /* read int status failed */
4189
4190 return 1; /* return error */
4191 }
4192 if ((prev & (1 << MPU6050_INTERRUPT_MOTION)) != 0) /* if motion */
4193 {
4194 if (handle->receive_callback != NULL) /* if receive callback */
4195 {
4196 handle->receive_callback(MPU6050_INTERRUPT_MOTION); /* run callback */
4197 }
4198 }
4199 if ((prev & (1 << MPU6050_INTERRUPT_FIFO_OVERFLOW)) != 0) /* if fifo overflow */
4200 {
4201 if (handle->receive_callback != NULL) /* if receive callback */
4202 {
4203 handle->receive_callback(MPU6050_INTERRUPT_FIFO_OVERFLOW); /* run callback */
4204 }
4205 (void)a_mpu6050_reset_fifo(handle); /* reset the fifo */
4206 }
4207 if ((prev & (1 << MPU6050_INTERRUPT_I2C_MAST)) != 0) /* if i2c master */
4208 {
4209 if (handle->receive_callback != NULL) /* if receive callback */
4210 {
4211 handle->receive_callback(MPU6050_INTERRUPT_I2C_MAST); /* run callback */
4212 }
4213 }
4214 if ((prev & (1 << MPU6050_INTERRUPT_DMP)) != 0) /* if dmp */
4215 {
4216 if (handle->receive_callback != NULL) /* if receive callback */
4217 {
4218 handle->receive_callback(MPU6050_INTERRUPT_DMP); /* run callback */
4219 }
4220 }
4221 if ((prev & (1 << MPU6050_INTERRUPT_DATA_READY)) != 0) /* if data ready */
4222 {
4223 if (handle->receive_callback != NULL) /* if receive callback */
4224 {
4225 handle->receive_callback(MPU6050_INTERRUPT_DATA_READY); /* run callback */
4226 }
4227 }
4228
4229 return 0; /* success return 0 */
4230}
4231
4244{
4245 uint8_t res;
4246 uint8_t prev;
4247
4248 if (handle == NULL) /* check handle */
4249 {
4250 return 2; /* return error */
4251 }
4252 if (handle->inited != 1) /* check handle initialization */
4253 {
4254 return 3; /* return error */
4255 }
4256
4257 res = a_mpu6050_iic_read(handle, MPU6050_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4258 if (res != 0) /* check result */
4259 {
4260 handle->debug_print("mpu6050: read user ctrl failed.\n"); /* read user ctrl failed */
4261
4262 return 1; /* return error */
4263 }
4264 prev &= ~(1 << 6); /* clear config */
4265 prev |= enable << 6; /* set config */
4266 res = a_mpu6050_iic_write(handle, MPU6050_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
4267 if (res != 0) /* check result */
4268 {
4269 handle->debug_print("mpu6050: write user ctrl failed.\n"); /* write user ctrl failed */
4270
4271 return 1; /* return error */
4272 }
4273
4274 return 0; /* success return 0 */
4275}
4276
4289{
4290 uint8_t res;
4291 uint8_t prev;
4292
4293 if (handle == NULL) /* check handle */
4294 {
4295 return 2; /* return error */
4296 }
4297 if (handle->inited != 1) /* check handle initialization */
4298 {
4299 return 3; /* return error */
4300 }
4301
4302 res = a_mpu6050_iic_read(handle, MPU6050_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4303 if (res != 0) /* check result */
4304 {
4305 handle->debug_print("mpu6050: read user ctrl failed.\n"); /* read user ctrl failed */
4306
4307 return 1; /* return error */
4308 }
4309 *enable = (mpu6050_bool_t)((prev >> 6) & 0x01); /* get bool */
4310
4311 return 0; /* success return 0 */
4312}
4313
4325{
4326 uint8_t res;
4327
4328 if (handle == NULL) /* check handle */
4329 {
4330 return 2; /* return error */
4331 }
4332 if (handle->inited != 1) /* check handle initialization */
4333 {
4334 return 3; /* return error */
4335 }
4336
4337 res = a_mpu6050_reset_fifo(handle); /* reset the fifo */
4338 if (res != 0) /* check result */
4339 {
4340 handle->debug_print("mpu6050: force reset fifo failed.\n"); /* force reset fifo failed */
4341
4342 return 1; /* return error */
4343 }
4344
4345 return 0; /* success return 0 */
4346}
4347
4360{
4361 uint8_t res;
4362 uint8_t prev;
4363
4364 if (handle == NULL) /* check handle */
4365 {
4366 return 2; /* return error */
4367 }
4368 if (handle->inited != 1) /* check handle initialization */
4369 {
4370 return 3; /* return error */
4371 }
4372
4373 res = a_mpu6050_iic_read(handle, MPU6050_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4374 if (res != 0) /* check result */
4375 {
4376 handle->debug_print("mpu6050: read user ctrl failed.\n"); /* read user ctrl failed */
4377
4378 return 1; /* return error */
4379 }
4380 prev &= ~(1 << 5); /* clear config */
4381 prev |= enable << 5; /* set config */
4382 res = a_mpu6050_iic_write(handle, MPU6050_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
4383 if (res != 0) /* check result */
4384 {
4385 handle->debug_print("mpu6050: write user ctrl failed.\n"); /* write user ctrl failed */
4386
4387 return 1; /* return error */
4388 }
4389
4390 return 0; /* success return 0 */
4391}
4392
4405{
4406 uint8_t res;
4407 uint8_t prev;
4408
4409 if (handle == NULL) /* check handle */
4410 {
4411 return 2; /* return error */
4412 }
4413 if (handle->inited != 1) /* check handle initialization */
4414 {
4415 return 3; /* return error */
4416 }
4417
4418 res = a_mpu6050_iic_read(handle, MPU6050_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4419 if (res != 0) /* check result */
4420 {
4421 handle->debug_print("mpu6050: read user ctrl failed.\n"); /* read user ctrl failed */
4422
4423 return 1; /* return error */
4424 }
4425 *enable = (mpu6050_bool_t)((prev >> 5) & 0x01); /* get bool */
4426
4427 return 0; /* success return 0 */
4428}
4429
4441{
4442 uint8_t res;
4443 uint8_t prev;
4444
4445 if (handle == NULL) /* check handle */
4446 {
4447 return 2; /* return error */
4448 }
4449 if (handle->inited != 1) /* check handle initialization */
4450 {
4451 return 3; /* return error */
4452 }
4453
4454 res = a_mpu6050_iic_read(handle, MPU6050_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4455 if (res != 0) /* check result */
4456 {
4457 handle->debug_print("mpu6050: read user ctrl failed.\n"); /* read user ctrl failed */
4458
4459 return 1; /* return error */
4460 }
4461 prev &= ~(1 << 2); /* clear config */
4462 prev |= 1 << 2; /* set config */
4463 res = a_mpu6050_iic_write(handle, MPU6050_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
4464 if (res != 0) /* check result */
4465 {
4466 handle->debug_print("mpu6050: write user ctrl failed.\n"); /* write user ctrl failed */
4467
4468 return 1; /* return error */
4469 }
4470
4471 return 0; /* success return 0 */
4472}
4473
4486{
4487 uint8_t res;
4488 uint8_t prev;
4489
4490 if (handle == NULL) /* check handle */
4491 {
4492 return 2; /* return error */
4493 }
4494 if (handle->inited != 1) /* check handle initialization */
4495 {
4496 return 3; /* return error */
4497 }
4498
4499 res = a_mpu6050_iic_read(handle, MPU6050_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4500 if (res != 0) /* check result */
4501 {
4502 handle->debug_print("mpu6050: read user ctrl failed.\n"); /* read user ctrl failed */
4503
4504 return 1; /* return error */
4505 }
4506 *enable = (mpu6050_bool_t)((prev >> 2) & 0x01); /* get bool */
4507
4508 return 0; /* success return 0 */
4509}
4510
4522{
4523 uint8_t res;
4524 uint8_t prev;
4525
4526 if (handle == NULL) /* check handle */
4527 {
4528 return 2; /* return error */
4529 }
4530 if (handle->inited != 1) /* check handle initialization */
4531 {
4532 return 3; /* return error */
4533 }
4534
4535 res = a_mpu6050_iic_read(handle, MPU6050_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4536 if (res != 0) /* check result */
4537 {
4538 handle->debug_print("mpu6050: read user ctrl failed.\n"); /* read user ctrl failed */
4539
4540 return 1; /* return error */
4541 }
4542 prev &= ~(1 << 1); /* clear config */
4543 prev |= 1 << 1; /* set config */
4544 res = a_mpu6050_iic_write(handle, MPU6050_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
4545 if (res != 0) /* check result */
4546 {
4547 handle->debug_print("mpu6050: write user ctrl failed.\n"); /* write user ctrl failed */
4548
4549 return 1; /* return error */
4550 }
4551
4552 return 0; /* success return 0 */
4553}
4554
4567{
4568 uint8_t res;
4569 uint8_t prev;
4570
4571 if (handle == NULL) /* check handle */
4572 {
4573 return 2; /* return error */
4574 }
4575 if (handle->inited != 1) /* check handle initialization */
4576 {
4577 return 3; /* return error */
4578 }
4579
4580 res = a_mpu6050_iic_read(handle, MPU6050_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4581 if (res != 0) /* check result */
4582 {
4583 handle->debug_print("mpu6050: read user ctrl failed.\n"); /* read user ctrl failed */
4584
4585 return 1; /* return error */
4586 }
4587 *enable = (mpu6050_bool_t)((prev >> 1) & 0x01); /* get bool */
4588
4589 return 0; /* success return 0 */
4590}
4591
4603{
4604 uint8_t res;
4605 uint8_t prev;
4606
4607 if (handle == NULL) /* check handle */
4608 {
4609 return 2; /* return error */
4610 }
4611 if (handle->inited != 1) /* check handle initialization */
4612 {
4613 return 3; /* return error */
4614 }
4615
4616 res = a_mpu6050_iic_read(handle, MPU6050_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4617 if (res != 0) /* check result */
4618 {
4619 handle->debug_print("mpu6050: read user ctrl failed.\n"); /* read user ctrl failed */
4620
4621 return 1; /* return error */
4622 }
4623 prev &= ~(1 << 0); /* clear config */
4624 prev |= 1 << 0; /* set config */
4625 res = a_mpu6050_iic_write(handle, MPU6050_REG_USER_CTRL, (uint8_t *)&prev, 1); /* write config */
4626 if (res != 0) /* check result */
4627 {
4628 handle->debug_print("mpu6050: write user ctrl failed.\n"); /* write user ctrl failed */
4629
4630 return 1; /* return error */
4631 }
4632
4633 return 0; /* success return 0 */
4634}
4635
4648{
4649 uint8_t res;
4650 uint8_t prev;
4651
4652 if (handle == NULL) /* check handle */
4653 {
4654 return 2; /* return error */
4655 }
4656 if (handle->inited != 1) /* check handle initialization */
4657 {
4658 return 3; /* return error */
4659 }
4660
4661 res = a_mpu6050_iic_read(handle, MPU6050_REG_USER_CTRL, (uint8_t *)&prev, 1); /* read config */
4662 if (res != 0) /* check result */
4663 {
4664 handle->debug_print("mpu6050: read user ctrl failed.\n"); /* read user ctrl failed */
4665
4666 return 1; /* return error */
4667 }
4668 *enable = (mpu6050_bool_t)((prev >> 0) & 0x01); /* get bool */
4669
4670 return 0; /* success return 0 */
4671}
4672
4684{
4685 uint8_t res;
4686 uint8_t prev;
4687
4688 if (handle == NULL) /* check handle */
4689 {
4690 return 2; /* return error */
4691 }
4692 if (handle->inited != 1) /* check handle initialization */
4693 {
4694 return 3; /* return error */
4695 }
4696
4697 res = a_mpu6050_iic_read(handle, MPU6050_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
4698 if (res != 0) /* check result */
4699 {
4700 handle->debug_print("mpu6050: read power management 1 failed.\n"); /* read power management 1 failed */
4701
4702 return 1; /* return error */
4703 }
4704 prev &= ~(1 << 7); /* clear config */
4705 prev |= 1 << 7; /* set config */
4706 res = a_mpu6050_iic_write(handle, MPU6050_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
4707 if (res != 0) /* check result */
4708 {
4709 handle->debug_print("mpu6050: write power management 1 failed.\n"); /* write power management 1 failed */
4710
4711 return 1; /* return error */
4712 }
4713 handle->delay_ms(10); /* delay 10 ms */
4714
4715 return 0; /* success return 0 */
4716}
4717
4730{
4731 uint8_t res;
4732 uint8_t prev;
4733
4734 if (handle == NULL) /* check handle */
4735 {
4736 return 2; /* return error */
4737 }
4738 if (handle->inited != 1) /* check handle initialization */
4739 {
4740 return 3; /* return error */
4741 }
4742
4743 res = a_mpu6050_iic_read(handle, MPU6050_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
4744 if (res != 0) /* check result */
4745 {
4746 handle->debug_print("mpu6050: read power management 1 failed.\n"); /* read power management 1 failed */
4747
4748 return 1; /* return error */
4749 }
4750 *enable = (mpu6050_bool_t)((prev >> 7) & 0x01); /* get bool */
4751
4752 return 0; /* success return 0 */
4753}
4754
4767{
4768 uint8_t res;
4769 uint8_t prev;
4770
4771 if (handle == NULL) /* check handle */
4772 {
4773 return 2; /* return error */
4774 }
4775 if (handle->inited != 1) /* check handle initialization */
4776 {
4777 return 3; /* return error */
4778 }
4779
4780 res = a_mpu6050_iic_read(handle, MPU6050_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
4781 if (res != 0) /* check result */
4782 {
4783 handle->debug_print("mpu6050: read power management 1 failed.\n"); /* read power management 1 failed */
4784
4785 return 1; /* return error */
4786 }
4787 prev &= ~(0x7 << 0); /* clear config */
4788 prev |= clock_source << 0; /* set config */
4789 res = a_mpu6050_iic_write(handle, MPU6050_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
4790 if (res != 0) /* check result */
4791 {
4792 handle->debug_print("mpu6050: write power management 1 failed.\n"); /* write power management 1 failed */
4793
4794 return 1; /* return error */
4795 }
4796
4797 return 0; /* success return 0 */
4798}
4799
4812{
4813 uint8_t res;
4814 uint8_t prev;
4815
4816 if (handle == NULL) /* check handle */
4817 {
4818 return 2; /* return error */
4819 }
4820 if (handle->inited != 1) /* check handle initialization */
4821 {
4822 return 3; /* return error */
4823 }
4824
4825 res = a_mpu6050_iic_read(handle, MPU6050_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
4826 if (res != 0) /* check result */
4827 {
4828 handle->debug_print("mpu6050: read power management 1 failed.\n"); /* read power management 1 failed */
4829
4830 return 1; /* return error */
4831 }
4832 *clock_source = (mpu6050_clock_source_t)((prev >> 0) & (0x7)); /* get clock source */
4833
4834 return 0; /* success return 0 */
4835}
4836
4849{
4850 uint8_t res;
4851 uint8_t prev;
4852
4853 if (handle == NULL) /* check handle */
4854 {
4855 return 2; /* return error */
4856 }
4857 if (handle->inited != 1) /* check handle initialization */
4858 {
4859 return 3; /* return error */
4860 }
4861
4862 res = a_mpu6050_iic_read(handle, MPU6050_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
4863 if (res != 0) /* check result */
4864 {
4865 handle->debug_print("mpu6050: read power management 1 failed.\n"); /* read power management 1 failed */
4866
4867 return 1; /* return error */
4868 }
4869 prev &= ~(1 << 3); /* clear config */
4870 prev |= (!enable) << 3; /* set config */
4871 res = a_mpu6050_iic_write(handle, MPU6050_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
4872 if (res != 0) /* check result */
4873 {
4874 handle->debug_print("mpu6050: write power management 1 failed.\n"); /* write power management 1 failed */
4875
4876 return 1; /* return error */
4877 }
4878
4879 return 0; /* success return 0 */
4880}
4881
4894{
4895 uint8_t res;
4896 uint8_t prev;
4897
4898 if (handle == NULL) /* check handle */
4899 {
4900 return 2; /* return error */
4901 }
4902 if (handle->inited != 1) /* check handle initialization */
4903 {
4904 return 3; /* return error */
4905 }
4906
4907 res = a_mpu6050_iic_read(handle, MPU6050_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
4908 if (res != 0) /* check result */
4909 {
4910 handle->debug_print("mpu6050: read power management 1 failed.\n"); /* read power management 1 failed */
4911
4912 return 1; /* return error */
4913 }
4914 *enable = (mpu6050_bool_t)(!((prev >> 3) & (0x1))); /* get bool */
4915
4916 return 0; /* success return 0 */
4917}
4918
4931{
4932 uint8_t res;
4933 uint8_t prev;
4934
4935 if (handle == NULL) /* check handle */
4936 {
4937 return 2; /* return error */
4938 }
4939 if (handle->inited != 1) /* check handle initialization */
4940 {
4941 return 3; /* return error */
4942 }
4943
4944 res = a_mpu6050_iic_read(handle, MPU6050_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
4945 if (res != 0) /* check result */
4946 {
4947 handle->debug_print("mpu6050: read power management 1 failed.\n"); /* read power management 1 failed */
4948
4949 return 1; /* return error */
4950 }
4951 prev &= ~(1 << 5); /* clear config */
4952 prev |= enable << 5; /* set config */
4953 res = a_mpu6050_iic_write(handle, MPU6050_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
4954 if (res != 0) /* check result */
4955 {
4956 handle->debug_print("mpu6050: write power management 1 failed.\n"); /* write power management 1 failed */
4957
4958 return 1; /* return error */
4959 }
4960
4961 return 0; /* success return 0 */
4962}
4963
4976{
4977 uint8_t res;
4978 uint8_t prev;
4979
4980 if (handle == NULL) /* check handle */
4981 {
4982 return 2; /* return error */
4983 }
4984 if (handle->inited != 1) /* check handle initialization */
4985 {
4986 return 3; /* return error */
4987 }
4988
4989 res = a_mpu6050_iic_read(handle, MPU6050_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
4990 if (res != 0) /* check result */
4991 {
4992 handle->debug_print("mpu6050: read power management 1 failed.\n"); /* read power management 1 failed */
4993
4994 return 1; /* return error */
4995 }
4996 *enable = (mpu6050_bool_t)((prev >> 5) & (0x1)); /* get bool */
4997
4998 return 0; /* success return 0 */
4999}
5000
5013{
5014 uint8_t res;
5015 uint8_t prev;
5016
5017 if (handle == NULL) /* check handle */
5018 {
5019 return 2; /* return error */
5020 }
5021 if (handle->inited != 1) /* check handle initialization */
5022 {
5023 return 3; /* return error */
5024 }
5025
5026 res = a_mpu6050_iic_read(handle, MPU6050_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
5027 if (res != 0) /* check result */
5028 {
5029 handle->debug_print("mpu6050: read power management 1 failed.\n"); /* read power management 1 failed */
5030
5031 return 1; /* return error */
5032 }
5033 prev &= ~(1 << 6); /* clear config */
5034 prev |= enable << 6; /* set config */
5035 res = a_mpu6050_iic_write(handle, MPU6050_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
5036 if (res != 0) /* check result */
5037 {
5038 handle->debug_print("mpu6050: write power management 1 failed.\n"); /* write power management 1 failed */
5039
5040 return 1; /* return error */
5041 }
5042
5043 return 0; /* success return 0 */
5044}
5045
5058{
5059 uint8_t res;
5060 uint8_t prev;
5061
5062 if (handle == NULL) /* check handle */
5063 {
5064 return 2; /* return error */
5065 }
5066 if (handle->inited != 1) /* check handle initialization */
5067 {
5068 return 3; /* return error */
5069 }
5070
5071 res = a_mpu6050_iic_read(handle, MPU6050_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
5072 if (res != 0) /* check result */
5073 {
5074 handle->debug_print("mpu6050: read power management 1 failed.\n"); /* read power management 1 failed */
5075
5076 return 1; /* return error */
5077 }
5078 *enable = (mpu6050_bool_t)((prev >> 6) & (0x1)); /* get bool */
5079
5080 return 0; /* success return 0 */
5081}
5082
5096{
5097 uint8_t res;
5098 uint8_t prev;
5099
5100 if (handle == NULL) /* check handle */
5101 {
5102 return 2; /* return error */
5103 }
5104 if (handle->inited != 1) /* check handle initialization */
5105 {
5106 return 3; /* return error */
5107 }
5108
5109 res = a_mpu6050_iic_read(handle, MPU6050_REG_PWR_MGMT_2, (uint8_t *)&prev, 1); /* read config */
5110 if (res != 0) /* check result */
5111 {
5112 handle->debug_print("mpu6050: read power management 2 failed.\n"); /* read power management 2 failed */
5113
5114 return 1; /* return error */
5115 }
5116 prev &= ~(1 << source); /* clear config */
5117 prev |= enable << source; /* set config */
5118 res = a_mpu6050_iic_write(handle, MPU6050_REG_PWR_MGMT_2, (uint8_t *)&prev, 1); /* write config */
5119 if (res != 0) /* check result */
5120 {
5121 handle->debug_print("mpu6050: write power management 2 failed.\n"); /* write power management 2 failed */
5122
5123 return 1; /* return error */
5124 }
5125
5126 return 0; /* success return 0 */
5127}
5128
5142{
5143 uint8_t res;
5144 uint8_t prev;
5145
5146 if (handle == NULL) /* check handle */
5147 {
5148 return 2; /* return error */
5149 }
5150 if (handle->inited != 1) /* check handle initialization */
5151 {
5152 return 3; /* return error */
5153 }
5154
5155 res = a_mpu6050_iic_read(handle, MPU6050_REG_PWR_MGMT_2, (uint8_t *)&prev, 1); /* read config */
5156 if (res != 0) /* check result */
5157 {
5158 handle->debug_print("mpu6050: read power management 2 failed.\n"); /* read power management 2 failed */
5159
5160 return 1; /* return error */
5161 }
5162 *enable = (mpu6050_bool_t)((prev >> source) & (0x1)); /* get bool */
5163
5164 return 0; /* success return 0 */
5165}
5166
5179{
5180 uint8_t res;
5181 uint8_t prev;
5182
5183 if (handle == NULL) /* check handle */
5184 {
5185 return 2; /* return error */
5186 }
5187 if (handle->inited != 1) /* check handle initialization */
5188 {
5189 return 3; /* return error */
5190 }
5191
5192 res = a_mpu6050_iic_read(handle, MPU6050_REG_PWR_MGMT_2, (uint8_t *)&prev, 1); /* read config */
5193 if (res != 0) /* check result */
5194 {
5195 handle->debug_print("mpu6050: read power management 2 failed.\n"); /* read power management 2 failed */
5196
5197 return 1; /* return error */
5198 }
5199 prev &= ~(0x3 << 6); /* clear config */
5200 prev |= frequency << 6; /* set config */
5201 res = a_mpu6050_iic_write(handle, MPU6050_REG_PWR_MGMT_2, (uint8_t *)&prev, 1); /* write config */
5202 if (res != 0) /* check result */
5203 {
5204 handle->debug_print("mpu6050: write power management 2 failed.\n"); /* write power management 2 failed */
5205
5206 return 1; /* return error */
5207 }
5208
5209 return 0; /* success return 0 */
5210}
5211
5224{
5225 uint8_t res;
5226 uint8_t prev;
5227
5228 if (handle == NULL) /* check handle */
5229 {
5230 return 2; /* return error */
5231 }
5232 if (handle->inited != 1) /* check handle initialization */
5233 {
5234 return 3; /* return error */
5235 }
5236
5237 res = a_mpu6050_iic_read(handle, MPU6050_REG_PWR_MGMT_2, (uint8_t *)&prev, 1); /* read config */
5238 if (res != 0) /* check result */
5239 {
5240 handle->debug_print("mpu6050: read power management 2 failed.\n"); /* read power management 2 failed */
5241
5242 return 1; /* return error */
5243 }
5244 *frequency = (mpu6050_wake_up_frequency_t)((prev >> 6) & 0x03); /* get frequency */
5245
5246 return 0; /* success return 0 */
5247}
5248
5260uint8_t mpu6050_get_fifo_count(mpu6050_handle_t *handle, uint16_t* count)
5261{
5262 uint8_t res;
5263 uint8_t buf[2];
5264
5265 if (handle == NULL) /* check handle */
5266 {
5267 return 2; /* return error */
5268 }
5269 if (handle->inited != 1) /* check handle initialization */
5270 {
5271 return 3; /* return error */
5272 }
5273
5274 res = a_mpu6050_iic_read(handle, MPU6050_REG_FIFO_COUNTH, (uint8_t *)buf, 2); /* read fifo count */
5275 if (res != 0) /* check result */
5276 {
5277 handle->debug_print("mpu6050: read fifo count failed.\n"); /* read fifo count failed */
5278
5279 return 1; /* return error */
5280 }
5281 *count = (uint16_t)(((uint16_t)buf[0] << 8) | buf[1]); /* set count */
5282
5283 return 0; /* success return 0 */
5284}
5285
5298uint8_t mpu6050_fifo_get(mpu6050_handle_t *handle, uint8_t *buf, uint16_t len)
5299{
5300 uint8_t res;
5301
5302 if (handle == NULL) /* check handle */
5303 {
5304 return 2; /* return error */
5305 }
5306 if (handle->inited != 1) /* check handle initialization */
5307 {
5308 return 3; /* return error */
5309 }
5310
5311 res = a_mpu6050_iic_read(handle, MPU6050_REG_R_W, buf, len); /* read fifo */
5312 if (res != 0) /* check result */
5313 {
5314 handle->debug_print("mpu6050: fifo read failed.\n"); /* fifo read failed */
5315
5316 return 1; /* return error */
5317 }
5318
5319 return 0; /* success return 0 */
5320}
5321
5334uint8_t mpu6050_fifo_set(mpu6050_handle_t *handle, uint8_t *buf, uint16_t len)
5335{
5336 uint8_t res;
5337
5338 if (handle == NULL) /* check handle */
5339 {
5340 return 2; /* return error */
5341 }
5342 if (handle->inited != 1) /* check handle initialization */
5343 {
5344 return 3; /* return error */
5345 }
5346
5347 res = a_mpu6050_iic_write(handle, MPU6050_REG_R_W, buf, len); /* write fifo */
5348 if (res != 0) /* check result */
5349 {
5350 handle->debug_print("mpu6050: fifo write failed.\n"); /* fifo write failed */
5351
5352 return 1; /* return error */
5353 }
5354
5355 return 0; /* success return 0 */
5356}
5357
5370{
5371 uint8_t res;
5372 uint8_t prev;
5373
5374 if (handle == NULL) /* check handle */
5375 {
5376 return 2; /* return error */
5377 }
5378 if (handle->inited != 1) /* check handle initialization */
5379 {
5380 return 3; /* return error */
5381 }
5382
5383 res = a_mpu6050_iic_read(handle, MPU6050_REG_SIGNAL_PATH_RESET, (uint8_t *)&prev, 1); /* read config */
5384 if (res != 0) /* check result */
5385 {
5386 handle->debug_print("mpu6050: read signal path reset failed.\n"); /* read signal path reset failed */
5387
5388 return 1; /* return error */
5389 }
5390 prev &= ~(1 << path); /* clear config */
5391 prev |= 1 << path; /* set config */
5392 res = a_mpu6050_iic_write(handle, MPU6050_REG_SIGNAL_PATH_RESET, (uint8_t *)&prev, 1); /* write config */
5393 if (res != 0) /* check result */
5394 {
5395 handle->debug_print("mpu6050: write signal path reset failed.\n"); /* write signal path reset failed */
5396
5397 return 1; /* return error */
5398 }
5399
5400 return 0; /* success return 0 */
5401}
5402
5415{
5416 uint8_t res;
5417
5418 if (handle == NULL) /* check handle */
5419 {
5420 return 2; /* return error */
5421 }
5422 if (handle->inited != 1) /* check handle initialization */
5423 {
5424 return 3; /* return error */
5425 }
5426
5427 res = a_mpu6050_iic_write(handle, MPU6050_REG_SMPRT_DIV, (uint8_t *)&d, 1); /* write config */
5428 if (res != 0) /* check result */
5429 {
5430 handle->debug_print("mpu6050: write smprt div failed.\n"); /* write smprt div failed */
5431
5432 return 1; /* return error */
5433 }
5434
5435 return 0; /* success return 0 */
5436}
5437
5450{
5451 uint8_t res;
5452
5453 if (handle == NULL) /* check handle */
5454 {
5455 return 2; /* return error */
5456 }
5457 if (handle->inited != 1) /* check handle initialization */
5458 {
5459 return 3; /* return error */
5460 }
5461
5462 res = a_mpu6050_iic_read(handle, MPU6050_REG_SMPRT_DIV, (uint8_t *)d, 1); /* read config */
5463 if (res != 0) /* check result */
5464 {
5465 handle->debug_print("mpu6050: read smprt div failed.\n"); /* read smprt div failed */
5466
5467 return 1; /* return error */
5468 }
5469
5470 return 0; /* success return 0 */
5471}
5472
5485{
5486 uint8_t res;
5487 uint8_t prev;
5488
5489 if (handle == NULL) /* check handle */
5490 {
5491 return 2; /* return error */
5492 }
5493 if (handle->inited != 1) /* check handle initialization */
5494 {
5495 return 3; /* return error */
5496 }
5497
5498 res = a_mpu6050_iic_read(handle, MPU6050_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
5499 if (res != 0) /* check result */
5500 {
5501 handle->debug_print("mpu6050: read config failed.\n"); /* read config failed */
5502
5503 return 1; /* return error */
5504 }
5505 prev &= ~(0x7 << 3); /* clear config */
5506 prev |= sync << 3; /* set config */
5507 res = a_mpu6050_iic_write(handle, MPU6050_REG_CONFIG, (uint8_t *)&prev, 1); /* write config */
5508 if (res != 0) /* check result */
5509 {
5510 handle->debug_print("mpu6050: write config failed.\n"); /* write config failed */
5511
5512 return 1; /* return error */
5513 }
5514
5515 return 0; /* success return 0 */
5516}
5517
5530{
5531 uint8_t res;
5532 uint8_t prev;
5533
5534 if (handle == NULL) /* check handle */
5535 {
5536 return 2; /* return error */
5537 }
5538 if (handle->inited != 1) /* check handle initialization */
5539 {
5540 return 3; /* return error */
5541 }
5542
5543 res = a_mpu6050_iic_read(handle, MPU6050_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
5544 if (res != 0) /* check result */
5545 {
5546 handle->debug_print("mpu6050: read config failed.\n"); /* read config failed */
5547
5548 return 1; /* return error */
5549 }
5550 *sync = (mpu6050_extern_sync_t)((prev >> 3) & 0x7); /* get the extern sync */
5551
5552 return 0; /* success return 0 */
5553}
5554
5567{
5568 uint8_t res;
5569 uint8_t prev;
5570
5571 if (handle == NULL) /* check handle */
5572 {
5573 return 2; /* return error */
5574 }
5575 if (handle->inited != 1) /* check handle initialization */
5576 {
5577 return 3; /* return error */
5578 }
5579
5580 res = a_mpu6050_iic_read(handle, MPU6050_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
5581 if (res != 0) /* check result */
5582 {
5583 handle->debug_print("mpu6050: read config failed.\n"); /* read config failed */
5584
5585 return 1; /* return error */
5586 }
5587 prev &= ~(0x7 << 0); /* clear config */
5588 prev |= filter << 0; /* set config */
5589 res = a_mpu6050_iic_write(handle, MPU6050_REG_CONFIG, (uint8_t *)&prev, 1); /* write config */
5590 if (res != 0) /* check result */
5591 {
5592 handle->debug_print("mpu6050: write config failed.\n"); /* write config failed */
5593
5594 return 1; /* return error */
5595 }
5596
5597 return 0; /* success return 0 */
5598}
5599
5612{
5613 uint8_t res;
5614 uint8_t prev;
5615
5616 if (handle == NULL) /* check handle */
5617 {
5618 return 2; /* return error */
5619 }
5620 if (handle->inited != 1) /* check handle initialization */
5621 {
5622 return 3; /* return error */
5623 }
5624
5625 res = a_mpu6050_iic_read(handle, MPU6050_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
5626 if (res != 0) /* check result */
5627 {
5628 handle->debug_print("mpu6050: read config failed.\n"); /* read config failed */
5629
5630 return 1; /* return error */
5631 }
5632 *filter = (mpu6050_low_pass_filter_t)((prev >> 0) & 0x7); /* get the filter */
5633
5634 return 0; /* success return 0 */
5635}
5636
5650{
5651 uint8_t res;
5652 uint8_t prev;
5653
5654 if (handle == NULL) /* check handle */
5655 {
5656 return 2; /* return error */
5657 }
5658 if (handle->inited != 1) /* check handle initialization */
5659 {
5660 return 3; /* return error */
5661 }
5662
5663 res = a_mpu6050_iic_read(handle, MPU6050_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* read gyroscope config */
5664 if (res != 0) /* check result */
5665 {
5666 handle->debug_print("mpu6050: read gyroscope config failed.\n"); /* read gyroscope config failed */
5667
5668 return 1; /* return error */
5669 }
5670 prev &= ~(1 << axis); /* clear config */
5671 prev |= enable << axis; /* set config */
5672 res = a_mpu6050_iic_write(handle, MPU6050_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* write gyroscope config */
5673 if (res != 0) /* check result */
5674 {
5675 handle->debug_print("mpu6050: write gyroscope config failed.\n"); /* write gyroscope config failed */
5676
5677 return 1; /* return error */
5678 }
5679
5680 return 0; /* success return 0 */
5681}
5682
5696{
5697 uint8_t res;
5698 uint8_t prev;
5699
5700 if (handle == NULL) /* check handle */
5701 {
5702 return 2; /* return error */
5703 }
5704 if (handle->inited != 1) /* check handle initialization */
5705 {
5706 return 3; /* return error */
5707 }
5708
5709 res = a_mpu6050_iic_read(handle, MPU6050_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* read gyroscope config */
5710 if (res != 0) /* check result */
5711 {
5712 handle->debug_print("mpu6050: read gyroscope config failed.\n"); /* read gyroscope config failed */
5713
5714 return 1; /* return error */
5715 }
5716 *enable = (mpu6050_bool_t)((prev >> axis) & 0x01); /* get the bool */
5717
5718 return 0; /* success return 0 */
5719}
5720
5733{
5734 uint8_t res;
5735 uint8_t prev;
5736
5737 if (handle == NULL) /* check handle */
5738 {
5739 return 2; /* return error */
5740 }
5741 if (handle->inited != 1) /* check handle initialization */
5742 {
5743 return 3; /* return error */
5744 }
5745
5746 res = a_mpu6050_iic_read(handle, MPU6050_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* read gyroscope config */
5747 if (res != 0) /* check result */
5748 {
5749 handle->debug_print("mpu6050: read gyroscope config failed.\n"); /* read gyroscope config failed */
5750
5751 return 1; /* return error */
5752 }
5753 prev &= ~(3 << 3); /* clear config */
5754 prev |= range << 3; /* set config */
5755 res = a_mpu6050_iic_write(handle, MPU6050_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* write gyroscope config */
5756 if (res != 0) /* check result */
5757 {
5758 handle->debug_print("mpu6050: write gyroscope config failed.\n"); /* write gyroscope config failed */
5759
5760 return 1; /* return error */
5761 }
5762
5763 return 0; /* success return 0 */
5764}
5765
5778{
5779 uint8_t res;
5780 uint8_t prev;
5781
5782 if (handle == NULL) /* check handle */
5783 {
5784 return 2; /* return error */
5785 }
5786 if (handle->inited != 1) /* check handle initialization */
5787 {
5788 return 3; /* return error */
5789 }
5790
5791 res = a_mpu6050_iic_read(handle, MPU6050_REG_GYRO_CONFIG, (uint8_t *)&prev, 1); /* read gyroscope config */
5792 if (res != 0) /* check result */
5793 {
5794 handle->debug_print("mpu6050: read gyroscope config failed.\n"); /* read gyroscope config failed */
5795
5796 return 1; /* return error */
5797 }
5798 *range = (mpu6050_gyroscope_range_t)((prev >> 3) & 0x3); /* get the range */
5799
5800 return 0; /* success return 0 */
5801}
5802
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_mpu6050_iic_read(handle, MPU6050_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* read accelerometer config */
5830 if (res != 0) /* check result */
5831 {
5832 handle->debug_print("mpu6050: read accelerometer config failed.\n"); /* read accelerometer config failed */
5833
5834 return 1; /* return error */
5835 }
5836 prev &= ~(1 << axis); /* clear config */
5837 prev |= enable << axis; /* set config */
5838 res = a_mpu6050_iic_write(handle, MPU6050_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* write accelerometer config */
5839 if (res != 0) /* check result */
5840 {
5841 handle->debug_print("mpu6050: write accelerometer config failed.\n"); /* write accelerometer config failed */
5842
5843 return 1; /* return error */
5844 }
5845
5846 return 0; /* success return 0 */
5847}
5848
5862{
5863 uint8_t res;
5864 uint8_t prev;
5865
5866 if (handle == NULL) /* check handle */
5867 {
5868 return 2; /* return error */
5869 }
5870 if (handle->inited != 1) /* check handle initialization */
5871 {
5872 return 3; /* return error */
5873 }
5874
5875 res = a_mpu6050_iic_read(handle, MPU6050_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* read accelerometer config */
5876 if (res != 0) /* check result */
5877 {
5878 handle->debug_print("mpu6050: read accelerometer config failed.\n"); /* read accelerometer config failed */
5879
5880 return 1; /* return error */
5881 }
5882 *enable = (mpu6050_bool_t)((prev >> axis) & 0x01); /* get the bool */
5883
5884 return 0; /* success return 0 */
5885}
5886
5899{
5900 uint8_t res;
5901 uint8_t prev;
5902
5903 if (handle == NULL) /* check handle */
5904 {
5905 return 2; /* return error */
5906 }
5907 if (handle->inited != 1) /* check handle initialization */
5908 {
5909 return 3; /* return error */
5910 }
5911
5912 res = a_mpu6050_iic_read(handle, MPU6050_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* read accelerometer config */
5913 if (res != 0) /* check result */
5914 {
5915 handle->debug_print("mpu6050: read accelerometer config failed.\n"); /* read accelerometer config failed */
5916
5917 return 1; /* return error */
5918 }
5919 prev &= ~(3 << 3); /* clear config */
5920 prev |= range << 3; /* set config */
5921 res = a_mpu6050_iic_write(handle, MPU6050_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* write accelerometer config */
5922 if (res != 0) /* check result */
5923 {
5924 handle->debug_print("mpu6050: write accelerometer config failed.\n"); /* write accelerometer config failed */
5925
5926 return 1; /* return error */
5927 }
5928
5929 return 0; /* success return 0 */
5930}
5931
5944{
5945 uint8_t res;
5946 uint8_t prev;
5947
5948 if (handle == NULL) /* check handle */
5949 {
5950 return 2; /* return error */
5951 }
5952 if (handle->inited != 1) /* check handle initialization */
5953 {
5954 return 3; /* return error */
5955 }
5956
5957 res = a_mpu6050_iic_read(handle, MPU6050_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* read accelerometer config */
5958 if (res != 0) /* check result */
5959 {
5960 handle->debug_print("mpu6050: read accelerometer config failed.\n"); /* read accelerometer config failed */
5961
5962 return 1; /* return error */
5963 }
5964 *range = (mpu6050_accelerometer_range_t)((prev >> 3) & 0x3); /* get the range */
5965
5966 return 0; /* success return 0 */
5967}
5968
5982{
5983 uint8_t res;
5984 uint8_t prev;
5985
5986 if (handle == NULL) /* check handle */
5987 {
5988 return 2; /* return error */
5989 }
5990 if (handle->inited != 1) /* check handle initialization */
5991 {
5992 return 3; /* return error */
5993 }
5994
5995 res = a_mpu6050_iic_read(handle, MPU6050_REG_FIFO_EN, (uint8_t *)&prev, 1); /* read fifo enable config */
5996 if (res != 0) /* check result */
5997 {
5998 handle->debug_print("mpu6050: read fifo enable config failed.\n"); /* read fifo enable config failed */
5999
6000 return 1; /* return error */
6001 }
6002 prev &= ~(1 << fifo); /* clear config */
6003 prev |= enable << fifo; /* set config */
6004 res = a_mpu6050_iic_write(handle, MPU6050_REG_FIFO_EN, (uint8_t *)&prev, 1); /* write fifo enable config */
6005 if (res != 0) /* check result */
6006 {
6007 handle->debug_print("mpu6050: write fifo enable config failed.\n"); /* write fifo enable config failed */
6008
6009 return 1; /* return error */
6010 }
6011
6012 return 0; /* success return 0 */
6013}
6014
6028{
6029 uint8_t res;
6030 uint8_t prev;
6031
6032 if (handle == NULL) /* check handle */
6033 {
6034 return 2; /* return error */
6035 }
6036 if (handle->inited != 1) /* check handle initialization */
6037 {
6038 return 3; /* return error */
6039 }
6040
6041 res = a_mpu6050_iic_read(handle, MPU6050_REG_FIFO_EN, (uint8_t *)&prev, 1); /* read fifo enable config */
6042 if (res != 0) /* check result */
6043 {
6044 handle->debug_print("mpu6050: read fifo enable config failed.\n"); /* read fifo enable config failed */
6045
6046 return 1; /* return error */
6047 }
6048 *enable = (mpu6050_bool_t)((prev >> fifo) & 0x01); /* get the bool */
6049
6050 return 0; /* success return 0 */
6051}
6052
6065{
6066 uint8_t res;
6067 uint8_t prev;
6068
6069 if (handle == NULL) /* check handle */
6070 {
6071 return 2; /* return error */
6072 }
6073 if (handle->inited != 1) /* check handle initialization */
6074 {
6075 return 3; /* return error */
6076 }
6077
6078 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
6079 if (res != 0) /* check result */
6080 {
6081 handle->debug_print("mpu6050: read interrupt pin failed.\n"); /* read interrupt pin failed */
6082
6083 return 1; /* return error */
6084 }
6085 prev &= ~(1 << 7); /* clear config */
6086 prev |= level << 7; /* set config */
6087 res = a_mpu6050_iic_write(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
6088 if (res != 0) /* check result */
6089 {
6090 handle->debug_print("mpu6050: write interrupt pin failed.\n"); /* write interrupt pin failed */
6091
6092 return 1; /* return error */
6093 }
6094
6095 return 0; /* success return 0 */
6096}
6097
6110{
6111 uint8_t res;
6112 uint8_t prev;
6113
6114 if (handle == NULL) /* check handle */
6115 {
6116 return 2; /* return error */
6117 }
6118 if (handle->inited != 1) /* check handle initialization */
6119 {
6120 return 3; /* return error */
6121 }
6122
6123 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
6124 if (res != 0) /* check result */
6125 {
6126 handle->debug_print("mpu6050: read interrupt pin failed.\n"); /* read interrupt pin failed */
6127
6128 return 1; /* return error */
6129 }
6130 *level = (mpu6050_pin_level_t)((prev >> 7) & 0x01); /* get the level */
6131
6132 return 0; /* success return 0 */
6133}
6134
6147{
6148 uint8_t res;
6149 uint8_t prev;
6150
6151 if (handle == NULL) /* check handle */
6152 {
6153 return 2; /* return error */
6154 }
6155 if (handle->inited != 1) /* check handle initialization */
6156 {
6157 return 3; /* return error */
6158 }
6159
6160 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
6161 if (res != 0) /* check result */
6162 {
6163 handle->debug_print("mpu6050: read interrupt pin failed.\n"); /* read interrupt pin failed */
6164
6165 return 1; /* return error */
6166 }
6167 prev &= ~(1 << 6); /* clear config */
6168 prev |= type << 6; /* set config */
6169 res = a_mpu6050_iic_write(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
6170 if (res != 0) /* check result */
6171 {
6172 handle->debug_print("mpu6050: write interrupt pin failed.\n"); /* write interrupt pin failed */
6173
6174 return 1; /* return error */
6175 }
6176
6177 return 0; /* success return 0 */
6178}
6179
6192{
6193 uint8_t res;
6194 uint8_t prev;
6195
6196 if (handle == NULL) /* check handle */
6197 {
6198 return 2; /* return error */
6199 }
6200 if (handle->inited != 1) /* check handle initialization */
6201 {
6202 return 3; /* return error */
6203 }
6204
6205 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
6206 if (res != 0) /* check result */
6207 {
6208 handle->debug_print("mpu6050: read interrupt pin failed.\n"); /* read interrupt pin failed */
6209
6210 return 1; /* return error */
6211 }
6212 *type = (mpu6050_pin_type_t)((prev >> 6) & 0x01); /* get the pin type */
6213
6214 return 0; /* success return 0 */
6215}
6216
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
6242 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
6243 if (res != 0) /* check result */
6244 {
6245 handle->debug_print("mpu6050: read interrupt pin failed.\n"); /* read interrupt pin failed */
6246
6247 return 1; /* return error */
6248 }
6249 prev &= ~(1 << 5); /* clear config */
6250 prev |= (!enable) << 5; /* set config */
6251 res = a_mpu6050_iic_write(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
6252 if (res != 0) /* check result */
6253 {
6254 handle->debug_print("mpu6050: write interrupt pin failed.\n"); /* write interrupt pin failed */
6255
6256 return 1; /* return error */
6257 }
6258
6259 return 0; /* success return 0 */
6260}
6261
6274{
6275 uint8_t res;
6276 uint8_t prev;
6277
6278 if (handle == NULL) /* check handle */
6279 {
6280 return 2; /* return error */
6281 }
6282 if (handle->inited != 1) /* check handle initialization */
6283 {
6284 return 3; /* return error */
6285 }
6286
6287 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
6288 if (res != 0) /* check result */
6289 {
6290 handle->debug_print("mpu6050: read interrupt pin failed.\n"); /* read interrupt pin failed */
6291
6292 return 1; /* return error */
6293 }
6294 *enable = (mpu6050_bool_t)(!((prev >> 5) & 0x01)); /* get the bool */
6295
6296 return 0; /* success return 0 */
6297}
6298
6311{
6312 uint8_t res;
6313 uint8_t prev;
6314
6315 if (handle == NULL) /* check handle */
6316 {
6317 return 2; /* return error */
6318 }
6319 if (handle->inited != 1) /* check handle initialization */
6320 {
6321 return 3; /* return error */
6322 }
6323
6324 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
6325 if (res != 0) /* check result */
6326 {
6327 handle->debug_print("mpu6050: read interrupt pin failed.\n"); /* read interrupt pin failed */
6328
6329 return 1; /* return error */
6330 }
6331 prev &= ~(1 << 4); /* clear config */
6332 prev |= enable << 4; /* set config */
6333 res = a_mpu6050_iic_write(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
6334 if (res != 0) /* check result */
6335 {
6336 handle->debug_print("mpu6050: write interrupt pin failed.\n"); /* write interrupt pin failed */
6337
6338 return 1; /* return error */
6339 }
6340
6341 return 0; /* success return 0 */
6342}
6343
6356{
6357 uint8_t res;
6358 uint8_t prev;
6359
6360 if (handle == NULL) /* check handle */
6361 {
6362 return 2; /* return error */
6363 }
6364 if (handle->inited != 1) /* check handle initialization */
6365 {
6366 return 3; /* return error */
6367 }
6368
6369 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
6370 if (res != 0) /* check result */
6371 {
6372 handle->debug_print("mpu6050: read interrupt pin failed.\n"); /* read interrupt pin failed */
6373
6374 return 1; /* return error */
6375 }
6376 *enable = (mpu6050_bool_t)((prev >> 4) & 0x01); /* get the bool */
6377
6378 return 0; /* success return 0 */
6379}
6380
6393{
6394 uint8_t res;
6395 uint8_t prev;
6396
6397 if (handle == NULL) /* check handle */
6398 {
6399 return 2; /* return error */
6400 }
6401 if (handle->inited != 1) /* check handle initialization */
6402 {
6403 return 3; /* return error */
6404 }
6405
6406 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
6407 if (res != 0) /* check result */
6408 {
6409 handle->debug_print("mpu6050: read interrupt pin failed.\n"); /* read interrupt pin failed */
6410
6411 return 1; /* return error */
6412 }
6413 prev &= ~(1 << 3); /* clear config */
6414 prev |= level << 3; /* set config */
6415 res = a_mpu6050_iic_write(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
6416 if (res != 0) /* check result */
6417 {
6418 handle->debug_print("mpu6050: write interrupt pin failed.\n"); /* write interrupt pin failed */
6419
6420 return 1; /* return error */
6421 }
6422
6423 return 0; /* success return 0 */
6424}
6425
6438{
6439 uint8_t res;
6440 uint8_t prev;
6441
6442 if (handle == NULL) /* check handle */
6443 {
6444 return 2; /* return error */
6445 }
6446 if (handle->inited != 1) /* check handle initialization */
6447 {
6448 return 3; /* return error */
6449 }
6450
6451 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
6452 if (res != 0) /* check result */
6453 {
6454 handle->debug_print("mpu6050: read interrupt pin failed.\n"); /* read interrupt pin failed */
6455
6456 return 1; /* return error */
6457 }
6458 *level = (mpu6050_pin_level_t)((prev >> 3) & 0x01); /* get the level */
6459
6460 return 0; /* success return 0 */
6461}
6462
6475{
6476 uint8_t res;
6477 uint8_t prev;
6478
6479 if (handle == NULL) /* check handle */
6480 {
6481 return 2; /* return error */
6482 }
6483 if (handle->inited != 1) /* check handle initialization */
6484 {
6485 return 3; /* return error */
6486 }
6487
6488 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
6489 if (res != 0) /* check result */
6490 {
6491 handle->debug_print("mpu6050: read interrupt pin failed.\n"); /* read interrupt pin failed */
6492
6493 return 1; /* return error */
6494 }
6495 prev &= ~(1 << 2); /* clear config */
6496 prev |= enable << 2; /* set config */
6497 res = a_mpu6050_iic_write(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
6498 if (res != 0) /* check result */
6499 {
6500 handle->debug_print("mpu6050: write interrupt pin failed.\n"); /* write interrupt pin failed */
6501
6502 return 1; /* return error */
6503 }
6504
6505 return 0; /* success return 0 */
6506}
6507
6520{
6521 uint8_t res;
6522 uint8_t prev;
6523
6524 if (handle == NULL) /* check handle */
6525 {
6526 return 2; /* return error */
6527 }
6528 if (handle->inited != 1) /* check handle initialization */
6529 {
6530 return 3; /* return error */
6531 }
6532
6533 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin config */
6534 if (res != 0) /* check result */
6535 {
6536 handle->debug_print("mpu6050: read interrupt pin failed.\n"); /* read interrupt pin failed */
6537
6538 return 1; /* return error */
6539 }
6540 *enable = (mpu6050_bool_t)((prev >> 2) & 0x01); /* get the bool */
6541
6542 return 0; /* success return 0 */
6543}
6544
6557{
6558 uint8_t res;
6559 uint8_t prev;
6560
6561 if (handle == NULL) /* check handle */
6562 {
6563 return 2; /* return error */
6564 }
6565 if (handle->inited != 1) /* check handle initialization */
6566 {
6567 return 3; /* return error */
6568 }
6569
6570 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin */
6571 if (res != 0) /* check result */
6572 {
6573 handle->debug_print("mpu6050: read interrupt pin failed.\n"); /* read interrupt pin failed */
6574
6575 return 1; /* return error */
6576 }
6577 prev &= ~(1 << 1); /* clear config */
6578 prev |= enable << 1; /* set config */
6579 res = a_mpu6050_iic_write(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* write interrupt pin */
6580 if (res != 0) /* check result */
6581 {
6582 handle->debug_print("mpu6050: write interrupt pin failed.\n"); /* write interrupt pin failed */
6583
6584 return 1; /* return error */
6585 }
6586
6587 return 0; /* success return 0 */
6588}
6589
6602{
6603 uint8_t res;
6604 uint8_t prev;
6605
6606 if (handle == NULL) /* check handle */
6607 {
6608 return 2; /* return error */
6609 }
6610 if (handle->inited != 1) /* check handle initialization */
6611 {
6612 return 3; /* return error */
6613 }
6614
6615 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_PIN_CFG, (uint8_t *)&prev, 1); /* read interrupt pin */
6616 if (res != 0) /* check result */
6617 {
6618 handle->debug_print("mpu6050: read interrupt pin failed.\n"); /* read interrupt pin failed */
6619
6620 return 1; /* return error */
6621 }
6622 *enable = (mpu6050_bool_t)((prev >> 1) & 0x01); /* get the bool */
6623
6624 return 0; /* success return 0 */
6625}
6626
6640{
6641 uint8_t res;
6642 uint8_t prev;
6643
6644 if (handle == NULL) /* check handle */
6645 {
6646 return 2; /* return error */
6647 }
6648 if (handle->inited != 1) /* check handle initialization */
6649 {
6650 return 3; /* return error */
6651 }
6652
6653 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_ENABLE, (uint8_t *)&prev, 1); /* read interrupt enable */
6654 if (res != 0) /* check result */
6655 {
6656 handle->debug_print("mpu6050: read interrupt enable failed.\n"); /* read interrupt enable failed */
6657
6658 return 1; /* return error */
6659 }
6660 prev &= ~(1 << type); /* clear config */
6661 prev |= enable << type; /* set config */
6662 res = a_mpu6050_iic_write(handle, MPU6050_REG_INT_ENABLE, (uint8_t *)&prev, 1); /* write interrupt enable */
6663 if (res != 0) /* check result */
6664 {
6665 handle->debug_print("mpu6050: write interrupt enable failed.\n"); /* write interrupt enable failed */
6666
6667 return 1; /* return error */
6668 }
6669
6670 return 0; /* success return 0 */
6671}
6672
6686{
6687 uint8_t res;
6688 uint8_t prev;
6689
6690 if (handle == NULL) /* check handle */
6691 {
6692 return 2; /* return error */
6693 }
6694 if (handle->inited != 1) /* check handle initialization */
6695 {
6696 return 3; /* return error */
6697 }
6698
6699 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_ENABLE, (uint8_t *)&prev, 1); /* read interrupt enable */
6700 if (res != 0) /* check result */
6701 {
6702 handle->debug_print("mpu6050: read interrupt enable failed.\n"); /* read interrupt enable failed */
6703
6704 return 1; /* return error */
6705 }
6706 *enable = (mpu6050_bool_t)((prev >> type) & 0x01); /* get the bool */
6707
6708 return 0; /* success return 0 */
6709}
6710
6722uint8_t mpu6050_get_interrupt_status(mpu6050_handle_t *handle, uint8_t *status)
6723{
6724 uint8_t res;
6725
6726 if (handle == NULL) /* check handle */
6727 {
6728 return 2; /* return error */
6729 }
6730 if (handle->inited != 1) /* check handle initialization */
6731 {
6732 return 3; /* return error */
6733 }
6734
6735 res = a_mpu6050_iic_read(handle, MPU6050_REG_INT_STATUS, (uint8_t *)status, 1); /* read interrupt status */
6736 if (res != 0) /* check result */
6737 {
6738 handle->debug_print("mpu6050: read interrupt status failed.\n"); /* read interrupt status failed */
6739
6740 return 1; /* return error */
6741 }
6742
6743 return 0; /* success return 0 */
6744}
6745
6759{
6760 uint8_t res;
6761 uint8_t prev;
6762
6763 if (handle == NULL) /* check handle */
6764 {
6765 return 2; /* return error */
6766 }
6767 if (handle->inited != 1) /* check handle initialization */
6768 {
6769 return 3; /* return error */
6770 }
6771 if (data > 0x1F) /* check the data */
6772 {
6773 handle->debug_print("mpu6050: data is over 0x1F.\n"); /* data is over 0x1F. */
6774
6775 return 4; /* return error */
6776 }
6777
6778 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_X, (uint8_t *)&prev, 1); /* read self test x */
6779 if (res != 0) /* check result */
6780 {
6781 handle->debug_print("mpu6050: read self test x failed.\n"); /* read self test x failed */
6782
6783 return 1; /* return error */
6784 }
6785 prev &= ~(0x1F); /* get the data */
6786 prev |= data; /* set the data */
6787 res = a_mpu6050_iic_write(handle, MPU6050_REG_SELF_TEST_X, (uint8_t *)&prev, 1); /* write self test x */
6788 if (res != 0) /* check result */
6789 {
6790 handle->debug_print("mpu6050: write self test x failed.\n"); /* write self test x failed */
6791
6792 return 1; /* return error */
6793 }
6794
6795 return 0; /* success return 0 */
6796}
6797
6809uint8_t mpu6050_get_gyroscope_x_test(mpu6050_handle_t *handle, uint8_t *data)
6810{
6811 uint8_t res;
6812
6813 if (handle == NULL) /* check handle */
6814 {
6815 return 2; /* return error */
6816 }
6817 if (handle->inited != 1) /* check handle initialization */
6818 {
6819 return 3; /* return error */
6820 }
6821
6822 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_X, (uint8_t *)data, 1); /* read self test x */
6823 if (res != 0) /* check result */
6824 {
6825 handle->debug_print("mpu6050: read self test x failed.\n"); /* read self test x failed */
6826
6827 return 1; /* return error */
6828 }
6829 *data &= 0x1F; /* get the data */
6830
6831 return 0; /* success return 0 */
6832}
6833
6847{
6848 uint8_t res;
6849 uint8_t prev;
6850
6851 if (handle == NULL) /* check handle */
6852 {
6853 return 2; /* return error */
6854 }
6855 if (handle->inited != 1) /* check handle initialization */
6856 {
6857 return 3; /* return error */
6858 }
6859 if (data > 0x1F) /* check the data */
6860 {
6861 handle->debug_print("mpu6050: data is over 0x1F.\n"); /* data is over 0x1F. */
6862
6863 return 4; /* return error */
6864 }
6865
6866 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_Y, (uint8_t *)&prev, 1); /* read self test y */
6867 if (res != 0) /* check result */
6868 {
6869 handle->debug_print("mpu6050: read self test y failed.\n"); /* read self test y failed */
6870
6871 return 1; /* return error */
6872 }
6873 prev &= ~(0x1F); /* get the data */
6874 prev |= data; /* set the data */
6875 res = a_mpu6050_iic_write(handle, MPU6050_REG_SELF_TEST_Y, (uint8_t *)&prev, 1); /* write self test y */
6876 if (res != 0) /* check result */
6877 {
6878 handle->debug_print("mpu6050: write self test y failed.\n"); /* write self test y failed */
6879
6880 return 1; /* return error */
6881 }
6882
6883 return 0; /* success return 0 */
6884}
6885
6897uint8_t mpu6050_get_gyroscope_y_test(mpu6050_handle_t *handle, uint8_t *data)
6898{
6899 uint8_t res;
6900
6901 if (handle == NULL) /* check handle */
6902 {
6903 return 2; /* return error */
6904 }
6905 if (handle->inited != 1) /* check handle initialization */
6906 {
6907 return 3; /* return error */
6908 }
6909
6910 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_Y, (uint8_t *)data, 1); /* read self test y */
6911 if (res != 0) /* check result */
6912 {
6913 handle->debug_print("mpu6050: read self test y failed.\n"); /* read self test y failed */
6914
6915 return 1; /* return error */
6916 }
6917 *data &= 0x1F; /* get the data */
6918
6919 return 0; /* success return 0 */
6920}
6921
6935{
6936 uint8_t res;
6937 uint8_t prev;
6938
6939 if (handle == NULL) /* check handle */
6940 {
6941 return 2; /* return error */
6942 }
6943 if (handle->inited != 1) /* check handle initialization */
6944 {
6945 return 3; /* return error */
6946 }
6947 if (data > 0x1F) /* check the data */
6948 {
6949 handle->debug_print("mpu6050: data is over 0x1F.\n"); /* data is over 0x1F. */
6950
6951 return 4; /* return error */
6952 }
6953
6954 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_Z, (uint8_t *)&prev, 1); /* read self test z */
6955 if (res != 0) /* check result */
6956 {
6957 handle->debug_print("mpu6050: read self test z failed.\n"); /* read self test z failed */
6958
6959 return 1; /* return error */
6960 }
6961 prev &= ~(0x1F); /* get the data */
6962 prev |= data; /* set the data */
6963 res = a_mpu6050_iic_write(handle, MPU6050_REG_SELF_TEST_Z, (uint8_t *)&prev, 1); /* write self test z */
6964 if (res != 0) /* check result */
6965 {
6966 handle->debug_print("mpu6050: write self test z failed.\n"); /* write self test z failed */
6967
6968 return 1; /* return error */
6969 }
6970
6971 return 0; /* success return 0 */
6972}
6973
6985uint8_t mpu6050_get_gyroscope_z_test(mpu6050_handle_t *handle, uint8_t *data)
6986{
6987 uint8_t res;
6988
6989 if (handle == NULL) /* check handle */
6990 {
6991 return 2; /* return error */
6992 }
6993 if (handle->inited != 1) /* check handle initialization */
6994 {
6995 return 3; /* return error */
6996 }
6997
6998 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_Z, (uint8_t *)data, 1); /* read self test z */
6999 if (res != 0) /* check result */
7000 {
7001 handle->debug_print("mpu6050: read self test z failed.\n"); /* read self test z failed */
7002
7003 return 1; /* return error */
7004 }
7005 *data &= 0x1F; /* get the data */
7006
7007 return 0; /* success return 0 */
7008}
7009
7023{
7024 uint8_t res;
7025 uint8_t prev;
7026
7027 if (handle == NULL) /* check handle */
7028 {
7029 return 2; /* return error */
7030 }
7031 if (handle->inited != 1) /* check handle initialization */
7032 {
7033 return 3; /* return error */
7034 }
7035 if (data > 0x1F) /* check the data */
7036 {
7037 handle->debug_print("mpu6050: data is over 0x1F.\n"); /* data is over 0x1F. */
7038
7039 return 4; /* return error */
7040 }
7041
7042 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_X, (uint8_t *)&prev, 1); /* read self test x */
7043 if (res != 0) /* check result */
7044 {
7045 handle->debug_print("mpu6050: read self test x failed.\n"); /* read self test x failed */
7046
7047 return 1; /* return error */
7048 }
7049 prev &= ~(7 << 5); /* get the data */
7050 prev |= ((data >> 2) & 0x7) << 5; /* set the data */
7051 res = a_mpu6050_iic_write(handle, MPU6050_REG_SELF_TEST_X, (uint8_t *)&prev, 1); /* write self test x */
7052 if (res != 0) /* check result */
7053 {
7054 handle->debug_print("mpu6050: write self test x failed.\n"); /* write self test x failed */
7055
7056 return 1; /* return error */
7057 }
7058 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_A, (uint8_t *)&prev, 1); /* read self test a */
7059 if (res != 0) /* check result */
7060 {
7061 handle->debug_print("mpu6050: read self test a failed.\n"); /* read self test a failed */
7062
7063 return 1; /* return error */
7064 }
7065 prev &= ~(3 << 4); /* clear the settings */
7066 prev |= (data & 0x3) << 4; /* set the data */
7067 res = a_mpu6050_iic_write(handle, MPU6050_REG_SELF_TEST_A, (uint8_t *)&prev, 1); /* write self test a */
7068 if (res != 0) /* check result */
7069 {
7070 handle->debug_print("mpu6050: write self test a failed.\n"); /* write self test a failed */
7071
7072 return 1; /* return error */
7073 }
7074
7075 return 0; /* success return 0 */
7076}
7077
7090{
7091 uint8_t res;
7092 uint8_t prev1;
7093 uint8_t prev2;
7094
7095 if (handle == NULL) /* check handle */
7096 {
7097 return 2; /* return error */
7098 }
7099 if (handle->inited != 1) /* check handle initialization */
7100 {
7101 return 3; /* return error */
7102 }
7103
7104 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_X, (uint8_t *)&prev1, 1); /* read self test x */
7105 if (res != 0) /* check result */
7106 {
7107 handle->debug_print("mpu6050: read self test x failed.\n"); /* read self test x failed */
7108
7109 return 1; /* return error */
7110 }
7111 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_A, (uint8_t *)&prev2, 1); /* read self test a */
7112 if (res != 0) /* check result */
7113 {
7114 handle->debug_print("mpu6050: read self test a failed.\n"); /* read self test a failed */
7115
7116 return 1; /* return error */
7117 }
7118 *data = ((prev1 & (0x7 << 5)) >> 5) << 2 | ((prev2 >> 4) & 0x3); /* get the data */
7119
7120 return 0; /* success return 0 */
7121}
7122
7136{
7137 uint8_t res;
7138 uint8_t prev;
7139
7140 if (handle == NULL) /* check handle */
7141 {
7142 return 2; /* return error */
7143 }
7144 if (handle->inited != 1) /* check handle initialization */
7145 {
7146 return 3; /* return error */
7147 }
7148 if (data > 0x1F) /* check the data */
7149 {
7150 handle->debug_print("mpu6050: data is over 0x1F.\n"); /* data is over 0x1F. */
7151
7152 return 4; /* return error */
7153 }
7154
7155 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_Y, (uint8_t *)&prev, 1); /* read self test y */
7156 if (res != 0) /* check result */
7157 {
7158 handle->debug_print("mpu6050: read self test y failed.\n"); /* read self test y failed */
7159
7160 return 1; /* return error */
7161 }
7162 prev &= ~(7 << 5); /* get the data */
7163 prev |= ((data >> 2) & 0x7) << 5; /* set the data */
7164 res = a_mpu6050_iic_write(handle, MPU6050_REG_SELF_TEST_Y, (uint8_t *)&prev, 1); /* write self test y */
7165 if (res != 0) /* check result */
7166 {
7167 handle->debug_print("mpu6050: write self test y failed.\n"); /* write self test y failed */
7168
7169 return 1; /* return error */
7170 }
7171 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_A, (uint8_t *)&prev, 1); /* read self test a */
7172 if (res != 0) /* check result */
7173 {
7174 handle->debug_print("mpu6050: read self test a failed.\n"); /* read self test a failed */
7175
7176 return 1; /* return error */
7177 }
7178 prev &= ~(3 << 2); /* clear the settings */
7179 prev |= (data & 0x3) << 2; /* set the data */
7180 res = a_mpu6050_iic_write(handle, MPU6050_REG_SELF_TEST_A, (uint8_t *)&prev, 1); /* write self test a */
7181 if (res != 0) /* check result */
7182 {
7183 handle->debug_print("mpu6050: write self test a failed.\n"); /* write self test a failed */
7184
7185 return 1; /* return error */
7186 }
7187
7188 return 0; /* success return 0 */
7189}
7190
7203{
7204 uint8_t res;
7205 uint8_t prev1;
7206 uint8_t prev2;
7207
7208 if (handle == NULL) /* check handle */
7209 {
7210 return 2; /* return error */
7211 }
7212 if (handle->inited != 1) /* check handle initialization */
7213 {
7214 return 3; /* return error */
7215 }
7216
7217 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_Y, (uint8_t *)&prev1, 1); /* read self test y */
7218 if (res != 0) /* check result */
7219 {
7220 handle->debug_print("mpu6050: read self test y failed.\n"); /* read self test y failed */
7221
7222 return 1; /* return error */
7223 }
7224 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_A, (uint8_t *)&prev2, 1); /* read self test a */
7225 if (res != 0) /* check result */
7226 {
7227 handle->debug_print("mpu6050: read self test a failed.\n"); /* read self test a failed */
7228
7229 return 1; /* return error */
7230 }
7231 *data = ((prev1 & (0x7 << 5)) >> 5) << 2 | ((prev2 >> 2) & 0x3); /* get the data */
7232
7233 return 0; /* success return 0 */
7234}
7235
7249{
7250 uint8_t res;
7251 uint8_t prev;
7252
7253 if (handle == NULL) /* check handle */
7254 {
7255 return 2; /* return error */
7256 }
7257 if (handle->inited != 1) /* check handle initialization */
7258 {
7259 return 3; /* return error */
7260 }
7261 if (data > 0x1F) /* check the data */
7262 {
7263 handle->debug_print("mpu6050: data is over 0x1F.\n"); /* data is over 0x1F. */
7264
7265 return 4; /* return error */
7266 }
7267
7268 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_Z, (uint8_t *)&prev, 1); /* read self test z */
7269 if (res != 0) /* check result */
7270 {
7271 handle->debug_print("mpu6050: read self test z failed.\n"); /* read self test z failed */
7272
7273 return 1; /* return error */
7274 }
7275 prev &= ~(7 << 5); /* get the data */
7276 prev |= ((data >> 2) & 0x7) << 5; /* set the data */
7277 res = a_mpu6050_iic_write(handle, MPU6050_REG_SELF_TEST_Z, (uint8_t *)&prev, 1); /* write self test z */
7278 if (res != 0) /* check result */
7279 {
7280 handle->debug_print("mpu6050: write self test z failed.\n"); /* write self test z failed */
7281
7282 return 1; /* return error */
7283 }
7284 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_A, (uint8_t *)&prev, 1); /* read self test a */
7285 if (res != 0) /* check result */
7286 {
7287 handle->debug_print("mpu6050: read self test a failed.\n"); /* read self test a failed */
7288
7289 return 1; /* return error */
7290 }
7291 prev &= ~(3 << 0); /* clear the settings */
7292 prev |= (data & 0x3) << 0; /* set the data */
7293 res = a_mpu6050_iic_write(handle, MPU6050_REG_SELF_TEST_A, (uint8_t *)&prev, 1); /* write self test a */
7294 if (res != 0) /* check result */
7295 {
7296 handle->debug_print("mpu6050: write self test a failed.\n"); /* write self test a failed */
7297
7298 return 1; /* return error */
7299 }
7300
7301 return 0; /* success return 0 */
7302}
7303
7316{
7317 uint8_t res;
7318 uint8_t prev1;
7319 uint8_t prev2;
7320
7321 if (handle == NULL) /* check handle */
7322 {
7323 return 2; /* return error */
7324 }
7325 if (handle->inited != 1) /* check handle initialization */
7326 {
7327 return 3; /* return error */
7328 }
7329
7330 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_Z, (uint8_t *)&prev1, 1); /* read self test z */
7331 if (res != 0) /* check result */
7332 {
7333 handle->debug_print("mpu6050: read self test z failed.\n"); /* read self test z failed */
7334
7335 return 1; /* return error */
7336 }
7337 res = a_mpu6050_iic_read(handle, MPU6050_REG_SELF_TEST_A, (uint8_t *)&prev2, 1); /* read self test a */
7338 if (res != 0) /* check result */
7339 {
7340 handle->debug_print("mpu6050: read self test a failed.\n"); /* read self test a failed */
7341
7342 return 1; /* return error */
7343 }
7344 *data = ((prev1 & (0x7 << 5)) >> 5) << 2 | ((prev2 >> 0) & 0x3); /* get the data */
7345
7346 return 0; /* success return 0 */
7347}
7348
7360uint8_t mpu6050_set_motion_threshold(mpu6050_handle_t *handle, uint8_t threshold)
7361{
7362 uint8_t res;
7363
7364 if (handle == NULL) /* check handle */
7365 {
7366 return 2; /* return error */
7367 }
7368 if (handle->inited != 1) /* check handle initialization */
7369 {
7370 return 3; /* return error */
7371 }
7372
7373 res = a_mpu6050_iic_write(handle, MPU6050_REG_MOTION_THRESHOLD, (uint8_t *)&threshold, 1); /* write motion threshold */
7374 if (res != 0) /* check result */
7375 {
7376 handle->debug_print("mpu6050: write motion threshold failed.\n"); /* write motion threshold failed*/
7377
7378 return 1; /* return error */
7379 }
7380
7381 return 0; /* success return 0 */
7382}
7383
7395uint8_t mpu6050_get_motion_threshold(mpu6050_handle_t *handle, uint8_t *threshold)
7396{
7397 uint8_t res;
7398
7399 if (handle == NULL) /* check handle */
7400 {
7401 return 2; /* return error */
7402 }
7403 if (handle->inited != 1) /* check handle initialization */
7404 {
7405 return 3; /* return error */
7406 }
7407
7408 res = a_mpu6050_iic_read(handle, MPU6050_REG_MOTION_THRESHOLD, (uint8_t *)threshold, 1); /* read motion threshold */
7409 if (res != 0) /* check result */
7410 {
7411 handle->debug_print("mpu6050: read motion threshold failed.\n"); /* read motion threshold failed*/
7412
7413 return 1; /* return error */
7414 }
7415
7416 return 0; /* success return 0 */
7417}
7418
7431{
7432 if (handle == NULL) /* check handle */
7433 {
7434 return 2; /* return error */
7435 }
7436 if (handle->inited != 1) /* check handle initialization */
7437 {
7438 return 3; /* return error */
7439 }
7440
7441 *reg = (uint8_t)(mg / 32.0f); /* convert real data to register data */
7442
7443 return 0; /* success return 0 */
7444}
7445
7457uint8_t mpu6050_motion_threshold_convert_to_data(mpu6050_handle_t *handle, uint8_t reg, float *mg)
7458{
7459 if (handle == NULL) /* check handle */
7460 {
7461 return 2; /* return error */
7462 }
7463 if (handle->inited != 1) /* check handle initialization */
7464 {
7465 return 3; /* return error */
7466 }
7467
7468 *mg = (float)(reg) * 32.0f; /* convert raw data to real data */
7469
7470 return 0; /* success return 0 */
7471}
7472
7484uint8_t mpu6050_set_motion_duration(mpu6050_handle_t *handle, uint8_t duration)
7485{
7486 uint8_t res;
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_mpu6050_iic_write(handle, MPU6050_REG_MOTION_DURATION, (uint8_t *)&duration, 1); /* write motion duration */
7498 if (res != 0) /* check result */
7499 {
7500 handle->debug_print("mpu6050: write motion duration failed.\n"); /* write motion duration failed*/
7501
7502 return 1; /* return error */
7503 }
7504
7505 return 0; /* success return 0 */
7506}
7507
7519uint8_t mpu6050_get_motion_duration(mpu6050_handle_t *handle, uint8_t *duration)
7520{
7521 uint8_t res;
7522
7523 if (handle == NULL) /* check handle */
7524 {
7525 return 2; /* return error */
7526 }
7527 if (handle->inited != 1) /* check handle initialization */
7528 {
7529 return 3; /* return error */
7530 }
7531
7532 res = a_mpu6050_iic_read(handle, MPU6050_REG_MOTION_DURATION, (uint8_t *)duration, 1); /* read motion duration */
7533 if (res != 0) /* check result */
7534 {
7535 handle->debug_print("mpu6050: read motion duration failed.\n"); /* read motion duration failed*/
7536
7537 return 1; /* return error */
7538 }
7539
7540 return 0; /* success return 0 */
7541}
7542
7554uint8_t mpu6050_motion_duration_convert_to_register(mpu6050_handle_t *handle, uint8_t ms, uint8_t *reg)
7555{
7556 if (handle == NULL) /* check handle */
7557 {
7558 return 2; /* return error */
7559 }
7560 if (handle->inited != 1) /* check handle initialization */
7561 {
7562 return 3; /* return error */
7563 }
7564
7565 *reg = (uint8_t)ms; /* convert real data to register data */
7566
7567 return 0; /* success return 0 */
7568}
7569
7581uint8_t mpu6050_motion_duration_convert_to_data(mpu6050_handle_t *handle, uint8_t reg, uint8_t *ms)
7582{
7583 if (handle == NULL) /* check handle */
7584 {
7585 return 2; /* return error */
7586 }
7587 if (handle->inited != 1) /* check handle initialization */
7588 {
7589 return 3; /* return error */
7590 }
7591
7592 *ms = reg; /* convert raw data to real data */
7593
7594 return 0; /* success return 0 */
7595}
7596
7609{
7610 uint8_t res;
7611 uint8_t prev;
7612
7613 if (handle == NULL) /* check handle */
7614 {
7615 return 2; /* return error */
7616 }
7617 if (handle->inited != 1) /* check handle initialization */
7618 {
7619 return 3; /* return error */
7620 }
7621
7622 handle->delay_ms(5); /* 5ms */
7623 res = a_mpu6050_iic_read(handle, MPU6050_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* read accel config */
7624 if (res != 0) /* check result */
7625 {
7626 handle->debug_print("mpu6050: read accel config failed.\n"); /* read accel config failed */
7627
7628 return 1; /* return error */
7629 }
7630 if (enable == MPU6050_BOOL_TRUE) /* enable */
7631 {
7632 prev |= 0x7; /* set the accel sample */
7633 }
7634 else /* disable */
7635 {
7636 prev &= ~0x7; /* clear the accel sample */
7637 }
7638 res = a_mpu6050_iic_write(handle, MPU6050_REG_ACCEL_CONFIG, (uint8_t *)&prev, 1); /* write accel config */
7639 if (res != 0) /* check result */
7640 {
7641 handle->debug_print("mpu6050: write accel config failed.\n"); /* write accel config failed */
7642
7643 return 1; /* return error */
7644 }
7645
7646 return 0; /* success return 0 */
7647}
7648
7661uint8_t mpu6050_self_test(mpu6050_handle_t *handle, int32_t gyro_offset_raw[3], int32_t accel_offset_raw[3])
7662{
7663 uint8_t res;
7664 uint8_t prev;
7665 int32_t gyro_offset_raw_st[3];
7666 int32_t accel_offset_raw_st[3];
7667
7668 if (handle == NULL) /* check handle */
7669 {
7670 return 2; /* return error */
7671 }
7672 if (handle->inited != 1) /* check handle initialization */
7673 {
7674 return 3; /* return error */
7675 }
7676
7677 res = a_mpu6050_get_st_biases(handle, gyro_offset_raw, accel_offset_raw, 0); /* get st biases */
7678 if (res != 0) /* check result */
7679 {
7680 handle->debug_print("mpu6050: get st biases failed.\n"); /* get st biases failed */
7681
7682 return 1; /* return error */
7683 }
7684 res = a_mpu6050_get_st_biases(handle, gyro_offset_raw_st, accel_offset_raw_st, 1); /* get st biases */
7685 if (res != 0) /* check result */
7686 {
7687 handle->debug_print("mpu6050: get st biases failed.\n"); /* get st biases failed */
7688
7689 return 1; /* return error */
7690 }
7691 res = a_mpu6050_accel_self_test(handle, accel_offset_raw, accel_offset_raw_st); /* accel self test */
7692 if (res != 0) /* check result */
7693 {
7694 handle->debug_print("mpu6050: accel self test failed.\n"); /* accel self test failed */
7695
7696 return 1; /* return error */
7697 }
7698 res = a_mpu6050_gyro_self_test(handle, gyro_offset_raw, gyro_offset_raw_st); /* gyro self test */
7699 if (res != 0) /* check result */
7700 {
7701 handle->debug_print("mpu6050: gyro self test failed.\n"); /* gyro self test failed */
7702
7703 return 1; /* return error */
7704 }
7705
7706 prev = 1 << 7; /* reset the device */
7707 res = a_mpu6050_iic_write(handle, MPU6050_REG_PWR_MGMT_1, &prev, 1); /* write pwr mgmt 1 */
7708 if (res != 0) /* check the result */
7709 {
7710 handle->debug_print("mpu6050: write pwr mgmt 1 failed.\n"); /* write pwr mgmt 1 failed */
7711
7712 return 1; /* return error */
7713 }
7714 handle->delay_ms(100); /* delay 100ms */
7715 res = a_mpu6050_iic_read(handle, MPU6050_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* read config */
7716 if (res != 0) /* check result */
7717 {
7718 handle->debug_print("mpu6050: read power management 1 failed.\n"); /* read power management 1 failed */
7719
7720 return 1; /* return error */
7721 }
7722 prev &= ~(1 << 6); /* clear config */
7723 res = a_mpu6050_iic_write(handle, MPU6050_REG_PWR_MGMT_1, (uint8_t *)&prev, 1); /* write config */
7724 if (res != 0) /* check result */
7725 {
7726 handle->debug_print("mpu6050: write power management 1 failed.\n"); /* write power management 1 failed */
7727
7728 return 1; /* return error */
7729 }
7730
7731 return 0; /* success return 0 */
7732}
7733
7746{
7747 uint8_t res;
7748 uint8_t prev;
7749
7750 if (handle == NULL) /* check handle */
7751 {
7752 return 2; /* return error */
7753 }
7754 if (handle->inited != 1) /* check handle initialization */
7755 {
7756 return 3; /* return error */
7757 }
7758
7759 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
7760 if (res != 0) /* check result */
7761 {
7762 handle->debug_print("mpu6050: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
7763
7764 return 1; /* return error */
7765 }
7766 prev &= ~0xF; /* clear the buffer */
7767 prev |= clk; /* set the clock */
7768 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* write i2c mst ctrl */
7769 if (res != 0) /* check result */
7770 {
7771 handle->debug_print("mpu6050: write i2c mst ctrl failed.\n"); /* write i2c mst ctrl failed */
7772
7773 return 1; /* return error */
7774 }
7775
7776 return 0; /* success return 0 */
7777}
7778
7791{
7792 uint8_t res;
7793 uint8_t prev;
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_mpu6050_iic_read(handle, MPU6050_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
7805 if (res != 0) /* check result */
7806 {
7807 handle->debug_print("mpu6050: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
7808
7809 return 1; /* return error */
7810 }
7811 *clk = (mpu6050_iic_clock_t)(prev & 0x0F); /* get the clock */
7812
7813 return 0; /* success return 0 */
7814}
7815
7828{
7829 uint8_t res;
7830 uint8_t prev;
7831
7832 if (handle == NULL) /* check handle */
7833 {
7834 return 2; /* return error */
7835 }
7836 if (handle->inited != 1) /* check handle initialization */
7837 {
7838 return 3; /* return error */
7839 }
7840
7841 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
7842 if (res != 0) /* check result */
7843 {
7844 handle->debug_print("mpu6050: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
7845
7846 return 1; /* return error */
7847 }
7848 prev &= ~(1 << 7); /* clear the settings */
7849 prev |= enable << 7; /* set the bool */
7850 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* write i2c mst ctrl */
7851 if (res != 0) /* check result */
7852 {
7853 handle->debug_print("mpu6050: write i2c mst ctrl failed.\n"); /* write i2c mst ctrl failed */
7854
7855 return 1; /* return error */
7856 }
7857
7858 return 0; /* success return 0 */
7859}
7860
7873{
7874 uint8_t res;
7875 uint8_t prev;
7876
7877 if (handle == NULL) /* check handle */
7878 {
7879 return 2; /* return error */
7880 }
7881 if (handle->inited != 1) /* check handle initialization */
7882 {
7883 return 3; /* return error */
7884 }
7885
7886 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
7887 if (res != 0) /* check result */
7888 {
7889 handle->debug_print("mpu6050: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
7890
7891 return 1; /* return error */
7892 }
7893 *enable = (mpu6050_bool_t)((prev >> 7) & 0x1); /* get the bool */
7894
7895 return 0; /* success return 0 */
7896}
7897
7910{
7911 uint8_t res;
7912 uint8_t prev;
7913
7914 if (handle == NULL) /* check handle */
7915 {
7916 return 2; /* return error */
7917 }
7918 if (handle->inited != 1) /* check handle initialization */
7919 {
7920 return 3; /* return error */
7921 }
7922
7923 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
7924 if (res != 0) /* check result */
7925 {
7926 handle->debug_print("mpu6050: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
7927
7928 return 1; /* return error */
7929 }
7930 prev &= ~(1 << 6); /* clear the settings */
7931 prev |= enable << 6; /* set the bool */
7932 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* write i2c mst ctrl */
7933 if (res != 0) /* check result */
7934 {
7935 handle->debug_print("mpu6050: write i2c mst ctrl failed.\n"); /* write i2c mst ctrl failed */
7936
7937 return 1; /* return error */
7938 }
7939
7940 return 0; /* success return 0 */
7941}
7942
7955{
7956 uint8_t res;
7957 uint8_t prev;
7958
7959 if (handle == NULL) /* check handle */
7960 {
7961 return 2; /* return error */
7962 }
7963 if (handle->inited != 1) /* check handle initialization */
7964 {
7965 return 3; /* return error */
7966 }
7967
7968 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
7969 if (res != 0) /* check result */
7970 {
7971 handle->debug_print("mpu6050: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
7972
7973 return 1; /* return error */
7974 }
7975 *enable = (mpu6050_bool_t)((prev >> 6) & 0x1); /* get the bool */
7976
7977 return 0; /* success return 0 */
7978}
7979
7992{
7993 uint8_t res;
7994 uint8_t prev;
7995
7996 if (handle == NULL) /* check handle */
7997 {
7998 return 2; /* return error */
7999 }
8000 if (handle->inited != 1) /* check handle initialization */
8001 {
8002 return 3; /* return error */
8003 }
8004
8005 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
8006 if (res != 0) /* check result */
8007 {
8008 handle->debug_print("mpu6050: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
8009
8010 return 1; /* return error */
8011 }
8012 prev &= ~(1 << 4); /* clear the settings */
8013 prev |= mode << 4; /* set the mode */
8014 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* write i2c mst ctrl */
8015 if (res != 0) /* check result */
8016 {
8017 handle->debug_print("mpu6050: write i2c mst ctrl failed.\n"); /* write i2c mst ctrl failed */
8018
8019 return 1; /* return error */
8020 }
8021
8022 return 0; /* success return 0 */
8023}
8024
8037{
8038 uint8_t res;
8039 uint8_t prev;
8040
8041 if (handle == NULL) /* check handle */
8042 {
8043 return 2; /* return error */
8044 }
8045 if (handle->inited != 1) /* check handle initialization */
8046 {
8047 return 3; /* return error */
8048 }
8049
8050 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
8051 if (res != 0) /* check result */
8052 {
8053 handle->debug_print("mpu6050: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
8054
8055 return 1; /* return error */
8056 }
8057 *mode = (mpu6050_iic_read_mode_t)((prev >> 4) & 0x1); /* get the mode */
8058
8059 return 0; /* success return 0 */
8060}
8061
8076{
8077 uint8_t res;
8078 uint8_t prev;
8079
8080 if (handle == NULL) /* check handle */
8081 {
8082 return 2; /* return error */
8083 }
8084 if (handle->inited != 1) /* check handle initialization */
8085 {
8086 return 3; /* return error */
8087 }
8088
8089 if ((slave == MPU6050_IIC_SLAVE_0) ||
8090 (slave == MPU6050_IIC_SLAVE_1) ||
8091 (slave == MPU6050_IIC_SLAVE_2)
8092 ) /* slave0-2 */
8093 {
8094 res = a_mpu6050_iic_read(handle, MPU6050_REG_FIFO_EN, (uint8_t *)&prev, 1); /* read fifo enable */
8095 if (res != 0) /* check result */
8096 {
8097 handle->debug_print("mpu6050: read fifo enable failed.\n"); /* read fifo enable failed */
8098
8099 return 1; /* return error */
8100 }
8101 prev &= ~(1 << slave); /* clear the settings */
8102 prev |= enable << slave; /* set the bool */
8103 res = a_mpu6050_iic_write(handle, MPU6050_REG_FIFO_EN, (uint8_t *)&prev, 1); /* write fifo enable ctrl */
8104 if (res != 0) /* check result */
8105 {
8106 handle->debug_print("mpu6050: write fifo enable failed.\n"); /* write fifo enable failed */
8107
8108 return 1; /* return error */
8109 }
8110 }
8111 else if (slave == MPU6050_IIC_SLAVE_3) /* slave3 */
8112 {
8113 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
8114 if (res != 0) /* check result */
8115 {
8116 handle->debug_print("mpu6050: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
8117
8118 return 1; /* return error */
8119 }
8120 prev &= ~(1 << 5); /* clear the settings */
8121 prev |= enable << 5; /* set the bool */
8122 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* write i2c mst ctrl */
8123 if (res != 0) /* check result */
8124 {
8125 handle->debug_print("mpu6050: write i2c mst ctrl failed.\n"); /* write i2c mst ctrl failed */
8126
8127 return 1; /* return error */
8128 }
8129 }
8130 else
8131 {
8132 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
8133
8134 return 4; /* return error */
8135 }
8136
8137 return 0; /* success return 0 */
8138}
8139
8154{
8155 uint8_t res;
8156 uint8_t prev;
8157
8158 if (handle == NULL) /* check handle */
8159 {
8160 return 2; /* return error */
8161 }
8162 if (handle->inited != 1) /* check handle initialization */
8163 {
8164 return 3; /* return error */
8165 }
8166
8167 if ((slave == MPU6050_IIC_SLAVE_0) ||
8168 (slave == MPU6050_IIC_SLAVE_1) ||
8169 (slave == MPU6050_IIC_SLAVE_2)
8170 ) /* slave0-2 */
8171 {
8172 res = a_mpu6050_iic_read(handle, MPU6050_REG_FIFO_EN, (uint8_t *)&prev, 1); /* read fifo enable */
8173 if (res != 0) /* check result */
8174 {
8175 handle->debug_print("mpu6050: read fifo enable failed.\n"); /* read fifo enable failed */
8176
8177 return 1; /* return error */
8178 }
8179 *enable = (mpu6050_bool_t)((prev >> slave) & 0x1); /* get the bool */
8180 }
8181 else if (slave == MPU6050_IIC_SLAVE_3) /* slave3 */
8182 {
8183 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_MST_CTRL, (uint8_t *)&prev, 1); /* read i2c mst ctrl */
8184 if (res != 0) /* check result */
8185 {
8186 handle->debug_print("mpu6050: read i2c mst ctrl failed.\n"); /* read i2c mst ctrl failed */
8187
8188 return 1; /* return error */
8189 }
8190 *enable = (mpu6050_bool_t)((prev >> 5) & 0x01); /* get the bool */
8191 }
8192 else
8193 {
8194 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
8195
8196 return 4; /* return error */
8197 }
8198
8199 return 0; /* success return 0 */
8200}
8201
8216{
8217 uint8_t res;
8218 uint8_t prev;
8219
8220 if (handle == NULL) /* check handle */
8221 {
8222 return 2; /* return error */
8223 }
8224 if (handle->inited != 1) /* check handle initialization */
8225 {
8226 return 3; /* return error */
8227 }
8228
8229 if (slave == MPU6050_IIC_SLAVE_0) /* slave0 */
8230 {
8231 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* read i2c slv0 addr */
8232 if (res != 0) /* check result */
8233 {
8234 handle->debug_print("mpu6050: read i2c slv0 addr failed.\n"); /* read i2c slv0 addr failed */
8235
8236 return 1; /* return error */
8237 }
8238 prev &= ~(1 << 7); /* clear the settings */
8239 prev |= mode << 7; /* set the bool */
8240 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* write i2c slv0 addr */
8241 if (res != 0) /* check result */
8242 {
8243 handle->debug_print("mpu6050: write i2c slv0 addr failed.\n"); /* write i2c slv0 addr failed */
8244
8245 return 1; /* return error */
8246 }
8247 }
8248 else if (slave == MPU6050_IIC_SLAVE_1) /* slave1 */
8249 {
8250 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV1_ADDR, (uint8_t *)&prev, 1); /* read i2c slv1 addr */
8251 if (res != 0) /* check result */
8252 {
8253 handle->debug_print("mpu6050: read i2c slv1 addr failed.\n"); /* read i2c slv1 addr failed */
8254
8255 return 1; /* return error */
8256 }
8257 prev &= ~(1 << 7); /* clear the settings */
8258 prev |= mode << 7; /* set the bool */
8259 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV1_ADDR, (uint8_t *)&prev, 1); /* write i2c slv1 addr */
8260 if (res != 0) /* check result */
8261 {
8262 handle->debug_print("mpu6050: write i2c slv1 addr failed.\n"); /* write i2c slv1 addr failed */
8263
8264 return 1; /* return error */
8265 }
8266 }
8267 else if (slave == MPU6050_IIC_SLAVE_2) /* slave2 */
8268 {
8269 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV2_ADDR, (uint8_t *)&prev, 1); /* read i2c slv2 addr */
8270 if (res != 0) /* check result */
8271 {
8272 handle->debug_print("mpu6050: read i2c slv2 addr failed.\n"); /* read i2c slv2 addr failed */
8273
8274 return 1; /* return error */
8275 }
8276 prev &= ~(1 << 7); /* clear the settings */
8277 prev |= mode << 7; /* set the bool */
8278 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV2_ADDR, (uint8_t *)&prev, 1); /* write i2c slv2 addr */
8279 if (res != 0) /* check result */
8280 {
8281 handle->debug_print("mpu6050: write i2c slv2 addr failed.\n"); /* write i2c slv2 addr failed */
8282
8283 return 1; /* return error */
8284 }
8285 }
8286 else if (slave == MPU6050_IIC_SLAVE_3) /* slave2 */
8287 {
8288 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV3_ADDR, (uint8_t *)&prev, 1); /* read i2c slv3 addr */
8289 if (res != 0) /* check result */
8290 {
8291 handle->debug_print("mpu6050: read i2c slv3 addr failed.\n"); /* read i2c slv3 addr failed */
8292
8293 return 1; /* return error */
8294 }
8295 prev &= ~(1 << 7); /* clear the settings */
8296 prev |= mode << 7; /* set the bool */
8297 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV3_ADDR, (uint8_t *)&prev, 1); /* write i2c slv3 addr */
8298 if (res != 0) /* check result */
8299 {
8300 handle->debug_print("mpu6050: write i2c slv3 addr failed.\n"); /* write i2c slv3 addr failed */
8301
8302 return 1; /* return error */
8303 }
8304 }
8305 else if (slave == MPU6050_IIC_SLAVE_4) /* slave4 */
8306 {
8307 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV4_ADDR, (uint8_t *)&prev, 1); /* read i2c slv4 addr */
8308 if (res != 0) /* check result */
8309 {
8310 handle->debug_print("mpu6050: read i2c slv4 addr failed.\n"); /* read i2c slv4 addr failed */
8311
8312 return 1; /* return error */
8313 }
8314 prev &= ~(1 << 7); /* clear the settings */
8315 prev |= mode << 7; /* set the bool */
8316 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV4_ADDR, (uint8_t *)&prev, 1); /* write i2c slv4 addr */
8317 if (res != 0) /* check result */
8318 {
8319 handle->debug_print("mpu6050: write i2c slv4 addr failed.\n"); /* write i2c slv4 addr failed */
8320
8321 return 1; /* return error */
8322 }
8323 }
8324 else
8325 {
8326 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
8327
8328 return 4; /* return error */
8329 }
8330
8331 return 0; /* success return 0 */
8332}
8333
8348{
8349 uint8_t res;
8350 uint8_t prev;
8351
8352 if (handle == NULL) /* check handle */
8353 {
8354 return 2; /* return error */
8355 }
8356 if (handle->inited != 1) /* check handle initialization */
8357 {
8358 return 3; /* return error */
8359 }
8360
8361 if (slave == MPU6050_IIC_SLAVE_0) /* slave0 */
8362 {
8363 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* read i2c slv0 addr */
8364 if (res != 0) /* check result */
8365 {
8366 handle->debug_print("mpu6050: read i2c slv0 addr failed.\n"); /* read i2c slv0 addr failed */
8367
8368 return 1; /* return error */
8369 }
8370 *mode = (mpu6050_iic_mode_t)((prev >> 7) & 0x1); /* get the mode */
8371 }
8372 else if (slave == MPU6050_IIC_SLAVE_1) /* slave1 */
8373 {
8374 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV1_ADDR, (uint8_t *)&prev, 1); /* read i2c slv1 addr */
8375 if (res != 0) /* check result */
8376 {
8377 handle->debug_print("mpu6050: read i2c slv1 addr failed.\n"); /* read i2c slv1 addr failed */
8378
8379 return 1; /* return error */
8380 }
8381 *mode = (mpu6050_iic_mode_t)((prev >> 7) & 0x1); /* get the mode */
8382 }
8383 else if (slave == MPU6050_IIC_SLAVE_2) /* slave2 */
8384 {
8385 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV2_ADDR, (uint8_t *)&prev, 1); /* read i2c slv2 addr */
8386 if (res != 0) /* check result */
8387 {
8388 handle->debug_print("mpu6050: read i2c slv2 addr failed.\n"); /* read i2c slv2 addr failed */
8389
8390 return 1; /* return error */
8391 }
8392 *mode = (mpu6050_iic_mode_t)((prev >> 7) & 0x1); /* get the mode */
8393 }
8394 else if (slave == MPU6050_IIC_SLAVE_3) /* slave2 */
8395 {
8396 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV3_ADDR, (uint8_t *)&prev, 1); /* read i2c slv3 addr */
8397 if (res != 0) /* check result */
8398 {
8399 handle->debug_print("mpu6050: read i2c slv3 addr failed.\n"); /* read i2c slv3 addr failed */
8400
8401 return 1; /* return error */
8402 }
8403 *mode = (mpu6050_iic_mode_t)((prev >> 7) & 0x1); /* get the mode */
8404 }
8405 else if (slave == MPU6050_IIC_SLAVE_4) /* slave4 */
8406 {
8407 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV4_ADDR, (uint8_t *)&prev, 1); /* read i2c slv4 addr */
8408 if (res != 0) /* check result */
8409 {
8410 handle->debug_print("mpu6050: read i2c slv4 addr failed.\n"); /* read i2c slv4 addr failed */
8411
8412 return 1; /* return error */
8413 }
8414 *mode = (mpu6050_iic_mode_t)((prev >> 7) & 0x1); /* get the mode */
8415 }
8416 else
8417 {
8418 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
8419
8420 return 4; /* return error */
8421 }
8422
8423 return 0; /* success return 0 */
8424}
8425
8439uint8_t mpu6050_set_iic_address(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, uint8_t addr_7bit)
8440{
8441 uint8_t res;
8442 uint8_t prev;
8443
8444 if (handle == NULL) /* check handle */
8445 {
8446 return 2; /* return error */
8447 }
8448 if (handle->inited != 1) /* check handle initialization */
8449 {
8450 return 3; /* return error */
8451 }
8452
8453 if (slave == MPU6050_IIC_SLAVE_0) /* slave0 */
8454 {
8455 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* read i2c slv0 addr */
8456 if (res != 0) /* check result */
8457 {
8458 handle->debug_print("mpu6050: read i2c slv0 addr failed.\n"); /* read i2c slv0 addr failed */
8459
8460 return 1; /* return error */
8461 }
8462 prev &= ~0x7F; /* clear the settings */
8463 prev |= addr_7bit & 0x7F; /* set the address */
8464 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* write i2c slv0 addr */
8465 if (res != 0) /* check result */
8466 {
8467 handle->debug_print("mpu6050: write i2c slv0 addr failed.\n"); /* write i2c slv0 addr failed */
8468
8469 return 1; /* return error */
8470 }
8471 }
8472 else if (slave == MPU6050_IIC_SLAVE_1) /* slave1 */
8473 {
8474 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV1_ADDR, (uint8_t *)&prev, 1); /* read i2c slv1 addr */
8475 if (res != 0) /* check result */
8476 {
8477 handle->debug_print("mpu6050: read i2c slv1 addr failed.\n"); /* read i2c slv1 addr failed */
8478
8479 return 1; /* return error */
8480 }
8481 prev &= ~0x7F; /* clear the settings */
8482 prev |= addr_7bit & 0x7F; /* set the address */
8483 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV1_ADDR, (uint8_t *)&prev, 1); /* write i2c slv1 addr */
8484 if (res != 0) /* check result */
8485 {
8486 handle->debug_print("mpu6050: write i2c slv1 addr failed.\n"); /* write i2c slv1 addr failed */
8487
8488 return 1; /* return error */
8489 }
8490 }
8491 else if (slave == MPU6050_IIC_SLAVE_2) /* slave2 */
8492 {
8493 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV2_ADDR, (uint8_t *)&prev, 1); /* read i2c slv2 addr */
8494 if (res != 0) /* check result */
8495 {
8496 handle->debug_print("mpu6050: read i2c slv2 addr failed.\n"); /* read i2c slv2 addr failed */
8497
8498 return 1; /* return error */
8499 }
8500 prev &= ~0x7F; /* clear the settings */
8501 prev |= addr_7bit & 0x7F; /* set the address */
8502 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV2_ADDR, (uint8_t *)&prev, 1); /* write i2c slv2 addr */
8503 if (res != 0) /* check result */
8504 {
8505 handle->debug_print("mpu6050: write i2c slv2 addr failed.\n"); /* write i2c slv2 addr failed */
8506
8507 return 1; /* return error */
8508 }
8509 }
8510 else if (slave == MPU6050_IIC_SLAVE_3) /* slave2 */
8511 {
8512 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV3_ADDR, (uint8_t *)&prev, 1); /* read i2c slv3 addr */
8513 if (res != 0) /* check result */
8514 {
8515 handle->debug_print("mpu6050: read i2c slv3 addr failed.\n"); /* read i2c slv3 addr failed */
8516
8517 return 1; /* return error */
8518 }
8519 prev &= ~0x7F; /* clear the settings */
8520 prev |= addr_7bit & 0x7F; /* set the address */
8521 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV3_ADDR, (uint8_t *)&prev, 1); /* write i2c slv3 addr */
8522 if (res != 0) /* check result */
8523 {
8524 handle->debug_print("mpu6050: write i2c slv3 addr failed.\n"); /* write i2c slv3 addr failed */
8525
8526 return 1; /* return error */
8527 }
8528 }
8529 else if (slave == MPU6050_IIC_SLAVE_4) /* slave4 */
8530 {
8531 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV4_ADDR, (uint8_t *)&prev, 1); /* read i2c slv4 addr */
8532 if (res != 0) /* check result */
8533 {
8534 handle->debug_print("mpu6050: read i2c slv4 addr failed.\n"); /* read i2c slv4 addr failed */
8535
8536 return 1; /* return error */
8537 }
8538 prev &= ~0x7F; /* clear the settings */
8539 prev |= addr_7bit & 0x7F; /* set the address */
8540 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV4_ADDR, (uint8_t *)&prev, 1); /* write i2c slv4 addr */
8541 if (res != 0) /* check result */
8542 {
8543 handle->debug_print("mpu6050: write i2c slv4 addr failed.\n"); /* write i2c slv4 addr failed */
8544
8545 return 1; /* return error */
8546 }
8547 }
8548 else
8549 {
8550 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
8551
8552 return 4; /* return error */
8553 }
8554
8555 return 0; /* success return 0 */
8556}
8557
8571uint8_t mpu6050_get_iic_address(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, uint8_t *addr_7bit)
8572{
8573 uint8_t res;
8574 uint8_t prev;
8575
8576 if (handle == NULL) /* check handle */
8577 {
8578 return 2; /* return error */
8579 }
8580 if (handle->inited != 1) /* check handle initialization */
8581 {
8582 return 3; /* return error */
8583 }
8584
8585 if (slave == MPU6050_IIC_SLAVE_0) /* slave0 */
8586 {
8587 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV0_ADDR, (uint8_t *)&prev, 1); /* read i2c slv0 addr */
8588 if (res != 0) /* check result */
8589 {
8590 handle->debug_print("mpu6050: read i2c slv0 addr failed.\n"); /* read i2c slv0 addr failed */
8591
8592 return 1; /* return error */
8593 }
8594 *addr_7bit = prev & 0x7F; /* get the address */
8595 }
8596 else if (slave == MPU6050_IIC_SLAVE_1) /* slave1 */
8597 {
8598 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV1_ADDR, (uint8_t *)&prev, 1); /* read i2c slv1 addr */
8599 if (res != 0) /* check result */
8600 {
8601 handle->debug_print("mpu6050: read i2c slv1 addr failed.\n"); /* read i2c slv1 addr failed */
8602
8603 return 1; /* return error */
8604 }
8605 *addr_7bit = prev & 0x7F; /* get the address */
8606 }
8607 else if (slave == MPU6050_IIC_SLAVE_2) /* slave2 */
8608 {
8609 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV2_ADDR, (uint8_t *)&prev, 1); /* read i2c slv2 addr */
8610 if (res != 0) /* check result */
8611 {
8612 handle->debug_print("mpu6050: read i2c slv2 addr failed.\n"); /* read i2c slv2 addr failed */
8613
8614 return 1; /* return error */
8615 }
8616 *addr_7bit = prev & 0x7F; /* get the address */
8617 }
8618 else if (slave == MPU6050_IIC_SLAVE_3) /* slave2 */
8619 {
8620 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV3_ADDR, (uint8_t *)&prev, 1); /* read i2c slv3 addr */
8621 if (res != 0) /* check result */
8622 {
8623 handle->debug_print("mpu6050: read i2c slv3 addr failed.\n"); /* read i2c slv3 addr failed */
8624
8625 return 1; /* return error */
8626 }
8627 *addr_7bit = prev & 0x7F; /* get the address */
8628 }
8629 else if (slave == MPU6050_IIC_SLAVE_4) /* slave4 */
8630 {
8631 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV4_ADDR, (uint8_t *)&prev, 1); /* read i2c slv4 addr */
8632 if (res != 0) /* check result */
8633 {
8634 handle->debug_print("mpu6050: read i2c slv4 addr failed.\n"); /* read i2c slv4 addr failed */
8635
8636 return 1; /* return error */
8637 }
8638 *addr_7bit = prev & 0x7F; /* get the address */
8639 }
8640 else
8641 {
8642 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
8643
8644 return 4; /* return error */
8645 }
8646
8647 return 0; /* success return 0 */
8648}
8649
8664{
8665 uint8_t res;
8666
8667 if (handle == NULL) /* check handle */
8668 {
8669 return 2; /* return error */
8670 }
8671 if (handle->inited != 1) /* check handle initialization */
8672 {
8673 return 3; /* return error */
8674 }
8675
8676 if (slave == MPU6050_IIC_SLAVE_0) /* slave0 */
8677 {
8678 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV0_REG, (uint8_t *)&reg, 1); /* write i2c slv0 reg */
8679 if (res != 0) /* check result */
8680 {
8681 handle->debug_print("mpu6050: write i2c slv0 reg failed.\n"); /* write i2c slv0 reg failed */
8682
8683 return 1; /* return error */
8684 }
8685 }
8686 else if (slave == MPU6050_IIC_SLAVE_1) /* slave1 */
8687 {
8688 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV1_REG, (uint8_t *)&reg, 1); /* write i2c slv1 reg */
8689 if (res != 0) /* check result */
8690 {
8691 handle->debug_print("mpu6050: write i2c slv1 reg failed.\n"); /* write i2c slv1 reg failed */
8692
8693 return 1; /* return error */
8694 }
8695 }
8696 else if (slave == MPU6050_IIC_SLAVE_2) /* slave2 */
8697 {
8698 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV2_REG, (uint8_t *)&reg, 1); /* write i2c slv2 reg */
8699 if (res != 0) /* check result */
8700 {
8701 handle->debug_print("mpu6050: write i2c slv2 reg failed.\n"); /* write i2c slv2 reg failed */
8702
8703 return 1; /* return error */
8704 }
8705 }
8706 else if (slave == MPU6050_IIC_SLAVE_3) /* slave2 */
8707 {
8708 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV3_REG, (uint8_t *)&reg, 1); /* write i2c slv3 reg */
8709 if (res != 0) /* check result */
8710 {
8711 handle->debug_print("mpu6050: write i2c slv3 reg failed.\n"); /* write i2c slv3 reg failed */
8712
8713 return 1; /* return error */
8714 }
8715 }
8716 else if (slave == MPU6050_IIC_SLAVE_4) /* slave4 */
8717 {
8718 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV4_REG, (uint8_t *)&reg, 1); /* write i2c slv4 reg */
8719 if (res != 0) /* check result */
8720 {
8721 handle->debug_print("mpu6050: write i2c slv4 reg failed.\n"); /* write i2c slv4 reg failed */
8722
8723 return 1; /* return error */
8724 }
8725 }
8726 else
8727 {
8728 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
8729
8730 return 4; /* return error */
8731 }
8732
8733 return 0; /* success return 0 */
8734}
8735
8750{
8751 uint8_t res;
8752
8753 if (handle == NULL) /* check handle */
8754 {
8755 return 2; /* return error */
8756 }
8757 if (handle->inited != 1) /* check handle initialization */
8758 {
8759 return 3; /* return error */
8760 }
8761
8762 if (slave == MPU6050_IIC_SLAVE_0) /* slave0 */
8763 {
8764 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV0_REG, (uint8_t *)reg, 1); /* read i2c slv0 reg */
8765 if (res != 0) /* check result */
8766 {
8767 handle->debug_print("mpu6050: read i2c slv0 reg failed.\n"); /* read i2c slv0 reg failed */
8768
8769 return 1; /* return error */
8770 }
8771 }
8772 else if (slave == MPU6050_IIC_SLAVE_1) /* slave1 */
8773 {
8774 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV1_REG, (uint8_t *)reg, 1); /* read i2c slv1 reg */
8775 if (res != 0) /* check result */
8776 {
8777 handle->debug_print("mpu6050: read i2c slv1 reg failed.\n"); /* read i2c slv1 reg failed */
8778
8779 return 1; /* return error */
8780 }
8781 }
8782 else if (slave == MPU6050_IIC_SLAVE_2) /* slave2 */
8783 {
8784 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV2_REG, (uint8_t *)reg, 1); /* read i2c slv2 reg */
8785 if (res != 0) /* check result */
8786 {
8787 handle->debug_print("mpu6050: read i2c slv2 reg failed.\n"); /* read i2c slv2 reg failed */
8788
8789 return 1; /* return error */
8790 }
8791 }
8792 else if (slave == MPU6050_IIC_SLAVE_3) /* slave2 */
8793 {
8794 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV3_REG, (uint8_t *)reg, 1); /* read i2c slv3 reg */
8795 if (res != 0) /* check result */
8796 {
8797 handle->debug_print("mpu6050: read i2c slv3 reg failed.\n"); /* read i2c slv3 reg failed */
8798
8799 return 1; /* return error */
8800 }
8801 }
8802 else if (slave == MPU6050_IIC_SLAVE_4) /* slave4 */
8803 {
8804 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV4_REG, (uint8_t *)reg, 1); /* read i2c slv4 reg */
8805 if (res != 0) /* check result */
8806 {
8807 handle->debug_print("mpu6050: read i2c slv4 reg failed.\n"); /* read i2c slv4 reg failed */
8808
8809 return 1; /* return error */
8810 }
8811 }
8812 else
8813 {
8814 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
8815
8816 return 4; /* return error */
8817 }
8818
8819 return 0; /* success return 0 */
8820}
8821
8836{
8837 uint8_t res;
8838
8839 if (handle == NULL) /* check handle */
8840 {
8841 return 2; /* return error */
8842 }
8843 if (handle->inited != 1) /* check handle initialization */
8844 {
8845 return 3; /* return error */
8846 }
8847
8848 if (slave == MPU6050_IIC_SLAVE_0) /* slave0 */
8849 {
8850 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV0_DO, (uint8_t *)&data, 1); /* write i2c slv0 do */
8851 if (res != 0) /* check result */
8852 {
8853 handle->debug_print("mpu6050: write i2c slv0 do failed.\n"); /* write i2c slv0 do fail */
8854
8855 return 1; /* return error */
8856 }
8857 }
8858 else if (slave == MPU6050_IIC_SLAVE_1) /* slave1 */
8859 {
8860 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV1_DO, (uint8_t *)&data, 1); /* write i2c slv1 do */
8861 if (res != 0) /* check result */
8862 {
8863 handle->debug_print("mpu6050: write i2c slv1 do failed.\n"); /* write i2c slv1 do fail */
8864
8865 return 1; /* return error */
8866 }
8867 }
8868 else if (slave == MPU6050_IIC_SLAVE_2) /* slave2 */
8869 {
8870 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV2_DO, (uint8_t *)&data, 1); /* write i2c slv2 do */
8871 if (res != 0) /* check result */
8872 {
8873 handle->debug_print("mpu6050: write i2c slv2 do failed.\n"); /* write i2c slv2 do fail */
8874
8875 return 1; /* return error */
8876 }
8877 }
8878 else if (slave == MPU6050_IIC_SLAVE_3) /* slave2 */
8879 {
8880 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV3_DO, (uint8_t *)&data, 1); /* write i2c slv3 do */
8881 if (res != 0) /* check result */
8882 {
8883 handle->debug_print("mpu6050: write i2c slv3 do failed.\n"); /* write i2c slv3 do fail */
8884
8885 return 1; /* return error */
8886 }
8887 }
8888 else
8889 {
8890 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
8891
8892 return 4; /* return error */
8893 }
8894
8895 return 0; /* success return 0 */
8896}
8897
8912{
8913 uint8_t res;
8914
8915 if (handle == NULL) /* check handle */
8916 {
8917 return 2; /* return error */
8918 }
8919 if (handle->inited != 1) /* check handle initialization */
8920 {
8921 return 3; /* return error */
8922 }
8923
8924 if (slave == MPU6050_IIC_SLAVE_0) /* slave0 */
8925 {
8926 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV0_DO, (uint8_t *)data, 1); /* read i2c slv0 do */
8927 if (res != 0) /* check result */
8928 {
8929 handle->debug_print("mpu6050: read i2c slv0 do failed.\n"); /* read i2c slv0 do failed */
8930
8931 return 1; /* return error */
8932 }
8933 }
8934 else if (slave == MPU6050_IIC_SLAVE_1) /* slave1 */
8935 {
8936 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV1_DO, (uint8_t *)data, 1); /* read i2c slv1 do */
8937 if (res != 0) /* check result */
8938 {
8939 handle->debug_print("mpu6050: read i2c slv1 do failed.\n"); /* read i2c slv1 do failed */
8940
8941 return 1; /* return error */
8942 }
8943 }
8944 else if (slave == MPU6050_IIC_SLAVE_2) /* slave2 */
8945 {
8946 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV2_DO, (uint8_t *)data, 1); /* read i2c slv2 do */
8947 if (res != 0) /* check result */
8948 {
8949 handle->debug_print("mpu6050: read i2c slv2 do failed.\n"); /* read i2c slv2 do failed */
8950
8951 return 1; /* return error */
8952 }
8953 }
8954 else if (slave == MPU6050_IIC_SLAVE_3) /* slave2 */
8955 {
8956 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV3_DO, (uint8_t *)data, 1); /* read i2c slv3 do */
8957 if (res != 0) /* check result */
8958 {
8959 handle->debug_print("mpu6050: read i2c slv3 do failed.\n"); /* read i2c slv3 do failed */
8960
8961 return 1; /* return error */
8962 }
8963 }
8964 else
8965 {
8966 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
8967
8968 return 4; /* return error */
8969 }
8970
8971 return 0; /* success return 0 */
8972}
8973
8988{
8989 uint8_t res;
8990 uint8_t prev;
8991
8992 if (handle == NULL) /* check handle */
8993 {
8994 return 2; /* return error */
8995 }
8996 if (handle->inited != 1) /* check handle initialization */
8997 {
8998 return 3; /* return error */
8999 }
9000
9001 if (slave == MPU6050_IIC_SLAVE_0) /* slave0 */
9002 {
9003 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
9004 if (res != 0) /* check result */
9005 {
9006 handle->debug_print("mpu6050: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
9007
9008 return 1; /* return error */
9009 }
9010 prev &= ~(1 << 7); /* clear the settings */
9011 prev |= enable << 7; /* set the bool */
9012 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* write i2c slv0 ctrl */
9013 if (res != 0) /* check result */
9014 {
9015 handle->debug_print("mpu6050: write i2c slv0 ctrl failed.\n"); /* write i2c slv0 ctrl failed */
9016
9017 return 1; /* return error */
9018 }
9019 }
9020 else if (slave == MPU6050_IIC_SLAVE_1) /* slave1 */
9021 {
9022 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
9023 if (res != 0) /* check result */
9024 {
9025 handle->debug_print("mpu6050: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
9026
9027 return 1; /* return error */
9028 }
9029 prev &= ~(1 << 7); /* clear the settings */
9030 prev |= enable << 7; /* set the bool */
9031 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* write i2c slv1 ctrl */
9032 if (res != 0) /* check result */
9033 {
9034 handle->debug_print("mpu6050: write i2c slv1 ctrl failed.\n"); /* write i2c slv1 ctrl failed */
9035
9036 return 1; /* return error */
9037 }
9038 }
9039 else if (slave == MPU6050_IIC_SLAVE_2) /* slave2 */
9040 {
9041 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
9042 if (res != 0) /* check result */
9043 {
9044 handle->debug_print("mpu6050: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
9045
9046 return 1; /* return error */
9047 }
9048 prev &= ~(1 << 7); /* clear the settings */
9049 prev |= enable << 7; /* set the bool */
9050 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* write i2c slv2 ctrl */
9051 if (res != 0) /* check result */
9052 {
9053 handle->debug_print("mpu6050: write i2c slv2 ctrl failed.\n"); /* write i2c slv2 ctrl failed */
9054
9055 return 1; /* return error */
9056 }
9057 }
9058 else if (slave == MPU6050_IIC_SLAVE_3) /* slave2 */
9059 {
9060 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
9061 if (res != 0) /* check result */
9062 {
9063 handle->debug_print("mpu6050: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
9064
9065 return 1; /* return error */
9066 }
9067 prev &= ~(1 << 7); /* clear the settings */
9068 prev |= enable << 7; /* set the bool */
9069 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* write i2c slv3 ctrl */
9070 if (res != 0) /* check result */
9071 {
9072 handle->debug_print("mpu6050: write i2c slv3 ctrl failed.\n"); /* write i2c slv3 ctrl failed */
9073
9074 return 1; /* return error */
9075 }
9076 }
9077 else
9078 {
9079 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
9080
9081 return 4; /* return error */
9082 }
9083
9084 return 0; /* success return 0 */
9085}
9086
9101{
9102 uint8_t res;
9103 uint8_t prev;
9104
9105 if (handle == NULL) /* check handle */
9106 {
9107 return 2; /* return error */
9108 }
9109 if (handle->inited != 1) /* check handle initialization */
9110 {
9111 return 3; /* return error */
9112 }
9113
9114 if (slave == MPU6050_IIC_SLAVE_0) /* slave0 */
9115 {
9116 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
9117 if (res != 0) /* check result */
9118 {
9119 handle->debug_print("mpu6050: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
9120
9121 return 1; /* return error */
9122 }
9123 *enable = (mpu6050_bool_t)((prev >> 7) & 0x1); /* get the bool */
9124 }
9125 else if (slave == MPU6050_IIC_SLAVE_1) /* slave1 */
9126 {
9127 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
9128 if (res != 0) /* check result */
9129 {
9130 handle->debug_print("mpu6050: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
9131
9132 return 1; /* return error */
9133 }
9134 *enable = (mpu6050_bool_t)((prev >> 7) & 0x1); /* get the bool */
9135 }
9136 else if (slave == MPU6050_IIC_SLAVE_2) /* slave2 */
9137 {
9138 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
9139 if (res != 0) /* check result */
9140 {
9141 handle->debug_print("mpu6050: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
9142
9143 return 1; /* return error */
9144 }
9145 *enable = (mpu6050_bool_t)((prev >> 7) & 0x1); /* get the bool */
9146 }
9147 else if (slave == MPU6050_IIC_SLAVE_3) /* slave2 */
9148 {
9149 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
9150 if (res != 0) /* check result */
9151 {
9152 handle->debug_print("mpu6050: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
9153
9154 return 1; /* return error */
9155 }
9156 *enable = (mpu6050_bool_t)((prev >> 7) & 0x1); /* get the bool */
9157 }
9158 else
9159 {
9160 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
9161
9162 return 4; /* return error */
9163 }
9164
9165 return 0; /* success return 0 */
9166}
9167
9182{
9183 uint8_t res;
9184 uint8_t prev;
9185
9186 if (handle == NULL) /* check handle */
9187 {
9188 return 2; /* return error */
9189 }
9190 if (handle->inited != 1) /* check handle initialization */
9191 {
9192 return 3; /* return error */
9193 }
9194
9195 if (slave == MPU6050_IIC_SLAVE_0) /* slave0 */
9196 {
9197 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
9198 if (res != 0) /* check result */
9199 {
9200 handle->debug_print("mpu6050: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
9201
9202 return 1; /* return error */
9203 }
9204 prev &= ~(1 << 6); /* clear the settings */
9205 prev |= enable << 6; /* set the bool */
9206 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* write i2c slv0 ctrl */
9207 if (res != 0) /* check result */
9208 {
9209 handle->debug_print("mpu6050: write i2c slv0 ctrl failed.\n"); /* write i2c slv0 ctrl failed */
9210
9211 return 1; /* return error */
9212 }
9213 }
9214 else if (slave == MPU6050_IIC_SLAVE_1) /* slave1 */
9215 {
9216 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
9217 if (res != 0) /* check result */
9218 {
9219 handle->debug_print("mpu6050: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
9220
9221 return 1; /* return error */
9222 }
9223 prev &= ~(1 << 6); /* clear the settings */
9224 prev |= enable << 6; /* set the bool */
9225 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* write i2c slv1 ctrl */
9226 if (res != 0) /* check result */
9227 {
9228 handle->debug_print("mpu6050: write i2c slv1 ctrl failed.\n"); /* write i2c slv1 ctrl failed */
9229
9230 return 1; /* return error */
9231 }
9232 }
9233 else if (slave == MPU6050_IIC_SLAVE_2) /* slave2 */
9234 {
9235 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
9236 if (res != 0) /* check result */
9237 {
9238 handle->debug_print("mpu6050: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
9239
9240 return 1; /* return error */
9241 }
9242 prev &= ~(1 << 6); /* clear the settings */
9243 prev |= enable << 6; /* set the bool */
9244 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* write i2c slv2 ctrl */
9245 if (res != 0) /* check result */
9246 {
9247 handle->debug_print("mpu6050: write i2c slv2 ctrl failed.\n"); /* write i2c slv2 ctrl failed */
9248
9249 return 1; /* return error */
9250 }
9251 }
9252 else if (slave == MPU6050_IIC_SLAVE_3) /* slave2 */
9253 {
9254 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
9255 if (res != 0) /* check result */
9256 {
9257 handle->debug_print("mpu6050: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
9258
9259 return 1; /* return error */
9260 }
9261 prev &= ~(1 << 6); /* clear the settings */
9262 prev |= enable << 6; /* set the bool */
9263 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* write i2c slv3 ctrl */
9264 if (res != 0) /* check result */
9265 {
9266 handle->debug_print("mpu6050: write i2c slv3 ctrl failed.\n"); /* write i2c slv3 ctrl failed */
9267
9268 return 1; /* return error */
9269 }
9270 }
9271 else
9272 {
9273 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
9274
9275 return 4; /* return error */
9276 }
9277
9278 return 0; /* success return 0 */
9279}
9280
9295{
9296 uint8_t res;
9297 uint8_t prev;
9298
9299 if (handle == NULL) /* check handle */
9300 {
9301 return 2; /* return error */
9302 }
9303 if (handle->inited != 1) /* check handle initialization */
9304 {
9305 return 3; /* return error */
9306 }
9307
9308 if (slave == MPU6050_IIC_SLAVE_0) /* slave0 */
9309 {
9310 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
9311 if (res != 0) /* check result */
9312 {
9313 handle->debug_print("mpu6050: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
9314
9315 return 1; /* return error */
9316 }
9317 *enable = (mpu6050_bool_t)((prev >> 6) & 0x1); /* get the bool */
9318 }
9319 else if (slave == MPU6050_IIC_SLAVE_1) /* slave1 */
9320 {
9321 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
9322 if (res != 0) /* check result */
9323 {
9324 handle->debug_print("mpu6050: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
9325
9326 return 1; /* return error */
9327 }
9328 *enable = (mpu6050_bool_t)((prev >> 6) & 0x1); /* get the bool */
9329 }
9330 else if (slave == MPU6050_IIC_SLAVE_2) /* slave2 */
9331 {
9332 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
9333 if (res != 0) /* check result */
9334 {
9335 handle->debug_print("mpu6050: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
9336
9337 return 1; /* return error */
9338 }
9339 *enable = (mpu6050_bool_t)((prev >> 6) & 0x1); /* get the bool */
9340 }
9341 else if (slave == MPU6050_IIC_SLAVE_3) /* slave2 */
9342 {
9343 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
9344 if (res != 0) /* check result */
9345 {
9346 handle->debug_print("mpu6050: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
9347
9348 return 1; /* return error */
9349 }
9350 *enable = (mpu6050_bool_t)((prev >> 6) & 0x1); /* get the bool */
9351 }
9352 else
9353 {
9354 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
9355
9356 return 4; /* return error */
9357 }
9358
9359 return 0; /* success return 0 */
9360}
9361
9376{
9377 uint8_t res;
9378 uint8_t prev;
9379
9380 if (handle == NULL) /* check handle */
9381 {
9382 return 2; /* return error */
9383 }
9384 if (handle->inited != 1) /* check handle initialization */
9385 {
9386 return 3; /* return error */
9387 }
9388
9389 if (slave == MPU6050_IIC_SLAVE_0) /* slave0 */
9390 {
9391 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
9392 if (res != 0) /* check result */
9393 {
9394 handle->debug_print("mpu6050: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
9395
9396 return 1; /* return error */
9397 }
9398 prev &= ~(1 << 5); /* clear the settings */
9399 prev |= mode << 5; /* set the bool */
9400 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* write i2c slv0 ctrl */
9401 if (res != 0) /* check result */
9402 {
9403 handle->debug_print("mpu6050: write i2c slv0 ctrl failed.\n"); /* write i2c slv0 ctrl failed */
9404
9405 return 1; /* return error */
9406 }
9407 }
9408 else if (slave == MPU6050_IIC_SLAVE_1) /* slave1 */
9409 {
9410 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
9411 if (res != 0) /* check result */
9412 {
9413 handle->debug_print("mpu6050: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
9414
9415 return 1; /* return error */
9416 }
9417 prev &= ~(1 << 5); /* clear the settings */
9418 prev |= mode << 5; /* set the bool */
9419 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* write i2c slv1 ctrl */
9420 if (res != 0) /* check result */
9421 {
9422 handle->debug_print("mpu6050: write i2c slv1 ctrl failed.\n"); /* write i2c slv1 ctrl failed */
9423
9424 return 1; /* return error */
9425 }
9426 }
9427 else if (slave == MPU6050_IIC_SLAVE_2) /* slave2 */
9428 {
9429 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
9430 if (res != 0) /* check result */
9431 {
9432 handle->debug_print("mpu6050: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
9433
9434 return 1; /* return error */
9435 }
9436 prev &= ~(1 << 5); /* clear the settings */
9437 prev |= mode << 5; /* set the bool */
9438 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* write i2c slv2 ctrl */
9439 if (res != 0) /* check result */
9440 {
9441 handle->debug_print("mpu6050: write i2c slv2 ctrl failed.\n"); /* write i2c slv2 ctrl failed */
9442
9443 return 1; /* return error */
9444 }
9445 }
9446 else if (slave == MPU6050_IIC_SLAVE_3) /* slave2 */
9447 {
9448 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
9449 if (res != 0) /* check result */
9450 {
9451 handle->debug_print("mpu6050: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
9452
9453 return 1; /* return error */
9454 }
9455 prev &= ~(1 << 5); /* clear the settings */
9456 prev |= mode << 5; /* set the bool */
9457 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* write i2c slv3 ctrl */
9458 if (res != 0) /* check result */
9459 {
9460 handle->debug_print("mpu6050: write i2c slv3 ctrl failed.\n"); /* write i2c slv3 ctrl failed */
9461
9462 return 1; /* return error */
9463 }
9464 }
9465 else
9466 {
9467 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
9468
9469 return 4; /* return error */
9470 }
9471
9472 return 0; /* success return 0 */
9473}
9474
9489{
9490 uint8_t res;
9491 uint8_t prev;
9492
9493 if (handle == NULL) /* check handle */
9494 {
9495 return 2; /* return error */
9496 }
9497 if (handle->inited != 1) /* check handle initialization */
9498 {
9499 return 3; /* return error */
9500 }
9501
9502 if (slave == MPU6050_IIC_SLAVE_0) /* slave0 */
9503 {
9504 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
9505 if (res != 0) /* check result */
9506 {
9507 handle->debug_print("mpu6050: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
9508
9509 return 1; /* return error */
9510 }
9511 *mode = (mpu6050_iic_transaction_mode_t)((prev >> 5) & 0x1); /* get the bool */
9512 }
9513 else if (slave == MPU6050_IIC_SLAVE_1) /* slave1 */
9514 {
9515 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
9516 if (res != 0) /* check result */
9517 {
9518 handle->debug_print("mpu6050: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
9519
9520 return 1; /* return error */
9521 }
9522 *mode = (mpu6050_iic_transaction_mode_t)((prev >> 5) & 0x1); /* get the bool */
9523 }
9524 else if (slave == MPU6050_IIC_SLAVE_2) /* slave2 */
9525 {
9526 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
9527 if (res != 0) /* check result */
9528 {
9529 handle->debug_print("mpu6050: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
9530
9531 return 1; /* return error */
9532 }
9533 *mode = (mpu6050_iic_transaction_mode_t)((prev >> 5) & 0x1); /* get the bool */
9534 }
9535 else if (slave == MPU6050_IIC_SLAVE_3) /* slave2 */
9536 {
9537 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
9538 if (res != 0) /* check result */
9539 {
9540 handle->debug_print("mpu6050: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
9541
9542 return 1; /* return error */
9543 }
9544 *mode = (mpu6050_iic_transaction_mode_t)((prev >> 5) & 0x1); /* get the bool */
9545 }
9546 else
9547 {
9548 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
9549
9550 return 4; /* return error */
9551 }
9552
9553 return 0; /* success return 0 */
9554}
9555
9570{
9571 uint8_t res;
9572 uint8_t prev;
9573
9574 if (handle == NULL) /* check handle */
9575 {
9576 return 2; /* return error */
9577 }
9578 if (handle->inited != 1) /* check handle initialization */
9579 {
9580 return 3; /* return error */
9581 }
9582
9583 if (slave == MPU6050_IIC_SLAVE_0) /* slave0 */
9584 {
9585 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
9586 if (res != 0) /* check result */
9587 {
9588 handle->debug_print("mpu6050: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
9589
9590 return 1; /* return error */
9591 }
9592 prev &= ~(1 << 4); /* clear the settings */
9593 prev |= order << 4; /* set the order */
9594 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* write i2c slv0 ctrl */
9595 if (res != 0) /* check result */
9596 {
9597 handle->debug_print("mpu6050: write i2c slv0 ctrl failed.\n"); /* write i2c slv0 ctrl failed */
9598
9599 return 1; /* return error */
9600 }
9601 }
9602 else if (slave == MPU6050_IIC_SLAVE_1) /* slave1 */
9603 {
9604 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
9605 if (res != 0) /* check result */
9606 {
9607 handle->debug_print("mpu6050: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
9608
9609 return 1; /* return error */
9610 }
9611 prev &= ~(1 << 4); /* clear the settings */
9612 prev |= order << 4; /* set the order */
9613 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* write i2c slv1 ctrl */
9614 if (res != 0) /* check result */
9615 {
9616 handle->debug_print("mpu6050: write i2c slv1 ctrl failed.\n"); /* write i2c slv1 ctrl failed */
9617
9618 return 1; /* return error */
9619 }
9620 }
9621 else if (slave == MPU6050_IIC_SLAVE_2) /* slave2 */
9622 {
9623 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
9624 if (res != 0) /* check result */
9625 {
9626 handle->debug_print("mpu6050: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
9627
9628 return 1; /* return error */
9629 }
9630 prev &= ~(1 << 4); /* clear the settings */
9631 prev |= order << 4; /* set the order */
9632 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* write i2c slv2 ctrl */
9633 if (res != 0) /* check result */
9634 {
9635 handle->debug_print("mpu6050: write i2c slv2 ctrl failed.\n"); /* write i2c slv2 ctrl failed */
9636
9637 return 1; /* return error */
9638 }
9639 }
9640 else if (slave == MPU6050_IIC_SLAVE_3) /* slave2 */
9641 {
9642 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
9643 if (res != 0) /* check result */
9644 {
9645 handle->debug_print("mpu6050: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
9646
9647 return 1; /* return error */
9648 }
9649 prev &= ~(1 << 4); /* clear the settings */
9650 prev |= order << 4; /* set the order */
9651 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* write i2c slv3 ctrl */
9652 if (res != 0) /* check result */
9653 {
9654 handle->debug_print("mpu6050: write i2c slv3 ctrl failed.\n"); /* write i2c slv3 ctrl failed */
9655
9656 return 1; /* return error */
9657 }
9658 }
9659 else
9660 {
9661 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
9662
9663 return 4; /* return error */
9664 }
9665
9666 return 0; /* success return 0 */
9667}
9668
9683{
9684 uint8_t res;
9685 uint8_t prev;
9686
9687 if (handle == NULL) /* check handle */
9688 {
9689 return 2; /* return error */
9690 }
9691 if (handle->inited != 1) /* check handle initialization */
9692 {
9693 return 3; /* return error */
9694 }
9695
9696 if (slave == MPU6050_IIC_SLAVE_0) /* slave0 */
9697 {
9698 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
9699 if (res != 0) /* check result */
9700 {
9701 handle->debug_print("mpu6050: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
9702
9703 return 1; /* return error */
9704 }
9705 *order = (mpu6050_iic_group_order_t)((prev >> 4) & 0x1); /* get the order */
9706 }
9707 else if (slave == MPU6050_IIC_SLAVE_1) /* slave1 */
9708 {
9709 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
9710 if (res != 0) /* check result */
9711 {
9712 handle->debug_print("mpu6050: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
9713
9714 return 1; /* return error */
9715 }
9716 *order = (mpu6050_iic_group_order_t)((prev >> 4) & 0x1); /* get the order */
9717 }
9718 else if (slave == MPU6050_IIC_SLAVE_2) /* slave2 */
9719 {
9720 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
9721 if (res != 0) /* check result */
9722 {
9723 handle->debug_print("mpu6050: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
9724
9725 return 1; /* return error */
9726 }
9727 *order = (mpu6050_iic_group_order_t)((prev >> 4) & 0x1); /* get the order */
9728 }
9729 else if (slave == MPU6050_IIC_SLAVE_3) /* slave2 */
9730 {
9731 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
9732 if (res != 0) /* check result */
9733 {
9734 handle->debug_print("mpu6050: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
9735
9736 return 1; /* return error */
9737 }
9738 *order = (mpu6050_iic_group_order_t)((prev >> 4) & 0x1); /* get the order */
9739 }
9740 else
9741 {
9742 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
9743
9744 return 4; /* return error */
9745 }
9746
9747 return 0; /* success return 0 */
9748}
9749
9765{
9766 uint8_t res;
9767 uint8_t prev;
9768
9769 if (handle == NULL) /* check handle */
9770 {
9771 return 2; /* return error */
9772 }
9773 if (handle->inited != 1) /* check handle initialization */
9774 {
9775 return 3; /* return error */
9776 }
9777 if (len > 0xF) /* check handle initialization */
9778 {
9779 handle->debug_print("mpu6050: len > 0xF.\n"); /* len > 0xF */
9780
9781 return 5; /* return error */
9782 }
9783
9784 if (slave == MPU6050_IIC_SLAVE_0) /* slave0 */
9785 {
9786 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
9787 if (res != 0) /* check result */
9788 {
9789 handle->debug_print("mpu6050: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
9790
9791 return 1; /* return error */
9792 }
9793 prev &= ~0xF; /* clear the settings */
9794 prev |= len; /* set the len */
9795 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* write i2c slv0 ctrl */
9796 if (res != 0) /* check result */
9797 {
9798 handle->debug_print("mpu6050: write i2c slv0 ctrl failed.\n"); /* write i2c slv0 ctrl failed */
9799
9800 return 1; /* return error */
9801 }
9802 }
9803 else if (slave == MPU6050_IIC_SLAVE_1) /* slave1 */
9804 {
9805 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
9806 if (res != 0) /* check result */
9807 {
9808 handle->debug_print("mpu6050: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
9809
9810 return 1; /* return error */
9811 }
9812 prev &= ~0xF; /* clear the settings */
9813 prev |= len; /* set the len */
9814 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* write i2c slv1 ctrl */
9815 if (res != 0) /* check result */
9816 {
9817 handle->debug_print("mpu6050: write i2c slv1 ctrl failed.\n"); /* write i2c slv1 ctrl failed */
9818
9819 return 1; /* return error */
9820 }
9821 }
9822 else if (slave == MPU6050_IIC_SLAVE_2) /* slave2 */
9823 {
9824 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
9825 if (res != 0) /* check result */
9826 {
9827 handle->debug_print("mpu6050: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
9828
9829 return 1; /* return error */
9830 }
9831 prev &= ~0xF; /* clear the settings */
9832 prev |= len; /* set the len */
9833 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* write i2c slv2 ctrl */
9834 if (res != 0) /* check result */
9835 {
9836 handle->debug_print("mpu6050: write i2c slv2 ctrl failed.\n"); /* write i2c slv2 ctrl failed */
9837
9838 return 1; /* return error */
9839 }
9840 }
9841 else if (slave == MPU6050_IIC_SLAVE_3) /* slave2 */
9842 {
9843 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
9844 if (res != 0) /* check result */
9845 {
9846 handle->debug_print("mpu6050: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
9847
9848 return 1; /* return error */
9849 }
9850 prev &= ~0xF; /* clear the settings */
9851 prev |= len; /* set the len */
9852 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* write i2c slv3 ctrl */
9853 if (res != 0) /* check result */
9854 {
9855 handle->debug_print("mpu6050: write i2c slv3 ctrl failed.\n"); /* write i2c slv3 ctrl failed */
9856
9857 return 1; /* return error */
9858 }
9859 }
9860 else
9861 {
9862 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
9863
9864 return 4; /* return error */
9865 }
9866
9867 return 0; /* success return 0 */
9868}
9869
9884{
9885 uint8_t res;
9886 uint8_t prev;
9887
9888 if (handle == NULL) /* check handle */
9889 {
9890 return 2; /* return error */
9891 }
9892 if (handle->inited != 1) /* check handle initialization */
9893 {
9894 return 3; /* return error */
9895 }
9896
9897 if (slave == MPU6050_IIC_SLAVE_0) /* slave0 */
9898 {
9899 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV0_CTRL, (uint8_t *)&prev, 1); /* read i2c slv0 ctrl */
9900 if (res != 0) /* check result */
9901 {
9902 handle->debug_print("mpu6050: read i2c slv0 ctrl failed.\n"); /* read i2c slv0 ctrl failed */
9903
9904 return 1; /* return error */
9905 }
9906 *len = prev & 0x0F; /* get the len */
9907 }
9908 else if (slave == MPU6050_IIC_SLAVE_1) /* slave1 */
9909 {
9910 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV1_CTRL, (uint8_t *)&prev, 1); /* read i2c slv1 ctrl */
9911 if (res != 0) /* check result */
9912 {
9913 handle->debug_print("mpu6050: read i2c slv1 ctrl failed.\n"); /* read i2c slv1 ctrl failed */
9914
9915 return 1; /* return error */
9916 }
9917 *len = prev & 0x0F; /* get the len */
9918 }
9919 else if (slave == MPU6050_IIC_SLAVE_2) /* slave2 */
9920 {
9921 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV2_CTRL, (uint8_t *)&prev, 1); /* read i2c slv2 ctrl */
9922 if (res != 0) /* check result */
9923 {
9924 handle->debug_print("mpu6050: read i2c slv2 ctrl failed.\n"); /* read i2c slv2 ctrl failed */
9925
9926 return 1; /* return error */
9927 }
9928 *len = prev & 0x0F; /* get the len */
9929 }
9930 else if (slave == MPU6050_IIC_SLAVE_3) /* slave2 */
9931 {
9932 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV3_CTRL, (uint8_t *)&prev, 1); /* read i2c slv3 ctrl */
9933 if (res != 0) /* check result */
9934 {
9935 handle->debug_print("mpu6050: read i2c slv3 ctrl failed.\n"); /* read i2c slv3 ctrl failed */
9936
9937 return 1; /* return error */
9938 }
9939 *len = prev & 0x0F; /* get the len */
9940 }
9941 else
9942 {
9943 handle->debug_print("mpu6050: invalid slave.\n"); /* invalid slave */
9944
9945 return 4; /* return error */
9946 }
9947
9948 return 0; /* success return 0 */
9949}
9950
9962uint8_t mpu6050_get_iic_status(mpu6050_handle_t *handle, uint8_t *status)
9963{
9964 uint8_t res;
9965
9966 if (handle == NULL) /* check handle */
9967 {
9968 return 2; /* return error */
9969 }
9970 if (handle->inited != 1) /* check handle initialization */
9971 {
9972 return 3; /* return error */
9973 }
9974
9975 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_MST_STATUS, (uint8_t *)status, 1); /* read i2c mst status */
9976 if (res != 0) /* check result */
9977 {
9978 handle->debug_print("mpu6050: read i2c mst status failed.\n"); /* read i2c mst status failed */
9979
9980 return 1; /* return error */
9981 }
9982
9983 return 0; /* success return 0 */
9984}
9985
9999{
10000 uint8_t res;
10001 uint8_t prev;
10002
10003 if (handle == NULL) /* check handle */
10004 {
10005 return 2; /* return error */
10006 }
10007 if (handle->inited != 1) /* check handle initialization */
10008 {
10009 return 3; /* return error */
10010 }
10011
10012 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_MST_DELAY_CTRL, (uint8_t *)&prev, 1); /* read i2c mst delay ctrl */
10013 if (res != 0) /* check result */
10014 {
10015 handle->debug_print("mpu6050: read i2c mst delay ctrl failed.\n"); /* read i2c mst delay ctrl failed */
10016
10017 return 1; /* return error */
10018 }
10019 prev &= ~(1 << delay); /* clear the settings */
10020 prev |= enable << delay; /* set the bool */
10021 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_MST_DELAY_CTRL, (uint8_t *)&prev, 1); /* write i2c mst delay ctrl */
10022 if (res != 0) /* check result */
10023 {
10024 handle->debug_print("mpu6050: write i2c mst delay ctrl failed.\n"); /* write i2c mst delay ctrl failed */
10025
10026 return 1; /* return error */
10027 }
10028
10029 return 0; /* success return 0 */
10030}
10031
10045{
10046 uint8_t res;
10047 uint8_t prev;
10048
10049 if (handle == NULL) /* check handle */
10050 {
10051 return 2; /* return error */
10052 }
10053 if (handle->inited != 1) /* check handle initialization */
10054 {
10055 return 3; /* return error */
10056 }
10057
10058 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_MST_DELAY_CTRL, (uint8_t *)&prev, 1); /* read i2c mst delay ctrl */
10059 if (res != 0) /* check result */
10060 {
10061 handle->debug_print("mpu6050: read i2c mst delay ctrl failed.\n"); /* read i2c mst delay ctrl failed */
10062
10063 return 1; /* return error */
10064 }
10065 *enable = (mpu6050_bool_t)((prev >> delay) & 0x1); /* get the bool */
10066
10067 return 0; /* success return 0 */
10068}
10069
10082{
10083 uint8_t res;
10084 uint8_t prev;
10085
10086 if (handle == NULL) /* check handle */
10087 {
10088 return 2; /* return error */
10089 }
10090 if (handle->inited != 1) /* check handle initialization */
10091 {
10092 return 3; /* return error */
10093 }
10094
10095 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
10096 if (res != 0) /* check result */
10097 {
10098 handle->debug_print("mpu6050: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
10099
10100 return 1; /* return error */
10101 }
10102 prev &= ~(1 << 7); /* clear the settings */
10103 prev |= enable << 7; /* set the bool */
10104 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* write i2c slv4 ctrl */
10105 if (res != 0) /* check result */
10106 {
10107 handle->debug_print("mpu6050: write i2c slv4 ctrl failed.\n"); /* write i2c slv4 ctrl failed */
10108
10109 return 1; /* return error */
10110 }
10111
10112 return 0; /* success return 0 */
10113}
10114
10127{
10128 uint8_t res;
10129 uint8_t prev;
10130
10131 if (handle == NULL) /* check handle */
10132 {
10133 return 2; /* return error */
10134 }
10135 if (handle->inited != 1) /* check handle initialization */
10136 {
10137 return 3; /* return error */
10138 }
10139
10140 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
10141 if (res != 0) /* check result */
10142 {
10143 handle->debug_print("mpu6050: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
10144
10145 return 1; /* return error */
10146 }
10147 *enable = (mpu6050_bool_t)((prev >> 7) & 0x1); /* get the bool */
10148
10149 return 0; /* success return 0 */
10150}
10151
10164{
10165 uint8_t res;
10166 uint8_t prev;
10167
10168 if (handle == NULL) /* check handle */
10169 {
10170 return 2; /* return error */
10171 }
10172 if (handle->inited != 1) /* check handle initialization */
10173 {
10174 return 3; /* return error */
10175 }
10176
10177 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
10178 if (res != 0) /* check result */
10179 {
10180 handle->debug_print("mpu6050: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
10181
10182 return 1; /* return error */
10183 }
10184 prev &= ~(1 << 6); /* clear the settings */
10185 prev |= enable << 6; /* set the bool */
10186 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* write i2c slv4 ctrl */
10187 if (res != 0) /* check result */
10188 {
10189 handle->debug_print("mpu6050: write i2c slv4 ctrl failed.\n"); /* write i2c slv4 ctrl failed */
10190
10191 return 1; /* return error */
10192 }
10193
10194 return 0; /* success return 0 */
10195}
10196
10209{
10210 uint8_t res;
10211 uint8_t prev;
10212
10213 if (handle == NULL) /* check handle */
10214 {
10215 return 2; /* return error */
10216 }
10217 if (handle->inited != 1) /* check handle initialization */
10218 {
10219 return 3; /* return error */
10220 }
10221
10222 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
10223 if (res != 0) /* check result */
10224 {
10225 handle->debug_print("mpu6050: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
10226
10227 return 1; /* return error */
10228 }
10229 *enable = (mpu6050_bool_t)((prev >> 6) & 0x1); /* get the bool */
10230
10231 return 0; /* success return 0 */
10232}
10233
10246{
10247 uint8_t res;
10248 uint8_t prev;
10249
10250 if (handle == NULL) /* check handle */
10251 {
10252 return 2; /* return error */
10253 }
10254 if (handle->inited != 1) /* check handle initialization */
10255 {
10256 return 3; /* return error */
10257 }
10258
10259 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
10260 if (res != 0) /* check result */
10261 {
10262 handle->debug_print("mpu6050: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
10263
10264 return 1; /* return error */
10265 }
10266 prev &= ~(1 << 5); /* clear the settings */
10267 prev |= mode << 5; /* set the mode */
10268 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* write i2c slv4 ctrl */
10269 if (res != 0) /* check result */
10270 {
10271 handle->debug_print("mpu6050: write i2c slv4 ctrl failed.\n"); /* write i2c slv4 ctrl failed */
10272
10273 return 1; /* return error */
10274 }
10275
10276 return 0; /* success return 0 */
10277}
10278
10291{
10292 uint8_t res;
10293 uint8_t prev;
10294
10295 if (handle == NULL) /* check handle */
10296 {
10297 return 2; /* return error */
10298 }
10299 if (handle->inited != 1) /* check handle initialization */
10300 {
10301 return 3; /* return error */
10302 }
10303
10304 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
10305 if (res != 0) /* check result */
10306 {
10307 handle->debug_print("mpu6050: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
10308
10309 return 1; /* return error */
10310 }
10311 *mode = (mpu6050_iic4_transaction_mode_t)((prev >> 5) & 0x1); /* get the mode */
10312
10313 return 0; /* success return 0 */
10314}
10315
10328uint8_t mpu6050_set_iic_delay(mpu6050_handle_t *handle, uint8_t delay)
10329{
10330 uint8_t res;
10331 uint8_t prev;
10332
10333 if (handle == NULL) /* check handle */
10334 {
10335 return 2; /* return error */
10336 }
10337 if (handle->inited != 1) /* check handle initialization */
10338 {
10339 return 3; /* return error */
10340 }
10341 if (delay > 0x1F) /* check the delay */
10342 {
10343 handle->debug_print("mpu6050: delay > 0x1F.\n"); /* delay > 0x1F */
10344
10345 return 4; /* return error */
10346 }
10347
10348 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
10349 if (res != 0) /* check result */
10350 {
10351 handle->debug_print("mpu6050: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
10352
10353 return 1; /* return error */
10354 }
10355 prev &= ~0x1F; /* clear the settings */
10356 prev |= delay; /* set the delay */
10357 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* write i2c slv4 ctrl */
10358 if (res != 0) /* check result */
10359 {
10360 handle->debug_print("mpu6050: write i2c slv4 ctrl failed.\n"); /* write i2c slv4 ctrl failed */
10361
10362 return 1; /* return error */
10363 }
10364
10365 return 0; /* success return 0 */
10366}
10367
10379uint8_t mpu6050_get_iic_delay(mpu6050_handle_t *handle, uint8_t *delay)
10380{
10381 uint8_t res;
10382 uint8_t prev;
10383
10384 if (handle == NULL) /* check handle */
10385 {
10386 return 2; /* return error */
10387 }
10388 if (handle->inited != 1) /* check handle initialization */
10389 {
10390 return 3; /* return error */
10391 }
10392
10393 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV4_CTRL, (uint8_t *)&prev, 1); /* read i2c slv4 ctrl */
10394 if (res != 0) /* check result */
10395 {
10396 handle->debug_print("mpu6050: read i2c slv4 ctrl failed.\n"); /* read i2c slv4 ctrl failed */
10397
10398 return 1; /* return error */
10399 }
10400 *delay = prev & 0x1F; /* get the delay */
10401
10402 return 0; /* success return 0 */
10403}
10404
10416uint8_t mpu6050_set_iic4_data_out(mpu6050_handle_t *handle, uint8_t data)
10417{
10418 uint8_t res;
10419
10420 if (handle == NULL) /* check handle */
10421 {
10422 return 2; /* return error */
10423 }
10424 if (handle->inited != 1) /* check handle initialization */
10425 {
10426 return 3; /* return error */
10427 }
10428
10429 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV4_DO, (uint8_t *)&data, 1); /* write i2c slv4 do */
10430 if (res != 0) /* check result */
10431 {
10432 handle->debug_print("mpu6050: write i2c slv4 do failed.\n"); /* write i2c slv4 do fail */
10433
10434 return 1; /* return error */
10435 }
10436
10437 return 0; /* success return 0 */
10438}
10439
10451uint8_t mpu6050_get_iic4_data_out(mpu6050_handle_t *handle, uint8_t *data)
10452{
10453 uint8_t res;
10454
10455 if (handle == NULL) /* check handle */
10456 {
10457 return 2; /* return error */
10458 }
10459 if (handle->inited != 1) /* check handle initialization */
10460 {
10461 return 3; /* return error */
10462 }
10463
10464 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV4_DO, (uint8_t *)data, 1); /* read i2c slv4 do */
10465 if (res != 0) /* check result */
10466 {
10467 handle->debug_print("mpu6050: read i2c slv4 do failed.\n"); /* read i2c slv4 do failed */
10468
10469 return 1; /* return error */
10470 }
10471
10472 return 0; /* success return 0 */
10473}
10474
10486uint8_t mpu6050_set_iic4_data_in(mpu6050_handle_t *handle, uint8_t data)
10487{
10488 uint8_t res;
10489
10490 if (handle == NULL) /* check handle */
10491 {
10492 return 2; /* return error */
10493 }
10494 if (handle->inited != 1) /* check handle initialization */
10495 {
10496 return 3; /* return error */
10497 }
10498
10499 res = a_mpu6050_iic_write(handle, MPU6050_REG_I2C_SLV4_DI, (uint8_t *)&data, 1); /* write i2c slv4 di */
10500 if (res != 0) /* check result */
10501 {
10502 handle->debug_print("mpu6050: write i2c slv4 di failed.\n"); /* write i2c slv4 di failed */
10503
10504 return 1; /* return error */
10505 }
10506
10507 return 0; /* success return 0 */
10508}
10509
10521uint8_t mpu6050_get_iic4_data_in(mpu6050_handle_t *handle, uint8_t *data)
10522{
10523 uint8_t res;
10524
10525 if (handle == NULL) /* check handle */
10526 {
10527 return 2; /* return error */
10528 }
10529 if (handle->inited != 1) /* check handle initialization */
10530 {
10531 return 3; /* return error */
10532 }
10533
10534 res = a_mpu6050_iic_read(handle, MPU6050_REG_I2C_SLV4_DI, (uint8_t *)data, 1); /* read i2c slv4 di */
10535 if (res != 0) /* check result */
10536 {
10537 handle->debug_print("mpu6050: read i2c slv4 di failed.\n"); /* read i2c slv4 di failed */
10538
10539 return 1; /* return error */
10540 }
10541
10542 return 0; /* success return 0 */
10543}
10544
10558uint8_t mpu6050_read_extern_sensor_data(mpu6050_handle_t *handle, uint8_t *data, uint8_t len)
10559{
10560 uint8_t res;
10561
10562 if (handle == NULL) /* check handle */
10563 {
10564 return 2; /* return error */
10565 }
10566 if (handle->inited != 1) /* check handle initialization */
10567 {
10568 return 3; /* return error */
10569 }
10570 if (len > 24) /* check handle initialization */
10571 {
10572 handle->debug_print("mpu6050: len > 24.\n"); /* len > 24 */
10573
10574 return 4; /* return error */
10575 }
10576
10577 res = a_mpu6050_iic_read(handle, MPU6050_REG_EXT_SENS_DATA_00, (uint8_t *)data, len); /* read ext sens data 00 */
10578 if (res != 0) /* check result */
10579 {
10580 handle->debug_print("mpu6050: read ext sens data 00 failed.\n"); /* read ext sens data 00 failed */
10581
10582 return 1; /* return error */
10583 }
10584
10585 return 0; /* success return 0 */
10586}
10587
10601uint8_t mpu6050_set_reg(mpu6050_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
10602{
10603 if (handle == NULL) /* check handle */
10604 {
10605 return 2; /* return error */
10606 }
10607 if (handle->inited != 1) /* check handle initialization */
10608 {
10609 return 3; /* return error */
10610 }
10611
10612 return a_mpu6050_iic_write(handle, reg, buf, len); /* write data */
10613}
10614
10628uint8_t mpu6050_get_reg(mpu6050_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
10629{
10630 if (handle == NULL) /* check handle */
10631 {
10632 return 2; /* return error */
10633 }
10634 if (handle->inited != 1) /* check handle initialization */
10635 {
10636 return 3; /* return error */
10637 }
10638
10639 return a_mpu6050_iic_read(handle, reg, buf, len); /* read data */
10640}
10641
10651{
10652 if (info == NULL) /* check handle */
10653 {
10654 return 2; /* return error */
10655 }
10656
10657 memset(info, 0, sizeof(mpu6050_info_t)); /* initialize mpu6050 info structure */
10658 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
10659 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
10660 strncpy(info->interface, "IIC", 8); /* copy interface name */
10661 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
10662 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
10663 info->max_current_ma = MAX_CURRENT; /* set maximum current */
10664 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
10665 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
10666 info->driver_version = DRIVER_VERSION; /* set driver version */
10667
10668 return 0; /* success return 0 */
10669}
#define MPU6050_DMP_D_0_22
#define MPU6050_REG_I2C_SLV2_REG
#define MPU6050_REG_I2C_SLV2_DO
#define MPU6050_DMP_D_PEDSTD_TIMECTR
#define MPU6050_DMP_FCFG_7
#define MPU6050_REG_I2C_SLV1_CTRL
#define MPU6050_REG_EXT_SENS_DATA_00
#define MPU6050_REG_USER_CTRL
#define MPU6050_REG_WHO_AM_I
#define MPU6050_DMP_INT_SRC_TAP
#define MPU6050_REG_SELF_TEST_X
chip register definition
#define MPU6050_REG_R_W
#define MPU6050_DMP_D_EXT_GYRO_BIAS_X
#define MPU6050_DMP_D_1_88
#define MPU6050_DMP_QUAT_MAG_SQ_MIN
#define MPU6050_DMP_TAP_THZ
#define MPU6050_REG_ACCEL_XOUT_H
#define MPU6050_DMP_CFG_LP_QUAT
#define MAX_CURRENT
#define MPU6050_REG_CONFIG
#define MPU6050_REG_FIFO_EN
#define MPU6050_DMP_CFG_ORIENT_INT
#define MPU6050_DMP_FCFG_2
#define MPU6050_REG_I2C_SLV0_DO
#define MPU6050_DMP_CFG_MOTION_BIAS
#define MPU6050_DMP_TAP_TIME_MULTI
#define MPU6050_REG_ACCEL_CONFIG
#define MPU6050_REG_I2C_SLV0_ADDR
#define MPU6050_DMP_TAP_THY
#define MIN(a, b)
inner function definition
#define MPU6050_REG_SELF_TEST_Z
#define MPU6050_DMP_CFG_15
#define MPU6050_REG_I2C_SLV1_ADDR
#define MPU6050_REG_MOTION_DURATION
#define MPU6050_REG_INT_ENABLE
#define MPU6050_DMP_SHAKE_REJECT_TIMEOUT
#define MPU6050_DMP_CFG_8
#define MPU6050_DMP_SHAKE_REJECT_TIME
#define MPU6050_DMP_D_EXT_GYRO_BIAS_Y
#define MPU6050_DMP_D_1_36
#define MPU6050_REG_I2C_SLV0_REG
#define MPU6050_DMP_D_1_92
#define MPU6050_DMP_FCFG_1
#define MPU6050_REG_BANK_SEL
#define MPU6050_REG_PROGRAM_START
#define MPU6050_DMP_D_PEDSTD_STEPCTR
#define MPU6050_REG_SELF_TEST_A
#define SUPPLY_VOLTAGE_MAX
#define MPU6050_REG_I2C_SLV0_CTRL
#define MPU6050_REG_I2C_SLV3_REG
#define MPU6050_REG_I2C_SLV1_REG
#define MPU6050_REG_I2C_SLV4_DI
#define MPU6050_DMP_TAPW_MIN
#define MPU6050_DMP_FEATURE_SEND_ANY_GYRO
#define MPU6050_DMP_TAP_THX
#define MPU6050_REG_INT_PIN_CFG
#define MPU6050_REG_I2C_MST_STATUS
#define MPU6050_REG_SELF_TEST_Y
#define MPU6050_DMP_CFG_6
#define MPU6050_DMP_FCFG_3
#define MPU6050_REG_I2C_SLV3_ADDR
#define TEMPERATURE_MAX
#define MPU6050_REG_FIFO_COUNTH
#define MPU6050_REG_PWR_MGMT_2
#define MPU6050_DMP_D_0_104
#define MPU6050_DMP_D_1_72
#define MPU6050_DMP_D_1_218
#define MPU6050_REG_I2C_SLV2_ADDR
#define MPU6050_REG_I2C_SLV4_ADDR
#define MPU6050_DMP_CFG_20
#define MPU6050_REG_GYRO_CONFIG
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define MPU6050_DMP_CFG_GYRO_RAW_DATA
#define MPU6050_DMP_D_1_90
#define MPU6050_DMP_D_1_44
#define MPU6050_REG_I2C_SLV3_CTRL
#define MPU6050_DMP_SAMPLE_RATE
mpu6050 dmp code definition
#define MPU6050_REG_I2C_MST_CTRL
#define MPU6050_DMP_D_1_40
#define MPU6050_REG_SMPRT_DIV
#define MPU6050_DMP_CFG_27
#define MPU6050_DMP_SHAKE_REJECT_THRESH
#define MPU6050_DMP_INT_SRC_ORIENT
#define MPU6050_DMP_TAP_THRESH
#define MPU6050_REG_I2C_SLV3_DO
#define MPU6050_REG_MOTION_THRESHOLD
#define MPU6050_REG_I2C_MST_DELAY_CTRL
#define MPU6050_REG_I2C_SLV4_CTRL
#define MPU6050_DMP_D_EXT_GYRO_BIAS_Z
#define CHIP_NAME
chip information definition
#define MPU6050_REG_TEMP_OUT_H
#define DRIVER_VERSION
#define MPU6050_DMP_CFG_FIFO_ON_EVENT
#define MPU6050_DMP_TAP_MIN_TAP_COUNT
#define MPU6050_REG_I2C_SLV4_REG
#define MPU6050_DMP_TAP_TIME
#define MPU6050_REG_PWR_MGMT_1
#define MPU6050_REG_I2C_SLV4_DO
#define MPU6050_REG_SIGNAL_PATH_RESET
#define MPU6050_DMP_D_1_79
#define MPU6050_REG_MEM
#define MPU6050_DMP_D_ACCEL_BIAS
#define MPU6050_DMP_QUAT_MAG_SQ_MAX
#define MPU6050_REG_INT_STATUS
#define MPU6050_REG_I2C_SLV1_DO
#define MPU6050_DMP_GYRO_SF
#define MPU6050_REG_I2C_SLV2_CTRL
driver mpu6050 header file
driver mpu6050 code header file
uint8_t mpu6050_get_interrupt_latch(mpu6050_handle_t *handle, mpu6050_bool_t *enable)
get the interrupt latch status
mpu6050_iic_mode_t
mpu6050 iic mode enumeration definition
uint8_t mpu6050_get_motion_duration(mpu6050_handle_t *handle, uint8_t *duration)
get the motion duration
uint8_t mpu6050_get_iic4_transaction_mode(mpu6050_handle_t *handle, mpu6050_iic4_transaction_mode_t *mode)
get the iic4 transaction mode
uint8_t mpu6050_get_motion_threshold(mpu6050_handle_t *handle, uint8_t *threshold)
get the motion_threshold
uint8_t mpu6050_get_temperature_sensor(mpu6050_handle_t *handle, mpu6050_bool_t *enable)
get the temperature sensor status
uint8_t mpu6050_get_iic_byte_swap(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, mpu6050_bool_t *enable)
get the iic byte swap status
uint8_t mpu6050_get_iic_transferred_len(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, uint8_t *len)
get the iic transferred length
uint8_t mpu6050_set_gyroscope_z_test(mpu6050_handle_t *handle, uint8_t data)
set the gyroscope z test
uint8_t mpu6050_get_accelerometer_test(mpu6050_handle_t *handle, mpu6050_axis_t axis, mpu6050_bool_t *enable)
get the accelerometer test
mpu6050_pin_type_t
mpu6050 pin type enumeration definition
uint8_t mpu6050_get_iic_read_mode(mpu6050_handle_t *handle, mpu6050_iic_read_mode_t *mode)
get the iic read mode
uint8_t mpu6050_get_accelerometer_x_test(mpu6050_handle_t *handle, uint8_t *data)
get the accelerometer x test
mpu6050_iic_read_mode_t
mpu6050 iic read mode enumeration definition
mpu6050_wake_up_frequency_t
mpu6050 wake up frequency enumeration definition
uint8_t mpu6050_get_iic4_data_out(mpu6050_handle_t *handle, uint8_t *data)
get the iic4 data out
struct mpu6050_info_s mpu6050_info_t
mpu6050 information structure definition
mpu6050_iic_clock_t
mpu6050 iic clock enumeration definition
uint8_t mpu6050_get_interrupt_status(mpu6050_handle_t *handle, uint8_t *status)
get the interrupt status
uint8_t mpu6050_set_iic4_enable(mpu6050_handle_t *handle, mpu6050_bool_t enable)
enable or disable the iic4
uint8_t mpu6050_set_iic_transaction_mode(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, mpu6050_iic_transaction_mode_t mode)
set the iic transaction mode
uint8_t mpu6050_set_iic4_data_in(mpu6050_handle_t *handle, uint8_t data)
set the iic4 data in
uint8_t mpu6050_get_cycle_wake_up(mpu6050_handle_t *handle, mpu6050_bool_t *enable)
get the cycle wake up mode status
uint8_t mpu6050_iic_master_reset(mpu6050_handle_t *handle)
reset the iic master controller
uint8_t mpu6050_set_gyroscope_y_test(mpu6050_handle_t *handle, uint8_t data)
set the gyroscope y test
uint8_t mpu6050_set_iic_wait_for_external_sensor(mpu6050_handle_t *handle, mpu6050_bool_t enable)
enable or disable iic wait for external sensor
uint8_t mpu6050_sensor_reset(mpu6050_handle_t *handle)
reset all sensors
uint8_t mpu6050_get_low_pass_filter(mpu6050_handle_t *handle, mpu6050_low_pass_filter_t *filter)
get the low pass filter
uint8_t mpu6050_set_wake_up_frequency(mpu6050_handle_t *handle, mpu6050_wake_up_frequency_t frequency)
set the wake up frequency
mpu6050_gyroscope_range_t
mpu6050 gyroscope range enumeration definition
uint8_t mpu6050_set_accelerometer_x_test(mpu6050_handle_t *handle, uint8_t data)
set the accelerometer x test
uint8_t mpu6050_fifo_reset(mpu6050_handle_t *handle)
reset the fifo
uint8_t mpu6050_get_interrupt_pin_type(mpu6050_handle_t *handle, mpu6050_pin_type_t *type)
get the interrupt pin type
uint8_t mpu6050_get_iic_address(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, uint8_t *addr_7bit)
get the iic address
uint8_t mpu6050_get_iic_group_order(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, mpu6050_iic_group_order_t *order)
get the iic group order
uint8_t mpu6050_init(mpu6050_handle_t *handle)
initialize the chip
uint8_t mpu6050_set_iic_multi_master(mpu6050_handle_t *handle, mpu6050_bool_t enable)
enable or disable iic multi master
uint8_t mpu6050_set_iic_group_order(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, mpu6050_iic_group_order_t order)
set the iic group order
uint8_t mpu6050_get_iic_clock(mpu6050_handle_t *handle, mpu6050_iic_clock_t *clk)
get the iic clock
uint8_t mpu6050_set_iic_address(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, uint8_t addr_7bit)
set the iic address
mpu6050_extern_sync_t
mpu6050 extern sync enumeration definition
uint8_t mpu6050_read_temperature(mpu6050_handle_t *handle, int16_t(*raw), float *degrees)
read the temperature
uint8_t mpu6050_set_accelerometer_range(mpu6050_handle_t *handle, mpu6050_accelerometer_range_t range)
set the accelerometer range
uint8_t mpu6050_device_reset(mpu6050_handle_t *handle)
reset the chip
mpu6050_address_t
mpu6050 address enumeration definition
uint8_t mpu6050_set_standby_mode(mpu6050_handle_t *handle, mpu6050_source_t source, mpu6050_bool_t enable)
set source into standby mode
mpu6050_iic_delay_t
mpu6050 iic delay enumeration definition
uint8_t mpu6050_get_iic_fifo_enable(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, mpu6050_bool_t *enable)
get the iic fifo status
uint8_t mpu6050_get_interrupt_read_clear(mpu6050_handle_t *handle, mpu6050_bool_t *enable)
get the interrupt reading clear status
uint8_t mpu6050_set_iic_register(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, uint8_t reg)
set the iic register
uint8_t mpu6050_motion_threshold_convert_to_register(mpu6050_handle_t *handle, float mg, uint8_t *reg)
convert the motion threshold to the register raw data
uint8_t mpu6050_get_iic_master_reset(mpu6050_handle_t *handle, mpu6050_bool_t *enable)
get the iic master reset status
uint8_t mpu6050_get_interrupt(mpu6050_handle_t *handle, mpu6050_interrupt_t type, mpu6050_bool_t *enable)
get the interrupt status
uint8_t mpu6050_self_test(mpu6050_handle_t *handle, int32_t gyro_offset_raw[3], int32_t accel_offset_raw[3])
run the self test
uint8_t mpu6050_set_gyroscope_x_test(mpu6050_handle_t *handle, uint8_t data)
set the gyroscope x test
uint8_t mpu6050_get_accelerometer_z_test(mpu6050_handle_t *handle, uint8_t *data)
get the accelerometer z test
uint8_t mpu6050_set_iic_delay(mpu6050_handle_t *handle, uint8_t delay)
set the iic delay
mpu6050_source_t
mpu6050 source enumeration definition
uint8_t mpu6050_get_sleep(mpu6050_handle_t *handle, mpu6050_bool_t *enable)
get the sleep status
uint8_t mpu6050_set_iic_transferred_len(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, uint8_t len)
set the iic transferred length
uint8_t mpu6050_set_motion_threshold(mpu6050_handle_t *handle, uint8_t threshold)
set the motion_threshold
uint8_t mpu6050_get_sample_rate_divider(mpu6050_handle_t *handle, uint8_t *d)
get the sample rate divider
uint8_t mpu6050_set_iic4_interrupt(mpu6050_handle_t *handle, mpu6050_bool_t enable)
enable or disable the iic4 interrupt
uint8_t mpu6050_set_iic_clock(mpu6050_handle_t *handle, mpu6050_iic_clock_t clk)
set the iic clock
uint8_t mpu6050_set_iic4_data_out(mpu6050_handle_t *handle, uint8_t data)
set the iic4 data out
uint8_t mpu6050_fifo_get(mpu6050_handle_t *handle, uint8_t *buf, uint16_t len)
fifo read bytes
uint8_t mpu6050_get_accelerometer_y_test(mpu6050_handle_t *handle, uint8_t *data)
get the accelerometer y test
uint8_t mpu6050_set_sample_rate_divider(mpu6050_handle_t *handle, uint8_t d)
set the sample rate divider
uint8_t mpu6050_set_motion_duration(mpu6050_handle_t *handle, uint8_t duration)
set the motion duration
uint8_t mpu6050_set_gyroscope_range(mpu6050_handle_t *handle, mpu6050_gyroscope_range_t range)
set the gyroscope range
uint8_t mpu6050_set_addr_pin(mpu6050_handle_t *handle, mpu6050_address_t addr_pin)
set the chip address pin
uint8_t mpu6050_get_wake_up_frequency(mpu6050_handle_t *handle, mpu6050_wake_up_frequency_t *frequency)
get the wake up frequency
uint8_t mpu6050_get_interrupt_level(mpu6050_handle_t *handle, mpu6050_pin_level_t *level)
get the interrupt level
mpu6050_iic_group_order_t
mpu6050 iic group order enumeration definition
uint8_t mpu6050_set_interrupt_read_clear(mpu6050_handle_t *handle, mpu6050_bool_t enable)
enable or disable the interrupt reading clear
uint8_t mpu6050_read(mpu6050_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
uint8_t mpu6050_set_fifo_enable(mpu6050_handle_t *handle, mpu6050_fifo_t fifo, mpu6050_bool_t enable)
enable or disable the fifo function
mpu6050_fifo_t
mpu6050 fifo enumeration definition
mpu6050_clock_source_t
mpu6050 clock source enumeration definition
uint8_t mpu6050_set_iic_byte_swap(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, mpu6050_bool_t enable)
enable or disable the iic byte swap
uint8_t mpu6050_get_gyroscope_z_test(mpu6050_handle_t *handle, uint8_t *data)
get the gyroscope z test
uint8_t mpu6050_get_iic_data_out(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, uint8_t *data)
get the iic data out
uint8_t mpu6050_get_fifo_enable(mpu6050_handle_t *handle, mpu6050_fifo_t fifo, mpu6050_bool_t *enable)
get the fifo function status
uint8_t mpu6050_get_extern_sync(mpu6050_handle_t *handle, mpu6050_extern_sync_t *sync)
get the extern sync type
uint8_t mpu6050_get_iic_master(mpu6050_handle_t *handle, mpu6050_bool_t *enable)
get the iic master status
uint8_t mpu6050_set_accelerometer_y_test(mpu6050_handle_t *handle, uint8_t data)
set the accelerometer y test
uint8_t mpu6050_set_interrupt(mpu6050_handle_t *handle, mpu6050_interrupt_t type, mpu6050_bool_t enable)
enable or disable the interrupt
uint8_t mpu6050_set_iic_bypass(mpu6050_handle_t *handle, mpu6050_bool_t enable)
enable or disable the iic bypass
uint8_t mpu6050_info(mpu6050_info_t *info)
get the chip's information
uint8_t mpu6050_set_gyroscope_test(mpu6050_handle_t *handle, mpu6050_axis_t axis, mpu6050_bool_t enable)
set the gyroscope test
uint8_t mpu6050_get_fsync_interrupt_level(mpu6050_handle_t *handle, mpu6050_pin_level_t *level)
get the fsync interrupt level
mpu6050_pin_level_t
mpu6050 pin level enumeration definition
uint8_t mpu6050_get_iic4_enable(mpu6050_handle_t *handle, mpu6050_bool_t *enable)
get the iic4 status
uint8_t mpu6050_set_cycle_wake_up(mpu6050_handle_t *handle, mpu6050_bool_t enable)
enable or disable the cycle wake up mode
uint8_t mpu6050_get_device_reset(mpu6050_handle_t *handle, mpu6050_bool_t *enable)
get the device reset status
uint8_t mpu6050_get_fifo_reset(mpu6050_handle_t *handle, mpu6050_bool_t *enable)
get the fifo reset status
uint8_t mpu6050_set_interrupt_pin_type(mpu6050_handle_t *handle, mpu6050_pin_type_t type)
set the interrupt pin type
uint8_t mpu6050_set_signal_path_reset(mpu6050_handle_t *handle, mpu6050_signal_path_reset_t path)
set the signal path reset
uint8_t mpu6050_get_iic_enable(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, mpu6050_bool_t *enable)
get the iic status
uint8_t mpu6050_get_iic_transaction_mode(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, mpu6050_iic_transaction_mode_t *mode)
get the iic transaction mode
uint8_t mpu6050_irq_handler(mpu6050_handle_t *handle)
irq handler
uint8_t mpu6050_get_standby_mode(mpu6050_handle_t *handle, mpu6050_source_t source, mpu6050_bool_t *enable)
get the source mode
uint8_t mpu6050_set_iic_master(mpu6050_handle_t *handle, mpu6050_bool_t enable)
enable or disable the iic master mode
uint8_t mpu6050_force_fifo_reset(mpu6050_handle_t *handle)
force reset the fifo
uint8_t mpu6050_get_gyroscope_x_test(mpu6050_handle_t *handle, uint8_t *data)
get the gyroscope x test
uint8_t mpu6050_get_gyroscope_y_test(mpu6050_handle_t *handle, uint8_t *data)
get the gyroscope y test
uint8_t mpu6050_set_temperature_sensor(mpu6050_handle_t *handle, mpu6050_bool_t enable)
enable or disable the temperature sensor
uint8_t mpu6050_set_interrupt_latch(mpu6050_handle_t *handle, mpu6050_bool_t enable)
enable or disable the interrupt latch
mpu6050_interrupt_t
mpu6050 interrupt enumeration definition
uint8_t mpu6050_set_iic4_transaction_mode(mpu6050_handle_t *handle, mpu6050_iic4_transaction_mode_t mode)
set the iic4 transaction mode
mpu6050_accelerometer_range_t
mpu6050 accelerometer range enumeration definition
mpu6050_signal_path_reset_t
mpu6050 signal path reset enumeration definition
uint8_t mpu6050_get_gyroscope_test(mpu6050_handle_t *handle, mpu6050_axis_t axis, mpu6050_bool_t *enable)
get the gyroscope test
mpu6050_iic_slave_t
mpu6050 iic slave enumeration definition
mpu6050_iic_transaction_mode_t
mpu6050 iic transaction mode enumeration definition
uint8_t mpu6050_get_fsync_interrupt(mpu6050_handle_t *handle, mpu6050_bool_t *enable)
get the fsync interrupt status
uint8_t mpu6050_set_iic_enable(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, mpu6050_bool_t enable)
enable or disable the iic
uint8_t mpu6050_set_accelerometer_test(mpu6050_handle_t *handle, mpu6050_axis_t axis, mpu6050_bool_t enable)
set the accelerometer test
uint8_t mpu6050_set_extern_sync(mpu6050_handle_t *handle, mpu6050_extern_sync_t sync)
set the extern sync type
uint8_t mpu6050_get_iic_bypass(mpu6050_handle_t *handle, mpu6050_bool_t *enable)
get the iic bypass status
uint8_t mpu6050_set_sleep(mpu6050_handle_t *handle, mpu6050_bool_t enable)
enable or disable the sleep mode
struct mpu6050_handle_s mpu6050_handle_t
mpu6050 handle structure definition
uint8_t mpu6050_motion_threshold_convert_to_data(mpu6050_handle_t *handle, uint8_t reg, float *mg)
convert the register raw data to the motion threshold
uint8_t mpu6050_get_clock_source(mpu6050_handle_t *handle, mpu6050_clock_source_t *clock_source)
get the chip clock source
mpu6050_bool_t
mpu6050 bool enumeration definition
uint8_t mpu6050_set_fifo(mpu6050_handle_t *handle, mpu6050_bool_t enable)
enable or disable fifo
uint8_t mpu6050_set_interrupt_level(mpu6050_handle_t *handle, mpu6050_pin_level_t level)
set the interrupt level
uint8_t mpu6050_read_extern_sensor_data(mpu6050_handle_t *handle, uint8_t *data, uint8_t len)
read the extern sensor data
uint8_t mpu6050_get_addr_pin(mpu6050_handle_t *handle, mpu6050_address_t *addr_pin)
get the chip address pin
uint8_t mpu6050_motion_duration_convert_to_register(mpu6050_handle_t *handle, uint8_t ms, uint8_t *reg)
convert the motion duration to the register raw data
uint8_t mpu6050_get_iic_status(mpu6050_handle_t *handle, uint8_t *status)
get the iic status
uint8_t mpu6050_get_accelerometer_range(mpu6050_handle_t *handle, mpu6050_accelerometer_range_t *range)
get the accelerometer range
uint8_t mpu6050_set_iic_data_out(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, uint8_t data)
set the iic data out
uint8_t mpu6050_get_iic_wait_for_external_sensor(mpu6050_handle_t *handle, mpu6050_bool_t *enable)
get the iic wait for external sensor status
uint8_t mpu6050_set_iic_fifo_enable(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, mpu6050_bool_t enable)
enable or disable the iic fifo
mpu6050_low_pass_filter_t
mpu6050 low pass filter enumeration definition
uint8_t mpu6050_get_fifo(mpu6050_handle_t *handle, mpu6050_bool_t *enable)
get the fifo status
uint8_t mpu6050_set_clock_source(mpu6050_handle_t *handle, mpu6050_clock_source_t clock_source)
set the chip clock source
uint8_t mpu6050_fifo_set(mpu6050_handle_t *handle, uint8_t *buf, uint16_t len)
fifo write bytes
uint8_t mpu6050_get_iic_register(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, uint8_t *reg)
get the iic register
uint8_t mpu6050_get_gyroscope_range(mpu6050_handle_t *handle, mpu6050_gyroscope_range_t *range)
get the gyroscope range
uint8_t mpu6050_set_iic_read_mode(mpu6050_handle_t *handle, mpu6050_iic_read_mode_t mode)
set the iic read mode
uint8_t mpu6050_get_iic4_data_in(mpu6050_handle_t *handle, uint8_t *data)
get the iic4 data in
uint8_t mpu6050_get_sensor_reset(mpu6050_handle_t *handle, mpu6050_bool_t *enable)
get the sensor reset status
uint8_t mpu6050_get_fifo_count(mpu6050_handle_t *handle, uint16_t *count)
get the fifo counter value
uint8_t mpu6050_set_fsync_interrupt(mpu6050_handle_t *handle, mpu6050_bool_t enable)
enable or disable the fsync interrupt
uint8_t mpu6050_motion_duration_convert_to_data(mpu6050_handle_t *handle, uint8_t reg, uint8_t *ms)
convert the register raw data to the motion duration
mpu6050_iic4_transaction_mode_t
mpu6050 iic4 transaction mode enumeration definition
uint8_t mpu6050_set_low_pass_filter(mpu6050_handle_t *handle, mpu6050_low_pass_filter_t filter)
set the low pass filter
uint8_t mpu6050_set_iic_mode(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, mpu6050_iic_mode_t mode)
set the iic mode
uint8_t mpu6050_deinit(mpu6050_handle_t *handle)
close the chip
uint8_t mpu6050_get_iic_delay_enable(mpu6050_handle_t *handle, mpu6050_iic_delay_t delay, mpu6050_bool_t *enable)
get the iic delay status
uint8_t mpu6050_set_iic_delay_enable(mpu6050_handle_t *handle, mpu6050_iic_delay_t delay, mpu6050_bool_t enable)
enable or disable the iic delay
uint8_t mpu6050_get_iic_mode(mpu6050_handle_t *handle, mpu6050_iic_slave_t slave, mpu6050_iic_mode_t *mode)
get the iic mode
uint8_t mpu6050_get_iic_multi_master(mpu6050_handle_t *handle, mpu6050_bool_t *enable)
get the iic multi master status
uint8_t mpu6050_get_iic_delay(mpu6050_handle_t *handle, uint8_t *delay)
get the iic delay
uint8_t mpu6050_set_fsync_interrupt_level(mpu6050_handle_t *handle, mpu6050_pin_level_t level)
set the fsync interrupt level
uint8_t mpu6050_set_force_accel_sample(mpu6050_handle_t *handle, mpu6050_bool_t enable)
enable or disable force accel sample
mpu6050_axis_t
mpu6050 axis enumeration definition
uint8_t mpu6050_set_accelerometer_z_test(mpu6050_handle_t *handle, uint8_t data)
set the accelerometer z test
uint8_t mpu6050_get_iic4_interrupt(mpu6050_handle_t *handle, mpu6050_bool_t *enable)
get the iic4 interrupt status
@ MPU6050_INTERRUPT_DMP
@ MPU6050_INTERRUPT_I2C_MAST
@ MPU6050_INTERRUPT_DATA_READY
@ MPU6050_INTERRUPT_FIFO_OVERFLOW
@ MPU6050_INTERRUPT_MOTION
@ MPU6050_IIC_SLAVE_3
@ MPU6050_IIC_SLAVE_1
@ MPU6050_IIC_SLAVE_0
@ MPU6050_IIC_SLAVE_2
@ MPU6050_IIC_SLAVE_4
@ MPU6050_BOOL_TRUE
@ MPU6050_BOOL_FALSE
@ MPU6050_AXIS_X
@ MPU6050_AXIS_Z
@ MPU6050_AXIS_Y
uint8_t mpu6050_dmp_set_tap_thresh(mpu6050_handle_t *handle, mpu6050_axis_t axis, uint16_t mg_ms)
dmp set the tap thresh
uint8_t mpu6050_dmp_set_gyro_bias(mpu6050_handle_t *handle, int32_t bias[3])
dmp set the gyro bias
uint8_t mpu6050_dmp_set_orientation(mpu6050_handle_t *handle, int8_t mat[9])
dmp set the orientation
uint8_t mpu6050_dmp_get_shake_reject_time(mpu6050_handle_t *handle, uint16_t *ms)
dmp get the shake reject time
uint8_t mpu6050_dmp_get_shake_reject_thresh(mpu6050_handle_t *handle, uint16_t *dps)
dmp get the shake reject thresh
uint8_t mpu6050_dmp_set_enable(mpu6050_handle_t *handle, mpu6050_bool_t enable)
enable or disable the dmp
uint8_t mpu6050_dmp_load_firmware(mpu6050_handle_t *handle)
load the dmp firmware
uint8_t mpu6050_dmp_set_tap_callback(mpu6050_handle_t *handle, void(*callback)(uint8_t count, uint8_t direction))
dmp set the tap callback
uint8_t mpu6050_dmp_set_orient_callback(mpu6050_handle_t *handle, void(*callback)(uint8_t orientation))
dmp set the orient callback
uint8_t mpu6050_dmp_set_shake_reject_timeout(mpu6050_handle_t *handle, uint16_t ms)
dmp set the shake reject timeout
uint8_t mpu6050_dmp_read(mpu6050_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 mpu6050_dmp_set_tap_time_multi(mpu6050_handle_t *handle, uint16_t ms)
dmp set max time between taps to register as a multi tap
uint8_t mpu6050_dmp_set_accel_bias(mpu6050_handle_t *handle, int32_t bias[3])
dmp set the accel bias
uint8_t mpu6050_dmp_get_pedometer_step_count(mpu6050_handle_t *handle, uint32_t *count)
dmp get the pedometer step count
#define MPU6050_DMP_CODE_SIZE
mpu6050 dmp code definition
uint8_t mpu6050_dmp_set_pedometer_step_count(mpu6050_handle_t *handle, uint32_t count)
dmp set the pedometer step count
uint8_t mpu6050_dmp_get_tap_axes(mpu6050_handle_t *handle, mpu6050_axis_t axis, mpu6050_bool_t *enable)
dmp get the tap axes status
uint8_t mpu6050_dmp_set_feature(mpu6050_handle_t *handle, uint16_t mask)
dmp enable or disable the dmp feature
uint8_t mpu6050_dmp_gyro_accel_raw_offset_convert(mpu6050_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 mpu6050_dmp_get_tap_thresh(mpu6050_handle_t *handle, mpu6050_axis_t axis, uint16_t *mg_ms)
dmp get the tap thresh
uint8_t mpu6050_dmp_set_6x_quaternion(mpu6050_handle_t *handle, mpu6050_bool_t enable)
dmp enable or disable generate 6 axis quaternions from dmp
uint8_t mpu6050_dmp_get_pedometer_walk_time(mpu6050_handle_t *handle, uint32_t *ms)
dmp get the pedometer walk time
uint8_t mpu6050_dmp_set_shake_reject_thresh(mpu6050_handle_t *handle, uint16_t dps)
dmp set the shake reject thresh
uint8_t mpu6050_dmp_get_tap_time(mpu6050_handle_t *handle, uint16_t *ms)
dmp get the tap time
mpu6050_dmp_interrupt_mode_t
mpu6050 dmp interrupt mode enumeration definition
uint8_t mpu6050_dmp_set_fifo_rate(mpu6050_handle_t *handle, uint16_t rate)
dmp set the fifo rate
uint8_t mpu6050_dmp_set_tap_axes(mpu6050_handle_t *handle, mpu6050_axis_t axis, mpu6050_bool_t enable)
dmp enable or disable the tap axes
uint8_t mpu6050_dmp_set_shake_reject_time(mpu6050_handle_t *handle, uint16_t ms)
dmp set the shake reject time
uint8_t mpu6050_dmp_get_fifo_rate(mpu6050_handle_t *handle, uint16_t *rate)
dmp get the fifo rate
uint8_t mpu6050_dmp_set_min_tap_count(mpu6050_handle_t *handle, uint8_t cnt)
dmp set the min tap count
uint8_t mpu6050_dmp_get_shake_reject_timeout(mpu6050_handle_t *handle, uint16_t *ms)
dmp get the shake reject timeout
uint8_t mpu6050_dmp_get_min_tap_count(mpu6050_handle_t *handle, uint8_t *cnt)
dmp get the min tap count
uint8_t mpu6050_dmp_get_tap_time_multi(mpu6050_handle_t *handle, uint16_t *ms)
dmp get max time between taps to register as a multi tap
uint8_t mpu6050_dmp_set_gyro_calibrate(mpu6050_handle_t *handle, mpu6050_bool_t enable)
dmp enable or disable gyro calibrate
uint8_t mpu6050_dmp_set_tap_time(mpu6050_handle_t *handle, uint16_t ms)
dmp set the tap time
uint8_t mpu6050_dmp_set_3x_quaternion(mpu6050_handle_t *handle, mpu6050_bool_t enable)
dmp enable or disable generate 3 axis quaternions from dmp
uint8_t mpu6050_dmp_set_interrupt_mode(mpu6050_handle_t *handle, mpu6050_dmp_interrupt_mode_t mode)
dmp set the interrupt mode
uint8_t mpu6050_dmp_set_pedometer_walk_time(mpu6050_handle_t *handle, uint32_t ms)
dmp set the pedometer walk time
@ MPU6050_DMP_FEATURE_PEDOMETER
@ MPU6050_DMP_FEATURE_TAP
@ MPU6050_DMP_FEATURE_ORIENT
@ MPU6050_DMP_FEATURE_6X_QUAT
@ MPU6050_DMP_FEATURE_GYRO_CAL
@ MPU6050_DMP_FEATURE_SEND_RAW_ACCEL
@ MPU6050_DMP_FEATURE_SEND_CAL_GYRO
@ MPU6050_DMP_FEATURE_3X_QUAT
@ MPU6050_DMP_INTERRUPT_MODE_CONTINUOUS
uint8_t mpu6050_get_reg(mpu6050_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t mpu6050_set_reg(mpu6050_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)
void(* delay_ms)(uint32_t ms)
void(* receive_callback)(uint8_t type)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(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]