unterwasserman
Fork of L3GD20 by
Embed:
(wiki syntax)
Show/hide line numbers
L3GD20.h
00001 /* Copyright (c) 2011 Pololu Corporation. For more information, see 00002 * 00003 * http://www.pololu.com/ 00004 * http://forum.pololu.com/ 00005 * 00006 * Permission is hereby granted, free of charge, to any person 00007 * obtaining a copy of this software and associated documentation 00008 * files (the "Software"), to deal in the Software without 00009 * restriction, including without limitation the rights to use, 00010 * copy, modify, merge, publish, distribute, sublicense, and/or sell 00011 * copies of the Software, and to permit persons to whom the 00012 * Software is furnished to do so, subject to the following 00013 * conditions: 00014 * 00015 * The above copyright notice and this permission notice shall be 00016 * included in all copies or substantial portions of the Software. 00017 * 00018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00019 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 00020 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00021 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 00022 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 00023 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00024 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00025 * OTHER DEALINGS IN THE SOFTWARE. 00026 */ 00027 00028 #ifndef __L3GD20_H 00029 #define __L3GD20_H 00030 00031 #include "mbed.h" 00032 00033 // register addresses 00034 00035 #define L3GD20_WHO_AM_I 0x0F 00036 00037 #define L3GD20_CTRL_REG1 0x20 00038 #define L3GD20_CTRL_REG2 0x21 00039 #define L3GD20_CTRL_REG3 0x22 00040 #define L3GD20_CTRL_REG4 0x23 00041 #define L3GD20_CTRL_REG5 0x24 00042 #define L3GD20_REFERENCE 0x25 00043 #define L3GD20_OUT_TEMP 0x26 00044 #define L3GD20_STATUS_REG 0x27 00045 00046 #define L3GD20_OUT_X_L 0x28 00047 #define L3GD20_OUT_X_H 0x29 00048 #define L3GD20_OUT_Y_L 0x2A 00049 #define L3GD20_OUT_Y_H 0x2B 00050 #define L3GD20_OUT_Z_L 0x2C 00051 #define L3GD20_OUT_Z_H 0x2D 00052 00053 #define L3GD20_FIFO_CTRL_REG 0x2E 00054 #define L3GD20_FIFO_SRC_REG 0x2F 00055 00056 #define L3GD20_INT1_CFG 0x30 00057 #define L3GD20_INT1_SRC 0x31 00058 #define L3GD20_INT1_THS_XH 0x32 00059 #define L3GD20_INT1_THS_XL 0x33 00060 #define L3GD20_INT1_THS_YH 0x34 00061 #define L3GD20_INT1_THS_YL 0x35 00062 #define L3GD20_INT1_THS_ZH 0x36 00063 #define L3GD20_INT1_THS_ZL 0x37 00064 #define L3GD20_INT1_DURATION 0x38 00065 00066 /** Interface library for the ST L3GD20 3-axis gyro 00067 * 00068 * Ported from Pololu L3GD20 library for Arduino by 00069 * 00070 * @code 00071 * #include "mbed.h" 00072 * #include "L3GD20.h" 00073 * L3GD20 gyro(p28, p27); 00074 * ... 00075 * int g[3]; 00076 * gyro.read(g); 00077 * @endcode 00078 */ 00079 class L3GD20 00080 { 00081 public: 00082 /** Create a new L3GD20 I2C interface 00083 * @param sda is the pin for the I2C SDA line 00084 * @param scl is the pin for the I2C SCL line 00085 */ 00086 L3GD20(PinName sda, PinName scl); 00087 00088 /** Read gyro values 00089 * @param g Array containing x, y, and z gyro values 00090 * @return g Array containing x, y, and z gyro values 00091 */ 00092 bool read(float *gx, float *gy, float *gz); 00093 00094 private: 00095 I2C _L3GD20; 00096 float gx, gy, gz; 00097 00098 bool write_reg(int addr_i2c,int addr_reg, char v); 00099 bool read_reg(int addr_i2c,int addr_reg, char *v); 00100 bool recv(char sad, char sub, char *buf, int length); 00101 }; 00102 00103 #endif
Generated on Mon Aug 8 2022 02:44:08 by 1.7.2