Zephyr API Documentation 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Bus helpers

Macros

#define DT_BUS(node_id)
 Node's bus controller.
 
#define DT_ON_BUS(node_id, bus)
 Is a node on a bus of a given type?
 

Detailed Description

Macro Definition Documentation

◆ DT_BUS

#define DT_BUS ( node_id)

#include <zephyr/devicetree.h>

Value:
DT_CAT(node_id, _BUS)

Node's bus controller.

Get the node identifier of the node's bus controller. This can be used with DT_PROP() to get properties of the bus controller.

It is an error to use this with nodes which do not have bus controllers.

Example devicetree fragment:

i2c@deadbeef {
status = "okay";
clock-frequency = < 100000 >;
i2c_device: accelerometer@12 {
...
};
};

Example usage:

DT_PROP(DT_BUS(DT_NODELABEL(i2c_device)), clock_frequency) // 100000
#define DT_BUS(node_id)
Node's bus controller.
Definition devicetree.h:3754
#define DT_NODELABEL(label)
Get a node identifier for a node label.
Definition devicetree.h:196
#define DT_PROP(node_id, prop)
Get a devicetree property value.
Definition devicetree.h:745
Parameters
node_idnode identifier
Returns
a node identifier for the node's bus controller

◆ DT_ON_BUS

#define DT_ON_BUS ( node_id,
bus )

#include <zephyr/devicetree.h>

Value:
IS_ENABLED(DT_CAT3(node_id, _BUS_, bus))
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition util_macro.h:140

Is a node on a bus of a given type?

Example devicetree overlay:

&i2c0 {
temp: temperature-sensor@76 {
compatible = "vnd,some-sensor";
reg = <0x76>;
};
};

Example usage, assuming i2c0 is an I2C bus controller node, and therefore temp is on an I2C bus:

DT_ON_BUS(DT_NODELABEL(temp), i2c) // 1
DT_ON_BUS(DT_NODELABEL(temp), spi) // 0
#define DT_ON_BUS(node_id, bus)
Is a node on a bus of a given type?
Definition devicetree.h:3784
Parameters
node_idnode identifier
buslowercase-and-underscores bus type as a C token (i.e. without quotes)
Returns
1 if the node is on a bus of the given type, 0 otherwise