Dependents:   ADXL345 TCPspittertobi ADXL345 RS485R_2 ... more

Committer:
nimbusgb
Date:
Wed Feb 02 06:38:11 2011 +0000
Revision:
0:3957077e9775
Child:
1:92fa975dab32
CS removed since to be in I2C mode the chip should hav its CS tied to Vcc anyway

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