mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
Samus: Support capsense input as keyboard events.
This is experimental for now; the capsense chip simply reports its buttons as the number keys on the keyboard (1-8). BUG=chrome-os-partner:23382 BRANCH=samus,ToT TEST=manual To test, you'll need a reworked and correctly programmed capsense module. Boot the system, and switch to VT2. Touch the capsense bar and you'll see the input appear on the console as though you were typing numbers. Note that the capsense hardware is still buggy. Refer to the bug for workarounds. Change-Id: I4c3a8b70b8197ffd538c38c59c9336383365afa7 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/185434 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Dave Parker <dparker@chromium.org>
This commit is contained in:
committed by
chrome-internal-fetch
parent
5c808ee56c
commit
683beb8737
@@ -8,6 +8,7 @@
|
||||
#include "adc.h"
|
||||
#include "adc_chip.h"
|
||||
#include "backlight.h"
|
||||
#include "capsense.h"
|
||||
#include "common.h"
|
||||
#include "driver/temp_sensor/tmp006.h"
|
||||
#include "driver/als_isl29035.h"
|
||||
@@ -64,6 +65,8 @@ const struct gpio_info gpio_list[] = {
|
||||
switch_interrupt},
|
||||
{"PCH_BL_EN", LM4_GPIO_M, (1<<3), GPIO_INT_RISING,
|
||||
backlight_interrupt},
|
||||
{"CAPSENSE_INT_L", LM4_GPIO_N, (1<<0), GPIO_INT_FALLING,
|
||||
capsense_interrupt},
|
||||
|
||||
/* Other inputs */
|
||||
{"BOARD_VERSION1", LM4_GPIO_Q, (1<<5), GPIO_INPUT, NULL},
|
||||
@@ -76,8 +79,6 @@ const struct gpio_info gpio_list[] = {
|
||||
{"USB1_STATUS_L", LM4_GPIO_E, (1<<6), GPIO_INPUT, NULL},
|
||||
{"USB2_OC_L", LM4_GPIO_E, (1<<0), GPIO_INPUT, NULL},
|
||||
{"USB2_STATUS_L", LM4_GPIO_D, (1<<7), GPIO_INPUT, NULL},
|
||||
/* Not yet sure if this will need to be handled as an interrupt */
|
||||
{"CAPSENSE_INT_L", LM4_GPIO_N, (1<<0), GPIO_INPUT, NULL},
|
||||
|
||||
/* Outputs; all unasserted by default except for reset signals */
|
||||
{"CPU_PROCHOT", LM4_GPIO_B, (1<<1), GPIO_OUT_LOW, NULL},
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#define CONFIG_ALS
|
||||
#define CONFIG_ALS_ISL29035
|
||||
#define CONFIG_BOARD_VERSION
|
||||
#define CONFIG_CAPSENSE
|
||||
#define CONFIG_POWER_COMMON
|
||||
#define CONFIG_CHIPSET_CAN_THROTTLE
|
||||
#define CONFIG_KEYBOARD_BOARD_CONFIG
|
||||
@@ -92,6 +93,7 @@ enum gpio_signal {
|
||||
GPIO_RECOVERY_L, /* Recovery signal from servo */
|
||||
GPIO_WP_L, /* Write protect input */
|
||||
GPIO_PCH_BL_EN, /* PCH backlight input */
|
||||
GPIO_CAPSENSE_INT_L, /* Capsense interrupt */
|
||||
|
||||
/* Other inputs */
|
||||
GPIO_BOARD_VERSION1, /* Board version stuffing resistor 1 */
|
||||
@@ -104,7 +106,6 @@ enum gpio_signal {
|
||||
GPIO_USB1_STATUS_L, /* USB charger port 1 status output */
|
||||
GPIO_USB2_OC_L, /* USB port overcurrent warning */
|
||||
GPIO_USB2_STATUS_L, /* USB charger port 2 status output */
|
||||
GPIO_CAPSENSE_INT_L, /* Capsense interrupt (through EC_WAKE_L) */
|
||||
|
||||
/* Outputs */
|
||||
GPIO_CPU_PROCHOT, /* Force CPU to think it's overheated */
|
||||
|
||||
@@ -21,6 +21,7 @@ common-$(CONFIG_BACKLIGHT_LID)+=backlight_lid.o
|
||||
common-$(CONFIG_BATTERY_BQ27541)+=battery.o
|
||||
common-$(CONFIG_BATTERY_SMART)+=battery.o
|
||||
common-$(CONFIG_BUTTON_COUNT)+=button.o
|
||||
common-$(CONFIG_CAPSENSE)+=capsense.o
|
||||
common-$(CONFIG_CHARGER)+=charge_state.o charger.o
|
||||
# TODO(crosbug.com/p/23815): This is really the charge state machine
|
||||
# for ARM, not the charger driver for the tps65090. Rename.
|
||||
|
||||
86
common/capsense.c
Normal file
86
common/capsense.c
Normal file
@@ -0,0 +1,86 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "console.h"
|
||||
#include "gpio.h"
|
||||
#include "hooks.h"
|
||||
#include "i2c.h"
|
||||
#include "keyboard_protocol.h"
|
||||
#include "timer.h"
|
||||
|
||||
/* Console output macro */
|
||||
#define CPRINTF(format, args...) cprintf(CC_KEYBOARD, format, ## args)
|
||||
|
||||
#define CAPSENSE_I2C_ADDR 0x08
|
||||
#define CAPSENSE_MASK_BITS 8
|
||||
#define CAPSENSE_POLL_INTERVAL (20 * MSEC)
|
||||
|
||||
static int capsense_read_bitmask(void)
|
||||
{
|
||||
int rv;
|
||||
uint8_t val = 0;
|
||||
|
||||
i2c_lock(I2C_PORT_CAPSENSE, 1);
|
||||
rv = i2c_xfer(I2C_PORT_CAPSENSE, CAPSENSE_I2C_ADDR,
|
||||
0, 0, &val, 1, I2C_XFER_SINGLE);
|
||||
i2c_lock(I2C_PORT_CAPSENSE, 0);
|
||||
|
||||
if (rv)
|
||||
CPRINTF("[%T %s failed: error %d]\n", __func__, rv);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static void capsense_init(void)
|
||||
{
|
||||
gpio_enable_interrupt(GPIO_CAPSENSE_INT_L);
|
||||
}
|
||||
DECLARE_HOOK(HOOK_INIT, capsense_init, HOOK_PRIO_DEFAULT);
|
||||
|
||||
/*
|
||||
* Keep checking polling the capsense until all the buttons are released.
|
||||
* We're not worrying about debouncing, since the capsense module should do
|
||||
* that for us.
|
||||
*/
|
||||
static void capsense_change_deferred(void)
|
||||
{
|
||||
static uint8_t cur_val;
|
||||
uint8_t new_val;
|
||||
int i, n, c;
|
||||
|
||||
new_val = capsense_read_bitmask();
|
||||
if (new_val != cur_val) {
|
||||
CPRINTF("[%T capsense 0x%02x: ", new_val);
|
||||
for (i = 0; i < CAPSENSE_MASK_BITS; i++) {
|
||||
/* See what changed */
|
||||
n = (new_val >> i) & 0x01;
|
||||
c = (cur_val >> i) & 0x01;
|
||||
CPRINTF("%s", n ? " X " : " _ ");
|
||||
if (n == c)
|
||||
continue;
|
||||
#ifdef HAS_TASK_KEYPROTO
|
||||
/* Treat it as a keyboard event. */
|
||||
keyboard_update_button(i + KEYBOARD_BUTTON_CAPSENSE_1,
|
||||
n);
|
||||
#endif
|
||||
}
|
||||
CPRINTF("]\n");
|
||||
cur_val = new_val;
|
||||
}
|
||||
|
||||
if (cur_val)
|
||||
hook_call_deferred(capsense_change_deferred,
|
||||
CAPSENSE_POLL_INTERVAL);
|
||||
}
|
||||
DECLARE_DEFERRED(capsense_change_deferred);
|
||||
|
||||
/*
|
||||
* Somebody's poking at us.
|
||||
*/
|
||||
void capsense_interrupt(enum gpio_signal signal)
|
||||
{
|
||||
hook_call_deferred(capsense_change_deferred, 0);
|
||||
}
|
||||
@@ -192,9 +192,11 @@ static const uint16_t scancode_set2[KEYBOARD_ROWS][KEYBOARD_COLS] = {
|
||||
/* Button scancodes. Must be in the same order as defined in button_type */
|
||||
static const uint16_t button_scancodes[2][KEYBOARD_BUTTON_COUNT] = {
|
||||
/* Set 1 */
|
||||
{0xe05e, 0xe02e, 0xe030},
|
||||
{0xe05e, 0xe02e, 0xe030,
|
||||
0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009},
|
||||
/* Set 2 */
|
||||
{0xe037, 0xe021, 0xe032},
|
||||
{0xe037, 0xe021, 0xe032,
|
||||
0x0016, 0x001e, 0x0026, 0x0025, 0x002e, 0x0036, 0x003d, 0x003e},
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -17,6 +17,14 @@ enum keyboard_button_type {
|
||||
KEYBOARD_BUTTON_POWER = 0,
|
||||
KEYBOARD_BUTTON_VOLUME_DOWN,
|
||||
KEYBOARD_BUTTON_VOLUME_UP,
|
||||
KEYBOARD_BUTTON_CAPSENSE_1,
|
||||
KEYBOARD_BUTTON_CAPSENSE_2,
|
||||
KEYBOARD_BUTTON_CAPSENSE_3,
|
||||
KEYBOARD_BUTTON_CAPSENSE_4,
|
||||
KEYBOARD_BUTTON_CAPSENSE_5,
|
||||
KEYBOARD_BUTTON_CAPSENSE_6,
|
||||
KEYBOARD_BUTTON_CAPSENSE_7,
|
||||
KEYBOARD_BUTTON_CAPSENSE_8,
|
||||
|
||||
KEYBOARD_BUTTON_COUNT
|
||||
};
|
||||
|
||||
14
include/capsense.h
Normal file
14
include/capsense.h
Normal file
@@ -0,0 +1,14 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#ifndef __CROS_EC_CAPSENSE_H
|
||||
#define __CROS_EC_CAPSENSE_H
|
||||
|
||||
#include "common.h"
|
||||
#include "gpio.h"
|
||||
|
||||
void capsense_interrupt(enum gpio_signal signal);
|
||||
|
||||
#endif /* __CROS_EC_CAPSENSE_H */
|
||||
@@ -145,6 +145,11 @@
|
||||
*/
|
||||
#undef CONFIG_BUTTON_COUNT
|
||||
|
||||
/*
|
||||
* Capsense chip has buttons, too.
|
||||
*/
|
||||
#undef CONFIG_CAPSENSE
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Charger config */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user