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>
This commit is contained in:
Gwendal Grignou
2015-09-01 15:25:01 -07:00
committed by chrome-bot
parent 3788806149
commit bde89ebc20
8 changed files with 30 additions and 22 deletions

View File

@@ -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

View File

@@ -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;
}
/*****************************************************************************/

View File

@@ -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
/*

View File

@@ -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);

View File

@@ -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);

View File

@@ -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
/**

View File

@@ -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

View File

@@ -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)