altos: Trigger sample complete when all data are ready
[fw/altos] / src / drivers / ao_mpu6000.h
1 /*
2  * Copyright © 2012 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 #ifndef _AO_MPU6000_H_
19 #define _AO_MPU6000_H_
20
21 #define MPU6000_ADDR_WRITE      0xd0
22 #define MPU6000_ADDR_READ       0xd1
23
24 #define MPU6000_SMPRT_DIV       0x19
25
26 #define MPU6000_CONFIG          0x1a
27
28 #define  MPU6000_CONFIG_EXT_SYNC_SET    3
29 #define  MPU6000_CONFIG_EXT_SYNC_SET_DISABLED           0
30 #define  MPU6000_CONFIG_EXT_SYNC_SET_TEMP_OUT_L         1
31 #define  MPU6000_CONFIG_EXT_SYNC_SET_GYRO_XOUT_L        2
32 #define  MPU6000_CONFIG_EXT_SYNC_SET_GYRO_YOUT_L        3
33 #define  MPU6000_CONFIG_EXT_SYNC_SET_GYRO_ZOUT_L        4
34 #define  MPU6000_CONFIG_EXT_SYNC_SET_ACCEL_XOUT_L       5
35 #define  MPU6000_CONFIG_EXT_SYNC_SET_ACCEL_YOUT_L       6
36 #define  MPU6000_CONFIG_EXT_SYNC_SET_ACCEL_ZOUT_L       7
37 #define  MPU6000_CONFIG_EXT_SYNC_SET_MASK               7
38
39 #define  MPU6000_CONFIG_DLPF_CFG        0
40 #define  MPU6000_CONFIG_DLPF_CFG_260_256                0
41 #define  MPU6000_CONFIG_DLPF_CFG_184_188                1
42 #define  MPU6000_CONFIG_DLPF_CFG_94_98                  2
43 #define  MPU6000_CONFIG_DLPF_CFG_44_42                  3
44 #define  MPU6000_CONFIG_DLPF_CFG_21_20                  4
45 #define  MPU6000_CONFIG_DLPF_CFG_10_10                  5
46 #define  MPU6000_CONFIG_DLPF_CFG_5_5                    6
47 #define  MPU6000_CONFIG_DLPF_CFG_MASK                   7
48
49 #define MPU6000_GYRO_CONFIG     0x1b
50 # define MPU600_GYRO_CONFIG_XG_ST       7
51 # define MPU600_GYRO_CONFIG_YG_ST       6
52 # define MPU600_GYRO_CONFIG_ZG_ST       5
53 # define MPU600_GYRO_CONFIG_FS_SEL      3
54 # define MPU600_GYRO_CONFIG_FS_SEL_250          0
55 # define MPU600_GYRO_CONFIG_FS_SEL_500          1
56 # define MPU600_GYRO_CONFIG_FS_SEL_1000         2
57 # define MPU600_GYRO_CONFIG_FS_SEL_2000         3
58 # define MPU600_GYRO_CONFIG_FS_SEL_MASK         3
59
60 #define MPU6000_ACCEL_CONFIG    0x1c
61 # define MPU600_ACCEL_CONFIG_XA_ST      7
62 # define MPU600_ACCEL_CONFIG_YA_ST      6
63 # define MPU600_ACCEL_CONFIG_ZA_ST      5
64 # define MPU600_ACCEL_CONFIG_AFS_SEL    3
65 # define MPU600_ACCEL_CONFIG_AFS_SEL_2G         0
66 # define MPU600_ACCEL_CONFIG_AFS_SEL_4G         1
67 # define MPU600_ACCEL_CONFIG_AFS_SEL_8G         2
68 # define MPU600_ACCEL_CONFIG_AFS_SEL_16G        3
69 # define MPU600_ACCEL_CONFIG_AFS_SEL_MASK       3
70 # define MPU600_ACCEL_CONFIG_ACCEL_HPF  0
71 # define MPU600_ACCEL_CONFIG_ACCEL_HPF_RESET    0
72 # define MPU600_ACCEL_CONFIG_ACCEL_HPF_5Hz      1
73 # define MPU600_ACCEL_CONFIG_ACCEL_HPF_2_5Hz    2
74 # define MPU600_ACCEL_CONFIG_ACCEL_HPF_1_25Hz   3
75 # define MPU600_ACCEL_CONFIG_ACCEL_HPF_0_63Hz   4
76 # define MPU600_ACCEL_CONFIG_ACCEL_HPF_HOLD     7
77 # define MPU600_ACCEL_CONFIG_ACCEL_HPF_MASK     7
78
79 #define MPU6000_INT_ENABLE      0x38
80 #define  MPU6000_INT_ENABLE_FF_EN               7
81 #define  MPU6000_INT_ENABLE_MOT_EN              6
82 #define  MPU6000_INT_ENABLE_ZMOT_EN             5
83 #define  MPU6000_INT_ENABLE_FIFO_OFLOW_EN       4
84 #define  MPU6000_INT_ENABLE_I2C_MST_INT_EN      3
85 #define  MPU6000_INT_ENABLE_DATA_RDY_EN         0
86
87 #define MPU6000_INT_STATUS      0x3a
88 #define  MPU6000_INT_STATUS_FF_EN               7
89 #define  MPU6000_INT_STATUS_MOT_EN              6
90 #define  MPU6000_INT_STATUS_ZMOT_EN             5
91 #define  MPU6000_INT_STATUS_FIFO_OFLOW_EN       4
92 #define  MPU6000_INT_STATUS_I2C_MST_INT_EN      3
93 #define  MPU6000_INT_STATUS_DATA_RDY_EN         0
94
95 #define MPU6000_ACCEL_XOUT_H            0x3b
96 #define MPU6000_ACCEL_XOUT_L            0x3c
97 #define MPU6000_ACCEL_YOUT_H            0x3d
98 #define MPU6000_ACCEL_YOUT_L            0x3e
99 #define MPU6000_ACCEL_ZOUT_H            0x3f
100 #define MPU6000_ACCEL_ZOUT_L            0x40
101 #define MPU6000_TEMP_H                  0x41
102 #define MPU6000_TEMP_L                  0x42
103 #define MPU6000_GYRO_XOUT_H             0x43
104 #define MPU6000_GYRO_XOUT_L             0x44
105 #define MPU6000_GYRO_YOUT_H             0x45
106 #define MPU6000_GYRO_YOUT_L             0x46
107 #define MPU6000_GYRO_ZOUT_H             0x47
108 #define MPU6000_GYRO_ZOUT_L             0x48
109
110 #define MPU6000_SIGNAL_PATH_RESET       0x68
111 #define MPU6000_SIGNAL_PATH_RESET_GYRO_RESET    2
112 #define MPU6000_SIGNAL_PATH_RESET_ACCEL_RESET   1
113 #define MPU6000_SIGNAL_PATH_RESET_TEMP_RESET    0
114
115 #define MPU6000_USER_CONTROL            0x6a
116 #define MPU6000_USER_CONTROL_FIFO_EN            6
117 #define MPU6000_USER_CONTROL_I2C_MST_EN         5
118 #define MPU6000_USER_CONTROL_I2C_IF_DIS         4
119 #define MPU6000_USER_CONTROL_FIFO_RESET         2
120 #define MPU6000_USER_CONTROL_I2C_MST_RESET      1
121 #define MPU6000_USER_CONTROL_SIG_COND_RESET     0
122
123 #define MPU6000_PWR_MGMT_1      0x6b
124 #define MPU6000_PWR_MGMT_1_DEVICE_RESET         7
125 #define MPU6000_PWR_MGMT_1_SLEEP                6
126 #define MPU6000_PWR_MGMT_1_CYCLE                5
127 #define MPU6000_PWR_MGMT_1_TEMP_DIS             3
128 #define MPU6000_PWR_MGMT_1_CLKSEL               0
129 #define MPU6000_PWR_MGMT_1_CLKSEL_INTERNAL              0
130 #define MPU6000_PWR_MGMT_1_CLKSEL_PLL_X_AXIS            1
131 #define MPU6000_PWR_MGMT_1_CLKSEL_PLL_Y_AXIS            2
132 #define MPU6000_PWR_MGMT_1_CLKSEL_PLL_Z_AXIS            3
133 #define MPU6000_PWR_MGMT_1_CLKSEL_PLL_EXTERNAL_32K      4
134 #define MPU6000_PWR_MGMT_1_CLKSEL_PLL_EXTERNAL_19M      5
135 #define MPU6000_PWR_MGMT_1_CLKSEL_STOP                  7
136 #define MPU6000_PWR_MGMT_1_CLKSEL_MASK                  7
137
138 #define MPU6000_PWR_MGMT_2      0x6c
139
140 #define MPU6000_WHO_AM_I        0x75
141
142 /* Self test acceleration is approximately 0.5g */
143 #define MPU6000_ST_ACCEL(full_scale)    (32767 / ((full_scale) * 2))
144
145 /* Self test gyro is approximately 50°/s */
146 #define MPU6000_ST_GYRO(full_scale)     ((int16_t) (((int32_t) 32767 * (int32_t) 50) / (full_scale)))
147
148 struct ao_mpu6000_sample {
149         int16_t         accel_x;
150         int16_t         accel_y;
151         int16_t         accel_z;
152         int16_t         temp;
153         int16_t         gyro_x;
154         int16_t         gyro_y;
155         int16_t         gyro_z;
156 };
157
158 void
159 ao_mpu6000_init(void);
160
161 #endif /* _AO_MPU6000_H_ */