倒车显示分两个部分,前端处理好视频输入信号,准备好内容,后端显示驱动再来把内容显示到LCD上。很明显,前端是TVD模块来处理的,后端是有DE模块来处理的,我们接下来先分析一下TVD模块怎么工作的。
首先,需要加载驱动打开设备驱动,如果有需要还可以执行IOCTL操作,跟在linux系统里操作驱动的IOCTL类似。代码如下:
/*****************************************************************************************************/
声明:本博内容均由http://blog.csdn.net/edsam49原创,转载请注明出处,谢谢!
/*****************************************************************************************************/
ret = wBoot_driver_install("c:\\drv_tvd.drv"); if(ret != 0) { DMSG_PANIC("ERR: wBoot_driver_install drv_tvd driver failed\n"); return -1; } ret = wBoot_script_parser_fetch("tvin_para", "tvin_reverse_channel_num", &reverseChannel, 1); if(ret) { __inf("unable to find tvin_para tvin_reverse_channel_num value\n"); } __inf("BoardInit_TVD: reverseChannel=%x\n", reverseChannel); TVDTransferToDRVInfo.ch = reverseChannel; //open tvd devices , we transfer some TVD parameter to driver tvd_hd = wBoot_driver_open(EGON2_EMOD_TYPE_DRV_TVD, &TVDTransferToDRVInfo); if(tvd_hd == NULL) { DMSG_PANIC("ERR: open drv_tvd driver failed\n"); return -1; }
加载驱动会执行到init接口,打开设备的时候会执行open接口,对应接口在上一篇文章中有介绍到。那么,我们可以再open的接口里对TVD 模块做一些必要的设置,当然一些模块的参数,我们可以再open的时候传给TVD的驱动,也就是传给DRV_TVD_OPEN函数接口。笔者根据需要传了一些控制参数进去,比如选择的TVD channel通道号,因为TVD有4个channel;显示的视频信号格式是NTSC信号还是PAL的信号,这样可以加快初始化,加快出正确的图像;以及Y/C的buffer地址,这里是为了让display这边方便的拿到显示buffer的地址,当然申请buffer放到TVD驱动里也是可以的,但是对应显示驱动就得晚于TVD驱动执行,这个问题其实也有人写一个固定的安全内存地址,其实也可以,只是感觉不灵活。
下面就说说TVD的具体驱动,首先TVD需要设置的是CLK,没有CLK什么都是扯,主要是ahb bus、tvd模块、DRAM、PLL3 VIDEO相关的clock,大致如下:
ccm_clock_disable(TVD_CKID); ccm_clock_enable(TVD_CKID); set_wbit(CCM_DRAMCLK_GATE_CTRL, 0x1U<<4);//tvd if(mode<4) { put_wvalue(CCM_PLL3_VIDEO_CTRL,0x80105000); put_wvalue(CCM_TVD_SCLK_CTRL,0x8000800a); } else { put_wvalue(CCM_PLL3_VIDEO_CTRL,0x8010905a); put_wvalue(CCM_TVD_SCLK_CTRL,0x80008004); } void ccm_clock_enable(u32 clk_id) { switch(clk_id>>8) { case AXI_BUS: set_wbit(CCM_AXI_GATE_CTRL, 0x1U<<(clk_id&0xff)); break; case AHB_BUS0: set_wbit(CCM_AHB_GATE0_CTRL, 0x1U<<(clk_id&0xff)); break; case AHB_BUS1: set_wbit(CCM_AHB_GATE1_CTRL, 0x1U<<(clk_id&0xff)); break; case APB0_BUS0: set_wbit(CCM_APB0_GATE0_CTRL, 0x1U<<(clk_id&0xff)); break; case APB1_BUS0: set_wbit(CCM_APB1_GATE0_CTRL, 0x1U<<(clk_id&0xff)); break; } } void ccm_clock_disable(u32 clk_id) { switch(clk_id>>8) { case AXI_BUS: clr_wbit(CCM_AXI_GATE_CTRL, 0x1U<<(clk_id&0xff)); break; case AHB_BUS0: clr_wbit(CCM_AHB_GATE0_CTRL, 0x1U<<(clk_id&0xff)); break; case AHB_BUS1: clr_wbit(CCM_AHB_GATE1_CTRL, 0x1U<<(clk_id&0xff)); break; case APB0_BUS0: clr_wbit(CCM_APB0_GATE0_CTRL, 0x1U<<(clk_id&0xff)); break; case APB1_BUS0: clr_wbit(CCM_APB1_GATE0_CTRL, 0x1U<<(clk_id&0xff)); break; } }
接着就是控制TVD模块具体的寄存器了,使能必不可少,IRQ设置不可少,对比度、亮度、饱和度等,当然还有其他的一堆,初步的值是全志提供的,但是为了更好的显示效果,主要是匹配你这个产品的屏参吧,那我们就看一段NTSC的参数吧!
put_wvalue( TVD_BASE + 0x0008, 0x00590900); //notch width 0059_0100 put_wvalue( TVD_BASE + 0x000c, 0x00000010); //YC sep put_wvalue( TVD_BASE + 0x0010, 0x008A32DD); //sync height put_wvalue( TVD_BASE + 0x0014, 0x800000a0); //adjust YC delay put_wvalue( TVD_BASE + 0x0018, 0x00002080); //adjust luma brightness put_wvalue( TVD_BASE + 0x001c, 0x008a0080); //chroma AGC target put_wvalue( TVD_BASE + 0x0024, 0x0682810a); //DISABLE AGC GATE KILL!!!!!!!!!!!!!!!!! put_wvalue( TVD_BASE + 0x0028, 0x00006440); //0000_6440 0000_5838 put_wvalue( TVD_BASE + 0x0034, 0x20000000); //2000_0000 2400_0000 put_wvalue( TVD_BASE + 0x0044, 0x50824632); //burst gate put_wvalue( TVD_BASE + 0x004c, 0x0e70106c); //NO CLAMP DURING VSYNC!!!!!!!!!!!!!!!!! put_wvalue( TVD_BASE + 0x0054, 0x00000025); //peak en put_wvalue( TVD_BASE + 0x006c, 0x00fffa0a); //YC separation config put_wvalue( TVD_BASE + 0x0080, 0x00500082); //hactive start and width put_wvalue( TVD_BASE + 0x0084, 0x00610022); //vactive start and height put_wvalue( TVD_BASE + 0x0030, 0x21f07c1f); //21f0_7c1f 262E_8BA2 put_wvalue( TVD_BASE + 0x002c, 0x0000CB74); put_wvalue( TVD_BASE + 0x0074, 0x000003c3); //chroma edge enhance put_wvalue( TVD_BASE + 0x050c, 0x0000000b); put_wvalue( TVD_BASE + 0x051c, 0x00100000); put_wvalue( TVD_BASE + 0x0134 + ch * 0x100, y<<16 | x); put_wvalue( TVD_BASE + 0x0138 + ch * 0x100, len); put_wvalue( TVD_BASE + 0x0100 + ch * 0x100, addr0); put_wvalue( TVD_BASE + 0x0110 + ch * 0x100, addr1); put_wvalue( TVD_BASE + 0x0104 + ch * 0x100, addr2); put_wvalue( TVD_BASE + 0x0114 + ch * 0x100, addr3); put_wvalue( TVD_BASE + 0x0108 + ch * 0x100, addr4); put_wvalue( TVD_BASE + 0x0118 + ch * 0x100, addr5); put_wvalue( TVD_BASE + 0x010c + ch * 0x100, addr6); put_wvalue( TVD_BASE + 0x011c + ch * 0x100, addr7); put_wvalue( TVD_BASE + 0x0130 + ch * 0x100, frame<<26 | is_mb<<24 | \ hsample<<12 | is_yuv422<<4 | 0x1); put_wvalue(TVD_BASE+0x0148,0xf1ffffff);//int//int en//frame end, overflow, underflow put_wvalue(TVD_BASE+0x0140,0xffffffff);//clear irq//frame end, overflow, underflow put_wvalue(TVD_BASE+0x014c,0xffffffff);//address change error put_wvalue(TVD_BASE+0x0150,0x00000000);//int en//lock unlock put_wvalue(TVD_BASE+0x0154,0x0000ffff);//clear irq//lock unlock
这些程序一走,数据就差不多出来了。那么接下来就准备显示吧!
显示这部分在boot里面也已经是支持了的,但是需要自己去改造成自己需要的。首先模块的初始化还是借用boot里面已经支持的BoardInit_Display()接口,除此之前就需要自己动手来做了。比如要设置显示layer具体参数,比如显示的宽高、buffer的地址、显示的格式、是否是UV combined模式等,也不少。除此之外还得打开layer,因为申请layer已经在BoardInit_Display()接口里完成了。笔者的NTSC的显示参数大致如下:
memset((&layer_para), 0, sizeof(layer_para)); layer_para.fb.size.width = 704; layer_para.fb.size.height = 480; layer_para.fb.addr[0] = (__u32)TVDTransferToDRVInfo.addrYx;//TVD_ADDR_Y0; layer_para.fb.addr[1] = (__u32)TVDTransferToDRVInfo.addrCx;//TVD_ADDR_C0; layer_para.fb.mode = DISP_MOD_NON_MB_UV_COMBINED; layer_para.fb.format = DISP_FORMAT_YUV422; layer_para.fb.br_swap = 0; layer_para.fb.seq = DISP_SEQ_UYVY; layer_para.ck_enable = 0; layer_para.mode = DISP_LAYER_WORK_MODE_SCALER; layer_para.alpha_en = 1; layer_para.alpha_val = 0xff; layer_para.pipe = 0; layer_para.src_win.x = 15; layer_para.src_win.y = 10; layer_para.src_win.width = 688; layer_para.src_win.height = 470; layer_para.scn_win.x = 0; layer_para.scn_win.y = 0; layer_para.scn_win.width = De_GetSceenWidth(); layer_para.scn_win.height = De_GetSceenHeight();
通过以上的简单分析,倒车显示是基本OK了。但是记得退出倒车的时候要关闭显示,关闭TVD,卸载对应驱动。到此,基本上整个过程就分析完了。