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 __L3GD20_H
tzxl10000 0:561f7672eaad 29 #define __L3GD20_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 L3GD20_WHO_AM_I 0x0F
tzxl10000 0:561f7672eaad 36
tzxl10000 0:561f7672eaad 37 #define L3GD20_CTRL_REG1 0x20
tzxl10000 0:561f7672eaad 38 #define L3GD20_CTRL_REG2 0x21
tzxl10000 0:561f7672eaad 39 #define L3GD20_CTRL_REG3 0x22
tzxl10000 0:561f7672eaad 40 #define L3GD20_CTRL_REG4 0x23
tzxl10000 0:561f7672eaad 41 #define L3GD20_CTRL_REG5 0x24
tzxl10000 0:561f7672eaad 42 #define L3GD20_REFERENCE 0x25
tzxl10000 0:561f7672eaad 43 #define L3GD20_OUT_TEMP 0x26
tzxl10000 0:561f7672eaad 44 #define L3GD20_STATUS_REG 0x27
tzxl10000 0:561f7672eaad 45
tzxl10000 0:561f7672eaad 46 #define L3GD20_OUT_X_L 0x28
tzxl10000 0:561f7672eaad 47 #define L3GD20_OUT_X_H 0x29
tzxl10000 0:561f7672eaad 48 #define L3GD20_OUT_Y_L 0x2A
tzxl10000 0:561f7672eaad 49 #define L3GD20_OUT_Y_H 0x2B
tzxl10000 0:561f7672eaad 50 #define L3GD20_OUT_Z_L 0x2C
tzxl10000 0:561f7672eaad 51 #define L3GD20_OUT_Z_H 0x2D
tzxl10000 0:561f7672eaad 52
tzxl10000 0:561f7672eaad 53 #define L3GD20_FIFO_CTRL_REG 0x2E
tzxl10000 0:561f7672eaad 54 #define L3GD20_FIFO_SRC_REG 0x2F
tzxl10000 0:561f7672eaad 55
tzxl10000 0:561f7672eaad 56 #define L3GD20_INT1_CFG 0x30
tzxl10000 0:561f7672eaad 57 #define L3GD20_INT1_SRC 0x31
tzxl10000 0:561f7672eaad 58 #define L3GD20_INT1_THS_XH 0x32
tzxl10000 0:561f7672eaad 59 #define L3GD20_INT1_THS_XL 0x33
tzxl10000 0:561f7672eaad 60 #define L3GD20_INT1_THS_YH 0x34
tzxl10000 0:561f7672eaad 61 #define L3GD20_INT1_THS_YL 0x35
tzxl10000 0:561f7672eaad 62 #define L3GD20_INT1_THS_ZH 0x36
tzxl10000 0:561f7672eaad 63 #define L3GD20_INT1_THS_ZL 0x37
tzxl10000 0:561f7672eaad 64 #define L3GD20_INT1_DURATION 0x38
tzxl10000 0:561f7672eaad 65
tzxl10000 0:561f7672eaad 66 /** Interface library for the ST L3GD20 3-axis gyro
tzxl10000 0:561f7672eaad 67 *
tzxl10000 0:561f7672eaad 68 * Ported from Pololu L3GD20 library for Arduino by
tzxl10000 0:561f7672eaad 69 *
tzxl10000 0:561f7672eaad 70 * @code
tzxl10000 0:561f7672eaad 71 * #include "mbed.h"
tzxl10000 0:561f7672eaad 72 * #include "L3GD20.h"
tzxl10000 0:561f7672eaad 73 * L3GD20 gyro(p28, p27);
tzxl10000 0:561f7672eaad 74 * ...
tzxl10000 0:561f7672eaad 75 * int g[3];
tzxl10000 0:561f7672eaad 76 * gyro.read(g);
tzxl10000 0:561f7672eaad 77 * @endcode
tzxl10000 0:561f7672eaad 78 */
tzxl10000 0:561f7672eaad 79 class L3GD20
tzxl10000 0:561f7672eaad 80 {
tzxl10000 0:561f7672eaad 81 public:
tzxl10000 0:561f7672eaad 82 /** Create a new L3GD20 I2C interface
tzxl10000 0:561f7672eaad 83 * @param sda is the pin for the I2C SDA line
tzxl10000 0:561f7672eaad 84 * @param scl is the pin for the I2C SCL line
tzxl10000 0:561f7672eaad 85 */
tzxl10000 0:561f7672eaad 86 L3GD20(PinName sda, PinName scl);
tzxl10000 0:561f7672eaad 87
tzxl10000 0:561f7672eaad 88 /** Read gyro values
tzxl10000 0:561f7672eaad 89 * @param g Array containing x, y, and z gyro values
tzxl10000 0:561f7672eaad 90 * @return g Array containing x, y, and z gyro values
tzxl10000 0:561f7672eaad 91 */
tzxl10000 0:561f7672eaad 92 bool read(float *gx, float *gy, float *gz);
tzxl10000 0:561f7672eaad 93
tzxl10000 0:561f7672eaad 94 private:
tzxl10000 0:561f7672eaad 95 I2C _L3GD20;
tzxl10000 0:561f7672eaad 96 float gx, gy, gz;
tzxl10000 0:561f7672eaad 97
tzxl10000 0:561f7672eaad 98 bool write_reg(int addr_i2c,int addr_reg, char v);
tzxl10000 0:561f7672eaad 99 bool read_reg(int addr_i2c,int addr_reg, char *v);
tzxl10000 0:561f7672eaad 100 bool recv(char sad, char sub, char *buf, int length);
tzxl10000 0:561f7672eaad 101 };
tzxl10000 0:561f7672eaad 102
tzxl10000 0:561f7672eaad 103 #endif