Re: [PATCH] iio: humidity: am2315: fix negative temperature decoding
From: Vidhu Sarwal
Date: Mon Sep 28 2026 - 17:10:41 EST
Hi Andy,
On Mon, Sep 28, 2026 at 9:01 PM Andy Shevchenko
<andy.shevchenko@xxxxxxxxx> wrote:
> Can you use sign_extend32()?
I checked whether sign_extend32() can be used here, but I don't
think itcan be applied since as per datasheet [1], The temperature value
is sign-magnitude such that bit 15 is the sign and bits 14 to 0
contain the magnitude. For eg., 0x8065 represents -101.
sign_extend32(temp_raw, 15) would instead interpret 0x8065 as a
two's-complement value, giving us -32667.
So I think the sign bit needs to be decoded explicitly by masking
bit 15 and negating the magnitude when set.
[1] https://cdn-shop.adafruit.com/datasheets/AM2315.pdf
Regards,
Vidhu Sarwal