no-OS
|
Implementation of ADXL367 Driver. More...
#include <stdlib.h>
#include "adxl367.h"
#include "no_os_delay.h"
#include "no_os_error.h"
#include "no_os_util.h"
#include "no_os_alloc.h"
#include "no_os_print_log.h"
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... | |
Implementation of ADXL367 Driver.
Copyright 2022(c) Analog Devices, Inc.
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, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 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.
int adxl367_adc_read_en | ( | struct adxl367_dev * | dev, |
bool | enable | ||
) |
Enables ADC reading. Disables temperature reading.
dev | - The device structure. |
enable | - 1 - ENABLE 2 - DISABLE |
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.
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. |
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.
dev | - The device structure. |
x | - Stores the X-axis data. |
y | - Stores the Y-axis data. |
z | - Stores the Z-axis data. |
int adxl367_get_nb_of_fifo_entries | ( | struct adxl367_dev * | dev, |
uint16_t * | entr_nb | ||
) |
Reads the number of FIFO entries.
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. |
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.
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). |
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.
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. |
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.
device | - The device structure. |
init_param | - The structure that contains the device initial parameters. |
int adxl367_int_map | ( | struct adxl367_dev * | dev, |
struct adxl367_int_map * | map, | ||
uint8_t | pin | ||
) |
Enables specified events to interrupt pin.
dev | - The device structure. |
map | - Structure with enabled events. |
pin | - INT pin number. Accepted values: 1 - INT1 2 - INT2 |
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.
dev | - The device structure. |
data | - ADC value. |
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.
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. |
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.
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. |
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.
dev | - The device structure. |
raw_temp | - Raw value of temperature. |
int adxl367_read_temperature | ( | struct adxl367_dev * | dev, |
struct adxl367_fractional_val * | temp | ||
) |
Reads the temperature of the device.
dev | - The device structure. |
temp | - Temperature output data. |
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.
dev | - The device structure. |
reg_addr | - The register address. |
data | - The register data. |
mask | - The mask. |
int adxl367_remove | ( | struct adxl367_dev * | dev | ) |
Frees the resources allocated by adxl367_init().
dev | - The device structure. |
int adxl367_self_test | ( | struct adxl367_dev * | dev | ) |
Performs self test.
dev | - The device structure. |
int adxl367_set_fifo_format | ( | struct adxl367_dev * | dev, |
enum adxl367_fifo_format | format | ||
) |
Sets FIFO format.
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 |
int adxl367_set_fifo_mode | ( | struct adxl367_dev * | dev, |
enum adxl367_fifo_mode | mode | ||
) |
Sets FIFO mode.
dev | - The device structure. |
mode | - FIFO mode. Accepted values: ADXL367_FIFO_DISABLED, ADXL367_OLDEST_SAVED, ADXL367_STREAM_MODE, ADXL367_TRIGGERED_MODE |
int adxl367_set_fifo_read_mode | ( | struct adxl367_dev * | dev, |
enum adxl367_fifo_read_mode | read_mode | ||
) |
Sets FIFO read mode.
dev | - The device structure. |
read_mode | - FIFO read mode. Accepted values: ADXL367_12B_CHID, ADXL367_8B, ADXL367_12B, ADXL367_14B_CHID |
int adxl367_set_fifo_sample_sets_nb | ( | struct adxl367_dev * | dev, |
uint16_t | sets_nb | ||
) |
Sets the number of FIFO sample sets.
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. |
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.
dev | - The device structure. |
x_offset | - X axis offset. |
y_offset | - Y axis offset. |
z_offset | - Z axis offset. |
int adxl367_set_output_rate | ( | struct adxl367_dev * | dev, |
enum adxl367_odr | odr | ||
) |
Selects the Output Data Rate of the device.
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 |
int adxl367_set_power_mode | ( | struct adxl367_dev * | dev, |
enum adxl367_op_mode | mode | ||
) |
Places the device into standby/measure mode.
dev | - The device structure. |
mode | - Power mode. Accepted values: ADXL367_OP_STANDBY = 0, ADXL367_OP_MEASURE = 2 |
int adxl367_set_range | ( | struct adxl367_dev * | dev, |
enum adxl367_range | range | ||
) |
Selects the measurement range.
dev | - The device structure. |
range | - Range option. Accepted values: ADXL367_2G_RANGE, +/- 2g ADXL367_4G_RANGE, +/- 4g ADXL367_8G_RANGE +/- 8g |
int adxl367_set_register_value | ( | struct adxl367_dev * | dev, |
uint8_t | register_value, | ||
uint8_t | register_address | ||
) |
Writes data into a register.
dev | - The device structure. |
register_value | - Data value to write. |
register_address | - Address of the register. |
int adxl367_setup_activity_detection | ( | struct adxl367_dev * | dev, |
uint8_t | ref_or_abs, | ||
uint16_t | threshold, | ||
uint8_t | time | ||
) |
Configures activity detection.
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. |
int adxl367_setup_inactivity_detection | ( | struct adxl367_dev * | dev, |
uint8_t | ref_or_abs, | ||
uint16_t | threshold, | ||
uint16_t | time | ||
) |
Configures inactivity detection.
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. |
int adxl367_software_reset | ( | struct adxl367_dev * | dev | ) |
Performs soft-reset.
dev | - The device structure. |
int adxl367_temp_read_en | ( | struct adxl367_dev * | dev, |
bool | enable | ||
) |
Enables temperature reading.
dev | - The device structure. |
enable | - 1 - ENABLE 2 - DISABLE |