Dependencies:   TextLCD mbed

Committer:
higedura
Date:
Mon Apr 23 14:59:48 2012 +0000
Revision:
0:f5a5a0e5fefb

        

Who changed what in which revision?

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