Firmware SDK
twr_lis2dh12

Driver for LIS2DH12 3-axis MEMS accelerometer. More...

Data Structures

struct  twr_lis2dh12_result_raw_t
 LIS2DH12 result in raw values. More...
 
struct  twr_lis2dh12_result_g_t
 LIS2DH12 result in g. More...
 
struct  twr_lis2dh12_alarm_t
 LIS2DH12 alarm set structure. More...
 

Typedefs

typedef struct twr_lis2dh12_t twr_lis2dh12_t
 LIS2DH12 instance.
 

Enumerations

enum  twr_lis2dh12_event_t {
  TWR_LIS2DH12_EVENT_ERROR = 0,
  TWR_LIS2DH12_EVENT_UPDATE = 1,
  TWR_LIS2DH12_EVENT_ALARM = 2
}
 Callback events. More...
 
enum  twr_lis2dh12_resolution_t {
  TWR_LIS2DH12_RESOLUTION_10BIT = 0,
  TWR_LIS2DH12_RESOLUTION_12BIT = 1,
  TWR_LIS2DH12_RESOLUTION_8BIT = 2
}
 Resolution and mode. More...
 
enum  twr_lis2dh12_scale_t {
  TWR_LIS2DH12_SCALE_2G = 0,
  TWR_LIS2DH12_SCALE_4G = 1,
  TWR_LIS2DH12_SCALE_8G = 2,
  TWR_LIS2DH12_SCALE_16G = 3
}
 

Functions

bool twr_lis2dh12_init (twr_lis2dh12_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address)
 Initialize LIS2DH12. More...
 
void twr_lis2dh12_set_event_handler (twr_lis2dh12_t *self, void(*event_handler)(twr_lis2dh12_t *, twr_lis2dh12_event_t, void *), void *event_param)
 Set callback function. More...
 
void twr_lis2dh12_set_update_interval (twr_lis2dh12_t *self, twr_tick_t interval)
 Set measurement interval. More...
 
bool twr_lis2dh12_measure (twr_lis2dh12_t *self)
 Start measurement manually. More...
 
bool twr_lis2dh12_get_result_raw (twr_lis2dh12_t *self, twr_lis2dh12_result_raw_t *result_raw)
 Get measured acceleration as raw value. More...
 
bool twr_lis2dh12_get_result_g (twr_lis2dh12_t *self, twr_lis2dh12_result_g_t *result_g)
 Get measured acceleration in g. More...
 
bool twr_lis2dh12_set_alarm (twr_lis2dh12_t *self, twr_lis2dh12_alarm_t *alarm)
 Enable or disable accelerometer threshold alarm. More...
 
bool twr_lis2dh12_set_resolution (twr_lis2dh12_t *self, twr_lis2dh12_resolution_t resolution)
 Set resolution. More...
 
bool twr_lis2dh12_set_scale (twr_lis2dh12_t *self, twr_lis2dh12_scale_t scale)
 Set scale. More...
 

Detailed Description

Driver for LIS2DH12 3-axis MEMS accelerometer.

Enumeration Type Documentation

◆ twr_lis2dh12_event_t

Callback events.

Enumerator
TWR_LIS2DH12_EVENT_ERROR 

Error event.

TWR_LIS2DH12_EVENT_UPDATE 

Update event.

TWR_LIS2DH12_EVENT_ALARM 

Alarm event.

Definition at line 14 of file twr_lis2dh12.h.

◆ twr_lis2dh12_resolution_t

Resolution and mode.

Enumerator
TWR_LIS2DH12_RESOLUTION_10BIT 

10-bit data output (Normal mode) (Default)

TWR_LIS2DH12_RESOLUTION_12BIT 

12-bit data output (High-resolution mode)

TWR_LIS2DH12_RESOLUTION_8BIT 

8-bit data output (Low-power mode)

Definition at line 29 of file twr_lis2dh12.h.

◆ twr_lis2dh12_scale_t

Enumerator
TWR_LIS2DH12_SCALE_2G 

±2 g (Default)

TWR_LIS2DH12_SCALE_4G 

±4 g.

TWR_LIS2DH12_SCALE_8G 

