summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2015-09-17 11:42:43 -0700
committerchrome-bot <chrome-bot@chromium.org>2015-09-17 19:00:53 -0700
commit5717b3150c8a8d43e07ce2dc8065c3515d3651f7 (patch)
treeb908d7a6bed31be5e5c06661bab52356b4d2b5da /common
parente686e95e9e2f50380862a9f95c0bba02d237b646 (diff)
downloadchrome-ec-5717b3150c8a8d43e07ce2dc8065c3515d3651f7.tar.gz
motion: add config option to use the old accelerometer ref frame
Add config option to use the old accelerometer reference frame, which is used on samus and products using 3.14 or earlier kernel. This fixes samus so that the lid angle calculation is correct again. This also moves the accel_orientation structure out of the board directory and into common code, since it purely is a function of the reference frame being used. BUG=chrome-os-partner:43494 BRANCH=none TEST=test on samus, verify lid angle calculation is correct once again. also, enable the motion_lid test and verify that it passes. Change-Id: I948a74a71964b54c68be66e828a030ddd0418947 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/300510 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/motion_lid.c50
-rw-r--r--common/motion_sense.c10
2 files changed, 55 insertions, 5 deletions
diff --git a/common/motion_lid.c b/common/motion_lid.c
index 32fea49e18..a563b1019b 100644
--- a/common/motion_lid.c
+++ b/common/motion_lid.c
@@ -38,6 +38,42 @@ static int lid_angle_is_reliable;
*/
#define HINGE_ALIGNED_WITH_GRAVITY_THRESHOLD FLOAT_TO_FP(0.96593)
+/*
+ * Define the accelerometer orientation matrices based on the standard
+ * reference frame in use (note: accel data is converted to standard ref
+ * frame before calculating lid angle).
+ */
+#ifdef CONFIG_ACCEL_STD_REF_FRAME_OLD
+const struct accel_orientation acc_orient = {
+ /* Hinge aligns with y axis. */
+ .rot_hinge_90 = {
+ { 0, 0, FLOAT_TO_FP(1)},
+ { 0, FLOAT_TO_FP(1), 0},
+ { FLOAT_TO_FP(-1), 0, 0}
+ },
+ .rot_hinge_180 = {
+ { FLOAT_TO_FP(-1), 0, 0},
+ { 0, FLOAT_TO_FP(1), 0},
+ { 0, 0, FLOAT_TO_FP(-1)}
+ },
+ .hinge_axis = {0, 1, 0},
+};
+#else
+const struct accel_orientation acc_orient = {
+ /* Hinge aligns with x axis. */
+ .rot_hinge_90 = {
+ { FLOAT_TO_FP(1), 0, 0},
+ { 0, 0, FLOAT_TO_FP(1)},
+ { 0, FLOAT_TO_FP(-1), 0}
+ },
+ .rot_hinge_180 = {
+ { FLOAT_TO_FP(1), 0, 0},
+ { 0, FLOAT_TO_FP(-1), 0},
+ { 0, 0, FLOAT_TO_FP(-1)}
+ },
+ .hinge_axis = {1, 0, 0},
+};
+#endif
/* Pointer to constant acceleration orientation data. */
const struct accel_orientation * const p_acc_orient = &acc_orient;
@@ -147,15 +183,25 @@ int motion_lid_get_angle(void)
*/
void motion_lid_calc(void)
{
- /* rotate lid vector by 180 degre to be in the right coordinate frame */
+#ifndef CONFIG_ACCEL_STD_REF_FRAME_OLD
+ /*
+ * rotate lid vector by 180 deg to be in the right coordinate frame
+ * because calculate_lid_angle assumes when the lid is closed, that
+ * the lid and base accelerometer data matches
+ */
vector_3_t lid = { accel_lid->xyz[X],
accel_lid->xyz[Y] * -1,
accel_lid->xyz[Z] * -1};
-
/* Calculate angle of lid accel. */
lid_angle_is_reliable = calculate_lid_angle(
accel_base->xyz, lid,
&lid_angle_deg);
+#else
+ /* Calculate angle of lid accel. */
+ lid_angle_is_reliable = calculate_lid_angle(
+ accel_base->xyz, accel_lid->xyz,
+ &lid_angle_deg);
+#endif
#ifdef CONFIG_LID_ANGLE_UPDATE
lid_angle_update(motion_lid_get_angle());
diff --git a/common/motion_sense.c b/common/motion_sense.c
index bea0bef1cf..9add2d1712 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -41,6 +41,10 @@ static int accel_disp;
#define SENSOR_ACTIVE(_sensor) (sensor_active & (_sensor)->active_mask)
+#if defined(CONFIG_LPC) || defined(TEST_MOTION_LID)
+#define UPDATE_HOST_MEM_MAP
+#endif
+
/*
* Mutex to protect sensor values between host command task and
* motion sense task:
@@ -388,7 +392,7 @@ static inline void set_present(uint8_t *lpc_status)
*lpc_status |= EC_MEMMAP_ACC_STATUS_PRESENCE_BIT;
}
-#ifdef CONFIG_LPC
+#ifdef UPDATE_HOST_MEM_MAP
/* Update/Write LPC data */
static inline void update_sense_data(uint8_t *lpc_status,
uint16_t *lpc_data, int *psample_id)
@@ -526,7 +530,7 @@ void motion_sense_task(void)
#ifdef CONFIG_ACCEL_FIFO
timestamp_t ts_last_int;
#endif
-#ifdef CONFIG_LPC
+#ifdef UPDATE_HOST_MEM_MAP
int sample_id = 0;
uint8_t *lpc_status;
uint16_t *lpc_data;
@@ -591,7 +595,7 @@ void motion_sense_task(void)
CPRINTF("]\n");
}
#endif
-#ifdef CONFIG_LPC
+#ifdef UPDATE_HOST_MEM_MAP
update_sense_data(lpc_status, lpc_data, &sample_id);
#endif