Skip to content

Commit

Permalink
sensor: default_rtio_sensor: fix: Treat individual axis data as q31_t
Browse files Browse the repository at this point in the history
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]>
(cherry picked from commit 5a1dfc8)
  • Loading branch information
ubieda authored and github-actions[bot] committed Jan 9, 2025
1 parent eaafb68 commit 82928c0
Showing 1 changed file with 32 additions and 37 deletions.
69 changes: 32 additions & 37 deletions drivers/sensor/default_rtio_sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,25 +313,44 @@ static int get_frame_count(const uint8_t *buffer, struct sensor_chan_spec channe

switch (channel.chan_type) {
case SENSOR_CHAN_ACCEL_XYZ:
channel.chan_type = SENSOR_CHAN_ACCEL_X;
break;
case SENSOR_CHAN_GYRO_XYZ:
channel.chan_type = SENSOR_CHAN_GYRO_X;
break;
case SENSOR_CHAN_MAGN_XYZ:
channel.chan_type = SENSOR_CHAN_MAGN_X;
break;
case SENSOR_CHAN_POS_DXYZ:
channel.chan_type = SENSOR_CHAN_POS_DX;
for (size_t i = 0 ; i < header->num_channels; ++i) {
/* For 3-axis channels, we need to verify we have each individual axis */
struct sensor_chan_spec channel_x = {
.chan_type = channel.chan_type - 3,
.chan_idx = channel.chan_idx,
};
struct sensor_chan_spec channel_y = {
.chan_type = channel.chan_type - 2,
.chan_idx = channel.chan_idx,
};
struct sensor_chan_spec channel_z = {
.chan_type = channel.chan_type - 1,
.chan_idx = channel.chan_idx,
};

/** The three axes don't need to be at the beginning of the header, but
* they should be consecutive.
*/
if (((header->num_channels - i) >= 3) &&
sensor_chan_spec_eq(header->channels[i], channel_x) &&
sensor_chan_spec_eq(header->channels[i + 1], channel_y) &&
sensor_chan_spec_eq(header->channels[i + 2], channel_z)) {
*frame_count = 1;
return 0;
}
}
break;
default:
break;
}
for (size_t i = 0; i < header->num_channels; ++i) {
if (sensor_chan_spec_eq(header->channels[i], channel)) {
*frame_count = 1;
return 0;
for (size_t i = 0; i < header->num_channels; ++i) {
if (sensor_chan_spec_eq(header->channels[i], channel)) {
*frame_count = 1;
return 0;
}
}
break;
}

return -ENOTSUP;
Expand All @@ -348,21 +367,9 @@ int sensor_natively_supported_channel_size_info(struct sensor_chan_spec channel,
}

switch (channel.chan_type) {
case SENSOR_CHAN_ACCEL_X:
case SENSOR_CHAN_ACCEL_Y:
case SENSOR_CHAN_ACCEL_Z:
case SENSOR_CHAN_ACCEL_XYZ:
case SENSOR_CHAN_GYRO_X:
case SENSOR_CHAN_GYRO_Y:
case SENSOR_CHAN_GYRO_Z:
case SENSOR_CHAN_GYRO_XYZ:
case SENSOR_CHAN_MAGN_X:
case SENSOR_CHAN_MAGN_Y:
case SENSOR_CHAN_MAGN_Z:
case SENSOR_CHAN_MAGN_XYZ:
case SENSOR_CHAN_POS_DX:
case SENSOR_CHAN_POS_DY:
case SENSOR_CHAN_POS_DZ:
case SENSOR_CHAN_POS_DXYZ:
*base_size = sizeof(struct sensor_three_axis_data);
*frame_size = sizeof(struct sensor_three_axis_sample_data);
Expand Down Expand Up @@ -475,33 +482,21 @@ static int decode(const uint8_t *buffer, struct sensor_chan_spec chan_spec,

/* Check for 3d channel mappings */
switch (chan_spec.chan_type) {
case SENSOR_CHAN_ACCEL_X:
case SENSOR_CHAN_ACCEL_Y:
case SENSOR_CHAN_ACCEL_Z:
case SENSOR_CHAN_ACCEL_XYZ:
count = decode_three_axis(header, q, data_out, SENSOR_CHAN_ACCEL_X,
SENSOR_CHAN_ACCEL_Y, SENSOR_CHAN_ACCEL_Z,
chan_spec.chan_idx);
break;
case SENSOR_CHAN_GYRO_X:
case SENSOR_CHAN_GYRO_Y:
case SENSOR_CHAN_GYRO_Z:
case SENSOR_CHAN_GYRO_XYZ:
count = decode_three_axis(header, q, data_out, SENSOR_CHAN_GYRO_X,
SENSOR_CHAN_GYRO_Y, SENSOR_CHAN_GYRO_Z,
chan_spec.chan_idx);
break;
case SENSOR_CHAN_MAGN_X:
case SENSOR_CHAN_MAGN_Y:
case SENSOR_CHAN_MAGN_Z:
case SENSOR_CHAN_MAGN_XYZ:
count = decode_three_axis(header, q, data_out, SENSOR_CHAN_MAGN_X,
SENSOR_CHAN_MAGN_Y, SENSOR_CHAN_MAGN_Z,
chan_spec.chan_idx);
break;
case SENSOR_CHAN_POS_DX:
case SENSOR_CHAN_POS_DY:
case SENSOR_CHAN_POS_DZ:
case SENSOR_CHAN_POS_DXYZ:
count = decode_three_axis(header, q, data_out, SENSOR_CHAN_POS_DX,
SENSOR_CHAN_POS_DY, SENSOR_CHAN_POS_DZ,
Expand Down

0 comments on commit 82928c0

Please sign in to comment.