[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aLbneKXFd7Nc711T@smile.fi.intel.com>
Date: Tue, 2 Sep 2025 15:47:52 +0300
From: Andy Shevchenko <andriy.shevchenko@...el.com>
To: dimitri.fedrau@...bherr.com
Cc: Javier Carrasco <javier.carrasco.cruz@...il.com>,
Li peiyu <579lpy@...il.com>, Jonathan Cameron <jic23@...nel.org>,
David Lechner <dlechner@...libre.com>,
Nuno Sá <nuno.sa@...log.com>,
Andy Shevchenko <andy@...nel.org>,
Dimitri Fedrau <dima.fedrau@...il.com>,
Jonathan Cameron <Jonathan.Cameron@...wei.com>,
linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org,
Chris Lesiak <chris.lesiak@...orbio.com>
Subject: Re: [PATCH v2 2/2] iio: humditiy: hdc3020: fix units for thresholds
and hysteresis
On Mon, Sep 01, 2025 at 07:51:59PM +0200, Dimitri Fedrau via B4 Relay wrote:
> From: Dimitri Fedrau <dimitri.fedrau@...bherr.com>
>
> According to the ABI the units after application of scale and offset are
> milli degree celsius for temperature thresholds and milli percent for
> relative humidity thresholds. Currently the resulting units are degree
> celsius for temperature thresholds and hysteresis and percent for relative
> humidity thresholds and hysteresis. Change scale factor to fix this issue.
...
> /*
> - * Get the temperature threshold from 9 LSBs, shift them to get
> - * the truncated temperature threshold representation and
> - * calculate the threshold according to the formula in the
> - * datasheet. Result is degree celsius scaled by 65535.
> + * Get the temperature threshold from 9 LSBs, shift them to get the
> + * truncated temperature threshold representation and calculate the
> + * threshold according to the formula in the datasheet and additionally
Replace "formula in the datasheet" by explicit formula
> + * scale by HDC3020_THRESH_FRACTION to avoid precision loss when
> + * calculating threshold and hysteresis values.
> */
> temp = FIELD_GET(HDC3020_THRESH_TEMP_MASK, thresh) <<
> HDC3020_THRESH_TEMP_TRUNC_SHIFT;
>
> - return -2949075 + (175 * temp);
> + return -589815 + (35 * temp);
TBH, I prefer to have the proper units be mentioned in the comment along with
return -2949075 / 5 + ((175 / 5) * temp);
5 itself can be a definition
#define ..._PRE_SCALE 5
and used everywhere.
...
> /*
> * Get the humidity threshold from 7 MSBs, shift them to get the
> * truncated humidity threshold representation and calculate the
> - * threshold according to the formula in the datasheet. Result is
> - * percent scaled by 65535.
> + * threshold according to the formula in the datasheet and additionally
> + * scale by HDC3020_THRESH_FRACTION to avoid precision loss when
> + * calculating threshold and hysteresis values.
> */
Ditto. "percent scaled by ..." is much better to understand.
> hum = FIELD_GET(HDC3020_THRESH_HUM_MASK, thresh) <<
> HDC3020_THRESH_HUM_TRUNC_SHIFT;
>
> - return hum * 100;
> + return hum * 20;
> }
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists