Embedded MotionDriver 6.1 Sourced from InvenSense

Embed: (wiki syntax)

« Back to documentation index

Sensor Driver Layer

Sensor Driver Layer

Hardware drivers to communicate with sensors via I2C. More...

Files

file  inv_mpu.c
 

An I2C-based driver for Invensense gyroscopes.


file  inv_mpu.h
 

An I2C-based driver for Invensense gyroscopes.


file  inv_mpu_dmp_motion_driver.c
 

DMP image and interface functions.


file  inv_mpu_dmp_motion_driver.h
 

DMP image and interface functions.


Functions

static int set_int_enable (unsigned char enable)
 Enable/disable data ready interrupt.
int mpu_reg_dump (void)
 Register dump for testing.
int mpu_read_reg (unsigned char reg, unsigned char *data)
 Read from a single register.
int mpu_init (struct int_param_s *int_param)
 Initialize hardware.
int mpu_lp_accel_mode (unsigned short rate)
 Enter low-power accel-only mode.
int mpu_get_gyro_reg (short *data, unsigned long *timestamp)
 Read raw gyro data directly from the registers.
int mpu_get_accel_reg (short *data, unsigned long *timestamp)
 Read raw accel data directly from the registers.
int mpu_get_temperature (long *data, unsigned long *timestamp)
 Read temperature data directly from the registers.
int mpu_read_6500_accel_bias (long *accel_bias)
 Read biases to the accel bias 6500 registers.
int mpu_read_6050_accel_bias (long *accel_bias)
 Read biases to the accel bias 6050 registers.
int mpu_set_gyro_bias_reg (long *gyro_bias)
 Push biases to the gyro bias 6500/6050 registers.
int mpu_set_accel_bias_6050_reg (const long *accel_bias)
 Push biases to the accel bias 6050 registers.
int mpu_set_accel_bias_6500_reg (const long *accel_bias)
 Push biases to the accel bias 6500 registers.
int mpu_reset_fifo (void)
 Reset FIFO read/write pointers.
int mpu_get_gyro_fsr (unsigned short *fsr)
 Get the gyro full-scale range.
int mpu_set_gyro_fsr (unsigned short fsr)
 Set the gyro full-scale range.
int mpu_get_accel_fsr (unsigned char *fsr)
 Get the accel full-scale range.
int mpu_set_accel_fsr (unsigned char fsr)
 Set the accel full-scale range.
int mpu_get_lpf (unsigned short *lpf)
 Get the current DLPF setting.
int mpu_set_lpf (unsigned short lpf)
 Set digital low pass filter.
int mpu_get_sample_rate (unsigned short *rate)
 Get sampling rate.
int mpu_set_sample_rate (unsigned short rate)
 Set sampling rate.
int mpu_get_compass_sample_rate (unsigned short *rate)
 Get compass sampling rate.
int mpu_set_compass_sample_rate (unsigned short rate)
 Set compass sampling rate.
int mpu_get_gyro_sens (float *sens)
 Get gyro sensitivity scale factor.
int mpu_get_accel_sens (unsigned short *sens)
 Get accel sensitivity scale factor.
int mpu_get_fifo_config (unsigned char *sensors)
 Get current FIFO configuration.
int mpu_configure_fifo (unsigned char sensors)
 Select which sensors are pushed to FIFO.
int mpu_get_power_state (unsigned char *power_on)
 Get current power state.
int mpu_set_sensors (unsigned char sensors)
 Turn specific sensors on/off.
int mpu_get_int_status (short *status)
 Read the MPU interrupt status registers.
int mpu_read_fifo (short *gyro, short *accel, unsigned long *timestamp, unsigned char *sensors, unsigned char *more)
 Get one packet from the FIFO.
int mpu_read_fifo_stream (unsigned short length, unsigned char *data, unsigned char *more)
 Get one unparsed packet from the FIFO.
int mpu_set_bypass (unsigned char bypass_on)
 Set device to bypass mode.
int mpu_set_int_level (unsigned char active_low)
 Set interrupt level.
int mpu_set_int_latched (unsigned char enable)
 Enable latched interrupts.
int mpu_run_6500_self_test (long *gyro, long *accel, unsigned char debug)
 Trigger gyro/accel/compass self-test for MPU6500/MPU9250 On success/error, the self-test returns a mask representing the sensor(s) that failed.
