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