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