ruuvi.drivers.c  ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
ruuvi_interface_lis2dh12.c File Reference
#include "ruuvi_driver_enabled_modules.h"
#include "ruuvi_driver_error.h"
#include "ruuvi_driver_sensor.h"
#include "ruuvi_interface_lis2dh12.h"
#include "ruuvi_interface_spi_lis2dh12.h"
#include "ruuvi_interface_yield.h"
#include "ruuvi_interface_log.h"
#include "lis2dh12_reg.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

Go to the source code of this file.

Macros

#define LOGD(fmt, ...)
 
#define NUM_AXIS   (3U)
 X, Y, Z. More...
 
#define NM_BIT_DIVEDER   (64U)
 Normal mode uses 10 bits in 16 bit field, leading to 2^6 factor in results. More...
 
#define MOTION_THRESHOLD_MAX   (0x7FU)
 Highest threshold value allowed. More...
 
#define PWRON_DELAY_MS   (10U)
 Milliseconds from poweron to sensor rdy. 5ms typ. More...
 
#define VERIFY_SENSOR_SLEEPS()
 Macro for checking that sensor is in sleep mode before configuration. More...
 

Functions

rd_status_t ri_lis2dh12_init (rd_sensor_t *p_sensor, rd_bus_t bus, uint8_t handle)
 rd_sensor_init_fp More...
 
rd_status_t ri_lis2dh12_uninit (rd_sensor_t *p_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 *mode)
 rd_sensor_setup_fp More...
 
rd_status_t ri_lis2dh12_mode_get (uint8_t *mode)
 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 *p_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 *const limit_g)
 Enable activity interrupt on LIS2DH12. More...
 

Detailed Description

Author
Otso Jousimaa otso@.nosp@m.ojou.nosp@m.sima..nosp@m.net
Date
2019-10-11

Implementation for LIS2DH12 basic usage. The implementation supports different resolutions, samplerates, high-passing, activity interrupt and FIFO.

Requires STM lis2dh12 driver, available on GitHub under BSD-3 license. Requires "application_config.h", will only get compiled if LIS2DH12_ACCELERATION is defined. Requires floats enabled in application.

Definition in file ruuvi_interface_lis2dh12.c.

Macro Definition Documentation

◆ LOGD

#define LOGD (   fmt,
  ... 
)

Definition at line 28 of file ruuvi_interface_lis2dh12.c.

◆ MOTION_THRESHOLD_MAX

#define MOTION_THRESHOLD_MAX   (0x7FU)

Highest threshold value allowed.

Definition at line 52 of file ruuvi_interface_lis2dh12.c.

◆ NM_BIT_DIVEDER

#define NM_BIT_DIVEDER   (64U)

Normal mode uses 10 bits in 16 bit field, leading to 2^6 factor in results.

Definition at line 51 of file ruuvi_interface_lis2dh12.c.

◆ NUM_AXIS

#define NUM_AXIS   (3U)

X, Y, Z.

Definition at line 50 of file ruuvi_interface_lis2dh12.c.

◆ PWRON_DELAY_MS

#define PWRON_DELAY_MS   (10U)

Milliseconds from poweron to sensor rdy. 5ms typ.

Definition at line 53 of file ruuvi_interface_lis2dh12.c.

◆ VERIFY_SENSOR_SLEEPS

#define VERIFY_SENSOR_SLEEPS ( )
Value:
do { \
uint8_t MACRO_MODE = 0; \
ri_lis2dh12_mode_get(&MACRO_MODE); \
if(RD_SENSOR_CFG_SLEEP != MACRO_MODE) { return RD_ERROR_INVALID_STATE; } \
} while(0)
#define RD_ERROR_INVALID_STATE
Invalid state, operation disallowed in this state.
#define RD_SENSOR_CFG_SLEEP
Sensor should go to sleep immediately.

Macro for checking that sensor is in sleep mode before configuration.

Definition at line 56 of file ruuvi_interface_lis2dh12.c.