My attempt to make a better lib (in development)

Dependents:   Nucleo_i2c_9dof

Fork of L3GD20 by brian claus

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers L3GD20.h Source File

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 #define L3GD20_LOW_ODR       0x39 // D20H
00066 
00067 
00068 #define DPS_TO_RPS  57.2957795130824
00069 
00070 /** Interface library for the ST L3GD20 3-axis gyro
00071  *
00072  * Ported from Pololu L3GD20 library for Arduino by
00073  *
00074  * @code
00075  * #include "mbed.h"
00076  * #include "L3GD20.h"
00077  * L3GD20 gyro(p28, p27);
00078  * ...
00079  * int g[3];
00080  * gyro.read(g);
00081  * @endcode
00082  */
00083 class L3GD20
00084 {
00085     public:
00086         /** Create a new L3GD20 I2C interface
00087          * @param sda is the pin for the I2C SDA line
00088          * @param scl is the pin for the I2C SCL line
00089          */
00090         L3GD20(PinName sda, PinName scl);
00091         L3GD20(I2C *pI2C);
00092         
00093         /** Destructor of the class
00094          */
00095          ~L3GD20();
00096         
00097         /** Read gyro values
00098          * @param g Array containing x, y, and z gyro values
00099          * @return g Array containing x, y, and z gyro values
00100          */
00101         bool read(float *gx, float *gy, float *gz);
00102         bool Convert_to_RadPerSec(float *gx, float *gy, float *gz);
00103         
00104     private:
00105         I2C* m_ptr_I2C;//_L3GD20;
00106         float gx, gy, gz;
00107 
00108         void init(void) ;
00109         bool write_reg(int addr_i2c,int addr_reg, char v);
00110         bool read_reg(int addr_i2c,int addr_reg, char *v);
00111         bool recv(char sad, char sub, char *buf, int length);
00112 };
00113 
00114 #endif