.. SPDX-License-Identifier: GPL-2.0

================
ADIS16550 driver
================

This driver supports Analog Device's IMUs on SPI bus.

1. Supported devices
====================

* `ADIS16550 <https://www.analog.com/ADIS16550>`_

The ADIS16550 is a complete inertial system that includes a triaxis gyroscope
and a triaxis accelerometer. The factory calibration characterizes each sensor for
sensitivity, bias, and alignment. As a result, each sensor has its own dynamic
compensation formulas that provide accurate sensor measurements.

2. Device attributes
====================

Accelerometer, gyroscope measurements are always provided. Furthermore, the
driver offers the capability to retrieve the delta angle and the delta velocity
measurements computed by the device.

The delta angle measurements represent a calculation of angular displacement
between each sample update, while the delta velocity measurements represent a
calculation of linear velocity change between each sample update.

Finally, temperature data are provided which show a coarse measurement of
the temperature inside of the IMU device. This data is most useful for
monitoring relative changes in the thermal environment.

Each IIO device, has a device folder under ``/sys/bus/iio/devices/iio:deviceX``,
where X is the IIO index of the device. Under these folders reside a set of
device files, depending on the characteristics and features of the hardware
device in questions. These files are consistently generalized and documented in
the IIO ABI documentation.

The following tables show the adis16550 related device files, found in the
specific device folder path ``/sys/bus/iio/devices/iio:deviceX``.

+-------------------------------------------+----------------------------------------------------------+
| 3-Axis Accelerometer related device files | Description                                              |
+-------------------------------------------+----------------------------------------------------------+
| in_accel_scale                            | Scale for the accelerometer channels.                    |
+-------------------------------------------+----------------------------------------------------------+
| in_accel_filter_low_pass_3db_frequency    | Bandwidth for the accelerometer channels.                |
+-------------------------------------------+----------------------------------------------------------+
| in_accel_x_calibbias                      | Calibration offset for the X-axis accelerometer channel. |
+-------------------------------------------+----------------------------------------------------------+
| in_accel_x_calibscale                     | Calibration scale for the X-axis accelerometer channel.  |
+-------------------------------------------+----------------------------------------------------------+
| in_accel_x_raw                            | Raw X-axis accelerometer channel value.                  |
+-------------------------------------------+----------------------------------------------------------+
| in_accel_y_calibbias                      | Calibration offset for the Y-axis accelerometer channel. |
+-------------------------------------------+----------------------------------------------------------+
| in_accel_y_calibscale                     | Calibration scale for the Y-axis accelerometer channel.  |
+-------------------------------------------+----------------------------------------------------------+
| in_accel_y_raw                            | Raw Y-axis accelerometer channel value.                  |
+-------------------------------------------+----------------------------------------------------------+
| in_accel_z_calibbias                      | Calibration offset for the Z-axis accelerometer channel. |
+-------------------------------------------+----------------------------------------------------------+
| in_accel_z_calibscale                     | Calibration scale for the Z-axis accelerometer channel.  |
+-------------------------------------------+----------------------------------------------------------+
| in_accel_z_raw                            | Raw Z-axis accelerometer channel value.                  |
+-------------------------------------------+----------------------------------------------------------+
| in_deltavelocity_scale                    | Scale for delta velocity channels.                       |
+-------------------------------------------+----------------------------------------------------------+
| in_deltavelocity_x_raw                    | Raw X-axis delta velocity channel value.                 |
+-------------------------------------------+----------------------------------------------------------+
| in_deltavelocity_y_raw                    | Raw Y-axis delta velocity channel value.                 |
+-------------------------------------------+----------------------------------------------------------+
| in_deltavelocity_z_raw                    | Raw Z-axis delta velocity channel value.                 |
+-------------------------------------------+----------------------------------------------------------+

