Test Slingshot

Dependencies:   mbed

Committer:
samux
Date:
Wed Jan 18 14:37:06 2012 +0000
Revision:
0:9cfbae3af1ea

        

Who changed what in which revision?

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