Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Devicetree MUX API

Macros

#define MUX_CONTROL_DT_GET_BY_IDX(node_id, idx)
 Get a pointer to the mux_control object defined by MUX_CONTROL_DT_SPEC_DEFINE_BY_IDX().
#define MUX_CONTROL_DT_GET(node_id)
 Equivalent to MUX_CONTROL_DT_GET_BY_IDX(node_id, 0).
#define MUX_CONTROL_DT_GET_BY_NAME(node_id, name)
 Get a pointer to the mux_control object defined by MUX_CONTROL_DT_SPEC_DEFINE_BY_NAME().
#define MUX_STATE_DT_GET_BY_IDX(node_id, idx)
 Get a pointer to the mux_state object defined by MUX_STATE_DT_SPEC_DEFINE_BY_IDX().
#define MUX_STATE_DT_GET(node_id)
 Equivalent to MUX_STATE_DT_GET_BY_IDX(node_id, 0).
#define MUX_STATE_DT_GET_BY_NAME(node_id, name)
 Get a pointer to the mux_state object defined by MUX_STATE_DT_SPEC_DEFINE_BY_NAME().
#define MUX_CONTROL_DT_DEV_GET_BY_IDX(node_id, idx)
 Get the MUX controller device pointer for a mux-controls entry.
#define MUX_CONTROL_DT_DEV_GET(node_id)
 Equivalent to MUX_CONTROL_DT_DEV_GET_BY_IDX(node_id, 0).
#define MUX_STATE_DT_DEV_GET_BY_IDX(node_id, idx)
 Get the MUX controller device pointer for a mux-states entry.
#define MUX_STATE_DT_DEV_GET(node_id)
 Equivalent to MUX_STATE_DT_DEV_GET_BY_IDX(node_id, 0).
#define MUX_STATE_DT_SPEC_DEFINE_ALL(node_id)
 Define a mux_state object for every entry in a node's mux-states property.
#define MUX_STATE_DT_INST_SPEC_DEFINE_ALL(inst)
 Equivalent to MUX_STATE_DT_SPEC_DEFINE_ALL() for DT_DRV_INST(inst).

Detailed Description

Macro Definition Documentation

◆ MUX_CONTROL_DT_DEV_GET

#define MUX_CONTROL_DT_DEV_GET ( node_id)

#include <zephyr/devicetree/mux.h>

Value:
#define MUX_CONTROL_DT_DEV_GET_BY_IDX(node_id, idx)
Get the MUX controller device pointer for a mux-controls entry.
Definition mux.h:286

Equivalent to MUX_CONTROL_DT_DEV_GET_BY_IDX(node_id, 0).

Parameters
node_idDevicetree node identifier of the consumer.
Returns
Pointer to the struct device for the first MUX controller.
See also
MUX_CONTROL_DT_DEV_GET_BY_IDX()

◆ MUX_CONTROL_DT_DEV_GET_BY_IDX

#define MUX_CONTROL_DT_DEV_GET_BY_IDX ( node_id,
idx )

#include <zephyr/devicetree/mux.h>

Value:
DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, mux_controls, idx))
#define DEVICE_DT_GET(node_id)
Get a device reference from a devicetree node identifier.
Definition device.h:317
#define DT_PHANDLE_BY_IDX(node_id, prop, idx)
Get a node identifier for a phandle in a property.
Definition devicetree.h:1908

Get the MUX controller device pointer for a mux-controls entry.

Equivalent to looking up the phandle of mux-controls at index idx and fetching its struct device pointer with DEVICE_DT_GET(). Use the returned device with mux_control_set() (and friends).

Example devicetree fragment:

mux0: mux-controller@... { compatible = "vendor,demux"; ... };
mux1: mux-controller@... { compatible = "vendor,demux"; ... };

n: node {
        mux-controls = <&mux0 5>, <&mux1 9>;
};

Example usage:

