Contiki-NG
Files | Functions

Driver for the Invensense MPU9250 Motion Processing Unit. More...

Files

file  mpu-9250-sensor.c
 Driver for the Sensortag Invensense MPU9250 motion processing unit.
 
file  mpu-9250-sensor.h
 Header file for the Sensortag Invensense MPU9250 motion processing unit.
 

Functions

static void sensor_sleep (void)
 Place the MPU in low power mode.
 
static void sensor_wakeup (void)
 Exit low power mode.
 
static void select_axes (void)
 Select gyro and accelerometer axes.
 
static bool acc_set_range (uint8_t new_range)
 Set the range of the accelerometer. More...
 
static uint8_t int_status (void)
 Check whether a data or wake on motion interrupt has occurred. More...
 
static void enable_sensor (uint16_t axes)
 Enable the MPU. More...
 
static bool acc_read (uint16_t *data)
 Read data from the accelerometer - X, Y, Z - 3 words. More...
 
static bool gyro_read (uint16_t *data)
 Read data from the gyroscope - X, Y, Z - 3 words. More...
 
static float acc_convert (int16_t raw_data)
 Convert accelerometer raw reading to a value in G. More...
 
static float gyro_convert (int16_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 MPU9250 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:

Function Documentation

◆ acc_convert()

static float acc_convert ( int16_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 444 of file mpu-9250-sensor.c.

◆ acc_read()

static bool acc_read ( uint16_t *  data)
static

Read data from the accelerometer - X, Y, Z - 3 words.

Returns
True if a valid reading could be taken, false otherwise

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

◆ acc_set_range()

static bool acc_set_range ( uint8_t  new_range)
static

Set the range of the accelerometer.

Parameters
new_rangeACC_RANGE_2G, ACC_RANGE_4G, ACC_RANGE_8G, ACC_RANGE_16G
Returns
true if the write to the sensor succeeded

Definition at line 315 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
enableWhen 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 600 of file mpu-9250-sensor.c.

◆ enable_sensor()

static void enable_sensor ( uint16_t  axes)
static

Enable the MPU.

Parameters
axesGyro bitmap [0..2], X = 1, Y = 2, Z = 4. 0 = gyro off Acc bitmap [3..5], X = 8, Y = 16, Z = 32. 0 = accelerometer off

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

◆ gyro_convert()

static float gyro_convert ( int16_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 479 of file mpu-9250-sensor.c.

References notify_ready().

◆ gyro_read()

static bool gyro_read ( uint16_t *  data)
static

Read data from the gyroscope - X, Y, Z - 3 words.

Returns
True if a valid reading could be taken, false otherwise

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

◆ int_status()

static uint8_t int_status ( void  )
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 347 of file mpu-9250-sensor.c.

Referenced by gpio_port_isr().

◆ 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

Definition at line 648 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 520 of file mpu-9250-sensor.c.