Paparazzi UAS  v6.2_unstable
Paparazzi is a free software Unmanned Aircraft System.
mpu9250.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Gautier Hattenberger <gautier.hattenberger@enac.fr>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
27 #ifndef MPU9250_H
28 #define MPU9250_H
29 
30 #include "std.h"
31 #include "math/pprz_algebra_int.h"
32 
33 /* Include address and register definition */
35 
37 #define MPU9250_DEFAULT_SMPLRT_DIV 0
38 #define MPU9250_DEFAULT_FS_SEL MPU9250_GYRO_RANGE_1000
40 #define MPU9250_DEFAULT_AFS_SEL MPU9250_ACCEL_RANGE_8G
42 #define MPU9250_DEFAULT_DLPF_ACCEL_CFG MPU9250_DLPF_ACCEL_41HZ
44 #define MPU9250_DEFAULT_DLPF_GYRO_CFG MPU9250_DLPF_GYRO_41HZ
46 #define MPU9250_DEFAULT_INT_CFG 1
48 #define MPU9250_DEFAULT_CLK_SEL 1
50 
51 // Default number of I2C slaves
52 #ifndef MPU9250_I2C_NB_SLAVES
53 #define MPU9250_I2C_NB_SLAVES 5
54 #endif
55 
61 #define MPU9250_GYRO_SENS_250 0.544883
62 #define MPU9250_GYRO_SENS_250_NUM 19327
63 #define MPU9250_GYRO_SENS_250_DEN 35470
64 #define MPU9250_GYRO_SENS_500 1.08977
65 #define MPU9250_GYRO_SENS_500_NUM 57663
66 #define MPU9250_GYRO_SENS_500_DEN 52913
67 #define MPU9250_GYRO_SENS_1000 2.17953
68 #define MPU9250_GYRO_SENS_1000_NUM 18271
69 #define MPU9250_GYRO_SENS_1000_DEN 8383
70 #define MPU9250_GYRO_SENS_2000 4.35906
71 #define MPU9250_GYRO_SENS_2000_NUM 36542
72 #define MPU9250_GYRO_SENS_2000_DEN 8383
73 
74 // Get default sensitivity from a table
75 extern const float MPU9250_GYRO_SENS[4];
76 // Get default sensitivity numerator and denominator from a table
77 extern const struct Int32Rates MPU9250_GYRO_SENS_FRAC[4][2];
78 
84 #define MPU9250_ACCEL_SENS_2G 0.613125
85 #define MPU9250_ACCEL_SENS_2G_NUM 981
86 #define MPU9250_ACCEL_SENS_2G_DEN 1600
87 #define MPU9250_ACCEL_SENS_4G 1.22625
88 #define MPU9250_ACCEL_SENS_4G_NUM 981
89 #define MPU9250_ACCEL_SENS_4G_DEN 800
90 #define MPU9250_ACCEL_SENS_8G 2.4525
91 #define MPU9250_ACCEL_SENS_8G_NUM 981
92 #define MPU9250_ACCEL_SENS_8G_DEN 400
93 #define MPU9250_ACCEL_SENS_16G 4.905
94 #define MPU9250_ACCEL_SENS_16G_NUM 981
95 #define MPU9250_ACCEL_SENS_16G_DEN 200
96 
97 // Get default sensitivity from a table
98 extern const float MPU9250_ACCEL_SENS[4];
99 // Get default sensitivity numerator and denominator from a table
100 extern const struct Int32Vect3 MPU9250_ACCEL_SENS_FRAC[4][2];
101 
115 };
116 
118 typedef void (*Mpu9250ConfigSet)(void *mpu, uint8_t _reg, uint8_t _val);
119 
121 typedef bool (*Mpu9250I2cSlaveConfigure)(Mpu9250ConfigSet mpu_set, void *mpu);
122 
125 };
126 
137  bool initialized;
138 
143 
149 };
150 
151 extern void mpu9250_set_default_config(struct Mpu9250Config *c);
152 
154 extern void mpu9250_send_config(Mpu9250ConfigSet mpu_set, void *mpu, struct Mpu9250Config *config);
155 
163 extern bool mpu9250_configure_i2c_slaves(Mpu9250ConfigSet mpu_set, void *mpu);
164 
165 #endif // MPU9250_H
MPU9250_CONF_INT_ENABLE
@ MPU9250_CONF_INT_ENABLE
Definition: mpu9250.h:113
Mpu9250Config::clk_sel
uint8_t clk_sel
Clock select.
Definition: mpu9250.h:134
uint8_t
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
MPU9250_CONF_RESET
@ MPU9250_CONF_RESET
Definition: mpu9250.h:104
Mpu9250Config::i2c_mst_clk
enum Mpu9250MstClk i2c_mst_clk
MPU I2C master clock speed.
Definition: mpu9250.h:147
Mpu9250I2cSlave::configure
Mpu9250I2cSlaveConfigure configure
Definition: mpu9250.h:124
Mpu9250Config::gyro_range
enum Mpu9250GyroRanges gyro_range
deg/s Range
Definition: mpu9250.h:131
Int32Rates
angular rates
Definition: pprz_algebra_int.h:179
Mpu9250Config::nb_bytes
uint8_t nb_bytes
number of bytes to read starting with MPU9250_REG_INT_STATUS
Definition: mpu9250.h:135
Mpu9250MstClk
Mpu9250MstClk
I2C Master clock.
Definition: mpu9250_regs.h:182
Mpu9250Config::init_status
enum Mpu9250ConfStatus init_status
init status
Definition: mpu9250.h:136
Mpu9250Config::dlpf_accel_cfg
enum Mpu9250DLPFAccel dlpf_accel_cfg
Digital Low Pass Filter for accelerometer.
Definition: mpu9250.h:129
Mpu9250Config::dlpf_gyro_cfg
enum Mpu9250DLPFGyro dlpf_gyro_cfg
Digital Low Pass Filter for gyroscope.
Definition: mpu9250.h:130
Mpu9250GyroRanges
Mpu9250GyroRanges
Selectable gyro range.
Definition: mpu9250_regs.h:162
pprz_algebra_int.h
Paparazzi fixed point algebra.
mpu9250_send_config
void mpu9250_send_config(Mpu9250ConfigSet mpu_set, void *mpu, struct Mpu9250Config *config)
Configuration sequence called once before normal use.
Definition: mpu9250.c:89
std.h
Mpu9250ConfStatus
Mpu9250ConfStatus
Definition: mpu9250.h:102
mpu9250_regs.h
MPU9250_CONF_DLPF_ACCEL
@ MPU9250_CONF_DLPF_ACCEL
Definition: mpu9250.h:108
Mpu9250I2cSlave
Definition: mpu9250.h:123
config
static const struct usb_config_descriptor config
Definition: usb_ser_hw.c:200
Mpu9250DLPFAccel
Mpu9250DLPFAccel
Definition: mpu9250_regs.h:149
MPU9250_ACCEL_SENS
const float MPU9250_ACCEL_SENS[4]
Definition: mpu9250.c:50
MPU9250_CONF_USER_RESET
@ MPU9250_CONF_USER_RESET
Definition: mpu9250.h:105
Int32Vect3
Definition: pprz_algebra_int.h:88
Mpu9250Config::i2c_bypass
bool i2c_bypass
Bypass MPU I2C.
Definition: mpu9250.h:142
mpu9250_configure_i2c_slaves
bool mpu9250_configure_i2c_slaves(Mpu9250ConfigSet mpu_set, void *mpu)
Configure I2C slaves of the MPU.
Definition: mpu9250_i2c.c:175
Mpu9250Config::accel_range
enum Mpu9250AccelRanges accel_range
g Range
Definition: mpu9250.h:132
MPU9250_CONF_UNINIT
@ MPU9250_CONF_UNINIT
Definition: mpu9250.h:103
mpu9250_set_default_config
void mpu9250_set_default_config(struct Mpu9250Config *c)
Definition: mpu9250.c:68
MPU9250_I2C_NB_SLAVES
#define MPU9250_I2C_NB_SLAVES
Definition: mpu9250.h:53
Mpu9250Config::nb_slaves
uint8_t nb_slaves
number of used I2C slaves
Definition: mpu9250.h:144
Mpu9250I2cSlaveConfigure
bool(* Mpu9250I2cSlaveConfigure)(Mpu9250ConfigSet mpu_set, void *mpu)
function prototype for configuration of a single I2C slave
Definition: mpu9250.h:121
MPU9250_CONF_DONE
@ MPU9250_CONF_DONE
Definition: mpu9250.h:114
MPU9250_CONF_DLPF_GYRO
@ MPU9250_CONF_DLPF_GYRO
Definition: mpu9250.h:109
Mpu9250Config::smplrt_div
uint8_t smplrt_div
Sample rate divider.
Definition: mpu9250.h:128
MPU9250_CONF_ACCEL
@ MPU9250_CONF_ACCEL
Definition: mpu9250.h:111
MPU9250_CONF_PWR
@ MPU9250_CONF_PWR
Definition: mpu9250.h:106
MPU9250_GYRO_SENS_FRAC
const struct Int32Rates MPU9250_GYRO_SENS_FRAC[4][2]
Definition: mpu9250.c:39
Mpu9250AccelRanges
Mpu9250AccelRanges
Selectable accel range.
Definition: mpu9250_regs.h:172
Mpu9250ConfigSet
void(* Mpu9250ConfigSet)(void *mpu, uint8_t _reg, uint8_t _val)
Configuration function prototype.
Definition: mpu9250.h:118
MPU9250_CONF_GYRO
@ MPU9250_CONF_GYRO
Definition: mpu9250.h:110
MPU9250_CONF_SD
@ MPU9250_CONF_SD
Definition: mpu9250.h:107
Mpu9250Config
Definition: mpu9250.h:127
MPU9250_GYRO_SENS
const float MPU9250_GYRO_SENS[4]
Definition: mpu9250.c:32
Mpu9250Config::slaves
struct Mpu9250I2cSlave slaves[MPU9250_I2C_NB_SLAVES]
I2C slaves.
Definition: mpu9250.h:146
Mpu9250Config::initialized
bool initialized
config done flag
Definition: mpu9250.h:137
MPU9250_CONF_I2C_SLAVES
@ MPU9250_CONF_I2C_SLAVES
Definition: mpu9250.h:112
MPU9250_ACCEL_SENS_FRAC
const struct Int32Vect3 MPU9250_ACCEL_SENS_FRAC[4][2]
Definition: mpu9250.c:57
Mpu9250Config::nb_slave_init
uint8_t nb_slave_init
number of already configured/initialized slaves
Definition: mpu9250.h:145
Mpu9250DLPFGyro
Mpu9250DLPFGyro
Digital Low Pass Filter Options.
Definition: mpu9250_regs.h:139
Mpu9250Config::i2c_mst_delay
uint8_t i2c_mst_delay
MPU I2C slaves delayed sample rate.
Definition: mpu9250.h:148
Mpu9250Config::drdy_int_enable
bool drdy_int_enable
Enable Data Ready Interrupt.
Definition: mpu9250.h:133