Forked from Aaron Berk's ITG3200 driver class library, customized for my specific application using 9DoF-Stick by Sparkfun.

Dependents:   HARP

Fork of ITG3200 by Aaron Berk

ITG-3200 is triple axis, digital interface, gyro sensor.

This library is forked from Aaron Berk's work.

This library is for specific application using 9DoF-Stick.

Datasheet:

http://invensense.com/mems/gyro/documents/PS-ITG-3200-00-01.4.pdf

This library has a feature to correct thermal drift of the device. For details, see Thermal Drift.

ITG-3200は3軸のデジタルインターフェースを備えたジャイロセンサです。

このライブラリは 9DoF-Stick を使用した特定の企画のために保守しています。

mbed IDEが日本語をサポートするまでは英語でコメントを書いていきますが、サポートした後もきっと英語で書いていくでしょう。

このライブラリはデバイスの熱ドリフトを補正する機能を持っています。詳しくは Thermal Drift

Files at this revision

API Documentation at this revision

Comitter:
gltest26
Date:
Tue Oct 02 17:09:20 2012 +0000
Parent:
7:43b936a53b64
Child:
9:05396b551a9a
Commit message:
Added a new constructor to accept an external I2C interface object.

Changed in this revision

ITG3200.cpp Show annotated file Show diff for this revision Revisions of this file
ITG3200.h Show annotated file Show diff for this revision Revisions of this file
--- a/ITG3200.cpp	Sat Sep 29 14:34:17 2012 +0000
+++ b/ITG3200.cpp	Tue Oct 02 17:09:20 2012 +0000
@@ -34,8 +34,11 @@
  */
 
 #include "ITG3200.h"
+#include <new>
 
-ITG3200::ITG3200(PinName sda, PinName scl, bool fastmode) : calibSamples(0), i2c_(sda, scl){
+ITG3200::ITG3200(PinName sda, PinName scl, bool fastmode) : calibSamples(0), i2c_(*reinterpret_cast<I2C*>(i2cRaw)){
+    // Placement new to avoid additional heap memory allocation.
+    new(i2cRaw) I2C(sda, scl);
 
     offset[0] = offset[1] = offset[2] = 0;
 
@@ -45,7 +48,15 @@
     }
     else
         i2c_.frequency(100000);
+}    
     
+ITG3200::~ITG3200(){
+    // If the I2C object is initialized in the buffer in this object, call destructor of it.
+    if(&i2c_ == reinterpret_cast<I2C*>(&i2cRaw))
+        reinterpret_cast<I2C*>(&i2cRaw)->~I2C();
+}
+
+void ITG3200::init(){
     //Set FS_SEL to 0x03 for proper operation.
     //See datasheet for details.
     char tx[2];
--- a/ITG3200.h	Sat Sep 29 14:34:17 2012 +0000
+++ b/ITG3200.h	Tue Oct 02 17:09:20 2012 +0000
@@ -106,6 +106,19 @@
      * @param fastmode Sets the internal I2C interface to use 400kHz clock.
      */
     ITG3200(PinName sda, PinName scl, bool fastmode = false);
+    
+    /**
+     * Constructor that accepts external i2c interface object.
+     *
+     * @param i2c The I2C interface object to use.
+     */
+    ITG3200(I2C &i2c) : i2c_(i2c){
+        init();
+    }
+    
+    ~ITG3200();
+    
+    void init();
 
     /**
      * Get the identity of the device.
@@ -446,7 +459,12 @@
     
 private:
 
-    I2C i2c_;
+    I2C &i2c_;
+    
+    /**
+     * The raw buffer for allocating I2C object in its own without heap memory.
+     */
+    char i2cRaw[sizeof(I2C)];
 
     /**
      * Converts big-endian 2's complement byte pair to native byte order of