mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
Added motion sense task to Clapper and Glimmer. This task samples the accelerometers and calculate a lid angle. Note that as the machine is rotated towards the hinge angle aligning with gravity, the lid calculation becomes less trustworthy. Added a math_util file to hold various mathematical functions useful for calculating lid angle that may be helpful in other places. For each board with accelerometers we need to define some orientation specific data in board.c. There is a calibration procedure through the EC console that can be enabled by defining CONFIG_ACCEL_CALIBRATE. The calibration procedure can help determine the orientation data required. For debugging purposes there is a console command to regularly print to the EC console the accelerometer data and derived lid angle. The console command can be enabled by defining CONFIG_CMD_LID_ANGLE. BUG=none Original-BUG=chrome-os-partner:24703 BRANCH=rambi TEST=Ran the calibration procedure on a Glimmer unit, and then rotated the machine in space. Verified that the lid angle calculated roughly matched actual lid angle. Original-Change-Id: I63a5e384b7f6b628b4ea01de49843355fb8d6ebe Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/184783 Reviewed-by: Randall Spangler <rspangler@chromium.org> Signed-off-by: Alec Berg <alecaberg@chromium.org> (cherry picked from commit efb07945a5159fa0e7a746c666b2519ebdca9c22) Conflicts: board/clapper/board.c board/clapper/ec.tasklist board/glimmer/board.c board/glimmer/ec.tasklist Change-Id: Ibc492ef5c11e7084e87f01338c4d7775f9a08c18 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/187433 Reviewed-by: Randall Spangler <rspangler@chromium.org>
139 lines
3.2 KiB
C
139 lines
3.2 KiB
C
/* Copyright (c) 2012 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.
|
|
*/
|
|
|
|
/* Console output module for Chrome EC */
|
|
|
|
#include "console.h"
|
|
#include "uart.h"
|
|
#include "util.h"
|
|
|
|
/* Default to all channels active */
|
|
#ifndef CC_DEFAULT
|
|
#define CC_DEFAULT CC_ALL
|
|
#endif
|
|
static uint32_t channel_mask = CC_DEFAULT;
|
|
static uint32_t channel_mask_saved = CC_DEFAULT;
|
|
|
|
/*
|
|
* List of channel names; must match enum console_channel.
|
|
*
|
|
* We could do something fancy and macro-y with this like ec.tasklist, so that
|
|
* the channel name list and console_channel enum come from the same header
|
|
* file. That's clever, but I'm not convinced it's more readable or
|
|
* maintainable than the two simple lists we have now.
|
|
*
|
|
* We could also try to get clever with #ifdefs or board-specific lists of
|
|
* channel names, so that for example boards without port80 support don't waste
|
|
* binary size on the channel name string for "port80". Pruning the channel
|
|
* list might also become more important if we have >32 channels - for example,
|
|
* if we decide to replace enum console_channel with enum module_id.
|
|
*/
|
|
static const char * const channel_names[] = {
|
|
"command",
|
|
"charger",
|
|
"chipset",
|
|
"clock",
|
|
"dma",
|
|
"events",
|
|
"gpio",
|
|
"hostcmd",
|
|
"i2c",
|
|
"keyboard",
|
|
"keyscan",
|
|
"lightbar",
|
|
"lpc",
|
|
"motionsense",
|
|
"port80",
|
|
"pwm",
|
|
"spi",
|
|
"switch",
|
|
"system",
|
|
"task",
|
|
"thermal",
|
|
"usbcharge",
|
|
"vboot",
|
|
"hook",
|
|
};
|
|
BUILD_ASSERT(ARRAY_SIZE(channel_names) == CC_CHANNEL_COUNT);
|
|
|
|
/*****************************************************************************/
|
|
/* Channel-based console output */
|
|
|
|
int cputs(enum console_channel channel, const char *outstr)
|
|
{
|
|
/* Filter out inactive channels */
|
|
if (!(CC_MASK(channel) & channel_mask))
|
|
return EC_SUCCESS;
|
|
|
|
return uart_puts(outstr);
|
|
}
|
|
|
|
int cprintf(enum console_channel channel, const char *format, ...)
|
|
{
|
|
int rv;
|
|
va_list args;
|
|
|
|
/* Filter out inactive channels */
|
|
if (!(CC_MASK(channel) & channel_mask))
|
|
return EC_SUCCESS;
|
|
|
|
va_start(args, format);
|
|
rv = uart_vprintf(format, args);
|
|
va_end(args);
|
|
return rv;
|
|
}
|
|
|
|
void cflush(void)
|
|
{
|
|
uart_flush_output();
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
/* Console commands */
|
|
|
|
/* Set active channels */
|
|
static int command_ch(int argc, char **argv)
|
|
{
|
|
int i;
|
|
char *e;
|
|
|
|
/* If one arg, save / restore, or set the mask */
|
|
if (argc == 2) {
|
|
if (strcasecmp(argv[1], "save") == 0) {
|
|
channel_mask_saved = channel_mask;
|
|
return EC_SUCCESS;
|
|
} else if (strcasecmp(argv[1], "restore") == 0) {
|
|
channel_mask = channel_mask_saved;
|
|
return EC_SUCCESS;
|
|
|
|
} else {
|
|
/* Set the mask */
|
|
int m = strtoi(argv[1], &e, 0);
|
|
if (*e)
|
|
return EC_ERROR_PARAM1;
|
|
|
|
/* No disabling the command output channel */
|
|
channel_mask = m | CC_MASK(CC_COMMAND);
|
|
|
|
return EC_SUCCESS;
|
|
}
|
|
}
|
|
|
|
/* Print the list of channels */
|
|
ccputs(" # Mask E Channel\n");
|
|
for (i = 0; i < CC_CHANNEL_COUNT; i++) {
|
|
ccprintf("%2d %08x %c %s\n",
|
|
i, CC_MASK(i),
|
|
(channel_mask & CC_MASK(i)) ? '*' : ' ',
|
|
channel_names[i]);
|
|
cflush();
|
|
}
|
|
return EC_SUCCESS;
|
|
};
|
|
DECLARE_CONSOLE_COMMAND(chan, command_ch,
|
|
"[ save | restore | <mask> ]",
|
|
"Save, restore, get or set console channel mask",
|
|
NULL);
|