Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
lsm303dlhc.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/i2c.h"
34 #include "math/pprz_algebra_int.h"
35 
36 /* Address and register definitions */
38 
44 };
45 
50 };
51 
59 };
60 
68 };
69 
70 struct Lsm303dlhc {
71  struct i2c_periph *i2c_p;
73  bool_t initialized;
74  union {
75  enum Lsm303dlhcAccConfStatus acc;
76  enum Lsm303dlhcMagConfStatus mag;
77  } init_status;
78  volatile bool_t data_available;
79  union {
80  struct Int16Vect3 vect;
81  int16_t value[3];
82  } data;
83  union {
84  struct Lsm303dlhcAccConfig acc;
85  struct Lsm303dlhcMagConfig mag;
86  } config;
87 };
88 
89 
90 
91 // TODO IRQ handling
92 
93 // Functions
94 extern void lsm303dlhc_init(struct Lsm303dlhc *lsm, struct i2c_periph *i2c_p, uint8_t addr);
95 extern void lsm303dlhc_start_configure(struct Lsm303dlhc *lsm);
96 extern void lsm303dlhc_read(struct Lsm303dlhc *lsm);
97 extern void lsm303dlhc_event(struct Lsm303dlhc *lsm);
98 
100 static inline void lsm303dlhc_periodic(struct Lsm303dlhc *lsm)
101 {
102  if (lsm->initialized) {
103  lsm303dlhc_read(lsm);
104  } else {
106  }
107 }
108 
109 #endif /* LSM303DLHC_H */
uint16_t value
Definition: adc_arch.c:586
uint8_t hres
high resolution output mode
Definition: lsm303dlhc.h:43
volatile bool_t data_available
data ready flag
Definition: lsm303dlhc.h:78
uint8_t lp_mode
Low power mode.
Definition: lsm303dlhc.h:41
bool_t initialized
config done flag
Definition: lsm303dlhc.h:73
struct i2c_periph * i2c_p
Definition: lsm303dlhc.h:71
void lsm303dlhc_event(struct Lsm303dlhc *lsm)
Definition: lsm303dlhc.c:209
union Lsm303dlhc::@40 config
Lsm303dlhcAccConfStatus
config status states
Definition: lsm303dlhc.h:53
Register defs for ST LSM303DLHC 3D accelerometer and magnetometer.
uint8_t rate
Data Output Rate Bits(6 -> 50Hz with HMC5843, 75Hz with HMC5883)
Definition: lsm303dlhc.h:47
Lsm303dlhcMagConfStatus
config status states
Definition: lsm303dlhc.h:62
static void lsm303dlhc_periodic(struct Lsm303dlhc *lsm)
convenience function: read or start configuration if not already initialized
Definition: lsm303dlhc.h:100
signed short int16_t
Definition: types.h:17
void lsm303dlhc_init(struct Lsm303dlhc *lsm, struct i2c_periph *i2c_p, uint8_t addr)
Initialize Lsm303dlhc struct and set default config options.
Definition: lsm303dlhc.c:82
I2C transaction structure.
Definition: i2c.h:93
union Lsm303dlhc::@39 data
uint8_t gain
Gain configuration (1 -> +- 1 Gauss)
Definition: lsm303dlhc.h:48
I2C peripheral structure.
Definition: i2c.h:138
unsigned char uint8_t
Definition: types.h:14
union Lsm303dlhc::@38 init_status
uint8_t mode
Measurement mode.
Definition: lsm303dlhc.h:49
uint8_t rate
Data Output Rate Bits(6 -> 50Hz with HMC5843, 75Hz with HMC5883)
Definition: lsm303dlhc.h:40
struct i2c_transaction i2c_trans
Definition: lsm303dlhc.h:72
void lsm303dlhc_start_configure(struct Lsm303dlhc *lsm)
Definition: lsm303dlhc.c:165
uint8_t scale
full scale selection
Definition: lsm303dlhc.h:42
void lsm303dlhc_read(struct Lsm303dlhc *lsm)
Definition: lsm303dlhc.c:185
Paparazzi fixed point algebra.
Architecture independent I2C (Inter-Integrated Circuit Bus) API.