Open aaronemassey opened 2 years ago
I'll have a tiny pull-request for this fairly soon.
I currently embed a struct of dt_spec nodes which represent ethernet ports for a switch product that can have N number of ports. So this feature allows me to embed these nodes properly.
@aaronemassey thanks for volunteering to add this. Please use DT_NUM_
instead of DT_COUNT_
for consistency:
$ rg '#define DT_NUM' include/zephyr/devicetree.h
1620:#define DT_NUM_RANGES(node_id) DT_CAT(node_id, _RANGES_NUM)
2146:#define DT_NUM_REGS(node_id) DT_CAT(node_id, _REG_NUM)
2239:#define DT_NUM_IRQS(node_id) DT_CAT(node_id, _IRQ_NUM)
2955:#define DT_NUM_INST_STATUS_OKAY(compat) \
I think you only need DT_NUM_CHILDREN, and DT_NUM_INST_STATUS_OKAY already exists for your other example.
I think this strategy does not work when passing to LISTIFY
however...
I'll have a tiny pull-request for this fairly soon.
Sorry for letting this drop. It only recently came back on my radar due to the issue activity :) Looking to have a PR up this or next week.
Hi @aaronemassey Is there a PR? I'm in need of this too.
Hi @aaronemassey Is there a PR? I'm in need of this too.
Bah, I should never commit to things so quickly like in https://github.com/zephyrproject-rtos/zephyr/issues/38715#issuecomment-1489242523. Things have been busy, but we're all busy :)
Will try to have something by EO this week/end. @swift-tk, you're welcome to add it if you want it sooner. It should basically be @mbolivar-nordic suggestions in https://github.com/zephyrproject-rtos/zephyr/issues/38715#issuecomment-1474433804.
Hi @aaronemassey I think I have a better solution see https://github.com/zephyrproject-rtos/zephyr/pull/71933.
Is your feature request related to a problem? Please describe.
I have a use-case where I need to know the length of children nodes or nodes with a compatible string.
Describe the solution you'd like
Two DT macros like:
DT_COUNT_STATUS_OKAY(compat)
DT_COUNT_CHILDREN(NODE_ID)
Describe alternatives you've considered Currently my solution is to write macro functions like:
But this seems kind of ugly and instead something that maybe should be usable from the DT macros.
Additional context I don't think any additional context is needed besides the example I supplied.
Thank you for all the work that has been put into Zephyr.
@yperess is also interested.