this is just implement uart using nrf51 with adxl345 spi

Dependents:   nRF51_ADXL345_UART_SPI

Committer:
asyrofi
Date:
Thu Dec 07 06:30:16 2017 +0000
Revision:
0:cd40b5e776b0
siplah;

Who changed what in which revision?

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