@@ -150,7 +150,8 @@ static int icm4268x_attr_set(const struct device *dev, enum sensor_channel chan,
150
150
if (attr == SENSOR_ATTR_SAMPLING_FREQUENCY ) {
151
151
new_config .accel_odr = icm4268x_accel_hz_to_reg (val -> val1 );
152
152
} 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 );
154
155
} else {
155
156
LOG_ERR ("Unsupported attribute" );
156
157
res = - ENOTSUP ;
@@ -163,7 +164,8 @@ static int icm4268x_attr_set(const struct device *dev, enum sensor_channel chan,
163
164
if (attr == SENSOR_ATTR_SAMPLING_FREQUENCY ) {
164
165
new_config .gyro_odr = icm4268x_gyro_odr_to_reg (val -> val1 );
165
166
} 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 );
167
169
} else {
168
170
LOG_ERR ("Unsupported attribute" );
169
171
res = - EINVAL ;
@@ -232,7 +234,7 @@ static int icm4268x_attr_get(const struct device *dev, enum sensor_channel chan,
232
234
if (attr == SENSOR_ATTR_SAMPLING_FREQUENCY ) {
233
235
icm4268x_accel_reg_to_hz (cfg -> accel_odr , val );
234
236
} 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 );
236
238
} else {
237
239
LOG_ERR ("Unsupported attribute" );
238
240
res = - EINVAL ;
@@ -245,7 +247,7 @@ static int icm4268x_attr_get(const struct device *dev, enum sensor_channel chan,
245
247
if (attr == SENSOR_ATTR_SAMPLING_FREQUENCY ) {
246
248
icm4268x_gyro_reg_to_odr (cfg -> gyro_odr , val );
247
249
} 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 );
249
251
} else {
250
252
LOG_ERR ("Unsupported attribute" );
251
253
res = - EINVAL ;
@@ -341,6 +343,10 @@ void icm4268x_unlock(const struct device *dev)
341
343
342
344
#define ICM42688_DT_CONFIG_INIT (inst ) \
343
345
{ \
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,), ()))) \
344
350
.accel_pwr_mode = DT_INST_PROP(inst, accel_pwr_mode), \
345
351
.accel_fs = DT_INST_PROP(inst, accel_fs), \
346
352
.accel_odr = DT_INST_PROP(inst, accel_odr), \
@@ -372,11 +378,25 @@ void icm4268x_unlock(const struct device *dev)
372
378
.spi_iodev = &icm4268x_spi_iodev_##inst,)) \
373
379
};
374
380
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
+
375
390
#define ICM4268X_INIT (inst ) \
376
391
\
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), \
378
394
"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)), ()); \
380
400
\
381
401
ICM4268X_DEFINE_DATA(inst); \
382
402
\
0 commit comments