Zephyr API 3.6.99
Loading...
Searching...
No Matches
Vendor and model name helpers

Macros

#define DT_NODE_VENDOR_BY_IDX(node_id, idx)
 Get the vendor at index idx as a string literal.
 
#define DT_NODE_VENDOR_HAS_IDX(node_id, idx)
 Does a node's compatible property have a vendor at an index?
 
#define DT_NODE_VENDOR_BY_IDX_OR(node_id, idx, default_value)
 Like DT_NODE_VENDOR_BY_IDX(), but with a fallback to default_value.
 
#define DT_NODE_VENDOR_OR(node_id, default_value)
 Get the node's (only) vendor as a string literal.
 
#define DT_NODE_MODEL_BY_IDX(node_id, idx)
 Get the model at index "idx" as a string literal.
 
#define DT_NODE_MODEL_HAS_IDX(node_id, idx)
 Does a node's compatible property have a model at an index?
 
#define DT_NODE_MODEL_BY_IDX_OR(node_id, idx, default_value)
 Like DT_NODE_MODEL_BY_IDX(), but with a fallback to default_value.
 
#define DT_NODE_MODEL_OR(node_id, default_value)
 Get the node's (only) model as a string literal.
 

Detailed Description

Macro Definition Documentation

◆ DT_NODE_MODEL_BY_IDX

#define DT_NODE_MODEL_BY_IDX ( node_id,
idx )

#include <zephyr/devicetree.h>

Value:
DT_CAT3(node_id, _COMPAT_MODEL_IDX_, idx)

Get the model at index "idx" as a string literal.

The model is a string extracted from the compatible after the vendor prefix.

Example vendor-prefixes.txt:

 vnd        A stand-in for a real vendor
 zephyr     Zephyr-specific binding

Example devicetree fragment:

 n1: node-1 {
    compatible = "vnd,model1", "gpio", "zephyr,model2";
 };

Example usage:

 DT_NODE_MODEL_BY_IDX(DT_NODELABEL(n1), 0) // "model1"
 DT_NODE_MODEL_BY_IDX(DT_NODELABEL(n1), 2) // "model2"

Notice that the compatible at index 1 doesn't match any entries in the vendor prefix file and therefore index 1 is not a valid model index. Use DT_NODE_MODEL_HAS_IDX(node_id, idx) to determine if an index is valid.

Parameters
node_idnode identifier
idxindex of the model to return
Returns
string literal of the idx-th model

◆ DT_NODE_MODEL_BY_IDX_OR

#define DT_NODE_MODEL_BY_IDX_OR ( node_id,
idx,
default_value )

#include <zephyr/devicetree.h>

Value:
(DT_NODE_MODEL_BY_IDX(node_id, idx)), (default_value))
#define DT_NODE_MODEL_HAS_IDX(node_id, idx)
Does a node's compatible property have a model at an index?
Definition devicetree.h:2167
#define DT_NODE_MODEL_BY_IDX(node_id, idx)
Get the model at index "idx" as a string literal.
Definition devicetree.h:2152
#define COND_CODE_1(_flag, _if_1_code, _else_code)
Insert code depending on whether _flag expands to 1 or not.
Definition util_macro.h:179

Like DT_NODE_MODEL_BY_IDX(), but with a fallback to default_value.

If the value exists, this expands to DT_NODE_MODEL_BY_IDX(node_id, idx). The default_value parameter is not expanded in this case.

Otherwise, this expands to default_value.

Parameters
node_idnode identifier
idxindex of the model to return
Returns
string literal of the idx-th model
Parameters
default_valuea fallback value to expand to
Returns
string literal of the idx-th model or "default_value"

◆ DT_NODE_MODEL_HAS_IDX

#define DT_NODE_MODEL_HAS_IDX ( node_id,
idx )

#include <zephyr/devicetree.h>

Value:
IS_ENABLED(DT_CAT4(node_id, _COMPAT_MODEL_IDX_, idx, _EXISTS))
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition util_macro.h:124

Does a node's compatible property have a model at an index?

If this returns 1, then DT_NODE_MODEL_BY_IDX(node_id, idx) is valid. If it returns 0, it is an error to use DT_NODE_MODEL_BY_IDX(node_id, idx) with index "idx".

Parameters
node_idnode identifier
idxindex of the model to check
Returns
1 if "idx" is a valid model index, 0 otherwise.

◆ DT_NODE_MODEL_OR

#define DT_NODE_MODEL_OR ( node_id,
default_value )

