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
itg3200.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 ITG3200
24  */
25 
27 #include "std.h"
28 
29 #define ITG_CONF_UNINIT 0
30 #define ITG_CONF_SD 1
31 #define ITG_CONF_DF 2
32 #define ITG_CONF_INT 3
33 #define ITG_CONF_PWR 4
34 #define ITG_CONF_DONE 5
35 
36 
37 // Data ready flag
38 volatile bool_t itg3200_data_available;
39 // Data vector
41 // I2C transaction structure
43 // Init flag
46 
47 // TODO IRQ handling
48 
49 void itg3200_init(void)
50 {
55 }
56 
57 // Configuration function called once before normal use
58 static void itg3200_send_config(void)
59 {
60  switch (itg3200_init_status) {
61  case ITG_CONF_SD:
66  break;
67  case ITG_CONF_DF:
72  break;
73  case ITG_CONF_INT:
78  break;
79  case ITG_CONF_PWR:
84  break;
85  case ITG_CONF_DONE:
88  break;
89  default:
90  break;
91  }
92 }
93 
94 // Configure
96 {
101  }
102  }
103 }
104 
105 // Normal reading
106 void itg3200_read(void)
107 {
111  }
112 }
113 
114 #define Int16FromBuf(_buf,_idx) ((int16_t)((_buf[_idx]<<8) | _buf[_idx+1]))
115 
116 void itg3200_event(void)
117 {
118  if (itg3200_initialized) {
121  }
123  // Successfull reading and new data available
124  if (itg3200_i2c_trans.buf[0] & 0x01) {
125  // New data available
130  }
132  }
133  }
134  else if (!itg3200_initialized && itg3200_init_status != ITG_CONF_UNINIT) { // Configuring
138  }
142  itg3200_send_config(); // Retry config (TODO max retry)
143  }
144  }
145 }
146 
#define ITG3200_REG_INT_CFG
Definition: itg3200.h:12
#define ITG3200_I2C_ADDR
Definition: itg3200.extra.h:59
#define ITG3200_REG_SMPLRT_DIV
Definition: itg3200.h:10
#define ITG3200_REG_INT_STATUS
Definition: itg3200.h:13
static void itg3200_send_config(void)
Definition: itg3200.c:58
bool_t itg3200_initialized
Definition: itg3200.c:44
int32_t p
in rad/s^2 with INT32_RATE_FRAC
#define ITG_CONF_UNINIT
Definition: itg3200.c:29
#define I2CTransmit(_p, _t, _s_addr, _len)
Definition: i2c.h:148
void itg3200_init(void)
Definition: itg3200.c:49
#define ITG_CONF_DONE
Definition: itg3200.c:34
#define ITG3200_SMPLRT_DIV
Definition: itg3200.extra.h:39
#define ITG3200_ADDR
Definition: itg3200.h:5
#define ITG_CONF_INT
Definition: itg3200.c:32
#define ITG3200_I2C_DEVICE
Definition: itg3200.extra.h:64
volatile bool_t itg3200_data_available
Definition: itg3200.c:38
#define Int16FromBuf(_buf, _idx)
Definition: itg3200.c:114
uint8_t slave_addr
Definition: i2c.h:43
#define FALSE
Definition: imu_chimu.h:141
void itg3200_read(void)
Definition: itg3200.c:106
struct i2c_transaction itg3200_i2c_trans
Definition: itg3200.c:42
#define ITG3200_PWR_MGM
Definition: itg3200.extra.h:55
uint8_t itg3200_init_status
Definition: itg3200.c:45
#define ITG_CONF_PWR
Definition: itg3200.c:33
enum I2CTransactionStatus status
Definition: i2c.h:47
struct Int32Rates itg3200_data
Definition: itg3200.c:40
angular rates
void itg3200_configure(void)
Definition: itg3200.c:95
#define ITG_CONF_DF
Definition: itg3200.c:31
#define TRUE
Definition: imu_chimu.h:144
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:46
#define ITG3200_DLPF_FS
Definition: itg3200.extra.h:54
unsigned char uint8_t
Definition: types.h:14
#define I2CTransceive(_p, _t, _s_addr, _len_w, _len_r)
Definition: i2c.h:156
#define ITG_CONF_SD
Definition: itg3200.c:30
#define ITG3200_INT_CFG
Definition: itg3200.extra.h:48
int32_t q
in rad/s^2 with INT32_RATE_FRAC
int32_t r
in rad/s^2 with INT32_RATE_FRAC
#define ITG3200_REG_DLPF_FS
Definition: itg3200.h:11
void itg3200_event(void)
Definition: itg3200.c:116
#define ITG3200_REG_PWR_MGM
Definition: itg3200.h:22