NOT FINISHED YET!!! My first try to get a self built fully working Quadrocopter based on an mbed, a self built frame and some other more or less cheap parts.

Dependencies:   mbed MODI2C

Committer:
maetugr
Date:
Wed Sep 26 12:15:00 2012 +0000
Revision:
0:0c4fafa398b4
Child:
2:93f703d2c4d7
Sensor Test; Acc, Gyro working, result on LCD (servo lib included)

Who changed what in which revision?

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