hige dura / Mbed 2 deprecated dotHR_EKF_phithe

Dependencies:   mbed FatFileSystem

Committer:
higedura
Date:
Sun Jun 10 08:44:32 2012 +0000
Revision:
0:75227c386257

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
higedura 0:75227c386257 1 /**
higedura 0:75227c386257 2 * @author Aaron Berk
higedura 0:75227c386257 3 *
higedura 0:75227c386257 4 * @section LICENSE
higedura 0:75227c386257 5 *
higedura 0:75227c386257 6 * Copyright (c) 2010 ARM Limited
higedura 0:75227c386257 7 *
higedura 0:75227c386257 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
higedura 0:75227c386257 9 * of this software and associated documentation files (the "Software"), to deal
higedura 0:75227c386257 10 * in the Software without restriction, including without limitation the rights
higedura 0:75227c386257 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
higedura 0:75227c386257 12 * copies of the Software, and to permit persons to whom the Software is
higedura 0:75227c386257 13 * furnished to do so, subject to the following conditions:
higedura 0:75227c386257 14 *
higedura 0:75227c386257 15 * The above copyright notice and this permission notice shall be included in
higedura 0:75227c386257 16 * all copies or substantial portions of the Software.
higedura 0:75227c386257 17 *
higedura 0:75227c386257 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
higedura 0:75227c386257 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
higedura 0:75227c386257 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
higedura 0:75227c386257 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
higedura 0:75227c386257 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
higedura 0:75227c386257 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
higedura 0:75227c386257 24 * THE SOFTWARE.
higedura 0:75227c386257 25 *
higedura 0:75227c386257 26 * @section DESCRIPTION
higedura 0:75227c386257 27 *
higedura 0:75227c386257 28 * ITG-3200 triple axis, digital interface, gyroscope.
higedura 0:75227c386257 29 *
higedura 0:75227c386257 30 * Datasheet:
higedura 0:75227c386257 31 *
higedura 0:75227c386257 32 * http://invensense.com/mems/gyro/documents/PS-ITG-3200-00-01.4.pdf
higedura 0:75227c386257 33 */
higedura 0:75227c386257 34
higedura 0:75227c386257 35 #ifndef ITG3200_H
higedura 0:75227c386257 36 #define ITG3200_H
higedura 0:75227c386257 37
higedura 0:75227c386257 38 /**
higedura 0:75227c386257 39 * Includes
higedura 0:75227c386257 40 */
higedura 0:75227c386257 41 #include "mbed.h"
higedura 0:75227c386257 42
higedura 0:75227c386257 43 /**
higedura 0:75227c386257 44 * Defines
higedura 0:75227c386257 45 */
higedura 0:75227c386257 46 #define ITG3200_I2C_ADDRESS 0x68 //7-bit address.
higedura 0:75227c386257 47
higedura 0:75227c386257 48 //-----------
higedura 0:75227c386257 49 // Registers
higedura 0:75227c386257 50 //-----------
higedura 0:75227c386257 51 #define WHO_AM_I_REG 0x00
higedura 0:75227c386257 52 #define SMPLRT_DIV_REG 0x15
higedura 0:75227c386257 53 #define DLPF_FS_REG 0x16
higedura 0:75227c386257 54 #define INT_CFG_REG 0x17
higedura 0:75227c386257 55 #define INT_STATUS 0x1A
higedura 0:75227c386257 56 #define TEMP_OUT_H_REG 0x1B
higedura 0:75227c386257 57 #define TEMP_OUT_L_REG 0x1C
higedura 0:75227c386257 58 #define GYRO_XOUT_H_REG 0x1D
higedura 0:75227c386257 59 #define GYRO_XOUT_L_REG 0x1E
higedura 0:75227c386257 60 #define GYRO_YOUT_H_REG 0x1F
higedura 0:75227c386257 61 #define GYRO_YOUT_L_REG 0x20
higedura 0:75227c386257 62 #define GYRO_ZOUT_H_REG 0x21
higedura 0:75227c386257 63 #define GYRO_ZOUT_L_REG 0x22
higedura 0:75227c386257 64 #define PWR_MGM_REG 0x3E
higedura 0:75227c386257 65
higedura 0:75227c386257 66 //----------------------------
higedura 0:75227c386257 67 // Low Pass Filter Bandwidths
higedura 0:75227c386257 68 //----------------------------
higedura 0:75227c386257 69 #define LPFBW_256HZ 0x00
higedura 0:75227c386257 70 #define LPFBW_188HZ 0x01
higedura 0:75227c386257 71 #define LPFBW_98HZ 0x02
higedura 0:75227c386257 72 #define LPFBW_42HZ 0x03
higedura 0:75227c386257 73 #define LPFBW_20HZ 0x04
higedura 0:75227c386257 74 #define LPFBW_10HZ 0x05
higedura 0:75227c386257 75 #define LPFBW_5HZ 0x06
higedura 0:75227c386257 76
higedura 0:75227c386257 77 /**
higedura 0:75227c386257 78 * ITG-3200 triple axis digital gyroscope.
higedura 0:75227c386257 79 */
higedura 0:75227c386257 80 class ITG3200 {
higedura 0:75227c386257 81
higedura 0:75227c386257 82 public:
higedura 0:75227c386257 83
higedura 0:75227c386257 84 /**
higedura 0:75227c386257 85 * Constructor.
higedura 0:75227c386257 86 *
higedura 0:75227c386257 87 * Sets FS_SEL to 0x03 for proper opertaion.
higedura 0:75227c386257 88 *
higedura 0:75227c386257 89 * @param sda - mbed pin to use for the SDA I2C line.
higedura 0:75227c386257 90 * @param scl - mbed pin to use for the SCL I2C line.
higedura 0:75227c386257 91 */
higedura 0:75227c386257 92 ITG3200(PinName sda, PinName scl);
higedura 0:75227c386257 93
higedura 0:75227c386257 94 /**
higedura 0:75227c386257 95 * Get the identity of the device.
higedura 0:75227c386257 96 *
higedura 0:75227c386257 97 * @return The contents of the Who Am I register which contains the I2C
higedura 0:75227c386257 98 * address of the device.
higedura 0:75227c386257 99 */
higedura 0:75227c386257 100 char getWhoAmI(void);
higedura 0:75227c386257 101
higedura 0:75227c386257 102 /**
higedura 0:75227c386257 103 * Set the address of the device.
higedura 0:75227c386257 104 *
higedura 0:75227c386257 105 * @param address The I2C slave address to write to the Who Am I register
higedura 0:75227c386257 106 * on the device.
higedura 0:75227c386257 107 */
higedura 0:75227c386257 108 void setWhoAmI(char address);
higedura 0:75227c386257 109
higedura 0:75227c386257 110 /**
higedura 0:75227c386257 111 * Get the sample rate divider.
higedura 0:75227c386257 112 *
higedura 0:75227c386257 113 * @return The sample rate divider as a number from 0-255.
higedura 0:75227c386257 114 */
higedura 0:75227c386257 115 char getSampleRateDivider(void);
higedura 0:75227c386257 116
higedura 0:75227c386257 117 /**
higedura 0:75227c386257 118 * Set the sample rate divider.
higedura 0:75227c386257 119 *
higedura 0:75227c386257 120 * Fsample = Finternal / (divider + 1), where Finternal = 1kHz or 8kHz,
higedura 0:75227c386257 121 * as decidied by the DLPF_FS register.
higedura 0:75227c386257 122 *
higedura 0:75227c386257 123 * @param The sample rate divider as a number from 0-255.
higedura 0:75227c386257 124 */
higedura 0:75227c386257 125 void setSampleRateDivider(char divider);
higedura 0:75227c386257 126
higedura 0:75227c386257 127 /**
higedura 0:75227c386257 128 * Get the internal sample rate.
higedura 0:75227c386257 129 *
higedura 0:75227c386257 130 * @return The internal sample rate in kHz - either 1 or 8.
higedura 0:75227c386257 131 */
higedura 0:75227c386257 132 int getInternalSampleRate(void);
higedura 0:75227c386257 133
higedura 0:75227c386257 134 /**
higedura 0:75227c386257 135 * Set the low pass filter bandwidth.
higedura 0:75227c386257 136 *
higedura 0:75227c386257 137 * Also used to set the internal sample rate.
higedura 0:75227c386257 138 * Pass the #define bandwidth codes as a parameter.
higedura 0:75227c386257 139 *
higedura 0:75227c386257 140 * 256Hz -> 8kHz internal sample rate.
higedura 0:75227c386257 141 * Everything else -> 1kHz internal rate.
higedura 0:75227c386257 142 *
higedura 0:75227c386257 143 * @param bandwidth Low pass filter bandwidth code
higedura 0:75227c386257 144 */
higedura 0:75227c386257 145 void setLpBandwidth(char bandwidth);
higedura 0:75227c386257 146
higedura 0:75227c386257 147 /**
higedura 0:75227c386257 148 * Get the interrupt configuration.
higedura 0:75227c386257 149 *
higedura 0:75227c386257 150 * See datasheet for register contents details.
higedura 0:75227c386257 151 *
higedura 0:75227c386257 152 * 7 6 5 4
higedura 0:75227c386257 153 * +------+------+--------------+------------------+
higedura 0:75227c386257 154 * | ACTL | OPEN | LATCH_INT_EN | INT_ANYRD_2CLEAR |
higedura 0:75227c386257 155 * +------+------+--------------+------------------+
higedura 0:75227c386257 156 *
higedura 0:75227c386257 157 * 3 2 1 0
higedura 0:75227c386257 158 * +---+------------+------------+---+
higedura 0:75227c386257 159 * | 0 | ITG_RDY_EN | RAW_RDY_EN | 0 |
higedura 0:75227c386257 160 * +---+------------+------------+---+
higedura 0:75227c386257 161 *
higedura 0:75227c386257 162 * ACTL Logic level for INT output pin; 1 = active low, 0 = active high.
higedura 0:75227c386257 163 * OPEN Drive type for INT output pin; 1 = open drain, 0 = push-pull.
higedura 0:75227c386257 164 * LATCH_INT_EN Latch mode; 1 = latch until interrupt is cleared,
higedura 0:75227c386257 165 * 0 = 50us pulse.
higedura 0:75227c386257 166 * INT_ANYRD_2CLEAR Latch clear method; 1 = any register read,
higedura 0:75227c386257 167 * 0 = status register read only.
higedura 0:75227c386257 168 * ITG_RDY_EN Enable interrupt when device is ready,
higedura 0:75227c386257 169 * (PLL ready after changing clock source).
higedura 0:75227c386257 170 * RAW_RDY_EN Enable interrupt when data is available.
higedura 0:75227c386257 171 * 0 Bits 1 and 3 of the INT_CFG register should be zero.
higedura 0:75227c386257 172 *
higedura 0:75227c386257 173 * @return the contents of the INT_CFG register.
higedura 0:75227c386257 174 */
higedura 0:75227c386257 175 char getInterruptConfiguration(void);
higedura 0:75227c386257 176
higedura 0:75227c386257 177 /**
higedura 0:75227c386257 178 * Set the interrupt configuration.
higedura 0:75227c386257 179 *
higedura 0:75227c386257 180 * See datasheet for configuration byte details.
higedura 0:75227c386257 181 *
higedura 0:75227c386257 182 * 7 6 5 4
higedura 0:75227c386257 183 * +------+------+--------------+------------------+
higedura 0:75227c386257 184 * | ACTL | OPEN | LATCH_INT_EN | INT_ANYRD_2CLEAR |
higedura 0:75227c386257 185 * +------+------+--------------+------------------+
higedura 0:75227c386257 186 *
higedura 0:75227c386257 187 * 3 2 1 0
higedura 0:75227c386257 188 * +---+------------+------------+---+
higedura 0:75227c386257 189 * | 0 | ITG_RDY_EN | RAW_RDY_EN | 0 |
higedura 0:75227c386257 190 * +---+------------+------------+---+
higedura 0:75227c386257 191 *
higedura 0:75227c386257 192 * ACTL Logic level for INT output pin; 1 = active low, 0 = active high.
higedura 0:75227c386257 193 * OPEN Drive type for INT output pin; 1 = open drain, 0 = push-pull.
higedura 0:75227c386257 194 * LATCH_INT_EN Latch mode; 1 = latch until interrupt is cleared,
higedura 0:75227c386257 195 * 0 = 50us pulse.
higedura 0:75227c386257 196 * INT_ANYRD_2CLEAR Latch clear method; 1 = any register read,
higedura 0:75227c386257 197 * 0 = status register read only.
higedura 0:75227c386257 198 * ITG_RDY_EN Enable interrupt when device is ready,
higedura 0:75227c386257 199 * (PLL ready after changing clock source).
higedura 0:75227c386257 200 * RAW_RDY_EN Enable interrupt when data is available.
higedura 0:75227c386257 201 * 0 Bits 1 and 3 of the INT_CFG register should be zero.
higedura 0:75227c386257 202 *
higedura 0:75227c386257 203 * @param config Configuration byte to write to INT_CFG register.
higedura 0:75227c386257 204 */
higedura 0:75227c386257 205 void setInterruptConfiguration(char config);
higedura 0:75227c386257 206
higedura 0:75227c386257 207 /**
higedura 0:75227c386257 208 * Check the ITG_RDY bit of the INT_STATUS register.
higedura 0:75227c386257 209 *
higedura 0:75227c386257 210 * @return True if the ITG_RDY bit is set, corresponding to PLL ready,
higedura 0:75227c386257 211 * false if the ITG_RDY bit is not set, corresponding to PLL not
higedura 0:75227c386257 212 * ready.
higedura 0:75227c386257 213 */
higedura 0:75227c386257 214 bool isPllReady(void);
higedura 0:75227c386257 215
higedura 0:75227c386257 216 /**
higedura 0:75227c386257 217 * Check the RAW_DATA_RDY bit of the INT_STATUS register.
higedura 0:75227c386257 218 *
higedura 0:75227c386257 219 * @return True if the RAW_DATA_RDY bit is set, corresponding to new data
higedura 0:75227c386257 220 * in the sensor registers, false if the RAW_DATA_RDY bit is not
higedura 0:75227c386257 221 * set, corresponding to no new data yet in the sensor registers.
higedura 0:75227c386257 222 */
higedura 0:75227c386257 223 bool isRawDataReady(void);
higedura 0:75227c386257 224
higedura 0:75227c386257 225 /**
higedura 0:75227c386257 226 * Get the temperature of the device.
higedura 0:75227c386257 227 *
higedura 0:75227c386257 228 * @return The temperature in degrees celsius.
higedura 0:75227c386257 229 */
higedura 0:75227c386257 230 float getTemperature(void);
higedura 0:75227c386257 231
higedura 0:75227c386257 232 /**
higedura 0:75227c386257 233 * Get the output for the x-axis gyroscope.
higedura 0:75227c386257 234 *
higedura 0:75227c386257 235 * Typical sensitivity is 14.375 LSB/(degrees/sec).
higedura 0:75227c386257 236 *
higedura 0:75227c386257 237 * @return The output on the x-axis in raw ADC counts.
higedura 0:75227c386257 238 */
higedura 0:75227c386257 239 int getGyroX(void);
higedura 0:75227c386257 240
higedura 0:75227c386257 241 /**
higedura 0:75227c386257 242 * Get the output for the y-axis gyroscope.
higedura 0:75227c386257 243 *
higedura 0:75227c386257 244 * Typical sensitivity is 14.375 LSB/(degrees/sec).
higedura 0:75227c386257 245 *
higedura 0:75227c386257 246 * @return The output on the y-axis in raw ADC counts.
higedura 0:75227c386257 247 */
higedura 0:75227c386257 248 int getGyroY(void);
higedura 0:75227c386257 249
higedura 0:75227c386257 250 /**
higedura 0:75227c386257 251 * Get the output on the z-axis gyroscope.
higedura 0:75227c386257 252 *
higedura 0:75227c386257 253 * Typical sensitivity is 14.375 LSB/(degrees/sec).
higedura 0:75227c386257 254 *
higedura 0:75227c386257 255 * @return The output on the z-axis in raw ADC counts.
higedura 0:75227c386257 256 */
higedura 0:75227c386257 257 int getGyroZ(void);
higedura 0:75227c386257 258
higedura 0:75227c386257 259 /**
higedura 0:75227c386257 260 * Get the power management configuration.
higedura 0:75227c386257 261 *
higedura 0:75227c386257 262 * See the datasheet for register contents details.
higedura 0:75227c386257 263 *
higedura 0:75227c386257 264 * 7 6 5 4
higedura 0:75227c386257 265 * +---------+-------+---------+---------+
higedura 0:75227c386257 266 * | H_RESET | SLEEP | STBY_XG | STBY_YG |
higedura 0:75227c386257 267 * +---------+-------+---------+---------+
higedura 0:75227c386257 268 *
higedura 0:75227c386257 269 * 3 2 1 0
higedura 0:75227c386257 270 * +---------+----------+----------+----------+
higedura 0:75227c386257 271 * | STBY_ZG | CLK_SEL2 | CLK_SEL1 | CLK_SEL0 |
higedura 0:75227c386257 272 * +---------+----------+----------+----------+
higedura 0:75227c386257 273 *
higedura 0:75227c386257 274 * H_RESET Reset device and internal registers to the power-up-default settings.
higedura 0:75227c386257 275 * SLEEP Enable low power sleep mode.
higedura 0:75227c386257 276 * STBY_XG Put gyro X in standby mode (1=standby, 0=normal).
higedura 0:75227c386257 277 * STBY_YG Put gyro Y in standby mode (1=standby, 0=normal).
higedura 0:75227c386257 278 * STBY_ZG Put gyro Z in standby mode (1=standby, 0=normal).
higedura 0:75227c386257 279 * CLK_SEL Select device clock source:
higedura 0:75227c386257 280 *
higedura 0:75227c386257 281 * CLK_SEL | Clock Source
higedura 0:75227c386257 282 * --------+--------------
higedura 0:75227c386257 283 * 0 Internal oscillator
higedura 0:75227c386257 284 * 1 PLL with X Gyro reference
higedura 0:75227c386257 285 * 2 PLL with Y Gyro reference
higedura 0:75227c386257 286 * 3 PLL with Z Gyro reference
higedura 0:75227c386257 287 * 4 PLL with external 32.768kHz reference
higedura 0:75227c386257 288 * 5 PLL with external 19.2MHz reference
higedura 0:75227c386257 289 * 6 Reserved
higedura 0:75227c386257 290 * 7 Reserved
higedura 0:75227c386257 291 *
higedura 0:75227c386257 292 * @return The contents of the PWR_MGM register.
higedura 0:75227c386257 293 */
higedura 0:75227c386257 294 char getPowerManagement(void);
higedura 0:75227c386257 295
higedura 0:75227c386257 296 /**
higedura 0:75227c386257 297 * Set power management configuration.
higedura 0:75227c386257 298 *
higedura 0:75227c386257 299 * See the datasheet for configuration byte details
higedura 0:75227c386257 300 *
higedura 0:75227c386257 301 * 7 6 5 4
higedura 0:75227c386257 302 * +---------+-------+---------+---------+
higedura 0:75227c386257 303 * | H_RESET | SLEEP | STBY_XG | STBY_YG |
higedura 0:75227c386257 304 * +---------+-------+---------+---------+
higedura 0:75227c386257 305 *
higedura 0:75227c386257 306 * 3 2 1 0
higedura 0:75227c386257 307 * +---------+----------+----------+----------+
higedura 0:75227c386257 308 * | STBY_ZG | CLK_SEL2 | CLK_SEL1 | CLK_SEL0 |
higedura 0:75227c386257 309 * +---------+----------+----------+----------+
higedura 0:75227c386257 310 *
higedura 0:75227c386257 311 * H_RESET Reset device and internal registers to the power-up-default settings.
higedura 0:75227c386257 312 * SLEEP Enable low power sleep mode.
higedura 0:75227c386257 313 * STBY_XG Put gyro X in standby mode (1=standby, 0=normal).
higedura 0:75227c386257 314 * STBY_YG Put gyro Y in standby mode (1=standby, 0=normal).
higedura 0:75227c386257 315 * STBY_ZG Put gyro Z in standby mode (1=standby, 0=normal).
higedura 0:75227c386257 316 * CLK_SEL Select device clock source:
higedura 0:75227c386257 317 *
higedura 0:75227c386257 318 * CLK_SEL | Clock Source
higedura 0:75227c386257 319 * --------+--------------
higedura 0:75227c386257 320 * 0 Internal oscillator
higedura 0:75227c386257 321 * 1 PLL with X Gyro reference
higedura 0:75227c386257 322 * 2 PLL with Y Gyro reference
higedura 0:75227c386257 323 * 3 PLL with Z Gyro reference
higedura 0:75227c386257 324 * 4 PLL with external 32.768kHz reference
higedura 0:75227c386257 325 * 5 PLL with external 19.2MHz reference
higedura 0:75227c386257 326 * 6 Reserved
higedura 0:75227c386257 327 * 7 Reserved
higedura 0:75227c386257 328 *
higedura 0:75227c386257 329 * @param config The configuration byte to write to the PWR_MGM register.
higedura 0:75227c386257 330 */
higedura 0:75227c386257 331 void setPowerManagement(char config);
higedura 0:75227c386257 332
higedura 0:75227c386257 333 private:
higedura 0:75227c386257 334
higedura 0:75227c386257 335 I2C i2c_;
higedura 0:75227c386257 336
higedura 0:75227c386257 337 };
higedura 0:75227c386257 338
higedura 0:75227c386257 339 #endif /* ITG3200_H */