Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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
Register and address definitions for AK8963 magnetometer.
struct i2c_transaction i2c_trans
Definition: mpu9250_i2c.h:61
MPU-60X0 driver common interface (I2C and SPI).
struct Mpu9250Config config
Definition: mpu9250_i2c.h:72
volatile bool data_available
data ready flag
Definition: mpu9250_i2c.h:62
Mpu9250I2cSlaveInitStatus
Definition: mpu9250_i2c.h:46
uint8_t data_ext[MPU9250_BUFFER_EXT_LEN]
Definition: mpu9250_i2c.h:71
union Mpu9250_I2c::@334 data_rates
Default Ak8963 structure.
Definition: ak8963.h:53
struct Ak8963 akm
"internal" magnetometer
Definition: mpu9250_i2c.h:75
struct i2c_periph * i2c_p
peripheral used for communcation
Definition: ak8963.h:54
signed short int16_t
Definition: types.h:17
void mpu9250_i2c_event(struct Mpu9250_I2c *mpu)
Definition: mpu9250_i2c.c:106
enum Mpu9250I2cSlaveInitStatus slave_init_status
Definition: mpu9250_i2c.h:73
I2C transaction structure.
Definition: i2c.h:93
void mpu9250_i2c_init(struct Mpu9250_I2c *mpu, struct i2c_periph *i2c_p, uint8_t addr)
Definition: mpu9250_i2c.c:33
unsigned char uint8_t
Definition: types.h:14
static void mpu9250_i2c_periodic(struct Mpu9250_I2c *mpu)
convenience function: read or start configuration if not already initialized
Definition: mpu9250_i2c.h:86
void mpu9250_i2c_read(struct Mpu9250_I2c *mpu)
Definition: mpu9250_i2c.c:87
bool initialized
config done flag
Definition: mpu9250.h:136
#define MPU9250_BUFFER_EXT_LEN
Definition: mpu9250_i2c.h:44
void mpu9250_i2c_start_configure(struct Mpu9250_I2c *mpu)
Definition: mpu9250_i2c.c:77
struct i2c_periph * i2c_p
Definition: mpu9250_i2c.h:60
Paparazzi fixed point algebra.
union Mpu9250_I2c::@333 data_accel
Architecture independent I2C (Inter-Integrated Circuit Bus) API.