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

Implementation of ADXL345 Driver. More...

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

Functions

uint8_t adxl345_get_register_value (struct adxl345_dev *dev, uint8_t register_address)
 Reads the value of a register.
 
void adxl345_set_register_value (struct adxl345_dev *dev, uint8_t register_address, uint8_t register_value)
 Writes data into a register.
 
int32_t adxl345_init (struct adxl345_dev **device, struct adxl345_init_param init_param)
 Initializes the communication peripheral and checks if the ADXL345 part is present.
 
int32_t adxl345_remove (struct adxl345_dev *dev)
 Free the resources allocated by adxl345_init().
 
void adxl345_set_power_mode (struct adxl345_dev *dev, uint8_t pwr_mode)
 Places the device into standby/measure mode.
 
void adxl345_get_xyz (struct adxl345_dev *dev, int16_t *x, int16_t *y, int16_t *z)
 Reads the raw output data of each axis.
 
void adxl345_get_g_xyz (struct adxl345_dev *dev, float *x, float *y, float *z)
 Reads the raw output data of each axis and converts it to g.
 
void adxl345_set_tap_detection (struct adxl345_dev *dev, uint8_t tap_type, uint8_t tap_axes, uint8_t tap_dur, uint8_t tap_latent, uint8_t tap_window, uint8_t tap_thresh, uint8_t tap_int)
 Enables/disables the tap detection.
 
void adxl345_set_activity_detection (struct adxl345_dev *dev, uint8_t act_on_off, uint8_t act_axes, uint8_t act_ac_dc, uint8_t act_thresh, uint8_t act_int)
 Enables/disables the activity detection.
 
void adxl345_set_inactivity_detection (struct adxl345_dev *dev, uint8_t inact_on_off, uint8_t inact_axes, uint8_t inact_ac_dc, uint8_t inact_thresh, uint8_t inact_time, uint8_t inact_int)
 Enables/disables the inactivity detection.
 
void adxl345_set_free_fall_detection (struct adxl345_dev *dev, uint8_t ff_on_off, uint8_t ff_thresh, uint8_t ff_time, uint8_t ff_int)
 Enables/disables the free-fall detection.
 
void adxl345_set_orientation_detection (struct adxl345_dev *dev, uint8_t orient_int, uint8_t orient_on_off, uint8_t int_3d, enum adxl345_dead_zone_angle dead_zone, enum adxl345_divisor_bandwidth divisor)
 Enables/disables the orientation detection (only for adxl346).
 
void adxl345_set_offset (struct adxl345_dev *dev, uint8_t x_offset, uint8_t y_offset, uint8_t z_offset)
 Sets an offset value for each axis (Offset Calibration).
 
void adxl345_set_range_resolution (struct adxl345_dev *dev, uint8_t g_range, uint8_t full_res)
 Selects the measurement range.
 

Detailed Description

Implementation of ADXL345 Driver.

Author
DBogdan (drago.nosp@m.s.bo.nosp@m.gdan@.nosp@m.anal.nosp@m.og.co.nosp@m.m)

