no-OS
Loading...
Searching...
No Matches
adxl372.c File Reference

Implementation of adxl372 Core Driver. More...

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "adxl372.h"
#include "no_os_alloc.h"
#include "no_os_error.h"
Include dependency graph for adxl372.c:

Functions

int32_t adxl372_read_reg (struct adxl372_dev *dev, uint8_t reg_addr, uint8_t *reg_data)
 
int32_t adxl372_write_reg (struct adxl372_dev *dev, uint8_t reg_addr, uint8_t reg_data)
 
int32_t adxl372_read_reg_multiple (struct adxl372_dev *dev, uint8_t reg_addr, uint8_t *reg_data, uint16_t count)
 
int32_t adxl372_write_mask (struct adxl372_dev *dev, uint8_t reg_addr, uint32_t mask, uint8_t data)
 
int32_t adxl372_set_activity_threshold (struct adxl372_dev *dev, enum adxl372_th_activity act, uint16_t thresh, bool referenced, bool enable)
 
int32_t adxl372_set_op_mode (struct adxl372_dev *dev, enum adxl372_op_mode op_mode)
 
int32_t adxl372_set_autosleep (struct adxl372_dev *dev, bool enable)
 
int32_t adxl372_set_bandwidth (struct adxl372_dev *dev, enum adxl372_bandwidth bw)
 
int32_t adxl372_set_act_proc_mode (struct adxl372_dev *dev, enum adxl372_act_proc_mode mode)
 
int32_t adxl372_set_odr (struct adxl372_dev *dev, enum adxl372_odr odr)
 
int32_t adxl372_set_instant_on_th (struct adxl372_dev *dev, enum adxl372_instant_on_th_mode mode)
 
int32_t adxl372_set_wakeup_rate (struct adxl372_dev *dev, enum adxl372_wakeup_rate wur)
 
int32_t adxl372_set_activity_time (struct adxl372_dev *dev, uint8_t time)
 
int32_t adxl372_set_inactivity_time (struct adxl372_dev *dev, uint16_t time)
 
int32_t adxl372_set_filter_settle (struct adxl372_dev *dev, enum adxl372_filter_settle mode)
 
int32_t adxl372_interrupt_config (struct adxl372_dev *dev, struct adxl372_irq_config int1, struct adxl372_irq_config int2)
 
int32_t adxl372_get_status (struct adxl372_dev *dev, uint8_t *status1, uint8_t *status2, uint16_t *fifo_entries)
 
int32_t adxl372_reset (struct adxl372_dev *dev)
 
int32_t adxl372_configure_fifo (struct adxl372_dev *dev, enum adxl372_fifo_mode mode, enum adxl372_fifo_format format, uint16_t fifo_samples)
 
int32_t adxl372_service_fifo_ev (struct adxl372_dev *dev, struct adxl372_xyz_accel_data *fifo_data, uint16_t *fifo_entries)
 
int32_t adxl372_get_fifo_xyz_data (struct adxl372_dev *dev, struct adxl372_xyz_accel_data *samples, uint16_t cnt)
 
int32_t adxl372_get_highest_peak_data (struct adxl372_dev *dev, struct adxl372_xyz_accel_data *max_peak)
 
int32_t adxl372_get_accel_data (struct adxl372_dev *dev, struct adxl372_xyz_accel_data *accel_data)
 
int32_t adxl372_init (struct adxl372_dev **device, struct adxl372_init_param init_param)
 

Detailed Description

Implementation of adxl372 Core Driver.

Author
SPopa (stefa.nosp@m.n.po.nosp@m.pa@an.nosp@m.alog.nosp@m..com)

