2 * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3 * Copyright (c) 2014 Intel Corporation.
5 * Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
6 * 8/24/2011 by Jeff Rowberg <jeff@rowberg.net>
8 * Permission is hereby granted, free of charge, to any person obtaining
9 * a copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #define MPU6050_ADDRESS_AD0_LOW 0x68 // address pin low (GND), default for InvenSense evaluation board
33 #define MPU6050_ADDRESS_AD0_HIGH 0x69 // address pin high (VCC)
34 #define ADDR MPU6050_ADDRESS_AD0_LOW // device address
37 #define MPU6050_CLOCK_PLL_XGYRO 0x01
38 #define MPU6050_GYRO_FS_250 0x00
39 #define MPU6050_ACCEL_FS_2 0x00
40 #define MPU6050_RA_INT_PIN_CFG 0x37
42 #define MPU6050_RA_ACCEL_XOUT_H 0x3B
43 #define MPU6050_RA_ACCEL_XOUT_L 0x3C
44 #define MPU6050_RA_ACCEL_YOUT_H 0x3D
45 #define MPU6050_RA_ACCEL_YOUT_L 0x3E
46 #define MPU6050_RA_ACCEL_ZOUT_H 0x3F
47 #define MPU6050_RA_ACCEL_ZOUT_L 0x40
48 #define MPU6050_RA_TEMP_OUT_H 0x41
49 #define MPU6050_RA_TEMP_OUT_L 0x42
50 #define MPU6050_RA_GYRO_XOUT_H 0x43
51 #define MPU6050_RA_GYRO_XOUT_L 0x44
52 #define MPU6050_RA_GYRO_YOUT_H 0x45
53 #define MPU6050_RA_GYRO_YOUT_L 0x46
54 #define MPU6050_RA_GYRO_ZOUT_H 0x47
55 #define MPU6050_RA_GYRO_ZOUT_L 0x48
57 #define MPU6050_RA_CONFIG 0x1A
58 #define MPU6050_CFG_DLPF_CFG_BIT 2
59 #define MPU6050_CFG_DLPF_CFG_LENGTH 3
61 #define MPU6050_RA_GYRO_CONFIG 0x1B
62 #define MPU6050_GCONFIG_FS_SEL_BIT 4
63 #define MPU6050_GCONFIG_FS_SEL_LENGTH 2
65 #define MPU6050_RA_ACCEL_CONFIG 0x1C
66 #define MPU6050_ACONFIG_AFS_SEL_BIT 4
67 #define MPU6050_ACONFIG_AFS_SEL_LENGTH 2
70 #define MPU9150_RA_MAG_ADDRESS 0x0C
71 #define MPU9150_RA_MAG_XOUT_L 0x03
73 #define MPU6050_RA_PWR_MGMT_1 0x6B
74 #define MPU6050_PWR1_CLKSEL_BIT 2
75 #define MPU6050_PWR1_CLKSEL_LENGTH 3
76 #define MPU6050_PWR1_SLEEP_BIT 6
78 #define MPU6050_RA_INT_PIN_CFG 0x37
81 #define MPU6050_PWR1_TEMP_DIS_BIT 3
82 #define MPU6050_RA_WHO_AM_I 0x75
83 #define MPU6050_WHO_AM_I_BIT 6
84 #define MPU6050_WHO_AM_I_LENGTH 6
86 #define SMOOTH_TIMES 10.0
112 * @brief C++ API for MPU9150 chip (Accelrometer, Gyro and Magnometer Sensor)
114 * This file defines the MPU9150 C++ interface for libmpu9150
116 * @snippet mpu9150-example.cxx Interesting
121 * Instanciates a MPU9150 object
123 * @param bus number of used bus
124 * @param devAddr addres of used i2c device
126 MPU9150 (int bus, int devAddr);
129 * MPU9150 object destructor, basicaly it close i2c connection.
134 * Initiate MPU9150 chips
136 maa_result_t initSensor ();
139 * Get identity of the device
141 uint8_t getDeviceID ();
144 * Get the Accelerometer, Gyro and Compass data from the chip and
145 * save it in private section.
147 maa_result_t getData ();
150 * @param data structure with 3 axis (x,y,z)
152 maa_result_t getAcceleromter (Vector3D * data);
155 * @param data structure with 3 axis (x,y,z)
157 maa_result_t getGyro (Vector3D * data);
160 * @param data structure with 3 axis (x,y,z)
162 maa_result_t getMagnometer (Vector3D * data);
165 * Read on die temperature from the chip
167 float getTemperature ();
170 * Return name of the component
182 maa_i2c_context m_i2Ctx;
184 AxisData axisMagnetomer;
185 AxisData axisAcceleromter;
186 AxisData axisGyroscope;
188 uint16_t i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer);
189 maa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
190 int updateRegBits (uint8_t reg, uint8_t bitStart,
191 uint8_t length, uint16_t data);
192 uint8_t getRegBits (uint8_t reg, uint8_t bitStart,
193 uint8_t length, uint8_t * data);