Zephyr API Documentation
4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
mux.h
Go to the documentation of this file.
1
/*
2
* SPDX-FileCopyrightText: 2026 NXP
3
*
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
19
20
#ifndef ZEPHYR_INCLUDE_DEVICETREE_MUX_H_
21
#define ZEPHYR_INCLUDE_DEVICETREE_MUX_H_
22
23
#include <
zephyr/device.h
>
24
#include <
zephyr/devicetree.h
>
25
#include <
zephyr/sys/util.h
>
26
27
#ifdef __cplusplus
28
extern
"C"
{
29
#endif
30
37
39
40
/* Helper that emits one cell value for DT_FOREACH_PHA_CELL_BY_IDX_SEP. */
41
#define Z_MUX_CELL_VAL(node_id, pha, idx, cell) \
42
DT_PHA_BY_IDX(node_id, pha, idx, cell)
43
44
/* Number of cells in the idx'th element of a phandle-array property. */
45
#define Z_MUX_PHA_NUM_CELLS(node_id, pha, idx) \
46
DT_PHA_NUM_CELLS_BY_IDX(node_id, pha, idx)
47
48
/* Internal storage identifier generators (mux-controls). */
49
50
#define Z_MUX_CTRL_CELLS_NAME(node_id, idx) \
51
DT_CAT4(zpriv_mux_ctrl_cells_, node_id, _, idx)
52
53
#define Z_MUX_CTRL_OBJ_NAME(node_id, idx) \
54
DT_CAT4(zpriv_mux_ctrl_, node_id, _, idx)
55
56
/* Internal storage identifier generators (mux-states). */
57
58
#define Z_MUX_STATE_CELLS_NAME(node_id, idx) \
59
DT_CAT4(zpriv_mux_state_cells_, node_id, _, idx)
60
61
#define Z_MUX_STATE_CTRL_NAME(node_id, idx) \
62
DT_CAT4(zpriv_mux_state_ctrl_, node_id, _, idx)
63
64
#define Z_MUX_STATE_OBJ_NAME(node_id, idx) \
65
DT_CAT4(zpriv_mux_state_, node_id, _, idx)
66
67
/* The first (N - 1) cells form the addressing; cell at index (N - 1) is the
68
* state. The cells[] array stores only the addressing portion so the embedded
69
* mux_control has the same shape as mux-controls-derived ones. The trailing
70
* state value is captured into mux_state.state by position (last argument),
71
* not by name, so backends are free to name the trailing cell whatever fits
72
* their hardware ("state", "input", "source", ...).
73
*
74
* GET_ARGS_FIRST_N(N, x0, x1, ..., xK) keeps the first N arguments. Combined
75
* with NUM_VA_ARGS_LESS_1(...) it yields "everything except the last", which
76
* is exactly the addressing portion of a mux-states specifier.
77
*
78
* GET_ARG_N(N, x0, x1, ..., xK) is 1-indexed, so GET_ARG_N(K, ...) over a
79
* list of K cells yields the last one (the state value).
80
*
81
* For 1-cell mux-states (trailing state cell only, no addressing) the cells
82
* array is empty (len == 0).
83
*/
84
#define Z_MUX_STATE_ADDRESSING_CELLS(node_id, idx) \
85
GET_ARGS_FIRST_N( \
86
NUM_VA_ARGS_LESS_1( \
87
DT_FOREACH_PHA_CELL_BY_IDX_SEP(node_id, mux_states, idx, \
88
Z_MUX_CELL_VAL, (,))), \
89
DT_FOREACH_PHA_CELL_BY_IDX_SEP(node_id, mux_states, idx, Z_MUX_CELL_VAL, (,)))
90
91
#define Z_MUX_STATE_LAST_CELL(node_id, idx) \
92
GET_ARG_N(Z_MUX_PHA_NUM_CELLS(node_id, mux_states, idx), \
93
DT_FOREACH_PHA_CELL_BY_IDX_SEP(node_id, mux_states, idx, Z_MUX_CELL_VAL, (,)))
94
96
132
#define MUX_CONTROL_DT_GET_BY_IDX(node_id, idx) (&Z_MUX_CTRL_OBJ_NAME(node_id, idx))
133
152
#define MUX_CONTROL_DT_GET(node_id) MUX_CONTROL_DT_GET_BY_IDX(node_id, 0)
153
177
#define MUX_CONTROL_DT_GET_BY_NAME(node_id, name) \
178
MUX_CONTROL_DT_GET_BY_IDX(node_id, \
179
DT_PHA_ELEM_IDX_BY_NAME(node_id, mux_controls, name))
180
211
#define MUX_STATE_DT_GET_BY_IDX(node_id, idx) (&Z_MUX_STATE_OBJ_NAME(node_id, idx))
212
231
#define MUX_STATE_DT_GET(node_id) MUX_STATE_DT_GET_BY_IDX(node_id, 0)
232
255
#define MUX_STATE_DT_GET_BY_NAME(node_id, name) \
256
MUX_STATE_DT_GET_BY_IDX(node_id, \
257
DT_PHA_ELEM_IDX_BY_NAME(node_id, mux_states, name))
258
286
#define MUX_CONTROL_DT_DEV_GET_BY_IDX(node_id, idx) \
287
DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, mux_controls, idx))
288
296
#define MUX_CONTROL_DT_DEV_GET(node_id) MUX_CONTROL_DT_DEV_GET_BY_IDX(node_id, 0)
297
326
#define MUX_STATE_DT_DEV_GET_BY_IDX(node_id, idx) \
327
DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, mux_states, idx))
328
336
#define MUX_STATE_DT_DEV_GET(node_id) MUX_STATE_DT_DEV_GET_BY_IDX(node_id, 0)
337
339
340
#define Z_MUX_STATE_DEFINE_FOR_EACH(node_id, prop, idx) \
341
MUX_STATE_DT_SPEC_DEFINE_BY_IDX(node_id, idx);
342
344
382
#define MUX_STATE_DT_SPEC_DEFINE_ALL(node_id) \
383
DT_FOREACH_PROP_ELEM(node_id, mux_states, Z_MUX_STATE_DEFINE_FOR_EACH)
384
390
#define MUX_STATE_DT_INST_SPEC_DEFINE_ALL(inst) \
391
MUX_STATE_DT_SPEC_DEFINE_ALL(DT_DRV_INST(inst))
392
396
397
#ifdef __cplusplus
398
}
399
#endif
400
401
#endif
/* ZEPHYR_INCLUDE_DEVICETREE_MUX_H_ */
device.h
devicetree.h
Devicetree main header.
util.h
Misc utilities.
zephyr
devicetree
mux.h
Generated on
for Zephyr API Documentation by
1.16.1