1e41f4b71Sopenharmony_ci# HDMI
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci## Overview
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci### HDMI
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ciHigh-definition multimedia interface (HDMI) is an interface for transmitting audio and video data from a source device, such as a DVD player or set-top box (STB), to a sink device, such as a TV or display.
9e41f4b71Sopenharmony_ciHDMI usually has a source and a sink.
10e41f4b71Sopenharmony_ciThe HDMI APIs provide a set of common functions for HDMI transmission, including:
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci- Opening and closing an HDMI controller
13e41f4b71Sopenharmony_ci- Starting and stopping HDMI transmission
14e41f4b71Sopenharmony_ci- Setting audio, video, and High Dynamic Range (HDR) attributes, color depth, and AV mute
15e41f4b71Sopenharmony_ci- Reading the raw Extended Display Identification Data (EDID) from a sink
16e41f4b71Sopenharmony_ci- Registering and unregistering a callback for HDMI hot plug detect (HPD)
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci### Basic Concepts
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ciHDMI is an audio and video transmission protocol released by Hitachi, Panasonic, Philips, Silicon Image, Sony, Thomson, and Toshiba. The transmission process complies with the Transition-minimized Differential Signaling (TMDS).
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci- TMDS is used to transmit audio, video, and various auxiliary data.
23e41f4b71Sopenharmony_ci- Display data channel (DDC) allows the TX and RX ends to obtain the transmitting and receiving capabilities. However, HDMI only needs to unidirectionally obtain the capabilities of the RX end (display).
24e41f4b71Sopenharmony_ci- Consumer Electronics Control (CEC) enables interaction between the HDMI TX and RX devices.
25e41f4b71Sopenharmony_ci- Fixed rate link (FRL) allows the maximum TMDS bandwidth to be increased from 18 Gbit/s to 48 Gbit/s.
26e41f4b71Sopenharmony_ci- High-bandwidth Digital Content Protection (HDCP) prevents copying of digital audio and video content being transmitted across devices.
27e41f4b71Sopenharmony_ci- EDID, usually stored in the display firmware, provides the vendor information, EDID version, maximum image size, color settings, vendor pre-settings, frequency range limit, display name, and serial number.
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci### Working Principles
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ciThe HDMI source provides +5 V and GND for DDC and CEC communication. Through the DDC, the source obtains the sink parameters, such as the RX capabilities. The CEC provides an optional channel to synchronize control signals between the source and sink for better user experience. There are four TMDS channels between the HDMI source and sink. The TMDS clock channel provides clock signals for TMDS, and the other three channels transmit audio, video, and auxiliary data. HDP is the hot plug detect port. When the sink is connected, the source responds by using an interrupt service routine (ISR).
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ciThe figure below shows the HDMI physical connection.
34e41f4b71Sopenharmony_ci 
35e41f4b71Sopenharmony_ci**Figure 1** HDMI physical connection
36e41f4b71Sopenharmony_ci  
37e41f4b71Sopenharmony_ci![](figures/HDMI_physical_connection.png "HDMI_physical_connection")
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci### Constraints
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ciCurrently, the HDMI module supports only the kernels (LiteOS) of mini and small systems.
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci## Development Guidelines
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci### When to Use
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ciHDMI features high transmission rate, wide transmission bandwidth, high compatibility, and can transmit uncompressed audio and video signals. Compared with the traditional full analog interface, HDMI simplifies connection between devices and provides HDMI-specific intelligent features, which are ideal for high-quality audio and video transmission of small-sized devices.
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci### Available APIs
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci**Table 1** HDMI driver APIs
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci| API                       | Description                      |
55e41f4b71Sopenharmony_ci| ----------------------------- | -------------------------- |
56e41f4b71Sopenharmony_ci| HdmiOpen                      | Opens an HDMI controller.            |
57e41f4b71Sopenharmony_ci| HdmiClose                     | Closes an HDMI controller.            |
58e41f4b71Sopenharmony_ci| HdmiStart                     | Starts HDMI transmission.              |
59e41f4b71Sopenharmony_ci| HdmiStop                      | Stops HDMI transmission.              |
60e41f4b71Sopenharmony_ci| HdmiAvmuteSet                 | Sets the AV mute feature.          |
61e41f4b71Sopenharmony_ci| HdmiDeepColorSet              | Sets the color depth.              |
62e41f4b71Sopenharmony_ci| HdmiDeepColorGet              | Obtains the color depth.              |
63e41f4b71Sopenharmony_ci| HdmiSetVideoAttribute         | Sets video attributes.              |
64e41f4b71Sopenharmony_ci| HdmiSetAudioAttribute         | Sets audio attributes.              |
65e41f4b71Sopenharmony_ci| HdmiSetHdrAttribute           | Sets HDR attributes.               |
66e41f4b71Sopenharmony_ci| HdmiReadSinkEdid              | Reads the raw EDID from a sink.    |
67e41f4b71Sopenharmony_ci| HdmiRegisterHpdCallbackFunc   | Registers a callback for HDMI HPD.|
68e41f4b71Sopenharmony_ci| HdmiUnregisterHpdCallbackFunc | Unregisters a callback for HDMI HPD.|
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci### How to Develop
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ciThe figure below illustrates the general HDMI development process.
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**Figure 2** Using HDMI driver APIs
75e41f4b71Sopenharmony_ci  
76e41f4b71Sopenharmony_ci![](figures/using-HDMI-process.png "using-HDMI-process")
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci#### Opening an HDMI Controller
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ciBefore HDMI communication, call **HdmiOpen()** to open an HDMI controller.
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci```c
83e41f4b71Sopenharmony_ciDevHandle HdmiOpen(int16_t number);
84e41f4b71Sopenharmony_ci```
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci**Table 2** Description of HdmiOpen
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci| Parameter      | Description            |
89e41f4b71Sopenharmony_ci| ---------- | -------------------- |
90e41f4b71Sopenharmony_ci| number     | HDMI controller ID.        |
91e41f4b71Sopenharmony_ci| **Return Value**| **Description**      |
92e41f4b71Sopenharmony_ci| NULL       | The operation failed.  |
93e41f4b71Sopenharmony_ci| Controller handle| Handle of the opened HDMI controller.|
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ciFor example, open controller 0 of the two HDMI controllers (numbered 0 and 1) in the system:
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci```c
98e41f4b71Sopenharmony_ciDevHandle hdmiHandle = NULL; /* HDMI controller handle /
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci/* Open HDMI controller 0. */
101e41f4b71Sopenharmony_cihdmiHandle = HdmiOpen(0);
102e41f4b71Sopenharmony_ciif (hdmiHandle == NULL) {
103e41f4b71Sopenharmony_ci    HDF_LOGE("HdmiOpen: failed\n");
104e41f4b71Sopenharmony_ci    return;
105e41f4b71Sopenharmony_ci}
106e41f4b71Sopenharmony_ci```
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci#### Registering a Callback for HPD
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci```c
111e41f4b71Sopenharmony_ciint32_t HdmiRegisterHpdCallbackFunc(DevHandle handle, struct HdmiHpdCallbackInfo *callback);
112e41f4b71Sopenharmony_ci```
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci**Table 3** Description of HdmiRegisterHpdCallbackFunc
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci| Parameter      | Description          |
117e41f4b71Sopenharmony_ci| ---------- | ------------------ |
118e41f4b71Sopenharmony_ci| handle     | HDMI controller handle.    |
119e41f4b71Sopenharmony_ci| callback   | Pointer to the callback to be invoked to return the HPD result.|
120e41f4b71Sopenharmony_ci| **Return Value**| **Description**    |
121e41f4b71Sopenharmony_ci| 0          | The operation is successful.          |
122e41f4b71Sopenharmony_ci| Negative value      | The operation failed.          |
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ciThe following is an example of registering a callback for HPD:
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci```c
127e41f4b71Sopenharmony_ci/* Definition of the callback for HPD */
128e41f4b71Sopenharmony_cistatic void HdmiHpdHandle(void *data, bool hpd)
129e41f4b71Sopenharmony_ci{
130e41f4b71Sopenharmony_ci    if (data == NULL) {
131e41f4b71Sopenharmony_ci        HDF_LOGE("priv data is NULL");
132e41f4b71Sopenharmony_ci        return;
133e41f4b71Sopenharmony_ci    }
134e41f4b71Sopenharmony_ci    if (hpd == true) {
135e41f4b71Sopenharmony_ci        HDF_LOGD("HdmiHpdHandle: hot plug");
136e41f4b71Sopenharmony_ci        /* Add related processing if required. */
137e41f4b71Sopenharmony_ci    } else {
138e41f4b71Sopenharmony_ci        HDF_LOGD("HdmiHpdHandle: hot unplug");
139e41f4b71Sopenharmony_ci        /* Add related processing if required. */
140e41f4b71Sopenharmony_ci    }
141e41f4b71Sopenharmony_ci}
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci/* Example of registering a callback for HPD */
144e41f4b71Sopenharmony_ci···
145e41f4b71Sopenharmony_cistruct HdmiHpdCallbackInfo info = {0};
146e41f4b71Sopenharmony_ciinfo.data = handle;
147e41f4b71Sopenharmony_ciinfo.callbackFunc = HdmiHpdHandle;
148e41f4b71Sopenharmony_ciret = HdmiRegisterHpdCallbackFunc(hdmiHandle, info);
149e41f4b71Sopenharmony_ciif (ret != 0) {
150e41f4b71Sopenharmony_ci    HDF_LOGE("HdmiRegisterHpdCallbackFunc: Register failed.");
151e41f4b71Sopenharmony_ci}
152e41f4b71Sopenharmony_ci···
153e41f4b71Sopenharmony_ci```
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci#### Reading the Raw EDID
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci```c
158e41f4b71Sopenharmony_ciint32_t HdmiReadSinkEdid(DevHandle handle, uint8_t *buffer, uint32_t len);
159e41f4b71Sopenharmony_ci```
160e41f4b71Sopenharmony_ci
161e41f4b71Sopenharmony_ci**Table 4** Description of HdmiReadSinkEdid
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci| Parameter      | Description              |
164e41f4b71Sopenharmony_ci| ---------- | ---------------------- |
165e41f4b71Sopenharmony_ci| handle     | HDMI controller handle.        |
166e41f4b71Sopenharmony_ci| buffer     | Pointer to the data buffer.            |
167e41f4b71Sopenharmony_ci| len        | Data length.              |
168e41f4b71Sopenharmony_ci| **Return Value**| **Description**        |
169e41f4b71Sopenharmony_ci| Positive integer    | Raw EDID read.|
170e41f4b71Sopenharmony_ci| Negative number or 0   | Failed to read the EDID.              |
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ciThe following is an example of reading the raw EDID from a sink:
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci```c
175e41f4b71Sopenharmony_ciint32_t len;
176e41f4b71Sopenharmony_ciuint8_t edid[HDMI_EDID_MAX_LEN] = {0};
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_cilen = HdmiReadSinkEdid(hdmiHandle, edid, HDMI_EDID_MAX_LEN);
179e41f4b71Sopenharmony_ciif (len <= 0) {
180e41f4b71Sopenharmony_ci    HDF_LOGE("%s: HdmiReadSinkEdid failed len = %d.", __func__, len);
181e41f4b71Sopenharmony_ci}
182e41f4b71Sopenharmony_ci```
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci#### Setting Audio Attributes
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci```c
187e41f4b71Sopenharmony_ciint32_t HdmiSetAudioAttribute(DevHandle handle, struct HdmiAudioAttr *attr);
188e41f4b71Sopenharmony_ci```
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ci**Table 5** Description of HdmiSetAudioAttribute
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci
193e41f4b71Sopenharmony_ci| Parameter  | Description      |
194e41f4b71Sopenharmony_ci| ------ | -------------- |
195e41f4b71Sopenharmony_ci| handle | HDMI controller handle.|
196e41f4b71Sopenharmony_ci| attr   | Pointer to the audio attributes.      |
197e41f4b71Sopenharmony_ci| **Return Value**| **Description**    |
198e41f4b71Sopenharmony_ci| 0      | The operation is successful.      |
199e41f4b71Sopenharmony_ci| Negative value  | The operation failed.      |
200e41f4b71Sopenharmony_ci
201e41f4b71Sopenharmony_ciThe following is an example of setting audio attributes:
202e41f4b71Sopenharmony_ci
203e41f4b71Sopenharmony_ci```c
204e41f4b71Sopenharmony_cistruct HdmiAudioAttr audioAttr = {0};
205e41f4b71Sopenharmony_ciint32_t ret;
206e41f4b71Sopenharmony_ci
207e41f4b71Sopenharmony_ciaudioAttr.codingType = HDMI_AUDIO_CODING_TYPE_MP3;
208e41f4b71Sopenharmony_ciaudioAttr.ifType = HDMI_AUDIO_IF_TYPE_I2S;
209e41f4b71Sopenharmony_ciaudioAttr.bitDepth = HDMI_ADIO_BIT_DEPTH_16;
210e41f4b71Sopenharmony_ciaudioAttr.sampleRate = HDMI_SAMPLE_RATE_8K;
211e41f4b71Sopenharmony_ciaudioAttr.channels = HDMI_AUDIO_FORMAT_CHANNEL_3;
212e41f4b71Sopenharmony_ciret = HdmiSetAudioAttribute(handle, &audioAttr);
213e41f4b71Sopenharmony_ciif (ret != 0) {
214e41f4b71Sopenharmony_ci    HDF_LOGE("HdmiSetAudioAttribute failed.");
215e41f4b71Sopenharmony_ci}
216e41f4b71Sopenharmony_ci```
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_ci#### Setting Video Attributes
219e41f4b71Sopenharmony_ci
220e41f4b71Sopenharmony_ci```c
221e41f4b71Sopenharmony_ciint32_t HdmiSetVideoAttribute(DevHandle handle, struct HdmiVideoAttr *attr);
222e41f4b71Sopenharmony_ci```
223e41f4b71Sopenharmony_ci
224e41f4b71Sopenharmony_ci**Table 6** Description of HdmiSetVideoAttribute
225e41f4b71Sopenharmony_ci
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ci| Parameter      | Description      |
228e41f4b71Sopenharmony_ci| ---------- | -------------- |
229e41f4b71Sopenharmony_ci| handle     | HDMI controller handle.|
230e41f4b71Sopenharmony_ci| attr       | Pointer to the video attributes.      |
231e41f4b71Sopenharmony_ci| **Return Value**| **Description**|
232e41f4b71Sopenharmony_ci| 0          | The operation is successful.      |
233e41f4b71Sopenharmony_ci| Negative value      | The operation failed.      |
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_ciThe following is an example of setting video attributes:
236e41f4b71Sopenharmony_ci
237e41f4b71Sopenharmony_ci```c
238e41f4b71Sopenharmony_cistruct HdmiVideoAttr videoAttr = {0};
239e41f4b71Sopenharmony_ciint32_t ret;
240e41f4b71Sopenharmony_ci
241e41f4b71Sopenharmony_civideoAttr.colorSpace = HDMI_COLOR_SPACE_YCBCR444;
242e41f4b71Sopenharmony_civideoAttr.colorimetry = HDMI_COLORIMETRY_EXTENDED;
243e41f4b71Sopenharmony_civideoAttr.extColorimetry = HDMI_EXTENDED_COLORIMETRY_BT2020_CONST_LUM;
244e41f4b71Sopenharmony_civideoAttr.quantization = HDMI_QUANTIZATION_RANGE_FULL;
245e41f4b71Sopenharmony_ciret = HdmiSetVideoAttribute(handle, &videoAttr);
246e41f4b71Sopenharmony_ciif (ret != 0) {
247e41f4b71Sopenharmony_ci    HDF_LOGE("HdmiSetVideoAttribute failed.");
248e41f4b71Sopenharmony_ci}
249e41f4b71Sopenharmony_ci```
250e41f4b71Sopenharmony_ci
251e41f4b71Sopenharmony_ci#### Setting HDR Attributes
252e41f4b71Sopenharmony_ci
253e41f4b71Sopenharmony_ci```c
254e41f4b71Sopenharmony_ciint32_t HdmiSetHdrAttribute(DevHandle handle, struct HdmiHdrAttr *attr);
255e41f4b71Sopenharmony_ci```
256e41f4b71Sopenharmony_ci
257e41f4b71Sopenharmony_ci**Table 7** Description of HdmiSetHdrAttribute
258e41f4b71Sopenharmony_ci
259e41f4b71Sopenharmony_ci
260e41f4b71Sopenharmony_ci| Parameter      | Description      |
261e41f4b71Sopenharmony_ci| ---------- | -------------- |
262e41f4b71Sopenharmony_ci| handle     | HDMI controller handle.|
263e41f4b71Sopenharmony_ci| attr       | Pointer to the HDR attributes       |
264e41f4b71Sopenharmony_ci| **Return Value**| **Description**|
265e41f4b71Sopenharmony_ci| 0          | The operation is successful.      |
266e41f4b71Sopenharmony_ci| Negative value      | The operation failed.      |
267e41f4b71Sopenharmony_ci
268e41f4b71Sopenharmony_ciThe following is an example of setting HDR attributes:
269e41f4b71Sopenharmony_ci
270e41f4b71Sopenharmony_ci```c
271e41f4b71Sopenharmony_cistruct HdmiHdrAttr hdrAttr = {0};
272e41f4b71Sopenharmony_ciint32_t ret;
273e41f4b71Sopenharmony_ci
274e41f4b71Sopenharmony_cihdrAttr.mode = HDMI_HDR_MODE_CEA_861_3;
275e41f4b71Sopenharmony_cihdrAttr.userMode = HDMI_HDR_USERMODE_DOLBY;
276e41f4b71Sopenharmony_cihdrAttr.eotfType = HDMI_EOTF_SMPTE_ST_2048;
277e41f4b71Sopenharmony_cihdrAttr.metadataType = HDMI_DRM_STATIC_METADATA_TYPE_1;
278e41f4b71Sopenharmony_cihdrAttr.colorimetry = HDMI_HDR_EXTENDED_COLORIMETRY_XV_YCC_709;
279e41f4b71Sopenharmony_ciret = HdmiSetHdrAttribute(handle, &hdrAttr);
280e41f4b71Sopenharmony_ciif (ret != 0) {
281e41f4b71Sopenharmony_ci    HDF_LOGE("HdmiSetHdrAttribute failed.");
282e41f4b71Sopenharmony_ci}
283e41f4b71Sopenharmony_ci```
284e41f4b71Sopenharmony_ci
285e41f4b71Sopenharmony_ci#### Setting HDMI AV Mute
286e41f4b71Sopenharmony_ci
287e41f4b71Sopenharmony_ci```c
288e41f4b71Sopenharmony_ciint32_t HdmiAvmuteSet(DevHandle handle, bool enable);
289e41f4b71Sopenharmony_ci```
290e41f4b71Sopenharmony_ci
291e41f4b71Sopenharmony_ci**Table 8** Description of HdmiAvmuteSet
292e41f4b71Sopenharmony_ci
293e41f4b71Sopenharmony_ci
294e41f4b71Sopenharmony_ci| Parameter      | Description         |
295e41f4b71Sopenharmony_ci| ---------- | ----------------- |
296e41f4b71Sopenharmony_ci| handle     | HDMI controller handle.   |
297e41f4b71Sopenharmony_ci| enable     | Whether to enable the AV mute feature.|
298e41f4b71Sopenharmony_ci| **Return Value**| **Description**   |
299e41f4b71Sopenharmony_ci| 0          | The operation is successful.         |
300e41f4b71Sopenharmony_ci| Negative value      | The operation failed.         |
301e41f4b71Sopenharmony_ci
302e41f4b71Sopenharmony_ciThe following is an example of setting AV mute:
303e41f4b71Sopenharmony_ci
304e41f4b71Sopenharmony_ci```c
305e41f4b71Sopenharmony_ciint32_t ret;
306e41f4b71Sopenharmony_ci
307e41f4b71Sopenharmony_ciret = HdmiAvmuteSet(hdmiHandle, true);
308e41f4b71Sopenharmony_ciif (ret != 0) {
309e41f4b71Sopenharmony_ci    HDF_LOGE("HdmiAvmuteSet failed.");
310e41f4b71Sopenharmony_ci}
311e41f4b71Sopenharmony_ci```
312e41f4b71Sopenharmony_ci
313e41f4b71Sopenharmony_ci#### Setting the Color Depth
314e41f4b71Sopenharmony_ci
315e41f4b71Sopenharmony_ci```c
316e41f4b71Sopenharmony_ciint32_t HdmiDeepColorSet(DevHandle handle, enum HdmiDeepColor color);
317e41f4b71Sopenharmony_ci```
318e41f4b71Sopenharmony_ci
319e41f4b71Sopenharmony_ci**Table 9** Description of HdmiDeepColorSet
320e41f4b71Sopenharmony_ci
321e41f4b71Sopenharmony_ci
322e41f4b71Sopenharmony_ci| Parameter      | Description      |
323e41f4b71Sopenharmony_ci| ---------- | -------------- |
324e41f4b71Sopenharmony_ci| handle     | HDMI controller handle.|
325e41f4b71Sopenharmony_ci| color      | Color depth to set.      |
326e41f4b71Sopenharmony_ci| **Return Value**| **Description**|
327e41f4b71Sopenharmony_ci| 0          | The operation is successful.      |
328e41f4b71Sopenharmony_ci| Negative value      | The operation failed.      |
329e41f4b71Sopenharmony_ci
330e41f4b71Sopenharmony_ciThe following is an example of setting the color depth:
331e41f4b71Sopenharmony_ci
332e41f4b71Sopenharmony_ci```c
333e41f4b71Sopenharmony_ciint32_t ret;
334e41f4b71Sopenharmony_ci
335e41f4b71Sopenharmony_ciret = HdmiDeepColorSet(handle, HDMI_DEEP_COLOR_48BITS);
336e41f4b71Sopenharmony_ciif (ret != 0) {
337e41f4b71Sopenharmony_ci    HDF_LOGE("HdmiDeepColorSet failed.");
338e41f4b71Sopenharmony_ci}
339e41f4b71Sopenharmony_ci```
340e41f4b71Sopenharmony_ci
341e41f4b71Sopenharmony_ci#### Obtaining the Color Depth
342e41f4b71Sopenharmony_ci
343e41f4b71Sopenharmony_ci```c
344e41f4b71Sopenharmony_ciint32_t HdmiDeepColorGet(DevHandle handle, enum HdmiDeepColor *color);
345e41f4b71Sopenharmony_ci```
346e41f4b71Sopenharmony_ci
347e41f4b71Sopenharmony_ci**Table 10** Description of HdmiDeepColorGet
348e41f4b71Sopenharmony_ci
349e41f4b71Sopenharmony_ci
350e41f4b71Sopenharmony_ci| Parameter      | Description      |
351e41f4b71Sopenharmony_ci| ---------- | -------------- |
352e41f4b71Sopenharmony_ci| handle     | HDMI controller handle.|
353e41f4b71Sopenharmony_ci| color      | Pointer to the color depth.      |
354e41f4b71Sopenharmony_ci| **Return Value**| **Description**|
355e41f4b71Sopenharmony_ci| 0          | The operation is successful.      |
356e41f4b71Sopenharmony_ci| Negative value      | The operation failed.      |
357e41f4b71Sopenharmony_ci
358e41f4b71Sopenharmony_ciThe following is an example of obtaining the color depth:
359e41f4b71Sopenharmony_ci
360e41f4b71Sopenharmony_ci```c
361e41f4b71Sopenharmony_cienum HdmiDeepColor color;
362e41f4b71Sopenharmony_ciint32_t ret;
363e41f4b71Sopenharmony_ci
364e41f4b71Sopenharmony_ciret = HdmiDeepColorGet(handle, &color);
365e41f4b71Sopenharmony_ciif (ret != 0) {
366e41f4b71Sopenharmony_ci    HDF_LOGE("HdmiDeepColorGet failed.");
367e41f4b71Sopenharmony_ci}
368e41f4b71Sopenharmony_ci```
369e41f4b71Sopenharmony_ci
370e41f4b71Sopenharmony_ci#### Starting HDMI Transmission
371e41f4b71Sopenharmony_ci
372e41f4b71Sopenharmony_ci```c
373e41f4b71Sopenharmony_ciint32_t HdmiStart(DevHandle handle);
374e41f4b71Sopenharmony_ci```
375e41f4b71Sopenharmony_ci
376e41f4b71Sopenharmony_ci**Table 11** Description of HdmiStart
377e41f4b71Sopenharmony_ci
378e41f4b71Sopenharmony_ci
379e41f4b71Sopenharmony_ci| Parameter      | Description      |
380e41f4b71Sopenharmony_ci| ---------- | -------------- |
381e41f4b71Sopenharmony_ci| handle     | HDMI controller handle.|
382e41f4b71Sopenharmony_ci| **Return Value**| **Description**|
383e41f4b71Sopenharmony_ci| 0          | The operation is successful.      |
384e41f4b71Sopenharmony_ci| Negative value      | The operation failed.      |
385e41f4b71Sopenharmony_ci
386e41f4b71Sopenharmony_ciThe following is an example of starting HDMI transmission:
387e41f4b71Sopenharmony_ci
388e41f4b71Sopenharmony_ci```c
389e41f4b71Sopenharmony_ciint32_t ret;
390e41f4b71Sopenharmony_ci
391e41f4b71Sopenharmony_ciret = HdmiStart(hdmiHandle);
392e41f4b71Sopenharmony_ciif (ret != 0) {
393e41f4b71Sopenharmony_ci    HDF_LOGE("Failed to start transmission.");
394e41f4b71Sopenharmony_ci}
395e41f4b71Sopenharmony_ci```
396e41f4b71Sopenharmony_ci
397e41f4b71Sopenharmony_ci#### Stopping HDMI Transmission<a name="section11"></a>
398e41f4b71Sopenharmony_ci
399e41f4b71Sopenharmony_ci```c
400e41f4b71Sopenharmony_ciint32_t HdmiStop(DevHandle handle);
401e41f4b71Sopenharmony_ci```
402e41f4b71Sopenharmony_ci
403e41f4b71Sopenharmony_ci**Table 12** Description of HdmiStop
404e41f4b71Sopenharmony_ci
405e41f4b71Sopenharmony_ci
406e41f4b71Sopenharmony_ci| Parameter      | Description      |
407e41f4b71Sopenharmony_ci| ---------- | -------------- |
408e41f4b71Sopenharmony_ci| handle     | HDMI controller handle.|
409e41f4b71Sopenharmony_ci| **Return Value**| **Description**|
410e41f4b71Sopenharmony_ci| 0          | The operation is successful.      |
411e41f4b71Sopenharmony_ci| Negative value      | The operation failed.      |
412e41f4b71Sopenharmony_ci
413e41f4b71Sopenharmony_ciThe following is an example of stopping HDMI transmission:
414e41f4b71Sopenharmony_ci
415e41f4b71Sopenharmony_ci```c
416e41f4b71Sopenharmony_ciint32_t ret;
417e41f4b71Sopenharmony_ci
418e41f4b71Sopenharmony_ciret = HdmiStop(hdmiHandle);
419e41f4b71Sopenharmony_ciif (ret != 0) {
420e41f4b71Sopenharmony_ci    HDF_LOGE("Failed to stop transmission.");
421e41f4b71Sopenharmony_ci}
422e41f4b71Sopenharmony_ci```
423e41f4b71Sopenharmony_ci
424e41f4b71Sopenharmony_ci#### Unregistering the Callback for HPD
425e41f4b71Sopenharmony_ci
426e41f4b71Sopenharmony_ci```c
427e41f4b71Sopenharmony_ciint32_t HdmiUnregisterHpdCallbackFunc(DevHandle handle);
428e41f4b71Sopenharmony_ci```
429e41f4b71Sopenharmony_ci
430e41f4b71Sopenharmony_ci**Table 13** Description of HdmiUnregisterHpdCallbackFunc
431e41f4b71Sopenharmony_ci
432e41f4b71Sopenharmony_ci
433e41f4b71Sopenharmony_ci| Parameter      | Description      |
434e41f4b71Sopenharmony_ci| ---------- | -------------- |
435e41f4b71Sopenharmony_ci| handle     | HDMI controller handle.|
436e41f4b71Sopenharmony_ci| **Return Value**| **Description**|
437e41f4b71Sopenharmony_ci| 0          | The operation is successful.      |
438e41f4b71Sopenharmony_ci| Negative value      | The operation failed.      |
439e41f4b71Sopenharmony_ci
440e41f4b71Sopenharmony_ciThe following is an example of unregistering the callback for HPD:
441e41f4b71Sopenharmony_ci
442e41f4b71Sopenharmony_ci```c
443e41f4b71Sopenharmony_ciint32_t ret;
444e41f4b71Sopenharmony_ci
445e41f4b71Sopenharmony_ciret = HdmiUnregisterHpdCallbackFunc(hdmiHandle);
446e41f4b71Sopenharmony_ciif (ret != 0) {
447e41f4b71Sopenharmony_ci    HDF_LOGE("unregister failed.");
448e41f4b71Sopenharmony_ci}
449e41f4b71Sopenharmony_ci```
450e41f4b71Sopenharmony_ci
451e41f4b71Sopenharmony_ci#### Closing an HDMI Controller
452e41f4b71Sopenharmony_ci
453e41f4b71Sopenharmony_ci```c
454e41f4b71Sopenharmony_civoid HdmiClose(DevHandle handle);
455e41f4b71Sopenharmony_ci```
456e41f4b71Sopenharmony_ci
457e41f4b71Sopenharmony_ci**Table 14** Description of HdmiClose
458e41f4b71Sopenharmony_ci
459e41f4b71Sopenharmony_ci
460e41f4b71Sopenharmony_ci| Parameter      | Description      |
461e41f4b71Sopenharmony_ci| ---------- | -------------- |
462e41f4b71Sopenharmony_ci| handle     | HDMI controller handle.|
463e41f4b71Sopenharmony_ci
464e41f4b71Sopenharmony_ciThe following is an example of closing an HDMI controller:
465e41f4b71Sopenharmony_ci
466e41f4b71Sopenharmony_ci```c
467e41f4b71Sopenharmony_ciHdmiClose(hdmiHandle);
468e41f4b71Sopenharmony_ci```
469e41f4b71Sopenharmony_ci
470e41f4b71Sopenharmony_ci### Example
471e41f4b71Sopenharmony_ci
472e41f4b71Sopenharmony_ciThis following example shows how to use HDMI APIs to manage an HDMI device on a Hi3516D V300 development board.
473e41f4b71Sopenharmony_ci
474e41f4b71Sopenharmony_ciA virtual driver is used in this example. The hardware information is as follows:
475e41f4b71Sopenharmony_ci
476e41f4b71Sopenharmony_ci-   SoC: Hi3516D V300
477e41f4b71Sopenharmony_ci
478e41f4b71Sopenharmony_ci-   HDMI controller: HDMI controller 0
479e41f4b71Sopenharmony_ci
480e41f4b71Sopenharmony_ci
481e41f4b71Sopenharmony_ciThe sample code is as follows:
482e41f4b71Sopenharmony_ci
483e41f4b71Sopenharmony_ci```c
484e41f4b71Sopenharmony_ci#include "hdmi_if.h"          /* Header file for HDMI standard APIs */
485e41f4b71Sopenharmony_ci#include "hdf_log.h"         /* Header file for log APIs */
486e41f4b71Sopenharmony_ci#include "osal_time.h"       /* Header file for delay and sleep APIs */
487e41f4b71Sopenharmony_ci
488e41f4b71Sopenharmony_ci/* Callback for hog plug detect */
489e41f4b71Sopenharmony_cistatic void HdmiHpdHandle(void *data, bool hpd)
490e41f4b71Sopenharmony_ci{
491e41f4b71Sopenharmony_ci    if (data == NULL) {
492e41f4b71Sopenharmony_ci    HDF_LOGE("priv data is NULL");
493e41f4b71Sopenharmony_ci    return;
494e41f4b71Sopenharmony_ci    }
495e41f4b71Sopenharmony_ci
496e41f4b71Sopenharmony_ci    if (hpd == true) {
497e41f4b71Sopenharmony_ci        HDF_LOGD("HdmiHpdHandle: hot plug");
498e41f4b71Sopenharmony_ci        /* Add related processing if required. */
499e41f4b71Sopenharmony_ci    } else {
500e41f4b71Sopenharmony_ci        HDF_LOGD("HdmiHpdHandle: hot unplug");
501e41f4b71Sopenharmony_ci        /* Add related processing if required. */
502e41f4b71Sopenharmony_ci    }
503e41f4b71Sopenharmony_ci}
504e41f4b71Sopenharmony_ci
505e41f4b71Sopenharmony_ci/* Set HDMI attributes. */
506e41f4b71Sopenharmony_cistatic int32_t TestHdmiSetAttr(DevHandle handle)
507e41f4b71Sopenharmony_ci{
508e41f4b71Sopenharmony_ci    enum HdmiDeepColor color;
509e41f4b71Sopenharmony_ci    struct HdmiVideoAttr videoAttr = {0};
510e41f4b71Sopenharmony_ci    struct HdmiAudioAttr audioAttr = {0};
511e41f4b71Sopenharmony_ci    struct HdmiHdrAttr hdrAttr = {0};
512e41f4b71Sopenharmony_ci    int32_t ret;
513e41f4b71Sopenharmony_ci
514e41f4b71Sopenharmony_ci    ret = HdmiDeepColorSet(handle, HDMI_DEEP_COLOR_48BITS);
515e41f4b71Sopenharmony_ci    
516e41f4b71Sopenharmony_ci    if (ret != 0) {
517e41f4b71Sopenharmony_ci        HDF_LOGE("HdmiDeepColorSet failed.");
518e41f4b71Sopenharmony_ci        return ret;
519e41f4b71Sopenharmony_ci    }
520e41f4b71Sopenharmony_ci    ret = HdmiDeepColorGet(handle, &color);
521e41f4b71Sopenharmony_ci    if (ret != 0) {
522e41f4b71Sopenharmony_ci        HDF_LOGE("HdmiDeepColorGet failed.");
523e41f4b71Sopenharmony_ci        return ret;
524e41f4b71Sopenharmony_ci    }
525e41f4b71Sopenharmony_ci    HDF_LOGE("HdmiDeepColorGet successful, color = %d.", color);
526e41f4b71Sopenharmony_ci    videoAttr.colorSpace = HDMI_COLOR_SPACE_YCBCR444;
527e41f4b71Sopenharmony_ci    videoAttr.colorimetry = HDMI_COLORIMETRY_EXTENDED;
528e41f4b71Sopenharmony_ci    videoAttr.extColorimetry = HDMI_EXTENDED_COLORIMETRY_BT2020_CONST_LUM;
529e41f4b71Sopenharmony_ci    videoAttr.quantization = HDMI_QUANTIZATION_RANGE_FULL;
530e41f4b71Sopenharmony_ci    ret = HdmiSetVideoAttribute(handle, &videoAttr);
531e41f4b71Sopenharmony_ci    if (ret != 0) {
532e41f4b71Sopenharmony_ci        HDF_LOGE("HdmiSetVideoAttribute failed.");
533e41f4b71Sopenharmony_ci        return ret;
534e41f4b71Sopenharmony_ci    }
535e41f4b71Sopenharmony_ci    audioAttr.codingType = HDMI_AUDIO_CODING_TYPE_MP3;
536e41f4b71Sopenharmony_ci    audioAttr.ifType = HDMI_AUDIO_IF_TYPE_I2S;
537e41f4b71Sopenharmony_ci    audioAttr.bitDepth = HDMI_ADIO_BIT_DEPTH_16;
538e41f4b71Sopenharmony_ci    audioAttr.sampleRate = HDMI_SAMPLE_RATE_8K;
539e41f4b71Sopenharmony_ci    audioAttr.channels = HDMI_AUDIO_FORMAT_CHANNEL_3;
540e41f4b71Sopenharmony_ci    ret = HdmiSetAudioAttribute(handle, &audioAttr);
541e41f4b71Sopenharmony_ci    if (ret != 0) {
542e41f4b71Sopenharmony_ci        HDF_LOGE("HdmiSetAudioAttribute failed.");
543e41f4b71Sopenharmony_ci        return ret;
544e41f4b71Sopenharmony_ci    }
545e41f4b71Sopenharmony_ci    hdrAttr.mode = HDMI_HDR_MODE_CEA_861_3;
546e41f4b71Sopenharmony_ci    hdrAttr.userMode = HDMI_HDR_USERMODE_DOLBY;
547e41f4b71Sopenharmony_ci    hdrAttr.eotfType = HDMI_EOTF_SMPTE_ST_2048;
548e41f4b71Sopenharmony_ci    hdrAttr.metadataType = HDMI_DRM_STATIC_METADATA_TYPE_1;
549e41f4b71Sopenharmony_ci    hdrAttr.colorimetry = HDMI_HDR_EXTENDED_COLORIMETRY_XV_YCC_709;
550e41f4b71Sopenharmony_ci    ret = HdmiSetHdrAttribute(handle, &hdrAttr);
551e41f4b71Sopenharmony_ci    if (ret != 0) {
552e41f4b71Sopenharmony_ci        HDF_LOGE("HdmiSetHdrAttribute failed.");
553e41f4b71Sopenharmony_ci        return ret;
554e41f4b71Sopenharmony_ci    }
555e41f4b71Sopenharmony_ci
556e41f4b71Sopenharmony_ci    return 0;
557e41f4b71Sopenharmony_ci}
558e41f4b71Sopenharmony_ci
559e41f4b71Sopenharmony_ci/* Main entry of HDMI routines */
560e41f4b71Sopenharmony_cistatic int32_t TestCaseHdmi(void)
561e41f4b71Sopenharmony_ci{
562e41f4b71Sopenharmony_ci    DevHandle handle = NULL;
563e41f4b71Sopenharmony_ci    int32_t ret;
564e41f4b71Sopenharmony_ci
565e41f4b71Sopenharmony_ci    struct HdmiHpdCallbackInfo info = {0};
566e41f4b71Sopenharmony_ci    uint8_t data[128] = {0};
567e41f4b71Sopenharmony_ci
568e41f4b71Sopenharmony_ci    HDF_LOGD("HdmiAdapterInit: successful.");
569e41f4b71Sopenharmony_ci    handle = HdmiOpen(0);
570e41f4b71Sopenharmony_ci    if (handle == NULL) {
571e41f4b71Sopenharmony_ci        HDF_LOGE("HdmiOpen failed.");
572e41f4b71Sopenharmony_ci        return ret;
573e41f4b71Sopenharmony_ci    }
574e41f4b71Sopenharmony_ci    info.data = handle;
575e41f4b71Sopenharmony_ci    info.callbackFunc = HdmiHpdHandle;
576e41f4b71Sopenharmony_ci    ret = HdmiRegisterHpdCallbackFunc(handle, &info);
577e41f4b71Sopenharmony_ci    if (ret != 0) {
578e41f4b71Sopenharmony_ci        HDF_LOGE("HdmiRegisterHpdCallbackFunc failed.");
579e41f4b71Sopenharmony_ci        return ret;
580e41f4b71Sopenharmony_ci    }
581e41f4b71Sopenharmony_ci
582e41f4b71Sopenharmony_ci    ret = HdmiReadSinkEdid(handle, data, 128);
583e41f4b71Sopenharmony_ci    if (ret <= 0) {
584e41f4b71Sopenharmony_ci        HDF_LOGE("HdmiReadSinkEdid failed.");
585e41f4b71Sopenharmony_ci        return ret;
586e41f4b71Sopenharmony_ci    }
587e41f4b71Sopenharmony_ci    HDF_LOGE("HdmiReadSinkEdid successful, data[6] = %d, data[8] = %d.", data[6], data[8]);
588e41f4b71Sopenharmony_ci
589e41f4b71Sopenharmony_ci    ret = TestHdmiSetAttr(handle);
590e41f4b71Sopenharmony_ci    if (ret != 0) {
591e41f4b71Sopenharmony_ci        HDF_LOGE("TestHdmiSetAttr failed.");
592e41f4b71Sopenharmony_ci        return ret;
593e41f4b71Sopenharmony_ci    }
594e41f4b71Sopenharmony_ci
595e41f4b71Sopenharmony_ci    ret = HdmiStart(handle);
596e41f4b71Sopenharmony_ci    if (ret != 0) {
597e41f4b71Sopenharmony_ci        HDF_LOGE("HdmiStart failed.");
598e41f4b71Sopenharmony_ci        return ret;
599e41f4b71Sopenharmony_ci    }
600e41f4b71Sopenharmony_ci
601e41f4b71Sopenharmony_ci    OsalMSleep(1000);
602e41f4b71Sopenharmony_ci
603e41f4b71Sopenharmony_ci    ret = HdmiStop(handle);
604e41f4b71Sopenharmony_ci    if (ret != 0) {
605e41f4b71Sopenharmony_ci        HDF_LOGE("HdmiStop failed.");
606e41f4b71Sopenharmony_ci        return ret;
607e41f4b71Sopenharmony_ci    }
608e41f4b71Sopenharmony_ci
609e41f4b71Sopenharmony_ci    ret = HdmiUnregisterHpdCallbackFunc(handle);
610e41f4b71Sopenharmony_ci    if (ret != 0) {
611e41f4b71Sopenharmony_ci        HDF_LOGE("HdmiUnregisterHpdCallbackFunc failed.");
612e41f4b71Sopenharmony_ci        return ret;
613e41f4b71Sopenharmony_ci    }
614e41f4b71Sopenharmony_ci    HdmiClose(handle);
615e41f4b71Sopenharmony_ci    return 0;
616e41f4b71Sopenharmony_ci}
617e41f4b71Sopenharmony_ci
618e41f4b71Sopenharmony_ci```
619