Dependencies:   mbed FatFileSystem

Committer:
higedura
Date:
Sun Jun 10 08:44:32 2012 +0000
Revision:
0:75227c386257

        

Who changed what in which revision?

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