ruuvi.drivers.c  ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
LIS2DH12 Inteface

Implement rd_sensor_t functions on LIS2DH12. More...

Files

file  ruuvi_interface_lis2dh12.h
 

Data Structures

struct  ri_lis2dh12_dev
 context for LIS2DH12 More...
 

Macros

#define RI_LIS2DH12_SELFTEST_DIFF_MIN   (17)
 Minimum counts of self-test change in 10 bit resolution 2 G scale, ref datasheet. More...
 
#define RI_LIS2DH12_SELFTEST_DIFF_MAX   (360)
 Maximum counts of self-test change in 10 bit resolution 2 G scale, ref datasheet. More...
 
#define RI_LIS2DH12_DEFAULT_SCALE   (2U)
 Scale used on "default" setting. More...
 
#define RI_LIS2DH12_DEFAULT_RESOLUTION   (10U)
 Resolution used on "default" setting. More...
 
#define LIS_SUCCESS   (0)
 No error in LIS driver. More...
 
#define SELF_TEST_DELAY_MS   (100U)
 At least 3 samples at 400 Hz, but recommended value 100. More...
 
#define SELF_TEST_SAMPLES_NUM   (5)
 5 samples More...
 

Functions

rd_status_t ri_lis2dh12_init (rd_sensor_t *acceleration_sensor, rd_bus_t bus, uint8_t handle)
 rd_sensor_init_fp More...
 
rd_status_t ri_lis2dh12_uninit (rd_sensor_t *acceleration_sensor, rd_bus_t bus, uint8_t handle)
 rd_sensor_init_fp More...
 
rd_status_t ri_lis2dh12_samplerate_set (uint8_t *samplerate)
 rd_sensor_setup_fp More...
 
rd_status_t ri_lis2dh12_samplerate_get (uint8_t *samplerate)
 rd_sensor_setup_fp More...
 
rd_status_t ri_lis2dh12_resolution_set (uint8_t *resolution)
 rd_sensor_setup_fp More...
 
rd_status_t ri_lis2dh12_resolution_get (uint8_t *resolution)
 rd_sensor_setup_fp More...
 
rd_status_t ri_lis2dh12_scale_set (uint8_t *scale)
 rd_sensor_setup_fp More...
 
rd_status_t ri_lis2dh12_scale_get (uint8_t *scale)
 rd_sensor_setup_fp More...
 
rd_status_t ri_lis2dh12_dsp_set (uint8_t *dsp, uint8_t *parameter)
 rd_sensor_dsp_fp More...
 
rd_status_t ri_lis2dh12_dsp_get (uint8_t *dsp, uint8_t *parameter)
 rd_sensor_dsp_fp More...
 
rd_status_t ri_lis2dh12_mode_set (uint8_t *)
 rd_sensor_setup_fp More...
 
rd_status_t ri_lis2dh12_mode_get (uint8_t *)
 rd_sensor_setup_fp More...
 
rd_status_t ri_lis2dh12_data_get (rd_sensor_data_t *const data)
 rd_sensor_data_fp More...
 
rd_status_t ri_lis2dh12_fifo_use (const bool enable)
 Enable 32-level FIFO in LIS2DH12 If FIFO is enabled, values are stored on LIS2DH12 FIFO and oldest element is returned on data read. More...
 
rd_status_t ri_lis2dh12_fifo_read (size_t *num_elements, rd_sensor_data_t *data)
 Read FIFO Reads up to num_elements data points from FIFO and populates pointer data with them. More...
 
rd_status_t ri_lis2dh12_fifo_interrupt_use (const bool enable)
 Enable FIFO full interrupt on LIS2DH12. Triggers as ACTIVE HIGH interrupt once FIFO has 32 elements. More...
 
rd_status_t ri_lis2dh12_activity_interrupt_use (const bool enable, float *limit_g)
 Enable activity interrupt on LIS2DH12. More...
 

Detailed Description

Implement rd_sensor_t functions on LIS2DH12.

The implementation supports different resolutions, samplerates, high-passing, activity interrupt and FIFO.

Macro Definition Documentation

◆ LIS_SUCCESS

#define LIS_SUCCESS   (0)

No error in LIS driver.

Definition at line 63 of file ruuvi_interface_lis2dh12.h.

◆ RI_LIS2DH12_DEFAULT_RESOLUTION

