Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
mpu9250_i2c.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, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
28 #ifndef MPU9250_I2C_H
29 #define MPU9250_I2C_H
30 
31 #include "std.h"
32 #include "math/pprz_algebra_int.h"
33 #include "mcu_periph/i2c.h"
34 
35 /* Include common MPU9250 options and definitions */
36 #include "peripherals/mpu9250.h"
37 #include "peripherals/ak8963.h"
38 
39 #ifndef IMU_MPU9250_READ_MAG
40 #define IMU_MPU9250_READ_MAG TRUE
41 //the MPU6500 is the same as the 9250, except for that its lacking a magneto
42 #endif
43 
44 #define MPU9250_BUFFER_EXT_LEN 16
45 
57 };
58 
59 struct Mpu9250_I2c {
60  struct i2c_periph *i2c_p;
62  volatile bool data_available;
63  union {
64  struct Int16Vect3 vect;
65  int16_t value[3];
66  } data_accel;
67  union {
68  struct Int16Rates rates;
69  int16_t value[3];
70  } data_rates;
74 #ifdef IMU_MPU9250_READ_MAG
75  struct Ak8963 akm;
76 #endif
77 };
78 
79 // Functions
80 extern void mpu9250_i2c_init(struct Mpu9250_I2c *mpu, struct i2c_periph *i2c_p, uint8_t addr);
81 extern void mpu9250_i2c_start_configure(struct Mpu9250_I2c *mpu);
82 extern void mpu9250_i2c_read(struct Mpu9250_I2c *mpu);
83 extern void mpu9250_i2c_event(struct Mpu9250_I2c *mpu);
84 
86 static inline void mpu9250_i2c_periodic(struct Mpu9250_I2c *mpu)
87 {
88  if (mpu->config.initialized) {
89  mpu9250_i2c_read(mpu);
90  } else {
92  }
93 }
94 
95 #endif // MPU9250_I2C_H
MPU9250_I2C_CONF_I2C_MST_EN
@ MPU9250_I2C_CONF_I2C_MST_EN
Definition: mpu9250_i2c.h:55
Int16Vect3
Definition: pprz_algebra_int.h:62
Ak8963
Default Ak8963 structure.
Definition: ak8963.h:53
Mpu9250_I2c::i2c_p
struct i2c_periph * i2c_p
Definition: mpu9250_i2c.h:60
MPU9250_I2C_CONF_I2C_MST_DIS
@ MPU9250_I2C_CONF_I2C_MST_DIS
Definition: mpu9250_i2c.h:48
MPU9250_I2C_CONF_DONE
@ MPU9250_I2C_CONF_DONE
Definition: mpu9250_i2c.h:56
Mpu9250_I2c
Definition: mpu9250_i2c.h:59
Mpu9250_I2c::slave_init_status
enum Mpu9250I2cSlaveInitStatus slave_init_status
Definition: mpu9250_i2c.h:73
MPU9250_I2C_CONF_SLAVES_CONFIGURE
@ MPU9250_I2C_CONF_SLAVES_CONFIGURE
Definition: mpu9250_i2c.h:50
Mpu9250_I2c::data_rates
union Mpu9250_I2c::@336 data_rates
mpu9250_i2c_start_configure
void mpu9250_i2c_start_configure(struct Mpu9250_I2c *mpu)
Definition: mpu9250_i2c.c:77
MPU9250_BUFFER_EXT_LEN
#define MPU9250_BUFFER_EXT_LEN
Definition: mpu9250_i2c.h:44
ak8963.h
mpu9250_i2c_init
void mpu9250_i2c_init(struct Mpu9250_I2c *mpu, struct i2c_periph *i2c_p, uint8_t addr)
Definition: mpu9250_i2c.c:33
Mpu9250_I2c::i2c_trans
struct i2c_transaction i2c_trans
Definition: mpu9250_i2c.h:61
pprz_algebra_int.h
Paparazzi fixed point algebra.
Mpu9250_I2c::config
struct Mpu9250Config config
Definition: mpu9250_i2c.h:72
std.h
Mpu9250_I2c::data_ext
uint8_t data_ext[MPU9250_BUFFER_EXT_LEN]
Definition: mpu9250_i2c.h:71
Ak8963::i2c_p
struct i2c_periph * i2c_p
peripheral used for communcation
Definition: ak8963.h:54
mpu9250_i2c_periodic
static void mpu9250_i2c_periodic(struct Mpu9250_I2c *mpu)
convenience function: read or start configuration if not already initialized
Definition: mpu9250_i2c.h:86
int16_t
signed short int16_t
Definition: types.h:17
uint8_t
unsigned char uint8_t
Definition: types.h:14
mpu9250.h
Mpu9250I2cSlaveInitStatus
Mpu9250I2cSlaveInitStatus
Definition: mpu9250_i2c.h:46
MPU9250_I2C_CONF_UNINIT
@ MPU9250_I2C_CONF_UNINIT
Definition: mpu9250_i2c.h:47
MPU9250_I2C_CONF_I2C_MST_CLK
@ MPU9250_I2C_CONF_I2C_MST_CLK
Definition: mpu9250_i2c.h:52
Int16Rates
Definition: pprz_algebra_int.h:169
i2c_transaction
I2C transaction structure.
Definition: i2c.h:93
Mpu9250_I2c::data_accel
union Mpu9250_I2c::@335 data_accel
MPU9250_I2C_CONF_I2C_MST_DELAY
@ MPU9250_I2C_CONF_I2C_MST_DELAY
Definition: mpu9250_i2c.h:53
Mpu9250Config
Definition: mpu9250.h:126
mpu9250_i2c_event
void mpu9250_i2c_event(struct Mpu9250_I2c *mpu)
Definition: mpu9250_i2c.c:106
MPU9250_I2C_CONF_I2C_BYPASS_EN
@ MPU9250_I2C_CONF_I2C_BYPASS_EN
Definition: mpu9250_i2c.h:49
MPU9250_I2C_CONF_I2C_BYPASS_DIS
@ MPU9250_I2C_CONF_I2C_BYPASS_DIS
Definition: mpu9250_i2c.h:51
Mpu9250_I2c::data_available
volatile bool data_available
data ready flag
Definition: mpu9250_i2c.h:62
MPU9250_I2C_CONF_I2C_SMPLRT
@ MPU9250_I2C_CONF_I2C_SMPLRT
Definition: mpu9250_i2c.h:54
Mpu9250Config::initialized
bool initialized
config done flag
Definition: mpu9250.h:136
i2c_periph
Definition: i2c.h:144
i2c.h
mpu9250_i2c_read
void mpu9250_i2c_read(struct Mpu9250_I2c *mpu)
Definition: mpu9250_i2c.c:87
Mpu9250_I2c::akm
struct Ak8963 akm
"internal" magnetometer
Definition: mpu9250_i2c.h:75