Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
l3gd20_spi.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Felix Ruess <felix.ruess@gmail.com>
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 L3GD20_SPI_H
29 #define L3GD20_SPI_H
30 
31 #include "std.h"
32 #include "math/pprz_algebra_int.h"
33 #include "mcu_periph/spi.h"
34 
35 /* Include common L3GD20 options and definitions */
36 #include "peripherals/l3gd20.h"
37 
38 struct L3gd20_Spi {
39  struct spi_periph *spi_p;
41  volatile uint8_t tx_buf[2];
42  volatile uint8_t rx_buf[8];
44  bool initialized;
45  volatile bool data_available;
46  union {
47  struct Int16Rates rates;
48  int16_t value[3];
50  struct L3gd20Config config;
51 };
52 
53 // Functions
54 extern void l3gd20_spi_init(struct L3gd20_Spi *l3g, struct spi_periph *spi_p, uint8_t slave_idx);
55 extern void l3gd20_spi_start_configure(struct L3gd20_Spi *l3g);
56 extern void l3gd20_spi_read(struct L3gd20_Spi *l3g);
57 extern void l3gd20_spi_event(struct L3gd20_Spi *l3g);
58 
60 static inline void l3gd20_spi_periodic(struct L3gd20_Spi *l3g)
61 {
62  if (l3g->initialized) {
63  l3gd20_spi_read(l3g);
64  } else {
66  }
67 }
68 
69 #endif // L3GD20_SPI_H
SPI peripheral structure.
Definition: spi.h:174
SPI transaction structure.
Definition: spi.h:148
ST L3GD20 3-axis gyroscope driver common interface (I2C and SPI).
L3gd20ConfStatus
Definition: l3gd20.h:43
struct spi_transaction spi_trans
Definition: l3gd20_spi.h:40
static void l3gd20_spi_periodic(struct L3gd20_Spi *l3g)
convenience function: read or start configuration if not already initialized
Definition: l3gd20_spi.h:60
struct spi_periph * spi_p
Definition: l3gd20_spi.h:39
void l3gd20_spi_event(struct L3gd20_Spi *l3g)
Definition: l3gd20_spi.c:135
volatile bool data_available
data ready flag
Definition: l3gd20_spi.h:45
void l3gd20_spi_start_configure(struct L3gd20_Spi *l3g)
Definition: l3gd20_spi.c:112
void l3gd20_spi_init(struct L3gd20_Spi *l3g, struct spi_periph *spi_p, uint8_t slave_idx)
Definition: l3gd20_spi.c:30
enum L3gd20ConfStatus init_status
init status
Definition: l3gd20_spi.h:43
volatile uint8_t rx_buf[8]
Definition: l3gd20_spi.h:42
union L3gd20_Spi::@329 data_rates
struct L3gd20Config config
Definition: l3gd20_spi.h:50
void l3gd20_spi_read(struct L3gd20_Spi *l3g)
Definition: l3gd20_spi.c:122
bool initialized
config done flag
Definition: l3gd20_spi.h:44
volatile uint8_t tx_buf[2]
Definition: l3gd20_spi.h:41
Paparazzi fixed point algebra.
Architecture independent SPI (Serial Peripheral Interface) API.
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