ADXL345 triple axis, digital accelerometer library.

Dependents:   AntiTheftGPS

Committer:
Owen
Date:
Thu Jan 20 20:11:51 2011 +0000
Revision:
0:745335502422
Based on ADXL345 from Jose R Padron (which is modified from Aaron Berk\s original). Fixes a bug in setFifoControl.

Who changed what in which revision?

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