no-OS
|
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"
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) |
Implementation of adxl372 Core Driver.
Copyright 2018(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.
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.
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. |
int32_t adxl372_get_accel_data | ( | struct adxl372_dev * | dev, |
struct adxl372_xyz_accel_data * | accel_data | ||
) |
Retrieve 3-axis acceleration data
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. |
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.
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 |
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
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. |
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
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) |
int32_t adxl372_init | ( | struct adxl372_dev ** | device, |
struct adxl372_init_param | init_param | ||
) |
Initialize the device.
device | - The device structure. |
init_param | - The structure that contains the device initial parameters. |
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.
dev | - The device structure. |
int1 | - INT1 interrupt pins. |
int2 | - INT2 interrupt pins. |
int32_t adxl372_read_reg | ( | struct adxl372_dev * | dev, |
uint8_t | reg_addr, | ||
uint8_t * | reg_data | ||
) |
Wrapper used to read device registers.
dev | - The device structure. |
reg_addr | - The register address. |
reg_data | - The register data. |
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.
dev | - The device structure. |
reg_addr | - The register address. |
reg_data | - The register data. |
count | - Number of bytes to read. |
int32_t adxl372_reset | ( | struct adxl372_dev * | dev | ) |
Software reset.
dev | - The device structure. |
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
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 |
int32_t adxl372_set_act_proc_mode | ( | struct adxl372_dev * | dev, |
enum adxl372_act_proc_mode | mode | ||
) |
Link/Loop Activity Processing.
dev | - The device structure. |
mode | - Mode of operation. Accepted values: ADXL372_DEFAULT ADXL372_LINKED ADXL372_LOOPED |
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
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. |
int32_t adxl372_set_activity_time | ( | struct adxl372_dev * | dev, |
uint8_t | time | ||
) |
Set the activity timer
dev | - The device structure. |
time | - The value set in this register. |
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.
dev | - The device structure. |
enable | - Accepted values: true false |
int32_t adxl372_set_bandwidth | ( | struct adxl372_dev * | dev, |
enum adxl372_bandwidth | bw | ||
) |
Select the desired output signal bandwidth.
dev | - The device structure. |
bw | - bandwidth. Accepted values: ADXL372_BW_200HZ ADXL372_BW_400HZ ADXL372_BW_800HZ ADXL372_BW_1600HZ ADXL372_BW_3200HZ |
int32_t adxl372_set_filter_settle | ( | struct adxl372_dev * | dev, |
enum adxl372_filter_settle | mode | ||
) |
Set the filter settling period.
dev | - The device structure. |
mode | - settle period Accepted values: ADXL372_FILTER_SETTLE_370 ADXL372_FILTER_SETTLE_16 |
int32_t adxl372_set_inactivity_time | ( | struct adxl372_dev * | dev, |
uint16_t | time | ||
) |
Set the inactivity timer
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). |
int32_t adxl372_set_instant_on_th | ( | struct adxl372_dev * | dev, |
enum adxl372_instant_on_th_mode | mode | ||
) |
Select instant on threshold
dev | - The device structure. |
mode | - 0 = low threshold, 1 = high threshold. Accepted values: ADXL372_INSTANT_ON_LOW_TH ADXL372_INSTANT_ON_HIGH_TH |
int32_t adxl372_set_odr | ( | struct adxl372_dev * | dev, |
enum adxl372_odr | odr | ||
) |
Set Output data rate.
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 |
int32_t adxl372_set_op_mode | ( | struct adxl372_dev * | dev, |
enum adxl372_op_mode | op_mode | ||
) |
Set the mode of operation.
dev | - The device structure. |
op_mode | - Mode of operation. Accepted values: ADXL372_STANDBY ADXL372_WAKE_UP ADXL372_INSTANT_ON ADXL372_FULL_BW_MEASUREMENT |
int32_t adxl372_set_wakeup_rate | ( | struct adxl372_dev * | dev, |
enum adxl372_wakeup_rate | wur | ||
) |
Set the Timer Rate for Wake-Up Mode.
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 |
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.
dev | - The device structure. |
reg_addr | - The register address. |
mask | - The mask. |
data | - The register data. |
int32_t adxl372_write_reg | ( | struct adxl372_dev * | dev, |
uint8_t | reg_addr, | ||
uint8_t | reg_data | ||
) |
Wrapper used to write to device registers.
dev | - The device structure. |
reg_addr | - The register address. |
reg_data | - The register data. |