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 
bus interface error
Definition: lis2dh12.h:119
sample with 400Hz
Definition: lis2dh12.h:84
int lis2dh12_read(const lis2dh12_t *dev, int16_t *data)
Read acceleration data from the given device.
spi_t spi
SPI bus the device is connected to.
Definition: lis2dh12.h:92
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.
enable boot on INT2
Definition: lis2dh12.h:163
uint8_t int_threshold
the threshold for triggering interrupt, threshold in range 0-127
Definition: lis2dh12.h:174
uint8_t int_config
values for configuration
Definition: lis2dh12.h:173
int lis2dh12_init(lis2dh12_t *dev, const lis2dh12_params_t *params)
Initialize the given LIS2DH12 sensor device.
enable X low evnt
Definition: lis2dh12.h:138
FIFO watermark inter.
Definition: lis2dh12.h:154
Low-level GPIO peripheral driver interface definitions.
uint16_t comp
scale compensation factor
Definition: lis2dh12.h:111
gpio_t int2_pin
second interrupt pin
Definition: lis2dh12.h:100
everything was fine
Definition: lis2dh12.h:118
INT1 and INT2 pin polarity.
Definition: lis2dh12.h:161
Parameter for interrupt configuration.
Definition: lis2dh12.h:172
enable activity interrupt on INT2
Definition: lis2dh12.h:162
lis2dh12_rate_t rate
sampling rate used
Definition: lis2dh12.h:103
no data available
Definition: lis2dh12.h:122
wrong interrupt line (has to be LIS2DH12_INT1 or LIS2DH12_INT2)
Definition: lis2dh12.h:121
first interrupt line
Definition: lis2dh12.h:130
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
enable Y high event
Definition: lis2dh12.h:141
sample with 200Hz
Definition: lis2dh12.h:83
uint8_t int_type
values for type of interrupts
Definition: lis2dh12.h:176
IA2 interrupt on INT1.
Definition: lis2dh12.h:156
unable to talk to device
Definition: lis2dh12.h:120
Low-level SPI peripheral driver interface definition.
and/or combination interrupt events
Definition: lis2dh12.h:145
lis2dh12_scale_t scale
sampling sensitivity used
Definition: lis2dh12.h:102
void * arg
the callback argument
Definition: lis2dh12.h:178
sample with 50Hz
Definition: lis2dh12.h:81
Definition of the generic [S]ensor [A]ctuator [U]ber [L]ayer.
enable 6-direction detection
Definition: lis2dh12.h:144
const lis2dh12_params_t * p
device configuration
Definition: lis2dh12.h:110
IA1 interrupt on INT1.
Definition: lis2dh12.h:157
sample with 100Hz
Definition: lis2dh12.h:82
int lis2dh12_read_int_src(const lis2dh12_t *dev, uint8_t *data, uint8_t int_line)
Read an interrupt event on LIS2DH12 sensor device.
sample with 1Hz
Definition: lis2dh12.h:78
sample with 25Hz
Definition: lis2dh12.h:80
int lis2dh12_poweroff(const lis2dh12_t *dev)
Power off the given device.
ZYXDA interrupt on INT1.
Definition: lis2dh12.h:155
enable Y low event
Definition: lis2dh12.h:140
lis2dh12_rate_t
Available sampling rates.
Definition: lis2dh12.h:77
enable X high event
Definition: lis2dh12.h:139
LIS2DH12 device descriptor.
Definition: lis2dh12.h:109
gpio_cb_t cb
the callback to execute
Definition: lis2dh12.h:177
int lis2dh12_poweron(const lis2dh12_t *dev)
Power on the given device.
click interrupt on INT2
Definition: lis2dh12.h:166
gpio_t int1_pin
first interrupt pin
Definition: lis2dh12.h:99
second interrupt line
Definition: lis2dh12.h:131
gpio_t cs
connected chip select pin
Definition: lis2dh12.h:93
enable Z low event
Definition: lis2dh12.h:142
sample with 10Hz
Definition: lis2dh12.h:79
click interrupt on INT1
Definition: lis2dh12.h:158
lis2dh12_scale_t
Available scale values.
Definition: lis2dh12.h:64
FIFO overrun interrupt on INT1.
Definition: lis2dh12.h:153
LIS2DH12 configuration parameters.
Definition: lis2dh12.h:90
uint8_t int_duration
time between two interrupts ODR section in CTRL_REG1, duration in range 0-127
Definition: lis2dh12.h:175
enable Z high event
Definition: lis2dh12.h:143
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:118
void(* gpio_cb_t)(void *arg)
Signature of event callback functions triggered from interrupts.
Definition: gpio.h:146
Low-level I2C peripheral driver interface definition.