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