mbed-os

Fork of mbed-os by erkin yucel

Committer:
xuaner
Date:
Thu Jul 20 14:26:57 2017 +0000
Revision:
1:3deb71413561
Parent:
0:f269e3021894
mbed_os

Who changed what in which revision?

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