Tyler Weaver / ITG3200

Dependents:   9Dof_unit_testing

Fork of ITG3200 by James Watanabe

Revision:
5:0a0315f0f34e
Parent:
4:155c44407af5
Child:
6:a7ad6046824c
--- 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){