Skip to content

Commit e060e4c

Browse files
fabiobaltierikartben
authored andcommitted
device: add a DEVICE_DT_GET_BY_IDX macro
Add a DEVICE_DT_GET_BY_IDX macro to get a struct device reference for a phandles node. This can be used directly as an argument of macros such as DT_INST_FOREACH_PROP_ELEM_SEP. Signed-off-by: Fabio Baltieri <[email protected]>
1 parent e161ad6 commit e060e4c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

include/zephyr/device.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,22 @@ typedef int16_t device_handle_t;
346346
COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(node_id), \
347347
(DEVICE_DT_GET(node_id)), (NULL))
348348

349+
/**
350+
* @brief Get a @ref device reference from a devicetree phandles by idx.
351+
*
352+
* Returns a pointer to a device object referenced by a phandles property, by idx.
353+
*
354+
* @param node_id A devicetree node identifier
355+
* @param prop lowercase-and-underscores property with type `phandle`,
356+
* `phandles`, or `phandle-array`
357+
* @param idx logical index into @p phs, which must be zero if @p phs
358+
* has type `phandle`
359+
*
360+
* @return A pointer to the device object created for that node
361+
*/
362+
#define DEVICE_DT_GET_BY_IDX(node_id, prop, idx) \
363+
DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx))
364+
349365
/**
350366
* @brief Obtain a pointer to a device object by name
351367
*

0 commit comments

Comments
 (0)