## IIO Channels

Data channels for each sensor may vary depending on the sensor’s functionality and point of measurement. In the case of ADXL345, an accelerometer, 3 channels represent acceleration on the X, Y and Z axes. A light sensor on the other hand, can have a channel that represents measurement in the visible spectrum and another for the infrared spectrum.

The struct iio_chan_spec is used to define channels. In ADXL345, its channels are defined like this:

## Channel sysfs Attributes

Exposition of chip information and configuration parameters are accessible via sysfs files. These files are hereto referred as attributes and for the IIO subsystem is found under /sys/bus/iio/iio:deviceX/ directory.

For an example of what these attributes were, you can check out this file on the kernel sources: Documentation/ABI/testing/syfs-bus-iio

For the ADXL345 IIO driver basic support submission, the following attributes are present:

The attributes follow this generic form:

{direction}_{type}_{index}_{modifier}_{info}

The industrialio-core.c file contain further details for examination:

These attributes are exposed to userspace in the form of bitmasks. The info_mask_* members in struct iio_chan_spec determine sharing of data across different channels. A detailed description of what each member is for is found in the header file iio.h:

## Reading and Writing on sysfs files

The earlier sections detailed how to create these sysfs files. Now we’re going to add the code that will enable us to read and/or write from/to these files.

In struct iio_info we’ll have to provide a read_raw function for reading as well as a write_raw function for writing. In ADXL345, I only provided a read_raw function since the configurable attributes are yet to be implemented.

For the RAW attribute:

For SCALE:

## Raw? Scale? What are these?

Looking back at the channel definition for the ADXL345, the bitmask IIO_CHAN_INFO_RAW was placed under info_mask_separate which yielded 3 separate sysfs files in the form of in_accel_[xyz]_raw as seen above.

We refer back to the IIO sysfs ABI which describes this in detail:

Whereas a single scale file shared across all channels (IIO_CHAN_INFO_SCALE) of the same type meant:

Therefore, the raw attributes represent raw readings from the device. Scale on the other hand is what you will apply to the raw data resulting to the acceleration values measured in terms of $m/s^2$.

The following x, y and z readings:

Translates to: