diff options
author | Aseda Aboagye <aaboagye@google.com> | 2018-08-17 10:36:44 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-08-17 20:39:05 -0700 |
commit | 6bc276f40d3ec84de7dd5dfeeef25487eabc8ab2 (patch) | |
tree | a32942ad4a0c46e0c74e3fcc4b755edbe45fc718 /common/adc.c | |
parent | 13e92a73c57d83eef08f6cf496e63a6f63f550d4 (diff) | |
download | chrome-ec-6bc276f40d3ec84de7dd5dfeeef25487eabc8ab2.tar.gz |
adc: Add ectool command for reading ADC channels.
BUG=b:76155036, b:112757066
BRANCH=None
TEST=Flash nocturne; update ectool; verify that `ectool adcread <ch>`
works as expected.
Change-Id: I42545d25f005a7eb9e0af54c8b5cb72d5d844084
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1180095
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Edward Hill <ecgh@chromium.org>
Diffstat (limited to 'common/adc.c')
-rw-r--r-- | common/adc.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/common/adc.c b/common/adc.c index 6375291a85..bbee4ce207 100644 --- a/common/adc.c +++ b/common/adc.c @@ -9,6 +9,8 @@ #include "adc_chip.h" #include "common.h" #include "console.h" +#include "ec_commands.h" +#include "host_command.h" #include "util.h" /* 'adc' console command is not supported in continuous mode */ @@ -63,4 +65,24 @@ static int command_adc(int argc, char **argv) DECLARE_CONSOLE_COMMAND(adc, command_adc, "[name]", "Print ADC channel(s)"); -#endif + +static int hc_adc_read(struct host_cmd_handler_args *args) +{ + const struct ec_params_adc_read *params = args->params; + struct ec_response_adc_read *resp = args->response; + enum adc_channel ch = (enum adc_channel)params->adc_channel; + int32_t adc_value; + + if (ch >= ADC_CH_COUNT) + return EC_RES_INVALID_PARAM; + + adc_value = adc_read_channel(ch); + if (adc_value == ADC_READ_ERROR) + return EC_RES_ERROR; + + resp->adc_value = adc_value; + args->response_size = sizeof(*resp); + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_ADC_READ, hc_adc_read, EC_VER_MASK(0)); +#endif /* CONFIG_ADC_PROFILE_FAST_CONTINUOUS */ |