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