← Documents Documentation/iio/adxl345.rst GitHub 원문 ↗

Linux 6.18.37 · IIO

ADXL345 driver

ADXL345/375의 범위·ODR, activity/free-fall, tap 이벤트와 IIO 버퍼를 설명합니다.

Source pathDocumentation/iio/adxl345.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

adxl345.rst:1-443

ADXL345 드라이버는 SPI·I²C 가속도계의 범위와 ODR, 축별 보정, activity·inactivity·free-fall, single/double tap 이벤트와 IIO 버퍼를 제공합니다. 이벤트 기간에 따른 레지스터 경로와 AC/DC 결합·auto-sleep 규칙이 핵심입니다.

문서 개요
항목
SourceDocumentation/iio/adxl345.rst
분량443 source lines
지원 장치ADXL345, ADXL375
ADXL345 범위±2 g, ±4 g, ±8 g, ±16 g
이벤트Activity, inactivity, free-fall, single/double tap

지원 범위와 주요 기능을 요약합니다.

통합 가속도 흐름
Scale range와 ODR 선택3축 raw·calibbias 처리Activity·inactivity 또는 tap 조건 설정INT1/INT2를 통해 IIO event 수신IIO buffer 또는 event monitor로 결과 확인

측정 설정에서 이벤트·버퍼 수집까지의 전체 경로입니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

지원 장치·속성과 처리값

1-73

이 드라이버는 SPI 또는 I²C 버스에 연결된 Analog Devices ADXL345와 ADXL375를 지원합니다.

ADXL345는 측정 범위를 선택할 수 있는 범용 저전력 3축 가속도계입니다. 지원 범위는 ±2 g, ±4 g, ±8 g, ±16 g입니다.

ADXL345 계열 지원 장치
장치버스측정 범위
ADXL345SPI 또는 I²C±2 g, ±4 g, ±8 g, ±16 g
ADXL375SPI 또는 I²C장치 고유 범위

동일 드라이버가 지원하는 장치와 ADXL345의 선택 가능한 범위입니다.

각 IIO 장치에는 `/sys/bus/iio/devices/iio:deviceX` 폴더가 있으며 X는 IIO 인덱스입니다. 하드웨어 기능에 따른 장치 파일이 이 경로 아래에 생성되고 일반 인터페이스는 IIO ABI 문서에 정의됩니다.

ADXL345 3축 가속도 속성
장치 파일설명
`in_accel_sampling_frequency`현재 선택한 sample rate
`in_accel_sampling_frequency_available`선택 가능한 sampling frequency 목록
`in_accel_scale`가속도계 채널 scale/range
`in_accel_scale_available`선택 가능한 scale range
`in_accel_x_calibbias`X축 가속도 보정 오프셋
`in_accel_x_raw`X축 가속도 원시 값
`in_accel_y_calibbias`Y축 가속도 오프셋 보정
`in_accel_y_raw`Y축 가속도 원시 값
`in_accel_z_calibbias`Z축 가속도 보정 오프셋
`in_accel_z_raw`Z축 가속도 원시 값

샘플 속도·범위와 축별 원시 값·보정 오프셋입니다.

채널의 `_raw` 속성은 장치 원시 값을 반환합니다. 처리된 값은 다음 공식으로 계산합니다.

processed value = (_raw + _offset) * _scale

`_offset`과 `_scale`은 장치 속성입니다. `_offset`이 없다면 0으로 간주합니다. X·Y·Z축 가속도의 처리 단위는 m/s²입니다.

ADXL345 처리값 단위
채널 유형처리값 단위
X·Y·Z축 가속도m/s²

IIO 프레임워크가 정의하는 가속도 처리 단위입니다.

ADXL345 가속도 처리
±2 g~±16 g 범위와 ODR 선택X·Y·Z 원시 값 취득축별 calibbias 적용선택한 scale 적용m/s² 처리값 산출

측정 범위 선택부터 물리 단위 결과까지의 흐름입니다.

.. SPDX-License-Identifier: GPL-2.0

===============
ADXL345 driver
===============

This driver supports Analog Device's ADXL345/375 on SPI/I2C bus.

1. Supported Devices
====================

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

The ADXL345 is a generic purpose low power, 3-axis accelerometer with selectable
measurement ranges. The ADXL345 supports the ±2 g, ±4 g, ±8 g, and ±16 g ranges.

