Skip to content

Commit 1fb5da9

Browse files
committed
drivers: sensor: adxl34x: Add sensor driver for ADXL3x motion sensors
The current adxl345 driver doesn't support the extended driver features Zephyr has to offer, and only support the sensor sample_fetch and channel_get API. It also doesn't support adxl344 and adxl346 sensors. This new driver is a full replacement of the existing driver (using a compatibility flag) and, apart from the full driver API (adding support for attributes, triggers, RTIO and decoders), also support access to all registers of the adxl343, adxl344, adxl345 and adxl346 sensors. It also has power management support and comes with a full set of regression tests. The adxl345 driver API has an additional (unofficial) feature which uses the FIFO to return multiple values using a single sensor_sample_fetch command. To make the adxl34x driver a drop in replacement of the adxl345 driver an additional compile flag was introduced which mimics this behavior (default off). Both the adxl345 and adxl34x drivers have been tested using the various (application) use-cases to check functionality and behavior. Source code is available in a different repository. Signed-off-by: Chaim Zax <[email protected]>
1 parent 67b7c99 commit 1fb5da9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+7501
-1
lines changed

drivers/sensor/adi/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ add_subdirectory_ifdef(CONFIG_ADLTC2990 adltc2990)
66
add_subdirectory_ifdef(CONFIG_ADT7310 adt7310)
77
add_subdirectory_ifdef(CONFIG_ADT7420 adt7420)
88
add_subdirectory_ifdef(CONFIG_ADXL345 adxl345)
9+
add_subdirectory_ifdef(CONFIG_ADXL34X adxl34x)
910
add_subdirectory_ifdef(CONFIG_ADXL362 adxl362)
1011
add_subdirectory_ifdef(CONFIG_ADXL367 adxl367)
1112
add_subdirectory_ifdef(CONFIG_ADXL372 adxl372)

drivers/sensor/adi/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ source "drivers/sensor/adi/adltc2990/Kconfig"
66
source "drivers/sensor/adi/adt7310/Kconfig"
77
source "drivers/sensor/adi/adt7420/Kconfig"
88
source "drivers/sensor/adi/adxl345/Kconfig"
9+
source "drivers/sensor/adi/adxl34x/Kconfig"
910
source "drivers/sensor/adi/adxl362/Kconfig"
1011
source "drivers/sensor/adi/adxl367/Kconfig"
1112
source "drivers/sensor/adi/adxl372/Kconfig"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Copyright (c) 2024 Chaim Zax
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
zephyr_library()
7+
8+
zephyr_library_sources(
9+
adxl34x.c
10+
adxl34x_configure.c
11+
adxl34x_attr.c
12+
)
13+
zephyr_library_sources_ifdef(CONFIG_ADXL34X_BUS_I2C adxl34x_i2c.c)
14+
zephyr_library_sources_ifdef(CONFIG_ADXL34X_BUS_SPI adxl34x_spi.c)
15+
zephyr_library_sources_ifdef(CONFIG_ADXL34X_TRIGGER adxl34x_trigger.c)
16+
zephyr_library_sources_ifdef(CONFIG_ADXL34X_DECODER adxl34x_decoder.c)
17+
zephyr_library_sources_ifdef(CONFIG_ADXL34X_ASYNC_API adxl34x_rtio.c)
18+
19+
zephyr_library_sources_ifdef(CONFIG_EMUL_ADXL34X adxl34x_emul.c)
20+
zephyr_include_directories_ifdef(CONFIG_EMUL_ADXL34X .)

