Skip to content

Commit 058253b

Browse files
teburdnashif
authored andcommitted
icm42688: Follow st's devicetree bindings
Fix the devicetree bindings to actually be used as the default configuration, following the example set by various ST sensor devices. This requires sadly dropping enums and using #defines for various options as well as repeating many numbers, but presumably is the way to do it given the precedent set by ST with sensors like the lsm6dso. Signed-off-by: Tom Burdick <[email protected]>
1 parent c0a955d commit 058253b

File tree

9 files changed

+407
-348
lines changed

9 files changed

+407
-348
lines changed

boards/nxp/vmu_rt1170/vmu_rt1170_mimxrt1176_cm7.dts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@
241241
};
242242
};
243243

244+
#include <zephyr/dt-bindings/sensor/icm42688.h>
245+
244246
&lpspi1 {
245247
status = "okay";
246248
cs-gpios =<&gpio2 11 GPIO_ACTIVE_LOW>;
@@ -250,10 +252,12 @@
250252
reg = <0>;
251253
int-gpios = <&gpio3 19 GPIO_ACTIVE_HIGH>;
252254
spi-max-frequency = <24000000>;
253-
accel-hz = <1000>;
254-
accel-fs = <16>;
255-
gyro-hz = <1000>;
256-
gyro-fs = <2000>;
255+
accel-pwr-mode = <ICM42688_DT_ACCEL_LN>;
256+
accel-odr = <ICM42688_DT_ACCEL_ODR_1000>;
257+
accel-fs = <ICM42688_DT_ACCEL_FS_16>;
258+
gyro-pwr-mode = <ICM42688_DT_GYRO_LN>;
259+
gyro-odr = <ICM42688_DT_GYRO_ODR_1000>;
260+
gyro-fs = <ICM42688_DT_GYRO_FS_2000>;
257261
};
258262
};
259263

@@ -266,10 +270,12 @@
266270
reg = <0>;
267271
int-gpios = <&gpio2 7 GPIO_ACTIVE_HIGH>;
268272
spi-max-frequency = <24000000>;
269-
accel-hz = <1000>;
270-
accel-fs = <16>;
271-
gyro-hz = <1000>;
272-
gyro-fs = <2000>;
273+
accel-pwr-mode = <ICM42688_DT_ACCEL_LN>;
274+
accel-odr = <ICM42688_DT_ACCEL_ODR_1000>;
275+
accel-fs = <ICM42688_DT_ACCEL_FS_16>;
276+
gyro-pwr-mode = <ICM42688_DT_GYRO_LN>;
277+
gyro-odr = <ICM42688_DT_GYRO_ODR_1000>;
278+
gyro-fs = <ICM42688_DT_GYRO_FS_2000>;
273279
};
274280
};
275281

boards/tdk/robokit1/robokit1-common.dtsi

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@
8989
};
9090
};
9191

92+
#include <zephyr/dt-bindings/sensor/icm42688.h>
93+
9294
&spi0 {
9395
pinctrl-0 = <&spi0_default>;
9496
pinctrl-names = "default";
@@ -103,10 +105,12 @@
103105
reg = <0>;
104106
int-gpios = <&pioc 5 GPIO_ACTIVE_HIGH>;
105107
spi-max-frequency = <24000000>;
106-
accel-hz = <32000>;
107-
accel-fs = <16>;
108-
gyro-hz = <32000>;
109-
gyro-fs = <2000>;
108+
accel-pwr-mode = <ICM42688_DT_ACCEL_LN>;
109+
accel-odr = <ICM42688_DT_ACCEL_ODR_2000>;
110+
accel-fs = <ICM42688_DT_ACCEL_FS_16>;
111+
gyro-pwr-mode = <ICM42688_DT_GYRO_LN>;
112+
gyro-odr = <ICM42688_DT_GYRO_ODR_2000>;
113+
gyro-fs = <ICM42688_DT_GYRO_FS_2000>;
110114
};
111115
spi_adc: adc@1 {
112116
compatible = "ti,ads7052";

drivers/sensor/tdk/icm42688/icm42688.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -271,20 +271,6 @@ int icm42688_init(const struct device *dev)
271271
}
272272
#endif
273273

274-
data->cfg.accel_mode = ICM42688_ACCEL_LN;
275-
data->cfg.accel_fs = ICM42688_ACCEL_FS_2G;
276-
data->cfg.accel_odr = ICM42688_ACCEL_ODR_1000;
277-
data->cfg.gyro_mode = ICM42688_GYRO_LN;
278-
data->cfg.gyro_fs = ICM42688_GYRO_FS_125;
279-
data->cfg.gyro_odr = ICM42688_GYRO_ODR_1000;
280-
data->cfg.temp_dis = false;
281-
data->cfg.fifo_en = IS_ENABLED(CONFIG_ICM42688_STREAM);
282-
data->cfg.batch_ticks = 0;
283-
data->cfg.fifo_hires = 0;
284-
data->cfg.interrupt1_drdy = 0;
285-
data->cfg.interrupt1_fifo_ths = 0;
286-
data->cfg.interrupt1_fifo_full = 0;
287-
288274
res = icm42688_configure(dev, &data->cfg);
289275
if (res != 0) {
290276
LOG_ERR("Failed to configure");
@@ -313,11 +299,30 @@ void icm42688_unlock(const struct device *dev)
313299
SPI_DT_IODEV_DEFINE(icm42688_spi_iodev_##inst, DT_DRV_INST(inst), ICM42688_SPI_CFG, 0U); \
314300
RTIO_DEFINE(icm42688_rtio_##inst, 8, 4);
315301

302+
#define ICM42688_DT_CONFIG_INIT(inst) \
303+
{ \
304+
.accel_pwr_mode = DT_INST_PROP(inst, accel_pwr_mode), \
305+
.accel_fs = DT_INST_PROP(inst, accel_fs), \
306+
.accel_odr = DT_INST_PROP(inst, accel_odr), \
307+
.gyro_pwr_mode = DT_INST_PROP(inst, gyro_pwr_mode), \
308+
.gyro_fs = DT_INST_PROP(inst, gyro_fs), \
309+
.gyro_odr = DT_INST_PROP(inst, gyro_odr), \
310+
.temp_dis = false, \
311+
.fifo_en = IS_ENABLED(CONFIG_ICM42688_STREAM), \
312+
.batch_ticks = 0, \
313+
.fifo_hires = false, \
314+
.interrupt1_drdy = false, \
315+
.interrupt1_fifo_ths = false, \
316+
.interrupt1_fifo_full = false \
317+
}
318+
316319
#define ICM42688_DEFINE_DATA(inst) \
317320
IF_ENABLED(CONFIG_ICM42688_STREAM, (ICM42688_RTIO_DEFINE(inst))); \
318321
static struct icm42688_dev_data icm42688_driver_##inst = { \
322+
.cfg = ICM42688_DT_CONFIG_INIT(inst), \
319323
IF_ENABLED(CONFIG_ICM42688_STREAM, (.r = &icm42688_rtio_##inst, \
320-
.spi_iodev = &icm42688_spi_iodev_##inst,))};
324+
.spi_iodev = &icm42688_spi_iodev_##inst,)) \
325+
};
321326

322327
#define ICM42688_INIT(inst) \
323328
ICM42688_DEFINE_DATA(inst); \

0 commit comments

Comments
 (0)