summaryrefslogtreecommitdiff
path: root/zephyr/shim/src/motionsense_sensors.c
diff options
context:
space:
mode:
authorHyungwoo Yang <hyungwoo.yang@intel.corp-partner.google.com>2021-03-19 15:25:05 -0700
committerCommit Bot <commit-bot@chromium.org>2021-03-23 23:13:18 +0000
commit52c66f7e5f5faf5d96625fe95c53a88b1f5c801c (patch)
treea860d2e5de70bf987eeaa37acf18c7f6bf84231a /zephyr/shim/src/motionsense_sensors.c
parent9ab043078548fd30c010b7c3d5dd394e29096491 (diff)
downloadchrome-ec-52c66f7e5f5faf5d96625fe95c53a88b1f5c801c.tar.gz
zephyr: DT: support sensor rotation matrix
This creates instances of rotation matrix(mat33_fp_t) which is used to convert raw value from a sensor to X, Y and Z on the defined coordinate system. BUG=b:173507858 BRANCH=none TEST=make buildall -j8 build volteer on zephyr Signed-off-by: Hyungwoo Yang <hyungwoo.yang@intel.corp-partner.google.com> Change-Id: Ifc80fe7ff33c46904af279b9f52e611c7157c346 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2778814 Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'zephyr/shim/src/motionsense_sensors.c')
-rw-r--r--zephyr/shim/src/motionsense_sensors.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/zephyr/shim/src/motionsense_sensors.c b/zephyr/shim/src/motionsense_sensors.c
index 681ebcce6b..9e8eef6f6f 100644
--- a/zephyr/shim/src/motionsense_sensors.c
+++ b/zephyr/shim/src/motionsense_sensors.c
@@ -31,3 +31,29 @@ static int init_sensor_mutex(const struct device *dev)
}
SYS_INIT(init_sensor_mutex, POST_KERNEL, 50);
#endif /* DT_NODE_EXISTS(SENSOR_MUTEX_NODE) */
+
+#define SENSOR_ROT_REF_NODE DT_PATH(motionsense_rotation_ref)
+#define SENSOR_ROT_STD_REF_NAME(id) DT_CAT(ROT_REF_, id)
+#define MAT_ITEM(i, id) FLOAT_TO_FP((int32_t)(DT_PROP_BY_IDX(id, mat33, i)))
+#define DECLARE_SENSOR_ROT_REF(id) \
+ static const mat33_fp_t SENSOR_ROT_STD_REF_NAME(id) = { \
+ { \
+ FOR_EACH_FIXED_ARG(MAT_ITEM, (,), id, 0, 1, 2) \
+ }, \
+ { \
+ FOR_EACH_FIXED_ARG(MAT_ITEM, (,), id, 3, 4, 5) \
+ }, \
+ { \
+ FOR_EACH_FIXED_ARG(MAT_ITEM, (,), id, 6, 7, 8) \
+ }, \
+ };
+
+/*
+ * Declare 3x3 rotation matrix for
+ * each child node of "/motionsense-rotation-ref" node in DT.
+ *
+ * A rotation matrix can be shared among the motion sensors.
+ */
+#if DT_NODE_EXISTS(SENSOR_ROT_REF_NODE)
+DT_FOREACH_CHILD(SENSOR_ROT_REF_NODE, DECLARE_SENSOR_ROT_REF)
+#endif