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