Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
adxl345.i2c.c
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (C) 2011 Gautier Hattenberger
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 
23 /* Driver for ADXL345 using I2C
24  */
25 
27 #include "std.h"
28 
29 #define ADXL_CONF_UNINIT 0
30 #define ADXL_CONF_RATE 1
31 #define ADXL_CONF_POWER 2
32 #define ADXL_CONF_INT 3
33 #define ADXL_CONF_FORMAT 4
34 #define ADXL_CONF_DONE 5
35 
36 
37 // Data ready flag
38 volatile bool_t adxl345_data_available;
39 // Data vector
41 // I2C transaction structure
43 // Init flag
46 
47 // TODO IRQ handling
48 
49 void adxl345_init(void)
50 {
55 }
56 
57 // Configuration function called once before normal use
58 static void adxl345_send_config(void)
59 {
60  switch (adxl345_init_status) {
61  case ADXL_CONF_RATE:
66  break;
67  case ADXL_CONF_POWER:
72  break;
73  case ADXL_CONF_INT:
78  break;
79  case ADXL_CONF_FORMAT:
84  break;
85  case ADXL_CONF_DONE:
88  break;
89  default:
90  break;
91  }
92 }
93 
94 // Configure
96 {
101  }
102  }
103 }
104 
105 // Normal reading
106 void adxl345_read(void)
107 {
111  }
112 }
113 
114 #define Int16FromBuf(_buf,_idx) ((int16_t)((_buf[_idx+1]<<8) | _buf[_idx]))
115 
116 void adxl345_event(void)
117 {
118  if (adxl345_initialized) {
121  }
123  // Successfull reading
129  }
130  }
131  else if (!adxl345_initialized && adxl345_init_status != ADXL_CONF_UNINIT) { // Configuring
135  }
139  adxl345_send_config(); // Retry config (TODO max retry)
140  }
141  }
142 }
143 
144 
static void adxl345_send_config(void)
Definition: adxl345.i2c.c:58
void adxl345_read(void)
Definition: adxl345.i2c.c:106
void adxl345_configure(void)
Definition: adxl345.i2c.c:95
#define ADXL345_I2C_ADDR
#define ADXL345_REG_DATA_FORMAT
Definition: adxl345.h:12
#define I2CTransmit(_p, _t, _s_addr, _len)
Definition: i2c.h:148
#define ADXL_CONF_FORMAT
Definition: adxl345.i2c.c:33
struct Int16Vect3 adxl345_data
Definition: adxl345.i2c.c:40
#define ADXL_CONF_POWER
Definition: adxl345.i2c.c:31
#define Int16FromBuf(_buf, _idx)
Definition: adxl345.i2c.c:114
#define ADXL345_REG_POWER_CTL
Definition: adxl345.h:10
uint8_t slave_addr
Definition: i2c.h:43
#define FALSE
Definition: imu_chimu.h:141
uint8_t adxl345_init_status
Definition: adxl345.i2c.c:45
#define ADXL_CONF_INT
Definition: adxl345.i2c.c:32
#define ADXL_CONF_UNINIT
Definition: adxl345.i2c.c:29
#define ADXL345_ADDR
Definition: adxl345.h:5
void adxl345_init(void)
Definition: adxl345.i2c.c:49
#define ADXL345_I2C_DEVICE
bool_t adxl345_initialized
Definition: adxl345.i2c.c:44
#define ADXL345_REG_BW_RATE
Definition: adxl345.h:9
enum I2CTransactionStatus status
Definition: i2c.h:47
#define ADXL_CONF_RATE
Definition: adxl345.i2c.c:30
#define TRUE
Definition: imu_chimu.h:144
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:46
#define ADXL345_POWER_CTL
volatile bool_t adxl345_data_available
Definition: adxl345.i2c.c:38
struct i2c_transaction adxl345_i2c_trans
Definition: adxl345.i2c.c:42
#define ADXL345_DATA_FORMAT
#define ADXL_CONF_DONE
Definition: adxl345.i2c.c:34
unsigned char uint8_t
Definition: types.h:14
#define ADXL345_REG_DATA_X0
Definition: adxl345.h:13
#define I2CTransceive(_p, _t, _s_addr, _len_w, _len_r)
Definition: i2c.h:156
#define ADXL345_REG_INT_ENABLE
Definition: adxl345.h:11
#define ADXL345_BW_RATE
void adxl345_event(void)
Definition: adxl345.i2c.c:116
#define ADXL345_INT_ENABLE