NA

Fork of L3G4200D by Michael Shimniok

Committer:
shimniok
Date:
Fri Jan 20 23:11:40 2012 +0000
Revision:
0:6d43e8289cc5
Child:
1:2e0278bddf66
Initial revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 0:6d43e8289cc5 1 /** Interface library for the ST L3G4200D 3-axis gyro
shimniok 0:6d43e8289cc5 2 *
shimniok 0:6d43e8289cc5 3 * Ported from Pololu L3G4200D library for Arduino by
shimniok 0:6d43e8289cc5 4 * Michael Shimniok http://bot-thoughts.com
shimniok 0:6d43e8289cc5 5 *
shimniok 0:6d43e8289cc5 6 * Copyright (c) 2011 Pololu Corporation. For more information, see
shimniok 0:6d43e8289cc5 7 *
shimniok 0:6d43e8289cc5 8 * http://www.pololu.com/
shimniok 0:6d43e8289cc5 9 * http://forum.pololu.com/
shimniok 0:6d43e8289cc5 10 *
shimniok 0:6d43e8289cc5 11 * Permission is hereby granted, free of charge, to any person
shimniok 0:6d43e8289cc5 12 * obtaining a copy of this software and associated documentation
shimniok 0:6d43e8289cc5 13 * files (the "Software"), to deal in the Software without
shimniok 0:6d43e8289cc5 14 * restriction, including without limitation the rights to use,
shimniok 0:6d43e8289cc5 15 * copy, modify, merge, publish, distribute, sublicense, and/or sell
shimniok 0:6d43e8289cc5 16 * copies of the Software, and to permit persons to whom the
shimniok 0:6d43e8289cc5 17 * Software is furnished to do so, subject to the following
shimniok 0:6d43e8289cc5 18 * conditions:
shimniok 0:6d43e8289cc5 19 *
shimniok 0:6d43e8289cc5 20 * The above copyright notice and this permission notice shall be
shimniok 0:6d43e8289cc5 21 * included in all copies or substantial portions of the Software.
shimniok 0:6d43e8289cc5 22 *
shimniok 0:6d43e8289cc5 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
shimniok 0:6d43e8289cc5 24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
shimniok 0:6d43e8289cc5 25 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
shimniok 0:6d43e8289cc5 26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
shimniok 0:6d43e8289cc5 27 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
shimniok 0:6d43e8289cc5 28 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
shimniok 0:6d43e8289cc5 29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
shimniok 0:6d43e8289cc5 30 * OTHER DEALINGS IN THE SOFTWARE.
shimniok 0:6d43e8289cc5 31 */
shimniok 0:6d43e8289cc5 32
shimniok 0:6d43e8289cc5 33 #ifndef __L3G4200D_H
shimniok 0:6d43e8289cc5 34 #define __L3G4200D_H
shimniok 0:6d43e8289cc5 35
shimniok 0:6d43e8289cc5 36 #include "mbed.h"
shimniok 0:6d43e8289cc5 37
shimniok 0:6d43e8289cc5 38 // register addresses
shimniok 0:6d43e8289cc5 39
shimniok 0:6d43e8289cc5 40 #define L3G4200D_WHO_AM_I 0x0F
shimniok 0:6d43e8289cc5 41
shimniok 0:6d43e8289cc5 42 #define L3G4200D_CTRL_REG1 0x20
shimniok 0:6d43e8289cc5 43 #define L3G4200D_CTRL_REG2 0x21
shimniok 0:6d43e8289cc5 44 #define L3G4200D_CTRL_REG3 0x22
shimniok 0:6d43e8289cc5 45 #define L3G4200D_CTRL_REG4 0x23
shimniok 0:6d43e8289cc5 46 #define L3G4200D_CTRL_REG5 0x24
shimniok 0:6d43e8289cc5 47 #define L3G4200D_REFERENCE 0x25
shimniok 0:6d43e8289cc5 48 #define L3G4200D_OUT_TEMP 0x26
shimniok 0:6d43e8289cc5 49 #define L3G4200D_STATUS_REG 0x27
shimniok 0:6d43e8289cc5 50
shimniok 0:6d43e8289cc5 51 #define L3G4200D_OUT_X_L 0x28
shimniok 0:6d43e8289cc5 52 #define L3G4200D_OUT_X_H 0x29
shimniok 0:6d43e8289cc5 53 #define L3G4200D_OUT_Y_L 0x2A
shimniok 0:6d43e8289cc5 54 #define L3G4200D_OUT_Y_H 0x2B
shimniok 0:6d43e8289cc5 55 #define L3G4200D_OUT_Z_L 0x2C
shimniok 0:6d43e8289cc5 56 #define L3G4200D_OUT_Z_H 0x2D
shimniok 0:6d43e8289cc5 57
shimniok 0:6d43e8289cc5 58 #define L3G4200D_FIFO_CTRL_REG 0x2E
shimniok 0:6d43e8289cc5 59 #define L3G4200D_FIFO_SRC_REG 0x2F
shimniok 0:6d43e8289cc5 60
shimniok 0:6d43e8289cc5 61 #define L3G4200D_INT1_CFG 0x30
shimniok 0:6d43e8289cc5 62 #define L3G4200D_INT1_SRC 0x31
shimniok 0:6d43e8289cc5 63 #define L3G4200D_INT1_THS_XH 0x32
shimniok 0:6d43e8289cc5 64 #define L3G4200D_INT1_THS_XL 0x33
shimniok 0:6d43e8289cc5 65 #define L3G4200D_INT1_THS_YH 0x34
shimniok 0:6d43e8289cc5 66 #define L3G4200D_INT1_THS_YL 0x35
shimniok 0:6d43e8289cc5 67 #define L3G4200D_INT1_THS_ZH 0x36
shimniok 0:6d43e8289cc5 68 #define L3G4200D_INT1_THS_ZL 0x37
shimniok 0:6d43e8289cc5 69 #define L3G4200D_INT1_DURATION 0x38
shimniok 0:6d43e8289cc5 70
shimniok 0:6d43e8289cc5 71 typedef char byte;
shimniok 0:6d43e8289cc5 72
shimniok 0:6d43e8289cc5 73 class L3G4200D
shimniok 0:6d43e8289cc5 74 {
shimniok 0:6d43e8289cc5 75 public:
shimniok 0:6d43e8289cc5 76 /** Create a new L3G4200D I2C interface
shimniok 0:6d43e8289cc5 77 * @param sda is the pin for the I2C SDA line
shimniok 0:6d43e8289cc5 78 * @param scl is the pin for the I2C SCL line
shimniok 0:6d43e8289cc5 79 */
shimniok 0:6d43e8289cc5 80 L3G4200D(PinName sda, PinName scl);
shimniok 0:6d43e8289cc5 81
shimniok 0:6d43e8289cc5 82 /** Read gyro values
shimniok 0:6d43e8289cc5 83 * @param g Array containing x, y, and z gyro values
shimniok 0:6d43e8289cc5 84 */
shimniok 0:6d43e8289cc5 85 void read(int g[3]);
shimniok 0:6d43e8289cc5 86
shimniok 0:6d43e8289cc5 87 private:
shimniok 0:6d43e8289cc5 88 byte data[6];
shimniok 0:6d43e8289cc5 89 int _rates[3];
shimniok 0:6d43e8289cc5 90 I2C _device;
shimniok 0:6d43e8289cc5 91 void writeReg(byte reg, byte value);
shimniok 0:6d43e8289cc5 92 byte readReg(byte reg);
shimniok 0:6d43e8289cc5 93 void enableDefault(void);
shimniok 0:6d43e8289cc5 94 };
shimniok 0:6d43e8289cc5 95
shimniok 0:6d43e8289cc5 96 #endif