mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: "Francesco Lavra" <flavra@baylibre.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 3/6] iio: tools: Add support for floating-point numbers in buffer scan elements
Date: Wed, 4 Mar 2026 16:53:50 -0600	[thread overview]
Message-ID: <c47ef538-7568-4e6a-9e39-a783bc0d6708@baylibre.com> (raw)
In-Reply-To: <20260304080650.2844401-1-flavra@baylibre.com>

On 3/4/26 2:06 AM, Francesco Lavra wrote:
> A subsequent commit will add floating-point support to the ABI; enhance
> the iio_generic_buffer tool to be able to parse this new data format.
> 
> Signed-off-by: Francesco Lavra <flavra@baylibre.com>
> ---
>  tools/iio/iio_generic_buffer.c | 56 +++++++++++++++++++++++++++++-----
>  tools/iio/iio_utils.c          |  8 ++---
>  tools/iio/iio_utils.h          |  4 +--
>  3 files changed, 55 insertions(+), 13 deletions(-)
> 
> diff --git a/tools/iio/iio_generic_buffer.c b/tools/iio/iio_generic_buffer.c
> index bc82bb6a7a2a..39c13b9ad20b 100644
> --- a/tools/iio/iio_generic_buffer.c
> +++ b/tools/iio/iio_generic_buffer.c
> @@ -89,7 +89,7 @@ static void print1byte(uint8_t input, struct iio_channel_info *info)
>  	 */
>  	input >>= info->shift;
>  	input &= info->mask;
> -	if (info->is_signed) {
> +	if (info->format == 's') {
>  		int8_t val = (int8_t)(input << (8 - info->bits_used)) >>
>  			     (8 - info->bits_used);
>  		printf("%05f ", ((float)val + info->offset) * info->scale);
> @@ -112,12 +112,26 @@ static void print2byte(uint16_t input, struct iio_channel_info *info)
>  	 */
>  	input >>= info->shift;
>  	input &= info->mask;
> -	if (info->is_signed) {
> +	switch (info->format) {
> +	case 's': {
>  		int16_t val = (int16_t)(input << (16 - info->bits_used)) >>
>  			      (16 - info->bits_used);
>  		printf("%05f ", ((float)val + info->offset) * info->scale);
> -	} else {
> +		break;
> +	}
> +	case 'u':
>  		printf("%05f ", ((float)input + info->offset) * info->scale);
> +		break;
> +	case 'f': {
> +		union {
> +			uint16_t u;
> +			__fp16 f;

Do we need to check for compiler support here since this data type might not
be supported on all targets?

Also wondering if _Float16 would be better than __fp16.

> +		} converter;
> +
> +		converter.u = input;
> +		printf("%05f ", ((float)converter.f + info->offset) * info->scale);
> +		break;
> +	}
>  	}
>  }
>  

...

> @@ -46,7 +46,7 @@ struct iio_channel_info {
>  	unsigned shift;
>  	uint64_t mask;
>  	unsigned be;
> -	unsigned is_signed;
> +	unsigned format;

char would be more natural.

>  	unsigned location;
>  };
>  


  reply	other threads:[~2026-03-04 22:53 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-04  8:05 [PATCH v7 0/6] imu: st_lsm6dsx: Add support for rotation sensor Francesco Lavra
2026-03-04  8:06 ` [PATCH v7 1/6] iio: imu: st_lsm6dsx: Fix check for invalid samples from FIFO Francesco Lavra
2026-03-07 12:46   ` Jonathan Cameron
2026-03-07 15:23     ` Lorenzo Bianconi
2026-03-07 17:04       ` Jonathan Cameron
2026-03-07 17:20         ` Lorenzo Bianconi
2026-03-04  8:06 ` [PATCH v7 2/6] iio: Replace 'sign' field with union in struct iio_scan_type Francesco Lavra
2026-03-04 22:55   ` David Lechner
2026-03-07 12:47     ` Jonathan Cameron
2026-03-07 13:10   ` Jonathan Cameron
2026-03-04  8:06 ` [PATCH v7 3/6] iio: tools: Add support for floating-point numbers in buffer scan elements Francesco Lavra
2026-03-04 22:53   ` David Lechner [this message]
2026-03-04  8:06 ` [PATCH v7 4/6] iio: ABI: " Francesco Lavra
2026-03-04 22:45   ` David Lechner
2026-03-05  9:09     ` Francesco Lavra
2026-03-05  9:23       ` Andy Shevchenko
2026-03-05 14:37         ` David Lechner
2026-03-06 12:09           ` Andy Shevchenko
2026-03-07 12:51             ` Jonathan Cameron
2026-03-17 10:40               ` Francesco Lavra
2026-03-04  8:07 ` [PATCH v7 5/6] iio: ABI: Add partial quaternion modifier Francesco Lavra
2026-03-04 11:51   ` Andy Shevchenko
2026-03-04 14:21     ` Francesco Lavra
2026-03-04 22:42       ` David Lechner
2026-03-05  8:50         ` Francesco Lavra
2026-03-05 14:40           ` David Lechner
2026-03-06 12:10             ` Andy Shevchenko
2026-03-04 19:25   ` kernel test robot
2026-03-04 22:35   ` David Lechner
2026-03-05  7:04     ` Andy Shevchenko
2026-03-07 13:00       ` Jonathan Cameron
2026-03-07 13:03     ` Jonathan Cameron
2026-03-08 20:27       ` Andy Shevchenko
2026-03-14 11:14         ` Jonathan Cameron
2026-03-07 13:05   ` Jonathan Cameron
2026-03-04  8:07 ` [PATCH v7 6/6] iio: imu: st_lsm6dsx: Add support for rotation sensor Francesco Lavra
2026-03-04 13:39   ` Andy Shevchenko

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=c47ef538-7568-4e6a-9e39-a783bc0d6708@baylibre.com \
    --to=dlechner@baylibre.com \
    --cc=andy@kernel.org \
    --cc=flavra@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®