2. Device Attributes
====================

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 table shows the ADXL345 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_sampling_frequency               | Currently selected sample rate.                          |
+-------------------------------------------+----------------------------------------------------------+
| in_accel_sampling_frequency_available     | Available sampling frequency configurations.             |
+-------------------------------------------+----------------------------------------------------------+
| in_accel_scale                            | Scale/range for the accelerometer channels.              |
+-------------------------------------------+----------------------------------------------------------+
| in_accel_scale_available                  | Available scale ranges for the accelerometer channel.    |
+-------------------------------------------+----------------------------------------------------------+
| in_accel_x_calibbias                      | Calibration offset for the X-axis accelerometer channel. |
+-------------------------------------------+----------------------------------------------------------+
| in_accel_x_raw                            | Raw X-axis accelerometer channel value.                  |
+-------------------------------------------+----------------------------------------------------------+
| in_accel_y_calibbias                      | y-axis acceleration offset correction                    |
+-------------------------------------------+----------------------------------------------------------+
| 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_raw                            | Raw Z-axis accelerometer channel value.                  |
+-------------------------------------------+----------------------------------------------------------+

Channel 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.

+-------------------------------------+---------------------------+
| Channel type                        | Measurement unit          |
+-------------------------------------+---------------------------+
| Acceleration on X, Y, and Z axis    | Meters per second squared |
+-------------------------------------+---------------------------+

이벤트 인터페이스와 inactivity 분기

74-144

각 IIO 이벤트는 대응 인터럽트에서 발생합니다. 센서 드라이버는 활성 인터럽트 선을 사용하지 않거나 INT1·INT2 중 하나만 사용합니다. 활성 INT 선은 Device Tree에 지정해야 합니다.

INT 선이 없으면 센서는 FIFO bypass 모드가 기본값이 됩니다. 이때 이벤트 감지는 비활성화되고 X·Y·Z축 측정값만 사용할 수 있습니다.

이벤트 파일은 `/sys/bus/iio/devices/iio:deviceX/events`에 있습니다. Activity와 inactivity는 기본적으로 DC 결합이므로 표에는 AC 결합 전용 파일도 명시적으로 나옵니다.

ADXL345 이벤트 속성
이벤트 파일설명
`in_accel_gesture_doubletap_en`모든 축의 double tap 감지 활성화
`in_accel_gesture_doubletap_reset_timeout`Double tap window, µs
`in_accel_gesture_doubletap_tap2_min_delay`Double tap latency, µs
`in_accel_gesture_singletap_timeout`Single tap duration, µs
`in_accel_gesture_singletap_value`Single tap threshold, 62.5/LSB
`in_accel_mag_falling_period`Inactivity 시간, 초
`in_accel_mag_falling_value`Inactivity threshold, 62.5/LSB
`in_accel_mag_adaptive_rising_en`X축 AC 결합 activity 활성화
`in_accel_mag_adaptive_falling_period`AC 결합 inactivity 시간, 초
`in_accel_mag_adaptive_falling_value`AC inactivity threshold, 62.5/LSB
`in_accel_mag_adaptive_rising_value`AC activity threshold, 62.5/LSB
`in_accel_mag_rising_en`X축 activity 감지 활성화
`in_accel_mag_rising_value`Activity threshold, 62.5/LSB
`in_accel_x_gesture_singletap_en`X축 single tap 활성화
`in_accel_x&y&z_mag_falling_en`모든 축 inactivity 활성화
`in_accel_x&y&z_mag_adaptive_falling_en`모든 축 AC inactivity 활성화
`in_accel_y_gesture_singletap_en`Y축 single tap 활성화
`in_accel_z_gesture_singletap_en`Z축 single tap 활성화

Tap, activity, inactivity와 AC 적응형 감지 설정입니다.

세부 기능은 센서 데이터시트를 참고합니다. ODR을 수동 설정하면 드라이버가 inactivity 감지의 기본 대기 시간을 추정합니다. ODR이 높을수록 기본 대기 시간은 길어지고 ODR이 낮을수록 짧아집니다. 명시적 시간을 설정할 수 있으며 0을 쓰면 기본 동작으로 돌아갑니다.

g 범위를 변경하면 드라이버는 이전 범위와 새 범위의 비율로 기본값을 조정해 activity·inactivity 임계값을 추정합니다. 결과는 0이 되지 않으며 항상 1~255 범위에 있습니다. 데이터시트의 단위는 최대 62.5 g/LSB이며 사용자가 명시적 값으로 추정치를 덮어쓸 수 있습니다.

