Loading...
Searching...
No Matches
lis2dh12.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2018 Freie Universität Berlin
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
34
35#include <stdint.h>
36#include <stdbool.h>
37
38#include "saul.h"
39#include "lis2dh12_registers.h"
40
41#include "periph/gpio.h"
42#ifdef MODULE_LIS2DH12_SPI
43#include "periph/spi.h"
44#else
45#include "periph/i2c.h"
46#endif
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52#if defined(MODULE_LIS2DH12) || defined(DOXYGEN)
56#define LIS2DH12_ADDR_DEFAULT (0x19)
57#endif
58
68
85
96
97#define LIS2DH12_CLICK_X_SINGLE (1 << 0)
98#define LIS2DH12_CLICK_X_DOUBLE (1 << 1)
99#define LIS2DH12_CLICK_Y_SINGLE (1 << 2)
100#define LIS2DH12_CLICK_Y_DOUBLE (1 << 3)
101#define LIS2DH12_CLICK_Z_SINGLE (1 << 4)
102#define LIS2DH12_CLICK_Z_DOUBLE (1 << 5)
103
107typedef struct {
108#if MODULE_LIS2DH12_SPI || DOXYGEN
109 spi_t spi;
110 gpio_t cs;
111#else
112 i2c_t i2c;
113 uint8_t addr;
114#endif
115#if MODULE_LIS2DH12_INT || DOXYGEN
116 gpio_t int1_pin;
117 gpio_t int2_pin;
118#endif
123
132
142
155
171
175typedef struct {
177} lis2dh12_t;
178
182enum {
189};
190
191/*
192 * @brief Interrupt lines
193 */
194enum {
197};
198
202typedef struct {
203 uint8_t int_config;
204 uint8_t int_threshold:7;
206 uint8_t int_duration:7;
208 uint8_t int_type;
210
214typedef union {
215 struct {
216 int16_t x;
217 int16_t y;
218 int16_t z;
219 } axis;
220 int16_t data[3];
222
232
241
247extern const saul_driver_t lis2dh12_saul_temp_driver;
249
250#if MODULE_LIS2DH12_INT || DOXYGEN
264 uint32_t mg, uint32_t us,
265 uint8_t axis, uint8_t event, uint8_t pin);
266
283void lis2dh12_cfg_click_event(const lis2dh12_t *dev, uint32_t mg,
284 uint32_t us_limit, uint32_t us_latency, uint32_t us_window,
285 uint8_t click, uint8_t pin);
286
296void lis2dh12_cfg_disable_event(const lis2dh12_t *dev, uint8_t event, uint8_t pin);
297
311int32_t lis2dh12_wait_event(const lis2dh12_t *dev, uint8_t pin, bool stale_events);
312#endif /* MODULE_LIS2DH12_INT */
313
322int lis2dh12_set_fifo(const lis2dh12_t *dev, const lis2dh12_fifo_t *config);
323
336
348 uint8_t number);
349
361
372
386int lis2dh12_read_temperature(const lis2dh12_t *dev, int16_t *temp);
387
396
406
415
425
434
444
453
463
475int lis2dh12_set_reference(const lis2dh12_t *dev, uint8_t reference);
476
487
497
498#ifdef __cplusplus
499}
500#endif
501
Definition of the generic [S]ensor [A]ctuator [U]ber [L]ayer.
Low-level GPIO peripheral driver interface definitions.
lis2dh12_scale_t
Available scale values.
Definition lis2dh12.h:62
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:226
uint16_t lis2dh12_get_datarate(const lis2dh12_t *dev)
Get device sampling rate in Hz.
int32_t 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.
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:136
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:73
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:90
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...
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:127
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:65
@ LIS2DH12_SCALE_2G
+- 2g
Definition lis2dh12.h:63
@ LIS2DH12_SCALE_16G
+- 16g
Definition lis2dh12.h:66
@ LIS2DH12_SCALE_4G
+- 4g
Definition lis2dh12.h:64
@ LIS2DH12_FIFO_MODE_BYPASS
default mode, FIFO is bypassed
Definition lis2dh12.h:227
@ LIS2DH12_FIFO_MODE_STREAM
Stream mode, oldest values get overwritten.
Definition lis2dh12.h:229
@ LIS2DH12_FIFO_MODE_FIFOMODE
normal FIFO mode, stops if FIFO is full
Definition lis2dh12.h:228
@ LIS2DH12_FIFO_MODE_STREAMtoFIFO
Stream mode and on interrupt jumps to FIFO mode.
Definition lis2dh12.h:230
@ LIS2DH12_NODEV
unable to talk to device
Definition lis2dh12.h:185
@ LIS2DH12_NODATA
no data available
Definition lis2dh12.h:188
@ LIS2DH12_NOBUS
bus interface error
Definition lis2dh12.h:184
@ LIS2DH12_OK
everything was fine
Definition lis2dh12.h:183
@ LIS2DH12_NOINT
wrong interrupt line (has to be LIS2DH12_INT1 or LIS2DH12_INT2)
Definition lis2dh12.h:186
@ LIS2DH12_INT1
first interrupt line
Definition lis2dh12.h:195
@ LIS2DH12_INT2
second interrupt line
Definition lis2dh12.h:196
@ LIS2DH12_HP_FREQ_DIV100
cutoff freq is ODR divided by 100
Definition lis2dh12.h:138
@ LIS2DH12_HP_FREQ_DIV200
cutoff freq is ODR divided by 200
Definition lis2dh12.h:139
@ LIS2DH12_HP_FREQ_DIV50
cutoff freq is ODR divided by 50
Definition lis2dh12.h:137
@ LIS2DH12_HP_FREQ_DIV400
cutoff freq is ODR divided by 400
Definition lis2dh12.h:140
@ LIS2DH12_RATE_400HZ
sample with 400Hz @ all resolutions
Definition lis2dh12.h:80
@ LIS2DH12_RATE_200HZ
sample with 200Hz @ all resolutions
Definition lis2dh12.h:79
@ LIS2DH12_RATE_1620HZ
sample with 1620HZ @ 8-bit
Definition lis2dh12.h:81
@ LIS2DH12_RATE_VERYHIGH
sample with 1344Hz @ High resolution or \ 5376Hz @ 8-bit
Definition lis2dh12.h:82
@ LIS2DH12_RATE_50HZ
sample with 50Hz @ all resolutions
Definition lis2dh12.h:77
@ LIS2DH12_RATE_25HZ
sample with 25Hz @ all resolutions
Definition lis2dh12.h:76
@ LIS2DH12_RATE_1HZ
sample with 1Hz @ all resolutions
Definition lis2dh12.h:74
@ LIS2DH12_RATE_10HZ
sample with 10Hz @ all resolutions
Definition lis2dh12.h:75
@ LIS2DH12_RATE_100HZ
sample with 100Hz @ all resolutions
Definition lis2dh12.h:78
@ LIS2DH12_POWER_LOW
8-bit mode
Definition lis2dh12.h:92
@ LIS2DH12_POWER_DOWN
power down the device
Definition lis2dh12.h:91
@ LIS2DH12_POWER_NORMAL
10-bit mode
Definition lis2dh12.h:93
@ LIS2DH12_POWER_HIGH
12-bit mode
Definition lis2dh12.h:94
@ LIS2DH12_HP_MODE_NORMAL
normal mode, reset by reading REG_REFERENCE
Definition lis2dh12.h:128
@ LIS2DH12_HP_MODE_REFERENCE
uses the reference signal for filtering
Definition lis2dh12.h:129
@ LIS2DH12_HP_MODE_AUTORESET
automatically resets on interrupt generation
Definition lis2dh12.h:130
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition i2c.h:155
Low-level I2C peripheral driver interface definition.
LIS2DH12 register definitions.
Low-level SPI peripheral driver interface definition.
event structure
Definition event.h:145
LIS2DH12 click config values.
Definition lis2dh12.h:159
bool enable_DOUBLE
otherwise single click for given axis are enabled
Definition lis2dh12.h:160
uint8_t TIME_latency
set number of ODR cycles for latency after a click
Definition lis2dh12.h:168
bool noINT_latency
if "0" interrupt stays high for TIME_latency setting \ if "1" interrupt stays high until CLICK_SRC is...
Definition lis2dh12.h:164
uint8_t TIME_window
set number of ODR cycles for window between clicks
Definition lis2dh12.h:169
bool enable_Y_CLICK
enable double pr single click for Y axes
Definition lis2dh12.h:162
bool enable_X_CLICK
enable double pr single click for X axes
Definition lis2dh12.h:161
uint8_t CLICK_thold
set click threshold
Definition lis2dh12.h:166
uint8_t TIME_limit
set number of ODR cycles for time limit over threshold value
Definition lis2dh12.h:167
bool enable_Z_CLICK
enable double pr single click for Z axes
Definition lis2dh12.h:163
LIS2DH12 FIFO config values.
Definition lis2dh12.h:236
bool FIFO_set_INT2
sets the FIFO interrupt to INT2, otherwise INT1
Definition lis2dh12.h:239
uint8_t FIFO_watermark
set the FIFO watermark level
Definition lis2dh12.h:238
lis2dh12_fifo_mode_t FIFO_mode
set FIFO mode
Definition lis2dh12.h:237
LIS2DH12 high pass config values.
Definition lis2dh12.h:146
bool INT2_enable
enables filter for AOI on interrupt 2
Definition lis2dh12.h:152
bool CLICK_enable
enables filter for click data
Definition lis2dh12.h:150
bool INT1_enable
enables filter for AOI on interrupt 1
Definition lis2dh12.h:151
lis2dh12_hp_mode_t Highpass_mode
set the High pass mode
Definition lis2dh12.h:147
lis2dh12_hp_freq_t Highpass_freq
set the High pass cutoff frequency \ related to device rate
Definition lis2dh12.h:148
bool DATA_OUT_enable
enables filter for data output
Definition lis2dh12.h:153
Parameter for interrupt configuration.
Definition lis2dh12.h:202
uint8_t int_config
values for configuration
Definition lis2dh12.h:203
uint8_t int_threshold
the threshold for triggering interrupt, threshold in range 0-127
Definition lis2dh12.h:204
uint8_t int_type
values for type of interrupts
Definition lis2dh12.h:208
uint8_t int_duration
time between two interrupts ODR section in CTRL_REG1, duration in range 0-127
Definition lis2dh12.h:206
LIS2DH12 configuration parameters.
Definition lis2dh12.h:107
lis2dh12_resolution_t resolution
resolution used
Definition lis2dh12.h:121
gpio_t cs
connected chip select pin
Definition lis2dh12.h:110
spi_t spi
SPI bus the device is connected to.
Definition lis2dh12.h:109
lis2dh12_rate_t rate
sampling rate used
Definition lis2dh12.h:120
gpio_t int1_pin
first interrupt pin
Definition lis2dh12.h:116
lis2dh12_scale_t scale
sampling sensitivity used
Definition lis2dh12.h:119
gpio_t int2_pin
second interrupt pin
Definition lis2dh12.h:117
LIS2DH12 device descriptor.
Definition lis2dh12.h:175
const lis2dh12_params_t * p
device configuration
Definition lis2dh12.h:176
Definition of the RIOT actuator/sensor interface.
Definition saul.h:286
LIS2DH12 FIFO data struct.
Definition lis2dh12.h:214
int16_t y
Y data in mili-g.
Definition lis2dh12.h:217
int16_t z
Z data in mili-g.
Definition lis2dh12.h:218
int16_t x
X data in mili-g.
Definition lis2dh12.h:216
int16_t data[3]
x, y, z data in mili-g
Definition lis2dh12.h:220