Ver1.01

Dependencies:   BMP085 SDFileSystem mbed

Committer:
emanon
Date:
Mon Jul 14 09:20:00 2014 +0000
Revision:
1:31e810237ac1
Parent:
0:e4ca6571a751
1st test

Who changed what in which revision?

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