drivers/sensor/adi/adxl34x/Kconfig

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#
2+
# Copyright (c) 2024 Chaim Zax
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
menuconfig ADXL34X
7+
bool "ADXL343, ADXL344, ADXL345 and ADXL346 accelerometers"
8+
default y
9+
depends on DT_HAS_ADI_ADXL34X_ENABLED
10+
select I2C if $(dt_compat_on_bus,$(DT_COMPAT_ADI_ADXL34X),i2c)
11+
select SPI if $(dt_compat_on_bus,$(DT_COMPAT_ADI_ADXL34X),spi)
12+
help
13+
Enable support for the ADXL343, ADXL344, ADXL345 and ADXL346 Three
14+
Axis accelerometer
15+
16+
if ADXL34X
17+
18+
config ADXL34X_BUS_I2C
19+
bool
20+
default y
21+
depends on $(dt_compat_on_bus,$(DT_COMPAT_ADI_ADXL34X),i2c)
22+
23+
config ADXL34X_BUS_SPI
24+
bool
25+
default y
26+
depends on $(dt_compat_on_bus,$(DT_COMPAT_ADI_ADXL34X),spi)
27+
28+
config ADXL34X_DECODER
29+
bool "Decoder logic"
30+
default y
31+
select ADXL34X_ASYNC_API
32+
depends on SENSOR_ASYNC_API
33+
help
34+
Compile the ADXL34X decoder API which allows decoding raw data
35+
returned from the sensor.
36+
37+
if ADXL34X_DECODER
38+
39+
choice
40+
prompt "Decoder data type"
41+
default ADXL34X_DATA_TYPE_Q31
42+
help
43+
Data type returned by the decoder.
44+
45+
config ADXL34X_DATA_TYPE_Q31
46+
bool "q31"
47+
help
48+
Return q31 sensor type values from the decoder
49+
50+
config ADXL34X_DATA_TYPE_SENSOR_VALUE
51+
bool "sensor_value"
52+
help
53+
Return sensor_value sensor type values from the decoder
54+
55+
config ADXL34X_DATA_TYPE_DOUBLE
56+
bool "double"
57+
help
58+
Return double sensor type values from the decoder
59+
60+
endchoice
61+
62+
endif # ADXL34X_DECODER
63+
64+
choice ADXL34X_FIFO_MODE
65+
prompt "FIFO mode"
66+
default ADXL34X_FIFO_MODE_BYPASS
67+
help
68+
Specify the FIFO mode to be used by the driver
69+
70+
config ADXL34X_FIFO_MODE_BYPASS
71+
bool "Bypass"
72+
help
73+
No FIFO, the FIFO of the adxl34x is bypassed. The sensor can only be
74+
used in polling mode, no triggers are available. Use this mode when
75+
the interrupt line of the adxl34x is not connected.
76+
77+
config ADXL34X_FIFO_MODE_FIFO
78+
bool "FIFO"
79+
select ADXL34X_TRIGGER
80+
select ADXL34X_ASYNC_API
81+
depends on SENSOR_ASYNC_API
82+
help
83+
FIFO collects up to 32 values and then stops collecting data,
84+
collecting new data only when FIFO is not full. Use this config option
85+
to enable streaming sensor data via RTIO subsystem. This mode requires
86+
the interrupt line of the adxl34x to be connected.
87+
88+
config ADXL34X_FIFO_MODE_STREAM
89+
bool "Stream"
90+
select ADXL34X_TRIGGER
91+
select ADXL34X_ASYNC_API
92+
depends on SENSOR_ASYNC_API
93+
help
94+
FIFO holds the last 32 data values. When FIFO is full, the oldest data
95+
is overwritten with newer data. This mode requires the interrupt line
96+
of the adxl34x to be connected.
97+
98+
config ADXL34X_FIFO_MODE_TRIGGER
99+
bool "Trigger"
100+
select ADXL34X_TRIGGER
101+
select ADXL34X_ASYNC_API
102+
depends on SENSOR_ASYNC_API
103+
help
104+
When triggered by the trigger bit, FIFO holds the last data samples
105+
before the trigger event and then continues to collect data until
106+
full. New data is collected only when FIFO is not full. This mode
107+
requires the interrupt line of the adxl34x to be connected.
108+
109+
endchoice
110+
111+
config EMUL_ADXL34X
112+
bool "Emulator for the ADXL34X"
113+
default y
114+
depends on EMUL
115+
help
116+
Enable the hardware emulator for the ADXL34X. Doing so allows
117+
exercising sensor APIs for this driver in native_sim and qemu.
118+
119+
config ADXL34X_EXTENDED_API
120+
bool "Extended API"
121+
default y
122+
help
123+
Enable the extended API for the ADXL34X. This option gives access to
124+
all registers of the adxl34x when not using user space.
125+
126+
config ADXL34X_ADXL345_COMPATIBLE
127+
bool "ADXL345 compatible"
128+
default n
129+
help
130+
Enable compatibility with the (old) ADXL345 driver. Enable this
131+
feature when the (existing) application was written for the ADXL345
132+
driver. The ADXL345 driver uses the FIFO when calling
133+
sensor_sample_fetch, and will return the number of samples collected
134+
(which is not the official API). This allows sensor_sample_get to be
135+
called multiple times to read all FIFO data.
136+
137+
config ADXL34X_TRIGGER
138+
bool
139+
140+
config ADXL34X_ASYNC_API
141+
bool
142+
143+
endif # ADXL34X

0 commit comments

Comments
 (0)