Skip to content

Conversation

@de-nordic
Copy link
Contributor

The macro is searching for all instances of specific device that contain specific property and evaluates to true (1) if any device does.
The macro used to do that by generating, using
DT_ANY_INST_HAS_PROP_STATUS_OKAY, a logical expression like (0 || 1 || 0), where each digit represented existence of property (1) or lack of it (0).
Unfortunately other util macros, like IS_ENABLED, were not able to evaluate such expression, as they often simply expect something they can evaluate to 0 or 1.

The commit here changes DT_ANY_INST_HAS_PROP_STATUS_OKAY to generate a list of tokens (1) where token is added to list only for instance of a device that has the property; then such list is processed using IS_EMPTY() macro and in the end 0 or 1 is generated, depending on whether any enabled instance of a device has the property or not. This change allows result of DT_ANY_INST_HAS_PROP_STATUS_OKAY to be used with macros like IS_ENABLED, IF_ENABLED or COND_CODE_x.

pdgendt
pdgendt previously approved these changes Mar 19, 2024
@pdgendt
Copy link
Contributor

pdgendt commented Mar 19, 2024

It would be nice if you could add a test case to tests/lib/devicetree/api.

@de-nordic
Copy link
Contributor Author

It would be nice if you could add a test case to tests/lib/devicetree/api.

There is a test case. It should run on the PR, I have run it locally.
Or you mean the testcase that would check if IS_ENABLED and IF_ENABLED work? In such case, you are right, that should be done.

Comment on lines 4192 to 4195
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will break documentation for the macro below. please place internal macros at the bottom, under INTERNAL_HIDDEN

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

The macro is searching for all instances of specific device
that contain specific property and evaluates to true (1) if
any device does.
The macro used to do that by generating, using
DT_ANY_INST_HAS_PROP_STATUS_OKAY, a logical expression
like (0 || 1 || 0), where each digit represented existence of
property (1) or lack of it (0).
Unfortunately other util macros, like IS_ENABLED, were
not able to evaluate such expression, as they often simply
expect something they can evaluate to 0 or 1.

The commit here changes DT_ANY_INST_HAS_PROP_STATUS_OKAY
to generate a list of tokens (1) where token is added to list
only for instance of a device that has the property;
then such list is processed using IS_EMPTY() macro and
in the end 0 or 1 is generated, depending on whether
any enabled instance of a device has the property or not.
This change allows result of DT_ANY_INST_HAS_PROP_STATUS_OKAY
to be used with macros like IS_ENABLED, IF_ENABLED or
COND_CODE_x.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
@de-nordic
Copy link
Contributor Author

tests/lib/devicetree/api.

Done

@de-nordic de-nordic requested review from gmarull and pdgendt March 19, 2024 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants