no-OS
Functions
adxl367.c File Reference

Implementation of ADXL367 Driver. More...

#include <stdlib.h>
#include "adxl367.h"
#include "no_os_delay.h"
#include "no_os_util.h"
#include "no_os_print_log.h"
Include dependency graph for adxl367.c:

Functions

int adxl367_init (struct adxl367_dev **device, struct adxl367_init_param init_param)
 Initializes communication with the device and checks if the part is present by reading the device id. More...
 
int adxl367_remove (struct adxl367_dev *dev)
 Frees the resources allocated by adxl367_init(). More...
 
int adxl367_self_test (struct adxl367_dev *dev)
 Performs self test. More...
 
int adxl367_set_register_value (struct adxl367_dev *dev, uint8_t register_value, uint8_t register_address)
 Writes data into a register. More...
 
int adxl367_get_register_value (struct adxl367_dev *dev, uint8_t *read_data, uint8_t register_address, uint8_t register_nb)
 Performs a burst read of a specified number of registers. More...
 
int adxl367_reg_write_msk (struct adxl367_dev *dev, uint8_t reg_addr, uint8_t data, uint8_t mask)
 Performs a masked write to a register. More...
 
int adxl367_software_reset (struct adxl367_dev *dev)
 Performs soft-reset. More...
 
int adxl367_set_power_mode (struct adxl367_dev *dev, enum adxl367_op_mode mode)
 Places the device into standby/measure mode. More...
 
int adxl367_set_range (struct adxl367_dev *dev, enum adxl367_range range)
 Selects the measurement range. More...
 
int adxl367_set_output_rate (struct adxl367_dev *dev, enum adxl367_odr odr)
 Selects the Output Data Rate of the device. More...
 
int adxl367_set_offset (struct adxl367_dev *dev, uint16_t x_offset, uint16_t y_offset, uint16_t z_offset)
 Sets offset for each axis. More...
 
int adxl367_get_raw_xyz (struct adxl367_dev *dev, int16_t *x, int16_t *y, int16_t *z)
 Reads the 3-axis raw data from the accelerometer. More...
 
int adxl367_get_g_xyz (struct adxl367_dev *dev, struct adxl367_fractional_val *x, struct adxl367_fractional_val *y, struct adxl367_fractional_val *z)
 Reads the 3-axis raw data from the accelerometer and converts it to g. More...
 
int adxl367_temp_read_en (struct adxl367_dev *dev, bool enable)
 Enables temperature reading. More...
 
int adxl367_adc_read_en (struct adxl367_dev *dev, bool enable)
 Enables ADC reading. Disables temperature reading. More...
 
int adxl367_read_raw_temp (struct adxl367_dev *dev, int16_t *raw_temp)
 Reads the raw temperature of the device. If ADXL367_TEMP_EN is not set, use adxl367_temp_read_en() first to enable temperature reading. More...
 
int adxl367_read_temperature (struct adxl367_dev *dev, struct adxl367_fractional_val *temp)
 Reads the temperature of the device. More...
 
int adxl367_read_adc (struct adxl367_dev *dev, int16_t *data)
 Reads ADC data. If ADXL367_ADC_EN is not set, use adxl367_adc_read_en() first to enable ADC reading. More...
 
int adxl367_get_nb_of_fifo_entries (struct adxl367_dev *dev, uint16_t *entr_nb)
 Reads the number of FIFO entries. More...
 
int adxl367_set_fifo_sample_sets_nb (struct adxl367_dev *dev, uint16_t sets_nb)
 Sets the number of FIFO sample sets. More...
 
int adxl367_set_fifo_mode (struct adxl367_dev *dev, enum adxl367_fifo_mode mode)
 Sets FIFO mode. More...
 
int adxl367_set_fifo_read_mode (struct adxl367_dev *dev, enum adxl367_fifo_read_mode read_mode)
 Sets FIFO read mode. More...
 
int adxl367_set_fifo_format (struct adxl367_dev *dev, enum adxl367_fifo_format format)
 Sets FIFO format. More...
 
int adxl367_fifo_setup (struct adxl367_dev *dev, enum adxl367_fifo_mode mode, enum adxl367_fifo_format format, uint8_t sets_nb)
 Configures the FIFO feature. Uses ADXL367_14B_CHID read mode as default. More...
 
int adxl367_read_raw_fifo (struct adxl367_dev *dev, int16_t *x, int16_t *y, int16_t *z, int16_t *temp_adc, uint16_t *entries)
 Reads all available raw values from FIFO. If, after setting FIFO mode, any of x, y, z, temp or adc aren't selected, assign NULL pointer. Uses ADXL367_14B_CHID read mode as default. More...
 
