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

Implementation of ADXL362 Driver. More...

#include <stdlib.h>
#include "adxl362.h"
#include "no_os_alloc.h"
Include dependency graph for adxl362.c:

Functions

int32_t adxl362_init (struct adxl362_dev **device, struct adxl362_init_param init_param)
 Initializes communication with the device and checks if the part is present by reading the device id.
 
int32_t adxl362_remove (struct adxl362_dev *dev)
 Free the resources allocated by adxl362_init().
 
void adxl362_set_register_value (struct adxl362_dev *dev, uint16_t register_value, uint8_t register_address, uint8_t bytes_number)
 Writes data into a register.
 
void adxl362_get_register_value (struct adxl362_dev *dev, uint8_t *read_data, uint8_t register_address, uint8_t bytes_number)
 Performs a burst read of a specified number of registers.
 
void adxl362_get_fifo_value (struct adxl362_dev *dev, uint8_t *buffer, uint16_t bytes_number)
 Reads multiple bytes from the device's FIFO buffer.
 
void adxl362_software_reset (struct adxl362_dev *dev)
 Resets the device via SPI communication bus.
 
void adxl362_set_power_mode (struct adxl362_dev *dev, uint8_t pwr_mode)
 Places the device into standby/measure mode.
 
void adxl362_set_range (struct adxl362_dev *dev, uint8_t g_range)
 Selects the measurement range.
 
void adxl362_set_output_rate (struct adxl362_dev *dev, uint8_t out_rate)
 Selects the Output Data Rate of the device.
 
void adxl362_get_xyz (struct adxl362_dev *dev, int16_t *x, int16_t *y, int16_t *z)
 Reads the 3-axis raw data from the accelerometer.
 
void adxl362_get_g_xyz (struct adxl362_dev *dev, float *x, float *y, float *z)
 Reads the 3-axis raw data from the accelerometer and converts it to g.
 
float adxl362_read_temperature (struct adxl362_dev *dev)
 Reads the temperature of the device.
 
void adxl362_fifo_setup (struct adxl362_dev *dev, uint8_t mode, uint16_t water_mark_lvl, uint8_t en_temp_read)
 Configures the FIFO feature.
 
void adxl362_setup_activity_detection (struct adxl362_dev *dev, uint8_t ref_or_abs, uint16_t threshold, uint8_t time)
 Configures activity detection.
 
void adxl362_setup_inactivity_detection (struct adxl362_dev *dev, uint8_t ref_or_abs, uint16_t threshold, uint16_t time)
 Configures inactivity detection.
 

Detailed Description

Implementation of ADXL362 Driver.

Author
DNechita(Dan.N.nosp@m.echi.nosp@m.ta@an.nosp@m.alog.nosp@m..com)

Copyright 2012(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Function Documentation

◆ adxl362_fifo_setup()

void adxl362_fifo_setup ( struct adxl362_dev * dev,
uint8_t mode,
uint16_t water_mark_lvl,
uint8_t en_temp_read )

Configures the FIFO feature.

Parameters
dev- The device structure.
mode- Mode selection. Example: ADXL362_FIFO_DISABLE - FIFO is disabled. ADXL362_FIFO_OLDEST_SAVED - Oldest saved mode. ADXL362_FIFO_STREAM - Stream mode. ADXL362_FIFO_TRIGGERED - Triggered mode.
water_mark_lvl- Specifies the number of samples to store in the FIFO.
en_temp_read- Store Temperature Data to FIFO. Example: 1 - temperature data is stored in the FIFO together with x-, y- and x-axis data. 0 - temperature data is skipped.

◆ adxl362_get_fifo_value()

void adxl362_get_fifo_value ( struct adxl362_dev * dev,
uint8_t * buffer,
uint16_t bytes_number )

Reads multiple bytes from the device's FIFO buffer.

Parameters
dev- The device structure.
buffer- Stores the read bytes.
bytes_number- Number of bytes to read.

◆ adxl362_get_g_xyz()

void adxl362_get_g_xyz ( struct adxl362_dev * dev,
float * x,
float * y,
float * 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.

◆ adxl362_get_register_value()

void adxl362_get_register_value ( struct adxl362_dev * dev,
uint8_t * read_data,
uint8_t register_address,
uint8_t bytes_number )

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.
bytes_number- Number of bytes to read.

◆ adxl362_get_xyz()

void adxl362_get_xyz ( struct adxl362_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).

◆ adxl362_init()

int32_t adxl362_init ( struct adxl362_dev ** device,
struct adxl362_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 - the initialization was successful and the device is present; -1 - an error occurred.

◆ adxl362_read_temperature()

float adxl362_read_temperature ( struct adxl362_dev * dev)

Reads the temperature of the device.

Parameters
dev- The device structure.
Returns
temp_celsius - The value of the temperature(degree s Celsius).

◆ adxl362_remove()

int32_t adxl362_remove ( struct adxl362_dev * dev)

Free the resources allocated by adxl362_init().

Parameters
dev- The device structure.
Returns
ret - The result of the remove procedure.

◆ adxl362_set_output_rate()

void adxl362_set_output_rate ( struct adxl362_dev * dev,
uint8_t out_rate )

Selects the Output Data Rate of the device.

Parameters
dev- The device structure.
out_rate- Output Data Rate option. Example: ADXL362_ODR_12_5_HZ - 12.5Hz ADXL362_ODR_25_HZ - 25Hz ADXL362_ODR_50_HZ - 50Hz ADXL362_ODR_100_HZ - 100Hz ADXL362_ODR_200_HZ - 200Hz ADXL362_ODR_400_HZ - 400Hz

◆ adxl362_set_power_mode()

void adxl362_set_power_mode ( struct adxl362_dev * dev,
uint8_t pwr_mode )

Places the device into standby/measure mode.

Parameters
dev- The device structure.
pwr_mode- Power mode. Example: 0 - standby mode. 1 - measure mode.

◆ adxl362_set_range()

void adxl362_set_range ( struct adxl362_dev * dev,
uint8_t g_range )

Selects the measurement range.

Parameters
dev- The device structure.
g_range- Range option. Example: ADXL362_RANGE_2G - +-2 g ADXL362_RANGE_4G - +-4 g ADXL362_RANGE_8G - +-8 g

◆ adxl362_set_register_value()

void adxl362_set_register_value ( struct adxl362_dev * dev,
uint16_t register_value,
uint8_t register_address,
uint8_t bytes_number )

Writes data into a register.

Parameters
dev- The device structure.
register_value- Data value to write.
register_address- Address of the register.
bytes_number- Number of bytes. Accepted values: 0 - 1.

◆ adxl362_setup_activity_detection()

void adxl362_setup_activity_detection ( struct adxl362_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- 11-bit unsigned value that the adxl362 samples are compared to.
time- 8-bit value written to the activity timer register. The amount of time (in seconds) is: time / ODR, where ODR - is the output data rate.

◆ adxl362_setup_inactivity_detection()

void adxl362_setup_inactivity_detection ( struct adxl362_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- 11-bit unsigned value that the adxl362 samples are compared to.
time- 16-bit value written to the inactivity timer register. The amount of time (in seconds) is: time / ODR, where ODR - is the output data rate.

◆ adxl362_software_reset()

void adxl362_software_reset ( struct adxl362_dev * dev)

Resets the device via SPI communication bus.

Parameters
dev- The device structure.