Republished Library, to be refined for use with the SparkFun 9DOF in HARP project.

Dependents:   vmConfort_v6

Fork of ADXL345 by Tyler Weaver

Committer:
tylerjw
Date:
Tue Nov 06 16:40:36 2012 +0000
Revision:
9:cc0260a2404b
Parent:
8:4cdd4315189f
Child:
10:d81793e01ec4
added config.txt functionality to init()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Digixx 0:1e4aa22fc1a1 1 /**
gltest26 3:7b83694c7292 2 * @file ADXL345.h
tylerjw 8:4cdd4315189f 3 * @author Tyler Weaver
Digixx 1:45faba962a46 4 * @author Uwe Gartmann
Digixx 1:45faba962a46 5 * @author Used ITG3200 library developed Peter Swanson as template
Digixx 1:45faba962a46 6 * A special thanks to Ewout van Bekkum for all his patient help in developing this library!
Digixx 0:1e4aa22fc1a1 7 *
Digixx 0:1e4aa22fc1a1 8 * @section LICENSE
Digixx 0:1e4aa22fc1a1 9 *
Digixx 0:1e4aa22fc1a1 10 * Permission is hereby granted, free of charge, to any person obtaining a copy
Digixx 0:1e4aa22fc1a1 11 * of this software and associated documentation files (the "Software"), to deal
Digixx 0:1e4aa22fc1a1 12 * in the Software without restriction, including without limitation the rights
Digixx 0:1e4aa22fc1a1 13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Digixx 0:1e4aa22fc1a1 14 * copies of the Software, and to permit persons to whom the Software is
Digixx 0:1e4aa22fc1a1 15 * furnished to do so, subject to the following conditions:
Digixx 0:1e4aa22fc1a1 16 *
Digixx 0:1e4aa22fc1a1 17 * The above copyright notice and this permission notice shall be included in
Digixx 0:1e4aa22fc1a1 18 * all copies or substantial portions of the Software.
Digixx 0:1e4aa22fc1a1 19 *
Digixx 0:1e4aa22fc1a1 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Digixx 0:1e4aa22fc1a1 21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Digixx 0:1e4aa22fc1a1 22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Digixx 0:1e4aa22fc1a1 23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Digixx 0:1e4aa22fc1a1 24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Digixx 0:1e4aa22fc1a1 25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Digixx 0:1e4aa22fc1a1 26 * THE SOFTWARE.
Digixx 0:1e4aa22fc1a1 27 *
Digixx 0:1e4aa22fc1a1 28 * @section DESCRIPTION
Digixx 0:1e4aa22fc1a1 29 *
Digixx 0:1e4aa22fc1a1 30 * ADXL345, triple axis, I2C interface, accelerometer.
Digixx 0:1e4aa22fc1a1 31 *
tylerjw 8:4cdd4315189f 32 * Modified for use with 9DOF sensor stick (no interupt pin access) on HARP project.
tylerjw 8:4cdd4315189f 33 *
Digixx 0:1e4aa22fc1a1 34 * Datasheet:
Digixx 0:1e4aa22fc1a1 35 *
Digixx 0:1e4aa22fc1a1 36 * http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf
tylerjw 8:4cdd4315189f 37 */
Digixx 0:1e4aa22fc1a1 38
Digixx 0:1e4aa22fc1a1 39
Digixx 0:1e4aa22fc1a1 40
Digixx 0:1e4aa22fc1a1 41 #ifndef ADXL345_H
Digixx 0:1e4aa22fc1a1 42 #define ADXL345_H
Digixx 0:1e4aa22fc1a1 43
gltest26 3:7b83694c7292 44 /*
Digixx 0:1e4aa22fc1a1 45 * Includes
Digixx 0:1e4aa22fc1a1 46 */
Digixx 0:1e4aa22fc1a1 47 #include "mbed.h"
Digixx 0:1e4aa22fc1a1 48
gltest26 3:7b83694c7292 49 /*
Digixx 0:1e4aa22fc1a1 50 * Defines
Digixx 0:1e4aa22fc1a1 51 */
Digixx 0:1e4aa22fc1a1 52 //Registers.
Digixx 0:1e4aa22fc1a1 53 #define ADXL345_DEVID_REG 0x00
Digixx 0:1e4aa22fc1a1 54 #define ADXL345_THRESH_TAP_REG 0x1D
Digixx 0:1e4aa22fc1a1 55 #define ADXL345_OFSX_REG 0x1E
Digixx 0:1e4aa22fc1a1 56 #define ADXL345_OFSY_REG 0x1F
Digixx 0:1e4aa22fc1a1 57 #define ADXL345_OFSZ_REG 0x20
Digixx 0:1e4aa22fc1a1 58 #define ADXL345_DUR_REG 0x21
Digixx 0:1e4aa22fc1a1 59 #define ADXL345_LATENT_REG 0x22
Digixx 0:1e4aa22fc1a1 60 #define ADXL345_WINDOW_REG 0x23
Digixx 0:1e4aa22fc1a1 61 #define ADXL345_THRESH_ACT_REG 0x24
Digixx 0:1e4aa22fc1a1 62 #define ADXL345_THRESH_INACT_REG 0x25
Digixx 0:1e4aa22fc1a1 63 #define ADXL345_TIME_INACT_REG 0x26
Digixx 0:1e4aa22fc1a1 64 #define ADXL345_ACT_INACT_CTL_REG 0x27
Digixx 0:1e4aa22fc1a1 65 #define ADXL345_THRESH_FF_REG 0x28
Digixx 0:1e4aa22fc1a1 66 #define ADXL345_TIME_FF_REG 0x29
Digixx 0:1e4aa22fc1a1 67 #define ADXL345_TAP_AXES_REG 0x2A
Digixx 0:1e4aa22fc1a1 68 #define ADXL345_ACT_TAP_STATUS_REG 0x2B
Digixx 0:1e4aa22fc1a1 69 #define ADXL345_BW_RATE_REG 0x2C
Digixx 0:1e4aa22fc1a1 70 #define ADXL345_POWER_CTL_REG 0x2D
Digixx 0:1e4aa22fc1a1 71 #define ADXL345_INT_ENABLE_REG 0x2E
Digixx 0:1e4aa22fc1a1 72 #define ADXL345_INT_MAP_REG 0x2F
Digixx 0:1e4aa22fc1a1 73 #define ADXL345_INT_SOURCE_REG 0x30
Digixx 0:1e4aa22fc1a1 74 #define ADXL345_DATA_FORMAT_REG 0x31
Digixx 0:1e4aa22fc1a1 75 #define ADXL345_DATAX0_REG 0x32
Digixx 0:1e4aa22fc1a1 76 #define ADXL345_DATAX1_REG 0x33
Digixx 0:1e4aa22fc1a1 77 #define ADXL345_DATAY0_REG 0x34
Digixx 0:1e4aa22fc1a1 78 #define ADXL345_DATAY1_REG 0x35
Digixx 0:1e4aa22fc1a1 79 #define ADXL345_DATAZ0_REG 0x36
Digixx 0:1e4aa22fc1a1 80 #define ADXL345_DATAZ1_REG 0x37
Digixx 0:1e4aa22fc1a1 81 #define ADXL345_FIFO_CTL 0x38
Digixx 0:1e4aa22fc1a1 82 #define ADXL345_FIFO_STATUS 0x39
Digixx 0:1e4aa22fc1a1 83
Digixx 0:1e4aa22fc1a1 84 //Data rate codes.
Digixx 0:1e4aa22fc1a1 85 #define ADXL345_3200HZ 0x0F
Digixx 0:1e4aa22fc1a1 86 #define ADXL345_1600HZ 0x0E
Digixx 0:1e4aa22fc1a1 87 #define ADXL345_800HZ 0x0D
Digixx 0:1e4aa22fc1a1 88 #define ADXL345_400HZ 0x0C
Digixx 0:1e4aa22fc1a1 89 #define ADXL345_200HZ 0x0B
Digixx 0:1e4aa22fc1a1 90 #define ADXL345_100HZ 0x0A
Digixx 0:1e4aa22fc1a1 91 #define ADXL345_50HZ 0x09
Digixx 0:1e4aa22fc1a1 92 #define ADXL345_25HZ 0x08
Digixx 0:1e4aa22fc1a1 93 #define ADXL345_12HZ5 0x07
Digixx 0:1e4aa22fc1a1 94 #define ADXL345_6HZ25 0x06
Digixx 0:1e4aa22fc1a1 95
tylerjw 6:5fb29534a6cf 96 // DATA_FORMAT register
tylerjw 6:5fb29534a6cf 97 #define ADXL345_2G 0x00
tylerjw 6:5fb29534a6cf 98 #define ADXL345_4G 0x01
tylerjw 6:5fb29534a6cf 99 #define ADXL345_8G 0x02
tylerjw 6:5fb29534a6cf 100 #define ADXL345_16G 0x03
tylerjw 6:5fb29534a6cf 101 #define ADXL345_LJUST 0x04
tylerjw 6:5fb29534a6cf 102 #define ADXL345_FULL_RES 0x08
tylerjw 6:5fb29534a6cf 103 #define ADXL345_INT_LOW 0x10
tylerjw 6:5fb29534a6cf 104 #define ADXL345_SELF_TEST 0x80
tylerjw 6:5fb29534a6cf 105
Digixx 0:1e4aa22fc1a1 106 // read or write bytes
tylerjw 8:4cdd4315189f 107 #define ADXL345_READ 0xA7
tylerjw 8:4cdd4315189f 108 #define ADXL345_WRITE 0xA6
Digixx 0:1e4aa22fc1a1 109 #define ADXL345_ADDRESS 0x53 //the ADXL345 7-bit address is 0x53 when ALT ADDRESS is low as it is on the sparkfun chip: when ALT ADDRESS is high the address is 0x1D
Digixx 0:1e4aa22fc1a1 110
Digixx 0:1e4aa22fc1a1 111 /////////////when ALT ADDRESS pin is high:
tylerjw 8:4cdd4315189f 112 //#define ADXL345_READ 0x3B
Digixx 0:1e4aa22fc1a1 113 //#define ADXL345_WRITE 0x3A
tylerjw 8:4cdd4315189f 114 //#define ADXL345_ADDRESS 0x1D
Digixx 0:1e4aa22fc1a1 115
Digixx 0:1e4aa22fc1a1 116 #define ADXL345_X 0x00
Digixx 0:1e4aa22fc1a1 117 #define ADXL345_Y 0x01
Digixx 0:1e4aa22fc1a1 118 #define ADXL345_Z 0x02
Digixx 0:1e4aa22fc1a1 119
Digixx 0:1e4aa22fc1a1 120 // modes
Digixx 0:1e4aa22fc1a1 121 #define MeasurementMode 0x08
Digixx 0:1e4aa22fc1a1 122
gltest26 3:7b83694c7292 123 /**
gltest26 3:7b83694c7292 124 * ADXL345 triple axis accelerometer.
gltest26 3:7b83694c7292 125 */
tylerjw 8:4cdd4315189f 126 class ADXL345
tylerjw 8:4cdd4315189f 127 {
Digixx 0:1e4aa22fc1a1 128
Digixx 0:1e4aa22fc1a1 129 public:
Digixx 0:1e4aa22fc1a1 130
gltest26 4:8046894b947e 131 static const char RANGE_BITS = 0x3;
gltest26 4:8046894b947e 132 static const char RANGE_2G = 0x0;
gltest26 4:8046894b947e 133 static const char RANGE_4G = 0x1;
gltest26 4:8046894b947e 134 static const char RANGE_8G = 0x2;
gltest26 4:8046894b947e 135 static const char RANGE_16G = 0x3;
gltest26 4:8046894b947e 136
Digixx 0:1e4aa22fc1a1 137 /**
Digixx 0:1e4aa22fc1a1 138 * Constructor.
Digixx 0:1e4aa22fc1a1 139 *
Digixx 0:1e4aa22fc1a1 140 * @param mosi mbed pin to use for SDA line of I2C interface.
Digixx 0:1e4aa22fc1a1 141 * @param sck mbed pin to use for SCL line of I2C interface.
Digixx 0:1e4aa22fc1a1 142 */
Digixx 0:1e4aa22fc1a1 143 ADXL345(PinName sda, PinName scl);
tylerjw 8:4cdd4315189f 144
gltest26 5:122a504fcfa3 145
gltest26 5:122a504fcfa3 146 /**
gltest26 5:122a504fcfa3 147 * Constructor that accepts external i2c interface object.
gltest26 5:122a504fcfa3 148 *
gltest26 5:122a504fcfa3 149 * @param i2c The I2C interface object to use.
gltest26 5:122a504fcfa3 150 */
tylerjw 9:cc0260a2404b 151 ADXL345(I2C &i2c) : i2c_(i2c), myI2c(NULL) {init();}
tylerjw 8:4cdd4315189f 152
gltest26 5:122a504fcfa3 153 /**
gltest26 5:122a504fcfa3 154 * Destructor that frees self-allocated I2C object.
gltest26 5:122a504fcfa3 155 */
gltest26 5:122a504fcfa3 156 ~ADXL345();
tylerjw 8:4cdd4315189f 157
gltest26 5:122a504fcfa3 158 void init();
Digixx 0:1e4aa22fc1a1 159
Digixx 0:1e4aa22fc1a1 160 /**
Digixx 0:1e4aa22fc1a1 161 * Get the output of all three axes.
Digixx 0:1e4aa22fc1a1 162 *
Digixx 0:1e4aa22fc1a1 163 * @param Pointer to a buffer to hold the accelerometer value for the
Digixx 0:1e4aa22fc1a1 164 * x-axis, y-axis and z-axis [in that order].
Digixx 0:1e4aa22fc1a1 165 */
tylerjw 8:4cdd4315189f 166 void getOutput(int16_t* readings);
Digixx 0:1e4aa22fc1a1 167
Digixx 0:1e4aa22fc1a1 168 /**
Digixx 0:1e4aa22fc1a1 169 * Read the device ID register on the device.
Digixx 0:1e4aa22fc1a1 170 *
Digixx 0:1e4aa22fc1a1 171 * @return The device ID code [0xE5]
Digixx 0:1e4aa22fc1a1 172 */
Digixx 0:1e4aa22fc1a1 173 char getDeviceID(void);
tylerjw 8:4cdd4315189f 174
tylerjw 8:4cdd4315189f 175 /**
tylerjw 8:4cdd4315189f 176 * Set the power mode.
tylerjw 8:4cdd4315189f 177 *
tylerjw 8:4cdd4315189f 178 * @param mode 0 -> Normal operation.
tylerjw 8:4cdd4315189f 179 * 1 -> Reduced power operation.
tylerjw 8:4cdd4315189f 180 */
Digixx 0:1e4aa22fc1a1 181 int setPowerMode(char mode);
tylerjw 8:4cdd4315189f 182
tylerjw 8:4cdd4315189f 183 /**
tylerjw 8:4cdd4315189f 184 * Get the BW_RATE register contents
tylerjw 8:4cdd4315189f 185 *
tylerjw 8:4cdd4315189f 186 * @returns The contents of BW_RATE register
tylerjw 8:4cdd4315189f 187 */
tylerjw 8:4cdd4315189f 188 char getBwRateReg();
tylerjw 8:4cdd4315189f 189
tylerjw 8:4cdd4315189f 190 /**
tylerjw 8:4cdd4315189f 191 * Set the BW_RATE register contents
tylerjw 8:4cdd4315189f 192 *
tylerjw 8:4cdd4315189f 193 * @param Byte to write to BW_RATE register
tylerjw 8:4cdd4315189f 194 */
tylerjw 8:4cdd4315189f 195 int setBwRateReg(char);
tylerjw 8:4cdd4315189f 196
tylerjw 8:4cdd4315189f 197 /**
tylerjw 8:4cdd4315189f 198 * Set the power control settings.
tylerjw 8:4cdd4315189f 199 *
tylerjw 8:4cdd4315189f 200 * See datasheet for details.
tylerjw 8:4cdd4315189f 201 *
tylerjw 8:4cdd4315189f 202 * @param The control byte to write to the POWER_CTL register.
tylerjw 8:4cdd4315189f 203 */
tylerjw 8:4cdd4315189f 204 int setPowerControl(char settings);
tylerjw 8:4cdd4315189f 205
tylerjw 8:4cdd4315189f 206 /**
tylerjw 8:4cdd4315189f 207 * Get the power control settings.
tylerjw 8:4cdd4315189f 208 *
tylerjw 8:4cdd4315189f 209 * See datasheet for details.
tylerjw 8:4cdd4315189f 210 *
tylerjw 8:4cdd4315189f 211 * @return The contents of the POWER_CTL register.
tylerjw 8:4cdd4315189f 212 */
Digixx 0:1e4aa22fc1a1 213 char getPowerControl(void);
Digixx 0:1e4aa22fc1a1 214
tylerjw 8:4cdd4315189f 215
Digixx 0:1e4aa22fc1a1 216 /**
Digixx 0:1e4aa22fc1a1 217 * Get the data format settings.
Digixx 0:1e4aa22fc1a1 218 *
Digixx 0:1e4aa22fc1a1 219 * @return The contents of the DATA_FORMAT register.
Digixx 0:1e4aa22fc1a1 220 */
tylerjw 8:4cdd4315189f 221
Digixx 0:1e4aa22fc1a1 222 char getDataFormatControl(void);
tylerjw 8:4cdd4315189f 223
Digixx 0:1e4aa22fc1a1 224 /**
Digixx 0:1e4aa22fc1a1 225 * Set the data format settings.
Digixx 0:1e4aa22fc1a1 226 *
Digixx 0:1e4aa22fc1a1 227 * @param settings The control byte to write to the DATA_FORMAT register.
Digixx 0:1e4aa22fc1a1 228 */
Digixx 0:1e4aa22fc1a1 229 int setDataFormatControl(char settings);
gltest26 4:8046894b947e 230
gltest26 4:8046894b947e 231 /**
gltest26 4:8046894b947e 232 * Set the data format settings with only specified bits.
gltest26 4:8046894b947e 233 *
gltest26 4:8046894b947e 234 * @param settings The control byte to write to the DATA_FORMAT register.
tylerjw 8:4cdd4315189f 235 * @param mask The mask bits that
gltest26 4:8046894b947e 236 */
gltest26 4:8046894b947e 237 int setDataFormatControl(char settings, char mask, char *prev = NULL);
tylerjw 8:4cdd4315189f 238
gltest26 4:8046894b947e 239 /**
Digixx 0:1e4aa22fc1a1 240 * Set the data rate.
Digixx 0:1e4aa22fc1a1 241 *
Digixx 0:1e4aa22fc1a1 242 * @param rate The rate code (see #defines or datasheet).
Digixx 0:1e4aa22fc1a1 243 */
Digixx 0:1e4aa22fc1a1 244 int setDataRate(char rate);
tylerjw 8:4cdd4315189f 245
Digixx 0:1e4aa22fc1a1 246
tylerjw 6:5fb29534a6cf 247 /**
Digixx 0:1e4aa22fc1a1 248 * Get the current offset for a particular axis.
Digixx 0:1e4aa22fc1a1 249 *
Digixx 0:1e4aa22fc1a1 250 * @param axis 0x00 -> X-axis
Digixx 0:1e4aa22fc1a1 251 * 0x01 -> Y-axis
Digixx 0:1e4aa22fc1a1 252 * 0x02 -> Z-axis
Digixx 0:1e4aa22fc1a1 253 * @return The current offset as an 8-bit 2's complement number with scale
Digixx 0:1e4aa22fc1a1 254 * factor 15.6mg/LSB.
Digixx 0:1e4aa22fc1a1 255 */
Digixx 0:1e4aa22fc1a1 256 char getOffset(char axis);
Digixx 0:1e4aa22fc1a1 257
Digixx 0:1e4aa22fc1a1 258 /**
Digixx 0:1e4aa22fc1a1 259 * Set the offset for a particular axis.
Digixx 0:1e4aa22fc1a1 260 *
Digixx 0:1e4aa22fc1a1 261 * @param axis 0x00 -> X-axis
Digixx 0:1e4aa22fc1a1 262 * 0x01 -> Y-axis
Digixx 0:1e4aa22fc1a1 263 * 0x02 -> Z-axis
Digixx 0:1e4aa22fc1a1 264 * @param offset The offset as an 8-bit 2's complement number with scale
Digixx 0:1e4aa22fc1a1 265 * factor 15.6mg/LSB.
Digixx 0:1e4aa22fc1a1 266 */
Digixx 0:1e4aa22fc1a1 267 int setOffset(char axis, char offset);
tylerjw 8:4cdd4315189f 268
Digixx 0:1e4aa22fc1a1 269 /**
Digixx 0:1e4aa22fc1a1 270 * Get the FIFO control settings.
Digixx 0:1e4aa22fc1a1 271 *
Digixx 0:1e4aa22fc1a1 272 * @return The contents of the FIFO_CTL register.
Digixx 0:1e4aa22fc1a1 273 */
Digixx 0:1e4aa22fc1a1 274 char getFifoControl(void);
tylerjw 8:4cdd4315189f 275
Digixx 0:1e4aa22fc1a1 276 /**
Digixx 0:1e4aa22fc1a1 277 * Set the FIFO control settings.
Digixx 0:1e4aa22fc1a1 278 *
Digixx 0:1e4aa22fc1a1 279 * @param The control byte to write to the FIFO_CTL register.
Digixx 0:1e4aa22fc1a1 280 */
Digixx 0:1e4aa22fc1a1 281 int setFifoControl(char settings);
tylerjw 8:4cdd4315189f 282
Digixx 0:1e4aa22fc1a1 283 /**
Digixx 0:1e4aa22fc1a1 284 * Get FIFO status.
Digixx 0:1e4aa22fc1a1 285 *
Digixx 0:1e4aa22fc1a1 286 * @return The contents of the FIFO_STATUS register.
Digixx 0:1e4aa22fc1a1 287 */
Digixx 0:1e4aa22fc1a1 288 char getFifoStatus(void);
tylerjw 8:4cdd4315189f 289
Digixx 0:1e4aa22fc1a1 290 /**
Digixx 0:1e4aa22fc1a1 291 * Read the tap threshold on the device.
Digixx 0:1e4aa22fc1a1 292 *
Digixx 0:1e4aa22fc1a1 293 * @return The tap threshold as an 8-bit number with a scale factor of
Digixx 0:1e4aa22fc1a1 294 * 62.5mg/LSB.
Digixx 0:1e4aa22fc1a1 295 */
Digixx 0:1e4aa22fc1a1 296 char getTapThreshold(void);
Digixx 0:1e4aa22fc1a1 297
Digixx 0:1e4aa22fc1a1 298 /**
Digixx 0:1e4aa22fc1a1 299 * Set the tap threshold.
Digixx 0:1e4aa22fc1a1 300 *
Digixx 0:1e4aa22fc1a1 301 * @param The tap threshold as an 8-bit number with a scale factor of
Digixx 0:1e4aa22fc1a1 302 * 62.5mg/LSB.
Digixx 0:1e4aa22fc1a1 303 */
Digixx 0:1e4aa22fc1a1 304 int setTapThreshold(char threshold);
Digixx 0:1e4aa22fc1a1 305
Digixx 0:1e4aa22fc1a1 306 /**
Digixx 0:1e4aa22fc1a1 307 * Get the tap duration required to trigger an event.
Digixx 0:1e4aa22fc1a1 308 *
Digixx 0:1e4aa22fc1a1 309 * @return The max time that an event must be above the tap threshold to
Digixx 0:1e4aa22fc1a1 310 * qualify as a tap event, in microseconds.
Digixx 0:1e4aa22fc1a1 311 */
Digixx 0:1e4aa22fc1a1 312 float getTapDuration(void);
Digixx 0:1e4aa22fc1a1 313
Digixx 0:1e4aa22fc1a1 314 /**
Digixx 0:1e4aa22fc1a1 315 * Set the tap duration required to trigger an event.
Digixx 0:1e4aa22fc1a1 316 *
Digixx 0:1e4aa22fc1a1 317 * @param duration_us The max time that an event must be above the tap
Digixx 0:1e4aa22fc1a1 318 * threshold to qualify as a tap event, in microseconds.
Digixx 0:1e4aa22fc1a1 319 * Time will be normalized by the scale factor which is
Digixx 0:1e4aa22fc1a1 320 * 625us/LSB. A value of 0 disables the single/double
Digixx 0:1e4aa22fc1a1 321 * tap functions.
Digixx 0:1e4aa22fc1a1 322 */
Digixx 0:1e4aa22fc1a1 323 int setTapDuration(short int duration_us);
Digixx 0:1e4aa22fc1a1 324
Digixx 0:1e4aa22fc1a1 325 /**
Digixx 0:1e4aa22fc1a1 326 * Get the tap latency between the detection of a tap and the time window.
Digixx 0:1e4aa22fc1a1 327 *
Digixx 0:1e4aa22fc1a1 328 * @return The wait time from the detection of a tap event to the start of
Digixx 0:1e4aa22fc1a1 329 * the time window during which a possible second tap event can be
Digixx 0:1e4aa22fc1a1 330 * detected in milliseconds.
Digixx 0:1e4aa22fc1a1 331 */
Digixx 0:1e4aa22fc1a1 332 float getTapLatency(void);
Digixx 0:1e4aa22fc1a1 333
Digixx 0:1e4aa22fc1a1 334 /**
Digixx 0:1e4aa22fc1a1 335 * Set the tap latency between the detection of a tap and the time window.
Digixx 0:1e4aa22fc1a1 336 *
Digixx 0:1e4aa22fc1a1 337 * @param latency_ms The wait time from the detection of a tap event to the
Digixx 0:1e4aa22fc1a1 338 * start of the time window during which a possible
Digixx 0:1e4aa22fc1a1 339 * second tap event can be detected in milliseconds.
Digixx 0:1e4aa22fc1a1 340 * A value of 0 disables the double tap function.
Digixx 0:1e4aa22fc1a1 341 */
Digixx 0:1e4aa22fc1a1 342 int setTapLatency(short int latency_ms);
Digixx 0:1e4aa22fc1a1 343
Digixx 0:1e4aa22fc1a1 344 /**
Digixx 0:1e4aa22fc1a1 345 * Get the time of window between tap latency and a double tap.
Digixx 0:1e4aa22fc1a1 346 *
Digixx 0:1e4aa22fc1a1 347 * @return The amount of time after the expiration of the latency time
Digixx 0:1e4aa22fc1a1 348 * during which a second valid tap can begin, in milliseconds.
Digixx 0:1e4aa22fc1a1 349 */
Digixx 0:1e4aa22fc1a1 350 float getWindowTime(void);
Digixx 0:1e4aa22fc1a1 351
Digixx 0:1e4aa22fc1a1 352 /**
Digixx 0:1e4aa22fc1a1 353 * Set the time of the window between tap latency and a double tap.
Digixx 0:1e4aa22fc1a1 354 *
Digixx 0:1e4aa22fc1a1 355 * @param window_ms The amount of time after the expiration of the latency
Digixx 0:1e4aa22fc1a1 356 * time during which a second valid tap can begin,
Digixx 0:1e4aa22fc1a1 357 * in milliseconds.
Digixx 0:1e4aa22fc1a1 358 */
Digixx 0:1e4aa22fc1a1 359 int setWindowTime(short int window_ms);
Digixx 0:1e4aa22fc1a1 360
Digixx 0:1e4aa22fc1a1 361 /**
Digixx 0:1e4aa22fc1a1 362 * Get the threshold value for detecting activity.
Digixx 0:1e4aa22fc1a1 363 *
Digixx 0:1e4aa22fc1a1 364 * @return The threshold value for detecting activity as an 8-bit number.
Digixx 0:1e4aa22fc1a1 365 * Scale factor is 62.5mg/LSB.
Digixx 0:1e4aa22fc1a1 366 */
tylerjw 8:4cdd4315189f 367 char getActivityThreshold(void);
Digixx 0:1e4aa22fc1a1 368
Digixx 0:1e4aa22fc1a1 369 /**
Digixx 0:1e4aa22fc1a1 370 * Set the threshold value for detecting activity.
Digixx 0:1e4aa22fc1a1 371 *
Digixx 0:1e4aa22fc1a1 372 * @param threshold The threshold value for detecting activity as an 8-bit
Digixx 0:1e4aa22fc1a1 373 * number. Scale factor is 62.5mg/LSB. A value of 0 may
Digixx 0:1e4aa22fc1a1 374 * result in undesirable behavior if the activity
Digixx 0:1e4aa22fc1a1 375 * interrupt is enabled.
Digixx 0:1e4aa22fc1a1 376 */
Digixx 0:1e4aa22fc1a1 377 int setActivityThreshold(char threshold);
Digixx 0:1e4aa22fc1a1 378
Digixx 0:1e4aa22fc1a1 379 /**
Digixx 0:1e4aa22fc1a1 380 * Get the threshold value for detecting inactivity.
Digixx 0:1e4aa22fc1a1 381 *
Digixx 0:1e4aa22fc1a1 382 * @return The threshold value for detecting inactivity as an 8-bit number.
Digixx 0:1e4aa22fc1a1 383 * Scale factor is 62.5mg/LSB.
Digixx 0:1e4aa22fc1a1 384 */
tylerjw 8:4cdd4315189f 385 char getInactivityThreshold(void);
Digixx 0:1e4aa22fc1a1 386
Digixx 0:1e4aa22fc1a1 387 /**
Digixx 0:1e4aa22fc1a1 388 * Set the threshold value for detecting inactivity.
Digixx 0:1e4aa22fc1a1 389 *
Digixx 0:1e4aa22fc1a1 390 * @param threshold The threshold value for detecting inactivity as an
Digixx 0:1e4aa22fc1a1 391 * 8-bit number. Scale factor is 62.5mg/LSB.
Digixx 0:1e4aa22fc1a1 392 */
Digixx 0:1e4aa22fc1a1 393 int setInactivityThreshold(char threshold);
Digixx 0:1e4aa22fc1a1 394
Digixx 0:1e4aa22fc1a1 395 /**
Digixx 0:1e4aa22fc1a1 396 * Get the time required for inactivity to be declared.
Digixx 0:1e4aa22fc1a1 397 *
Digixx 0:1e4aa22fc1a1 398 * @return The amount of time that acceleration must be less than the
Digixx 0:1e4aa22fc1a1 399 * inactivity threshold for inactivity to be declared, in
Digixx 0:1e4aa22fc1a1 400 * seconds.
Digixx 0:1e4aa22fc1a1 401 */
tylerjw 8:4cdd4315189f 402 char getTimeInactivity(void);
tylerjw 8:4cdd4315189f 403
Digixx 0:1e4aa22fc1a1 404 /**
Digixx 0:1e4aa22fc1a1 405 * Set the time required for inactivity to be declared.
Digixx 0:1e4aa22fc1a1 406 *
Digixx 0:1e4aa22fc1a1 407 * @param inactivity The amount of time that acceleration must be less than
Digixx 0:1e4aa22fc1a1 408 * the inactivity threshold for inactivity to be
Digixx 0:1e4aa22fc1a1 409 * declared, in seconds. A value of 0 results in an
Digixx 0:1e4aa22fc1a1 410 * interrupt when the output data is less than the
Digixx 0:1e4aa22fc1a1 411 * threshold inactivity.
Digixx 0:1e4aa22fc1a1 412 */
Digixx 0:1e4aa22fc1a1 413 int setTimeInactivity(char timeInactivity);
tylerjw 8:4cdd4315189f 414
Digixx 0:1e4aa22fc1a1 415 /**
Digixx 0:1e4aa22fc1a1 416 * Get the activity/inactivity control settings.
Digixx 0:1e4aa22fc1a1 417 *
Digixx 0:1e4aa22fc1a1 418 * D7 D6 D5 D4
Digixx 0:1e4aa22fc1a1 419 * +-----------+--------------+--------------+--------------+
Digixx 0:1e4aa22fc1a1 420 * | ACT ac/dc | ACT_X enable | ACT_Y enable | ACT_Z enable |
Digixx 0:1e4aa22fc1a1 421 * +-----------+--------------+--------------+--------------+
Digixx 0:1e4aa22fc1a1 422 *
Digixx 0:1e4aa22fc1a1 423 * D3 D2 D1 D0
Digixx 0:1e4aa22fc1a1 424 * +-------------+----------------+----------------+----------------+
Digixx 0:1e4aa22fc1a1 425 * | INACT ac/dc | INACT_X enable | INACT_Y enable | INACT_Z enable |
Digixx 0:1e4aa22fc1a1 426 * +-------------+----------------+----------------+----------------+
Digixx 0:1e4aa22fc1a1 427 *
Digixx 0:1e4aa22fc1a1 428 * See datasheet for details.
Digixx 0:1e4aa22fc1a1 429 *
Digixx 0:1e4aa22fc1a1 430 * @return The contents of the ACT_INACT_CTL register.
Digixx 0:1e4aa22fc1a1 431 */
tylerjw 8:4cdd4315189f 432 char getActivityInactivityControl(void);
tylerjw 8:4cdd4315189f 433
Digixx 0:1e4aa22fc1a1 434 /**
Digixx 0:1e4aa22fc1a1 435 * Set the activity/inactivity control settings.
Digixx 0:1e4aa22fc1a1 436 *
Digixx 0:1e4aa22fc1a1 437 * D7 D6 D5 D4
Digixx 0:1e4aa22fc1a1 438 * +-----------+--------------+--------------+--------------+
Digixx 0:1e4aa22fc1a1 439 * | ACT ac/dc | ACT_X enable | ACT_Y enable | ACT_Z enable |
Digixx 0:1e4aa22fc1a1 440 * +-----------+--------------+--------------+--------------+
Digixx 0:1e4aa22fc1a1 441 *
Digixx 0:1e4aa22fc1a1 442 * D3 D2 D1 D0
Digixx 0:1e4aa22fc1a1 443 * +-------------+----------------+----------------+----------------+
Digixx 0:1e4aa22fc1a1 444 * | INACT ac/dc | INACT_X enable | INACT_Y enable | INACT_Z enable |
Digixx 0:1e4aa22fc1a1 445 * +-------------+----------------+----------------+----------------+
Digixx 0:1e4aa22fc1a1 446 *
Digixx 0:1e4aa22fc1a1 447 * See datasheet for details.
Digixx 0:1e4aa22fc1a1 448 *
Digixx 0:1e4aa22fc1a1 449 * @param settings The control byte to write to the ACT_INACT_CTL register.
Digixx 0:1e4aa22fc1a1 450 */
Digixx 0:1e4aa22fc1a1 451 int setActivityInactivityControl(char settings);
tylerjw 8:4cdd4315189f 452
Digixx 0:1e4aa22fc1a1 453 /**
Digixx 0:1e4aa22fc1a1 454 * Get the threshold for free fall detection.
Digixx 0:1e4aa22fc1a1 455 *
Digixx 0:1e4aa22fc1a1 456 * @return The threshold value for free-fall detection, as an 8-bit number,
Digixx 0:1e4aa22fc1a1 457 * with scale factor 62.5mg/LSB.
Digixx 0:1e4aa22fc1a1 458 */
tylerjw 8:4cdd4315189f 459 char getFreefallThreshold(void);
tylerjw 8:4cdd4315189f 460
Digixx 0:1e4aa22fc1a1 461 /**
Digixx 0:1e4aa22fc1a1 462 * Set the threshold for free fall detection.
Digixx 0:1e4aa22fc1a1 463 *
Digixx 0:1e4aa22fc1a1 464 * @return The threshold value for free-fall detection, as an 8-bit number,
tylerjw 8:4cdd4315189f 465 * with scale factor 62.5mg/LSB. A value of 0 may result in
Digixx 0:1e4aa22fc1a1 466 * undesirable behavior if the free-fall interrupt is enabled.
Digixx 0:1e4aa22fc1a1 467 * Values between 300 mg and 600 mg (0x05 to 0x09) are recommended.
Digixx 0:1e4aa22fc1a1 468 */
Digixx 0:1e4aa22fc1a1 469 int setFreefallThreshold(char threshold);
tylerjw 8:4cdd4315189f 470
Digixx 0:1e4aa22fc1a1 471 /**
Digixx 0:1e4aa22fc1a1 472 * Get the time required to generate a free fall interrupt.
Digixx 0:1e4aa22fc1a1 473 *
Digixx 0:1e4aa22fc1a1 474 * @return The minimum time that the value of all axes must be less than
Digixx 0:1e4aa22fc1a1 475 * the freefall threshold to generate a free-fall interrupt, in
Digixx 0:1e4aa22fc1a1 476 * milliseconds.
Digixx 0:1e4aa22fc1a1 477 */
tylerjw 8:4cdd4315189f 478 char getFreefallTime(void);
tylerjw 8:4cdd4315189f 479
Digixx 0:1e4aa22fc1a1 480 /**
Digixx 0:1e4aa22fc1a1 481 * Set the time required to generate a free fall interrupt.
Digixx 0:1e4aa22fc1a1 482 *
Digixx 0:1e4aa22fc1a1 483 * @return The minimum time that the value of all axes must be less than
Digixx 0:1e4aa22fc1a1 484 * the freefall threshold to generate a free-fall interrupt, in
Digixx 0:1e4aa22fc1a1 485 * milliseconds. A value of 0 may result in undesirable behavior
tylerjw 8:4cdd4315189f 486 * if the free-fall interrupt is enabled. Values between 100 ms
Digixx 0:1e4aa22fc1a1 487 * and 350 ms (0x14 to 0x46) are recommended.
Digixx 0:1e4aa22fc1a1 488 */
Digixx 0:1e4aa22fc1a1 489 int setFreefallTime(short int freefallTime_ms);
tylerjw 8:4cdd4315189f 490
Digixx 0:1e4aa22fc1a1 491 /**
Digixx 0:1e4aa22fc1a1 492 * Get the axis tap settings.
Digixx 0:1e4aa22fc1a1 493 *
Digixx 0:1e4aa22fc1a1 494 * D3 D2 D1 D0
Digixx 0:1e4aa22fc1a1 495 * +----------+--------------+--------------+--------------+
Digixx 0:1e4aa22fc1a1 496 * | Suppress | TAP_X enable | TAP_Y enable | TAP_Z enable |
Digixx 0:1e4aa22fc1a1 497 * +----------+--------------+--------------+--------------+
Digixx 0:1e4aa22fc1a1 498 *
Digixx 0:1e4aa22fc1a1 499 * (D7-D4 are 0s).
Digixx 0:1e4aa22fc1a1 500 *
Digixx 0:1e4aa22fc1a1 501 * See datasheet for more details.
Digixx 0:1e4aa22fc1a1 502 *
Digixx 0:1e4aa22fc1a1 503 * @return The contents of the TAP_AXES register.
tylerjw 8:4cdd4315189f 504 */
tylerjw 8:4cdd4315189f 505 char getTapAxisControl(void);
tylerjw 8:4cdd4315189f 506
Digixx 0:1e4aa22fc1a1 507 /**
Digixx 0:1e4aa22fc1a1 508 * Set the axis tap settings.
Digixx 0:1e4aa22fc1a1 509 *
Digixx 0:1e4aa22fc1a1 510 * D3 D2 D1 D0
Digixx 0:1e4aa22fc1a1 511 * +----------+--------------+--------------+--------------+
Digixx 0:1e4aa22fc1a1 512 * | Suppress | TAP_X enable | TAP_Y enable | TAP_Z enable |
Digixx 0:1e4aa22fc1a1 513 * +----------+--------------+--------------+--------------+
Digixx 0:1e4aa22fc1a1 514 *
Digixx 0:1e4aa22fc1a1 515 * (D7-D4 are 0s).
Digixx 0:1e4aa22fc1a1 516 *
Digixx 0:1e4aa22fc1a1 517 * See datasheet for more details.
Digixx 0:1e4aa22fc1a1 518 *
Digixx 0:1e4aa22fc1a1 519 * @param The control byte to write to the TAP_AXES register.
Digixx 0:1e4aa22fc1a1 520 */
Digixx 0:1e4aa22fc1a1 521 int setTapAxisControl(char settings);
tylerjw 8:4cdd4315189f 522
Digixx 0:1e4aa22fc1a1 523 /**
Digixx 0:1e4aa22fc1a1 524 * Get the source of a tap.
Digixx 0:1e4aa22fc1a1 525 *
Digixx 0:1e4aa22fc1a1 526 * @return The contents of the ACT_TAP_STATUS register.
Digixx 0:1e4aa22fc1a1 527 */
tylerjw 8:4cdd4315189f 528 char getTapSource(void);
Digixx 0:1e4aa22fc1a1 529
tylerjw 8:4cdd4315189f 530 /**
tylerjw 8:4cdd4315189f 531 * Get the interrupt enable settings.
tylerjw 8:4cdd4315189f 532 *
tylerjw 8:4cdd4315189f 533 * @return The contents of the INT_ENABLE register.
tylerjw 8:4cdd4315189f 534 */
tylerjw 8:4cdd4315189f 535
tylerjw 8:4cdd4315189f 536 char getInterruptEnableControl(void);
tylerjw 8:4cdd4315189f 537
Digixx 0:1e4aa22fc1a1 538 /**
Digixx 0:1e4aa22fc1a1 539 * Set the interrupt enable settings.
Digixx 0:1e4aa22fc1a1 540 *
Digixx 0:1e4aa22fc1a1 541 * @param settings The control byte to write to the INT_ENABLE register.
Digixx 0:1e4aa22fc1a1 542 */
Digixx 0:1e4aa22fc1a1 543 int setInterruptEnableControl(char settings);
tylerjw 8:4cdd4315189f 544
Digixx 0:1e4aa22fc1a1 545 /**
Digixx 0:1e4aa22fc1a1 546 * Get the interrupt mapping settings.
Digixx 0:1e4aa22fc1a1 547 *
Digixx 0:1e4aa22fc1a1 548 * @return The contents of the INT_MAP register.
Digixx 0:1e4aa22fc1a1 549 */
tylerjw 8:4cdd4315189f 550 char getInterruptMappingControl(void);
tylerjw 8:4cdd4315189f 551
Digixx 0:1e4aa22fc1a1 552 /**
Digixx 0:1e4aa22fc1a1 553 * Set the interrupt mapping settings.
Digixx 0:1e4aa22fc1a1 554 *
Digixx 0:1e4aa22fc1a1 555 * @param settings The control byte to write to the INT_MAP register.
Digixx 0:1e4aa22fc1a1 556 */
Digixx 0:1e4aa22fc1a1 557 int setInterruptMappingControl(char settings);
tylerjw 8:4cdd4315189f 558
Digixx 0:1e4aa22fc1a1 559 /**
Digixx 0:1e4aa22fc1a1 560 * Get the interrupt source.
Digixx 0:1e4aa22fc1a1 561 *
Digixx 0:1e4aa22fc1a1 562 * @return The contents of the INT_SOURCE register.
Digixx 0:1e4aa22fc1a1 563 */
tylerjw 8:4cdd4315189f 564 char getInterruptSource(void);
tylerjw 8:4cdd4315189f 565
tylerjw 8:4cdd4315189f 566 /**
tylerjw 8:4cdd4315189f 567 * Calibrate using the calibrate routine, sets the offset registers
tylerjw 8:4cdd4315189f 568 *
tylerjw 8:4cdd4315189f 569 * 100 samples at 100Hz (1 second)
tylerjw 8:4cdd4315189f 570 * Sensor should be in x=0g,y=0g,z=1g orientation and held still
tylerjw 8:4cdd4315189f 571 *
tylerjw 8:4cdd4315189f 572 * @param pointer to timer object (should already be started)
tylerjw 8:4cdd4315189f 573 * @param store_output true -> stores offsets in local file system, false -> only offset registers are set
tylerjw 8:4cdd4315189f 574 * @param serial output (pc) for debugging
tylerjw 8:4cdd4315189f 575 */
tylerjw 8:4cdd4315189f 576 void calibrate(Timer*, bool, Serial*);
tylerjw 8:4cdd4315189f 577 /**
tylerjw 8:4cdd4315189f 578 * Calibrate using the calibrate routine, sets the offset registers
tylerjw 8:4cdd4315189f 579 *
tylerjw 8:4cdd4315189f 580 * 100 samples at 100Hz (1 second)
tylerjw 8:4cdd4315189f 581 * Sensor should be in x=0g,y=0g,z=1g orientation and held still
tylerjw 8:4cdd4315189f 582 *
tylerjw 8:4cdd4315189f 583 * @param pointer to timer object (should already be started)
tylerjw 8:4cdd4315189f 584 * @param store_output true -> stores offsets in local file system, false -> only offset registers are set
tylerjw 8:4cdd4315189f 585 */
tylerjw 8:4cdd4315189f 586 void calibrate(Timer*, bool);
tylerjw 8:4cdd4315189f 587
Digixx 0:1e4aa22fc1a1 588 private:
Digixx 0:1e4aa22fc1a1 589
gltest26 5:122a504fcfa3 590 I2C &i2c_;
tylerjw 8:4cdd4315189f 591
gltest26 5:122a504fcfa3 592 I2C *myI2c;
Digixx 0:1e4aa22fc1a1 593
Digixx 0:1e4aa22fc1a1 594 /**
Digixx 0:1e4aa22fc1a1 595 * Read one byte from a register on the device.
Digixx 0:1e4aa22fc1a1 596 *
Digixx 0:1e4aa22fc1a1 597 * @param: - the address to be read from
Digixx 0:1e4aa22fc1a1 598 *
Digixx 0:1e4aa22fc1a1 599 * @return: the value of the data read
Digixx 0:1e4aa22fc1a1 600 */
Digixx 0:1e4aa22fc1a1 601 char SingleByteRead(char address);
Digixx 0:1e4aa22fc1a1 602
Digixx 0:1e4aa22fc1a1 603 /**
Digixx 0:1e4aa22fc1a1 604 * Write one byte to a register on the device.
Digixx 0:1e4aa22fc1a1 605 *
Digixx 0:1e4aa22fc1a1 606 * @param:
Digixx 0:1e4aa22fc1a1 607 - address of the register to write to.
Digixx 0:1e4aa22fc1a1 608 - the value of the data to store
Digixx 0:1e4aa22fc1a1 609 */
gltest26 4:8046894b947e 610 int SingleByteWrite(char address, char data);
Digixx 0:1e4aa22fc1a1 611
Digixx 0:1e4aa22fc1a1 612 /**
Digixx 0:1e4aa22fc1a1 613 * Read several consecutive bytes on the device and store them in a given location.
Digixx 0:1e4aa22fc1a1 614 *
Digixx 0:1e4aa22fc1a1 615 * @param startAddress: The address of the first register to read from.
Digixx 0:1e4aa22fc1a1 616 * @param ptr_output: a pointer to the location to store the data being read
Digixx 0:1e4aa22fc1a1 617 * @param size: The number of bytes to read.
Digixx 0:1e4aa22fc1a1 618 */
Digixx 0:1e4aa22fc1a1 619 void multiByteRead(char startAddress, char* ptr_output, int size);
Digixx 0:1e4aa22fc1a1 620
Digixx 0:1e4aa22fc1a1 621 /**
Digixx 0:1e4aa22fc1a1 622 * Write several consecutive bytes on the device.
Digixx 0:1e4aa22fc1a1 623 *
Digixx 0:1e4aa22fc1a1 624 * @param startAddress: The address of the first register to write to.
Digixx 0:1e4aa22fc1a1 625 * @param ptr_data: Pointer to a location which contains the data to write.
Digixx 0:1e4aa22fc1a1 626 * @param size: The number of bytes to write.
Digixx 0:1e4aa22fc1a1 627 */
Digixx 0:1e4aa22fc1a1 628 int multiByteWrite(char startAddress, char* ptr_data, int size);
tylerjw 9:cc0260a2404b 629
gltest26 3:7b83694c7292 630 /**
gltest26 3:7b83694c7292 631 * Converts little-endian 2's complement byte pair to native byte order of
gltest26 3:7b83694c7292 632 * the CPU and then sign extend it to the CPU's register size.
gltest26 3:7b83694c7292 633 *
gltest26 3:7b83694c7292 634 * Implemented here to make the compiler inline expand it.
gltest26 3:7b83694c7292 635 */
tylerjw 8:4cdd4315189f 636 static int wordExtend(const char rx[2]) {
gltest26 3:7b83694c7292 637 // Readings are expressed in 16bit 2's complement, so we must first
gltest26 3:7b83694c7292 638 // concatenate two bytes to make a word and sign extend it to obtain
gltest26 3:7b83694c7292 639 // correct negative values.
gltest26 3:7b83694c7292 640 // ARMCC compiles char as unsigned, which means no sign extension is
gltest26 3:7b83694c7292 641 // performed during bitwise operations to chars. But we should make sure
gltest26 3:7b83694c7292 642 // that lower byte won't extend its sign past upper byte for other
gltest26 3:7b83694c7292 643 // compilers if we want to keep it portable.
gltest26 3:7b83694c7292 644 return int16_t(((unsigned char)rx[1] << 8) | (unsigned char)rx[0]);
gltest26 3:7b83694c7292 645 }
tylerjw 9:cc0260a2404b 646
tylerjw 9:cc0260a2404b 647 /**
tylerjw 9:cc0260a2404b 648 * Sample 100 times and average
tylerjw 9:cc0260a2404b 649 *
tylerjw 9:cc0260a2404b 650 * @param period of sample rate
tylerjw 9:cc0260a2404b 651 * @param array to hold raw data, should be int16_t[100][3] (sample,axis)
tylerjw 9:cc0260a2404b 652 * @param array to hold averages, should be 3 in length
tylerjw 9:cc0260a2404b 653 * @param pointer to timer object
tylerjw 9:cc0260a2404b 654 */
tylerjw 9:cc0260a2404b 655 void sample100avg(float, int16_t[][3], int16_t*, Timer*);
Digixx 0:1e4aa22fc1a1 656 };
Digixx 0:1e4aa22fc1a1 657
Digixx 0:1e4aa22fc1a1 658 #endif /* ADXL345_H */