diff options
author | Vyacheslav Bocharov <adeep@lexina.in> | 2022-07-03 15:49:09 +0300 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2022-08-04 20:59:59 +0300 |
commit | 6ac4774426d687b5c365c79c9187e88f6c874878 (patch) | |
tree | 118a1fde61d446482ea93fb33c0b51d220f95c5d | |
parent | 11d30963bc19c400517c4edd83f83ca06775a05c (diff) | |
download | u-boot-6ac4774426d687b5c365c79c9187e88f6c874878.tar.xz |
cmd: fix do_adc_single()
The source code contains an error:
- argv[2] contains <channel> arg, variable for env_set is in argv[3]
- number of args is 4
Revert 54d24d72601321f4470c4edf31c6b29adae424a7
cmd: simplify do_adc_single()
Fixes 9de612ae4ded53f742f5f99929c06d0839471ced
cmd: adc: Add support for storing ADC result in env variable
Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r-- | cmd/adc.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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, val; @@ -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 >= 4) + varname = argv[3]; + ret = adc_channel_single_shot(argv[1], simple_strtol(argv[2], NULL, 0), &data); if (ret) { @@ -95,7 +99,8 @@ static int do_adc_single(struct cmd_tbl *cmdtp, int flag, int argc, printf("%u\n", data); } - env_set_ulong(argv[2], val); + if (varname) + env_set_ulong(varname, val); return CMD_RET_SUCCESS; } @@ -160,5 +165,5 @@ static char adc_help_text[] = U_BOOT_CMD_WITH_SUBCMDS(adc, "ADC sub-system", adc_help_text, U_BOOT_SUBCMD_MKENT(list, 1, 1, do_adc_list), U_BOOT_SUBCMD_MKENT(info, 2, 1, do_adc_info), - U_BOOT_SUBCMD_MKENT(single, 3, 1, do_adc_single), + U_BOOT_SUBCMD_MKENT(single, 4, 1, do_adc_single), U_BOOT_SUBCMD_MKENT(scan, 3, 1, do_adc_scan)); |