|
| 1 | +/** |
| 2 | + * @file |
| 3 | + * @brief Display Devicetree macro public API header file. |
| 4 | + */ |
| 5 | + |
| 6 | +/* |
| 7 | + * Copyright (c) 2025 Abderrahmane JARMOUNI |
| 8 | + * |
| 9 | + * SPDX-License-Identifier: Apache-2.0 |
| 10 | + */ |
| 11 | + |
| 12 | +#ifndef ZEPHYR_INCLUDE_DEVICETREE_DISPLAY_H_ |
| 13 | +#define ZEPHYR_INCLUDE_DEVICETREE_DISPLAY_H_ |
| 14 | + |
| 15 | +#ifdef __cplusplus |
| 16 | +extern "C" { |
| 17 | +#endif |
| 18 | + |
| 19 | +/** |
| 20 | + * @defgroup devicetree-display Devicetree Display API |
| 21 | + * @ingroup devicetree |
| 22 | + * @{ |
| 23 | + */ |
| 24 | + |
| 25 | +/** |
| 26 | + * @brief Get display node identifier by logical index from "displays" property of node with |
| 27 | + * compatible "zephyr,displays" |
| 28 | + * |
| 29 | + * Example devicetree fragment: |
| 30 | + * |
| 31 | + * @code{.dts} |
| 32 | + * displays_node: my-displays { |
| 33 | + * compatible = "zephyr,displays"; |
| 34 | + * displays = <&n2 &n3>; |
| 35 | + * status = "okay"; |
| 36 | + * }; |
| 37 | + * |
| 38 | + * n2: node-2 { ... }; |
| 39 | + * n3: node-3 { ... }; |
| 40 | + * @endcode |
| 41 | + * |
| 42 | + * Above, displays property has two elements: |
| 43 | + * |
| 44 | + * - index 0 has phandle `&n2`, which is `node-2`'s phandle |
| 45 | + * - index 1 has phandle `&n3`, which is `node-3`'s phandle |
| 46 | + * |
| 47 | + * Example usage: |
| 48 | + * |
| 49 | + * @code{.c} |
| 50 | + * |
| 51 | + * DT_ZEPHYR_DISPLAY(0) // node identifier for display node node-2 |
| 52 | + * DT_ZEPHYR_DISPLAY(1) // node identifier for display node node-3 |
| 53 | + * @endcode |
| 54 | + * |
| 55 | + * @param idx logical index of display node's phandle in "displays" property |
| 56 | + * |
| 57 | + * @return display node identifier, @ref DT_INVALID_NODE otherwise |
| 58 | + */ |
| 59 | +#define DT_ZEPHYR_DISPLAY(idx) \ |
| 60 | + DT_PHANDLE_BY_IDX(DT_COMPAT_GET_ANY_STATUS_OKAY(zephyr_displays), displays, idx) |
| 61 | + |
| 62 | +/** |
| 63 | + * @brief Get number of zephyr displays |
| 64 | + * |
| 65 | + * @return number of displays designated by "displays" property of "zephyr,displays" compatible |
| 66 | + * node, if it exists, otherwise 1 if "zephyr,display" chosen property exists, 0 otherwise |
| 67 | + */ |
| 68 | +#define DT_ZEPHYR_DISPLAYS_COUNT \ |
| 69 | + COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(zephyr_displays), \ |
| 70 | + (DT_PROP_LEN(DT_COMPAT_GET_ANY_STATUS_OKAY(zephyr_displays), displays)), \ |
| 71 | + (DT_HAS_CHOSEN(zephyr_display))) |
| 72 | +/** |
| 73 | + * @} |
| 74 | + */ |
| 75 | + |
| 76 | +#ifdef __cplusplus |
| 77 | +} |
| 78 | +#endif |
| 79 | + |
| 80 | +#endif /* ZEPHYR_INCLUDE_DEVICETREE_DMAS_H_ */ |
0 commit comments