|
3787 | 3787 | */
|
3788 | 3788 | #define DT_ON_BUS(node_id, bus) IS_ENABLED(DT_CAT3(node_id, _BUS_, bus))
|
3789 | 3789 |
|
| 3790 | +/** |
| 3791 | + * @} |
| 3792 | + */ |
| 3793 | + |
| 3794 | +/** |
| 3795 | + * @defgroup devicetree-generic-endpoint Endpoint helpers |
| 3796 | + * @ingroup devicetree |
| 3797 | + * @{ |
| 3798 | + */ |
| 3799 | + |
| 3800 | +/** |
| 3801 | + * @brief Get the remote endpoint node connected to a local endpoint. |
| 3802 | + * |
| 3803 | + * Some devices, such as video devices, can be interconnected through port and endpoints. |
| 3804 | + * |
| 3805 | + * For a selected node's endpoint, the remote endpoint connected to it can be access through |
| 3806 | + * @ref DT_REMOTE_ENDPOINT(). |
| 3807 | + * This remote endpoint node can then be accessed using other macros to read its properties. |
| 3808 | + * |
| 3809 | + * Example devicetree overlay: |
| 3810 | + * |
| 3811 | + * @code{.dts} |
| 3812 | + * &sink { |
| 3813 | + * port { |
| 3814 | + * sink_in: endpoint@123 { |
| 3815 | + * remote-endpoint-label = "source_out"; |
| 3816 | + * }; |
| 3817 | + * }; |
| 3818 | + * }; |
| 3819 | + * |
| 3820 | + * &source { |
| 3821 | + * port { |
| 3822 | + * source_out: endpoint { |
| 3823 | + * remote-endpoint-label = "sink_in"; |
| 3824 | + * }; |
| 3825 | + * }; |
| 3826 | + * }; |
| 3827 | + * @endcode |
| 3828 | + * |
| 3829 | + * Example usage: starting from the sink, access the source endpoint connected to @c endpoint@123: |
| 3830 | + * |
| 3831 | + * @code{.c} |
| 3832 | + * DT_REMOTE_ENDPOINT(DT_NODELABEL(sink_in), port, endpoint_123) |
| 3833 | + * @endcode |
| 3834 | + * |
| 3835 | + * Example usage, starting from the source, to access the sink endpoint connected to @c endpoint: |
| 3836 | + * |
| 3837 | + * @code{.c} |
| 3838 | + * DT_REMOTE_ENDPOINT(DT_NODELABEL(source_out), port, endpoint) |
| 3839 | + * @endcode |
| 3840 | + * |
| 3841 | + * @note Once circular phandle references are supported, @c remote-endpoint-label (string) may be |
| 3842 | + * changed into @c remote-endpoint (phandle). |
| 3843 | + * |
| 3844 | + * @param node The local node. |
| 3845 | + * @param port The port to search. |
| 3846 | + * @param ep The endpoint to search. |
| 3847 | + * |
| 3848 | + * @return The remote node of the endpoint connected to @p port, @p ep. |
| 3849 | + */ |
| 3850 | +#define DT_REMOTE_ENDPOINT(node, port, ep) \ |
| 3851 | + DT_NODELABEL(DT_STRING_TOKEN(DT_CHILD(DT_CHILD(node, port), ep), remote_endpoint_label)) |
| 3852 | + |
| 3853 | +/** |
| 3854 | + * @brief Get the remote device node connected to a local endpoint. |
| 3855 | + * |
| 3856 | + * For a given node, return the remote endpoint node connected to the specified port and endpoint. |
| 3857 | + * This permit accessing the remote device properties. |
| 3858 | + * |
| 3859 | + * Example usage, starting from the sink, to access the source device connected to @c endpoint@123: |
| 3860 | + * |
| 3861 | + * @code{.c} |
| 3862 | + * DT_REMOTE_ENDPOINT(DT_NODELABEL(sink_in), port, endpoint_123) |
| 3863 | + * @endcode |
| 3864 | + * |
| 3865 | + * @note Once circular phandle references are supported, @c remote-endpoint-label (string) may be |
| 3866 | + * changed into @c remote-endpoint (phandle). |
| 3867 | + * |
| 3868 | + * @param node The local node. |
| 3869 | + * @param port The port to search. |
| 3870 | + * @param ep The endpoint to search. |
| 3871 | + * |
| 3872 | + * @return The remote node of the device connected to @p port, @p ep. |
| 3873 | + */ |
| 3874 | +#define DT_REMOTE_DEVICE(node, port, ep) DT_GPARENT(DT_REMOTE_ENDPOINT(node, port, ep)) |
| 3875 | + |
3790 | 3876 | /**
|
3791 | 3877 | * @}
|
3792 | 3878 | */
|
|
0 commit comments