ruuvi.drivers.c
${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
|
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... | |
Implement rd_sensor_t functions on LIS2DH12.
The implementation supports different resolutions, samplerates, high-passing, activity interrupt and FIFO.
#define LIS_SUCCESS (0) |
No error in LIS driver.
Definition at line 63 of file ruuvi_interface_lis2dh12.h.
#define RI_LIS2DH12_DEFAULT_RESOLUTION (10U) |
Resolution used on "default" setting.
Definition at line 62 of file ruuvi_interface_lis2dh12.h.
#define RI_LIS2DH12_DEFAULT_SCALE (2U) |
Scale used on "default" setting.
Definition at line 60 of file ruuvi_interface_lis2dh12.h.
#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.
#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.
#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.
#define SELF_TEST_SAMPLES_NUM (5) |
5 samples
Definition at line 65 of file ruuvi_interface_lis2dh12.h.
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.
[in] | enable | True to enable interrupt, false to disable interrupt |
[in,out] | 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 |
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.
rd_status_t ri_lis2dh12_data_get | ( | rd_sensor_data_t *const | data | ) |
Definition at line 957 of file ruuvi_interface_lis2dh12.c.
rd_status_t ri_lis2dh12_dsp_get | ( | uint8_t * | dsp, |
uint8_t * | parameter | ||
) |
Definition at line 688 of file ruuvi_interface_lis2dh12.c.
rd_status_t ri_lis2dh12_dsp_set | ( | uint8_t * | dsp, |
uint8_t * | parameter | ||
) |
Definition at line 613 of file ruuvi_interface_lis2dh12.c.
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.
[in] | enable | True to enable interrupt, false to disable interrupt |
Definition at line 1088 of file ruuvi_interface_lis2dh12.c.
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.
[in,out] | num_elements | Input: number of elements in data. Output: Number of elements placed in data |
[out] | data | array with num_elements slots. |
Definition at line 1031 of file ruuvi_interface_lis2dh12.c.
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.
[in] | enable | true to enable FIFO, false to disable or reset FIFO. |
Definition at line 1014 of file ruuvi_interface_lis2dh12.c.
rd_status_t ri_lis2dh12_init | ( | rd_sensor_t * | acceleration_sensor, |
rd_bus_t | bus, | ||
uint8_t | handle | ||
) |
Definition at line 262 of file ruuvi_interface_lis2dh12.c.
rd_status_t ri_lis2dh12_mode_get | ( | uint8_t * | mode | ) |
Definition at line 781 of file ruuvi_interface_lis2dh12.c.
rd_status_t ri_lis2dh12_mode_set | ( | uint8_t * | mode | ) |
Definition at line 728 of file ruuvi_interface_lis2dh12.c.
rd_status_t ri_lis2dh12_resolution_get | ( | uint8_t * | resolution | ) |
Definition at line 503 of file ruuvi_interface_lis2dh12.c.
rd_status_t ri_lis2dh12_resolution_set | ( | uint8_t * | resolution | ) |
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.
rd_status_t ri_lis2dh12_samplerate_get | ( | uint8_t * | samplerate | ) |
Definition at line 418 of file ruuvi_interface_lis2dh12.c.
rd_status_t ri_lis2dh12_samplerate_set | ( | uint8_t * | samplerate | ) |
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.
rd_status_t ri_lis2dh12_scale_get | ( | uint8_t * | scale | ) |
Definition at line 570 of file ruuvi_interface_lis2dh12.c.
rd_status_t ri_lis2dh12_scale_set | ( | uint8_t * | scale | ) |
Setup lis2dh12 scale. Scale is rounded up, i.e. "at least this much"
Definition at line 538 of file ruuvi_interface_lis2dh12.c.
rd_status_t ri_lis2dh12_uninit | ( | rd_sensor_t * | acceleration_sensor, |
rd_bus_t | bus, | ||
uint8_t | handle | ||
) |
Definition at line 349 of file ruuvi_interface_lis2dh12.c.