int mpu_write_mem (unsigned short mem_addr, unsigned short length, unsigned char *data)
 Write to the DMP memory.
int mpu_read_mem (unsigned short mem_addr, unsigned short length, unsigned char *data)
 Read from the DMP memory.
int mpu_load_firmware (unsigned short length, const unsigned char *firmware, unsigned short start_addr, unsigned short sample_rate)
 Load and verify DMP image.
int mpu_set_dmp_state (unsigned char enable)
 Enable/disable DMP support.
int mpu_get_dmp_state (unsigned char *enabled)
 Get DMP state.
int mpu_get_compass_reg (short *data, unsigned long *timestamp)
 Read raw compass data.
int mpu_get_compass_fsr (unsigned short *fsr)
 Get the compass full-scale range.
int mpu_lp_motion_interrupt (unsigned short thresh, unsigned char time, unsigned short lpa_freq)
 Enters LP accel motion interrupt mode.
int dmp_load_motion_driver_firmware (void)
 Load the DMP with this image.
int dmp_set_orientation (unsigned short orient)
 Push gyro and accel orientation to the DMP.
int dmp_set_gyro_bias (long *bias)
 Push gyro biases to the DMP.
int dmp_set_accel_bias (long *bias)
 Push accel biases to the DMP.
int dmp_set_fifo_rate (unsigned short rate)
 Set DMP output rate.
int dmp_get_fifo_rate (unsigned short *rate)
 Get DMP output rate.
int dmp_set_tap_thresh (unsigned char axis, unsigned short thresh)
 Set tap threshold for a specific axis.
int dmp_set_tap_axes (unsigned char axis)
 Set which axes will register a tap.
int dmp_set_tap_count (unsigned char min_taps)
 Set minimum number of taps needed for an interrupt.
int dmp_set_tap_time (unsigned short time)
 Set length between valid taps.
int dmp_set_tap_time_multi (unsigned short time)
 Set max time between taps to register as a multi-tap.
int dmp_set_shake_reject_thresh (long sf, unsigned short thresh)
 Set shake rejection threshold.
int dmp_set_shake_reject_time (unsigned short time)
 Set shake rejection time.
int dmp_set_shake_reject_timeout (unsigned short time)
 Set shake rejection timeout.
int dmp_get_pedometer_step_count (unsigned long *count)
 Get current step count.
int dmp_set_pedometer_step_count (unsigned long count)
 Overwrite current step count.
int dmp_get_pedometer_walk_time (unsigned long *time)
 Get duration of walking time.
int dmp_set_pedometer_walk_time (unsigned long time)
 Overwrite current walk time.
int dmp_enable_feature (unsigned short mask)
 Enable DMP features.
int dmp_get_enabled_features (unsigned short *mask)
 Get list of currently enabled DMP features.
int dmp_enable_gyro_cal (unsigned char enable)
 Calibrate the gyro data in the DMP.
int dmp_enable_lp_quat (unsigned char enable)
 Generate 3-axis quaternions from the DMP.
int dmp_enable_6x_lp_quat (unsigned char enable)
 Generate 6-axis quaternions from the DMP.
static int decode_gesture (unsigned char *gesture)
 Decode the four-byte gesture data and execute any callbacks.
int dmp_set_interrupt_mode (unsigned char mode)
 Specify when a DMP interrupt should occur.
int dmp_read_fifo (short *gyro, short *accel, long *quat, unsigned long *timestamp, short *sensors, unsigned char *more)
 Get one packet from the FIFO.
int dmp_register_tap_cb (void(*func)(unsigned char, unsigned char))
 Register a function to be executed on a tap event.
int dmp_register_android_orient_cb (void(*func)(unsigned char))
 Register a function to be executed on a android orientation event.

Detailed Description

Hardware drivers to communicate with sensors via I2C.


Function Documentation

static int decode_gesture ( unsigned char *  gesture ) [static]

Decode the four-byte gesture data and execute any callbacks.

Parameters:
[in]gestureGesture data from DMP packet.
Returns:
0 if successful.

Definition at line 1194 of file inv_mpu_dmp_motion_driver.c.

int dmp_enable_6x_lp_quat ( unsigned char  enable )

Generate 6-axis quaternions from the DMP.

In this driver, the 3-axis and 6-axis DMP quaternion features are mutually exclusive.

Parameters:
[in]enable1 to enable 6-axis quaternion.
Returns:
0 if successful.

