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 {
89 };
94 enum {
97 };
102 enum {
108 };
113 typedef struct {
114  int16_t x;
115  int16_t y;
116  int16_t z;
122 typedef struct {
123  uint8_t source;
124  uint8_t map;
125  uint8_t enable;
126  uint8_t thres_tap;
127  uint8_t thres_dur;
128  uint8_t thres_latent;
129  uint8_t thres_window;
130  uint8_t thres_act;
131  uint8_t thres_inact;
132  uint8_t time_inact;
133  uint8_t thres_ff;
134  uint8_t time_ff;
135  uint8_t act_inact;
136  uint8_t tap_axes;
142 typedef struct {
143  gpio_t int1;
144  gpio_t int2;
145  uint8_t offset[3];
146  uint8_t range;
147  uint8_t rate;
148  uint8_t full_res;
154 typedef struct {
156  uint8_t addr;
159  float scale_factor;
160 } adxl345_t;
172 int adxl345_init(adxl345_t *dev, const adxl345_params_t* params);
185 void adxl345_read(const adxl345_t *dev, adxl345_data_t *data);
192 void adxl345_set_interrupt(const adxl345_t *dev);
199 void adxl345_set_measure(const adxl345_t *dev);
206 void adxl345_set_standby(const adxl345_t *dev);
213 void adxl345_set_sleep(const adxl345_t *dev);
220 void adxl345_set_autosleep(const adxl345_t *dev);
228 void adxl345_set_bandwidth_rate(const adxl345_t *dev, uint8_t bw_rate);
238 void adxl345_set_fifo_mode(const adxl345_t *dev, uint8_t mode,
239  uint8_t output, uint8_t value);
241 #ifdef __cplusplus
242 }
243 #endif
245 #endif /* ADXL345_H */
i2c_t i2c
I2C device which is used.
Definition: adxl345.h:155
I2C device address if Alt addr pin is low.
Definition: adxl345.h:36
Interrupt configuration struct for the ADXL345 sensor.
Definition: adxl345.h:122
3.13 Hz Output Data Rate
Definition: adxl345.h:68
gpio_t int1
accelerometer int1 pin
Definition: adxl345.h:143
uint8_t thres_window
Tap window.
Definition: adxl345.h:129
new data ready to be read
Definition: adxl345.h:104
FIFO trigger mode.
Definition: adxl345.h:88
800 Hz Output Data Rate
Definition: adxl345.h:76
uint8_t addr
I2C address.
Definition: adxl345.h:156
+/- 16 g Full Scale Rang
Definition: adxl345.h:56
FIFO stream mode.
Definition: adxl345.h:87
Low-level GPIO peripheral driver interface definitions.
int16_t x
X-Axis measurement result.
Definition: adxl345.h:114
void adxl345_set_autosleep(const adxl345_t *dev)
Set autosleep mode.
void adxl345_set_interrupt(const adxl345_t *dev)
set ADXL345's interrupts configuration
FIFO mode.
Definition: adxl345.h:86
uint8_t enable
Interrupt enable control.
Definition: adxl345.h:125
Output interrupt on INT2 pin.
Definition: adxl345.h:96
Configuration struct for the ADXL345 sensor.
Definition: adxl345.h:142
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:158
FIFO bypass mode.
Definition: adxl345.h:85
0.2 Hz Output Data Rate
Definition: adxl345.h:64
ADXL345 result vector struct.
Definition: adxl345.h:113
+/- 2 g Full Scale Rang
Definition: adxl345.h:53
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:124
uint8_t full_res
Resolution bit.
Definition: adxl345.h:148
void adxl345_read(const adxl345_t *dev, adxl345_data_t *data)
Read accelerometer's data.
6.25 Hz Output Data Rate
Definition: adxl345.h:69
0.1 Hz Output Data Rate
Definition: adxl345.h:63
12.5 Hz Output Data Rate
Definition: adxl345.h:70
uint8_t thres_tap
Tap threshold.
Definition: adxl345.h:126
400 Hz Output Data Rate
Definition: adxl345.h:75
+/- 4 g Full Scale Rang
Definition: adxl345.h:54
uint8_t time_ff
Time threshold.
Definition: adxl345.h:134
1600 Hz Output Data Rate
Definition: adxl345.h:77
0.78 Hz Output Data Rate
Definition: adxl345.h:66
no data available
Definition: adxl345.h:107
uint8_t thres_ff
Free-fall threshold.
Definition: adxl345.h:133
uint8_t time_inact
Inactivity time.
Definition: adxl345.h:132
3200 Hz Output Data Rate
Definition: adxl345.h:78
1.56 Hz Output Data Rate
Definition: adxl345.h:67
uint8_t range
Sensitivity configuration.
Definition: adxl345.h:146
50 Hz Output Data Rate
Definition: adxl345.h:72
int16_t z
Z-Axis measurement result.
Definition: adxl345.h:116
int16_t y
Y-Axis measurement result.
Definition: adxl345.h:115
Device descriptor for the ADXL345 sensor.
Definition: adxl345.h:154
25 Hz Output Data Rate
Definition: adxl345.h:71
uint8_t thres_dur
Tap duration.
Definition: adxl345.h:127
uint8_t tap_axes
Axis control for single tap/double tap.
Definition: adxl345.h:136
0.39 Hz Output Data Rate
Definition: adxl345.h:65
void adxl345_set_sleep(const adxl345_t *dev)
Set sleep mode.
uint8_t thres_latent
Tap latency.
Definition: adxl345.h:128
gpio_t int2
accelerometer int2 pin
Definition: adxl345.h:144
uint8_t rate
Configured sample rate for accel.
Definition: adxl345.h:147
Output interrupt on INT1 pin.
Definition: adxl345.h:95
uint8_t act_inact
Enable ctrl for activity/inactivity detection.
Definition: adxl345.h:135
void adxl345_set_measure(const adxl345_t *dev)
set ADXL345's measure mode
I2C device address if Alt addr pin is high.
Definition: adxl345.h:35
I2C communication failed.
Definition: adxl345.h:105
uint8_t source
Source of interrupts.
Definition: adxl345.h:123
100 Hz Output Data Rate
Definition: adxl345.h:73
no ADXL345 device found on the bus
Definition: adxl345.h:106
int adxl345_init(adxl345_t *dev, const adxl345_params_t *params)
Initialize the ADXL345 accelerometer driver.
adxl345_params_t * params
Device configuration.
Definition: adxl345.h:157
+/- 8 g Full Scale Rang
Definition: adxl345.h:55
200 Hz Output Data Rate
Definition: adxl345.h:74
everything was fine
Definition: adxl345.h:103
uint8_t thres_inact
Inactivity threshold.
Definition: adxl345.h:131
float scale_factor
Scale factor for converting value to mg.
Definition: adxl345.h:159
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:130
Low-level I2C peripheral driver interface definition.