Paparazzi UAS  v7.0_unstable
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];
67  union {
68  struct Int16Rates rates;
69  int16_t value[3];
72  struct Mpu9250Config config;
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
Register and address definitions for AK8963 magnetometer.
struct i2c_periph * i2c_p
peripheral used for communcation
Definition: ak8963.h:54
Default Ak8963 structure.
Definition: ak8963.h:53
I2C transaction structure.
Definition: i2c.h:93
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
MPU-60X0 driver common interface (I2C and SPI).
bool initialized
config done flag
Definition: mpu9250.h:137
struct Mpu9250Config config
Definition: mpu9250_i2c.h:72
void mpu9250_i2c_event(struct Mpu9250_I2c *mpu)
Definition: mpu9250_i2c.c:106
uint8_t data_ext[MPU9250_BUFFER_EXT_LEN]
Definition: mpu9250_i2c.h:71
void mpu9250_i2c_read(struct Mpu9250_I2c *mpu)
Definition: mpu9250_i2c.c:87
struct i2c_transaction i2c_trans
Definition: mpu9250_i2c.h:61
struct Ak8963 akm
"internal" magnetometer
Definition: mpu9250_i2c.h:75
union Mpu9250_I2c::@334 data_rates
union Mpu9250_I2c::@333 data_accel
#define MPU9250_BUFFER_EXT_LEN
Definition: mpu9250_i2c.h:44
static void mpu9250_i2c_periodic(struct Mpu9250_I2c *mpu)
convenience function: read or start configuration if not already initialized
Definition: mpu9250_i2c.h:86
enum Mpu9250I2cSlaveInitStatus slave_init_status
Definition: mpu9250_i2c.h:73
void mpu9250_i2c_init(struct Mpu9250_I2c *mpu, struct i2c_periph *i2c_p, uint8_t addr)
Definition: mpu9250_i2c.c:33
void mpu9250_i2c_start_configure(struct Mpu9250_I2c *mpu)
Definition: mpu9250_i2c.c:77
struct i2c_periph * i2c_p
Definition: mpu9250_i2c.h:60
Mpu9250I2cSlaveInitStatus
Definition: mpu9250_i2c.h:46
@ MPU9250_I2C_CONF_DONE
Definition: mpu9250_i2c.h:56
@ MPU9250_I2C_CONF_I2C_SMPLRT
Definition: mpu9250_i2c.h:54
@ MPU9250_I2C_CONF_I2C_BYPASS_EN
Definition: mpu9250_i2c.h:49
@ MPU9250_I2C_CONF_UNINIT
Definition: mpu9250_i2c.h:47
@ MPU9250_I2C_CONF_I2C_MST_DELAY
Definition: mpu9250_i2c.h:53
@ MPU9250_I2C_CONF_I2C_MST_EN
Definition: mpu9250_i2c.h:55
@ MPU9250_I2C_CONF_I2C_MST_DIS
Definition: mpu9250_i2c.h:48
@ MPU9250_I2C_CONF_I2C_BYPASS_DIS
Definition: mpu9250_i2c.h:51
@ MPU9250_I2C_CONF_I2C_MST_CLK
Definition: mpu9250_i2c.h:52
@ MPU9250_I2C_CONF_SLAVES_CONFIGURE
Definition: mpu9250_i2c.h:50
volatile bool data_available
data ready flag
Definition: mpu9250_i2c.h:62
Paparazzi fixed point algebra.
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98