Slingshot Controller

Dependencies:   ADXL345 DebounceIn USBDevice mbed

Committer:
Brandon
Date:
Sun Oct 14 18:58:38 2012 +0000
Revision:
0:cf17ea89fd09
lab3

Who changed what in which revision?

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