MPU6050 library

Dependents:   CSSE4011_BLE_IMU_Project_rev2 Seeed_Tiny_BLE_Get_Started nrf51822_fix_i2c_spi_conflict balanceboard ... more

Committer:
yihui
Date:
Thu Nov 05 01:38:50 2015 +0000
Revision:
1:6aedb937cb38
Parent:
0:1b6dab73c06b
add mbed_i2c_clear() function; ; use mbed_i2c_clear to recover i2c bus when i2c is stuck

Who changed what in which revision?

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