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