LIS2DUXS12 Part Drivers API Documentation - Core

This page documents the API of the Core component of the LIS2DUXS12 Part Drivers.

An overview of the driver is also available here: main_doc .

Functions

Functions

lis2duxs12_drv_status_t lis2duxs12_drv_init ( lis2duxs12_object_t * p_obj , uint32_t id )

initialize the LIS2DUXS12 sensor.

Parameters :
  • p_obj – the device object

  • id – the device instance id

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_deinit ( lis2duxs12_object_t * p_obj )

deinitialize the LIS2DUXS12 sensor.

Parameters :

p_obj – the device instance object

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_exit_deep_power_down_i2c ( lis2duxs12_object_t * p_obj )

exit from deep power down in I2C.

Parameters :

p_obj – the device instance object

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_exit_deep_power_down_spi ( lis2duxs12_object_t * p_obj )

Exit from deep power down in SPI.

Parameters :

p_obj – the device instance object

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_readid ( lis2duxs12_object_t * p_obj , uint8_t * id )

read component ID.

Parameters :
  • p_obj – the device instance object

  • id – the WHO_AM_I value

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_enable ( lis2duxs12_object_t * p_obj )

enable the LIS2DUXS12 accelerometer sensor.

Parameters :

p_obj – the device instance object

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_disable ( lis2duxs12_object_t * p_obj )

disable the LIS2DUXS12 accelerometer sensor.

Parameters :

p_obj – the device instance object

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_get_sensitivity ( lis2duxs12_object_t * p_obj , float_t * sensitivity )

get the LIS2DUXS12 accelerometer sensor sensitivity.

Parameters :
  • p_obj – the device instance object

  • sensitivity – pointer

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_get_output_data_rate ( lis2duxs12_object_t * p_obj , float_t * odr )

get the LIS2DUXS12 accelerometer sensor output data rate.

Parameters :
  • p_obj – the device instance object

  • odr – pointer to where the output data rate is written

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_set_output_data_rate ( lis2duxs12_object_t * p_obj , float_t odr )

set the LIS2DUXS12 accelerometer sensor output data rate.

Parameters :
  • p_obj – the device instance object

  • odr – the output data rate value to be set

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_set_output_data_rate_with_mode ( lis2duxs12_object_t * p_obj , float_t odr , lis2duxs12_power_mode_t power )

set the LIS2DUXS12 accelerometer sensor output data rate.

Parameters :
  • p_obj – the device instance object

  • odr – the output data rate value to be set

  • power – the ultra low power option

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_get_fullscale ( lis2duxs12_object_t * p_obj , float_t * fullscale )

get the LIS2DUXS12 accelerometer sensor full scale.

Parameters :
  • p_obj – the device instance object

  • fullscale – pointer where the full scale is written

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_set_fullscale ( lis2duxs12_object_t * p_obj , float_t fullscale )

set the LIS2DUXS12 accelerometer sensor full scale.

Parameters :
  • p_obj – the device instance object

  • fullscale – the functional full scale to be set

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_get_axesraw ( lis2duxs12_object_t * p_obj , lis2duxs12_axesraw_t * value )

get the LIS2DUXS12 accelerometer sensor raw axes.

Parameters :
  • p_obj – the device instance object

  • value – pointer where the raw axis values are written

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_get_axes ( lis2duxs12_object_t * p_obj , lis2duxs12_axes_t * acceleration )

get the LIS2DUXS12 accelerometer sensor axes.

Parameters :
  • p_obj – the device instance object

  • acceleration – pointer where the axis values are written

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_read_reg ( lis2duxs12_object_t * p_obj , uint8_t reg , uint8_t * data )

get the LIS2DUXS12 register value.

Parameters :
  • p_obj – the device instance object

  • reg – address to be read

  • data – pointer where the value is written

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_write_reg ( lis2duxs12_object_t * p_obj , uint8_t reg , uint8_t data )

Set the LIS2DUXS12 register value.

