ok

Committer:
stepJun
Date:
Thu Jun 05 12:03:11 2014 +0000
Revision:
0:cd9ad4e6166d
ok

Who changed what in which revision?

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