Copyright 2018(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Function Documentation

◆ adxl372_configure_fifo()

int32_t adxl372_configure_fifo ( struct adxl372_dev * dev,
enum adxl372_fifo_mode mode,
enum adxl372_fifo_format format,
uint16_t fifo_samples )

Configure the operating parameters for the FIFO.

Parameters
dev- The device structure.
mode- FIFO Mode. Specifies FIFO operating mode. Accepted values: ADXL372_FIFO_BYPASSED ADXL372_FIFO_STREAMED ADXL372_FIFO_TRIGGERED ADXL372_FIFO_OLD_SAVED
format- FIFO Format. Specifies which data is stored in the FIFO buffer. Accepted values: ADXL372_XYZ_FIFO ADXL372_X_FIFO ADXL372_Y_FIFO ADXL372_XY_FIFO ADXL372_Z_FIFO ADXL372_XZ_FIFO ADXL372_YZ_FIFO ADXL372_XYZ_PEAK_FIFO
fifo_samples- FIFO Samples. Watermark number of FIFO samples that triggers a FIFO_FULL condition when reached. Values range from 0 to 512.
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_get_accel_data()

int32_t adxl372_get_accel_data ( struct adxl372_dev * dev,
struct adxl372_xyz_accel_data * accel_data )

Retrieve 3-axis acceleration data

Parameters
dev- The device structure.
accel_data- pointer to a variable of type adxl372_xyz_accel_data where (x, y, z) acceleration data will be stored.
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_get_fifo_xyz_data()

int32_t adxl372_get_fifo_xyz_data ( struct adxl372_dev * dev,
struct adxl372_xyz_accel_data * samples,
uint16_t cnt )

Get the data stored in FIFO.

Parameters
dev- The device structure.
samples- pointer to the raw data stored in the ADXL372_FIFO_DATA
cnt- How many samples should be retrieved from the FIFO DATA reg
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_get_highest_peak_data()

int32_t adxl372_get_highest_peak_data ( struct adxl372_dev * dev,
struct adxl372_xyz_accel_data * max_peak )

Retrieve the highest magnitude (x, y, z) sample recorded since the last read of the MAXPEAK registers

Parameters
dev- The device structure.
max_peak- pointer to a variable of type adxl372_xyz_accel_data where (x, y, z) max values will be stored.
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_get_status()

int32_t adxl372_get_status ( struct adxl372_dev * dev,
uint8_t * status1,
uint8_t * status2,
uint16_t * fifo_entries )

Get the STATUS, STATUS2, FIFO_ENTRIES and FIFO_ENTRIES2 registers data

Parameters
dev- The device structure.
status1- Data stored in the STATUS1 register
status2- Data stored in the STATUS2 register
fifo_entries- Number of valid data samples present in the FIFO buffer (0 to 512)
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_init()

int32_t adxl372_init ( struct adxl372_dev ** device,
struct adxl372_init_param init_param )

Initialize the device.

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.

◆ adxl372_interrupt_config()

int32_t adxl372_interrupt_config ( struct adxl372_dev * dev,
struct adxl372_irq_config int1,
struct adxl372_irq_config int2 )

Configure the INT1 and INT2 interrupt pins.

Parameters
dev- The device structure.
int1- INT1 interrupt pins.
int2- INT2 interrupt pins.
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_read_reg()

int32_t adxl372_read_reg ( struct adxl372_dev * dev,
uint8_t reg_addr,
uint8_t * reg_data )

Wrapper used to read device registers.

Parameters
dev- The device structure.
reg_addr- The register address.
reg_data- The register data.
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_read_reg_multiple()

int32_t adxl372_read_reg_multiple ( struct adxl372_dev * dev,
uint8_t reg_addr,
uint8_t * reg_data,
uint16_t count )

Wrapper used of multibyte reads.

Parameters
dev- The device structure.
reg_addr- The register address.
reg_data- The register data.
count- Number of bytes to read.
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_reset()

int32_t adxl372_reset ( struct adxl372_dev * dev)

Software reset.

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

◆ adxl372_service_fifo_ev()

int32_t adxl372_service_fifo_ev ( struct adxl372_dev * dev,
struct adxl372_xyz_accel_data * fifo_data,
uint16_t * fifo_entries )

Retrieve data stored in FIFO. Can be used in polling mode, but works best when interrupts are used

Parameters
dev- The device structure.
fifo_data- pointer to an array of type adxl372_xyz_accel_data where (x, y, z) values will be stored. Array max size should be 170, as the FIFO can hold up to 512 samples.
fifo_entries- pointer which will store the number of valid data samples present in the FIFO buffer
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_set_act_proc_mode()

int32_t adxl372_set_act_proc_mode ( struct adxl372_dev * dev,
enum adxl372_act_proc_mode mode )

Link/Loop Activity Processing.

Parameters
dev- The device structure.
mode- Mode of operation. Accepted values: ADXL372_DEFAULT ADXL372_LINKED ADXL372_LOOPED
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_set_activity_threshold()

int32_t adxl372_set_activity_threshold ( struct adxl372_dev * dev,
enum adxl372_th_activity act,
uint16_t thresh,
bool referenced,
bool enable )

Set the threshold for activity detection for all 3-axis

Parameters
dev- The device structure.
act- Type of activity. Accepted values: ADXL372_ACTIVITY ADXL372_ACTIVITY2 ADXL372_INACTIVITY
thresh- 11-bit unsigned value sets the threshold for activity, activity2 or inactivity detection.
referenced- Selects referenced or absolute activity processing.
enable- Enable activity detection using all 3-axis data.
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_set_activity_time()

int32_t adxl372_set_activity_time ( struct adxl372_dev * dev,
uint8_t time )

Set the activity timer

Parameters
dev- The device structure.
time- The value set in this register.
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_set_autosleep()

int32_t adxl372_set_autosleep ( struct adxl372_dev * dev,
bool enable )

Autosleep. When set to 1, autosleep is enabled, and the device enters wake-up mode automatically upon detection of inactivity.

Parameters
dev- The device structure.
enable- Accepted values: true false
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_set_bandwidth()

int32_t adxl372_set_bandwidth ( struct adxl372_dev * dev,
enum adxl372_bandwidth bw )

Select the desired output signal bandwidth.

Parameters
dev- The device structure.
bw- bandwidth. Accepted values: ADXL372_BW_200HZ ADXL372_BW_400HZ ADXL372_BW_800HZ ADXL372_BW_1600HZ ADXL372_BW_3200HZ
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_set_filter_settle()

int32_t adxl372_set_filter_settle ( struct adxl372_dev * dev,
enum adxl372_filter_settle mode )

Set the filter settling period.

Parameters
dev- The device structure.
mode- settle period Accepted values: ADXL372_FILTER_SETTLE_370 ADXL372_FILTER_SETTLE_16
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_set_inactivity_time()

int32_t adxl372_set_inactivity_time ( struct adxl372_dev * dev,
uint16_t time )

Set the inactivity timer

Parameters
dev- The device structure.
time- is the 16-bit value set by the TIME_INACT_L register (eight LSBs) and the TIME_INACT_H register (eight MSBs).
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_set_instant_on_th()

int32_t adxl372_set_instant_on_th ( struct adxl372_dev * dev,
enum adxl372_instant_on_th_mode mode )

Select instant on threshold

Parameters
dev- The device structure.
mode- 0 = low threshold, 1 = high threshold. Accepted values: ADXL372_INSTANT_ON_LOW_TH ADXL372_INSTANT_ON_HIGH_TH
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_set_odr()

int32_t adxl372_set_odr ( struct adxl372_dev * dev,
enum adxl372_odr odr )

Set Output data rate.

Parameters
dev- The device structure.
odr- Output data rate. Accepted values: ADXL372_ODR_400HZ ADXL372_ODR_800HZ ADXL372_ODR_1600HZ ADXL372_ODR_3200HZ ADXL372_ODR_6400HZ
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_set_op_mode()

int32_t adxl372_set_op_mode ( struct adxl372_dev * dev,
enum adxl372_op_mode op_mode )

Set the mode of operation.

Parameters
dev- The device structure.
op_mode- Mode of operation. Accepted values: ADXL372_STANDBY ADXL372_WAKE_UP ADXL372_INSTANT_ON ADXL372_FULL_BW_MEASUREMENT
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_set_wakeup_rate()

int32_t adxl372_set_wakeup_rate ( struct adxl372_dev * dev,
enum adxl372_wakeup_rate wur )

Set the Timer Rate for Wake-Up Mode.

Parameters
dev- The device structure.
wur- wake up mode rate Accepted values: ADXL372_WUR_52ms ADXL372_WUR_104ms ADXL372_WUR_208ms ADXL372_WUR_512ms ADXL372_WUR_2048ms ADXL372_WUR_4096ms ADXL372_WUR_8192ms ADXL372_WUR_24576ms
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_write_mask()

int32_t adxl372_write_mask ( struct adxl372_dev * dev,
uint8_t reg_addr,
uint32_t mask,
uint8_t data )

Write to device using a mask.

Parameters
dev- The device structure.
reg_addr- The register address.
mask- The mask.
data- The register data.
Returns
0 in case of success, negative error code otherwise.

◆ adxl372_write_reg()

int32_t adxl372_write_reg ( struct adxl372_dev * dev,
uint8_t reg_addr,
uint8_t reg_data )

Wrapper used to write to device registers.

Parameters
dev- The device structure.
reg_addr- The register address.
reg_data- The register data.
Returns
0 in case of success, negative error code otherwise.