no-OS
Functions
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. More...
 
int32_t adxl362_remove (struct adxl362_dev *dev)
 Free the resources allocated by adxl362_init(). More...
 
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. More...
 
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. More...
 
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. More...
 
void adxl362_software_reset (struct adxl362_dev *dev)
 Resets the device via SPI communication bus. More...
 
void adxl362_set_power_mode (struct adxl362_dev *dev, uint8_t pwr_mode)
 Places the device into standby/measure mode. More...
 
void adxl362_set_range (struct adxl362_dev *dev, uint8_t g_range)
 Selects the measurement range. More...
 
void adxl362_set_output_rate (struct adxl362_dev *dev, uint8_t out_rate)
 Selects the Output Data Rate of the device. More...
 
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. More...
 
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. More...
 
float adxl362_read_temperature (struct adxl362_dev *dev)
 Reads the temperature of the device. More...
 
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. More...
 
void adxl362_setup_activity_detection (struct adxl362_dev *dev, uint8_t ref_or_abs, uint16_t threshold, uint8_t time)
 Configures activity detection. More...
 
void adxl362_setup_inactivity_detection (struct adxl362_dev *dev, uint8_t ref_or_abs, uint16_t threshold, uint16_t time)
 Configures inactivity detection. More...
 

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.

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

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

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.

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.
Returns
None.

◆ 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.
Returns
None.

◆ 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.
Returns
None.

◆ 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.
Returns
None.
Here is the caller graph for this function:

◆ 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).
Returns
None.

◆ 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
Returns
None.

◆ 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.
Returns
None.

◆ 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
Returns
None.

◆ 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.
Returns
None.
Here is the caller graph for this function:

◆ 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.
Returns
None.

◆ 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.
Returns
None.

◆ adxl362_software_reset()

void adxl362_software_reset ( struct adxl362_dev dev)

Resets the device via SPI communication bus.

Parameters
dev- The device structure.
Returns
None.