Add functions to read Ax, Ay and Az individually

Committer:
elrafapadron
Date:
Mon Oct 25 03:08:47 2010 +0000
Revision:
0:baba3e2f977d

        

Who changed what in which revision?

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