Republished Library, to be refined for use with the SparkFun 9DOF in HARP project.
Fork of ADXL345 by
Diff: ADXL345.h
- 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 */