[PATCH] cmd: adc: Add support for storing ADC result in env variable
Marek Vasut
marex at denx.de
Wed Apr 13 04:17:03 CEST 2022
Add the ability to start ADC conversion result in an environment
variable. This is useful for further arbitrary processing by the
U-Boot scripts.
Signed-off-by: Marek Vasut <marex at denx.de>
Cc: Fabrice Gasnier <fabrice.gasnier at foss.st.com>
Cc: Simon Glass <sjg at 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);
+ }
+
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,
--
2.35.1
More information about the U-Boot
mailing list