Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
adxl345_i2c.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 ADXL345_I2C_H
30 #define ADXL345_I2C_H
31 
32 #include "std.h"
33 #include "math/pprz_algebra_int.h"
34 #include "mcu_periph/i2c.h"
35 
36 /* Include common ADXL345 options and definitions */
37 #include "peripherals/adxl345.h"
38 
39 struct Adxl345_I2c {
40  struct i2c_periph *i2c_p;
43  bool initialized;
44  volatile bool data_available;
45  union {
46  struct Int16Vect3 vect;
47  int16_t value[3];
48  } data;
50 };
51 
52 // Functions
53 extern void adxl345_i2c_init(struct Adxl345_I2c *adxl, struct i2c_periph *i2c_p, uint8_t addr);
54 extern void adxl345_i2c_start_configure(struct Adxl345_I2c *adxl);
55 extern void adxl345_i2c_read(struct Adxl345_I2c *adxl);
56 extern void adxl345_i2c_event(struct Adxl345_I2c *adxl);
57 
59 static inline void adxl345_i2c_periodic(struct Adxl345_I2c *adxl)
60 {
61  if (adxl->initialized) {
62  adxl345_i2c_read(adxl);
63  } else {
65  }
66 }
67 
68 #endif // ADXL345_I2C_H
void adxl345_i2c_event(struct Adxl345_I2c *adxl)
Definition: adxl345_i2c.c:114
void adxl345_i2c_init(struct Adxl345_I2c *adxl, struct i2c_periph *i2c_p, uint8_t addr)
Definition: adxl345_i2c.c:36
struct i2c_transaction i2c_trans
Definition: adxl345_i2c.h:41
bool initialized
config done flag
Definition: adxl345_i2c.h:43
void adxl345_i2c_read(struct Adxl345_I2c *adxl)
Definition: adxl345_i2c.c:101
enum Adxl345ConfStatus init_status
init status
Definition: adxl345_i2c.h:42
struct Adxl345Config config
Definition: adxl345_i2c.h:49
static void adxl345_i2c_periodic(struct Adxl345_I2c *adxl)
convenience function: read or start configuration if not already initialized
Definition: adxl345_i2c.h:59
signed short int16_t
Definition: types.h:17
I2C transaction structure.
Definition: i2c.h:93
union Adxl345_I2c::@293 data
struct i2c_periph * i2c_p
Definition: adxl345_i2c.h:40
I2C peripheral structure.
Definition: i2c.h:138
Adxl345ConfStatus
Definition: adxl345.h:36
unsigned char uint8_t
Definition: types.h:14
Analog Devices ADXL345 accelerometer driver common interface (I2C and SPI).
void adxl345_i2c_start_configure(struct Adxl345_I2c *adxl)
Start configuration if not already done.
Definition: adxl345_i2c.c:90
Paparazzi fixed point algebra.
volatile bool data_available
data ready flag
Definition: adxl345_i2c.h:44
Architecture independent I2C (Inter-Integrated Circuit Bus) API.