Skip to content

Commit 6b3d53e

Browse files
ymleung314kartben
authored andcommitted
drivers: icm42688: ignore invalid fifo data
When using 20-bit FIFO packets, invalid data is indicated by the value -524288. Currently, no check is done against this and invalid data is decoded. Fixed by adding a simple check. Also, the wrong bit is used to check if HIRES is enabled. Fixed by using the correct mask. Signed-off-by: Yau-ming Leung <ymleung314@gmail.com>
1 parent 0d08e0d commit 6b3d53e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

drivers/sensor/tdk/icm42688/icm42688_decoder.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ static int icm42688_read_imu_from_packet(const uint8_t *pkt, bool is_accel, int
245245
{
246246
uint32_t unsigned_value;
247247
int32_t signed_value;
248-
bool is_hires = FIELD_GET(FIFO_HEADER_ACCEL, pkt[0]) == 1;
248+
bool is_hires = FIELD_GET(FIFO_HEADER_20, pkt[0]) == 1;
249249
int offset = 1 + (axis_offset * 2);
250250

251251
const uint32_t scale[2][2] = {
@@ -265,6 +265,19 @@ static int icm42688_read_imu_from_packet(const uint8_t *pkt, bool is_accel, int
265265
offset = 17 + axis_offset;
266266
unsigned_value = (unsigned_value << 4) | FIELD_GET(mask, pkt[offset]);
267267
signed_value = unsigned_value | (0 - (unsigned_value & BIT(19)));
268+
269+
/*
270+
* By default, INTF_CONFIG0 is set to 0x30 and thus FIFO_HOLD_LAST_DATA_EN is set to
271+
* 0. For 20-bit FIFO packets, -524288 indicates invalid data.
272+
*
273+
* At the time of writing, INTF_CONFIG0 is not configured explicitly.
274+
*
275+
* TODO: Enable/disable this check based on FIFO_HOLD_LAST_DATA_EN if INTF_CONFIG0
276+
* is configured explicitly.
277+
*/
278+
if (signed_value == -524288) {
279+
return -ENODATA;
280+
}
268281
} else {
269282
signed_value = unsigned_value | (0 - (unsigned_value & BIT(16)));
270283
}

0 commit comments

Comments
 (0)