motion library for mpu6050, mpu9250 and etc, supports i2c and spi

Committer:
yihui
Date:
Tue Jul 05 07:19:59 2016 +0000
Revision:
0:814475fdc553
initial

Who changed what in which revision?

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