Wiki

This version (04 May 2022 17:21) was approved by Cosmin Tanislav.The Previously approved version (04 May 2022 17:17) is available.Diff

ADXL367 Input 3-Axis Digital Accelerometer Linux Driver

Supported Devices

Evaluation Boards

Source Code

Status

Source Mainlined?
git Yes

Files

Example device tree

Function File
dts rpi-adxl367-overlay.dts

Example platform device initialization

Required devicetree properties:

  • compatible: Needs to be the name of the device. E.g. “adi,adxl367”
  • reg: the I2C address or SPI chip select number for the device

Required properties for SPI bus usage:

  • spi-max-frequency: Maximum SPI clock frequency.

Optional properties:

  • interrupts: a list of interrupt specifiers

Example for a SPI device node:

	#address-cells = <1>;
	#size-cells = <0>;
	status = "okay";

	adxl367@0 {
		compatible = "adi,adxl367";
		reg = <0>;
		spi-max-frequency = <1000000>;
		interrupt-parent = <&gpio>;
		interrupts = <25 IRQ_TYPE_EDGE_RISING>;
	};

Example for a I2C device node:

	#address-cells = <1>;
	#size-cells = <0>;
	status = "okay";

	adxl367@53 {
		compatible = "adi,adxl367";
		reg = <53>;
		interrupt-parent = <&gpio>;
		interrupts = <25 IRQ_TYPE_EDGE_RISING>;
	};

Driver testing

This specifies any shell prompt running on the target

root:/> cd /sys/bus/iio/devices/
root:/sys/bus/iio/devices> ls
iio:device0

root:/sys/bus/iio/devices> cd iio\:device0

root:/sys/bus/iio/devices/iio:device0> ls -l
drwxr-xr-x 2 root root    0 May  3 16:17 buffer
-r--r--r-- 1 root root 4096 May  3 16:17 dev
drwxr-xr-x 2 root root    0 May  3 16:17 events
-rw-r--r-- 1 root root 4096 May  3 16:17 in_accel_scale
-r--r--r-- 1 root root 4096 May  3 16:17 in_accel_scale_available
-rw-r--r-- 1 root root 4096 May  3 16:17 in_accel_x_raw
-rw-r--r-- 1 root root 4096 May  3 16:17 in_accel_y_raw
-rw-r--r-- 1 root root 4096 May  3 16:17 in_accel_z_raw
-rw-r--r-- 1 root root 4096 May  3 16:17 in_temp_offset
-rw-r--r-- 1 root root 4096 May  3 16:17 in_temp_raw
-rw-r--r-- 1 root root 4096 May  3 16:17 in_temp_scale
-rw-r--r-- 1 root root 4096 May  3 16:17 in_voltage_offset
-rw-r--r-- 1 root root 4096 May  3 16:17 in_voltage_raw
-rw-r--r-- 1 root root 4096 May  3 16:17 in_voltage_scale
-r--r--r-- 1 root root 4096 May  3 16:17 name
lrwxrwxrwx 1 root root    0 May  3 16:17 of_node -> ../../../../../../../../firmware/devicetree/base/soc/spi@7e204000/adxl367@0
drwxr-xr-x 2 root root    0 May  3 16:17 power
-rw-r--r-- 1 root root 4096 May  3 16:17 sampling_frequency
-r--r--r-- 1 root root 4096 May  3 16:17 sampling_frequency_available
drwxr-xr-x 2 root root    0 May  3 16:17 scan_elements
lrwxrwxrwx 1 root root    0 May  3 16:17 subsystem -> ../../../../../../../../bus/iio
-rw-r--r-- 1 root root 4096 May  3 16:17 uevent

Show device name

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0> cat name
adxl367

Show scale

Description:
scale to be applied to in_accel_*_raw in order to obtain the acceleration.

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0> cat in_accel_scale
0.002394347

Show axis x measurement

Description:
Raw unscaled acceleration measurement on x axis

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0> cat in_accel_x_raw
-5

Set sampling frequency

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0> cat sampling_frequency_available
12.500000 25.000000 50.000000 100.000000 200.000000 400.000000
root:/sys/bus/iio/devices/iio:device0> cat sampling_frequency
12.500000
root:/sys/bus/iio/devices/iio:device0> echo 400.000000 > sampling_frequency
root:/sys/bus/iio/devices/iio:device0> cat sampling_frequency
400.000000

Using the FIFO Buffer

