xref: /linux/Documentation/iio/adxl345.rst (revision ec2e0fb07d789976c601bec19ecced7a501c3705)
1fdcb9cb9SLothar Rubusch.. SPDX-License-Identifier: GPL-2.0
2fdcb9cb9SLothar Rubusch
3fdcb9cb9SLothar Rubusch===============
4fdcb9cb9SLothar RubuschADXL345 driver
5fdcb9cb9SLothar Rubusch===============
6fdcb9cb9SLothar Rubusch
7fdcb9cb9SLothar RubuschThis driver supports Analog Device's ADXL345/375 on SPI/I2C bus.
8fdcb9cb9SLothar Rubusch
9fdcb9cb9SLothar Rubusch1. Supported Devices
10fdcb9cb9SLothar Rubusch====================
11fdcb9cb9SLothar Rubusch
12fdcb9cb9SLothar Rubusch* `ADXL345 <https://www.analog.com/ADXL345>`_
13fdcb9cb9SLothar Rubusch* `ADXL375 <https://www.analog.com/ADXL375>`_
14fdcb9cb9SLothar Rubusch
15fdcb9cb9SLothar RubuschThe ADXL345 is a generic purpose low power, 3-axis accelerometer with selectable
16fdcb9cb9SLothar Rubuschmeasurement ranges. The ADXL345 supports the ±2 g, ±4 g, ±8 g, and ±16 g ranges.
17fdcb9cb9SLothar Rubusch
18fdcb9cb9SLothar Rubusch2. Device Attributes
19fdcb9cb9SLothar Rubusch====================
20fdcb9cb9SLothar Rubusch
21fdcb9cb9SLothar RubuschEach IIO device, has a device folder under ``/sys/bus/iio/devices/iio:deviceX``,
22fdcb9cb9SLothar Rubuschwhere X is the IIO index of the device. Under these folders reside a set of
23fdcb9cb9SLothar Rubuschdevice files, depending on the characteristics and features of the hardware
24fdcb9cb9SLothar Rubuschdevice in questions. These files are consistently generalized and documented in
25fdcb9cb9SLothar Rubuschthe IIO ABI documentation.
26fdcb9cb9SLothar Rubusch
27fdcb9cb9SLothar RubuschThe following table shows the ADXL345 related device files, found in the
28fdcb9cb9SLothar Rubuschspecific device folder path ``/sys/bus/iio/devices/iio:deviceX``.
29fdcb9cb9SLothar Rubusch
30fdcb9cb9SLothar Rubusch+-------------------------------------------+----------------------------------------------------------+
31fdcb9cb9SLothar Rubusch| 3-Axis Accelerometer related device files | Description                                              |
32fdcb9cb9SLothar Rubusch+-------------------------------------------+----------------------------------------------------------+
33fdcb9cb9SLothar Rubusch| in_accel_sampling_frequency               | Currently selected sample rate.                          |
34fdcb9cb9SLothar Rubusch+-------------------------------------------+----------------------------------------------------------+
35fdcb9cb9SLothar Rubusch| in_accel_sampling_frequency_available     | Available sampling frequency configurations.             |
36fdcb9cb9SLothar Rubusch+-------------------------------------------+----------------------------------------------------------+
37fdcb9cb9SLothar Rubusch| in_accel_scale                            | Scale/range for the accelerometer channels.              |
38fdcb9cb9SLothar Rubusch+-------------------------------------------+----------------------------------------------------------+
39fdcb9cb9SLothar Rubusch| in_accel_scale_available                  | Available scale ranges for the accelerometer channel.    |
40fdcb9cb9SLothar Rubusch+-------------------------------------------+----------------------------------------------------------+
41fdcb9cb9SLothar Rubusch| in_accel_x_calibbias                      | Calibration offset for the X-axis accelerometer channel. |
42fdcb9cb9SLothar Rubusch+-------------------------------------------+----------------------------------------------------------+
43fdcb9cb9SLothar Rubusch| in_accel_x_raw                            | Raw X-axis accelerometer channel value.                  |
44fdcb9cb9SLothar Rubusch+-------------------------------------------+----------------------------------------------------------+
45fdcb9cb9SLothar Rubusch| in_accel_y_calibbias                      | y-axis acceleration offset correction                    |
46fdcb9cb9SLothar Rubusch+-------------------------------------------+----------------------------------------------------------+
47fdcb9cb9SLothar Rubusch| in_accel_y_raw                            | Raw Y-axis accelerometer channel value.                  |
48fdcb9cb9SLothar Rubusch+-------------------------------------------+----------------------------------------------------------+
49fdcb9cb9SLothar Rubusch| in_accel_z_calibbias                      | Calibration offset for the Z-axis accelerometer channel. |
50fdcb9cb9SLothar Rubusch+-------------------------------------------+----------------------------------------------------------+
51fdcb9cb9SLothar Rubusch| in_accel_z_raw                            | Raw Z-axis accelerometer channel value.                  |
52fdcb9cb9SLothar Rubusch+-------------------------------------------+----------------------------------------------------------+
53fdcb9cb9SLothar Rubusch
54fdcb9cb9SLothar RubuschChannel Processed Values
55fdcb9cb9SLothar Rubusch-------------------------
56fdcb9cb9SLothar Rubusch
57fdcb9cb9SLothar RubuschA channel value can be read from its _raw attribute. The value returned is the
58fdcb9cb9SLothar Rubuschraw value as reported by the devices. To get the processed value of the channel,
59fdcb9cb9SLothar Rubuschapply the following formula:
60fdcb9cb9SLothar Rubusch
61fdcb9cb9SLothar Rubusch.. code-block:: bash
62fdcb9cb9SLothar Rubusch
63fdcb9cb9SLothar Rubusch        processed value = (_raw + _offset) * _scale
64fdcb9cb9SLothar Rubusch
65fdcb9cb9SLothar RubuschWhere _offset and _scale are device attributes. If no _offset attribute is
66fdcb9cb9SLothar Rubuschpresent, simply assume its value is 0.
67fdcb9cb9SLothar Rubusch
68fdcb9cb9SLothar Rubusch+-------------------------------------+---------------------------+
69fdcb9cb9SLothar Rubusch| Channel type                        | Measurement unit          |
70fdcb9cb9SLothar Rubusch+-------------------------------------+---------------------------+
71fdcb9cb9SLothar Rubusch| Acceleration on X, Y, and Z axis    | Meters per second squared |
72fdcb9cb9SLothar Rubusch+-------------------------------------+---------------------------+
73fdcb9cb9SLothar Rubusch
74fdcb9cb9SLothar RubuschSensor Events
75fdcb9cb9SLothar Rubusch-------------
76fdcb9cb9SLothar Rubusch
77fdcb9cb9SLothar RubuschSpecific IIO events are triggered by their corresponding interrupts. The sensor
78fdcb9cb9SLothar Rubuschdriver supports either none or a single active interrupt (INT) line, selectable
79fdcb9cb9SLothar Rubuschfrom the two available options: INT1 or INT2. The active INT line should be
80fdcb9cb9SLothar Rubuschspecified in the device tree. If no INT line is configured, the sensor defaults
81fdcb9cb9SLothar Rubuschto FIFO bypass mode, where event detection is disabled and only X, Y, and Z axis
82fdcb9cb9SLothar Rubuschmeasurements are available.
83fdcb9cb9SLothar Rubusch
84fdcb9cb9SLothar RubuschThe table below lists the ADXL345-related device files located in the
85fdcb9cb9SLothar Rubuschdevice-specific path: ``/sys/bus/iio/devices/iio:deviceX/events``.
86fdcb9cb9SLothar RubuschNote that activity and inactivity detection are DC-coupled by default;
87fdcb9cb9SLothar Rubuschtherefore, only the AC-coupled activity and inactivity events are explicitly
88fdcb9cb9SLothar Rubuschlisted.
89fdcb9cb9SLothar Rubusch
90fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
91fdcb9cb9SLothar Rubusch| Event handle                                | Description                                 |
92fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
93fdcb9cb9SLothar Rubusch| in_accel_gesture_doubletap_en               | Enable double tap detection on all axis     |
94fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
95fdcb9cb9SLothar Rubusch| in_accel_gesture_doubletap_reset_timeout    | Double tap window in [us]                   |
96fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
97fdcb9cb9SLothar Rubusch| in_accel_gesture_doubletap_tap2_min_delay   | Double tap latent in [us]                   |
98fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
99fdcb9cb9SLothar Rubusch| in_accel_gesture_singletap_timeout          | Single tap duration in [us]                 |
100fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
101fdcb9cb9SLothar Rubusch| in_accel_gesture_singletap_value            | Single tap threshold value in 62.5/LSB      |
102fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
103fdcb9cb9SLothar Rubusch| in_accel_mag_falling_period                 | Inactivity time in seconds                  |
104fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
105fdcb9cb9SLothar Rubusch| in_accel_mag_falling_value                  | Inactivity threshold value in 62.5/LSB      |
106fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
107fdcb9cb9SLothar Rubusch| in_accel_mag_adaptive_rising_en             | Enable AC coupled activity on X axis        |
108fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
109fdcb9cb9SLothar Rubusch| in_accel_mag_adaptive_falling_period        | AC coupled inactivity time in seconds       |
110fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
111fdcb9cb9SLothar Rubusch| in_accel_mag_adaptive_falling_value         | AC coupled inactivity threshold in 62.5/LSB |
112fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
113fdcb9cb9SLothar Rubusch| in_accel_mag_adaptive_rising_value          | AC coupled activity threshold in 62.5/LSB   |
114fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
115fdcb9cb9SLothar Rubusch| in_accel_mag_rising_en                      | Enable activity detection on X axis         |
116fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
117fdcb9cb9SLothar Rubusch| in_accel_mag_rising_value                   | Activity threshold value in 62.5/LSB        |
118fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
119fdcb9cb9SLothar Rubusch| in_accel_x_gesture_singletap_en             | Enable single tap detection on X axis       |
120fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
121fdcb9cb9SLothar Rubusch| in_accel_x&y&z_mag_falling_en               | Enable inactivity detection on all axis     |
122fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
123fdcb9cb9SLothar Rubusch| in_accel_x&y&z_mag_adaptive_falling_en      | Enable AC coupled inactivity on all axis    |
124fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
125fdcb9cb9SLothar Rubusch| in_accel_y_gesture_singletap_en             | Enable single tap detection on Y axis       |
126fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
127fdcb9cb9SLothar Rubusch| in_accel_z_gesture_singletap_en             | Enable single tap detection on Z axis       |
128fdcb9cb9SLothar Rubusch+---------------------------------------------+---------------------------------------------+
129fdcb9cb9SLothar Rubusch
130fdcb9cb9SLothar RubuschPlease refer to the sensor's datasheet for a detailed description of this
131fdcb9cb9SLothar Rubuschfunctionality.
132fdcb9cb9SLothar Rubusch
133fdcb9cb9SLothar RubuschManually setting the **ODR** will cause the driver to estimate default values
134fdcb9cb9SLothar Rubuschfor inactivity detection timing, where higher ODR values correspond to longer
135fdcb9cb9SLothar Rubuschdefault wait times, and lower ODR values to shorter ones. If these defaults do
136fdcb9cb9SLothar Rubuschnot meet your application’s needs, you can explicitly configure the inactivity
137fdcb9cb9SLothar Rubuschwait time. Setting this value to 0 will revert to the default behavior.
138fdcb9cb9SLothar Rubusch
139fdcb9cb9SLothar RubuschWhen changing the **g range** configuration, the driver attempts to estimate
140fdcb9cb9SLothar Rubuschappropriate activity and inactivity thresholds by scaling the default values
141fdcb9cb9SLothar Rubuschbased on the ratio of the previous range to the new one. The resulting threshold
142fdcb9cb9SLothar Rubuschwill never be zero and will always fall between 1 and 255, corresponding to up
143fdcb9cb9SLothar Rubuschto 62.5 g/LSB as specified in the datasheet. However, you can override these
144fdcb9cb9SLothar Rubuschestimated thresholds by setting explicit values.
145fdcb9cb9SLothar Rubusch
146fdcb9cb9SLothar RubuschWhen **activity** and **inactivity** events are enabled, the driver
147fdcb9cb9SLothar Rubuschautomatically manages hysteresis behavior by setting the **link** and
148fdcb9cb9SLothar Rubusch**auto-sleep** bits. The link bit connects the activity and inactivity
149fdcb9cb9SLothar Rubuschfunctions, so that one follows the other. The auto-sleep function puts the
150fdcb9cb9SLothar Rubuschsensor into sleep mode when inactivity is detected, reducing power consumption
151fdcb9cb9SLothar Rubuschto the sub-12.5 Hz rate.
152fdcb9cb9SLothar Rubusch
153ee6ef197SLothar RubuschThe inactivity time is configurable between 1 and 255 seconds. In addition to
154ee6ef197SLothar Rubuschinactivity detection, the sensor also supports free-fall detection, which, from
155ee6ef197SLothar Rubuschthe IIO perspective, is treated as a fall in magnitude across all axes. In
156ee6ef197SLothar Rubuschsensor terms, free-fall is defined using an inactivity period ranging from 0.000
157ee6ef197SLothar Rubuschto 1.000 seconds.
158ee6ef197SLothar Rubusch
159ee6ef197SLothar RubuschThe driver behaves as follows:
160*a4ee7e22SXing Guo
161ee6ef197SLothar Rubusch* If the configured inactivity period is 1 second or more, the driver uses the
162ee6ef197SLothar Rubusch  sensor's inactivity register. This allows the event to be linked with
163ee6ef197SLothar Rubusch  activity detection, use auto-sleep, and be either AC- or DC-coupled.
164ee6ef197SLothar Rubusch
165ee6ef197SLothar Rubusch* If the inactivity period is less than 1 second, the event is treated as plain
166ee6ef197SLothar Rubusch  inactivity or free-fall detection. In this case, auto-sleep and coupling
167ee6ef197SLothar Rubusch  (AC/DC) are not applied.
168ee6ef197SLothar Rubusch
169ee6ef197SLothar Rubusch* If an inactivity time of 0 seconds is configured, the driver selects a
170ee6ef197SLothar Rubusch  heuristically determined default period (greater than 1 second) to optimize
171ee6ef197SLothar Rubusch  power consumption. This also uses the inactivity register.
172ee6ef197SLothar Rubusch
173ee6ef197SLothar RubuschNote: According to the datasheet, the optimal ODR for detecting activity,
174ee6ef197SLothar Rubuschor inactivity (or when operating with the free-fall register) should fall within
175ee6ef197SLothar Rubuschthe range of 12.5 Hz to 400 Hz. The recommended free-fall threshold is between
176ee6ef197SLothar Rubusch300 mg and 600 mg (register values 0x05 to 0x09).
177ee6ef197SLothar Rubusch
178fdcb9cb9SLothar RubuschIn DC-coupled mode, the current acceleration magnitude is directly compared to
179fdcb9cb9SLothar Rubuschthe values in the THRESH_ACT and THRESH_INACT registers to determine activity or
180fdcb9cb9SLothar Rubuschinactivity. In contrast, AC-coupled activity detection uses the acceleration
181fdcb9cb9SLothar Rubuschvalue at the start of detection as a reference point, and subsequent samples are
182fdcb9cb9SLothar Rubuschcompared against this reference. While DC-coupling is the default mode-comparing
183fdcb9cb9SLothar Rubuschlive values to fixed thresholds-AC-coupling relies on an internal filter
184fdcb9cb9SLothar Rubuschrelative to the configured threshold.
185fdcb9cb9SLothar Rubusch
186fdcb9cb9SLothar RubuschAC and DC coupling modes are configured separately for activity and inactivity
187fdcb9cb9SLothar Rubuschdetection, but only one mode can be active at a time for each. For example, if
188fdcb9cb9SLothar RubuschAC-coupled activity detection is enabled and then DC-coupled mode is set, only
189fdcb9cb9SLothar RubuschDC-coupled activity detection will be active. In other words, only the most
190fdcb9cb9SLothar Rubuschrecent configuration is applied.
191fdcb9cb9SLothar Rubusch
192fdcb9cb9SLothar Rubusch**Single tap** detection can be configured per the datasheet by setting the
193fdcb9cb9SLothar Rubuschthreshold and duration parameters. When only single tap detection is enabled,
194fdcb9cb9SLothar Rubuschthe single tap interrupt triggers as soon as the acceleration exceeds the
195fdcb9cb9SLothar Rubuschthreshold (marking the start of the duration) and then falls below it, provided
196fdcb9cb9SLothar Rubuschthe duration limit is not exceeded. If both single tap and double tap detections
197fdcb9cb9SLothar Rubuschare enabled, the single tap interrupt is triggered only after the double tap
198fdcb9cb9SLothar Rubuschevent has been either confirmed or dismissed.
199fdcb9cb9SLothar Rubusch
200fdcb9cb9SLothar RubuschTo configure **double tap** detection, you must also set the window and latency
201fdcb9cb9SLothar Rubuschparameters in microseconds (µs). The latency period begins once the single tap
202fdcb9cb9SLothar Rubuschsignal drops below the threshold and acts as a waiting time during which any
203fdcb9cb9SLothar Rubuschspikes are ignored for double tap detection. After the latency period ends, the
204fdcb9cb9SLothar Rubuschdetection window starts. If the acceleration rises above the threshold and then
205fdcb9cb9SLothar Rubuschfalls below it again within this window, a double tap event is triggered upon
206fdcb9cb9SLothar Rubuschthe fall below the threshold.
207fdcb9cb9SLothar Rubusch
208fdcb9cb9SLothar RubuschDouble tap event detection is thoroughly explained in the datasheet. After a
209fdcb9cb9SLothar Rubuschsingle tap event is detected, a double tap event may follow, provided the signal
210fdcb9cb9SLothar Rubuschmeets certain criteria. However, double tap detection can be invalidated for
211fdcb9cb9SLothar Rubuschthree reasons:
212fdcb9cb9SLothar Rubusch
213fdcb9cb9SLothar Rubusch* If the **suppress bit** is set, any acceleration spike above the tap
214fdcb9cb9SLothar Rubusch  threshold during the tap latency period immediately invalidates the double tap
215fdcb9cb9SLothar Rubusch  detection. In other words, no spikes are allowed during latency when the
216fdcb9cb9SLothar Rubusch  suppress bit is active.
217fdcb9cb9SLothar Rubusch
218fdcb9cb9SLothar Rubusch* The double tap event is invalid if the acceleration is above the threshold at
219fdcb9cb9SLothar Rubusch  the start of the double tap window.
220fdcb9cb9SLothar Rubusch
221fdcb9cb9SLothar Rubusch* Double tap detection is also invalidated if the acceleration duration exceeds
222fdcb9cb9SLothar Rubusch  the limit set by the duration register.
223fdcb9cb9SLothar Rubusch
224fdcb9cb9SLothar RubuschFor double tap detection, the same duration applies as for single tap: the
225fdcb9cb9SLothar Rubuschacceleration must rise above the threshold and then fall below it within the
226fdcb9cb9SLothar Rubuschspecified duration. Note that the suppress bit is typically enabled when double
227fdcb9cb9SLothar Rubuschtap detection is active.
228fdcb9cb9SLothar Rubusch
229fdcb9cb9SLothar RubuschUsage Examples
230fdcb9cb9SLothar Rubusch--------------
231fdcb9cb9SLothar Rubusch
232fdcb9cb9SLothar RubuschShow device name:
233fdcb9cb9SLothar Rubusch
234fdcb9cb9SLothar Rubusch.. code-block:: bash
235fdcb9cb9SLothar Rubusch
236fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> cat name
237fdcb9cb9SLothar Rubusch        adxl345
238fdcb9cb9SLothar Rubusch
239fdcb9cb9SLothar RubuschShow accelerometer channels value:
240fdcb9cb9SLothar Rubusch
241fdcb9cb9SLothar Rubusch.. code-block:: bash
242fdcb9cb9SLothar Rubusch
243fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> cat in_accel_x_raw
244fdcb9cb9SLothar Rubusch        -1
245fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> cat in_accel_y_raw
246fdcb9cb9SLothar Rubusch        2
247fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> cat in_accel_z_raw
248fdcb9cb9SLothar Rubusch        -253
249fdcb9cb9SLothar Rubusch
250fdcb9cb9SLothar RubuschSet calibration offset for accelerometer channels:
251fdcb9cb9SLothar Rubusch
252fdcb9cb9SLothar Rubusch.. code-block:: bash
253fdcb9cb9SLothar Rubusch
254fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> cat in_accel_x_calibbias
255fdcb9cb9SLothar Rubusch        0
256fdcb9cb9SLothar Rubusch
257fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 50 > in_accel_x_calibbias
258fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> cat in_accel_x_calibbias
259fdcb9cb9SLothar Rubusch        50
260fdcb9cb9SLothar Rubusch
261fdcb9cb9SLothar RubuschGiven the 13-bit full resolution, the available ranges are calculated by the
262fdcb9cb9SLothar Rubuschfollowing formula:
263fdcb9cb9SLothar Rubusch
264fdcb9cb9SLothar Rubusch.. code-block:: bash
265fdcb9cb9SLothar Rubusch
266fdcb9cb9SLothar Rubusch        (g * 2 * 9.80665) / (2^(resolution) - 1) * 100; for g := 2|4|8|16
267fdcb9cb9SLothar Rubusch
268fdcb9cb9SLothar RubuschScale range configuration:
269fdcb9cb9SLothar Rubusch
270fdcb9cb9SLothar Rubusch.. code-block:: bash
271fdcb9cb9SLothar Rubusch
272fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_scale
273fdcb9cb9SLothar Rubusch        0.478899
274fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_scale_available
275fdcb9cb9SLothar Rubusch        0.478899 0.957798 1.915595 3.831190
276fdcb9cb9SLothar Rubusch
277fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 1.915595 > ./in_accel_scale
278fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_scale
279fdcb9cb9SLothar Rubusch        1.915595
280fdcb9cb9SLothar Rubusch
281fdcb9cb9SLothar RubuschSet output data rate (ODR):
282fdcb9cb9SLothar Rubusch
283fdcb9cb9SLothar Rubusch.. code-block:: bash
284fdcb9cb9SLothar Rubusch
285fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_sampling_frequency
286fdcb9cb9SLothar Rubusch        200.000000
287fdcb9cb9SLothar Rubusch
288fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_sampling_frequency_available
289fdcb9cb9SLothar Rubusch        0.097000 0.195000 0.390000 0.781000 1.562000 3.125000 6.250000 12.500000 25.000000 50.000000 100.000000 200.000000 400.000000 800.000000 1600.000000 3200.000000
290fdcb9cb9SLothar Rubusch
291fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 1.562000 > ./in_accel_sampling_frequency
292fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_sampling_frequency
293fdcb9cb9SLothar Rubusch        1.562000
294fdcb9cb9SLothar Rubusch
295fdcb9cb9SLothar RubuschConfigure one or several events:
296fdcb9cb9SLothar Rubusch
297fdcb9cb9SLothar Rubusch.. code-block:: bash
298fdcb9cb9SLothar Rubusch
299fdcb9cb9SLothar Rubusch        root:> cd /sys/bus/iio/devices/iio:device0
300fdcb9cb9SLothar Rubusch
301fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 1 > ./buffer0/in_accel_x_en
302fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 1 > ./buffer0/in_accel_y_en
303fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 1 > ./buffer0/in_accel_z_en
304fdcb9cb9SLothar Rubusch
305fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 1 > ./scan_elements/in_accel_x_en
306fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 1 > ./scan_elements/in_accel_y_en
307fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 1 > ./scan_elements/in_accel_z_en
308fdcb9cb9SLothar Rubusch
309fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 14   > ./in_accel_x_calibbias
310fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 2    > ./in_accel_y_calibbias
311fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo -250 > ./in_accel_z_calibbias
312fdcb9cb9SLothar Rubusch
313fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 24 > ./buffer0/length
314fdcb9cb9SLothar Rubusch
315fdcb9cb9SLothar Rubusch        ## AC coupled activity, threshold [62.5/LSB]
316fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 6 > ./events/in_accel_mag_adaptive_rising_value
317fdcb9cb9SLothar Rubusch
318fdcb9cb9SLothar Rubusch        ## AC coupled inactivity, threshold, [62.5/LSB]
319fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 4 > ./events/in_accel_mag_adaptive_falling_value
320fdcb9cb9SLothar Rubusch
321fdcb9cb9SLothar Rubusch        ## AC coupled inactivity, time [s]
322fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 3 > ./events/in_accel_mag_adaptive_falling_period
323fdcb9cb9SLothar Rubusch
324fdcb9cb9SLothar Rubusch        ## singletap, threshold
325fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 35 > ./events/in_accel_gesture_singletap_value
326fdcb9cb9SLothar Rubusch
327fdcb9cb9SLothar Rubusch        ## singletap, duration [us]
328fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 0.001875  > ./events/in_accel_gesture_singletap_timeout
329fdcb9cb9SLothar Rubusch
330fdcb9cb9SLothar Rubusch        ## doubletap, window [us]
331fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 0.025 > ./events/in_accel_gesture_doubletap_reset_timeout
332fdcb9cb9SLothar Rubusch
333fdcb9cb9SLothar Rubusch        ## doubletap, latent [us]
334fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 0.025 > ./events/in_accel_gesture_doubletap_tap2_min_delay
335fdcb9cb9SLothar Rubusch
336fdcb9cb9SLothar Rubusch        ## AC coupled activity, enable
337fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_mag_adaptive_rising_en
338fdcb9cb9SLothar Rubusch
339fdcb9cb9SLothar Rubusch        ## AC coupled inactivity, enable
340fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_x\&y\&z_mag_adaptive_falling_en
341fdcb9cb9SLothar Rubusch
342fdcb9cb9SLothar Rubusch        ## singletap, enable
343fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_x_gesture_singletap_en
344fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_y_gesture_singletap_en
345fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_z_gesture_singletap_en
346fdcb9cb9SLothar Rubusch
347fdcb9cb9SLothar Rubusch        ## doubletap, enable
348fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_gesture_doubletap_en
349fdcb9cb9SLothar Rubusch
350fdcb9cb9SLothar RubuschVerify incoming events:
351fdcb9cb9SLothar Rubusch
352fdcb9cb9SLothar Rubusch.. code-block:: bash
353fdcb9cb9SLothar Rubusch
354fdcb9cb9SLothar Rubusch        root:# iio_event_monitor adxl345
355fdcb9cb9SLothar Rubusch        Found IIO device with name adxl345 with device number 0
356fdcb9cb9SLothar Rubusch        Event: time: 1739063415957073383, type: accel(z), channel: 0, evtype: mag, direction: rising
357fdcb9cb9SLothar Rubusch        Event: time: 1739063415963770218, type: accel(z), channel: 0, evtype: mag, direction: rising
358fdcb9cb9SLothar Rubusch        Event: time: 1739063416002563061, type: accel(z), channel: 0, evtype: gesture, direction: singletap
359fdcb9cb9SLothar Rubusch        Event: time: 1739063426271128739, type: accel(x&y&z), channel: 0, evtype: mag, direction: falling
360fdcb9cb9SLothar Rubusch        Event: time: 1739063436539080713, type: accel(x&y&z), channel: 0, evtype: mag, direction: falling
361fdcb9cb9SLothar Rubusch        Event: time: 1739063438357970381, type: accel(z), channel: 0, evtype: mag, direction: rising
362fdcb9cb9SLothar Rubusch        Event: time: 1739063446726161586, type: accel(z), channel: 0, evtype: mag, direction: rising
363fdcb9cb9SLothar Rubusch        Event: time: 1739063446727892670, type: accel(z), channel: 0, evtype: mag, direction: rising
364fdcb9cb9SLothar Rubusch        Event: time: 1739063446743019768, type: accel(z), channel: 0, evtype: mag, direction: rising
365fdcb9cb9SLothar Rubusch        Event: time: 1739063446744650696, type: accel(z), channel: 0, evtype: mag, direction: rising
366fdcb9cb9SLothar Rubusch        Event: time: 1739063446763559386, type: accel(z), channel: 0, evtype: gesture, direction: singletap
367fdcb9cb9SLothar Rubusch        Event: time: 1739063448818126480, type: accel(x&y&z), channel: 0, evtype: mag, direction: falling
368fdcb9cb9SLothar Rubusch        ...
369fdcb9cb9SLothar Rubusch
370fdcb9cb9SLothar RubuschActivity and inactivity belong together and indicate state changes as follows
371fdcb9cb9SLothar Rubusch
372fdcb9cb9SLothar Rubusch.. code-block:: bash
373fdcb9cb9SLothar Rubusch
374fdcb9cb9SLothar Rubusch        root:# iio_event_monitor adxl345
375fdcb9cb9SLothar Rubusch        Found IIO device with name adxl345 with device number 0
376fdcb9cb9SLothar Rubusch        Event: time: 1744648001133946293, type: accel(x), channel: 0, evtype: mag, direction: rising
377fdcb9cb9SLothar Rubusch          <after inactivity time elapsed>
378fdcb9cb9SLothar Rubusch        Event: time: 1744648057724775499, type: accel(x&y&z), channel: 0, evtype: mag, direction: falling
379fdcb9cb9SLothar Rubusch        ...
380fdcb9cb9SLothar Rubusch
381fdcb9cb9SLothar Rubusch3. Device Buffers
382fdcb9cb9SLothar Rubusch=================
383fdcb9cb9SLothar Rubusch
384fdcb9cb9SLothar RubuschThis driver supports IIO buffers.
385fdcb9cb9SLothar Rubusch
386fdcb9cb9SLothar RubuschAll devices support retrieving the raw acceleration and temperature measurements
387fdcb9cb9SLothar Rubuschusing buffers.
388fdcb9cb9SLothar Rubusch
389fdcb9cb9SLothar RubuschUsage examples
390fdcb9cb9SLothar Rubusch--------------
391fdcb9cb9SLothar Rubusch
392fdcb9cb9SLothar RubuschSelect channels for buffer read:
393fdcb9cb9SLothar Rubusch
394fdcb9cb9SLothar Rubusch.. code-block:: bash
395fdcb9cb9SLothar Rubusch
396fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_accel_x_en
397fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_accel_y_en
398fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_accel_z_en
399fdcb9cb9SLothar Rubusch
400fdcb9cb9SLothar RubuschSet the number of samples to be stored in the buffer:
401fdcb9cb9SLothar Rubusch
402fdcb9cb9SLothar Rubusch.. code-block:: bash
403fdcb9cb9SLothar Rubusch
404fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 10 > buffer/length
405fdcb9cb9SLothar Rubusch
406fdcb9cb9SLothar RubuschEnable buffer readings:
407fdcb9cb9SLothar Rubusch
408fdcb9cb9SLothar Rubusch.. code-block:: bash
409fdcb9cb9SLothar Rubusch
410fdcb9cb9SLothar Rubusch        root:/sys/bus/iio/devices/iio:device0> echo 1 > buffer/enable
411fdcb9cb9SLothar Rubusch
412fdcb9cb9SLothar RubuschObtain buffered data:
413fdcb9cb9SLothar Rubusch
414fdcb9cb9SLothar Rubusch.. code-block:: bash
415fdcb9cb9SLothar Rubusch
416fdcb9cb9SLothar Rubusch        root:> iio_readdev -b 16 -s 1024 adxl345 | hexdump -d
417fdcb9cb9SLothar Rubusch        WARNING: High-speed mode not enabled
418fdcb9cb9SLothar Rubusch        0000000   00003   00012   00013   00005   00010   00011   00005   00011
419fdcb9cb9SLothar Rubusch        0000010   00013   00004   00012   00011   00003   00012   00014   00007
420fdcb9cb9SLothar Rubusch        0000020   00011   00013   00004   00013   00014   00003   00012   00013
421fdcb9cb9SLothar Rubusch        0000030   00004   00012   00013   00005   00011   00011   00005   00012
422fdcb9cb9SLothar Rubusch        0000040   00014   00005   00012   00014   00004   00010   00012   00004
423fdcb9cb9SLothar Rubusch        0000050   00013   00011   00003   00011   00012   00005   00011   00013
424fdcb9cb9SLothar Rubusch        0000060   00003   00012   00012   00003   00012   00012   00004   00012
425fdcb9cb9SLothar Rubusch        0000070   00012   00003   00013   00013   00003   00013   00012   00005
426fdcb9cb9SLothar Rubusch        0000080   00012   00013   00003   00011   00012   00005   00012   00013
427fdcb9cb9SLothar Rubusch        0000090   00003   00013   00011   00005   00013   00014   00003   00012
428fdcb9cb9SLothar Rubusch        00000a0   00012   00003   00012   00013   00004   00012   00015   00004
429fdcb9cb9SLothar Rubusch        00000b0   00014   00011   00003   00014   00013   00004   00012   00011
430fdcb9cb9SLothar Rubusch        00000c0   00004   00012   00013   00004   00014   00011   00004   00013
431fdcb9cb9SLothar Rubusch        00000d0   00012   00002   00014   00012   00005   00012   00013   00005
432fdcb9cb9SLothar Rubusch        00000e0   00013   00013   00003   00013   00013   00005   00012   00013
433fdcb9cb9SLothar Rubusch        00000f0   00004   00014   00015   00005   00012   00011   00005   00012
434fdcb9cb9SLothar Rubusch        ...
435fdcb9cb9SLothar Rubusch
436fdcb9cb9SLothar RubuschSee ``Documentation/iio/iio_devbuf.rst`` for more information about how buffered
437fdcb9cb9SLothar Rubuschdata is structured.
438fdcb9cb9SLothar Rubusch
439fdcb9cb9SLothar Rubusch4. IIO Interfacing Tools
440fdcb9cb9SLothar Rubusch========================
441fdcb9cb9SLothar Rubusch
442fdcb9cb9SLothar RubuschSee ``Documentation/iio/iio_tools.rst`` for the description of the available IIO
443fdcb9cb9SLothar Rubuschinterfacing tools.
444