summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2019-06-10 15:39:25 -0700
committerCommit Bot <commit-bot@chromium.org>2019-06-24 21:12:41 +0000
commit4f7f1b7fc6eec40094000e77e87f22f512f8321b (patch)
tree39163a5268377d0d414ab112aa2c406401669b54 /common
parentb1fa948170aa5b5441914797256db6fb04b4464c (diff)
downloadchrome-ec-4f7f1b7fc6eec40094000e77e87f22f512f8321b.tar.gz
fpsensor: Refactor fp_command_mode
This refactoring allows us to call fp_command_mode from the debug console commands and ensure that we're testing the same underlying code path that the host commands use. BRANCH=nocturne BUG=b:124773209 TEST="fpenroll" in hatch FP console "fpmatch" in hatch FP console "fpclear" in hatch FP console TEST=On nocturne: flash_fp_mcu ec.bin Enroll fingerprint via UI, lock/unlock, Remove fingerprint via UI Change-Id: I5e1e314c7f1d67dc663795cafe751545516e9f89 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1652285 Reviewed-by: Nicolas Norvez <norvez@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/fpsensor/fpsensor.c25
-rw-r--r--common/fpsensor/fpsensor_state.c31
2 files changed, 40 insertions, 16 deletions
diff --git a/common/fpsensor/fpsensor.c b/common/fpsensor/fpsensor.c
index f1b31e43c7..1e384e5a5f 100644
--- a/common/fpsensor/fpsensor.c
+++ b/common/fpsensor/fpsensor.c
@@ -593,12 +593,23 @@ static void upload_pgm_image(uint8_t *frame)
CPRINTF("\x04"); /* End Of Transmission */
}
-static int fp_console_action(uint32_t mode)
+static enum ec_error_list fp_console_action(uint32_t mode)
{
int tries = 200;
- ccprintf("Waiting for finger ...\n");
- sensor_mode = mode;
- task_set_event(TASK_ID_FPSENSOR, TASK_EVENT_UPDATE_CONFIG, 0);
+ uint32_t mode_output = 0;
+ int rc = 0;
+
+ CPRINTS("Waiting for finger ...");
+
+ rc = fp_set_sensor_mode(mode, &mode_output);
+
+ if (rc != EC_RES_SUCCESS) {
+ /*
+ * EC host command errors do not directly map to console command
+ * errors.
+ */
+ return EC_ERROR_UNKNOWN;
+ }
while (tries--) {
if (!(sensor_mode & FP_MODE_ANY_CAPTURE)) {
@@ -614,7 +625,7 @@ int command_fpcapture(int argc, char **argv)
{
int capture_type = FP_CAPTURE_SIMPLE_IMAGE;
uint32_t mode;
- int rc;
+ enum ec_error_list rc;
if (system_is_locked())
return EC_RES_ACCESS_DENIED;
@@ -639,7 +650,7 @@ DECLARE_CONSOLE_COMMAND(fpcapture, command_fpcapture, "", "");
int command_fpenroll(int argc, char **argv)
{
- int rc;
+ enum ec_error_list rc;
int percent = 0;
uint32_t event;
static const char * const enroll_str[] = {"OK", "Low Quality",
@@ -675,7 +686,7 @@ DECLARE_CONSOLE_COMMAND(fpenroll, command_fpenroll, "", "");
int command_fpmatch(int argc, char **argv)
{
- int rc = fp_console_action(FP_MODE_MATCH);
+ enum ec_error_list rc = fp_console_action(FP_MODE_MATCH);
uint32_t event = atomic_read_clear(&fp_events);
if (rc == EC_SUCCESS && event & EC_MKBP_FP_MATCH) {
diff --git a/common/fpsensor/fpsensor_state.c b/common/fpsensor/fpsensor_state.c
index 2b546191a3..9767ed71dc 100644
--- a/common/fpsensor/fpsensor_state.c
+++ b/common/fpsensor/fpsensor_state.c
@@ -139,27 +139,40 @@ static int validate_fp_mode(const uint32_t mode)
return EC_SUCCESS;
}
-static int fp_command_mode(struct host_cmd_handler_args *args)
+int fp_set_sensor_mode(uint32_t mode, uint32_t *mode_output)
{
- const struct ec_params_fp_mode *p = args->params;
- struct ec_response_fp_mode *r = args->response;
int ret;
- ret = validate_fp_mode(p->mode);
+ if (mode_output == NULL)
+ return EC_RES_INVALID_PARAM;
+
+ ret = validate_fp_mode(mode);
if (ret != EC_SUCCESS) {
- CPRINTS("Invalid FP mode 0x%x", p->mode);
+ CPRINTS("Invalid FP mode 0x%x", mode);
return EC_RES_INVALID_PARAM;
}
- if (!(p->mode & FP_MODE_DONT_CHANGE)) {
- sensor_mode = p->mode;
+ if (!(mode & FP_MODE_DONT_CHANGE)) {
+ sensor_mode = mode;
task_set_event(TASK_ID_FPSENSOR, TASK_EVENT_UPDATE_CONFIG, 0);
}
- r->mode = sensor_mode;
- args->response_size = sizeof(*r);
+ *mode_output = sensor_mode;
return EC_RES_SUCCESS;
}
+
+static int fp_command_mode(struct host_cmd_handler_args *args)
+{
+ const struct ec_params_fp_mode *p = args->params;
+ struct ec_response_fp_mode *r = args->response;
+
+ int ret = fp_set_sensor_mode(p->mode, &r->mode);
+
+ if (ret == EC_RES_SUCCESS)
+ args->response_size = sizeof(*r);
+
+ return ret;
+}
DECLARE_HOST_COMMAND(EC_CMD_FP_MODE, fp_command_mode, EC_VER_MASK(0));
static int fp_command_context(struct host_cmd_handler_args *args)