some correction to work nice

Dependents:   Minimu-9v2

Fork of L3GD20 by brian claus

L3GD20.h

Committer:
patsteph
Date:
2013-11-17
Revision:
2:90eddd0eff29
Parent:
0:62dfce144cf7

File content as of revision 2:90eddd0eff29:

#ifndef __L3GD20_H
#define __L3GD20_H

#include "mbed.h"

// Defines ////////////////////////////////////////////////////////////////

// The Arduino two-wire interface uses a 7-bit number for the address, 
// and sets the last bit correctly based on reads and writes
// mbed I2C libraries take the 7-bit address shifted left 1 bit
// #define GYR_ADDRESS (0xD2 >> 1)
#define GYR_ADDRESS 0xD6

// register addresses

#define L3GD20_WHO_AM_I      0x0F

#define L3GD20_CTRL_REG1     0x20
#define L3GD20_CTRL_REG2     0x21
#define L3GD20_CTRL_REG3     0x22
#define L3GD20_CTRL_REG4     0x23
#define L3GD20_CTRL_REG5     0x24
#define L3GD20_REFERENCE     0x25
#define L3GD20_OUT_TEMP      0x26
#define L3GD20_STATUS_REG    0x27

#define L3GD20_OUT_X_L       0x28
#define L3GD20_OUT_X_H       0x29
#define L3GD20_OUT_Y_L       0x2A
#define L3GD20_OUT_Y_H       0x2B
#define L3GD20_OUT_Z_L       0x2C
#define L3GD20_OUT_Z_H       0x2D

#define L3GD20_FIFO_CTRL_REG 0x2E
#define L3GD20_FIFO_SRC_REG  0x2F

#define L3GD20_INT1_CFG      0x30
#define L3GD20_INT1_SRC      0x31
#define L3GD20_INT1_THS_XH   0x32
#define L3GD20_INT1_THS_XL   0x33
#define L3GD20_INT1_THS_YH   0x34
#define L3GD20_INT1_THS_YL   0x35
#define L3GD20_INT1_THS_ZH   0x36
#define L3GD20_INT1_THS_ZL   0x37
#define L3GD20_INT1_DURATION 0x38

// device types

#define L3G_DEVICE_AUTO 0
#define L3G4200D_DEVICE 1
#define L3GD20_DEVICE 2

// SA0 states

#define L3G_SA0_LOW 0
#define L3G_SA0_HIGH 1
#define L3G_SA0_AUTO 2

/** Interface library for the ST L3GD20 3-axis gyro
 *
 * Ported from Pololu L3GD20 library for Arduino by
 *
 * @code
 * #include "mbed.h"
 * #include "L3GD20.h"
 * L3GD20 gyro(p28, p27);
 * ...
 * int g[3];
 * gyro.read(g);
 * @endcode
 */
class L3GD20
{
    public:
        /** Create a new L3GD20 I2C interface
         * @param sda is the pin for the I2C SDA line
         * @param scl is the pin for the I2C SCL line
         */
        L3GD20(PinName sda, PinName scl);
        
        /** Read gyro values
         * @param g Array containing x, y, and z gyro values
         * @return g Array containing x, y, and z gyro values
         */
        bool read(float *gx, float *gy, float *gz);
        bool write_reg(int addr_i2c,int addr_reg, char v);
        
    private:
            I2C _L3GD20;
        float gx, gy, gz;

        
        bool read_reg(int addr_i2c,int addr_reg, char *v);
        bool recv(char sad, char sub, char *buf, int length);
};

#endif