Skip to content

Commit 5a1dfc8

Browse files
ubiedakartben
authored andcommitted
sensor: default_rtio_sensor: fix: Treat individual axis data as q31_t
Instead of assuming that an individual axis must contain all data-values. Additionally, for determining that there's XYZ data, all three channels must be present in the header. Signed-off-by: Luis Ubieda <[email protected]>
1 parent 36dfea1 commit 5a1dfc8

File tree

1 file changed

+32
-37
lines changed

1 file changed

+32
-37
lines changed

drivers/sensor/default_rtio_sensor.c

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -318,25 +318,44 @@ static int get_frame_count(const uint8_t *buffer, struct sensor_chan_spec channe
318318

319319
switch (channel.chan_type) {
320320
case SENSOR_CHAN_ACCEL_XYZ:
321-
channel.chan_type = SENSOR_CHAN_ACCEL_X;
322-
break;
323321
case SENSOR_CHAN_GYRO_XYZ:
324-
channel.chan_type = SENSOR_CHAN_GYRO_X;
325-
break;
326322
case SENSOR_CHAN_MAGN_XYZ:
327-
channel.chan_type = SENSOR_CHAN_MAGN_X;
328-
break;
329323
case SENSOR_CHAN_POS_DXYZ:
330-
channel.chan_type = SENSOR_CHAN_POS_DX;
324+
for (size_t i = 0 ; i < header->num_channels; ++i) {
325+
/* For 3-axis channels, we need to verify we have each individual axis */
326+
struct sensor_chan_spec channel_x = {
327+
.chan_type = channel.chan_type - 3,
328+
.chan_idx = channel.chan_idx,
329+
};
330+
struct sensor_chan_spec channel_y = {
331+
.chan_type = channel.chan_type - 2,
332+
.chan_idx = channel.chan_idx,
333+
};
334+
struct sensor_chan_spec channel_z = {
335+
.chan_type = channel.chan_type - 1,
336+
.chan_idx = channel.chan_idx,
337+
};
338+
339+
/** The three axes don't need to be at the beginning of the header, but
340+
* they should be consecutive.
341+
*/
342+
if (((header->num_channels - i) >= 3) &&
343+
sensor_chan_spec_eq(header->channels[i], channel_x) &&
344+
sensor_chan_spec_eq(header->channels[i + 1], channel_y) &&
345+
sensor_chan_spec_eq(header->channels[i + 2], channel_z)) {
346+
*frame_count = 1;
347+
return 0;
348+
}
349+
}
331350
break;
332351
default:
333-
break;
334-
}
335-
for (size_t i = 0; i < header->num_channels; ++i) {
336-
if (sensor_chan_spec_eq(header->channels[i], channel)) {
337-
*frame_count = 1;
338-
return 0;
352+
for (size_t i = 0; i < header->num_channels; ++i) {
353+
if (sensor_chan_spec_eq(header->channels[i], channel)) {
354+
*frame_count = 1;
355+
return 0;
356+
}
339357
}
358+
break;
340359
}
341360

342361
return -ENOTSUP;
@@ -353,21 +372,9 @@ int sensor_natively_supported_channel_size_info(struct sensor_chan_spec channel,
353372
}
354373

355374
switch (channel.chan_type) {
356-
case SENSOR_CHAN_ACCEL_X:
357-
case SENSOR_CHAN_ACCEL_Y:
358-
case SENSOR_CHAN_ACCEL_Z:
359375
case SENSOR_CHAN_ACCEL_XYZ:
360-
case SENSOR_CHAN_GYRO_X:
361-
case SENSOR_CHAN_GYRO_Y:
362-
case SENSOR_CHAN_GYRO_Z:
363376
case SENSOR_CHAN_GYRO_XYZ:
364-
case SENSOR_CHAN_MAGN_X:
365-
case SENSOR_CHAN_MAGN_Y:
366-
case SENSOR_CHAN_MAGN_Z:
367377
case SENSOR_CHAN_MAGN_XYZ:
368-
case SENSOR_CHAN_POS_DX:
369-
case SENSOR_CHAN_POS_DY:
370-
case SENSOR_CHAN_POS_DZ:
371378
case SENSOR_CHAN_POS_DXYZ:
372379
*base_size = sizeof(struct sensor_three_axis_data);
373380
*frame_size = sizeof(struct sensor_three_axis_sample_data);
@@ -480,33 +487,21 @@ static int decode(const uint8_t *buffer, struct sensor_chan_spec chan_spec,
480487

481488
/* Check for 3d channel mappings */
482489
switch (chan_spec.chan_type) {
483-
case SENSOR_CHAN_ACCEL_X:
484-
case SENSOR_CHAN_ACCEL_Y:
485-
case SENSOR_CHAN_ACCEL_Z:
486490
case SENSOR_CHAN_ACCEL_XYZ:
487491
count = decode_three_axis(header, q, data_out, SENSOR_CHAN_ACCEL_X,
488492
SENSOR_CHAN_ACCEL_Y, SENSOR_CHAN_ACCEL_Z,
489493
chan_spec.chan_idx);
490494
break;
491-
case SENSOR_CHAN_GYRO_X:
492-
case SENSOR_CHAN_GYRO_Y:
493-
case SENSOR_CHAN_GYRO_Z:
494495
case SENSOR_CHAN_GYRO_XYZ:
495496
count = decode_three_axis(header, q, data_out, SENSOR_CHAN_GYRO_X,
496497
SENSOR_CHAN_GYRO_Y, SENSOR_CHAN_GYRO_Z,
497498
chan_spec.chan_idx);
498499
break;
499-
case SENSOR_CHAN_MAGN_X:
500-
case SENSOR_CHAN_MAGN_Y:
501-
case SENSOR_CHAN_MAGN_Z:
502500
case SENSOR_CHAN_MAGN_XYZ:
503501
count = decode_three_axis(header, q, data_out, SENSOR_CHAN_MAGN_X,
504502
SENSOR_CHAN_MAGN_Y, SENSOR_CHAN_MAGN_Z,
505503
chan_spec.chan_idx);
506504
break;
507-
case SENSOR_CHAN_POS_DX:
508-
case SENSOR_CHAN_POS_DY:
509-
case SENSOR_CHAN_POS_DZ:
510505
case SENSOR_CHAN_POS_DXYZ:
511506
count = decode_three_axis(header, q, data_out, SENSOR_CHAN_POS_DX,
512507
SENSOR_CHAN_POS_DY, SENSOR_CHAN_POS_DZ,

0 commit comments

Comments
 (0)