Line data Source code
1 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 : * @ingroup display_interface
23 : * @{
24 : */
25 :
26 : /**
27 : * @brief Get display node identifier by logical index from "displays" property of node with
28 : * compatible "zephyr,displays"
29 : *
30 : * Example devicetree fragment:
31 : *
32 : * @code{.dts}
33 : * displays_node: my-displays {
34 : * compatible = "zephyr,displays";
35 : * displays = <&n2 &n3>;
36 : * status = "okay";
37 : * };
38 : *
39 : * n2: node-2 { ... };
40 : * n3: node-3 { ... };
41 : * @endcode
42 : *
43 : * Above, displays property has two elements:
44 : *
45 : * - index 0 has phandle `&n2`, which is `node-2`'s phandle
46 : * - index 1 has phandle `&n3`, which is `node-3`'s phandle
47 : *
48 : * Example usage:
49 : *
50 : * @code{.c}
51 : *
52 : * DT_ZEPHYR_DISPLAY(0) // node identifier for display node node-2
53 : * DT_ZEPHYR_DISPLAY(1) // node identifier for display node node-3
54 : * @endcode
55 : *
56 : * @param idx logical index of display node's phandle in "displays" property
57 : *
58 : * @return display node identifier, @ref DT_INVALID_NODE otherwise
59 : */
60 1 : #define DT_ZEPHYR_DISPLAY(idx) \
61 : DT_PHANDLE_BY_IDX(DT_COMPAT_GET_ANY_STATUS_OKAY(zephyr_displays), displays, idx)
62 :
63 : /**
64 : * @brief Get number of zephyr displays
65 : *
66 : * @return number of displays designated by "displays" property of "zephyr,displays" compatible
67 : * node, if it exists, otherwise 1 if "zephyr,display" chosen property exists, 0 otherwise
68 : */
69 1 : #define DT_ZEPHYR_DISPLAYS_COUNT \
70 : COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(zephyr_displays), \
71 : (DT_PROP_LEN(DT_COMPAT_GET_ANY_STATUS_OKAY(zephyr_displays), displays)), \
72 : (DT_HAS_CHOSEN(zephyr_display)))
73 : /**
74 : * @}
75 : */
76 :
77 : #ifdef __cplusplus
78 : }
79 : #endif
80 :
81 : #endif /* ZEPHYR_INCLUDE_DEVICETREE_DMAS_H_ */
|