-
Notifications
You must be signed in to change notification settings - Fork 8.2k
devicetree: Add helper macros for GPIO element/array initialization #23795
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,6 +190,94 @@ extern "C" { | |
| #define DT_INST_GPIO_FLAGS(inst, gpio_pha) \ | ||
| DT_INST_GPIO_FLAGS_BY_IDX(inst, gpio_pha, 0) | ||
|
|
||
| /** | ||
| * @brief Create a struct initializer for a "gpio" phandle-array element | ||
| * | ||
| * The struct initializer will be of the form: | ||
| * | ||
| * { label, pin, flags }, | ||
| * | ||
| * Example devicetree fragment: | ||
| * | ||
| * gpio1: gpio@... { | ||
| * label = "GPIO_1"; | ||
| * }; | ||
| * | ||
| * gpio2: gpio@... { | ||
| * label = "GPIO_2"; | ||
| * }; | ||
| * | ||
| * n: node { | ||
| * gpios = <&gpio1 10 20>, <&gpio2 30 40>; | ||
| * }; | ||
| * | ||
| * Example usage: | ||
| * | ||
| * DT_GPIO_ELEM(DT_NODELABEL(n), gpios, 1) | ||
| * | ||
| * Will produce the following struct initializer: | ||
| * | ||
| * { "GPIO_2", 30, 40 }, | ||
| * | ||
| * The idx element is placed first so that the macro will be usable by | ||
| * UTIL_LISTIFY | ||
| * | ||
| * @param idx into the gpio_pha phandle-array | ||
| * @param node_id node identifier | ||
| * @param gpio_pha lowercase-and-underscores GPIO property with | ||
| * type "phandle-array" | ||
| * @return a struct initializer for the give index "idx" into the | ||
| * "phandle-array" gpio_pha | ||
| */ | ||
| #define DT_GPIO_ELEM(idx, node_id, gpio_pha) \ | ||
| { \ | ||
| DT_GPIO_LABEL_BY_IDX(node_id, gpio_pha, idx), \ | ||
| DT_GPIO_PIN_BY_IDX(node_id, gpio_pha, idx), \ | ||
| DT_GPIO_FLAGS_BY_IDX(node_id, gpio_pha, idx), \ | ||
| }, | ||
|
|
||
| /** | ||
| * @brief Create an array initializer for a "gpio" phandle-array | ||
| * | ||
| * The array initializer will be of the form: | ||
| * | ||
| * { | ||
| * { label[0], pin[0], flags[0] } | ||
| * ... | ||
| * { label[n-1], pin[n-1], flags[n-1] }, | ||
| * } | ||
| * | ||
| * Example devicetree fragment: | ||
| * | ||
| * gpio1: gpio@... { | ||
| * label = "GPIO_1"; | ||
| * }; | ||
| * | ||
| * gpio2: gpio@... { | ||
| * label = "GPIO_2"; | ||
| * }; | ||
| * | ||
| * n: node { | ||
| * gpios = <&gpio1 10 20>, <&gpio2 30 40>; | ||
| * }; | ||
| * | ||
| * Example usage: | ||
| * | ||
| * DT_GPIO_LISTIFY(DT_NODELABEL(n), gpios) | ||
| * | ||
| * Will produce: | ||
| * | ||
| * { { "GPIO_1", 10, 20 }, { "GPIO_2", 30, 40 }, } | ||
| * | ||
| * @param node_id node identifier | ||
| * @param gpio_pha lowercase-and-underscores GPIO property with | ||
| * type "phandle-array" | ||
| * @return an array initializer for the given "phandle-array" gpio_pha | ||
| */ | ||
| #define DT_GPIO_LISTIFY(node_id, gpio_pha) \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be better to let the user pass the macro here as an argument instead of assuming DT_GPIO_ELEM? Keeps the API generic in cases where it's not a label/pin/flags always. |
||
| { UTIL_LISTIFY(DT_PROP_LEN(node_id, gpio_pha), DT_GPIO_ELEM, \ | ||
| node_id, gpio_pha) } | ||
|
|
||
| /** | ||
| * @} | ||
| */ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What do you think about the name DT_GPIO_LPF_AT_IDX?
The other phandle array macros also take arguments in (node_id, gpio_pha, idx) order.
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.
DT_GPIO_CELLS_AT_IDXwould be more consistent with the underlying devicetree terminology and would be highlight the similarity with other phandle-valued aggregates. I really find_LPF_to be obscure. (Pins, Flags, what is L?)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.
I think L is label
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.
OK, not obvious especially if label goes away. I'd rather find a name that covers all phandle+specifiers so we can use it consistently for
DT_PWM_,DT_IOCHANNEL_, ....CELLSignores the phandle, so maybeDT_GPIO_PHCELLS_? Ideally when the phandle reference changes from a label to an identifier we wouldn't have to change the name, just the definition of the macro and of the structure into which it should be stored.But really this PR is jumping to a partial solution for #23691 without addressing the other part: eliminating the custom
struct sx1276_dio. We do not need a global macro creating precedent and adding new names to convert lora/sx1276.c; that file can use a local define as I did in #23245 (review)