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  */
24 #ifndef ADXL345_H
25 #define ADXL345_H
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
31 #include "periph/i2c.h"
32 #include "periph/gpio.h"
37 enum {
38  ADXL345_ADDR_1D = 0x1D,
39  ADXL345_ADDR_53 = 0x53,
40 };
45 enum {
50 };
55 enum {
60 };
65 enum {
82 };
87 enum {
92 };
97 enum {
100 };
105 enum {
111 };
116 typedef struct {
117  int16_t x;
118  int16_t y;
119  int16_t z;
125 typedef struct {
126  uint8_t source;
127  uint8_t map;
128  uint8_t enable;
129  uint8_t thres_tap;
130  uint8_t thres_dur;
131  uint8_t thres_latent;
132  uint8_t thres_window;
133  uint8_t thres_act;
134  uint8_t thres_inact;
135  uint8_t time_inact;
136  uint8_t thres_ff;
137  uint8_t time_ff;
138  uint8_t act_inact;
139  uint8_t tap_axes;
145 typedef struct {
147  uint8_t addr;
148  gpio_t int1;
149  gpio_t int2;
150  uint8_t offset[3];
151  uint8_t range;
152  uint8_t rate;
153  uint8_t full_res;
159 typedef struct {
162  int16_t scale_factor;
163 } adxl345_t;
175 int adxl345_init(adxl345_t *dev, const adxl345_params_t* params);
188 void adxl345_read(const adxl345_t *dev, adxl345_data_t *data);
195 void adxl345_set_interrupt(const adxl345_t *dev);
202 void adxl345_set_measure(const adxl345_t *dev);
209 void adxl345_set_standby(const adxl345_t *dev);
216 void adxl345_set_sleep(const adxl345_t *dev);
223 void adxl345_set_autosleep(const adxl345_t *dev);
231 void adxl345_set_bandwidth_rate(const adxl345_t *dev, uint8_t bw_rate);
241 void adxl345_set_fifo_mode(const adxl345_t *dev, uint8_t mode,
242  uint8_t output, uint8_t value);
244 #ifdef __cplusplus
245 }
246 #endif
248 #endif /* ADXL345_H */
+/- 8 g Full Scale Range
Definition: adxl345.h:58
no ADXL345 device found on the bus
Definition: adxl345.h:109
Interrupt configuration struct for the ADXL345 sensor.
Definition: adxl345.h:125
everything was fine
Definition: adxl345.h:106
new data ready to be read
Definition: adxl345.h:107
gpio_t int1
accelerometer int1 pin
Definition: adxl345.h:148
3200 Hz Output Data Rate
Definition: adxl345.h:81
FIFO stream mode.
Definition: adxl345.h:90
uint8_t thres_window
Tap window.
Definition: adxl345.h:132
800 Hz Output Data Rate
Definition: adxl345.h:79
0.78 Hz Output Data Rate
Definition: adxl345.h:69
Low-level GPIO peripheral driver interface definitions.
400 Hz Output Data Rate
Definition: adxl345.h:78
0.39 Hz Output Data Rate
Definition: adxl345.h:68
int16_t x
X-Axis measurement result.
Definition: adxl345.h:117
void adxl345_set_autosleep(const adxl345_t *dev)
Set autosleep mode.
FIFO mode.
Definition: adxl345.h:89
void adxl345_set_interrupt(const adxl345_t *dev)
set ADXL345's interrupts configuration
50 Hz Output Data Rate
Definition: adxl345.h:75
uint8_t enable
Interrupt enable control.
Definition: adxl345.h:128
Configuration struct for the ADXL345 sensor.
Definition: adxl345.h:145
FIFO bypass mode.
Definition: adxl345.h:88
I2C device address if Alt addr pin is low.
Definition: adxl345.h:39
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:157
void adxl345_set_standby(const adxl345_t *dev)
Set standby mode.
adxl345_interrupt_t interrupt
Interrupts configuration.
Definition: adxl345.h:161
Autosleep mode.
Definition: adxl345.h:49
ADXL345 result vector struct.
Definition: adxl345.h:116
i2c_t i2c
I2C device which is used.
Definition: adxl345.h:146
+/- 2 g Full Scale Range
Definition: adxl345.h:56
void adxl345_set_bandwidth_rate(const adxl345_t *dev, uint8_t bw_rate)
Set bandwidth rate.
uint8_t map
Interrupt mapping control.
Definition: adxl345.h:127
uint8_t full_res
Resolution bit.
Definition: adxl345.h:153
void adxl345_read(const adxl345_t *dev, adxl345_data_t *data)
Read accelerometer's data.
Sleep mode.
Definition: adxl345.h:48
uint8_t thres_tap
Tap threshold.
Definition: adxl345.h:129
uint8_t time_ff
Time threshold.
Definition: adxl345.h:137
+/- 4 g Full Scale Range
Definition: adxl345.h:57
uint8_t addr
I2C address.
Definition: adxl345.h:147
Output interrupt on INT2 pin.
Definition: adxl345.h:99
25 Hz Output Data Rate
Definition: adxl345.h:74
uint8_t thres_ff
Free-fall threshold.
Definition: adxl345.h:136
int16_t scale_factor
Scale factor for converting value to mg.
Definition: adxl345.h:162
FIFO trigger mode.
Definition: adxl345.h:91
uint8_t time_inact
Inactivity time.
Definition: adxl345.h:135
200 Hz Output Data Rate
Definition: adxl345.h:77
3.13 Hz Output Data Rate
Definition: adxl345.h:71
uint8_t range
Sensitivity configuration.
Definition: adxl345.h:151
int16_t z
Z-Axis measurement result.
Definition: adxl345.h:119
int16_t y
Y-Axis measurement result.
Definition: adxl345.h:118
+/- 16 g Full Scale Range
Definition: adxl345.h:59
Device descriptor for the ADXL345 sensor.
Definition: adxl345.h:159
Standby mode.
Definition: adxl345.h:47
uint8_t thres_dur
Tap duration.
Definition: adxl345.h:130
uint8_t tap_axes
Axis control for single tap/double tap.
Definition: adxl345.h:139
void adxl345_set_sleep(const adxl345_t *dev)
Set sleep mode.
uint8_t thres_latent
Tap latency.
Definition: adxl345.h:131
I2C device address if Alt addr pin is high.
Definition: adxl345.h:38
gpio_t int2
accelerometer int2 pin
Definition: adxl345.h:149
uint8_t rate
Configured sample rate for accel.
Definition: adxl345.h:152
Measure mode.
Definition: adxl345.h:46
adxl345_params_t params
Device configuration.
Definition: adxl345.h:160
6.25 Hz Output Data Rate
Definition: adxl345.h:72
uint8_t act_inact
Enable ctrl for activity/inactivity detection.
Definition: adxl345.h:138
no data available
Definition: adxl345.h:110
void adxl345_set_measure(const adxl345_t *dev)
set ADXL345's measure mode
Output interrupt on INT1 pin.
Definition: adxl345.h:98
0.2 Hz Output Data Rate
Definition: adxl345.h:67
0.1 Hz Output Data Rate
Definition: adxl345.h:66
100 Hz Output Data Rate
Definition: adxl345.h:76
uint8_t source
Source of interrupts.
Definition: adxl345.h:126
12.5 Hz Output Data Rate
Definition: adxl345.h:73
int adxl345_init(adxl345_t *dev, const adxl345_params_t *params)
Initialize the ADXL345 accelerometer driver.
1600 Hz Output Data Rate
Definition: adxl345.h:80
1.56 Hz Output Data Rate
Definition: adxl345.h:70
uint8_t thres_inact
Inactivity threshold.
Definition: adxl345.h:134
void adxl345_set_fifo_mode(const adxl345_t *dev, uint8_t mode, uint8_t output, uint8_t value)
Set fifo mode with its configuration.
uint8_t thres_act
Activity threshold.
Definition: adxl345.h:133
I2C communication failed.
Definition: adxl345.h:108
Low-level I2C peripheral driver interface definition.