int adxl367_read_converted_fifo (struct adxl367_dev *dev, struct adxl367_fractional_val *x, struct adxl367_fractional_val *y, struct adxl367_fractional_val *z, struct adxl367_fractional_val *temp_adc, uint16_t *entries)
 Reads converted values from FIFO. If, after setting FIFO mode, any of x, y, z, temp or adc aren't selected, assign NULL pointer. Uses ADXL367_14B_CHID read mode as default. More...
 
int adxl367_int_map (struct adxl367_dev *dev, struct adxl367_int_map *map, uint8_t pin)
 Enables specified events to interrupt pin. More...
 
int adxl367_setup_activity_detection (struct adxl367_dev *dev, uint8_t ref_or_abs, uint16_t threshold, uint8_t time)
 Configures activity detection. More...
 
int adxl367_setup_inactivity_detection (struct adxl367_dev *dev, uint8_t ref_or_abs, uint16_t threshold, uint16_t time)
 Configures inactivity detection. More...
 

Detailed Description

Implementation of ADXL367 Driver.

Author
Andrei Porumb (andre.nosp@m.i.po.nosp@m.rumb@.nosp@m.anal.nosp@m.og.co.nosp@m.m)

Copyright 2022(c) Analog Devices, Inc.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

◆ adxl367_adc_read_en()

int adxl367_adc_read_en ( struct adxl367_dev dev,
bool  enable 
)

Enables ADC reading. Disables temperature reading.

Parameters
dev- The device structure.
enable- 1 - ENABLE 2 - DISABLE
Returns
0 in case of success, negative error code otherwise.

◆ adxl367_fifo_setup()

int adxl367_fifo_setup ( struct adxl367_dev dev,
enum adxl367_fifo_mode  mode,
enum adxl367_fifo_format  format,
uint8_t  sets_nb 
)

Configures the FIFO feature. Uses ADXL367_14B_CHID read mode as default.

Parameters
dev- The device structure.
mode- FIFO mode selection. Example: ADXL367_FIFO_DISABLED, ADXL367_OLDEST_SAVED, ADXL367_STREAM_MODE, ADXL367_TRIGGERED_MODE
format- FIFO format selection. Example: ADXL367_FIFO_FORMAT_XYZ, ADXL367_FIFO_FORMAT_X, ADXL367_FIFO_FORMAT_Y, ADXL367_FIFO_FORMAT_Z, ADXL367_FIFO_FORMAT_XYZT, ADXL367_FIFO_FORMAT_XT, ADXL367_FIFO_FORMAT_YT, ADXL367_FIFO_FORMAT_ZT, ADXL367_FIFO_FORMAT_XYZA, ADXL367_FIFO_FORMAT_XA, ADXL367_FIFO_FORMAT_YA, ADXL367_FIFO_FORMAT_ZA
sets_nb- Specifies the number of samples sets to store in the FIFO.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_get_g_xyz()

int adxl367_get_g_xyz ( struct adxl367_dev dev,
struct adxl367_fractional_val x,
struct adxl367_fractional_val y,
struct adxl367_fractional_val z 
)

Reads the 3-axis raw data from the accelerometer and converts it to g.

Parameters
dev- The device structure.
x- Stores the X-axis data.
y- Stores the Y-axis data.
z- Stores the Z-axis data.
Returns
0 in case of success, negative error code otherwise.

◆ adxl367_get_nb_of_fifo_entries()

int adxl367_get_nb_of_fifo_entries ( struct adxl367_dev dev,
uint16_t *  entr_nb 
)

Reads the number of FIFO entries.

Parameters
dev- The device structure.
entr_nb- Entries number. Different from sets number. For example, if ADXL367_FIFO_FORMAT_XYZ is selected, one set contains 3 entries.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_get_raw_xyz()

int adxl367_get_raw_xyz ( struct adxl367_dev dev,
int16_t *  x,
int16_t *  y,
int16_t *  z 
)

Reads the 3-axis raw data from the accelerometer.

