ADXL345 Evaluation

Dependencies:   mbed

Committer:
Frederick_H
Date:
Fri Sep 01 10:53:50 2017 +0000
Revision:
6:592373200317
Parent:
3:e4783c57bcc0
Add zoom and shift function on Mapper

Who changed what in which revision?

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