Files
OpenCellular/common/lid_angle.c
Alec Berg 242f195771 rambi: glimmer: Disable key scanning in suspend when lid is open
Added ability to disable the keyboard to wake from suspend when the lid
is outside a certain angle range. This has been added to glimmer by
defining CONFIG_LID_ANGLE_KEY_SCAN in its board.h.

Also modified the lid angle calculation to include a reliability
flag which can be used to tell when the hinge aligns too closely
with gravity and the lid angle value is unreliable.

BUG=none
BRANCH=rambi
TEST=Tested on a glimmer:

In S3, verified that when the lid is open past ~180 deg, the keyboard
does not wake the machine. Also verified that if you align hinge with
gravity, the keyboard enabled/disabled status remains the same (since
we can't actually trust the lid angle value).

Change-Id: I45b2c7c3c4bbcae61d3a0f8b5baa461ab8dabfb0
Original-Change-Id: If1a1592d259902d38941936961854b81b3a75b95
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/190061
Reviewed-on: https://chromium-review.googlesource.com/191612
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-03-27 18:44:14 +00:00

82 lines
2.3 KiB
C

/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* Lid angle module for Chrome EC */
#include "chipset.h"
#include "common.h"
#include "console.h"
#include "keyboard_scan.h"
#include "lid_angle.h"
#include "lid_switch.h"
#include "motion_sense.h"
/* Console output macros */
#define CPUTS(outstr) cputs(CC_LIDANGLE, outstr)
#define CPRINTF(format, args...) cprintf(CC_LIDANGLE, format, ## args)
/*
* Define the number of previous lid angle measurements to keep for determining
* whether to enable or disable key scanning. Note, that in order to change
* the state of key scanning, all stored measurements of the lid angle buffer
* must be in the specified range.
*/
#define KEY_SCAN_LID_ANGLE_BUFFER_SIZE 4
void lidangle_keyscan_update(float lid_ang)
{
static float lidangle_buffer[KEY_SCAN_LID_ANGLE_BUFFER_SIZE];
static int index;
int i;
int keys_accept = 1, keys_ignore = 1;
/* Record most recent lid angle in circular buffer. */
lidangle_buffer[index] = lid_ang;
index = (index == KEY_SCAN_LID_ANGLE_BUFFER_SIZE-1) ? 0 : index+1;
#ifdef CONFIG_LID_SWITCH
/*
* If lid is closed, don't need to check if keyboard scanning should
* be enabled.
*/
if (!lid_is_open())
return;
#endif
if (chipset_in_state(CHIPSET_STATE_SUSPEND)) {
for (i = 0; i < KEY_SCAN_LID_ANGLE_BUFFER_SIZE; i++) {
/*
* If any lid angle samples are unreliable, then
* don't change keyboard scanning state.
*/
if (lidangle_buffer[i] == LID_ANGLE_UNRELIABLE)
return;
/*
* Force all elements of the lid angle buffer to be
* in range of one of the conditions in order to change
* to the corresponding key scanning state.
*/
if (!LID_IN_RANGE_TO_ACCEPT_KEYS(lidangle_buffer[i]))
keys_accept = 0;
if (!LID_IN_RANGE_TO_IGNORE_KEYS(lidangle_buffer[i]))
keys_ignore = 0;
}
/* Enable or disable keyboard scanning if necessary. */
if (keys_accept && !keyboard_scan_is_enabled()) {
CPRINTF("[%T Enabling keyboard scan, lid ang at %d]\n",
(int)lidangle_buffer[index]);
keyboard_scan_enable(1);
} else if (keys_ignore && !keys_accept &&
keyboard_scan_is_enabled()) {
CPRINTF("[%T Disabling keyboard scan, lid ang at %d]\n",
(int)lidangle_buffer[index]);
keyboard_scan_enable(0);
}
}
}