Adafruit 9DOF - L3GD20H Driver

Dependents:   Galileo_HoverBoardRider projetinterface

Committer:
julioefajardo
Date:
Sat Apr 09 04:27:11 2016 +0000
Revision:
0:81b60e58e9e1
Adafruit 9 DOF - L3GD20H Driver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
julioefajardo 0:81b60e58e9e1 1 /* Copyright (c) 2011 Pololu Corporation. For more information, see
julioefajardo 0:81b60e58e9e1 2 *
julioefajardo 0:81b60e58e9e1 3 * http://www.pololu.com/
julioefajardo 0:81b60e58e9e1 4 * http://forum.pololu.com/
julioefajardo 0:81b60e58e9e1 5 *
julioefajardo 0:81b60e58e9e1 6 * Permission is hereby granted, free of charge, to any person
julioefajardo 0:81b60e58e9e1 7 * obtaining a copy of this software and associated documentation
julioefajardo 0:81b60e58e9e1 8 * files (the "Software"), to deal in the Software without
julioefajardo 0:81b60e58e9e1 9 * restriction, including without limitation the rights to use,
julioefajardo 0:81b60e58e9e1 10 * copy, modify, merge, publish, distribute, sublicense, and/or sell
julioefajardo 0:81b60e58e9e1 11 * copies of the Software, and to permit persons to whom the
julioefajardo 0:81b60e58e9e1 12 * Software is furnished to do so, subject to the following
julioefajardo 0:81b60e58e9e1 13 * conditions:
julioefajardo 0:81b60e58e9e1 14 *
julioefajardo 0:81b60e58e9e1 15 * The above copyright notice and this permission notice shall be
julioefajardo 0:81b60e58e9e1 16 * included in all copies or substantial portions of the Software.
julioefajardo 0:81b60e58e9e1 17 *
julioefajardo 0:81b60e58e9e1 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
julioefajardo 0:81b60e58e9e1 19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
julioefajardo 0:81b60e58e9e1 20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
julioefajardo 0:81b60e58e9e1 21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
julioefajardo 0:81b60e58e9e1 22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
julioefajardo 0:81b60e58e9e1 23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
julioefajardo 0:81b60e58e9e1 24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
julioefajardo 0:81b60e58e9e1 25 * OTHER DEALINGS IN THE SOFTWARE.
julioefajardo 0:81b60e58e9e1 26 */
julioefajardo 0:81b60e58e9e1 27
julioefajardo 0:81b60e58e9e1 28 #ifndef __L3GD20H_H
julioefajardo 0:81b60e58e9e1 29 #define __L3GD20H_H
julioefajardo 0:81b60e58e9e1 30
julioefajardo 0:81b60e58e9e1 31 #include "mbed.h"
julioefajardo 0:81b60e58e9e1 32
julioefajardo 0:81b60e58e9e1 33 // register addresses
julioefajardo 0:81b60e58e9e1 34
julioefajardo 0:81b60e58e9e1 35 #define L3GD20_WHO_AM_I 0x0F
julioefajardo 0:81b60e58e9e1 36
julioefajardo 0:81b60e58e9e1 37 #define L3GD20_CTRL_REG1 0x20
julioefajardo 0:81b60e58e9e1 38 #define L3GD20_CTRL_REG2 0x21
julioefajardo 0:81b60e58e9e1 39 #define L3GD20_CTRL_REG3 0x22
julioefajardo 0:81b60e58e9e1 40 #define L3GD20_CTRL_REG4 0x23
julioefajardo 0:81b60e58e9e1 41 #define L3GD20_CTRL_REG5 0x24
julioefajardo 0:81b60e58e9e1 42 #define L3GD20_REFERENCE 0x25
julioefajardo 0:81b60e58e9e1 43 #define L3GD20_OUT_TEMP 0x26
julioefajardo 0:81b60e58e9e1 44 #define L3GD20_STATUS_REG 0x27
julioefajardo 0:81b60e58e9e1 45
julioefajardo 0:81b60e58e9e1 46 #define L3GD20_OUT_X_L 0x28
julioefajardo 0:81b60e58e9e1 47 #define L3GD20_OUT_X_H 0x29
julioefajardo 0:81b60e58e9e1 48 #define L3GD20_OUT_Y_L 0x2A
julioefajardo 0:81b60e58e9e1 49 #define L3GD20_OUT_Y_H 0x2B
julioefajardo 0:81b60e58e9e1 50 #define L3GD20_OUT_Z_L 0x2C
julioefajardo 0:81b60e58e9e1 51 #define L3GD20_OUT_Z_H 0x2D
julioefajardo 0:81b60e58e9e1 52
julioefajardo 0:81b60e58e9e1 53 #define L3GD20_FIFO_CTRL_REG 0x2E
julioefajardo 0:81b60e58e9e1 54 #define L3GD20_FIFO_SRC_REG 0x2F
julioefajardo 0:81b60e58e9e1 55
julioefajardo 0:81b60e58e9e1 56 #define L3GD20_INT1_CFG 0x30
julioefajardo 0:81b60e58e9e1 57 #define L3GD20_INT1_SRC 0x31
julioefajardo 0:81b60e58e9e1 58 #define L3GD20_INT1_THS_XH 0x32
julioefajardo 0:81b60e58e9e1 59 #define L3GD20_INT1_THS_XL 0x33
julioefajardo 0:81b60e58e9e1 60 #define L3GD20_INT1_THS_YH 0x34
julioefajardo 0:81b60e58e9e1 61 #define L3GD20_INT1_THS_YL 0x35
julioefajardo 0:81b60e58e9e1 62 #define L3GD20_INT1_THS_ZH 0x36
julioefajardo 0:81b60e58e9e1 63 #define L3GD20_INT1_THS_ZL 0x37
julioefajardo 0:81b60e58e9e1 64 #define L3GD20_INT1_DURATION 0x38
julioefajardo 0:81b60e58e9e1 65
julioefajardo 0:81b60e58e9e1 66 /** Interface library for the ST L3GD20 3-axis gyro
julioefajardo 0:81b60e58e9e1 67 *
julioefajardo 0:81b60e58e9e1 68 * Ported from Pololu L3GD20 library for Arduino by
julioefajardo 0:81b60e58e9e1 69 *
julioefajardo 0:81b60e58e9e1 70 * @code
julioefajardo 0:81b60e58e9e1 71 * #include "mbed.h"
julioefajardo 0:81b60e58e9e1 72 * #include "L3GD20.h"
julioefajardo 0:81b60e58e9e1 73 * L3GD20 gyro(p28, p27);
julioefajardo 0:81b60e58e9e1 74 * ...
julioefajardo 0:81b60e58e9e1 75 * int g[3];
julioefajardo 0:81b60e58e9e1 76 * gyro.read(g);
julioefajardo 0:81b60e58e9e1 77 * @endcode
julioefajardo 0:81b60e58e9e1 78 */
julioefajardo 0:81b60e58e9e1 79 class L3GD20H
julioefajardo 0:81b60e58e9e1 80 {
julioefajardo 0:81b60e58e9e1 81 public:
julioefajardo 0:81b60e58e9e1 82 /** Create a new L3GD20 I2C interface
julioefajardo 0:81b60e58e9e1 83 * @param sda is the pin for the I2C SDA line
julioefajardo 0:81b60e58e9e1 84 * @param scl is the pin for the I2C SCL line
julioefajardo 0:81b60e58e9e1 85 */
julioefajardo 0:81b60e58e9e1 86 L3GD20H(PinName sda, PinName scl);
julioefajardo 0:81b60e58e9e1 87
julioefajardo 0:81b60e58e9e1 88 /** Read gyro values
julioefajardo 0:81b60e58e9e1 89 * @param g Array containing x, y, and z gyro values
julioefajardo 0:81b60e58e9e1 90 * @return g Array containing x, y, and z gyro values
julioefajardo 0:81b60e58e9e1 91 */
julioefajardo 0:81b60e58e9e1 92 bool read(short g[3]);
julioefajardo 0:81b60e58e9e1 93
julioefajardo 0:81b60e58e9e1 94 private:
julioefajardo 0:81b60e58e9e1 95 I2C _L3GD20H;
julioefajardo 0:81b60e58e9e1 96 short gx, gy, gz;
julioefajardo 0:81b60e58e9e1 97
julioefajardo 0:81b60e58e9e1 98 bool write_reg(int addr_i2c,int addr_reg, char v);
julioefajardo 0:81b60e58e9e1 99 bool read_reg(int addr_i2c,int addr_reg, char *v);
julioefajardo 0:81b60e58e9e1 100 bool recv(char sad, char sub, char *buf, int length);
julioefajardo 0:81b60e58e9e1 101 };
julioefajardo 0:81b60e58e9e1 102
julioefajardo 0:81b60e58e9e1 103 #endif