ODR·범위 자동 추정
변경자동 조정사용자 재정의
ODR 증가Inactivity 기본 대기 시간 증가명시적 기간 설정 가능
ODR 감소Inactivity 기본 대기 시간 감소0을 쓰면 기본값 복귀
g range 변경이전/새 범위 비율로 threshold 재조정1~255 범위의 명시적 값 가능

사용자가 ODR 또는 g 범위를 바꿀 때 드라이버가 조정하는 기본값입니다.

인터럽트 구성에 따른 기능
Device Tree에서 INT1 또는 INT2 하나 선택선택한 선으로 IIO 이벤트 매핑INT가 없으면 FIFO bypass이벤트 감지 비활성화X·Y·Z 측정만 제공

Device Tree INT 설정 여부가 이벤트와 FIFO 동작을 결정합니다.

Sensor Events
-------------

Specific IIO events are triggered by their corresponding interrupts. The sensor
driver supports either none or a single active interrupt (INT) line, selectable
from the two available options: INT1 or INT2. The active INT line should be
specified in the device tree. If no INT line is configured, the sensor defaults
to FIFO bypass mode, where event detection is disabled and only X, Y, and Z axis
measurements are available.

The table below lists the ADXL345-related device files located in the
device-specific path: ``/sys/bus/iio/devices/iio:deviceX/events``.
Note that activity and inactivity detection are DC-coupled by default;
therefore, only the AC-coupled activity and inactivity events are explicitly
listed.

+---------------------------------------------+---------------------------------------------+
| Event handle                                | Description                                 |
+---------------------------------------------+---------------------------------------------+
| in_accel_gesture_doubletap_en               | Enable double tap detection on all axis     |
+---------------------------------------------+---------------------------------------------+
| in_accel_gesture_doubletap_reset_timeout    | Double tap window in [us]                   |
+---------------------------------------------+---------------------------------------------+
| in_accel_gesture_doubletap_tap2_min_delay   | Double tap latent in [us]                   |
+---------------------------------------------+---------------------------------------------+
| in_accel_gesture_singletap_timeout          | Single tap duration in [us]                 |
+---------------------------------------------+---------------------------------------------+
| in_accel_gesture_singletap_value            | Single tap threshold value in 62.5/LSB      |
+---------------------------------------------+---------------------------------------------+
| in_accel_mag_falling_period                 | Inactivity time in seconds                  |
+---------------------------------------------+---------------------------------------------+
| in_accel_mag_falling_value                  | Inactivity threshold value in 62.5/LSB      |
+---------------------------------------------+---------------------------------------------+
| in_accel_mag_adaptive_rising_en             | Enable AC coupled activity on X axis        |
+---------------------------------------------+---------------------------------------------+
| in_accel_mag_adaptive_falling_period        | AC coupled inactivity time in seconds       |
+---------------------------------------------+---------------------------------------------+
| in_accel_mag_adaptive_falling_value         | AC coupled inactivity threshold in 62.5/LSB |
+---------------------------------------------+---------------------------------------------+
| in_accel_mag_adaptive_rising_value          | AC coupled activity threshold in 62.5/LSB   |
+---------------------------------------------+---------------------------------------------+
| in_accel_mag_rising_en                      | Enable activity detection on X axis         |
+---------------------------------------------+---------------------------------------------+
| in_accel_mag_rising_value                   | Activity threshold value in 62.5/LSB        |
+---------------------------------------------+---------------------------------------------+
| in_accel_x_gesture_singletap_en             | Enable single tap detection on X axis       |
+---------------------------------------------+---------------------------------------------+
| in_accel_x&y&z_mag_falling_en               | Enable inactivity detection on all axis     |
+---------------------------------------------+---------------------------------------------+
| in_accel_x&y&z_mag_adaptive_falling_en      | Enable AC coupled inactivity on all axis    |
+---------------------------------------------+---------------------------------------------+
| in_accel_y_gesture_singletap_en             | Enable single tap detection on Y axis       |
+---------------------------------------------+---------------------------------------------+
| in_accel_z_gesture_singletap_en             | Enable single tap detection on Z axis       |
+---------------------------------------------+---------------------------------------------+

Please refer to the sensor's datasheet for a detailed description of this
functionality.

