adxl345.h
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  */
8 
21 #ifndef ADXL345_H
22 #define ADXL345_H
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #include "periph/i2c.h"
29 #include "periph/gpio.h"
30 
34 enum {
35  ADXL345_ADDR_1D = 0x1D,
36  ADXL345_ADDR_53 = 0x53,
37 };
38 
42 enum {
43  ADXL345_MEASURE_MODE,
44  ADXL345_STANDBY_MODE,
45  ADXL345_SLEEP_MODE,
46  ADXL345_AUTOSLEEP_MODE,
47 };
48 
52 enum {
57 };
58 
62 enum {
79 };
80 
84 enum {
85  BYPASS = 0,
86  FIFO = 1,
87  STREAM = 2,
88  TRIGGER = 3
89 };
90 
94 enum {
95  INT1,
97 };
98 
102 enum {
108 };
109 
113 typedef struct {
114  int16_t x;
115  int16_t y;
116  int16_t z;
118 
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;
138 
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;
150 
154 typedef struct {
156  uint8_t addr;
159  float scale_factor;
160 } adxl345_t;
161 
172 int adxl345_init(adxl345_t *dev, const adxl345_params_t* params);
185 void adxl345_read(const adxl345_t *dev, adxl345_data_t *data);
186 
192 void adxl345_set_interrupt(const adxl345_t *dev);
193 
199 void adxl345_set_measure(const adxl345_t *dev);
200 
206 void adxl345_set_standby(const adxl345_t *dev);
207 
213 void adxl345_set_sleep(const adxl345_t *dev);
214 
220 void adxl345_set_autosleep(const adxl345_t *dev);
221 
228 void adxl345_set_bandwidth_rate(const adxl345_t *dev, uint8_t bw_rate);
229 
238 void adxl345_set_fifo_mode(const adxl345_t *dev, uint8_t mode,
239  uint8_t output, uint8_t value);
240 
241 #ifdef __cplusplus
242 }
243 #endif
244 
245 #endif /* ADXL345_H */
246 
i2c_t i2c
I2C device which is used.
Definition: adxl345.h:155
Interrupt configuration struct for the ADXL345 sensor.
Definition: adxl345.h:122
200 Hz Output Data Rate
Definition: adxl345.h:74
gpio_t int1
accelerometer int1 pin
Definition: adxl345.h:143
+/- 4 g Full Scale Rang
Definition: adxl345.h:54
+/- 16 g Full Scale Rang
Definition: adxl345.h:56
25 Hz Output Data Rate
Definition: adxl345.h:71
1600 Hz Output Data Rate
Definition: adxl345.h:77
Output interrupt on INT2 pin.
Definition: adxl345.h:96
I2C communication failed.
Definition: adxl345.h:105
uint8_t thres_window
Tap window.
Definition: adxl345.h:129
0.1 Hz Output Data Rate
Definition: adxl345.h:63
400 Hz Output Data Rate
Definition: adxl345.h:75
uint8_t addr
I2C address.
Definition: adxl345.h:156
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
uint8_t enable
Interrupt enable control.
Definition: adxl345.h:125
no ADXL345 device found on the bus
Definition: adxl345.h:106
Configuration struct for the ADXL345 sensor.
Definition: adxl345.h:142
12.5 Hz Output Data Rate
Definition: adxl345.h:70
I2C device address if Alt addr pin is high.
Definition: adxl345.h:35
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:108
void adxl345_set_standby(const adxl345_t *dev)
Set standby mode.
adxl345_interrupt_t interrupt
Interrupts configuration.
Definition: adxl345.h:158
ADXL345 result vector struct.
Definition: adxl345.h:113
void adxl345_set_bandwidth_rate(const adxl345_t *dev, uint8_t bw_rate)
Set bandwidth rate.
+/- 2 g Full Scale Rang
Definition: adxl345.h:53
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.
uint8_t thres_tap
Tap threshold.
Definition: adxl345.h:126
everything was fine
Definition: adxl345.h:103
100 Hz Output Data Rate
Definition: adxl345.h:73
uint8_t time_ff
Time threshold.
Definition: adxl345.h:134
I2C device address if Alt addr pin is low.
Definition: adxl345.h:36
0.39 Hz Output Data Rate
Definition: adxl345.h:65
FIFO trigger mode.
Definition: adxl345.h:88
uint8_t thres_ff
Free-fall threshold.
Definition: adxl345.h:133
uint8_t time_inact
Inactivity time.
Definition: adxl345.h:132
uint8_t range
Sensitivity configuration.
Definition: adxl345.h:146
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
Output interrupt on INT1 pin.
Definition: adxl345.h:95
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
3200 Hz Output Data Rate
Definition: adxl345.h:78
void adxl345_set_sleep(const adxl345_t *dev)
Set sleep mode.
FIFO stream mode.
Definition: adxl345.h:87
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
uint8_t act_inact
Enable ctrl for activity/inactivity detection.
Definition: adxl345.h:135
+/- 8 g Full Scale Rang
Definition: adxl345.h:55
1.56 Hz Output Data Rate
Definition: adxl345.h:67
void adxl345_set_measure(const adxl345_t *dev)
set ADXL345's measure mode
3.13 Hz Output Data Rate
Definition: adxl345.h:68
no data available
Definition: adxl345.h:107
FIFO mode.
Definition: adxl345.h:86
6.25 Hz Output Data Rate
Definition: adxl345.h:69
uint8_t source
Source of interrupts.
Definition: adxl345.h:123
50 Hz Output Data Rate
Definition: adxl345.h:72
new data ready to be read
Definition: adxl345.h:104
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
uint8_t thres_inact
Inactivity threshold.
Definition: adxl345.h:131
800 Hz Output Data Rate
Definition: adxl345.h:76
FIFO bypass mode.
Definition: adxl345.h:85
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.
0.78 Hz Output Data Rate
Definition: adxl345.h:66
0.2 Hz Output Data Rate
Definition: adxl345.h:64
uint8_t thres_act
Activity threshold.
Definition: adxl345.h:130
Low-level I2C peripheral driver interface definition.