Copyright 2012(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Function Documentation

◆ adxl345_get_g_xyz()

void adxl345_get_g_xyz ( struct adxl345_dev * dev,
float * x,
float * y,
float * z )

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

Parameters
dev- The device structure.
x- X-axis's output data.
y- Y-axis's output data.
z- Z-axis's output data.

◆ adxl345_get_register_value()

uint8_t adxl345_get_register_value ( struct adxl345_dev * dev,
uint8_t register_address )

Reads the value of a register.

Parameters
dev- The device structure.
register_address- Address of the register.
Returns
register_value - Value of the register.

◆ adxl345_get_xyz()

void adxl345_get_xyz ( struct adxl345_dev * dev,
int16_t * x,
int16_t * y,
int16_t * z )

Reads the raw output data of each axis.

Parameters
dev- The device structure.
x- X-axis's output data.
y- Y-axis's output data.
z- Z-axis's output data.

◆ adxl345_init()

int32_t adxl345_init ( struct adxl345_dev ** device,
struct adxl345_init_param init_param )

Initializes the communication peripheral and checks if the ADXL345 part is present.

Parameters
device- The device structure.
init_param- The structure that contains the device initial parameters.
Returns
status - Result of the initialization procedure. Example: -1 - I2C/SPI peripheral was not initialized or ADXL345 part is not present. 0 - I2C/SPI peripheral is initialized and ADXL345 part is present.

◆ adxl345_remove()

int32_t adxl345_remove ( struct adxl345_dev * dev)

Free the resources allocated by adxl345_init().

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

◆ adxl345_set_activity_detection()

void adxl345_set_activity_detection ( struct adxl345_dev * dev,
uint8_t act_on_off,
uint8_t act_axes,
uint8_t act_ac_dc,
uint8_t act_thresh,
uint8_t act_int )

Enables/disables the activity detection.

Parameters
dev- The device structure.
act_on_off- Enables/disables the activity detection. Example: 0x0 - disables the activity detection. 0x1 - enables the activity detection.
act_axes- Axes which participate in detecting activity. Example: 0x0 - disables axes participation. ADXL345_ACT_X_EN - enables x-axis participation. ADXL345_ACT_Y_EN - enables y-axis participation. ADXL345_ACT_Z_EN - enables z-axis participation.
act_ac_dc- Selects dc-coupled or ac-coupled operation. Example: 0x0 - dc-coupled operation. ADXL345_ACT_ACDC - ac-coupled operation.
act_thresh- Threshold value for detecting activity. The scale factor is 62.5 mg/LSB.
act_int- Interrupts pin. Example: 0x0 - activity interrupts on INT1 pin. ADXL345_ACTIVITY - activity interrupts on INT2 pin.

◆ adxl345_set_free_fall_detection()

void adxl345_set_free_fall_detection ( struct adxl345_dev * dev,
uint8_t ff_on_off,
uint8_t ff_thresh,
uint8_t ff_time,
uint8_t ff_int )

Enables/disables the free-fall detection.

Parameters
dev- The device structure.
ff_on_off- Enables/disables the free-fall detection. Example: 0x0 - disables the free-fall detection. 0x1 - enables the free-fall detection.
ff_thresh- Threshold value for free-fall detection. The scale factor is 62.5 mg/LSB.
ff_time- Time value for free-fall detection. The scale factor is 5 ms/LSB.
ff_int- Interrupts pin. Example: 0x0 - free-fall interrupts on INT1 pin. ADXL345_FREE_FALL - free-fall interrupts on INT2 pin.

◆ adxl345_set_inactivity_detection()

void adxl345_set_inactivity_detection ( struct adxl345_dev * dev,
uint8_t inact_on_off,
uint8_t inact_axes,
uint8_t inact_ac_dc,
uint8_t inact_thresh,
uint8_t inact_time,
uint8_t inact_int )

Enables/disables the inactivity detection.

Parameters
dev- The device structure.
inact_on_off- Enables/disables the inactivity detection. Example: 0x0 - disables the inactivity detection. 0x1 - enables the inactivity detection.
inact_axes- Axes which participate in detecting inactivity. Example: 0x0 - disables axes participation. ADXL345_INACT_X_EN - enables x-axis. ADXL345_INACT_Y_EN - enables y-axis. ADXL345_INACT_Z_EN - enables z-axis.
inact_ac_dc- Selects dc-coupled or ac-coupled operation. Example: 0x0 - dc-coupled operation. ADXL345_INACT_ACDC - ac-coupled operation.
inact_thresh- Threshold value for detecting inactivity. The scale factor is 62.5 mg/LSB.
inact_time- Inactivity time. The scale factor is 1 sec/LSB.
inact_int- Interrupts pin. Example: 0x0 - inactivity interrupts on INT1 pin. ADXL345_INACTIVITY - inactivity interrupts on INT2 pin.

◆ adxl345_set_offset()

void adxl345_set_offset ( struct adxl345_dev * dev,
uint8_t x_offset,
uint8_t y_offset,
uint8_t z_offset )

Sets an offset value for each axis (Offset Calibration).

Parameters
dev- The device structure.
x_offset- X-axis's offset.
y_offset- Y-axis's offset.
z_offset- Z-axis's offset.

◆ adxl345_set_orientation_detection()

void adxl345_set_orientation_detection ( struct adxl345_dev * dev,
uint8_t orient_int,
uint8_t orient_on_off,
uint8_t int_3d,
enum adxl345_dead_zone_angle dead_zone,
enum adxl345_divisor_bandwidth divisor )

Enables/disables the orientation detection (only for adxl346).

Parameters
dev- The device structure.
orient_int- Interrupts pin. Example: 0x0 - orientation interrupts on INT1 pin. ADXL345_ORIENTATION - orientation interrupts on INT2 pin.
orient_on_off- Enables/disables the orientation detection. Example: 0x0 - disables the orientation detection. 0x1 - enables the orientation detection.
int_3d- Enables/disables the 3d orientation detection. Example: 0x0 - disables the 3d orientation detection (enables 2d orientation detection). 0x1 - enables the 3d orientation detection (disables 2d orientation detection).
dead_zone- Dead zone angle encoding.
divisor- Bandwidth divisor encoding.

◆ adxl345_set_power_mode()

void adxl345_set_power_mode ( struct adxl345_dev * dev,
uint8_t pwr_mode )

Places the device into standby/measure mode.

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

◆ adxl345_set_range_resolution()

void adxl345_set_range_resolution ( struct adxl345_dev * dev,
uint8_t g_range,
uint8_t full_res )

Selects the measurement range.

Parameters
dev- The device structure.
g_range- Range option. Example: ADXL345_RANGE_PM_2G - +-2 g ADXL345_RANGE_PM_4G - +-4 g ADXL345_RANGE_PM_8G - +-8 g ADXL345_RANGE_PM_16G - +-16 g
full_res- Full resolution option. Example: 0x0 - Disables full resolution. ADXL345_FULL_RES - Enables full resolution.

◆ adxl345_set_register_value()

void adxl345_set_register_value ( struct adxl345_dev * dev,
uint8_t register_address,
uint8_t register_value )

Writes data into a register.

Parameters
dev- The device structure.
register_address- Address of the register.
register_value- Data value to write.

◆ adxl345_set_tap_detection()

void adxl345_set_tap_detection ( struct adxl345_dev * dev,
uint8_t tap_type,
uint8_t tap_axes,
uint8_t tap_dur,
uint8_t tap_latent,
uint8_t tap_window,
uint8_t tap_thresh,
uint8_t tap_int )

Enables/disables the tap detection.

Parameters
dev- The device structure.
tap_type- Tap type (none, single, double). Example: 0x0 - disables tap detection. ADXL345_SINGLE_TAP - enables single tap detection. ADXL345_DOUBLE_TAP - enables double tap detection.
tap_axes- Axes which participate in tap detection. Example: 0x0 - disables axes participation. ADXL345_TAP_X_EN - enables x-axis participation. ADXL345_TAP_Y_EN - enables y-axis participation. ADXL345_TAP_Z_EN - enables z-axis participation.
tap_dur- Tap duration. The scale factor is 625us is/LSB.
tap_latent- Tap latency. The scale factor is 1.25 ms/LSB.
tap_window- Tap window. The scale factor is 1.25 ms/LSB.
tap_thresh- Tap threshold. The scale factor is 62.5 mg/LSB.
tap_int- Interrupts pin. Example: 0x0 - interrupts on INT1 pin. ADXL345_SINGLE_TAP - single tap interrupts on INT2 pin. ADXL345_DOUBLE_TAP - double tap interrupts on INT2 pin.