31#define MOTION_DRIVER_TARGET_MSP430
45#if defined MOTION_DRIVER_TARGET_MSP430
47#define i2c_write MPU_Write_Len
48#define i2c_read MPU_Read_Len
49#define delay_ms HAL_Delay
62#define min(a,b) ((a<b)?a:b)
63#elif defined EMPL_TARGET_MSP430
65#include "msp430_i2c.h"
66#include "msp430_clock.h"
67#include "msp430_interrupt.h"
69#define i2c_write msp430_i2c_write
70#define i2c_read msp430_i2c_read
71#define delay_ms msp430_delay_ms
72#define get_ms msp430_get_clock_ms
73static inline int reg_int_cb(
struct int_param_s *int_param)
75 return msp430_reg_int_cb(int_param->
cb, int_param->
pin, int_param->
lp_exit,
83#define min(a,b) ((a<b)?a:b)
84#elif defined EMPL_TARGET_UC3L0
92#include "sensors_xplained.h"
93#include "uc3l0_clock.h"
94#define i2c_write(a, b, c, d) twi_write(a, b, d, c)
95#define i2c_read(a, b, c, d) twi_read(a, b, d, c)
97#define get_ms uc3l0_get_clock_ms
98static inline int reg_int_cb(
struct int_param_s *int_param)
100 sensor_board_irq_connect(int_param->
pin, int_param->
cb, int_param->arg);
103#define log_i MPL_LOGI
104#define log_e MPL_LOGE
107#define fabs(x) (((x)>0)?(x):-(x))
109#error Gyro driver is missing the system layer implementations.
112#if !defined MPU6050 && !defined MPU9150 && !defined MPU6500 && !defined MPU9250
113#error Which gyro are you using? Define MPUxxxx in your compiler options.
131#if defined AK8963_SECONDARY
132#error "MPU9150 and AK8963_SECONDARY cannot both be defined."
133#elif !defined AK8975_SECONDARY
134#define AK8975_SECONDARY
140#if defined AK8975_SECONDARY
141#error "MPU9250 and AK8975_SECONDARY cannot both be defined."
142#elif !defined AK8963_SECONDARY
143#define AK8963_SECONDARY
147#if defined AK8975_SECONDARY || defined AK8963_SECONDARY
148#define AK89xx_SECONDARY
187#if defined AK89xx_SECONDARY
188 unsigned char s0_addr;
189 unsigned char s0_reg;
190 unsigned char s0_ctrl;
191 unsigned char s1_addr;
192 unsigned char s1_reg;
193 unsigned char s1_ctrl;
194 unsigned char s4_ctrl;
197 unsigned char i2c_delay_ctrl;
198 unsigned char raw_compass;
200 unsigned char yg_offs_tc;
212#if defined AK89xx_SECONDARY
213 unsigned short compass_fsr;
272#ifdef AK89xx_SECONDARY
274 unsigned short compass_sample_rate;
275 unsigned char compass_addr;
276 short mag_sens_adj[3];
367#define BIT_I2C_MST_VDDIO (0x80)
368#define BIT_FIFO_EN (0x40)
369#define BIT_DMP_EN (0x80)
370#define BIT_FIFO_RST (0x04)
371#define BIT_DMP_RST (0x08)
372#define BIT_FIFO_OVERFLOW (0x10)
373#define BIT_DATA_RDY_EN (0x01)
374#define BIT_DMP_INT_EN (0x02)
375#define BIT_MOT_INT_EN (0x40)
376#define BITS_FSR (0x18)
377#define BITS_LPF (0x07)
378#define BITS_HPF (0x07)
379#define BITS_CLK (0x07)
380#define BIT_FIFO_SIZE_1024 (0x40)
381#define BIT_FIFO_SIZE_2048 (0x80)
382#define BIT_FIFO_SIZE_4096 (0xC0)
383#define BIT_RESET (0x80)
384#define BIT_SLEEP (0x40)
385#define BIT_S0_DELAY_EN (0x01)
386#define BIT_S2_DELAY_EN (0x04)
387#define BITS_SLAVE_LENGTH (0x0F)
388#define BIT_SLAVE_BYTE_SW (0x40)
389#define BIT_SLAVE_GROUP (0x10)
390#define BIT_SLAVE_EN (0x80)
391#define BIT_I2C_READ (0x80)
392#define BITS_I2C_MASTER_DLY (0x1F)
393#define BIT_AUX_IF_EN (0x20)
394#define BIT_ACTL (0x80)
395#define BIT_LATCH_EN (0x20)
396#define BIT_ANY_RD_CLR (0x10)
397#define BIT_BYPASS_EN (0x02)
398#define BITS_WOM_EN (0xC0)
399#define BIT_LPA_CYCLE (0x20)
400#define BIT_STBY_XA (0x20)
401#define BIT_STBY_YA (0x10)
402#define BIT_STBY_ZA (0x08)
403#define BIT_STBY_XG (0x04)
404#define BIT_STBY_YG (0x02)
405#define BIT_STBY_ZG (0x01)
406#define BIT_STBY_XYZA (BIT_STBY_XA | BIT_STBY_YA | BIT_STBY_ZA)
407#define BIT_STBY_XYZG (BIT_STBY_XG | BIT_STBY_YG | BIT_STBY_ZG)
409#if defined AK8975_SECONDARY
410#define SUPPORTS_AK89xx_HIGH_SENS (0x00)
411#define AK89xx_FSR (9830)
412#elif defined AK8963_SECONDARY
413#define SUPPORTS_AK89xx_HIGH_SENS (0x10)
414#define AK89xx_FSR (4915)
417#ifdef AK89xx_SECONDARY
418#define AKM_REG_WHOAMI (0x00)
420#define AKM_REG_ST1 (0x02)
421#define AKM_REG_HXL (0x03)
422#define AKM_REG_ST2 (0x09)
424#define AKM_REG_CNTL (0x0A)
425#define AKM_REG_ASTC (0x0C)
426#define AKM_REG_ASAX (0x10)
427#define AKM_REG_ASAY (0x11)
428#define AKM_REG_ASAZ (0x12)
430#define AKM_DATA_READY (0x01)
431#define AKM_DATA_OVERRUN (0x02)
432#define AKM_OVERFLOW (0x80)
433#define AKM_DATA_ERROR (0x40)
435#define AKM_BIT_SELF_TEST (0x40)
437#define AKM_POWER_DOWN (0x00 | SUPPORTS_AK89xx_HIGH_SENS)
438#define AKM_SINGLE_MEASUREMENT (0x01 | SUPPORTS_AK89xx_HIGH_SENS)
439#define AKM_FUSE_ROM_ACCESS (0x0F | SUPPORTS_AK89xx_HIGH_SENS)
440#define AKM_MODE_SELF_TEST (0x08 | SUPPORTS_AK89xx_HIGH_SENS)
442#define AKM_WHOAMI (0x48)
596 .lp_accel_odr = 0x1E,
599 .fifo_count_h = 0x72,
605 .dmp_int_status = 0x39,
615 .mem_start_addr = 0x6E,
617#ifdef AK89xx_SECONDARY
618 ,.raw_compass = 0x49,
628 .i2c_delay_ctrl = 0x67
638#if defined AK89xx_SECONDARY
639 ,.compass_fsr = AK89xx_FSR
645 .accel_sens = 32768/16,
649 .reg_accel_fsr = 0x18,
654 .max_gyro_var = 0.14f,
657 .max_accel_var = 0.14f
667#define MAX_PACKET_LENGTH (12)
669#ifdef AK89xx_SECONDARY
671#define MAX_COMPASS_SAMPLE_RATE (100)
723 log_i(
"%#5x: %#5x\r\n", ii, data);
759 unsigned char data[6], rev;
776 rev = ((data[5] & 0x01) << 2) | ((data[3] & 0x01) << 1) |
786 log_e(
"Unsupported software product rev %d.\n", rev);
792 rev = data[0] & 0x0F;
794 log_e(
"Product ID read as 0 indicates device is either "
795 "incompatible or an MPU3050.\n");
797 }
else if (rev == 4) {
798 log_i(
"Half sensitivity part found.\n");
804#define MPU6500_MEM_REV_ADDR (0x17)
810 log_e(
"Unsupported software product rev %d.\n", rev);
830#ifdef AK89xx_SECONDARY
859#ifdef AK89xx_SECONDARY
890 unsigned char tmp[2];
917 }
else if (rate <= 5) {
920 }
else if (rate <= 20) {
935 tmp[0] = INV_LPA_2_5HZ;
939 tmp[0] = INV_LPA_10HZ;
945 tmp[0] = INV_LPA_80HZ;
946 else if (rate <= 160)
947 tmp[0] = INV_LPA_160HZ;
948 else if (rate <= 320)
949 tmp[0] = INV_LPA_320HZ;
951 tmp[0] = INV_LPA_640HZ;
974 unsigned char tmp[6];
981 data[0] = (tmp[0] << 8) | tmp[1];
982 data[1] = (tmp[2] << 8) | tmp[3];
983 data[2] = (tmp[4] << 8) | tmp[5];
997 unsigned char tmp[6];
1004 data[0] = (tmp[0] << 8) | tmp[1];
1005 data[1] = (tmp[2] << 8) | tmp[3];
1006 data[2] = (tmp[4] << 8) | tmp[5];
1020 unsigned char tmp[2];
1028 raw = (tmp[0] << 8) | tmp[1];
1045 unsigned char data[6];
1052 if (!accel_bias[0] && !accel_bias[1] && !accel_bias[2])
1057 fg[0] = ((data[0] >> 4) + 8) & 0xf;
1058 fg[1] = ((data[1] >> 4) + 8) & 0xf;
1059 fg[2] = ((data[2] >> 4) + 8) & 0xf;
1061 accel_hw[0] = (short)(accel_bias[0] * 2 / (64 + fg[0]));
1062 accel_hw[1] = (short)(accel_bias[1] * 2 / (64 + fg[1]));
1063 accel_hw[2] = (short)(accel_bias[2] * 2 / (64 + fg[2]));
1068 got_accel[0] = ((short)data[0] << 8) | data[1];
1069 got_accel[1] = ((short)data[2] << 8) | data[3];
1070 got_accel[2] = ((short)data[4] << 8) | data[5];
1072 accel_hw[0] += got_accel[0];
1073 accel_hw[1] += got_accel[1];
1074 accel_hw[2] += got_accel[2];
1076 data[0] = (accel_hw[0] >> 8) & 0xff;
1077 data[1] = (accel_hw[0]) & 0xff;
1078 data[2] = (accel_hw[1] >> 8) & 0xff;
1079 data[3] = (accel_hw[1]) & 0xff;
1080 data[4] = (accel_hw[2] >> 8) & 0xff;
1081 data[5] = (accel_hw[2]) & 0xff;
1378 if (rate && (rate <= 40)) {
1390 else if (rate > 1000)
1393 data = 1000 / rate - 1;
1399#ifdef AK89xx_SECONDARY
1416#ifdef AK89xx_SECONDARY
1438#ifdef AK89xx_SECONDARY
1537 sensors &= ~INV_XYZ_COMPASS;
1595#ifdef AK89xx_SECONDARY
1596 unsigned char user_ctrl;
1629#ifdef AK89xx_SECONDARY
1640 data = AKM_SINGLE_MEASUREMENT;
1643 data = AKM_POWER_DOWN;
1644 user_ctrl &= ~BIT_AUX_IF_EN;
1649 user_ctrl &= ~BIT_DMP_EN;
1671 unsigned char tmp[2];
1676 status[0] = (tmp[0] << 8) | tmp[1];
1699 unsigned char *sensors,
unsigned char *more)
1703 unsigned char packet_size = 0;
1704 unsigned short fifo_count, index = 0;
1726 fifo_count = (data[0] << 8) | data[1];
1727 if (fifo_count < packet_size)
1739 get_ms((
unsigned long*)timestamp);
1743 more[0] = fifo_count / packet_size - 1;
1747 accel[0] = (data[index+0] << 8) | data[index+1];
1748 accel[1] = (data[index+2] << 8) | data[index+3];
1749 accel[2] = (data[index+4] << 8) | data[index+5];
1754 gyro[0] = (data[index+0] << 8) | data[index+1];
1759 gyro[1] = (data[index+0] << 8) | data[index+1];
1764 gyro[2] = (data[index+0] << 8) | data[index+1];
1780 unsigned char *more)
1782 unsigned char tmp[2];
1783 unsigned short fifo_count;
1791 fifo_count = (tmp[0] << 8) | tmp[1];
1792 if (fifo_count < length) {
1808 more[0] = fifo_count / length - 1;
1827 tmp &= ~BIT_AUX_IF_EN;
1845 tmp &= ~BIT_AUX_IF_EN;
1902 unsigned char tmp[4], shift_code[3], ii;
1907 shift_code[0] = ((tmp[0] & 0xE0) >> 3) | ((tmp[3] & 0x30) >> 4);
1908 shift_code[1] = ((tmp[1] & 0xE0) >> 3) | ((tmp[3] & 0x0C) >> 2);
1909 shift_code[2] = ((tmp[2] & 0xE0) >> 3) | (tmp[3] & 0x03);
1910 for (ii = 0; ii < 3; ii++) {
1911 if (!shift_code[ii]) {
1918 st_shift[ii] = 0.34f;
1919 while (--shift_code[ii])
1920 st_shift[ii] *= 1.034f;
1928 float st_shift[3], st_shift_cust, st_shift_var;
1931 for(jj = 0; jj < 3; jj++) {
1932 st_shift_cust = labs(bias_regular[jj] - bias_st[jj]) / 65536.f;
1934 st_shift_var = st_shift_cust / st_shift[jj] - 1.f;
1937 }
else if ((st_shift_cust <
test.
min_g) ||
1948 unsigned char tmp[3];
1949 float st_shift, st_shift_cust, st_shift_var;
1958 for (jj = 0; jj < 3; jj++) {
1959 st_shift_cust = labs(bias_regular[jj] - bias_st[jj]) / 65536.f;
1964 st_shift_var = st_shift_cust / st_shift - 1.f;
1974#ifdef AK89xx_SECONDARY
1975static int compass_self_test(
void)
1977 unsigned char tmp[6];
1978 unsigned char tries = 10;
1984 tmp[0] = AKM_POWER_DOWN;
1987 tmp[0] = AKM_BIT_SELF_TEST;
1990 tmp[0] = AKM_MODE_SELF_TEST;
1998 if (tmp[0] & AKM_DATA_READY)
2001 if (!(tmp[0] & AKM_DATA_READY))
2008 data = (short)(tmp[1] << 8) | tmp[0];
2009 if ((data > 100) || (data < -100))
2011 data = (short)(tmp[3] << 8) | tmp[2];
2012 if ((data > 100) || (data < -100))
2014 data = (short)(tmp[5] << 8) | tmp[4];
2015 if ((data > -300) || (data < -1000))
2019 tmp[0] = 0 | SUPPORTS_AK89xx_HIGH_SENS;
2021 tmp[0] = SUPPORTS_AK89xx_HIGH_SENS;
2032 unsigned char packet_count, ii;
2033 unsigned short fifo_count;
2093 fifo_count = (data[0] << 8) | data[1];
2095 gyro[0] = gyro[1] = gyro[2] = 0;
2096 accel[0] = accel[1] = accel[2] = 0;
2098 for (ii = 0; ii < packet_count; ii++) {
2099 short accel_cur[3], gyro_cur[3];
2102 accel_cur[0] = ((short)data[0] << 8) | data[1];
2103 accel_cur[1] = ((short)data[2] << 8) | data[3];
2104 accel_cur[2] = ((short)data[4] << 8) | data[5];
2105 accel[0] += (long)accel_cur[0];
2106 accel[1] += (long)accel_cur[1];
2107 accel[2] += (long)accel_cur[2];
2108 gyro_cur[0] = (((short)data[6] << 8) | data[7]);
2109 gyro_cur[1] = (((short)data[8] << 8) | data[9]);
2110 gyro_cur[2] = (((short)data[10] << 8) | data[11]);
2111 gyro[0] += (long)gyro_cur[0];
2112 gyro[1] += (long)gyro_cur[1];
2113 gyro[2] += (long)gyro_cur[2];
2116 gyro[0] = (long)(((
float)gyro[0]*65536.f) /
test.
gyro_sens / packet_count);
2117 gyro[1] = (long)(((
float)gyro[1]*65536.f) /
test.
gyro_sens / packet_count);
2118 gyro[2] = (long)(((
float)gyro[2]*65536.f) /
test.
gyro_sens / packet_count);
2130 gyro[0] = (long)(((
long long)gyro[0]<<16) /
test.
gyro_sens / packet_count);
2131 gyro[1] = (long)(((
long long)gyro[1]<<16) /
test.
gyro_sens / packet_count);
2132 gyro[2] = (long)(((
long long)gyro[2]<<16) /
test.
gyro_sens / packet_count);
2172 const unsigned char tries = 2;
2173 long gyro_st[3], accel_st[3];
2174 unsigned char accel_result, gyro_result;
2175#ifdef AK89xx_SECONDARY
2176 unsigned char compass_result;
2181 unsigned char accel_fsr, fifo_sensors, sensors_on;
2182 unsigned short gyro_fsr, sample_rate, lpf;
2183 unsigned char dmp_was_on;
2201 for (ii = 0; ii < tries; ii++)
2211 for (ii = 0; ii < tries; ii++)
2228#ifdef AK89xx_SECONDARY
2229 compass_result = compass_self_test();
2230 if (!compass_result)
2234#elif defined MPU6500
2272 unsigned char *data)
2274 unsigned char tmp[2];
2281 tmp[0] = (
unsigned char)(mem_addr >> 8);
2282 tmp[1] = (
unsigned char)(mem_addr & 0xFF);
2305 unsigned char *data)
2307 unsigned char tmp[2];
2314 tmp[0] = (
unsigned char)(mem_addr >> 8);
2315 tmp[1] = (
unsigned char)(mem_addr & 0xFF);
2337 unsigned short start_addr,
unsigned short sample_rate)
2340 unsigned short this_write;
2342#define LOAD_CHUNK (16)
2351 for (ii = 0; ii < length; ii += this_write) {
2353 if (
mpu_write_mem(ii, this_write, (
unsigned char*)&firmware[ii]))
2357 if (memcmp(firmware+ii, cur, this_write))
2362 tmp[0] = start_addr >> 8;
2363 tmp[1] = start_addr & 0xFF;
2426#ifdef AK89xx_SECONDARY
2427 unsigned char data[4], akm_addr;
2432 for (akm_addr = 0x0C; akm_addr <= 0x0F; akm_addr++) {
2434 result =
i2c_read(akm_addr, AKM_REG_WHOAMI, 1, data);
2435 if (!result && (data[0] == AKM_WHOAMI))
2439 if (akm_addr > 0x0F) {
2441 log_e(
"Compass not found.\n");
2447 data[0] = AKM_POWER_DOWN;
2452 data[0] = AKM_FUSE_ROM_ACCESS;
2460 st.
chip_cfg.mag_sens_adj[0] = (long)data[0] + 128;
2461 st.
chip_cfg.mag_sens_adj[1] = (long)data[1] + 128;
2462 st.
chip_cfg.mag_sens_adj[2] = (long)data[2] + 128;
2464 data[0] = AKM_POWER_DOWN;
2482 data[0] = AKM_REG_ST1;
2497 data[0] = AKM_REG_CNTL;
2507 data[0] = AKM_SINGLE_MEASUREMENT;
2537#ifdef AK89xx_SECONDARY
2538 unsigned char tmp[9];
2546 tmp[8] = AKM_SINGLE_MEASUREMENT;
2554#if defined AK8975_SECONDARY
2556 if (!(tmp[0] & AKM_DATA_READY))
2558 if ((tmp[7] & AKM_OVERFLOW) || (tmp[7] & AKM_DATA_ERROR))
2560#elif defined AK8963_SECONDARY
2562 if (!(tmp[0] & AKM_DATA_READY) || (tmp[0] & AKM_DATA_OVERRUN))
2564 if (tmp[7] & AKM_OVERFLOW)
2567 data[0] = (tmp[2] << 8) | tmp[1];
2568 data[1] = (tmp[4] << 8) | tmp[3];
2569 data[2] = (tmp[6] << 8) | tmp[5];
2571 data[0] = ((long)data[0] *
st.
chip_cfg.mag_sens_adj[0]) >> 8;
2572 data[1] = ((long)data[1] *
st.
chip_cfg.mag_sens_adj[1]) >> 8;
2573 data[2] = ((long)data[2] *
st.
chip_cfg.mag_sens_adj[2]) >> 8;
2590#ifdef AK89xx_SECONDARY
2591 fsr[0] =
st.
hw->compass_fsr;
2643 unsigned char lpa_freq)
2645 unsigned char data[3];
2648 unsigned char thresh_hw;
2655 else if (thresh < 32)
2658 thresh_hw = thresh >> 5;
2659#elif defined MPU6500
2663 else if (thresh < 4)
2666 thresh_hw = thresh >> 2;
2675#elif defined MPU6500
2721 goto lp_int_restore;
2724 data[0] = thresh_hw;
2727 goto lp_int_restore;
2733 goto lp_int_restore;
2739 else if (lpa_freq <= 5)
2741 else if (lpa_freq <= 20)
2747 goto lp_int_restore;
2751#elif defined MPU6500
2760 goto lp_int_restore;
2763 data[0] = thresh_hw;
2765 goto lp_int_restore;
2770 else if (lpa_freq == 2)
2771 data[0] = INV_LPA_2_5HZ;
2772 else if (lpa_freq <= 5)
2774 else if (lpa_freq <= 10)
2775 data[0] = INV_LPA_10HZ;
2776 else if (lpa_freq <= 20)
2778 else if (lpa_freq <= 40)
2780 else if (lpa_freq <= 80)
2781 data[0] = INV_LPA_80HZ;
2782 else if (lpa_freq <= 160)
2783 data[0] = INV_LPA_160HZ;
2784 else if (lpa_freq <= 320)
2785 data[0] = INV_LPA_320HZ;
2787 data[0] = INV_LPA_640HZ;
2789 goto lp_int_restore;
2794 goto lp_int_restore;
2799 goto lp_int_restore;
2804 goto lp_int_restore;
2814 if (cache_ptr[ii] != 0)
2815 goto lp_int_restore;
2843 goto lp_int_restore;
2865#define q30 1073741824.0f
2877 long gyro[3], accel[3];
2884 unsigned short accel_sens;
2886 gyro[0] = (long)(gyro[0] * sens);
2887 gyro[1] = (long)(gyro[1] * sens);
2888 gyro[2] = (long)(gyro[2] * sens);
2891 accel[0] *= accel_sens;
2892 accel[1] *= accel_sens;
2893 accel[2] *= accel_sens;
2899 const signed char *mtx){
2900 unsigned short scalar;
2919 else if (row[0] < 0)
2921 else if (row[1] > 0)
2923 else if (row[1] < 0)
2925 else if (row[2] > 0)
2927 else if (row[2] < 0)
2971 float q0=1.0f,q1=0.0f,q2=0.0f,q3=0.0f;
2972 unsigned long sensor_timestamp;
2973 short gyro[3], accel[3], sensors;
2976 if(
dmp_read_fifo(gyro, accel, quat, &sensor_timestamp, &sensors,&more))
return 1;
2994 *pitch = asin(-2 * q1 * q3 + 2 * q0* q2)* 57.3;
2995 *roll = atan2(2 * q2 * q3 + 2 * q0 * q1, -2 * q1 * q1 - 2 * q2* q2 + 1)* 57.3;
2996 *yaw = atan2(2*(q1*q2 + q0*q3),q0*q0+q1*q1-q2*q2-q3*q3) * 57.3;
int mpu_set_sample_rate(unsigned short rate)
Set sampling rate. Sampling rate must be between 4Hz and 1kHz.
int mpu_get_gyro_sens(float *sens)
Get gyro sensitivity scale factor.
int dmp_read_fifo(short *gyro, short *accel, long *quat, unsigned long *timestamp, short *sensors, unsigned char *more)
Get one packet from the FIFO. If sensors does not contain a particular sensor, disregard the data ret...
int mpu_get_fifo_config(unsigned char *sensors)
Get current FIFO configuration. sensors can contain a combination of the following flags: INV_X_GYR...
int mpu_get_int_status(short *status)
Read the MPU interrupt status registers.
int mpu_reg_dump(void)
Register dump for testing.
int mpu_read_fifo_stream(unsigned short length, unsigned char *data, unsigned char *more)
Get one unparsed packet from the FIFO. This function should be used if the packet is to be parsed els...
unsigned short sample_rate
int mpu_get_sample_rate(unsigned short *rate)
Get sampling rate.
unsigned short sample_rate
static int gyro_self_test(long *bias_regular, long *bias_st)
int mpu_set_accel_fsr(unsigned char fsr)
Set the accel full-scale range.
unsigned char int_motion_only
unsigned short inv_row_2_scale(const signed char *row)
int mpu_read_fifo(short *gyro, short *accel, unsigned long *timestamp, unsigned char *sensors, unsigned char *more)
Get one packet from the FIFO. If sensors does not contain a particular sensor, disregard the data ret...
int mpu_read_mem(unsigned short mem_addr, unsigned short length, unsigned char *data)
Read from the DMP memory. This function prevents I2C reads past the bank boundaries....
unsigned char lp_accel_mode
int mpu_set_bypass(unsigned char bypass_on)
Set device to bypass mode.
#define BIT_FIFO_SIZE_1024
int mpu_run_self_test(long *gyro, long *accel)
Trigger gyro/accel/compass self-test. On success/error, the self-test returns a mask representing the...
static struct gyro_state_s st
int mpu_lp_accel_mode(unsigned char rate)
Enter low-power accel-only mode. In low-power accel mode, the chip goes to sleep and only wakes up to...
unsigned char reg_accel_fsr
unsigned char reg_rate_div
unsigned short inv_orientation_matrix_to_scalar(const signed char *mtx)
#define DMP_FEATURE_SEND_CAL_GYRO
unsigned char fifo_sensors
const struct gyro_reg_s * reg
int dmp_set_gyro_bias(long *bias)
Push gyro biases to the DMP. Because the gyro integration is handled in the DMP, any gyro biases calc...
int mpu_set_accel_bias(const long *accel_bias)
Push biases to the accel bias registers. This function expects biases relative to the current sensor ...
int dmp_set_fifo_rate(unsigned short rate)
Set DMP output rate. Only used when DMP is on.
const struct gyro_reg_s reg
int mpu_get_gyro_reg(short *data, unsigned long *timestamp)
Read raw gyro data directly from the registers.
unsigned char latched_int
int mpu_set_lpf(unsigned short lpf)
Set digital low pass filter. The following LPF settings are supported: 188, 98, 42,...
const struct test_s * test
int mpu_read_reg(unsigned char reg, unsigned char *data)
Read from a single register. NOTE: The memory and FIFO read/write registers cannot be accessed.
unsigned short dmp_sample_rate
int mpu_get_accel_sens(unsigned short *sens)
Get accel sensitivity scale factor.
int mpu_set_int_latched(unsigned char enable)
Enable latched interrupts. Any MPU register will clear the interrupt.
int mpu_get_compass_reg(short *data, unsigned long *timestamp)
Read raw compass data.
int dmp_load_motion_driver_firmware(void)
Load the DMP with this image.
int mpu_set_dmp_state(unsigned char enable)
Enable/disable DMP support.
void log_none(char *fmt,...)
int dmp_set_orientation(unsigned short orient)
Push gyro and accel orientation to the DMP. The orientation is represented here as the output of inv_...
unsigned char bypass_mode
int mpu_set_sensors(unsigned char sensors)
Turn specific sensors on/off. sensors can contain a combination of the following flags: INV_X_GYRO,...
unsigned char active_low_int
int dmp_enable_feature(unsigned short mask)
Enable DMP features. The following #define's are used in the input mask: DMP_FEATURE_TAP DMP_FEAT...
int mpu_set_compass_sample_rate(unsigned short rate)
Set compass sampling rate. The compass on the auxiliary I2C bus is read by the MPU hardware at a maxi...
unsigned char mem_start_addr
int mpu_lp_motion_interrupt(unsigned short thresh, unsigned char time, unsigned char lpa_freq)
Enters LP accel motion interrupt mode. The behavior of this feature is very different between the MPU...
unsigned char fifo_enable
struct chip_cfg_s chip_cfg
unsigned char packet_thresh
static int get_st_biases(long *gyro, long *accel, unsigned char hw_test)
int mpu_load_firmware(unsigned short length, const unsigned char *firmware, unsigned short start_addr, unsigned short sample_rate)
Load and verify DMP image.
#define MAX_PACKET_LENGTH
#define DMP_FEATURE_SEND_RAW_ACCEL
unsigned char reg_gyro_fsr
int mpu_get_temperature(long *data, unsigned long *timestamp)
Read temperature data directly from the registers.
int mpu_get_lpf(unsigned short *lpf)
Get the current DLPF setting.
static int accel_self_test(long *bias_regular, long *bias_st)
unsigned char prgm_start_h
unsigned char int_pin_cfg
#define DMP_FEATURE_GYRO_CAL
int mpu_get_compass_sample_rate(unsigned short *rate)
Get compass sampling rate.
int mpu_get_accel_fsr(unsigned char *fsr)
Get the accel full-scale range.
unsigned char fifo_count_h
static int get_accel_prod_shift(float *st_shift)
int mpu_configure_fifo(unsigned char sensors)
Select which sensors are pushed to FIFO. sensors can contain a combination of the following flags: ...
int mpu_init(void)
Initialize hardware. Initial configuration: Gyro FSR: +/- 2000DPS Accel FSR +/- 2G DLPF: 42Hz FIFO ra...
#define BIT_I2C_MST_VDDIO
u8 mpu_dmp_get_data(float *pitch, float *roll, float *yaw)
int mpu_set_int_level(unsigned char active_low)
Set interrupt level.
int mpu_set_gyro_fsr(unsigned short fsr)
Set the gyro full-scale range.
static signed char gyro_orientation[9]
int mpu_get_compass_fsr(unsigned short *fsr)
Get the compass full-scale range.
struct motion_int_cache_s cache
int mpu_get_accel_reg(short *data, unsigned long *timestamp)
Read raw accel data directly from the registers.
#define DMP_FEATURE_6X_LP_QUAT
unsigned char dmp_int_status
int mpu_get_power_state(unsigned char *power_on)
Get current power state.
int mpu_reset_fifo(void)
Reset FIFO read/write pointers.
#define DMP_FEATURE_ANDROID_ORIENT
int mpu_get_gyro_fsr(unsigned short *fsr)
Get the gyro full-scale range.
void mget_ms(unsigned long *time)
#define BIT_FIFO_OVERFLOW
int dmp_set_accel_bias(long *bias)
Push accel biases to the DMP. These biases will be removed from the DMP 6-axis quaternion.
static int set_int_enable(unsigned char enable)
Enable/disable data ready interrupt. If the DMP is on, the DMP interrupt is enabled....
int mpu_get_dmp_state(unsigned char *enabled)
Get DMP state.
int mpu_write_mem(unsigned short mem_addr, unsigned short length, unsigned char *data)
Write to the DMP memory. This function prevents I2C writes past the bank boundaries....
@ INV_FILTER_2100HZ_NOLPF
@ INV_FILTER_256HZ_NOLPF2
An I2C-based driver for Invensense gyroscopes.
DMP image and interface functions.