Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
Bus helpers

Macros

#define DT_BUS(node_id)   DT_CAT(node_id, _BUS)
 Node's bus controller. More...
 
#define DT_BUS_LABEL(node_id)   DT_PROP(DT_BUS(node_id), label)
 Node's bus controller's label property. More...
 
#define DT_ON_BUS(node_id, bus)   IS_ENABLED(DT_CAT(node_id, _BUS_##bus))
 Is a node on a bus of a given type? More...
 

Detailed Description

Macro Definition Documentation

◆ DT_BUS

#define DT_BUS (   node_id)    DT_CAT(node_id, _BUS)

#include <include/devicetree.h>

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 {
        label = "I2C_CTLR";
        status = "okay";
        clock-frequency = < 100000 >;

        i2c_device: accelerometer@12 {
                ...
        };
};

Example usage:

DT_PROP(DT_BUS(DT_NODELABEL(i2c_device)), clock_frequency) // 100000
Parameters
node_idnode identifier
Returns
a node identifier for the node's bus controller

◆ DT_BUS_LABEL

#define DT_BUS_LABEL (   node_id)    DT_PROP(DT_BUS(node_id), label)

#include <include/devicetree.h>

Node's bus controller's label property.

Parameters
node_idnode identifier
Returns
the label property of the node's bus controller DT_BUS(node)

◆ DT_ON_BUS

#define DT_ON_BUS (   node_id,
  bus 
)    IS_ENABLED(DT_CAT(node_id, _BUS_##bus))

#include <include/devicetree.h>

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
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