diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2020-10-21 16:11:07 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-11-06 01:43:08 +0000 |
commit | 851daf728dca124f4bb2b6d27238d3952be5cf2b (patch) | |
tree | 5a7725232cc1992a74340e6540fb2ba80e6b7896 /common | |
parent | 8dfdaa83815669c50f70332932fa35614ef2e4f6 (diff) | |
download | chrome-ec-851daf728dca124f4bb2b6d27238d3952be5cf2b.tar.gz |
motion: orientation: update interface
Enabling orientation sensor would not compile anymore.
Fix interface by replacing macros with functions.
BUG=chromium:718919
BRANCH=none
TEST=Compile when enabled on grunt and eve.
Change-Id: Ic5d6992d040cde79ef3f691db494804e160b7650
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2491266
Reviewed-by: Ching-Kang Yen <chingkang@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/build.mk | 1 | ||||
-rw-r--r-- | common/motion_orientation.c | 37 | ||||
-rw-r--r-- | common/motion_sense.c | 58 |
3 files changed, 53 insertions, 43 deletions
diff --git a/common/build.mk b/common/build.mk index e255e44d72..aec737d1f2 100644 --- a/common/build.mk +++ b/common/build.mk @@ -108,6 +108,7 @@ common-$(CONFIG_MAG_CALIBRATE)+= mag_cal.o math_util.o vec3.o mat33.o mat44.o \ common-$(CONFIG_MKBP_EVENT)+=mkbp_event.o common-$(CONFIG_OCPC)+=ocpc.o common-$(CONFIG_ONEWIRE)+=onewire.o +common-$(CONFIG_ORIENTATION_SENSOR)+=motion_orientation.o common-$(CONFIG_PECI_COMMON)+=peci.o common-$(CONFIG_POWER_BUTTON)+=power_button.o common-$(CONFIG_POWER_BUTTON_X86)+=power_button_x86.o diff --git a/common/motion_orientation.c b/common/motion_orientation.c new file mode 100644 index 0000000000..9a20ff8499 --- /dev/null +++ b/common/motion_orientation.c @@ -0,0 +1,37 @@ +/* Copyright 2020 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. + */ + +/* Implement an orientation sensor. */ + +#include "motion_orientation.h" + +/* + * Orientation mode vectors, must match sequential ordering of + * known orientations from enum motionsensor_orientation + */ +static const intv3_t orientation_modes[] = { + [MOTIONSENSE_ORIENTATION_LANDSCAPE] = { 0, -1, 0 }, + [MOTIONSENSE_ORIENTATION_PORTRAIT] = { 1, 0, 0 }, + [MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT] = { -1, 0, 0 }, + [MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE] = { 0, 1, 0 }, +}; + +enum motionsensor_orientation motion_orientation_remap( + const struct motion_sensor_t *s, + enum motionsensor_orientation orientation) +{ + enum motionsensor_orientation rotated_orientation; + const intv3_t *orientation_v; + intv3_t rotated_orientation_v; + + if (orientation == MOTIONSENSE_ORIENTATION_UNKNOWN) + return MOTIONSENSE_ORIENTATION_UNKNOWN; + + orientation_v = &orientation_modes[orientation]; + rotate(*orientation_v, *s->rot_standard_ref, rotated_orientation_v); + rotated_orientation = ((2 * rotated_orientation_v[1] + + rotated_orientation_v[0] + 4) % 5); + return rotated_orientation; +} diff --git a/common/motion_sense.c b/common/motion_sense.c index 0d0db5e101..e3b6e71943 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -22,6 +22,7 @@ #include "motion_sense.h" #include "motion_sense_fifo.h" #include "motion_lid.h" +#include "motion_orientation.h" #include "online_calibration.h" #include "power.h" #include "queue.h" @@ -35,18 +36,6 @@ #define CPRINTS(format, args...) cprints(CC_MOTION_SENSE, format, ## args) #define CPRINTF(format, args...) cprintf(CC_MOTION_SENSE, format, ## args) -#ifdef CONFIG_ORIENTATION_SENSOR -/* - * Orientation mode vectors, must match sequential ordering of - * known orientations from enum motionsensor_orientation - */ -const intv3_t orientation_modes[] = { - [MOTIONSENSE_ORIENTATION_LANDSCAPE] = { 0, -1, 0 }, - [MOTIONSENSE_ORIENTATION_PORTRAIT] = { 1, 0, 0 }, - [MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT] = { -1, 0, 0 }, - [MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE] = { 0, 1, 0 }, -}; -#endif /* Delay between FIFO interruption. */ static unsigned int ap_event_interval; @@ -739,25 +728,6 @@ static int motion_sense_process(struct motion_sensor_t *sensor, return ret; } -#ifdef CONFIG_ORIENTATION_SENSOR -enum motionsensor_orientation motion_sense_remap_orientation( - const struct motion_sensor_t *s, - enum motionsensor_orientation orientation) -{ - enum motionsensor_orientation rotated_orientation; - const intv3_t *orientation_v; - intv3_t rotated_orientation_v; - - if (orientation == MOTIONSENSE_ORIENTATION_UNKNOWN) - return MOTIONSENSE_ORIENTATION_UNKNOWN; - - orientation_v = &orientation_modes[orientation]; - rotate(*orientation_v, *s->rot_standard_ref, rotated_orientation_v); - rotated_orientation = ((2 * rotated_orientation_v[1] + - rotated_orientation_v[0] + 4) % 5); - return rotated_orientation; -} -#endif #ifdef CONFIG_GESTURE_DETECTION static void check_and_queue_gestures(uint32_t *event) @@ -828,22 +798,24 @@ static void check_and_queue_gestures(uint32_t *event) }; mutex_lock(sensor->mutex); - if (ORIENTATION_CHANGED(sensor) && (GET_ORIENTATION(sensor) != - MOTIONSENSE_ORIENTATION_UNKNOWN)) { - SET_ORIENTATION_UPDATED(sensor); - vector.state = GET_ORIENTATION(sensor); - motion_sense_fifo_add_data(&vector, NULL, 0, - __hw_clock_source_read()); + if (motion_orientation_changed(sensor) && + (*motion_orientation_ptr(sensor) != + MOTIONSENSE_ORIENTATION_UNKNOWN)) { + motion_orientation_update(sensor); + vector.state = *motion_orientation_ptr(sensor); + motion_sense_fifo_stage_data(&vector, NULL, 0, + __hw_clock_source_read()); + motion_sense_fifo_commit_data(); #ifdef CONFIG_DEBUG_ORIENTATION { static const char * const mode_strs[] = { - "Landscape", - "Portrait", - "Inv_Portrait", - "Inv_Landscape", - "Unknown" + "Landscape", + "Portrait", + "Inv_Portrait", + "Inv_Landscape", + "Unknown" }; - CPRINTS(mode_strs[GET_ORIENTATION(sensor)]); + CPRINTS(mode[vector.state]); } #endif } |