Parameters :
  • p_obj – the device instance object

  • reg – address to be written

  • data – value to be written

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_set_interrupt_latch ( lis2duxs12_object_t * p_obj , uint8_t status )
lis2duxs12_drv_status_t lis2duxs12_drv_acc_enable_drdy_interrupt ( lis2duxs12_object_t * p_obj )
lis2duxs12_drv_status_t lis2duxs12_drv_acc_disable_drdy_interrupt ( lis2duxs12_object_t * p_obj )
lis2duxs12_drv_status_t lis2duxs12_drv_acc_set_selftest ( lis2duxs12_object_t * p_obj , uint8_t val )
lis2duxs12_drv_status_t lis2duxs12_drv_acc_get_drdy_status ( lis2duxs12_object_t * p_obj , uint8_t * status )

get the LIS2DUXS12 ACC data-ready bit value.

Parameters :
  • p_obj – the device instance object

  • status – the status of the data-ready bit

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_get_init_status ( lis2duxs12_object_t * p_obj , uint8_t * status )

get the LIS2DUXS12 ACC initialization status.

Parameters :
  • p_obj – the device instance object

  • status – 1 if initialized, 0 otherwise

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_get_event_status ( lis2duxs12_object_t * p_obj , lis2duxs12_event_status_t * status )

get the status of all hardware events.

Parameters :
  • p_obj – the device instance object

  • status – the status of all hardware events

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_enable_wake_up_detection ( lis2duxs12_object_t * p_obj , lis2duxs12_sensorintpin_t intpin )

enable wake-up detection.

Parameters :
  • p_obj – the device instance object

  • intpin – interrupt pin line to be used

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_disable_wake_up_detection ( lis2duxs12_object_t * p_obj )

disable wake up detection.

Parameters :

p_obj – the device instance object

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_set_wake_up_threshold ( lis2duxs12_object_t * p_obj , float_t threshold )

set wake up threshold.

Parameters :
  • p_obj – the device instance object

  • threshold – wake up detection threshold

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_set_wake_up_duration ( lis2duxs12_object_t * p_obj , uint8_t duration )

set wake up duration.

Parameters :
  • p_obj – the device instance object

  • duration – wake up detection duration

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_enable_6d_orientation ( lis2duxs12_object_t * p_obj , lis2duxs12_sensorintpin_t intpin )

enable 6d orientation.

Parameters :
  • p_obj – the device instance object

  • intpin – interrupt pin line to be used

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_disable_6d_orientation ( lis2duxs12_object_t * p_obj )

disable 6D orientation detection.

Parameters :

p_obj – the device instance object

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_set_6d_orientation_threshold ( lis2duxs12_object_t * p_obj , uint8_t threshold )

Set 6D orientation threshold.

Parameters :
  • p_obj – the device instance object

  • threshold – 6D orientation threshold

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_get_6d_orientation_xl ( lis2duxs12_object_t * p_obj , uint8_t * xlow )

get the status of XLow orientation.

Parameters :
  • p_obj – the device instance object

  • xlow – the status of XLow orientation

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_get_6d_orientation_xh ( lis2duxs12_object_t * p_obj , uint8_t * xhigh )

get the status of XHigh orientation.

Parameters :
  • p_obj – the device instance object

  • xhigh – the status of XHigh orientation

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_get_6d_orientation_yl ( lis2duxs12_object_t * p_obj , uint8_t * ylow )

get the status of YLow orientation.

Parameters :
  • p_obj – the device instance object

  • ylow – the status of YLow orientation

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_get_6d_orientation_yh ( lis2duxs12_object_t * p_obj , uint8_t * yhigh )

get the status of YHigh orientation.

Parameters :
  • p_obj – the device instance object

  • yhigh – the status of YHigh orientation

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_get_6d_orientation_zl ( lis2duxs12_object_t * p_obj , uint8_t * zlow )

Get the status of ZLow orientation.

