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 <vladislav.pejic@orioninc.com>
This commit is contained in:
parent
9ccaf9b5bd
commit
832bbd8030
1 changed files with 5 additions and 8 deletions
|
@ -8,11 +8,9 @@
|
||||||
|
|
||||||
#ifdef CONFIG_ADXL372_STREAM
|
#ifdef CONFIG_ADXL372_STREAM
|
||||||
|
|
||||||
/*
|
/* (1.0 / 10 (sensor sensitivity)) * (2^31 / 2^11 (sensor shift) ) * SENSOR_G */
|
||||||
* Sensor resolution is 100mg/LSB, 12-bit value needs to be right
|
#define SENSOR_QSCALE_FACTOR UINT32_C(1027604)
|
||||||
* shifted by 4 or divided by 16. Overall this results in a scale of 160
|
|
||||||
*/
|
|
||||||
#define SENSOR_SCALING_FACTOR (SENSOR_G / (16 * 1000 / 100))
|
|
||||||
#define ADXL372_COMPLEMENT 0xf000
|
#define ADXL372_COMPLEMENT 0xf000
|
||||||
|
|
||||||
static const uint32_t accel_period_ns[] = {
|
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)
|
||||||
data_in |= ADXL372_COMPLEMENT;
|
data_in |= ADXL372_COMPLEMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t micro_ms2 = data_in * SENSOR_SCALING_FACTOR;
|
*out = data_in * SENSOR_QSCALE_FACTOR;
|
||||||
|
|
||||||
*out = CLAMP((micro_ms2 + (micro_ms2 % 1000000)), INT32_MIN, INT32_MAX);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int adxl372_decode_stream(const uint8_t *buffer, struct sensor_chan_spec chan_spec,
|
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
|
||||||
memset(data, 0, sizeof(struct sensor_three_axis_data));
|
memset(data, 0, sizeof(struct sensor_three_axis_data));
|
||||||
data->header.base_timestamp_ns = enc_data->timestamp;
|
data->header.base_timestamp_ns = enc_data->timestamp;
|
||||||
data->header.reading_count = 1;
|
data->header.reading_count = 1;
|
||||||
|
data->header.shift = 11; /* Sensor shift */
|
||||||
|
|
||||||
buffer += sizeof(struct adxl372_fifo_data);
|
buffer += sizeof(struct adxl372_fifo_data);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue