XerolySkinnerBscpp 1.0.0
C++版本的驱动库
inv_mpu.h
浏览该文件的文档.
1/*
2 $License:
3 Copyright (C) 2011-2012 InvenSense Corporation, All Rights Reserved.
4 See included License.txt for License information.
5 $
6 */
21#ifndef _INV_MPU_H_
22#define _INV_MPU_H_
23#include "main.h"
24#include "varint.h"
25
26//定义输出速度
27#define DEFAULT_MPU_HZ (100) //100Hz
28
29#define INV_X_GYRO (0x40)
30#define INV_Y_GYRO (0x20)
31#define INV_Z_GYRO (0x10)
32#define INV_XYZ_GYRO (INV_X_GYRO | INV_Y_GYRO | INV_Z_GYRO)
33#define INV_XYZ_ACCEL (0x08)
34#define INV_XYZ_COMPASS (0x01)
35
36//移植官方MSP430 DMP驱动过来
38//#if defined EMPL_TARGET_MSP430 || defined MOTION_DRIVER_TARGET_MSP430
39 void (*cb)(void);
40 unsigned short pin;
41 unsigned char lp_exit;
42 unsigned char active_low;
43//#elif defined EMPL_TARGET_UC3L0
44// unsigned long pin;
45// void (*cb)(volatile void*);
46// void *arg;
47//#endif
48};
49
50#define MPU_INT_STATUS_DATA_READY (0x0001)
51#define MPU_INT_STATUS_DMP (0x0002)
52#define MPU_INT_STATUS_PLL_READY (0x0004)
53#define MPU_INT_STATUS_I2C_MST (0x0008)
54#define MPU_INT_STATUS_FIFO_OVERFLOW (0x0010)
55#define MPU_INT_STATUS_ZMOT (0x0020)
56#define MPU_INT_STATUS_MOT (0x0040)
57#define MPU_INT_STATUS_FREE_FALL (0x0080)
58#define MPU_INT_STATUS_DMP_0 (0x0100)
59#define MPU_INT_STATUS_DMP_1 (0x0200)
60#define MPU_INT_STATUS_DMP_2 (0x0400)
61#define MPU_INT_STATUS_DMP_3 (0x0800)
62#define MPU_INT_STATUS_DMP_4 (0x1000)
63#define MPU_INT_STATUS_DMP_5 (0x2000)
64
65/* Set up APIs */
66int mpu_init(void);
68int mpu_set_bypass(unsigned char bypass_on);
69
70/* Configuration APIs */
71int mpu_lp_accel_mode(unsigned char rate);
72int mpu_lp_motion_interrupt(unsigned short thresh, unsigned char time,
73 unsigned char lpa_freq);
74int mpu_set_int_level(unsigned char active_low);
75int mpu_set_int_latched(unsigned char enable);
76
77int mpu_set_dmp_state(unsigned char enable);
78int mpu_get_dmp_state(unsigned char *enabled);
79
80int mpu_get_lpf(unsigned short *lpf);
81int mpu_set_lpf(unsigned short lpf);
82
83int mpu_get_gyro_fsr(unsigned short *fsr);
84int mpu_set_gyro_fsr(unsigned short fsr);
85
86int mpu_get_accel_fsr(unsigned char *fsr);
87int mpu_set_accel_fsr(unsigned char fsr);
88
89int mpu_get_compass_fsr(unsigned short *fsr);
90
91int mpu_get_gyro_sens(float *sens);
92int mpu_get_accel_sens(unsigned short *sens);
93
94int mpu_get_sample_rate(unsigned short *rate);
95int mpu_set_sample_rate(unsigned short rate);
96int mpu_get_compass_sample_rate(unsigned short *rate);
97int mpu_set_compass_sample_rate(unsigned short rate);
98
99int mpu_get_fifo_config(unsigned char *sensors);
100int mpu_configure_fifo(unsigned char sensors);
101
102int mpu_get_power_state(unsigned char *power_on);
103int mpu_set_sensors(unsigned char sensors);
104
105int mpu_set_accel_bias(const long *accel_bias);
106
107/* Data getter/setter APIs */
108int mpu_get_gyro_reg(short *data, unsigned long *timestamp);
109int mpu_get_accel_reg(short *data, unsigned long *timestamp);
110int mpu_get_compass_reg(short *data, unsigned long *timestamp);
111int mpu_get_temperature(long *data, unsigned long *timestamp);
112
113int mpu_get_int_status(short *status);
114int mpu_read_fifo(short *gyro, short *accel, unsigned long *timestamp,
115 unsigned char *sensors, unsigned char *more);
116int mpu_read_fifo_stream(unsigned short length, unsigned char *data,
117 unsigned char *more);
118int mpu_reset_fifo(void);
119
120int mpu_write_mem(unsigned short mem_addr, unsigned short length,
121 unsigned char *data);
122int mpu_read_mem(unsigned short mem_addr, unsigned short length,
123 unsigned char *data);
124int mpu_load_firmware(unsigned short length, const unsigned char *firmware,
125 unsigned short start_addr, unsigned short sample_rate);
126
127int mpu_reg_dump(void);
128int mpu_read_reg(unsigned char reg, unsigned char *data);
129int mpu_run_self_test(long *gyro, long *accel);
130int mpu_register_tap_cb(void (*func)(unsigned char, unsigned char));
131//自行添加的一些函数
132void mget_ms(unsigned long *time);
133unsigned short inv_row_2_scale(const signed char *row);
134unsigned short inv_orientation_matrix_to_scalar(const signed char *mtx);
135u8 run_self_test(void);
136u8 mpu_dmp_init(void);
137u8 mpu_dmp_get_data(float *pitch,float *roll,float *yaw);
138
139#endif /* #ifndef _INV_MPU_H_ */
140
int mpu_set_sample_rate(unsigned short rate)
Set sampling rate. Sampling rate must be between 4Hz and 1kHz.
Definition: inv_mpu.c:1367
int mpu_get_gyro_sens(float *sens)
Get gyro sensitivity scale factor.
Definition: inv_mpu.c:1458
int mpu_get_fifo_config(unsigned char *sensors)
Get current FIFO configuration. sensors can contain a combination of the following flags: INV_X_GYR...
Definition: inv_mpu.c:1516
int mpu_get_int_status(short *status)
Read the MPU interrupt status registers.
Definition: inv_mpu.c:1669
int mpu_register_tap_cb(void(*func)(unsigned char, unsigned char))
int mpu_reg_dump(void)
Register dump for testing.
Definition: inv_mpu.c:713
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...
Definition: inv_mpu.c:1779
int mpu_get_sample_rate(unsigned short *rate)
Get sampling rate.
Definition: inv_mpu.c:1352
int mpu_set_accel_fsr(unsigned char fsr)
Set the accel full-scale range.
Definition: inv_mpu.c:1246
unsigned short inv_row_2_scale(const signed char *row)
Definition: inv_mpu.c:2914
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...
Definition: inv_mpu.c:1698
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....
Definition: inv_mpu.c:2304
int mpu_set_bypass(unsigned char bypass_on)
Set device to bypass mode.
Definition: inv_mpu.c:1817
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...
Definition: inv_mpu.c:2169
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...
Definition: inv_mpu.c:888
unsigned short inv_orientation_matrix_to_scalar(const signed char *mtx)
Definition: inv_mpu.c:2898
unsigned char lp_exit
Definition: inv_mpu.h:41
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 ...
Definition: inv_mpu.c:1043
const struct gyro_reg_s reg
Definition: inv_mpu.c:489
int mpu_get_gyro_reg(short *data, unsigned long *timestamp)
Read raw gyro data directly from the registers.
Definition: inv_mpu.c:972
int mpu_set_lpf(unsigned short lpf)
Set digital low pass filter. The following LPF settings are supported: 188, 98, 42,...
Definition: inv_mpu.c:1319
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.
Definition: inv_mpu.c:735
unsigned short pin
Definition: inv_mpu.h:40
int mpu_get_accel_sens(unsigned short *sens)
Get accel sensitivity scale factor.
Definition: inv_mpu.c:1484
int mpu_set_int_latched(unsigned char enable)
Enable latched interrupts. Any MPU register will clear the interrupt.
Definition: inv_mpu.c:1879
int mpu_get_compass_reg(short *data, unsigned long *timestamp)
Read raw compass data.
Definition: inv_mpu.c:2535
int mpu_set_dmp_state(unsigned char enable)
Enable/disable DMP support.
Definition: inv_mpu.c:2377
int mpu_set_sensors(unsigned char sensors)
Turn specific sensors on/off. sensors can contain a combination of the following flags: INV_X_GYRO,...
Definition: inv_mpu.c:1592
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...
Definition: inv_mpu.c:1436
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...
Definition: inv_mpu.c:2642
int mpu_load_firmware(unsigned short length, const unsigned char *firmware, unsigned short start_addr, unsigned short sample_rate)
Load and verify DMP image.
Definition: inv_mpu.c:2336
int mpu_init_slave(void)
void(* cb)(void)
Definition: inv_mpu.h:39
unsigned char active_low
Definition: inv_mpu.h:42
int mpu_get_temperature(long *data, unsigned long *timestamp)
Read temperature data directly from the registers.
Definition: inv_mpu.c:1018
int mpu_get_lpf(unsigned short *lpf)
Get the current DLPF setting.
Definition: inv_mpu.c:1283
int mpu_get_compass_sample_rate(unsigned short *rate)
Get compass sampling rate.
Definition: inv_mpu.c:1414
int mpu_get_accel_fsr(unsigned char *fsr)
Get the accel full-scale range.
Definition: inv_mpu.c:1218
int mpu_configure_fifo(unsigned char sensors)
Select which sensors are pushed to FIFO. sensors can contain a combination of the following flags: ...
Definition: inv_mpu.c:1531
int mpu_init(void)
Initialize hardware. Initial configuration: Gyro FSR: +/- 2000DPS Accel FSR +/- 2G DLPF: 42Hz FIFO ra...
Definition: inv_mpu.c:757
u8 mpu_dmp_get_data(float *pitch, float *roll, float *yaw)
Definition: inv_mpu.c:2970
int mpu_set_int_level(unsigned char active_low)
Set interrupt level.
Definition: inv_mpu.c:1867
int mpu_set_gyro_fsr(unsigned short fsr)
Set the gyro full-scale range.
Definition: inv_mpu.c:1181
int mpu_get_compass_fsr(unsigned short *fsr)
Get the compass full-scale range.
Definition: inv_mpu.c:2588
int mpu_get_accel_reg(short *data, unsigned long *timestamp)
Read raw accel data directly from the registers.
Definition: inv_mpu.c:995
int mpu_get_power_state(unsigned char *power_on)
Get current power state.
Definition: inv_mpu.c:1573
int mpu_reset_fifo(void)
Reset FIFO read/write pointers.
Definition: inv_mpu.c:1092
int mpu_get_gyro_fsr(unsigned short *fsr)
Get the gyro full-scale range.
Definition: inv_mpu.c:1154
void mget_ms(unsigned long *time)
Definition: inv_mpu.c:2933
u8 mpu_dmp_init(void)
Definition: inv_mpu.c:2937
int mpu_get_dmp_state(unsigned char *enabled)
Get DMP state.
Definition: inv_mpu.c:2416
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....
Definition: inv_mpu.c:2271
u8 run_self_test(void)
Definition: inv_mpu.c:2874
uint8_t u8
8位无符号数类型
Definition: varint.h:40