Skip to content

Test DT_INST_PROP_HAS_IDX() inside the macros for multi instances #29833

@avisconti

Description

@avisconti

I'm fixing interrupt handling inside LIS2DH sensor driver, which has recently been made multi instance.
The LIS2DH driver should be done in a way to use two interrupts (drdy on INT1 and other vtriggers on INT2) defined in DT, like:

lis2dh@18 {
    compatible = "st,lis2dh";
    reg = <0x18>;
    label = "LIS2DH";
    irq-gpios = <&arduino_header 5 GPIO_ACTIVE_HIGH>, <&arduino_header 6 GPIO_ACTIVE_HIGH> ;
};

In the code I'm writing someling like this:

.irq1_dev_name = COND_CODE_1(DT_INST_PROP_HAS_IDX(inst, irq_gpios, 0),> \
                                                          (DT_INST_GPIO_LABEL_BY_IDX(inst, irq_gpios, 0)),     \
                                                           (NULL) ),    \

.irq2_dev_name = COND_CODE_1(DT_INST_PROP_HAS_IDX(inst, irq_gpios, 1),> \
                                                          (DT_INST_GPIO_LABEL_BY_IDX(inst, irq_gpios, 1)),     \
                                                           (NULL) ),    \

But COND_CODE_1 requires something different as it gives following errors when building:

../include/sys/util_internal.h:52:14: error: pasting "_XXXX" and "(" does not give a valid
preprocessing token
52 | __COND_CODE(_XXXX##_flag, _if_1_code, _else_code)
| ^~~~~
../include/sys/util_macro.h:112:2: note: in expansion of macro 'Z_COND_CODE_1'
112 | Z_COND_CODE_1(_flag, _if_1_code, _else_code)
| ^~~~~~~~~~~~~
/local/home/visconti/Projects/zephyrproject/zephyr/drivers/sensor/lis2dh/lis2dh.c:414:20: note: in
expansion of macro 'COND_CODE_1'
414 | .irq1_dev_name = COND_CODE_1(DT_INST_PROP_HAS_IDX(inst, irq_gpios, 0),
| ^~~~~~~~~~~

Is it possible to create new macros for handling such cases?
Thanks

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions