Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DA61DC433F5 for ; Thu, 14 Apr 2022 16:44:36 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B8B81837C9; Thu, 14 Apr 2022 18:44:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.b="xhA49cjc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9F54283AFF; Thu, 14 Apr 2022 18:44:33 +0200 (CEST) Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 53F4283826 for ; Thu, 14 Apr 2022 18:44:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=0103bed731=patrick.delaunay@foss.st.com Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 23ECerp1014778; Thu, 14 Apr 2022 18:44:28 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=selector1; bh=aX/Tnf6J45PAHptiszKoK+yqoQgVgq6OBAAxInyWQKg=; b=xhA49cjcmBdhrp1tcoJZqMFvcghm5gKDJbqbJRmvQTg+xPf/s3u/JS9ivH/SWQhaRjfg im7TP1TtUxj1ax4Q/+RLM40lJa/KpnKGz9RZfbTTpoMF/F3w2CvVLporeKmdYPvQ9l8R o4ZUK/aPS2ayB+IlvdFBE4vOHjoFJvO4BFZPZ47uSeQfedBgxdLCW22guRzNfrWGcgAT 7mBBXbY4loLLGyFtVUg4EpHmBw7rCQo8dJqSjV9EgNVvcAgiZ0qzXc8HwuRMpz/pKRaW ZVPa03J+Kr06LrJEe4NYD3iv654525t/PSN6ZynHgYoOegszxwlcBnboz+kCKIXFs/Al tQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3fb7gppfn5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Apr 2022 18:44:28 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 21C7A10002A; Thu, 14 Apr 2022 18:44:28 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 1C88F233000; Thu, 14 Apr 2022 18:44:28 +0200 (CEST) Received: from [10.48.0.213] (10.75.127.44) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Thu, 14 Apr 2022 18:44:27 +0200 Message-ID: Date: Thu, 14 Apr 2022 18:44:26 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH] cmd: adc: Add support for storing ADC result in env variable Content-Language: en-US To: Marek Vasut , CC: Fabrice Gasnier , Simon Glass References: <20220413021703.454385-1-marex@denx.de> From: Patrick DELAUNAY In-Reply-To: <20220413021703.454385-1-marex@denx.de> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_02,2022-02-23_01 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean 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 > Cc: Fabrice Gasnier > Cc: Simon Glass > --- > 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 - Get ADC device info\n" > - "adc single - Get Single data of ADC device channel\n" > + "adc single [varname] - Get Single data of ADC device channel\n" > "adc scan [channel mask] - Scan all [or masked] ADC channels"; > > U_BOOT_CMD_WITH_SUBCMDS(adc, "ADC sub-system", adc_help_text, Regards Patrick