±8 g.

TWR_LIS2DH12_SCALE_16G 

±16 g.

Definition at line 42 of file twr_lis2dh12.h.

Function Documentation

◆ twr_lis2dh12_get_result_g()

bool twr_lis2dh12_get_result_g ( twr_lis2dh12_t self,
twr_lis2dh12_result_g_t result_g 
)

Get measured acceleration in g.

Parameters
[in]selfInstance
[in]result_gPointer to structure where result will be stored
Returns
true When value is valid
false When value is invalid

Definition at line 92 of file twr_lis2dh12.c.

Here is the call graph for this function:

◆ twr_lis2dh12_get_result_raw()

bool twr_lis2dh12_get_result_raw ( twr_lis2dh12_t self,
twr_lis2dh12_result_raw_t result_raw 
)

Get measured acceleration as raw value.

Parameters
[in]selfInstance
[in]result_rawPointer to structure where result will be stored
Returns
true When value is valid
false When value is invalid

Definition at line 85 of file twr_lis2dh12.c.

Referenced by twr_lis2dh12_get_result_g().

Here is the caller graph for this function:

◆ twr_lis2dh12_init()

bool twr_lis2dh12_init ( twr_lis2dh12_t self,
twr_i2c_channel_t  i2c_channel,
uint8_t  i2c_address 
)

Initialize LIS2DH12.

Parameters
[in]selfInstance
[in]i2c_channelI2C channel
[in]i2c_addressI2C device address

Definition at line 25 of file twr_lis2dh12.c.

Here is the call graph for this function:

◆ twr_lis2dh12_measure()

bool twr_lis2dh12_measure ( twr_lis2dh12_t self)

Start measurement manually.

Parameters
[in]selfInstance
Returns
true On success
false When other measurement is in progress

Definition at line 71 of file twr_lis2dh12.c.

Referenced by twr_lis2dh12_get_result_g(), twr_lis2dh12_set_alarm(), twr_lis2dh12_set_scale(), and twr_lis2dh12_set_update_interval().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_lis2dh12_set_alarm()

bool twr_lis2dh12_set_alarm ( twr_lis2dh12_t self,
twr_lis2dh12_alarm_t alarm 
)

Enable or disable accelerometer threshold alarm.

Parameters
[in]selfInstance
[in]alarmPointer to structure with alarm configuration, if null then disable the alarm
Returns
true When configuration was successful
false When configuration was not successful

Definition at line 300 of file twr_lis2dh12.c.

Here is the call graph for this function:

◆ twr_lis2dh12_set_event_handler()

void twr_lis2dh12_set_event_handler ( twr_lis2dh12_t self,
void(*)(twr_lis2dh12_t *, twr_lis2dh12_event_t, void *)  event_handler,
void *  event_param 
)

Set callback function.

Parameters
[in]selfInstance
[in]event_handlerFunction address
[in]event_paramOptional event parameter (can be NULL)

Definition at line 49 of file twr_lis2dh12.c.

◆ twr_lis2dh12_set_resolution()

bool twr_lis2dh12_set_resolution ( twr_lis2dh12_t self,
twr_lis2dh12_resolution_t  resolution 
)

Set resolution.

Parameters
[in]selfInstance
[in]resolution
Returns
true When configuration was successful
false When configuration was not successful

Definition at line 393 of file twr_lis2dh12.c.

Here is the call graph for this function:

◆ twr_lis2dh12_set_scale()

bool twr_lis2dh12_set_scale ( twr_lis2dh12_t self,
twr_lis2dh12_scale_t  scale 
)

Set scale.

Parameters
[in]selfInstance
[in]scale
Returns
true When configuration was successful
false When configuration was not successful

Definition at line 404 of file twr_lis2dh12.c.

Here is the call graph for this function:

◆ twr_lis2dh12_set_update_interval()

void twr_lis2dh12_set_update_interval ( twr_lis2dh12_t self,
twr_tick_t  interval 
)

Set measurement interval.

Parameters
[in]selfInstance
[in]intervalMeasurement interval

Definition at line 55 of file twr_lis2dh12.c.

Here is the call graph for this function: