Contiki-NG
mpu-9250-sensor.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30/**
31 * \addtogroup sensortag-peripherals
32 * @{
33 *
34 * \defgroup sensortag-mpu SensorTag Motion Processing Unit
35 *
36 * Driver for the Invensense MPU-9250 Motion Processing Unit.
37 *
38 * Due to the time required between triggering a reading and the
39 * reading becoming available, this driver is meant to be used in an
40 * asynchronous fashion. The caller must first activate the sensor by
41 * calling
42 *
43 * mpu_9250_sensor.configure(SENSORS_ACTIVE, xyz);
44 *
45 * The value for the xyz arguments depends on the required readings. If
46 * the caller intends to read both the accelerometer as well as the gyro
47 * then xyz should be MPU_9250_SENSOR_TYPE_ALL. If the caller only needs
48 * to take a reading from one of the two elements, xyz should be one of
49 * MPU_9250_SENSOR_TYPE_ACC or MPU_9250_SENSOR_TYPE_GYRO
50 *
51 * Calling configure() will power up the sensor and initialise it. When
52 * the sensor is ready to provide readings, the driver will generate a
53 * sensors_changed event.
54 *
55 * Calls to status() will return the driver's state which could indicate
56 * that the sensor is off, booting or on.
57 *
58 * Once a reading has been taken, the caller has two options:
59 * - Turn the sensor off by calling SENSORS_DEACTIVATE, but in order to
60 * take subsequent readings the sensor must be started up all over
61 * - Leave the sensor on. In this scenario, the caller can simply keep
62 * calling value() for subsequent readings, but having the sensor on
63 * will consume more energy, especially if both accelerometer and the
64 * gyro are on.
65 * @{
66 *
67 * \file
68 * Header file for the Sensortag Invensense MPU-9250 motion processing unit
69 * \author
70 * Edvard Pettersen <e.pettersen@ti.com>
71 */
72/*---------------------------------------------------------------------------*/
73#ifndef MPU_9250_SENSOR_H_
74#define MPU_9250_SENSOR_H_
75/*---------------------------------------------------------------------------*/
76#include "contiki.h"
77#include "lib/sensors.h"
78/*---------------------------------------------------------------------------*/
79#include "board-conf.h"
80/*---------------------------------------------------------------------------*/
81#if BOARD_SENSORS_ENABLE
82#if (TI_I2C_CONF_ENABLE == 0) || (TI_I2C_CONF_I2C0_ENABLE == 0)
83#error "The MPU-9250 requires the I2C driver (TI_I2C_CONF_ENABLE = 1)"
84#endif
85#endif
86/*---------------------------------------------------------------------------*/
87#define MPU_9250_READING_ERROR -1
88/*---------------------------------------------------------------------------*/
89/* Accelerometer / Gyro Axes */
90typedef enum {
91 MPU_9250_SENSOR_TYPE_NONE = (0), /**< 0b000000 = 0x00 */
92 MPU_9250_SENSOR_TYPE_GYRO_X = (1 << 0), /**< 0b000001 = 0x01 */
93 MPU_9250_SENSOR_TYPE_GYRO_Y = (1 << 1), /**< 0b000010 = 0x02 */
94 MPU_9250_SENSOR_TYPE_GYRO_Z = (1 << 2), /**< 0b000100 = 0x04 */
95 MPU_9250_SENSOR_TYPE_ACC_X = (1 << 3), /**< 0b001000 = 0x08 */
96 MPU_9250_SENSOR_TYPE_ACC_Y = (1 << 4), /**< 0b010000 = 0x10 */
97 MPU_9250_SENSOR_TYPE_ACC_Z = (1 << 5), /**< 0b100000 = 0x20 */
101 /**< 0b000111 = 0x07 */
105 /**< 0b111000 = 0x38 */
108 /**< 0b111111 = 0x3F */
110/*---------------------------------------------------------------------------*/
111/* Accelerometer range */
112typedef enum {
113 MPU_9250_SENSOR_ACC_RANGE_2G = 0,
114 MPU_9250_SENSOR_ACC_RANGE_4G = 1,
115 MPU_9250_SENSOR_ACC_RANGE_8G = 2,
116 MPU_9250_SENSOR_ACC_RANGE_16G = 3
117} MPU_9250_SENSOR_ACC_RANGE;
118/*---------------------------------------------------------------------------*/
119/* Sensor status */
120typedef enum {
121 MPU_9250_SENSOR_STATUS_DISABLED,
122 MPU_9250_SENSOR_STATUS_ENABLED,
123 MPU_9250_SENSOR_STATUS_BOOTING,
124 MPU_9250_SENSOR_STATUS_READY
125} MPU_9250_SENSOR_STATUS;
126/*---------------------------------------------------------------------------*/
127/* Accelerometer range configuration, type MPU_9250_SENSOR_ACC_RANGE */
128#ifdef MPU_9250_SENSOR_CONF_ACC_RANGE_ARG
129#define MPU_9250_SENSOR_ACC_RANGE_ARG MPU_9250_SENSOR_CONF_ACC_RANGE
130#else
131#define MPU_9250_SENSOR_ACC_RANGE_ARG MPU_9250_SENSOR_ACC_RANGE_2G
132#endif
133/*---------------------------------------------------------------------------*/
134extern const struct sensors_sensor mpu_9250_sensor;
135/*---------------------------------------------------------------------------*/
136#endif /* MPU_9250_SENSOR_H_ */
137/*---------------------------------------------------------------------------*/
138/**
139 * @}
140 * @}
141 */
MPU_9250_SENSOR_TYPE
@ 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
0b111000 = 0x38
@ MPU_9250_SENSOR_TYPE_ACC_Z
0b100000 = 0x20
@ MPU_9250_SENSOR_TYPE_NONE
0b000000 = 0x00
@ MPU_9250_SENSOR_TYPE_ALL
0b111111 = 0x3F
@ MPU_9250_SENSOR_TYPE_GYRO_Y
0b000010 = 0x02
@ MPU_9250_SENSOR_TYPE_GYRO_X
0b000001 = 0x01
@ MPU_9250_SENSOR_TYPE_GYRO
0b000111 = 0x07
Header file with definitions related to SmartRF06 EB boards.