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 audio and video transmission protocol jointly released by Hitachi, Panasonic, Philips, Silicon Image, Sony, Thomson and Toshiba. It is used to transmit 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. The transmission process complies with the Transition-minimized Differential Signaling (TMDS).
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci### Basic Concepts
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci- TMDS<br>Transmits audio, video, and various auxiliary data.
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci- Display data channel (DDC)<br>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).
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci- Consumer Electronics Control (CEC)<br> Enables interaction between the HDMI TX and RX devices.
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci- Fixed rate link (FRL)<br>Allows the maximum TMDS bandwidth to be increased from 18 Gbit/s to 48 Gbit/s.
19e41f4b71Sopenharmony_ci- High-bandwidth Digital Content Protection (HDCP)<br>Prevents copying of digital audio and video content being transmitted across devices.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci### Working Principles
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ciIn the HDF, the HDMI module uses the independent service mode for API adaptation. In this mode, each device independently publishes a service to process external access requests. When receiving an access request, the HDF DeviceManager extracts parameters from the request to call the internal APIs of the target device. In the independent service mode, the HDF DeviceManager provides service management capabilities. However, you need to configure a node for each device, which increases memory usage.
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci **Figure 1** Independent service mode
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci![image1](figures/independent-service-mode.png)
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci### Constraints
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ciCurrently, the HDMI module supports only the kernels (LiteOS) of mini and small systems.
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci## Development Guidelines
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci### When to Use
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_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.
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci### Available APIs
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci**HdmiCntlrOps**:
43e41f4b71Sopenharmony_ci```c
44e41f4b71Sopenharmony_cistruct HdmiCntlrOps {
45e41f4b71Sopenharmony_ci    void (*hardWareInit)(struct HdmiCntlr *cntlr);
46e41f4b71Sopenharmony_ci    void (*hardWareStatusGet)(struct HdmiCntlr *cntlr, struct HdmiHardwareStatus *status);
47e41f4b71Sopenharmony_ci    void (*controllerReset)(struct HdmiCntlr *cntlr);
48e41f4b71Sopenharmony_ci    bool (*hotPlugStateGet)(struct HdmiCntlr *cntlr);
49e41f4b71Sopenharmony_ci    bool (*hotPlugInterruptStateGet)(struct HdmiCntlr *cntlr);
50e41f4b71Sopenharmony_ci    void (*lowPowerSet)(struct HdmiCntlr *cntlr, bool enable);
51e41f4b71Sopenharmony_ci    void (*tmdsModeSet)(struct HdmiCntlr *cntlr, enum HdmiTmdsModeType mode);
52e41f4b71Sopenharmony_ci    int32_t (*tmdsConfigSet)(struct HdmiCntlr *cntlr, struct HdmiTmdsConfig mode);
53e41f4b71Sopenharmony_ci    void (*infoFrameEnable)(struct HdmiCntlr *cntlr, enum HdmiPacketType infoFrameType, bool enable);
54e41f4b71Sopenharmony_ci    int32_t (*infoFrameSend)(struct HdmiCntlr *cntlr, enum HdmiPacketType infoFrameType, uint8_t *data, uint32_t len);
55e41f4b71Sopenharmony_ci    int32_t (*infoFrameDataSet)(struct HdmiCntlr *cntlr, uint32_t type, uint8_t *data, uint32_t len);
56e41f4b71Sopenharmony_ci    int32_t (*cecMsgSend)(struct HdmiCntlr *cntlr, struct HdmiCecMsg *msg);
57e41f4b71Sopenharmony_ci    void (*audioPathEnable)(struct HdmiCntlr *cntlr, bool enable);
58e41f4b71Sopenharmony_ci    void (*audioPathSet)(struct HdmiCntlr *cntlr, struct HdmiAudioConfigInfo *config);
59e41f4b71Sopenharmony_ci    void (*phyOutputEnable)(struct HdmiCntlr *cntlr, bool enable);
60e41f4b71Sopenharmony_ci    void (*phyOutputSet)(struct HdmiCntlr *cntlr, struct HdmiPhyCfg *cfg);
61e41f4b71Sopenharmony_ci    void (*blackDataSet)(struct HdmiCntlr *cntlr, bool enable);
62e41f4b71Sopenharmony_ci    void (*videoMuteEnable)(struct HdmiCntlr *cntlr, bool enable);
63e41f4b71Sopenharmony_ci    void (*videoPathSet)(struct HdmiCntlr *cntlr, struct HdmiVideoAttr *attr);
64e41f4b71Sopenharmony_ci    void (*audioMuteEnable)(struct HdmiCntlr *cntlr, bool enable);
65e41f4b71Sopenharmony_ci    void (*avmuteSet)(struct HdmiCntlr *cntlr, bool enable);
66e41f4b71Sopenharmony_ci    int32_t (*ddcTransfer)(struct HdmiCntlr *cntlr, struct HdmiDdcCfg *ddcCfg);
67e41f4b71Sopenharmony_ci    bool (*scdcSourceScrambleGet)(struct HdmiCntlr *cntlr);
68e41f4b71Sopenharmony_ci    int32_t (*scdcSourceScrambleSet)(struct HdmiCntlr *cntlr, bool enable);
69e41f4b71Sopenharmony_ci    void (*frlSet)(struct HdmiCntlr *cntlr);
70e41f4b71Sopenharmony_ci    int32_t (*frlEnable)(struct HdmiCntlr *cntlr, bool enable);
71e41f4b71Sopenharmony_ci    int32_t (*audioNctsSet)(struct HdmiCntlr *cntlr, struct HdmiFrlAudioNctsConfig *cfg);
72e41f4b71Sopenharmony_ci    void (*frlTrainingConfigSet)(struct HdmiCntlr *cntlr, struct HdmiFrlTrainConfig *cfg);
73e41f4b71Sopenharmony_ci    void (*frlTrainingStart)(struct HdmiCntlr *cntlr);
74e41f4b71Sopenharmony_ci    void (*frlGetTriningRslt)(struct HdmiCntlr *cntlr, struct HdmiFrlTrainRslt *rslt);
75e41f4b71Sopenharmony_ci    void (*hdcpRegInit)(struct HdmiCntlr *cntlr);
76e41f4b71Sopenharmony_ci    int32_t (*hdcpGenerateAksvAndAn)(struct HdmiCntlr *cntlr);
77e41f4b71Sopenharmony_ci    int32_t (*hdcpOptReg)(struct HdmiCntlr *cntlr, enum HdmiHdcpRegOptType type, uint8_t *data, uint32_t len);
78e41f4b71Sopenharmony_ci    void (*hdrTimerSet)(struct HdmiCntlr *cntlr, struct HdmiHdrTimerConfig *config);
79e41f4b71Sopenharmony_ci};
80e41f4b71Sopenharmony_ci```
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci**Table 1** Description of the callback functions in HdmiCntlrOps
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci| Function                | Input Parameter                                                        | Output Parameter                                  | Return Value            | Description                                              |
85e41f4b71Sopenharmony_ci| ------------------------ | ------------------------------------------------------------ | -------------------------------------- | ------------------ | -------------------------------------------------- |
86e41f4b71Sopenharmony_ci| hardWareInit             | **cntlr**: structure pointer to an HDMI controller at the core layer.| –| –| Initializes the HDMI hardware.|
87e41f4b71Sopenharmony_ci| hardWareStatusGet        | **cntlr**: structure pointer to an HDMI controller at the core layer.<br>| **status**: pointer to the HDMI hardware status.| –| Obtains the HDMI hardware status.|
88e41f4b71Sopenharmony_ci| controllerReset          | **cntlr**: structure pointer to an HDMI controller at the core layer.| –| –| Resets an HDMI controller.|
89e41f4b71Sopenharmony_ci| hotPlugStateGet          | **cntlr**: structure pointer to an HDMI controller at the core layer.| –| **bool**: HDMI hot-plug status.| Obtains the HDMI hot-plug status.|
90e41f4b71Sopenharmony_ci| hotPlugInterruptStateGet | **cntlr**: structure pointer to an HDMI controller at the core layer.| –| **bool**: HDMI hot-plug interrupt status.| Obtains the HDMI hot-plug interrupt status.|
91e41f4b71Sopenharmony_ci| lowPowerSet              | **cntlr**: structure pointer to an HDMI controller at the core layer.<br>**enable**: whether to enable low power consumption.| –| –| Enables or disables low power consumption.|
92e41f4b71Sopenharmony_ci| tmdsModeSet              | **cntlr**: structure pointer to an HDMI controller at the core layer.<br>**mode**: TMDS mode.| –| –| Sets the TMDS mode.|
93e41f4b71Sopenharmony_ci| tmdsConfigSet | **cntlr**: structure pointer to an HDMI controller at the core layer.<br>**mode**: TMDS parameters.| –| HDF_STATUS| Sets TMDS parameters.|
94e41f4b71Sopenharmony_ci| infoFrameEnable | **cntlr**: structure pointer to an HDMI controller at the core layer.<br>**infoFrameType**: packet type.<br>**enable**: whether to enable infoFrame.| –| –| Enables or disables infoFrame.|
95e41f4b71Sopenharmony_ci| infoFrameSend | **cntlr**: structure pointer to an HDMI controller at the core layer.<br>**infoFrameType**: packet type.<br>**data**: pointer to infoFrame data.<br>**len**: data length.| –| HDF_STATUS| Sends an infoFrame.|
96e41f4b71Sopenharmony_ci|cecMsgSend|**cntlr**: structure pointer to an HDMI controller at the core layer.<br>**msg**: pointer to the CEC message|–|HDF_STATUS|Sends a CEC message.|
97e41f4b71Sopenharmony_ci|audioPathEnable|**cntlr**: structure pointer to an HDMI controller at the core layer.<br>**enable**: whether to enable the audio path.|–|–|Enables or disables the audio path.|
98e41f4b71Sopenharmony_ci| audioPathSet | **cntlr**: structure pointer to an HDMI controller at the core layer.<br>**config**: pointer to the audio path configuration.| –| –| Sets the audio path.|
99e41f4b71Sopenharmony_ci|phyOutputEnable|**cntlr**: structure pointer to an HDMI controller at the core layer.<br>**enable**: whether to enable the physical layer output.|–|–|Enables or disables the physical layer output.|
100e41f4b71Sopenharmony_ci| phyOutputSet | **cntlr**: structure pointer to an HDMI controller at the core layer.<br>**cfg**: pointer to the physical layer configuration.| –| –| Sets the physical layer information.|
101e41f4b71Sopenharmony_ci|blackDataSet|**cntlr**: structure pointer to an HDMI controller at the core layer.<br>**enable**: whether to enable the black screen.|–|–|Sets the black screen.|
102e41f4b71Sopenharmony_ci|videoMuteEnable|**cntlr**: structure pointer to an HDMI controller at the core layer.<br>**enable**: whether to enable the video mute feature.|–|–|Enables or disables the video mute feature.|
103e41f4b71Sopenharmony_ci| videoPathSet | **cntlr**: structure pointer to an HDMI controller at the core layer.<br>**attr**: pointer to the video path configuration.| –| –| Sets the video path.|
104e41f4b71Sopenharmony_ci|audioMuteEnable|**cntlr**: structure pointer to an HDMI controller at the core layer.<br>**enable**: whether to enable the audio mute feature.|–|–|Enables or disables the audio mute feature.|
105e41f4b71Sopenharmony_ci|avmuteSet|**cntlr**: structure pointer to an HDMI controller at the core layer.<br>**enable**: whether to enable the AV mute feature.|–|–|Enables or disables the AV mute feature.|
106e41f4b71Sopenharmony_ci|ddcTransfer|**cntlr**: structure pointer to an HDMI controller at the core layer.<br>**ddcCfg**: pointer to the DDC configuration.|**ddcCfg**: DDC configuration.|HDF_STATUS|Reads and writes data through the DDC.|
107e41f4b71Sopenharmony_ci| scdcSourceScrambleGet | **cntlr**: structure pointer to an HDMI controller at the core layer.| –| Scrambling status of the source.| Obtains the scrambling status of the source.|
108e41f4b71Sopenharmony_ci|scdcSourceScrambleSet|**cntlr**: structure pointer to an HDMI controller at the core layer.<br>**enable**: whether to enable the scrambling for the source.|–|HDF_STATUS|Enables or disable scrambling for the source.|
109e41f4b71Sopenharmony_ci|frlEnable|**cntlr**: structure pointer to an HDMI controller at the core layer.<br>**enable**: whether to enable the FRL.|–|HDF_STATUS|Enables or disables the FRL.|
110e41f4b71Sopenharmony_ci| audioNctsSet | **cntlr**: structure pointer to an HDMI controller at the core layer.<br>**cfg**: pointer to the N/CTS configuration.| –| HDF_STATUS| Sets the audio N/CTS information.|
111e41f4b71Sopenharmony_ci|frlTrainingConfigSet|**cntlr**: structure pointer to an HDMI controller at the core layer.<br>**cfg**: pointer to the FRL training configuration.|–|–|Sets FRL training information.|
112e41f4b71Sopenharmony_ci| frlTrainingStart | **cntlr**: structure pointer to an HDMI controller at the core layer.| –| –| Starts FRL training.|
113e41f4b71Sopenharmony_ci| frlGetTriningRslt | **cntlr**: structure pointer to an HDMI controller at the core layer.| **rslt**: FRL training result.| –| Obtains the FRL training result.|
114e41f4b71Sopenharmony_ci| hdcpRegInit | **cntlr**: structure pointer to an HDMI controller at the core layer.| –| –| Initializes registers related to the High-bandwidth Digital Content Protection (HDCP) process.|
115e41f4b71Sopenharmony_ci|hdcpGenerateAksvAndAn |**cntlr**: structure pointer to an HDMI controller at the core layer.| –| HDF_STATUS| Generates the **Aksv** and **An** in the HDCP process.|
116e41f4b71Sopenharmony_ci| hdcpOptReg | **cntlr**: structure pointer to an HDMI controller at the core layer.<br>**type**: operation type.<br>**data**: register data.<br>**len**: data length.| **data**: register data.| HDF_STATUS| Reads or writes the registers during the HDCP process.|
117e41f4b71Sopenharmony_ci| hdrTimerSet | **cntlr**: structure pointer to an HDMI controller at the core layer.<br>**config**: pointer to the timer configuration| –| –| Sets the HDR-related timer.|
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci### How to Develop
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ciThe HDMI module adaptation involves the following steps:
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci1. Instantiate the driver entry.
125e41f4b71Sopenharmony_ci   - Instantiate the **HdfDriverEntry** structure.
126e41f4b71Sopenharmony_ci   - Call **HDF_INIT** to register the **HdfDriverEntry** instance with the HDF.
127e41f4b71Sopenharmony_ci2. Configure attribute files.
128e41f4b71Sopenharmony_ci   - Add the **deviceNode** information to the **device_info.hcs** file.
129e41f4b71Sopenharmony_ci   - (Optional) Add the **hdmi_config.hcs** file.
130e41f4b71Sopenharmony_ci3. Instantiate the HDMI controller object.
131e41f4b71Sopenharmony_ci   - Initialize **HdmiCntlr**.
132e41f4b71Sopenharmony_ci   - Instantiate **HdmiCntlrOps** in **HdmiCntlr**.
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci### Development Example
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci1. Instantiate the driver entry.
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci    The driver entry must be a global variable of the **HdfDriverEntry** type (which is defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**. In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci    Generally, the HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci    HDMI driver entry example:
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci    ```c
145e41f4b71Sopenharmony_ci    struct HdfDriverEntry g_hdmiDriverEntry = {
146e41f4b71Sopenharmony_ci        .moduleVersion = 1,
147e41f4b71Sopenharmony_ci        .Bind = HdmiAdapterBind,
148e41f4b71Sopenharmony_ci        .Init = HdmiAdapterInit,
149e41f4b71Sopenharmony_ci        .Release = HdmiAdapterRelease,
150e41f4b71Sopenharmony_ci        .moduleName = "adapter_hdmi_driver",// (mandatory) The value must be the same as that in the .hcs file.
151e41f4b71Sopenharmony_ci    };
152e41f4b71Sopenharmony_ci    HDF_INIT(g_hdmiDriverEntry);            // Call HDF_INIT to register the driver entry with the HDF.
153e41f4b71Sopenharmony_ci    ```
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci2. Configure attribute files.
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci    Add **deviceNode** to the **device_info.hcs** file, and configure the device attributes in the **hdmi_config.hcs** file. The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the driver implementation and the default values or restriction ranges of the **HdmiCntlr** members at the core layer.
158e41f4b71Sopenharmony_ci
159e41f4b71Sopenharmony_ci    Configure HDMI controller information from the first node. This node specifies a type of HDMI controllers rather than a specific HDMI controller. In this example, there is only one HDMI controller. If there are multiple HDMI controllers, you need to add the **deviceNode** information to the **device_info** file and add the corresponding device attributes to the **hdmi_config** file.
160e41f4b71Sopenharmony_ci
161e41f4b71Sopenharmony_ci    - **device_info.hcs** configuration example
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci        ```c
164e41f4b71Sopenharmony_ci        root {
165e41f4b71Sopenharmony_ci            platform :: host {
166e41f4b71Sopenharmony_ci                 device_hdmi :: device {
167e41f4b71Sopenharmony_ci                    device0 :: deviceNode {
168e41f4b71Sopenharmony_ci                        policy = 2;                               // Publish services.
169e41f4b71Sopenharmony_ci                        priority = 20;                            // Driver startup priority.
170e41f4b71Sopenharmony_ci                        permission = 0644;                        // Permission to create device nodes for the driver.
171e41f4b71Sopenharmony_ci                        serviceName = "HDF_PLATFORM_HDMI_0";      // (Mandatory) Unique name of the service published by the driver.
172e41f4b71Sopenharmony_ci                        moduleName = "hdmi_driver";               // (Mandatory) Driver name, which must be the same as moduleName in the driver entry.
173e41f4b71Sopenharmony_ci                        deviceMatchAttr = "adapter_hdmi_driver";  // (Mandatory) Controller private data, which must be same as that of the corresponding controller in hdmi_config.hcs.
174e41f4b71Sopenharmony_ci                    }                                             // The specific controller information is in hdmi_config.hcs.
175e41f4b71Sopenharmony_ci                 }
176e41f4b71Sopenharmony_ci            }
177e41f4b71Sopenharmony_ci        }
178e41f4b71Sopenharmony_ci        ```
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci    - **hdmi_config.hcs** configuration example
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ci        ```c
183e41f4b71Sopenharmony_ci         root {
184e41f4b71Sopenharmony_ci             platform {
185e41f4b71Sopenharmony_ci                hdmi_config {
186e41f4b71Sopenharmony_ci                    template hdmi_controller {     // Template configuration. In the template, you can configure the common parameters shared by device nodes.
187e41f4b71Sopenharmony_ci                        match_attr = "";           // (Mandatory) The value must be the same as that of deviceMatchAttr in device_info.hcs.
188e41f4b71Sopenharmony_ci                        index = 0;                 // (Mandatory) HDMI controller number.
189e41f4b71Sopenharmony_ci                        regBasePhy = 0x10100000;   // (Mandatory) Physical base address of the register.
190e41f4b71Sopenharmony_ci                        regSize = 0xd1;            // (Mandatory) Register bit width.
191e41f4b71Sopenharmony_ci                        irqNum = 100;              //(Mandatory) Interrupt request (IRQ) number.
192e41f4b71Sopenharmony_ci                        maxTmdsClock = 300;
193e41f4b71Sopenharmony_ci                        videoTiming = 10;
194e41f4b71Sopenharmony_ci                        quantization = 1;
195e41f4b71Sopenharmony_ci                        colorSpace = 0;
196e41f4b71Sopenharmony_ci                        colorimetry = 0;
197e41f4b71Sopenharmony_ci                        audioIfType = 0;
198e41f4b71Sopenharmony_ci                        audioBitDepth = 1;
199e41f4b71Sopenharmony_ci                        audioSampleRate = 2;
200e41f4b71Sopenharmony_ci                        audioChannels = 1;
201e41f4b71Sopenharmony_ci                        hdrColorimetry = 4;
202e41f4b71Sopenharmony_ci                        hdrUserMode = 1;
203e41f4b71Sopenharmony_ci                        cap = 0xd001e045;
204e41f4b71Sopenharmony_ci                    }
205e41f4b71Sopenharmony_ci                    controller_0x10100000 :: hdmi_controller {
206e41f4b71Sopenharmony_ci                        match_attr = "adapter_hdmi_driver";
207e41f4b71Sopenharmony_ci                        index = 0;
208e41f4b71Sopenharmony_ci                        regBasePhy = 0x10100000;
209e41f4b71Sopenharmony_ci                        irqNum = 100;
210e41f4b71Sopenharmony_ci                        maxTmdsClock = 400;
211e41f4b71Sopenharmony_ci                        defTmdsClock = 300;
212e41f4b71Sopenharmony_ci                        maxFrlRate = 600;
213e41f4b71Sopenharmony_ci                        videoTiming = 10;
214e41f4b71Sopenharmony_ci                        quantization = 1;
215e41f4b71Sopenharmony_ci                        colorSpace = 0;
216e41f4b71Sopenharmony_ci                        colorimetry = 0;
217e41f4b71Sopenharmony_ci                        audioIfType = 0;
218e41f4b71Sopenharmony_ci                        audioSampleRate = 2;
219e41f4b71Sopenharmony_ci                        audioChannels = 1;
220e41f4b71Sopenharmony_ci                        hdrColorimetry = 4;
221e41f4b71Sopenharmony_ci                        hdrUserMode = 1;
222e41f4b71Sopenharmony_ci                        cap = 0xd001e045;
223e41f4b71Sopenharmony_ci                    }
224e41f4b71Sopenharmony_ci                }
225e41f4b71Sopenharmony_ci            }
226e41f4b71Sopenharmony_ci        }
227e41f4b71Sopenharmony_ci        ```
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_ci3. Instantiate the **HdmiCntlr** object.
230e41f4b71Sopenharmony_ci
231e41f4b71Sopenharmony_ci    Initialize the **HdmiCntlr** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init** and **Release**) to instantiate **HdmiCntlrOps** in **HdmiCntlr** (so that the underlying driver functions can be called).
232e41f4b71Sopenharmony_ci
233e41f4b71Sopenharmony_ci    - Defining the custom structure
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_ci        > ![](../public_sys-resources/icon-note.gif) **NOTE**
236e41f4b71Sopenharmony_ci        >
237e41f4b71Sopenharmony_ci        >
238e41f4b71Sopenharmony_ci        > To the driver, the custom structure holds parameters and data. The **DeviceResourceIface** method provided by the HDF reads the values in the **hdmi_config.hcs** file to initialize the members in the custom structure and passes important parameters, such as the device number and bus number, to the **HdmiCntlr** object at the core layer.
239e41f4b71Sopenharmony_ci    
240e41f4b71Sopenharmony_ci        ```c
241e41f4b71Sopenharmony_ci        struct HdmiAdapterHost {
242e41f4b71Sopenharmony_ci            struct HdmiCntlr *cntlr;        // (Mandatory) Control object at the core layer. The details are as follows:
243e41f4b71Sopenharmony_ci            volatile unsigned char *regBase;// (Mandatory) Register base address.
244e41f4b71Sopenharmony_ci            uint32_t regBasePhy;            // (Mandatory) Physical base address of the register.
245e41f4b71Sopenharmony_ci            uint32_t regSize;               // (Mandatory) Register bit width.
246e41f4b71Sopenharmony_ci            uint32_t irqNum;                // (Mandatory) IRQ number.
247e41f4b71Sopenharmony_ci        };
248e41f4b71Sopenharmony_ci        
249e41f4b71Sopenharmony_ci        /* HdmiCntlr is the controller structure at the core layer. The Init function assigns values to the members of HdmiCntlr. */
250e41f4b71Sopenharmony_ci        struct HdmiCntlr {
251e41f4b71Sopenharmony_ci            struct IDeviceIoService service;
252e41f4b71Sopenharmony_ci            struct HdfDeviceObject *hdfDevObj;
253e41f4b71Sopenharmony_ci            struct PlatformDevice device;
254e41f4b71Sopenharmony_ci            struct OsalMutex mutex;
255e41f4b71Sopenharmony_ci            struct PlatformQueue *msgQueue;
256e41f4b71Sopenharmony_ci            struct HdmiCntlrCap cap;
257e41f4b71Sopenharmony_ci            struct HdmiAttr attr;
258e41f4b71Sopenharmony_ci            struct HdmiCntlrOps *ops;
259e41f4b71Sopenharmony_ci            uint32_t deviceIndex;
260e41f4b71Sopenharmony_ci            uint32_t state;                 // Controller status.
261e41f4b71Sopenharmony_ci            enum HdmiTmdsModeType tmdsMode;
262e41f4b71Sopenharmony_ci            struct HdmiDevice *hdmi;
263e41f4b71Sopenharmony_ci            struct HdmiInfoframe infoframe;
264e41f4b71Sopenharmony_ci            struct HdmiScdc *scdc;
265e41f4b71Sopenharmony_ci            struct HdmiDdc ddc;
266e41f4b71Sopenharmony_ci            struct HdmiFrl *frl;
267e41f4b71Sopenharmony_ci            struct HdmiHdcp *hdcp;
268e41f4b71Sopenharmony_ci            struct HdmiCec *cec;
269e41f4b71Sopenharmony_ci            struct HdmiEvent event;
270e41f4b71Sopenharmony_ci            struct HdmiHdr *hdr;
271e41f4b71Sopenharmony_ci            void *priv;
272e41f4b71Sopenharmony_ci        };
273e41f4b71Sopenharmony_ci        ```
274e41f4b71Sopenharmony_ci
275e41f4b71Sopenharmony_ci    -  Instantiating **HdmiCntlrOps** in **HdmiCntlr**
276e41f4b71Sopenharmony_ci    
277e41f4b71Sopenharmony_ci        ```c 
278e41f4b71Sopenharmony_ci        static struct HdmiCntlrOps g_hdmiAdapterHostOps = {
279e41f4b71Sopenharmony_ci            .hardWareInit = HdmiAdapterHardWareInit,
280e41f4b71Sopenharmony_ci            .hardWareStatusGet = HdmiAdapterHardWareStatusGet,
281e41f4b71Sopenharmony_ci            .controllerReset = HdmiAdapterControllerReset,
282e41f4b71Sopenharmony_ci            .hotPlugStateGet = HdmiAdapterHotPlugStateGet,
283e41f4b71Sopenharmony_ci            .hotPlugInterruptStateGet = HdmiAdapterHotPlugInterruptStateGet,
284e41f4b71Sopenharmony_ci            .lowPowerSet = HdmiAdapterLowPowerSet,
285e41f4b71Sopenharmony_ci            .tmdsModeSet = HdmiAdapterTmdsModeSet,
286e41f4b71Sopenharmony_ci            .tmdsConfigSet = HdmiAdapterTmdsConfigSet,
287e41f4b71Sopenharmony_ci            .infoframeEnable = HdmiAdapterInfoframeEnable,
288e41f4b71Sopenharmony_ci            .infoframeSend = HdmiAdapterInfoframeSend,
289e41f4b71Sopenharmony_ci            .infoframeDataSet = HdmiAdapterInfoframeDataSet,
290e41f4b71Sopenharmony_ci            .cecMsgSend = HdmiAdapterCecMsgSend,
291e41f4b71Sopenharmony_ci            .audioPathEnable = HdmiAdapterAudioPathEnable,
292e41f4b71Sopenharmony_ci            .audioPathSet = HdmiAdapterAudioPathSet,
293e41f4b71Sopenharmony_ci            .phyOutputEnable = HdmiAdapterPhyOutputEnable,
294e41f4b71Sopenharmony_ci            .phyOutputSet = HdmiAdapterPhyOutputSet,
295e41f4b71Sopenharmony_ci            .blackDataSet = HdmiAdapterBlackDataSet,
296e41f4b71Sopenharmony_ci            .videoMuteEnable = HdmiAdapterVideoMuteEnable,
297e41f4b71Sopenharmony_ci            .videoPathSet = HdmiAdapterVideoPathSet,
298e41f4b71Sopenharmony_ci            .audioMuteEnable = HdmiAdapterAudioMuteEnable,
299e41f4b71Sopenharmony_ci            .avmuteSet = HdmiAdapterAvmuteSet,
300e41f4b71Sopenharmony_ci            .ddcTransfer = HdmiAdapterDdcTransfer,
301e41f4b71Sopenharmony_ci            .scdcSourceScrambleGet = HdmiAdapterScdcSourceScrambleGet,
302e41f4b71Sopenharmony_ci            .scdcSourceScrambleSet = HdmiAdapterScdcSourceScrambleSet,
303e41f4b71Sopenharmony_ci            .frlSet = HdmiAdapterFrlSet,
304e41f4b71Sopenharmony_ci            .frlEnable = HdmiAdapterFrlEnable,
305e41f4b71Sopenharmony_ci            .audioNctsSet = HdmiAdapterAudioNctsSet,
306e41f4b71Sopenharmony_ci            .frlTrainingConfigSet = HdmiAdapterFrlTrainingConfigSet,
307e41f4b71Sopenharmony_ci            .frlTrainingStart = HdmiAdapterFrlTrainingStart,
308e41f4b71Sopenharmony_ci            .frlGetTriningRslt = HdmiAdapterFrlGetTriningRslt,
309e41f4b71Sopenharmony_ci            .hdcpRegInit = HdmiAdapterHdcpRegInit,
310e41f4b71Sopenharmony_ci            .hdcpGenerateAksvAndAn = HdmiAdapterHdcpGenerateAksvAndAn,
311e41f4b71Sopenharmony_ci            .hdcpOptReg = HdmiAdapterHdcpOptReg,
312e41f4b71Sopenharmony_ci            .hdrTimerSet = HdmiAdapterHdrTimerSet,
313e41f4b71Sopenharmony_ci        };
314e41f4b71Sopenharmony_ci        ```
315e41f4b71Sopenharmony_ci
316e41f4b71Sopenharmony_ci    - **Bind** function
317e41f4b71Sopenharmony_ci    
318e41f4b71Sopenharmony_ci        **Input parameter**:
319e41f4b71Sopenharmony_ci    
320e41f4b71Sopenharmony_ci        **HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
321e41f4b71Sopenharmony_ci    
322e41f4b71Sopenharmony_ci        **Return value**:
323e41f4b71Sopenharmony_ci    
324e41f4b71Sopenharmony_ci        **HDF_STATUS**
325e41f4b71Sopenharmony_ci    
326e41f4b71Sopenharmony_ci        The table below describes some status. For more information, see **HDF_STATUS** in the **/drivers/framework/include/utils/hdf_base.h** file.
327e41f4b71Sopenharmony_ci    
328e41f4b71Sopenharmony_ci        |Status|Description|
329e41f4b71Sopenharmony_ci        |:-|:-|
330e41f4b71Sopenharmony_ci        |HDF_ERR_INVALID_OBJECT|Invalid controller object.|
331e41f4b71Sopenharmony_ci        |HDF_ERR_INVALID_PARAM |Invalid parameter.|
332e41f4b71Sopenharmony_ci        |HDF_ERR_MALLOC_FAIL   |Failed to allocate memory.|
333e41f4b71Sopenharmony_ci        |HDF_ERR_IO            |I/O error.|
334e41f4b71Sopenharmony_ci        |HDF_SUCCESS           |Transmission successful.|
335e41f4b71Sopenharmony_ci        |HDF_FAILURE           |Transmission failed.|
336e41f4b71Sopenharmony_ci    
337e41f4b71Sopenharmony_ci        **Function description**:
338e41f4b71Sopenharmony_ci    
339e41f4b71Sopenharmony_ci        Initializes the custom structure object **HdmiAdapterHost** and **HdmiCntlr**, and calls the **HdmiCntlrAdd** function to add the HDMI controller to the core layer.
340e41f4b71Sopenharmony_ci    
341e41f4b71Sopenharmony_ci        The **HdmiCntlr**, **HdmiAdapterHost**, and **HdfDeviceObject** assign values with each other so that other functions can be converted successfully.
342e41f4b71Sopenharmony_ci    
343e41f4b71Sopenharmony_ci        ```c
344e41f4b71Sopenharmony_ci        static int32_t HdmiAdapterBind(struct HdfDeviceObject *obj)
345e41f4b71Sopenharmony_ci        {
346e41f4b71Sopenharmony_ci            struct HdmiCntlr *cntlr = NULL;
347e41f4b71Sopenharmony_ci            struct HimciAdapterHost *host = NULL;
348e41f4b71Sopenharmony_ci            int32_t ret;
349e41f4b71Sopenharmony_ci            cntlr = (struct HdmiCntlr *)OsalMemCalloc(sizeof(struct HdmiCntlr));
350e41f4b71Sopenharmony_ci            if (cntlr == NULL) {
351e41f4b71Sopenharmony_ci                HDF_LOGE("%s: malloc cntlr failed!", __func__);
352e41f4b71Sopenharmony_ci                return HDF_ERR_MALLOC_FAIL;
353e41f4b71Sopenharmony_ci            }
354e41f4b71Sopenharmony_ci            host = (struct HimciAdapterHost *)OsalMemCalloc(sizeof(struct HimciAdapterHost));
355e41f4b71Sopenharmony_ci            if (host == NULL) {
356e41f4b71Sopenharmony_ci                HDF_LOGE("%s: malloc host failed!", __func__);
357e41f4b71Sopenharmony_ci                return HDF_ERR_MALLOC_FAIL;
358e41f4b71Sopenharmony_ci            }
359e41f4b71Sopenharmony_ci            cntlr->priv = (void *)host;              // (Mandatory) Store host to the private data of cntlr.
360e41f4b71Sopenharmony_ci            cntlr->ops = &g_hdmiHostOps;             // (Mandatory) Connect to the HdmiCntlrOps instance.
361e41f4b71Sopenharmony_ci            cntlr->hdfDevObj = obj;                  // (Mandatory) Prerequisites for conversion between HdfDeviceObject and HdmiCntlr.
362e41f4b71Sopenharmony_ci            obj->service = &cntlr->service;          // (Mandatory) Prerequisites for conversion between HdfDeviceObject and HdmiCntlr.
363e41f4b71Sopenharmony_ci            ret = HdmiAdapterCntlrParse(cntlr, obj); // (Mandatory) Initialize cntlr. If the operation fails, execute goto __ERR.
364e41f4b71Sopenharmony_ci            ... 
365e41f4b71Sopenharmony_ci            ret = HdmiAdapterHostParse(host, obj);   // (Mandatory) Initialize the attributes of the host object. If the operation fails, execute goto__ERR.
366e41f4b71Sopenharmony_ci            ...
367e41f4b71Sopenharmony_ci            ret = HdmiAdapterHostInit(host, cntlr);  // Initialize the custom structure. If the operation fails, execute goto __ERR.
368e41f4b71Sopenharmony_ci            ...
369e41f4b71Sopenharmony_ci            ret = HdmiCntlrAdd(cntlr);               // Call the functions at the core layer. If the operation fails, execute goto__ERR.
370e41f4b71Sopenharmony_ci            ...
371e41f4b71Sopenharmony_ci            HDF_LOGD("HdmiAdapterBind: success.");
372e41f4b71Sopenharmony_ci            return HDF_SUCCESS;
373e41f4b71Sopenharmony_ci        __ERR:
374e41f4b71Sopenharmony_ci            HdmiAdapterDeleteHost(host);
375e41f4b71Sopenharmony_ci            HDF_LOGD("HdmiAdapterBind: fail, err = %d.", ret);
376e41f4b71Sopenharmony_ci            return ret;
377e41f4b71Sopenharmony_ci        }
378e41f4b71Sopenharmony_ci        ```
379e41f4b71Sopenharmony_ci    
380e41f4b71Sopenharmony_ci    - **Init** function
381e41f4b71Sopenharmony_ci    
382e41f4b71Sopenharmony_ci        **Input parameter**:
383e41f4b71Sopenharmony_ci    
384e41f4b71Sopenharmony_ci        **HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
385e41f4b71Sopenharmony_ci    
386e41f4b71Sopenharmony_ci        **Return value**:
387e41f4b71Sopenharmony_ci    
388e41f4b71Sopenharmony_ci        **HDF_STATUS**
389e41f4b71Sopenharmony_ci    
390e41f4b71Sopenharmony_ci        **Function description**:
391e41f4b71Sopenharmony_ci    
392e41f4b71Sopenharmony_ci        Implements the **HdmiAdapterInit** function.
393e41f4b71Sopenharmony_ci    
394e41f4b71Sopenharmony_ci        ```c
395e41f4b71Sopenharmony_ci        static int32_t HdmiAdapterInit(struct HdfDeviceObject *obj)
396e41f4b71Sopenharmony_ci        {
397e41f4b71Sopenharmony_ci            return HDF_SUCCESS;
398e41f4b71Sopenharmony_ci        }
399e41f4b71Sopenharmony_ci        ```
400e41f4b71Sopenharmony_ci    
401e41f4b71Sopenharmony_ci    - **Release** function
402e41f4b71Sopenharmony_ci    
403e41f4b71Sopenharmony_ci        **Input parameter**:
404e41f4b71Sopenharmony_ci        
405e41f4b71Sopenharmony_ci       **HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
406e41f4b71Sopenharmony_ci       
407e41f4b71Sopenharmony_ci        **Return value**:
408e41f4b71Sopenharmony_ci       
409e41f4b71Sopenharmony_ci        No value is returned.
410e41f4b71Sopenharmony_ci       
411e41f4b71Sopenharmony_ci        **Function description**:
412e41f4b71Sopenharmony_ci       
413e41f4b71Sopenharmony_ci        Releases the memory and deletes the controller. This function assigns values to the **Release** callback in the driver entry structure. If the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources.
414e41f4b71Sopenharmony_ci       
415e41f4b71Sopenharmony_ci        > ![](../public_sys-resources/icon-note.gif) **NOTE**<br>
416e41f4b71Sopenharmony_ci        > All forced conversion operations for obtaining the corresponding object can be successful only when the **Init** function has the corresponding value assignment operations.
417e41f4b71Sopenharmony_ci        ```c
418e41f4b71Sopenharmony_ci        static void HdmiAdapterRelease(struct HdfDeviceObject *obj)
419e41f4b71Sopenharmony_ci        {
420e41f4b71Sopenharmony_ci            struct HdmiCntlr *cntlr = NULL;
421e41f4b71Sopenharmony_ci            ...
422e41f4b71Sopenharmony_ci            cntlr = (struct HdmiCntlr *)obj->service;// Forcibly convert HdfDeviceObject to HdmiCntlr by using service. For details about the value assignment, see the Bind function.
423e41f4b71Sopenharmony_ci            ...
424e41f4b71Sopenharmony_ci            HimciDeleteHost((struct HimciAdapterHost *)cntlr->priv);// Customized memory release function. A forced conversion from HdmiCntlr to HimciAdapterHost is involved in the process.
425e41f4b71Sopenharmony_ci        }
426e41f4b71Sopenharmony_ci        ```
427e41f4b71Sopenharmony_ci       
428