Manually setting the **ODR** will cause the driver to estimate default values
for inactivity detection timing, where higher ODR values correspond to longer
default wait times, and lower ODR values to shorter ones. If these defaults do
not meet your application’s needs, you can explicitly configure the inactivity
wait time. Setting this value to 0 will revert to the default behavior.

When changing the **g range** configuration, the driver attempts to estimate
appropriate activity and inactivity thresholds by scaling the default values
based on the ratio of the previous range to the new one. The resulting threshold
will never be zero and will always fall between 1 and 255, corresponding to up
to 62.5 g/LSB as specified in the datasheet. However, you can override these
estimated thresholds by setting explicit values.

Auto-sleep·free-fall과 tap 판정

145-228

Activity와 inactivity 이벤트를 모두 켜면 드라이버가 `link`와 `auto-sleep` 비트를 설정해 히스테리시스를 자동 관리합니다. Link는 두 기능이 서로 이어지게 하고, auto-sleep은 inactivity 감지 시 센서를 12.5 Hz 미만의 절전 속도로 전환합니다.

Inactivity 시간은 1~255초로 설정할 수 있습니다. Free-fall도 지원하며 IIO에서는 모든 축 크기가 떨어지는 이벤트로 처리합니다. 센서 관점의 free-fall은 0.000~1.000초 inactivity 기간으로 정의됩니다.

Inactivity 기간에 따른 경로
설정 기간처리Link/auto-sleep·결합
1초 이상Inactivity register 사용Activity 연동, auto-sleep, AC/DC 가능
0초 초과 1초 미만Plain inactivity 또는 free-fallAuto-sleep과 AC/DC 결합 미적용
0초휴리스틱 기본값, 1초 초과Inactivity register 사용, 절전 최적화

1초 경계와 0초 특수값이 레지스터·결합·절전 기능을 결정합니다.

데이터시트는 activity·inactivity 또는 free-fall 레지스터 사용 시 12.5~400 Hz ODR을 권장합니다. 권장 free-fall 임계값은 300~600 mg이며 레지스터 값은 0x05~0x09입니다.

DC 결합에서는 현재 가속도 크기를 THRESH_ACT·THRESH_INACT의 고정 임계값과 직접 비교합니다. AC 결합 activity는 감지 시작 시점의 가속도를 기준으로 잡고 이후 샘플을 그 기준과 비교합니다. 즉 DC는 현재 값과 고정 임계값을, AC는 내부 필터가 만든 상대값과 설정 임계값을 비교합니다.

AC·DC 결합 비교
방식비교 기준전환 규칙
DC현재 가속도 대 고정 THRESH_ACT/THRESH_INACT기본 방식
AC감지 시작 기준점에 대한 상대 변화내부 filter 사용
전환Activity와 inactivity별 독립 설정가장 최근 설정 하나만 활성

Activity와 inactivity 각각에서 한 방식만 활성화됩니다.

Single tap은 임계값과 duration을 설정합니다. Single tap만 켜면 가속도가 임계값을 넘는 순간 duration이 시작되고 제한 시간 안에 다시 아래로 떨어질 때 인터럽트가 발생합니다. Single과 double tap을 함께 켜면 double tap이 확정되거나 기각된 뒤에 single tap 인터럽트가 발생합니다.

Double tap에는 window와 latency를 µs 단위로 추가 설정해야 합니다. 첫 tap 신호가 임계값 아래로 내려가면 latency가 시작되며 이 기간의 spike는 double tap 판정에서 무시됩니다. Latency가 끝나면 window가 시작되고, 그 안에서 가속도가 임계값 위로 올랐다가 다시 아래로 내려가면 내려가는 순간 double tap 이벤트가 발생합니다.

Double tap 무효화 조건
조건무효화 이유
Suppress bit 활성 + latency 중 threshold 초과 spikeLatency에는 spike를 허용하지 않음
Double tap window 시작 시 이미 threshold 위유효한 두 번째 상승 경계가 없음
가속도 duration이 register 제한 초과Tap 지속 시간 조건 위반

첫 tap 뒤 double tap 후보가 기각되는 세 조건입니다.

Double tap에도 single tap과 같은 duration 제한이 적용됩니다. 가속도는 지정된 시간 안에 임계값 위로 올랐다가 아래로 내려와야 합니다. Double tap 감지 시 suppress bit는 일반적으로 활성화합니다.

