Export for Dan

Dependencies:   mbed MODSERIAL1

Committer:
atravieso
Date:
Fri Oct 30 18:51:47 2015 +0000
Revision:
6:aa3219001d18
Serial comms work via J3 via an RS232 level shifter.  Humidity and accelerations print to the terminal.

Who changed what in which revision?

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