mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-29 18:11:05 +00:00
Our code base contains a lot of debug messages in this pattern:
CPRINTF("[%T xxx]\n") or ccprintf("[%T xxx]\n")
The strings are taking up spaces in the EC binaries, so let's refactor
this by adding cprints() and ccprints().
cprints() is just like cprintf(), except that it adds the brackets
and the timestamp. ccprints() is equivalent to cprints(CC_CONSOLE, ...)
This saves us hundreds of bytes in EC binaries.
BUG=chromium:374575
TEST=Build and check flash size
BRANCH=None
Change-Id: Ifafe8dc1b80e698b28ed42b70518c7917b49ee51
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/200490
Reviewed-by: Randall Spangler <rspangler@chromium.org>
88 lines
2.0 KiB
C
88 lines
2.0 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.
|
|
*/
|
|
|
|
#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 CPRINTS(format, args...) cprints(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)
|
|
CPRINTS("%s failed: error %d", __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);
|
|
}
|