2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 #ifndef _AO_MPU6000_H_
19 #define _AO_MPU6000_H_
21 #define MPU6000_ADDR_WRITE 0xd0
22 #define MPU6000_ADDR_READ 0xd1
25 #define MPUREG_XG_OFFS_TC 0x00
26 #define MPUREG_YG_OFFS_TC 0x01
27 #define MPUREG_ZG_OFFS_TC 0x02
28 #define MPUREG_X_FINE_GAIN 0x03
29 #define MPUREG_Y_FINE_GAIN 0x04
30 #define MPUREG_Z_FINE_GAIN 0x05
31 #define MPUREG_XA_OFFS_H 0x06 // X axis accelerometer offset (high byte)
32 #define MPUREG_XA_OFFS_L 0x07 // X axis accelerometer offset (low byte)
33 #define MPUREG_YA_OFFS_H 0x08 // Y axis accelerometer offset (high byte)
34 #define MPUREG_YA_OFFS_L 0x09 // Y axis accelerometer offset (low byte)
35 #define MPUREG_ZA_OFFS_H 0x0A // Z axis accelerometer offset (high byte)
36 #define MPUREG_ZA_OFFS_L 0x0B // Z axis accelerometer offset (low byte)
37 #define MPUREG_PRODUCT_ID 0x0C // Product ID Register
38 #define MPUREG_XG_OFFS_USRH 0x13 // X axis gyro offset (high byte)
39 #define MPUREG_XG_OFFS_USRL 0x14 // X axis gyro offset (low byte)
40 #define MPUREG_YG_OFFS_USRH 0x15 // Y axis gyro offset (high byte)
41 #define MPUREG_YG_OFFS_USRL 0x16 // Y axis gyro offset (low byte)
42 #define MPUREG_ZG_OFFS_USRH 0x17 // Z axis gyro offset (high byte)
43 #define MPUREG_ZG_OFFS_USRL 0x18 // Z axis gyro offset (low byte)
45 #define MPU6000_SMPRT_DIV 0x19
47 #define MPU6000_CONFIG 0x1a
49 #define MPU6000_CONFIG_EXT_SYNC_SET 3
50 #define MPU6000_CONFIG_EXT_SYNC_SET_DISABLED 0
51 #define MPU6000_CONFIG_EXT_SYNC_SET_TEMP_OUT_L 1
52 #define MPU6000_CONFIG_EXT_SYNC_SET_GYRO_XOUT_L 2
53 #define MPU6000_CONFIG_EXT_SYNC_SET_GYRO_YOUT_L 3
54 #define MPU6000_CONFIG_EXT_SYNC_SET_GYRO_ZOUT_L 4
55 #define MPU6000_CONFIG_EXT_SYNC_SET_ACCEL_XOUT_L 5
56 #define MPU6000_CONFIG_EXT_SYNC_SET_ACCEL_YOUT_L 6
57 #define MPU6000_CONFIG_EXT_SYNC_SET_ACCEL_ZOUT_L 7
58 #define MPU6000_CONFIG_EXT_SYNC_SET_MASK 7
60 #define MPU6000_CONFIG_DLPF_CFG 0
61 #define MPU6000_CONFIG_DLPF_CFG_260_256 0
62 #define MPU6000_CONFIG_DLPF_CFG_184_188 1
63 #define MPU6000_CONFIG_DLPF_CFG_94_98 2
64 #define MPU6000_CONFIG_DLPF_CFG_44_42 3
65 #define MPU6000_CONFIG_DLPF_CFG_21_20 4
66 #define MPU6000_CONFIG_DLPF_CFG_10_10 5
67 #define MPU6000_CONFIG_DLPF_CFG_5_5 6
68 #define MPU6000_CONFIG_DLPF_CFG_MASK 7
70 #define MPU6000_GYRO_CONFIG 0x1b
71 # define MPU600_GYRO_CONFIG_XG_ST 7
72 # define MPU600_GYRO_CONFIG_YG_ST 6
73 # define MPU600_GYRO_CONFIG_ZG_ST 5
74 # define MPU600_GYRO_CONFIG_FS_SEL 3
75 # define MPU600_GYRO_CONFIG_FS_SEL_250 0
76 # define MPU600_GYRO_CONFIG_FS_SEL_500 1
77 # define MPU600_GYRO_CONFIG_FS_SEL_1000 2
78 # define MPU600_GYRO_CONFIG_FS_SEL_2000 3
79 # define MPU600_GYRO_CONFIG_FS_SEL_MASK 3
81 #define MPU6000_ACCEL_CONFIG 0x1c
82 # define MPU600_ACCEL_CONFIG_XA_ST 7
83 # define MPU600_ACCEL_CONFIG_YA_ST 6
84 # define MPU600_ACCEL_CONFIG_ZA_ST 5
85 # define MPU600_ACCEL_CONFIG_AFS_SEL 3
86 # define MPU600_ACCEL_CONFIG_AFS_SEL_2G 0
87 # define MPU600_ACCEL_CONFIG_AFS_SEL_4G 1
88 # define MPU600_ACCEL_CONFIG_AFS_SEL_8G 2
89 # define MPU600_ACCEL_CONFIG_AFS_SEL_16G 3
90 # define MPU600_ACCEL_CONFIG_AFS_SEL_MASK 3
91 # define MPU600_ACCEL_CONFIG_ACCEL_HPF 0
92 # define MPU600_ACCEL_CONFIG_ACCEL_HPF_RESET 0
93 # define MPU600_ACCEL_CONFIG_ACCEL_HPF_5Hz 1
94 # define MPU600_ACCEL_CONFIG_ACCEL_HPF_2_5Hz 2
95 # define MPU600_ACCEL_CONFIG_ACCEL_HPF_1_25Hz 3
96 # define MPU600_ACCEL_CONFIG_ACCEL_HPF_0_63Hz 4
97 # define MPU600_ACCEL_CONFIG_ACCEL_HPF_HOLD 7
98 # define MPU600_ACCEL_CONFIG_ACCEL_HPF_MASK 7
100 #define MPU6000_INT_ENABLE 0x38
101 #define MPU6000_INT_ENABLE_FF_EN 7
102 #define MPU6000_INT_ENABLE_MOT_EN 6
103 #define MPU6000_INT_ENABLE_ZMOT_EN 5
104 #define MPU6000_INT_ENABLE_FIFO_OFLOW_EN 4
105 #define MPU6000_INT_ENABLE_I2C_MST_INT_EN 3
106 #define MPU6000_INT_ENABLE_DATA_RDY_EN 0
108 #define MPU6000_INT_STATUS 0x3a
109 #define MPU6000_INT_STATUS_FF_EN 7
110 #define MPU6000_INT_STATUS_MOT_EN 6
111 #define MPU6000_INT_STATUS_ZMOT_EN 5
112 #define MPU6000_INT_STATUS_FIFO_OFLOW_EN 4
113 #define MPU6000_INT_STATUS_I2C_MST_INT_EN 3
114 #define MPU6000_INT_STATUS_DATA_RDY_EN 0
116 #define MPU6000_ACCEL_XOUT_H 0x3b
117 #define MPU6000_ACCEL_XOUT_L 0x3c
118 #define MPU6000_ACCEL_YOUT_H 0x3d
119 #define MPU6000_ACCEL_YOUT_L 0x3e
120 #define MPU6000_ACCEL_ZOUT_H 0x3f
121 #define MPU6000_ACCEL_ZOUT_L 0x40
122 #define MPU6000_TEMP_H 0x41
123 #define MPU6000_TEMP_L 0x42
124 #define MPU6000_GYRO_XOUT_H 0x43
125 #define MPU6000_GYRO_XOUT_L 0x44
126 #define MPU6000_GYRO_YOUT_H 0x45
127 #define MPU6000_GYRO_YOUT_L 0x46
128 #define MPU6000_GYRO_ZOUT_H 0x47
129 #define MPU6000_GYRO_ZOUT_L 0x48
131 #define MPU6000_SIGNAL_PATH_RESET 0x68
132 #define MPU6000_SIGNAL_PATH_RESET_GYRO_RESET 2
133 #define MPU6000_SIGNAL_PATH_RESET_ACCEL_RESET 1
134 #define MPU6000_SIGNAL_PATH_RESET_TEMP_RESET 0
136 #define MPU6000_USER_CTRL 0x6a
137 #define MPU6000_USER_CTRL_FIFO_EN 6
138 #define MPU6000_USER_CTRL_I2C_MST_EN 5
139 #define MPU6000_USER_CTRL_I2C_IF_DIS 4
140 #define MPU6000_USER_CTRL_FIFO_RESET 2
141 #define MPU6000_USER_CTRL_I2C_MST_RESET 1
142 #define MPU6000_USER_CTRL_SIG_COND_RESET 0
144 #define MPU6000_PWR_MGMT_1 0x6b
145 #define MPU6000_PWR_MGMT_1_DEVICE_RESET 7
146 #define MPU6000_PWR_MGMT_1_SLEEP 6
147 #define MPU6000_PWR_MGMT_1_CYCLE 5
148 #define MPU6000_PWR_MGMT_1_TEMP_DIS 3
149 #define MPU6000_PWR_MGMT_1_CLKSEL 0
150 #define MPU6000_PWR_MGMT_1_CLKSEL_INTERNAL 0
151 #define MPU6000_PWR_MGMT_1_CLKSEL_PLL_X_AXIS 1
152 #define MPU6000_PWR_MGMT_1_CLKSEL_PLL_Y_AXIS 2
153 #define MPU6000_PWR_MGMT_1_CLKSEL_PLL_Z_AXIS 3
154 #define MPU6000_PWR_MGMT_1_CLKSEL_PLL_EXTERNAL_32K 4
155 #define MPU6000_PWR_MGMT_1_CLKSEL_PLL_EXTERNAL_19M 5
156 #define MPU6000_PWR_MGMT_1_CLKSEL_STOP 7
157 #define MPU6000_PWR_MGMT_1_CLKSEL_MASK 7
159 #define MPU6000_PWR_MGMT_2 0x6c
161 #define MPU6000_WHO_AM_I 0x75
163 /* Self test acceleration is approximately 0.5g */
164 #define MPU6000_ST_ACCEL(full_scale) (32767 / ((full_scale) * 2))
166 /* Self test gyro is approximately 50°/s */
167 #define MPU6000_ST_GYRO(full_scale) ((int16_t) (((int32_t) 32767 * (int32_t) 50) / (full_scale)))
169 #define MPU6000_GYRO_FULLSCALE 2000
170 #define MPU6000_ACCEL_FULLSCALE 16
172 struct ao_mpu6000_sample {
182 extern struct ao_mpu6000_sample ao_mpu6000_current;
185 ao_mpu6000_init(void);
187 /* Product ID Description for MPU6000
188 * high 4 bits low 4 bits
189 * Product Name Product Revision
191 #define MPU6000ES_REV_C4 0x14 /* 0001 0100 */
192 #define MPU6000ES_REV_C5 0x15 /* 0001 0101 */
193 #define MPU6000ES_REV_D6 0x16 /* 0001 0110 */
194 #define MPU6000ES_REV_D7 0x17 /* 0001 0111 */
195 #define MPU6000ES_REV_D8 0x18 /* 0001 1000 */
196 #define MPU6000_REV_C4 0x54 /* 0101 0100 */
197 #define MPU6000_REV_C5 0x55 /* 0101 0101 */
198 #define MPU6000_REV_D6 0x56 /* 0101 0110 */
199 #define MPU6000_REV_D7 0x57 /* 0101 0111 */
200 #define MPU6000_REV_D8 0x58 /* 0101 1000 */
201 #define MPU6000_REV_D9 0x59 /* 0101 1001 */
203 #endif /* _AO_MPU6000_H_ */