Definition at line 1173 of file inv_mpu_dmp_motion_driver.c.

int dmp_enable_feature ( unsigned short  mask )

Enable DMP features.

The following #define's are used in the input mask:
DMP_FEATURE_TAP
DMP_FEATURE_ANDROID_ORIENT
DMP_FEATURE_LP_QUAT
DMP_FEATURE_6X_LP_QUAT
DMP_FEATURE_GYRO_CAL
DMP_FEATURE_SEND_RAW_ACCEL
DMP_FEATURE_SEND_RAW_GYRO
NOTE: DMP_FEATURE_LP_QUAT and DMP_FEATURE_6X_LP_QUAT are mutually exclusive.
NOTE: DMP_FEATURE_SEND_RAW_GYRO and DMP_FEATURE_SEND_CAL_GYRO are also mutually exclusive.

Parameters:
[in]maskMask of features to enable.
Returns:
0 if successful.

Definition at line 994 of file inv_mpu_dmp_motion_driver.c.

int dmp_enable_gyro_cal ( unsigned char  enable )

Calibrate the gyro data in the DMP.

After eight seconds of no motion, the DMP will compute gyro biases and subtract them from the quaternion output. If dmp_enable_feature is called with DMP_FEATURE_SEND_CAL_GYRO, the biases will also be subtracted from the gyro output.

Parameters:
[in]enable1 to enable gyro calibration.
Returns:
0 if successful.

Definition at line 1131 of file inv_mpu_dmp_motion_driver.c.

int dmp_enable_lp_quat ( unsigned char  enable )

Generate 3-axis quaternions from the DMP.

In this driver, the 3-axis and 6-axis DMP quaternion features are mutually exclusive.

Parameters:
[in]enable1 to enable 3-axis quaternion.
Returns:
0 if successful.

Definition at line 1149 of file inv_mpu_dmp_motion_driver.c.

int dmp_get_enabled_features ( unsigned short *  mask )

Get list of currently enabled DMP features.

Parameters:
[out]Maskof enabled features.
Returns:
0 if successful.

Definition at line 1116 of file inv_mpu_dmp_motion_driver.c.

int dmp_get_fifo_rate ( unsigned short *  rate )

Get DMP output rate.

Parameters:
[out]rateCurrent fifo rate (Hz).
Returns:
0 if successful.

Definition at line 707 of file inv_mpu_dmp_motion_driver.c.

int dmp_get_pedometer_step_count ( unsigned long *  count )

Get current step count.

Parameters:
[out]countNumber of steps detected.
Returns:
0 if successful.

Definition at line 907 of file inv_mpu_dmp_motion_driver.c.

int dmp_get_pedometer_walk_time ( unsigned long *  time )

Get duration of walking time.

Parameters:
[in]timeWalk time in milliseconds.
Returns:
0 if successful.

Definition at line 944 of file inv_mpu_dmp_motion_driver.c.

int dmp_load_motion_driver_firmware ( void   )

Load the DMP with this image.

Returns:
0 if successful.

Definition at line 509 of file inv_mpu_dmp_motion_driver.c.

int dmp_read_fifo ( short *  gyro,
short *  accel,
long *  quat,
unsigned long *  timestamp,
short *  sensors,
unsigned char *  more 
)

Get one packet from the FIFO.

If sensors does not contain a particular sensor, disregard the data returned to that pointer.
sensors can contain a combination of the following flags:
INV_X_GYRO, INV_Y_GYRO, INV_Z_GYRO
INV_XYZ_GYRO
INV_XYZ_ACCEL
INV_WXYZ_QUAT
If the FIFO has no new data, sensors will be zero.
If the FIFO is disabled, sensors will be zero and this function will return a non-zero error code.

Parameters:
[out]gyroGyro data in hardware units.
[out]accelAccel data in hardware units.
[out]quat3-axis quaternion data in hardware units.
[out]timestampTimestamp in milliseconds.
[out]sensorsMask of sensors read from FIFO.
[out]moreNumber of remaining packets.
Returns:
0 if successful.

Definition at line 1265 of file inv_mpu_dmp_motion_driver.c.

int dmp_register_android_orient_cb ( void(*)(unsigned char)  func )

Register a function to be executed on a android orientation event.

Parameters:
[in]funcCallback function.
Returns:
0 if successful.

