no-OS
Functions
adxl38x.c File Reference

Implementation of ADXL38X Driver. More...

#include <stdlib.h>
#include <errno.h>
#include "adxl38x.h"
#include "no_os_delay.h"
#include "no_os_alloc.h"
#include "no_os_util.h"
Include dependency graph for adxl38x.c:

Functions

int adxl38x_read_device_data (struct adxl38x_dev *dev, uint8_t base_address, uint16_t size, uint8_t *read_data)
 Reads from the device. More...
 
int adxl38x_write_device_data (struct adxl38x_dev *dev, uint8_t base_address, uint16_t size, uint8_t *write_data)
 Writes to the device. More...
 
int adxl38x_register_update_bits (struct adxl38x_dev *dev, uint8_t reg_addr, uint8_t mask, uint8_t update_val)
 Updates register with specified bits using given mask. More...
 
int adxl38x_init (struct adxl38x_dev **device, struct adxl38x_init_param init_param)
 Initializes the device and checks for valid peripheral communication. More...
 
int adxl38x_remove (struct adxl38x_dev *dev)
 Free the resources allocated by the init function. More...
 
int adxl38x_soft_reset (struct adxl38x_dev *dev)
 Performs a soft reset of the device. More...
 
int adxl38x_set_op_mode (struct adxl38x_dev *dev, enum adxl38x_op_mode op_mode)
 Places the device into the given operation mode. More...
 
int adxl38x_get_op_mode (struct adxl38x_dev *dev, enum adxl38x_op_mode *op_mode)
 Gets the current operation mode of the device. More...
 
int adxl38x_set_range (struct adxl38x_dev *dev, enum adxl38x_range range_val)
 Sets the measurement range register value. More...
 
int adxl38x_get_range (struct adxl38x_dev *dev, enum adxl38x_range *range_val)
 Gets the current range setting of the device. More...
 
int adxl38x_get_deviceID (struct adxl38x_dev *dev, enum adxl38x_id *devID)
 Gets the current device type. More...
 
int adxl38x_set_self_test_registers (struct adxl38x_dev *dev, bool st_mode, bool st_force, bool st_dir)
 Sets the part to execute self-test routine. More...
 
int adxl38x_clear_self_test_registers (struct adxl38x_dev *dev)
 Resets the self test registers for the part. More...
 
int adxl38x_get_sts_reg (struct adxl38x_dev *dev, union adxl38x_sts_reg_flags *status_flags)
 Reads the status registers. More...
 
int adxl38x_get_raw_xyz (struct adxl38x_dev *dev, uint16_t *raw_x, uint16_t *raw_y, uint16_t *raw_z)
 Reads the raw output data using continuous read. More...
 
int adxl38x_get_temp (struct adxl38x_dev *dev, struct adxl38x_fractional_val *temp_degC)
 Reads the raw temperature data using burst read. More...
 
int adxl38x_get_raw_data (struct adxl38x_dev *dev, enum adxl38x_ch_select channels, uint16_t *raw_x, uint16_t *raw_y, uint16_t *raw_z, uint16_t *raw_temp)
 Reads the raw output data using burst read. More...
 
int adxl38x_get_xyz_gees (struct adxl38x_dev *dev, enum adxl38x_ch_select channels, struct adxl38x_fractional_val *x, struct adxl38x_fractional_val *y, struct adxl38x_fractional_val *z)
 Reads the raw output data of each axis and converts it to g. More...
 
int adxl38x_selftest (struct adxl38x_dev *dev, enum adxl38x_op_mode op_mode, bool *st_x, bool *st_y, bool *st_z)
 Executed Selftest on the sensing axes and returns the outcome of the test. More...
 
int adxl38x_accel_set_FIFO (struct adxl38x_dev *dev, uint16_t num_samples, bool external_trigger, enum adxl38x_fifo_mode fifo_mode, bool ch_ID_enable, bool read_reset)
 Function to set the paramenters for FIFO mode. More...
 
int adxl38x_data_raw_to_gees (struct adxl38x_dev *dev, uint8_t *raw_accel_data, struct adxl38x_fractional_val *data_frac)
 Function to convert accel data to gees. More...
 

Detailed Description

Implementation of ADXL38X Driver.

Author
Balarupini Rajendran (balar.nosp@m.upin.nosp@m.i.raj.nosp@m.endr.nosp@m.an@an.nosp@m.alog.nosp@m..com)