const struct device *d0 = MUX_CONTROL_DT_DEV_GET_BY_IDX(DT_NODELABEL(n), 0); // &mux0
const struct device *d1 = MUX_CONTROL_DT_DEV_GET_BY_IDX(DT_NODELABEL(n), 1); // &mux1
Parameters
node_idDevicetree node identifier of the consumer.
idxLogical index into the mux-controls property.
Returns
Pointer to the struct device for the MUX controller at index idx.
See also
DEVICE_DT_GET()

◆ MUX_CONTROL_DT_GET

#define MUX_CONTROL_DT_GET ( node_id)

#include <zephyr/devicetree/mux.h>

Value:
#define MUX_CONTROL_DT_GET_BY_IDX(node_id, idx)
Get a pointer to the mux_control object defined by MUX_CONTROL_DT_SPEC_DEFINE_BY_IDX().
Definition mux.h:132

Equivalent to MUX_CONTROL_DT_GET_BY_IDX(node_id, 0).

Example devicetree fragment:

n: node {
        mux-controls = <&mux0 5>;
};

Example usage:

MUX_CONTROL_DT_SPEC_DEFINE(DT_NODELABEL(n));
const struct mux_control *m = MUX_CONTROL_DT_GET(DT_NODELABEL(n));
Parameters
node_idDevicetree node identifier of the consumer.
Returns
Pointer to a struct mux_control for the first entry.
See also
MUX_CONTROL_DT_GET_BY_IDX()

◆ MUX_CONTROL_DT_GET_BY_IDX

#define MUX_CONTROL_DT_GET_BY_IDX ( node_id,
idx )

#include <zephyr/devicetree/mux.h>

Value:
(&Z_MUX_CTRL_OBJ_NAME(node_id, idx))

Get a pointer to the mux_control object defined by MUX_CONTROL_DT_SPEC_DEFINE_BY_IDX().

The MUX_CONTROL_DT_SPEC_DEFINE_BY_IDX() macro that allocates the underlying storage lives in <zephyr/drivers/mux.h>; this macro just returns its address.

Example devicetree fragment:

mux0: mux-controller@... {
        compatible = "vendor,demux";
        #mux-control-cells = <1>;
        ...
};

n: node {
        mux-controls = <&mux0 5>, <&mux0 7>;
};

Example usage:

MUX_CONTROL_DT_SPEC_DEFINE_BY_IDX(DT_NODELABEL(n), 0);
MUX_CONTROL_DT_SPEC_DEFINE_BY_IDX(DT_NODELABEL(n), 1);

const struct mux_control *m0 =
        MUX_CONTROL_DT_GET_BY_IDX(DT_NODELABEL(n), 0);  // channel 5
const struct mux_control *m1 =
        MUX_CONTROL_DT_GET_BY_IDX(DT_NODELABEL(n), 1);  // channel 7
Parameters
node_idDevicetree node identifier of the consumer.
idxLogical index into the mux-controls property.
Returns
Pointer to a struct mux_control.
See also
MUX_CONTROL_DT_SPEC_DEFINE_BY_IDX()

◆ MUX_CONTROL_DT_GET_BY_NAME

#define MUX_CONTROL_DT_GET_BY_NAME ( node_id,
name )

#include <zephyr/devicetree/mux.h>

Value:
DT_PHA_ELEM_IDX_BY_NAME(node_id, mux_controls, name))
#define DT_PHA_ELEM_IDX_BY_NAME(node_id, pha, name)
Get the index of a phandle array element by name.
Definition devicetree.h:4240

Get a pointer to the mux_control object defined by MUX_CONTROL_DT_SPEC_DEFINE_BY_NAME().

Example devicetree fragment:

n: node {
        mux-controls = <&mux0 5>, <&mux0 7>;
        mux-control-names = "phase_a", "phase_b";
};

Example usage:

MUX_CONTROL_DT_SPEC_DEFINE_BY_NAME(DT_NODELABEL(n), phase_a);
const struct mux_control *ma =
        MUX_CONTROL_DT_GET_BY_NAME(DT_NODELABEL(n), phase_a);  // channel 5
