Messages in this thread | | | Date | Fri, 20 Oct 2023 15:09:14 +0300 | Subject | Re: [PATCH] iio: kx022a: Fix acceleration value scaling | From | Matti Vaittinen <> |
| |
On 10/19/23 21:21, Jagath Jog J wrote: > Hi Matti, > > On Thu, Oct 19, 2023 at 6:54 PM Matti Vaittinen > <mazziesaccount@gmail.com> wrote: >> >> The IIO ABI mandates acceleration values from accelerometer to be >> emitted in m/s^2. The KX022A was emitting values in micro m/s^2. >> >> Fix driver to report the correct scale values. >> >> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com> >> Reported-by: Jagath Jog J <jagathjog1996@gmail.com> >> Fixes: 7c1d1677b322 ("iio: accel: Support Kionix/ROHM KX022A accelerometer") >> >> --- >> The fix is somewhat crude and just crops the last 3 digits (rounds) of the >> scale while using IIO_VAL_INT_PLUS_NANO. I played with a thought of using >> IIO_VAL_FRACTIONAL, which could have modelled the computation >> G_range * g * scaling / (2^16 * scaling) - where scaling 10000 would >> have allowed using g value 980665. >> >> This would have worked fine for reporting scale and available scales - >> but would be somewhat tricky when converting the user-supplied scale to >> register values in write_raw(). >> >> Well, the g varies from 9.832 (poles) to 9.780 (equator) according to >> some website - no proper source check done but this sounds about right - >> so maybe the loss of accuracy is acceptable. >> >> I did only very quick testing on KX022A and iio_generic_buffer. After >> the patch the values seemed to be correct order of magnitude. Further >> testing is appreciated :) > > Values are correct with this change, Thank you for fixing. > Tested-by: Jagath Jog J <jagathjog1996@gmail.com>
Thanks a ton for testing! May I ask which component did you use (or did you just use some 'simulated' regster values?)
Yours, -- Matti
-- Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
| |