Driver for ADXL345

Dependents:   m3Dpi

Fork of ADXL345_I2C by Ian Molesworth

Committer:
sillevl
Date:
Sat Dec 19 10:40:48 2015 +0000
Revision:
3:a453a5e561c2
Parent:
2:f2d04afa9603
add constructor that accepts I2C object

Who changed what in which revision?

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