|
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 MPU-9250 motion processing unit.
|
|
|
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...
|
|
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:
- Turn the sensor off by calling SENSORS_DEACTIVATE, but in order to
take subsequent readings the sensor must be started up all over
- Leave the sensor on. In this scenario, the caller can simply keep
calling value() for subsequent readings, but having the sensor on
will consume more energy, especially if both accelerometer and the
gyro are on.
◆ 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.
◆ acc_convert()
static int32_t acc_convert |
( |
int32_t |
raw_data | ) |
|
|
static |
Convert accelerometer raw reading to a value in G.
- Parameters
-
raw_data | The raw accelerometer reading. |
- Returns
- The converted value.
Definition at line 396 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 349 of file mpu-9250-sensor.c.
◆ configure()
static int configure |
( |
int |
type, |
|
|
int |
enable |
|
) |
| |
|
static |
Configuration function for the MPU9250 sensor.
- Parameters
-
type | Activate, enable or disable the sensor. See below. |
enable | Enable 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 554 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_data | The raw accelerometer reading. |
- Returns
- The converted value.
Definition at line 413 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 372 of file mpu-9250-sensor.c.
◆ 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 336 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 243 of file mpu-9250-sensor.c.
◆ status()
static int status |
( |
int |
type | ) |
|
|
static |
Returns the status of the sensor.
- Parameters
-
type | SENSORS_ACTIVE or SENSORS_READY |
- Returns
- 1 if the sensor is enabled, else 0.
Definition at line 616 of file mpu-9250-sensor.c.
◆ value()
static int value |
( |
int |
type | ) |
|
|
static |
Returns a reading from the sensor.
- Parameters
-
type | MPU_9250_SENSOR_TYPE_ACC_[XYZ] or MPU_9250_SENSOR_TYPE_GYRO_[XYZ]. |
- Returns
- Centi-G (ACC) or centi-Deg/Sec (Gyro).
Definition at line 467 of file mpu-9250-sensor.c.