Re: [PATCH] iio: humidity: hdc3020: add threshold events support

Dimitri Fedrau
2024-02-03T14:54:05Z

Am Sat, Feb 03, 2024 at 11:06:02AM +0100 schrieb Javier Carrasco:
> On 03.02.24 10:58, Christophe JAILLET wrote:
> > Le 03/02/2024 à 10:05, Dimitri Fedrau a écrit :
> >> [...]
> >> drivers/iio/humidity/hdc3020.c | 339 +++++++++++++++++++++++++++++++++
> >> 1 file changed, 339 insertions(+)
>
> ...
>
> >> + guard(mutex)(&data->lock);
> >> + switch (chan->type) {
> >> + case IIO_TEMP:
> >> + /*
> >> + * Store truncated temperature threshold into 9 LSBs while
> >> + * keeping the old humidity threshold in the 7 MSBs.
> >> + */
> >> + val = (((val + 45) * 65535 / 175) >> HDC3020_THRESH_TEMP_SHIFT);
> >
> > Why 175?
> > If the span is -40/+120, I guess it should be 160 and if it is -45/+120,
> > 165. No?
> >
> > Maybe something like:
> > #define MIN_TEMP -45 (or -40)
> > #define MAX_TEMP 120
> > in order to avoid hard coded constant?
> >
>
> the 45 and 175 values come from the conversion formula provided in the
> datasheet (page 13), even though the sensor range is from –40°C to 125°C.
>
Will add following constants:
#define MIN_TEMP -40
#define MAX_TEMP 125

It's the supported temperature range by the chip as Javier already
explained. Thanks for finding this.
> >> [...]

Best regards,
Dimitri