Parameters :
  • p_obj – the device instance object

  • zlow – the status of ZLow orientation

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_acc_get_6d_orientation_zh ( lis2duxs12_object_t * p_obj , uint8_t * zhigh )

get the status of ZHigh orientation.

Parameters :
  • p_obj – the device instance object

  • zhigh – the status of ZHigh orientation

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_set_mem_bank ( lis2duxs12_object_t * p_obj , uint8_t val )

Set memory bank.

Parameters :
  • p_obj – the device instance object

  • val – the value of the memory bank in reg FUNC_CFG_ACCESS 0 - LIS2DUXS12_MAIN_MEM_BANK, 1 - LIS2DUXS12_EMBED_FUNC_MEM_BANK

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_enable_irq ( lis2duxs12_object_t * p_obj , lis2duxs12_sensorintpin_t intpin )

enable the interrupt.

Parameters :
  • p_obj – the device instance object

  • intpin – the interrupt pin

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_disable_irq ( lis2duxs12_object_t * p_obj , lis2duxs12_sensorintpin_t intpin )

disable the interrupt.

Parameters :
  • p_obj – the device instance object

  • intpin – the interrupt pin

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_wait_ms ( lis2duxs12_object_t * p_obj , uint32_t ms )

wait for a certain number of milliseconds.

Parameters :
  • p_obj – the device instance object

  • ms – the number of milliseconds to wait

Return values :

0 – in case of success, an error code otherwise

lis2duxs12_drv_status_t lis2duxs12_drv_register_callback ( lis2duxs12_object_t * pobj , lis2duxs12_callback_t cb , void * arg , lis2duxs12_sensorintpin_t intpin )

Register the callback function for interrupt events.

Parameters :
  • p_obj – the device instance object

  • cb – the callback function

  • arg – the optional argument given to the callback

  • intpin – the interrupt pin

Return values :

0 – in case of success, an error code otherwise

Types

Enums

enum lis2duxs12_sensorintpin_t

Interrupt pin selection.

Values:

enumerator LIS2DUXS12_INT1_PIN

INT1 pin

enumerator LIS2DUXS12_INT2_PIN

INT2 pin

enum lis2duxs12_power_mode_t

Power mode selection.

Values:

enumerator LIS2DUXS12_ULTRA_LOW_POWER

Ultra low power

enumerator LIS2DUXS12_LOW_POWER

Low power

enumerator LIS2DUXS12_HIGH_PERFORMANCE

High performance

enum lis2duxs12_drv_status_t

driver status codes.

Values:

enumerator LIS2DUXS12_OK

No error

enumerator LIS2DUXS12_ERROR

Error

Typedefs

typedef struct lis2duxs12_object_s lis2duxs12_object_t

LIS2DUXS12 object type.

LIS2DUXS12 object structure type callback function pointer definition

typedef void ( * lis2duxs12_callback_t ) ( lis2duxs12_object_t * pobj , void * arg )
struct lis2duxs12_cb_ctx_t

Callback context structure.

Public Members

lis2duxs12_callback_t callback

Callback function to register

void * arg

Optional argument given to the callback

struct lis2duxs12_axesraw_t

raw axes data.

Public Members

int16_t x_axis

X axis

int16_t y_axis

Y axis

int16_t z_axis

Z axis

struct lis2duxs12_axes_t

converted axes data.

Public Members

int32_t x_axis

X axis

int32_t y_axis

Y axis

int32_t z_axis

Z axis

struct lis2duxs12_event_status_t

event status flags.

Public Members

uint32_t freefallstatus

Free-fall

uint32_t tapstatus

Tap

uint32_t doubletapstatus

Double tap

uint32_t wakeupstatus

Wake-up

uint32_t stepstatus

Step

uint32_t tiltstatus

Tilt

uint32_t d6dorientationstatus

6D orientation

uint32_t sleepstatus

Sleep

struct lis2duxs12_object_s

LIS2DUXS12 object structure.

Public Members

lis2duxs12_io_t io_ctx

Bus I/O context

