SparkFun_9DOF_SensorStick

Dependencies:   FatFileSystem mbed

Fork of 9DOF_SensorStick by hige dura

Committer:
higedura
Date:
Mon Sep 03 03:44:13 2012 +0000
Revision:
5:12e37af16f2e
Parent:
0:80d32420bc63
update

Who changed what in which revision?

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