Re: [PATCH v5 2/3] iio: accel: Support Kionix/ROHM KX022A accelerometer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Matti,

On Mon, Oct 24, 2022 at 6:10 PM Matti Vaittinen
<mazziesaccount@xxxxxxxxx> wrote:
>
> KX022A is a 3-axis accelerometer from ROHM/Kionix. The sensor features
> include variable ODRs, I2C and SPI control, FIFO/LIFO with watermark IRQ,
> tap/motion detection, wake-up & back-to-sleep events, four acceleration
> ranges (2, 4, 8 and 16g), and probably some other cool features.

This is a nice driver, and I found it very helpful as a reference.
One question regarding scale please see below.

> + * range is typically +-2G/4G/8G/16G, distributed over the amount of bits.
> + * The scale table can be calculated using
> + *     (range / 2^bits) * g = (range / 2^bits) * 9.80665 m/s^2
> + *     => KX022A uses 16 bit (HiRes mode - assume the low 8 bits are zeroed
> + *     in low-power mode(?) )
> + *     => +/-2G  => 4 / 2^16 * 9,80665 * 10^6 (to scale to micro)
> + *     => +/-2G  - 598.550415
> + *        +/-4G  - 1197.10083
> + *        +/-8G  - 2394.20166
> + *        +/-16G - 4788.40332
> + */
> +static const int kx022a_scale_table[][2] = {
> +       { 598, 550415 },
> +       { 1197, 100830 },
> +       { 2394, 201660 },
> +       { 4788, 403320 },
> +};

Given that the integer part is non-zero, and
IIO_VAL_INT_PLUS_MICRO is returned for read_scale,
As raw value will never be fractional how does this
correspond to a reading of 9.8 m/s² for the Z-axis?

> +
> +static int kx022a_read_avail(struct iio_dev *indio_dev,
> +                            struct iio_chan_spec const *chan,
> +                            const int **vals, int *type, int *length,
> +                            long mask)
> +{
> +       switch (mask) {
> +       case IIO_CHAN_INFO_SAMP_FREQ:
> +               *vals = (const int *)kx022a_accel_samp_freq_table;
> +               *length = ARRAY_SIZE(kx022a_accel_samp_freq_table) *
> +                         ARRAY_SIZE(kx022a_accel_samp_freq_table[0]);
> +               *type = IIO_VAL_INT_PLUS_MICRO;
> +               return IIO_AVAIL_LIST;
> +       case IIO_CHAN_INFO_SCALE:
> +               *vals = (const int *)kx022a_scale_table;
> +               *length = ARRAY_SIZE(kx022a_scale_table) *
> +                         ARRAY_SIZE(kx022a_scale_table[0]);
> +               *type = IIO_VAL_INT_PLUS_MICRO;
> +               return IIO_AVAIL_LIST;
> +       default:
> +               return -EINVAL;
> +       }
> +}

Regards
Jagath




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux