Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
mpu9250_spi.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_SPI_H
29 #define MPU9250_SPI_H
30 
31 #include "std.h"
32 #include "math/pprz_algebra_int.h"
33 #include "mcu_periph/spi.h"
34 
35 /* Include common MPU9250 options and definitions */
36 #include "peripherals/mpu9250.h"
37 
38 
39 #define MPU9250_BUFFER_LEN 32
40 #define MPU9250_BUFFER_EXT_LEN 16
41 
49 };
50 
51 struct Mpu9250_Spi {
52  struct spi_periph *spi_p;
54  volatile uint8_t tx_buf[2];
56  volatile bool data_available;
57  union {
58  struct Int16Vect3 vect;
59  int16_t value[3];
60  } data_accel;
61  union {
62  struct Int16Rates rates;
63  int16_t value[3];
64  } data_rates;
68 };
69 
70 // Functions
71 extern void mpu9250_spi_init(struct Mpu9250_Spi *mpu, struct spi_periph *spi_p, uint8_t addr);
72 extern void mpu9250_spi_start_configure(struct Mpu9250_Spi *mpu);
73 extern void mpu9250_spi_read(struct Mpu9250_Spi *mpu);
74 extern void mpu9250_spi_event(struct Mpu9250_Spi *mpu);
75 
77 static inline void mpu9250_spi_periodic(struct Mpu9250_Spi *mpu)
78 {
79  if (mpu->config.initialized) {
80  mpu9250_spi_read(mpu);
81  } else {
83  }
84 }
85 
86 #endif // MPU9250_SPI_H
Mpu9250_Spi::spi_p
struct spi_periph * spi_p
Definition: mpu9250_spi.h:52
Int16Vect3
Definition: pprz_algebra_int.h:62
mpu9250_spi_periodic
static void mpu9250_spi_periodic(struct Mpu9250_Spi *mpu)
convenience function: read or start configuration if not already initialized
Definition: mpu9250_spi.h:77
MPU9250_BUFFER_LEN
#define MPU9250_BUFFER_LEN
Definition: mpu9250_spi.h:39
Mpu9250_Spi::data_ext
uint8_t data_ext[MPU9250_BUFFER_EXT_LEN]
Definition: mpu9250_spi.h:65
Mpu9250_Spi::data_rates
union Mpu9250_Spi::@338 data_rates
MPU9250_SPI_CONF_I2C_MST_EN
@ MPU9250_SPI_CONF_I2C_MST_EN
Definition: mpu9250_spi.h:46
MPU9250_BUFFER_EXT_LEN
#define MPU9250_BUFFER_EXT_LEN
Definition: mpu9250_spi.h:40
spi.h
spi_transaction
SPI transaction structure.
Definition: spi.h:148
Mpu9250SpiSlaveInitStatus
Mpu9250SpiSlaveInitStatus
Definition: mpu9250_spi.h:42
pprz_algebra_int.h
Paparazzi fixed point algebra.
mpu9250_spi_start_configure
void mpu9250_spi_start_configure(struct Mpu9250_Spi *mpu)
Definition: mpu9250_spi.c:77
spi_periph
SPI peripheral structure.
Definition: spi.h:174
std.h
Mpu9250_Spi::spi_trans
struct spi_transaction spi_trans
Definition: mpu9250_spi.h:53
Mpu9250_Spi::rx_buf
volatile uint8_t rx_buf[MPU9250_BUFFER_LEN]
Definition: mpu9250_spi.h:55
int16_t
signed short int16_t
Definition: types.h:17
Mpu9250_Spi::slave_init_status
enum Mpu9250SpiSlaveInitStatus slave_init_status
Definition: mpu9250_spi.h:67
uint8_t
unsigned char uint8_t
Definition: types.h:14
mpu9250.h
Mpu9250_Spi::data_accel
union Mpu9250_Spi::@337 data_accel
Int16Rates
Definition: pprz_algebra_int.h:169
mpu9250_spi_init
void mpu9250_spi_init(struct Mpu9250_Spi *mpu, struct spi_periph *spi_p, uint8_t addr)
Definition: mpu9250_spi.c:31
mpu9250_spi_event
void mpu9250_spi_event(struct Mpu9250_Spi *mpu)
Definition: mpu9250_spi.c:109
MPU9250_SPI_CONF_I2C_MST_CLK
@ MPU9250_SPI_CONF_I2C_MST_CLK
Definition: mpu9250_spi.h:44
mpu9250_spi_read
void mpu9250_spi_read(struct Mpu9250_Spi *mpu)
Definition: mpu9250_spi.c:96
Mpu9250_Spi
Definition: mpu9250_spi.h:51
Mpu9250_Spi::data_available
volatile bool data_available
data ready flag
Definition: mpu9250_spi.h:56
Mpu9250Config
Definition: mpu9250.h:126
MPU9250_SPI_CONF_I2C_MST_DELAY
@ MPU9250_SPI_CONF_I2C_MST_DELAY
Definition: mpu9250_spi.h:45
MPU9250_SPI_CONF_DONE
@ MPU9250_SPI_CONF_DONE
Definition: mpu9250_spi.h:48
Mpu9250_Spi::config
struct Mpu9250Config config
Definition: mpu9250_spi.h:66
Mpu9250Config::initialized
bool initialized
config done flag
Definition: mpu9250.h:136
MPU9250_SPI_CONF_UNINIT
@ MPU9250_SPI_CONF_UNINIT
Definition: mpu9250_spi.h:43
Mpu9250_Spi::tx_buf
volatile uint8_t tx_buf[2]
Definition: mpu9250_spi.h:54
MPU9250_SPI_CONF_SLAVES_CONFIGURE
@ MPU9250_SPI_CONF_SLAVES_CONFIGURE
Definition: mpu9250_spi.h:47