diff options
Diffstat (limited to 'zephyr')
-rw-r--r-- | zephyr/dts/bindings/motionsense/cros-ec,motionsense-rotation-ref.yaml | 55 | ||||
-rw-r--r-- | zephyr/shim/src/motionsense_sensors.c | 26 |
2 files changed, 81 insertions, 0 deletions
diff --git a/zephyr/dts/bindings/motionsense/cros-ec,motionsense-rotation-ref.yaml b/zephyr/dts/bindings/motionsense/cros-ec,motionsense-rotation-ref.yaml new file mode 100644 index 0000000000..7de86ec8db --- /dev/null +++ b/zephyr/dts/bindings/motionsense/cros-ec,motionsense-rotation-ref.yaml @@ -0,0 +1,55 @@ +# Copyright 2021 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. + +description: rotation reference parent node + +compatible: "cros-ec,motionsense-rotation-ref" + +child-binding: + description: | + A rotation matrix node is used to create + an instance of mat33_fp_t which is used by + sensor drivers. + properties: + mat33: + required: true + type: array + description: | + 3x3 matrix to rotate x, y, and z axes. + Applications with the sensor API expects sansor data + based on the same defined coordinate system. + * X-axis is horizontal and positive toward the right + * Y-axis is vertical and positive toward the top + * Z-axis points toward the user + + Depending on how the sensor is mounted on board(PCB), we + may need to change the direction of a axis and swap X and + Y-axis. Using the 3x3 matrix, it generates the correct + X,Y, and Z on the defined coordinate system. + + +- -+ +- -+ +- -+ + | v1 v2 v3 | | sensor_X | | X | + | v4 v5 v6 | * | sensor_Y | = | Y | + | v7 v8 v9 | | sensor_Z | | Z | + +- -+ +- -+ +- -+ + +# +# examples: +# +# motionsense-rotation-ref { +# compatible = "cros-ec,motionsense-rotation-ref"; +# /* change the direction of Y and Z-axis */ +# lid_rot_ref: lid-rotation-ref { +# mat33 = <1 0 0 +# 0 (-1) 0 +# 0 0 (-1)>; +# }; +# /* swap X and Y-axis, and then change the direction of Y-axis */ +# base_rot_ref: base-rotation-ref { +# mat33 = <0 1 0 +# (-1) 0 0 +# 0 0 1>; +# }; +# }; +# 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 |