Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Mesotic SAS
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
21 #ifndef ADXL345_H
22 #define ADXL345_H
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
28 #include "periph/i2c.h"
29 #include "periph/gpio.h"
34 enum {
35  ADXL345_ADDR_1D = 0x1D,
36  ADXL345_ADDR_53 = 0x53,
37 };
42 enum {
47 };
52 enum {
57 };
62 enum {
79 };
84 enum {
85  BYPASS = 0,
86  FIFO = 1,
87  STREAM = 2,
88  TRIGGER = 3
89 };
93 enum {
94  INT1,
96 };
101 enum {
107 };
112 typedef struct {
113  int16_t x;
114  int16_t y;
115  int16_t z;
121 typedef struct {
122  uint8_t source;
123  uint8_t map;
124  uint8_t enable;
125  uint8_t thres_tap;
126  uint8_t thres_dur;
127  uint8_t thres_latent;
128  uint8_t thres_window;
129  uint8_t thres_act;
130  uint8_t thres_inact;
131  uint8_t time_inact;
132  uint8_t thres_ff;
133  uint8_t time_ff;
134  uint8_t act_inact;
135  uint8_t tap_axes;
141 typedef struct {
142  gpio_t int1;
143  gpio_t int2;
144  uint8_t offset[3];
145  uint8_t range;
146  uint8_t rate;
147  uint8_t full_res;
153 typedef struct {
155  uint8_t addr;
158  float scale_factor;
159 } adxl345_t;
171 int adxl345_init(adxl345_t *dev, adxl345_params_t* params);
184 void adxl345_read(adxl345_t *dev, adxl345_data_t *data);
198 void adxl345_set_measure(adxl345_t *dev);
205 void adxl345_set_standby(adxl345_t *dev);
212 void adxl345_set_sleep(adxl345_t *dev);
227 void adxl345_set_bandwidth_rate(adxl345_t *dev, uint8_t bw_rate);
237 void adxl345_set_fifo_mode(adxl345_t *dev, uint8_t mode,
238  uint8_t output, uint8_t value);
240 #ifdef __cplusplus
241 }
242 #endif
244 #endif /* ADXL345_H */
i2c_t i2c
I2C device which is used.
Definition: adxl345.h:154
Interrupt configuration struct for the ADXL345 sensor.
Definition: adxl345.h:121
+/- 8 g Full Scale Rang
Definition: adxl345.h:55
gpio_t int1
accelerometer int1 pin
Definition: adxl345.h:142
void adxl345_set_fifo_mode(adxl345_t *dev, uint8_t mode, uint8_t output, uint8_t value)
Set fifo mode with its configuration.
void adxl345_set_sleep(adxl345_t *dev)
Set sleep mode.
I2C device address if Alt addr pin is high.
Definition: adxl345.h:35
+/- 4 g Full Scale Rang
Definition: adxl345.h:54
uint8_t thres_window
Tap window.
Definition: adxl345.h:128
uint8_t addr
I2C address.
Definition: adxl345.h:155
Low-level GPIO peripheral driver interface definitions.
no ADXL345 device found on the bus
Definition: adxl345.h:105
void adxl345_set_interrupt(adxl345_t *dev)
set ADXL345's interrupts configuration
int16_t x
X-Axis measurement result.
Definition: adxl345.h:113
uint8_t enable
Interrupt enable control.
Definition: adxl345.h:124
Configuration struct for the ADXL345 sensor.
Definition: adxl345.h:141
Output interrupt on INT2 pin.
Definition: adxl345.h:95
0.2 Hz Output Data Rate
Definition: adxl345.h:64
25 Hz Output Data Rate
Definition: adxl345.h:71
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:104
800 Hz Output Data Rate
Definition: adxl345.h:76
adxl345_interrupt_t interrupt
Interrupts configuration.
Definition: adxl345.h:157
ADXL345 result vector struct.
Definition: adxl345.h:112
void adxl345_set_measure(adxl345_t *dev)
set ADXL345's measure mode
3.13 Hz Output Data Rate
Definition: adxl345.h:68
FIFO trigger mode.
Definition: adxl345.h:88
void adxl345_set_autosleep(adxl345_t *dev)
Set autosleep mode.
uint8_t map
Interrupt mapping control.
Definition: adxl345.h:123
uint8_t full_res
Resolution bit.
Definition: adxl345.h:147
FIFO bypass mode.
Definition: adxl345.h:85
0.39 Hz Output Data Rate
Definition: adxl345.h:65
1.56 Hz Output Data Rate
Definition: adxl345.h:67
400 Hz Output Data Rate
Definition: adxl345.h:75
FIFO stream mode.
Definition: adxl345.h:87
void adxl345_set_bandwidth_rate(adxl345_t *dev, uint8_t bw_rate)
Set bandwidth rate.
uint8_t thres_tap
Tap threshold.
Definition: adxl345.h:125
+/- 2 g Full Scale Rang
Definition: adxl345.h:53
uint8_t time_ff
Time threshold.
Definition: adxl345.h:133
+/- 16 g Full Scale Rang
Definition: adxl345.h:56
uint8_t thres_ff
Free-fall threshold.
Definition: adxl345.h:132
3200 Hz Output Data Rate
Definition: adxl345.h:78
uint8_t time_inact
Inactivity time.
Definition: adxl345.h:131
200 Hz Output Data Rate
Definition: adxl345.h:74
uint8_t range
Sensitivity configuration.
Definition: adxl345.h:145
I2C device address if Alt addr pin is low.
Definition: adxl345.h:36
int16_t z
Z-Axis measurement result.
Definition: adxl345.h:115
int16_t y
Y-Axis measurement result.
Definition: adxl345.h:114
Device descriptor for the ADXL345 sensor.
Definition: adxl345.h:153
0.1 Hz Output Data Rate
Definition: adxl345.h:63
no data available
Definition: adxl345.h:106
100 Hz Output Data Rate
Definition: adxl345.h:73
12.5 Hz Output Data Rate
Definition: adxl345.h:70
uint8_t thres_dur
Tap duration.
Definition: adxl345.h:126
new data ready to be read
Definition: adxl345.h:103
everything was fine
Definition: adxl345.h:102
uint8_t tap_axes
Axis control for single tap/double tap.
Definition: adxl345.h:135
uint8_t thres_latent
Tap latency.
Definition: adxl345.h:127
1600 Hz Output Data Rate
Definition: adxl345.h:77
gpio_t int2
accelerometer int2 pin
Definition: adxl345.h:143
uint8_t rate
Configured sample rate for accel.
Definition: adxl345.h:146
uint8_t act_inact
Enable ctrl for activity/inactivity detection.
Definition: adxl345.h:134
int adxl345_init(adxl345_t *dev, adxl345_params_t *params)
Initialize the ADXL345 accelerometer driver.
I2C communication failed.
Definition: adxl345.h:104
50 Hz Output Data Rate
Definition: adxl345.h:72
6.25 Hz Output Data Rate
Definition: adxl345.h:69
uint8_t source
Source of interrupts.
Definition: adxl345.h:122
void adxl345_read(adxl345_t *dev, adxl345_data_t *data)
Read accelerometer's data.
adxl345_params_t * params
Device configuration.
Definition: adxl345.h:156
0.78 Hz Output Data Rate
Definition: adxl345.h:66
void adxl345_set_standby(adxl345_t *dev)
Set standby mode.
uint8_t thres_inact
Inactivity threshold.
Definition: adxl345.h:130
Output interrupt on INT1 pin.
Definition: adxl345.h:94
float scale_factor
Scale factor for converting value to mg.
Definition: adxl345.h:158
FIFO mode.
Definition: adxl345.h:86
uint8_t thres_act
Activity threshold.
Definition: adxl345.h:129
Low-level I2C peripheral driver interface definition.