Skip to content

Commit 5edd422

Browse files
trentp-igormbolivar-nordic
authored andcommitted
drivers/sensor: lsm6dso: Refactor common config out of I2C/SPI macros
Move common settings out of the SPI and I2C instantiation macros and into a common macro, which the aforementioned two macros can then use. Signed-off-by: Trent Piepho <[email protected]>
1 parent c269692 commit 5edd422

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

drivers/sensor/lsm6dso/lsm6dso.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,16 @@ static int lsm6dso_init(const struct device *dev)
876876
SPI_MODE_CPOL | \
877877
SPI_MODE_CPHA) \
878878

879+
#define LSM6DSO_CONFIG_COMMON(inst) \
880+
.accel_pm = DT_INST_PROP(inst, accel_pm), \
881+
.accel_odr = DT_INST_PROP(inst, accel_odr), \
882+
.accel_range = DT_INST_PROP(inst, accel_range), \
883+
.gyro_pm = DT_INST_PROP(inst, gyro_pm), \
884+
.gyro_odr = DT_INST_PROP(inst, gyro_odr), \
885+
.gyro_range = DT_INST_PROP(inst, gyro_range), \
886+
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \
887+
(LSM6DSO_CFG_IRQ(inst)), ())
888+
879889
#define LSM6DSO_CONFIG_SPI(inst) \
880890
{ \
881891
.ctx = { \
@@ -891,14 +901,7 @@ static int lsm6dso_init(const struct device *dev)
891901
LSM6DSO_SPI_OP, \
892902
0), \
893903
}, \
894-
.accel_pm = DT_INST_PROP(inst, accel_pm), \
895-
.accel_odr = DT_INST_PROP(inst, accel_odr), \
896-
.accel_range = DT_INST_PROP(inst, accel_range), \
897-
.gyro_pm = DT_INST_PROP(inst, gyro_pm), \
898-
.gyro_odr = DT_INST_PROP(inst, gyro_odr), \
899-
.gyro_range = DT_INST_PROP(inst, gyro_range), \
900-
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \
901-
(LSM6DSO_CFG_IRQ(inst)), ()) \
904+
LSM6DSO_CONFIG_COMMON(inst) \
902905
}
903906

904907
/*
@@ -918,14 +921,7 @@ static int lsm6dso_init(const struct device *dev)
918921
.stmemsc_cfg = { \
919922
.i2c = I2C_DT_SPEC_INST_GET(inst), \
920923
}, \
921-
.accel_pm = DT_INST_PROP(inst, accel_pm), \
922-
.accel_odr = DT_INST_PROP(inst, accel_odr), \
923-
.accel_range = DT_INST_PROP(inst, accel_range), \
924-
.gyro_pm = DT_INST_PROP(inst, gyro_pm), \
925-
.gyro_odr = DT_INST_PROP(inst, gyro_odr), \
926-
.gyro_range = DT_INST_PROP(inst, gyro_range), \
927-
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \
928-
(LSM6DSO_CFG_IRQ(inst)), ()) \
924+
LSM6DSO_CONFIG_COMMON(inst) \
929925
}
930926

931927
/*

0 commit comments

Comments
 (0)