mbed implementation of the FreeIMU IMU for HobbyKing's 10DOF board
L3G4200D.h@1:85fcfcb7b137, 2013-07-17 (annotated)
- Committer:
- pommzorz
- Date:
- Wed Jul 17 18:53:37 2013 +0000
- Revision:
- 1:85fcfcb7b137
- Parent:
- 0:9a1682a09c50
oops forgot one file...
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pommzorz | 0:9a1682a09c50 | 1 | /* Copyright (c) 2011 Pololu Corporation. For more information, see |
pommzorz | 0:9a1682a09c50 | 2 | * |
pommzorz | 0:9a1682a09c50 | 3 | * http://www.pololu.com/ |
pommzorz | 0:9a1682a09c50 | 4 | * http://forum.pololu.com/ |
pommzorz | 0:9a1682a09c50 | 5 | * |
pommzorz | 0:9a1682a09c50 | 6 | * Permission is hereby granted, free of charge, to any person |
pommzorz | 0:9a1682a09c50 | 7 | * obtaining a copy of this software and associated documentation |
pommzorz | 0:9a1682a09c50 | 8 | * files (the "Software"), to deal in the Software without |
pommzorz | 0:9a1682a09c50 | 9 | * restriction, including without limitation the rights to use, |
pommzorz | 0:9a1682a09c50 | 10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell |
pommzorz | 0:9a1682a09c50 | 11 | * copies of the Software, and to permit persons to whom the |
pommzorz | 0:9a1682a09c50 | 12 | * Software is furnished to do so, subject to the following |
pommzorz | 0:9a1682a09c50 | 13 | * conditions: |
pommzorz | 0:9a1682a09c50 | 14 | * |
pommzorz | 0:9a1682a09c50 | 15 | * The above copyright notice and this permission notice shall be |
pommzorz | 0:9a1682a09c50 | 16 | * included in all copies or substantial portions of the Software. |
pommzorz | 0:9a1682a09c50 | 17 | * |
pommzorz | 0:9a1682a09c50 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
pommzorz | 0:9a1682a09c50 | 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
pommzorz | 0:9a1682a09c50 | 20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
pommzorz | 0:9a1682a09c50 | 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
pommzorz | 0:9a1682a09c50 | 22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
pommzorz | 0:9a1682a09c50 | 23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
pommzorz | 0:9a1682a09c50 | 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
pommzorz | 0:9a1682a09c50 | 25 | * OTHER DEALINGS IN THE SOFTWARE. |
pommzorz | 0:9a1682a09c50 | 26 | */ |
pommzorz | 0:9a1682a09c50 | 27 | |
pommzorz | 0:9a1682a09c50 | 28 | #ifndef __L3G4200D_H |
pommzorz | 0:9a1682a09c50 | 29 | #define __L3G4200D_H |
pommzorz | 0:9a1682a09c50 | 30 | |
pommzorz | 0:9a1682a09c50 | 31 | #include "mbed.h" |
pommzorz | 0:9a1682a09c50 | 32 | |
pommzorz | 0:9a1682a09c50 | 33 | // register addresses |
pommzorz | 0:9a1682a09c50 | 34 | |
pommzorz | 0:9a1682a09c50 | 35 | #define L3G4200D_WHO_AM_I 0x0F |
pommzorz | 0:9a1682a09c50 | 36 | |
pommzorz | 0:9a1682a09c50 | 37 | #define L3G4200D_CTRL_REG1 0x20 |
pommzorz | 0:9a1682a09c50 | 38 | #define L3G4200D_CTRL_REG2 0x21 |
pommzorz | 0:9a1682a09c50 | 39 | #define L3G4200D_CTRL_REG3 0x22 |
pommzorz | 0:9a1682a09c50 | 40 | #define L3G4200D_CTRL_REG4 0x23 |
pommzorz | 0:9a1682a09c50 | 41 | #define L3G4200D_CTRL_REG5 0x24 |
pommzorz | 0:9a1682a09c50 | 42 | #define L3G4200D_REFERENCE 0x25 |
pommzorz | 0:9a1682a09c50 | 43 | #define L3G4200D_OUT_TEMP 0x26 |
pommzorz | 0:9a1682a09c50 | 44 | #define L3G4200D_STATUS_REG 0x27 |
pommzorz | 0:9a1682a09c50 | 45 | |
pommzorz | 0:9a1682a09c50 | 46 | #define L3G4200D_OUT_X_L 0x28 |
pommzorz | 0:9a1682a09c50 | 47 | #define L3G4200D_OUT_X_H 0x29 |
pommzorz | 0:9a1682a09c50 | 48 | #define L3G4200D_OUT_Y_L 0x2A |
pommzorz | 0:9a1682a09c50 | 49 | #define L3G4200D_OUT_Y_H 0x2B |
pommzorz | 0:9a1682a09c50 | 50 | #define L3G4200D_OUT_Z_L 0x2C |
pommzorz | 0:9a1682a09c50 | 51 | #define L3G4200D_OUT_Z_H 0x2D |
pommzorz | 0:9a1682a09c50 | 52 | |
pommzorz | 0:9a1682a09c50 | 53 | #define L3G4200D_FIFO_CTRL_REG 0x2E |
pommzorz | 0:9a1682a09c50 | 54 | #define L3G4200D_FIFO_SRC_REG 0x2F |
pommzorz | 0:9a1682a09c50 | 55 | |
pommzorz | 0:9a1682a09c50 | 56 | #define L3G4200D_INT1_CFG 0x30 |
pommzorz | 0:9a1682a09c50 | 57 | #define L3G4200D_INT1_SRC 0x31 |
pommzorz | 0:9a1682a09c50 | 58 | #define L3G4200D_INT1_THS_XH 0x32 |
pommzorz | 0:9a1682a09c50 | 59 | #define L3G4200D_INT1_THS_XL 0x33 |
pommzorz | 0:9a1682a09c50 | 60 | #define L3G4200D_INT1_THS_YH 0x34 |
pommzorz | 0:9a1682a09c50 | 61 | #define L3G4200D_INT1_THS_YL 0x35 |
pommzorz | 0:9a1682a09c50 | 62 | #define L3G4200D_INT1_THS_ZH 0x36 |
pommzorz | 0:9a1682a09c50 | 63 | #define L3G4200D_INT1_THS_ZL 0x37 |
pommzorz | 0:9a1682a09c50 | 64 | #define L3G4200D_INT1_DURATION 0x38 |
pommzorz | 0:9a1682a09c50 | 65 | |
pommzorz | 0:9a1682a09c50 | 66 | typedef char byte; |
pommzorz | 0:9a1682a09c50 | 67 | |
pommzorz | 0:9a1682a09c50 | 68 | /** Interface library for the ST L3G4200D 3-axis gyro |
pommzorz | 0:9a1682a09c50 | 69 | * |
pommzorz | 0:9a1682a09c50 | 70 | * Ported from Pololu L3G4200D library for Arduino by |
pommzorz | 0:9a1682a09c50 | 71 | * Michael Shimniok http://bot-thoughts.com |
pommzorz | 0:9a1682a09c50 | 72 | * |
pommzorz | 0:9a1682a09c50 | 73 | * @code |
pommzorz | 0:9a1682a09c50 | 74 | * #include "mbed.h" |
pommzorz | 0:9a1682a09c50 | 75 | * #include "L3G4200D.h" |
pommzorz | 0:9a1682a09c50 | 76 | * L3G4200D gyro(p28, p27); |
pommzorz | 0:9a1682a09c50 | 77 | * ... |
pommzorz | 0:9a1682a09c50 | 78 | * int g[3]; |
pommzorz | 0:9a1682a09c50 | 79 | * gyro.read(g); |
pommzorz | 0:9a1682a09c50 | 80 | * @endcode |
pommzorz | 0:9a1682a09c50 | 81 | */ |
pommzorz | 0:9a1682a09c50 | 82 | class L3G4200D |
pommzorz | 0:9a1682a09c50 | 83 | { |
pommzorz | 0:9a1682a09c50 | 84 | public: |
pommzorz | 0:9a1682a09c50 | 85 | /** Create a new L3G4200D I2C interface |
pommzorz | 0:9a1682a09c50 | 86 | * @param sda is the pin for the I2C SDA line |
pommzorz | 0:9a1682a09c50 | 87 | * @param scl is the pin for the I2C SCL line |
pommzorz | 0:9a1682a09c50 | 88 | */ |
pommzorz | 0:9a1682a09c50 | 89 | L3G4200D(PinName sda, PinName scl); |
pommzorz | 0:9a1682a09c50 | 90 | |
pommzorz | 0:9a1682a09c50 | 91 | /** Read gyro values |
pommzorz | 0:9a1682a09c50 | 92 | * @param g Array containing x, y, and z gyro values |
pommzorz | 0:9a1682a09c50 | 93 | * @return g Array containing x, y, and z gyro values |
pommzorz | 0:9a1682a09c50 | 94 | */ |
pommzorz | 0:9a1682a09c50 | 95 | void read(int *g); |
pommzorz | 0:9a1682a09c50 | 96 | void read3(int x, int y, int z); |
pommzorz | 0:9a1682a09c50 | 97 | void zeroCalibrate(unsigned int totSamples, unsigned int sampleDelayMS); |
pommzorz | 0:9a1682a09c50 | 98 | void readRawCal(int *_GyroXYZ); |
pommzorz | 0:9a1682a09c50 | 99 | void readFin(float *_GyroXYZ); // includes gain and offset |
pommzorz | 0:9a1682a09c50 | 100 | |
pommzorz | 0:9a1682a09c50 | 101 | private: |
pommzorz | 0:9a1682a09c50 | 102 | float gains[3]; |
pommzorz | 0:9a1682a09c50 | 103 | int offsets[3]; |
pommzorz | 0:9a1682a09c50 | 104 | float polarities[3]; |
pommzorz | 0:9a1682a09c50 | 105 | |
pommzorz | 0:9a1682a09c50 | 106 | void setGains(float _Xgain, float _Ygain, float _Zgain); |
pommzorz | 0:9a1682a09c50 | 107 | void setOffsets(int _Xoffset, int _Yoffset, int _Zoffset); |
pommzorz | 0:9a1682a09c50 | 108 | void setRevPolarity(bool _Xpol, bool _Ypol, bool _Zpol); // true = Reversed false = default |
pommzorz | 0:9a1682a09c50 | 109 | |
pommzorz | 0:9a1682a09c50 | 110 | |
pommzorz | 0:9a1682a09c50 | 111 | byte data[6]; |
pommzorz | 0:9a1682a09c50 | 112 | int _rates[3]; |
pommzorz | 0:9a1682a09c50 | 113 | I2C _device; |
pommzorz | 0:9a1682a09c50 | 114 | void writeReg(byte reg, byte value); |
pommzorz | 0:9a1682a09c50 | 115 | byte readReg(byte reg); |
pommzorz | 0:9a1682a09c50 | 116 | void enableDefault(void); |
pommzorz | 0:9a1682a09c50 | 117 | }; |
pommzorz | 0:9a1682a09c50 | 118 | |
pommzorz | 0:9a1682a09c50 | 119 | #endif |