Contiki-NG
Files | Enumerations | Functions

 Driver for the Invensense MPU-9250 Motion Processing Unit.
More...

Files

 
 

Enumerations

enum  MPU_9250_SENSOR_TYPE {
  MPU_9250_SENSOR_TYPE_NONE = (0), MPU_9250_SENSOR_TYPE_GYRO_X = (1 << 0), MPU_9250_SENSOR_TYPE_GYRO_Y = (1 << 1), MPU_9250_SENSOR_TYPE_GYRO_Z = (1 << 2),
  MPU_9250_SENSOR_TYPE_ACC_X = (1 << 3), MPU_9250_SENSOR_TYPE_ACC_Y = (1 << 4), MPU_9250_SENSOR_TYPE_ACC_Z = (1 << 5), MPU_9250_SENSOR_TYPE_GYRO,
  MPU_9250_SENSOR_TYPE_ACC, MPU_9250_SENSOR_TYPE_ALL
}
 

Functions

static bool i2c_write_read (void *wbuf, size_t wcount, void *rbuf, size_t rcount)
 Setup and peform an I2C transaction. More...
 
static bool i2c_write (void *wbuf, size_t wcount)
 Peform a write only I2C transaction. More...
 
static bool i2c_read (void *rbuf, size_t rcount)
 Peform a read only I2C transaction. More...
 
static bool sensor_init (void)
 Initialize the MPU-9250 sensor driver. More...
 
static void sensor_sleep (void)
 Place the sensor in low-power mode.
 
static void sensor_wakeup (void)
 Wakeup the sensor from low-power mode.
 
static bool sensor_data_ready (uint8_t *int_status)
 Check whether a data or wake on motion interrupt has occurred. More...
 
static bool acc_read (uint8_t int_status, uint16_t *data)
 Read data from the accelerometer, total of 3 words (X, Y, Z). More...
 
static bool gyro_read (uint8_t int_status, uint16_t *data)
 Read data from the accelerometer, total of 3 words (X, Y, Z). More...
 
static int32_t acc_convert (int32_t raw_data)
 Convert accelerometer raw reading to a value in G. More...
 
static int32_t gyro_convert (int32_t raw_data)
 Convert gyro raw reading to a value in deg/sec. More...
 
static int value (int type)
 Returns a reading from the sensor. More...
 
static int configure (int type, int enable)
 Configuration function for the MPU9250 sensor. More...
 
static int status (int type)
 Returns the status of the sensor. More...
 

Detailed Description

 Driver for the Invensense MPU-9250 Motion Processing Unit.

Due to the time required between triggering a reading and the reading becoming available, this driver is meant to be used in an asynchronous fashion. The caller must first activate the sensor by calling

mpu_9250_sensor.configure(SENSORS_ACTIVE, xyz);

The value for the xyz arguments depends on the required readings. If the caller intends to read both the accelerometer as well as the gyro then xyz should be MPU_9250_SENSOR_TYPE_ALL. If the caller only needs to take a reading from one of the two elements, xyz should be one of MPU_9250_SENSOR_TYPE_ACC or MPU_9250_SENSOR_TYPE_GYRO

Calling configure() will power up the sensor and initialise it. When the sensor is ready to provide readings, the driver will generate a sensors_changed event.

Calls to status() will return the driver's state which could indicate that the sensor is off, booting or on.

Once a reading has been taken, the caller has two options:

Enumeration Type Documentation

◆ MPU_9250_SENSOR_TYPE

Enumerator
MPU_9250_SENSOR_TYPE_NONE 

0b000000 = 0x00

MPU_9250_SENSOR_TYPE_GYRO_X 

0b000001 = 0x01

MPU_9250_SENSOR_TYPE_GYRO_Y 

0b000010 = 0x02

MPU_9250_SENSOR_TYPE_GYRO_Z 

0b000100 = 0x04

MPU_9250_SENSOR_TYPE_ACC_X 

0b001000 = 0x08

MPU_9250_SENSOR_TYPE_ACC_Y 

0b010000 = 0x10

MPU_9250_SENSOR_TYPE_ACC_Z 

0b100000 = 0x20

MPU_9250_SENSOR_TYPE_GYRO 

0b000111 = 0x07

MPU_9250_SENSOR_TYPE_ACC 

0b111000 = 0x38

MPU_9250_SENSOR_TYPE_ALL 

