no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
adxl345.h
Go to the documentation of this file.
1/***************************************************************************/
33#ifndef __ADXL345_H__
34#define __ADXL345_H__
35
36#include <stdint.h>
37#include "no_os_i2c.h"
38#include "no_os_spi.h"
39
40/* Options for communicating with the device. */
41#define ADXL345_SPI_COMM 0
42#define ADXL345_I2C_COMM 1
43
44/* I2C address of the device */
45#define ADXL345_ADDRESS 0x1D
46
47/* SPI commands */
48#define ADXL345_SPI_READ (1 << 7)
49#define ADXL345_SPI_WRITE (0 << 7)
50#define ADXL345_SPI_MB (1 << 6)
51
52/* ADXL345 Register Map */
53#define ADXL345_DEVID 0x00 // R Device ID.
54#define ADXL345_THRESH_TAP 0x1D // R/W Tap threshold.
55#define ADXL345_OFSX 0x1E // R/W X-axis offset.
56#define ADXL345_OFSY 0x1F // R/W Y-axis offset.
57#define ADXL345_OFSZ 0x20 // R/W Z-axis offset.
58#define ADXL345_DUR 0x21 // R/W Tap duration.
59#define ADXL345_LATENT 0x22 // R/W Tap latency.
60#define ADXL345_WINDOW 0x23 // R/W Tap window.
61#define ADXL345_THRESH_ACT 0x24 // R/W Activity threshold.
62#define ADXL345_THRESH_INACT 0x25 // R/W Inactivity threshold.
63#define ADXL345_TIME_INACT 0x26 // R/W Inactivity time.
64#define ADXL345_ACT_INACT_CTL 0x27 // R/W Axis enable control for activity
65// and inactivity detection.
66#define ADXL345_THRESH_FF 0x28 // R/W Free-fall threshold.
67#define ADXL345_TIME_FF 0x29 // R/W Free-fall time.
68#define ADXL345_TAP_AXES 0x2A // R/W Axis control for tap/double tap.
69#define ADXL345_ACT_TAP_STATUS 0x2B // R Source of tap/double tap.
70#define ADXL345_BW_RATE 0x2C // R/W Data rate and power mode control.
71#define ADXL345_POWER_CTL 0x2D // R/W Power saving features control.
72#define ADXL345_INT_ENABLE 0x2E // R/W Interrupt enable control.
73#define ADXL345_INT_MAP 0x2F // R/W Interrupt mapping control.
74#define ADXL345_INT_SOURCE 0x30 // R Source of interrupts.
75#define ADXL345_DATA_FORMAT 0x31 // R/W Data format control.
76#define ADXL345_DATAX0 0x32 // R X-Axis Data 0.
77#define ADXL345_DATAX1 0x33 // R X-Axis Data 1.
78#define ADXL345_DATAY0 0x34 // R Y-Axis Data 0.
79#define ADXL345_DATAY1 0x35 // R Y-Axis Data 1.
80#define ADXL345_DATAZ0 0x36 // R Z-Axis Data 0.
81#define ADXL345_DATAZ1 0x37 // R Z-Axis Data 1.
82#define ADXL345_FIFO_CTL 0x38 // R/W FIFO control.
83#define ADXL345_FIFO_STATUS 0x39 // R FIFO status.
84#define ADXL345_TAP_SIGN 0x3A // R Sign and source for single tap/double tap.
85#define ADXL345_ORIENT_CONF 0x3B // R/W Orientation configuration.
86#define ADXL345_ORIENT 0x3C // R Orientation status.
87
88/* ADXL345_ACT_INACT_CTL definition */
89#define ADXL345_ACT_ACDC (1 << 7)
90#define ADXL345_ACT_X_EN (1 << 6)
91#define ADXL345_ACT_Y_EN (1 << 5)
92#define ADXL345_ACT_Z_EN (1 << 4)
93#define ADXL345_INACT_ACDC (1 << 3)
94#define ADXL345_INACT_X_EN (1 << 2)
95#define ADXL345_INACT_Y_EN (1 << 1)
96#define ADXL345_INACT_Z_EN (1 << 0)
97
98/* ADXL345_TAP_AXES definition */
99#define ADXL345_SUPPRESS (1 << 3)
100#define ADXL345_TAP_X_EN (1 << 2)
101#define ADXL345_TAP_Y_EN (1 << 1)
102#define ADXL345_TAP_Z_EN (1 << 0)
103
104/* ADXL345_ACT_TAP_STATUS definition */
105#define ADXL345_ACT_X_SRC (1 << 6)
106#define ADXL345_ACT_Y_SRC (1 << 5)
107#define ADXL345_ACT_Z_SRC (1 << 4)
108#define ADXL345_ASLEEP (1 << 3)
109#define ADXL345_TAP_X_SRC (1 << 2)
110#define ADXL345_TAP_Y_SRC (1 << 1)
111#define ADXL345_TAP_Z_SRC (1 << 0)
112
113/* ADXL345_BW_RATE definition */
114#define ADXL345_LOW_POWER (1 << 4)
115#define ADXL345_RATE(x) ((x) & 0xF)
116
117/* ADXL345_POWER_CTL definition */
118#define ADXL345_PCTL_LINK (1 << 5)
119#define ADXL345_PCTL_AUTO_SLEEP (1 << 4)
120#define ADXL345_PCTL_MEASURE (1 << 3)
121#define ADXL345_PCTL_SLEEP (1 << 2)
122#define ADXL345_PCTL_WAKEUP(x) ((x) & 0x3)
123
124/* ADXL345_INT_ENABLE / ADXL345_INT_MAP / ADXL345_INT_SOURCE definition */
125#define ADXL345_DATA_READY (1 << 7)
126#define ADXL345_SINGLE_TAP (1 << 6)
127#define ADXL345_DOUBLE_TAP (1 << 5)
128#define ADXL345_ACTIVITY (1 << 4)
129#define ADXL345_INACTIVITY (1 << 3)
130#define ADXL345_FREE_FALL (1 << 2)
131#define ADXL345_WATERMARK (1 << 1)
132#define ADXL345_OVERRUN (1 << 0)
133#define ADXL345_ORIENTATION (1 << 0)
134
135/* ADXL345_DATA_FORMAT definition */
136#define ADXL345_SELF_TEST (1 << 7)
137#define ADXL345_SPI (1 << 6)
138#define ADXL345_INT_INVERT (1 << 5)
139#define ADXL345_FULL_RES (1 << 3)
140#define ADXL345_JUSTIFY (1 << 2)
141#define ADXL345_RANGE(x) ((x) & 0x3)
142
143/* ADXL345_RANGE(x) options */
144#define ADXL345_RANGE_PM_2G 0
145#define ADXL345_RANGE_PM_4G 1
146#define ADXL345_RANGE_PM_8G 2
147#define ADXL345_RANGE_PM_16G 3
148
149/* ADXL345_FIFO_CTL definition */
150#define ADXL345_FIFO_MODE(x) (((x) & 0x3) << 6)
151#define ADXL345_TRIGGER (1 << 5)
152#define ADXL345_SAMPLES(x) ((x) & 0x1F)
153
154/* ADXL345_FIFO_MODE(x) options */
155#define ADXL345_FIFO_BYPASS 0
156#define ADXL345_FIFO_FIFO 1
157#define ADXL345_FIFO_STREAM 2
158#define ADXL345_FIFO_TRIGGER 3
159
160/* ADXL345_FIFO_STATUS definition */
161#define ADXL345_FIFO_TRIG (1 << 7)
162#define ADXL345_ENTRIES(x) ((x) & 0x3F)
163
164/* ADXL345_ORIENT_CONF definition */
165#define ADXL345_INT_ORIENT(x) (((x) & 0x1) << 7)
166#define ADXL345_DEAD_ZONE(x) (((x) & 0x7) << 4)
167#define ADXL345_INT_3D(x) (((x) & 0x1) << 3)
168#define ADXL345_DIVISOR(x) ((x) & 7)
169
170/* ADXL345 ID */
171#define ADXL345_ID 0xE5
172/* ADXL346 ID */
173#define ADXL346_ID 0xE6
174
175/* ADXL345 Full Resolution Scale Factor */
176#define ADXL345_SCALE_FACTOR 0.0039
177
186
201
216
235
254
256uint8_t adxl345_get_register_value(struct adxl345_dev *dev,
257 uint8_t register_address);
258
261 uint8_t register_address,
262 uint8_t register_value);
263
265int32_t adxl345_init(struct adxl345_dev **device,
267
269int32_t adxl345_remove(struct adxl345_dev *dev);
270
272void adxl345_set_power_mode(struct adxl345_dev *dev,
273 uint8_t pwr_mode);
274
276void adxl345_get_xyz(struct adxl345_dev *dev,
277 int16_t* x,
278 int16_t* y,
279 int16_t* z);
280
282void adxl345_get_g_xyz(struct adxl345_dev *dev,
283 float* x,
284 float* y,
285 float* z);
286
289 uint8_t tap_type,
290 uint8_t tap_axes,
291 uint8_t tap_dur,
292 uint8_t tap_latent,
293 uint8_t tap_window,
294 uint8_t tap_thresh,
295 uint8_t tap_int);
296
299 uint8_t act_on_off,
300 uint8_t act_axes,
301 uint8_t act_ac_dc,
302 uint8_t act_thresh,
303 uint8_t act_int);
304
307 uint8_t inact_on_off,
308 uint8_t inact_axes,
309 uint8_t inact_ac_dc,
310 uint8_t inact_thresh,
311 uint8_t inact_time,
312 uint8_t inact_int);
313
316 uint8_t ff_on_off,
317 uint8_t ff_thresh,
318 uint8_t ff_time,
319 uint8_t ff_int);
320
323 uint8_t orient_int,
324 uint8_t orient_on_off,
325 uint8_t int_3d,
326 enum adxl345_dead_zone_angle dead_zone,
327 enum adxl345_divisor_bandwidth divisor);
328
330void adxl345_set_offset(struct adxl345_dev *dev,
331 uint8_t x_offset,
332 uint8_t y_offset,
333 uint8_t z_offset);
334
337 uint8_t g_range,
338 uint8_t full_res);
339
340#endif /* __ADXL345_H__ */
struct ad7616_init_param init_param
Definition ad7616_sdz.c:107
void adxl345_set_inactivity_detection(struct adxl345_dev *dev, uint8_t inact_on_off, uint8_t inact_axes, uint8_t inact_ac_dc, uint8_t inact_thresh, uint8_t inact_time, uint8_t inact_int)
Enables/disables the inactivity detection.
Definition adxl345.c:436
int32_t adxl345_remove(struct adxl345_dev *dev)
Free the resources allocated by adxl345_init().
Definition adxl345.c:157
void adxl345_set_register_value(struct adxl345_dev *dev, uint8_t register_address, uint8_t register_value)
Writes data into a register.
Definition adxl345.c:85
void adxl345_set_orientation_detection(struct adxl345_dev *dev, uint8_t orient_int, uint8_t orient_on_off, uint8_t int_3d, enum adxl345_dead_zone_angle dead_zone, enum adxl345_divisor_bandwidth divisor)
Enables/disables the orientation detection (only for adxl346).
Definition adxl345.c:551
adxl345_divisor_bandwidth
ADXL346 Divisor bandwidth encoding.
Definition adxl345.h:206
@ ODR_DIV_9
Definition adxl345.h:207
@ ODR_DIV_100
Definition adxl345.h:210
@ ODR_DIV_400
Definition adxl345.h:212
@ ODR_DIV_50
Definition adxl345.h:209
@ ODR_DIV_200
Definition adxl345.h:211
@ ODR_DIV_1600
Definition adxl345.h:214
@ ODR_DIV_22
Definition adxl345.h:208
@ ODR_DIV_800
Definition adxl345.h:213
int32_t adxl345_init(struct adxl345_dev **device, struct adxl345_init_param init_param)
Initializes the communication peripheral and checks if the ADXL345 part is present.
Definition adxl345.c:121
void adxl345_set_range_resolution(struct adxl345_dev *dev, uint8_t g_range, uint8_t full_res)
Selects the measurement range.
Definition adxl345.c:627
void adxl345_get_g_xyz(struct adxl345_dev *dev, float *x, float *y, float *z)
Reads the raw output data of each axis and converts it to g.
Definition adxl345.c:249
adxl345_dead_zone_angle
ADXL346 Dead zone angle encoding.
Definition adxl345.h:191
@ DEGREES_30_8
Definition adxl345.h:197
@ DEGREES_36_1
Definition adxl345.h:198
@ DEGREES_41_4
Definition adxl345.h:199
@ DEGREES_15_2
Definition adxl345.h:194
@ DEGREES_5_1
Definition adxl345.h:192
@ DEGREES_25_5
Definition adxl345.h:196
@ DEGREES_10_2
Definition adxl345.h:193
@ DEGREES_20_4
Definition adxl345.h:195
adxl345_type
ADXL345 Supported devices.
Definition adxl345.h:182
@ ID_ADXL346
Definition adxl345.h:184
@ ID_ADXL345
Definition adxl345.h:183
void adxl345_set_tap_detection(struct adxl345_dev *dev, uint8_t tap_type, uint8_t tap_axes, uint8_t tap_dur, uint8_t tap_latent, uint8_t tap_window, uint8_t tap_thresh, uint8_t tap_int)
Enables/disables the tap detection.
Definition adxl345.c:293
uint8_t adxl345_get_register_value(struct adxl345_dev *dev, uint8_t register_address)
Reads the value of a register.
Definition adxl345.c:51
void adxl345_set_power_mode(struct adxl345_dev *dev, uint8_t pwr_mode)
Places the device into standby/measure mode.
Definition adxl345.c:179
void adxl345_set_offset(struct adxl345_dev *dev, uint8_t x_offset, uint8_t y_offset, uint8_t z_offset)
Sets an offset value for each axis (Offset Calibration).
Definition adxl345.c:598
void adxl345_set_free_fall_detection(struct adxl345_dev *dev, uint8_t ff_on_off, uint8_t ff_thresh, uint8_t ff_time, uint8_t ff_int)
Enables/disables the free-fall detection.
Definition adxl345.c:499
void adxl345_set_activity_detection(struct adxl345_dev *dev, uint8_t act_on_off, uint8_t act_axes, uint8_t act_ac_dc, uint8_t act_thresh, uint8_t act_int)
Enables/disables the activity detection.
Definition adxl345.c:370
void adxl345_get_xyz(struct adxl345_dev *dev, int16_t *x, int16_t *y, int16_t *z)
Reads the raw output data of each axis.
Definition adxl345.c:202
Header file of I2C Interface.
Header file of SPI Interface.
ADXL345 Device structure.
Definition adxl345.h:221
uint8_t communication_type
Definition adxl345.h:229
struct no_os_spi_desc * spi_desc
Definition adxl345.h:225
uint8_t selected_range
Definition adxl345.h:231
struct no_os_i2c_desc * i2c_desc
Definition adxl345.h:223
uint8_t full_resolution_set
Definition adxl345.h:233
enum adxl345_type dev_type
Definition adxl345.h:227
Structure holding the parameters for ADXL345 device initialization.
Definition adxl345.h:240
struct no_os_spi_init_param spi_init
Definition adxl345.h:244
uint8_t full_resolution_set
Definition adxl345.h:252
uint8_t selected_range
Definition adxl345.h:250
struct no_os_i2c_init_param i2c_init
Definition adxl345.h:242
enum adxl345_type dev_type
Definition adxl345.h:246
uint8_t communication_type
Definition adxl345.h:248
Definition ad9361_util.h:63
Structure holding I2C address descriptor.
Definition no_os_i2c.h:89
Structure holding the parameters for I2C initialization.
Definition no_os_i2c.h:52
Structure holding SPI descriptor.
Definition no_os_spi.h:180
Structure holding the parameters for SPI initialization.
Definition no_os_spi.h:128