From: "Javier Carrasco" <javier.carrasco.cruz@gmail.com>
To: dimitri.fedrau@liebherr.com, "Li peiyu" <579lpy@gmail.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Dimitri Fedrau" <dima.fedrau@gmail.com>
Cc: "Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
<linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
"Chris Lesiak" <chris.lesiak@licorbio.com>
Subject: Re: [PATCH 2/2] iio: humditiy: hdc3020: fix units for thresholds and hysteresis
Date: Sun, 24 Aug 2025 20:36:58 +0800 [thread overview]
Message-ID: <DCANVO3ZBHUN.A8E9WABNLHG4@gmail.com> (raw)
In-Reply-To: <20250821-hdc3020-units-fix-v1-2-6ab0bc353c5e@liebherr.com>
Hello Dimitri, thank you for your patch. A few comments inline:
> From: Dimitri Fedrau <dimitri.fedrau@liebherr.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. Change scale factor to fix this issue.
I miss some explanation of what is going on (i.e. wrong) at the moment,
the scale factor that is being used and what results are being obtained.
> @@ -379,12 +379,12 @@ static int hdc3020_thresh_get_temp(u16 thresh)
> * 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
Having used 65535 back then without explaining why, or at least without using
a #define was not the best idea. It's difficult to understand why it is used
without getting into details.
13107 is even less obvious. I believe you divided 65535 by 5 everywhere in the
code, but it's not clear why.
I'd suggest a clear definition at the beginning of the code because it
is used in different parts of the code, after having explained why it
is necessary in the commit message as I mentioned before.
> - * datasheet. Result is degree celsius scaled by 65535.
> + * datasheet. Result is degree celsius scaled by 13107.
> */
> temp = FIELD_GET(HDC3020_THRESH_TEMP_MASK, thresh) <<
> HDC3020_THRESH_TEMP_TRUNC_SHIFT;
>
Again, it's difficult to understand why everything is divided by 5.
> - return -2949075 + (175 * temp);
> + return -589815 + (35 * temp);
> }
>
> static int hdc3020_thresh_get_hum(u16 thresh)
> @@ -395,12 +395,12 @@ static int hdc3020_thresh_get_hum(u16 thresh)
> * 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.
> + * percent scaled by 13107.
> */
> hum = FIELD_GET(HDC3020_THRESH_HUM_MASK, thresh) <<
> HDC3020_THRESH_HUM_TRUNC_SHIFT;
>
Similarly, multiplying by 20 (100/5) looks weird for a percentage.
> - return hum * 100;
> + return hum * 20;
> }
...
> @@ -630,7 +630,7 @@ static int hdc3020_read_thresh(struct iio_dev *indio_dev,
> thresh = hdc3020_thresh_get_temp(ret);
> switch (info) {
> case IIO_EV_INFO_VALUE:
MILLI, as suggested for [1/2]? The same would apply to the following
diffs.
> - *val = thresh;
> + *val = thresh * 1000;
> break;
> case IIO_EV_INFO_HYSTERESIS:
> ret = hdc3020_read_be16(data, reg_clr);
> @@ -638,18 +638,18 @@ static int hdc3020_read_thresh(struct iio_dev *indio_dev,
> return ret;
>
> clr = hdc3020_thresh_get_temp(ret);
Thanks and best regards,
Javier Carrasco
next prev parent reply other threads:[~2025-08-24 12:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-21 15:23 [PATCH 0/2] iio: humditiy: hdc3020: fix units Dimitri Fedrau via B4 Relay
2025-08-21 15:23 ` [PATCH 1/2] iio: humditiy: hdc3020: fix units for temperature and humidity measurement Dimitri Fedrau via B4 Relay
2025-08-21 15:44 ` Andy Shevchenko
2025-08-21 15:45 ` Andy Shevchenko
2025-08-22 12:36 ` Dimitri Fedrau
2025-08-21 15:23 ` [PATCH 2/2] iio: humditiy: hdc3020: fix units for thresholds and hysteresis Dimitri Fedrau via B4 Relay
2025-08-24 12:36 ` Javier Carrasco [this message]
2025-08-28 7:43 ` Dimitri Fedrau
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=DCANVO3ZBHUN.A8E9WABNLHG4@gmail.com \
--to=javier.carrasco.cruz@gmail.com \
--cc=579lpy@gmail.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=andy@kernel.org \
--cc=chris.lesiak@licorbio.com \
--cc=dima.fedrau@gmail.com \
--cc=dimitri.fedrau@liebherr.com \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®