2 ******************************************************************************
3 * @addtogroup PIOS PIOS Core hardware abstraction layer
5 * @addtogroup PIOS_MPU6000 MPU6000 Functions
6 * @brief Deals with the hardware interface to the 3-axis gyro
10 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
11 * @brief MPU6000 3-axis gyro function headers
12 * @see The GNU Public License (GPL) Version 3
14 ******************************************************************************
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 * You should have received a copy of the GNU General Public License along
28 * with this program; if not, write to the Free Software Foundation, Inc.,
29 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #ifndef PIOS_MPU6000_H
33 #define PIOS_MPU6000_H
35 /* MPU6000 Addresses */
36 #define PIOS_MPU6000_SMPLRT_DIV_REG 0X19
37 #define PIOS_MPU6000_DLPF_CFG_REG 0X1A
38 #define PIOS_MPU6000_GYRO_CFG_REG 0X1B
39 #define PIOS_MPU6000_ACCEL_CFG_REG 0X1C
40 #define PIOS_MPU6000_FIFO_EN_REG 0x23
41 #define PIOS_MPU6000_INT_CFG_REG 0x37
42 #define PIOS_MPU6000_INT_EN_REG 0x38
43 #define PIOS_MPU6000_INT_STATUS_REG 0x3A
44 #define PIOS_MPU6000_ACCEL_X_OUT_MSB 0x3B
45 #define PIOS_MPU6000_ACCEL_X_OUT_LSB 0x3C
46 #define PIOS_MPU6000_ACCEL_Y_OUT_MSB 0x3D
47 #define PIOS_MPU6000_ACCEL_Y_OUT_LSB 0x3E
48 #define PIOS_MPU6000_ACCEL_Z_OUT_MSB 0x3F
49 #define PIOS_MPU6000_ACCEL_Z_OUT_LSB 0x40
50 #define PIOS_MPU6000_TEMP_OUT_MSB 0x41
51 #define PIOS_MPU6000_TEMP_OUT_LSB 0x42
52 #define PIOS_MPU6000_GYRO_X_OUT_MSB 0x43
53 #define PIOS_MPU6000_GYRO_X_OUT_LSB 0x44
54 #define PIOS_MPU6000_GYRO_Y_OUT_MSB 0x45
55 #define PIOS_MPU6000_GYRO_Y_OUT_LSB 0x46
56 #define PIOS_MPU6000_GYRO_Z_OUT_MSB 0x47
57 #define PIOS_MPU6000_GYRO_Z_OUT_LSB 0x48
58 #define PIOS_MPU6000_USER_CTRL_REG 0x6A
59 #define PIOS_MPU6000_PWR_MGMT_REG 0x6B
60 #define PIOS_MPU6000_FIFO_CNT_MSB 0x72
61 #define PIOS_MPU6000_FIFO_CNT_LSB 0x73
62 #define PIOS_MPU6000_FIFO_REG 0x74
63 #define PIOS_MPU6000_WHOAMI 0x75
65 /* FIFO enable for storing different values */
66 #define PIOS_MPU6000_FIFO_TEMP_OUT 0x80
67 #define PIOS_MPU6000_FIFO_GYRO_X_OUT 0x40
68 #define PIOS_MPU6000_FIFO_GYRO_Y_OUT 0x20
69 #define PIOS_MPU6000_FIFO_GYRO_Z_OUT 0x10
70 #define PIOS_MPU6000_ACCEL_OUT 0x08
72 /* Interrupt Configuration */
73 #define PIOS_MPU6000_INT_ACTL 0x80
74 #define PIOS_MPU6000_INT_OPEN 0x40
75 #define PIOS_MPU6000_INT_LATCH_EN 0x20
76 #define PIOS_MPU6000_INT_CLR_ANYRD 0x10
78 #define PIOS_MPU6000_INTEN_OVERFLOW 0x10
79 #define PIOS_MPU6000_INTEN_DATA_RDY 0x01
81 /* Interrupt status */
82 #define PIOS_MPU6000_INT_STATUS_FIFO_FULL 0x80
83 #define PIOS_MPU6000_INT_STATUS_FIFO_OVERFLOW 0x10
84 #define PIOS_MPU6000_INT_STATUS_IMU_RDY 0X04
85 #define PIOS_MPU6000_INT_STATUS_DATA_RDY 0X01
87 /* User control functionality */
88 #define PIOS_MPU6000_USERCTL_FIFO_EN 0X40
89 #define PIOS_MPU6000_USERCTL_I2C_MST_EN 0x20
90 #define PIOS_MPU6000_USERCTL_DIS_I2C 0X10
91 #define PIOS_MPU6000_USERCTL_FIFO_RST 0X04
92 #define PIOS_MPU6000_USERCTL_SIG_COND 0X02
93 #define PIOS_MPU6000_USERCTL_GYRO_RST 0X01
95 /* Power management and clock selection */
96 #define PIOS_MPU6000_PWRMGMT_IMU_RST 0X80
97 #define PIOS_MPU6000_PWRMGMT_INTERN_CLK 0X00
98 #define PIOS_MPU6000_PWRMGMT_PLL_X_CLK 0X01
99 #define PIOS_MPU6000_PWRMGMT_PLL_Y_CLK 0X02
100 #define PIOS_MPU6000_PWRMGMT_PLL_Z_CLK 0X03
101 #define PIOS_MPU6000_PWRMGMT_STOP_CLK 0X07
103 enum pios_mpu6000_range
{
104 PIOS_MPU6000_SCALE_250_DEG
= 0x00,
105 PIOS_MPU6000_SCALE_500_DEG
= 0x08,
106 PIOS_MPU6000_SCALE_1000_DEG
= 0x10,
107 PIOS_MPU6000_SCALE_2000_DEG
= 0x18
110 enum pios_mpu6000_filter
{
111 PIOS_MPU6000_LOWPASS_256_HZ
= 0x00,
112 PIOS_MPU6000_LOWPASS_188_HZ
= 0x01,
113 PIOS_MPU6000_LOWPASS_98_HZ
= 0x02,
114 PIOS_MPU6000_LOWPASS_42_HZ
= 0x03,
115 PIOS_MPU6000_LOWPASS_20_HZ
= 0x04,
116 PIOS_MPU6000_LOWPASS_10_HZ
= 0x05,
117 PIOS_MPU6000_LOWPASS_5_HZ
= 0x06
120 enum pios_mpu6000_accel_range
{
121 PIOS_MPU6000_ACCEL_2G
= 0x00,
122 PIOS_MPU6000_ACCEL_4G
= 0x08,
123 PIOS_MPU6000_ACCEL_8G
= 0x10,
124 PIOS_MPU6000_ACCEL_16G
= 0x18
127 enum pios_mpu6000_orientation
{ // clockwise rotation from board forward
128 PIOS_MPU6000_TOP_0DEG
= 0x00,
129 PIOS_MPU6000_TOP_90DEG
= 0x01,
130 PIOS_MPU6000_TOP_180DEG
= 0x02,
131 PIOS_MPU6000_TOP_270DEG
= 0x03
134 struct pios_mpu6000_data
{
138 #if defined(PIOS_MPU6000_ACCEL)
142 #endif /* PIOS_MPU6000_ACCEL */
146 struct pios_mpu6000_cfg
{
147 const struct pios_exti_cfg
*exti_cfg
; /* Pointer to the EXTI configuration */
149 uint8_t Fifo_store
; /* FIFO storage of different readings (See datasheet page 31 for more details) */
151 /* Sample rate divider to use (See datasheet page 32 for more details).*/
152 uint8_t Smpl_rate_div_no_dlp
; /* used when no dlp is applied (fs=8KHz)*/
153 uint8_t Smpl_rate_div_dlp
; /* used when dlp is on (fs=1kHz)*/
154 uint8_t interrupt_cfg
; /* Interrupt configuration (See datasheet page 35 for more details) */
155 uint8_t interrupt_en
; /* Interrupt configuration (See datasheet page 35 for more details) */
156 uint8_t User_ctl
; /* User control settings (See datasheet page 41 for more details) */
157 uint8_t Pwr_mgmt_clk
; /* Power management and clock selection (See datasheet page 32 for more details) */
158 enum pios_mpu6000_accel_range accel_range
;
159 enum pios_mpu6000_range gyro_range
;
160 enum pios_mpu6000_filter filter
;
161 enum pios_mpu6000_orientation orientation
;
164 /* Public Functions */
165 extern int32_t PIOS_MPU6000_Init(uint32_t spi_id
, uint32_t slave_num
, const struct pios_mpu6000_cfg
*new_cfg
);
166 extern int32_t PIOS_MPU6000_ConfigureRanges(enum pios_mpu6000_range gyroRange
, enum pios_mpu6000_accel_range accelRange
, enum pios_mpu6000_filter filterSetting
);
167 extern xQueueHandle
PIOS_MPU6000_GetQueue();
168 extern int32_t PIOS_MPU6000_ReadGyros(struct pios_mpu6000_data
*buffer
);
169 extern int32_t PIOS_MPU6000_ReadID();
170 extern int32_t PIOS_MPU6000_Test();
171 extern float PIOS_MPU6000_GetScale();
172 extern float PIOS_MPU6000_GetAccelScale();
173 extern bool PIOS_MPU6000_IRQHandler(void);
175 #endif /* PIOS_MPU6000_H */