Dependencies:   FatFileSystem mbed

Committer:
higedura
Date:
Sat Apr 21 14:07:27 2012 +0000
Revision:
2:307500c991dd
Parent:
0:813b917360ac

        

Who changed what in which revision?

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