AHRS library for the Polulu minIMU-9 Ability to interface with the Polulu Python minIMU-9 monitor
Diff: L3G4200D.h
- Revision:
- 1:3272ece36ce1
- Parent:
- 0:dc35364e2291
--- a/L3G4200D.h Thu Apr 12 13:47:23 2012 +0000 +++ b/L3G4200D.h Mon Apr 23 14:31:08 2012 +0000 @@ -1,112 +1,62 @@ -/* mbed L3G4200D Library version 0.1 - * Copyright (c) 2012 Prediluted - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - #ifndef L3G4200D_h #define L3G4200D_h #include "mbed.h" -#include <vector> +// register addresses + +#define L3G4200D_WHO_AM_I 0x0F + +#define L3G4200D_CTRL_REG1 0x20 +#define L3G4200D_CTRL_REG2 0x21 +#define L3G4200D_CTRL_REG3 0x22 +#define L3G4200D_CTRL_REG4 0x23 +#define L3G4200D_CTRL_REG5 0x24 +#define L3G4200D_REFERENCE 0x25 +#define L3G4200D_OUT_TEMP 0x26 +#define L3G4200D_STATUS_REG 0x27 + +#define L3G4200D_OUT_X_L 0x28 +#define L3G4200D_OUT_X_H 0x29 +#define L3G4200D_OUT_Y_L 0x2A +#define L3G4200D_OUT_Y_H 0x2B +#define L3G4200D_OUT_Z_L 0x2C +#define L3G4200D_OUT_Z_H 0x2D + +#define L3G4200D_FIFO_CTRL_REG 0x2E +#define L3G4200D_FIFO_SRC_REG 0x2F + +#define L3G4200D_INT1_CFG 0x30 +#define L3G4200D_INT1_SRC 0x31 +#define L3G4200D_INT1_THS_XH 0x32 +#define L3G4200D_INT1_THS_XL 0x33 +#define L3G4200D_INT1_THS_YH 0x34 +#define L3G4200D_INT1_THS_YL 0x35 +#define L3G4200D_INT1_THS_ZH 0x36 +#define L3G4200D_INT1_THS_ZL 0x37 +#define L3G4200D_INT1_DURATION 0x38 +#define GYR_ADDRESS ( 0xD2 >> 1 ) + +typedef unsigned char byte; class L3G4200D { - public: + typedef struct Plane { + float x, y, z; + } Plane; - /** - * Create an L3G4200D object connected to the specified I2C pins - * @param sda I2C SDA pin - * @param scl I2C SCL pin - */ - L3G4200D( PinName sda, PinName scl ); - L3G4200D( void ); - - /** - * Return status code of prevoius function call - */ - inline int getStatus( void ) { return( _status ); } - - /** - * Read specified register content - * @param reg register address - */ - int registerRead( int reg ); - - /** - * Write to specified register - * @param reg register address - * @parma data data to be written - */ - void registerWrite( int reg, char data ); - - /** - * read gyroscope vector - */ - std::vector<short> read( void ); + Plane g; // gyro angular velocity readings + I2C i2c; + L3G4200D(PinName, PinName); - /** - * Read angular velogity (in degrees per second) - */ - std::vector<float> angularVelocity( void ); - - /** - * Read temperature (in celsius) - */ - int temperature( void ); + void writeReg(byte reg, byte value); + char readReg(byte reg); + + void read(void); - // Device registers addresses - static const int WHO_AM_I; - static const int CTRL_REG1; - static const int CTRL_REG2; - static const int CTRL_REG3; - static const int CTRL_REG4; - static const int CTRL_REG5; - static const int REFERENCE; - static const int OUT_TEMP; - static const int STATUS_REG; - static const int OUT_X_L; - static const int OUT_X_H; - static const int OUT_Y_L; - static const int OUT_Y_H; - static const int OUT_Z_L; - static const int OUT_Z_H; - static const int FIFO_CTRL_REG; - static const int FIFO_SRC_REG; - static const int INT1_CFG; - static const int INT1_SRC; - static const int INT1_THS_XH; - static const int INT1_THS_XL; - static const int INT1_THS_YH; - static const int INT1_THS_YL; - static const int INT1_THS_ZH; - static const int INT1_THS_ZL; - static const int INT1_DURATION; - -private: - - int _status; - I2C _i2c; - char _bytes[7]; - - static const int GYR_ADDRESS; - + // vector functions + static void vector_cross(const Plane *a, const Plane *b, Plane *out); + static float vector_dot(const Plane *a,const Plane *b); + static void vector_normalize(Plane *a); }; -#endif // L3G4200D_h \ No newline at end of file +#endif