| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
#ifndef __ADXL345_H__ |
| 43 |
#define __ADXL345_H__ |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
#define ADXL345_SPI_COMM 0 |
| 51 |
#define ADXL345_I2C_COMM 1 |
| 52 |
|
| 53 |
|
| 54 |
#define ADXL345_SLAVE_ID 1 |
| 55 |
|
| 56 |
|
| 57 |
#define ADXL345_ADDRESS 0x1D |
| 58 |
|
| 59 |
|
| 60 |
#define ADXL345_SPI_READ (1 << 7) |
| 61 |
#define ADXL345_SPI_WRITE (0 << 7) |
| 62 |
#define ADXL345_SPI_MB (1 << 6) |
| 63 |
|
| 64 |
|
| 65 |
#define ADXL345_DEVID 0x00 // R Device ID. |
| 66 |
#define ADXL345_THRESH_TAP 0x1D // R/W Tap threshold. |
| 67 |
#define ADXL345_OFSX 0x1E // R/W X-axis offset. |
| 68 |
#define ADXL345_OFSY 0x1F // R/W Y-axis offset. |
| 69 |
#define ADXL345_OFSZ 0x20 // R/W Z-axis offset. |
| 70 |
#define ADXL345_DUR 0x21 // R/W Tap duration. |
| 71 |
#define ADXL345_LATENT 0x22 // R/W Tap latency. |
| 72 |
#define ADXL345_WINDOW 0x23 // R/W Tap window. |
| 73 |
#define ADXL345_THRESH_ACT 0x24 // R/W Activity threshold. |
| 74 |
#define ADXL345_THRESH_INACT 0x25 // R/W Inactivity threshold. |
| 75 |
#define ADXL345_TIME_INACT 0x26 // R/W Inactivity time. |
| 76 |
#define ADXL345_ACT_INACT_CTL 0x27 // R/W Axis enable control for activity |
| 77 |
|
| 78 |
#define ADXL345_THRESH_FF 0x28 // R/W Free-fall threshold. |
| 79 |
#define ADXL345_TIME_FF 0x29 // R/W Free-fall time. |
| 80 |
#define ADXL345_TAP_AXES 0x2A // R/W Axis control for tap/double tap. |
| 81 |
#define ADXL345_ACT_TAP_STATUS 0x2B // R Source of tap/double tap. |
| 82 |
#define ADXL345_BW_RATE 0x2C // R/W Data rate and power mode control. |
| 83 |
#define ADXL345_POWER_CTL 0x2D // R/W Power saving features control. |
| 84 |
#define ADXL345_INT_ENABLE 0x2E // R/W Interrupt enable control. |
| 85 |
#define ADXL345_INT_MAP 0x2F // R/W Interrupt mapping control. |
| 86 |
#define ADXL345_INT_SOURCE 0x30 // R Source of interrupts. |
| 87 |
#define ADXL345_DATA_FORMAT 0x31 // R/W Data format control. |
| 88 |
#define ADXL345_DATAX0 0x32 // R X-Axis Data 0. |
| 89 |
#define ADXL345_DATAX1 0x33 // R X-Axis Data 1. |
| 90 |
#define ADXL345_DATAY0 0x34 // R Y-Axis Data 0. |
| 91 |
#define ADXL345_DATAY1 0x35 // R Y-Axis Data 1. |
| 92 |
#define ADXL345_DATAZ0 0x36 // R Z-Axis Data 0. |
| 93 |
#define ADXL345_DATAZ1 0x37 // R Z-Axis Data 1. |
| 94 |
#define ADXL345_FIFO_CTL 0x38 // R/W FIFO control. |
| 95 |
#define ADXL345_FIFO_STATUS 0x39 // R FIFO status. |
| 96 |
|
| 97 |
|
| 98 |
#define ADXL345_ACT_ACDC (1 << 7) |
| 99 |
#define ADXL345_ACT_X_EN (1 << 6) |
| 100 |
#define ADXL345_ACT_Y_EN (1 << 5) |
| 101 |
#define ADXL345_ACT_Z_EN (1 << 4) |
| 102 |
#define ADXL345_INACT_ACDC (1 << 3) |
| 103 |
#define ADXL345_INACT_X_EN (1 << 2) |
| 104 |
#define ADXL345_INACT_Y_EN (1 << 1) |
| 105 |
#define ADXL345_INACT_Z_EN (1 << 0) |
| 106 |
|
| 107 |
|
| 108 |
#define ADXL345_SUPPRESS (1 << 3) |
| 109 |
#define ADXL345_TAP_X_EN (1 << 2) |
| 110 |
#define ADXL345_TAP_Y_EN (1 << 1) |
| 111 |
#define ADXL345_TAP_Z_EN (1 << 0) |
| 112 |
|
| 113 |
|
| 114 |
#define ADXL345_ACT_X_SRC (1 << 6) |
| 115 |
#define ADXL345_ACT_Y_SRC (1 << 5) |
| 116 |
#define ADXL345_ACT_Z_SRC (1 << 4) |
| 117 |
#define ADXL345_ASLEEP (1 << 3) |
| 118 |
#define ADXL345_TAP_X_SRC (1 << 2) |
| 119 |
#define ADXL345_TAP_Y_SRC (1 << 1) |
| 120 |
#define ADXL345_TAP_Z_SRC (1 << 0) |
| 121 |
|
| 122 |
|
| 123 |
#define ADXL345_LOW_POWER (1 << 4) |
| 124 |
#define ADXL345_RATE(x) ((x) & 0xF) |
| 125 |
|
| 126 |
|
| 127 |
#define ADXL345_PCTL_LINK (1 << 5) |
| 128 |
#define ADXL345_PCTL_AUTO_SLEEP (1 << 4) |
| 129 |
#define ADXL345_PCTL_MEASURE (1 << 3) |
| 130 |
#define ADXL345_PCTL_SLEEP (1 << 2) |
| 131 |
#define ADXL345_PCTL_WAKEUP(x) ((x) & 0x3) |
| 132 |
|
| 133 |
|
| 134 |
#define ADXL345_DATA_READY (1 << 7) |
| 135 |
#define ADXL345_SINGLE_TAP (1 << 6) |
| 136 |
#define ADXL345_DOUBLE_TAP (1 << 5) |
| 137 |
#define ADXL345_ACTIVITY (1 << 4) |
| 138 |
#define ADXL345_INACTIVITY (1 << 3) |
| 139 |
#define ADXL345_FREE_FALL (1 << 2) |
| 140 |
#define ADXL345_WATERMARK (1 << 1) |
| 141 |
#define ADXL345_OVERRUN (1 << 0) |
| 142 |
|
| 143 |
|
| 144 |
#define ADXL345_SELF_TEST (1 << 7) |
| 145 |
#define ADXL345_SPI (1 << 6) |
| 146 |
#define ADXL345_INT_INVERT (1 << 5) |
| 147 |
#define ADXL345_FULL_RES (1 << 3) |
| 148 |
#define ADXL345_JUSTIFY (1 << 2) |
| 149 |
#define ADXL345_RANGE(x) ((x) & 0x3) |
| 150 |
|
| 151 |
|
| 152 |
#define ADXL345_RANGE_PM_2G 0 |
| 153 |
#define ADXL345_RANGE_PM_4G 1 |
| 154 |
#define ADXL345_RANGE_PM_8G 2 |
| 155 |
#define ADXL345_RANGE_PM_16G 3 |
| 156 |
|
| 157 |
|
| 158 |
#define ADXL345_FIFO_MODE(x) (((x) & 0x3) << 6) |
| 159 |
#define ADXL345_TRIGGER (1 << 5) |
| 160 |
#define ADXL345_SAMPLES(x) ((x) & 0x1F) |
| 161 |
|
| 162 |
|
| 163 |
#define ADXL345_FIFO_BYPASS 0 |
| 164 |
#define ADXL345_FIFO_FIFO 1 |
| 165 |
#define ADXL345_FIFO_STREAM 2 |
| 166 |
#define ADXL345_FIFO_TRIGGER 3 |
| 167 |
|
| 168 |
|
| 169 |
#define ADXL345_FIFO_TRIG (1 << 7) |
| 170 |
#define ADXL345_ENTRIES(x) ((x) & 0x3F) |
| 171 |
|
| 172 |
|
| 173 |
#define ADXL345_ID 0xE5 |
| 174 |
|
| 175 |
|
| 176 |
#define ADXL345_SCALE_FACTOR 0.0039 |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
unsigned char ADXL345_GetRegisterValue(unsigned char registerAddress); |
| 184 |
|
| 185 |
|
| 186 |
void ADXL345_SetRegisterValue(unsigned char registerAddress, |
| 187 |
unsigned char registerValue); |
| 188 |
|
| 189 |
|
| 190 |
char ADXL345_Init(char commProtocol); |
| 191 |
|
| 192 |
|
| 193 |
void ADXL345_SetPowerMode(unsigned char pwrMode); |
| 194 |
|
| 195 |
|
| 196 |
void ADXL345_GetXyz(short* x, |
| 197 |
short* y, |
| 198 |
short* z); |
| 199 |
|
| 200 |
|
| 201 |
void ADXL345_GetGxyz(float* x, |
| 202 |
float* y, |
| 203 |
float* z); |
| 204 |
|
| 205 |
|
| 206 |
void ADXL345_SetTapDetection(unsigned char tapType, |
| 207 |
unsigned char tapAxes, |
| 208 |
unsigned char tapDur, |
| 209 |
unsigned char tapLatent, |
| 210 |
unsigned char tapWindow, |
| 211 |
unsigned char tapThresh, |
| 212 |
unsigned char tapInt); |
| 213 |
|
| 214 |
|
| 215 |
void ADXL345_SetActivityDetection(unsigned char actOnOff, |
| 216 |
unsigned char actAxes, |
| 217 |
unsigned char actAcDc, |
| 218 |
unsigned char actThresh, |
| 219 |
unsigned char actInt); |
| 220 |
|
| 221 |
|
| 222 |
void ADXL345_SetInactivityDetection(unsigned char inactOnOff, |
| 223 |
unsigned char inactAxes, |
| 224 |
unsigned char inactAcDc, |
| 225 |
unsigned char inactThresh, |
| 226 |
unsigned char inactTime, |
| 227 |
unsigned char inactInt); |
| 228 |
|
| 229 |
|
| 230 |
void ADXL345_SetFreeFallDetection(unsigned char ffOnOff, |
| 231 |
unsigned char ffThresh, |
| 232 |
unsigned char ffTime, |
| 233 |
unsigned char ffInt); |
| 234 |
|
| 235 |
|
| 236 |
void ADXL345_SetOffset(unsigned char xOffset, |
| 237 |
unsigned char yOffset, |
| 238 |
unsigned char zOffset); |
| 239 |
|
| 240 |
|
| 241 |
void ADXL345_SetRangeResolution(unsigned char gRange, unsigned char fullRes); |
| 242 |
|
| 243 |
#endif |