no-OS
Loading...
Searching...
No Matches
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.
 
int adxl38x_write_device_data (struct adxl38x_dev *dev, uint8_t base_address, uint16_t size, uint8_t *write_data)
 Writes to the device.
 
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.
 
int adxl38x_init (struct adxl38x_dev **device, struct adxl38x_init_param init_param)
 Initializes the device and checks for valid peripheral communication.
 
int adxl38x_remove (struct adxl38x_dev *dev)
 Free the resources allocated by the init function.
 
int adxl38x_soft_reset (struct adxl38x_dev *dev)
 Performs a soft reset of the device.
 
int adxl38x_set_op_mode (struct adxl38x_dev *dev, enum adxl38x_op_mode op_mode)
 Places the device into the given operation mode.
 
int adxl38x_get_op_mode (struct adxl38x_dev *dev, enum adxl38x_op_mode *op_mode)
 Gets the current operation mode of the device.
 
int adxl38x_set_range (struct adxl38x_dev *dev, enum adxl38x_range range_val)
 Sets the measurement range register value.
 
int adxl38x_get_range (struct adxl38x_dev *dev, enum adxl38x_range *range_val)
 Gets the current range setting of the device.
 
int adxl38x_get_deviceID (struct adxl38x_dev *dev, enum adxl38x_id *devID)
 Gets the current device type.
 
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.
 
int adxl38x_clear_self_test_registers (struct adxl38x_dev *dev)
 Resets the self test registers for the part.
 
int adxl38x_get_sts_reg (struct adxl38x_dev *dev, union adxl38x_sts_reg_flags *status_flags)
 Reads the status registers.
 
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.
 
int adxl38x_get_temp (struct adxl38x_dev *dev, struct adxl38x_fractional_val *temp_degC)
 Reads the raw temperature data using burst read.
 
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.
 
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.
 
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.
 
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.
 
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.
 

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.

SPDX-License-Identifier: BSD-3-Clause

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.

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

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

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

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

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

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

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

◆ 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

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

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

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

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

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

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

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

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

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