0b111111 = 0x3F

Definition at line 90 of file mpu-9250-sensor.h.

Function Documentation

◆ acc_convert()

static int32_t acc_convert ( int32_t  raw_data)
static

Convert accelerometer raw reading to a value in G.

Parameters
raw_dataThe raw accelerometer reading.
Returns
The converted value.

Definition at line 453 of file mpu-9250-sensor.c.

◆ acc_read()

static bool acc_read ( uint8_t  int_status,
uint16_t *  data 
)
static

Read data from the accelerometer, total of 3 words (X, Y, Z).

Returns
true if a valid reading could be taken; otherwise, false.

Definition at line 406 of file mpu-9250-sensor.c.

◆ configure()

static int configure ( int  type,
int  enable 
)
static

Configuration function for the MPU9250 sensor.

Parameters
typeActivate, enable or disable the sensor. See below.
enableEnable or disable sensor. When type == SENSORS_HW_INIT we turn on the hardware. When type == SENSORS_ACTIVE and enable==1 we enable the sensor. When type == SENSORS_ACTIVE and enable==0 we disable the sensor.

Definition at line 590 of file mpu-9250-sensor.c.

◆ gyro_convert()

static int32_t gyro_convert ( int32_t  raw_data)
static

Convert gyro raw reading to a value in deg/sec.

Parameters
raw_dataThe raw accelerometer reading.
Returns
The converted value.

Definition at line 470 of file mpu-9250-sensor.c.

◆ gyro_read()

static bool gyro_read ( uint8_t  int_status,
uint16_t *  data 
)
static

Read data from the accelerometer, total of 3 words (X, Y, Z).

Returns
true if a valid reading could be taken; otherwise, false.

Definition at line 429 of file mpu-9250-sensor.c.

◆ i2c_read()

static bool i2c_read ( void *  rbuf,
size_t  rcount 
)
inlinestatic

Peform a read only I2C transaction.

Parameters
rbufInput buffer during the I2C transation.
rcountHow many bytes to read into rbuf.
Returns
true if the I2C operation was successful; else, return false.

Definition at line 279 of file mpu-9250-sensor.c.

References i2c_write_read().

◆ i2c_write()

static bool i2c_write ( void *  wbuf,
size_t  wcount 
)
inlinestatic

Peform a write only I2C transaction.

Parameters
wbufOutput buffer during the I2C transation.
wcountHow many bytes in the wbuf.
Returns
true if the I2C operation was successful; else, return false.

Definition at line 267 of file mpu-9250-sensor.c.

References i2c_write_read().

◆ i2c_write_read()

static bool i2c_write_read ( void *  wbuf,
size_t  wcount,
void *  rbuf,
size_t  rcount 
)
static

Setup and peform an I2C transaction.

Parameters
wbufOutput buffer during the I2C transation.
wcountHow many bytes in the wbuf.
rbufInput buffer during the I2C transation.
rcountHow many bytes to read into rbuf.
Returns
true if the I2C operation was successful; else, return false.

Definition at line 247 of file mpu-9250-sensor.c.

Referenced by i2c_read(), and i2c_write().

◆ sensor_data_ready()

static bool sensor_data_ready ( uint8_t *  int_status)
static

Check whether a data or wake on motion interrupt has occurred.

Returns
Return the interrupt status.
     This driver does not use interrupts, however this function allows
     us to determine whether a new sensor reading is available.

Definition at line 393 of file mpu-9250-sensor.c.

◆ sensor_init()

static bool sensor_init ( void  )
static

Initialize the MPU-9250 sensor driver.

Returns
true if I2C operation successful; else, return false.

Definition at line 289 of file mpu-9250-sensor.c.

◆ status()

static int status ( int  type)
static

Returns the status of the sensor.

Parameters
typeSENSORS_ACTIVE or SENSORS_READY
Returns
1 if the sensor is enabled, else 0.

Definition at line 643 of file mpu-9250-sensor.c.

◆ value()

static int value ( int  type)
static

Returns a reading from the sensor.

Parameters
typeMPU_9250_SENSOR_TYPE_ACC_[XYZ] or MPU_9250_SENSOR_TYPE_GYRO_[XYZ].
Returns
Centi-G (ACC) or centi-Deg/Sec (Gyro).

Definition at line 516 of file mpu-9250-sensor.c.