Definition at line 1369 of file inv_mpu_dmp_motion_driver.c.

int dmp_register_tap_cb ( void(*)(unsigned char, unsigned char)  func )

Register a function to be executed on a tap event.

The tap direction is represented by one of the following:
TAP_X_UP
TAP_X_DOWN
TAP_Y_UP
TAP_Y_DOWN
TAP_Z_UP
TAP_Z_DOWN

Parameters:
[in]funcCallback function.
Returns:
0 if successful.

Definition at line 1358 of file inv_mpu_dmp_motion_driver.c.

int dmp_set_accel_bias ( long *  bias )

Push accel biases to the DMP.

These biases will be removed from the DMP 6-axis quaternion.

Parameters:
[in]biasAccel biases in q16.
Returns:
0 if successful.

Definition at line 629 of file inv_mpu_dmp_motion_driver.c.

int dmp_set_fifo_rate ( unsigned short  rate )

Set DMP output rate.

Only used when DMP is on.

Parameters:
[in]rateDesired fifo rate (Hz).
Returns:
0 if successful.

Definition at line 681 of file inv_mpu_dmp_motion_driver.c.

int dmp_set_gyro_bias ( long *  bias )

Push gyro biases to the DMP.

Because the gyro integration is handled in the DMP, any gyro biases calculated by the MPL should be pushed down to DMP memory to remove 3-axis quaternion drift.
NOTE: If the DMP-based gyro calibration is enabled, the DMP will overwrite the biases written to this location once a new one is computed.

Parameters:
[in]biasGyro biases in q16.
Returns:
0 if successful.

Definition at line 577 of file inv_mpu_dmp_motion_driver.c.

int dmp_set_interrupt_mode ( unsigned char  mode )

Specify when a DMP interrupt should occur.

A DMP interrupt can be configured to trigger on either of the two conditions below:
a. One FIFO period has elapsed (set by mpu_set_sample_rate).
b. A tap event has been detected.

Parameters:
[in]modeDMP_INT_GESTURE or DMP_INT_CONTINUOUS.
Returns:
0 if successful.

Definition at line 1226 of file inv_mpu_dmp_motion_driver.c.

int dmp_set_orientation ( unsigned short  orient )

Push gyro and accel orientation to the DMP.

The orientation is represented here as the output of inv_orientation_matrix_to_scalar.

Parameters:
[in]orientGyro and accel orientation in body frame.
Returns:
0 if successful.

Definition at line 522 of file inv_mpu_dmp_motion_driver.c.

int dmp_set_pedometer_step_count ( unsigned long  count )

Overwrite current step count.

WARNING: This function writes to DMP memory and could potentially encounter a race condition if called while the pedometer is enabled.

Parameters:
[in]countNew step count.
Returns:
0 if successful.

Definition at line 928 of file inv_mpu_dmp_motion_driver.c.

int dmp_set_pedometer_walk_time ( unsigned long  time )

Overwrite current walk time.

WARNING: This function writes to DMP memory and could potentially encounter a race condition if called while the pedometer is enabled.

Parameters:
[in]timeNew walk time in milliseconds.

Definition at line 964 of file inv_mpu_dmp_motion_driver.c.

int dmp_set_shake_reject_thresh ( long  sf,
unsigned short  thresh 
)

Set shake rejection threshold.

If the DMP detects a gyro sample larger than thresh, taps are rejected.

Parameters:
[in]sfGyro scale factor.
[in]threshGyro threshold in dps.
Returns:
0 if successful.

Definition at line 855 of file inv_mpu_dmp_motion_driver.c.

int dmp_set_shake_reject_time ( unsigned short  time )

Set shake rejection time.

Sets the length of time that the gyro must be outside of the threshold set by gyro_set_shake_reject_thresh before taps are rejected. A mandatory 60 ms is added to this parameter.

Parameters:
[in]timeTime in milliseconds.
Returns:
0 if successful.

Definition at line 874 of file inv_mpu_dmp_motion_driver.c.

int dmp_set_shake_reject_timeout ( unsigned short  time )

Set shake rejection timeout.

Sets the length of time after a shake rejection that the gyro must stay inside of the threshold before taps can be detected again. A mandatory 60 ms is added to this parameter.

Parameters:
[in]timeTime in milliseconds.
Returns:
0 if successful.

Definition at line 892 of file inv_mpu_dmp_motion_driver.c.

