|
435 | 435 | */ |
436 | 436 | #define DT_CHILD(node_id, child) UTIL_CAT(node_id, DT_S_PREFIX(child)) |
437 | 437 |
|
| 438 | +/** |
| 439 | + * @brief Get a node identifier for a child node by a reg address |
| 440 | + * |
| 441 | + * Example devicetree fragment: |
| 442 | + * |
| 443 | + * @code{.dts} |
| 444 | + * / { |
| 445 | + * soc-label: soc { |
| 446 | + * serial1: serial@40001000 { |
| 447 | + * status = "okay"; |
| 448 | + * current-speed = <115200>; |
| 449 | + * reg = <0x40001000 0x1000>; |
| 450 | + * ... |
| 451 | + * }; |
| 452 | + * }; |
| 453 | + * }; |
| 454 | + * @endcode |
| 455 | + * |
| 456 | + * Example usage with DT_PROP() to get the status of the |
| 457 | + * `serial@40001000` node: |
| 458 | + * |
| 459 | + * @code{.c} |
| 460 | + * #define SOC_NODE DT_NODELABEL(soc_label) |
| 461 | + * DT_PROP(DT_CHILD_BY_REG_ADDR(SOC_NODE, 0, 0x40001000), status) // "okay" |
| 462 | + * @endcode |
| 463 | + * |
| 464 | + * |
| 465 | + * @param node_id node identifier |
| 466 | + * @param idx Register address index for the child node. |
| 467 | + * @param addr Register address for the child node. Can be hexadecimal (prefix with 0x) or decimal |
| 468 | + * |
| 469 | + * @return node identifier for the child node with the reg address at a specified index |
| 470 | + */ |
| 471 | +#define DT_CHILD_BY_REG_ADDR(node_id, idx, addr) \ |
| 472 | + DT_CAT5(node_id, _CHILD_REG_IDX_, idx, _ADDR_, addr) |
| 473 | + |
| 474 | +/** |
| 475 | + * @brief Get a node identifier for a child node by a unit address |
| 476 | + * |
| 477 | + * Example devicetree fragment: |
| 478 | + * |
| 479 | + * @code{.dts} |
| 480 | + * / { |
| 481 | + * soc-label: soc { |
| 482 | + * serial1: serial@40001000 { |
| 483 | + * status = "okay"; |
| 484 | + * current-speed = <115200>; |
| 485 | + * reg = <0x40001000 0x1000>; |
| 486 | + * ... |
| 487 | + * }; |
| 488 | + * }; |
| 489 | + * }; |
| 490 | + * @endcode |
| 491 | + * |
| 492 | + * Example usage with DT_PROP() to get the status of the |
| 493 | + * `serial@40001000` node: |
| 494 | + * |
| 495 | + * @code{.c} |
| 496 | + * #define SOC_NODE DT_NODELABEL(soc_label) |
| 497 | + * DT_PROP(DT_CHILD_BY_UNIT_ADDR(SOC_NODE, 0x40001000), status) // "okay" |
| 498 | + * @endcode |
| 499 | + * |
| 500 | + * |
| 501 | + * @param node_id node identifier |
| 502 | + * @param addr Unit address for the child node. Can be hexadecimal (prefix with 0x) or decimal |
| 503 | + * |
| 504 | + * @return node identifier for the child node with the reg address at a specified index |
| 505 | + */ |
| 506 | +#define DT_CHILD_BY_UNIT_ADDR(node_id, addr) \ |
| 507 | + DT_CAT3(node_id, _CHILD_UNIT_ADDR_, addr) |
| 508 | + |
438 | 509 | /** |
439 | 510 | * @brief Get a node identifier for a status `okay` node with a compatible |
440 | 511 | * |
|
4066 | 4137 | #define DT_INST_CHILD(inst, child) \ |
4067 | 4138 | DT_CHILD(DT_DRV_INST(inst), child) |
4068 | 4139 |
|
| 4140 | +/** |
| 4141 | + * @brief Get a node identifier for a child node by a reg address of DT_DRV_INST(inst) |
| 4142 | + * |
| 4143 | + * @param inst instance number |
| 4144 | + * @param idx Register address index for the child node. |
| 4145 | + * @param addr Register address for the child node. Can be hexadecimal (prefix with 0x) or decimal |
| 4146 | + * |
| 4147 | + * @return node identifier for the child node with the reg address at a specified index |
| 4148 | + * |
| 4149 | + * @see DT_CHILD_BY_REG_ADDR |
| 4150 | + */ |
| 4151 | +#define DT_INST_CHILD_BY_REG_ADDR(inst, idx, addr) \ |
| 4152 | + DT_CHILD_BY_REG_ADDR(DT_DRV_INST(inst), idx, addr) |
| 4153 | + |
| 4154 | +/** |
| 4155 | + * @brief Get a node identifier for a child node by a unit address of DT_DRV_INST(inst) |
| 4156 | + * |
| 4157 | + * @param inst instance number |
| 4158 | + * @param addr Unit address for the child node. Can be hexadecimal (prefix with 0x) or decimal |
| 4159 | + * |
| 4160 | + * @return node identifier for the child node with the reg address at a specified index |
| 4161 | + * |
| 4162 | + * @see DT_CHILD_BY_UNIT_ADDR |
| 4163 | + */ |
| 4164 | +#define DT_INST_CHILD_BY_UNIT_ADDR(inst, addr) \ |
| 4165 | + DT_CHILD_BY_UNIT_ADDR(DT_DRV_INST(inst), addr) |
| 4166 | + |
4069 | 4167 | /** |
4070 | 4168 | * @brief Get the number of child nodes of a given node |
4071 | 4169 | * |
|
0 commit comments