|
41 | 41 | * |
42 | 42 | * _ENUM_IDX: property's value as an index into bindings enum |
43 | 43 | * _ENUM_TOKEN: property's value as a token into bindings enum (string |
44 | | - * enum values are identifiers) |
45 | | - * _ENUM_UPPER_TOKEN: like _ENUM_TOKEN, but uppercased |
| 44 | + * enum values are identifiers) [deprecated, use _STRING_TOKEN] |
| 45 | + * _ENUM_UPPER_TOKEN: like _ENUM_TOKEN, but uppercased [deprecated, use |
| 46 | + * _STRING_UPPER_TOKEN] |
46 | 47 | * _EXISTS: property is defined |
47 | 48 | * _FOREACH_PROP_ELEM: helper for "iterating" over values in the property |
48 | 49 | * _FOREACH_PROP_ELEM_VARGS: foreach functions with variable number of arguments |
|
55 | 56 | * _NAME_<name>_PH: phandle array's phandle by name |
56 | 57 | * _NAME_<name>_VAL_<val>: phandle array's property specifier by name |
57 | 58 | * _NAME_<name>_VAL_<val>_EXISTS: cell value exists, by name |
| 59 | + * _STRING_TOKEN: string property's value as a token |
| 60 | + * _STRING_UPPER_TOKEN: like _STRING_TOKEN, but uppercased |
58 | 61 | */ |
59 | 62 |
|
60 | 63 | /** |
|
702 | 705 | COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \ |
703 | 706 | (DT_ENUM_IDX(node_id, prop)), (default_idx_value)) |
704 | 707 |
|
| 708 | +/** |
| 709 | + * @brief Get a string property's value as a token. |
| 710 | + * |
| 711 | + * This removes "the quotes" from string-valued properties, and converts |
| 712 | + * non-alphanumeric characters to underscores. That can be useful, for example, |
| 713 | + * when programmatically using the value to form a C variable or code. |
| 714 | + * |
| 715 | + * DT_STRING_TOKEN() can only be used for properties with string type. |
| 716 | + * |
| 717 | + * It is an error to use DT_STRING_TOKEN() in other circumstances. |
| 718 | + * |
| 719 | + * Example devicetree fragment: |
| 720 | + * |
| 721 | + * n1: node-1 { |
| 722 | + * prop = "foo"; |
| 723 | + * }; |
| 724 | + * n2: node-2 { |
| 725 | + * prop = "FOO"; |
| 726 | + * } |
| 727 | + * n3: node-3 { |
| 728 | + * prop = "123 foo"; |
| 729 | + * }; |
| 730 | + * |
| 731 | + * Example bindings fragment: |
| 732 | + * |
| 733 | + * properties: |
| 734 | + * prop: |
| 735 | + * type: string |
| 736 | + * |
| 737 | + * Example usage: |
| 738 | + * |
| 739 | + * DT_STRING_TOKEN(DT_NODELABEL(n1), prop) // foo |
| 740 | + * DT_STRING_TOKEN(DT_NODELABEL(n2), prop) // FOO |
| 741 | + * DT_STRING_TOKEN(DT_NODELABEL(n3), prop) // 123_foo |
| 742 | + * |
| 743 | + * Notice how: |
| 744 | + * |
| 745 | + * - Unlike C identifiers, the property values may begin with a |
| 746 | + * number. It's the user's responsibility not to use such values as |
| 747 | + * the name of a C identifier. |
| 748 | + * |
| 749 | + * - The uppercased "FOO" in the DTS remains @p FOO as a token. It is |
| 750 | + * *not* converted to @p foo. |
| 751 | + * |
| 752 | + * - The whitespace in the DTS "123 foo" string is converted to @p |
| 753 | + * 123_foo as a token. |
| 754 | + * |
| 755 | + * @param node_id node identifier |
| 756 | + * @param prop lowercase-and-underscores property string name |
| 757 | + * @return the value of @p prop as a token, i.e. without any quotes |
| 758 | + * and with special characters converted to underscores |
| 759 | + */ |
| 760 | +#define DT_STRING_TOKEN(node_id, prop) \ |
| 761 | + DT_CAT4(node_id, _P_, prop, _STRING_TOKEN) |
| 762 | + |
| 763 | +/** |
| 764 | + * @brief Like DT_STRING_TOKEN(), but uppercased. |
| 765 | + * |
| 766 | + * This removes "the quotes and capitalize" from string-valued properties, and |
| 767 | + * converts non-alphanumeric characters to underscores. That can be useful, for |
| 768 | + * example, when programmatically using the value to form a C variable or code. |
| 769 | + * |
| 770 | + * DT_STRING_UPPER_TOKEN() can only be used for properties with string type. |
| 771 | + * |
| 772 | + * It is an error to use DT_STRING_UPPER_TOKEN() in other circumstances. |
| 773 | + * |
| 774 | + * Example devicetree fragment: |
| 775 | + * |
| 776 | + * n1: node-1 { |
| 777 | + * prop = "foo"; |
| 778 | + * }; |
| 779 | + * n2: node-2 { |
| 780 | + * prop = "123 foo"; |
| 781 | + * }; |
| 782 | + * |
| 783 | + * Example bindings fragment: |
| 784 | + * |
| 785 | + * properties: |
| 786 | + * prop: |
| 787 | + * type: string |
| 788 | + * |
| 789 | + * Example usage: |
| 790 | + * |
| 791 | + * DT_STRING_UPPER_TOKEN(DT_NODELABEL(n1), prop) // FOO |
| 792 | + * DT_STRING_UPPER_TOKEN(DT_NODELABEL(n2), prop) // 123_FOO |
| 793 | + * |
| 794 | + * Notice how: |
| 795 | + * |
| 796 | + * - Unlike C identifiers, the property values may begin with a |
| 797 | + * number. It's the user's responsibility not to use such values as |
| 798 | + * the name of a C identifier. |
| 799 | + * |
| 800 | + * - The lowercased "foo" in the DTS becomes @p FOO as a token, i.e. |
| 801 | + * it is uppercased. |
| 802 | + * |
| 803 | + * - The whitespace in the DTS "123 foo" string is converted to @p |
| 804 | + * 123_FOO as a token, i.e. it is uppercased and whitespace becomes |
| 805 | + * an underscore. |
| 806 | + * |
| 807 | + * @param node_id node identifier |
| 808 | + * @param prop lowercase-and-underscores property string name |
| 809 | + * @return the value of @p prop as a token, i.e. without any quotes |
| 810 | + * and with special characters converted to underscores |
| 811 | + */ |
| 812 | +#define DT_STRING_UPPER_TOKEN(node_id, prop) \ |
| 813 | + DT_CAT4(node_id, _P_, prop, _STRING_UPPER_TOKEN) |
| 814 | + |
705 | 815 | /** |
706 | 816 | * @brief Get an enumeration property's value as a token. |
707 | 817 | * |
|
764 | 874 | * and with special characters converted to underscores |
765 | 875 | */ |
766 | 876 | #define DT_ENUM_TOKEN(node_id, prop) \ |
| 877 | + __DEPRECATED_MACRO \ |
767 | 878 | DT_CAT4(node_id, _P_, prop, _ENUM_TOKEN) |
768 | 879 |
|
769 | 880 | /** |
|
823 | 934 | * underscores |
824 | 935 | */ |
825 | 936 | #define DT_ENUM_UPPER_TOKEN(node_id, prop) \ |
| 937 | + __DEPRECATED_MACRO \ |
826 | 938 | DT_CAT4(node_id, _P_, prop, _ENUM_UPPER_TOKEN) |
827 | 939 |
|
828 | 940 | /* |
|
0 commit comments