Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
adxl345.extra_i2c.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Gautier Hattenberger
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
23 /* driver for the accelrometer ADXL345 from Analog Devices
24  * this extra header allows standalone operation of the ADXL345 using I2C protocol
25  */
26 
27 #ifndef ITG3200_EXTRA_I2C_H
28 #define ITG3200_EXTRA_I2C_H
29 
30 #include "std.h"
31 #include "math/pprz_algebra_int.h"
32 #include "mcu_periph/i2c.h"
33 
34 /* Include address and register definition */
35 #include "peripherals/adxl345.h"
36 
37 /* Default conf */
38 #ifndef ADXL345_BW_RATE
39 #define ADXL345_BW_RATE 0x0a // Output rate 100Hz, bandwidth 50Hz
40 #endif
41 #ifndef ADXL345_POWER_CTL_MEASURE
42 #define ADXL345_POWER_CTL_MEASURE 0x1 // Continious measurement mode
43 #endif
44 #ifndef ADXL345_INT_ENABLE
45 #define ADXL345_INT_ENABLE 0x0 // Disable interrups
46 #endif
47 #ifndef ADXL345_DATA_FORMAT_FULL_RES
48 #define ADXL345_DATA_FORMAT_FULL_RES 0x1 // Full resolution mode
49 #endif
50 #ifndef ADXL345_DATA_FORMAT_JUSTIFY
51 #define ADXL345_DATA_FORMAT_JUSTIFY 0x0 // Right justified with sign extension
52 #endif
53 #ifndef ADXL345_DATA_FORMAT_RANGE
54 #define ADXL345_DATA_FORMAT_RANGE 0x3 // g Range: 16g
55 #endif
56 
57 #define ADXL345_POWER_CTL (ADXL345_POWER_CTL_MEASURE<<3)
58 #define ADXL345_DATA_FORMAT ((ADXL345_DATA_FORMAT_FULL_RES<<3)|(ADXL345_DATA_FORMAT_JUSTIFY<<2)|(ADXL345_DATA_FORMAT_RANGE))
59 
60 /* Default I2C address */
61 #ifndef ADXL345_I2C_ADDR
62 #define ADXL345_I2C_ADDR ADXL345_ADDR
63 #endif
64 
65 /* Default I2C device */
66 #ifndef ADXL345_I2C_DEVICE
67 #define ADXL345_I2C_DEVICE i2c1
68 #endif
69 
70 // Config done flag
71 extern bool_t adxl345_initialized;
72 // Data ready flag
73 extern volatile bool_t adxl345_data_available;
74 // Data vector
75 extern struct Int16Vect3 adxl345_data;
76 // I2C transaction structure
77 extern struct i2c_transaction adxl345_trans;
78 
79 // TODO IRQ handling
80 
81 // Functions
82 extern void adxl345_init(void);
83 extern void adxl345_configure(void);
84 extern void adxl345_read(void);
85 extern void adxl345_event(void);
86 
87 // Macro for using ADXL345 in periodic function
88 #define Adxl345Periodic() { \
89  if (adxl345_initialized) adxl345_read(); \
90  else adxl345_configure(); \
91 }
92 
93 #define AccelEvent(_handler) { \
94  adxl345_event(); \
95  if (adxl345_data_available) { \
96  _handler(); \
97  } \
98  }
99 
100 #endif // ADXL345_EXTRA_I2C_H
101 
void adxl345_read(void)
Definition: adxl345.i2c.c:106
void adxl345_event(void)
Definition: adxl345.i2c.c:116
void adxl345_init(void)
Definition: adxl345.i2c.c:49
struct Int16Vect3 adxl345_data
Definition: adxl345.i2c.c:40
void adxl345_configure(void)
Definition: adxl345.i2c.c:95
bool_t adxl345_initialized
Definition: adxl345.i2c.c:44
volatile bool_t adxl345_data_available
Definition: adxl345.i2c.c:38
struct i2c_transaction adxl345_trans
Paparazzi fixed point algebra.