Paparazzi UAS  v5.15_devel-88-gb3ad7fe
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
lsm303d_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 LSM303DSPI_H
30 #define LSM303DSPI_H
31 
32 #include "std.h"
33 #include "mcu_periph/spi.h"
34 #include "math/pprz_algebra_int.h"
35 #include "peripherals/lsm303d.h"
36 
37 struct Lsm303d_Spi {
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;
56 };
57 
58 // TODO IRQ handling
59 
60 // Functions
61 extern void lsm303d_spi_init(struct Lsm303d_Spi *lsm, struct spi_periph *spi_p, uint8_t slave_idx,
62  enum Lsm303dTarget target);
63 extern void lsm303d_spi_start_configure(struct Lsm303d_Spi *lsm);
64 extern void lsm303d_spi_read(struct Lsm303d_Spi *lsm);
65 extern void lsm303d_spi_event(struct Lsm303d_Spi *lsm);
66 
68 static inline void lsm303d_spi_periodic(struct Lsm303d_Spi *lsm)
69 {
70  if (lsm->initialized) {
71  lsm303d_spi_read(lsm);
72  } else {
74  }
75 }
76 
77 #endif /* LSM303DSPI_H */
void lsm303d_spi_read(struct Lsm303d_Spi *lsm)
Definition: lsm303d_spi.c:151
void lsm303d_spi_event(struct Lsm303d_Spi *lsm)
Definition: lsm303d_spi.c:176
void lsm303d_spi_start_configure(struct Lsm303d_Spi *lsm)
Definition: lsm303d_spi.c:140
bool initialized
config done flag
Definition: lsm303d_spi.h:40
Lsm303dTarget
Definition: lsm303d.h:80
union Lsm303d_Spi::@316 data_mag
SPI transaction structure.
Definition: spi.h:142
union Lsm303d_Spi::@315 data_accel
struct spi_periph * spi_p
Definition: lsm303d_spi.h:38
Architecture independent SPI (Serial Peripheral Interface) API.
volatile uint8_t rx_buf[8]
Definition: lsm303d_spi.h:43
SPI peripheral structure.
Definition: spi.h:168
volatile bool data_available_mag
data ready flag magneto
Definition: lsm303d_spi.h:46
struct spi_transaction spi_trans
Definition: lsm303d_spi.h:39
volatile bool data_available_acc
data ready flag accelero
Definition: lsm303d_spi.h:45
enum Lsm303dTarget target
Definition: lsm303d_spi.h:41
signed short int16_t
Definition: types.h:17
volatile uint8_t tx_buf[2]
Definition: lsm303d_spi.h:42
Lsm303dConfStatus
config status states
Definition: lsm303d.h:67
struct Lsm303dConfig conf
Definition: lsm303d_spi.h:55
unsigned char uint8_t
Definition: types.h:14
void lsm303d_spi_init(struct Lsm303d_Spi *lsm, struct spi_periph *spi_p, uint8_t slave_idx, enum Lsm303dTarget target)
Definition: lsm303d_spi.c:32
Driver for ST LSM303D 3D accelerometer and magnetometer.
struct FloatVect2 target
Paparazzi fixed point algebra.
static void lsm303d_spi_periodic(struct Lsm303d_Spi *lsm)
convenience function: read or start configuration if not already initialized
Definition: lsm303d_spi.h:68
enum Lsm303dConfStatus init_status
Definition: lsm303d_spi.h:44