linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dimitri Fedrau <dima.fedrau@gmail.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: dimitri.fedrau@liebherr.com,
	"Javier Carrasco" <javier.carrasco.cruz@gmail.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>,
	"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 v3 2/2] iio: humditiy: hdc3020: fix units for thresholds and hysteresis
Date: Wed, 15 Oct 2025 16:40:19 +0200	[thread overview]
Message-ID: <20251015144019.GA2207492@legfed1> (raw)
In-Reply-To: <CAHp75Vd6g_Nw0U_4NXEQZvLBCP49mXDrmxFj8yYqR7kW7festw@mail.gmail.com>

Am Wed, Oct 15, 2025 at 12:45:31PM +0300 schrieb Andy Shevchenko:
> On Mon, Oct 13, 2025 at 11:12 AM Dimitri Fedrau via B4 Relay
> <devnull+dimitri.fedrau.liebherr.com@kernel.org> wrote:
> >
> > 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.
> 
> ...
> 
> 
> > -       return -2949075 + (175 * temp);
> > +       return -589815 + (35 * temp);
> 
> I was under the impression that we agreed on the explicit division by 5.
> 
>   return -2949075 / 5 + (175 / 5 * temp);
>

I wanted to scale the formula as it has been done before, but didn't make
it really clear. After thinking about it again, I think you are right,
will add the explicit division by 5.

> ...
> 
> > -       return hum * 100;
> > +       return hum * 20;
> 
> And in a similar way here.
> 

Ok.

> 
> >                         s_clr = max(s_clr, HDC3020_MIN_TEMP_MICRO);
> >                         s_clr = min(s_clr, HDC3020_MAX_TEMP_MICRO);
> > @@ -565,7 +574,8 @@ static int hdc3020_write_thresh(struct iio_dev *indio_dev,
> >                         /* Calculate old hysteresis */
> >                         s_thresh = (s64)hdc3020_thresh_get_hum(thresh) * 1000000;
> >                         s_clr = (s64)hdc3020_thresh_get_hum(clr) * 1000000;
> > -                       s_hyst = div_s64(abs(s_thresh - s_clr), 65535);
> > +                       s_hyst = div_s64(abs(s_thresh - s_clr),
> > +                                        HDC3020_THRESH_FRACTION);
> >                         /* Set new threshold */
> >                         thresh = reg_val;
> >                         /* Try to set old hysteresis */
> > @@ -574,15 +584,16 @@ static int hdc3020_write_thresh(struct iio_dev *indio_dev,
> >                 case IIO_EV_INFO_HYSTERESIS:
> >                         /*
> >                          * Function hdc3020_thresh_get_hum returns relative
> > -                        * humidity in percent scaled by 65535. Scale by 1000000
> > -                        * to be able to subtract scaled hysteresis value.
> > +                        * humidity in percent scaled by HDC3020_THRESH_FRACTION.
> > +                        * Scale by 1000000 to be able to subtract scaled
> > +                        * hysteresis value.
> >                          */
> >                         s_thresh = (s64)hdc3020_thresh_get_hum(thresh) * 1000000;
> >                         /*
> > -                        * Units of s_val are in micro percent, scale by 65535
> > -                        * to get same units as s_thresh.
> > +                        * Units of s_val are in micro percent, scale by
> > +                        * HDC3020_THRESH_FRACTION to get same units as s_thresh.
> >                          */
> > -                       s_hyst = (s64)s_val * 65535;
> > +                       s_hyst = (s64)s_val * HDC3020_THRESH_FRACTION;
> >                         s_clr = hdc3020_thresh_clr(s_thresh, s_hyst, dir);
> >                         s_clr = max(s_clr, 0);
> >                         s_clr = min(s_clr, HDC3020_MAX_HUM_MICRO);
> > @@ -630,7 +641,7 @@ static int hdc3020_read_thresh(struct iio_dev *indio_dev,
> >                 thresh = hdc3020_thresh_get_temp(ret);
> >                 switch (info) {
> >                 case IIO_EV_INFO_VALUE:
> > -                       *val = thresh;
> > +                       *val = thresh * MILLI;
> >                         break;
> >                 case IIO_EV_INFO_HYSTERESIS:
> >                         ret = hdc3020_read_be16(data, reg_clr);
> > @@ -638,18 +649,18 @@ static int hdc3020_read_thresh(struct iio_dev *indio_dev,
> >                                 return ret;
> >
> >                         clr = hdc3020_thresh_get_temp(ret);
> > -                       *val = abs(thresh - clr);
> > +                       *val = abs(thresh - clr) * MILLI;
> >                         break;
> >                 default:
> >                         return -EOPNOTSUPP;
> >                 }
> > -               *val2 = 65535;
> > +               *val2 = HDC3020_THRESH_FRACTION;
> >                 return IIO_VAL_FRACTIONAL;
> >         case IIO_HUMIDITYRELATIVE:
> >                 thresh = hdc3020_thresh_get_hum(ret);
> >                 switch (info) {
> >                 case IIO_EV_INFO_VALUE:
> > -                       *val = thresh;
> > +                       *val = thresh * MILLI;
> >                         break;
> >                 case IIO_EV_INFO_HYSTERESIS:
> >                         ret = hdc3020_read_be16(data, reg_clr);
> > @@ -657,12 +668,12 @@ static int hdc3020_read_thresh(struct iio_dev *indio_dev,
> >                                 return ret;
> >
> >                         clr = hdc3020_thresh_get_hum(ret);
> > -                       *val = abs(thresh - clr);
> > +                       *val = abs(thresh - clr) * MILLI;
> >                         break;
> >                 default:
> >                         return -EOPNOTSUPP;
> >                 }
> > -               *val2 = 65535;
> > +               *val2 = HDC3020_THRESH_FRACTION;
> >                 return IIO_VAL_FRACTIONAL;
> >         default:
> >                 return -EOPNOTSUPP;
> >
> > --
> > 2.39.5
> >
> >
> 
>
Best regards,
Dimitri Fedrau

      reply	other threads:[~2025-10-15 14:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-13  8:12 [PATCH v3 0/2] iio: humditiy: hdc3020: fix units Dimitri Fedrau via B4 Relay
2025-10-13  8:12 ` [PATCH v3 1/2] iio: humditiy: hdc3020: fix units for temperature and humidity measurement Dimitri Fedrau via B4 Relay
2025-10-13  8:12 ` [PATCH v3 2/2] iio: humditiy: hdc3020: fix units for thresholds and hysteresis Dimitri Fedrau via B4 Relay
2025-10-15  8:29   ` Javier Carrasco
2025-10-15  9:45   ` Andy Shevchenko
2025-10-15 14:40     ` Dimitri Fedrau [this message]

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=20251015144019.GA2207492@legfed1 \
    --to=dima.fedrau@gmail.com \
    --cc=579lpy@gmail.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=andy@kernel.org \
    --cc=chris.lesiak@licorbio.com \
    --cc=dimitri.fedrau@liebherr.com \
    --cc=dlechner@baylibre.com \
    --cc=javier.carrasco.cruz@gmail.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;
as well as URLs for NNTP newsgroup(s).