Skip to content

Commit f850634

Browse files
ubiedakartben
authored andcommitted
sensor: icm42688: change single-axis data reported as sensor_q31_data
When individual axis is retrieved, it does not require the other values. Simplify one-shot decoder to follow this pattern. Signed-off-by: Luis Ubieda <luisf@croxel.com>
1 parent 0fc4806 commit f850634

File tree

1 file changed

+25
-56
lines changed

1 file changed

+25
-56
lines changed

drivers/sensor/tdk/icm42688/icm42688_decoder.c

Lines changed: 25 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -434,42 +434,36 @@ static int icm42688_one_shot_decode(const uint8_t *buffer, struct sensor_chan_sp
434434
case SENSOR_CHAN_ACCEL_X:
435435
case SENSOR_CHAN_ACCEL_Y:
436436
case SENSOR_CHAN_ACCEL_Z:
437-
case SENSOR_CHAN_ACCEL_XYZ: {
438-
channel_request = icm42688_encode_channel(SENSOR_CHAN_ACCEL_XYZ);
437+
case SENSOR_CHAN_GYRO_X:
438+
case SENSOR_CHAN_GYRO_Y:
439+
case SENSOR_CHAN_GYRO_Z:
440+
case SENSOR_CHAN_DIE_TEMP: {
441+
channel_request = icm42688_encode_channel(chan_spec.chan_type);
439442
if ((channel_request & edata->channels) != channel_request) {
440443
return -ENODATA;
441444
}
442445

443-
struct sensor_three_axis_data *out = data_out;
446+
struct sensor_q31_data *out = data_out;
444447

445448
out->header.base_timestamp_ns = edata->header.timestamp;
446449
out->header.reading_count = 1;
447-
rc = icm42688_get_shift(SENSOR_CHAN_ACCEL_XYZ, header->accel_fs, header->gyro_fs,
450+
451+
rc = icm42688_get_shift(chan_spec.chan_type, header->accel_fs, header->gyro_fs,
448452
&out->shift);
449453
if (rc != 0) {
450454
return -EINVAL;
451455
}
452456

453457
icm42688_convert_raw_to_q31(
454-
&cfg, SENSOR_CHAN_ACCEL_X,
455-
edata->readings[icm42688_get_channel_position(SENSOR_CHAN_ACCEL_X)],
456-
&out->readings[0].x);
457-
icm42688_convert_raw_to_q31(
458-
&cfg, SENSOR_CHAN_ACCEL_Y,
459-
edata->readings[icm42688_get_channel_position(SENSOR_CHAN_ACCEL_Y)],
460-
&out->readings[0].y);
461-
icm42688_convert_raw_to_q31(
462-
&cfg, SENSOR_CHAN_ACCEL_Z,
463-
edata->readings[icm42688_get_channel_position(SENSOR_CHAN_ACCEL_Z)],
464-
&out->readings[0].z);
458+
&cfg, chan_spec.chan_type,
459+
edata->readings[icm42688_get_channel_position(chan_spec.chan_type)],
460+
&out->readings[0].value);
465461
*fit = 1;
466462
return 1;
467463
}
468-
case SENSOR_CHAN_GYRO_X:
469-
case SENSOR_CHAN_GYRO_Y:
470-
case SENSOR_CHAN_GYRO_Z:
464+
case SENSOR_CHAN_ACCEL_XYZ:
471465
case SENSOR_CHAN_GYRO_XYZ: {
472-
channel_request = icm42688_encode_channel(SENSOR_CHAN_GYRO_XYZ);
466+
channel_request = icm42688_encode_channel(chan_spec.chan_type);
473467
if ((channel_request & edata->channels) != channel_request) {
474468
return -ENODATA;
475469
}
@@ -478,52 +472,27 @@ static int icm42688_one_shot_decode(const uint8_t *buffer, struct sensor_chan_sp
478472

479473
out->header.base_timestamp_ns = edata->header.timestamp;
480474
out->header.reading_count = 1;
481-
rc = icm42688_get_shift(SENSOR_CHAN_GYRO_XYZ, header->accel_fs, header->gyro_fs,
475+
rc = icm42688_get_shift(chan_spec.chan_type, header->accel_fs, header->gyro_fs,
482476
&out->shift);
483477
if (rc != 0) {
484478
return -EINVAL;
485479
}
486480

487-
out->readings[0].timestamp_delta = 0;
488481
icm42688_convert_raw_to_q31(
489-
&cfg, SENSOR_CHAN_GYRO_X,
490-
edata->readings[icm42688_get_channel_position(SENSOR_CHAN_GYRO_X)],
482+
&cfg, chan_spec.chan_type - 3,
483+
edata->readings[icm42688_get_channel_position(chan_spec.chan_type - 3)],
491484
&out->readings[0].x);
492485
icm42688_convert_raw_to_q31(
493-
&cfg, SENSOR_CHAN_GYRO_Y,
494-
edata->readings[icm42688_get_channel_position(SENSOR_CHAN_GYRO_Y)],
486+
&cfg, chan_spec.chan_type - 2,
487+
edata->readings[icm42688_get_channel_position(chan_spec.chan_type - 2)],
495488
&out->readings[0].y);
496489
icm42688_convert_raw_to_q31(
497-
&cfg, SENSOR_CHAN_GYRO_Z,
498-
edata->readings[icm42688_get_channel_position(SENSOR_CHAN_GYRO_Z)],
490+
&cfg, chan_spec.chan_type - 1,
491+
edata->readings[icm42688_get_channel_position(chan_spec.chan_type - 1)],
499492
&out->readings[0].z);
500493
*fit = 1;
501494
return 1;
502495
}
503-
case SENSOR_CHAN_DIE_TEMP: {
504-
channel_request = icm42688_encode_channel(SENSOR_CHAN_DIE_TEMP);
505-
if ((channel_request & edata->channels) != channel_request) {
506-
return -ENODATA;
507-
}
508-
509-
struct sensor_q31_data *out = data_out;
510-
511-
out->header.base_timestamp_ns = edata->header.timestamp;
512-
out->header.reading_count = 1;
513-
514-
rc = icm42688_get_shift(SENSOR_CHAN_DIE_TEMP, header->accel_fs, header->gyro_fs,
515-
&out->shift);
516-
if (rc != 0) {
517-
return -EINVAL;
518-
}
519-
out->readings[0].timestamp_delta = 0;
520-
icm42688_convert_raw_to_q31(
521-
&cfg, SENSOR_CHAN_DIE_TEMP,
522-
edata->readings[icm42688_get_channel_position(SENSOR_CHAN_DIE_TEMP)],
523-
&out->readings[0].temperature);
524-
*fit = 1;
525-
return 1;
526-
}
527496
default:
528497
return -EINVAL;
529498
}
@@ -606,17 +575,17 @@ static int icm42688_decoder_get_size_info(struct sensor_chan_spec chan_spec, siz
606575
size_t *frame_size)
607576
{
608577
switch (chan_spec.chan_type) {
578+
case SENSOR_CHAN_ACCEL_XYZ:
579+
case SENSOR_CHAN_GYRO_XYZ:
580+
*base_size = sizeof(struct sensor_three_axis_data);
581+
*frame_size = sizeof(struct sensor_three_axis_sample_data);
582+
return 0;
609583
case SENSOR_CHAN_ACCEL_X:
610584
case SENSOR_CHAN_ACCEL_Y:
611585
case SENSOR_CHAN_ACCEL_Z:
612-
case SENSOR_CHAN_ACCEL_XYZ:
613586
case SENSOR_CHAN_GYRO_X:
614587
case SENSOR_CHAN_GYRO_Y:
615588
case SENSOR_CHAN_GYRO_Z:
616-
case SENSOR_CHAN_GYRO_XYZ:
617-
*base_size = sizeof(struct sensor_three_axis_data);
618-
*frame_size = sizeof(struct sensor_three_axis_sample_data);
619-
return 0;
620589
case SENSOR_CHAN_DIE_TEMP:
621590
*base_size = sizeof(struct sensor_q31_data);
622591
*frame_size = sizeof(struct sensor_q31_sample_data);

0 commit comments

Comments
 (0)