#include <zephyr/devicetree.h>

Value:
DT_NODE_MODEL_BY_IDX_OR(node_id, 0, default_value)
#define DT_NODE_MODEL_BY_IDX_OR(node_id, idx, default_value)
Like DT_NODE_MODEL_BY_IDX(), but with a fallback to default_value.
Definition devicetree.h:2184

Get the node's (only) model as a string literal.

Equivalent to DT_NODE_MODEL_BY_IDX_OR(node_id, 0, default_value).

Parameters
node_idnode identifier
default_valuea fallback value to expand to

◆ DT_NODE_VENDOR_BY_IDX

#define DT_NODE_VENDOR_BY_IDX ( node_id,
idx )

#include <zephyr/devicetree.h>

Value:
DT_CAT3(node_id, _COMPAT_VENDOR_IDX_, idx)

Get the vendor at index idx as a string literal.

The vendor is a string extracted from vendor prefixes if an entry exists that matches the node's compatible prefix. There may be as many as one vendor prefixes file per directory in DTS_ROOT.

Example vendor-prefixes.txt:

 vnd        A stand-in for a real vendor
 zephyr     Zephyr-specific binding

Example devicetree fragment:

n1: node-1 {
compatible = "vnd,model1", "gpio", "zephyr,model2";
};

Example usage:

DT_NODE_VENDOR_BY_IDX(DT_NODELABEL(n1), 0) // "A stand-in for a real vendor"
DT_NODE_VENDOR_BY_IDX(DT_NODELABEL(n1), 2) // "Zephyr-specific binding"
#define DT_NODELABEL(label)
Get a node identifier for a node label.
Definition devicetree.h:200
#define DT_NODE_VENDOR_BY_IDX(node_id, idx)
Get the vendor at index idx as a string literal.
Definition devicetree.h:2076

Notice that the compatible at index 1 doesn't match any entries in the vendor prefix file and therefore index 1 is not a valid vendor index. Use DT_NODE_VENDOR_HAS_IDX(node_id, idx) to determine if an index is valid.

Parameters
node_idnode identifier
idxindex of the vendor to return
Returns
string literal of the idx-th vendor

◆ DT_NODE_VENDOR_BY_IDX_OR

#define DT_NODE_VENDOR_BY_IDX_OR ( node_id,
idx,
default_value )

#include <zephyr/devicetree.h>

Value:
(DT_NODE_VENDOR_BY_IDX(node_id, idx)), (default_value))
#define DT_NODE_VENDOR_HAS_IDX(node_id, idx)
Does a node's compatible property have a vendor at an index?
Definition devicetree.h:2091

Like DT_NODE_VENDOR_BY_IDX(), but with a fallback to default_value.

If the value exists, this expands to DT_NODE_VENDOR_BY_IDX(node_id, idx). The default_value parameter is not expanded in this case.

Otherwise, this expands to default_value.

Parameters
node_idnode identifier
idxindex of the vendor to return
Returns
string literal of the idx-th vendor
Parameters
default_valuea fallback value to expand to
Returns
string literal of the idx-th vendor or "default_value"

◆ DT_NODE_VENDOR_HAS_IDX

#define DT_NODE_VENDOR_HAS_IDX ( node_id,
idx )

#include <zephyr/devicetree.h>

Value:
IS_ENABLED(DT_CAT4(node_id, _COMPAT_VENDOR_IDX_, idx, _EXISTS))

Does a node's compatible property have a vendor at an index?

If this returns 1, then DT_NODE_VENDOR_BY_IDX(node_id, idx) is valid. If it returns 0, it is an error to use DT_NODE_VENDOR_BY_IDX(node_id, idx) with index idx.

Parameters
node_idnode identifier
idxindex of the vendor to check
Returns
1 if idx is a valid vendor index, 0 otherwise.

◆ DT_NODE_VENDOR_OR

#define DT_NODE_VENDOR_OR ( node_id,
default_value )

#include <zephyr/devicetree.h>

Value:
DT_NODE_VENDOR_BY_IDX_OR(node_id, 0, default_value)
#define DT_NODE_VENDOR_BY_IDX_OR(node_id, idx, default_value)
Like DT_NODE_VENDOR_BY_IDX(), but with a fallback to default_value.
Definition devicetree.h:2108

Get the node's (only) vendor as a string literal.

Equivalent to DT_NODE_VENDOR_BY_IDX_OR(node_id, 0, default_value).

Parameters
node_idnode identifier
default_valuea fallback value to expand to