TA的每日心情 | 开心 2020-7-25 10:37 |
---|
签到天数: 40 天 连续签到: 1 天 [LV.5]常住居民I
|
本帖最后由 武器哈12 于 2019-11-23 00:49 编辑
先附上我的视频:
这次学习一下米尔MYD-C7Z020开发板HDMI的使用,米尔的教程里面有一个HDMI显示的例子,挺有参考价值,这次实验是在例程的基础上修改而来,准备在液晶屏上显示方块移动。
首先我们先一起来了解一下HDMI硬件:
MYD-C7Z020开发板HDMI使用的sii9022芯片来驱动,FPGA与sii9022的连接如下图所示:
从图中可以看到si9022的数据引脚、VSYNC、DE、HSNC接到了FPGA的PL侧,配置引脚I2C0_SCL、I2C0_SCL街道了PS的MIO51/MIO52,因此驱动sii9022需要使用到CPU,通过软件程序来配置sii9022的工作模式,另一方面编写verilog代码驱动HDMI。
step1:配置ZYNQ7 Processing system,注意在IP核中选IIC外设,并引出PL侧时钟和复位管脚,如下图所示:
编写HDMI驱动代码,代码基本架构如下图所示:
vga_display用于产生方块的移动图形,hdmi_control是VGA驱动代码,rgb_ycrcb模块是将VGA转换成ycrcb格式,ycrcb_yuv422是将ycrcb转换成yuv422格式。代码比较多,这里就不粘贴出来了,打下可以下载附件,附件里面有工程和代码,提供给大家参考。
Step2:在SDK中编写IIC驱动,由于在在IP中选了IIC,所以SDK中包含了IIC的基本驱动代码,我们只需要通过这些函数来配置SII9022即可,代码如下:
- #include "xil_types.h"
- #include "xiicps.h"
- #include "sleep.h"
- XIicPs IicInstance; /* The instance of the IIC device. */
- #define IIC_DEVICE_ID XPAR_XIICPS_0_DEVICE_ID
- u8 WriteBuffer[1 + 1];
- u8 ReadBuffer[1]; /* Read buffer for reading a page. */
- struct sensor_register {
- u8 addr;
- u8 value;
- };
- static const struct sensor_register sii9022_init_regs[] = {
- {0x1e, 0x00},
- {0x08, 0x70},
- {0x09, 0x06},
- {0x0a, 0x00},
- {0x19, 0x00},
- {0x60, 0x04},
- {0x3c, 0x01},
- {0x1a, 0x11},
- {0x00, 0x02}, /* IO CTRL */
- {0x01, 0x0d}, /* IO CTRL */
- {0x02, 0x44}, /* IO CTRL */
- {0x03, 0x16}, /*?? */
- {0x04, 0x34}, /*?? */
- {0x05, 0x04}, /*?? */
- {0x06, 0x17}, /*?? */
- {0x07, 0x02}, /* IO CTRL */
- {0x08, 0x70}, /* IO CTRL */
- {0x61, 0x03}, /* IO CTRL */
- {0x1a, 0x01},
- {0xff, 0xff}, /*over */
- };
- int iic_write_8(u8 a,u8 data)
- {
- int Status;
- WriteBuffer[0] = a;
- WriteBuffer[1] = data;
- Status = XIicPs_MasterSendPolled(&IicInstance, WriteBuffer,
- 2, 0x3b);
- if (Status != XST_SUCCESS) {
- return XST_FAILURE;
- }
- while (XIicPs_BusIsBusy(&IicInstance));
- usleep(2500);
- if (Status != XST_SUCCESS) {
- return XST_FAILURE;
- }
- WriteBuffer[0] = a;
- Status = XIicPs_MasterSendPolled(&IicInstance, WriteBuffer,
- 1, 0x3b);
- if (Status != XST_SUCCESS) {
- return XST_FAILURE;
- }
- while (XIicPs_BusIsBusy(&IicInstance));
- usleep(2500);
- Status = XIicPs_MasterRecvPolled(&IicInstance, ReadBuffer,
- 1, 0x3b);
- if (Status != XST_SUCCESS) {
- return XST_FAILURE;
- }
- while (XIicPs_BusIsBusy(&IicInstance));
- xil_printf("0x%02x=0x%02x\r\n",a,ReadBuffer[0]);
- return 0;
- }
- int iic_master_init(void)
- {
- int Status;
- XIicPs_Config *ConfigPtr; /* Pointer to configuration data */
- ConfigPtr = XIicPs_LookupConfig(IIC_DEVICE_ID);
- if (ConfigPtr == NULL) {
- return XST_FAILURE;
- }
- Status = XIicPs_CfgInitialize(&IicInstance, ConfigPtr,
- ConfigPtr->BaseAddress);
- if (Status != XST_SUCCESS) {
- return XST_FAILURE;
- }
- XIicPs_SetSClk(&IicInstance, 400000);
- return XST_SUCCESS;
- }
- int sii9022_init(void)
- {
- int i;
- i=0;
- /* ------------------------------------------------------------ */
- /* sii9022 hardware reset */
- /* ------------------------------------------------------------ */
- Xil_Out32(0xE000A000 + 0x244,0x00080000);
- Xil_Out32(0xE000A000 + 0x248,0x00080000);
- Xil_Out32(0xE000A000 + 0xC,0xFFF70008);
- usleep(2500);
- iic_master_init();
- iic_write_8(0xc7,0x00);//software reset
- while(1)
- {
- if(sii9022_init_regs.addr==0xff)
- break;
- iic_write_8(sii9022_init_regs.addr,sii9022_init_regs.value);
- i++;
- }
- return 0;
- }
我的工程:
hdmi_testa.zip
(4.62 MB, 下载次数: 34)
|
|