• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <unistd.h>
17 #include <sys/ioctl.h>
18 #include <fcntl.h>
19 
20 #include "hi_mipi_tx.h"
21 #include "sample_comm.h"
22 #include "sample_comm_ive.h"
23 #include "sample_lcd.h"
24 
25 #ifdef __cplusplus
26 #if __cplusplus
27 extern "C" {
28 #endif
29 #endif /* End of #ifdef __cplusplus */
30 
31 #define USLEEP_TIME   1000 // 1000: usleep time, in microseconds
32 #define G_MBUF_LENGTH 50 // 50: length of g_mbuf
33 #define ALIGN_DOWN_SIZE 2
34 
35 #define G_MBUF_ARRAY_SUBSCRIPT_0     0
36 #define G_MBUF_ARRAY_SUBSCRIPT_1     1
37 #define G_MBUF_ARRAY_SUBSCRIPT_2     2
38 #define G_MBUF_ARRAY_SUBSCRIPT_3     3
39 #define G_MBUF_ARRAY_SUBSCRIPT_4     4
40 #define G_MBUF_ARRAY_SUBSCRIPT_5     5
41 #define G_MBUF_ARRAY_SUBSCRIPT_6     6
42 #define G_MBUF_ARRAY_SUBSCRIPT_7     7
43 #define G_MBUF_ARRAY_SUBSCRIPT_8     8
44 #define G_MBUF_ARRAY_SUBSCRIPT_9     9
45 #define G_MBUF_ARRAY_SUBSCRIPT_10    10
46 #define G_MBUF_ARRAY_SUBSCRIPT_11    11
47 #define G_MBUF_ARRAY_SUBSCRIPT_12    12
48 #define G_MBUF_ARRAY_SUBSCRIPT_13    13
49 #define G_MBUF_ARRAY_SUBSCRIPT_14    14
50 #define G_MBUF_ARRAY_SUBSCRIPT_15    15
51 #define G_MBUF_ARRAY_SUBSCRIPT_16    16
52 
53 #define LANE_ID_SUBSCRIPT_0    0
54 #define LANE_ID_SUBSCRIPT_1    1
55 #define LANE_ID_SUBSCRIPT_2    2
56 #define LANE_ID_SUBSCRIPT_3    3
57 
58 static unsigned char g_mBuf[G_MBUF_LENGTH];
59 static SampleVoModeMux g_sampleVoModeMux = {0};
60 static VO_PUB_ATTR_S stVoPubAttr = {0};
61 static VO_VIDEO_LAYER_ATTR_S  stLayerAttr    = {0};
62 static VO_CSC_S               stVideoCSC     = {0};
63 static RECT_S stDefDispRect  = {0, 0, 800, 480};
64 static SIZE_S stDefImageSize = {800, 480};
65 
66 LcdMediaInfo g_lcdMediaInfo = { 0 };
67 
SAMPLE_VOU_SYS_Exit(void)68 HI_VOID SAMPLE_VOU_SYS_Exit(void)
69 {
70     HI_MPI_SYS_Exit();
71     HI_MPI_VB_Exit();
72 }
73 
SAMPLE_VO_GetUserLayerAttr(VO_VIDEO_LAYER_ATTR_S * pstLayerAttr,SIZE_S * pstDevSize)74 HI_VOID SAMPLE_VO_GetUserLayerAttr(VO_VIDEO_LAYER_ATTR_S *pstLayerAttr, SIZE_S *pstDevSize)
75 {
76     pstLayerAttr->bClusterMode = HI_FALSE;
77     pstLayerAttr->bDoubleFrame = HI_FALSE;
78     pstLayerAttr->enDstDynamicRange = DYNAMIC_RANGE_SDR8;
79     pstLayerAttr->enPixFormat = PIXEL_FORMAT_YVU_SEMIPLANAR_420;
80 
81     pstLayerAttr->stDispRect.s32X = 0;
82     pstLayerAttr->stDispRect.s32Y = 0;
83     pstLayerAttr->stDispRect.u32Height = pstDevSize->u32Height;
84     pstLayerAttr->stDispRect.u32Width  = pstDevSize->u32Width;
85 
86     pstLayerAttr->stImageSize.u32Height = pstDevSize->u32Height;
87     pstLayerAttr->stImageSize.u32Width = pstDevSize->u32Width;
88 
89     return;
90 }
91 
SAMPLE_VO_GetUserChnAttr(VO_CHN_ATTR_S * pstChnAttr,SIZE_S * pstDevSize,HI_S32 VoChnNum)92 HI_VOID SAMPLE_VO_GetUserChnAttr(VO_CHN_ATTR_S *pstChnAttr, SIZE_S *pstDevSize, HI_S32 VoChnNum)
93 {
94     HI_S32 i;
95     for (i = 0; i < VoChnNum; i++) {
96         pstChnAttr[i].bDeflicker = HI_FALSE;
97         pstChnAttr[i].u32Priority = 0;
98         pstChnAttr[i].stRect.s32X = 0;
99         pstChnAttr[i].stRect.s32Y = 0;
100         pstChnAttr[i].stRect.u32Height = pstDevSize->u32Height;
101         pstChnAttr[i].stRect.u32Width = pstDevSize->u32Width;
102         }
103 
104     return;
105 }
106 
107 /*
108  * 打开MIPI Tx设备
109  * Open MIPI Tx device
110  */
SampleOpenMipiTxFd(HI_VOID)111 HI_S32 SampleOpenMipiTxFd(HI_VOID)
112 {
113     HI_S32 fd;
114 
115     fd = open("/dev/hi_mipi_tx", O_RDWR);
116     if (fd < 0) {
117         printf("open hi_mipi_tx dev failed\n");
118     }
119     return fd;
120 }
121 
122 /*
123  * 关闭MIPI Tx设备
124  * Close MIPI Tx device
125  */
SampleCloseMipiTxFd(HI_S32 fd)126 HI_VOID SampleCloseMipiTxFd(HI_S32 fd)
127 {
128     close(fd);
129     return;
130 }
131 
132 /*
133  * 获取MIPI Tx配置信息
134  * Get MIPI Tx config information
135  */
SAMPLE_GetMipiTxConfig(combo_dev_cfg_t * pstMipiTxConfig)136 HI_VOID SAMPLE_GetMipiTxConfig(combo_dev_cfg_t *pstMipiTxConfig)
137 {
138     /*
139      * 用户需要设置MIPI设备配置
140      * User need set MIPI device config
141      */
142     pstMipiTxConfig->devno = 0;
143     pstMipiTxConfig->lane_id[LANE_ID_SUBSCRIPT_0] = 0;
144     pstMipiTxConfig->lane_id[LANE_ID_SUBSCRIPT_1] = 1;
145     // -1: 2 lane mode configuration,lane_id[4] = {0, 1, -1, -1}
146     pstMipiTxConfig->lane_id[LANE_ID_SUBSCRIPT_2] = -1;
147     // -1: 2 lane mode configuration,lane_id[4] = {0, 1, -1, -1}
148     pstMipiTxConfig->lane_id[LANE_ID_SUBSCRIPT_3] = -1;
149     pstMipiTxConfig->output_mode = OUTPUT_MODE_DSI_VIDEO;
150     pstMipiTxConfig->output_format = OUT_FORMAT_RGB_24_BIT;
151     pstMipiTxConfig->video_mode = BURST_MODE;
152     pstMipiTxConfig->sync_info.vid_pkt_size = 480; // 480: received packet size
153     pstMipiTxConfig->sync_info.vid_hsa_pixels = 10; // 10: The number of pixels in the input line sync pulse area
154     pstMipiTxConfig->sync_info.vid_hbp_pixels = 50; // 50: Number of pixels in blanking area after input
155     pstMipiTxConfig->sync_info.vid_hline_pixels = 590; // 590: The total number of pixels detected per line
156     pstMipiTxConfig->sync_info.vid_vsa_lines = 4; // 4: Number of frame sync pulse lines detected
157     pstMipiTxConfig->sync_info.vid_vbp_lines = 20; // 20: Number of blanking area lines after frame sync pulse
158     pstMipiTxConfig->sync_info.vid_vfp_lines = 20; // 20:Number of blanking area lines before frame sync pulse
159     pstMipiTxConfig->sync_info.vid_active_lines = 800; // 800: VACTIVE rows
160     pstMipiTxConfig->sync_info.edpi_cmd_size = 0; // 0: Write memory command bytes
161     pstMipiTxConfig->phy_data_rate = 359; // 359: MIPI Tx output rate
162     pstMipiTxConfig->pixel_clk = 29878; // 29878: pixel clock. The unit is KHz
163 
164     return;
165 }
166 
167 /*
168  * 设置MIPI Tx配置信息
169  * Set MIPI Tx config information
170  */
SAMPLE_SetMipiTxConfig(HI_S32 fd,combo_dev_cfg_t * pstMipiTxConfig)171 HI_S32 SAMPLE_SetMipiTxConfig(HI_S32 fd, combo_dev_cfg_t *pstMipiTxConfig)
172 {
173     HI_S32 s32Ret = ioctl(fd, HI_MIPI_TX_SET_DEV_CFG, pstMipiTxConfig);
174     if (s32Ret != HI_SUCCESS) {
175         printf("MIPI_TX SET_DEV_CONFIG failed\n");
176         SampleCloseMipiTxFd(fd);
177         return s32Ret;
178     }
179     return s32Ret;
180 }
181 
182 /*
183  * 设置MIPI Tx设备属性
184  * Set MIPI Tx device attr
185  */
SampleSetMipiTxDevAttr(HI_S32 fd)186 HI_S32 SampleSetMipiTxDevAttr(HI_S32 fd)
187 {
188     HI_S32 s32Ret;
189     combo_dev_cfg_t stMipiTxConfig;
190 
191     SAMPLE_GetMipiTxConfig(&stMipiTxConfig); // USER GET MIPI DEV CONFIG
192     s32Ret = SAMPLE_SetMipiTxConfig(fd, &stMipiTxConfig); // USER SET MIPI DEV CONFIG
193 
194     return s32Ret;
195 }
196 
197 /*
198  * 初始化MIPI Tx设备
199  * Init MIPI Tx device
200  */
SAMPLE_USER_INIT_MIPITx(HI_S32 fd,cmd_info_t * pcmd_info)201 HI_S32 SAMPLE_USER_INIT_MIPITx(HI_S32 fd, cmd_info_t *pcmd_info)
202 {
203     HI_S32 s32Ret = ioctl(fd, HI_MIPI_TX_SET_CMD, pcmd_info);
204     if (s32Ret !=  HI_SUCCESS) {
205         printf("MIPI_TX SET CMD failed\n");
206         SampleCloseMipiTxFd(fd);
207         return s32Ret;
208     }
209 
210     return HI_SUCCESS;
211 }
212 
213 /*
214  * 配置MIPI Tx初始化序列
215  * Config MIPI Tx initialization sequence
216  */
SampleVoInitMipiTxScreen(HI_S32 fd)217 HI_S32 SampleVoInitMipiTxScreen(HI_S32 fd)
218 {
219     HI_S32 s32Ret;
220     cmd_info_t cmd_info;
221     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
222     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xFF;
223     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x77;
224     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x01;
225     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0x00;
226     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_4] = 0x00;
227     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_5] = 0x13;
228     cmd_info.devno = 0;
229     cmd_info.cmd_size = 6; // 6: command data size
230     cmd_info.data_type = 0x29;
231     cmd_info.cmd = g_mBuf;
232     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
233     if (s32Ret != HI_SUCCESS) {
234         return s32Ret;
235     }
236     usleep(USLEEP_TIME);
237 
238     cmd_info.devno = 0;
239     cmd_info.cmd_size = 0x08ef;
240     cmd_info.data_type = 0x23;
241     cmd_info.cmd = NULL;
242     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
243     if (s32Ret != HI_SUCCESS) {
244         return s32Ret;
245     }
246     usleep(USLEEP_TIME);
247 
248     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
249     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xFF;
250     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x77;
251     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x01;
252     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0x00;
253     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_4] = 0x00;
254     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_5] = 0x10;
255     cmd_info.devno = 0;
256     cmd_info.cmd_size = 6; // 6: command data size
257     cmd_info.data_type = 0x29;
258     cmd_info.cmd = g_mBuf;
259     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
260     if (s32Ret != HI_SUCCESS) {
261         return s32Ret;
262     }
263     usleep(USLEEP_TIME);
264 
265     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
266     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xC0;
267     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x63;
268     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x00;
269     cmd_info.devno = 0;
270     cmd_info.cmd_size = 3; // 3: command data size
271     cmd_info.data_type = 0x29;
272     cmd_info.cmd = g_mBuf;
273     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
274     if (s32Ret != HI_SUCCESS) {
275         return s32Ret;
276     }
277     usleep(USLEEP_TIME);
278 
279     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
280     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xC1;
281     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x10;
282     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x02;
283     cmd_info.devno = 0;
284     cmd_info.cmd_size = 3; // 3: command data size
285     cmd_info.data_type = 0x29;
286     cmd_info.cmd = g_mBuf;
287     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
288     if (s32Ret != HI_SUCCESS) {
289         return s32Ret;
290     }
291     usleep(USLEEP_TIME);
292 
293     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
294     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xC2;
295     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x01;
296     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x08;
297     cmd_info.devno = 0;
298     cmd_info.cmd_size = 3; // 3: command data size
299     cmd_info.data_type = 0x29;
300     cmd_info.cmd = g_mBuf;
301     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
302     if (s32Ret != HI_SUCCESS) {
303         return s32Ret;
304     }
305     usleep(USLEEP_TIME);
306 
307     cmd_info.devno = 0;
308     cmd_info.cmd_size = 0x18CC;
309     cmd_info.data_type = 0x23;
310     cmd_info.cmd = NULL;
311     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
312     if (s32Ret != HI_SUCCESS) {
313         return s32Ret;
314     }
315     usleep(USLEEP_TIME);
316 
317     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
318     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xB0;
319     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x40;
320     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0xC9;
321     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0x8F;
322     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_4] = 0x0D;
323     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_5] = 0x11;
324     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_6] = 0x07;
325     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_7] = 0x02;
326     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_8] = 0x09;
327     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_9] = 0x09;
328     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_10] = 0x1F;
329     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_11] = 0x04;
330     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_12] = 0x50;
331     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_13] = 0x0F;
332     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_14] = 0xE4;
333     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_15] = 0x29;
334     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_16] = 0xDF;
335     cmd_info.devno = 0;
336     cmd_info.cmd_size = 17; // 17: command data size
337     cmd_info.data_type = 0x29;
338     cmd_info.cmd = g_mBuf;
339     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
340     if (s32Ret != HI_SUCCESS) {
341         return s32Ret;
342     }
343     usleep(USLEEP_TIME);
344 
345     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
346     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xB1;
347     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x40;
348     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0xCB;
349     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0xD3;
350     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_4] = 0x11;
351     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_5] = 0x8F;
352     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_6] = 0x04;
353     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_7] = 0x00;
354     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_8] = 0x08;
355     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_9] = 0x07;
356     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_10] = 0x1C;
357     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_11] = 0x06;
358     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_12] = 0x53;
359     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_13] = 0x12;
360     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_14] = 0x63;
361     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_15] = 0xEB;
362     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_16] = 0xDF;
363     cmd_info.devno = 0;
364     cmd_info.cmd_size = 17; // 17: command data size
365     cmd_info.data_type = 0x29;
366     cmd_info.cmd = g_mBuf;
367     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
368     if (s32Ret != HI_SUCCESS) {
369         return s32Ret;
370     }
371     usleep(USLEEP_TIME);
372 
373     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
374     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xFF;
375     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x77;
376     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x01;
377     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0x00;
378     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_4] = 0x00;
379     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_5] = 0x11;
380     cmd_info.devno = 0;
381     cmd_info.cmd_size = 6; // 6: command data size
382     cmd_info.data_type = 0x29;
383     cmd_info.cmd = g_mBuf;
384     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
385     if (s32Ret != HI_SUCCESS) {
386         return s32Ret;
387     }
388     usleep(USLEEP_TIME);
389 
390     cmd_info.devno = 0;
391     cmd_info.cmd_size = 0x65b0;
392     cmd_info.data_type = 0x23;
393     cmd_info.cmd = NULL;
394     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
395     if (s32Ret != HI_SUCCESS) {
396         return s32Ret;
397     }
398     usleep(USLEEP_TIME);
399 
400     cmd_info.devno = 0;
401     cmd_info.cmd_size = 0x34b1;
402     cmd_info.data_type = 0x23;
403     cmd_info.cmd = NULL;
404     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
405     if (s32Ret != HI_SUCCESS) {
406         return s32Ret;
407     }
408     usleep(USLEEP_TIME);
409 
410     cmd_info.devno = 0;
411     cmd_info.cmd_size = 0x87b2;
412     cmd_info.data_type = 0x23;
413     cmd_info.cmd = NULL;
414     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
415     if (s32Ret != HI_SUCCESS) {
416         return s32Ret;
417     }
418     usleep(USLEEP_TIME);
419 
420     cmd_info.devno = 0;
421     cmd_info.cmd_size = 0x80b3;
422     cmd_info.data_type = 0x23;
423     cmd_info.cmd = NULL;
424     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
425     if (s32Ret != HI_SUCCESS) {
426         return s32Ret;
427     }
428     usleep(USLEEP_TIME);
429 
430     cmd_info.devno = 0;
431     cmd_info.cmd_size = 0x49b5;
432     cmd_info.data_type = 0x23;
433     cmd_info.cmd = NULL;
434     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
435     if (s32Ret != HI_SUCCESS) {
436         return s32Ret;
437     }
438     usleep(USLEEP_TIME);
439 
440     cmd_info.devno = 0;
441     cmd_info.cmd_size = 0x85b7;
442     cmd_info.data_type = 0x23;
443     cmd_info.cmd = NULL;
444     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
445     if (s32Ret != HI_SUCCESS) {
446         return s32Ret;
447     }
448     usleep(USLEEP_TIME);
449 
450     cmd_info.devno = 0;
451     cmd_info.cmd_size = 0x20b8;
452     cmd_info.data_type = 0x23;
453     cmd_info.cmd = NULL;
454     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
455     if (s32Ret != HI_SUCCESS) {
456         return s32Ret;
457     }
458     usleep(USLEEP_TIME);
459 
460     cmd_info.devno = 0;
461     cmd_info.cmd_size = 0x10b9;
462     cmd_info.data_type = 0x23;
463     cmd_info.cmd = NULL;
464     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
465     if (s32Ret != HI_SUCCESS) {
466         return s32Ret;
467     }
468     usleep(USLEEP_TIME);
469 
470     cmd_info.devno = 0;
471     cmd_info.cmd_size = 0x78c1;
472     cmd_info.data_type = 0x23;
473     cmd_info.cmd = NULL;
474     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
475     if (s32Ret != HI_SUCCESS) {
476         return s32Ret;
477     }
478     usleep(USLEEP_TIME);
479 
480     cmd_info.devno = 0;
481     cmd_info.cmd_size = 0x78c2;
482     cmd_info.data_type = 0x23;
483     cmd_info.cmd = NULL;
484     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
485     if (s32Ret != HI_SUCCESS) {
486         return s32Ret;
487     }
488     usleep(USLEEP_TIME);
489 
490     cmd_info.devno = 0;
491     cmd_info.cmd_size = 0x88d0;
492     cmd_info.data_type = 0x23;
493     cmd_info.cmd = NULL;
494     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
495     if (s32Ret != HI_SUCCESS) {
496         return s32Ret;
497     }
498     usleep(USLEEP_TIME);
499     usleep(100000);  // 100000: The process hangs for a period of time, in microseconds
500 
501     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
502     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xE0;
503     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x00;
504     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x19;
505     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0x02;
506     cmd_info.devno = 0;
507     cmd_info.cmd_size = 4; // 4: command data size
508     cmd_info.data_type = 0x29;
509     cmd_info.cmd = g_mBuf;
510     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
511     if (s32Ret != HI_SUCCESS) {
512         return s32Ret;
513     }
514     usleep(USLEEP_TIME);
515     usleep(USLEEP_TIME);
516 
517     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
518     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xE1;
519     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x05;
520     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0xA0;
521     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0x07;
522     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_4] = 0xA0;
523     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_5] = 0x04;
524     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_6] = 0xA0;
525     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_7] = 0x06;
526     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_8] = 0xA0;
527     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_9] = 0x00;
528     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_10] = 0x44;
529     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_11] = 0x44;
530     cmd_info.devno = 0;
531     cmd_info.cmd_size = 12; // 12: command data size
532     cmd_info.data_type = 0x29;
533     cmd_info.cmd = g_mBuf;
534     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
535     if (s32Ret != HI_SUCCESS) {
536         return s32Ret;
537     }
538     usleep(USLEEP_TIME);
539 
540     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
541     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xE2;
542     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x00;
543     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x00;
544     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0x00;
545     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_4] = 0x00;
546     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_5] = 0x00;
547     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_6] = 0x00;
548     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_7] = 0x00;
549     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_8] = 0x00;
550     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_9] = 0x00;
551     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_10] = 0x00;
552     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_11] = 0x00;
553     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_12] = 0x00;
554     cmd_info.devno = 0;
555     cmd_info.cmd_size = 13; // 13: command data size
556     cmd_info.data_type = 0x29;
557     cmd_info.cmd = g_mBuf;
558     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
559     if (s32Ret != HI_SUCCESS) {
560         return s32Ret;
561     }
562     usleep(USLEEP_TIME);
563 
564     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
565     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xE3;
566     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x00;
567     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x00;
568     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0x33;
569     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_4] = 0x33;
570     cmd_info.devno = 0;
571     cmd_info.cmd_size = 5; // 5: command data size
572     cmd_info.data_type = 0x29;
573     cmd_info.cmd = g_mBuf;
574     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
575     if (s32Ret != HI_SUCCESS) {
576         return s32Ret;
577     }
578     usleep(USLEEP_TIME);
579 
580     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
581     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xE4;
582     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x44;
583     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x44;
584     cmd_info.devno = 0;
585     cmd_info.cmd_size = 3; // 3: command data size
586     cmd_info.data_type = 0x29;
587     cmd_info.cmd = g_mBuf;
588     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
589     if (s32Ret != HI_SUCCESS) {
590         return s32Ret;
591     }
592     usleep(USLEEP_TIME);
593 
594     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
595     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xE5;
596     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x0D;
597     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x31;
598     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0xC8;
599     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_4] = 0xAF;
600     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_5] = 0x0F;
601     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_6] = 0x33;
602     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_7] = 0xC8;
603     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_8] = 0xAF;
604     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_9] = 0x09;
605     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_10] = 0x2D;
606     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_11] = 0xC8;
607     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_12] = 0xAF;
608     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_13] = 0x0B;
609     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_14] = 0x2F;
610     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_15] = 0xC8;
611     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_16] = 0xAF;
612     cmd_info.devno = 0;
613     cmd_info.cmd_size = 17; // 17: command data size
614     cmd_info.data_type = 0x29;
615     cmd_info.cmd = g_mBuf;
616     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
617     if (s32Ret != HI_SUCCESS) {
618         return s32Ret;
619     }
620     usleep(USLEEP_TIME);
621 
622     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
623     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xE6;
624     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x00;
625     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x00;
626     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0x33;
627     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_4] = 0x33;
628     cmd_info.devno = 0;
629     cmd_info.cmd_size = 5; // 5: command data size
630     cmd_info.data_type = 0x29;
631     cmd_info.cmd = g_mBuf;
632     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
633     if (s32Ret != HI_SUCCESS) {
634         return s32Ret;
635     }
636     usleep(USLEEP_TIME);
637 
638     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
639     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xE7;
640     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x44;
641     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x44;
642     cmd_info.devno = 0;
643     cmd_info.cmd_size = 3; // 3: command data size
644     cmd_info.data_type = 0x29;
645     cmd_info.cmd = g_mBuf;
646     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
647     if (s32Ret != HI_SUCCESS) {
648         return s32Ret;
649     }
650     usleep(USLEEP_TIME);
651 
652     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
653     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xE8;
654     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x0C;
655     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x30;
656     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0xC8;
657     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_4] = 0xAF;
658     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_5] = 0x0E;
659     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_6] = 0x32;
660     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_7] = 0xC8;
661     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_8] = 0xAF;
662     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_9] = 0x08;
663     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_10] = 0x2C;
664     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_11] = 0xC8;
665     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_12] = 0xAF;
666     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_13] = 0x0A;
667     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_14] = 0x2E;
668     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_15] = 0xC8;
669     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_16] = 0xAF;
670     cmd_info.devno = 0;
671     cmd_info.cmd_size = 17; // 17: command data size
672     cmd_info.data_type = 0x29;
673     cmd_info.cmd = g_mBuf;
674     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
675     if (s32Ret != HI_SUCCESS) {
676         return s32Ret;
677     }
678     usleep(USLEEP_TIME);
679 
680     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
681     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xEB;
682     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x02;
683     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x00;
684     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0xE4;
685     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_4] = 0xE4;
686     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_5] = 0x44;
687     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_6] = 0x00;
688     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_7] = 0x40;
689     cmd_info.devno = 0;
690     cmd_info.cmd_size = 8; // 8: command data size
691     cmd_info.data_type = 0x29;
692     cmd_info.cmd = g_mBuf;
693     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
694     if (s32Ret != HI_SUCCESS) {
695         return s32Ret;
696     }
697     usleep(USLEEP_TIME);
698 
699     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
700     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xEC;
701     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x3C;
702     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x00;
703     cmd_info.devno = 0;
704     cmd_info.cmd_size = 3; // 3: command data size
705     cmd_info.data_type = 0x29;
706     cmd_info.cmd = g_mBuf;
707     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
708     if (s32Ret != HI_SUCCESS) {
709         return s32Ret;
710     }
711     usleep(USLEEP_TIME);
712 
713     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
714     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xED;
715     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0xAB;
716     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x89;
717     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0x76;
718     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_4] = 0x54;
719     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_5] = 0x01;
720     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_6] = 0xFF;
721     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_7] = 0xFF;
722     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_8] = 0xFF;
723     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_9] = 0xFF;
724     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_10] = 0xFF;
725     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_11] = 0xFF;
726     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_12] = 0x10;
727     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_13] = 0x45;
728     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_14] = 0x67;
729     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_15] = 0x98;
730     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_16] = 0xBA;
731     cmd_info.devno = 0;
732     cmd_info.cmd_size = 17; // 17: command data size
733     cmd_info.data_type = 0x29;
734     cmd_info.cmd = g_mBuf;
735     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
736     if (s32Ret != HI_SUCCESS) {
737         return s32Ret;
738     }
739     usleep(USLEEP_TIME);
740 
741     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
742     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xEF;
743     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x08;
744     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x08;
745     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0x08;
746     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_4] = 0x45;
747     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_5] = 0x3F;
748     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_6] = 0x54;
749     cmd_info.devno = 0;
750     cmd_info.cmd_size = 7; // 7: command data size
751     cmd_info.data_type = 0x29;
752     cmd_info.cmd = g_mBuf;
753     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
754     if (s32Ret != HI_SUCCESS) {
755         return s32Ret;
756     }
757     usleep(USLEEP_TIME);
758 
759     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
760     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xFF;
761     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x77;
762     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x01;
763     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0x00;
764     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_4] = 0x00;
765     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_5] = 0x00;
766     cmd_info.devno = 0;
767     cmd_info.cmd_size = 6; // 6: command data size
768     cmd_info.data_type = 0x29;
769     cmd_info.cmd = g_mBuf;
770     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
771     if (s32Ret != HI_SUCCESS) {
772         return s32Ret;
773     }
774     usleep(USLEEP_TIME);
775 
776     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
777     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xFF;
778     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x77;
779     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x01;
780     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0x00;
781     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_4] = 0x00;
782     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_5] = 0x13;
783     cmd_info.devno = 0;
784     cmd_info.cmd_size = 6; // 6: command data size
785     cmd_info.data_type = 0x29;
786     cmd_info.cmd = g_mBuf;
787     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
788     if (s32Ret != HI_SUCCESS) {
789         return s32Ret;
790     }
791     usleep(USLEEP_TIME);
792 
793     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
794     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xE8;
795     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x00;
796     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x0E;
797     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0x11;
798     cmd_info.devno = 0;
799     cmd_info.cmd_size = 4; // 4: command data size
800     cmd_info.data_type = 0x29;
801     cmd_info.cmd = g_mBuf;
802     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
803     if (s32Ret != HI_SUCCESS) {
804         return s32Ret;
805     }
806     usleep(USLEEP_TIME);
807     usleep(120000); // 120000: The process hangs for a period of time, in microseconds
808 
809     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
810     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xE8;
811     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x00;
812     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x0C;
813     cmd_info.devno = 0;
814     cmd_info.cmd_size = 3; // 3: command data size
815     cmd_info.data_type = 0x29;
816     cmd_info.cmd = g_mBuf;
817     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
818     if (s32Ret != HI_SUCCESS) {
819         return s32Ret;
820     }
821     usleep(USLEEP_TIME);
822     usleep(10000); // 10000: The process hangs for a period of time, in microseconds
823 
824     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
825     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xE8;
826     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x00;
827     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x00;
828     cmd_info.devno = 0;
829     cmd_info.cmd_size = 3; // 3: command data size
830     cmd_info.data_type = 0x29;
831     cmd_info.cmd = g_mBuf;
832     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
833     if (s32Ret != HI_SUCCESS) {
834         return s32Ret;
835     }
836     usleep(USLEEP_TIME);
837     usleep(10000); // 10000: The process hangs for a period of time, in microseconds
838 
839     memset_s(g_mBuf, sizeof(g_mBuf), 0, G_MBUF_LENGTH);
840     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_0] = 0xFF;
841     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_1] = 0x77;
842     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_2] = 0x01;
843     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_3] = 0x00;
844     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_4] = 0x00;
845     g_mBuf[G_MBUF_ARRAY_SUBSCRIPT_5] = 0x00;
846     cmd_info.devno = 0;
847     cmd_info.cmd_size = 6; // 6: command data size
848     cmd_info.data_type = 0x29;
849     cmd_info.cmd = g_mBuf;
850     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
851     if (s32Ret != HI_SUCCESS) {
852         return s32Ret;
853     }
854     usleep(USLEEP_TIME);
855     usleep(10000); // 10000: The process hangs for a period of time, in microseconds
856 
857     cmd_info.devno = 0;
858     cmd_info.cmd_size = 0x11;
859     cmd_info.data_type = 0x05;
860     cmd_info.cmd = NULL;
861     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
862     if (s32Ret != HI_SUCCESS) {
863         return s32Ret;
864     }
865     usleep(USLEEP_TIME);
866     usleep(150000); // 150000: The process hangs for a period of time, in microseconds
867 
868     cmd_info.devno = 0;
869     cmd_info.cmd_size = 0x29;
870     cmd_info.data_type = 0x05;
871     cmd_info.cmd = NULL;
872     s32Ret = SAMPLE_USER_INIT_MIPITx(fd, &cmd_info);
873     if (s32Ret != HI_SUCCESS) {
874         return s32Ret;
875     }
876     usleep(USLEEP_TIME);
877     usleep(50000); // 50000: The process hangs for a period of time, in microseconds
878 
879     return HI_SUCCESS;
880 }
881 
882 /*
883  * 启用MIPI Tx设备
884  * Enable MIPI Tx device
885  */
SAMPLE_VO_ENABLE_MIPITx(HI_S32 fd)886 HI_S32 SAMPLE_VO_ENABLE_MIPITx(HI_S32 fd)
887 {
888     HI_S32 s32Ret = ioctl(fd, HI_MIPI_TX_ENABLE);
889     if (s32Ret != HI_SUCCESS) {
890         printf("MIPI_TX enable failed\n");
891         return s32Ret;
892     }
893 
894     return s32Ret;
895 }
896 
897 /*
898  * 禁用MIPI Tx设备
899  * Disable MIPI Tx device
900  */
SAMPLE_VO_DISABLE_MIPITx(HI_S32 fd)901 HI_S32 SAMPLE_VO_DISABLE_MIPITx(HI_S32 fd)
902 {
903     HI_S32 s32Ret = ioctl(fd, HI_MIPI_TX_DISABLE);
904     if (s32Ret != HI_SUCCESS) {
905         printf("MIPI_TX disable failed\n");
906         return s32Ret;
907     }
908 
909     return s32Ret;
910 }
911 
912 /*
913  * 设置VO至MIPI通路,获取MIPI设备
914  * Set VO config to MIPI, get MIPI device
915  */
SAMPLE_VO_CONFIG_MIPI(HI_S32 * mipiFD)916 HI_S32 SAMPLE_VO_CONFIG_MIPI(HI_S32* mipiFD)
917 {
918     HI_S32 s32Ret;
919     HI_S32  fd;
920 
921     /*
922      * 打开MIPI FD
923      * Open MIPI FD
924      */
925     fd = SampleOpenMipiTxFd();
926     if (fd < 0) {
927         return HI_FAILURE;
928     }
929 	*mipiFD = fd;
930 
931     /*
932      * 设置MIPI Tx设备属性
933      * Set MIPI Tx device attribution
934      */
935     s32Ret = SampleSetMipiTxDevAttr(fd);
936     if (s32Ret != HI_SUCCESS) {
937         return s32Ret;
938     }
939 
940     usleep(10000); // 10000: The process hangs for a period of time, in microseconds
941     system("cd /sys/class/gpio/;echo 5 > export;echo out > gpio5/direction;echo 1 > gpio5/value");
942     usleep(200000); // 200000: The process hangs for a period of time, in microseconds
943     system("echo 0 > /sys/class/gpio/gpio5/value");
944     usleep(200000); // 200000: The process hangs for a period of time, in microseconds
945     system("echo 1 > /sys/class/gpio/gpio5/value");
946     usleep(20000); // 20000: The process hangs for a period of time, in microseconds
947 
948     /*
949      * 配置MIPI Tx初始化序列
950      * Config MIPI Tx initialization sequence
951      */
952     s32Ret = SampleVoInitMipiTxScreen(fd);
953     if (s32Ret != HI_SUCCESS) {
954         return s32Ret;
955     }
956 
957     /*
958      * 启用MIPI Tx设备
959      * Enable MIPI Tx device
960      */
961     s32Ret = SAMPLE_VO_ENABLE_MIPITx(fd);
962     if (s32Ret != HI_SUCCESS) {
963         return s32Ret;
964     }
965 
966     return s32Ret;
967 }
968 
969 /*
970  * 获得mipi设备的宽和高
971  * Get mipi device Height and width
972  */
SampleCommVoGetWhMipi(VO_INTF_SYNC_E enIntfSync,HI_U32 * pu32W,HI_U32 * pu32H,HI_U32 * pu32Frm)973 HI_S32 SampleCommVoGetWhMipi(VO_INTF_SYNC_E enIntfSync, HI_U32* pu32W, HI_U32* pu32H, HI_U32* pu32Frm)
974 {
975     switch (enIntfSync) {
976         case VO_OUTPUT_1080P24:
977             *pu32W = 1920; // 1920: VO_OUTPUT_1080P24-Width
978             *pu32H = 1080; // 1080: VO_OUTPUT_1080P24-Height
979             *pu32Frm = 24; // 24: VO_OUTPUT_1080P24-Frame rate
980             break;
981         case VO_OUTPUT_1080P25:
982             *pu32W = 1920; // 1920: VO_OUTPUT_1080P25-Width
983             *pu32H = 1080; // 1080: VO_OUTPUT_1080P25-Height
984             *pu32Frm = 25; // 25: VO_OUTPUT_1080P25-Frame rate
985             break;
986         case VO_OUTPUT_1080P30:
987             *pu32W = 1920; // 1920: VO_OUTPUT_1080P30-Width
988             *pu32H = 1080; // 1080: VO_OUTPUT_1080P30-Height
989             *pu32Frm = 30; // 30: VO_OUTPUT_1080P30-Frame rate
990             break;
991         case VO_OUTPUT_720P50:
992             *pu32W = 1280; // 1280: VO_OUTPUT_720P50-Width
993             *pu32H = 720; // 720: VO_OUTPUT_720P50-Height
994             *pu32Frm = 50; // 50: VO_OUTPUT_720P50-Frame rate
995             break;
996         case VO_OUTPUT_720P60:
997             *pu32W = 1280; // 1280: VO_OUTPUT_720P60-Width
998             *pu32H = 720; // 720: VO_OUTPUT_720P60-Height
999             *pu32Frm = 60; // 60: VO_OUTPUT_720P60-Frame rate
1000             break;
1001         case VO_OUTPUT_1080P50:
1002             *pu32W = 1920; // 1920: VO_OUTPUT_1080P50-Width
1003             *pu32H = 1080; // 1080: VO_OUTPUT_1080P50-Height
1004             *pu32Frm = 50; // 50: VO_OUTPUT_1080P50-Frame rate
1005             break;
1006         case VO_OUTPUT_1080P60:
1007             *pu32W = 1920; // 1920: VO_OUTPUT_1080P60-Width
1008             *pu32H = 1080; // 1080: VO_OUTPUT_1080P60-Height
1009             *pu32Frm = 60; // 60: VO_OUTPUT_1080P60-Frame rate
1010             break;
1011         case VO_OUTPUT_USER:
1012             *pu32W = 800; // 800: VO_OUTPUT_USER-Width
1013             *pu32H = 480; // 480: VO_OUTPUT_USER-Height
1014             *pu32Frm = 60; // 60: VO_OUTPUT_USER-Frame rate
1015             break;
1016         default:
1017             SAMPLE_PRT("vo enIntfSync %d not support, please config self!\n", enIntfSync);
1018             return HI_FAILURE;
1019     }
1020 
1021     return HI_SUCCESS;
1022 }
1023 
SampleCommVoStartDevMipi(VO_DEV VoDev,VO_PUB_ATTR_S * pstPubAttr)1024 HI_S32 SampleCommVoStartDevMipi(VO_DEV VoDev, VO_PUB_ATTR_S* pstPubAttr)
1025 {
1026     HI_S32 s32Ret;
1027     VO_USER_INTFSYNC_INFO_S stUserInfo = {0};
1028 
1029     stUserInfo.bClkReverse = HI_TRUE;
1030     stUserInfo.u32DevDiv = 1;
1031     stUserInfo.u32PreDiv = 1;
1032     stUserInfo.stUserIntfSyncAttr.enClkSource = VO_CLK_SOURCE_PLL;
1033     stUserInfo.stUserIntfSyncAttr.stUserSyncPll.u32Fbdiv = 244; // 244: PLL integer frequency multiplier coefficient
1034     stUserInfo.stUserIntfSyncAttr.stUserSyncPll.u32Frac = 0x1A36;
1035     stUserInfo.stUserIntfSyncAttr.stUserSyncPll.u32Refdiv = 4; // 4: PLL reference clock frequency division coefficient
1036     // 7: PLL first stage output frequency division coefficient
1037     stUserInfo.stUserIntfSyncAttr.stUserSyncPll.u32Postdiv1 = 7;
1038     // 7: PLL second stage output frequency division coefficient
1039     stUserInfo.stUserIntfSyncAttr.stUserSyncPll.u32Postdiv2 = 7;
1040     HI_U32 u32Framerate = 60; // 60: device frame rate
1041 
1042     /*
1043      * 配置视频输出设备的公共属性
1044      * Set the common properties of the video output device
1045      */
1046     s32Ret = HI_MPI_VO_SetPubAttr(VoDev, pstPubAttr);
1047     if (s32Ret != HI_SUCCESS) {
1048         SAMPLE_PRT("failed with %#x!\n", s32Ret);
1049         return HI_FAILURE;
1050     }
1051 
1052     /*
1053      * 设置设备用户时序下设备帧率
1054      * Set the device frame rate under the device user timing
1055      */
1056     s32Ret = HI_MPI_VO_SetDevFrameRate(VoDev, u32Framerate);
1057     if (s32Ret != HI_SUCCESS) {
1058         SAMPLE_PRT("failed with %#x!\n", s32Ret);
1059         return HI_FAILURE;
1060     }
1061 
1062     /*
1063      * 设置用户接口时序信息,用于配置时钟源、时钟大小和时钟分频比
1064      *
1065      * Set user interface timing information, used to configure clock source,
1066      * clock size and clock frequency division ratio
1067      */
1068     s32Ret = HI_MPI_VO_SetUserIntfSyncInfo(VoDev, &stUserInfo);
1069     if (s32Ret != HI_SUCCESS) {
1070         SAMPLE_PRT("failed with %#x!\n", s32Ret);
1071         return HI_FAILURE;
1072     }
1073 
1074     /*
1075      * 启用视频输出设备
1076      * Enable video output device
1077      */
1078     s32Ret = HI_MPI_VO_Enable(VoDev);
1079     if (s32Ret != HI_SUCCESS) {
1080         SAMPLE_PRT("failed with %#x!\n", s32Ret);
1081         return HI_FAILURE;
1082     }
1083 
1084     return s32Ret;
1085 }
1086 
SampleCommVoStartChnModeMux(SAMPLE_VO_MODE_E enMode)1087 HI_S32 SampleCommVoStartChnModeMux(SAMPLE_VO_MODE_E enMode)
1088 {
1089     int s32Ret;
1090     switch (enMode) {
1091         case VO_MODE_1MUX:
1092             g_sampleVoModeMux.u32WndNum = 1;
1093             g_sampleVoModeMux.u32Square = 1;
1094             break;
1095         case VO_MODE_2MUX:
1096             g_sampleVoModeMux.u32WndNum = 2; // 2: 2MUX-WndNum
1097             g_sampleVoModeMux.u32Square = 2; // 2: 2MUX-Square
1098             break;
1099         case VO_MODE_4MUX:
1100             g_sampleVoModeMux.u32WndNum = 4; // 4: 4MUX-WndNum
1101             g_sampleVoModeMux.u32Square = 2; // 2: 4MUX-Square
1102             break;
1103         case VO_MODE_8MUX:
1104             g_sampleVoModeMux.u32WndNum = 8; // 8: 8MUX-WndNum
1105             g_sampleVoModeMux.u32Square = 3; // 3: 8MUX-Square
1106             break;
1107         case VO_MODE_9MUX:
1108             g_sampleVoModeMux.u32WndNum = 9; // 9: 9MUX-WndNum
1109             g_sampleVoModeMux.u32Square = 3; // 3: 9MUX-Square
1110             break;
1111         case VO_MODE_16MUX:
1112             g_sampleVoModeMux.u32WndNum = 16; // 16: 16MUX-WndNum
1113             g_sampleVoModeMux.u32Square = 4; // 4: 16MUX-Square
1114             break;
1115         case VO_MODE_25MUX:
1116             g_sampleVoModeMux.u32WndNum = 25; // 25: 25MUX-WndNum
1117             g_sampleVoModeMux.u32Square = 5; // 5: 25MUX-Square
1118             break;
1119         case VO_MODE_36MUX:
1120             g_sampleVoModeMux.u32WndNum = 36; // 36: 36MUX-WndNum
1121             g_sampleVoModeMux.u32Square = 6; // 6: 36MUX-Square
1122             break;
1123         case VO_MODE_49MUX:
1124             g_sampleVoModeMux.u32WndNum = 49; // 49: 49MUX-WndNum
1125             g_sampleVoModeMux.u32Square = 7; // 7: 49MUX-Square
1126             break;
1127         case VO_MODE_2X4:
1128             g_sampleVoModeMux.u32WndNum = 8; // 8: 2X4-WndNum
1129             g_sampleVoModeMux.u32Square = 3; // 3: 2X4-Square
1130             g_sampleVoModeMux.u32Row    = 4; // 4: 2X4-Row
1131             g_sampleVoModeMux.u32Col    = 2; // 2: 2X4-Col
1132             break;
1133         default:
1134             SAMPLE_PRT("failed with %#x!\n", s32Ret);
1135             return HI_FAILURE;
1136     }
1137 
1138     return HI_SUCCESS;
1139 }
1140 
SampleCommVoStartChnMipi(VO_LAYER VoLayer,SAMPLE_VO_MODE_E enMode)1141 HI_S32 SampleCommVoStartChnMipi(VO_LAYER VoLayer, SAMPLE_VO_MODE_E enMode)
1142 {
1143     HI_S32 i;
1144     HI_S32 s32Ret    = HI_SUCCESS;
1145     HI_U32 u32Width  = 0;
1146     HI_U32 u32Height = 0;
1147     VO_CHN_ATTR_S         stChnAttr;
1148     VO_VIDEO_LAYER_ATTR_S stLayerAttr;
1149 
1150     s32Ret = SampleCommVoStartChnModeMux(enMode);
1151     SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, "for SampleCommVoStartChnModeMux FAIL, s32Ret=%x\n", s32Ret);
1152 
1153     /*
1154      * 获取视频层属性
1155      * Get video layer properties
1156      */
1157     s32Ret = HI_MPI_VO_GetVideoLayerAttr(VoLayer, &stLayerAttr);
1158     SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, "for HI_MPI_VO_GetVideoLayerAttr FAIL, s32Ret=%x\n", s32Ret);
1159     u32Width  = stLayerAttr.stImageSize.u32Width;
1160     u32Height = stLayerAttr.stImageSize.u32Height;
1161     SAMPLE_PRT("enMode:%d, u32Width:%d, u32Height:%d, u32Square:%d\n", enMode,
1162         u32Width, u32Height, g_sampleVoModeMux.u32Square);
1163 
1164     for (i = 0; i < g_sampleVoModeMux.u32WndNum; i++) {
1165         if (enMode == VO_MODE_1MUX  || enMode == VO_MODE_2MUX  || enMode == VO_MODE_4MUX  ||
1166             enMode == VO_MODE_8MUX  || enMode == VO_MODE_9MUX  || enMode == VO_MODE_16MUX ||
1167             enMode == VO_MODE_25MUX || enMode == VO_MODE_36MUX || enMode == VO_MODE_49MUX) {
1168             stChnAttr.stRect.s32X       = HI_ALIGN_DOWN((u32Width / g_sampleVoModeMux.u32Square) *
1169                 (i % g_sampleVoModeMux.u32Square), ALIGN_DOWN_SIZE);
1170             stChnAttr.stRect.s32Y       = HI_ALIGN_DOWN((u32Height / g_sampleVoModeMux.u32Square) *
1171                 (i / g_sampleVoModeMux.u32Square), ALIGN_DOWN_SIZE);
1172             stChnAttr.stRect.u32Width   = HI_ALIGN_DOWN(u32Width / g_sampleVoModeMux.u32Square, ALIGN_DOWN_SIZE);
1173             stChnAttr.stRect.u32Height  = HI_ALIGN_DOWN(u32Height / g_sampleVoModeMux.u32Square, ALIGN_DOWN_SIZE);
1174             stChnAttr.u32Priority       = 0;
1175             stChnAttr.bDeflicker        = HI_FALSE;
1176         } else if (enMode == VO_MODE_2X4) {
1177             stChnAttr.stRect.s32X       = HI_ALIGN_DOWN((u32Width / g_sampleVoModeMux.u32Col) *
1178                 (i % g_sampleVoModeMux.u32Col), ALIGN_DOWN_SIZE);
1179             stChnAttr.stRect.s32Y       = HI_ALIGN_DOWN((u32Height / g_sampleVoModeMux.u32Row) *
1180                 (i / g_sampleVoModeMux.u32Col), ALIGN_DOWN_SIZE);
1181             stChnAttr.stRect.u32Width   = HI_ALIGN_DOWN(u32Width / g_sampleVoModeMux.u32Col, ALIGN_DOWN_SIZE);
1182             stChnAttr.stRect.u32Height  = HI_ALIGN_DOWN(u32Height / g_sampleVoModeMux.u32Row, ALIGN_DOWN_SIZE);
1183             stChnAttr.u32Priority       = 0;
1184             stChnAttr.bDeflicker        = HI_FALSE;
1185         }
1186 
1187         /*
1188          * 配置指定视频输出通道的属性
1189          * Set properties for the specified video output channel
1190          */
1191         s32Ret = HI_MPI_VO_SetChnAttr(VoLayer, i, &stChnAttr);
1192         SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, "for HI_MPI_VO_SetChnAttr FAIL, s32Ret=%x\n", s32Ret);
1193 
1194         /*
1195          * 设置指定视频输出通道的旋转角度
1196          * Set video output channel rotation angle
1197          */
1198         s32Ret = HI_MPI_VO_SetChnRotation(VoLayer, i, ROTATION_90);
1199         SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, "for HI_MPI_VO_SetChnRotation FAIL, s32Ret=%x\n", s32Ret);
1200 
1201         /*
1202          * 启用指定的视频输出通道
1203          * Enables the specified video output channel
1204          */
1205         s32Ret = HI_MPI_VO_EnableChn(VoLayer, i);
1206         SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, "for HI_MPI_VO_EnableChn FAIL, s32Ret=%x\n", s32Ret);
1207     }
1208 
1209     return HI_SUCCESS;
1210 }
1211 
StVoPubAttrCfg(SAMPLE_VO_CONFIG_S * pstVoConfig)1212 static HI_VOID StVoPubAttrCfg(SAMPLE_VO_CONFIG_S *pstVoConfig)
1213 {
1214     HI_ASSERT(pstVoConfig);
1215     /*
1216      * 定义视频输出公共属性结构体
1217      * Define the video output public attribute structure
1218      */
1219     stVoPubAttr.enIntfType  = VO_INTF_MIPI;
1220     stVoPubAttr.enIntfSync  = VO_OUTPUT_USER;
1221     stVoPubAttr.stSyncInfo.bSynm = 0;
1222     stVoPubAttr.stSyncInfo.bIop = 1;
1223     stVoPubAttr.stSyncInfo.u8Intfb = 0;
1224 
1225     stVoPubAttr.stSyncInfo.u16Hmid = 1;
1226     stVoPubAttr.stSyncInfo.u16Bvact = 1;
1227     stVoPubAttr.stSyncInfo.u16Bvbb = 1;
1228     stVoPubAttr.stSyncInfo.u16Bvfb = 1;
1229 
1230     stVoPubAttr.stSyncInfo.bIdv = 0;
1231     stVoPubAttr.stSyncInfo.bIhs = 0;
1232     stVoPubAttr.stSyncInfo.bIvs = 0;
1233 
1234     stVoPubAttr.stSyncInfo.u16Hact = 480; // 480: Horizontal effective area. Unit: pixel
1235     stVoPubAttr.stSyncInfo.u16Hbb = 60; // 60: Horizontal blanking of the rear shoulder. Unit: pixel
1236     stVoPubAttr.stSyncInfo.u16Hfb = 50; // 50: Horizontal blanking of the front shoulder. Unit: pixel
1237     stVoPubAttr.stSyncInfo.u16Hpw = 10; // 10: The width of the horizontal sync signal. Unit: pixel
1238     stVoPubAttr.stSyncInfo.u16Vact = 800; // 800: Vertical effective area. Unit: line
1239     stVoPubAttr.stSyncInfo.u16Vbb = 24; // 24: Vertical blanking of the rear shoulder.  Unit: line
1240     stVoPubAttr.stSyncInfo.u16Vfb = 20; // 20: Vertical blanking of the front shoulder.  Unit: line
1241     stVoPubAttr.stSyncInfo.u16Vpw = 4; // 4: The width of the vertical sync signal. Unit: line
1242     stVoPubAttr.u32BgColor  = pstVoConfig->u32BgColor;
1243 }
1244 
StLayerAttrCfg(SAMPLE_VO_CONFIG_S * pstVoConfig)1245 static HI_VOID StLayerAttrCfg(SAMPLE_VO_CONFIG_S *pstVoConfig)
1246 {
1247     HI_ASSERT(pstVoConfig);
1248     stLayerAttr.bClusterMode     = HI_FALSE;
1249     stLayerAttr.bDoubleFrame    = HI_FALSE;
1250     stLayerAttr.enPixFormat       = pstVoConfig->enPixFormat;
1251 
1252     stLayerAttr.stDispRect.s32X = 0;
1253     stLayerAttr.stDispRect.s32Y = 0;
1254     stLayerAttr.enDstDynamicRange     = pstVoConfig->enDstDynamicRange;
1255 }
1256 
1257 /*
1258  * 启动VO到MIPI lcd通路
1259  * Start VO to MIPI lcd
1260  */
SampleCommVoStartMipi(SAMPLE_VO_CONFIG_S * pstVoConfig)1261 HI_S32 SampleCommVoStartMipi(SAMPLE_VO_CONFIG_S *pstVoConfig)
1262 {
1263     HI_S32 s32Ret;
1264 
1265     HI_ASSERT(pstVoConfig);
1266     StVoPubAttrCfg(pstVoConfig);
1267     s32Ret = SampleCommVoStartDevMipi(pstVoConfig->VoDev, &stVoPubAttr);
1268     SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, "StartDevMipi FAIL, ret=%x\n", s32Ret);
1269     /*
1270      * 获得MIPI设备的宽和高
1271      * Get MIPI device Height and width
1272      */
1273     s32Ret = SampleCommVoGetWhMipi(stVoPubAttr.enIntfSync,
1274         &stLayerAttr.stDispRect.u32Width, &stLayerAttr.stDispRect.u32Height, &stLayerAttr.u32DispFrmRt);
1275     SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FAIL, "VoGetWhMipi fail, err(%#x)\n", s32Ret);
1276 
1277     StLayerAttrCfg(pstVoConfig);
1278 
1279     /*
1280      * 如果存在变化,设置显示矩形框
1281      * Set display rectangle if changed
1282      */
1283     if (memcmp(&pstVoConfig->stDispRect, &stDefDispRect, sizeof(RECT_S)) != 0) {
1284         memcpy_s(&stLayerAttr.stDispRect, sizeof(stLayerAttr.stDispRect),
1285             &pstVoConfig->stDispRect, sizeof(RECT_S));
1286     }
1287 
1288     /*
1289      * 如果存在变化,设置图片大小
1290      * Set image size if changed
1291      */
1292     if (memcmp(&pstVoConfig->stImageSize, &stDefImageSize, sizeof(SIZE_S)) != 0) {
1293         memcpy_s(&stLayerAttr.stImageSize, sizeof(stLayerAttr.stImageSize),
1294             &pstVoConfig->stImageSize, sizeof(SIZE_S));
1295     }
1296     stLayerAttr.stImageSize.u32Width  = stLayerAttr.stDispRect.u32Width = 480; // 480: video layer canvas Width
1297     stLayerAttr.stImageSize.u32Height = stLayerAttr.stDispRect.u32Height = 800; // 800: video layer canvas Height
1298 
1299     if (pstVoConfig->u32DisBufLen) {
1300         /*
1301          * 设置显示缓冲的长度
1302          * Set buffer length
1303          */
1304         s32Ret = HI_MPI_VO_SetDisplayBufLen(pstVoConfig->VoDev, pstVoConfig->u32DisBufLen);
1305         SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FAIL, "HI_MPI_VO_SetDisplayBufLen fail, err(%#x)\n", s32Ret);
1306     }
1307     if (VO_PART_MODE_MULTI == pstVoConfig->enVoPartMode) {
1308         /*
1309          * 设置视频层的分割模式
1310          * Set the segmentation mode of the video layer
1311          */
1312         s32Ret = HI_MPI_VO_SetVideoLayerPartitionMode(pstVoConfig->VoDev, pstVoConfig->enVoPartMode);
1313         SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FAIL, "SetVideoLayerMode fail, err(%#x)\n", s32Ret);
1314     }
1315 
1316     s32Ret = SAMPLE_COMM_VO_StartLayer(pstVoConfig->VoDev, &stLayerAttr); // start layer
1317     SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FAIL, "VO_StartLayer fail, err(%#x)\n", s32Ret);
1318 
1319     if (VO_INTF_MIPI == pstVoConfig->enVoIntfType) {
1320         s32Ret = HI_MPI_VO_GetVideoLayerCSC(pstVoConfig->VoDev, &stVideoCSC); // get video layerCSC
1321         SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FAIL, "GetVideoLayerCSC fail, err(%#x)\n", s32Ret);
1322         stVideoCSC.enCscMatrix = VO_CSC_MATRIX_BT709_TO_RGB_PC;
1323         s32Ret = HI_MPI_VO_SetVideoLayerCSC(pstVoConfig->VoDev, &stVideoCSC); // Set video layer CSC
1324         SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FAIL, "SetVideoLayerCSC fail, err(%#x)\n", s32Ret);
1325     }
1326 
1327     s32Ret = SampleCommVoStartChnMipi(pstVoConfig->VoDev, pstVoConfig->enVoMode); // start vo channels
1328     SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, FAIL1, "VoStartChnMipi fail, err(%#x)\n", s32Ret);
1329     return HI_SUCCESS;
1330 
1331 FAIL1:
1332     SAMPLE_COMM_VO_StopLayer(pstVoConfig->VoDev);
1333 FAIL:
1334     SAMPLE_COMM_VO_StopDev(pstVoConfig->VoDev);
1335     return s32Ret;
1336 }
1337 
Pause(HI_VOID)1338 static HI_VOID Pause(HI_VOID)
1339 {
1340     printf("---------------press Enter key to exit!---------------\n");
1341     (void)getchar();
1342 }
1343 
1344 /*
1345  * 初始化VI配置
1346  * Init ViCfg
1347  */
ViCfgInit(ViCfg * self)1348 void ViCfgInit(ViCfg* self)
1349 {
1350     HI_ASSERT(self);
1351     if (memset_s(self, sizeof(*self), 0, sizeof(*self)) != EOK) {
1352         HI_ASSERT(0);
1353     }
1354 
1355     SAMPLE_COMM_VI_GetSensorInfo(self);
1356     self->s32WorkingViNum = 1;
1357     self->as32WorkingViId[0] = 0;
1358 
1359     self->astViInfo[0].stSnsInfo.MipiDev =
1360         SAMPLE_COMM_VI_GetComboDevBySensor(self->astViInfo[0].stSnsInfo.enSnsType, 0);
1361     self->astViInfo[0].stSnsInfo.s32BusId = 0;
1362 }
1363 
1364 /*
1365  * 设置VI设备信息
1366  * Set VI device information
1367  */
ViCfgSetDev(ViCfg * self,int devId,WDR_MODE_E wdrMode)1368 void ViCfgSetDev(ViCfg* self, int devId, WDR_MODE_E wdrMode)
1369 {
1370     HI_ASSERT(self);
1371     HI_ASSERT((int)wdrMode < WDR_MODE_BUTT);
1372 
1373     self->astViInfo[0].stDevInfo.ViDev = devId;
1374     self->astViInfo[0].stDevInfo.enWDRMode = (int)wdrMode < 0 ? WDR_MODE_NONE : wdrMode;
1375 }
1376 
1377 /*
1378  * 设置VI的PIPE信息
1379  * Set the PIPE information of the VI
1380  */
ViCfgSetPipe(ViCfg * self,int pipe0Id,int pipe1Id,int pipe2Id,int pipe3Id)1381 void ViCfgSetPipe(ViCfg* self, int pipe0Id, int pipe1Id, int pipe2Id, int pipe3Id)
1382 {
1383     HI_ASSERT(self);
1384 
1385     self->astViInfo[0].stPipeInfo.aPipe[APIPE0] = pipe0Id;
1386     self->astViInfo[0].stPipeInfo.aPipe[APIPE1] = pipe1Id;
1387     self->astViInfo[0].stPipeInfo.aPipe[APIPE2] = pipe2Id;
1388     self->astViInfo[0].stPipeInfo.aPipe[APIPE3] = pipe3Id;
1389 }
1390 
1391 /*
1392  * 设置VI通道
1393  * Set up the VI channel
1394  */
ViCfgSetChn(ViCfg * self,int chnId,PIXEL_FORMAT_E pixFormat,VIDEO_FORMAT_E videoFormat,DYNAMIC_RANGE_E dynamicRange)1395 void ViCfgSetChn(ViCfg* self, int chnId, PIXEL_FORMAT_E pixFormat,
1396     VIDEO_FORMAT_E videoFormat, DYNAMIC_RANGE_E dynamicRange)
1397 {
1398     HI_ASSERT(self);
1399     HI_ASSERT((int)pixFormat < PIXEL_FORMAT_BUTT);
1400     HI_ASSERT((int)videoFormat < VIDEO_FORMAT_BUTT);
1401     HI_ASSERT((int)dynamicRange < DYNAMIC_RANGE_BUTT);
1402 
1403     self->astViInfo[0].stChnInfo.ViChn = chnId;
1404     self->astViInfo[0].stChnInfo.enPixFormat =
1405         (int)pixFormat < 0 ? PIXEL_FORMAT_YVU_SEMIPLANAR_420 : pixFormat;
1406     self->astViInfo[0].stChnInfo.enVideoFormat =
1407         (int)videoFormat < 0 ? VIDEO_FORMAT_LINEAR : videoFormat;
1408     self->astViInfo[0].stChnInfo.enDynamicRange =
1409         (int)dynamicRange < 0 ? DYNAMIC_RANGE_SDR8 : dynamicRange;
1410 }
1411 
1412 /*
1413  * 初始化VPSS配置
1414  * Init VpssCfg
1415  */
VpssCfgInit(VpssCfg * self)1416 void VpssCfgInit(VpssCfg* self)
1417 {
1418     HI_ASSERT(self);
1419     if (memset_s(self, sizeof(*self), 0, sizeof(*self)) != EOK) {
1420         HI_ASSERT(0);
1421     }
1422     self->grpId = -1;
1423     self->chnNum = 0;
1424 }
1425 
1426 /*
1427  * 设置VPSS组
1428  * Set up VPSS Group
1429  */
VpssCfgSetGrp(VpssCfg * self,int grpId,const VPSS_GRP_ATTR_S * grpAttr,int maxWidth,int maxHeight)1430 void VpssCfgSetGrp(VpssCfg* self,
1431     int grpId, const VPSS_GRP_ATTR_S* grpAttr, int maxWidth, int maxHeight)
1432 {
1433     HI_ASSERT(self);
1434     HI_ASSERT(grpId >= 0);
1435 
1436     self->grpId = grpId;
1437 
1438     if (grpAttr) {
1439         self->grpAttr = *grpAttr;
1440     } else { // Set as default
1441         self->grpAttr.u32MaxW = maxWidth < 0 ? 0 : maxWidth;
1442         self->grpAttr.u32MaxH = maxHeight < 0 ? 0 : maxHeight;
1443         self->grpAttr.enPixelFormat = PIXEL_FORMAT_YVU_SEMIPLANAR_420;
1444         self->grpAttr.enDynamicRange = DYNAMIC_RANGE_SDR8;
1445         self->grpAttr.stFrameRate.s32SrcFrameRate = -1;
1446         self->grpAttr.stFrameRate.s32DstFrameRate = -1;
1447         self->grpAttr.bNrEn = HI_TRUE;
1448     }
1449 }
1450 
1451 /*
1452  * 增加一个VPSS通道
1453  * Add a VPSS channel
1454  */
VpssCfgAddChn(VpssCfg * self,int chnId,const VPSS_CHN_ATTR_S * chnAttr,int width,int height)1455 VPSS_CHN_ATTR_S* VpssCfgAddChn(VpssCfg* self,
1456     int chnId, const VPSS_CHN_ATTR_S* chnAttr, int width, int height)
1457 {
1458     HI_ASSERT(self);
1459     HI_ASSERT(self->chnNum < (sizeof(self->chnCfgs) / sizeof((self->chnCfgs)[0])));
1460     static const uint32_t depthDef = 2;
1461     VpssChnCfg *chnCfg = &self->chnCfgs[self->chnNum];
1462 
1463     if (chnAttr) {
1464         chnCfg->attr = *chnAttr;
1465     } else { // Set as default
1466         chnCfg->attr.u32Width = width < 0 ? 0 : width;
1467         chnCfg->attr.u32Height = height < 0 ? 0 : height;
1468         chnCfg->attr.enChnMode = VPSS_CHN_MODE_USER;
1469         chnCfg->attr.enVideoFormat = VIDEO_FORMAT_LINEAR;
1470         chnCfg->attr.enPixelFormat = PIXEL_FORMAT_YVU_SEMIPLANAR_420;
1471         chnCfg->attr.enDynamicRange = DYNAMIC_RANGE_SDR8;
1472         chnCfg->attr.enCompressMode = COMPRESS_MODE_NONE;
1473         chnCfg->attr.stFrameRate.s32SrcFrameRate = -1;
1474         chnCfg->attr.stFrameRate.s32DstFrameRate = -1;
1475         chnCfg->attr.u32Depth = depthDef;
1476         chnCfg->attr.bMirror = HI_FALSE;
1477         chnCfg->attr.bFlip = HI_FALSE;
1478         chnCfg->attr.stAspectRatio.enMode = ASPECT_RATIO_NONE;
1479     }
1480     chnCfg->id = chnId;
1481 
1482     self->chnNum++;
1483     return &chnCfg->attr;
1484 }
1485 
1486 /*
1487  * 根据VPSS配置来启动VPSS
1488  * Start VPSS according to VPSS config
1489  */
VpssStart(const VpssCfg * cfg)1490 int VpssStart(const VpssCfg* cfg)
1491 {
1492     HI_ASSERT(cfg);
1493     VPSS_GRP grpId = cfg->grpId;
1494     HI_S32 ret;
1495 
1496     /*
1497      * 创建一个VPSS GROUP
1498      * Create a VPSS GROUP
1499      */
1500     ret = HI_MPI_VPSS_CreateGrp(grpId, &cfg->grpAttr);
1501     if (ret != 0) {
1502         SAMPLE_PRT("HI_MPI_VPSS_CreateGrp(%d) FAIL, ret=%#x\n", grpId, ret);
1503         return ret;
1504     }
1505 
1506     for (int i = 0; i < cfg->chnNum; i++) {
1507         /*
1508          * 设置VPSS通道属性
1509          * Set VPSS channel properties
1510          */
1511         ret = HI_MPI_VPSS_SetChnAttr(grpId, cfg->chnCfgs[i].id, &cfg->chnCfgs[i].attr);
1512         if (ret != 0) {
1513             SAMPLE_PRT("HI_MPI_VPSS_SetChnAttr(%d) FAIL, ret=%#x\n", cfg->chnCfgs[i].id, ret);
1514             return ret;
1515         }
1516 
1517         /*
1518          * 启用VPSS通道
1519          * Enable VPSS channel
1520          */
1521         ret = HI_MPI_VPSS_EnableChn(grpId, cfg->chnCfgs[i].id);
1522         if (ret != 0) {
1523             SAMPLE_PRT("HI_MPI_VPSS_EnableChn(%d) FAIL, ret=%#x\n", cfg->chnCfgs[i].id, ret);
1524             return ret;
1525         }
1526     }
1527 
1528     /*
1529      * 启用VPSS GROUP
1530      * Enable VPSS GROUP
1531      */
1532     ret = HI_MPI_VPSS_StartGrp(grpId);
1533     if (ret != 0) {
1534         SAMPLE_PRT("HI_MPI_VPSS_StartGrp(%d) FAIL, ret=%#x\n", grpId, ret);
1535         return ret;
1536     }
1537     return HI_SUCCESS;
1538 }
1539 
1540 /*
1541  * 终止使用ViCfg启动的VI
1542  * Terminate VI started with ViCfg
1543  */
ViStop(const ViCfg * viCfg)1544 int ViStop(const ViCfg* viCfg)
1545 {
1546     return SAMPLE_COMM_VI_StopVi((ViCfg*)viCfg);
1547 }
1548 
1549 /*
1550  * 停止使用VpssCfg启动的VPSS
1551  * Terminate VPSS started with VpssCfg
1552  */
VpssStop(const VpssCfg * cfg)1553 int VpssStop(const VpssCfg* cfg)
1554 {
1555     HI_ASSERT(cfg);
1556     VPSS_GRP grpId = cfg->grpId;
1557     HI_S32 ret;
1558 
1559     for (int i = 0; i < cfg->chnNum; i++) {
1560         /*
1561          * 禁用VPSS通道
1562          * Disable VPSS channel
1563          */
1564         ret = HI_MPI_VPSS_DisableChn(grpId, cfg->chnCfgs[i].id);
1565         if (ret != 0) {
1566             SAMPLE_PRT("HI_MPI_VPSS_DisableChn(%d, %d) FAIL, ret=%#x\n", grpId, cfg->chnCfgs[i].id, ret);
1567             return ret;
1568         }
1569     }
1570 
1571     /*
1572      * 禁用VPSS GROUP
1573      * Stop VPSS GROUP
1574      */
1575     ret = HI_MPI_VPSS_StopGrp(grpId);
1576     if (ret != 0) {
1577         SAMPLE_PRT("HI_MPI_VPSS_StopGrp(%d) FAIL, ret=%#x\n", grpId, ret);
1578         return ret;
1579     }
1580 
1581     /*
1582      * 销毁一个VPSS GROUP
1583      * Destroy a VPSS GROUP
1584      */
1585     ret = HI_MPI_VPSS_DestroyGrp(grpId);
1586     if (ret != 0) {
1587         SAMPLE_PRT("HI_MPI_VPSS_DestroyGrp(%d) FAIL, ret=%#x\n", grpId, ret);
1588         return ret;
1589     }
1590     return HI_SUCCESS;
1591 }
1592 
1593 /*
1594  * 根据VI配置来启动VI
1595  * Start VI according to ViCfg
1596  */
ViStart(const ViCfg * viCfg)1597 int ViStart(const ViCfg* viCfg)
1598 {
1599     static const uint32_t frmRateDef = 30;
1600     SAMPLE_SNS_TYPE_E snsType = viCfg->astViInfo[0].stSnsInfo.enSnsType;
1601     ISP_CTRL_PARAM_S ispCtrlParam;
1602     HI_U32 frmRate;
1603     HI_S32 ret;
1604 
1605     ret = SAMPLE_COMM_VI_SetParam((ViCfg*)viCfg);
1606     if (ret != 0) {
1607         SAMPLE_PRT("SAMPLE_COMM_VI_SetParam FAIL, ret=%#x\n", ret);
1608         return ret;
1609     }
1610 
1611     /*
1612      * 通过Sensor型号来获取帧率
1613      * Get the frame rate through the Sensor model
1614      */
1615     SAMPLE_COMM_VI_GetFrameRateBySensor(snsType, &frmRate);
1616     ret = HI_MPI_ISP_GetCtrlParam(viCfg->astViInfo[0].stPipeInfo.aPipe[0], &ispCtrlParam);
1617     if (ret != 0) {
1618         SAMPLE_PRT("HI_MPI_ISP_GetCtrlParam FAIL, ret=%#x\n", ret);
1619         return ret;
1620     }
1621 
1622     ispCtrlParam.u32StatIntvl = frmRate / frmRateDef;
1623     ret = HI_MPI_ISP_SetCtrlParam(viCfg->astViInfo[0].stPipeInfo.aPipe[0], &ispCtrlParam);
1624     if (ret != 0) {
1625         SAMPLE_PRT("HI_MPI_ISP_SetCtrlParam FAIL, ret=%#x\n", ret);
1626         return ret;
1627     }
1628 
1629     ret = SAMPLE_COMM_VI_StartVi((ViCfg*)viCfg);
1630     if (ret != 0) {
1631         SAMPLE_PRT("SAMPLE_COMM_VI_StartVi FAIL, ret=%#x\n", ret);
1632         return ret;
1633     }
1634 
1635     return HI_SUCCESS;
1636 }
1637 
1638 /*
1639  * 将VI绑定到VPSS
1640  * Bind VI to VPSS
1641  */
ViBindVpss(VI_PIPE viPipe,VI_CHN viChn,VPSS_GRP vpssGrp)1642 int ViBindVpss(VI_PIPE viPipe, VI_CHN viChn, VPSS_GRP vpssGrp)
1643 {
1644     MPP_CHN_S srcChn;
1645     MPP_CHN_S dstChn;
1646 
1647     srcChn.enModId = HI_ID_VI;
1648     srcChn.s32DevId = viPipe;
1649     srcChn.s32ChnId = viChn;
1650 
1651     dstChn.enModId = HI_ID_VPSS;
1652     dstChn.s32DevId = vpssGrp;
1653     dstChn.s32ChnId = 0;
1654 
1655     int ret = HI_MPI_SYS_Bind(&srcChn, &dstChn);
1656     if (ret != 0) {
1657         SAMPLE_PRT("HI_MPI_SYS_Bind(VI:%d, VPSS:%d) FAIL, ret=%#x\n", viChn, vpssGrp, ret);
1658         return ret;
1659     }
1660 
1661     return ret;
1662 }
1663 
1664 /*
1665  * 新的MppSess
1666  * New MppSess
1667  */
MppSessNew(void)1668 static MppSess* MppSessNew(void)
1669 {
1670     MppSess *sess = (MppSess*)malloc(sizeof(*sess));
1671     if (sess == NULL) {
1672         SAMPLE_PRT("%s: malloc failed!\n", __FUNCTION__);
1673         HI_ASSERT(sess);
1674     }
1675 
1676     if (memset_s(sess, sizeof(*sess), 0, sizeof(*sess)) != EOK) {
1677         HI_ASSERT(0);
1678     }
1679 
1680     sess->vpssGrp = -1;
1681     sess->vpssChn0 = -1;
1682     sess->vpssChn1 = -1;
1683 
1684     return sess;
1685 }
1686 
1687 /*
1688  * 创建并启动{VI->VPSS}MppSess
1689  * Create and start {VI->VPSS}MppSess
1690  */
ViVpssCreate(MppSess ** sess,const ViCfg * viCfg,const VpssCfg * vpssCfg)1691 int ViVpssCreate(MppSess** sess, const ViCfg* viCfg, const VpssCfg* vpssCfg)
1692 {
1693     HI_ASSERT(sess && viCfg && vpssCfg);
1694     *sess = NULL;
1695     int res;
1696     int ret;
1697 
1698     ret = ViStart(viCfg);
1699     SAMPLE_CHECK_EXPR_GOTO(ret != HI_SUCCESS, FAIL1,
1700         "vi start fail, err(%#x)\n", ret);
1701 
1702     ret = VpssStart(vpssCfg);
1703     SAMPLE_CHECK_EXPR_GOTO(ret != HI_SUCCESS, FAIL2,
1704         "vpss start fail, err(%#x)\n", ret);
1705 
1706     VI_PIPE pipeId = viCfg->astViInfo[0].stPipeInfo.aPipe[0];
1707     VI_CHN chnId = viCfg->astViInfo[0].stChnInfo.ViChn;
1708     ret = ViBindVpss(pipeId, chnId, vpssCfg->grpId);
1709     SAMPLE_CHECK_EXPR_GOTO(ret != HI_SUCCESS, FAIL3,
1710         "vi bind vpss fail, err(%#x)\n", ret);
1711 
1712     MppSess *self = MppSessNew();
1713     *sess = self;
1714     self->viCfg = *viCfg;
1715     self->vpssCfg = *vpssCfg;
1716     self->used |= MPP_VI;
1717     self->used |= MPP_VPSS;
1718     self->vpssGrp = vpssCfg->grpId;
1719     self->vpssChn0 = vpssCfg->chnCfgs[0].id;
1720     self->vpssChn1 = vpssCfg->chnNum > 1 ? vpssCfg->chnCfgs[1].id : -1;
1721     return 0;
1722 
1723     FAIL3:
1724         res = VpssStop(vpssCfg);
1725         SAMPLE_PRT("ViVpssCreate\n");
1726         if (res != 0) {
1727             SAMPLE_PRT("VpssStop FAIL, ret=%#x\n", res);
1728         }
1729     FAIL2:
1730         ViStop(viCfg);
1731     FAIL1:
1732         return ret;
1733 }
1734 
StVoParamCfg(VoCfg * self)1735 HI_VOID StVoParamCfg(VoCfg *self)
1736 {
1737     SAMPLE_COMM_VO_GetDefConfig(self);
1738     self->enDstDynamicRange = DYNAMIC_RANGE_SDR8;
1739 
1740     self->enVoIntfType = VO_INTF_MIPI; /* set VO int type */
1741     self->enIntfSync = VO_OUTPUT_USER; /* set VO output information */
1742 
1743     self->enPicSize = g_lcdMediaInfo.enPicSize;
1744 }
1745 
StVbParamCfg(VbCfg * self)1746 HI_VOID StVbParamCfg(VbCfg *self)
1747 {
1748     memset_s(&g_lcdMediaInfo.vbCfg, sizeof(VB_CONFIG_S), 0, sizeof(VB_CONFIG_S));
1749     // 2: The number of buffer pools that can be accommodated in the entire system
1750     self->u32MaxPoolCnt              = 2;
1751 
1752     /*
1753      * 获取一帧图片的buffer大小
1754      * Get picture buffer size
1755      */
1756     g_lcdMediaInfo.u32BlkSize = COMMON_GetPicBufferSize(g_lcdMediaInfo.stSize.u32Width, g_lcdMediaInfo.stSize.u32Height,
1757         SAMPLE_PIXEL_FORMAT, DATA_BITWIDTH_8, COMPRESS_MODE_SEG, DEFAULT_ALIGN);
1758     self->astCommPool[0].u64BlkSize  = g_lcdMediaInfo.u32BlkSize;
1759     // 10: Number of cache blocks per cache pool. Value range: (0, 10240]
1760     self->astCommPool[0].u32BlkCnt   = 10;
1761 
1762     /*
1763      * 获取raw buffer的大小
1764      * Get raw buffer size
1765      */
1766     g_lcdMediaInfo.u32BlkSize = VI_GetRawBufferSize(g_lcdMediaInfo.stSize.u32Width, g_lcdMediaInfo.stSize.u32Height,
1767         PIXEL_FORMAT_RGB_BAYER_16BPP, COMPRESS_MODE_NONE, DEFAULT_ALIGN);
1768     self->astCommPool[1].u64BlkSize  = g_lcdMediaInfo.u32BlkSize;
1769     // 4: Number of cache blocks per cache pool. Value range: (0, 10240]
1770     self->astCommPool[1].u32BlkCnt   = 4;
1771 }
1772 
ViPramCfg(HI_VOID)1773 HI_VOID ViPramCfg(HI_VOID)
1774 {
1775     ViCfgInit(&g_lcdMediaInfo.viCfg);
1776     ViCfgSetDev(&g_lcdMediaInfo.viCfg, 0, -1);
1777     ViCfgSetPipe(&g_lcdMediaInfo.viCfg, 0, -1, -1, -1);
1778     g_lcdMediaInfo.viCfg.astViInfo[0].stPipeInfo.enMastPipeMode = 0;
1779     ViCfgSetChn(&g_lcdMediaInfo.viCfg, 0, -1, -1, -1);
1780     g_lcdMediaInfo.viCfg.astViInfo[0].stChnInfo.enCompressMode = 1;
1781 }
1782 
1783 /*
1784  * 将sensor采集的图像显示在LCD屏幕上,即视频输入->视频处理子系统->视频输出->显示屏
1785  * Display the data collected by sensor to LCD screen, VI->VPSS->VO->MIPI
1786  */
SampleVioVpssVoMipi(void)1787 int SampleVioVpssVoMipi(void)
1788 {
1789     HI_S32             s32Ret;
1790     HI_S32             fd = 0;
1791 
1792     /*
1793      * 配置VI参数
1794      * Config VI parameter
1795      */
1796     ViPramCfg();
1797 
1798     /*
1799      * 通过Sensor型号获取enPicSize
1800      * Obtain enPicSize through the Sensor type
1801      */
1802     s32Ret = SAMPLE_COMM_VI_GetSizeBySensor(g_lcdMediaInfo.viCfg.astViInfo[0].stSnsInfo.enSnsType,
1803         &g_lcdMediaInfo.enPicSize);
1804     SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, "get picture size by sensor failed, s32Ret=%#x\n", s32Ret);
1805 
1806     /*
1807      * 根据enPicSize,得到图片的宽高
1808      * Get picture size(w*h), according enPicSize
1809      */
1810     s32Ret = SAMPLE_COMM_SYS_GetPicSize(g_lcdMediaInfo.enPicSize, &g_lcdMediaInfo.stSize);
1811     SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, "get picture size failed, s32Ret=%#x\n", s32Ret);
1812     SAMPLE_PRT("AIC: snsMaxSize=%ux%u\n", g_lcdMediaInfo.stSize.u32Width, g_lcdMediaInfo.stSize.u32Height);
1813 
1814     /*
1815      * 配置VB参数
1816      * Config VB parameter
1817      */
1818     StVbParamCfg(&g_lcdMediaInfo.vbCfg);
1819 
1820     /*
1821      * 视频缓存池初始化以及MPI系统初始化
1822      * VB init & MPI system init
1823      */
1824     s32Ret = SAMPLE_COMM_SYS_Init(&g_lcdMediaInfo.vbCfg);
1825     SAMPLE_CHECK_EXPR_RET(s32Ret != HI_SUCCESS, s32Ret, "system init FAIL, s32Ret=%#x\n", s32Ret);
1826 
1827     /*
1828      * 设置VO至MIPI通路,获取MIPI设备
1829      * Set VO config to MIPI, get MIPI device
1830      */
1831     s32Ret = SAMPLE_VO_CONFIG_MIPI(&fd);
1832     SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, EXIT, "CONFIG MIPI FAIL.s32Ret:0x%x\n", s32Ret);
1833 
1834     /*
1835      * 配置VPSS参数
1836      * Config VPSS parameter
1837      */
1838     VpssCfgInit(&g_lcdMediaInfo.vpssCfg);
1839     VpssCfgSetGrp(&g_lcdMediaInfo.vpssCfg, AIC_VPSS_GRP, NULL,
1840         g_lcdMediaInfo.stSize.u32Width, g_lcdMediaInfo.stSize.u32Width);
1841     g_lcdMediaInfo.vpssCfg.grpAttr.enPixelFormat = PIXEL_FORMAT_YVU_SEMIPLANAR_420;
1842     VpssCfgAddChn(&g_lcdMediaInfo.vpssCfg, AIC_VPSS_ZOUT_CHN, NULL, AICSTART_VI_OUTWIDTH, AICSTART_VI_OUTHEIGHT);
1843     HI_ASSERT(!g_lcdMediaInfo.viSess);
1844     s32Ret = ViVpssCreate(&g_lcdMediaInfo.viSess, &g_lcdMediaInfo.viCfg, &g_lcdMediaInfo.vpssCfg);
1845     SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, EXIT1, "ViVpss Sess create FAIL, ret=%#x\n", s32Ret);
1846 
1847     g_lcdMediaInfo.vpssGrp = AIC_VPSS_GRP;
1848     g_lcdMediaInfo.vpssChn0 = AIC_VPSS_ZOUT_CHN;
1849 
1850     /*
1851      * 配置VO参数
1852      * Config VO parameter
1853      */
1854     StVoParamCfg(&g_lcdMediaInfo.voCfg);
1855 
1856     /*
1857      * 启动VO到MIPI lcd通路
1858      * Start VO to MIPI lcd
1859      */
1860     s32Ret = SampleCommVoStartMipi(&g_lcdMediaInfo.voCfg);
1861     SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, EXIT1, "start vo FAIL. s32Ret: 0x%x\n", s32Ret);
1862 
1863     /*
1864      * VPSS绑定VO
1865      * VPSS bind VO
1866      */
1867     s32Ret = SAMPLE_COMM_VPSS_Bind_VO(g_lcdMediaInfo.vpssGrp, g_lcdMediaInfo.vpssChn0, g_lcdMediaInfo.voCfg.VoDev, 0);
1868     SAMPLE_CHECK_EXPR_GOTO(s32Ret != HI_SUCCESS, EXIT2, "vo bind vpss FAIL. s32Ret: 0x%x\n", s32Ret);
1869     SAMPLE_PRT("vpssGrp:%d, vpssChn:%d\n", g_lcdMediaInfo.vpssGrp, g_lcdMediaInfo.vpssChn0);
1870 
1871     Pause();
1872 
1873     SAMPLE_COMM_VPSS_UnBind_VO(g_lcdMediaInfo.vpssGrp, g_lcdMediaInfo.vpssChn0, g_lcdMediaInfo.voCfg.VoDev, 0);
1874     SAMPLE_VO_DISABLE_MIPITx(fd);
1875     SampleCloseMipiTxFd(fd);
1876     system("echo 0 > /sys/class/gpio/gpio55/value");
1877 
1878 EXIT2:
1879     SAMPLE_COMM_VO_StopVO(&g_lcdMediaInfo.voCfg);
1880 EXIT1:
1881     VpssStop(&g_lcdMediaInfo.vpssCfg);
1882     SAMPLE_COMM_VI_UnBind_VPSS(g_lcdMediaInfo.viCfg.astViInfo[0].stPipeInfo.aPipe[0],
1883         g_lcdMediaInfo.viCfg.astViInfo[0].stChnInfo.ViChn, g_lcdMediaInfo.vpssGrp);
1884     ViStop(&g_lcdMediaInfo.viCfg);
1885 EXIT:
1886     SAMPLE_COMM_SYS_Exit();
1887     return s32Ret;
1888 }
1889 
1890 #ifdef __cplusplus
1891 #if __cplusplus
1892 }
1893 #endif
1894 #endif /* End of #ifdef __cplusplus */