Parameters
node_idDevicetree node identifier of the consumer.
nameLowercase-and-underscores name from the mux-control-names property.
Returns
Pointer to a struct mux_control for the named entry.
See also
MUX_CONTROL_DT_GET_BY_IDX()

◆ MUX_STATE_DT_DEV_GET

#define MUX_STATE_DT_DEV_GET ( node_id)

#include <zephyr/devicetree/mux.h>

Value:
#define MUX_STATE_DT_DEV_GET_BY_IDX(node_id, idx)
Get the MUX controller device pointer for a mux-states entry.
Definition mux.h:326

Equivalent to MUX_STATE_DT_DEV_GET_BY_IDX(node_id, 0).

Parameters
node_idDevicetree node identifier of the consumer.
Returns
Pointer to the struct device for the first MUX controller.
See also
MUX_STATE_DT_DEV_GET_BY_IDX()

◆ MUX_STATE_DT_DEV_GET_BY_IDX

#define MUX_STATE_DT_DEV_GET_BY_IDX ( node_id,
idx )

#include <zephyr/devicetree/mux.h>

Value:
DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, mux_states, idx))

Get the MUX controller device pointer for a mux-states entry.

Equivalent to looking up the phandle of mux-states at index idx and fetching its struct device pointer with DEVICE_DT_GET(). Pair with MUX_STATE_DT_GET_BY_IDX() to feed mux_state_apply():

mux_state_apply(MUX_STATE_DT_DEV_GET_BY_IDX(node, idx),
                MUX_STATE_DT_GET_BY_IDX(node, idx));

Example devicetree fragment:

mux0: mux-controller@... { compatible = "vendor,demux"; ... };

n: node {
        mux-states = <&mux0 5 2>;
};

Example usage:

const struct device *dev = MUX_STATE_DT_DEV_GET_BY_IDX(DT_NODELABEL(n), 0); // &mux0
Parameters
node_idDevicetree node identifier of the consumer.
idxLogical index into the mux-states property.
Returns
Pointer to the struct device for the MUX controller at index idx.
See also
DEVICE_DT_GET()

◆ MUX_STATE_DT_GET

#define MUX_STATE_DT_GET ( node_id)

#include <zephyr/devicetree/mux.h>

Value:
#define MUX_STATE_DT_GET_BY_IDX(node_id, idx)
Get a pointer to the mux_state object defined by MUX_STATE_DT_SPEC_DEFINE_BY_IDX().
Definition mux.h:211

Equivalent to MUX_STATE_DT_GET_BY_IDX(node_id, 0).

Example devicetree fragment:

n: node {
        mux-states = <&mux0 5 2>;
};

Example usage:

MUX_STATE_DT_SPEC_DEFINE(DT_NODELABEL(n));
const struct mux_state *s = MUX_STATE_DT_GET(DT_NODELABEL(n));
Parameters
node_idDevicetree node identifier of the consumer.
Returns
Pointer to a struct mux_state for the first entry.
See also
MUX_STATE_DT_GET_BY_IDX()

◆ MUX_STATE_DT_GET_BY_IDX

#define MUX_STATE_DT_GET_BY_IDX ( node_id,
idx )

#include <zephyr/devicetree/mux.h>

Value:
(&Z_MUX_STATE_OBJ_NAME(node_id, idx))

Get a pointer to the mux_state object defined by MUX_STATE_DT_SPEC_DEFINE_BY_IDX().

Example devicetree fragment:

mux0: mux-controller@... {
        compatible = "vendor,demux";
        #mux-control-cells = <1>;
        #mux-state-cells   = <2>;
        ...
};

n: node {
        mux-states = <&mux0 5 2>, <&mux0 7 3>;
        // entry 0: channel=5, state=2
        // entry 1: channel=7, state=3
};

Example usage:

MUX_STATE_DT_SPEC_DEFINE_BY_IDX(DT_NODELABEL(n), 0);
const struct mux_state *s0 = MUX_STATE_DT_GET_BY_IDX(DT_NODELABEL(n), 0);
// s0->control->cells[0] == 5, s0->state == 2
Parameters
node_idDevicetree node identifier of the consumer.
idxLogical index into the mux-states property.
Returns
Pointer to a struct mux_state.
See also
MUX_STATE_DT_SPEC_DEFINE_BY_IDX()

◆ MUX_STATE_DT_GET_BY_NAME

#define MUX_STATE_DT_GET_BY_NAME ( node_id,
name )

#include <zephyr/devicetree/mux.h>

Value:
DT_PHA_ELEM_IDX_BY_NAME(node_id, mux_states, name))

Get a pointer to the mux_state object defined by MUX_STATE_DT_SPEC_DEFINE_BY_NAME().

Example devicetree fragment:

n: node {
        mux-states = <&mux0 5 2>, <&mux0 7 3>;
        mux-state-names = "default", "alt";
};

Example usage:

MUX_STATE_DT_SPEC_DEFINE_BY_NAME(DT_NODELABEL(n), default);
const struct mux_state *def = MUX_STATE_DT_GET_BY_NAME(DT_NODELABEL(n), default);
Parameters
node_idDevicetree node identifier of the consumer.
nameLowercase-and-underscores name from the mux-state-names property.
Returns
Pointer to a struct mux_state for the named entry.
See also
MUX_STATE_DT_GET_BY_IDX()

◆ MUX_STATE_DT_INST_SPEC_DEFINE_ALL

#define MUX_STATE_DT_INST_SPEC_DEFINE_ALL ( inst)

#include <zephyr/devicetree/mux.h>

Value:
#define DT_DRV_INST(inst)
Node identifier for an instance of a DT_DRV_COMPAT compatible.
Definition devicetree.h:4333
#define MUX_STATE_DT_SPEC_DEFINE_ALL(node_id)
Define a mux_state object for every entry in a node's mux-states property.
Definition mux.h:382

Equivalent to MUX_STATE_DT_SPEC_DEFINE_ALL() for DT_DRV_INST(inst).

Parameters
instDT_DRV_COMPAT instance number.

◆ MUX_STATE_DT_SPEC_DEFINE_ALL

#define MUX_STATE_DT_SPEC_DEFINE_ALL ( node_id)

#include <zephyr/devicetree/mux.h>

Value:
DT_FOREACH_PROP_ELEM(node_id, mux_states, Z_MUX_STATE_DEFINE_FOR_EACH)
#define DT_FOREACH_PROP_ELEM(node_id, prop, fn)
Invokes fn for each element in the value of property prop.
Definition devicetree.h:3618

Define a mux_state object for every entry in a node's mux-states property.

Convenience over calling MUX_STATE_DT_SPEC_DEFINE_BY_IDX() in a loop. The emitted mux_state storage is then referenced from a consumer- defined entry array; the consumer chooses the entry struct shape.

Example devicetree fragment:

mux0: mux-controller@... { compatible = "vendor,demux"; ... };
mux1: mux-controller@... { compatible = "vendor,demux"; ... };

consumer: my-consumer {
        mux-states = <&mux0 5 2>, <&mux1 9 3>;
};

Example usage:

struct my_mux_entry {
        const struct device *dev;
        const struct mux_state *state;
};

#define MY_ENTRY_INIT(node_id, prop, idx)                       \
        { .dev   = MUX_STATE_DT_DEV_GET_BY_IDX(node_id, idx),   \
          .state = MUX_STATE_DT_GET_BY_IDX(node_id, idx), },

MUX_STATE_DT_SPEC_DEFINE_ALL(DT_NODELABEL(consumer));
static const struct my_mux_entry entries[] = {
        DT_FOREACH_PROP_ELEM(DT_NODELABEL(consumer), mux_states,
                             MY_ENTRY_INIT)
};
Parameters
node_idDevicetree node identifier of the consumer.
See also
MUX_STATE_DT_SPEC_DEFINE_BY_IDX()