+--------------------------------------------+------------------------------------------------------+
| 3-Axis Gyroscope related device files      | Description                                          |
+--------------------------------------------+------------------------------------------------------+
| in_anglvel_scale                           | Scale for the gyroscope channels.                    |
+--------------------------------------------+------------------------------------------------------+
| in_anglvel_filter_low_pass_3db_frequency   | Scale for the gyroscope channels.                    |
+--------------------------------------------+------------------------------------------------------+
| in_anglvel_x_calibbias                     | Calibration offset for the X-axis gyroscope channel. |
+--------------------------------------------+------------------------------------------------------+
| in_anglvel_x_calibscale                    | Calibration scale for the X-axis gyroscope channel.  |
+--------------------------------------------+------------------------------------------------------+
| in_anglvel_x_raw                           | Raw X-axis gyroscope channel value.                  |
+--------------------------------------------+------------------------------------------------------+
| in_anglvel_y_calibbias                     | Calibration offset for the Y-axis gyroscope channel. |
+--------------------------------------------+------------------------------------------------------+
| in_anglvel_y_calibscale                    | Calibration scale for the Y-axis gyroscope channel.  |
+--------------------------------------------+------------------------------------------------------+
| in_anglvel_y_raw                           | Raw Y-axis gyroscope channel value.                  |
+--------------------------------------------+------------------------------------------------------+
| in_anglvel_z_calibbias                     | Calibration offset for the Z-axis gyroscope channel. |
+--------------------------------------------+------------------------------------------------------+
| in_anglvel_z_calibscale                    | Calibration scale for the Z-axis gyroscope channel.  |
+--------------------------------------------+------------------------------------------------------+
| in_anglvel_z_raw                           | Raw Z-axis gyroscope channel value.                  |
+--------------------------------------------+------------------------------------------------------+
| in_deltaangl_scale                         | Scale for delta angle channels.                      |
+--------------------------------------------+------------------------------------------------------+
| in_deltaangl_x_raw                         | Raw X-axis delta angle channel value.                |
+--------------------------------------------+------------------------------------------------------+
| in_deltaangl_y_raw                         | Raw Y-axis delta angle channel value.                |
+--------------------------------------------+------------------------------------------------------+
| in_deltaangl_z_raw                         | Raw Z-axis delta angle channel value.                |
+--------------------------------------------+------------------------------------------------------+

+----------------------------------+-------------------------------------------+
| Temperature sensor related files | Description                               |
+----------------------------------+-------------------------------------------+
| in_temp0_raw                     | Raw temperature channel value.            |
+----------------------------------+-------------------------------------------+
| in_temp0_offset                  | Offset for the temperature sensor channel.|
+----------------------------------+-------------------------------------------+
| in_temp0_scale                   | Scale for the temperature sensor channel. |
+----------------------------------+-------------------------------------------+

+----------------------------+--------------------------------------------------------------------------------+
| Miscellaneous device files | Description                                                                    |
+----------------------------+--------------------------------------------------------------------------------+
| name                       | Name of the IIO device.                                                        |
+----------------------------+--------------------------------------------------------------------------------+
| sampling_frequency         | Currently selected sample rate.                                                |
+----------------------------+--------------------------------------------------------------------------------+

The following table shows the adis16550 related device debug files, found in the
specific device debug folder path ``/sys/kernel/debug/iio/iio:deviceX``.

+----------------------+-------------------------------------------------------------------------+
| Debugfs device files | Description                                                             |
+----------------------+-------------------------------------------------------------------------+
| serial_number        | The serial number of the chip in hexadecimal format.                    |
+----------------------+-------------------------------------------------------------------------+
| product_id           | Chip specific product id (16550).                                       |
+----------------------+-------------------------------------------------------------------------+
| flash_count          | The number of flash writes performed on the device.                     |
+----------------------+-------------------------------------------------------------------------+
| firmware_revision    | String containing the firmware revision in the following format ##.##.  |
+----------------------+-------------------------------------------------------------------------+
| firmware_date        | String containing the firmware date in the following format mm-dd-yyyy. |
+----------------------+-------------------------------------------------------------------------+

Channels processed values
-------------------------

A channel value can be read from its _raw attribute. The value returned is the
raw value as reported by the devices. To get the processed value of the channel,
apply the following formula:

