]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/tests/peripherals/ADXL345/ADXL345.h
6 * Copyright (c) 2010 ARM Limited
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 * @section DESCRIPTION
28 * ADXL345, triple axis, digital interface, accelerometer.
32 * http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf
47 #define ADXL345_DEVID_REG 0x00
48 #define ADXL345_THRESH_TAP_REG 0x1D
49 #define ADXL345_OFSX_REG 0x1E
50 #define ADXL345_OFSY_REG 0x1F
51 #define ADXL345_OFSZ_REG 0x20
52 #define ADXL345_DUR_REG 0x21
53 #define ADXL345_LATENT_REG 0x22
54 #define ADXL345_WINDOW_REG 0x23
55 #define ADXL345_THRESH_ACT_REG 0x24
56 #define ADXL345_THRESH_INACT_REG 0x25
57 #define ADXL345_TIME_INACT_REG 0x26
58 #define ADXL345_ACT_INACT_CTL_REG 0x27
59 #define ADXL345_THRESH_FF_REG 0x28
60 #define ADXL345_TIME_FF_REG 0x29
61 #define ADXL345_TAP_AXES_REG 0x2A
62 #define ADXL345_ACT_TAP_STATUS_REG 0x2B
63 #define ADXL345_BW_RATE_REG 0x2C
64 #define ADXL345_POWER_CTL_REG 0x2D
65 #define ADXL345_INT_ENABLE_REG 0x2E
66 #define ADXL345_INT_MAP_REG 0x2F
67 #define ADXL345_INT_SOURCE_REG 0x30
68 #define ADXL345_DATA_FORMAT_REG 0x31
69 #define ADXL345_DATAX0_REG 0x32
70 #define ADXL345_DATAX1_REG 0x33
71 #define ADXL345_DATAY0_REG 0x34
72 #define ADXL345_DATAY1_REG 0x35
73 #define ADXL345_DATAZ0_REG 0x36
74 #define ADXL345_DATAZ1_REG 0x37
75 #define ADXL345_FIFO_CTL 0x38
76 #define ADXL345_FIFO_STATUS 0x39
79 #define ADXL345_3200HZ 0x0F
80 #define ADXL345_1600HZ 0x0E
81 #define ADXL345_800HZ 0x0D
82 #define ADXL345_400HZ 0x0C
83 #define ADXL345_200HZ 0x0B
84 #define ADXL345_100HZ 0x0A
85 #define ADXL345_50HZ 0x09
86 #define ADXL345_25HZ 0x08
87 #define ADXL345_12HZ5 0x07
88 #define ADXL345_6HZ25 0x06
90 #define ADXL345_SPI_READ 0x80
91 #define ADXL345_SPI_WRITE 0x00
92 #define ADXL345_MULTI_BYTE 0x60
94 #define ADXL345_X 0x00
95 #define ADXL345_Y 0x01
96 #define ADXL345_Z 0x02
99 * ADXL345 triple axis, digital interface, accelerometer.
108 * @param mosi mbed pin to use for MOSI line of SPI interface.
109 * @param miso mbed pin to use for MISO line of SPI interface.
110 * @param sck mbed pin to use for SCK line of SPI interface.
111 * @param cs mbed pin to use for not chip select line of SPI interface.
113 ADXL345(PinName mosi
, PinName miso
, PinName sck
, PinName cs
);
116 * Read the device ID register on the device.
118 * @return The device ID code [0xE5]
123 * Read the tap threshold on the device.
125 * @return The tap threshold as an 8-bit number with a scale factor of
128 int getTapThreshold(void);
131 * Set the tap threshold.
133 * @param The tap threshold as an 8-bit number with a scale factor of
136 void setTapThreshold(int threshold
);
139 * Get the current offset for a particular axis.
141 * @param axis 0x00 -> X-axis
144 * @return The current offset as an 8-bit 2's complement number with scale
147 int getOffset(int axis
);
150 * Set the offset for a particular axis.
152 * @param axis 0x00 -> X-axis
155 * @param offset The offset as an 8-bit 2's complement number with scale
158 void setOffset(int axis
, char offset
);
161 * Get the tap duration required to trigger an event.
163 * @return The max time that an event must be above the tap threshold to
164 * qualify as a tap event, in microseconds.
166 int getTapDuration(void);
169 * Set the tap duration required to trigger an event.
171 * @param duration_us The max time that an event must be above the tap
172 * threshold to qualify as a tap event, in microseconds.
173 * Time will be normalized by the scale factor which is
174 * 625us/LSB. A value of 0 disables the single/double
177 void setTapDuration(int duration_us
);
180 * Get the tap latency between the detection of a tap and the time window.
182 * @return The wait time from the detection of a tap event to the start of
183 * the time window during which a possible second tap event can be
184 * detected in milliseconds.
186 float getTapLatency(void);
189 * Set the tap latency between the detection of a tap and the time window.
191 * @param latency_ms The wait time from the detection of a tap event to the
192 * start of the time window during which a possible
193 * second tap event can be detected in milliseconds.
194 * A value of 0 disables the double tap function.
196 void setTapLatency(int latency_ms
);
199 * Get the time of window between tap latency and a double tap.
201 * @return The amount of time after the expiration of the latency time
202 * during which a second valid tap can begin, in milliseconds.
204 float getWindowTime(void);
207 * Set the time of the window between tap latency and a double tap.
209 * @param window_ms The amount of time after the expiration of the latency
210 * time during which a second valid tap can begin,
213 void setWindowTime(int window_ms
);
216 * Get the threshold value for detecting activity.
218 * @return The threshold value for detecting activity as an 8-bit number.
219 * Scale factor is 62.5mg/LSB.
221 int getActivityThreshold(void);
224 * Set the threshold value for detecting activity.
226 * @param threshold The threshold value for detecting activity as an 8-bit
227 * number. Scale factor is 62.5mg/LSB. A value of 0 may
228 * result in undesirable behavior if the activity
229 * interrupt is enabled.
231 void setActivityThreshold(int threshold
);
234 * Get the threshold value for detecting inactivity.
236 * @return The threshold value for detecting inactivity as an 8-bit number.
237 * Scale factor is 62.5mg/LSB.
239 int getInactivityThreshold(void);
242 * Set the threshold value for detecting inactivity.
244 * @param threshold The threshold value for detecting inactivity as an
245 * 8-bit number. Scale factor is 62.5mg/LSB.
247 void setInactivityThreshold(int threshold
);
250 * Get the time required for inactivity to be declared.
252 * @return The amount of time that acceleration must be less than the
253 * inactivity threshold for inactivity to be declared, in
256 int getTimeInactivity(void);
259 * Set the time required for inactivity to be declared.
261 * @param inactivity The amount of time that acceleration must be less than
262 * the inactivity threshold for inactivity to be
263 * declared, in seconds. A value of 0 results in an
264 * interrupt when the output data is less than the
265 * threshold inactivity.
267 void setTimeInactivity(int timeInactivity
);
270 * Get the activity/inactivity control settings.
273 * +-----------+--------------+--------------+--------------+
274 * | ACT ac/dc | ACT_X enable | ACT_Y enable | ACT_Z enable |
275 * +-----------+--------------+--------------+--------------+
278 * +-------------+----------------+----------------+----------------+
279 * | INACT ac/dc | INACT_X enable | INACT_Y enable | INACT_Z enable |
280 * +-------------+----------------+----------------+----------------+
282 * See datasheet for details.
284 * @return The contents of the ACT_INACT_CTL register.
286 int getActivityInactivityControl(void);
289 * Set the activity/inactivity control settings.
292 * +-----------+--------------+--------------+--------------+
293 * | ACT ac/dc | ACT_X enable | ACT_Y enable | ACT_Z enable |
294 * +-----------+--------------+--------------+--------------+
297 * +-------------+----------------+----------------+----------------+
298 * | INACT ac/dc | INACT_X enable | INACT_Y enable | INACT_Z enable |
299 * +-------------+----------------+----------------+----------------+
301 * See datasheet for details.
303 * @param settings The control byte to write to the ACT_INACT_CTL register.
305 void setActivityInactivityControl(int settings
);
308 * Get the threshold for free fall detection.
310 * @return The threshold value for free-fall detection, as an 8-bit number,
311 * with scale factor 62.5mg/LSB.
313 int getFreefallThreshold(void);
316 * Set the threshold for free fall detection.
318 * @return The threshold value for free-fall detection, as an 8-bit number,
319 * with scale factor 62.5mg/LSB. A value of 0 may result in
320 * undesirable behavior if the free-fall interrupt is enabled.
321 * Values between 300 mg and 600 mg (0x05 to 0x09) are recommended.
323 void setFreefallThreshold(int threshold
);
326 * Get the time required to generate a free fall interrupt.
328 * @return The minimum time that the value of all axes must be less than
329 * the freefall threshold to generate a free-fall interrupt, in
332 int getFreefallTime(void);
335 * Set the time required to generate a free fall interrupt.
337 * @return The minimum time that the value of all axes must be less than
338 * the freefall threshold to generate a free-fall interrupt, in
339 * milliseconds. A value of 0 may result in undesirable behavior
340 * if the free-fall interrupt is enabled. Values between 100 ms
341 * and 350 ms (0x14 to 0x46) are recommended.
343 void setFreefallTime(int freefallTime_ms
);
346 * Get the axis tap settings.
349 * +----------+--------------+--------------+--------------+
350 * | Suppress | TAP_X enable | TAP_Y enable | TAP_Z enable |
351 * +----------+--------------+--------------+--------------+
355 * See datasheet for more details.
357 * @return The contents of the TAP_AXES register.
359 int getTapAxisControl(void);
362 * Set the axis tap settings.
365 * +----------+--------------+--------------+--------------+
366 * | Suppress | TAP_X enable | TAP_Y enable | TAP_Z enable |
367 * +----------+--------------+--------------+--------------+
371 * See datasheet for more details.
373 * @param The control byte to write to the TAP_AXES register.
375 void setTapAxisControl(int settings
);
378 * Get the source of a tap.
380 * @return The contents of the ACT_TAP_STATUS register.
382 int getTapSource(void);
385 * Set the power mode.
387 * @param mode 0 -> Normal operation.
388 * 1 -> Reduced power operation.
390 void setPowerMode(char mode
);
395 * @param rate The rate code (see #defines or datasheet).
397 void setDataRate(int rate
);
400 * Get the power control settings.
402 * See datasheet for details.
404 * @return The contents of the POWER_CTL register.
406 int getPowerControl(void);
409 * Set the power control settings.
411 * See datasheet for details.
413 * @param The control byte to write to the POWER_CTL register.
415 void setPowerControl(int settings
);
418 * Get the interrupt enable settings.
420 * @return The contents of the INT_ENABLE register.
422 int getInterruptEnableControl(void);
425 * Set the interrupt enable settings.
427 * @param settings The control byte to write to the INT_ENABLE register.
429 void setInterruptEnableControl(int settings
);
432 * Get the interrupt mapping settings.
434 * @return The contents of the INT_MAP register.
436 int getInterruptMappingControl(void);
439 * Set the interrupt mapping settings.
441 * @param settings The control byte to write to the INT_MAP register.
443 void setInterruptMappingControl(int settings
);
446 * Get the interrupt source.
448 * @return The contents of the INT_SOURCE register.
450 int getInterruptSource(void);
453 * Get the data format settings.
455 * @return The contents of the DATA_FORMAT register.
457 int getDataFormatControl(void);
460 * Set the data format settings.
462 * @param settings The control byte to write to the DATA_FORMAT register.
464 void setDataFormatControl(int settings
);
467 * Get the output of all three axes.
469 * @param Pointer to a buffer to hold the accelerometer value for the
470 * x-axis, y-axis and z-axis [in that order].
472 void getOutput(int* readings
);
475 * Get the FIFO control settings.
477 * @return The contents of the FIFO_CTL register.
479 int getFifoControl(void);
482 * Set the FIFO control settings.
484 * @param The control byte to write to the FIFO_CTL register.
486 void setFifoControl(int settings
);
491 * @return The contents of the FIFO_STATUS register.
493 int getFifoStatus(void);
501 * Read one byte from a register on the device.
503 * @param address Address of the register to read.
505 * @return The contents of the register address.
507 int oneByteRead(int address
);
510 * Write one byte to a register on the device.
512 * @param address Address of the register to write to.
513 * @param data The data to write into the register.
515 void oneByteWrite(int address
, char data
);
518 * Read several consecutive bytes on the device.
520 * @param startAddress The address of the first register to read from.
521 * @param buffer Pointer to a buffer to store data read from the device.
522 * @param size The number of bytes to read.
524 void multiByteRead(int startAddress
, char* buffer
, int size
);
527 * Write several consecutive bytes on the device.
529 * @param startAddress The address of the first register to write to.
530 * @param buffer Pointer to a buffer which contains the data to write.
531 * @param size The number of bytes to write.
533 void multiByteWrite(int startAddress
, char* buffer
, int size
);
537 #endif /* ADXL345_H */