Description:
The ADXL367 includes a deep, 512 sample FIFO buffer. The 512 FIFO samples can be allotted in several ways, such as the following:

  • 512 sample sets of single-axis data
  • 256 sample sets of concurrent 2-channel data
  • 170 sample sets of concurrent 3-channel data
  • 128 sample sets of concurrent 4-channel data

Buffer management

Description:
The scan_elements directory contains interfaces for elements that will be captured for a single triggered sample set in the buffer

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0> cd scan_elements/
root:/sys/bus/iio/devices/iio:device0/scan_elements> ls -l
-rw-r--r-- 1 root root 4096 May  3 16:17 in_accel_x_en
-r--r--r-- 1 root root 4096 May  3 16:17 in_accel_x_index
-r--r--r-- 1 root root 4096 May  3 16:17 in_accel_x_type
-rw-r--r-- 1 root root 4096 May  3 16:17 in_accel_y_en
-r--r--r-- 1 root root 4096 May  3 16:17 in_accel_y_index
-r--r--r-- 1 root root 4096 May  3 16:17 in_accel_y_type
-rw-r--r-- 1 root root 4096 May  3 16:17 in_accel_z_en
-r--r--r-- 1 root root 4096 May  3 16:17 in_accel_z_index
-r--r--r-- 1 root root 4096 May  3 16:17 in_accel_z_type
-rw-r--r-- 1 root root 4096 May  3 16:17 in_temp_en
-r--r--r-- 1 root root 4096 May  3 16:17 in_temp_index
-r--r--r-- 1 root root 4096 May  3 16:17 in_temp_type
-rw-r--r-- 1 root root 4096 May  3 16:17 in_voltage_en
-r--r--r-- 1 root root 4096 May  3 16:17 in_voltage_index
-r--r--r-- 1 root root 4096 May  3 16:17 in_voltage_type

Before enabling the buffer, a few steps need to be completed.

  • For example, if we want the FIFO to store sample sets of concurrent 3-channel data, we need to enable the scan elements:

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/scan_elements> echo 1 > in_accel_x_en
root:/sys/bus/iio/devices/iio:device0/scan_elements> echo 1 > in_accel_y_en
root:/sys/bus/iio/devices/iio:device0/scan_elements> echo 1 > in_accel_z_en

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/scan_elements> cd ../buffer/
root:/sys/bus/iio/devices/iio:device0/buffer> ls -l
-r--r--r-- 1 root root 4096 May  3 16:17 data_available
-rw-r--r-- 1 root root 4096 May  3 16:17 enable
-r--r--r-- 1 root root 4096 May  3 16:17 hwfifo_enabled
-r--r--r-- 1 root root 4096 May  3 16:17 hwfifo_watermark
-r--r--r-- 1 root root 4096 May  3 16:17 hwfifo_watermark_max
-r--r--r-- 1 root root 4096 May  3 16:17 hwfifo_watermark_min
-rw-r--r-- 1 root root 4096 May  3 16:17 length
-rw-r--r-- 1 root root 4096 May  3 16:17 watermark

  • Set the buffer length:

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/buffer> echo 1024 > length

  • Set the watermak:

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/buffer> echo 512 > watermark

  • Enable the buffer:

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/buffer> echo 1 > enable

  • Read the samples:

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/buffer> cat /dev/iio:device0

Low level register access via debugfs (direct_reg_access)

Some IIO drivers feature an optional debug facility, allowing users to read or write registers directly. Special care needs to be taken when using this feature, since you can modify registers on the back of the driver. Accessing debugfs requires root privileges.

This specifies any shell prompt running on the target

root:/> /sys/kernel/debug/iio/iio:device0/
root:/sys/kernel/debug/iio/iio:device0> ls direct_reg_access  
direct_reg_access

Reading

This specifies any shell prompt running on the target

root:/sys/kernel/debug/iio/iio:device0> echo 0x0 > direct_reg_access
root:/sys/kernel/debug/iio/iio:device0> cat direct_reg_access 
0xAD

Writing

Write ADDRESS VALUE

This specifies any shell prompt running on the target

root@analog:/sys/kernel/debug/iio/iio:device0> echo 0x3D 0x80 > direct_reg_access   
root@analog:/sys/kernel/debug/iio/iio:device0> cat direct_reg_access 
0x80

More Information

resources/tools-software/linux-drivers/iio-accelerometer/adxl367.txt · Last modified: 04 May 2022 17:21 by Cosmin Tanislav