Slightly modified version (to work with processing GUI)

Dependencies:   ITG3200 mbed

Fork of 6DoF_IMU_readvalue by Ryo Nakabayashi

Committer:
Vigneshwar
Date:
Tue Oct 22 00:13:07 2013 +0000
Revision:
3:04df9b19199b
Parent:
0:cda6d9f5a43c
Child:
5:e4a11d519322
njm

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ryought 0:cda6d9f5a43c 1 /**
ryought 0:cda6d9f5a43c 2 * @author Peter Swanson
ryought 0:cda6d9f5a43c 3 * A personal note from me: Jesus Christ has changed my life so much it blows my mind. I say this because
ryought 0:cda6d9f5a43c 4 * today, religion is thought of as something that you do or believe and has about as
ryought 0:cda6d9f5a43c 5 * little impact on a person as their political stance. But for me, God gives me daily
ryought 0:cda6d9f5a43c 6 * strength and has filled my life with the satisfaction that I could never find in any
Vigneshwar 3:04df9b19199b 7 * of the other things that I once looked for it in.
ryought 0:cda6d9f5a43c 8 * If your interested, heres verse that changed my life:
ryought 0:cda6d9f5a43c 9 * Rom 8:1-3: "Therefore, there is now no condemnation for those who are in Christ Jesus,
ryought 0:cda6d9f5a43c 10 * because through Christ Jesus, the law of the Spirit who gives life has set
Vigneshwar 3:04df9b19199b 11 * me free from the law of sin (which brings...) and death. For what the law
ryought 0:cda6d9f5a43c 12 * was powerless to do in that it was weakened by the flesh, God did by sending
ryought 0:cda6d9f5a43c 13 * His own Son in the likeness of sinful flesh to be a sin offering. And so He
Vigneshwar 3:04df9b19199b 14 * condemned sin in the flesh in order that the righteous requirements of the
ryought 0:cda6d9f5a43c 15 * (God's) law might be fully met in us, who live not according to the flesh
ryought 0:cda6d9f5a43c 16 * but according to the Spirit."
ryought 0:cda6d9f5a43c 17 *
ryought 0:cda6d9f5a43c 18 * A special thanks to Ewout van Bekkum for all his patient help in developing this library!
ryought 0:cda6d9f5a43c 19 *
ryought 0:cda6d9f5a43c 20 * @section LICENSE
ryought 0:cda6d9f5a43c 21 *
ryought 0:cda6d9f5a43c 22 * Permission is hereby granted, free of charge, to any person obtaining a copy
ryought 0:cda6d9f5a43c 23 * of this software and associated documentation files (the "Software"), to deal
ryought 0:cda6d9f5a43c 24 * in the Software without restriction, including without limitation the rights
ryought 0:cda6d9f5a43c 25 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
ryought 0:cda6d9f5a43c 26 * copies of the Software, and to permit persons to whom the Software is
ryought 0:cda6d9f5a43c 27 * furnished to do so, subject to the following conditions:
ryought 0:cda6d9f5a43c 28 *
ryought 0:cda6d9f5a43c 29 * The above copyright notice and this permission notice shall be included in
ryought 0:cda6d9f5a43c 30 * all copies or substantial portions of the Software.
ryought 0:cda6d9f5a43c 31 *
ryought 0:cda6d9f5a43c 32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ryought 0:cda6d9f5a43c 33 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ryought 0:cda6d9f5a43c 34 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ryought 0:cda6d9f5a43c 35 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ryought 0:cda6d9f5a43c 36 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ryought 0:cda6d9f5a43c 37 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
ryought 0:cda6d9f5a43c 38 * THE SOFTWARE.
ryought 0:cda6d9f5a43c 39 *
ryought 0:cda6d9f5a43c 40 * @section DESCRIPTION
ryought 0:cda6d9f5a43c 41 *
ryought 0:cda6d9f5a43c 42 * ADXL345, triple axis, I2C interface, accelerometer.
ryought 0:cda6d9f5a43c 43 *
ryought 0:cda6d9f5a43c 44 * Datasheet:
ryought 0:cda6d9f5a43c 45 *
ryought 0:cda6d9f5a43c 46 * http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf
Vigneshwar 3:04df9b19199b 47 */
ryought 0:cda6d9f5a43c 48
ryought 0:cda6d9f5a43c 49
ryought 0:cda6d9f5a43c 50
ryought 0:cda6d9f5a43c 51 #ifndef ADXL345_I2C_H
ryought 0:cda6d9f5a43c 52 #define ADXL345_I2C_H
ryought 0:cda6d9f5a43c 53
ryought 0:cda6d9f5a43c 54 /**
ryought 0:cda6d9f5a43c 55 * Includes
ryought 0:cda6d9f5a43c 56 */
ryought 0:cda6d9f5a43c 57 #include "mbed.h"
ryought 0:cda6d9f5a43c 58
ryought 0:cda6d9f5a43c 59 /**
ryought 0:cda6d9f5a43c 60 * Defines
ryought 0:cda6d9f5a43c 61 */
ryought 0:cda6d9f5a43c 62 //Registers.
ryought 0:cda6d9f5a43c 63 #define ADXL345_DEVID_REG 0x00
ryought 0:cda6d9f5a43c 64 #define ADXL345_THRESH_TAP_REG 0x1D
ryought 0:cda6d9f5a43c 65 #define ADXL345_OFSX_REG 0x1E
ryought 0:cda6d9f5a43c 66 #define ADXL345_OFSY_REG 0x1F
ryought 0:cda6d9f5a43c 67 #define ADXL345_OFSZ_REG 0x20
ryought 0:cda6d9f5a43c 68 #define ADXL345_DUR_REG 0x21
ryought 0:cda6d9f5a43c 69 #define ADXL345_LATENT_REG 0x22
ryought 0:cda6d9f5a43c 70 #define ADXL345_WINDOW_REG 0x23
ryought 0:cda6d9f5a43c 71 #define ADXL345_THRESH_ACT_REG 0x24
ryought 0:cda6d9f5a43c 72 #define ADXL345_THRESH_INACT_REG 0x25
ryought 0:cda6d9f5a43c 73 #define ADXL345_TIME_INACT_REG 0x26
ryought 0:cda6d9f5a43c 74 #define ADXL345_ACT_INACT_CTL_REG 0x27
ryought 0:cda6d9f5a43c 75 #define ADXL345_THRESH_FF_REG 0x28
ryought 0:cda6d9f5a43c 76 #define ADXL345_TIME_FF_REG 0x29
ryought 0:cda6d9f5a43c 77 #define ADXL345_TAP_AXES_REG 0x2A
ryought 0:cda6d9f5a43c 78 #define ADXL345_ACT_TAP_STATUS_REG 0x2B
ryought 0:cda6d9f5a43c 79 #define ADXL345_BW_RATE_REG 0x2C
ryought 0:cda6d9f5a43c 80 #define ADXL345_POWER_CTL_REG 0x2D
ryought 0:cda6d9f5a43c 81 #define ADXL345_INT_ENABLE_REG 0x2E
ryought 0:cda6d9f5a43c 82 #define ADXL345_INT_MAP_REG 0x2F
ryought 0:cda6d9f5a43c 83 #define ADXL345_INT_SOURCE_REG 0x30
ryought 0:cda6d9f5a43c 84 #define ADXL345_DATA_FORMAT_REG 0x31
ryought 0:cda6d9f5a43c 85 #define ADXL345_DATAX0_REG 0x32
ryought 0:cda6d9f5a43c 86 #define ADXL345_DATAX1_REG 0x33
ryought 0:cda6d9f5a43c 87 #define ADXL345_DATAY0_REG 0x34
ryought 0:cda6d9f5a43c 88 #define ADXL345_DATAY1_REG 0x35
ryought 0:cda6d9f5a43c 89 #define ADXL345_DATAZ0_REG 0x36
ryought 0:cda6d9f5a43c 90 #define ADXL345_DATAZ1_REG 0x37
ryought 0:cda6d9f5a43c 91 #define ADXL345_FIFO_CTL 0x38
ryought 0:cda6d9f5a43c 92 #define ADXL345_FIFO_STATUS 0x39
ryought 0:cda6d9f5a43c 93
ryought 0:cda6d9f5a43c 94 //Data rate codes.
ryought 0:cda6d9f5a43c 95 #define ADXL345_3200HZ 0x0F
ryought 0:cda6d9f5a43c 96 #define ADXL345_1600HZ 0x0E
ryought 0:cda6d9f5a43c 97 #define ADXL345_800HZ 0x0D
ryought 0:cda6d9f5a43c 98 #define ADXL345_400HZ 0x0C
ryought 0:cda6d9f5a43c 99 #define ADXL345_200HZ 0x0B
ryought 0:cda6d9f5a43c 100 #define ADXL345_100HZ 0x0A
ryought 0:cda6d9f5a43c 101 #define ADXL345_50HZ 0x09
ryought 0:cda6d9f5a43c 102 #define ADXL345_25HZ 0x08
ryought 0:cda6d9f5a43c 103 #define ADXL345_12HZ5 0x07
ryought 0:cda6d9f5a43c 104 #define ADXL345_6HZ25 0x06
ryought 0:cda6d9f5a43c 105
ryought 0:cda6d9f5a43c 106 // read or write bytes
Vigneshwar 3:04df9b19199b 107 #define ADXL345_I2C_READ 0xA7
Vigneshwar 3:04df9b19199b 108 #define ADXL345_I2C_WRITE 0xA6
ryought 0:cda6d9f5a43c 109 #define ADXL345_I2C_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
ryought 0:cda6d9f5a43c 110
ryought 0:cda6d9f5a43c 111 /////////////when ALT ADDRESS pin is high:
Vigneshwar 3:04df9b19199b 112 //#define ADXL345_I2C_READ 0x3B
ryought 0:cda6d9f5a43c 113 //#define ADXL345_I2C_WRITE 0x3A
Vigneshwar 3:04df9b19199b 114 //#define ADXL345_I2C_ADDRESS 0x1D
ryought 0:cda6d9f5a43c 115
ryought 0:cda6d9f5a43c 116 #define ADXL345_X 0x00
ryought 0:cda6d9f5a43c 117 #define ADXL345_Y 0x01
ryought 0:cda6d9f5a43c 118 #define ADXL345_Z 0x02
ryought 0:cda6d9f5a43c 119
ryought 0:cda6d9f5a43c 120
ryought 0:cda6d9f5a43c 121
ryought 0:cda6d9f5a43c 122 // modes
ryought 0:cda6d9f5a43c 123 #define MeasurementMode 0x08
ryought 0:cda6d9f5a43c 124
ryought 0:cda6d9f5a43c 125
ryought 0:cda6d9f5a43c 126
ryought 0:cda6d9f5a43c 127
ryought 0:cda6d9f5a43c 128
ryought 0:cda6d9f5a43c 129
ryought 0:cda6d9f5a43c 130
Vigneshwar 3:04df9b19199b 131 class ADXL345_I2C
Vigneshwar 3:04df9b19199b 132 {
ryought 0:cda6d9f5a43c 133
ryought 0:cda6d9f5a43c 134 public:
ryought 0:cda6d9f5a43c 135
ryought 0:cda6d9f5a43c 136 /**
ryought 0:cda6d9f5a43c 137 * Constructor.
ryought 0:cda6d9f5a43c 138 *
ryought 0:cda6d9f5a43c 139 * @param mosi mbed pin to use for SDA line of I2C interface.
ryought 0:cda6d9f5a43c 140 * @param sck mbed pin to use for SCL line of I2C interface.
ryought 0:cda6d9f5a43c 141 */
ryought 0:cda6d9f5a43c 142 ADXL345_I2C(PinName sda, PinName scl);
ryought 0:cda6d9f5a43c 143
ryought 0:cda6d9f5a43c 144 /**
ryought 0:cda6d9f5a43c 145 * Get the output of all three axes.
ryought 0:cda6d9f5a43c 146 *
ryought 0:cda6d9f5a43c 147 * @param Pointer to a buffer to hold the accelerometer value for the
ryought 0:cda6d9f5a43c 148 * x-axis, y-axis and z-axis [in that order].
ryought 0:cda6d9f5a43c 149 */
ryought 0:cda6d9f5a43c 150 void getOutput(int* readings);
ryought 0:cda6d9f5a43c 151
ryought 0:cda6d9f5a43c 152 /**
ryought 0:cda6d9f5a43c 153 * Read the device ID register on the device.
ryought 0:cda6d9f5a43c 154 *
ryought 0:cda6d9f5a43c 155 * @return The device ID code [0xE5]
ryought 0:cda6d9f5a43c 156 */
ryought 0:cda6d9f5a43c 157 char getDeviceID(void);
ryought 0:cda6d9f5a43c 158
ryought 0:cda6d9f5a43c 159
Vigneshwar 3:04df9b19199b 160
Vigneshwar 3:04df9b19199b 161 /**
Vigneshwar 3:04df9b19199b 162 * Set the power mode.
Vigneshwar 3:04df9b19199b 163 *
Vigneshwar 3:04df9b19199b 164 * @param mode 0 -> Normal operation.
Vigneshwar 3:04df9b19199b 165 * 1 -> Reduced power operation.
Vigneshwar 3:04df9b19199b 166 */
Vigneshwar 3:04df9b19199b 167 int setPowerMode(char mode);
Vigneshwar 3:04df9b19199b 168
Vigneshwar 3:04df9b19199b 169 /**
Vigneshwar 3:04df9b19199b 170 * Set the power control settings.
Vigneshwar 3:04df9b19199b 171 *
Vigneshwar 3:04df9b19199b 172 * See datasheet for details.
Vigneshwar 3:04df9b19199b 173 *
Vigneshwar 3:04df9b19199b 174 * @param The control byte to write to the POWER_CTL register.
Vigneshwar 3:04df9b19199b 175 */
Vigneshwar 3:04df9b19199b 176 int setPowerControl(char settings);
Vigneshwar 3:04df9b19199b 177 /**
Vigneshwar 3:04df9b19199b 178 * Get the power control settings.
Vigneshwar 3:04df9b19199b 179 *
Vigneshwar 3:04df9b19199b 180 * See datasheet for details.
Vigneshwar 3:04df9b19199b 181 *
Vigneshwar 3:04df9b19199b 182 * @return The contents of the POWER_CTL register.
Vigneshwar 3:04df9b19199b 183 */
ryought 0:cda6d9f5a43c 184 char getPowerControl(void);
ryought 0:cda6d9f5a43c 185
Vigneshwar 3:04df9b19199b 186
ryought 0:cda6d9f5a43c 187 /**
ryought 0:cda6d9f5a43c 188 * Get the data format settings.
ryought 0:cda6d9f5a43c 189 *
ryought 0:cda6d9f5a43c 190 * @return The contents of the DATA_FORMAT register.
ryought 0:cda6d9f5a43c 191 */
Vigneshwar 3:04df9b19199b 192
ryought 0:cda6d9f5a43c 193 char getDataFormatControl(void);
Vigneshwar 3:04df9b19199b 194
ryought 0:cda6d9f5a43c 195 /**
ryought 0:cda6d9f5a43c 196 * Set the data format settings.
ryought 0:cda6d9f5a43c 197 *
ryought 0:cda6d9f5a43c 198 * @param settings The control byte to write to the DATA_FORMAT register.
ryought 0:cda6d9f5a43c 199 */
ryought 0:cda6d9f5a43c 200 int setDataFormatControl(char settings);
Vigneshwar 3:04df9b19199b 201
Vigneshwar 3:04df9b19199b 202 /**
Vigneshwar 3:04df9b19199b 203 * Set the data rate.
Vigneshwar 3:04df9b19199b 204 *
Vigneshwar 3:04df9b19199b 205 * @param rate The rate code (see #defines or datasheet).
Vigneshwar 3:04df9b19199b 206 */
ryought 0:cda6d9f5a43c 207 int setDataRate(char rate);
Vigneshwar 3:04df9b19199b 208
ryought 0:cda6d9f5a43c 209
Vigneshwar 3:04df9b19199b 210 /**
Vigneshwar 3:04df9b19199b 211 * Get the current offset for a particular axis.
Vigneshwar 3:04df9b19199b 212 *
Vigneshwar 3:04df9b19199b 213 * @param axis 0x00 -> X-axis
Vigneshwar 3:04df9b19199b 214 * 0x01 -> Y-axis
Vigneshwar 3:04df9b19199b 215 * 0x02 -> Z-axis
Vigneshwar 3:04df9b19199b 216 * @return The current offset as an 8-bit 2's complement number with scale
Vigneshwar 3:04df9b19199b 217 * factor 15.6mg/LSB.
Vigneshwar 3:04df9b19199b 218 */
Vigneshwar 3:04df9b19199b 219
Vigneshwar 3:04df9b19199b 220 char getOffset(char axis);
ryought 0:cda6d9f5a43c 221
ryought 0:cda6d9f5a43c 222 /**
ryought 0:cda6d9f5a43c 223 * Set the offset for a particular axis.
ryought 0:cda6d9f5a43c 224 *
ryought 0:cda6d9f5a43c 225 * @param axis 0x00 -> X-axis
ryought 0:cda6d9f5a43c 226 * 0x01 -> Y-axis
ryought 0:cda6d9f5a43c 227 * 0x02 -> Z-axis
ryought 0:cda6d9f5a43c 228 * @param offset The offset as an 8-bit 2's complement number with scale
ryought 0:cda6d9f5a43c 229 * factor 15.6mg/LSB.
ryought 0:cda6d9f5a43c 230 */
ryought 0:cda6d9f5a43c 231 int setOffset(char axis, char offset);
ryought 0:cda6d9f5a43c 232
ryought 0:cda6d9f5a43c 233
Vigneshwar 3:04df9b19199b 234
ryought 0:cda6d9f5a43c 235 /**
ryought 0:cda6d9f5a43c 236 * Get the FIFO control settings.
ryought 0:cda6d9f5a43c 237 *
ryought 0:cda6d9f5a43c 238 * @return The contents of the FIFO_CTL register.
ryought 0:cda6d9f5a43c 239 */
ryought 0:cda6d9f5a43c 240 char getFifoControl(void);
Vigneshwar 3:04df9b19199b 241
ryought 0:cda6d9f5a43c 242 /**
ryought 0:cda6d9f5a43c 243 * Set the FIFO control settings.
ryought 0:cda6d9f5a43c 244 *
ryought 0:cda6d9f5a43c 245 * @param The control byte to write to the FIFO_CTL register.
ryought 0:cda6d9f5a43c 246 */
ryought 0:cda6d9f5a43c 247 int setFifoControl(char settings);
Vigneshwar 3:04df9b19199b 248
ryought 0:cda6d9f5a43c 249 /**
ryought 0:cda6d9f5a43c 250 * Get FIFO status.
ryought 0:cda6d9f5a43c 251 *
ryought 0:cda6d9f5a43c 252 * @return The contents of the FIFO_STATUS register.
ryought 0:cda6d9f5a43c 253 */
ryought 0:cda6d9f5a43c 254 char getFifoStatus(void);
Vigneshwar 3:04df9b19199b 255
ryought 0:cda6d9f5a43c 256 /**
ryought 0:cda6d9f5a43c 257 * Read the tap threshold on the device.
ryought 0:cda6d9f5a43c 258 *
ryought 0:cda6d9f5a43c 259 * @return The tap threshold as an 8-bit number with a scale factor of
ryought 0:cda6d9f5a43c 260 * 62.5mg/LSB.
ryought 0:cda6d9f5a43c 261 */
ryought 0:cda6d9f5a43c 262 char getTapThreshold(void);
ryought 0:cda6d9f5a43c 263
ryought 0:cda6d9f5a43c 264 /**
ryought 0:cda6d9f5a43c 265 * Set the tap threshold.
ryought 0:cda6d9f5a43c 266 *
ryought 0:cda6d9f5a43c 267 * @param The tap threshold as an 8-bit number with a scale factor of
ryought 0:cda6d9f5a43c 268 * 62.5mg/LSB.
ryought 0:cda6d9f5a43c 269 */
ryought 0:cda6d9f5a43c 270 int setTapThreshold(char threshold);
ryought 0:cda6d9f5a43c 271
ryought 0:cda6d9f5a43c 272 /**
ryought 0:cda6d9f5a43c 273 * Get the tap duration required to trigger an event.
ryought 0:cda6d9f5a43c 274 *
ryought 0:cda6d9f5a43c 275 * @return The max time that an event must be above the tap threshold to
ryought 0:cda6d9f5a43c 276 * qualify as a tap event, in microseconds.
ryought 0:cda6d9f5a43c 277 */
ryought 0:cda6d9f5a43c 278 float getTapDuration(void);
ryought 0:cda6d9f5a43c 279
ryought 0:cda6d9f5a43c 280 /**
ryought 0:cda6d9f5a43c 281 * Set the tap duration required to trigger an event.
ryought 0:cda6d9f5a43c 282 *
ryought 0:cda6d9f5a43c 283 * @param duration_us The max time that an event must be above the tap
ryought 0:cda6d9f5a43c 284 * threshold to qualify as a tap event, in microseconds.
ryought 0:cda6d9f5a43c 285 * Time will be normalized by the scale factor which is
ryought 0:cda6d9f5a43c 286 * 625us/LSB. A value of 0 disables the single/double
ryought 0:cda6d9f5a43c 287 * tap functions.
ryought 0:cda6d9f5a43c 288 */
ryought 0:cda6d9f5a43c 289 int setTapDuration(short int duration_us);
ryought 0:cda6d9f5a43c 290
ryought 0:cda6d9f5a43c 291 /**
ryought 0:cda6d9f5a43c 292 * Get the tap latency between the detection of a tap and the time window.
ryought 0:cda6d9f5a43c 293 *
ryought 0:cda6d9f5a43c 294 * @return The wait time from the detection of a tap event to the start of
ryought 0:cda6d9f5a43c 295 * the time window during which a possible second tap event can be
ryought 0:cda6d9f5a43c 296 * detected in milliseconds.
ryought 0:cda6d9f5a43c 297 */
ryought 0:cda6d9f5a43c 298 float getTapLatency(void);
ryought 0:cda6d9f5a43c 299
ryought 0:cda6d9f5a43c 300 /**
ryought 0:cda6d9f5a43c 301 * Set the tap latency between the detection of a tap and the time window.
ryought 0:cda6d9f5a43c 302 *
ryought 0:cda6d9f5a43c 303 * @param latency_ms The wait time from the detection of a tap event to the
ryought 0:cda6d9f5a43c 304 * start of the time window during which a possible
ryought 0:cda6d9f5a43c 305 * second tap event can be detected in milliseconds.
ryought 0:cda6d9f5a43c 306 * A value of 0 disables the double tap function.
ryought 0:cda6d9f5a43c 307 */
ryought 0:cda6d9f5a43c 308 int setTapLatency(short int latency_ms);
ryought 0:cda6d9f5a43c 309
ryought 0:cda6d9f5a43c 310 /**
ryought 0:cda6d9f5a43c 311 * Get the time of window between tap latency and a double tap.
ryought 0:cda6d9f5a43c 312 *
ryought 0:cda6d9f5a43c 313 * @return The amount of time after the expiration of the latency time
ryought 0:cda6d9f5a43c 314 * during which a second valid tap can begin, in milliseconds.
ryought 0:cda6d9f5a43c 315 */
ryought 0:cda6d9f5a43c 316 float getWindowTime(void);
ryought 0:cda6d9f5a43c 317
ryought 0:cda6d9f5a43c 318 /**
ryought 0:cda6d9f5a43c 319 * Set the time of the window between tap latency and a double tap.
ryought 0:cda6d9f5a43c 320 *
ryought 0:cda6d9f5a43c 321 * @param window_ms The amount of time after the expiration of the latency
ryought 0:cda6d9f5a43c 322 * time during which a second valid tap can begin,
ryought 0:cda6d9f5a43c 323 * in milliseconds.
ryought 0:cda6d9f5a43c 324 */
ryought 0:cda6d9f5a43c 325 int setWindowTime(short int window_ms);
ryought 0:cda6d9f5a43c 326
ryought 0:cda6d9f5a43c 327 /**
ryought 0:cda6d9f5a43c 328 * Get the threshold value for detecting activity.
ryought 0:cda6d9f5a43c 329 *
ryought 0:cda6d9f5a43c 330 * @return The threshold value for detecting activity as an 8-bit number.
ryought 0:cda6d9f5a43c 331 * Scale factor is 62.5mg/LSB.
ryought 0:cda6d9f5a43c 332 */
Vigneshwar 3:04df9b19199b 333 char getActivityThreshold(void);
ryought 0:cda6d9f5a43c 334
ryought 0:cda6d9f5a43c 335 /**
ryought 0:cda6d9f5a43c 336 * Set the threshold value for detecting activity.
ryought 0:cda6d9f5a43c 337 *
ryought 0:cda6d9f5a43c 338 * @param threshold The threshold value for detecting activity as an 8-bit
ryought 0:cda6d9f5a43c 339 * number. Scale factor is 62.5mg/LSB. A value of 0 may
ryought 0:cda6d9f5a43c 340 * result in undesirable behavior if the activity
ryought 0:cda6d9f5a43c 341 * interrupt is enabled.
ryought 0:cda6d9f5a43c 342 */
ryought 0:cda6d9f5a43c 343 int setActivityThreshold(char threshold);
ryought 0:cda6d9f5a43c 344
ryought 0:cda6d9f5a43c 345 /**
ryought 0:cda6d9f5a43c 346 * Get the threshold value for detecting inactivity.
ryought 0:cda6d9f5a43c 347 *
ryought 0:cda6d9f5a43c 348 * @return The threshold value for detecting inactivity as an 8-bit number.
ryought 0:cda6d9f5a43c 349 * Scale factor is 62.5mg/LSB.
ryought 0:cda6d9f5a43c 350 */
Vigneshwar 3:04df9b19199b 351 char getInactivityThreshold(void);
ryought 0:cda6d9f5a43c 352
ryought 0:cda6d9f5a43c 353 /**
ryought 0:cda6d9f5a43c 354 * Set the threshold value for detecting inactivity.
ryought 0:cda6d9f5a43c 355 *
ryought 0:cda6d9f5a43c 356 * @param threshold The threshold value for detecting inactivity as an
ryought 0:cda6d9f5a43c 357 * 8-bit number. Scale factor is 62.5mg/LSB.
ryought 0:cda6d9f5a43c 358 */
ryought 0:cda6d9f5a43c 359 int setInactivityThreshold(char threshold);
ryought 0:cda6d9f5a43c 360
ryought 0:cda6d9f5a43c 361 /**
ryought 0:cda6d9f5a43c 362 * Get the time required for inactivity to be declared.
ryought 0:cda6d9f5a43c 363 *
ryought 0:cda6d9f5a43c 364 * @return The amount of time that acceleration must be less than the
ryought 0:cda6d9f5a43c 365 * inactivity threshold for inactivity to be declared, in
ryought 0:cda6d9f5a43c 366 * seconds.
ryought 0:cda6d9f5a43c 367 */
Vigneshwar 3:04df9b19199b 368 char getTimeInactivity(void);
Vigneshwar 3:04df9b19199b 369
ryought 0:cda6d9f5a43c 370 /**
ryought 0:cda6d9f5a43c 371 * Set the time required for inactivity to be declared.
ryought 0:cda6d9f5a43c 372 *
ryought 0:cda6d9f5a43c 373 * @param inactivity The amount of time that acceleration must be less than
ryought 0:cda6d9f5a43c 374 * the inactivity threshold for inactivity to be
ryought 0:cda6d9f5a43c 375 * declared, in seconds. A value of 0 results in an
ryought 0:cda6d9f5a43c 376 * interrupt when the output data is less than the
ryought 0:cda6d9f5a43c 377 * threshold inactivity.
ryought 0:cda6d9f5a43c 378 */
ryought 0:cda6d9f5a43c 379 int setTimeInactivity(char timeInactivity);
Vigneshwar 3:04df9b19199b 380
ryought 0:cda6d9f5a43c 381 /**
ryought 0:cda6d9f5a43c 382 * Get the activity/inactivity control settings.
ryought 0:cda6d9f5a43c 383 *
ryought 0:cda6d9f5a43c 384 * D7 D6 D5 D4
ryought 0:cda6d9f5a43c 385 * +-----------+--------------+--------------+--------------+
ryought 0:cda6d9f5a43c 386 * | ACT ac/dc | ACT_X enable | ACT_Y enable | ACT_Z enable |
ryought 0:cda6d9f5a43c 387 * +-----------+--------------+--------------+--------------+
ryought 0:cda6d9f5a43c 388 *
ryought 0:cda6d9f5a43c 389 * D3 D2 D1 D0
ryought 0:cda6d9f5a43c 390 * +-------------+----------------+----------------+----------------+
ryought 0:cda6d9f5a43c 391 * | INACT ac/dc | INACT_X enable | INACT_Y enable | INACT_Z enable |
ryought 0:cda6d9f5a43c 392 * +-------------+----------------+----------------+----------------+
ryought 0:cda6d9f5a43c 393 *
ryought 0:cda6d9f5a43c 394 * See datasheet for details.
ryought 0:cda6d9f5a43c 395 *
ryought 0:cda6d9f5a43c 396 * @return The contents of the ACT_INACT_CTL register.
ryought 0:cda6d9f5a43c 397 */
Vigneshwar 3:04df9b19199b 398 char getActivityInactivityControl(void);
Vigneshwar 3:04df9b19199b 399
ryought 0:cda6d9f5a43c 400 /**
ryought 0:cda6d9f5a43c 401 * Set the activity/inactivity control settings.
ryought 0:cda6d9f5a43c 402 *
ryought 0:cda6d9f5a43c 403 * D7 D6 D5 D4
ryought 0:cda6d9f5a43c 404 * +-----------+--------------+--------------+--------------+
ryought 0:cda6d9f5a43c 405 * | ACT ac/dc | ACT_X enable | ACT_Y enable | ACT_Z enable |
ryought 0:cda6d9f5a43c 406 * +-----------+--------------+--------------+--------------+
ryought 0:cda6d9f5a43c 407 *
ryought 0:cda6d9f5a43c 408 * D3 D2 D1 D0
ryought 0:cda6d9f5a43c 409 * +-------------+----------------+----------------+----------------+
ryought 0:cda6d9f5a43c 410 * | INACT ac/dc | INACT_X enable | INACT_Y enable | INACT_Z enable |
ryought 0:cda6d9f5a43c 411 * +-------------+----------------+----------------+----------------+
ryought 0:cda6d9f5a43c 412 *
ryought 0:cda6d9f5a43c 413 * See datasheet for details.
ryought 0:cda6d9f5a43c 414 *
ryought 0:cda6d9f5a43c 415 * @param settings The control byte to write to the ACT_INACT_CTL register.
ryought 0:cda6d9f5a43c 416 */
ryought 0:cda6d9f5a43c 417 int setActivityInactivityControl(char settings);
Vigneshwar 3:04df9b19199b 418
ryought 0:cda6d9f5a43c 419 /**
ryought 0:cda6d9f5a43c 420 * Get the threshold for free fall detection.
ryought 0:cda6d9f5a43c 421 *
ryought 0:cda6d9f5a43c 422 * @return The threshold value for free-fall detection, as an 8-bit number,
ryought 0:cda6d9f5a43c 423 * with scale factor 62.5mg/LSB.
ryought 0:cda6d9f5a43c 424 */
Vigneshwar 3:04df9b19199b 425 char getFreefallThreshold(void);
Vigneshwar 3:04df9b19199b 426
ryought 0:cda6d9f5a43c 427 /**
ryought 0:cda6d9f5a43c 428 * Set the threshold for free fall detection.
ryought 0:cda6d9f5a43c 429 *
ryought 0:cda6d9f5a43c 430 * @return The threshold value for free-fall detection, as an 8-bit number,
Vigneshwar 3:04df9b19199b 431 * with scale factor 62.5mg/LSB. A value of 0 may result in
ryought 0:cda6d9f5a43c 432 * undesirable behavior if the free-fall interrupt is enabled.
ryought 0:cda6d9f5a43c 433 * Values between 300 mg and 600 mg (0x05 to 0x09) are recommended.
ryought 0:cda6d9f5a43c 434 */
ryought 0:cda6d9f5a43c 435 int setFreefallThreshold(char threshold);
Vigneshwar 3:04df9b19199b 436
ryought 0:cda6d9f5a43c 437 /**
ryought 0:cda6d9f5a43c 438 * Get the time required to generate a free fall interrupt.
ryought 0:cda6d9f5a43c 439 *
ryought 0:cda6d9f5a43c 440 * @return The minimum time that the value of all axes must be less than
ryought 0:cda6d9f5a43c 441 * the freefall threshold to generate a free-fall interrupt, in
ryought 0:cda6d9f5a43c 442 * milliseconds.
ryought 0:cda6d9f5a43c 443 */
Vigneshwar 3:04df9b19199b 444 char getFreefallTime(void);
Vigneshwar 3:04df9b19199b 445
ryought 0:cda6d9f5a43c 446 /**
ryought 0:cda6d9f5a43c 447 * Set the time required to generate a free fall interrupt.
ryought 0:cda6d9f5a43c 448 *
ryought 0:cda6d9f5a43c 449 * @return The minimum time that the value of all axes must be less than
ryought 0:cda6d9f5a43c 450 * the freefall threshold to generate a free-fall interrupt, in
ryought 0:cda6d9f5a43c 451 * milliseconds. A value of 0 may result in undesirable behavior
Vigneshwar 3:04df9b19199b 452 * if the free-fall interrupt is enabled. Values between 100 ms
ryought 0:cda6d9f5a43c 453 * and 350 ms (0x14 to 0x46) are recommended.
ryought 0:cda6d9f5a43c 454 */
ryought 0:cda6d9f5a43c 455 int setFreefallTime(short int freefallTime_ms);
Vigneshwar 3:04df9b19199b 456
ryought 0:cda6d9f5a43c 457 /**
ryought 0:cda6d9f5a43c 458 * Get the axis tap settings.
ryought 0:cda6d9f5a43c 459 *
ryought 0:cda6d9f5a43c 460 * D3 D2 D1 D0
ryought 0:cda6d9f5a43c 461 * +----------+--------------+--------------+--------------+
ryought 0:cda6d9f5a43c 462 * | Suppress | TAP_X enable | TAP_Y enable | TAP_Z enable |
ryought 0:cda6d9f5a43c 463 * +----------+--------------+--------------+--------------+
ryought 0:cda6d9f5a43c 464 *
ryought 0:cda6d9f5a43c 465 * (D7-D4 are 0s).
ryought 0:cda6d9f5a43c 466 *
ryought 0:cda6d9f5a43c 467 * See datasheet for more details.
ryought 0:cda6d9f5a43c 468 *
ryought 0:cda6d9f5a43c 469 * @return The contents of the TAP_AXES register.
Vigneshwar 3:04df9b19199b 470 */
Vigneshwar 3:04df9b19199b 471 char getTapAxisControl(void);
Vigneshwar 3:04df9b19199b 472
ryought 0:cda6d9f5a43c 473 /**
ryought 0:cda6d9f5a43c 474 * Set the axis tap settings.
ryought 0:cda6d9f5a43c 475 *
ryought 0:cda6d9f5a43c 476 * D3 D2 D1 D0
ryought 0:cda6d9f5a43c 477 * +----------+--------------+--------------+--------------+
ryought 0:cda6d9f5a43c 478 * | Suppress | TAP_X enable | TAP_Y enable | TAP_Z enable |
ryought 0:cda6d9f5a43c 479 * +----------+--------------+--------------+--------------+
ryought 0:cda6d9f5a43c 480 *
ryought 0:cda6d9f5a43c 481 * (D7-D4 are 0s).
ryought 0:cda6d9f5a43c 482 *
ryought 0:cda6d9f5a43c 483 * See datasheet for more details.
ryought 0:cda6d9f5a43c 484 *
ryought 0:cda6d9f5a43c 485 * @param The control byte to write to the TAP_AXES register.
ryought 0:cda6d9f5a43c 486 */
ryought 0:cda6d9f5a43c 487 int setTapAxisControl(char settings);
Vigneshwar 3:04df9b19199b 488
ryought 0:cda6d9f5a43c 489 /**
ryought 0:cda6d9f5a43c 490 * Get the source of a tap.
ryought 0:cda6d9f5a43c 491 *
ryought 0:cda6d9f5a43c 492 * @return The contents of the ACT_TAP_STATUS register.
ryought 0:cda6d9f5a43c 493 */
Vigneshwar 3:04df9b19199b 494 char getTapSource(void);
ryought 0:cda6d9f5a43c 495
Vigneshwar 3:04df9b19199b 496 /**
Vigneshwar 3:04df9b19199b 497 * Get the interrupt enable settings.
Vigneshwar 3:04df9b19199b 498 *
Vigneshwar 3:04df9b19199b 499 * @return The contents of the INT_ENABLE register.
Vigneshwar 3:04df9b19199b 500 */
Vigneshwar 3:04df9b19199b 501
Vigneshwar 3:04df9b19199b 502 char getInterruptEnableControl(void);
Vigneshwar 3:04df9b19199b 503
ryought 0:cda6d9f5a43c 504 /**
ryought 0:cda6d9f5a43c 505 * Set the interrupt enable settings.
ryought 0:cda6d9f5a43c 506 *
ryought 0:cda6d9f5a43c 507 * @param settings The control byte to write to the INT_ENABLE register.
ryought 0:cda6d9f5a43c 508 */
ryought 0:cda6d9f5a43c 509 int setInterruptEnableControl(char settings);
Vigneshwar 3:04df9b19199b 510
ryought 0:cda6d9f5a43c 511 /**
ryought 0:cda6d9f5a43c 512 * Get the interrupt mapping settings.
ryought 0:cda6d9f5a43c 513 *
ryought 0:cda6d9f5a43c 514 * @return The contents of the INT_MAP register.
ryought 0:cda6d9f5a43c 515 */
Vigneshwar 3:04df9b19199b 516 char getInterruptMappingControl(void);
Vigneshwar 3:04df9b19199b 517
ryought 0:cda6d9f5a43c 518 /**
ryought 0:cda6d9f5a43c 519 * Set the interrupt mapping settings.
ryought 0:cda6d9f5a43c 520 *
ryought 0:cda6d9f5a43c 521 * @param settings The control byte to write to the INT_MAP register.
ryought 0:cda6d9f5a43c 522 */
ryought 0:cda6d9f5a43c 523 int setInterruptMappingControl(char settings);
Vigneshwar 3:04df9b19199b 524
ryought 0:cda6d9f5a43c 525 /**
ryought 0:cda6d9f5a43c 526 * Get the interrupt source.
ryought 0:cda6d9f5a43c 527 *
ryought 0:cda6d9f5a43c 528 * @return The contents of the INT_SOURCE register.
ryought 0:cda6d9f5a43c 529 */
Vigneshwar 3:04df9b19199b 530 char getInterruptSource(void);
Vigneshwar 3:04df9b19199b 531
Vigneshwar 3:04df9b19199b 532
ryought 0:cda6d9f5a43c 533 private:
ryought 0:cda6d9f5a43c 534
ryought 0:cda6d9f5a43c 535 I2C i2c_;
Vigneshwar 3:04df9b19199b 536
ryought 0:cda6d9f5a43c 537
ryought 0:cda6d9f5a43c 538 /**
ryought 0:cda6d9f5a43c 539 * Read one byte from a register on the device.
ryought 0:cda6d9f5a43c 540 *
ryought 0:cda6d9f5a43c 541 * @param: - the address to be read from
ryought 0:cda6d9f5a43c 542 *
ryought 0:cda6d9f5a43c 543 * @return: the value of the data read
ryought 0:cda6d9f5a43c 544 */
ryought 0:cda6d9f5a43c 545 char SingleByteRead(char address);
ryought 0:cda6d9f5a43c 546
ryought 0:cda6d9f5a43c 547 /**
ryought 0:cda6d9f5a43c 548 * Write one byte to a register on the device.
ryought 0:cda6d9f5a43c 549 *
ryought 0:cda6d9f5a43c 550 * @param:
ryought 0:cda6d9f5a43c 551 - address of the register to write to.
ryought 0:cda6d9f5a43c 552 - the value of the data to store
ryought 0:cda6d9f5a43c 553 */
Vigneshwar 3:04df9b19199b 554
Vigneshwar 3:04df9b19199b 555
Vigneshwar 3:04df9b19199b 556 int SingleByteWrite(char address, char data);
ryought 0:cda6d9f5a43c 557
ryought 0:cda6d9f5a43c 558 /**
ryought 0:cda6d9f5a43c 559 * Read several consecutive bytes on the device and store them in a given location.
ryought 0:cda6d9f5a43c 560 *
ryought 0:cda6d9f5a43c 561 * @param startAddress: The address of the first register to read from.
ryought 0:cda6d9f5a43c 562 * @param ptr_output: a pointer to the location to store the data being read
ryought 0:cda6d9f5a43c 563 * @param size: The number of bytes to read.
ryought 0:cda6d9f5a43c 564 */
ryought 0:cda6d9f5a43c 565 void multiByteRead(char startAddress, char* ptr_output, int size);
ryought 0:cda6d9f5a43c 566
ryought 0:cda6d9f5a43c 567 /**
ryought 0:cda6d9f5a43c 568 * Write several consecutive bytes on the device.
ryought 0:cda6d9f5a43c 569 *
ryought 0:cda6d9f5a43c 570 * @param startAddress: The address of the first register to write to.
ryought 0:cda6d9f5a43c 571 * @param ptr_data: Pointer to a location which contains the data to write.
ryought 0:cda6d9f5a43c 572 * @param size: The number of bytes to write.
ryought 0:cda6d9f5a43c 573 */
ryought 0:cda6d9f5a43c 574 int multiByteWrite(char startAddress, char* ptr_data, int size);
ryought 0:cda6d9f5a43c 575
ryought 0:cda6d9f5a43c 576 };
ryought 0:cda6d9f5a43c 577
ryought 0:cda6d9f5a43c 578 #endif /* ADXL345_I2C_H */