Skip to content

Commit f8416de

Browse files
ubiedakartben
authored andcommitted
sensor: adxl345: fix: Overriding of ODR setting in DTS property
This patch fixes previous overriding of ODR setting through DTS (it would always be 25-Hz, irrespective of what the DTS property said). While doing so, create dt-binding enum to improve settings clarity. Signed-off-by: Luis Ubieda <luisf@croxel.com>
1 parent 5e1a2fc commit f8416de

File tree

4 files changed

+58
-20
lines changed

4 files changed

+58
-20
lines changed

drivers/sensor/adi/adxl345/adxl345.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,6 @@ static int adxl345_init(const struct device *dev)
562562
.fifo_config.fifo_mode = ADXL345_FIFO_STREAMED, \
563563
.fifo_config.fifo_trigger = ADXL345_INT2, \
564564
.fifo_config.fifo_samples = SAMPLE_NUM, \
565-
.odr = ADXL345_RATE_25HZ, \
566565

567566
#define ADXL345_CONFIG_SPI(inst) \
568567
{ \

drivers/sensor/adi/adxl345/adxl345.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <zephyr/kernel.h>
1515
#include <zephyr/sys/util.h>
1616

17+
#include <zephyr/dt-bindings/sensor/adxl345.h>
18+
1719
#ifdef CONFIG_ADXL345_STREAM
1820
#include <zephyr/rtio/rtio.h>
1921
#endif /* CONFIG_ADXL345_STREAM */
@@ -117,12 +119,12 @@
117119
#define ADXL345_BUS_SPI 1
118120

119121
enum adxl345_odr {
120-
ADXL345_ODR_12HZ = 0x7,
121-
ADXL345_ODR_25HZ,
122-
ADXL345_ODR_50HZ,
123-
ADXL345_ODR_100HZ,
124-
ADXL345_ODR_200HZ,
125-
ADXL345_ODR_400HZ
122+
ADXL345_ODR_12HZ = ADXL345_DT_ODR_12_5,
123+
ADXL345_ODR_25HZ = ADXL345_DT_ODR_25,
124+
ADXL345_ODR_50HZ = ADXL345_DT_ODR_50,
125+
ADXL345_ODR_100HZ = ADXL345_DT_ODR_100,
126+
ADXL345_ODR_200HZ = ADXL345_DT_ODR_200,
127+
ADXL345_ODR_400HZ = ADXL345_DT_ODR_400,
126128
};
127129

128130
enum adxl345_fifo_trigger {

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
11
# Copyright (c) 2022 Analog Devices Inc.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
description: |
5+
ADXL345 3-axis accelerometer
6+
When setting the accelerometer DTS properties, make sure to include
7+
adxl345.h and use the macros defined there.
8+
9+
Example:
10+
#include <zephyr/dt-bindings/sensor/adxl345.h>
11+
12+
adxl345: adxl345@1d {
13+
...
14+
15+
odr = <ADXL345_DT_ODR_25>;
16+
};
17+
418
include: sensor-device.yaml
519

620
properties:
721
odr:
822
type: int
9-
default: 0
23+
default: 10
1024
description: |
1125
Accelerometer sampling frequency (ODR). Default is power on reset value.
12-
0 # 12.5Hz
13-
1 # 25Hz
14-
2 # 50Hz
15-
3 # 100Hz
16-
4 # 200Hz
17-
5 # 400Hz
1826
enum:
19-
- 0
20-
- 1
21-
- 2
22-
- 3
23-
- 4
24-
- 5
27+
- 7 # ADXL345_DT_ODR_12_5
28+
- 8 # ADXL345_DT_ODR_25
29+
- 9 # ADXL345_DT_ODR_50
30+
- 10 # ADXL345_DT_ODR_100
31+
- 11 # ADXL345_DT_ODR_200
32+
- 12 # ADXL345_DT_ODR_400
2533

2634
int2-gpios:
2735
type: phandle-array
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2025 Croxel Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADI_ADX345_H_
7+
#define ZEPHYR_INCLUDE_DT_BINDINGS_ADI_ADX345_H_
8+
9+
/**
10+
* @defgroup ADXL345 ADI DT Options
11+
* @ingroup sensor_interface
12+
* @{
13+
*/
14+
15+
/**
16+
* @defgroup ADXL345_ODR Output Rate options
17+
* @{
18+
*/
19+
#define ADXL345_DT_ODR_12_5 7
20+
#define ADXL345_DT_ODR_25 8
21+
#define ADXL345_DT_ODR_50 9
22+
#define ADXL345_DT_ODR_100 10
23+
#define ADXL345_DT_ODR_200 11
24+
#define ADXL345_DT_ODR_400 12
25+
/** @} */
26+
27+
/** @} */
28+
29+
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADI_ADX345_H_ */

0 commit comments

Comments
 (0)