int dmp_set_tap_axes ( unsigned char  axis )

Set which axes will register a tap.

Parameters:
[in]axis1, 2, and 4 for XYZ, respectively.
Returns:
0 if successful.

Definition at line 785 of file inv_mpu_dmp_motion_driver.c.

int dmp_set_tap_count ( unsigned char  min_taps )

Set minimum number of taps needed for an interrupt.

Parameters:
[in]min_tapsMinimum consecutive taps (1-4).
Returns:
0 if successful.

Definition at line 803 of file inv_mpu_dmp_motion_driver.c.

int dmp_set_tap_thresh ( unsigned char  axis,
unsigned short  thresh 
)

Set tap threshold for a specific axis.

Parameters:
[in]axis1, 2, and 4 for XYZ accel, respectively.
[in]threshTap threshold, in mg/ms.
Returns:
0 if successful.

Definition at line 719 of file inv_mpu_dmp_motion_driver.c.

int dmp_set_tap_time ( unsigned short  time )

Set length between valid taps.

Parameters:
[in]timeMilliseconds between taps.
Returns:
0 if successful.

Definition at line 821 of file inv_mpu_dmp_motion_driver.c.

int dmp_set_tap_time_multi ( unsigned short  time )

Set max time between taps to register as a multi-tap.

Parameters:
[in]timeMax milliseconds between taps.
Returns:
0 if successful.

Definition at line 837 of file inv_mpu_dmp_motion_driver.c.

int mpu_configure_fifo ( unsigned char  sensors )

Select which sensors are pushed to FIFO.

sensors can contain a combination of the following flags:
INV_X_GYRO, INV_Y_GYRO, INV_Z_GYRO
INV_XYZ_GYRO
INV_XYZ_ACCEL

Parameters:
[in]sensorsMask of sensors to push to FIFO.
Returns:
0 if successful.

Definition at line 1563 of file inv_mpu.c.

int mpu_get_accel_fsr ( unsigned char *  fsr )

Get the accel full-scale range.

Parameters:
[out]fsrCurrent full-scale range.
Returns:
0 if successful.

Definition at line 1250 of file inv_mpu.c.

int mpu_get_accel_reg ( short *  data,
unsigned long *  timestamp 
)

Read raw accel data directly from the registers.

Parameters:
[out]dataRaw data in hardware units.
[out]timestampTimestamp in milliseconds. Null if not needed.
Returns:
0 if successful.

Definition at line 915 of file inv_mpu.c.

int mpu_get_accel_sens ( unsigned short *  sens )

Get accel sensitivity scale factor.

Parameters:
[out]sensConversion from hardware units to g's.
Returns:
0 if successful.

Definition at line 1516 of file inv_mpu.c.

int mpu_get_compass_fsr ( unsigned short *  fsr )

Get the compass full-scale range.

Parameters:
[out]fsrCurrent full-scale range.
Returns:
0 if successful.

Definition at line 3093 of file inv_mpu.c.

int mpu_get_compass_reg ( short *  data,
unsigned long *  timestamp 
)

Read raw compass data.

Parameters:
[out]dataRaw data in hardware units.
[out]timestampTimestamp in milliseconds. Null if not needed.
Returns:
0 if successful.

Definition at line 3040 of file inv_mpu.c.

int mpu_get_compass_sample_rate ( unsigned short *  rate )

Get compass sampling rate.

Parameters:
[out]rateCurrent compass sampling rate (Hz).
Returns:
0 if successful.

Definition at line 1446 of file inv_mpu.c.

int mpu_get_dmp_state ( unsigned char *  enabled )

Get DMP state.

Parameters:
[out]enabled1 if enabled.
Returns:
0 if successful.

Definition at line 2924 of file inv_mpu.c.

int mpu_get_fifo_config ( unsigned char *  sensors )

Get current FIFO configuration.

sensors can contain a combination of the following flags:
INV_X_GYRO, INV_Y_GYRO, INV_Z_GYRO
INV_XYZ_GYRO
INV_XYZ_ACCEL

Parameters:
[out]sensorsMask of sensors in FIFO.
Returns:
0 if successful.

Definition at line 1548 of file inv_mpu.c.

int mpu_get_gyro_fsr ( unsigned short *  fsr )

Get the gyro full-scale range.

Parameters:
[out]fsrCurrent full-scale range.
Returns:
0 if successful.

