Skip to content

Commit 832bbd8

Browse files
vladislav-pejicdleach02
authored andcommitted
driver: sensor: adxl372: Bug fix for q31_t conv
This is a bug fix for adxl372_accel_convert_q31 function. Function is used to convert samples received from sensor to q31_t format when RTIO stream is used. Signed-off-by: Vladislav Pejic <[email protected]>
1 parent 9ccaf9b commit 832bbd8

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

drivers/sensor/adi/adxl372/adxl372_decoder.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88

99
#ifdef CONFIG_ADXL372_STREAM
1010

11-
/*
12-
* Sensor resolution is 100mg/LSB, 12-bit value needs to be right
13-
* shifted by 4 or divided by 16. Overall this results in a scale of 160
14-
*/
15-
#define SENSOR_SCALING_FACTOR (SENSOR_G / (16 * 1000 / 100))
11+
/* (1.0 / 10 (sensor sensitivity)) * (2^31 / 2^11 (sensor shift) ) * SENSOR_G */
12+
#define SENSOR_QSCALE_FACTOR UINT32_C(1027604)
13+
1614
#define ADXL372_COMPLEMENT 0xf000
1715

1816
static const uint32_t accel_period_ns[] = {
@@ -31,9 +29,7 @@ static inline void adxl372_accel_convert_q31(q31_t *out, const uint8_t *buff)
3129
data_in |= ADXL372_COMPLEMENT;
3230
}
3331

34-
int64_t micro_ms2 = data_in * SENSOR_SCALING_FACTOR;
35-
36-
*out = CLAMP((micro_ms2 + (micro_ms2 % 1000000)), INT32_MIN, INT32_MAX);
32+
*out = data_in * SENSOR_QSCALE_FACTOR;
3733
}
3834

3935
static int adxl372_decode_stream(const uint8_t *buffer, struct sensor_chan_spec chan_spec,
@@ -54,6 +50,7 @@ static int adxl372_decode_stream(const uint8_t *buffer, struct sensor_chan_spec
5450
memset(data, 0, sizeof(struct sensor_three_axis_data));
5551
data->header.base_timestamp_ns = enc_data->timestamp;
5652
data->header.reading_count = 1;
53+
data->header.shift = 11; /* Sensor shift */
5754

5855
buffer += sizeof(struct adxl372_fifo_data);
5956

0 commit comments

Comments
 (0)