diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2015-09-01 15:25:01 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2015-09-18 17:55:32 -0700 |
commit | bde89ebc203d9d15ede2cefb3eea8511d1fc3b65 (patch) | |
tree | e6b039f3f45ace4086e3f9ed99b0344a3437a7f1 | |
parent | 3788806149da2732b00e31316c7996b96ad60e01 (diff) | |
download | chrome-ec-bde89ebc203d9d15ede2cefb3eea8511d1fc3b65.tar.gz |
common: motion: move gesture actions in motion task.
Change the IRQ interface to allow adding events.
Move code to send the lightbar sequence from gesture.c to motion task.
TEST=compile, works on Ryu.
BRANCH=smaug
BUG=chrome-os-partner:44754
Change-Id: I981ea123ebef0e8e3d6aa320eade89f10e83b6fc
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/296822
Reviewed-by: Alec Berg <alecaberg@chromium.org>
-rw-r--r-- | board/samus/board.h | 2 | ||||
-rw-r--r-- | common/gesture.c | 11 | ||||
-rw-r--r-- | common/motion_sense.c | 19 | ||||
-rw-r--r-- | driver/accelgyro_bmi160.c | 4 | ||||
-rw-r--r-- | driver/als_si114x.c | 4 | ||||
-rw-r--r-- | include/accelgyro.h | 4 | ||||
-rw-r--r-- | include/config.h | 4 | ||||
-rw-r--r-- | include/gesture.h | 4 |
8 files changed, 30 insertions, 22 deletions
diff --git a/board/samus/board.h b/board/samus/board.h index a2aa81e410..d7fba7588f 100644 --- a/board/samus/board.h +++ b/board/samus/board.h @@ -209,6 +209,8 @@ void set_pp5000_in_g3(int mask, int enable); #define CONFIG_GESTURE_TAP_INNER_WINDOW_T 30 #define CONFIG_GESTURE_TAP_MIN_INTERSTICE_T 120 #define CONFIG_GESTURE_TAP_MAX_INTERSTICE_T 500 +/* event 2 to 9 are reserved for hardware interrupt */ +#define CONFIG_GESTURE_TAP_EVENT TASK_EVENT_CUSTOM(1024) #define CONFIG_LID_ANGLE_SENSOR_BASE 0 #define CONFIG_LID_ANGLE_SENSOR_LID 1 diff --git a/common/gesture.c b/common/gesture.c index b1858ba311..278e74e980 100644 --- a/common/gesture.c +++ b/common/gesture.c @@ -292,19 +292,14 @@ static void gesture_chipset_suspend(void) DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, gesture_chipset_suspend, GESTURE_HOOK_PRIO); -void gesture_calc(void) +void gesture_calc(uint32_t *event) { /* Only check for gesture if lid is closed and tap detection is on */ if (!tap_detection || lid_is_open()) return; - if (gesture_tap_for_battery()) { - CPRINTS("Double Tap!"); - lightbar_sequence(LIGHTBAR_TAP); - - /* Don't need to run motion sense task for a while */ - task_wait_event(500 * MSEC); - } + if (gesture_tap_for_battery()) + *event |= CONFIG_GESTURE_TAP_EVENT; } /*****************************************************************************/ diff --git a/common/motion_sense.c b/common/motion_sense.c index 737a7b35ac..fcc28b467d 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -15,6 +15,7 @@ #include "host_command.h" #include "hwtimer.h" #include "lid_angle.h" +#include "lightbar.h" #include "math_util.h" #include "mkbp_event.h" #include "motion_sense.h" @@ -459,14 +460,14 @@ static int motion_sense_read(struct motion_sensor_t *sensor) } static int motion_sense_process(struct motion_sensor_t *sensor, - uint32_t event, + uint32_t *event, const timestamp_t *ts, int *flush_needed) { int ret = EC_SUCCESS; #ifdef CONFIG_ACCEL_INTERRUPTS - if ((event & TASK_EVENT_MOTION_INTERRUPT_MASK) && + if ((*event & TASK_EVENT_MOTION_INTERRUPT_MASK) && (sensor->drv->irq_handler != NULL)) { sensor->drv->irq_handler(sensor, event); sensor->last_collection = ts->le.lo; @@ -490,7 +491,7 @@ static int motion_sense_process(struct motion_sensor_t *sensor, } else { ret = EC_ERROR_BUSY; } - if (event & TASK_EVENT_MOTION_FLUSH_PENDING) { + if (*event & TASK_EVENT_MOTION_FLUSH_PENDING) { int flush_pending; flush_pending = atomic_read_clear(&sensor->flush_pending); for (; flush_pending > 0; flush_pending--) { @@ -564,7 +565,7 @@ void motion_sense_task(void) } ts_begin_task = get_time(); - ret = motion_sense_process(sensor, event, + ret = motion_sense_process(sensor, &event, &ts_begin_task, &fifo_flush_needed); if (ret != EC_SUCCESS) @@ -573,9 +574,17 @@ void motion_sense_task(void) } } +#ifdef CONFIG_GESTURE_DETECTION #ifdef CONFIG_GESTURE_SW_DETECTION /* Run gesture recognition engine */ - gesture_calc(); + gesture_calc(&event); +#endif +#ifdef CONFIG_GESTURE_SENSOR_BATTERY_TAP + if (event & CONFIG_GESTURE_TAP_EVENT) { + CPRINTS("double tap!"); + lightbar_sequence(LIGHTBAR_TAP); + } +#endif #endif #ifdef CONFIG_LID_ANGLE /* diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c index b4cfaf43d9..a229eecc79 100644 --- a/driver/accelgyro_bmi160.c +++ b/driver/accelgyro_bmi160.c @@ -697,12 +697,12 @@ static int config_interrupt(const struct motion_sensor_t *s) * For now, we just print out. We should set a bitmask motion sense code will * act upon. */ -static int irq_handler(struct motion_sensor_t *s, uint32_t event) +static int irq_handler(struct motion_sensor_t *s, uint32_t *event) { int interrupt; if ((s->type != MOTIONSENSE_TYPE_ACCEL) || - (!(event & CONFIG_ACCELGYRO_BMI160_INT_EVENT))) + (!(*event & CONFIG_ACCELGYRO_BMI160_INT_EVENT))) return EC_SUCCESS; raw_read32(s->addr, BMI160_INT_STATUS_0, &interrupt); diff --git a/driver/als_si114x.c b/driver/als_si114x.c index 3eeab5af6a..a993f4b99e 100644 --- a/driver/als_si114x.c +++ b/driver/als_si114x.c @@ -147,13 +147,13 @@ void si114x_interrupt(enum gpio_signal signal) * For now, we just print out. We should set a bitmask motion sense code will * act upon. */ -static int irq_handler(struct motion_sensor_t *s, uint32_t event) +static int irq_handler(struct motion_sensor_t *s, uint32_t *event) { int ret = EC_SUCCESS, val; struct si114x_drv_data_t *data = SI114X_GET_DATA(s); struct si114x_typed_data_t *type_data = SI114X_GET_TYPED_DATA(s); - if (!(event & CONFIG_ALS_SI114X_INT_EVENT)) + if (!(*event & CONFIG_ALS_SI114X_INT_EVENT)) return EC_SUCCESS; ret = raw_read8(s->addr, SI114X_REG_IRQ_STATUS, &val); diff --git a/include/accelgyro.h b/include/accelgyro.h index 46ab68d855..756c2e0e9d 100644 --- a/include/accelgyro.h +++ b/include/accelgyro.h @@ -104,9 +104,9 @@ struct accelgyro_drv { * handler for interrupts triggered by the sensor: it runs in task and * process the events that triggered an interrupt. * @s Pointer to sensor data. - * @event Event to process. + * @event Event to process. May add add other events for the next processor. */ - int (*irq_handler)(struct motion_sensor_t *s, uint32_t event); + int (*irq_handler)(struct motion_sensor_t *s, uint32_t *event); #endif #ifdef CONFIG_ACCEL_FIFO /** diff --git a/include/config.h b/include/config.h index df07c873e3..e0be139ba9 100644 --- a/include/config.h +++ b/include/config.h @@ -836,7 +836,7 @@ /* Sensor sampling interval for gesture recognition */ #undef CONFIG_GESTURE_SAMPLING_INTERVAL_MS -/* Which sensor to look for gesture recognition */ +/* Which sensor to look for battery tap recognition */ #undef CONFIG_GESTURE_SENSOR_BATTERY_TAP /* @@ -858,6 +858,8 @@ #undef CONFIG_GESTURE_TAP_MAX_INTERSTICE_T #undef CONFIG_GESTURE_TAP_THRES_MG +/* Event generated when battery tap is detected */ +#undef CONFIG_GESTURE_TAP_EVENT /* Do we want to detect the lid angle? */ #undef CONFIG_LID_ANGLE diff --git a/include/gesture.h b/include/gesture.h index d98dc8cdf8..d480794758 100644 --- a/include/gesture.h +++ b/include/gesture.h @@ -9,9 +9,9 @@ #define __CROS_EC_GESTURE_H /** - * Run gesture detection engine. + * Run gesture detection engine. Modify the event flag when gestures are found. */ -void gesture_calc(void); +void gesture_calc(uint32_t *event); /* gesture hooks are triggered after the motion sense hooks. */ #define GESTURE_HOOK_PRIO (MOTION_SENSE_HOOK_PRIO + 10) |