#define RI_LIS2DH12_DEFAULT_RESOLUTION   (10U)

Resolution used on "default" setting.

Definition at line 62 of file ruuvi_interface_lis2dh12.h.

◆ RI_LIS2DH12_DEFAULT_SCALE

#define RI_LIS2DH12_DEFAULT_SCALE   (2U)

Scale used on "default" setting.

Definition at line 60 of file ruuvi_interface_lis2dh12.h.

◆ RI_LIS2DH12_SELFTEST_DIFF_MAX

#define RI_LIS2DH12_SELFTEST_DIFF_MAX   (360)

Maximum counts of self-test change in 10 bit resolution 2 G scale, ref datasheet.

Definition at line 58 of file ruuvi_interface_lis2dh12.h.

◆ RI_LIS2DH12_SELFTEST_DIFF_MIN

#define RI_LIS2DH12_SELFTEST_DIFF_MIN   (17)

Minimum counts of self-test change in 10 bit resolution 2 G scale, ref datasheet.

Definition at line 56 of file ruuvi_interface_lis2dh12.h.

◆ SELF_TEST_DELAY_MS

#define SELF_TEST_DELAY_MS   (100U)

At least 3 samples at 400 Hz, but recommended value 100.

Definition at line 64 of file ruuvi_interface_lis2dh12.h.

◆ SELF_TEST_SAMPLES_NUM

#define SELF_TEST_SAMPLES_NUM   (5)

5 samples

Definition at line 65 of file ruuvi_interface_lis2dh12.h.

Function Documentation

◆ ri_lis2dh12_activity_interrupt_use()

rd_status_t ri_lis2dh12_activity_interrupt_use ( const bool  enable,
float *const  limit_g 
)

Enable activity interrupt on LIS2DH12.

Triggers as ACTIVE HIGH interrupt while detected movement is above threshold limit_g Axes are high-passed for this interrupt, i.e. gravity won't trigger the interrupt Axes are examined individually, compound acceleration won't trigger the interrupt.

Parameters
[in]enableTrue to enable interrupt, false to disable interrupt
[in,out]limit_gDesired acceleration to trigger the interrupt. Is considered as "at least", the acceleration is rounded up to next value. Is written with value that was set to interrupt
Returns
RD_SUCCESS on success
RD_ERROR_NULL if limit_g is NULL
RD_INVALID_STATE if acceleration limit is higher than maximum scale
error code from stack on other error.

Enable activity interrupt on LIS2DH12 Triggers as ACTIVE HIGH interrupt while detected movement is above threshold limit_g Axes are high-passed for this interrupt, i.e. gravity won't trigger the interrupt Axes are examined individually, compound acceleration won't trigger the interrupt.

parameter enable: True to enable interrupt, false to disable interrupt parameter limit_g: Desired acceleration to trigger the interrupt. Is considered as "at least", the acceleration is rounded up to next value. Is written with value that was set to interrupt returns: RD_SUCCESS on success returns: RD_ERROR_INVALID_STATE if acceleration limit is higher than maximum scale returns: error code from stack on error.

Definition at line 1123 of file ruuvi_interface_lis2dh12.c.

◆ ri_lis2dh12_data_get()

rd_status_t ri_lis2dh12_data_get ( rd_sensor_data_t *const  data)

rd_sensor_data_fp

Definition at line 957 of file ruuvi_interface_lis2dh12.c.

◆ ri_lis2dh12_dsp_get()

rd_status_t ri_lis2dh12_dsp_get ( uint8_t *  dsp,
uint8_t *  parameter 
)

rd_sensor_dsp_fp

Definition at line 688 of file ruuvi_interface_lis2dh12.c.

◆ ri_lis2dh12_dsp_set()

rd_status_t ri_lis2dh12_dsp_set ( uint8_t *  dsp,
uint8_t *  parameter 
)

rd_sensor_dsp_fp

Definition at line 613 of file ruuvi_interface_lis2dh12.c.

◆ ri_lis2dh12_fifo_interrupt_use()

rd_status_t ri_lis2dh12_fifo_interrupt_use ( const bool  enable)

Enable FIFO full interrupt on LIS2DH12. Triggers as ACTIVE HIGH interrupt once FIFO has 32 elements.

Parameters
[in]enableTrue to enable interrupt, false to disable interrupt
Returns
RD_SUCCESS on success, error code from stack otherwise.

