Skip to content

Commit 05e8a65

Browse files
ubiedakartben
authored andcommitted
sensor: icm45686: Add low-pass filter configuration options
Both for Gyro and Accelerometer. Signed-off-by: Luis Ubieda <luisf@croxel.com>
1 parent 25793fe commit 05e8a65

File tree

5 files changed

+114
-0
lines changed

5 files changed

+114
-0
lines changed

drivers/sensor/tdk/icm45686/icm45686.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,38 @@ static int icm45686_init(const struct device *dev)
312312
return err;
313313
}
314314

315+
/** Write Low-pass filter settings through indirect register access */
316+
uint8_t gyro_lpf_write_array[] = REG_IREG_PREPARE_WRITE_ARRAY(
317+
REG_IPREG_SYS1_OFFSET,
318+
REG_IPREG_SYS1_REG_172,
319+
REG_IPREG_SYS1_REG_172_GYRO_LPFBW_SEL(
320+
cfg->settings.gyro.lpf));
321+
322+
err = icm45686_bus_write(dev, REG_IREG_ADDR_15_8, gyro_lpf_write_array,
323+
sizeof(gyro_lpf_write_array));
324+
if (err) {
325+
LOG_ERR("Failed to set Gyro BW settings: %d", err);
326+
return err;
327+
}
328+
329+
/** Wait before indirect register write is made effective
330+
* before proceeding with next one.
331+
*/
332+
k_sleep(K_MSEC(1));
333+
334+
uint8_t accel_lpf_write_array[] = REG_IREG_PREPARE_WRITE_ARRAY(
335+
REG_IPREG_SYS2_OFFSET,
336+
REG_IPREG_SYS2_REG_131,
337+
REG_IPREG_SYS2_REG_131_ACCEL_LPFBW_SEL(
338+
cfg->settings.accel.lpf));
339+
340+
err = icm45686_bus_write(dev, REG_IREG_ADDR_15_8, accel_lpf_write_array,
341+
sizeof(accel_lpf_write_array));
342+
if (err) {
343+
LOG_ERR("Failed to set Accel BW settings: %d", err);
344+
return err;
345+
}
346+
315347
LOG_DBG("Init OK");
316348

317349
return 0;
@@ -341,11 +373,13 @@ static int icm45686_init(const struct device *dev)
341373
.pwr_mode = DT_INST_PROP(inst, accel_pwr_mode), \
342374
.fs = DT_INST_PROP(inst, accel_fs), \
343375
.odr = DT_INST_PROP(inst, accel_odr), \
376+
.lpf = DT_INST_PROP_OR(inst, accel_lpf, 0), \
344377
}, \
345378
.gyro = { \
346379
.pwr_mode = DT_INST_PROP(inst, gyro_pwr_mode), \
347380
.fs = DT_INST_PROP(inst, gyro_fs), \
348381
.odr = DT_INST_PROP(inst, gyro_odr), \
382+
.lpf = DT_INST_PROP_OR(inst, gyro_lpf, 0), \
349383
}, \
350384
}, \
351385
}; \

drivers/sensor/tdk/icm45686/icm45686.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ struct icm45686_config {
6363
uint8_t pwr_mode : 2;
6464
uint8_t fs : 4;
6565
uint8_t odr : 4;
66+
uint8_t lpf : 3;
6667
} accel;
6768
struct {
6869
uint8_t pwr_mode : 2;
6970
uint8_t fs : 4;
7071
uint8_t odr : 4;
72+
uint8_t lpf : 3;
7173
} gyro;
7274
} settings;
7375
};

drivers/sensor/tdk/icm45686/icm45686_reg.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
#define ZEPHYR_DRIVERS_SENSOR_ICM45686_REG_H_
1111

1212
#include <zephyr/sys/util.h>
13+
#include <zephyr/sys/byteorder.h>
1314

1415
/* Address value has a read bit */
1516
#define REG_SPI_READ_BIT BIT(7)
1617

1718
/* Registers */
19+
/* Register Bank 0 */
1820
#define REG_ACCEL_DATA_X1_UI 0x00
1921
#define REG_ACCEL_DATA_X0_UI 0x01
2022
#define REG_ACCEL_DATA_Y1_UI 0x02
@@ -34,8 +36,19 @@
3436
#define REG_GYRO_CONFIG0 0x1C
3537
#define REG_DRIVE_CONFIG0 0x32
3638
#define REG_WHO_AM_I 0x72
39+
#define REG_IREG_ADDR_15_8 0x7C
40+
#define REG_IREG_ADDR_7_0 0x7D
41+
#define REG_IREG_DATA 0x7E
3742
#define REG_MISC2 0x7F
3843

44+
/* User Bank IPREG_SYS1 - Gyro-related config settings */
45+
#define REG_IPREG_SYS1_OFFSET 0xA400
46+
#define REG_IPREG_SYS1_REG_172 0xAC
47+
48+
/* User Bank IPREG_SYS2 - Accel-related config settings */
49+
#define REG_IPREG_SYS2_OFFSET 0xA500
50+
#define REG_IPREG_SYS2_REG_131 0x83
51+
3952
/* Helper Macros for register manipulation */
4053
#define REG_PWR_MGMT0_ACCEL_MODE(val) ((val) & BIT_MASK(2))
4154
#define REG_PWR_MGMT0_GYRO_MODE(val) (((val) & BIT_MASK(2)) << 2)
@@ -50,7 +63,13 @@
5063