Double tap 판정
첫 tap이 threshold 아래로 복귀Latency 시작, spike 판정 규칙 적용Latency 종료 후 detection window 시작Window 안에서 두 번째 threshold 상승Duration 안에 하강하면 double tap 확정

첫 tap 종료부터 두 번째 tap 확정까지의 시간 순서입니다.


When **activity** and **inactivity** events are enabled, the driver
automatically manages hysteresis behavior by setting the **link** and
**auto-sleep** bits. The link bit connects the activity and inactivity
functions, so that one follows the other. The auto-sleep function puts the
sensor into sleep mode when inactivity is detected, reducing power consumption
to the sub-12.5 Hz rate.

The inactivity time is configurable between 1 and 255 seconds. In addition to
inactivity detection, the sensor also supports free-fall detection, which, from
the IIO perspective, is treated as a fall in magnitude across all axes. In
sensor terms, free-fall is defined using an inactivity period ranging from 0.000
to 1.000 seconds.

The driver behaves as follows:

* If the configured inactivity period is 1 second or more, the driver uses the
  sensor's inactivity register. This allows the event to be linked with
  activity detection, use auto-sleep, and be either AC- or DC-coupled.

* If the inactivity period is less than 1 second, the event is treated as plain
  inactivity or free-fall detection. In this case, auto-sleep and coupling
  (AC/DC) are not applied.

* If an inactivity time of 0 seconds is configured, the driver selects a
  heuristically determined default period (greater than 1 second) to optimize
  power consumption. This also uses the inactivity register.

Note: According to the datasheet, the optimal ODR for detecting activity,
or inactivity (or when operating with the free-fall register) should fall within
the range of 12.5 Hz to 400 Hz. The recommended free-fall threshold is between
300 mg and 600 mg (register values 0x05 to 0x09).

In DC-coupled mode, the current acceleration magnitude is directly compared to
the values in the THRESH_ACT and THRESH_INACT registers to determine activity or
inactivity. In contrast, AC-coupled activity detection uses the acceleration
value at the start of detection as a reference point, and subsequent samples are
compared against this reference. While DC-coupling is the default mode-comparing
live values to fixed thresholds-AC-coupling relies on an internal filter
relative to the configured threshold.

AC and DC coupling modes are configured separately for activity and inactivity
detection, but only one mode can be active at a time for each. For example, if
AC-coupled activity detection is enabled and then DC-coupled mode is set, only
DC-coupled activity detection will be active. In other words, only the most
recent configuration is applied.

**Single tap** detection can be configured per the datasheet by setting the
threshold and duration parameters. When only single tap detection is enabled,
the single tap interrupt triggers as soon as the acceleration exceeds the
threshold (marking the start of the duration) and then falls below it, provided
the duration limit is not exceeded. If both single tap and double tap detections
are enabled, the single tap interrupt is triggered only after the double tap
event has been either confirmed or dismissed.

To configure **double tap** detection, you must also set the window and latency
parameters in microseconds (µs). The latency period begins once the single tap
signal drops below the threshold and acts as a waiting time during which any
spikes are ignored for double tap detection. After the latency period ends, the
detection window starts. If the acceleration rises above the threshold and then
falls below it again within this window, a double tap event is triggered upon
the fall below the threshold.

Double tap event detection is thoroughly explained in the datasheet. After a
single tap event is detected, a double tap event may follow, provided the signal
meets certain criteria. However, double tap detection can be invalidated for
three reasons:

* If the **suppress bit** is set, any acceleration spike above the tap
  threshold during the tap latency period immediately invalidates the double tap
  detection. In other words, no spikes are allowed during latency when the
  suppress bit is active.

* The double tap event is invalid if the acceleration is above the threshold at
  the start of the double tap window.

* Double tap detection is also invalidated if the acceleration duration exceeds
  the limit set by the duration register.

For double tap detection, the same duration applies as for single tap: the
acceleration must rise above the threshold and then fall below it within the
specified duration. Note that the suppress bit is typically enabled when double
tap detection is active.

범위·ODR·이벤트 사용 예

229-380

장치 이름 예제 결과는 `adxl345`이며 X·Y·Z축 원시 값은 각각 −1, 2, −253입니다.

root:/sys/bus/iio/devices/iio:device0> cat name
adxl345
root:/sys/bus/iio/devices/iio:device0> cat in_accel_x_raw
-1
root:/sys/bus/iio/devices/iio:device0> cat in_accel_y_raw
2
root:/sys/bus/iio/devices/iio:device0> cat in_accel_z_raw
-253

