diff options
Diffstat (limited to 'zephyr/shim')
-rw-r--r-- | zephyr/shim/include/motionsense_sensors.h | 26 | ||||
-rw-r--r-- | zephyr/shim/src/motionsense_sensors.c | 43 |
2 files changed, 62 insertions, 7 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. * diff --git a/zephyr/shim/src/motionsense_sensors.c b/zephyr/shim/src/motionsense_sensors.c index 0a74595ce3..bac92e58e8 100644 --- a/zephyr/shim/src/motionsense_sensors.c +++ b/zephyr/shim/src/motionsense_sensors.c @@ -94,7 +94,7 @@ DT_FOREACH_CHILD(SENSOR_ROT_REF_NODE, DECLARE_SENSOR_ROT_REF) compat, create_data_macro) /* - * sensor_drv_list.inc is included two times in this file. This is the first + * sensor_drv_list.inc is included three times in this file. This is the first * time and it is for creating sensor driver-specific data. So we ignore * CREATE_MOTION_SENSOR() that creates motion sensor at this time. */ @@ -209,10 +209,23 @@ DT_FOREACH_CHILD(SENSOR_ROT_REF_NODE, DECLARE_SENSOR_ROT_REF) .max_frequency = s_max_freq \ }, -#define MK_SENSOR_ENTRY(inst, s_compat, s_chip, s_type, s_drv, \ - s_min_freq, s_max_freq) \ - DO_MK_SENSOR_ENTRY(DT_INST(inst, s_compat), \ - s_chip, s_type, s_drv, s_min_freq, s_max_freq) +/* Construct an entry iff the alternate_for property is missing. */ +#define MK_SENSOR_ENTRY(inst, s_compat, s_chip, s_type, s_drv, s_min_freq, \ + s_max_freq) \ + COND_CODE_0(DT_NODE_HAS_PROP(DT_INST(inst, s_compat), alternate_for), \ + (DO_MK_SENSOR_ENTRY(DT_INST(inst, s_compat), s_chip, \ + s_type, s_drv, s_min_freq, \ + s_max_freq)), \ + ()) + +/* Construct an entry iff the alternate_for property exists. */ +#define MK_SENSOR_ALT_ENTRY(inst, s_compat, s_chip, s_type, s_drv, s_min_freq, \ + s_max_freq) \ + COND_CODE_1(DT_NODE_HAS_PROP(DT_INST(inst, s_compat), alternate_for), \ + (DO_MK_SENSOR_ENTRY(DT_INST(inst, s_compat), s_chip, \ + s_type, s_drv, s_min_freq, \ + s_max_freq)), \ + ()) #undef CREATE_SENSOR_DATA /* @@ -269,6 +282,26 @@ struct motion_sensor_t motion_sensors[] = { #endif }; +/* + * Remap the CREATE_MOTION_SENSOR to call MK_SENSOR_ALT_ENTRY to create a list + * of alternate sensors that will be used at runtime. + */ +#undef CREATE_MOTION_SENSOR +#define CREATE_MOTION_SENSOR(s_compat, s_chip, s_type, s_drv, s_min_freq, \ + s_max_freq) \ + UTIL_LISTIFY(DT_NUM_INST_STATUS_OKAY(s_compat), MK_SENSOR_ALT_ENTRY, \ + s_compat, s_chip, s_type, s_drv, s_min_freq, s_max_freq) + +/* + * The list of alternate motion sensors that may be used at runtime to replace + * an entry in the motion_sensors array. + */ +__maybe_unused static struct motion_sensor_t motion_sensors_alt[] = { +#if DT_NODE_EXISTS(SENSOR_ALT_NODE) +#include "motionsense_driver/sensor_drv_list.inc" +#endif +}; + #ifdef CONFIG_DYNAMIC_MOTION_SENSOR_COUNT unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); #else |