Loading...
Searching...
No Matches
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#include <stdbool.h>
41
42#include "saul.h"
43#include "lis2dh12_registers.h"
44
45#include "periph/gpio.h"
46#ifdef MODULE_LIS2DH12_SPI
47#include "periph/spi.h"
48#else
49#include "periph/i2c.h"
50#endif
51
52#ifdef __cplusplus
53extern "C" {
54#endif
55
56#if defined(MODULE_LIS2DH12) || defined(DOXYGEN)
60#define LIS2DH12_ADDR_DEFAULT (0x19)
61#endif
62
72
89
100
101#define LIS2DH12_CLICK_X_SINGLE (1 << 0)
102#define LIS2DH12_CLICK_X_DOUBLE (1 << 1)
103#define LIS2DH12_CLICK_Y_SINGLE (1 << 2)
104#define LIS2DH12_CLICK_Y_DOUBLE (1 << 3)
105#define LIS2DH12_CLICK_Z_SINGLE (1 << 4)
106#define LIS2DH12_CLICK_Z_DOUBLE (1 << 5)
111typedef struct {
112#if MODULE_LIS2DH12_SPI || DOXYGEN
113 spi_t spi;
114 gpio_t cs;
115#else
116 i2c_t i2c;
117 uint8_t addr;
118#endif
119#if MODULE_LIS2DH12_INT || DOXYGEN
120 gpio_t int1_pin;
121 gpio_t int2_pin;
122#endif
127
136
146
159
175
179typedef struct {
181} lis2dh12_t;
182
186enum {
190 LIS2DH12_NOINT = -3,
193};
194
195/*
196 * @brief Interrupt lines
197 */
198enum {
201};
202
206typedef struct {
207 uint8_t int_config;
208 uint8_t int_threshold:7;
210 uint8_t int_duration:7;
212 uint8_t int_type;
214
218typedef union {
219 struct {
220 int16_t x;
221 int16_t y;
222 int16_t z;
223 } axis;
224 int16_t data[3];
226
236
245
251extern const saul_driver_t lis2dh12_saul_temp_driver;
254#if MODULE_LIS2DH12_INT || DOXYGEN
268 uint32_t mg, uint32_t us,
269 uint8_t axis, uint8_t event, uint8_t pin);
270
287void lis2dh12_cfg_click_event(const lis2dh12_t *dev, uint32_t mg,
288 uint32_t us_limit, uint32_t us_latency, uint32_t us_window,
289 uint8_t click, uint8_t pin);
290
300void lis2dh12_cfg_disable_event(const lis2dh12_t *dev, uint8_t event, uint8_t pin);
301
315int lis2dh12_wait_event(const lis2dh12_t *dev, uint8_t pin, bool stale_events);
316#endif /* MODULE_LIS2DH12_INT */
317
326int lis2dh12_set_fifo(const lis2dh12_t *dev, const lis2dh12_fifo_t *config);
327
340
352 uint8_t number);
353
365
376
390int lis2dh12_read_temperature(const lis2dh12_t *dev, int16_t *temp);
391
400
410
419
429
438
448
457
467
479int lis2dh12_set_reference(const lis2dh12_t *dev, uint8_t reference);
480
491
501
502#ifdef __cplusplus
503}
504#endif
505
506#endif /* LIS2DH12_H */
Low-level GPIO peripheral driver interface definitions.
lis2dh12_scale_t
Available scale values.
Definition lis2dh12.h:66
int lis2dh12_set_datarate(const lis2dh12_t *dev, lis2dh12_rate_t rate)
Change device sampling rate.
int lis2dh12_set_resolution(const lis2dh12_t *dev, lis2dh12_resolution_t resolution)
Change device resolution.
lis2dh12_fifo_mode_t
LIS2DH12 FIFO modes.
Definition lis2dh12.h:230
uint16_t lis2dh12_get_datarate(const lis2dh12_t *dev)
Get device sampling rate in Hz.
void lis2dh12_cfg_threshold_event(const lis2dh12_t *dev, uint32_t mg, uint32_t us, uint8_t axis, uint8_t event, uint8_t pin)
Configure a threshold event An Interrupt will be generated if acceleration exceeds the set threshold ...
int lis2dh12_restart_fifo(const lis2dh12_t *dev)
Restart the FIFO mode this sets the FIFO mode in BYPASS mode and then back to previous mode Note: The...
lis2dh12_resolution_t lis2dh12_get_resolution(const lis2dh12_t *dev)
Get device resolution.
lis2dh12_hp_freq_t
LIS2DH12 high pass cutoff frequency.
Definition lis2dh12.h:140
lis2dh12_scale_t lis2dh12_get_scale(lis2dh12_t *dev)
Get device measuring range.
int lis2dh12_set_scale(lis2dh12_t *dev, lis2dh12_scale_t scale)
Change device measuring range.
void lis2dh12_cfg_click_event(const lis2dh12_t *dev, uint32_t mg, uint32_t us_limit, uint32_t us_latency, uint32_t us_window, uint8_t click, uint8_t pin)
Configure a click event A click event is generated when the acceleration exceeds the set threshold fo...
int lis2dh12_clear_data(const lis2dh12_t *dev)
Clear the LIS2DH12 memory, clears all sampled data.
int lis2dh12_set_reference(const lis2dh12_t *dev, uint8_t reference)
Set the reference value to control the high-pass reference.
int lis2dh12_read(const lis2dh12_t *dev, lis2dh12_fifo_data_t *data)
Read acceleration data from the given device.
const saul_driver_t lis2dh12_saul_driver
Export the SAUL interface for this driver.
int lis2dh12_read_temperature(const lis2dh12_t *dev, int16_t *temp)
Read temperature data from the given device.
lis2dh12_rate_t
Available sampling rates.
Definition lis2dh12.h:77
int lis2dh12_set_fifo(const lis2dh12_t *dev, const lis2dh12_fifo_t *config)
Set the FIFO configuration.
lis2dh12_resolution_t
Available resolutions.
Definition lis2dh12.h:94
int lis2dh12_poweron(const lis2dh12_t *dev)
Power on the given device and resets resolution and sampling rate to default values in the device des...
int lis2dh12_wait_event(const lis2dh12_t *dev, uint8_t pin, bool stale_events)
Wait for an interrupt event This function will block until an interrupt is received.
uint8_t lis2dh12_read_fifo_data(const lis2dh12_t *dev, lis2dh12_fifo_data_t *fifo_data, uint8_t number)
This function will read a given number of data from FIFO reads amount of data that is available in FI...
int lis2dh12_set_highpass(const lis2dh12_t *dev, const lis2dh12_highpass_t *config)
Configures the high pass filter.
int lis2dh12_poweroff(const lis2dh12_t *dev)
Power off the given device.
lis2dh12_hp_mode_t
LIS2DH12 high pass modes.
Definition lis2dh12.h:131
int lis2dh12_init(lis2dh12_t *dev, const lis2dh12_params_t *params)
Initialize the given LIS2DH12 sensor device.
void lis2dh12_cfg_disable_event(const lis2dh12_t *dev, uint8_t event, uint8_t pin)
Disable interrupt generation for an event This disables an interrupt on pin if a previously configure...
@ LIS2DH12_SCALE_8G
+- 8g
Definition lis2dh12.h:69
@ LIS2DH12_SCALE_2G
+- 2g
Definition lis2dh12.h:67
@ LIS2DH12_SCALE_16G
+- 16g
Definition lis2dh12.h:70
@ LIS2DH12_SCALE_4G
+- 4g
Definition lis2dh12.h:68
@ LIS2DH12_INT1
first interrupt line
Definition lis2dh12.h:199
@ LIS2DH12_INT2
second interrupt line
Definition lis2dh12.h:200
@ LIS2DH12_FIFO_MODE_BYPASS
default mode, FIFO is bypassed
Definition lis2dh12.h:231
@ LIS2DH12_FIFO_MODE_STREAM
Stream mode, oldest values get overwritten.
Definition lis2dh12.h:233
@ LIS2DH12_FIFO_MODE_FIFOMODE
normal FIFO mode, stops if FIFO is full
Definition lis2dh12.h:232
@ LIS2DH12_FIFO_MODE_STREAMtoFIFO
Stream mode and on interrupt jumps to FIFO mode.
Definition lis2dh12.h:234
@ LIS2DH12_HP_FREQ_DIV100
cutoff freq is ODR divided by 100
Definition lis2dh12.h:142
@ LIS2DH12_HP_FREQ_DIV200
cutoff freq is ODR divided by 200
Definition lis2dh12.h:143
@ LIS2DH12_HP_FREQ_DIV50
cutoff freq is ODR divided by 50
Definition lis2dh12.h:141
@ LIS2DH12_HP_FREQ_DIV400
cutoff freq is ODR divided by 400
Definition lis2dh12.h:144
@ LIS2DH12_RATE_400HZ
sample with 400Hz @ all resolutions
Definition lis2dh12.h:84
@ LIS2DH12_RATE_200HZ
sample with 200Hz @ all resolutions
Definition lis2dh12.h:83
@ LIS2DH12_RATE_1620HZ
sample with 1620HZ @ 8-bit
Definition lis2dh12.h:85
@ LIS2DH12_RATE_VERYHIGH
sample with 1344Hz @ High resolution or \ 5376Hz @ 8-bit
Definition lis2dh12.h:86
@ LIS2DH12_RATE_50HZ
sample with 50Hz @ all resolutions
Definition lis2dh12.h:81
@ LIS2DH12_RATE_25HZ
sample with 25Hz @ all resolutions
Definition lis2dh12.h:80
@ LIS2DH12_RATE_1HZ
sample with 1Hz @ all resolutions
Definition lis2dh12.h:78
@ LIS2DH12_RATE_10HZ
sample with 10Hz @ all resolutions
Definition lis2dh12.h:79
@ LIS2DH12_RATE_100HZ
sample with 100Hz @ all resolutions
Definition lis2dh12.h:82
@ LIS2DH12_POWER_LOW
8-bit mode
Definition lis2dh12.h:96
@ LIS2DH12_POWER_DOWN
power down the device
Definition lis2dh12.h:95
@ LIS2DH12_POWER_NORMAL
10-bit mode
Definition lis2dh12.h:97
@ LIS2DH12_POWER_HIGH
12-bit mode
Definition lis2dh12.h:98
@ LIS2DH12_NODEV
unable to talk to device
Definition lis2dh12.h:189
@ LIS2DH12_NODATA
no data available
Definition lis2dh12.h:192
@ LIS2DH12_NOBUS
bus interface error
Definition lis2dh12.h:188
@ LIS2DH12_OK
everything was fine
Definition lis2dh12.h:187
@ LIS2DH12_NOINT
wrong interrupt line (has to be LIS2DH12_INT1 or LIS2DH12_INT2)
Definition lis2dh12.h:190
@ LIS2DH12_HP_MODE_NORMAL
normal mode, reset by reading REG_REFERENCE
Definition lis2dh12.h:132
@ LIS2DH12_HP_MODE_REFERENCE
uses the reference signal for filtering
Definition lis2dh12.h:133
@ LIS2DH12_HP_MODE_AUTORESET
automatically resets on interrupt generation
Definition lis2dh12.h:134
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition i2c.h:151
Low-level I2C peripheral driver interface definition.
LIS2DH12 register definitions.
Low-level SPI peripheral driver interface definition.
event structure
Definition event.h:148
LIS2DH12 click config values.
Definition lis2dh12.h:163
bool enable_DOUBLE
otherwise single click for given axis are enabled
Definition lis2dh12.h:164
uint8_t TIME_latency
set number of ODR cycles for latency after a click
Definition lis2dh12.h:172
bool noINT_latency
if "0" interrupt stays high for TIME_latency setting \ if "1" interrupt stays high until CLICK_SRC is...
Definition lis2dh12.h:168
uint8_t TIME_window
set number of ODR cycles for window between clicks
Definition lis2dh12.h:173
bool enable_Y_CLICK
enable double pr single click for Y axes
Definition lis2dh12.h:166
bool enable_X_CLICK
enable double pr single click for X axes
Definition lis2dh12.h:165
uint8_t CLICK_thold
set click threshold
Definition lis2dh12.h:170
uint8_t TIME_limit
set number of ODR cycles for time limit over threshold value
Definition lis2dh12.h:171
bool enable_Z_CLICK
enable double pr single click for Z axes
Definition lis2dh12.h:167
LIS2DH12 FIFO config values.
Definition lis2dh12.h:240
bool FIFO_set_INT2
sets the FIFO interrupt to INT2, otherwise INT1
Definition lis2dh12.h:243
uint8_t FIFO_watermark
set the FIFO watermark level
Definition lis2dh12.h:242
lis2dh12_fifo_mode_t FIFO_mode
set FIFO mode
Definition lis2dh12.h:241
LIS2DH12 high pass config values.
Definition lis2dh12.h:150
bool INT2_enable
enables filter for AOI on interrupt 2
Definition lis2dh12.h:156
bool CLICK_enable
enables filter for click data
Definition lis2dh12.h:154
bool INT1_enable
enables filter for AOI on interrupt 1
Definition lis2dh12.h:155
lis2dh12_hp_mode_t Highpass_mode
set the High pass mode
Definition lis2dh12.h:151
lis2dh12_hp_freq_t Highpass_freq
set the High pass cutoff frequency \ related to device rate
Definition lis2dh12.h:152
bool DATA_OUT_enable
enables filter for data output
Definition lis2dh12.h:157
Parameter for interrupt configuration.
Definition lis2dh12.h:206
uint8_t int_config
values for configuration
Definition lis2dh12.h:207
uint8_t int_threshold
the threshold for triggering interrupt, threshold in range 0-127
Definition lis2dh12.h:208
uint8_t int_type
values for type of interrupts
Definition lis2dh12.h:212
uint8_t int_duration
time between two interrupts ODR section in CTRL_REG1, duration in range 0-127
Definition lis2dh12.h:210
LIS2DH12 configuration parameters.
Definition lis2dh12.h:111
lis2dh12_resolution_t resolution
resolution used
Definition lis2dh12.h:125
gpio_t cs
connected chip select pin
Definition lis2dh12.h:114
spi_t spi
SPI bus the device is connected to.
Definition lis2dh12.h:113
lis2dh12_rate_t rate
sampling rate used
Definition lis2dh12.h:124
gpio_t int1_pin
first interrupt pin
Definition lis2dh12.h:120
lis2dh12_scale_t scale
sampling sensitivity used
Definition lis2dh12.h:123
gpio_t int2_pin
second interrupt pin
Definition lis2dh12.h:121
LIS2DH12 device descriptor.
Definition lis2dh12.h:179
const lis2dh12_params_t * p
device configuration
Definition lis2dh12.h:180
Definition of the RIOT actuator/sensor interface.
Definition saul.h:284
Functionality for reading [S]ensor [A]ctuator [U]ber [L]ayer sensors as SenML.
LIS2DH12 FIFO data struct.
Definition lis2dh12.h:218
int16_t y
Y data in mili-g.
Definition lis2dh12.h:221
int16_t z
Z data in mili-g.
Definition lis2dh12.h:222
int16_t x
X data in mili-g.
Definition lis2dh12.h:220