Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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
Int16Vect3
Definition: pprz_algebra_int.h:62
Adxl345_I2c
Definition: adxl345_i2c.h:39
adxl345_i2c_start_configure
void adxl345_i2c_start_configure(struct Adxl345_I2c *adxl)
Start configuration if not already done.
Definition: adxl345_i2c.c:90
Adxl345_I2c::config
struct Adxl345Config config
Definition: adxl345_i2c.h:49
adxl345_i2c_periodic
static void adxl345_i2c_periodic(struct Adxl345_I2c *adxl)
convenience function: read or start configuration if not already initialized
Definition: adxl345_i2c.h:59
pprz_algebra_int.h
Paparazzi fixed point algebra.
adxl345.h
std.h
Adxl345_I2c::i2c_p
struct i2c_periph * i2c_p
Definition: adxl345_i2c.h:40
int16_t
signed short int16_t
Definition: types.h:17
Adxl345_I2c::initialized
bool initialized
config done flag
Definition: adxl345_i2c.h:43
uint8_t
unsigned char uint8_t
Definition: types.h:14
i2c_transaction
I2C transaction structure.
Definition: i2c.h:93
adxl345_i2c_event
void adxl345_i2c_event(struct Adxl345_I2c *adxl)
Definition: adxl345_i2c.c:114
Adxl345_I2c::data
union Adxl345_I2c::@304 data
Adxl345_I2c::data_available
volatile bool data_available
data ready flag
Definition: adxl345_i2c.h:44
Adxl345ConfStatus
Adxl345ConfStatus
Definition: adxl345.h:36
adxl345_i2c_read
void adxl345_i2c_read(struct Adxl345_I2c *adxl)
Definition: adxl345_i2c.c:101
Adxl345_I2c::i2c_trans
struct i2c_transaction i2c_trans
Definition: adxl345_i2c.h:41
Adxl345_I2c::init_status
enum Adxl345ConfStatus init_status
init status
Definition: adxl345_i2c.h:42
adxl345_i2c_init
void adxl345_i2c_init(struct Adxl345_I2c *adxl, struct i2c_periph *i2c_p, uint8_t addr)
Definition: adxl345_i2c.c:36
i2c_periph
Definition: i2c.h:144
i2c.h
Adxl345Config
Definition: adxl345.h:45