no-OS
|
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"
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... | |
Implementation of ADXL38X Driver.
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:
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.
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.
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. |
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.
dev | - The device structure. |
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.
dev | - The device structure. |
raw_accel_data | - Raw data array of two bytes |
data_frac | - Fractional data in gees |
int adxl38x_get_deviceID | ( | struct adxl38x_dev * | dev, |
enum adxl38x_id * | devID | ||
) |
Gets the current device type.
dev | - The device structure |
devID | - Read Device ID |
int adxl38x_get_op_mode | ( | struct adxl38x_dev * | dev, |
enum adxl38x_op_mode * | op_mode | ||
) |
Gets the current operation mode of the device.
dev | - The device structure. |
op_mode | - Read operation mode. |
int adxl38x_get_range | ( | struct adxl38x_dev * | dev, |
enum adxl38x_range * | range_val | ||
) |
Gets the current range setting of the device.
dev | - The device structure. |
range_val | - Read range. |
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.
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. |
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.
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. |
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)
dev | - The device structure. |
status_flags | - Combined Status value. |
int adxl38x_get_temp | ( | struct adxl38x_dev * | dev, |
struct adxl38x_fractional_val * | temp_degC | ||
) |
Reads the raw temperature data using burst read.
dev | - The device structure. |
temp_degC | - Temperature data in degree Celcius |
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.
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. |
int adxl38x_init | ( | struct adxl38x_dev ** | device, |
struct adxl38x_init_param | init_param | ||
) |
Initializes the device and checks for valid peripheral communication.
device | - The device structure. |
init_param | - Structure containing initialization parameters |
int adxl38x_read_device_data | ( | struct adxl38x_dev * | dev, |
uint8_t | base_address, | ||
uint16_t | size, | ||
uint8_t * | read_data | ||
) |
Reads from the device.
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 |
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.
dev | - The device structure. |
reg_addr | - Address of the register to update. |
mask | - Mask for the update field. |
update_val | - Value to be updated. |
int adxl38x_remove | ( | struct adxl38x_dev * | dev | ) |
Free the resources allocated by the init function.
dev | - The device structure. |
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.
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 |
int adxl38x_set_op_mode | ( | struct adxl38x_dev * | dev, |
enum adxl38x_op_mode | op_mode | ||
) |
Places the device into the given operation mode.
dev | - The device structure. |
op_mode | - Operation mode mode. |
int adxl38x_set_range | ( | struct adxl38x_dev * | dev, |
enum adxl38x_range | range_val | ||
) |
Sets the measurement range register value.
dev | - The device structure. |
range_val | - Selected range. |
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.
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. |
int adxl38x_soft_reset | ( | struct adxl38x_dev * | dev | ) |
Performs a soft reset of the device.
dev | - The device structure. |
int adxl38x_write_device_data | ( | struct adxl38x_dev * | dev, |
uint8_t | base_address, | ||
uint16_t | size, | ||
uint8_t * | write_data | ||
) |
Writes to the device.
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. |