Definition at line 1186 of file inv_mpu.c.

int mpu_get_gyro_reg ( short *  data,
unsigned long *  timestamp 
)

Read raw gyro data directly from the registers.

Parameters:
[out]dataRaw data in hardware units.
[out]timestampTimestamp in milliseconds. Null if not needed.
Returns:
0 if successful.

Definition at line 892 of file inv_mpu.c.

int mpu_get_gyro_sens ( float *  sens )

Get gyro sensitivity scale factor.

Parameters:
[out]sensConversion from hardware units to dps.
Returns:
0 if successful.

Definition at line 1490 of file inv_mpu.c.

int mpu_get_int_status ( short *  status )

Read the MPU interrupt status registers.

Parameters:
[out]statusMask of interrupt bits.
Returns:
0 if successful.

Definition at line 1701 of file inv_mpu.c.

int mpu_get_lpf ( unsigned short *  lpf )

Get the current DLPF setting.

Parameters:
[out]lpfCurrent LPF setting. 0 if successful.

Definition at line 1315 of file inv_mpu.c.

int mpu_get_power_state ( unsigned char *  power_on )

Get current power state.

Parameters:
[in]power_on1 if turned on, 0 if suspended.
Returns:
0 if successful.

Definition at line 1605 of file inv_mpu.c.

int mpu_get_sample_rate ( unsigned short *  rate )

Get sampling rate.

Parameters:
[out]rateCurrent sampling rate (Hz).
Returns:
0 if successful.

Definition at line 1384 of file inv_mpu.c.

int mpu_get_temperature ( long *  data,
unsigned long *  timestamp 
)

Read temperature data directly from the registers.

Parameters:
[out]dataData in q16 format.
[out]timestampTimestamp in milliseconds. Null if not needed.
Returns:
0 if successful.

Definition at line 938 of file inv_mpu.c.

int mpu_init ( struct int_param_s *  int_param )

Initialize hardware.

Initial configuration:
Gyro FSR: +/- 2000DPS
Accel FSR +/- 2G
DLPF: 42Hz
FIFO rate: 50Hz
Clock source: Gyro PLL
FIFO: Disabled.
Data ready interrupt: Disabled, active low, unlatched.

Parameters:
[in]int_paramPlatform-specific parameters to interrupt API.
Returns:
0 if successful.

Definition at line 714 of file inv_mpu.c.

int mpu_load_firmware ( unsigned short  length,
const unsigned char *  firmware,
unsigned short  start_addr,
unsigned short  sample_rate 
)

Load and verify DMP image.

Parameters:
[in]lengthLength of DMP image.
[in]firmwareDMP code.
[in]start_addrStarting address of DMP code memory.
[in]sample_rateFixed sampling rate used when DMP is enabled.
Returns:
0 if successful.

Definition at line 2844 of file inv_mpu.c.

int mpu_lp_accel_mode ( unsigned short  rate )

Enter low-power accel-only mode.

In low-power accel mode, the chip goes to sleep and only wakes up to sample the accelerometer at one of the following frequencies:
MPU6050: 1.25Hz, 5Hz, 20Hz, 40Hz
MPU6500: 1.25Hz, 2.5Hz, 5Hz, 10Hz, 20Hz, 40Hz, 80Hz, 160Hz, 320Hz, 640Hz
If the requested rate is not one listed above, the device will be set to the next highest rate. Requesting a rate above the maximum supported frequency will result in an error.
To select a fractional wake-up frequency, round down the value passed to rate.

Parameters:
[in]rateMinimum sampling rate, or zero to disable LP accel mode.
Returns:
0 if successful.

Definition at line 808 of file inv_mpu.c.

int mpu_lp_motion_interrupt ( unsigned short  thresh,
unsigned char  time,
unsigned short  lpa_freq 
)

Enters LP accel motion interrupt mode.

The behaviour of this feature is very different between the MPU6050 and the MPU6500. Each chip's version of this feature is explained below.


The hardware motion threshold can be between 32mg and 8160mg in 32mg increments.


Low-power accel mode supports the following frequencies:
1.25Hz, 5Hz, 20Hz, 40Hz


MPU6500:
Unlike the MPU6050 version, the hardware does not "lock in" a reference sample. The hardware monitors the accel data and detects any large change over a short period of time.


The hardware motion threshold can be between 4mg and 1020mg in 4mg increments.


