Contiki-NG
|
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. | |
static uint8_t | int_status (void) |
Check whether a data or wake on motion interrupt has occurred. | |
static void | enable_sensor (uint16_t axes) |
Enable the MPU. | |
static bool | acc_read (uint16_t *data) |
Read data from the accelerometer - X, Y, Z - 3 words. | |
static bool | gyro_read (uint16_t *data) |
Read data from the gyroscope - X, Y, Z - 3 words. | |
static float | acc_convert (int16_t raw_data) |
Convert accelerometer raw reading to a value in G. | |
static float | gyro_convert (int16_t raw_data) |
Convert gyro raw reading to a value in deg/sec. | |
static int | value (int type) |
Returns a reading from the sensor. | |
static int | configure (int type, int enable) |
Configuration function for the MPU9250 sensor. | |
static int | status (int type) |
Returns the status of the sensor. | |
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:
|
static |
Convert accelerometer raw reading to a value in G.
raw_data | The raw accelerometer reading |
Definition at line 444 of file mpu-9250-sensor.c.
References value().
Referenced by value().
|
static |
Read data from the accelerometer - X, Y, Z - 3 words.
Definition at line 385 of file mpu-9250-sensor.c.
References sensor_common_read_reg(), sensor_common_set_error_data(), and value().
Referenced by value().
|
static |
Set the range of the accelerometer.
new_range | ACC_RANGE_2G, ACC_RANGE_4G, ACC_RANGE_8G, ACC_RANGE_16G |
Definition at line 315 of file mpu-9250-sensor.c.
References sensor_common_write_reg(), and value().
|
static |
Configuration function for the MPU9250 sensor.
type | Activate, enable or disable the sensor. See below |
enable |
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 600 of file mpu-9250-sensor.c.
References BOARD_IOID_MPU_INT, configure(), ctimer_stop(), sensor_sleep(), and value().
Referenced by configure().
|
static |
Enable the MPU.
axes | Gyro 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.
References select_axes(), sensor_sleep(), sensor_wakeup(), and value().
|
static |
Convert gyro raw reading to a value in deg/sec.
raw_data | The raw accelerometer reading |
Definition at line 479 of file mpu-9250-sensor.c.
References value().
Referenced by value().
|
static |
Read data from the gyroscope - X, Y, Z - 3 words.
Definition at line 413 of file mpu-9250-sensor.c.
References sensor_common_read_reg(), sensor_common_set_error_data(), and value().
Referenced by value().
|
static |
Check whether a data or wake on motion interrupt has occurred.
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.
References sensor_common_read_reg().
Referenced by acc_read(), gpio_port_isr(), gyro_read(), sensor_data_ready(), and value().
|
static |
Returns the status of the sensor.
type | SENSORS_ACTIVE or SENSORS_READY |
Definition at line 648 of file mpu-9250-sensor.c.
|
static |
Returns a reading from the sensor.
type | MPU_9250_SENSOR_TYPE_ACC_[XYZ] or MPU_9250_SENSOR_TYPE_GYRO_[XYZ] |
Definition at line 520 of file mpu-9250-sensor.c.
References acc_convert(), acc_read(), gyro_convert(), gyro_read(), int_status(), RTIMER_NOW, and value().
Referenced by acc_convert(), acc_convert(), acc_read(), acc_read(), acc_set_range(), configure(), enable_sensor(), gyro_convert(), gyro_convert(), gyro_read(), gyro_read(), select_axes(), sensor_data_ready(), sensor_sleep(), sensor_wakeup(), and value().