analogdevicesinc / linux

Linux kernel variant from Analog Devices; see README.md for details

Home Page:https://github.com/analogdevicesinc/linux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Raw values of adxrs290 were not sign-extended.

kister-jimenez opened this issue · comments

static int adxrs290_get_rate_data(struct iio_dev *indio_dev, const u8 cmd, int *val)

The raw value of this attribute is a 16-bit signed integer. However, the 16-bit spi data was assigned with to an int without sign-extension. This will cause the attribute to be positive and (doubled) in negative revolutions.

Same thing with the temperature attribute. Temperature is signed 12-bit stored as signed 16-bit integer but, was stored as int without sign extension.

static int adxrs290_get_temp_data(struct iio_dev *indio_dev, int *val)

@layman-n-ish
can you take a quick look at this?

Hi @kister-jimenez. Thanks for reporting this.

You're right, the raw two's complement rate and temperature data from ADXRS290 should be sign-extended while packing those to an int. I guess I didn't notice this because I expected the readings exposed to the sysfs attribute files to be the raw, two's-complemented values.

Modifying L127 to *val = sign_extend32(temp, 15); should fix the issue, I suppose.

Similarly, L149 to *val = sign_extend32(temp & 0x0FFF, 11);

The buffer data capture code is not susceptible as, to my knowledge, the IIO core does the necessary extension. So, nothing changes there.

I tested the above modifications and hope this is what you expected:

Screenshot from 2020-11-12 20-29-26

Feel free to send in a PR fixing this issue once you too test the above modifications.

@layman-n-ish Thanks. I'm closing this now. I've tested the fix and the PR has been merged.