summaryrefslogtreecommitdiff
path: root/common/motion_sense.c
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2014-04-08 10:28:29 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-04-10 00:10:07 +0000
commit0abb7a45d973a5d612d901726588db78e4679720 (patch)
tree0f2e1c72f7b8699fafdda85c3068dd39e4283b9d /common/motion_sense.c
parentda755350cfddfc0483cb4d95d5899027f70c5436 (diff)
downloadchrome-ec-0abb7a45d973a5d612d901726588db78e4679720.tar.gz
accel: Add host cmd for setting lid angle threshold for disabling keyboard wake
Added a sub-command to the motionsense host command (0x2b) for getting/setting the lid angle at which the keyboard is disabled as a wake source in S3. The value can be anywhere from 0 to 360 degrees, default set to 180. Note, this only takes affect for boards that have CONFIG_LID_ANGLE_KEY_SCAN defined. Modified ectool motionsense command to use new host sub-command. Also modified the lid angle measurement in the EC to be in the range [0, 360], instead of [-180, 180], and changed casting of lid angle as an int to round to nearest. BUG=none BRANCH=rambi TEST=Tested on a glimmer: Using default keyboard disable lid angle of 180, made sure that when lid angle is past 180, key presses do not wake system, and when lid angle is less than 180, key presses do wake up system. Used ectool motionsense kb_wake to set the keyboard disable lid angle to 0. Made sure that keyboard never wakes up the system. Set keyboard disable lid angle to 360 and made sure that the keyboard always wakes up the system. Change-Id: I437164c6e38c29169ef6e20e86c9cf2a1c78f86e Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/193663 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'common/motion_sense.c')
-rw-r--r--common/motion_sense.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 1fb158b7c9..d48b578cd1 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -133,6 +133,10 @@ static int calculate_lid_angle(vector_3_t base, vector_3_t lid,
if (ang_lid_270 > ang_lid_90)
ang_lid_to_base = -ang_lid_to_base;
+ /* Place lid angle between 0 and 360 degrees. */
+ if (ang_lid_to_base < 0)
+ ang_lid_to_base += 360;
+
*lid_angle = ang_lid_to_base;
return reliable;
}
@@ -140,7 +144,11 @@ static int calculate_lid_angle(vector_3_t base, vector_3_t lid,
int motion_get_lid_angle(void)
{
if (lid_angle_is_reliable)
- return (int)lid_angle_deg;
+ /*
+ * Round to nearest int by adding 0.5. Note, only works because
+ * lid angle is known to be positive.
+ */
+ return (int)(lid_angle_deg + 0.5F);
else
return (int)LID_ANGLE_UNRELIABLE;
}
@@ -253,7 +261,11 @@ void motion_sense_task(void)
/*
* Copy sensor data to shared memory. Note that this code
- * assumes little endian, which is what the host expects.
+ * assumes little endian, which is what the host expects. Also,
+ * note that we share the lid angle calculation with host only
+ * for debugging purposes. The EC lid angle is an approximation
+ * with un-calibrated accels. The AP calculates a separate,
+ * more accurate lid angle.
*/
lpc_data[0] = motion_get_lid_angle();
lpc_data[1] = acc_base_host[X];
@@ -467,6 +479,20 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
args->response_size = sizeof(out->sensor_range);
break;
+ case MOTIONSENSE_CMD_KB_WAKE_ANGLE:
+#ifdef CONFIG_LID_ANGLE_KEY_SCAN
+ /* Set new keyboard wake lid angle if data arg has value. */
+ if (in->kb_wake_angle.data != EC_MOTION_SENSE_NO_VALUE)
+ lid_angle_set_kb_wake_angle(in->kb_wake_angle.data);
+
+ out->kb_wake_angle.ret = lid_angle_get_kb_wake_angle();
+#else
+ out->kb_wake_angle.ret = 0;
+#endif
+ args->response_size = sizeof(out->kb_wake_angle);
+
+ break;
+
default:
CPRINTF("[%T MS bad cmd 0x%x]\n", in->cmd);
return EC_RES_INVALID_PARAM;