1# MIPI DSI<a name="EN-US_TOPIC_0000001062724343"></a> 2 3- [Overview](#section16806142183217) 4 - [Available APIs](#section129611916132011) 5 6- [Usage Guidelines](#section037231715335) 7 - [How to Use](#section49299119344) 8 - [Obtains a MIPI DSI device handle.](#section5126155683811) 9 - [Setting MIPI DSI Configuration Parameters](#section201164274344) 10 - [Sending/Receiving the Pointer to a Command](#section199401342173415) 11 - [Releasing the MIPI DSI Device Handle](#section161011610357) 12 13- [Usage Example](#section17470126123520) 14 15## Overview<a name="section16806142183217"></a> 16 17- The Display Serial Interface \(DSI\) is a specification stipulated by the Mobile Industry Processor Interface \(MIPI\) Alliance, aiming to reduce the cost of display controllers in a mobile device. It defines a serial bus and communication protocol among the host, the source of image data, and the target device. In this way, the DSI can send pixel data or commands to peripherals \(usually LCDs or similar display devices\) in serial mode, or reads information such as status and pixel from the peripherals. 18 19- MIPI DSI is capable of working in both high speed \(HS\) mode and low power \(LP\) mode. All data lanes can only travel from the DSI host to a peripheral in HS mode, except the first data lane, which can also receive data such as status information and pixels from the peripheral in LP mode. The clock lane is dedicated to transmitting synchronization clock signals in HS mode. 20- [Figure 1](#fig1122611461203) shows a simplified DSI interface. Conceptually, a DSI-compliant interface has the same features as interfaces complying with DBI-2 and DPI-2 standards. It sends pixels or commands to a peripheral and can read status or pixel information from the peripheral. The main difference is that the DSI serializes all pixel data, commands, and events that, in traditional interfaces, are conveyed to and from the peripheral on a parallel data bus with additional control signals. 21 22 **Figure 1** DSI transmitting and receiving interface<a name="fig1122611461203"></a> 23  24 25 26### Available APIs<a name="section129611916132011"></a> 27 28**Table 1** APIs for MIPI DSI 29 30<a name="table4199102313245"></a> 31<table><thead align="left"><tr id="row1619910238244"><th class="cellrowborder" valign="top" width="26.619999999999997%" id="mcps1.2.4.1.1"><p id="p141991023182411"><a name="p141991023182411"></a><a name="p141991023182411"></a>Capability</p> 32</th> 33<th class="cellrowborder" valign="top" width="28.910000000000004%" id="mcps1.2.4.1.2"><p id="p1199102315247"><a name="p1199102315247"></a><a name="p1199102315247"></a>Function</p> 34</th> 35<th class="cellrowborder" valign="top" width="44.47%" id="mcps1.2.4.1.3"><p id="p719918232240"><a name="p719918232240"></a><a name="p719918232240"></a>Description</p> 36</th> 37</tr> 38</thead> 39<tbody><tr id="row15199023172414"><td class="cellrowborder" rowspan="2" valign="top" width="26.619999999999997%" headers="mcps1.2.4.1.1 "><p id="p919902312413"><a name="p919902312413"></a><a name="p919902312413"></a>Setting/Obtaining MIPI DSI configuration parameters</p> 40</td> 41<td class="cellrowborder" valign="top" width="28.910000000000004%" headers="mcps1.2.4.1.2 "><p id="p21995232243"><a name="p21995232243"></a><a name="p21995232243"></a>MipiDsiSetCfg</p> 42</td> 43<td class="cellrowborder" valign="top" width="44.47%" headers="mcps1.2.4.1.3 "><p id="p919911233240"><a name="p919911233240"></a><a name="p919911233240"></a>Sets configuration parameters for a MIPI DSI device.</p> 44</td> 45</tr> 46<tr id="row171996232248"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p7199623152412"><a name="p7199623152412"></a><a name="p7199623152412"></a>MipiDsiGetCfg</p> 47</td> 48<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1119919235248"><a name="p1119919235248"></a><a name="p1119919235248"></a>Obtains configuration parameters of a MIPI DSI device.</p> 49</td> 50</tr> 51<tr id="row91994239242"><td class="cellrowborder" rowspan="2" valign="top" width="26.619999999999997%" headers="mcps1.2.4.1.1 "><p id="p101998233245"><a name="p101998233245"></a><a name="p101998233245"></a>Obtaining /Releasing device handles</p> 52</td> 53<td class="cellrowborder" valign="top" width="28.910000000000004%" headers="mcps1.2.4.1.2 "><p id="p51991323112415"><a name="p51991323112415"></a><a name="p51991323112415"></a>MipiDsiOpen</p> 54</td> 55<td class="cellrowborder" valign="top" width="44.47%" headers="mcps1.2.4.1.3 "><p id="p11991623182415"><a name="p11991623182415"></a><a name="p11991623182415"></a>Obtains a MIPI DSI device handle.</p> 56</td> 57</tr> 58<tr id="row12199192352411"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p131991123172412"><a name="p131991123172412"></a><a name="p131991123172412"></a>MipiDsiClose</p> 59</td> 60<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p520062313249"><a name="p520062313249"></a><a name="p520062313249"></a>Releases a specified MIPI DSI device handle.</p> 61</td> 62</tr> 63<tr id="row7200152382417"><td class="cellrowborder" rowspan="2" valign="top" width="26.619999999999997%" headers="mcps1.2.4.1.1 "><p id="p8200202312241"><a name="p8200202312241"></a><a name="p8200202312241"></a>Setting the LP or HS mode</p> 64</td> 65<td class="cellrowborder" valign="top" width="28.910000000000004%" headers="mcps1.2.4.1.2 "><p id="p6200192318247"><a name="p6200192318247"></a><a name="p6200192318247"></a>MipiDsiSetLpMode</p> 66</td> 67<td class="cellrowborder" valign="top" width="44.47%" headers="mcps1.2.4.1.3 "><p id="p16200192319240"><a name="p16200192319240"></a><a name="p16200192319240"></a>Sets LP mode for a MIPI DSI device.</p> 68</td> 69</tr> 70<tr id="row122001523182417"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p22009236249"><a name="p22009236249"></a><a name="p22009236249"></a>MipiDsiSetHsMode</p> 71</td> 72<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p22001423192418"><a name="p22001423192418"></a><a name="p22001423192418"></a>Sets HS mode for a MIPI DSI device.</p> 73</td> 74</tr> 75<tr id="row52002237248"><td class="cellrowborder" rowspan="2" valign="top" width="26.619999999999997%" headers="mcps1.2.4.1.1 "><p id="p10200162332412"><a name="p10200162332412"></a><a name="p10200162332412"></a>Reading/Sending commands</p> 76</td> 77<td class="cellrowborder" valign="top" width="28.910000000000004%" headers="mcps1.2.4.1.2 "><p id="p19200142315249"><a name="p19200142315249"></a><a name="p19200142315249"></a>MipiDsiTx</p> 78</td> 79<td class="cellrowborder" valign="top" width="44.47%" headers="mcps1.2.4.1.3 "><p id="p1020082319243"><a name="p1020082319243"></a><a name="p1020082319243"></a>Sends a display command set (DCS) command for sending data.</p> 80</td> 81</tr> 82<tr id="row6200162372416"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p18200112392417"><a name="p18200112392417"></a><a name="p18200112392417"></a>MipiDsiRx</p> 83</td> 84<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p9200102312249"><a name="p9200102312249"></a><a name="p9200102312249"></a>Receives a DCS command for reading data with the specified length.</p> 85</td> 86</tr> 87</tbody> 88</table> 89 90> **NOTE:** 91>All functions described in this document can be called only in kernel space. 92 93## Usage Guidelines<a name="section037231715335"></a> 94 95### How to Use<a name="section49299119344"></a> 96 97[Figure 2](#fig99821771782) shows the process of using a MIPI DSI device. 98 99**Figure 2** Process of using a MIPI DSI device<a name="fig99821771782"></a> 100 101 102 103 104### Obtains a MIPI DSI device handle.<a name="section5126155683811"></a> 105 106Before performing MIPI DSI communication, obtain a MIPI DSI device handle by calling **MipiDsiOpen**. This function returns a MIPI DSI device handle with a specified channel ID. 107 108DevHandle MipiDsiOpen\(uint8\_t id\); 109 110**Table 2** Description of **MipiDsiOpen** 111 112<a name="table7603619123820"></a> 113<table><thead align="left"><tr id="row1060351914386"><th class="cellrowborder" valign="top" width="20.66%" id="mcps1.2.3.1.1"><p id="p14603181917382"><a name="p14603181917382"></a><a name="p14603181917382"></a><strong id="b824620346298"><a name="b824620346298"></a><a name="b824620346298"></a>Parameter</strong></p> 114</th> 115<th class="cellrowborder" valign="top" width="79.34%" id="mcps1.2.3.1.2"><p id="p36031519183819"><a name="p36031519183819"></a><a name="p36031519183819"></a><strong id="b465435112910"><a name="b465435112910"></a><a name="b465435112910"></a>Description</strong></p> 116</th> 117</tr> 118</thead> 119<tbody><tr id="row960361918383"><td class="cellrowborder" valign="top" width="20.66%" headers="mcps1.2.3.1.1 "><p id="p8603161903818"><a name="p8603161903818"></a><a name="p8603161903818"></a>id</p> 120</td> 121<td class="cellrowborder" valign="top" width="79.34%" headers="mcps1.2.3.1.2 "><p id="p19603111916381"><a name="p19603111916381"></a><a name="p19603111916381"></a>MIPI DSI channel ID.</p> 122</td> 123</tr> 124<tr id="row11410612183019"><td class="cellrowborder" valign="top" width="20.66%" headers="mcps1.2.3.1.1 "><p id="p460381915385"><a name="p460381915385"></a><a name="p460381915385"></a><strong id="b132118377294"><a name="b132118377294"></a><a name="b132118377294"></a>Return Value</strong></p> 125</td> 126<td class="cellrowborder" valign="top" width="79.34%" headers="mcps1.2.3.1.2 "><p id="p96031619153812"><a name="p96031619153812"></a><a name="p96031619153812"></a><strong id="b1661638162915"><a name="b1661638162915"></a><a name="b1661638162915"></a>Description</strong></p> 127</td> 128</tr> 129<tr id="row15410111273017"><td class="cellrowborder" valign="top" width="20.66%" headers="mcps1.2.3.1.1 "><p id="p1060418195389"><a name="p1060418195389"></a><a name="p1060418195389"></a>NULL</p> 130</td> 131<td class="cellrowborder" valign="top" width="79.34%" headers="mcps1.2.3.1.2 "><p id="p760471912388"><a name="p760471912388"></a><a name="p760471912388"></a>Failed to receive the specified command.</p> 132</td> 133</tr> 134<tr id="row1241081213303"><td class="cellrowborder" valign="top" width="20.66%" headers="mcps1.2.3.1.1 "><p id="p5604719133811"><a name="p5604719133811"></a><a name="p5604719133811"></a>Device handle</p> 135</td> 136<td class="cellrowborder" valign="top" width="79.34%" headers="mcps1.2.3.1.2 "><p id="p3604181933818"><a name="p3604181933818"></a><a name="p3604181933818"></a>MIPI DSI device handle with a specified channel ID, whose data type is <strong id="b643184319293"><a name="b643184319293"></a><a name="b643184319293"></a>DevHandle</strong>.</p> 137</td> 138</tr> 139</tbody> 140</table> 141 142The following example shows how to obtain a MIPI DSI device handle with the channel ID **0**: 143 144``` 145DevHandle mipiDsiHandle = NULL; /* Device handle */ 146chnId = 0; /* MIPI DSI channel ID */ 147 148/* Obtain the MIPI DSI device handle based on a specified channel ID. */ 149mipiDsiHandle = MipiDsiOpen(chnId); 150if (mipiDsiHandle == NULL) { 151 HDF_LOGE("MipiDsiOpen: failed\n"); 152 return; 153} 154``` 155 156### Setting MIPI DSI Configuration Parameters<a name="section201164274344"></a> 157 158- Set MIPI DSI configuration parameters by calling the following function: 159 160int32\_t MipiDsiSetCfg\(DevHandle handle, struct MipiCfg \*cfg\); 161 162**Table 3** Description of **MipiDsiSetCfg** 163 164<a name="table10692555281"></a> 165<table><thead align="left"><tr id="row116914559288"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1169195516288"><a name="p1169195516288"></a><a name="p1169195516288"></a><strong id="b1804534152914"><a name="b1804534152914"></a><a name="b1804534152914"></a>Parameter</strong></p> 166</th> 167<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p769125512286"><a name="p769125512286"></a><a name="p769125512286"></a><strong id="b461693511292"><a name="b461693511292"></a><a name="b461693511292"></a>Description</strong></p> 168</th> 169</tr> 170</thead> 171<tbody><tr id="row4691155142812"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p66935515288"><a name="p66935515288"></a><a name="p66935515288"></a>handle</p> 172</td> 173<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p863714348217"><a name="p863714348217"></a><a name="p863714348217"></a>MIPI DSI device handle.</p> 174</td> 175</tr> 176<tr id="row469145572817"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p46915519287"><a name="p46915519287"></a><a name="p46915519287"></a>cfg</p> 177</td> 178<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p76995518289"><a name="p76995518289"></a><a name="p76995518289"></a>Pointer to MIPI DSI configuration parameters.</p> 179</td> 180</tr> 181<tr id="row16913554284"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p16955512812"><a name="p16955512812"></a><a name="p16955512812"></a><strong id="b1696737132913"><a name="b1696737132913"></a><a name="b1696737132913"></a>Return Value</strong></p> 182</td> 183<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p206945502813"><a name="p206945502813"></a><a name="p206945502813"></a><strong id="b42104011299"><a name="b42104011299"></a><a name="b42104011299"></a>Description</strong></p> 184</td> 185</tr> 186<tr id="row146914556283"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p669175582818"><a name="p669175582818"></a><a name="p669175582818"></a>0</p> 187</td> 188<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p169205511283"><a name="p169205511283"></a><a name="p169205511283"></a>Succeeded in setting MIPI DSI configuration parameters.</p> 189</td> 190</tr> 191<tr id="row5694558283"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p269175516286"><a name="p269175516286"></a><a name="p269175516286"></a>Negative value</p> 192</td> 193<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p11691554280"><a name="p11691554280"></a><a name="p11691554280"></a>Failed to set MIPI DSI configuration parameters.</p> 194</td> 195</tr> 196</tbody> 197</table> 198 199``` 200int32_t ret; 201struct MipiCfg cfg = {0}; 202 203/* Configuration parameters of the connected device are as follows: */ 204cfg.lane = DSI_4_LANES; 205cfg.mode = DSI_CMD_MODE; 206cfg.burstMode = VIDEO_NON_BURST_MODE_SYNC_EVENTS; 207cfg.format = FORMAT_RGB_24_BIT; 208cfg.pixelClk = 174; 209cfg.phyDataRate = 384; 210cfg.timingInfo.hsaPixels = 50; 211cfg.timingInfo.hbpPixels = 55; 212cfg.timingInfo.hlinePixels = 1200; 213cfg.timingInfo.yResLines = 1800; 214cfg.timingInfo.vbpLines = 33; 215cfg.timingInfo.vsaLines = 76; 216cfg.timingInfo.vfpLines = 120; 217cfg.timingInfo.xResPixels = 1342; 218/* Set MIPI DSI configuration parameters. */ 219ret = MipiDsiSetCfg(g_handle, &cfg); 220if (ret != 0) { 221 HDF_LOGE("%s: SetMipiCfg fail! ret=%d\n", __func__, ret); 222 return -1; 223} 224``` 225 226- Obtain MIPI DSI configuration parameters by calling the following function: 227 228int32\_t MipiDsiGetCfg\(DevHandle handle, struct MipiCfg \*cfg\); 229 230**Table 4** Description of **MipiDsiGetCfg** 231 232<a name="table7709554280"></a> 233<table><thead align="left"><tr id="row670115515282"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p470205515287"><a name="p470205515287"></a><a name="p470205515287"></a><strong id="b14806334142912"><a name="b14806334142912"></a><a name="b14806334142912"></a>Parameter</strong></p> 234</th> 235<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p270755162817"><a name="p270755162817"></a><a name="p270755162817"></a><strong id="b6618113519294"><a name="b6618113519294"></a><a name="b6618113519294"></a>Description</strong></p> 236</th> 237</tr> 238</thead> 239<tbody><tr id="row57014555286"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p11701155172815"><a name="p11701155172815"></a><a name="p11701155172815"></a>handle</p> 240</td> 241<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p57015510283"><a name="p57015510283"></a><a name="p57015510283"></a>MIPI DSI device handle.</p> 242</td> 243</tr> 244<tr id="row1870155192815"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p137115572815"><a name="p137115572815"></a><a name="p137115572815"></a>cfg</p> 245</td> 246<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p771195522818"><a name="p771195522818"></a><a name="p771195522818"></a>Pointer to MIPI DSI configuration parameters.</p> 247</td> 248</tr> 249<tr id="row12718555283"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1871175515289"><a name="p1871175515289"></a><a name="p1871175515289"></a><strong id="b8698737142912"><a name="b8698737142912"></a><a name="b8698737142912"></a>Return Value</strong></p> 250</td> 251<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p771955182813"><a name="p771955182813"></a><a name="p771955182813"></a><strong id="b84194010291"><a name="b84194010291"></a><a name="b84194010291"></a>Description</strong></p> 252</td> 253</tr> 254<tr id="row1071155582812"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p6718551282"><a name="p6718551282"></a><a name="p6718551282"></a>0</p> 255</td> 256<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p171195516285"><a name="p171195516285"></a><a name="p171195516285"></a>Succeeded in receiving the specified command.</p> 257</td> 258</tr> 259<tr id="row97135519282"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p11711355162815"><a name="p11711355162815"></a><a name="p11711355162815"></a>Negative value</p> 260</td> 261<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p77116555286"><a name="p77116555286"></a><a name="p77116555286"></a>Failed to receive the specified command.</p> 262</td> 263</tr> 264</tbody> 265</table> 266 267``` 268int32_t ret; 269struct MipiCfg cfg; 270memset(&cfg, 0, sizeof(struct MipiCfg)); 271ret = MipiDsiGetCfg(g_handle, &cfg); 272if (ret != HDF_SUCCESS) { 273 HDF_LOGE("%s: GetMipiCfg fail!\n", __func__); 274 return HDF_FAILURE; 275} 276``` 277 278### Sending/Receiving the Pointer to a Command<a name="section199401342173415"></a> 279 280- Send the pointer to a specified command by calling the following function: 281 282int32\_t MipiDsiTx\(PalHandle handle, struct DsiCmdDesc \*cmd\); 283 284**Table 5** Description of **MipiDsiTx** 285 286<a name="table1018490043"></a> 287<table><thead align="left"><tr id="row31848013417"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1415816132411"><a name="p1415816132411"></a><a name="p1415816132411"></a><strong id="b1280873492913"><a name="b1280873492913"></a><a name="b1280873492913"></a>Parameter</strong></p> 288</th> 289<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p11158111316410"><a name="p11158111316410"></a><a name="p11158111316410"></a><strong id="b1461953592915"><a name="b1461953592915"></a><a name="b1461953592915"></a>Description</strong></p> 290</th> 291</tr> 292</thead> 293<tbody><tr id="row10184701945"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p104891871157"><a name="p104891871157"></a><a name="p104891871157"></a>handle</p> 294</td> 295<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p204891671156"><a name="p204891671156"></a><a name="p204891671156"></a>MIPI DSI device handle.</p> 296</td> 297</tr> 298<tr id="row928111518418"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p4282955412"><a name="p4282955412"></a><a name="p4282955412"></a>cmd</p> 299</td> 300<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p7282752412"><a name="p7282752412"></a><a name="p7282752412"></a>Pointer to the command to be sent.</p> 301</td> 302</tr> 303<tr id="row17393154515328"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p8158313248"><a name="p8158313248"></a><a name="p8158313248"></a><strong id="b969917374296"><a name="b969917374296"></a><a name="b969917374296"></a>Return Value</strong></p> 304</td> 305<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p161591413741"><a name="p161591413741"></a><a name="p161591413741"></a><strong id="b1351140142912"><a name="b1351140142912"></a><a name="b1351140142912"></a>Description</strong></p> 306</td> 307</tr> 308<tr id="row339324593215"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p103191916578"><a name="p103191916578"></a><a name="p103191916578"></a>0</p> 309</td> 310<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1231981611712"><a name="p1231981611712"></a><a name="p1231981611712"></a>Succeeded in sending the specified command.</p> 311</td> 312</tr> 313<tr id="row15393184519323"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p531916166716"><a name="p531916166716"></a><a name="p531916166716"></a>Negative value</p> 314</td> 315<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p93191161174"><a name="p93191161174"></a><a name="p93191161174"></a>Failed to send the specified command.</p> 316</td> 317</tr> 318</tbody> 319</table> 320 321``` 322int32_t ret; 323struct DsiCmdDesc *cmd = OsalMemCalloc(sizeof(struct DsiCmdDesc)); 324if (cmd == NULL) { 325 return HDF_FAILURE; 326} 327cmd->dtype = DTYPE_DCS_WRITE; 328cmd->dlen = 1; 329cmd->payload = OsalMemCalloc(sizeof(uint8_t)); 330if (cmd->payload == NULL) { 331 HdfFree(cmd); 332 return HDF_FAILURE; 333} 334*(cmd->payload) = DTYPE_GEN_LWRITE; 335MipiDsiSetLpMode(mipiHandle); 336ret = MipiDsiTx(mipiHandle, cmd); 337MipiDsiSetHsMode(mipiHandle); 338if (ret != HDF_SUCCESS) { 339 HDF_LOGE("%s: PalMipiDsiTx fail! ret=%d\n", __func__, ret); 340 HdfFree(cmd->payload); 341 HdfFree(cmd); 342 return HDF_FAILURE; 343} 344HdfFree(cmd->payload); 345HdfFree(cmd); 346``` 347 348- Receive a specified command by calling the following function: 349 350int32\_t MipiDsiRx\(DevHandle handle, struct DsiCmdDesc \*cmd, uint32\_t readLen, uint8\_t \*out\); 351 352**Table 6** Description of **MipiDsiRx** 353 354<a name="table223910318361"></a> 355<table><thead align="left"><tr id="row924033173613"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p16240143143611"><a name="p16240143143611"></a><a name="p16240143143611"></a><strong id="b19809334172910"><a name="b19809334172910"></a><a name="b19809334172910"></a>Parameter</strong></p> 356</th> 357<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p32401031113610"><a name="p32401031113610"></a><a name="p32401031113610"></a><strong id="b4620163552915"><a name="b4620163552915"></a><a name="b4620163552915"></a>Description</strong></p> 358</th> 359</tr> 360</thead> 361<tbody><tr id="row024043193619"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p16231153542520"><a name="p16231153542520"></a><a name="p16231153542520"></a>handle</p> 362</td> 363<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p122311535122518"><a name="p122311535122518"></a><a name="p122311535122518"></a>MIPI DSI device handle.</p> 364</td> 365</tr> 366<tr id="row192401331163613"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p8706172453614"><a name="p8706172453614"></a><a name="p8706172453614"></a>cmd</p> 367</td> 368<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p0706424183610"><a name="p0706424183610"></a><a name="p0706424183610"></a>Pointer to the command to be received.</p> 369</td> 370</tr> 371<tr id="row12646535173616"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p16465359364"><a name="p16465359364"></a><a name="p16465359364"></a>readLen</p> 372</td> 373<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p564617356360"><a name="p564617356360"></a><a name="p564617356360"></a>Length of the data to read.</p> 374</td> 375</tr> 376<tr id="row919916426361"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p11199942153616"><a name="p11199942153616"></a><a name="p11199942153616"></a>out</p> 377</td> 378<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p91991042143618"><a name="p91991042143618"></a><a name="p91991042143618"></a>Pointer to the read data.</p> 379</td> 380</tr> 381<tr id="row14240133143619"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1723253542518"><a name="p1723253542518"></a><a name="p1723253542518"></a><strong id="b47011237142916"><a name="b47011237142916"></a><a name="b47011237142916"></a>Return Value</strong></p> 382</td> 383<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p223217356253"><a name="p223217356253"></a><a name="p223217356253"></a><strong id="b15616408294"><a name="b15616408294"></a><a name="b15616408294"></a>Description</strong></p> 384</td> 385</tr> 386<tr id="row424093120369"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1123203518257"><a name="p1123203518257"></a><a name="p1123203518257"></a>0</p> 387</td> 388<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p62324353251"><a name="p62324353251"></a><a name="p62324353251"></a>Succeeded in receiving the specified command.</p> 389</td> 390</tr> 391<tr id="row18241531153610"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p42321635122517"><a name="p42321635122517"></a><a name="p42321635122517"></a>Negative value</p> 392</td> 393<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p323283510252"><a name="p323283510252"></a><a name="p323283510252"></a>Failed to receive the specified command.</p> 394</td> 395</tr> 396</tbody> 397</table> 398 399``` 400int32_t ret; 401uint8_t readVal = 0; 402 403struct DsiCmdDesc *cmdRead = OsalMemCalloc(sizeof(struct DsiCmdDesc)); 404if (cmdRead == NULL) { 405 return HDF_FAILURE; 406} 407cmdRead->dtype = DTYPE_DCS_READ; 408cmdRead->dlen = 1; 409cmdRead->payload = OsalMemCalloc(sizeof(uint8_t)); 410if (cmdRead->payload == NULL) { 411 HdfFree(cmdRead); 412 return HDF_FAILURE; 413} 414*(cmdRead->payload) = DDIC_REG_STATUS; 415MipiDsiSetLpMode(g_handle); 416ret = MipiDsiRx(g_handle, cmdRead, sizeof(readVal), &readVal); 417MipiDsiSetHsMode(g_handle); 418if (ret != HDF_SUCCESS) { 419 HDF_LOGE("%s: MipiDsiRx fail! ret=%d\n", __func__, ret); 420 HdfFree(cmdRead->payload); 421 HdfFree(cmdRead); 422 return HDF_FAILURE; 423} 424HdfFree(cmdRead->payload); 425HdfFree(cmdRead); 426``` 427 428### Releasing the MIPI DSI Device Handle<a name="section161011610357"></a> 429 430After the MIPI DSI communication, release the MIPI DSI device handle by calling the following function: 431 432void MipiDsiClose\(DevHandle handle\); 433 434This function releases the resources requested by **MipiDsiOpen**. 435 436**Table 7** Description of **MipiDsiClose** 437 438<a name="table72517953115"></a> 439<table><thead align="left"><tr id="row1525793312"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p115402031153111"><a name="p115402031153111"></a><a name="p115402031153111"></a><strong id="b1487612133120"><a name="b1487612133120"></a><a name="b1487612133120"></a>Parameter</strong></p> 440</th> 441<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p65406313319"><a name="p65406313319"></a><a name="p65406313319"></a><strong id="b6397192316313"><a name="b6397192316313"></a><a name="b6397192316313"></a>Description</strong></p> 442</th> 443</tr> 444</thead> 445<tbody><tr id="row1926109193116"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p105419317318"><a name="p105419317318"></a><a name="p105419317318"></a>handle</p> 446</td> 447<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p132442255912"><a name="p132442255912"></a><a name="p132442255912"></a>MIPI DSI device handle.</p> 448</td> 449</tr> 450</tbody> 451</table> 452 453``` 454MipiDsiClose(mipiHandle); /* Release the MIPI DSI device handle */ 455``` 456 457## Usage Example<a name="section17470126123520"></a> 458 459The following is an example of using a MIPI DSI device: 460 461``` 462#include "hdf.h" 463#include "mipi_dsi_if.h" 464 465void PalMipiDsiTestSample(void) 466{ 467 uint8_t chnId; 468 int32_t ret; 469 DevHandle handle = NULL; 470 471 /* Device channel ID */ 472 chnId = 0; 473 /* Obtain the MIPI DSI device handle based on a specified channel ID. */ 474 handle = MipiDsiOpen(chnId); 475 if (handle == NULL) { 476 HDF_LOGE("MipiDsiOpen: failed!\n"); 477 return; 478 } 479 /* MIPI DSI configuration parameters */ 480 struct MipiCfg cfg = {0}; 481 cfg.lane = DSI_4_LANES; 482 cfg.mode = DSI_CMD_MODE; 483 cfg.burstMode = VIDEO_NON_BURST_MODE_SYNC_EVENTS; 484 cfg.format = FORMAT_RGB_24_BIT; 485 cfg.pixelClk = 174; 486 cfg.phyDataRate = 384; 487 cfg.timingInfo.hsaPixels = 50; 488 cfg.timingInfo.hbpPixels = 55; 489 cfg.timingInfo.hlinePixels = 1200; 490 cfg.timingInfo.yResLines = 1800; 491 cfg.timingInfo.vbpLines = 33; 492 cfg.timingInfo.vsaLines = 76; 493 cfg.timingInfo.vfpLines = 120; 494 cfg.timingInfo.xResPixels = 1342; 495 /* Set MIPI DSI configuration parameters. */ 496 ret = MipiDsiSetCfg(g_handle, &cfg); 497 if (ret != 0) { 498 HDF_LOGE("%s: SetMipiCfg fail! ret=%d\n", __func__, ret); 499 return; 500 } 501 /* Send the command for initializing the PANEL register. */ 502 struct DsiCmdDesc *cmd = OsalMemCalloc(sizeof(struct DsiCmdDesc)); 503 if (cmd == NULL) { 504 return; 505 } 506 cmd->dtype = DTYPE_DCS_WRITE; 507 cmd->dlen = 1; 508 cmd->payload = OsalMemCalloc(sizeof(uint8_t)); 509 if (cmd->payload == NULL) { 510 HdfFree(cmd); 511 return; 512 } 513 *(cmd->payload) = DTYPE_GEN_LWRITE; 514 MipiDsiSetLpMode(mipiHandle); 515 ret = MipiDsiTx(mipiHandle, cmd); 516 MipiDsiSetHsMode(mipiHandle); 517 if (ret != HDF_SUCCESS) { 518 HDF_LOGE("%s: MipiDsiTx fail! ret=%d\n", __func__, ret); 519 HdfFree(cmd->payload); 520 HdfFree(cmd); 521 return; 522 } 523 HdfFree(cmd->payload); 524 HdfFree(cmd); 525 /* Pointer to the register that reads the PANEL status */ 526 uint8_t readVal = 0; 527 struct DsiCmdDesc *cmdRead = OsalMemCalloc(sizeof(struct DsiCmdDesc)); 528 if (cmdRead == NULL) { 529 return; 530 } 531 cmdRead->dtype = DTYPE_DCS_READ; 532 cmdRead->dlen = 1; 533 cmdRead->payload = OsalMemCalloc(sizeof(uint8_t)); 534 if (cmdRead->payload == NULL) { 535 HdfFree(cmdRead); 536 return; 537 } 538 *(cmdRead->payload) = DDIC_REG_STATUS; 539 MipiDsiSetLpMode(g_handle); 540 ret = MipiDsiRx(g_handle, cmdRead, sizeof(readVal), &readVal); 541 MipiDsiSetHsMode(g_handle); 542 if (ret != HDF_SUCCESS) { 543 HDF_LOGE("%s: MipiDsiRx fail! ret=%d\n", __func__, ret); 544 HdfFree(cmdRead->payload); 545 HdfFree(cmdRead); 546 return; 547 } 548 HdfFree(cmdRead->payload); 549 HdfFree(cmdRead); 550 /* Release the MIPI DSI device handle. */ 551 MipiDsiClose(handle); 552} 553``` 554 555