mbed implementation of the FreeIMU IMU for HobbyKing's 10DOF board

Dependents:   testHK10DOF

Committer:
pommzorz
Date:
Wed Jul 17 18:53:37 2013 +0000
Revision:
1:85fcfcb7b137
Parent:
0:9a1682a09c50
oops forgot one file...

Who changed what in which revision?

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