Republished Library, to be refined for use with the SparkFun 9DOF in HARP project.
Fork of ADXL345 by
ADXL345.h@6:5fb29534a6cf, 2012-11-01 (annotated)
- Committer:
- tylerjw
- Date:
- Thu Nov 01 15:54:31 2012 +0000
- Revision:
- 6:5fb29534a6cf
- Parent:
- 5:122a504fcfa3
- Child:
- 7:839128c6e20a
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Digixx | 0:1e4aa22fc1a1 | 1 | /** |
gltest26 | 3:7b83694c7292 | 2 | * @file ADXL345.h |
Digixx | 1:45faba962a46 | 3 | * @author Uwe Gartmann |
Digixx | 1:45faba962a46 | 4 | * @author Used ITG3200 library developed Peter Swanson as template |
Digixx | 1:45faba962a46 | 5 | * A special thanks to Ewout van Bekkum for all his patient help in developing this library! |
Digixx | 0:1e4aa22fc1a1 | 6 | * |
Digixx | 0:1e4aa22fc1a1 | 7 | * @section LICENSE |
Digixx | 0:1e4aa22fc1a1 | 8 | * |
Digixx | 0:1e4aa22fc1a1 | 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
Digixx | 0:1e4aa22fc1a1 | 10 | * of this software and associated documentation files (the "Software"), to deal |
Digixx | 0:1e4aa22fc1a1 | 11 | * in the Software without restriction, including without limitation the rights |
Digixx | 0:1e4aa22fc1a1 | 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
Digixx | 0:1e4aa22fc1a1 | 13 | * copies of the Software, and to permit persons to whom the Software is |
Digixx | 0:1e4aa22fc1a1 | 14 | * furnished to do so, subject to the following conditions: |
Digixx | 0:1e4aa22fc1a1 | 15 | * |
Digixx | 0:1e4aa22fc1a1 | 16 | * The above copyright notice and this permission notice shall be included in |
Digixx | 0:1e4aa22fc1a1 | 17 | * all copies or substantial portions of the Software. |
Digixx | 0:1e4aa22fc1a1 | 18 | * |
Digixx | 0:1e4aa22fc1a1 | 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Digixx | 0:1e4aa22fc1a1 | 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Digixx | 0:1e4aa22fc1a1 | 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
Digixx | 0:1e4aa22fc1a1 | 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Digixx | 0:1e4aa22fc1a1 | 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Digixx | 0:1e4aa22fc1a1 | 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
Digixx | 0:1e4aa22fc1a1 | 25 | * THE SOFTWARE. |
Digixx | 0:1e4aa22fc1a1 | 26 | * |
Digixx | 0:1e4aa22fc1a1 | 27 | * @section DESCRIPTION |
Digixx | 0:1e4aa22fc1a1 | 28 | * |
Digixx | 0:1e4aa22fc1a1 | 29 | * ADXL345, triple axis, I2C interface, accelerometer. |
Digixx | 0:1e4aa22fc1a1 | 30 | * |
Digixx | 0:1e4aa22fc1a1 | 31 | * Datasheet: |
Digixx | 0:1e4aa22fc1a1 | 32 | * |
Digixx | 0:1e4aa22fc1a1 | 33 | * http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf |
Digixx | 0:1e4aa22fc1a1 | 34 | */ |
Digixx | 0:1e4aa22fc1a1 | 35 | |
Digixx | 0:1e4aa22fc1a1 | 36 | |
Digixx | 0:1e4aa22fc1a1 | 37 | |
Digixx | 0:1e4aa22fc1a1 | 38 | #ifndef ADXL345_H |
Digixx | 0:1e4aa22fc1a1 | 39 | #define ADXL345_H |
Digixx | 0:1e4aa22fc1a1 | 40 | |
gltest26 | 3:7b83694c7292 | 41 | /* |
Digixx | 0:1e4aa22fc1a1 | 42 | * Includes |
Digixx | 0:1e4aa22fc1a1 | 43 | */ |
Digixx | 0:1e4aa22fc1a1 | 44 | #include "mbed.h" |
Digixx | 0:1e4aa22fc1a1 | 45 | |
gltest26 | 3:7b83694c7292 | 46 | /* |
Digixx | 0:1e4aa22fc1a1 | 47 | * Defines |
Digixx | 0:1e4aa22fc1a1 | 48 | */ |
Digixx | 0:1e4aa22fc1a1 | 49 | //Registers. |
Digixx | 0:1e4aa22fc1a1 | 50 | #define ADXL345_DEVID_REG 0x00 |
Digixx | 0:1e4aa22fc1a1 | 51 | #define ADXL345_THRESH_TAP_REG 0x1D |
Digixx | 0:1e4aa22fc1a1 | 52 | #define ADXL345_OFSX_REG 0x1E |
Digixx | 0:1e4aa22fc1a1 | 53 | #define ADXL345_OFSY_REG 0x1F |
Digixx | 0:1e4aa22fc1a1 | 54 | #define ADXL345_OFSZ_REG 0x20 |
Digixx | 0:1e4aa22fc1a1 | 55 | #define ADXL345_DUR_REG 0x21 |
Digixx | 0:1e4aa22fc1a1 | 56 | #define ADXL345_LATENT_REG 0x22 |
Digixx | 0:1e4aa22fc1a1 | 57 | #define ADXL345_WINDOW_REG 0x23 |
Digixx | 0:1e4aa22fc1a1 | 58 | #define ADXL345_THRESH_ACT_REG 0x24 |
Digixx | 0:1e4aa22fc1a1 | 59 | #define ADXL345_THRESH_INACT_REG 0x25 |
Digixx | 0:1e4aa22fc1a1 | 60 | #define ADXL345_TIME_INACT_REG 0x26 |
Digixx | 0:1e4aa22fc1a1 | 61 | #define ADXL345_ACT_INACT_CTL_REG 0x27 |
Digixx | 0:1e4aa22fc1a1 | 62 | #define ADXL345_THRESH_FF_REG 0x28 |
Digixx | 0:1e4aa22fc1a1 | 63 | #define ADXL345_TIME_FF_REG 0x29 |
Digixx | 0:1e4aa22fc1a1 | 64 | #define ADXL345_TAP_AXES_REG 0x2A |
Digixx | 0:1e4aa22fc1a1 | 65 | #define ADXL345_ACT_TAP_STATUS_REG 0x2B |
Digixx | 0:1e4aa22fc1a1 | 66 | #define ADXL345_BW_RATE_REG 0x2C |
Digixx | 0:1e4aa22fc1a1 | 67 | #define ADXL345_POWER_CTL_REG 0x2D |
Digixx | 0:1e4aa22fc1a1 | 68 | #define ADXL345_INT_ENABLE_REG 0x2E |
Digixx | 0:1e4aa22fc1a1 | 69 | #define ADXL345_INT_MAP_REG 0x2F |
Digixx | 0:1e4aa22fc1a1 | 70 | #define ADXL345_INT_SOURCE_REG 0x30 |
Digixx | 0:1e4aa22fc1a1 | 71 | #define ADXL345_DATA_FORMAT_REG 0x31 |
Digixx | 0:1e4aa22fc1a1 | 72 | #define ADXL345_DATAX0_REG 0x32 |
Digixx | 0:1e4aa22fc1a1 | 73 | #define ADXL345_DATAX1_REG 0x33 |
Digixx | 0:1e4aa22fc1a1 | 74 | #define ADXL345_DATAY0_REG 0x34 |
Digixx | 0:1e4aa22fc1a1 | 75 | #define ADXL345_DATAY1_REG 0x35 |
Digixx | 0:1e4aa22fc1a1 | 76 | #define ADXL345_DATAZ0_REG 0x36 |
Digixx | 0:1e4aa22fc1a1 | 77 | #define ADXL345_DATAZ1_REG 0x37 |
Digixx | 0:1e4aa22fc1a1 | 78 | #define ADXL345_FIFO_CTL 0x38 |
Digixx | 0:1e4aa22fc1a1 | 79 | #define ADXL345_FIFO_STATUS 0x39 |
Digixx | 0:1e4aa22fc1a1 | 80 | |
Digixx | 0:1e4aa22fc1a1 | 81 | //Data rate codes. |
Digixx | 0:1e4aa22fc1a1 | 82 | #define ADXL345_3200HZ 0x0F |
Digixx | 0:1e4aa22fc1a1 | 83 | #define ADXL345_1600HZ 0x0E |
Digixx | 0:1e4aa22fc1a1 | 84 | #define ADXL345_800HZ 0x0D |
Digixx | 0:1e4aa22fc1a1 | 85 | #define ADXL345_400HZ 0x0C |
Digixx | 0:1e4aa22fc1a1 | 86 | #define ADXL345_200HZ 0x0B |
Digixx | 0:1e4aa22fc1a1 | 87 | #define ADXL345_100HZ 0x0A |
Digixx | 0:1e4aa22fc1a1 | 88 | #define ADXL345_50HZ 0x09 |
Digixx | 0:1e4aa22fc1a1 | 89 | #define ADXL345_25HZ 0x08 |
Digixx | 0:1e4aa22fc1a1 | 90 | #define ADXL345_12HZ5 0x07 |
Digixx | 0:1e4aa22fc1a1 | 91 | #define ADXL345_6HZ25 0x06 |
Digixx | 0:1e4aa22fc1a1 | 92 | |
tylerjw | 6:5fb29534a6cf | 93 | // DATA_FORMAT register |
tylerjw | 6:5fb29534a6cf | 94 | #define ADXL345_2G 0x00 |
tylerjw | 6:5fb29534a6cf | 95 | #define ADXL345_4G 0x01 |
tylerjw | 6:5fb29534a6cf | 96 | #define ADXL345_8G 0x02 |
tylerjw | 6:5fb29534a6cf | 97 | #define ADXL345_16G 0x03 |
tylerjw | 6:5fb29534a6cf | 98 | #define ADXL345_LJUST 0x04 |
tylerjw | 6:5fb29534a6cf | 99 | #define ADXL345_FULL_RES 0x08 |
tylerjw | 6:5fb29534a6cf | 100 | #define ADXL345_INT_LOW 0x10 |
tylerjw | 6:5fb29534a6cf | 101 | #define ADXL345_SELF_TEST 0x80 |
tylerjw | 6:5fb29534a6cf | 102 | |
Digixx | 0:1e4aa22fc1a1 | 103 | // read or write bytes |
Digixx | 0:1e4aa22fc1a1 | 104 | #define ADXL345_READ 0xA7 |
Digixx | 0:1e4aa22fc1a1 | 105 | #define ADXL345_WRITE 0xA6 |
Digixx | 0:1e4aa22fc1a1 | 106 | #define ADXL345_ADDRESS 0x53 //the ADXL345 7-bit address is 0x53 when ALT ADDRESS is low as it is on the sparkfun chip: when ALT ADDRESS is high the address is 0x1D |
Digixx | 0:1e4aa22fc1a1 | 107 | |
Digixx | 0:1e4aa22fc1a1 | 108 | /////////////when ALT ADDRESS pin is high: |
Digixx | 0:1e4aa22fc1a1 | 109 | //#define ADXL345_READ 0x3B |
Digixx | 0:1e4aa22fc1a1 | 110 | //#define ADXL345_WRITE 0x3A |
Digixx | 0:1e4aa22fc1a1 | 111 | //#define ADXL345_ADDRESS 0x1D |
Digixx | 0:1e4aa22fc1a1 | 112 | |
Digixx | 0:1e4aa22fc1a1 | 113 | #define ADXL345_X 0x00 |
Digixx | 0:1e4aa22fc1a1 | 114 | #define ADXL345_Y 0x01 |
Digixx | 0:1e4aa22fc1a1 | 115 | #define ADXL345_Z 0x02 |
Digixx | 0:1e4aa22fc1a1 | 116 | |
Digixx | 0:1e4aa22fc1a1 | 117 | |
Digixx | 0:1e4aa22fc1a1 | 118 | |
Digixx | 0:1e4aa22fc1a1 | 119 | // modes |
Digixx | 0:1e4aa22fc1a1 | 120 | #define MeasurementMode 0x08 |
Digixx | 0:1e4aa22fc1a1 | 121 | |
Digixx | 0:1e4aa22fc1a1 | 122 | |
Digixx | 0:1e4aa22fc1a1 | 123 | |
Digixx | 0:1e4aa22fc1a1 | 124 | |
Digixx | 0:1e4aa22fc1a1 | 125 | |
Digixx | 0:1e4aa22fc1a1 | 126 | |
gltest26 | 3:7b83694c7292 | 127 | /** |
gltest26 | 3:7b83694c7292 | 128 | * ADXL345 triple axis accelerometer. |
gltest26 | 3:7b83694c7292 | 129 | */ |
Digixx | 0:1e4aa22fc1a1 | 130 | class ADXL345 { |
Digixx | 0:1e4aa22fc1a1 | 131 | |
Digixx | 0:1e4aa22fc1a1 | 132 | public: |
Digixx | 0:1e4aa22fc1a1 | 133 | |
gltest26 | 4:8046894b947e | 134 | static const char RANGE_BITS = 0x3; |
gltest26 | 4:8046894b947e | 135 | static const char RANGE_2G = 0x0; |
gltest26 | 4:8046894b947e | 136 | static const char RANGE_4G = 0x1; |
gltest26 | 4:8046894b947e | 137 | static const char RANGE_8G = 0x2; |
gltest26 | 4:8046894b947e | 138 | static const char RANGE_16G = 0x3; |
gltest26 | 4:8046894b947e | 139 | |
Digixx | 0:1e4aa22fc1a1 | 140 | /** |
Digixx | 0:1e4aa22fc1a1 | 141 | * Constructor. |
Digixx | 0:1e4aa22fc1a1 | 142 | * |
Digixx | 0:1e4aa22fc1a1 | 143 | * @param mosi mbed pin to use for SDA line of I2C interface. |
Digixx | 0:1e4aa22fc1a1 | 144 | * @param sck mbed pin to use for SCL line of I2C interface. |
Digixx | 0:1e4aa22fc1a1 | 145 | */ |
Digixx | 0:1e4aa22fc1a1 | 146 | ADXL345(PinName sda, PinName scl); |
gltest26 | 5:122a504fcfa3 | 147 | |
gltest26 | 5:122a504fcfa3 | 148 | |
gltest26 | 5:122a504fcfa3 | 149 | /** |
gltest26 | 5:122a504fcfa3 | 150 | * Constructor that accepts external i2c interface object. |
gltest26 | 5:122a504fcfa3 | 151 | * |
gltest26 | 5:122a504fcfa3 | 152 | * @param i2c The I2C interface object to use. |
gltest26 | 5:122a504fcfa3 | 153 | */ |
gltest26 | 5:122a504fcfa3 | 154 | ADXL345(I2C &i2c) : i2c_(i2c), myI2c(NULL){} |
gltest26 | 5:122a504fcfa3 | 155 | |
gltest26 | 5:122a504fcfa3 | 156 | /** |
gltest26 | 5:122a504fcfa3 | 157 | * Destructor that frees self-allocated I2C object. |
gltest26 | 5:122a504fcfa3 | 158 | */ |
gltest26 | 5:122a504fcfa3 | 159 | ~ADXL345(); |
gltest26 | 5:122a504fcfa3 | 160 | |
gltest26 | 5:122a504fcfa3 | 161 | void init(); |
Digixx | 0:1e4aa22fc1a1 | 162 | |
Digixx | 0:1e4aa22fc1a1 | 163 | /** |
Digixx | 0:1e4aa22fc1a1 | 164 | * Get the output of all three axes. |
Digixx | 0:1e4aa22fc1a1 | 165 | * |
Digixx | 0:1e4aa22fc1a1 | 166 | * @param Pointer to a buffer to hold the accelerometer value for the |
Digixx | 0:1e4aa22fc1a1 | 167 | * x-axis, y-axis and z-axis [in that order]. |
Digixx | 0:1e4aa22fc1a1 | 168 | */ |
Digixx | 0:1e4aa22fc1a1 | 169 | void getOutput(int* readings); |
Digixx | 0:1e4aa22fc1a1 | 170 | |
Digixx | 0:1e4aa22fc1a1 | 171 | /** |
Digixx | 0:1e4aa22fc1a1 | 172 | * Read the device ID register on the device. |
Digixx | 0:1e4aa22fc1a1 | 173 | * |
Digixx | 0:1e4aa22fc1a1 | 174 | * @return The device ID code [0xE5] |
Digixx | 0:1e4aa22fc1a1 | 175 | */ |
Digixx | 0:1e4aa22fc1a1 | 176 | char getDeviceID(void); |
Digixx | 0:1e4aa22fc1a1 | 177 | |
Digixx | 0:1e4aa22fc1a1 | 178 | /** |
Digixx | 0:1e4aa22fc1a1 | 179 | * Set the power mode. |
Digixx | 0:1e4aa22fc1a1 | 180 | * |
Digixx | 0:1e4aa22fc1a1 | 181 | * @param mode 0 -> Normal operation. |
Digixx | 0:1e4aa22fc1a1 | 182 | * 1 -> Reduced power operation. |
Digixx | 0:1e4aa22fc1a1 | 183 | */ |
Digixx | 0:1e4aa22fc1a1 | 184 | int setPowerMode(char mode); |
Digixx | 0:1e4aa22fc1a1 | 185 | |
Digixx | 0:1e4aa22fc1a1 | 186 | /** |
Digixx | 0:1e4aa22fc1a1 | 187 | * Set the power control settings. |
Digixx | 0:1e4aa22fc1a1 | 188 | * |
Digixx | 0:1e4aa22fc1a1 | 189 | * See datasheet for details. |
Digixx | 0:1e4aa22fc1a1 | 190 | * |
Digixx | 0:1e4aa22fc1a1 | 191 | * @param The control byte to write to the POWER_CTL register. |
Digixx | 0:1e4aa22fc1a1 | 192 | */ |
Digixx | 0:1e4aa22fc1a1 | 193 | int setPowerControl(char settings); |
Digixx | 0:1e4aa22fc1a1 | 194 | /** |
Digixx | 0:1e4aa22fc1a1 | 195 | * Get the power control settings. |
Digixx | 0:1e4aa22fc1a1 | 196 | * |
Digixx | 0:1e4aa22fc1a1 | 197 | * See datasheet for details. |
Digixx | 0:1e4aa22fc1a1 | 198 | * |
Digixx | 0:1e4aa22fc1a1 | 199 | * @return The contents of the POWER_CTL register. |
Digixx | 0:1e4aa22fc1a1 | 200 | */ |
Digixx | 0:1e4aa22fc1a1 | 201 | char getPowerControl(void); |
Digixx | 0:1e4aa22fc1a1 | 202 | |
Digixx | 0:1e4aa22fc1a1 | 203 | |
Digixx | 0:1e4aa22fc1a1 | 204 | /** |
Digixx | 0:1e4aa22fc1a1 | 205 | * Get the data format settings. |
Digixx | 0:1e4aa22fc1a1 | 206 | * |
Digixx | 0:1e4aa22fc1a1 | 207 | * @return The contents of the DATA_FORMAT register. |
Digixx | 0:1e4aa22fc1a1 | 208 | */ |
Digixx | 0:1e4aa22fc1a1 | 209 | |
Digixx | 0:1e4aa22fc1a1 | 210 | char getDataFormatControl(void); |
Digixx | 0:1e4aa22fc1a1 | 211 | |
Digixx | 0:1e4aa22fc1a1 | 212 | /** |
Digixx | 0:1e4aa22fc1a1 | 213 | * Set the data format settings. |
Digixx | 0:1e4aa22fc1a1 | 214 | * |
Digixx | 0:1e4aa22fc1a1 | 215 | * @param settings The control byte to write to the DATA_FORMAT register. |
Digixx | 0:1e4aa22fc1a1 | 216 | */ |
Digixx | 0:1e4aa22fc1a1 | 217 | int setDataFormatControl(char settings); |
gltest26 | 4:8046894b947e | 218 | |
gltest26 | 4:8046894b947e | 219 | /** |
gltest26 | 4:8046894b947e | 220 | * Set the data format settings with only specified bits. |
gltest26 | 4:8046894b947e | 221 | * |
gltest26 | 4:8046894b947e | 222 | * @param settings The control byte to write to the DATA_FORMAT register. |
gltest26 | 4:8046894b947e | 223 | * @param mask The mask bits that |
gltest26 | 4:8046894b947e | 224 | */ |
gltest26 | 4:8046894b947e | 225 | int setDataFormatControl(char settings, char mask, char *prev = NULL); |
Digixx | 0:1e4aa22fc1a1 | 226 | |
gltest26 | 4:8046894b947e | 227 | /** |
Digixx | 0:1e4aa22fc1a1 | 228 | * Set the data rate. |
Digixx | 0:1e4aa22fc1a1 | 229 | * |
Digixx | 0:1e4aa22fc1a1 | 230 | * @param rate The rate code (see #defines or datasheet). |
Digixx | 0:1e4aa22fc1a1 | 231 | */ |
Digixx | 0:1e4aa22fc1a1 | 232 | int setDataRate(char rate); |
Digixx | 0:1e4aa22fc1a1 | 233 | |
Digixx | 0:1e4aa22fc1a1 | 234 | |
tylerjw | 6:5fb29534a6cf | 235 | /** |
Digixx | 0:1e4aa22fc1a1 | 236 | * Get the current offset for a particular axis. |
Digixx | 0:1e4aa22fc1a1 | 237 | * |
Digixx | 0:1e4aa22fc1a1 | 238 | * @param axis 0x00 -> X-axis |
Digixx | 0:1e4aa22fc1a1 | 239 | * 0x01 -> Y-axis |
Digixx | 0:1e4aa22fc1a1 | 240 | * 0x02 -> Z-axis |
Digixx | 0:1e4aa22fc1a1 | 241 | * @return The current offset as an 8-bit 2's complement number with scale |
Digixx | 0:1e4aa22fc1a1 | 242 | * factor 15.6mg/LSB. |
Digixx | 0:1e4aa22fc1a1 | 243 | */ |
Digixx | 0:1e4aa22fc1a1 | 244 | |
Digixx | 0:1e4aa22fc1a1 | 245 | char getOffset(char axis); |
Digixx | 0:1e4aa22fc1a1 | 246 | |
Digixx | 0:1e4aa22fc1a1 | 247 | /** |
Digixx | 0:1e4aa22fc1a1 | 248 | * Set the offset for a particular axis. |
Digixx | 0:1e4aa22fc1a1 | 249 | * |
Digixx | 0:1e4aa22fc1a1 | 250 | * @param axis 0x00 -> X-axis |
Digixx | 0:1e4aa22fc1a1 | 251 | * 0x01 -> Y-axis |
Digixx | 0:1e4aa22fc1a1 | 252 | * 0x02 -> Z-axis |
Digixx | 0:1e4aa22fc1a1 | 253 | * @param offset The offset as an 8-bit 2's complement number with scale |
Digixx | 0:1e4aa22fc1a1 | 254 | * factor 15.6mg/LSB. |
Digixx | 0:1e4aa22fc1a1 | 255 | */ |
Digixx | 0:1e4aa22fc1a1 | 256 | int setOffset(char axis, char offset); |
Digixx | 0:1e4aa22fc1a1 | 257 | |
Digixx | 0:1e4aa22fc1a1 | 258 | /** |
Digixx | 0:1e4aa22fc1a1 | 259 | * Get the FIFO control settings. |
Digixx | 0:1e4aa22fc1a1 | 260 | * |
Digixx | 0:1e4aa22fc1a1 | 261 | * @return The contents of the FIFO_CTL register. |
Digixx | 0:1e4aa22fc1a1 | 262 | */ |
Digixx | 0:1e4aa22fc1a1 | 263 | char getFifoControl(void); |
Digixx | 0:1e4aa22fc1a1 | 264 | |
Digixx | 0:1e4aa22fc1a1 | 265 | /** |
Digixx | 0:1e4aa22fc1a1 | 266 | * Set the FIFO control settings. |
Digixx | 0:1e4aa22fc1a1 | 267 | * |
Digixx | 0:1e4aa22fc1a1 | 268 | * @param The control byte to write to the FIFO_CTL register. |
Digixx | 0:1e4aa22fc1a1 | 269 | */ |
Digixx | 0:1e4aa22fc1a1 | 270 | int setFifoControl(char settings); |
Digixx | 0:1e4aa22fc1a1 | 271 | |
Digixx | 0:1e4aa22fc1a1 | 272 | /** |
Digixx | 0:1e4aa22fc1a1 | 273 | * Get FIFO status. |
Digixx | 0:1e4aa22fc1a1 | 274 | * |
Digixx | 0:1e4aa22fc1a1 | 275 | * @return The contents of the FIFO_STATUS register. |
Digixx | 0:1e4aa22fc1a1 | 276 | */ |
Digixx | 0:1e4aa22fc1a1 | 277 | char getFifoStatus(void); |
Digixx | 0:1e4aa22fc1a1 | 278 | |
Digixx | 0:1e4aa22fc1a1 | 279 | /** |
Digixx | 0:1e4aa22fc1a1 | 280 | * Read the tap threshold on the device. |
Digixx | 0:1e4aa22fc1a1 | 281 | * |
Digixx | 0:1e4aa22fc1a1 | 282 | * @return The tap threshold as an 8-bit number with a scale factor of |
Digixx | 0:1e4aa22fc1a1 | 283 | * 62.5mg/LSB. |
Digixx | 0:1e4aa22fc1a1 | 284 | */ |
Digixx | 0:1e4aa22fc1a1 | 285 | char getTapThreshold(void); |
Digixx | 0:1e4aa22fc1a1 | 286 | |
Digixx | 0:1e4aa22fc1a1 | 287 | /** |
Digixx | 0:1e4aa22fc1a1 | 288 | * Set the tap threshold. |
Digixx | 0:1e4aa22fc1a1 | 289 | * |
Digixx | 0:1e4aa22fc1a1 | 290 | * @param The tap threshold as an 8-bit number with a scale factor of |
Digixx | 0:1e4aa22fc1a1 | 291 | * 62.5mg/LSB. |
Digixx | 0:1e4aa22fc1a1 | 292 | */ |
Digixx | 0:1e4aa22fc1a1 | 293 | int setTapThreshold(char threshold); |
Digixx | 0:1e4aa22fc1a1 | 294 | |
Digixx | 0:1e4aa22fc1a1 | 295 | /** |
Digixx | 0:1e4aa22fc1a1 | 296 | * Get the tap duration required to trigger an event. |
Digixx | 0:1e4aa22fc1a1 | 297 | * |
Digixx | 0:1e4aa22fc1a1 | 298 | * @return The max time that an event must be above the tap threshold to |
Digixx | 0:1e4aa22fc1a1 | 299 | * qualify as a tap event, in microseconds. |
Digixx | 0:1e4aa22fc1a1 | 300 | */ |
Digixx | 0:1e4aa22fc1a1 | 301 | float getTapDuration(void); |
Digixx | 0:1e4aa22fc1a1 | 302 | |
Digixx | 0:1e4aa22fc1a1 | 303 | /** |
Digixx | 0:1e4aa22fc1a1 | 304 | * Set the tap duration required to trigger an event. |
Digixx | 0:1e4aa22fc1a1 | 305 | * |
Digixx | 0:1e4aa22fc1a1 | 306 | * @param duration_us The max time that an event must be above the tap |
Digixx | 0:1e4aa22fc1a1 | 307 | * threshold to qualify as a tap event, in microseconds. |
Digixx | 0:1e4aa22fc1a1 | 308 | * Time will be normalized by the scale factor which is |
Digixx | 0:1e4aa22fc1a1 | 309 | * 625us/LSB. A value of 0 disables the single/double |
Digixx | 0:1e4aa22fc1a1 | 310 | * tap functions. |
Digixx | 0:1e4aa22fc1a1 | 311 | */ |
Digixx | 0:1e4aa22fc1a1 | 312 | int setTapDuration(short int duration_us); |
Digixx | 0:1e4aa22fc1a1 | 313 | |
Digixx | 0:1e4aa22fc1a1 | 314 | /** |
Digixx | 0:1e4aa22fc1a1 | 315 | * Get the tap latency between the detection of a tap and the time window. |
Digixx | 0:1e4aa22fc1a1 | 316 | * |
Digixx | 0:1e4aa22fc1a1 | 317 | * @return The wait time from the detection of a tap event to the start of |
Digixx | 0:1e4aa22fc1a1 | 318 | * the time window during which a possible second tap event can be |
Digixx | 0:1e4aa22fc1a1 | 319 | * detected in milliseconds. |
Digixx | 0:1e4aa22fc1a1 | 320 | */ |
Digixx | 0:1e4aa22fc1a1 | 321 | float getTapLatency(void); |
Digixx | 0:1e4aa22fc1a1 | 322 | |
Digixx | 0:1e4aa22fc1a1 | 323 | /** |
Digixx | 0:1e4aa22fc1a1 | 324 | * Set the tap latency between the detection of a tap and the time window. |
Digixx | 0:1e4aa22fc1a1 | 325 | * |
Digixx | 0:1e4aa22fc1a1 | 326 | * @param latency_ms The wait time from the detection of a tap event to the |
Digixx | 0:1e4aa22fc1a1 | 327 | * start of the time window during which a possible |
Digixx | 0:1e4aa22fc1a1 | 328 | * second tap event can be detected in milliseconds. |
Digixx | 0:1e4aa22fc1a1 | 329 | * A value of 0 disables the double tap function. |
Digixx | 0:1e4aa22fc1a1 | 330 | */ |
Digixx | 0:1e4aa22fc1a1 | 331 | int setTapLatency(short int latency_ms); |
Digixx | 0:1e4aa22fc1a1 | 332 | |
Digixx | 0:1e4aa22fc1a1 | 333 | /** |
Digixx | 0:1e4aa22fc1a1 | 334 | * Get the time of window between tap latency and a double tap. |
Digixx | 0:1e4aa22fc1a1 | 335 | * |
Digixx | 0:1e4aa22fc1a1 | 336 | * @return The amount of time after the expiration of the latency time |
Digixx | 0:1e4aa22fc1a1 | 337 | * during which a second valid tap can begin, in milliseconds. |
Digixx | 0:1e4aa22fc1a1 | 338 | */ |
Digixx | 0:1e4aa22fc1a1 | 339 | float getWindowTime(void); |
Digixx | 0:1e4aa22fc1a1 | 340 | |
Digixx | 0:1e4aa22fc1a1 | 341 | /** |
Digixx | 0:1e4aa22fc1a1 | 342 | * Set the time of the window between tap latency and a double tap. |
Digixx | 0:1e4aa22fc1a1 | 343 | * |
Digixx | 0:1e4aa22fc1a1 | 344 | * @param window_ms The amount of time after the expiration of the latency |
Digixx | 0:1e4aa22fc1a1 | 345 | * time during which a second valid tap can begin, |
Digixx | 0:1e4aa22fc1a1 | 346 | * in milliseconds. |
Digixx | 0:1e4aa22fc1a1 | 347 | */ |
Digixx | 0:1e4aa22fc1a1 | 348 | int setWindowTime(short int window_ms); |
Digixx | 0:1e4aa22fc1a1 | 349 | |
Digixx | 0:1e4aa22fc1a1 | 350 | /** |
Digixx | 0:1e4aa22fc1a1 | 351 | * Get the threshold value for detecting activity. |
Digixx | 0:1e4aa22fc1a1 | 352 | * |
Digixx | 0:1e4aa22fc1a1 | 353 | * @return The threshold value for detecting activity as an 8-bit number. |
Digixx | 0:1e4aa22fc1a1 | 354 | * Scale factor is 62.5mg/LSB. |
Digixx | 0:1e4aa22fc1a1 | 355 | */ |
Digixx | 0:1e4aa22fc1a1 | 356 | char getActivityThreshold(void); |
Digixx | 0:1e4aa22fc1a1 | 357 | |
Digixx | 0:1e4aa22fc1a1 | 358 | /** |
Digixx | 0:1e4aa22fc1a1 | 359 | * Set the threshold value for detecting activity. |
Digixx | 0:1e4aa22fc1a1 | 360 | * |
Digixx | 0:1e4aa22fc1a1 | 361 | * @param threshold The threshold value for detecting activity as an 8-bit |
Digixx | 0:1e4aa22fc1a1 | 362 | * number. Scale factor is 62.5mg/LSB. A value of 0 may |
Digixx | 0:1e4aa22fc1a1 | 363 | * result in undesirable behavior if the activity |
Digixx | 0:1e4aa22fc1a1 | 364 | * interrupt is enabled. |
Digixx | 0:1e4aa22fc1a1 | 365 | */ |
Digixx | 0:1e4aa22fc1a1 | 366 | int setActivityThreshold(char threshold); |
Digixx | 0:1e4aa22fc1a1 | 367 | |
Digixx | 0:1e4aa22fc1a1 | 368 | /** |
Digixx | 0:1e4aa22fc1a1 | 369 | * Get the threshold value for detecting inactivity. |
Digixx | 0:1e4aa22fc1a1 | 370 | * |
Digixx | 0:1e4aa22fc1a1 | 371 | * @return The threshold value for detecting inactivity as an 8-bit number. |
Digixx | 0:1e4aa22fc1a1 | 372 | * Scale factor is 62.5mg/LSB. |
Digixx | 0:1e4aa22fc1a1 | 373 | */ |
Digixx | 0:1e4aa22fc1a1 | 374 | char getInactivityThreshold(void); |
Digixx | 0:1e4aa22fc1a1 | 375 | |
Digixx | 0:1e4aa22fc1a1 | 376 | /** |
Digixx | 0:1e4aa22fc1a1 | 377 | * Set the threshold value for detecting inactivity. |
Digixx | 0:1e4aa22fc1a1 | 378 | * |
Digixx | 0:1e4aa22fc1a1 | 379 | * @param threshold The threshold value for detecting inactivity as an |
Digixx | 0:1e4aa22fc1a1 | 380 | * 8-bit number. Scale factor is 62.5mg/LSB. |
Digixx | 0:1e4aa22fc1a1 | 381 | */ |
Digixx | 0:1e4aa22fc1a1 | 382 | int setInactivityThreshold(char threshold); |
Digixx | 0:1e4aa22fc1a1 | 383 | |
Digixx | 0:1e4aa22fc1a1 | 384 | /** |
Digixx | 0:1e4aa22fc1a1 | 385 | * Get the time required for inactivity to be declared. |
Digixx | 0:1e4aa22fc1a1 | 386 | * |
Digixx | 0:1e4aa22fc1a1 | 387 | * @return The amount of time that acceleration must be less than the |
Digixx | 0:1e4aa22fc1a1 | 388 | * inactivity threshold for inactivity to be declared, in |
Digixx | 0:1e4aa22fc1a1 | 389 | * seconds. |
Digixx | 0:1e4aa22fc1a1 | 390 | */ |
Digixx | 0:1e4aa22fc1a1 | 391 | char getTimeInactivity(void); |
Digixx | 0:1e4aa22fc1a1 | 392 | |
Digixx | 0:1e4aa22fc1a1 | 393 | /** |
Digixx | 0:1e4aa22fc1a1 | 394 | * Set the time required for inactivity to be declared. |
Digixx | 0:1e4aa22fc1a1 | 395 | * |
Digixx | 0:1e4aa22fc1a1 | 396 | * @param inactivity The amount of time that acceleration must be less than |
Digixx | 0:1e4aa22fc1a1 | 397 | * the inactivity threshold for inactivity to be |
Digixx | 0:1e4aa22fc1a1 | 398 | * declared, in seconds. A value of 0 results in an |
Digixx | 0:1e4aa22fc1a1 | 399 | * interrupt when the output data is less than the |
Digixx | 0:1e4aa22fc1a1 | 400 | * threshold inactivity. |
Digixx | 0:1e4aa22fc1a1 | 401 | */ |
Digixx | 0:1e4aa22fc1a1 | 402 | int setTimeInactivity(char timeInactivity); |
Digixx | 0:1e4aa22fc1a1 | 403 | |
Digixx | 0:1e4aa22fc1a1 | 404 | /** |
Digixx | 0:1e4aa22fc1a1 | 405 | * Get the activity/inactivity control settings. |
Digixx | 0:1e4aa22fc1a1 | 406 | * |
Digixx | 0:1e4aa22fc1a1 | 407 | * D7 D6 D5 D4 |
Digixx | 0:1e4aa22fc1a1 | 408 | * +-----------+--------------+--------------+--------------+ |
Digixx | 0:1e4aa22fc1a1 | 409 | * | ACT ac/dc | ACT_X enable | ACT_Y enable | ACT_Z enable | |
Digixx | 0:1e4aa22fc1a1 | 410 | * +-----------+--------------+--------------+--------------+ |
Digixx | 0:1e4aa22fc1a1 | 411 | * |
Digixx | 0:1e4aa22fc1a1 | 412 | * D3 D2 D1 D0 |
Digixx | 0:1e4aa22fc1a1 | 413 | * +-------------+----------------+----------------+----------------+ |
Digixx | 0:1e4aa22fc1a1 | 414 | * | INACT ac/dc | INACT_X enable | INACT_Y enable | INACT_Z enable | |
Digixx | 0:1e4aa22fc1a1 | 415 | * +-------------+----------------+----------------+----------------+ |
Digixx | 0:1e4aa22fc1a1 | 416 | * |
Digixx | 0:1e4aa22fc1a1 | 417 | * See datasheet for details. |
Digixx | 0:1e4aa22fc1a1 | 418 | * |
Digixx | 0:1e4aa22fc1a1 | 419 | * @return The contents of the ACT_INACT_CTL register. |
Digixx | 0:1e4aa22fc1a1 | 420 | */ |
Digixx | 0:1e4aa22fc1a1 | 421 | char getActivityInactivityControl(void); |
Digixx | 0:1e4aa22fc1a1 | 422 | |
Digixx | 0:1e4aa22fc1a1 | 423 | /** |
Digixx | 0:1e4aa22fc1a1 | 424 | * Set the activity/inactivity control settings. |
Digixx | 0:1e4aa22fc1a1 | 425 | * |
Digixx | 0:1e4aa22fc1a1 | 426 | * D7 D6 D5 D4 |
Digixx | 0:1e4aa22fc1a1 | 427 | * +-----------+--------------+--------------+--------------+ |
Digixx | 0:1e4aa22fc1a1 | 428 | * | ACT ac/dc | ACT_X enable | ACT_Y enable | ACT_Z enable | |
Digixx | 0:1e4aa22fc1a1 | 429 | * +-----------+--------------+--------------+--------------+ |
Digixx | 0:1e4aa22fc1a1 | 430 | * |
Digixx | 0:1e4aa22fc1a1 | 431 | * D3 D2 D1 D0 |
Digixx | 0:1e4aa22fc1a1 | 432 | * +-------------+----------------+----------------+----------------+ |
Digixx | 0:1e4aa22fc1a1 | 433 | * | INACT ac/dc | INACT_X enable | INACT_Y enable | INACT_Z enable | |
Digixx | 0:1e4aa22fc1a1 | 434 | * +-------------+----------------+----------------+----------------+ |
Digixx | 0:1e4aa22fc1a1 | 435 | * |
Digixx | 0:1e4aa22fc1a1 | 436 | * See datasheet for details. |
Digixx | 0:1e4aa22fc1a1 | 437 | * |
Digixx | 0:1e4aa22fc1a1 | 438 | * @param settings The control byte to write to the ACT_INACT_CTL register. |
Digixx | 0:1e4aa22fc1a1 | 439 | */ |
Digixx | 0:1e4aa22fc1a1 | 440 | int setActivityInactivityControl(char settings); |
Digixx | 0:1e4aa22fc1a1 | 441 | |
Digixx | 0:1e4aa22fc1a1 | 442 | /** |
Digixx | 0:1e4aa22fc1a1 | 443 | * Get the threshold for free fall detection. |
Digixx | 0:1e4aa22fc1a1 | 444 | * |
Digixx | 0:1e4aa22fc1a1 | 445 | * @return The threshold value for free-fall detection, as an 8-bit number, |
Digixx | 0:1e4aa22fc1a1 | 446 | * with scale factor 62.5mg/LSB. |
Digixx | 0:1e4aa22fc1a1 | 447 | */ |
Digixx | 0:1e4aa22fc1a1 | 448 | char getFreefallThreshold(void); |
Digixx | 0:1e4aa22fc1a1 | 449 | |
Digixx | 0:1e4aa22fc1a1 | 450 | /** |
Digixx | 0:1e4aa22fc1a1 | 451 | * Set the threshold for free fall detection. |
Digixx | 0:1e4aa22fc1a1 | 452 | * |
Digixx | 0:1e4aa22fc1a1 | 453 | * @return The threshold value for free-fall detection, as an 8-bit number, |
Digixx | 0:1e4aa22fc1a1 | 454 | * with scale factor 62.5mg/LSB. A value of 0 may result in |
Digixx | 0:1e4aa22fc1a1 | 455 | * undesirable behavior if the free-fall interrupt is enabled. |
Digixx | 0:1e4aa22fc1a1 | 456 | * Values between 300 mg and 600 mg (0x05 to 0x09) are recommended. |
Digixx | 0:1e4aa22fc1a1 | 457 | */ |
Digixx | 0:1e4aa22fc1a1 | 458 | int setFreefallThreshold(char threshold); |
Digixx | 0:1e4aa22fc1a1 | 459 | |
Digixx | 0:1e4aa22fc1a1 | 460 | /** |
Digixx | 0:1e4aa22fc1a1 | 461 | * Get the time required to generate a free fall interrupt. |
Digixx | 0:1e4aa22fc1a1 | 462 | * |
Digixx | 0:1e4aa22fc1a1 | 463 | * @return The minimum time that the value of all axes must be less than |
Digixx | 0:1e4aa22fc1a1 | 464 | * the freefall threshold to generate a free-fall interrupt, in |
Digixx | 0:1e4aa22fc1a1 | 465 | * milliseconds. |
Digixx | 0:1e4aa22fc1a1 | 466 | */ |
Digixx | 0:1e4aa22fc1a1 | 467 | char getFreefallTime(void); |
Digixx | 0:1e4aa22fc1a1 | 468 | |
Digixx | 0:1e4aa22fc1a1 | 469 | /** |
Digixx | 0:1e4aa22fc1a1 | 470 | * Set the time required to generate a free fall interrupt. |
Digixx | 0:1e4aa22fc1a1 | 471 | * |
Digixx | 0:1e4aa22fc1a1 | 472 | * @return The minimum time that the value of all axes must be less than |
Digixx | 0:1e4aa22fc1a1 | 473 | * the freefall threshold to generate a free-fall interrupt, in |
Digixx | 0:1e4aa22fc1a1 | 474 | * milliseconds. A value of 0 may result in undesirable behavior |
Digixx | 0:1e4aa22fc1a1 | 475 | * if the free-fall interrupt is enabled. Values between 100 ms |
Digixx | 0:1e4aa22fc1a1 | 476 | * and 350 ms (0x14 to 0x46) are recommended. |
Digixx | 0:1e4aa22fc1a1 | 477 | */ |
Digixx | 0:1e4aa22fc1a1 | 478 | int setFreefallTime(short int freefallTime_ms); |
Digixx | 0:1e4aa22fc1a1 | 479 | |
Digixx | 0:1e4aa22fc1a1 | 480 | /** |
Digixx | 0:1e4aa22fc1a1 | 481 | * Get the axis tap settings. |
Digixx | 0:1e4aa22fc1a1 | 482 | * |
Digixx | 0:1e4aa22fc1a1 | 483 | * D3 D2 D1 D0 |
Digixx | 0:1e4aa22fc1a1 | 484 | * +----------+--------------+--------------+--------------+ |
Digixx | 0:1e4aa22fc1a1 | 485 | * | Suppress | TAP_X enable | TAP_Y enable | TAP_Z enable | |
Digixx | 0:1e4aa22fc1a1 | 486 | * +----------+--------------+--------------+--------------+ |
Digixx | 0:1e4aa22fc1a1 | 487 | * |
Digixx | 0:1e4aa22fc1a1 | 488 | * (D7-D4 are 0s). |
Digixx | 0:1e4aa22fc1a1 | 489 | * |
Digixx | 0:1e4aa22fc1a1 | 490 | * See datasheet for more details. |
Digixx | 0:1e4aa22fc1a1 | 491 | * |
Digixx | 0:1e4aa22fc1a1 | 492 | * @return The contents of the TAP_AXES register. |
Digixx | 0:1e4aa22fc1a1 | 493 | */ |
Digixx | 0:1e4aa22fc1a1 | 494 | char getTapAxisControl(void); |
Digixx | 0:1e4aa22fc1a1 | 495 | |
Digixx | 0:1e4aa22fc1a1 | 496 | /** |
Digixx | 0:1e4aa22fc1a1 | 497 | * Set the axis tap settings. |
Digixx | 0:1e4aa22fc1a1 | 498 | * |
Digixx | 0:1e4aa22fc1a1 | 499 | * D3 D2 D1 D0 |
Digixx | 0:1e4aa22fc1a1 | 500 | * +----------+--------------+--------------+--------------+ |
Digixx | 0:1e4aa22fc1a1 | 501 | * | Suppress | TAP_X enable | TAP_Y enable | TAP_Z enable | |
Digixx | 0:1e4aa22fc1a1 | 502 | * +----------+--------------+--------------+--------------+ |
Digixx | 0:1e4aa22fc1a1 | 503 | * |
Digixx | 0:1e4aa22fc1a1 | 504 | * (D7-D4 are 0s). |
Digixx | 0:1e4aa22fc1a1 | 505 | * |
Digixx | 0:1e4aa22fc1a1 | 506 | * See datasheet for more details. |
Digixx | 0:1e4aa22fc1a1 | 507 | * |
Digixx | 0:1e4aa22fc1a1 | 508 | * @param The control byte to write to the TAP_AXES register. |
Digixx | 0:1e4aa22fc1a1 | 509 | */ |
Digixx | 0:1e4aa22fc1a1 | 510 | int setTapAxisControl(char settings); |
Digixx | 0:1e4aa22fc1a1 | 511 | |
Digixx | 0:1e4aa22fc1a1 | 512 | /** |
Digixx | 0:1e4aa22fc1a1 | 513 | * Get the source of a tap. |
Digixx | 0:1e4aa22fc1a1 | 514 | * |
Digixx | 0:1e4aa22fc1a1 | 515 | * @return The contents of the ACT_TAP_STATUS register. |
Digixx | 0:1e4aa22fc1a1 | 516 | */ |
Digixx | 0:1e4aa22fc1a1 | 517 | char getTapSource(void); |
Digixx | 0:1e4aa22fc1a1 | 518 | |
Digixx | 0:1e4aa22fc1a1 | 519 | /** |
Digixx | 0:1e4aa22fc1a1 | 520 | * Get the interrupt enable settings. |
Digixx | 0:1e4aa22fc1a1 | 521 | * |
Digixx | 0:1e4aa22fc1a1 | 522 | * @return The contents of the INT_ENABLE register. |
Digixx | 0:1e4aa22fc1a1 | 523 | */ |
Digixx | 0:1e4aa22fc1a1 | 524 | |
Digixx | 0:1e4aa22fc1a1 | 525 | char getInterruptEnableControl(void); |
Digixx | 0:1e4aa22fc1a1 | 526 | |
Digixx | 0:1e4aa22fc1a1 | 527 | /** |
Digixx | 0:1e4aa22fc1a1 | 528 | * Set the interrupt enable settings. |
Digixx | 0:1e4aa22fc1a1 | 529 | * |
Digixx | 0:1e4aa22fc1a1 | 530 | * @param settings The control byte to write to the INT_ENABLE register. |
Digixx | 0:1e4aa22fc1a1 | 531 | */ |
Digixx | 0:1e4aa22fc1a1 | 532 | int setInterruptEnableControl(char settings); |
Digixx | 0:1e4aa22fc1a1 | 533 | |
Digixx | 0:1e4aa22fc1a1 | 534 | /** |
Digixx | 0:1e4aa22fc1a1 | 535 | * Get the interrupt mapping settings. |
Digixx | 0:1e4aa22fc1a1 | 536 | * |
Digixx | 0:1e4aa22fc1a1 | 537 | * @return The contents of the INT_MAP register. |
Digixx | 0:1e4aa22fc1a1 | 538 | */ |
Digixx | 0:1e4aa22fc1a1 | 539 | char getInterruptMappingControl(void); |
Digixx | 0:1e4aa22fc1a1 | 540 | |
Digixx | 0:1e4aa22fc1a1 | 541 | /** |
Digixx | 0:1e4aa22fc1a1 | 542 | * Set the interrupt mapping settings. |
Digixx | 0:1e4aa22fc1a1 | 543 | * |
Digixx | 0:1e4aa22fc1a1 | 544 | * @param settings The control byte to write to the INT_MAP register. |
Digixx | 0:1e4aa22fc1a1 | 545 | */ |
Digixx | 0:1e4aa22fc1a1 | 546 | int setInterruptMappingControl(char settings); |
Digixx | 0:1e4aa22fc1a1 | 547 | |
Digixx | 0:1e4aa22fc1a1 | 548 | /** |
Digixx | 0:1e4aa22fc1a1 | 549 | * Get the interrupt source. |
Digixx | 0:1e4aa22fc1a1 | 550 | * |
Digixx | 0:1e4aa22fc1a1 | 551 | * @return The contents of the INT_SOURCE register. |
Digixx | 0:1e4aa22fc1a1 | 552 | */ |
Digixx | 0:1e4aa22fc1a1 | 553 | char getInterruptSource(void); |
Digixx | 0:1e4aa22fc1a1 | 554 | |
Digixx | 0:1e4aa22fc1a1 | 555 | |
Digixx | 0:1e4aa22fc1a1 | 556 | private: |
Digixx | 0:1e4aa22fc1a1 | 557 | |
gltest26 | 5:122a504fcfa3 | 558 | I2C &i2c_; |
gltest26 | 5:122a504fcfa3 | 559 | |
gltest26 | 5:122a504fcfa3 | 560 | I2C *myI2c; |
Digixx | 0:1e4aa22fc1a1 | 561 | |
Digixx | 0:1e4aa22fc1a1 | 562 | |
Digixx | 0:1e4aa22fc1a1 | 563 | /** |
Digixx | 0:1e4aa22fc1a1 | 564 | * Read one byte from a register on the device. |
Digixx | 0:1e4aa22fc1a1 | 565 | * |
Digixx | 0:1e4aa22fc1a1 | 566 | * @param: - the address to be read from |
Digixx | 0:1e4aa22fc1a1 | 567 | * |
Digixx | 0:1e4aa22fc1a1 | 568 | * @return: the value of the data read |
Digixx | 0:1e4aa22fc1a1 | 569 | */ |
Digixx | 0:1e4aa22fc1a1 | 570 | char SingleByteRead(char address); |
Digixx | 0:1e4aa22fc1a1 | 571 | |
Digixx | 0:1e4aa22fc1a1 | 572 | /** |
Digixx | 0:1e4aa22fc1a1 | 573 | * Write one byte to a register on the device. |
Digixx | 0:1e4aa22fc1a1 | 574 | * |
Digixx | 0:1e4aa22fc1a1 | 575 | * @param: |
Digixx | 0:1e4aa22fc1a1 | 576 | - address of the register to write to. |
Digixx | 0:1e4aa22fc1a1 | 577 | - the value of the data to store |
Digixx | 0:1e4aa22fc1a1 | 578 | */ |
gltest26 | 4:8046894b947e | 579 | int SingleByteWrite(char address, char data); |
Digixx | 0:1e4aa22fc1a1 | 580 | |
Digixx | 0:1e4aa22fc1a1 | 581 | /** |
Digixx | 0:1e4aa22fc1a1 | 582 | * Read several consecutive bytes on the device and store them in a given location. |
Digixx | 0:1e4aa22fc1a1 | 583 | * |
Digixx | 0:1e4aa22fc1a1 | 584 | * @param startAddress: The address of the first register to read from. |
Digixx | 0:1e4aa22fc1a1 | 585 | * @param ptr_output: a pointer to the location to store the data being read |
Digixx | 0:1e4aa22fc1a1 | 586 | * @param size: The number of bytes to read. |
Digixx | 0:1e4aa22fc1a1 | 587 | */ |
Digixx | 0:1e4aa22fc1a1 | 588 | void multiByteRead(char startAddress, char* ptr_output, int size); |
Digixx | 0:1e4aa22fc1a1 | 589 | |
Digixx | 0:1e4aa22fc1a1 | 590 | /** |
Digixx | 0:1e4aa22fc1a1 | 591 | * Write several consecutive bytes on the device. |
Digixx | 0:1e4aa22fc1a1 | 592 | * |
Digixx | 0:1e4aa22fc1a1 | 593 | * @param startAddress: The address of the first register to write to. |
Digixx | 0:1e4aa22fc1a1 | 594 | * @param ptr_data: Pointer to a location which contains the data to write. |
Digixx | 0:1e4aa22fc1a1 | 595 | * @param size: The number of bytes to write. |
Digixx | 0:1e4aa22fc1a1 | 596 | */ |
Digixx | 0:1e4aa22fc1a1 | 597 | int multiByteWrite(char startAddress, char* ptr_data, int size); |
Digixx | 0:1e4aa22fc1a1 | 598 | |
gltest26 | 3:7b83694c7292 | 599 | private: |
gltest26 | 3:7b83694c7292 | 600 | |
gltest26 | 3:7b83694c7292 | 601 | /** |
gltest26 | 3:7b83694c7292 | 602 | * Converts little-endian 2's complement byte pair to native byte order of |
gltest26 | 3:7b83694c7292 | 603 | * the CPU and then sign extend it to the CPU's register size. |
gltest26 | 3:7b83694c7292 | 604 | * |
gltest26 | 3:7b83694c7292 | 605 | * Implemented here to make the compiler inline expand it. |
gltest26 | 3:7b83694c7292 | 606 | */ |
gltest26 | 3:7b83694c7292 | 607 | static int wordExtend(const char rx[2]){ |
gltest26 | 3:7b83694c7292 | 608 | // Readings are expressed in 16bit 2's complement, so we must first |
gltest26 | 3:7b83694c7292 | 609 | // concatenate two bytes to make a word and sign extend it to obtain |
gltest26 | 3:7b83694c7292 | 610 | // correct negative values. |
gltest26 | 3:7b83694c7292 | 611 | // ARMCC compiles char as unsigned, which means no sign extension is |
gltest26 | 3:7b83694c7292 | 612 | // performed during bitwise operations to chars. But we should make sure |
gltest26 | 3:7b83694c7292 | 613 | // that lower byte won't extend its sign past upper byte for other |
gltest26 | 3:7b83694c7292 | 614 | // compilers if we want to keep it portable. |
gltest26 | 3:7b83694c7292 | 615 | return int16_t(((unsigned char)rx[1] << 8) | (unsigned char)rx[0]); |
gltest26 | 3:7b83694c7292 | 616 | } |
gltest26 | 3:7b83694c7292 | 617 | |
Digixx | 0:1e4aa22fc1a1 | 618 | }; |
Digixx | 0:1e4aa22fc1a1 | 619 | |
Digixx | 0:1e4aa22fc1a1 | 620 | #endif /* ADXL345_H */ |