Driver for the STM LIS2DH12 accelerometer. More...
Driver for the STM LIS2DH12 accelerometer.
This device driver provides a minimal interface to LIS2DH12 devices. As of now, it only provides very basic access to the device. The driver configures the device to continuously read the acceleration data with statically defined scale and rate, and with a fixed 10-bit resolution. The LIS2DH12's FIFO is bypassed, so the driver might not be sufficient for use cases where the complete history of readings is of interest.
Also, the current version of the driver supports only interfacing the sensor via SPI. The driver is however written in a way, that adding I2C interface support is quite simple, as all bus related functions (acquire, release, read, write) are cleanly separated in the code.
This driver provides [S]ensor [A]ctuator [U]ber [L]ayer capabilities.
Files | |
file | lis2dh12.h |
Interface definition for the STM LIS2DH12 accelerometer. | |
file | lis2dh12_params.h |
Default configuration for LIS2DH12 devices. | |
file | lis2dh12_internal.h |
Command definition for the LIS2DH12 accelerometer. | |
Data Structures | |
struct | lis2dh12_params_t |
LIS2DH12 configuration parameters. More... | |
struct | lis2dh12_t |
LIS2DH12 device descriptor. More... | |
struct | lis2dh12_int_params_t |
Parameter for interrupt configuration. More... | |
Macros | |
#define | LIS2DH12_ADDR_DEFAULT (0x19) |
Default I2C slave address for LIS2DH12 devices. | |
#define | LIS2DH12_INT_SRC_XL (0x01) |
Status of INT_SRC register. More... | |
#define | LIS2DH12_INT_SRC_XH (0x02) |
X high event has occurred. | |
#define | LIS2DH12_INT_SRC_YL (0x04) |
Y low event has occurred. | |
#define | LIS2DH12_INT_SRC_YH (0x08) |
Y high event has occurred. | |
#define | LIS2DH12_INT_SRC_ZL (0x10) |
Z low event has occurred. | |
#define | LIS2DH12_INT_SRC_ZH (0x20) |
Z high event has occurred. | |
#define | LIS2DH12_INT_SRC_IA (0x40) |
1 if interrupt occurred | |
#define | LIS2DH12_STATUS_XDA (0x01) |
Status of INT_SRC register. More... | |
#define | LIS2DH12_STATUS_YDA (0x02) |
Y-axis new data available. | |
#define | LIS2DH12_STATUS_ZDA (0x04) |
Z-axis new data available. | |
#define | LIS2DH12_STATUS_ZYXDA (0x08) |
on X-, Y-, Z-axis new data available | |
#define | LIS2DH12_STATUS_XOR (0x10) |
X-axis data overrun. | |
#define | LIS2DH12_STATUS_YOR (0x20) |
Y-axis data overrun. | |
#define | LIS2DH12_STATUS_ZOR (0x40) |
Y-axis data overrun. | |
#define | LIS2DH12_STATUS_ZYXOR (0x80) |
on X-, Y-, Z-axis data overrun | |
Functions | |
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. More... | |
int | lis2dh12_read_int_src (const lis2dh12_t *dev, uint8_t *data, uint8_t int_line) |
Read an interrupt event on LIS2DH12 sensor device. More... | |
int | lis2dh12_init (lis2dh12_t *dev, const lis2dh12_params_t *params) |
Initialize the given LIS2DH12 sensor device. More... | |
int | lis2dh12_read (const lis2dh12_t *dev, int16_t *data) |
Read acceleration data from the given device. More... | |
int | lis2dh12_poweron (const lis2dh12_t *dev) |
Power on the given device. More... | |
int | lis2dh12_poweroff (const lis2dh12_t *dev) |
Power off the given device. More... | |
Variables | |
const saul_driver_t | lis2dh12_saul_driver |
Export the SAUL interface for this driver. | |
#define LIS2DH12_INT_SRC_XL (0x01) |
#define LIS2DH12_STATUS_XDA (0x01) |
anonymous enum |
Status and error return codes.
Definition at line 117 of file lis2dh12.h.
anonymous enum |
Enumerator | |
---|---|
LIS2DH12_INT1 | first interrupt line |
LIS2DH12_INT2 | second interrupt line |
Definition at line 129 of file lis2dh12.h.
anonymous enum |
Interrupt config register values.
Definition at line 137 of file lis2dh12.h.
anonymous enum |
Interrupt type values.
Definition at line 151 of file lis2dh12.h.
enum lis2dh12_rate_t |
Available sampling rates.
Definition at line 77 of file lis2dh12.h.
enum lis2dh12_scale_t |
Available scale values.
Enumerator | |
---|---|
LIS2DH12_SCALE_2G | +- 2g |
LIS2DH12_SCALE_4G | +- 4g |
LIS2DH12_SCALE_8G | +- 8g |
LIS2DH12_SCALE_16G | +- 16g |
Definition at line 64 of file lis2dh12.h.
int lis2dh12_init | ( | lis2dh12_t * | dev, |
const lis2dh12_params_t * | params | ||
) |
Initialize the given LIS2DH12 sensor device.
[out] | dev | device descriptor |
[in] | params | static device configuration |
int lis2dh12_poweroff | ( | const lis2dh12_t * | dev | ) |
Power off the given device.
[in] | dev | device descriptor |
int lis2dh12_poweron | ( | const lis2dh12_t * | dev | ) |
Power on the given device.
[in] | dev | device descriptor |
int lis2dh12_read | ( | const lis2dh12_t * | dev, |
int16_t * | data | ||
) |
Read acceleration data from the given device.
[in] | dev | device descriptor |
[out] | data | acceleration data in mili-g, MUST hold 3 values |
int lis2dh12_read_int_src | ( | const lis2dh12_t * | dev, |
uint8_t * | data, | ||
uint8_t | int_line | ||
) |
Read an interrupt event on LIS2DH12 sensor device.
[in] | dev | device descriptor |
[out] | data | device interrupt data |
[in] | int_line | number of interrupt line (LIS2DH12_INT1 or LIS2DH12_INT2) |
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.
[in] | dev | device descriptor |
[in] | params | device interrupt configuration |
[in] | int_line | number of interrupt line (LIS2DH12_INT1 or LIS2DH12_INT2) |