X축 보정 오프셋은 0에서 50으로 변경합니다.

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

13비트 full resolution에서 사용 가능한 범위는 다음 공식으로 계산합니다. 여기서 g는 2, 4, 8, 16 중 하나입니다.

(g * 2 * 9.80665) / (2^(resolution) - 1) * 100; for g := 2|4|8|16

현재 scale은 0.478899이고 선택 가능한 값은 0.478899, 0.957798, 1.915595, 3.831190입니다. 예제에서는 1.915595를 선택합니다.

cat ./in_accel_scale
0.478899
cat ./in_accel_scale_available
0.478899 0.957798 1.915595 3.831190
echo 1.915595 > ./in_accel_scale

현재 ODR은 200 Hz입니다. 사용 가능한 주파수는 0.097부터 3200 Hz까지 16개이며 예제에서는 1.562 Hz를 선택합니다.

cat ./in_accel_sampling_frequency
200.000000
cat ./in_accel_sampling_frequency_available
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
echo 1.562000 > ./in_accel_sampling_frequency
범위와 ODR 예제
설정기존 값선택 값
Scale0.4788991.915595
ODR200.000000 Hz1.562000 Hz

원문에서 조회하고 선택하는 scale·sample rate 값입니다.

복합 이벤트 예제는 buffer0과 scan_elements에서 X·Y·Z 채널을 켜고, 축 보정값 14, 2, −250과 buffer0 길이 24를 설정합니다.

이벤트 값은 AC activity 임계값 6, AC inactivity 임계값 4와 기간 3초, single tap 임계값 35와 duration 0.001875, double tap window 0.025와 latency 0.025로 설정합니다.

echo 6 > ./events/in_accel_mag_adaptive_rising_value
echo 4 > ./events/in_accel_mag_adaptive_falling_value
echo 3 > ./events/in_accel_mag_adaptive_falling_period
echo 35 > ./events/in_accel_gesture_singletap_value
echo 0.001875 > ./events/in_accel_gesture_singletap_timeout
echo 0.025 > ./events/in_accel_gesture_doubletap_reset_timeout
echo 0.025 > ./events/in_accel_gesture_doubletap_tap2_min_delay

그 뒤 AC activity, 모든 축 AC inactivity, X·Y·Z single tap, 모든 축 double tap 이벤트를 각각 활성화합니다.

echo 1 > ./events/in_accel_mag_adaptive_rising_en
echo 1 > ./events/in_accel_x\&y\&z_mag_adaptive_falling_en
echo 1 > ./events/in_accel_x_gesture_singletap_en
echo 1 > ./events/in_accel_y_gesture_singletap_en
echo 1 > ./events/in_accel_z_gesture_singletap_en
echo 1 > ./events/in_accel_gesture_doubletap_en
복합 이벤트 설정
기능활성화
AC activityThreshold 6`mag_adaptive_rising_en`
AC inactivityThreshold 4, period 3 s`x&y&z_mag_adaptive_falling_en`
Single tapThreshold 35, duration 0.001875X·Y·Z 축별 enable
Double tapWindow 0.025, latency 0.025`doubletap_en`

예제의 임계값·시간과 활성화 대상입니다.

`iio_event_monitor adxl345` 출력에는 특정 축의 `mag rising`, 축별 `gesture singletap`, 모든 축의 `mag falling` 이벤트가 타임스탬프와 함께 나타납니다.

이벤트 모니터 출력
출력 유형의미
`accel(z), mag, rising`Z축 activity 감지
`accel(z), gesture, singletap`Z축 single tap 감지
`accel(x&y&z), mag, falling`모든 축 inactivity 감지

출력의 채널 조합과 방향이 나타내는 상태입니다.

Activity와 inactivity는 상태 전환 쌍입니다. Activity rising 이후 설정한 inactivity 시간이 지나면 모든 축 falling 이벤트가 발생합니다.

Activity·inactivity 상태 전환
특정 축 activity threshold 초과`mag rising` 이벤트설정된 inactivity 시간 대기모든 축이 inactivity 조건 충족`x&y&z mag falling` 이벤트

이벤트 모니터에서 관찰되는 연결된 상태 변화입니다.

Usage Examples
--------------

Show device name:

