library for MPU6050 and MPU9250, supports both I2C and SPI

Dependents:   Seeed_nRF51822_MPU9250

Committer:
yihui
Date:
Thu Dec 10 07:39:48 2015 +0000
Revision:
0:972f3778c19c
initial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 0:972f3778c19c 1 /*
yihui 0:972f3778c19c 2 $License:
yihui 0:972f3778c19c 3 Copyright (C) 2011-2012 InvenSense Corporation, All Rights Reserved.
yihui 0:972f3778c19c 4 See included License.txt for License information.
yihui 0:972f3778c19c 5 $
yihui 0:972f3778c19c 6 */
yihui 0:972f3778c19c 7 /**
yihui 0:972f3778c19c 8 * @addtogroup DRIVERS Sensor Driver Layer
yihui 0:972f3778c19c 9 * @brief Hardware drivers to communicate with sensors via I2C.
yihui 0:972f3778c19c 10 *
yihui 0:972f3778c19c 11 * @{
yihui 0:972f3778c19c 12 * @file inv_mpu.h
yihui 0:972f3778c19c 13 * @brief An I2C-based driver for Invensense gyroscopes.
yihui 0:972f3778c19c 14 * @details This driver currently works for the following devices:
yihui 0:972f3778c19c 15 * MPU6050
yihui 0:972f3778c19c 16 * MPU6500
yihui 0:972f3778c19c 17 * MPU9150 (or MPU6050 w/ AK8975 on the auxiliary bus)
yihui 0:972f3778c19c 18 * MPU9250 (or MPU6500 w/ AK8963 on the auxiliary bus)
yihui 0:972f3778c19c 19 */
yihui 0:972f3778c19c 20
yihui 0:972f3778c19c 21 #ifndef _INV_MPU_H_
yihui 0:972f3778c19c 22 #define _INV_MPU_H_
yihui 0:972f3778c19c 23
yihui 0:972f3778c19c 24 #ifdef __cplusplus
yihui 0:972f3778c19c 25 extern "C" {
yihui 0:972f3778c19c 26 #endif
yihui 0:972f3778c19c 27
yihui 0:972f3778c19c 28 #define INV_X_GYRO (0x40)
yihui 0:972f3778c19c 29 #define INV_Y_GYRO (0x20)
yihui 0:972f3778c19c 30 #define INV_Z_GYRO (0x10)
yihui 0:972f3778c19c 31 #define INV_XYZ_GYRO (INV_X_GYRO | INV_Y_GYRO | INV_Z_GYRO)
yihui 0:972f3778c19c 32 #define INV_XYZ_ACCEL (0x08)
yihui 0:972f3778c19c 33 #define INV_XYZ_COMPASS (0x01)
yihui 0:972f3778c19c 34
yihui 0:972f3778c19c 35 struct int_param_s {
yihui 0:972f3778c19c 36 #if defined EMPL_TARGET_MSP430 || defined MOTION_DRIVER_TARGET_MSP430
yihui 0:972f3778c19c 37 void (*cb)(void);
yihui 0:972f3778c19c 38 unsigned short pin;
yihui 0:972f3778c19c 39 unsigned char lp_exit;
yihui 0:972f3778c19c 40 unsigned char active_low;
yihui 0:972f3778c19c 41 #elif defined EMPL_TARGET_UC3L0
yihui 0:972f3778c19c 42 unsigned long pin;
yihui 0:972f3778c19c 43 void (*cb)(volatile void*);
yihui 0:972f3778c19c 44 void *arg;
yihui 0:972f3778c19c 45 #endif
yihui 0:972f3778c19c 46 };
yihui 0:972f3778c19c 47
yihui 0:972f3778c19c 48 #define MPU_INT_STATUS_DATA_READY (0x0001)
yihui 0:972f3778c19c 49 #define MPU_INT_STATUS_DMP (0x0002)
yihui 0:972f3778c19c 50 #define MPU_INT_STATUS_PLL_READY (0x0004)
yihui 0:972f3778c19c 51 #define MPU_INT_STATUS_I2C_MST (0x0008)
yihui 0:972f3778c19c 52 #define MPU_INT_STATUS_FIFO_OVERFLOW (0x0010)
yihui 0:972f3778c19c 53 #define MPU_INT_STATUS_ZMOT (0x0020)
yihui 0:972f3778c19c 54 #define MPU_INT_STATUS_MOT (0x0040)
yihui 0:972f3778c19c 55 #define MPU_INT_STATUS_FREE_FALL (0x0080)
yihui 0:972f3778c19c 56 #define MPU_INT_STATUS_DMP_0 (0x0100)
yihui 0:972f3778c19c 57 #define MPU_INT_STATUS_DMP_1 (0x0200)
yihui 0:972f3778c19c 58 #define MPU_INT_STATUS_DMP_2 (0x0400)
yihui 0:972f3778c19c 59 #define MPU_INT_STATUS_DMP_3 (0x0800)
yihui 0:972f3778c19c 60 #define MPU_INT_STATUS_DMP_4 (0x1000)
yihui 0:972f3778c19c 61 #define MPU_INT_STATUS_DMP_5 (0x2000)
yihui 0:972f3778c19c 62
yihui 0:972f3778c19c 63 /* Set up APIs */
yihui 0:972f3778c19c 64 int mpu_init(struct int_param_s *int_param);
yihui 0:972f3778c19c 65 int mpu_init_slave(void);
yihui 0:972f3778c19c 66 int mpu_set_bypass(unsigned char bypass_on);
yihui 0:972f3778c19c 67
yihui 0:972f3778c19c 68 /* Configuration APIs */
yihui 0:972f3778c19c 69 int mpu_lp_accel_mode(unsigned char rate);
yihui 0:972f3778c19c 70 int mpu_lp_motion_interrupt(unsigned short thresh, unsigned char time,
yihui 0:972f3778c19c 71 unsigned char lpa_freq);
yihui 0:972f3778c19c 72 int mpu_set_int_level(unsigned char active_low);
yihui 0:972f3778c19c 73 int mpu_set_int_latched(unsigned char enable);
yihui 0:972f3778c19c 74
yihui 0:972f3778c19c 75 int mpu_set_dmp_state(unsigned char enable);
yihui 0:972f3778c19c 76 int mpu_get_dmp_state(unsigned char *enabled);
yihui 0:972f3778c19c 77
yihui 0:972f3778c19c 78 int mpu_get_lpf(unsigned short *lpf);
yihui 0:972f3778c19c 79 int mpu_set_lpf(unsigned short lpf);
yihui 0:972f3778c19c 80
yihui 0:972f3778c19c 81 int mpu_get_gyro_fsr(unsigned short *fsr);
yihui 0:972f3778c19c 82 int mpu_set_gyro_fsr(unsigned short fsr);
yihui 0:972f3778c19c 83
yihui 0:972f3778c19c 84 int mpu_get_accel_fsr(unsigned char *fsr);
yihui 0:972f3778c19c 85 int mpu_set_accel_fsr(unsigned char fsr);
yihui 0:972f3778c19c 86
yihui 0:972f3778c19c 87 int mpu_get_compass_fsr(unsigned short *fsr);
yihui 0:972f3778c19c 88
yihui 0:972f3778c19c 89 int mpu_get_gyro_sens(float *sens);
yihui 0:972f3778c19c 90 int mpu_get_accel_sens(unsigned short *sens);
yihui 0:972f3778c19c 91
yihui 0:972f3778c19c 92 int mpu_get_sample_rate(unsigned short *rate);
yihui 0:972f3778c19c 93 int mpu_set_sample_rate(unsigned short rate);
yihui 0:972f3778c19c 94 int mpu_get_compass_sample_rate(unsigned short *rate);
yihui 0:972f3778c19c 95 int mpu_set_compass_sample_rate(unsigned short rate);
yihui 0:972f3778c19c 96
yihui 0:972f3778c19c 97 int mpu_get_fifo_config(unsigned char *sensors);
yihui 0:972f3778c19c 98 int mpu_configure_fifo(unsigned char sensors);
yihui 0:972f3778c19c 99
yihui 0:972f3778c19c 100 int mpu_get_power_state(unsigned char *power_on);
yihui 0:972f3778c19c 101 int mpu_set_sensors(unsigned char sensors);
yihui 0:972f3778c19c 102
yihui 0:972f3778c19c 103 int mpu_read_6500_accel_bias(long *accel_bias);
yihui 0:972f3778c19c 104 int mpu_set_gyro_bias_reg(long * gyro_bias);
yihui 0:972f3778c19c 105 int mpu_set_accel_bias_6500_reg(const long *accel_bias);
yihui 0:972f3778c19c 106 int mpu_read_6050_accel_bias(long *accel_bias);
yihui 0:972f3778c19c 107 int mpu_set_accel_bias_6050_reg(const long *accel_bias);
yihui 0:972f3778c19c 108
yihui 0:972f3778c19c 109 /* Data getter/setter APIs */
yihui 0:972f3778c19c 110 int mpu_get_gyro_reg(short *data, unsigned long *timestamp);
yihui 0:972f3778c19c 111 int mpu_get_accel_reg(short *data, unsigned long *timestamp);
yihui 0:972f3778c19c 112 int mpu_get_compass_reg(short *data, unsigned long *timestamp);
yihui 0:972f3778c19c 113 int mpu_get_temperature(long *data, unsigned long *timestamp);
yihui 0:972f3778c19c 114
yihui 0:972f3778c19c 115 int mpu_get_int_status(short *status);
yihui 0:972f3778c19c 116 int mpu_read_fifo(short *gyro, short *accel, unsigned long *timestamp,
yihui 0:972f3778c19c 117 unsigned char *sensors, unsigned char *more);
yihui 0:972f3778c19c 118 int mpu_read_fifo_stream(unsigned short length, unsigned char *data,
yihui 0:972f3778c19c 119 unsigned char *more);
yihui 0:972f3778c19c 120 int mpu_reset_fifo(void);
yihui 0:972f3778c19c 121
yihui 0:972f3778c19c 122 int mpu_write_mem(unsigned short mem_addr, unsigned short length,
yihui 0:972f3778c19c 123 unsigned char *data);
yihui 0:972f3778c19c 124 int mpu_read_mem(unsigned short mem_addr, unsigned short length,
yihui 0:972f3778c19c 125 unsigned char *data);
yihui 0:972f3778c19c 126 int mpu_load_firmware(unsigned short length, const unsigned char *firmware,
yihui 0:972f3778c19c 127 unsigned short start_addr, unsigned short sample_rate);
yihui 0:972f3778c19c 128
yihui 0:972f3778c19c 129 int mpu_reg_dump(void);
yihui 0:972f3778c19c 130 int mpu_read_reg(unsigned char reg, unsigned char *data);
yihui 0:972f3778c19c 131 int mpu_run_self_test(long *gyro, long *accel);
yihui 0:972f3778c19c 132 int mpu_run_6500_self_test(long *gyro, long *accel, unsigned char debug);
yihui 0:972f3778c19c 133 int mpu_register_tap_cb(void (*func)(unsigned char, unsigned char));
yihui 0:972f3778c19c 134
yihui 0:972f3778c19c 135 #ifdef __cplusplus
yihui 0:972f3778c19c 136 }
yihui 0:972f3778c19c 137 #endif
yihui 0:972f3778c19c 138
yihui 0:972f3778c19c 139 #endif /* #ifndef _INV_MPU_H_ */
yihui 0:972f3778c19c 140