lis2dh12.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Freie Universität Berlin
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 
36 #ifndef LIS2DH12_H
37 #define LIS2DH12_H
38 
39 #include <stdint.h>
40 
41 #include "saul.h"
42 
43 #include "periph/gpio.h"
44 #ifdef MODULE_LIS2DH12_SPI
45 #include "periph/spi.h"
46 #else
47 #include "periph/i2c.h"
48 #endif
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 #if defined(MODULE_LIS2DH12) || defined(DOXYGEN)
55 
58 #define LIS2DH12_ADDR_DEFAULT (0x19)
59 #endif
60 
64 typedef enum {
70 
77 typedef enum {
86 
90 typedef struct {
91 #if MODULE_LIS2DH12_SPI || DOXYGEN
93  gpio_t cs;
94 #else
95  i2c_t i2c;
96  uint8_t addr;
97 #endif
98 #if MODULE_LIS2DH12_INT || DOXYGEN
99  gpio_t int1_pin;
100  gpio_t int2_pin;
101 #endif
105 
109 typedef struct {
111  uint16_t comp;
112 } lis2dh12_t;
113 
117 enum {
123 };
124 
125 #if MODULE_LIS2DH12_INT || DOXYGEN
126 /*
127  * @brief Interrupt lines
128  */
129 enum{
132 };
133 
137 enum {
146 };
147 
151 enum {
152  /* for interrupt 1 (CTRL_REG3) */
160  /* for interrupt 2 (CTRL_REG6) */
167 };
168 
172 typedef struct {
173  uint8_t int_config;
174  uint8_t int_threshold:7;
175  uint8_t int_duration:7;
176  uint8_t int_type;
178  void *arg;
180 
184 #define LIS2DH12_INT_SRC_XL (0x01)
185 #define LIS2DH12_INT_SRC_XH (0x02)
186 #define LIS2DH12_INT_SRC_YL (0x04)
187 #define LIS2DH12_INT_SRC_YH (0x08)
188 #define LIS2DH12_INT_SRC_ZL (0x10)
189 #define LIS2DH12_INT_SRC_ZH (0x20)
190 #define LIS2DH12_INT_SRC_IA (0x40)
191 #endif /* MODULE_LIS2DH12_INT */
192 
196 #define LIS2DH12_STATUS_XDA (0x01)
197 #define LIS2DH12_STATUS_YDA (0x02)
198 #define LIS2DH12_STATUS_ZDA (0x04)
199 #define LIS2DH12_STATUS_ZYXDA (0x08)
200 #define LIS2DH12_STATUS_XOR (0x10)
201 #define LIS2DH12_STATUS_YOR (0x20)
202 #define LIS2DH12_STATUS_ZOR (0x40)
203 #define LIS2DH12_STATUS_ZYXOR (0x80)
208 extern const saul_driver_t lis2dh12_saul_driver;
209 
210 #if MODULE_LIS2DH12_INT || DOXYGEN
211 
221 int lis2dh12_set_int(const lis2dh12_t *dev, const lis2dh12_int_params_t *params, uint8_t int_line);
222 
233 int lis2dh12_read_int_src(const lis2dh12_t *dev, uint8_t *data, uint8_t int_line);
234 #endif /* MODULE_LIS2DH12_INT */
235 
246 int lis2dh12_init(lis2dh12_t *dev, const lis2dh12_params_t *params);
247 
257 int lis2dh12_read(const lis2dh12_t *dev, int16_t *data);
258 
267 int lis2dh12_poweron(const lis2dh12_t *dev);
268 
277 int lis2dh12_poweroff(const lis2dh12_t *dev);
278 
279 #ifdef __cplusplus
280 }
281 #endif
282 
283 #endif /* LIS2DH12_H */
284 
LIS2DH12_INT_CFG_YHIE
@ LIS2DH12_INT_CFG_YHIE
enable Y high event
Definition: lis2dh12.h:141
LIS2DH12_NODEV
@ LIS2DH12_NODEV
unable to talk to device
Definition: lis2dh12.h:120
LIS2DH12_INT_CFG_AOI
@ LIS2DH12_INT_CFG_AOI
and/or combination interrupt events
Definition: lis2dh12.h:145
LIS2DH12_INT_TYPE_I1_IA2
@ LIS2DH12_INT_TYPE_I1_IA2
IA2 interrupt on INT1.
Definition: lis2dh12.h:156
LIS2DH12_INT_CFG_ZLIE
@ LIS2DH12_INT_CFG_ZLIE
enable Z low event
Definition: lis2dh12.h:142
lis2dh12_init
int lis2dh12_init(lis2dh12_t *dev, const lis2dh12_params_t *params)
Initialize the given LIS2DH12 sensor device.
LIS2DH12_NODATA
@ LIS2DH12_NODATA
no data available
Definition: lis2dh12.h:122
spi.h
Low-level SPI peripheral driver interface definition.
lis2dh12_params_t
LIS2DH12 configuration parameters.
Definition: lis2dh12.h:90
lis2dh12_int_params_t::int_type
uint8_t int_type
values for type of interrupts
Definition: lis2dh12.h:176
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
lis2dh12_set_int
int lis2dh12_set_int(const lis2dh12_t *dev, const lis2dh12_int_params_t *params, uint8_t int_line)
Set the interrupt values in LIS2DH12 sensor device.
lis2dh12_params_t::rate
lis2dh12_rate_t rate
sampling rate used
Definition: lis2dh12.h:103
LIS2DH12_OK
@ LIS2DH12_OK
everything was fine
Definition: lis2dh12.h:118
LIS2DH12_INT_TYPE_I1_IA1
@ LIS2DH12_INT_TYPE_I1_IA1
IA1 interrupt on INT1.
Definition: lis2dh12.h:157
LIS2DH12_INT_TYPE_I2_IA1
@ LIS2DH12_INT_TYPE_I2_IA1
IA1 on INT2.
Definition: lis2dh12.h:165
lis2dh12_params_t::int2_pin
gpio_t int2_pin
second interrupt pin
Definition: lis2dh12.h:100
LIS2DH12_INT_TYPE_I2_CLICK
@ LIS2DH12_INT_TYPE_I2_CLICK
click interrupt on INT2
Definition: lis2dh12.h:166
lis2dh12_int_params_t::int_duration
uint8_t int_duration
time between two interrupts ODR section in CTRL_REG1, duration in range 0-127
Definition: lis2dh12.h:175
LIS2DH12_INT_TYPE_I2_ACT
@ LIS2DH12_INT_TYPE_I2_ACT
enable activity interrupt on INT2
Definition: lis2dh12.h:162
lis2dh12_int_params_t::int_threshold
uint8_t int_threshold
the threshold for triggering interrupt, threshold in range 0-127
Definition: lis2dh12.h:174
lis2dh12_int_params_t
Parameter for interrupt configuration.
Definition: lis2dh12.h:172
lis2dh12_rate_t
lis2dh12_rate_t
Available sampling rates.
Definition: lis2dh12.h:77
lis2dh12_params_t::spi
spi_t spi
SPI bus the device is connected to.
Definition: lis2dh12.h:92
LIS2DH12_INT_TYPE_I2_BOOT
@ LIS2DH12_INT_TYPE_I2_BOOT
enable boot on INT2
Definition: lis2dh12.h:163
LIS2DH12_INT_TYPE_I1_ZYXDA
@ LIS2DH12_INT_TYPE_I1_ZYXDA
ZYXDA interrupt on INT1.
Definition: lis2dh12.h:155
lis2dh12_int_params_t::arg
void * arg
the callback argument
Definition: lis2dh12.h:178
LIS2DH12_RATE_1HZ
@ LIS2DH12_RATE_1HZ
sample with 1Hz
Definition: lis2dh12.h:78
LIS2DH12_RATE_25HZ
@ LIS2DH12_RATE_25HZ
sample with 25Hz
Definition: lis2dh12.h:80
lis2dh12_poweron
int lis2dh12_poweron(const lis2dh12_t *dev)
Power on the given device.
LIS2DH12_SCALE_2G
@ LIS2DH12_SCALE_2G
+- 2g
Definition: lis2dh12.h:65
LIS2DH12_SCALE_4G
@ LIS2DH12_SCALE_4G
+- 4g
Definition: lis2dh12.h:66
LIS2DH12_RATE_200HZ
@ LIS2DH12_RATE_200HZ
sample with 200Hz
Definition: lis2dh12.h:83
lis2dh12_t
LIS2DH12 device descriptor.
Definition: lis2dh12.h:109
LIS2DH12_INT_TYPE_INT_POLARITY
@ LIS2DH12_INT_TYPE_INT_POLARITY
INT1 and INT2 pin polarity.
Definition: lis2dh12.h:161
lis2dh12_t::comp
uint16_t comp
scale compensation factor
Definition: lis2dh12.h:111
lis2dh12_params_t::scale
lis2dh12_scale_t scale
sampling sensitivity used
Definition: lis2dh12.h:102
LIS2DH12_RATE_10HZ
@ LIS2DH12_RATE_10HZ
sample with 10Hz
Definition: lis2dh12.h:79
LIS2DH12_INT_CFG_YLIE
@ LIS2DH12_INT_CFG_YLIE
enable Y low event
Definition: lis2dh12.h:140
lis2dh12_read
int lis2dh12_read(const lis2dh12_t *dev, int16_t *data)
Read acceleration data from the given device.
lis2dh12_scale_t
lis2dh12_scale_t
Available scale values.
Definition: lis2dh12.h:64
LIS2DH12_SCALE_8G
@ LIS2DH12_SCALE_8G
+- 8g
Definition: lis2dh12.h:67
LIS2DH12_INT_CFG_ZHIE
@ LIS2DH12_INT_CFG_ZHIE
enable Z high event
Definition: lis2dh12.h:143
LIS2DH12_INT_CFG_XHIE
@ LIS2DH12_INT_CFG_XHIE
enable X high event
Definition: lis2dh12.h:139
lis2dh12_int_params_t::cb
gpio_cb_t cb
the callback to execute
Definition: lis2dh12.h:177
LIS2DH12_INT2
@ LIS2DH12_INT2
second interrupt line
Definition: lis2dh12.h:131
lis2dh12_params_t::int1_pin
gpio_t int1_pin
first interrupt pin
Definition: lis2dh12.h:99
LIS2DH12_INT_CFG_6D
@ LIS2DH12_INT_CFG_6D
enable 6-direction detection
Definition: lis2dh12.h:144
LIS2DH12_SCALE_16G
@ LIS2DH12_SCALE_16G
+- 16g
Definition: lis2dh12.h:68
gpio_cb_t
void(* gpio_cb_t)(void *arg)
Signature of event callback functions triggered from interrupts.
Definition: gpio.h:146
LIS2DH12_RATE_400HZ
@ LIS2DH12_RATE_400HZ
sample with 400Hz
Definition: lis2dh12.h:84
LIS2DH12_RATE_100HZ
@ LIS2DH12_RATE_100HZ
sample with 100Hz
Definition: lis2dh12.h:82
LIS2DH12_INT_TYPE_I1_OVERRUN
@ LIS2DH12_INT_TYPE_I1_OVERRUN
FIFO overrun interrupt on INT1.
Definition: lis2dh12.h:153
LIS2DH12_INT_CFG_XLIE
@ LIS2DH12_INT_CFG_XLIE
enable X low evnt
Definition: lis2dh12.h:138
gpio.h
Low-level GPIO peripheral driver interface definitions.
lis2dh12_int_params_t::int_config
uint8_t int_config
values for configuration
Definition: lis2dh12.h:173
LIS2DH12_NOINT
@ LIS2DH12_NOINT
wrong interrupt line (has to be LIS2DH12_INT1 or LIS2DH12_INT2)
Definition: lis2dh12.h:121
LIS2DH12_INT_TYPE_I1_WTM
@ LIS2DH12_INT_TYPE_I1_WTM
FIFO watermark inter.
Definition: lis2dh12.h:154
saul.h
Definition of the generic [S]ensor [A]ctuator [U]ber [L]ayer.
lis2dh12_t::p
const lis2dh12_params_t * p
device configuration
Definition: lis2dh12.h:110
LIS2DH12_INT1
@ LIS2DH12_INT1
first interrupt line
Definition: lis2dh12.h:130
LIS2DH12_RATE_50HZ
@ LIS2DH12_RATE_50HZ
sample with 50Hz
Definition: lis2dh12.h:81
lis2dh12_read_int_src
int lis2dh12_read_int_src(const lis2dh12_t *dev, uint8_t *data, uint8_t int_line)
Read an interrupt event on LIS2DH12 sensor device.
LIS2DH12_NOBUS
@ LIS2DH12_NOBUS
bus interface error
Definition: lis2dh12.h:119
LIS2DH12_INT_TYPE_I1_CLICK
@ LIS2DH12_INT_TYPE_I1_CLICK
click interrupt on INT1
Definition: lis2dh12.h:158
lis2dh12_params_t::cs
gpio_t cs
connected chip select pin
Definition: lis2dh12.h:93
lis2dh12_poweroff
int lis2dh12_poweroff(const lis2dh12_t *dev)
Power off the given device.
i2c.h
Low-level I2C peripheral driver interface definition.
LIS2DH12_INT_TYPE_I2_IA2
@ LIS2DH12_INT_TYPE_I2_IA2
IA2 on INT2.
Definition: lis2dh12.h:164
spi_t
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:118