.. code-block:: bash

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

Show accelerometer channels value:

.. code-block:: bash

        root:/sys/bus/iio/devices/iio:device0> cat in_accel_x_raw
        -1
        root:/sys/bus/iio/devices/iio:device0> cat in_accel_y_raw
        2
        root:/sys/bus/iio/devices/iio:device0> cat in_accel_z_raw
        -253

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 50 > in_accel_x_calibbias
        root:/sys/bus/iio/devices/iio:device0> cat in_accel_x_calibbias
        50

Given the 13-bit full resolution, the available ranges are calculated by the
following formula:

.. code-block:: bash

        (g * 2 * 9.80665) / (2^(resolution) - 1) * 100; for g := 2|4|8|16

Scale range configuration:

.. code-block:: bash

        root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_scale
        0.478899
        root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_scale_available
        0.478899 0.957798 1.915595 3.831190

        root:/sys/bus/iio/devices/iio:device0> echo 1.915595 > ./in_accel_scale
        root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_scale
        1.915595

Set output data rate (ODR):

.. code-block:: bash

        root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_sampling_frequency
        200.000000

        root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_sampling_frequency_available
        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

        root:/sys/bus/iio/devices/iio:device0> echo 1.562000 > ./in_accel_sampling_frequency
        root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_sampling_frequency
        1.562000

Configure one or several events:

.. code-block:: bash

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

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

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

        root:/sys/bus/iio/devices/iio:device0> echo 14   > ./in_accel_x_calibbias
        root:/sys/bus/iio/devices/iio:device0> echo 2    > ./in_accel_y_calibbias
        root:/sys/bus/iio/devices/iio:device0> echo -250 > ./in_accel_z_calibbias

        root:/sys/bus/iio/devices/iio:device0> echo 24 > ./buffer0/length

        ## AC coupled activity, threshold [62.5/LSB]
        root:/sys/bus/iio/devices/iio:device0> echo 6 > ./events/in_accel_mag_adaptive_rising_value

        ## AC coupled inactivity, threshold, [62.5/LSB]
        root:/sys/bus/iio/devices/iio:device0> echo 4 > ./events/in_accel_mag_adaptive_falling_value

        ## AC coupled inactivity, time [s]
        root:/sys/bus/iio/devices/iio:device0> echo 3 > ./events/in_accel_mag_adaptive_falling_period

        ## singletap, threshold
        root:/sys/bus/iio/devices/iio:device0> echo 35 > ./events/in_accel_gesture_singletap_value

        ## singletap, duration [us]
        root:/sys/bus/iio/devices/iio:device0> echo 0.001875  > ./events/in_accel_gesture_singletap_timeout

        ## doubletap, window [us]
        root:/sys/bus/iio/devices/iio:device0> echo 0.025 > ./events/in_accel_gesture_doubletap_reset_timeout

        ## doubletap, latent [us]
        root:/sys/bus/iio/devices/iio:device0> echo 0.025 > ./events/in_accel_gesture_doubletap_tap2_min_delay

        ## AC coupled activity, enable
        root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_mag_adaptive_rising_en

        ## AC coupled inactivity, enable
        root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_x\&y\&z_mag_adaptive_falling_en

        ## singletap, enable
        root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_x_gesture_singletap_en
        root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_y_gesture_singletap_en
        root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_z_gesture_singletap_en

        ## doubletap, enable
        root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_gesture_doubletap_en

Verify incoming events:

.. code-block:: bash

        root:# iio_event_monitor adxl345
        Found IIO device with name adxl345 with device number 0
        Event: time: 1739063415957073383, type: accel(z), channel: 0, evtype: mag, direction: rising
        Event: time: 1739063415963770218, type: accel(z), channel: 0, evtype: mag, direction: rising
        Event: time: 1739063416002563061, type: accel(z), channel: 0, evtype: gesture, direction: singletap
        Event: time: 1739063426271128739, type: accel(x&y&z), channel: 0, evtype: mag, direction: falling
        Event: time: 1739063436539080713, type: accel(x&y&z), channel: 0, evtype: mag, direction: falling
        Event: time: 1739063438357970381, type: accel(z), channel: 0, evtype: mag, direction: rising
        Event: time: 1739063446726161586, type: accel(z), channel: 0, evtype: mag, direction: rising
        Event: time: 1739063446727892670, type: accel(z), channel: 0, evtype: mag, direction: rising
        Event: time: 1739063446743019768, type: accel(z), channel: 0, evtype: mag, direction: rising
        Event: time: 1739063446744650696, type: accel(z), channel: 0, evtype: mag, direction: rising
        Event: time: 1739063446763559386, type: accel(z), channel: 0, evtype: gesture, direction: singletap
        Event: time: 1739063448818126480, type: accel(x&y&z), channel: 0, evtype: mag, direction: falling
        ...

