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:
Wed Sep 12 22:56:04 2012 +0000
Parent:
4:155c44407af5
Child:
6:a7ad6046824c
Commit message:
Made byte ordering and sign extending portable.

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	Wed Sep 12 15:23:29 2012 +0000
+++ b/ITG3200.cpp	Wed Sep 12 22:56:04 2012 +0000
@@ -205,14 +205,7 @@
     
     i2c_.read(I2C_ADDRESS, rx, 2);
     
-    // Readings are expressed in 16bit 2's complement, so we must first
-    // concatenate two bytes to make a word and sign extend it to obtain
-    // correct negative values.
-    // ARMCC compiles char as unsigned, which means no sign extension is
-    // performed during bitwise operations to chars. But we should make sure
-    // that lower byte won't extend its sign past upper byte for other
-    // compilers if we want to keep it portable.
-    return int16_t(((unsigned)rx[0] << 8) | (unsigned)rx[1]);
+    return swapExtend(rx);
 }
 
 float ITG3200::getTemperature(){
@@ -231,7 +224,7 @@
     i2c_.read(I2C_ADDRESS, rx, 6);
     
     for(int i = 0; i < 3; i++)
-        readings[i] = int16_t((unsigned) rx[i * 2 + 0] << 8) | ((unsigned) rx[i * 2 + 1]);
+        readings[i] = swapExtend(&rx[i * 2]);
 }
 
 char ITG3200::getPowerManagement(void){
--- a/ITG3200.h	Wed Sep 12 15:23:29 2012 +0000
+++ b/ITG3200.h	Wed Sep 12 22:56:04 2012 +0000
@@ -425,6 +425,22 @@
 
     I2C i2c_;
 
+    /**
+     * Converts big-endian 2's complement byte pair to native byte order of
+     * the CPU and then sign extend it to the CPU's register size.
+     *
+     * Implemented here to make the compiler inline expand it.
+     */
+    int swapExtend(const char rx[2]){
+        // Readings are expressed in 16bit 2's complement, so we must first
+        // concatenate two bytes to make a word and sign extend it to obtain
+        // correct negative values.
+        // ARMCC compiles char as unsigned, which means no sign extension is
+        // performed during bitwise operations to chars. But we should make sure
+        // that lower byte won't extend its sign past upper byte for other
+        // compilers if we want to keep it portable.
+        return int16_t(((unsigned char)rx[0] << 8) | (unsigned char)rx[1]);
+    }
 };