Skip to content

Commit 5fc5259

Browse files
vladislav-pejickartben
authored andcommitted
drivers: sensor: adxl362: FIFO mode from DT
Adds support for setting FIFO mode from DT. Signed-off-by: Vladislav Pejic <vladislav.pejic@orioninc.com>
1 parent 6f59533 commit 5fc5259

File tree

6 files changed

+79
-8
lines changed

6 files changed

+79
-8
lines changed

boards/shields/eval_adxl362_ardz/eval_adxl362_ardz.overlay

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#include <zephyr/dt-bindings/sensor/adxl362.h>
8+
79
&arduino_spi {
810
status = "okay";
911

@@ -12,6 +14,8 @@
1214
reg = <0x0>;
1315
spi-max-frequency = <DT_FREQ_M(1)>;
1416
int1-gpios = <&arduino_header 8 GPIO_ACTIVE_HIGH>;
17+
fifo-mode = <ADXL362_FIFO_MODE_STREAM>;
18+
fifo-watermark = <0x80>;
1519
status = "okay";
1620
};
1721
};

drivers/sensor/adi/adxl362/adxl362.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ static int adxl362_chip_init(const struct device *dev)
717717
}
718718

719719
/* Configures the FIFO feature. */
720-
ret = adxl362_fifo_setup(dev, ADXL362_FIFO_DISABLE, 0, 0);
720+
ret = adxl362_fifo_setup(dev, config->fifo_mode, config->water_mark_lvl, 0);
721721
if (ret) {
722722
return ret;
723723
}
@@ -821,7 +821,7 @@ static int adxl362_init(const struct device *dev)
821821
ADXL362_SPI_CFG, 0U); \
822822
RTIO_DEFINE(adxl362_rtio_ctx_##inst, 8, 8);
823823

824-
#define ADXL362_DEFINE(inst) \
824+
#define ADXL362_DEFINE(inst)\
825825
IF_ENABLED(CONFIG_ADXL362_STREAM, (ADXL362_RTIO_DEFINE(inst))); \
826826
static struct adxl362_data adxl362_data_##inst = { \
827827
IF_ENABLED(CONFIG_ADXL362_STREAM, (.rtio_ctx = &adxl362_rtio_ctx_##inst, \
@@ -832,6 +832,8 @@ static int adxl362_init(const struct device *dev)
832832
.power_ctl = ADXL362_POWER_CTL_MEASURE(ADXL362_MEASURE_ON) | \
833833
(DT_INST_PROP(inst, wakeup_mode) * ADXL362_POWER_CTL_WAKEUP) | \
834834
(DT_INST_PROP(inst, autosleep) * ADXL362_POWER_CTL_AUTOSLEEP), \
835+
.fifo_mode = DT_INST_PROP_OR(inst, fifo_mode, ADXL362_FIFO_DISABLE), \
836+
.water_mark_lvl = DT_INST_PROP_OR(inst, fifo_watermark, 0x80), \
835837
IF_ENABLED(CONFIG_ADXL362_TRIGGER, \
836838
(.interrupt = GPIO_DT_SPEC_INST_GET_OR(inst, int1_gpios, { 0 }),)) \
837839
}; \

drivers/sensor/adi/adxl362/adxl362.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <zephyr/drivers/gpio.h>
1313
#include <zephyr/drivers/spi.h>
1414
#include <zephyr/drivers/sensor.h>
15+
#include <zephyr/dt-bindings/sensor/adxl362.h>
1516

1617
#define ADXL362_SLAVE_ID 1
1718

@@ -84,10 +85,10 @@
8485
#define ADXL362_FIFO_CTL_FIFO_MODE(x) (((x) & 0x3) << 0)
8586

8687
/* ADXL362_FIFO_CTL_FIFO_MODE(x) options */
87-
#define ADXL362_FIFO_DISABLE 0
88-
#define ADXL362_FIFO_OLDEST_SAVED 1
89-
#define ADXL362_FIFO_STREAM 2
90-
#define ADXL362_FIFO_TRIGGERED 3
88+
#define ADXL362_FIFO_DISABLE ADXL362_FIFO_MODE_DISABLED
89+
#define ADXL362_FIFO_OLDEST_SAVED ADXL362_FIFO_MODE_OLDEST_SAVED
90+
#define ADXL362_FIFO_STREAM ADXL362_FIFO_MODE_STREAM
91+
#define ADXL362_FIFO_TRIGGERED ADXL362_FIFO_MODE_TRIGGERED
9192

9293
/* ADXL362_REG_INTMAP1 */
9394
#define ADXL362_INTMAP1_INT_LOW (1 << 7)
@@ -188,6 +189,8 @@ struct adxl362_config {
188189
uint8_t int2_config;
189190
#endif
190191
uint8_t power_ctl;
192+
uint8_t fifo_mode;
193+
uint16_t water_mark_lvl;
191194
};
192195

193196
struct adxl362_data {

drivers/sensor/adi/adxl362/adxl362_stream.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ void adxl362_submit_stream(const struct device *dev, struct rtio_iodev_sqe *iode
107107
}
108108

109109
if (fifo_mode == ADXL362_FIFO_DISABLE) {
110-
fifo_mode = ADXL362_FIFO_STREAM;
110+
LOG_ERR("ERROR: FIFO DISABLED");
111+
return;
111112
}
112113

113114
if (en_temp_read == 0) {

dts/bindings/sensor/adi,adxl362.yaml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
# Copyright (c) 2018, NXP
22
# SPDX-License-Identifier: Apache-2.0
33

4-
description: ADXL362 3-axis SPI accelerometer
4+
description: |
5+
ADXL362 3-axis SPI accelerometer
6+
When setting the accelerometer DTS properties and want to use
7+
streaming funcionality, make sure to include adxl362.h and
8+
use the macros defined there for fifo-mode and fifo-watermark properties.
9+
10+
Example:
11+
#include <zephyr/dt-bindings/sensor/adxl362.h>
12+
13+
adxl362: adxl362@0 {
14+
...
15+
fifo-mode = <ADXL362_FIFO_MODE_STREAM>;
16+
fifo-watermark = <0x80>;
17+
};
518
619
compatible: "adi,adxl362"
720

@@ -27,3 +40,23 @@ properties:
2740
Enter Wake-Up mode when inactivity is detected,
2841
reenter Measurement mode when activity is detected.
2942
Only applies for Linked and Loop mode, ignored otherwise.
43+
44+
fifo-mode:
45+
type: int
46+
description: |
47+
Accelerometer FIFO Mode.
48+
0 # ADXL362_FIFO_MODE_DISABLED
49+
1 # ADXL362_FIFO_MODE_OLDEST_SAVED
50+
2 # ADXL362_FIFO_MODE_STREAM
51+
3 # ADXL362_FIFO_MODE_TRIGGERED
52+
enum:
53+
- 0
54+
- 1
55+
- 2
56+
- 3
57+
58+
fifo-watermark:
59+
type: int
60+
description: |
61+
Specify the FIFO watermark level in frame count.
62+
Valid range: 0 - 511
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2025 Analog Devices Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADI_ADX362_H_
7+
#define ZEPHYR_INCLUDE_DT_BINDINGS_ADI_ADX362_H_
8+
9+
/**
10+
* @defgroup ADXL362 ADI DT Options
11+
* @ingroup sensor_interface
12+
* @{
13+
*/
14+
15+
/**
16+
* @defgroup ADXL362_FIFO_MODE FIFO mode options
17+
* @{
18+
*/
19+
#define ADXL362_FIFO_MODE_DISABLED 0x0
20+
#define ADXL362_FIFO_MODE_OLDEST_SAVED 0x1
21+
#define ADXL362_FIFO_MODE_STREAM 0x2
22+
#define ADXL362_FIFO_MODE_TRIGGERED 0x3
23+
24+
/** @} */
25+
26+
/** @} */
27+
28+
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADI_ADX362_H_ */

0 commit comments

Comments
 (0)