.. code-block:: bash

        processed value = (_raw + _offset) * _scale

Where _offset and _scale are device attributes. If no _offset attribute is
present, simply assume its value is 0.

The adis16550 driver offers data for 5 types of channels, the table below shows
the measurement units for the processed value, which are defined by the IIO
framework:

+--------------------------------------+---------------------------+
| Channel type                         | Measurement unit          |
+--------------------------------------+---------------------------+
| Acceleration on X, Y, and Z axis     | Meters per Second squared |
+--------------------------------------+---------------------------+
| Angular velocity on X, Y and Z axis  | Radians per second        |
+--------------------------------------+---------------------------+
| Delta velocity on X. Y, and Z axis   | Meters per Second         |
+--------------------------------------+---------------------------+
| Delta angle on X, Y, and Z axis      | Radians                   |
+--------------------------------------+---------------------------+
| Temperature                          | Millidegrees Celsius      |
+--------------------------------------+---------------------------+

Usage examples
--------------

Show device name:

.. code-block:: bash

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

Show accelerometer channels value:

.. code-block:: bash

        root:/sys/bus/iio/devices/iio:device0> cat in_accel_x_raw
        6903851
        root:/sys/bus/iio/devices/iio:device0> cat in_accel_y_raw
        5650550
        root:/sys/bus/iio/devices/iio:device0> cat in_accel_z_raw
        104873530
        root:/sys/bus/iio/devices/iio:device0> cat in_accel_scale
        0.000000095

- X-axis acceleration = in_accel_x_raw * in_accel_scale = 0.655865845 m/s^2
- Y-axis acceleration = in_accel_y_raw * in_accel_scale = 0.53680225 m/s^2
- Z-axis acceleration = in_accel_z_raw * in_accel_scale = 9.96298535 m/s^2

Show gyroscope channels value:

.. code-block:: bash

        root:/sys/bus/iio/devices/iio:device0> cat in_anglvel_x_raw
        193309
        root:/sys/bus/iio/devices/iio:device0> cat in_anglvel_y_raw
        -763676
        root:/sys/bus/iio/devices/iio:device0> cat in_anglvel_z_raw
        -358108
        root:/sys/bus/iio/devices/iio:device0> cat in_anglvel_scale
        0.000000003

- X-axis angular velocity = in_anglvel_x_raw * in_anglvel_scale = 0.000579927 rad/s
- Y-axis angular velocity = in_anglvel_y_raw * in_anglvel_scale = −0.002291028 rad/s
- Z-axis angular velocity = in_anglvel_z_raw * in_anglvel_scale = −0.001074324 rad/s

Set calibration offset for accelerometer channels:

.. code-block:: bash

        root:/sys/bus/iio/devices/iio:device0> cat in_accel_x_calibbias
        0

        root:/sys/bus/iio/devices/iio:device0> echo 5000 > in_accel_x_calibbias
        root:/sys/bus/iio/devices/iio:device0> cat in_accel_x_calibbias
        5000

Set calibration offset for gyroscope channels:

.. code-block:: bash

        root:/sys/bus/iio/devices/iio:device0> cat in_anglvel_y_calibbias
        0

        root:/sys/bus/iio/devices/iio:device0> echo -5000 > in_anglvel_y_calibbias
        root:/sys/bus/iio/devices/iio:device0> cat in_anglvel_y_calibbias
        -5000

Set sampling frequency:

.. code-block:: bash

	root:/sys/bus/iio/devices/iio:device0> cat sampling_frequency
        4000.000000

        root:/sys/bus/iio/devices/iio:device0> echo 1000 > sampling_frequency
        1000.000000

Set bandwidth for accelerometer channels:

.. code-block:: bash

        root:/sys/bus/iio/devices/iio:device0> cat in_accel_filter_low_pass_3db_frequency
        0

        root:/sys/bus/iio/devices/iio:device0> echo 100 > in_accel_filter_low_pass_3db_frequency
        root:/sys/bus/iio/devices/iio:device0> cat in_accel_filter_low_pass_3db_frequency
        100

