All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Rishi Gupta <gupt21@gmail.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>
Subject: Re: [PATCH 2/2] iio: light: veml6030: fix scale to conform to ABI
Date: Tue, 14 Jan 2025 16:26:16 +0200	[thread overview]
Message-ID: <bdda37a2-5151-409e-9df1-c0cbfc8a5093@gmail.com> (raw)
In-Reply-To: <D71TEJCQD9XK.5FNF9SJLFJ94@gmail.com>

On 14/01/2025 15:02, Javier Carrasco wrote:
> On Tue Jan 14, 2025 at 7:43 AM CET, Matti Vaittinen wrote:
> ...
>>> I will give you a simple example, so you can tell me where my reasoning
>>> fails:
>>>
>>> raw = 100 counts
>>> scale = 2.1504 lux/count (when IT=25ms and GAIN=1/8)
>>> processed = 215.04 lux (raw * scale, ABI compliant for IIO_LIGHT)
>>
>> Your reasoning does not fail. But, the scale = 1 / (N * total_gain),
>> right? (N here depends on how we choose the scale/gain values) Here,
>> the total_gain means the effect of both the hardware_gain and the
>> integration time.
>>
>> Hence,
>> processed =  X * (raw * scale)
>>
>> => processed = X * (raw * (1 / (N * total_gain))
>> => processed = X * raw / (N * total_gain);
>>
>> Hence I thought you might be able to get rid of this 64bit division by
>> using the total_gain from the iio_gts_get_total_gain() instead of
>> using the scale. Or, am I missing something?
>>
> 
> I am not sure by X you mean the maximum resolution, but if that is the
> case, the following would work (pseudo-code):

Yes. X denoted the value by which the count needs to be multiplied to 
get the lux (when total gain "in the terms of gts" is x1. I think in 
this particular case the "gain is x1" is a bit confusing as it appears 
this really means the hardware gain is 1/8, right?). Anyways, lux/count 
it is, so in short - yes. :)

> 
> /* Maximum resolution (2.1504 lux/count) * 10000 */
> #define VEML6030_MAX_RES 21504
> 
> total_gain = iio_gts_get_total_gain();
> processed_int = raw * VEML6030_MAX_RES / total_gain / 10000;

Yes. This is what I was thinking of.

> processed_micro = ((raw * VEML6030_MAX_RES / total_gain) % 10000) * 100;

gah. I didn't consider representing the micro portion. Staring this 
makes me feel dizzy :) Well, it looks correct, and I guess the precision 
is not lost by the division(?) But yes, you did perfectly get what I was 
after!

Jonathan, do you think I am just guiding Javier to make a mess? :)

If not, then this might be the way to go.

Yours,
	-- Matti

  reply	other threads:[~2025-01-14 14:26 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-07 20:50 [PATCH 0/2] iio: light: fix scale in veml6030 Javier Carrasco
2025-01-07 20:50 ` [PATCH 1/2] iio: light: veml6030: extend regmap to support regfields and caching Javier Carrasco
2025-01-12 13:18   ` Jonathan Cameron
2025-01-12 14:10     ` Javier Carrasco
2025-01-12 16:40       ` Jonathan Cameron
2025-01-07 20:50 ` [PATCH 2/2] iio: light: veml6030: fix scale to conform to ABI Javier Carrasco
2025-01-09 17:46   ` Javier Carrasco
2025-01-12 13:22   ` Jonathan Cameron
2025-01-13 11:56   ` Matti Vaittinen
2025-01-13 15:05     ` Javier Carrasco
2025-01-13 19:52       ` Matti Vaittinen
2025-01-13 22:32         ` Javier Carrasco
2025-01-14  6:43           ` Matti Vaittinen
2025-01-14 13:02             ` Javier Carrasco
2025-01-14 14:26               ` Matti Vaittinen [this message]
2025-01-18 12:16                 ` Jonathan Cameron
2025-01-13 10:25 ` [PATCH 0/2] iio: light: fix scale in veml6030 Matti Vaittinen
2025-01-13 11:02   ` Javier Carrasco

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bdda37a2-5151-409e-9df1-c0cbfc8a5093@gmail.com \
    --to=mazziesaccount@gmail.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=gupt21@gmail.com \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.