Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
lsm303dlhc_spi.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Gautier Hattenberger <gautier.hattenberger@enac.fr>
3  * 2013 Felix Ruess <felix.ruess@gmail.com>
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 
29 #ifndef LSM303DLHC_H
30 #define LSM303DLHC_H
31 
32 #include "std.h"
33 #include "mcu_periph/spi.h"
34 #include "math/pprz_algebra_int.h"
35 #include "peripherals/lsm303dlhc.h"
36 
38  struct spi_periph *spi_p;
40  bool initialized;
42  volatile uint8_t tx_buf[2];
43  volatile uint8_t rx_buf[8];
45  volatile bool data_available_acc;
46  volatile bool data_available_mag;
47  union {
48  struct Int16Vect3 vect;
49  int16_t value[3];
50  } data_accel;
51  union {
52  struct Int16Vect3 vect;
53  int16_t value[3];
54  } data_mag;
55  union {
56  struct Lsm303dlhcAccConfig acc;
57  struct Lsm303dlhcMagConfig mag;
58  } config;
59 };
60 
61 // TODO IRQ handling
62 
63 // Functions
64 extern void lsm303dlhc_spi_init(struct Lsm303dlhc_Spi *lsm, struct spi_periph *spi_p, uint8_t slave_idx,
66 extern void lsm303dlhc_spi_start_configure(struct Lsm303dlhc_Spi *lsm);
67 extern void lsm303dlhc_spi_read(struct Lsm303dlhc_Spi *lsm);
68 extern void lsm303dlhc_spi_event(struct Lsm303dlhc_Spi *lsm);
69 
71 static inline void lsm303dlhc_spi_periodic(struct Lsm303dlhc_Spi *lsm)
72 {
73  if (lsm->initialized) {
75  } else {
77  }
78 }
79 
80 #endif /* LSM303DLHC_H */
Lsm303dlhcConfStatus
config status states
Definition: lsm303dlhc.h:68
struct spi_periph * spi_p
static void lsm303dlhc_spi_periodic(struct Lsm303dlhc_Spi *lsm)
convenience function: read or start configuration if not already initialized
SPI transaction structure.
Definition: spi.h:142
volatile uint8_t rx_buf[8]
Architecture independent SPI (Serial Peripheral Interface) API.
volatile bool data_available_acc
data ready flag accelero
SPI peripheral structure.
Definition: spi.h:168
union Lsm303dlhc_Spi::@310 data_mag
volatile uint8_t tx_buf[2]
void lsm303dlhc_spi_start_configure(struct Lsm303dlhc_Spi *lsm)
union Lsm303dlhc_Spi::@311 config
union Lsm303dlhc_Spi::@309 data_accel
signed short int16_t
Definition: types.h:17
struct spi_transaction spi_trans
enum Lsm303dlhcTarget target
bool initialized
config done flag
void lsm303dlhc_spi_read(struct Lsm303dlhc_Spi *lsm)
unsigned char uint8_t
Definition: types.h:14
volatile bool data_available_mag
data ready flag magneto
void lsm303dlhc_spi_event(struct Lsm303dlhc_Spi *lsm)
enum Lsm303dlhcConfStatus init_status
void lsm303dlhc_spi_init(struct Lsm303dlhc_Spi *lsm, struct spi_periph *spi_p, uint8_t slave_idx, enum Lsm303dlhcTarget target)
struct FloatVect2 target
Lsm303dlhcTarget
Definition: lsm303dlhc.h:81
Driver for ST LSM303DLHC 3D accelerometer and magnetometer.
Paparazzi fixed point algebra.