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

Macros

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

Detailed Description

Macro Definition Documentation

◆ DT_BUS

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

#include <zephyr/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 {
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:3365
#define DT_NODELABEL(label)
Get a node identifier for a node label.
Definition: devicetree.h:200
#define DT_PROP(node_id, prop)
Get a devicetree property value.
Definition: devicetree.h:617
Parameters
node_idnode identifier
Returns
a node identifier for the node's bus controller

◆ DT_ON_BUS

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

#include <zephyr/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
#define DT_ON_BUS(node_id, bus)
Is a node on a bus of a given type?
Definition: devicetree.h:3395
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