Paparazzi UAS  v6.2_unstable
Paparazzi is a free software Unmanned Aircraft System.
mpu60x0.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Gautier Hattenberger
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 MPU60X0_H
28 #define MPU60X0_H
29 
30 #include "std.h"
31 #include "math/pprz_algebra_int.h"
32 
33 /* Include address and register definition */
35 
37 #define MPU60X0_DEFAULT_SMPLRT_DIV 0
38 #define MPU60X0_DEFAULT_FS_SEL MPU60X0_GYRO_RANGE_2000
40 #define MPU60X0_DEFAULT_AFS_SEL MPU60X0_ACCEL_RANGE_16G
42 #define MPU60X0_DEFAULT_DLPF_CFG MPU60X0_DLPF_98HZ
44 #define MPU60X0_DEFAULT_DLPF_CFG_ACC MPU60X0_DLPF_ACC_99HZ
46 #define MPU60X0_DEFAULT_INT_CFG 1
48 #define MPU60X0_DEFAULT_CLK_SEL 1
50 
51 // Default number of I2C slaves
52 #ifndef MPU60X0_I2C_NB_SLAVES
53 #define MPU60X0_I2C_NB_SLAVES 5
54 #endif
55 
61 #define MPU60X0_GYRO_SENS_250 0.544883
62 #define MPU60X0_GYRO_SENS_250_NUM 19327
63 #define MPU60X0_GYRO_SENS_250_DEN 35470
64 #define MPU60X0_GYRO_SENS_500 1.08977
65 #define MPU60X0_GYRO_SENS_500_NUM 57663
66 #define MPU60X0_GYRO_SENS_500_DEN 52913
67 #define MPU60X0_GYRO_SENS_1000 2.17953
68 #define MPU60X0_GYRO_SENS_1000_NUM 18271
69 #define MPU60X0_GYRO_SENS_1000_DEN 8383
70 #define MPU60X0_GYRO_SENS_2000 4.35906
71 #define MPU60X0_GYRO_SENS_2000_NUM 36542
72 #define MPU60X0_GYRO_SENS_2000_DEN 8383
73 
74 // Get default sensitivity from a table
75 extern const float MPU60X0_GYRO_SENS[4];
76 // Get default sensitivity numerator and denominator from a table
77 extern const struct Int32Rates MPU60X0_GYRO_SENS_FRAC[4][2];
78 
84 #define MPU60X0_ACCEL_SENS_2G 0.613125
85 #define MPU60X0_ACCEL_SENS_2G_NUM 981
86 #define MPU60X0_ACCEL_SENS_2G_DEN 1600
87 #define MPU60X0_ACCEL_SENS_4G 1.22625
88 #define MPU60X0_ACCEL_SENS_4G_NUM 981
89 #define MPU60X0_ACCEL_SENS_4G_DEN 800
90 #define MPU60X0_ACCEL_SENS_8G 2.4525
91 #define MPU60X0_ACCEL_SENS_8G_NUM 981
92 #define MPU60X0_ACCEL_SENS_8G_DEN 400
93 #define MPU60X0_ACCEL_SENS_16G 4.905
94 #define MPU60X0_ACCEL_SENS_16G_NUM 981
95 #define MPU60X0_ACCEL_SENS_16G_DEN 200
96 
97 // Get default sensitivity from a table
98 extern const float MPU60X0_ACCEL_SENS[4];
99 // Get default sensitivity numerator and denominator from a table
100 extern const struct Int32Vect3 MPU60X0_ACCEL_SENS_FRAC[4][2];
101 
110 };
111 
126 };
127 
129 typedef void (*Mpu60x0ConfigSet)(void *mpu, uint8_t _reg, uint8_t _val);
130 
132 typedef bool (*Mpu60x0I2cSlaveConfigure)(Mpu60x0ConfigSet mpu_set, void *mpu);
133 
136 };
137 
149  bool initialized;
150 
155 
161 };
162 
163 extern void mpu60x0_set_default_config(struct Mpu60x0Config *c);
164 
166 extern void mpu60x0_send_config(Mpu60x0ConfigSet mpu_set, void *mpu, struct Mpu60x0Config *config);
167 
175 extern bool mpu60x0_configure_i2c_slaves(Mpu60x0ConfigSet mpu_set, void *mpu);
176 
177 #endif // MPU60X0_H
Mpu60x0Config::nb_bytes
uint8_t nb_bytes
number of bytes to read starting with MPU60X0_REG_INT_STATUS
Definition: mpu60x0.h:147
Mpu60x0Config::smplrt_div
uint8_t smplrt_div
Sample rate divider.
Definition: mpu60x0.h:140
uint8_t
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
MPU60X0_GYRO_SENS_FRAC
const struct Int32Rates MPU60X0_GYRO_SENS_FRAC[4][2]
Definition: mpu60x0.c:38
Mpu60x0Config::nb_slave_init
uint8_t nb_slave_init
number of already configured/initialized slaves
Definition: mpu60x0.h:157
MPU60X0_CONF_UNINIT
@ MPU60X0_CONF_UNINIT
Definition: mpu60x0.h:113
MPU60X0_CONF_I2C_SLAVES
@ MPU60X0_CONF_I2C_SLAVES
Definition: mpu60x0.h:122
MPU60X0
@ MPU60X0
Definition: mpu60x0.h:105
ICM20689
@ ICM20689
Definition: mpu60x0.h:109
Int32Rates
angular rates
Definition: pprz_algebra_int.h:179
Mpu60x0Config::gyro_range
enum Mpu60x0GyroRanges gyro_range
deg/s Range
Definition: mpu60x0.h:143
ICM20602
@ ICM20602
Definition: mpu60x0.h:108
Mpu60x0Config::drdy_int_enable
bool drdy_int_enable
Enable Data Ready Interrupt.
Definition: mpu60x0.h:145
MPU60X0_CONF_DONE
@ MPU60X0_CONF_DONE
Definition: mpu60x0.h:125
MPU60X0_CONF_UNDOC1
@ MPU60X0_CONF_UNDOC1
Definition: mpu60x0.h:124
Mpu60x0Config::i2c_mst_clk
enum Mpu60x0MstClk i2c_mst_clk
MPU I2C master clock speed.
Definition: mpu60x0.h:159
MPU60X0_CONF_INT_ENABLE
@ MPU60X0_CONF_INT_ENABLE
Definition: mpu60x0.h:123
Mpu60x0Config::accel_range
enum Mpu60x0AccelRanges accel_range
g Range
Definition: mpu60x0.h:144
Mpu60x0Config::dlpf_cfg_acc
enum Mpu60x0ACCDLPF dlpf_cfg_acc
Digital Low Pass Filter for acceleremoter (ICM devices only)
Definition: mpu60x0.h:142
Mpu60x0Config::dlpf_cfg
enum Mpu60x0DLPF dlpf_cfg
Digital Low Pass Filter.
Definition: mpu60x0.h:141
ICM20608
@ ICM20608
Definition: mpu60x0.h:107
mpu60x0_regs.h
MPU60X0_CONF_ACCEL
@ MPU60X0_CONF_ACCEL
Definition: mpu60x0.h:120
Mpu60x0I2cSlaveConfigure
bool(* Mpu60x0I2cSlaveConfigure)(Mpu60x0ConfigSet mpu_set, void *mpu)
function prototype for configuration of a single I2C slave
Definition: mpu60x0.h:132
pprz_algebra_int.h
Paparazzi fixed point algebra.
Mpu60x0ConfigSet
void(* Mpu60x0ConfigSet)(void *mpu, uint8_t _reg, uint8_t _val)
Configuration function prototype.
Definition: mpu60x0.h:129
mpu60x0_send_config
void mpu60x0_send_config(Mpu60x0ConfigSet mpu_set, void *mpu, struct Mpu60x0Config *config)
Configuration sequence called once before normal use.
Definition: mpu60x0.c:89
MPU60X0_ACCEL_SENS_FRAC
const struct Int32Vect3 MPU60X0_ACCEL_SENS_FRAC[4][2]
Definition: mpu60x0.c:56
std.h
Mpu60x0Config::clk_sel
uint8_t clk_sel
Clock select.
Definition: mpu60x0.h:146
Mpu60x0MstClk
Mpu60x0MstClk
I2C Master clock.
Definition: mpu60x0_regs.h:190
Mpu60x0I2cSlave::configure
Mpu60x0I2cSlaveConfigure configure
Definition: mpu60x0.h:135
MPU60X0_CONF_PWR
@ MPU60X0_CONF_PWR
Definition: mpu60x0.h:116
config
static const struct usb_config_descriptor config
Definition: usb_ser_hw.c:200
Int32Vect3
Definition: pprz_algebra_int.h:88
Mpu60x0I2cSlave
Definition: mpu60x0.h:134
Mpu60x0DLPF
Mpu60x0DLPF
Digital Low Pass Filter Options DLFP is affecting both gyro and accels (on MPU not ICM),...
Definition: mpu60x0_regs.h:143
Mpu60x0Type
Mpu60x0Type
MPU60x0 sensor type.
Definition: mpu60x0.h:104
MPU60X0_CONF_DLPF
@ MPU60X0_CONF_DLPF
Definition: mpu60x0.h:118
Mpu60x0Config::init_status
enum Mpu60x0ConfStatus init_status
init status
Definition: mpu60x0.h:148
MPU60X0_CONF_SD
@ MPU60X0_CONF_SD
Definition: mpu60x0.h:117
Mpu60x0GyroRanges
Mpu60x0GyroRanges
Selectable gyro range.
Definition: mpu60x0_regs.h:170
MPU60X0_I2C_NB_SLAVES
#define MPU60X0_I2C_NB_SLAVES
Definition: mpu60x0.h:53
MPU60X0_CONF_RESET
@ MPU60X0_CONF_RESET
Definition: mpu60x0.h:114
Mpu60x0Config::nb_slaves
uint8_t nb_slaves
number of used I2C slaves
Definition: mpu60x0.h:156
Mpu60x0Config::i2c_bypass
bool i2c_bypass
Bypass MPU I2C.
Definition: mpu60x0.h:154
MPU60X0_CONF_ACCEL2
@ MPU60X0_CONF_ACCEL2
Definition: mpu60x0.h:121
ICM20600
@ ICM20600
Definition: mpu60x0.h:106
mpu60x0_configure_i2c_slaves
bool mpu60x0_configure_i2c_slaves(Mpu60x0ConfigSet mpu_set, void *mpu)
Configure I2C slaves of the MPU.
Definition: mpu60x0_i2c.c:135
Mpu60x0Config::i2c_mst_delay
uint8_t i2c_mst_delay
MPU I2C slaves delayed sample rate.
Definition: mpu60x0.h:160
Mpu60x0Config::slaves
struct Mpu60x0I2cSlave slaves[MPU60X0_I2C_NB_SLAVES]
I2C slaves.
Definition: mpu60x0.h:158
MPU60X0_CONF_GYRO
@ MPU60X0_CONF_GYRO
Definition: mpu60x0.h:119
MPU60X0_ACCEL_SENS
const float MPU60X0_ACCEL_SENS[4]
Definition: mpu60x0.c:49
Mpu60x0Config
Definition: mpu60x0.h:138
Mpu60x0ConfStatus
Mpu60x0ConfStatus
Definition: mpu60x0.h:112
Mpu60x0Config::type
enum Mpu60x0Type type
The type of sensor (MPU60x0, ICM20608, ...)
Definition: mpu60x0.h:139
Mpu60x0ACCDLPF
Mpu60x0ACCDLPF
Digital Low Pass Filter Options DLFP specifically for the ICM device accelerometer.
Definition: mpu60x0_regs.h:156
MPU60X0_CONF_USER_RESET
@ MPU60X0_CONF_USER_RESET
Definition: mpu60x0.h:115
Mpu60x0AccelRanges
Mpu60x0AccelRanges
Selectable accel range.
Definition: mpu60x0_regs.h:180
Mpu60x0Config::initialized
bool initialized
config done flag
Definition: mpu60x0.h:149
mpu60x0_set_default_config
void mpu60x0_set_default_config(struct Mpu60x0Config *c)
Definition: mpu60x0.c:67
MPU60X0_GYRO_SENS
const float MPU60X0_GYRO_SENS[4]
Definition: mpu60x0.c:31