stmdev_ctx_t ctx

Register context

uint8_t is_initialized

Init flag

uint8_t acc_is_enabled

Acc enable flag

float_t acc_odr

Acc ODR

lis2duxs12_power_mode_t power_mode

Power mode

lis2duxs12_priv_t priv_data

Private data

lis2duxs12_cb_ctx_t cb_ctx_irq1

IRQ1 callback ctx

lis2duxs12_cb_ctx_t cb_ctx_irq2

IRQ2 callback ctx

union lis2duxs12_axis3bit16_t
#include <lis2duxs12.h>

3-axis 16-bit buffer.

Public Members

int16_t i16bit [ 3 ]

16-bit data

uint8_t u8bit [ 6 ]

8-bit view

union lis2duxs12_axis1bit16_t
#include <lis2duxs12.h>

1-axis 16-bit buffer.

Public Members

int16_t i16bit

16-bit data

uint8_t u8bit [ 2 ]

8-bit view

union lis2duxs12_axis3bit32_t
#include <lis2duxs12.h>

3-axis 32-bit buffer.

Public Members

int32_t i32bit [ 3 ]

32-bit data

uint8_t u8bit [ 12 ]

8-bit view

union lis2duxs12_axis1bit32_t
#include <lis2duxs12.h>

1-axis 32-bit buffer.

Public Members

int32_t i32bit

32-bit data

uint8_t u8bit [ 4 ]

8-bit view

Constants and macros

Defines

LIS2DUXS12_I2C_BUS 0U

I2C bus

LIS2DUXS12_SPI_BUS 1U

SPI bus

LIS2DUXS12_I3C_BUS 3U

I3C bus

LIS2DUXS12_ACC_ODR_1_HZ_6 1.6f

1.6 Hz ODR

LIS2DUXS12_ACC_ODR_3_HZ 3.0f

3 Hz ODR

LIS2DUXS12_ACC_ODR_6_HZ 6.0f

6 Hz ODR

LIS2DUXS12_ACC_ODR_12_HZ_5 12.5f

12.5 Hz ODR

LIS2DUXS12_ACC_ODR_25_HZ 25.0f

25 Hz ODR

LIS2DUXS12_ACC_ODR_50_HZ 50.0f

50 Hz ODR

LIS2DUXS12_ACC_ODR_100_HZ 100.0f

100 Hz ODR

LIS2DUXS12_ACC_ODR_200_HZ 200.0f

200 Hz ODR

LIS2DUXS12_ACC_ODR_400_HZ 400.0f

400 Hz ODR

LIS2DUXS12_ACC_ODR_800_HZ 800.0f

800 Hz ODR

LIS2DUXS12_FS_2G_FP 2.0f

2 g full scale

LIS2DUXS12_FS_4G_FP 4.0f

4 g full scale

LIS2DUXS12_FS_8G_FP 8.0f

8 g full scale

LIS2DUXS12_FS_16G_FP 16.0f

16 g full scale

LIS2DUXS12_ACC_SENSITIVITY_FOR_FS_2G 0.061f

2 g sensitivity

LIS2DUXS12_ACC_SENSITIVITY_FOR_FS_4G 0.122f

4 g sensitivity

LIS2DUXS12_ACC_SENSITIVITY_FOR_FS_8G 0.244f

8 g sensitivity

LIS2DUXS12_ACC_SENSITIVITY_FOR_FS_16G 0.488f

16 g sensitivity

LIS2DUXS12_QVAR_GAIN 74.4f

QVAR gain

LIS2DUXS12_QVAR_GAIN_MULTIPL_0_5X 0.5f

QVAR gain x0.5

LIS2DUXS12_QVAR_GAIN_MULTIPL_1X 1.0f

QVAR gain x1

LIS2DUXS12_QVAR_GAIN_MULTIPL_2X 2.0f

QVAR gain x2

LIS2DUXS12_QVAR_GAIN_MULTIPL_4X 4.0f

QVAR gain x4