Activity and inactivity belong together and indicate state changes as follows

.. code-block:: bash

        root:# iio_event_monitor adxl345
        Found IIO device with name adxl345 with device number 0
        Event: time: 1744648001133946293, type: accel(x), channel: 0, evtype: mag, direction: rising
          <after inactivity time elapsed>
        Event: time: 1744648057724775499, type: accel(x&y&z), channel: 0, evtype: mag, direction: falling
        ...

IIO 버퍼와 인터페이스 도구

381-443

이 드라이버는 IIO 버퍼를 지원합니다. 모든 지원 장치는 원시 가속도와 온도 측정값을 버퍼로 읽을 수 있습니다.

버퍼 읽기를 위해 X·Y·Z 가속도 scan element를 활성화합니다.

echo 1 > scan_elements/in_accel_x_en
echo 1 > scan_elements/in_accel_y_en
echo 1 > scan_elements/in_accel_z_en

저장할 샘플 수는 `buffer/length`에 10을 쓰고 `buffer/enable`에 1을 써서 수집을 시작합니다.

echo 10 > buffer/length
echo 1 > buffer/enable

원문 예제는 `iio_readdev -b 16 -s 1024 adxl345 | hexdump -d`로 버퍼를 읽습니다. 고속 모드가 켜지지 않았다는 경고 뒤에 10진수 원시 샘플이 연속 출력됩니다.

iio_readdev -b 16 -s 1024 adxl345 | hexdump -d
ADXL345 버퍼 구성
단계설정
채널X·Y·Z `scan_elements` 활성화
길이`buffer/length = 10`
활성화`buffer/enable = 1`
읽기`iio_readdev -b 16 -s 1024 adxl345 | hexdump -d`

세 축 채널 선택부터 사용자 공간 읽기까지의 설정입니다.

ADXL345 버퍼 캡처
X·Y·Z scan element 선택버퍼 길이 10 설정버퍼 활성화`iio_readdev`로 16개 블록·1024개 샘플 요청`hexdump -d`로 원시 값 확인

IIO scan 구성부터 원시 샘플 출력까지의 흐름입니다.

버퍼 데이터 구조는 `Documentation/iio/iio_devbuf.rst`를 참고합니다. 사용 가능한 IIO 인터페이스 도구는 `Documentation/iio/iio_tools.rst`에 설명되어 있습니다.

3. Device Buffers
=================

This driver supports IIO buffers.

All devices support retrieving the raw acceleration and temperature measurements
using buffers.

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

Select channels for buffer read:

.. code-block:: bash

        root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_accel_x_en
        root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_accel_y_en
        root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_accel_z_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:> iio_readdev -b 16 -s 1024 adxl345 | hexdump -d
        WARNING: High-speed mode not enabled
        0000000   00003   00012   00013   00005   00010   00011   00005   00011
        0000010   00013   00004   00012   00011   00003   00012   00014   00007
        0000020   00011   00013   00004   00013   00014   00003   00012   00013
        0000030   00004   00012   00013   00005   00011   00011   00005   00012
        0000040   00014   00005   00012   00014   00004   00010   00012   00004
        0000050   00013   00011   00003   00011   00012   00005   00011   00013
        0000060   00003   00012   00012   00003   00012   00012   00004   00012
        0000070   00012   00003   00013   00013   00003   00013   00012   00005
        0000080   00012   00013   00003   00011   00012   00005   00012   00013
        0000090   00003   00013   00011   00005   00013   00014   00003   00012
        00000a0   00012   00003   00012   00013   00004   00012   00015   00004
        00000b0   00014   00011   00003   00014   00013   00004   00012   00011
        00000c0   00004   00012   00013   00004   00014   00011   00004   00013
        00000d0   00012   00002   00014   00012   00005   00012   00013   00005
        00000e0   00013   00013   00003   00013   00013   00005   00012   00013
        00000f0   00004   00014   00015   00005   00012   00011   00005   00012
        ...

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.