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