diff options
author | Nick Sanders <nsanders@chromium.org> | 2016-04-26 19:00:17 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-05-26 16:17:26 -0700 |
commit | 5cc3cac589d3e869266c18ed7e538a769496478f (patch) | |
tree | a95d179a6dbde223775a2a39c1482589c8b751a7 /common | |
parent | 4fa3b1e80c0ec46710e701da636da23ac1edefce (diff) | |
download | chrome-ec-5cc3cac589d3e869266c18ed7e538a769496478f.tar.gz |
servo_v4: Fix ADC console command
The console adc command prints adc values in the
order they appear in hardware, however they are lableled
in the order they are enumerated in board.h, which is not
necessarily the same.
This prints the correct name and value pairs, and removes
the adc_read_all_channels function which is not otherwise
used.
BUG=chromium:571476
BRANCH=None
TEST="adc" command associates correct values with names now.
Change-Id: I688641953d20082224b4120eaefe0d634ad4c74c
Signed-off-by: Nick Sanders <nsanders@google.com>
Reviewed-on: https://chromium-review.googlesource.com/340892
Commit-Ready: Nick Sanders <nsanders@chromium.org>
Tested-by: Nick Sanders <nsanders@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/adc.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/common/adc.c b/common/adc.c index 10e9399bdb..431a857de3 100644 --- a/common/adc.c +++ b/common/adc.c @@ -29,27 +29,34 @@ static enum adc_channel find_adc_channel_by_name(const char *name) return ADC_CH_COUNT; } +static int print_one_adc(int channel) +{ + int v; + + v = adc_read_channel(channel); + if (v == ADC_READ_ERROR) + return EC_ERROR_UNKNOWN; + ccprintf(" %s = %d\n", adc_channels[channel].name, v); + return EC_SUCCESS; +} + static int command_adc(int argc, char **argv) { - int i, v; - int data[ADC_CH_COUNT]; + int i, ret; /* If a channel is specified, read only that one */ if (argc == 2) { i = find_adc_channel_by_name(argv[1]); if (i == ADC_CH_COUNT) return EC_ERROR_PARAM1; - v = adc_read_channel(i); - if (v == ADC_READ_ERROR) - return EC_ERROR_UNKNOWN; - ccprintf(" %s = %d\n", adc_channels[i].name, v); - return EC_SUCCESS; + return print_one_adc(i); } else { /* Otherwise print them all */ - if (adc_read_all_channels(data)) - return EC_ERROR_UNKNOWN; - for (i = 0; i < ADC_CH_COUNT; ++i) - ccprintf(" %s = %d\n", adc_channels[i].name, data[i]); + for (i = 0; i < ADC_CH_COUNT; ++i) { + ret = print_one_adc(i); + if (ret) + return ret; + } return EC_SUCCESS; } } |