@@ -150,7 +150,8 @@ static int icm4268x_attr_set(const struct device *dev, enum sensor_channel chan,
150150 if (attr == SENSOR_ATTR_SAMPLING_FREQUENCY ) {
151151 new_config .accel_odr = icm4268x_accel_hz_to_reg (val -> val1 );
152152 } else if (attr == SENSOR_ATTR_FULL_SCALE ) {
153- new_config .accel_fs = icm4268x_accel_fs_to_reg (sensor_ms2_to_g (val ));
153+ new_config .accel_fs = icm4268x_accel_fs_to_reg (sensor_ms2_to_g (val ),
154+ data -> cfg .variant );
154155 } else {
155156 LOG_ERR ("Unsupported attribute" );
156157 res = - ENOTSUP ;
@@ -163,7 +164,8 @@ static int icm4268x_attr_set(const struct device *dev, enum sensor_channel chan,
163164 if (attr == SENSOR_ATTR_SAMPLING_FREQUENCY ) {
164165 new_config .gyro_odr = icm4268x_gyro_odr_to_reg (val -> val1 );
165166 } else if (attr == SENSOR_ATTR_FULL_SCALE ) {
166- new_config .gyro_fs = icm4268x_gyro_fs_to_reg (sensor_rad_to_degrees (val ));
167+ new_config .gyro_fs = icm4268x_gyro_fs_to_reg (sensor_rad_to_degrees (val ),
168+ data -> cfg .variant );
167169 } else {
168170 LOG_ERR ("Unsupported attribute" );
169171 res = - EINVAL ;
@@ -232,7 +234,7 @@ static int icm4268x_attr_get(const struct device *dev, enum sensor_channel chan,
232234 if (attr == SENSOR_ATTR_SAMPLING_FREQUENCY ) {
233235 icm4268x_accel_reg_to_hz (cfg -> accel_odr , val );
234236 } else if (attr == SENSOR_ATTR_FULL_SCALE ) {
235- icm4268x_accel_reg_to_fs (cfg -> accel_fs , val );
237+ icm4268x_accel_reg_to_fs (cfg -> accel_fs , data -> cfg . variant , val );
236238 } else {
237239 LOG_ERR ("Unsupported attribute" );
238240 res = - EINVAL ;
@@ -245,7 +247,7 @@ static int icm4268x_attr_get(const struct device *dev, enum sensor_channel chan,
245247 if (attr == SENSOR_ATTR_SAMPLING_FREQUENCY ) {
246248 icm4268x_gyro_reg_to_odr (cfg -> gyro_odr , val );
247249 } else if (attr == SENSOR_ATTR_FULL_SCALE ) {
248- icm4268x_gyro_reg_to_fs (cfg -> gyro_fs , val );
250+ icm4268x_gyro_reg_to_fs (cfg -> gyro_fs , data -> cfg . variant , val );
249251 } else {
250252 LOG_ERR ("Unsupported attribute" );
251253 res = - EINVAL ;
@@ -341,6 +343,10 @@ void icm4268x_unlock(const struct device *dev)
341343
342344#define ICM42688_DT_CONFIG_INIT (inst ) \
343345 { \
346+ COND_CODE_1(DT_INST_NODE_HAS_COMPAT(inst, invensense_icm42688), \
347+ (.variant = ICM4268X_VARIANT_ICM42688,), ( \
348+ COND_CODE_1(DT_INST_NODE_HAS_COMPAT(inst, invensense_icm42686), \
349+ (.variant = ICM4268X_VARIANT_ICM42686,), ()))) \
344350 .accel_pwr_mode = DT_INST_PROP(inst, accel_pwr_mode), \
345351 .accel_fs = DT_INST_PROP(inst, accel_fs), \
346352 .accel_odr = DT_INST_PROP(inst, accel_odr), \
@@ -372,11 +378,25 @@ void icm4268x_unlock(const struct device *dev)
372378 .spi_iodev = &icm4268x_spi_iodev_##inst,)) \
373379 };
374380
381+ /** The rest of the Device-tree configuration is validated in the YAML
382+ * file. This outlier comes from the fact we're sharing the dts-properties
383+ * across variants, and ICM42686 has an extra enum for the accel-fs.
384+ */
385+ #define ICM42688_BUILD_CONFIG_VALIDATION (inst ) \
386+ BUILD_ASSERT((DT_INST_PROP(inst, accel_fs) >= ICM42688_DT_ACCEL_FS_16) && \
387+ (DT_INST_PROP(inst, accel_fs) <= ICM42688_DT_ACCEL_FS_2), \
388+ "Invalid accel-fs configured for ICM42688. Please revisit DTS config-set");
389+
375390#define ICM4268X_INIT (inst ) \
376391 \
377- BUILD_ASSERT(DT_INST_NODE_HAS_COMPAT(inst, invensense_icm42688), \
392+ BUILD_ASSERT(DT_INST_NODE_HAS_COMPAT(inst, invensense_icm42688) || \
393+ DT_INST_NODE_HAS_COMPAT(inst, invensense_icm42686), \
378394 "Please define additional compatible property to dts node: " \
379- "<invensense,icm42688>"); \
395+ "<invensense,icm42688> or <invensense,icm42686>"); \
396+ \
397+ \
398+ COND_CODE_1(DT_INST_NODE_HAS_COMPAT(inst, invensense_icm42688), \
399+ (ICM42688_BUILD_CONFIG_VALIDATION(inst)), ()); \
380400 \
381401 ICM4268X_DEFINE_DATA(inst); \
382402 \
0 commit comments