Dependencies:   FatFileSystem mbed

Committer:
higedura
Date:
Sat Apr 21 14:07:27 2012 +0000
Revision:
2:307500c991dd
Parent:
0:813b917360ac

        

Who changed what in which revision?

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