Forked from Uwe Gartmann's ADXL345 library, customized as part of the 9DOF stick from Sparkfun.com

Fork of ADXL345 by Uwe Gartmann

ADXL345 is triple axis, digital interface, accelerometer.

This library is forked from Uwe Gartmann and Peter Swanson's work.

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

Datasheet:

http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf

ADXL345は3軸のデジタルインターフェースを備えた加速度センサです。

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

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

Revision:
3:7b83694c7292
Parent:
1:45faba962a46
Child:
4:8046894b947e
--- a/ADXL345.h	Sun Sep 09 15:37:26 2012 +0000
+++ b/ADXL345.h	Thu Sep 13 11:43:11 2012 +0000
@@ -1,4 +1,5 @@
 /**
+ * @file ADXL345.h
  * @author Uwe Gartmann
  * @author Used ITG3200 library developed Peter Swanson as template
  * A special thanks to Ewout van Bekkum for all his patient help in developing this library!
@@ -37,12 +38,12 @@
 #ifndef ADXL345_H
 #define ADXL345_H
 
-/**
+/*
  * Includes
  */
 #include "mbed.h"
 
-/**
+/*
  * Defines
  */
 //Registers.
@@ -113,7 +114,9 @@
 
 
 
-
+/**
+ * ADXL345 triple axis accelerometer.
+ */
 class ADXL345 {
 
 public:
@@ -554,6 +557,25 @@
      */
     int multiByteWrite(char startAddress, char* ptr_data, int size);
 
+private:
+
+    /**
+     * Converts little-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.
+     */
+    static int wordExtend(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[1] << 8) | (unsigned char)rx[0]);
+    }
+
 };
 
 #endif /* ADXL345_H */