ADXL345_I2C

Dependents:   jetfish robotic_fish_ver_4_9_pixy

Committer:
Reiko
Date:
Mon Jul 29 20:37:49 2013 +0000
Revision:
0:753991a08b2a
Added ADXL345_I2C code

Who changed what in which revision?

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