InvenSense Motion Driver v5.1.2 ported
inv_mpu.h@4:2cb380415dc7, 2014-11-02 (annotated)
- Committer:
- oprospero
- Date:
- Sun Nov 02 19:17:45 2014 +0000
- Revision:
- 4:2cb380415dc7
- Parent:
- 3:8ac73f9099ab
Added reset function
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
oprospero | 0:4dd021344a6b | 1 | #ifndef _INV_MPU_H_ |
oprospero | 0:4dd021344a6b | 2 | #define _INV_MPU_H_ |
oprospero | 0:4dd021344a6b | 3 | |
oprospero | 0:4dd021344a6b | 4 | #include "I2Cdev.h" |
oprospero | 0:4dd021344a6b | 5 | |
oprospero | 0:4dd021344a6b | 6 | |
oprospero | 0:4dd021344a6b | 7 | |
oprospero | 0:4dd021344a6b | 8 | |
oprospero | 0:4dd021344a6b | 9 | #define INV_X_GYRO (0x40) |
oprospero | 0:4dd021344a6b | 10 | #define INV_Y_GYRO (0x20) |
oprospero | 0:4dd021344a6b | 11 | #define INV_Z_GYRO (0x10) |
oprospero | 0:4dd021344a6b | 12 | #define INV_XYZ_GYRO (INV_X_GYRO | INV_Y_GYRO | INV_Z_GYRO) |
oprospero | 0:4dd021344a6b | 13 | #define INV_XYZ_ACCEL (0x08) |
oprospero | 0:4dd021344a6b | 14 | #define INV_XYZ_COMPASS (0x01) |
oprospero | 0:4dd021344a6b | 15 | |
oprospero | 0:4dd021344a6b | 16 | #define MPU_INT_STATUS_DATA_READY (0x0001) |
oprospero | 0:4dd021344a6b | 17 | #define MPU_INT_STATUS_DMP (0x0002) |
oprospero | 0:4dd021344a6b | 18 | #define MPU_INT_STATUS_PLL_READY (0x0004) |
oprospero | 0:4dd021344a6b | 19 | #define MPU_INT_STATUS_I2C_MST (0x0008) |
oprospero | 0:4dd021344a6b | 20 | #define MPU_INT_STATUS_FIFO_OVERFLOW (0x0010) |
oprospero | 0:4dd021344a6b | 21 | #define MPU_INT_STATUS_ZMOT (0x0020) |
oprospero | 0:4dd021344a6b | 22 | #define MPU_INT_STATUS_MOT (0x0040) |
oprospero | 0:4dd021344a6b | 23 | #define MPU_INT_STATUS_FREE_FALL (0x0080) |
oprospero | 0:4dd021344a6b | 24 | #define MPU_INT_STATUS_DMP_0 (0x0100) |
oprospero | 0:4dd021344a6b | 25 | #define MPU_INT_STATUS_DMP_1 (0x0200) |
oprospero | 0:4dd021344a6b | 26 | #define MPU_INT_STATUS_DMP_2 (0x0400) |
oprospero | 0:4dd021344a6b | 27 | #define MPU_INT_STATUS_DMP_3 (0x0800) |
oprospero | 0:4dd021344a6b | 28 | #define MPU_INT_STATUS_DMP_4 (0x1000) |
oprospero | 0:4dd021344a6b | 29 | #define MPU_INT_STATUS_DMP_5 (0x2000) |
oprospero | 0:4dd021344a6b | 30 | |
oprospero | 0:4dd021344a6b | 31 | #define MPU6050_WHO_AM_I_BIT 6 |
oprospero | 0:4dd021344a6b | 32 | #define MPU6050_WHO_AM_I_LENGTH 6 |
oprospero | 0:4dd021344a6b | 33 | #define MPU6050_RA_WHO_AM_I 0x75 |
oprospero | 0:4dd021344a6b | 34 | |
oprospero | 0:4dd021344a6b | 35 | class InvMpu |
oprospero | 0:4dd021344a6b | 36 | { |
oprospero | 0:4dd021344a6b | 37 | private: |
oprospero | 0:4dd021344a6b | 38 | I2Cdev i2Cdev; |
oprospero | 0:4dd021344a6b | 39 | |
oprospero | 0:4dd021344a6b | 40 | public: |
oprospero | 0:4dd021344a6b | 41 | InvMpu(); |
oprospero | 0:4dd021344a6b | 42 | int getDeviceID(); |
oprospero | 0:4dd021344a6b | 43 | bool testConnection(); |
oprospero | 0:4dd021344a6b | 44 | |
oprospero | 3:8ac73f9099ab | 45 | int mpu_reset(void); |
oprospero | 0:4dd021344a6b | 46 | // static |
oprospero | 0:4dd021344a6b | 47 | int set_int_enable(unsigned char enable); |
oprospero | 0:4dd021344a6b | 48 | int get_accel_prod_shift(float *st_shift); |
oprospero | 0:4dd021344a6b | 49 | int accel_self_test(long *bias_regular, long *bias_st); |
oprospero | 0:4dd021344a6b | 50 | int gyro_self_test(long *bias_regular, long *bias_st); |
oprospero | 0:4dd021344a6b | 51 | int compass_self_test(void); |
oprospero | 0:4dd021344a6b | 52 | int get_st_biases(long *gyro, long *accel, unsigned char hw_test); |
oprospero | 0:4dd021344a6b | 53 | int setup_compass(void); |
oprospero | 0:4dd021344a6b | 54 | |
oprospero | 0:4dd021344a6b | 55 | /* Set up APIs */ |
oprospero | 0:4dd021344a6b | 56 | int mpu_init(void); |
oprospero | 0:4dd021344a6b | 57 | int mpu_init_slave(void); |
oprospero | 0:4dd021344a6b | 58 | int mpu_set_bypass(unsigned char bypass_on); |
oprospero | 0:4dd021344a6b | 59 | |
oprospero | 0:4dd021344a6b | 60 | /* Configuration APIs */ |
oprospero | 0:4dd021344a6b | 61 | int mpu_lp_accel_mode(unsigned char rate); |
oprospero | 0:4dd021344a6b | 62 | int mpu_lp_motion_interrupt(unsigned short thresh, unsigned char time, |
oprospero | 0:4dd021344a6b | 63 | unsigned char lpa_freq); |
oprospero | 0:4dd021344a6b | 64 | int mpu_set_int_level(unsigned char active_low); |
oprospero | 0:4dd021344a6b | 65 | int mpu_set_int_latched(unsigned char enable); |
oprospero | 0:4dd021344a6b | 66 | |
oprospero | 0:4dd021344a6b | 67 | int mpu_set_dmp_state(unsigned char enable); |
oprospero | 0:4dd021344a6b | 68 | int mpu_get_dmp_state(unsigned char *enabled); |
oprospero | 0:4dd021344a6b | 69 | |
oprospero | 0:4dd021344a6b | 70 | int mpu_get_lpf(unsigned short *lpf); |
oprospero | 0:4dd021344a6b | 71 | int mpu_set_lpf(unsigned short lpf); |
oprospero | 0:4dd021344a6b | 72 | |
oprospero | 0:4dd021344a6b | 73 | int mpu_get_gyro_fsr(unsigned short *fsr); |
oprospero | 0:4dd021344a6b | 74 | int mpu_set_gyro_fsr(unsigned short fsr); |
oprospero | 0:4dd021344a6b | 75 | |
oprospero | 0:4dd021344a6b | 76 | int mpu_get_accel_fsr(unsigned char *fsr); |
oprospero | 0:4dd021344a6b | 77 | int mpu_set_accel_fsr(unsigned char fsr); |
oprospero | 0:4dd021344a6b | 78 | |
oprospero | 0:4dd021344a6b | 79 | int mpu_get_compass_fsr(unsigned short *fsr); |
oprospero | 0:4dd021344a6b | 80 | |
oprospero | 0:4dd021344a6b | 81 | int mpu_get_gyro_sens(float *sens); |
oprospero | 0:4dd021344a6b | 82 | int mpu_get_accel_sens(unsigned short *sens); |
oprospero | 0:4dd021344a6b | 83 | |
oprospero | 0:4dd021344a6b | 84 | int mpu_get_sample_rate(unsigned short *rate); |
oprospero | 0:4dd021344a6b | 85 | int mpu_set_sample_rate(unsigned short rate); |
oprospero | 0:4dd021344a6b | 86 | int mpu_get_compass_sample_rate(unsigned short *rate); |
oprospero | 0:4dd021344a6b | 87 | int mpu_set_compass_sample_rate(unsigned short rate); |
oprospero | 0:4dd021344a6b | 88 | |
oprospero | 0:4dd021344a6b | 89 | int mpu_get_fifo_config(unsigned char *sensors); |
oprospero | 0:4dd021344a6b | 90 | int mpu_configure_fifo(unsigned char sensors); |
oprospero | 0:4dd021344a6b | 91 | |
oprospero | 0:4dd021344a6b | 92 | int mpu_get_power_state(unsigned char *power_on); |
oprospero | 0:4dd021344a6b | 93 | int mpu_set_sensors(unsigned char sensors); |
oprospero | 0:4dd021344a6b | 94 | |
oprospero | 0:4dd021344a6b | 95 | int mpu_read_6500_accel_bias(long *accel_bias); |
oprospero | 0:4dd021344a6b | 96 | int mpu_read_6500_gyro_bias(long *gyro_bias); |
oprospero | 0:4dd021344a6b | 97 | int mpu_set_gyro_bias_reg(long * gyro_bias); |
oprospero | 0:4dd021344a6b | 98 | int mpu_set_accel_bias_6500_reg(const long *accel_bias); |
oprospero | 0:4dd021344a6b | 99 | int mpu_read_6050_accel_bias(long *accel_bias); |
oprospero | 0:4dd021344a6b | 100 | int mpu_set_accel_bias_6050_reg(const long *accel_bias); |
oprospero | 0:4dd021344a6b | 101 | |
oprospero | 0:4dd021344a6b | 102 | /* Data getter/setter APIs */ |
oprospero | 0:4dd021344a6b | 103 | int mpu_get_gyro_reg(short *data, unsigned long *timestamp); |
oprospero | 0:4dd021344a6b | 104 | int mpu_get_accel_reg(short *data, unsigned long *timestamp); |
oprospero | 0:4dd021344a6b | 105 | int mpu_get_compass_reg(short *data, unsigned long *timestamp); |
oprospero | 0:4dd021344a6b | 106 | int mpu_get_temperature(long *data, unsigned long *timestamp); |
oprospero | 0:4dd021344a6b | 107 | |
oprospero | 0:4dd021344a6b | 108 | int mpu_get_int_status(short *status); |
oprospero | 0:4dd021344a6b | 109 | int mpu_read_fifo(short *gyro, short *accel, unsigned long *timestamp, |
oprospero | 0:4dd021344a6b | 110 | unsigned char *sensors, unsigned char *more); |
oprospero | 0:4dd021344a6b | 111 | int mpu_read_fifo_stream(unsigned short length, unsigned char *data, |
oprospero | 0:4dd021344a6b | 112 | unsigned char *more); |
oprospero | 0:4dd021344a6b | 113 | int mpu_reset_fifo(void); |
oprospero | 0:4dd021344a6b | 114 | |
oprospero | 0:4dd021344a6b | 115 | int mpu_write_mem(unsigned short mem_addr, unsigned short length, |
oprospero | 0:4dd021344a6b | 116 | unsigned char *data); |
oprospero | 0:4dd021344a6b | 117 | int mpu_read_mem(unsigned short mem_addr, unsigned short length, |
oprospero | 0:4dd021344a6b | 118 | unsigned char *data); |
oprospero | 0:4dd021344a6b | 119 | int mpu_load_firmware(unsigned short length, const unsigned char *firmware, |
oprospero | 0:4dd021344a6b | 120 | unsigned short start_addr, unsigned short sample_rate); |
oprospero | 0:4dd021344a6b | 121 | |
oprospero | 0:4dd021344a6b | 122 | int mpu_reg_dump(void); |
oprospero | 0:4dd021344a6b | 123 | int mpu_read_reg(unsigned char reg, unsigned char *data); |
oprospero | 0:4dd021344a6b | 124 | int mpu_run_self_test(long *gyro, long *accel); |
oprospero | 0:4dd021344a6b | 125 | int mpu_run_6500_self_test(long *gyro, long *accel, unsigned char debug); |
oprospero | 0:4dd021344a6b | 126 | int mpu_register_tap_cb(void (*func)(unsigned char, unsigned char)); |
oprospero | 0:4dd021344a6b | 127 | |
oprospero | 0:4dd021344a6b | 128 | }; |
oprospero | 0:4dd021344a6b | 129 | |
oprospero | 0:4dd021344a6b | 130 | |
oprospero | 0:4dd021344a6b | 131 | #endif /* #ifndef _INV_MPU_H_ */ |