Driver for the STM LIS2DH12 accelerometer. More...

Detailed Description

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...
 

Macros

#define LIS2DH12_ADDR_DEFAULT   (0x19)
 Default I2C slave address for LIS2DH12 devices.
 

Enumerations

enum  lis2dh12_scale_t { LIS2DH12_SCALE_2G = 0x00, LIS2DH12_SCALE_4G = 0x10, LIS2DH12_SCALE_8G = 0x20, LIS2DH12_SCALE_16G = 0x30 }
 Available scale values. More...
 
enum  lis2dh12_rate_t {
  LIS2DH12_RATE_1HZ = 0x17, LIS2DH12_RATE_10HZ = 0x27, LIS2DH12_RATE_25HZ = 0x37, LIS2DH12_RATE_50HZ = 0x47,
  LIS2DH12_RATE_100HZ = 0x57, LIS2DH12_RATE_200HZ = 0x67, LIS2DH12_RATE_400HZ = 0x77
}
 Available sampling rates. More...
 
enum  { LIS2DH12_OK = 0, LIS2DH12_NOBUS = -1, LIS2DH12_NODEV = -2 }
 Status and error return codes. More...
 

Functions

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.
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Status and error return codes.

Enumerator
LIS2DH12_OK 

everything was fine

LIS2DH12_NOBUS 

bus interface error

LIS2DH12_NODEV 

unable to talk to device

Definition at line 113 of file lis2dh12.h.

◆ lis2dh12_rate_t

Available sampling rates.

Note
The device does also support some additional rates for specific low- power modes, but those are as of now not supported by this driver
Enumerator
LIS2DH12_RATE_1HZ 

sample with 1Hz

LIS2DH12_RATE_10HZ 

sample with 10Hz

LIS2DH12_RATE_25HZ 

sample with 25Hz

LIS2DH12_RATE_50HZ 

sample with 50Hz

LIS2DH12_RATE_100HZ 

sample with 100Hz

LIS2DH12_RATE_200HZ 

sample with 200Hz

LIS2DH12_RATE_400HZ 

sample with 400Hz

Definition at line 77 of file lis2dh12.h.

◆ 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.

Function Documentation

◆ lis2dh12_init()

int lis2dh12_init ( lis2dh12_t dev,
const lis2dh12_params_t params 
)

Initialize the given LIS2DH12 sensor device.

Parameters
[out]devdevice descriptor
[in]paramsstatic device configuration
Returns
LIS2DH12_OK on success
LIS2DH12_NOBUS on bus errors
LIS2DH12_NODEV if no LIS2DH12 device was found on the bus

◆ lis2dh12_poweroff()

int lis2dh12_poweroff ( const lis2dh12_t dev)

Power off the given device.

Parameters
[in]devdevice descriptor
Returns
LIS2DH12_OK on success
LIS2DH12_NOBUS on bus error

◆ lis2dh12_poweron()

int lis2dh12_poweron ( const lis2dh12_t dev)

Power on the given device.

Parameters
[in]devdevice descriptor
Returns
LIS2DH12_OK on success
LIS2DH12_NOBUS on bus error

◆ lis2dh12_read()

int lis2dh12_read ( const lis2dh12_t dev,
int16_t *  data 
)

Read acceleration data from the given device.

Parameters
[in]devdevice descriptor
[out]dataacceleration data in mili-g, MUST hold 3 values
Returns
LIS2DH12_OK on success
LIS2DH12_NOBUS on bus error