1# MIPI DSI 2 3## Overview 4 5The 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. 6 7MIPI 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. 8[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. 9 10 **Figure 1** DSI transmitting and receiving interface<a name="fig1122611461203"></a> 11  12 13 14## Available APIs 15 16**Table 1** APIs for MIPI DSI 17 18<a name="table4199102313245"></a> 19<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> 20</th> 21<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> 22</th> 23<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> 24</th> 25</tr> 26</thead> 27<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> 28</td> 29<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> 30</td> 31<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> 32</td> 33</tr> 34<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> 35</td> 36<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> 37</td> 38</tr> 39<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> 40</td> 41<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> 42</td> 43<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> 44</td> 45</tr> 46<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> 47</td> 48<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> 49</td> 50</tr> 51<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> 52</td> 53<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> 54</td> 55<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> 56</td> 57</tr> 58<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> 59</td> 60<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> 61</td> 62</tr> 63<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> 64</td> 65<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> 66</td> 67<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> 68</td> 69</tr> 70<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> 71</td> 72<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> 73</td> 74</tr> 75</tbody> 76</table> 77 78> **NOTE**<br> All functions described in this document can be called only in kernel space. 79 80## Usage Guidelines 81 82### How to Use 83 84The figure below illustrates how to use the APIs. 85 86**Figure 2** Using MIPI DSI driver APIs 87 88  89 90### Obtaining a MIPI DSI Device Handle<a name="section5126155683811"></a> 91 92Before 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. 93 94DevHandle MipiDsiOpen\(uint8\_t id\); 95 96**Table 2** Description of **MipiDsiOpen** 97 98<a name="table7603619123820"></a> 99<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> 100</th> 101<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> 102</th> 103</tr> 104</thead> 105<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> 106</td> 107<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> 108</td> 109</tr> 110<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> 111</td> 112<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> 113</td> 114</tr> 115<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> 116</td> 117<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> 118</td> 119</tr> 120<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> 121</td> 122<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> 123</td> 124</tr> 125</tbody> 126</table> 127 128The following example shows how to obtain a MIPI DSI device handle with the channel ID **0**: 129 130``` 131DevHandle mipiDsiHandle = NULL; /* Device handle */ 132chnId = 0; /* MIPI DSI channel ID */ 133 134/* Obtain the MIPI DSI device handle based on a specified channel ID. */ 135mipiDsiHandle = MipiDsiOpen(chnId); 136if (mipiDsiHandle == NULL) { 137 HDF_LOGE("MipiDsiOpen: failed\n"); 138 return; 139} 140``` 141 142### Setting MIPI DSI Configuration Parameters<a name="section201164274344"></a> 143 144- Set MIPI DSI configuration parameters by calling the following function: 145 146int32\_t MipiDsiSetCfg\(DevHandle handle, struct MipiCfg \*cfg\); 147 148**Table 3** Description of **MipiDsiSetCfg** 149 150<a name="table10692555281"></a> 151<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> 152</th> 153<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> 154</th> 155</tr> 156</thead> 157<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> 158</td> 159<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> 160</td> 161</tr> 162<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> 163</td> 164<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> 165</td> 166</tr> 167<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> 168</td> 169<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> 170</td> 171</tr> 172<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> 173</td> 174<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> 175</td> 176</tr> 177<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> 178</td> 179<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> 180</td> 181</tr> 182</tbody> 183</table> 184 185``` 186int32_t ret; 187struct MipiCfg cfg = {0}; 188 189/* Configuration parameters of the connected device are as follows: */ 190cfg.lane = DSI_4_LANES; 191cfg.mode = DSI_CMD_MODE; 192cfg.burstMode = VIDEO_NON_BURST_MODE_SYNC_EVENTS; 193cfg.format = FORMAT_RGB_24_BIT; 194cfg.pixelClk = 174; 195cfg.phyDataRate = 384; 196cfg.timingInfo.hsaPixels = 50; 197cfg.timingInfo.hbpPixels = 55; 198cfg.timingInfo.hlinePixels = 1200; 199cfg.timingInfo.yResLines = 1800; 200cfg.timingInfo.vbpLines = 33; 201cfg.timingInfo.vsaLines = 76; 202cfg.timingInfo.vfpLines = 120; 203cfg.timingInfo.xResPixels = 1342; 204/* Set MIPI DSI configuration parameters. */ 205ret = MipiDsiSetCfg(mipiDsiHandle, &cfg); 206if (ret != 0) { 207 HDF_LOGE("%s: SetMipiCfg fail! ret=%d\n", __func__, ret); 208 return -1; 209} 210``` 211 212- Obtain MIPI DSI configuration parameters by calling the following function: 213 214int32\_t MipiDsiGetCfg\(DevHandle handle, struct MipiCfg \*cfg\); 215 216**Table 4** Description of **MipiDsiGetCfg** 217 218<a name="table7709554280"></a> 219<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> 220</th> 221<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> 222</th> 223</tr> 224</thead> 225<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> 226</td> 227<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> 228</td> 229</tr> 230<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> 231</td> 232<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> 233</td> 234</tr> 235<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> 236</td> 237<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> 238</td> 239</tr> 240<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> 241</td> 242<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> 243</td> 244</tr> 245<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> 246</td> 247<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> 248</td> 249</tr> 250</tbody> 251</table> 252 253``` 254int32_t ret; 255struct MipiCfg cfg; 256memset(&cfg, 0, sizeof(struct MipiCfg)); 257ret = MipiDsiGetCfg(mipiDsiHandle, &cfg); 258if (ret != HDF_SUCCESS) { 259 HDF_LOGE("%s: GetMipiCfg fail!\n", __func__); 260 return HDF_FAILURE; 261} 262``` 263 264### Sending/Receiving the Pointer to a Command<a name="section199401342173415"></a> 265 266- Send the pointer to a specified command by calling the following function: 267 268int32\_t MipiDsiTx\(PalHandle handle, struct DsiCmdDesc \*cmd\); 269 270**Table 5** Description of **MipiDsiTx** 271 272<a name="table1018490043"></a> 273<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> 274</th> 275<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> 276</th> 277</tr> 278</thead> 279<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> 280</td> 281<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> 282</td> 283</tr> 284<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> 285</td> 286<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> 287</td> 288</tr> 289<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> 290</td> 291<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> 292</td> 293</tr> 294<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> 295</td> 296<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> 297</td> 298</tr> 299<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> 300</td> 301<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> 302</td> 303</tr> 304</tbody> 305</table> 306 307``` 308int32_t ret; 309struct DsiCmdDesc *cmd = OsalMemCalloc(sizeof(struct DsiCmdDesc)); 310if (cmd == NULL) { 311 return HDF_FAILURE; 312} 313cmd->dtype = DTYPE_DCS_WRITE; 314cmd->dlen = 1; 315cmd->payload = OsalMemCalloc(sizeof(uint8_t)); 316if (cmd->payload == NULL) { 317 HdfFree(cmd); 318 return HDF_FAILURE; 319} 320*(cmd->payload) = DTYPE_GEN_LWRITE; 321MipiDsiSetLpMode(mipiHandle); 322ret = MipiDsiTx(mipiHandle, cmd); 323MipiDsiSetHsMode(mipiHandle); 324if (ret != HDF_SUCCESS) { 325 HDF_LOGE("%s: PalMipiDsiTx fail! ret=%d\n", __func__, ret); 326 HdfFree(cmd->payload); 327 HdfFree(cmd); 328 return HDF_FAILURE; 329} 330HdfFree(cmd->payload); 331HdfFree(cmd); 332``` 333 334- Receive a specified command by calling the following function: 335 336int32\_t MipiDsiRx\(DevHandle handle, struct DsiCmdDesc \*cmd, uint32\_t readLen, uint8\_t \*out\); 337 338**Table 6** Description of **MipiDsiRx** 339 340<a name="table223910318361"></a> 341<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> 342</th> 343<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> 344</th> 345</tr> 346</thead> 347<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> 348</td> 349<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> 350</td> 351</tr> 352<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> 353</td> 354<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> 355</td> 356</tr> 357<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> 358</td> 359<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> 360</td> 361</tr> 362<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> 363</td> 364<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> 365</td> 366</tr> 367<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> 368</td> 369<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> 370</td> 371</tr> 372<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> 373</td> 374<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> 375</td> 376</tr> 377<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> 378</td> 379<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> 380</td> 381</tr> 382</tbody> 383</table> 384 385``` 386int32_t ret; 387uint8_t readVal = 0; 388 389struct DsiCmdDesc *cmdRead = OsalMemCalloc(sizeof(struct DsiCmdDesc)); 390if (cmdRead == NULL) { 391 return HDF_FAILURE; 392} 393cmdRead->dtype = DTYPE_DCS_READ; 394cmdRead->dlen = 1; 395cmdRead->payload = OsalMemCalloc(sizeof(uint8_t)); 396if (cmdRead->payload == NULL) { 397 HdfFree(cmdRead); 398 return HDF_FAILURE; 399} 400*(cmdRead->payload) = DDIC_REG_STATUS; 401MipiDsiSetLpMode(mipiDsiHandle); 402ret = MipiDsiRx(mipiDsiHandle, cmdRead, sizeof(readVal), &readVal); 403MipiDsiSetHsMode(mipiDsiHandle); 404if (ret != HDF_SUCCESS) { 405 HDF_LOGE("%s: MipiDsiRx fail! ret=%d\n", __func__, ret); 406 HdfFree(cmdRead->payload); 407 HdfFree(cmdRead); 408 return HDF_FAILURE; 409} 410HdfFree(cmdRead->payload); 411HdfFree(cmdRead); 412``` 413 414### Releasing the MIPI DSI Device Handle<a name="section161011610357"></a> 415 416After the MIPI DSI communication, release the MIPI DSI device handle by calling the following function: 417 418void MipiDsiClose\(DevHandle handle\); 419 420This function releases the resources requested by **MipiDsiOpen**. 421 422**Table 7** Description of **MipiDsiClose** 423 424<a name="table72517953115"></a> 425<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> 426</th> 427<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> 428</th> 429</tr> 430</thead> 431<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> 432</td> 433<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> 434</td> 435</tr> 436</tbody> 437</table> 438 439``` 440MipiDsiClose(mipiHandle); /* Release the MIPI DSI device handle */ 441``` 442 443## Usage Example<a name="section17470126123520"></a> 444 445The following is an example of using a MIPI DSI device: 446 447``` 448#include "hdf.h" 449#include "mipi_dsi_if.h" 450 451void PalMipiDsiTestSample(void) 452{ 453 uint8_t chnId; 454 int32_t ret; 455 DevHandle mipiDsiHandle = NULL; 456 457 /* Device channel ID */ 458 chnId = 0; 459 /* Obtain the MIPI DSI device handle based on a specified channel ID. */ 460 mipiDsiHandle = MipiDsiOpen(chnId); 461 if (mipiDsiHandle == NULL) { 462 HDF_LOGE("MipiDsiOpen: failed!\n"); 463 return; 464 } 465 /* MIPI DSI configuration parameters */ 466 struct MipiCfg cfg = {0}; 467 cfg.lane = DSI_4_LANES; 468 cfg.mode = DSI_CMD_MODE; 469 cfg.burstMode = VIDEO_NON_BURST_MODE_SYNC_EVENTS; 470 cfg.format = FORMAT_RGB_24_BIT; 471 cfg.pixelClk = 174; 472 cfg.phyDataRate = 384; 473 cfg.timingInfo.hsaPixels = 50; 474 cfg.timingInfo.hbpPixels = 55; 475 cfg.timingInfo.hlinePixels = 1200; 476 cfg.timingInfo.yResLines = 1800; 477 cfg.timingInfo.vbpLines = 33; 478 cfg.timingInfo.vsaLines = 76; 479 cfg.timingInfo.vfpLines = 120; 480 cfg.timingInfo.xResPixels = 1342; 481 /* Set MIPI DSI configuration parameters. */ 482 ret = MipiDsiSetCfg(mipiDsiHandle, &cfg); 483 if (ret != 0) { 484 HDF_LOGE("%s: SetMipiCfg fail! ret=%d\n", __func__, ret); 485 return; 486 } 487 /* Send the command for initializing the PANEL register. */ 488 struct DsiCmdDesc *cmd = OsalMemCalloc(sizeof(struct DsiCmdDesc)); 489 if (cmd == NULL) { 490 return; 491 } 492 cmd->dtype = DTYPE_DCS_WRITE; 493 cmd->dlen = 1; 494 cmd->payload = OsalMemCalloc(sizeof(uint8_t)); 495 if (cmd->payload == NULL) { 496 HdfFree(cmd); 497 return; 498 } 499 *(cmd->payload) = DTYPE_GEN_LWRITE; 500 MipiDsiSetLpMode(mipiHandle); 501 ret = MipiDsiTx(mipiHandle, cmd); 502 MipiDsiSetHsMode(mipiHandle); 503 if (ret != HDF_SUCCESS) { 504 HDF_LOGE("%s: MipiDsiTx fail! ret=%d\n", __func__, ret); 505 HdfFree(cmd->payload); 506 HdfFree(cmd); 507 return; 508 } 509 HdfFree(cmd->payload); 510 HdfFree(cmd); 511 /* Pointer to the register that reads the PANEL status */ 512 uint8_t readVal = 0; 513 struct DsiCmdDesc *cmdRead = OsalMemCalloc(sizeof(struct DsiCmdDesc)); 514 if (cmdRead == NULL) { 515 return; 516 } 517 cmdRead->dtype = DTYPE_DCS_READ; 518 cmdRead->dlen = 1; 519 cmdRead->payload = OsalMemCalloc(sizeof(uint8_t)); 520 if (cmdRead->payload == NULL) { 521 HdfFree(cmdRead); 522 return; 523 } 524 *(cmdRead->payload) = DDIC_REG_STATUS; 525 MipiDsiSetLpMode(mipiDsiHandle); 526 ret = MipiDsiRx(mipiDsiHandle, cmdRead, sizeof(readVal), &readVal); 527 MipiDsiSetHsMode(mipiDsiHandle); 528 if (ret != HDF_SUCCESS) { 529 HDF_LOGE("%s: MipiDsiRx fail! ret=%d\n", __func__, ret); 530 HdfFree(cmdRead->payload); 531 HdfFree(cmdRead); 532 return; 533 } 534 HdfFree(cmdRead->payload); 535 HdfFree(cmdRead); 536 /* Release the MIPI DSI device handle. */ 537 MipiDsiClose(handle); 538} 539```