All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick DELAUNAY <patrick.delaunay@foss.st.com>
To: Marek Vasut <marex@denx.de>, <u-boot@lists.denx.de>
Cc: Fabrice Gasnier <fabrice.gasnier@foss.st.com>,
	Simon Glass <sjg@chromium.org>
Subject: Re: [PATCH] cmd: adc: Add support for storing ADC result in env variable
Date: Thu, 14 Apr 2022 18:44:26 +0200	[thread overview]
Message-ID: <f04aa2cb-62d0-468d-5766-b4e4821f71fa@foss.st.com> (raw)
In-Reply-To: <20220413021703.454385-1-marex@denx.de>

Hi Marek,

On 4/13/22 04:17, Marek Vasut wrote:
> Add the ability to start ADC conversion result in an environment

s/to start/to save/ ?

> variable. This is useful for further arbitrary processing by the
> U-Boot scripts.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
> Cc: Simon Glass <sjg@chromium.org>
> ---
>   cmd/adc.c | 13 ++++++++++++-
>   1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/cmd/adc.c b/cmd/adc.c
> index 75739bc8eed..4f548b811ec 100644
> --- a/cmd/adc.c
> +++ b/cmd/adc.c
> @@ -71,6 +71,7 @@ static int do_adc_info(struct cmd_tbl *cmdtp, int flag, int argc,
>   static int do_adc_single(struct cmd_tbl *cmdtp, int flag, int argc,
>   			 char *const argv[])
>   {
> +	char *varname = NULL;
>   	struct udevice *dev;
>   	unsigned int data;
>   	int ret, uV;
> @@ -78,6 +79,9 @@ static int do_adc_single(struct cmd_tbl *cmdtp, int flag, int argc,
>   	if (argc < 3)
>   		return CMD_RET_USAGE;
>   
> +	if (argc >= 3)
> +		varname = argv[2];
> +
>   	ret = adc_channel_single_shot(argv[1], simple_strtol(argv[2], NULL, 0),
>   				      &data);
>   	if (ret) {
> @@ -92,6 +96,13 @@ static int do_adc_single(struct cmd_tbl *cmdtp, int flag, int argc,
>   	else
>   		printf("%u\n", data);
>   
> +	if (varname) {
> +		if (!adc_raw_to_uV(dev, data, &uV))
> +			env_set_ulong(varname, uV);
> +		else
> +			env_set_ulong(varname, data);
> +	}
> +


Minor remark: no need to call 2 times adc_raw_to_uV()

conversion result can be saved in a local variable

+   ulong var_value;

     ret = uclass_get_device_by_name(UCLASS_ADC, argv[1], &dev);
     if (!ret && !adc_raw_to_uV(dev, data, &uV)) {
         printf("%u, %d uV\n", data, uV);
+        var_value = uV;
     } else {
         printf("%u\n", data);
+        var_value = data;
     }

+    if (varname)
+       env_set_ulong(varname, var_value);


>   	return CMD_RET_SUCCESS;
>   }
>   
> @@ -149,7 +160,7 @@ static int do_adc_scan(struct cmd_tbl *cmdtp, int flag, int argc,
>   static char adc_help_text[] =
>   	"list - list ADC devices\n"
>   	"adc info <name> - Get ADC device info\n"
> -	"adc single <name> <channel> - Get Single data of ADC device channel\n"
> +	"adc single <name> <channel> [varname] - Get Single data of ADC device channel\n"
>   	"adc scan <name> [channel mask] - Scan all [or masked] ADC channels";
>   
>   U_BOOT_CMD_WITH_SUBCMDS(adc, "ADC sub-system", adc_help_text,


Regards

Patrick


      reply	other threads:[~2022-04-14 16:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-13  2:17 [PATCH] cmd: adc: Add support for storing ADC result in env variable Marek Vasut
2022-04-14 16:44 ` Patrick DELAUNAY [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=f04aa2cb-62d0-468d-5766-b4e4821f71fa@foss.st.com \
    --to=patrick.delaunay@foss.st.com \
    --cc=fabrice.gasnier@foss.st.com \
    --cc=marex@denx.de \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.