fish

Dependencies:   mbed

Committer:
tzxl10000
Date:
Wed Jun 14 20:22:45 2017 +0000
Revision:
0:561f7672eaad
fish;

Who changed what in which revision?

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