summaryrefslogtreecommitdiff
path: root/zephyr/shim/include/motionsense_sensors.h
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2021-04-22 10:56:19 -0600
committerCommit Bot <commit-bot@chromium.org>2021-04-23 20:01:23 +0000
commit4aaa85760faeec02f94b86b99d40768362d8c158 (patch)
treebacf5655e96231da3437ffb5ab7be844b5601760 /zephyr/shim/include/motionsense_sensors.h
parentcea345aa111d93617806d55ed68950d2e072db0e (diff)
downloadchrome-ec-4aaa85760faeec02f94b86b99d40768362d8c158.tar.gz
zephyr: sensors: Add alternate sensors support
In some boards there's a runtime decision for which sensor to use. In order to support this we'll need an instance of the alternate sensors as well as a mapping for them. Add an optional phandle `alternate-for` to the base sensors bindings. When used, the sensor will be excluded from the primary motion_sensors array and added instead to the motion_sensors_alt array. BRANCH=none BUG=b:183990188, b:185966444 TEST=zmake testall Signed-off-by: Yuval Peress <peress@chromium.org> Change-Id: I6f6e3a9659a381c45fd97fbce9fecb2a807f7fa2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2846415 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'zephyr/shim/include/motionsense_sensors.h')
-rw-r--r--zephyr/shim/include/motionsense_sensors.h26
1 files changed, 24 insertions, 2 deletions
diff --git a/zephyr/shim/include/motionsense_sensors.h b/zephyr/shim/include/motionsense_sensors.h
index 013a03d8dc..bf7ff95f85 100644
--- a/zephyr/shim/include/motionsense_sensors.h
+++ b/zephyr/shim/include/motionsense_sensors.h
@@ -10,10 +10,17 @@
#define SENSOR_NODE DT_PATH(motionsense_sensor)
#define SENSOR_INFO_NODE DT_PATH(motionsense_sensor_info)
+#define SENSOR_ALT_NODE DT_PATH(motionsesne_sensor_alt)
#define SENSOR_ID(id) DT_CAT(SENSOR_, id)
-#define SENSOR_ID_WITH_COMMA(id) \
- IF_ENABLED(DT_NODE_HAS_STATUS(id, okay), (SENSOR_ID(id),))
+
+/* Define the SENSOR_ID if:
+ * DT_NODE_HAS_STATUS(id, okay) && !DT_NODE_HAS_PROP(id, alternate_for)
+ */
+#define SENSOR_ID_WITH_COMMA(id) \
+ IF_ENABLED(DT_NODE_HAS_STATUS(id, okay), \
+ (COND_CODE_0(DT_NODE_HAS_PROP(id, alternate_for), \
+ (SENSOR_ID(id), ), ())))
enum sensor_id {
#if DT_NODE_EXISTS(SENSOR_NODE)
@@ -22,6 +29,21 @@ enum sensor_id {
SENSOR_COUNT,
};
+#undef SENSOR_ID_WITH_COMMA
+/* Define the SENSOR_ID if:
+ * DT_NODE_HAS_STATUS(id, okay) && DT_NODE_HAS_PROP(id, alternate_for)
+ */
+#define SENSOR_ID_WITH_COMMA(id) \
+ IF_ENABLED(DT_NODE_HAS_STATUS(id, okay), \
+ (COND_CODE_1(DT_NODE_HAS_PROP(id, alternate_for), \
+ (SENSOR_ID(id), ), ())))
+enum sensor_alt_id {
+#if DT_NODE_EXISTS(SENSOR_ALT_NODE)
+ DT_FOREACH_CHILD(SENSOR_ALT_NODE, SENSOR_ID_WITH_COMMA)
+#endif
+ SENSOR_ALT_COUNT,
+};
+
/*
* Find the accelerometers for lid angle calculation.
*