Definition at line 1088 of file ruuvi_interface_lis2dh12.c.

◆ ri_lis2dh12_fifo_read()

rd_status_t ri_lis2dh12_fifo_read ( size_t *  num_elements,
rd_sensor_data_t data 
)

Read FIFO Reads up to num_elements data points from FIFO and populates pointer data with them.

Parameters
[in,out]num_elementsInput: number of elements in data. Output: Number of elements placed in data
[out]dataarray with num_elements slots.
Returns
RD_SUCCESS on success
RD_ERROR_NULL if either parameter is NULL
RD_ERROR_INVALID_STATE if FIFO is not in use
error code from stack on error.

Definition at line 1031 of file ruuvi_interface_lis2dh12.c.

◆ ri_lis2dh12_fifo_use()

rd_status_t ri_lis2dh12_fifo_use ( const bool  enable)

Enable 32-level FIFO in LIS2DH12 If FIFO is enabled, values are stored on LIS2DH12 FIFO and oldest element is returned on data read.

Parameters
[in]enabletrue to enable FIFO, false to disable or reset FIFO.
Returns
RD_SUCCESS on success, error code from stack on error.

Definition at line 1014 of file ruuvi_interface_lis2dh12.c.

◆ ri_lis2dh12_init()

rd_status_t ri_lis2dh12_init ( rd_sensor_t acceleration_sensor,
rd_bus_t  bus,
uint8_t  handle 
)

rd_sensor_init_fp

Definition at line 262 of file ruuvi_interface_lis2dh12.c.

◆ ri_lis2dh12_mode_get()

rd_status_t ri_lis2dh12_mode_get ( uint8_t *  mode)

rd_sensor_setup_fp

Definition at line 781 of file ruuvi_interface_lis2dh12.c.

◆ ri_lis2dh12_mode_set()

rd_status_t ri_lis2dh12_mode_set ( uint8_t *  mode)

rd_sensor_setup_fp

Definition at line 728 of file ruuvi_interface_lis2dh12.c.

◆ ri_lis2dh12_resolution_get()

rd_status_t ri_lis2dh12_resolution_get ( uint8_t *  resolution)

rd_sensor_setup_fp

Definition at line 503 of file ruuvi_interface_lis2dh12.c.

◆ ri_lis2dh12_resolution_set()

rd_status_t ri_lis2dh12_resolution_set ( uint8_t *  resolution)

rd_sensor_setup_fp

Setup resolution. Resolution is rounded up, i.e. "please give at least this many bits"

Definition at line 476 of file ruuvi_interface_lis2dh12.c.

◆ ri_lis2dh12_samplerate_get()

rd_status_t ri_lis2dh12_samplerate_get ( uint8_t *  samplerate)

rd_sensor_setup_fp

Definition at line 418 of file ruuvi_interface_lis2dh12.c.

◆ ri_lis2dh12_samplerate_set()

rd_status_t ri_lis2dh12_samplerate_set ( uint8_t *  samplerate)

rd_sensor_setup_fp

Set up samplerate. Powers down sensor on SAMPLERATE_STOP, writes value to lis2dh12 only if mode is continous as writing samplerate to sensor starts sampling. MAX is 200 Hz as it can be represented by the configuration format Samplerate is rounded up, i.e. "Please give me at least samplerate F.", 5 is rounded to 10 Hz etc.

Definition at line 381 of file ruuvi_interface_lis2dh12.c.

◆ ri_lis2dh12_scale_get()

rd_status_t ri_lis2dh12_scale_get ( uint8_t *  scale)

rd_sensor_setup_fp

Definition at line 570 of file ruuvi_interface_lis2dh12.c.

◆ ri_lis2dh12_scale_set()

rd_status_t ri_lis2dh12_scale_set ( uint8_t *  scale)

rd_sensor_setup_fp

Setup lis2dh12 scale. Scale is rounded up, i.e. "at least this much"

Definition at line 538 of file ruuvi_interface_lis2dh12.c.

◆ ri_lis2dh12_uninit()

rd_status_t ri_lis2dh12_uninit ( rd_sensor_t acceleration_sensor,
rd_bus_t  bus,
uint8_t  handle 
)

rd_sensor_init_fp

Definition at line 349 of file ruuvi_interface_lis2dh12.c.