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
9#pragma once
10
37
38#include <stdint.h>
39#include <stdbool.h>
40
41#include "saul.h"
42#include "lis2dh12_registers.h"
43
44#include "periph/gpio.h"
45#ifdef MODULE_LIS2DH12_SPI
46#include "periph/spi.h"
47#else
48#include "periph/i2c.h"
49#endif
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55#if defined(MODULE_LIS2DH12) || defined(DOXYGEN)
59#define LIS2DH12_ADDR_DEFAULT (0x19)
60#endif
61
71
88
99
100#define LIS2DH12_CLICK_X_SINGLE (1 << 0)
101#define LIS2DH12_CLICK_X_DOUBLE (1 << 1)
102#define LIS2DH12_CLICK_Y_SINGLE (1 << 2)
103#define LIS2DH12_CLICK_Y_DOUBLE (1 << 3)
104#define LIS2DH12_CLICK_Z_SINGLE (1 << 4)
105#define LIS2DH12_CLICK_Z_DOUBLE (1 << 5)
106
110typedef struct {
111#if MODULE_LIS2DH12_SPI || DOXYGEN
112 spi_t spi;
113 gpio_t cs;
114#else
115 i2c_t i2c;
116 uint8_t addr;
117#endif
118#if MODULE_LIS2DH12_INT || DOXYGEN
119 gpio_t int1_pin;
120 gpio_t int2_pin;
121#endif
126
135
145
158
174
178typedef struct {
180} lis2dh12_t;
181
185enum {
192};
193
194/*
195 * @brief Interrupt lines
196 */
197enum {
200};
201
205typedef struct {
206 uint8_t int_config;
207 uint8_t int_threshold:7;
209 uint8_t int_duration:7;
211 uint8_t int_type;
213
217typedef union {
218 struct {
219 int16_t x;
220 int16_t y;
221 int16_t z;
222 } axis;
223 int16_t data[3];
225
235
244
250extern const saul_driver_t lis2dh12_saul_temp_driver;
252
253#if MODULE_LIS2DH12_INT || DOXYGEN
267 uint32_t mg, uint32_t us,
268 uint8_t axis, uint8_t event, uint8_t pin);
269
286void lis2dh12_cfg_click_event(const lis2dh12_t *dev, uint32_t mg,
287 uint32_t us_limit, uint32_t us_latency, uint32_t us_window,
288 uint8_t click, uint8_t pin);
289
299void lis2dh12_cfg_disable_event(const lis2dh12_t *dev, uint8_t event, uint8_t pin);
300
314int32_t lis2dh12_wait_event(const lis2dh12_t *dev, uint8_t pin, bool stale_events);
315#endif /* MODULE_LIS2DH12_INT */
316
325int lis2dh12_set_fifo(const lis2dh12_t *dev, const lis2dh12_fifo_t *config);
326
339
351 uint8_t number);
352
364
375
389int lis2dh12_read_temperature(const lis2dh12_t *dev, int16_t *temp);
390
399
409
418
428
437
447
456
466
478int lis2dh12_set_reference(const lis2dh12_t *dev, uint8_t reference);
479
490
500
501#ifdef __cplusplus
502}
503#endif
504
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:65
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:229
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:139
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:76
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:93
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:130
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:68
@ LIS2DH12_SCALE_2G
+- 2g
Definition lis2dh12.h:66
@ LIS2DH12_SCALE_16G
+- 16g
Definition lis2dh12.h:69
@ LIS2DH12_SCALE_4G
+- 4g
Definition lis2dh12.h:67
@ LIS2DH12_FIFO_MODE_BYPASS
default mode, FIFO is bypassed
Definition lis2dh12.h:230
@ LIS2DH12_FIFO_MODE_STREAM
Stream mode, oldest values get overwritten.
Definition lis2dh12.h:232
@ LIS2DH12_FIFO_MODE_FIFOMODE
normal FIFO mode, stops if FIFO is full
Definition lis2dh12.h:231
@ LIS2DH12_FIFO_MODE_STREAMtoFIFO
Stream mode and on interrupt jumps to FIFO mode.
Definition lis2dh12.h:233
@ LIS2DH12_NODEV
unable to talk to device
Definition lis2dh12.h:188
@ LIS2DH12_NODATA
no data available
Definition lis2dh12.h:191
@ LIS2DH12_NOBUS
bus interface error
Definition lis2dh12.h:187
@ LIS2DH12_OK
everything was fine
Definition lis2dh12.h:186
@ LIS2DH12_NOINT
wrong interrupt line (has to be LIS2DH12_INT1 or LIS2DH12_INT2)
Definition lis2dh12.h:189
@ LIS2DH12_INT1
first interrupt line
Definition lis2dh12.h:198
@ LIS2DH12_INT2
second interrupt line
Definition lis2dh12.h:199
@ LIS2DH12_HP_FREQ_DIV100
cutoff freq is ODR divided by 100
Definition lis2dh12.h:141
@ LIS2DH12_HP_FREQ_DIV200
cutoff freq is ODR divided by 200
Definition lis2dh12.h:142
@ LIS2DH12_HP_FREQ_DIV50
cutoff freq is ODR divided by 50
Definition lis2dh12.h:140
@ LIS2DH12_HP_FREQ_DIV400
cutoff freq is ODR divided by 400
Definition lis2dh12.h:143
@ LIS2DH12_RATE_400HZ
sample with 400Hz @ all resolutions
Definition lis2dh12.h:83
@ LIS2DH12_RATE_200HZ
sample with 200Hz @ all resolutions
Definition lis2dh12.h:82
@ LIS2DH12_RATE_1620HZ
sample with 1620HZ @ 8-bit
Definition lis2dh12.h:84
@ LIS2DH12_RATE_VERYHIGH
sample with 1344Hz @ High resolution or \ 5376Hz @ 8-bit
Definition lis2dh12.h:85
@ LIS2DH12_RATE_50HZ
sample with 50Hz @ all resolutions
Definition lis2dh12.h:80
@ LIS2DH12_RATE_25HZ
sample with 25Hz @ all resolutions
Definition lis2dh12.h:79
@ LIS2DH12_RATE_1HZ
sample with 1Hz @ all resolutions
Definition lis2dh12.h:77
@ LIS2DH12_RATE_10HZ
sample with 10Hz @ all resolutions
Definition lis2dh12.h:78
@ LIS2DH12_RATE_100HZ
sample with 100Hz @ all resolutions
Definition lis2dh12.h:81
@ LIS2DH12_POWER_LOW
8-bit mode
Definition lis2dh12.h:95
@ LIS2DH12_POWER_DOWN
power down the device
Definition lis2dh12.h:94
@ LIS2DH12_POWER_NORMAL
10-bit mode
Definition lis2dh12.h:96
@ LIS2DH12_POWER_HIGH
12-bit mode
Definition lis2dh12.h:97
@ LIS2DH12_HP_MODE_NORMAL
normal mode, reset by reading REG_REFERENCE
Definition lis2dh12.h:131
@ LIS2DH12_HP_MODE_REFERENCE
uses the reference signal for filtering
Definition lis2dh12.h:132
@ LIS2DH12_HP_MODE_AUTORESET
automatically resets on interrupt generation
Definition lis2dh12.h:133
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition i2c.h:144
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:162
bool enable_DOUBLE
otherwise single click for given axis are enabled
Definition lis2dh12.h:163
uint8_t TIME_latency
set number of ODR cycles for latency after a click
Definition lis2dh12.h:171
bool noINT_latency
if "0" interrupt stays high for TIME_latency setting \ if "1" interrupt stays high until CLICK_SRC is...
Definition lis2dh12.h:167
uint8_t TIME_window
set number of ODR cycles for window between clicks
Definition lis2dh12.h:172
bool enable_Y_CLICK
enable double pr single click for Y axes
Definition lis2dh12.h:165
bool enable_X_CLICK
enable double pr single click for X axes
Definition lis2dh12.h:164
uint8_t CLICK_thold
set click threshold
Definition lis2dh12.h:169
uint8_t TIME_limit
set number of ODR cycles for time limit over threshold value
Definition lis2dh12.h:170
bool enable_Z_CLICK
enable double pr single click for Z axes
Definition lis2dh12.h:166
LIS2DH12 FIFO config values.
Definition lis2dh12.h:239
bool FIFO_set_INT2
sets the FIFO interrupt to INT2, otherwise INT1
Definition lis2dh12.h:242
uint8_t FIFO_watermark
set the FIFO watermark level
Definition lis2dh12.h:241
lis2dh12_fifo_mode_t FIFO_mode
set FIFO mode
Definition lis2dh12.h:240
LIS2DH12 high pass config values.
Definition lis2dh12.h:149
bool INT2_enable
enables filter for AOI on interrupt 2
Definition lis2dh12.h:155
bool CLICK_enable
enables filter for click data
Definition lis2dh12.h:153
bool INT1_enable
enables filter for AOI on interrupt 1
Definition lis2dh12.h:154
lis2dh12_hp_mode_t Highpass_mode
set the High pass mode
Definition lis2dh12.h:150
lis2dh12_hp_freq_t Highpass_freq
set the High pass cutoff frequency \ related to device rate
Definition lis2dh12.h:151
bool DATA_OUT_enable
enables filter for data output
Definition lis2dh12.h:156
Parameter for interrupt configuration.
Definition lis2dh12.h:205
uint8_t int_config
values for configuration
Definition lis2dh12.h:206
uint8_t int_threshold
the threshold for triggering interrupt, threshold in range 0-127
Definition lis2dh12.h:207
uint8_t int_type
values for type of interrupts
Definition lis2dh12.h:211
uint8_t int_duration
time between two interrupts ODR section in CTRL_REG1, duration in range 0-127
Definition lis2dh12.h:209
LIS2DH12 configuration parameters.
Definition lis2dh12.h:110
lis2dh12_resolution_t resolution
resolution used
Definition lis2dh12.h:124
gpio_t cs
connected chip select pin
Definition lis2dh12.h:113
spi_t spi
SPI bus the device is connected to.
Definition lis2dh12.h:112
lis2dh12_rate_t rate
sampling rate used
Definition lis2dh12.h:123
gpio_t int1_pin
first interrupt pin
Definition lis2dh12.h:119
lis2dh12_scale_t scale
sampling sensitivity used
Definition lis2dh12.h:122
gpio_t int2_pin
second interrupt pin
Definition lis2dh12.h:120
LIS2DH12 device descriptor.
Definition lis2dh12.h:178
const lis2dh12_params_t * p
device configuration
Definition lis2dh12.h:179
Definition of the RIOT actuator/sensor interface.
Definition saul.h:283
LIS2DH12 FIFO data struct.
Definition lis2dh12.h:217
int16_t y
Y data in mili-g.
Definition lis2dh12.h:220
int16_t z
Z data in mili-g.
Definition lis2dh12.h:221
int16_t x
X data in mili-g.
Definition lis2dh12.h:219
int16_t data[3]
x, y, z data in mili-g
Definition lis2dh12.h:223