summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-07-31 10:54:27 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-08-01 02:52:28 +0000
commite2f233faafe2b7932fad0f03ef2ecd73c0b8abef (patch)
tree15c34614f5df05bf5c2b1a6a9cf83712ae5efd2b
parent0085573ff4b035fc45c7d902c622f9e39cd997e3 (diff)
downloadchrome-ec-e2f233faafe2b7932fad0f03ef2ecd73c0b8abef.tar.gz
motion_sense: Move angle calculation under LPC_MODE
When LPC mode is used, there is an assumption that the first 2 sensors are accelerometers, and the optional 3rd is a gyro. Put the code that fill lpc_data with #ifdef. Prevent lpc space corruption if more than 3 sensors are present. BRANCH=smaug TEST=Compile. Smaug works BUG=None Change-Id: I12c9b823efb57d7b190a1813228f6f02fa0bebcb Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/290073
-rw-r--r--common/motion_sense.c15
-rw-r--r--include/ec_commands.h5
2 files changed, 15 insertions, 5 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 133e9d784f..465674fb56 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -290,6 +290,7 @@ static inline void set_present(uint8_t *lpc_status)
*lpc_status |= EC_MEMMAP_ACC_STATUS_PRESENCE_BIT;
}
+#ifdef CONFIG_LPC
/* Update/Write LPC data */
static inline void update_sense_data(uint8_t *lpc_status,
uint16_t *lpc_data, int *psample_id)
@@ -318,7 +319,8 @@ static inline void update_sense_data(uint8_t *lpc_status,
#else
lpc_data[0] = LID_ANGLE_UNRELIABLE;
#endif
- for (i = 0; i < motion_sensor_count; i++) {
+ /* Assumptions on the list of sensors */
+ for (i = 0; i < MIN(motion_sensor_count, 3); i++) {
sensor = &motion_sensors[i];
lpc_data[1+3*i] = sensor->xyz[X];
lpc_data[2+3*i] = sensor->xyz[Y];
@@ -333,6 +335,7 @@ static inline void update_sense_data(uint8_t *lpc_status,
EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
*lpc_status = EC_MEMMAP_ACC_STATUS_PRESENCE_BIT | *psample_id;
}
+#endif
static int motion_sense_read(struct motion_sensor_t *sensor)
{
@@ -407,19 +410,21 @@ void motion_sense_task(void)
{
int i, ret, wait_us, fifo_flush_needed = 0;
timestamp_t ts_begin_task, ts_end_task;
- uint8_t *lpc_status;
- uint16_t *lpc_data;
uint32_t event = 0;
- int sample_id = 0;
int rd_cnt;
struct motion_sensor_t *sensor;
#ifdef CONFIG_ACCEL_FIFO
timestamp_t ts_last_int;
#endif
+#ifdef CONFIG_LPC
+ int sample_id = 0;
+ uint8_t *lpc_status;
+ uint16_t *lpc_data;
lpc_status = host_get_memmap(EC_MEMMAP_ACC_STATUS);
lpc_data = (uint16_t *)host_get_memmap(EC_MEMMAP_ACC_DATA);
set_present(lpc_status);
+#endif
#ifdef CONFIG_ACCEL_FIFO
ts_last_int = get_time();
@@ -483,7 +488,9 @@ void motion_sense_task(void)
CPRINTF("]\n");
}
#endif
+#ifdef CONFIG_LPC
update_sense_data(lpc_status, lpc_data, &sample_id);
+#endif
ts_end_task = get_time();
#ifdef CONFIG_ACCEL_FIFO
diff --git a/include/ec_commands.h b/include/ec_commands.h
index dfe67b71d6..f64ffd6eac 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -90,7 +90,10 @@
/* Unused 0x84 - 0x8f */
#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
/* Unused 0x91 */
-#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometer data 0x92 - 0x9f */
+#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */
+/* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
+/* 0x94 - 0x99: 1st Accelerometer */
+/* 0x9a - 0x9f: 2nd Accelerometer */
#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
/* Unused 0xa6 - 0xdf */