Show serial number:

.. code-block:: bash

        root:/sys/kernel/debug/iio/iio:device0> cat serial_number
        0x000000b6

Show product id:

.. code-block:: bash

        root:/sys/kernel/debug/iio/iio:device0> cat product_id
        16550

Show flash count:

.. code-block:: bash

        root:/sys/kernel/debug/iio/iio:device0> cat flash_count
        13

Show firmware revision:

.. code-block:: bash

        root:/sys/kernel/debug/iio/iio:device0> cat firmware_revision
        1.5

Show firmware date:

.. code-block:: bash

        root:/sys/kernel/debug/iio/iio:device0> cat firmware_date
        28-04-2021

3. Device buffers
=================

This driver supports IIO buffers.

The device supports retrieving the raw acceleration, gyroscope, delta velocity,
delta angle and temperature measurements using buffers.

However, when retrieving acceleration or gyroscope data using buffers, delta
readings will not be available and vice versa. This is because the device only
allows to read either acceleration and gyroscope data or delta velocity and
delta angle data at a time and switching between these two burst data selection
modes is time consuming.

Usage examples
--------------

Set device trigger in current_trigger, if not already set:

.. code-block:: bash

        root:/sys/bus/iio/devices/iio:device0> cat trigger/current_trigger

        root:/sys/bus/iio/devices/iio:device0> echo adis16550-dev0 > trigger/current_trigger
        root:/sys/bus/iio/devices/iio:device0> cat trigger/current_trigger
        adis16550-dev0

Select channels for buffer read:

.. code-block:: bash

        root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_deltavelocity_x_en
        root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_deltavelocity_y_en
        root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_deltavelocity_z_en
        root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_temp0_en

Set the number of samples to be stored in the buffer:

.. code-block:: bash

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

Enable buffer readings:

.. code-block:: bash

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

Obtain buffered data:

.. code-block:: bash

        root:/sys/bus/iio/devices/iio:device0> hexdump -C /dev/iio\:device0
        ...
        0000cdf0  00 00 0d 2f 00 00 08 43  00 00 09 09 00 00 a4 5f  |.../...C......._|
        0000ce00  00 00 0d 2f 00 00 07 de  00 00 08 db 00 00 a4 4b  |.../...........K|
        0000ce10  00 00 0d 2f 00 00 07 58  00 00 08 a3 00 00 a4 55  |.../...X.......U|
        0000ce20  00 00 0d 2f 00 00 06 d6  00 00 08 5c 00 00 a4 62  |.../.......\...b|
        0000ce30  00 00 0d 2f 00 00 06 45  00 00 08 37 00 00 a4 47  |.../...E...7...G|
        0000ce40  00 00 0d 2f 00 00 05 d4  00 00 08 30 00 00 a3 fa  |.../.......0....|
        0000ce50  00 00 0d 2f 00 00 05 d0  00 00 08 12 00 00 a3 d3  |.../............|
        0000ce60  00 00 0d 2f 00 00 05 dd  00 00 08 2e 00 00 a3 e9  |.../............|
        0000ce70  00 00 0d 2f 00 00 05 cc  00 00 08 51 00 00 a3 d5  |.../.......Q....|
        0000ce80  00 00 0d 2f 00 00 05 ba  00 00 08 22 00 00 a3 9a  |.../......."....|
        0000ce90  00 00 0d 2f 00 00 05 9c  00 00 07 d9 00 00 a3 40  |.../...........@|
        0000cea0  00 00 0d 2f 00 00 05 68  00 00 07 94 00 00 a2 e4  |.../...h........|
        0000ceb0  00 00 0d 2f 00 00 05 25  00 00 07 8d 00 00 a2 ce  |.../...%........|
        ...

See ``Documentation/iio/iio_devbuf.rst`` for more information about how buffered
data is structured.

4. IIO Interfacing Tools
========================

See ``Documentation/iio/iio_tools.rst`` for the description of the available IIO
interfacing tools.
