diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2015-08-25 18:52:19 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2015-08-29 01:34:14 -0700 |
commit | 4e7e1bb796190e658ea2de8d4e391efa59b0d643 (patch) | |
tree | c6927e9226f1853ce2602cc71d6399f7ad210860 /test/motion_lid.c | |
parent | 398bd9a0178c0120a2dbf3f58419d6a5360dfb3d (diff) | |
download | chrome-ec-4e7e1bb796190e658ea2de8d4e391efa59b0d643.tar.gz |
motion_sense: Add more complex EC/AP sensor rate support.
Add config settings for ODR and EC rate per requestor and
per power state (1 for the AP, 3 for the EC).
This way we can finely set ec rate and ODR depending on usage.
On chromeos, AP is not setting frequency, so EC sets for different power
state. On some platform, sensors can now be suspended in S3/S5.
Allow EC oversampling when AP is only looking for a few samples.
It is useful for double tap detection where high accelerator ODR is
required.
BRANCH=ryu
TEST=Tested on Ryu
BUG=chromium:513458
Change-Id: Ic3888a749699f07b10c5da3bc07204afd4de70da
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/295637
Diffstat (limited to 'test/motion_lid.c')
-rw-r--r-- | test/motion_lid.c | 93 |
1 files changed, 62 insertions, 31 deletions
diff --git a/test/motion_lid.c b/test/motion_lid.c index d204ec4ab0..964bd9f026 100644 --- a/test/motion_lid.c +++ b/test/motion_lid.c @@ -24,7 +24,7 @@ * Period in us for the motion task period. * The task will read the vectors at that interval */ -#define TEST_LID_EC_RATE (SUSPEND_SAMPLING_INTERVAL / 10) +#define TEST_LID_EC_RATE (10) /* * Time in ms to wait for the task to read the vectors. @@ -51,10 +51,9 @@ static int accel_set_range(const struct motion_sensor_t *s, return EC_SUCCESS; } -static int accel_get_range(const struct motion_sensor_t *s, - int * const range) +static int accel_get_range(const struct motion_sensor_t *s) { - return EC_SUCCESS; + return 0; } static int accel_set_resolution(const struct motion_sensor_t *s, @@ -64,23 +63,24 @@ static int accel_set_resolution(const struct motion_sensor_t *s, return EC_SUCCESS; } -static int accel_get_resolution(const struct motion_sensor_t *s, - int * const res) +static int accel_get_resolution(const struct motion_sensor_t *s) { - return EC_SUCCESS; + return 0; } +int test_data_rate[2] = { 0 }; + static int accel_set_data_rate(const struct motion_sensor_t *s, const int rate, const int rnd) { + test_data_rate[s - motion_sensors] = rate | (rnd ? ROUND_UP_FLAG : 0); return EC_SUCCESS; } -static int accel_get_data_rate(const struct motion_sensor_t *s, - int * const rate) +static int accel_get_data_rate(const struct motion_sensor_t *s) { - return EC_SUCCESS; + return test_data_rate[s - motion_sensors]; } const struct accelgyro_drv test_motion_sense = { @@ -117,11 +117,28 @@ struct motion_sensor_t motion_sensors[] = { .drv_data = NULL, .addr = 0, .rot_standard_ref = &base_standard_ref, - .default_config = { - .odr = 119000, - .range = 2, - .ec_rate = SUSPEND_SAMPLING_INTERVAL, - } + .default_range = 2, /* g, enough for laptop. */ + .config = { + /* AP: by default shutdown all sensors */ + [SENSOR_CONFIG_AP] = { + .odr = 0, + .ec_rate = 0, + }, + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 119000 | ROUND_UP_FLAG, + .ec_rate = TEST_LID_EC_RATE + }, + /* Used for double tap */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 119000 | ROUND_UP_FLAG, + .ec_rate = TEST_LID_EC_RATE * 100, + }, + [SENSOR_CONFIG_EC_S5] = { + .odr = 0, + .ec_rate = 0, + }, + }, }, {.name = "lid", .active_mask = SENSOR_ACTIVE_S0, @@ -133,11 +150,28 @@ struct motion_sensor_t motion_sensors[] = { .drv_data = NULL, .addr = 0, .rot_standard_ref = &lid_standard_ref, - .default_config = { - .odr = 119000, - .range = 2, - .ec_rate = SUSPEND_SAMPLING_INTERVAL, - } + .default_range = 2, /* g, enough for laptop. */ + .config = { + /* AP: by default shutdown all sensors */ + [SENSOR_CONFIG_AP] = { + .odr = 0, + .ec_rate = 0, + }, + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 119000 | ROUND_UP_FLAG, + .ec_rate = TEST_LID_EC_RATE, + }, + /* Used for double tap */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 119000 | ROUND_UP_FLAG, + .ec_rate = TEST_LID_EC_RATE * 100, + }, + [SENSOR_CONFIG_EC_S5] = { + .odr = 0, + .ec_rate = 0, + }, + }, }, }; const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); @@ -163,19 +197,16 @@ static int test_lid_angle(void) struct motion_sensor_t *lid = &motion_sensors[1]; /* Go to S3 state */ - TEST_ASSERT(accel_interval == SUSPEND_SAMPLING_INTERVAL); - TEST_ASSERT(motion_sensors[0].active == SENSOR_ACTIVE_S5); + TEST_ASSERT(sensor_active == SENSOR_ACTIVE_S5); + TEST_ASSERT(accel_get_data_rate(lid) == 0); + TEST_ASSERT(accel_interval == 0); /* Go to S0 state */ hook_notify(HOOK_CHIPSET_RESUME); - TEST_ASSERT(accel_interval == SUSPEND_SAMPLING_INTERVAL); - TEST_ASSERT(motion_sensors[0].active == SENSOR_ACTIVE_S0); - - motion_sense_set_accel_interval(base, TEST_LID_EC_RATE); - TEST_ASSERT(accel_interval == TEST_LID_EC_RATE); - - motion_sense_set_accel_interval(lid, TEST_LID_EC_RATE); - TEST_ASSERT(accel_interval == TEST_LID_EC_RATE); + msleep(1000); + TEST_ASSERT(sensor_active == SENSOR_ACTIVE_S0); + TEST_ASSERT(accel_get_data_rate(lid) == (119000 | ROUND_UP_FLAG)); + TEST_ASSERT(accel_interval == TEST_LID_EC_RATE * MSEC); /* * Set the base accelerometer as if it were sitting flat on a desk @@ -191,7 +222,7 @@ static int test_lid_angle(void) task_wake(TASK_ID_MOTIONSENSE); /* wait for the EC sampling period to expire */ - msleep(TEST_LID_EC_RATE/MSEC); + msleep(TEST_LID_EC_RATE); task_wake(TASK_ID_MOTIONSENSE); wait_for_valid_sample(); |