-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Devicetree: Macro to initialize driver for every device instance #23416
Devicetree: Macro to initialize driver for every device instance #23416
Conversation
All checks are passing now. checkpatch (informational only, not a failure)
Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting this. This will be very useful for initialising multiple device instances.
3de925e
to
8c9ea2e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8c9ea2e
to
85e2039
Compare
Generally looks go to me. Will let @mbolivar-nordic and @nordic-krch comment on the UTIL_PASS_ARG_TO_MACRO bits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This macro will be really helpful, thanks for this constribution. @io-pa it would be helpful to add some documentation/example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
I think you could define UTIL_PASS_ARG_TO_MACRO as DT_PASS_ARG_TO_MACRO_INTERNAL at the end of devicetree.h to avoid having to extend the util.h API for this.
Can you please also:
- update doc/guides/dts/howtos.rst to use this in the code example in the "Create struct devices in a driver" section? IMO this should be the standard way to define devices now, whenever possible.
- add a test case for DT_INST_FOREACH to tests/lib/devicetree/src/main.c? Every macro in devicetree.h has at least one test case in that file. One idea would be to pass TEST_GPIO_INIT to DT_INST_FOREACH instead of the way it's done now.
Might want to change the commit log's "device.h" to "devicetree.h" if you get a chance also. Not a blocker. |
With this macro device drivers can call macros and functions on every device instance compatible to that driver. This makes it possible to make drivers agnostic to the potential counts of instances. Sidenote: Introduces helper macro DT_CALL_WITH_ARG. Signed-off-by: Ioannis Papamanoglou <iopapamanoglou@gmail.com>
85e2039
to
af45164
Compare
af45164
to
36d8949
Compare
I changed the helper macro to add |
Updated howto "create struct devices in a driver" section to use DT_INST_FOREACH instead of manual per-instance macros. Signed-off-by: Ioannis Papamanoglou <iopapamanoglou@gmail.com>
36d8949
to
45e1723
Compare
Replace manual per-instance macros with DT_INST_FOREACH for TEST_GPIO_INIT test. Signed-off-by: Ioannis Papamanoglou <iopapamanoglou@gmail.com>
45e1723
to
f68822e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
* Has to accept instance_number as only parameter. | ||
*/ | ||
#define DT_INST_FOREACH(inst_expr) \ | ||
UTIL_LISTIFY(DT_NUM_INST(DT_DRV_COMPAT), DT_CALL_WITH_ARG, inst_expr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checking -- this does the right thing if DT_NUM_INST(DT_DRV_COMPAT) is 0, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uses LISTIFY internally, and that uses REPEAT and REPEAT checks wether the variable is 0 in the beginning so should be fine. I just tested it though to be sure and it looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for confirming.
Shippable failure looks ignorable. |
ignoring the shippable failure as its not related. |
This pull request introduces the macro: DT_INST_FOREACH(inst_expr).
This makes it possible to do this:
DT_INST_FOREACH(I2C_NRFX_TWIM_DEVICE);
Instead of:
The macro calls the passed inst_expr for every compatible (and enabled) device in the device tree.
By using this approach the drivers don't have to make assumption about the maximum count of device instances anymore.
The expr argument can be either a macro or a function that take the instance number as argument.