MPU6500 Low-power accel mode supports the following frequencies:
1.25Hz, 2.5Hz, 5Hz, 10Hz, 20Hz, 40Hz, 80Hz, 160Hz, 320Hz, 640Hz



NOTES:
The driver will round down thresh to the nearest supported value if an unsupported threshold is selected.
To select a fractional wake-up frequency, round down the value passed to lpa_freq.
The MPU6500 does not support a delay parameter. If this function is used for the MPU6500, the value passed to time will be ignored.
To disable this mode, set lpa_freq to zero. The driver will restore the previous configuration.

Parameters:
[in]threshMotion threshold in mg.
[in]timeDuration in milliseconds that the accel data must exceed thresh before motion is reported.
[in]lpa_freqMinimum sampling rate, or zero to disable.
Returns:
0 if successful.

Definition at line 3141 of file inv_mpu.c.

int mpu_read_6050_accel_bias ( long *  accel_bias )

Read biases to the accel bias 6050 registers.

This function reads from the MPU6050 accel offset cancellations registers. The format are G in +-8G format. The register is initialized with OTP factory trim values.

Parameters:
[in]accel_biasreturned structure with the accel bias
Returns:
0 if successful.

Definition at line 986 of file inv_mpu.c.

int mpu_read_6500_accel_bias ( long *  accel_bias )

Read biases to the accel bias 6500 registers.

This function reads from the MPU6500 accel offset cancellations registers. The format are G in +-8G format. The register is initialized with OTP factory trim values.

Parameters:
[in]accel_biasreturned structure with the accel bias
Returns:
0 if successful.

Definition at line 964 of file inv_mpu.c.

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 returned to that pointer.
sensors can contain a combination of the following flags:
INV_X_GYRO, INV_Y_GYRO, INV_Z_GYRO
INV_XYZ_GYRO
INV_XYZ_ACCEL
If the FIFO has no new data, sensors will be zero.
If the FIFO is disabled, sensors will be zero and this function will return a non-zero error code.

Parameters:
[out]gyroGyro data in hardware units.
[out]accelAccel data in hardware units.
[out]timestampTimestamp in milliseconds.
[out]sensorsMask of sensors read from FIFO.
[out]moreNumber of remaining packets.
Returns:
0 if successful.

Definition at line 1730 of file inv_mpu.c.

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 elsewhere.

Parameters:
[in]lengthLength of one FIFO packet.
[in]dataFIFO packet.
[in]moreNumber of remaining packets.

Definition at line 1811 of file inv_mpu.c.

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. The DMP memory is only accessible when the chip is awake.

Parameters:
[in]mem_addrMemory location (bank << 8 | start address)
[in]lengthNumber of bytes to read.
[out]dataBytes read from memory.
Returns:
0 if successful.

Definition at line 2812 of file inv_mpu.c.

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.

Parameters:
[in]regRegister address.
[out]dataRegister data.
Returns:
0 if successful.

Definition at line 692 of file inv_mpu.c.

int mpu_reg_dump ( void   )

Register dump for testing.

Returns:
0 if successful.

Definition at line 670 of file inv_mpu.c.

int mpu_reset_fifo ( void   )

Reset FIFO read/write pointers.

Returns:
0 if successful.

Definition at line 1124 of file inv_mpu.c.

int mpu_run_6500_self_test ( long *  gyro,
long *  accel,
unsigned char  debug 
)

Trigger gyro/accel/compass self-test for MPU6500/MPU9250 On success/error, the self-test returns a mask representing the sensor(s) that failed.

For each bit, a one (1) represents a "pass" case; conversely, a zero (0) indicates a failure.


The mask is defined as follows:
Bit 0: Gyro.
Bit 1: Accel.
Bit 2: Compass.

Parameters:
[out]gyroGyro biases in q16 format.
[out]accelAccel biases (if applicable) in q16 format.
[in]debugDebug flag used to print out more detailed logs. Must first set up logging in Motion Driver.
Returns:
Result mask (see above).

Definition at line 2554 of file inv_mpu.c.

int mpu_set_accel_bias_6050_reg ( const long *  accel_bias )

Push biases to the accel bias 6050 registers.

This function expects biases relative to the current sensor output, and these biases will be added to the factory-supplied values. Bias inputs are LSB in +-8G format.

