Paparazzi UAS  v7.0_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;
41  enum Lsm303dTarget target;
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];
51  union {
52  struct Int16Vect3 vect;
53  int16_t value[3];
55  struct Lsm303dConfig conf;
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 */
SPI peripheral structure.
Definition: spi.h:174
SPI transaction structure.
Definition: spi.h:148
Driver for ST LSM303D 3D accelerometer and magnetometer.
Lsm303dTarget
Definition: lsm303d.h:88
Lsm303dConfStatus
config status states
Definition: lsm303d.h:75
void lsm303d_spi_event(struct Lsm303d_Spi *lsm)
Definition: lsm303d_spi.c:176
struct spi_transaction spi_trans
Definition: lsm303d_spi.h:39
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
volatile uint8_t rx_buf[8]
Definition: lsm303d_spi.h:43
enum Lsm303dConfStatus init_status
Definition: lsm303d_spi.h:44
static void lsm303d_spi_periodic(struct Lsm303d_Spi *lsm)
convenience function: read or start configuration if not already initialized
Definition: lsm303d_spi.h:68
struct spi_periph * spi_p
Definition: lsm303d_spi.h:38
bool initialized
config done flag
Definition: lsm303d_spi.h:40
struct Lsm303dConfig conf
Definition: lsm303d_spi.h:55
volatile bool data_available_acc
data ready flag accelero
Definition: lsm303d_spi.h:45
enum Lsm303dTarget target
Definition: lsm303d_spi.h:41
union Lsm303d_Spi::@333 data_mag
volatile bool data_available_mag
data ready flag magneto
Definition: lsm303d_spi.h:46
void lsm303d_spi_start_configure(struct Lsm303d_Spi *lsm)
Definition: lsm303d_spi.c:140
volatile uint8_t tx_buf[2]
Definition: lsm303d_spi.h:42
union Lsm303d_Spi::@332 data_accel
void lsm303d_spi_read(struct Lsm303d_Spi *lsm)
Definition: lsm303d_spi.c:151
Paparazzi fixed point algebra.
Architecture independent SPI (Serial Peripheral Interface) API.
struct target_t target
Definition: target_pos.c:64
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