Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
avisconti opened this issue Nov 5, 2020 · 3 comments · Fixed by #29985
Closed

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

avisconti opened this issue Nov 5, 2020 · 3 comments · Fixed by #29985
Assignees
Labels
area: Devicetree Tooling PR modifies or adds a Device Tree tooling area: Devicetree Enhancement Changes/Updates/Additions to existing features

Comments

@avisconti
Copy link
Collaborator

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

@avisconti avisconti added the Enhancement Changes/Updates/Additions to existing features label Nov 5, 2020
@avisconti
Copy link
Collaborator Author

avisconti commented Nov 5, 2020

@mbolivar-nordic
I assigned it to you, but feel free to redirect it to the proper person of course

@avisconti
Copy link
Collaborator Author

@mbolivar-nordic
Do you think I should assign it or involve anyone else?

@avisconti
Copy link
Collaborator Author

Added @galak and @pabigot

@mbolivar-nordic mbolivar-nordic added area: Devicetree area: Devicetree Tooling PR modifies or adds a Device Tree tooling labels Nov 13, 2020
mbolivar-nordic added a commit to mbolivar-nordic/zephyr that referenced this issue Nov 13, 2020
We have a use case for checking the results of a DT_PROP_HAS_IDX()
call with COND_CODE_1(). That won't work because its expansion is an
integer comparison; COND_CODE_1() expects a literal 1 or 0.

Adjust the macro implementation so it expands to a literal 1 or 0.
Make this work even when the index argument needs an expansion while
we're at it.

Fixes: zephyrproject-rtos#29833
Signed-off-by: Martí Bolívar <[email protected]>
galak pushed a commit that referenced this issue Nov 15, 2020
We have a use case for checking the results of a DT_PROP_HAS_IDX()
call with COND_CODE_1(). That won't work because its expansion is an
integer comparison; COND_CODE_1() expects a literal 1 or 0.

Adjust the macro implementation so it expands to a literal 1 or 0.
Make this work even when the index argument needs an expansion while
we're at it.

Fixes: #29833
Signed-off-by: Martí Bolívar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Tooling PR modifies or adds a Device Tree tooling area: Devicetree Enhancement Changes/Updates/Additions to existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants