Skip to content

Commit 36917d4

Browse files
ubiedakartben
authored andcommitted
sensor: adxl345: Allow fifo-watermark configurable through dts
Allow for users to define the fifo-watermark on a per-instance basis through device-tree properties. This setting is validated at build time, so missing it when required, or setting an invalid value should not end up in a run-time errror (as in: it runs but nothing happens). Signed-off-by: Luis Ubieda <luisf@croxel.com>
1 parent 4243ad2 commit 36917d4

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

drivers/sensor/adi/adxl345/adxl345.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ static int adxl345_init(const struct device *dev)
482482
#ifdef CONFIG_ADXL345_TRIGGER
483483
rc = adxl345_configure_fifo(dev, ADXL345_FIFO_STREAMED,
484484
ADXL345_INT2,
485-
SAMPLE_NUM);
485+
cfg->fifo_config.fifo_samples);
486486
if (rc) {
487487
return rc;
488488
}
@@ -561,7 +561,7 @@ static int adxl345_init(const struct device *dev)
561561
.odr = DT_INST_PROP(inst, odr), \
562562
.fifo_config.fifo_mode = ADXL345_FIFO_STREAMED, \
563563
.fifo_config.fifo_trigger = ADXL345_INT2, \
564-
.fifo_config.fifo_samples = SAMPLE_NUM, \
564+
.fifo_config.fifo_samples = DT_INST_PROP_OR(inst, fifo_watermark, 0),
565565

566566
#define ADXL345_CONFIG_SPI(inst) \
567567
{ \
@@ -590,7 +590,19 @@ static int adxl345_init(const struct device *dev)
590590
(ADXL345_CFG_IRQ(inst)), ()) \
591591
}
592592

593-
#define ADXL345_DEFINE(inst) \
593+
#define ADXL345_DEFINE(inst) \
594+
\
595+
BUILD_ASSERT(!IS_ENABLED(CONFIG_ADXL345_STREAM) || \
596+
DT_INST_NODE_HAS_PROP(inst, fifo_watermark), \
597+
"Streaming requires fifo-watermark property. Please set it in the" \
598+
"device-tree node properties"); \
599+
BUILD_ASSERT(COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, fifo_watermark), \
600+
((DT_INST_PROP(inst, fifo_watermark) > 0) && \
601+
(DT_INST_PROP(inst, fifo_watermark) < 32)), \
602+
(true)), \
603+
"fifo-watermark must be between 1 and 32. Please set it in " \
604+
"the device-tree node properties"); \
605+
\
594606
IF_ENABLED(CONFIG_ADXL345_STREAM, (ADXL345_RTIO_DEFINE(inst))); \
595607
static struct adxl345_dev_data adxl345_data_##inst = { \
596608
IF_ENABLED(CONFIG_ADXL345_STREAM, (.rtio_ctx = &adxl345_rtio_ctx_##inst, \

dts/bindings/sensor/adi,adxl345-common.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ properties:
3131
- 11 # ADXL345_DT_ODR_200
3232
- 12 # ADXL345_DT_ODR_400
3333

34+
fifo-watermark:
35+
type: int
36+
description: |
37+
Specify the FIFO watermark level in frame count.
38+
Valid range: 1 - 31
39+
3440
int2-gpios:
3541
type: phandle-array
3642
description: |

0 commit comments

Comments
 (0)