Parameters:
[in]accel_biasNew biases.
Returns:
0 if successful.

Definition at line 1052 of file inv_mpu.c.

int mpu_set_accel_bias_6500_reg ( const long *  accel_bias )

Push biases to the accel bias 6500 registers.

This function expects biases relative to the current sensor output, and these biases will be added to the factory-supplied values. Bias inputs are LSB in +-8G format.

Parameters:
[in]accel_biasNew biases.
Returns:
0 if successful.

Definition at line 1090 of file inv_mpu.c.

int mpu_set_accel_fsr ( unsigned char  fsr )

Set the accel full-scale range.

Parameters:
[in]fsrDesired full-scale range.
Returns:
0 if successful.

Definition at line 1278 of file inv_mpu.c.

int mpu_set_bypass ( unsigned char  bypass_on )

Set device to bypass mode.

Parameters:
[in]bypass_on1 to enable bypass mode.
Returns:
0 if successful.

Definition at line 1849 of file inv_mpu.c.

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 maximum of 100Hz. The actual rate can be set to a fraction of the gyro sampling rate.


WARNING: The new rate may be different than what was requested. Call mpu_get_compass_sample_rate to check the actual setting.

Parameters:
[in]rateDesired compass sampling rate (Hz).
Returns:
0 if successful.

Definition at line 1468 of file inv_mpu.c.

int mpu_set_dmp_state ( unsigned char  enable )

Enable/disable DMP support.

Parameters:
[in]enable1 to turn on the DMP.
Returns:
0 if successful.

Definition at line 2885 of file inv_mpu.c.

int mpu_set_gyro_bias_reg ( long *  gyro_bias )

Push biases to the gyro bias 6500/6050 registers.

This function expects biases relative to the current sensor output, and these biases will be added to the factory-supplied values. Bias inputs are LSB in +-1000dps format.

Parameters:
[in]gyro_biasNew biases.
Returns:
0 if successful.

Definition at line 1022 of file inv_mpu.c.

int mpu_set_gyro_fsr ( unsigned short  fsr )

Set the gyro full-scale range.

Parameters:
[in]fsrDesired full-scale range.
Returns:
0 if successful.

Definition at line 1213 of file inv_mpu.c.

int mpu_set_int_latched ( unsigned char  enable )

Enable latched interrupts.

Any MPU register will clear the interrupt.

Parameters:
[in]enable1 to enable, 0 to disable.
Returns:
0 if successful.

Definition at line 1911 of file inv_mpu.c.

int mpu_set_int_level ( unsigned char  active_low )

Set interrupt level.

Parameters:
[in]active_low1 for active low, 0 for active high.
Returns:
0 if successful.

Definition at line 1899 of file inv_mpu.c.

int mpu_set_lpf ( unsigned short  lpf )

Set digital low pass filter.

The following LPF settings are supported: 188, 98, 42, 20, 10, 5.

Parameters:
[in]lpfDesired LPF setting.
Returns:
0 if successful.

Definition at line 1351 of file inv_mpu.c.

int mpu_set_sample_rate ( unsigned short  rate )

Set sampling rate.

Sampling rate must be between 4Hz and 1kHz.

Parameters:
[in]rateDesired sampling rate (Hz).
Returns:
0 if successful.

Definition at line 1399 of file inv_mpu.c.

int mpu_set_sensors ( unsigned char  sensors )

Turn specific sensors on/off.

sensors can contain a combination of the following flags:
INV_X_GYRO, INV_Y_GYRO, INV_Z_GYRO
INV_XYZ_GYRO
INV_XYZ_ACCEL
INV_XYZ_COMPASS

Parameters:
[in]sensorsMask of sensors to wake.
Returns:
0 if successful.

Definition at line 1624 of file inv_mpu.c.

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. The DMP memory is only accessible when the chip is awake.

Parameters:
[in]mem_addrMemory location (bank << 8 | start address)
[in]lengthNumber of bytes to write.
[in]dataBytes to write to memory.
Returns:
0 if successful.

Definition at line 2779 of file inv_mpu.c.

static int set_int_enable ( unsigned char  enable ) [static]

Enable/disable data ready interrupt.

If the DMP is on, the DMP interrupt is enabled. Otherwise, the data ready interrupt is used.

Parameters:
[in]enable1 to enable interrupt.
Returns:
0 if successful.

Definition at line 638 of file inv_mpu.c.