teste

Committer:
goncaloc
Date:
Sun Oct 31 10:59:35 2010 +0000
Revision:
0:a5a2383a6e2f
0v0

Who changed what in which revision?

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