From 4e8120a3641d5ed8de5a53e08f2bb711e5516167 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Tue, 8 Sep 2015 09:56:44 -0700 Subject: [PATCH] common: motion: Add double tap gesture host interface Allow the host to enable/disable double tap. Send event when double tap is present. Also fix a bug when scanning for gestures. BRANCH=smaug BUG=chrome-os-partner:44754 TEST=compile. Check on Ryu. Change-Id: I50d008cd3823072ab1c1e2d21f1276cd2185d797 Signed-off-by: Gwendal Grignou Reviewed-on: https://chromium-review.googlesource.com/298683 --- common/motion_sense.c | 30 +++++++++++++++++++++--------- include/ec_commands.h | 1 + util/ectool.c | 3 +++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/common/motion_sense.c b/common/motion_sense.c index b825e6bb8b..54b00c5bd4 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -363,14 +363,14 @@ static void motion_sense_shutdown(void) #ifdef CONFIG_GESTURE_DETECTION_MASK mask = CONFIG_GESTURE_DETECTION_MASK; while (mask) { - i = 31 - __builtin_clz(mask); - mask &= (1 << mask); + i = get_next_bit(&mask); sensor = &motion_sensors[i]; sensor->drv->list_activities(sensor, &enabled, &disabled); + /* exclude double tap, it is used internally. */ + enabled &= ~(1 << MOTIONSENSE_ACTIVITY_DOUBLE_TAP); while (enabled) { - int activity = 31 - __builtin_clz(enabled); - enabled &= ~(1 << activity); + int activity = get_next_bit(&enabled); sensor->drv->manage_activity(sensor, activity, 0, NULL); } } @@ -612,6 +612,20 @@ void motion_sense_task(void) #endif #ifdef CONFIG_GESTURE_SENSOR_BATTERY_TAP if (event & CONFIG_GESTURE_TAP_EVENT) { +#ifdef CONFIG_ACCEL_FIFO + struct ec_response_motion_sensor_data vector; + + /* + * Send events to the FIFO + * AP is ignoring double tap event, do no wake up and no + * automatic disable. + */ + vector.flags = 0; + vector.activity = MOTIONSENSE_ACTIVITY_DOUBLE_TAP; + vector.state = 1; /* triggered */ + vector.sensor_num = MOTION_SENSE_ACTIVITY_SENSOR_ID; + motion_sense_fifo_add_unit(&vector, NULL, 0); +#endif CPRINTS("double tap!"); lightbar_sequence(LIGHTBAR_TAP); } @@ -622,7 +636,6 @@ void motion_sense_task(void) #ifdef CONFIG_ACCEL_FIFO struct ec_response_motion_sensor_data vector; - CPRINTS("significant motion"); /* Send events to the FIFO */ vector.flags = MOTIONSENSE_SENSOR_FLAG_WAKEUP; vector.activity = MOTIONSENSE_ACTIVITY_SIG_MOTION; @@ -630,6 +643,7 @@ void motion_sense_task(void) vector.sensor_num = MOTION_SENSE_ACTIVITY_SENSOR_ID; motion_sense_fifo_add_unit(&vector, NULL, 0); #endif + CPRINTS("significant motion"); /* Disable further detection */ activity_sensor = &motion_sensors[CONFIG_GESTURE_SIGMO]; activity_sensor->drv->manage_activity( @@ -1022,8 +1036,7 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args) ret = EC_RES_SUCCESS; mask = CONFIG_GESTURE_DETECTION_MASK; while (mask && ret == EC_RES_SUCCESS) { - i = 31 - __builtin_clz(mask); - mask &= (1 << mask); + i = get_next_bit(&mask); sensor = &motion_sensors[i]; ret = sensor->drv->list_activities(sensor, &enabled, &disabled); @@ -1044,8 +1057,7 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args) return EC_RES_INVALID_PARAM; mask = CONFIG_GESTURE_DETECTION_MASK; while (mask && ret == EC_RES_SUCCESS) { - i = 31 - __builtin_clz(mask); - mask &= (1 << mask); + i = get_next_bit(&mask); sensor = &motion_sensors[i]; sensor->drv->list_activities(sensor, &enabled, &disabled); diff --git a/include/ec_commands.h b/include/ec_commands.h index 3dd3e7c93a..ddf47d4fc7 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -1788,6 +1788,7 @@ struct ec_response_motion_sense_fifo_data { enum motionsensor_activity { MOTIONSENSE_ACTIVITY_RESERVED = 0, MOTIONSENSE_ACTIVITY_SIG_MOTION = 1, + MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2, }; struct ec_motion_sense_activity { diff --git a/util/ectool.c b/util/ectool.c index dd419ceb3b..0617559220 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -3271,6 +3271,9 @@ static void motionsense_display_activities(uint32_t activities) if (activities & (1 << MOTIONSENSE_ACTIVITY_SIG_MOTION)) printf("%d: Significant motion\n", MOTIONSENSE_ACTIVITY_SIG_MOTION); + if (activities & (1 << MOTIONSENSE_ACTIVITY_DOUBLE_TAP)) + printf("%d: Double tap\n", + MOTIONSENSE_ACTIVITY_DOUBLE_TAP); } static int cmd_motionsense(int argc, char **argv)