Parameters
dev- The device structure.
x- Stores the X-axis data(as two's complement).
y- Stores the Y-axis data(as two's complement).
z- Stores the Z-axis data(as two's complement).
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_get_register_value()

int adxl367_get_register_value ( struct adxl367_dev dev,
uint8_t *  read_data,
uint8_t  register_address,
uint8_t  register_nb 
)

Performs a burst read of a specified number of registers.

Parameters
dev- The device structure.
read_data- The read values are stored in this buffer.
register_address- The start address of the burst read.
register_nb- Number of registers to be read in burst.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_init()

int adxl367_init ( struct adxl367_dev **  device,
struct adxl367_init_param  init_param 
)

Initializes communication with the device and checks if the part is present by reading the device id.

Parameters
device- The device structure.
init_param- The structure that contains the device initial parameters.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_int_map()

int adxl367_int_map ( struct adxl367_dev dev,
struct adxl367_int_map map,
uint8_t  pin 
)

Enables specified events to interrupt pin.

Parameters
dev- The device structure.
map- Structure with enabled events.
pin- INT pin number. Accepted values: 1 - INT1 2 - INT2
Returns
0 in case of success, negative error code otherwise.

◆ adxl367_read_adc()

int adxl367_read_adc ( struct adxl367_dev dev,
int16_t *  data 
)

Reads ADC data. If ADXL367_ADC_EN is not set, use adxl367_adc_read_en() first to enable ADC reading.

Parameters
dev- The device structure.
data- ADC value.
Returns
0 in case of success, negative error code otherwise.

◆ adxl367_read_converted_fifo()

int adxl367_read_converted_fifo ( struct adxl367_dev dev,
struct adxl367_fractional_val x,
struct adxl367_fractional_val y,
struct adxl367_fractional_val z,
struct adxl367_fractional_val temp_adc,
uint16_t *  entries 
)

Reads converted values from FIFO. If, after setting FIFO mode, any of x, y, z, temp or adc aren't selected, assign NULL pointer. Uses ADXL367_14B_CHID read mode as default.

Parameters
dev- The device structure.
x- X axis fractional data buffer. If not used, assign NULL.
y- Y axis fractional data buffer. If not used, assign NULL.
z- Z axis fractional data buffer. If not used, assign NULL.
temp_adc- Fractional buffer for temperature. If ADC is used, ADC's value will be stored to integer field. If not used, assign NULL.
entries- Number of read entries.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_read_raw_fifo()

int adxl367_read_raw_fifo ( struct adxl367_dev dev,
int16_t *  x,
int16_t *  y,
int16_t *  z,
int16_t *  temp_adc,
uint16_t *  entries 
)

Reads all available raw values from FIFO. If, after setting FIFO mode, any of x, y, z, temp or adc aren't selected, assign NULL pointer. Uses ADXL367_14B_CHID read mode as default.

Parameters
dev- The device structure.
x- X axis raw data buffer. If not used, assign NULL.
y- Y axis raw data buffer. If not used, assign NULL.
z- Z axis raw data buffer. If not used, assign NULL.
temp_adc- Data buffer for temperature or adc raw data. If not used assign NULL.
entries- Number of read entries.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_read_raw_temp()

int adxl367_read_raw_temp ( struct adxl367_dev dev,
int16_t *  raw_temp 
)

Reads the raw temperature of the device. If ADXL367_TEMP_EN is not set, use adxl367_temp_read_en() first to enable temperature reading.

Parameters
dev- The device structure.
raw_temp- Raw value of temperature.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_read_temperature()

int adxl367_read_temperature ( struct adxl367_dev dev,
struct adxl367_fractional_val temp 
)

Reads the temperature of the device.

Parameters
dev- The device structure.
temp- Temperature output data.
Returns
0 in case of success, negative error code otherwise.

◆ adxl367_reg_write_msk()

int adxl367_reg_write_msk ( struct adxl367_dev dev,
uint8_t  reg_addr,
uint8_t  data,
uint8_t  mask 
)

Performs a masked write to a register.

Parameters
dev- The device structure.
reg_addr- The register address.
data- The register data.
mask- The mask.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_remove()

int adxl367_remove ( struct adxl367_dev dev)

Frees the resources allocated by adxl367_init().

Parameters
dev- The device structure.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_self_test()

int adxl367_self_test ( struct adxl367_dev dev)

Performs self test.

Parameters
dev- The device structure.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_set_fifo_format()

int adxl367_set_fifo_format ( struct adxl367_dev dev,
enum adxl367_fifo_format  format 
)

Sets FIFO format.

Parameters
dev- The device structure.
format- FIFO format. Accepted values: ADXL367_FIFO_FORMAT_XYZ, ADXL367_FIFO_FORMAT_X, ADXL367_FIFO_FORMAT_Y, ADXL367_FIFO_FORMAT_Z, ADXL367_FIFO_FORMAT_XYZT, ADXL367_FIFO_FORMAT_XT, ADXL367_FIFO_FORMAT_YT, ADXL367_FIFO_FORMAT_ZT, ADXL367_FIFO_FORMAT_XYZA, ADXL367_FIFO_FORMAT_XA, ADXL367_FIFO_FORMAT_YA, ADXL367_FIFO_FORMAT_ZA
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_set_fifo_mode()

int adxl367_set_fifo_mode ( struct adxl367_dev dev,
enum adxl367_fifo_mode  mode 
)

Sets FIFO mode.

Parameters
dev- The device structure.
mode- FIFO mode. Accepted values: ADXL367_FIFO_DISABLED, ADXL367_OLDEST_SAVED, ADXL367_STREAM_MODE, ADXL367_TRIGGERED_MODE
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_set_fifo_read_mode()

int adxl367_set_fifo_read_mode ( struct adxl367_dev dev,
enum adxl367_fifo_read_mode  read_mode 
)

Sets FIFO read mode.

Parameters
dev- The device structure.
read_mode- FIFO read mode. Accepted values: ADXL367_12B_CHID, ADXL367_8B, ADXL367_12B, ADXL367_14B_CHID
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_set_fifo_sample_sets_nb()

int adxl367_set_fifo_sample_sets_nb ( struct adxl367_dev dev,
uint16_t  sets_nb 
)

Sets the number of FIFO sample sets.

Parameters
dev- The device structure.
sets_nb- Sample sets number. For example, if ADXL367_FIFO_FORMAT_XYZ is selected, a value of 2 will represent 6 entries.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_set_offset()

int adxl367_set_offset ( struct adxl367_dev dev,
uint16_t  x_offset,
uint16_t  y_offset,
uint16_t  z_offset 
)

Sets offset for each axis.

Parameters
dev- The device structure.
x_offset- X axis offset.
y_offset- Y axis offset.
z_offset- Z axis offset.
Returns
0 in case of success, negative error code otherwise.

◆ adxl367_set_output_rate()

int adxl367_set_output_rate ( struct adxl367_dev dev,
enum adxl367_odr  odr 
)

Selects the Output Data Rate of the device.

Parameters
dev- The device structure.
odr- Output Data Rate option. Accepted values: ADXL367_ODR_12P5HZ, ADXL367_ODR_25HZ, ADXL367_ODR_50HZ, ADXL367_ODR_100HZ, ADXL367_ODR_200HZ, ADXL367_ODR_400HZ
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_set_power_mode()

int adxl367_set_power_mode ( struct adxl367_dev dev,
enum adxl367_op_mode  mode 
)

Places the device into standby/measure mode.

Parameters
dev- The device structure.
mode- Power mode. Accepted values: ADXL367_OP_STANDBY = 0, ADXL367_OP_MEASURE = 2
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_set_range()

int adxl367_set_range ( struct adxl367_dev dev,
enum adxl367_range  range 
)

Selects the measurement range.

Parameters
dev- The device structure.
range- Range option. Accepted values: ADXL367_2G_RANGE, +/- 2g ADXL367_4G_RANGE, +/- 4g ADXL367_8G_RANGE +/- 8g
Returns
0 in case of success, negative error code otherwise.

◆ adxl367_set_register_value()

int adxl367_set_register_value ( struct adxl367_dev dev,
uint8_t  register_value,
uint8_t  register_address 
)

Writes data into a register.

Parameters
dev- The device structure.
register_value- Data value to write.
register_address- Address of the register.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_setup_activity_detection()

int adxl367_setup_activity_detection ( struct adxl367_dev dev,
uint8_t  ref_or_abs,
uint16_t  threshold,
uint8_t  time 
)

Configures activity detection.

Parameters
dev- The device structure.
ref_or_abs- Referenced/Absolute Activity Select. Example: 0 - absolute mode. 1 - referenced mode.
threshold- 13-bit unsigned value samples are compared to.
time- 8-bit value written to the timed activity register. Value = number of samples. For example, at 100Hz ODR, 100 value translates to 1 second.
Returns
0 in case of success, negative error code otherwise.

◆ adxl367_setup_inactivity_detection()

int adxl367_setup_inactivity_detection ( struct adxl367_dev dev,
uint8_t  ref_or_abs,
uint16_t  threshold,
uint16_t  time 
)

Configures inactivity detection.

Parameters
dev- The device structure.
ref_or_abs- Referenced/Absolute Inactivity Select. Example: 0 - absolute mode. 1 - referenced mode.
threshold- 13-bit unsigned value samples are compared to.
time- 16-bit value written to the timed inactivity register. Value = number of samples. For example, at 100Hz ODR, 100 value translates to 1 second.
Returns
0 in case of success, negative error code otherwise.

◆ adxl367_software_reset()

int adxl367_software_reset ( struct adxl367_dev dev)

Performs soft-reset.

Parameters
dev- The device structure.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adxl367_temp_read_en()

int adxl367_temp_read_en ( struct adxl367_dev dev,
bool  enable 
)

Enables temperature reading.

Parameters
dev- The device structure.
enable- 1 - ENABLE 2 - DISABLE
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function: