Paparazzi UAS  v6.2_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 */
Int16Vect3
Definition: pprz_algebra_int.h:62
uint8_t
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
Lsm303d_Spi::data_available_acc
volatile bool data_available_acc
data ready flag accelero
Definition: lsm303d_spi.h:45
Lsm303d_Spi::conf
struct Lsm303dConfig conf
Definition: lsm303d_spi.h:55
Lsm303d_Spi::rx_buf
volatile uint8_t rx_buf[8]
Definition: lsm303d_spi.h:43
spi.h
Lsm303d_Spi::target
enum Lsm303dTarget target
Definition: lsm303d_spi.h:41
spi_transaction
SPI transaction structure.
Definition: spi.h:148
Lsm303d_Spi::tx_buf
volatile uint8_t tx_buf[2]
Definition: lsm303d_spi.h:42
Lsm303dTarget
Lsm303dTarget
Definition: lsm303d.h:88
Lsm303d_Spi
Definition: lsm303d_spi.h:37
pprz_algebra_int.h
Paparazzi fixed point algebra.
spi_periph
SPI peripheral structure.
Definition: spi.h:174
int16_t
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93
std.h
lsm303d_spi_periodic
static void lsm303d_spi_periodic(struct Lsm303d_Spi *lsm)
convenience function: read or start configuration if not already initialized
Definition: lsm303d_spi.h:68
Lsm303d_Spi::init_status
enum Lsm303dConfStatus init_status
Definition: lsm303d_spi.h:44
Lsm303dConfig
Definition: lsm303d.h:64
Lsm303dConfStatus
Lsm303dConfStatus
config status states
Definition: lsm303d.h:75
lsm303d_spi_event
void lsm303d_spi_event(struct Lsm303d_Spi *lsm)
Definition: lsm303d_spi.c:176
lsm303d_spi_start_configure
void lsm303d_spi_start_configure(struct Lsm303d_Spi *lsm)
Definition: lsm303d_spi.c:140
Lsm303d_Spi::spi_p
struct spi_periph * spi_p
Definition: lsm303d_spi.h:38
lsm303d_spi_read
void lsm303d_spi_read(struct Lsm303d_Spi *lsm)
Definition: lsm303d_spi.c:151
Lsm303d_Spi::initialized
bool initialized
config done flag
Definition: lsm303d_spi.h:40
Lsm303d_Spi::spi_trans
struct spi_transaction spi_trans
Definition: lsm303d_spi.h:39
Lsm303d_Spi::data_available_mag
volatile bool data_available_mag
data ready flag magneto
Definition: lsm303d_spi.h:46
lsm303d.h
Lsm303d_Spi::data_accel
union Lsm303d_Spi::@317 data_accel
Lsm303d_Spi::data_mag
union Lsm303d_Spi::@318 data_mag
target
struct FloatVect2 target
Definition: obstacle_avoidance.c:78
lsm303d_spi_init
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