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