no-OS
Functions
adxl345.c File Reference

Implementation of ADXL345 Driver. More...

#include <stdlib.h>
#include "adxl345.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. More...
 
void adxl345_set_register_value (struct adxl345_dev *dev, uint8_t register_address, uint8_t register_value)
 Writes data into a register. More...
 
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. More...
 
int32_t adxl345_remove (struct adxl345_dev *dev)
 Free the resources allocated by adxl345_init(). More...
 
void adxl345_set_power_mode (struct adxl345_dev *dev, uint8_t pwr_mode)
 Places the device into standby/measure mode. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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). More...
 
void adxl345_set_range_resolution (struct adxl345_dev *dev, uint8_t g_range, uint8_t full_res)
 Selects the measurement range. More...
 

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.

All rights reserved.

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 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, 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

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

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

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

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

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

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

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

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

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

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

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