5164
#define REG_MISC2_SOFT_RST(val) ((val << 1) & BIT(1))
5265

66+
#define REG_IPREG_SYS1_REG_172_GYRO_LPFBW_SEL(val) (val & BIT_MASK(3))
67+
68+
#define REG_IPREG_SYS2_REG_131_ACCEL_LPFBW_SEL(val) (val & BIT_MASK(3))
69+
5370
/* Misc. Defines */
5471
#define WHO_AM_I_ICM45686 0xE9
5572

73+
#define REG_IREG_PREPARE_WRITE_ARRAY(base, reg, val) {((base) >> 8) & 0xFF, reg, val}
74+
5675
#endif /* ZEPHYR_DRIVERS_SENSOR_ICM45686_REG_H_ */

dts/bindings/sensor/invensense,icm45686.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ properties:
7979
- 3 # ICM45686_DT_ACCEL_FS_4
8080
- 4 # ICM45686_DT_ACCEL_FS_2
8181

82+
accel-lpf:
83+
type: int
84+
default: 0
85+
description: |
86+
Specify the accelerometer low pass filter cut-off frequency
87+
as a fraction of the output data rate.
88+
Default is power-up configuration.
89+
enum:
90+
- 0 # ICM45686_DT_ACCEL_LPF_BW_OFF
91+
- 1 # ICM45686_DT_ACCEL_LPF_BW_1_4
92+
- 2 # ICM45686_DT_ACCEL_LPF_BW_1_8
93+
- 3 # ICM45686_DT_ACCEL_LPF_BW_1_16
94+
- 4 # ICM45686_DT_ACCEL_LPF_BW_1_32
95+
- 5 # ICM45686_DT_ACCEL_LPF_BW_1_64
96+
- 6 # ICM45686_DT_ACCEL_LPF_BW_1_128
97+
8298
gyro-pwr-mode:
8399
type: int
84100
default: 0
@@ -128,3 +144,19 @@ properties:
128144
- 6 # ICM45686_DT_GYRO_FS_62_5
129145
- 7 # ICM45686_DT_GYRO_FS_31_25
130146
- 8 # ICM45686_DT_GYRO_FS_15_625
147+
148+
gyro-lpf:
149+
type: int
150+
default: 0
151+
description: |
152+
Specify the gyro low pass filter cut-off frequency
153+
as a fraction of the output data rate.
154+
Default is power-up configuration.
155+
enum:
156+
- 0 # ICM45686_DT_GYRO_LPF_BW_OFF
157+
- 1 # ICM45686_DT_GYRO_LPF_BW_1_4
158+
- 2 # ICM45686_DT_GYRO_LPF_BW_1_8
159+
- 3 # ICM45686_DT_GYRO_LPF_BW_1_16
160+
- 4 # ICM45686_DT_GYRO_LPF_BW_1_32
161+
- 5 # ICM45686_DT_GYRO_LPF_BW_1_64
162+
- 6 # ICM45686_DT_GYRO_LPF_BW_1_128

include/zephyr/dt-bindings/sensor/icm45686.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,33 @@
9797
#define ICM45686_DT_GYRO_ODR_1_5625 15 /* LP-mode only */
9898
/** @} */
9999

100+
/**
101+
* @defgroup ICM45686_GYRO_LPF Gyroscope Low-pass Filtering options
102+
* @{
103+
*/
104+
#define ICM45686_DT_GYRO_LPF_BW_OFF 0
105+
#define ICM45686_DT_GYRO_LPF_BW_1_4 1
106+
#define ICM45686_DT_GYRO_LPF_BW_1_8 2
107+
#define ICM45686_DT_GYRO_LPF_BW_1_16 3
108+
#define ICM45686_DT_GYRO_LPF_BW_1_32 4
109+
#define ICM45686_DT_GYRO_LPF_BW_1_64 5
110+
#define ICM45686_DT_GYRO_LPF_BW_1_128 6
111+
/** @} */
112+
113+
/**
114+
* @defgroup ICM45686_ACCEL_LPF Accelerometer Low-pass Filtering options
115+
* @{
116+
*/
117+
#define ICM45686_DT_ACCEL_LPF_BW_OFF 0
118+
#define ICM45686_DT_ACCEL_LPF_BW_1_4 1
119+
#define ICM45686_DT_ACCEL_LPF_BW_1_8 2
120+
#define ICM45686_DT_ACCEL_LPF_BW_1_16 3
121+
#define ICM45686_DT_ACCEL_LPF_BW_1_32 4
122+
#define ICM45686_DT_ACCEL_LPF_BW_1_64 5
123+
#define ICM45686_DT_ACCEL_LPF_BW_1_128 6
124+
/** @} */
125+
126+
100127
/** @} */
101128

102129
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_TDK_ICM45686_H_ */

0 commit comments

Comments
 (0)