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.extra.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 gyro ITG3200 from InvenSense
24  * this extra header allows standalone operation of the ITG3200
25  */
26 
27 #ifndef ITG3200_EXTRA_H
28 #define ITG3200_EXTRA_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/itg3200.h"
36 
37 /* Default conf */
38 #ifndef ITG3200_SMPLRT_DIV
39 #define ITG3200_SMPLRT_DIV 0x00 // Sample rate divider
40 #endif
41 #ifndef ITG3200_FS_SEL
42 #define ITG3200_FS_SEL 0x3 // Full scale range +- 2000°/s
43 #endif
44 #ifndef ITG3200_DLPF_CFG
45 #define ITG3200_DLPF_CFG 0x3 // Internal sampling (1kHz, 42Hz LP Bandwidth)
46 #endif
47 #ifndef ITG3200_INT_CFG
48 #define ITG3200_INT_CFG 0x00 // No interrupt
49 #endif
50 #ifndef ITG3200_CLK_SEL
51 #define ITG3200_CLK_SEL 0x1 // PLL with X gyro reference
52 #endif
53 
54 #define ITG3200_DLPF_FS ((ITG3200_FS_SEL<<3)|(ITG3200_DLPF_CFG))
55 #define ITG3200_PWR_MGM (ITG3200_CLK_SEL)
56 
57 /* Default I2C address */
58 #ifndef ITG3200_I2C_ADDR
59 #define ITG3200_I2C_ADDR ITG3200_ADDR
60 #endif
61 
62 /* Default I2C device */
63 #ifndef ITG3200_I2C_DEVICE
64 #define ITG3200_I2C_DEVICE i2c1
65 #endif
66 
67 // Config done flag
68 extern bool_t itg3200_initialized;
69 // Data ready flag
70 extern volatile bool_t itg3200_data_available;
71 // Data vector
72 extern struct Int32Rates itg3200_data;
73 // I2C transaction structure
74 extern struct i2c_transaction itg3200_trans;
75 
76 // TODO IRQ handling
77 
78 // Functions
79 extern void itg3200_init(void);
80 extern void itg3200_configure(void);
81 extern void itg3200_read(void);
82 extern void itg3200_event(void);
83 
84 // Macro for using ITG3200 in periodic function
85 #define Itg3200Periodic() { \
86  if (itg3200_initialized) itg3200_read(); \
87  else itg3200_configure(); \
88 }
89 
90 #define GyroEvent(_handler) { \
91  itg3200_event(); \
92  if (itg3200_data_available) { \
93  _handler(); \
94  } \
95  }
96 
97 #endif // ITG3200_EXTRA_H
void itg3200_init(void)
Definition: itg3200.c:49
void itg3200_read(void)
Definition: itg3200.c:106
void itg3200_configure(void)
Definition: itg3200.c:95
struct Int32Rates itg3200_data
Definition: itg3200.c:40
struct i2c_transaction itg3200_trans
volatile bool_t itg3200_data_available
Definition: itg3200.c:38
angular rates
void itg3200_event(void)
Definition: itg3200.c:116
bool_t itg3200_initialized
Definition: itg3200.c:44
Paparazzi fixed point algebra.