mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
Samus: move gesture to common
Move gesture to common directory, 1st step to be reused by other board. Cleanup motion_sense shutdown path. BUG=chrome-os-partner:33102 TEST=Double tap still works on Samus BRANCH=ToT Change-Id: I0a3b38c4a7dbe95c27dcdebff04c1176aaf932d1 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/225235 Reviewed-by: Sheng-liang Song <ssl@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org>
This commit is contained in:
committed by
chrome-internal-fetch
parent
ac375d000e
commit
f3b29e3fec
@@ -182,6 +182,13 @@ enum board_version {
|
||||
/* Discharge battery when on AC power for factory test. */
|
||||
int board_discharge_on_ac(int enable);
|
||||
|
||||
/* Define for sensor tasks */
|
||||
#define CONFIG_SENSOR_BATTERY_TAP 0
|
||||
#define CONFIG_GESTURE_TAP_OUTER_WINDOW_T 200
|
||||
#define CONFIG_GESTURE_TAP_INNER_WINDOW_T 30
|
||||
#define CONFIG_GESTURE_TAP_MIN_INTERSTICE_T 120
|
||||
#define CONFIG_GESTURE_TAP_MAX_INTERSTICE_T 500
|
||||
|
||||
#endif /* !__ASSEMBLER__ */
|
||||
|
||||
#endif /* __BOARD_H */
|
||||
|
||||
@@ -9,4 +9,4 @@
|
||||
# the IC is TI Stellaris LM4
|
||||
CHIP:=lm4
|
||||
|
||||
board-y=board.o power_sequence.o panel.o extpower.o gesture.o
|
||||
board-y=board.o power_sequence.o panel.o extpower.o
|
||||
|
||||
@@ -84,4 +84,5 @@ common-$(HAS_TASK_PDCMD)+=host_command_master.o host_command_pd.o
|
||||
common-$(HAS_TASK_KEYSCAN)+=keyboard_scan.o
|
||||
common-$(HAS_TASK_LIGHTBAR)+=lb_common.o lightbar.o
|
||||
common-$(HAS_TASK_MOTIONSENSE)+=motion_sense.o math_util.o
|
||||
common-$(CONFIG_GESTURE_DETECTION)+=gesture.o
|
||||
common-$(TEST_BUILD)+=test_util.o
|
||||
|
||||
@@ -39,6 +39,7 @@ static const char * const channel_names[] = {
|
||||
"clock",
|
||||
"dma",
|
||||
"events",
|
||||
"gesture",
|
||||
"gpio",
|
||||
"hostcmd",
|
||||
"i2c",
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include "accelgyro.h"
|
||||
#include "common.h"
|
||||
#include "console.h"
|
||||
#include "hooks.h"
|
||||
#include "gesture.h"
|
||||
#include "lid_switch.h"
|
||||
#include "lightbar.h"
|
||||
#include "motion_sense.h"
|
||||
@@ -16,9 +18,9 @@
|
||||
#include "util.h"
|
||||
|
||||
/* Console output macros */
|
||||
#define CPUTS(outstr) cputs(CC_MOTION_SENSE, outstr)
|
||||
#define CPRINTS(format, args...) cprints(CC_MOTION_SENSE, format, ## args)
|
||||
#define CPRINTF(format, args...) cprintf(CC_MOTION_SENSE, format, ## args)
|
||||
#define CPUTS(outstr) cputs(CC_GESTURE, outstr)
|
||||
#define CPRINTS(format, args...) cprints(CC_GESTURE, format, ## args)
|
||||
#define CPRINTF(format, args...) cprintf(CC_GESTURE, format, ## args)
|
||||
|
||||
/* Output datarate for tap sensor (in milli-Hz) */
|
||||
#define TAP_ODR (1000000 / CONFIG_GESTURE_SAMPLING_INTERVAL_MS)
|
||||
@@ -39,10 +41,18 @@
|
||||
#define MIN_INTERSTICE_T 120
|
||||
#define MAX_INTERSTICE_T 500
|
||||
|
||||
#define OUTER_WINDOW (OUTER_WINDOW_T / CONFIG_GESTURE_SAMPLING_INTERVAL_MS)
|
||||
#define INNER_WINDOW (INNER_WINDOW_T / CONFIG_GESTURE_SAMPLING_INTERVAL_MS)
|
||||
#define MIN_INTERSTICE (MIN_INTERSTICE_T / CONFIG_GESTURE_SAMPLING_INTERVAL_MS)
|
||||
#define MAX_INTERSTICE (MAX_INTERSTICE_T / CONFIG_GESTURE_SAMPLING_INTERVAL_MS)
|
||||
#define OUTER_WINDOW \
|
||||
(CONFIG_GESTURE_TAP_OUTER_WINDOW_T / \
|
||||
CONFIG_GESTURE_SAMPLING_INTERVAL_MS)
|
||||
#define INNER_WINDOW \
|
||||
(CONFIG_GESTURE_TAP_INNER_WINDOW_T / \
|
||||
CONFIG_GESTURE_SAMPLING_INTERVAL_MS)
|
||||
#define MIN_INTERSTICE \
|
||||
(CONFIG_GESTURE_TAP_MIN_INTERSTICE_T / \
|
||||
CONFIG_GESTURE_SAMPLING_INTERVAL_MS)
|
||||
#define MAX_INTERSTICE \
|
||||
(CONFIG_GESTURE_TAP_MAX_INTERSTICE_T / \
|
||||
CONFIG_GESTURE_SAMPLING_INTERVAL_MS)
|
||||
#define MAX_WINDOW OUTER_WINDOW
|
||||
|
||||
/* State machine states for detecting double tap */
|
||||
@@ -63,7 +73,8 @@ enum tap_states {
|
||||
};
|
||||
|
||||
/* Tap sensor to use */
|
||||
static struct motion_sensor_t *sensor = &motion_sensors[0];
|
||||
static struct motion_sensor_t *sensor =
|
||||
&motion_sensors[CONFIG_SENSOR_BATTERY_TAP];
|
||||
|
||||
/* Tap state information */
|
||||
static int history_z[MAX_WINDOW]; /* Changes in Z */
|
||||
@@ -74,7 +85,6 @@ static int tap_debug;
|
||||
|
||||
/* Tap detection flag */
|
||||
static int tap_detection;
|
||||
static int saved_odr;
|
||||
|
||||
/*
|
||||
* TODO(crosbug.com/p/33102): Cleanup this function: break into multiple
|
||||
@@ -250,12 +260,12 @@ static int gesture_tap_for_battery(void)
|
||||
CPRINTS("tap st %d->%d, error div by 0",
|
||||
state_p, state);
|
||||
else
|
||||
CPRINTS("tap st %d->%d, st_cnt %-3d, Z_in:Z_out %-3d, "
|
||||
"Z_in:XY_in %-3d, dZ_in %-8.3d, "
|
||||
"dZ_in_max %-8.3d, dZ_out %-8.3d",
|
||||
state_p, state, state_cnt,
|
||||
CPRINTS("tap st %d->%d, st_cnt %-3d",
|
||||
state_p, state, state_cnt);
|
||||
CPRINTS("Z_in:Z_out %-3d, Z_in:XY_in %-3d",
|
||||
delta_z_inner / delta_z_outer,
|
||||
delta_z_inner / delta_xy_inner,
|
||||
delta_z_inner / delta_xy_inner);
|
||||
CPRINTS("dZ_in %-8.3d, dZ_in_max %-8.3d, dZ_out %-8.3d",
|
||||
delta_z_inner, delta_z_inner_max,
|
||||
delta_z_outer);
|
||||
}
|
||||
@@ -263,17 +273,17 @@ static int gesture_tap_for_battery(void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void gesture_chipset_resume(void)
|
||||
static void gesture_chipset_resume(void)
|
||||
{
|
||||
/* Restore ODR and disable tap detection */
|
||||
/* disable tap detection */
|
||||
tap_detection = 0;
|
||||
sensor->drv->set_data_rate(sensor, saved_odr, 1);
|
||||
}
|
||||
DECLARE_HOOK(HOOK_CHIPSET_RESUME, gesture_chipset_resume,
|
||||
GESTURE_HOOK_PRIO);
|
||||
|
||||
void gesture_chipset_suspend(void)
|
||||
static void gesture_chipset_suspend(void)
|
||||
{
|
||||
/* Record active ODR, set ODR to desired value */
|
||||
sensor->drv->get_data_rate(sensor, &saved_odr);
|
||||
/* Set ODR to desired value */
|
||||
sensor->drv->set_data_rate(sensor, TAP_ODR, 1);
|
||||
|
||||
/*
|
||||
@@ -285,12 +295,8 @@ void gesture_chipset_suspend(void)
|
||||
history_idx = 0;
|
||||
tap_detection = 1;
|
||||
}
|
||||
|
||||
void gesture_chipset_shutdown(void)
|
||||
{
|
||||
sensor->odr = TAP_ODR;
|
||||
saved_odr = sensor->default_odr;
|
||||
}
|
||||
DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, gesture_chipset_suspend,
|
||||
GESTURE_HOOK_PRIO);
|
||||
|
||||
void gesture_calc(void)
|
||||
{
|
||||
@@ -164,7 +164,7 @@ int motion_get_lid_angle(void)
|
||||
return (int)LID_ANGLE_UNRELIABLE;
|
||||
}
|
||||
|
||||
static void clock_chipset_shutdown(void)
|
||||
static void motion_sense_shutdown(void)
|
||||
{
|
||||
int i;
|
||||
struct motion_sensor_t *sensor;
|
||||
@@ -175,19 +175,16 @@ static void clock_chipset_shutdown(void)
|
||||
sensor->odr = sensor->default_odr;
|
||||
sensor->range = sensor->default_range;
|
||||
if ((sensor->state == SENSOR_INITIALIZED) &&
|
||||
!(sensor->active_mask & sensor->active))
|
||||
!(sensor->active_mask & sensor->active)) {
|
||||
sensor->drv->set_data_rate(sensor, 0, 0);
|
||||
sensor->state = SENSOR_NOT_INITIALIZED;
|
||||
sensor->state = SENSOR_NOT_INITIALIZED;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_GESTURE_DETECTION
|
||||
/* run gesture module hook which may override default behavior */
|
||||
gesture_chipset_shutdown();
|
||||
#endif
|
||||
}
|
||||
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, clock_chipset_shutdown, HOOK_PRIO_DEFAULT);
|
||||
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, motion_sense_shutdown,
|
||||
MOTION_SENSE_HOOK_PRIO);
|
||||
|
||||
static void clock_chipset_suspend(void)
|
||||
static void motion_sense_suspend(void)
|
||||
{
|
||||
int i;
|
||||
struct motion_sensor_t *sensor;
|
||||
@@ -200,20 +197,16 @@ static void clock_chipset_suspend(void)
|
||||
|
||||
/* Saving power if the sensor is not active in S3 */
|
||||
if ((sensor->state == SENSOR_INITIALIZED) &&
|
||||
!(sensor->active_mask & sensor->active)) {
|
||||
!(sensor->active_mask & sensor->active)) {
|
||||
sensor->drv->set_data_rate(sensor, 0, 0);
|
||||
sensor->state = SENSOR_NOT_INITIALIZED;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_GESTURE_DETECTION
|
||||
/* run gesture module hook which may override default behavior */
|
||||
gesture_chipset_suspend();
|
||||
#endif
|
||||
}
|
||||
DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, clock_chipset_suspend, HOOK_PRIO_DEFAULT);
|
||||
DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, motion_sense_suspend,
|
||||
MOTION_SENSE_HOOK_PRIO);
|
||||
|
||||
static void clock_chipset_resume(void)
|
||||
static void motion_sense_resume(void)
|
||||
{
|
||||
int i;
|
||||
struct motion_sensor_t *sensor;
|
||||
@@ -223,14 +216,14 @@ static void clock_chipset_resume(void)
|
||||
for (i = 0; i < motion_sensor_count; i++) {
|
||||
sensor = &motion_sensors[i];
|
||||
sensor->active = SENSOR_ACTIVE_S0;
|
||||
if (sensor->state == SENSOR_INITIALIZED) {
|
||||
/* Put back the odr previously set. */
|
||||
sensor->drv->set_data_rate(sensor, sensor->odr, 1);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_GESTURE_DETECTION
|
||||
/* run gesture module hook which may override default behavior */
|
||||
gesture_chipset_resume();
|
||||
#endif
|
||||
}
|
||||
DECLARE_HOOK(HOOK_CHIPSET_RESUME, clock_chipset_resume, HOOK_PRIO_DEFAULT);
|
||||
DECLARE_HOOK(HOOK_CHIPSET_RESUME, motion_sense_resume,
|
||||
MOTION_SENSE_HOOK_PRIO);
|
||||
|
||||
/* Write to LPC status byte to represent that accelerometers are present. */
|
||||
static inline void set_present(uint8_t *lpc_status)
|
||||
|
||||
@@ -539,11 +539,31 @@
|
||||
#undef CONFIG_FW_WP_RO_SIZE
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Motion sensor based gesture recognition */
|
||||
/* Motion sensor based gesture recognition information */
|
||||
#undef CONFIG_GESTURE_DETECTION
|
||||
|
||||
#ifndef CONFIG_GESTURE_DETECTION
|
||||
/* Which sensor to look for gesture recognition */
|
||||
#undef CONFIG_SENSOR_BATTERY_TAP
|
||||
/* Sensor sampling interval for gesture recognition */
|
||||
#undef CONFIG_GESTURE_SAMPLING_INTERVAL_MS
|
||||
/*
|
||||
* Double tap detection parameters
|
||||
* Double tap works by looking for two isolated Z-axis accelerometer impulses
|
||||
* preceded and followed by relatively calm periods of accelerometer motion.
|
||||
*
|
||||
* Define an outer and inner window. The inner window specifies how
|
||||
* long the tap impulse is expected to last. The outer window specifies the
|
||||
* period before the initial tap impluse and after the final tap impulse for
|
||||
* which to check for relatively calm periods. In between the two impulses
|
||||
* there is a minimum and maximum interstice time allowed.
|
||||
*/
|
||||
#undef CONFIG_GESTURE_TAP_OUTER_WINDOW_T
|
||||
#undef CONFIG_GESTURE_TAP_INNER_WINDOW_T
|
||||
#undef CONFIG_GESTURE_TAP_MIN_INTERSTICE_T
|
||||
#undef CONFIG_GESTURE_TAP_MAX_INTERSTICE_T
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -34,6 +34,7 @@ enum console_channel {
|
||||
CC_CLOCK,
|
||||
CC_DMA,
|
||||
CC_EVENTS,
|
||||
CC_GESTURE,
|
||||
CC_GPIO,
|
||||
CC_HOSTCMD,
|
||||
CC_I2C,
|
||||
|
||||
@@ -13,19 +13,7 @@
|
||||
*/
|
||||
void gesture_calc(void);
|
||||
|
||||
/**
|
||||
* Gesture hook to call on chipset resume.
|
||||
*/
|
||||
void gesture_chipset_resume(void);
|
||||
|
||||
/**
|
||||
* Gesture hook to call on chipset suspend.
|
||||
*/
|
||||
void gesture_chipset_suspend(void);
|
||||
|
||||
/**
|
||||
* Gesture hook to call on chipset shutdown.
|
||||
*/
|
||||
void gesture_chipset_shutdown(void);
|
||||
/* gesture hooks are triggered after the motion sense hooks. */
|
||||
#define GESTURE_HOOK_PRIO (MOTION_SENSE_HOOK_PRIO + 10)
|
||||
|
||||
#endif /* __CROS_EC_GESTURE_H */
|
||||
|
||||
@@ -131,4 +131,10 @@ struct motion_sensor_t {
|
||||
extern struct motion_sensor_t motion_sensors[];
|
||||
extern const unsigned int motion_sensor_count;
|
||||
|
||||
/*
|
||||
* Priority of the motion sense resume/suspend hooks, to be sure associated
|
||||
* hooks are scheduled properly.
|
||||
*/
|
||||
#define MOTION_SENSE_HOOK_PRIO (HOOK_PRIO_DEFAULT)
|
||||
|
||||
#endif /* __CROS_EC_MOTION_SENSE_H */
|
||||
|
||||
Reference in New Issue
Block a user