Copyright 2024(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

◆ adxl38x_accel_set_FIFO()

int adxl38x_accel_set_FIFO ( struct adxl38x_dev dev,
uint16_t  num_samples,
bool  external_trigger,
enum adxl38x_fifo_mode  fifo_mode,
bool  ch_ID_enable,
bool  read_reset 
)

Function to set the paramenters for FIFO mode.

Parameters
dev- The device structure.
num_samples- Number of FIFO entries that FIFI_WATERMARK should set.
external_trigger- Enable/disable external trigger in FIFO stream mode.
fifo_mode- FIFO mode setting.
ch_ID_enable- Enable/disable channel ID.
read_reset- reset read/write point and read state machine.
Returns
ret - Result of the procedure.
Here is the caller graph for this function:

◆ adxl38x_clear_self_test_registers()

int adxl38x_clear_self_test_registers ( struct adxl38x_dev dev)

Resets the self test registers for the part.

NOTE: It is recommended that the ADXL380 self-test should be performed in mid and high gee ranges and in high power mode.

Parameters
dev- The device structure.
Returns
ret - Result of the writing procedure.

◆ adxl38x_data_raw_to_gees()

int adxl38x_data_raw_to_gees ( struct adxl38x_dev dev,
uint8_t *  raw_accel_data,
struct adxl38x_fractional_val data_frac 
)

Function to convert accel data to gees.

Parameters
dev- The device structure.
raw_accel_data- Raw data array of two bytes
data_frac- Fractional data in gees
Returns
ret - Result of the procedure.
Here is the caller graph for this function:

◆ adxl38x_get_deviceID()

int adxl38x_get_deviceID ( struct adxl38x_dev dev,
enum adxl38x_id devID 
)

Gets the current device type.

Parameters
dev- The device structure
devID- Read Device ID
Returns
ret - Result of the reading operation procedure.
Here is the caller graph for this function:

◆ adxl38x_get_op_mode()

int adxl38x_get_op_mode ( struct adxl38x_dev dev,
enum adxl38x_op_mode op_mode 
)

Gets the current operation mode of the device.

Parameters
dev- The device structure.
op_mode- Read operation mode.
Returns
ret - Result of the reading operation procedure.
Here is the caller graph for this function:

◆ adxl38x_get_range()

int adxl38x_get_range ( struct adxl38x_dev dev,
enum adxl38x_range range_val 
)

Gets the current range setting of the device.

Parameters
dev- The device structure.
range_val- Read range.
Returns
ret - Result of the reading operation procedure.
Here is the caller graph for this function:

◆ adxl38x_get_raw_data()

int adxl38x_get_raw_data ( struct adxl38x_dev dev,
enum adxl38x_ch_select  channels,
uint16_t *  raw_x,
uint16_t *  raw_y,
uint16_t *  raw_z,
uint16_t *  raw_temp 
)

Reads the raw output data using burst read.

Parameters
dev- The device structure.
channels- Channels to enable.
raw_x- X-axis's raw output data.
raw_y- Y-axis's raw output data.
raw_z- Z-axis's raw output data.
raw_temp- Raw temp output data.
Returns
ret - Result of the reading procedure.
Here is the caller graph for this function:

◆ adxl38x_get_raw_xyz()

int adxl38x_get_raw_xyz ( struct adxl38x_dev dev,
uint16_t *  raw_x,
uint16_t *  raw_y,
uint16_t *  raw_z 
)

Reads the raw output data using continuous read.

Parameters
dev- The device structure.
raw_x- X-axis's raw output data.
raw_y- Y-axis's raw output data.
raw_z- Z-axis's raw output data.
Returns
ret - Result of the reading procedure.

◆ adxl38x_get_sts_reg()

int adxl38x_get_sts_reg ( struct adxl38x_dev dev,
union adxl38x_sts_reg_flags status_flags 
)

Reads the status registers.

TODO: Update according to datasheet (Currently based on RevH)

Parameters
dev- The device structure.
status_flags- Combined Status value.
Returns
ret - 32-bit status value as a combination of status 0 to 3 registers.
Here is the caller graph for this function:

◆ adxl38x_get_temp()

int adxl38x_get_temp ( struct adxl38x_dev dev,
struct adxl38x_fractional_val temp_degC 
)

Reads the raw temperature data using burst read.

Parameters
dev- The device structure.
temp_degC- Temperature data in degree Celcius
Returns
ret - Result of the reading procedure.

◆ adxl38x_get_xyz_gees()

int adxl38x_get_xyz_gees ( struct adxl38x_dev dev,
enum adxl38x_ch_select  channels,
struct adxl38x_fractional_val x,
struct adxl38x_fractional_val y,
struct adxl38x_fractional_val z 
)

Reads the raw output data of each axis and converts it to g.

Parameters
dev- The device structure.
channels- Channels to enable.
x- X-axis's output data.
y- Y-axis's output data.
z- Z-axis's output data.
Returns
ret - Result of the reading procedure.
Here is the caller graph for this function:

◆ adxl38x_init()

int adxl38x_init ( struct adxl38x_dev **  device,
struct adxl38x_init_param  init_param 
)

Initializes the device and checks for valid peripheral communication.

Parameters
device- The device structure.
init_param- Structure containing initialization parameters
Returns
ret - Result of the initialization
Here is the caller graph for this function:

◆ adxl38x_read_device_data()

int adxl38x_read_device_data ( struct adxl38x_dev dev,
uint8_t  base_address,
uint16_t  size,
uint8_t *  read_data 
)

Reads from the device.

Parameters
dev- The device structure.
base_address- Address of the base register.
size- The number of bytes to be read and returned in read_data.
read_data- The read data buffer
Returns
ret - Result of the reading procedure.
Here is the caller graph for this function:

◆ adxl38x_register_update_bits()

int adxl38x_register_update_bits ( struct adxl38x_dev dev,
uint8_t  reg_addr,
uint8_t  mask,
uint8_t  update_val 
)

Updates register with specified bits using given mask.

Parameters
dev- The device structure.
reg_addr- Address of the register to update.
mask- Mask for the update field.
update_val- Value to be updated.
Returns
ret - Result of the writing procedure.
Here is the caller graph for this function:

◆ adxl38x_remove()

int adxl38x_remove ( struct adxl38x_dev dev)

Free the resources allocated by the init function.

Parameters
dev- The device structure.
Returns
ret - Result of the remove procedure.
Here is the caller graph for this function:

◆ adxl38x_selftest()

int adxl38x_selftest ( struct adxl38x_dev dev,
enum adxl38x_op_mode  op_mode,
bool st_x,
bool st_y,
bool st_z 
)

Executed Selftest on the sensing axes and returns the outcome of the test.

Parameters
dev- The device structure.
op_mode- Operation mode in which self-test is executed
st_x- Result of X-axis self test success/failure
st_y- Result of X-axis self test success/failure
st_z- Result of X-axis self test success/failure
Returns
ret - Outcome of the selftest.
Here is the caller graph for this function:

◆ adxl38x_set_op_mode()

int adxl38x_set_op_mode ( struct adxl38x_dev dev,
enum adxl38x_op_mode  op_mode 
)

Places the device into the given operation mode.

Parameters
dev- The device structure.
op_mode- Operation mode mode.
Returns
ret - Result of the setting operation procedure.
Here is the caller graph for this function:

◆ adxl38x_set_range()

int adxl38x_set_range ( struct adxl38x_dev dev,
enum adxl38x_range  range_val 
)

Sets the measurement range register value.

Parameters
dev- The device structure.
range_val- Selected range.
Returns
ret - Result of the writing procedure.
Here is the caller graph for this function:

◆ adxl38x_set_self_test_registers()

int adxl38x_set_self_test_registers ( struct adxl38x_dev dev,
bool  st_mode,
bool  st_force,
bool  st_dir 
)

Sets the part to execute self-test routine.

NOTE: It is recommended that the ADXL380 self-test should be performed in mid and high gee ranges and in high power mode.

Parameters
dev- The device structure.
st_mode- Enable/disable bit for self test.
st_force- Enable/disable bit for forced self test.
st_dir- Direction bit for self test. 0 - Forward, 1 - Reverse.
Returns
ret - Result of the writing procedure.
Here is the caller graph for this function:

◆ adxl38x_soft_reset()

int adxl38x_soft_reset ( struct adxl38x_dev dev)

Performs a soft reset of the device.

Parameters
dev- The device structure.
Returns
ret - Result of the soft reset procedure.
Here is the caller graph for this function:

◆ adxl38x_write_device_data()

int adxl38x_write_device_data ( struct adxl38x_dev dev,
uint8_t  base_address,
uint16_t  size,
uint8_t *  write_data 
)

Writes to the device.

Parameters
dev- The device structure.
base_address- Address of the base register.
size- The number of bytes to be written. It is the size of the write_data buffer.
write_data- The data which is going to be written.
Returns
ret - Result of the writing procedure.
Here is the caller graph for this function: