HDMI of zynq 7000 displays picture files in SD card

This article is a continuation of the HDMI display experiment of zynq 7000. The  content shown above is included in the code, and this article directly displays the BMP image file in the SD card.

You must have completed the HDMI display experiment of zynq 7000  before you can do this experiment.

Code download:

Link: https://pan.baidu.com/s/11-RLOYtl1AyxcQ_XGbw2YQ 
extraction code: zvnc 

hdmiSDsrc.zip is the code of this article 17k, satan.zip is the compression of sample pictures, the others are the above content

hardware design

The hardware design of this experiment is basically the  same as the HDMI display experiment of zynq 7000 , so there is no need to re-create a new project, open its Vivado project, save it as a new project and name it "sd_hdmi_out", as shown in the figure below, open it after completion Project folder, delete the .sdk folder, this is the program of the previous experiment, this experiment does not need.

Then the software will automatically open this project, click "Open Block Design" to open the design file. Because this experiment wants to read the data of the SD card, SD0 should be enabled. Double-click the ZYNQ7 Processing System to open the setting page and enable SD0, as shown in the figure below (this should be set according to your SD card hardware):

Then click "OK" and save the settings. Then regenerate the top-level HDL. Click Generate Bitstream to generate a new BIT stream file.

After the generation is complete, export the hardware (File->Export->Export Hardware), and check Include bitstream when exporting.

The hardware part is complete. File ->Launch SDK Let's enter the software design part.

software design

Create a new application project in the opened SDK software and name it "hdmi_sd". Select the project template as blank. In this experiment, we need to read files in the SD card, so add a file system to support file operations, click Modify this BSP's Settings to enter the settings page, as shown in the following figure:

Generally, this interface will be displayed after creating a new project. If it does not appear, remember to click system.mss in the bsp directory.

Check the xilffs below, the software will automatically add related files to the project, as shown in the figure below:
 

After that, you can see that the relevant files have been added to the project.
 

Then open the downloaded file and copy it, or the microphase data routine directory SDK_Demo\ 18_sd_hdmi_out\sd_hdmi_out\sd_hdmi_out.sdk, copy the src folder in it, and save it to the same location of the newly created project, prompting that the same file skips and does not replace it. Then right-click the project under SDK software and click Refresh to recompile.

Open the display_demo.c main program file, we can see that this experiment adds the function bmp_read to read the picture file on the basis of the previous experiment. Use the f_open file operation function in the function to open the picture file, then read the first 54 bytes of the image header file to obtain the image pixel and other attribute information, and then read the pixel data in the order from bottom to top, from left to right. In this way, we have obtained all the pixel data of the picture, which is equivalent to the header files of several picture data used in the previous experiment. After successfully obtaining the image data, we can follow the steps of the previous experiment to write the data into the VDMA buffer, and then display it on the screen through the HDMI interface.

Compared with the code of the previous experiment, bmp_read replaces DemoPrintTest. Now read the display data from the picture file, and the latter is a variable pre-assigned from the header file, the common point is that it is sent to the display area DDR.

#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
#include "xil_types.h"
#include "xil_cache.h"
#include "xparameters.h"
#include "display_demo.h"
#include "display_ctrl/display_ctrl.h"
#include "display_ctrl/vga_modes.h"
#include "ff.h"

/*
 * XPAR redefines
 */
#define DYNCLK_BASEADDR     XPAR_AXI_DYNCLK_0_BASEADDR
#define VGA_VDMA_ID         XPAR_AXIVDMA_0_DEVICE_ID
#define DISP_VTC_ID         XPAR_VTC_0_DEVICE_ID

/* ------------------------------------------------------------ */
/*				Global Variables								*/
/* ------------------------------------------------------------ */


/*
 * Display Driver struct
 */
DisplayCtrl dispCtrl;
XAxiVdma vdma;
static FIL fil;		/* File object */
static FATFS fatfs;
/*
 * Frame buffers for video data
 */
u8 frameBuf[DISPLAY_NUM_FRAMES][DEMO_MAX_FRAME];
u8 *pFrames[DISPLAY_NUM_FRAMES];  // array of pointers to the frame buffers

/* ------------------------------------------------------------ */
/*				Procedure Definitions							*/
/* ------------------------------------------------------------ */
unsigned char read_line_buf[1920 * 4];
void bmp_read(char * bmp,u8 *frame,u32 stride)
{
	short y,x;
	short Ximage;
	short Yimage;
	u32 iPixelAddr = 0;
	FRESULT res;
	unsigned char TMPBUF[64];
	unsigned int br;         // File R/W count

	res = f_open(&fil, bmp, FA_OPEN_EXISTING | FA_READ);
	if(res != FR_OK)
	{
		return ;
	}
	res = f_read(&fil, TMPBUF, 54, &br);
	if(res != FR_OK)
	{
		return ;
	}
	Ximage=(unsigned short int)TMPBUF[19]*256+TMPBUF[18];
	Yimage=(unsigned short int)TMPBUF[23]*256+TMPBUF[22];
	iPixelAddr = (Yimage-1)*stride ;

	for(y = 0; y < Yimage ; y++)
	{
		f_read(&fil, read_line_buf, Ximage * 3, &br);
		for(x = 0; x < Ximage; x++)
		{
			frame[x * BYTES_PIXEL + iPixelAddr + 0] = read_line_buf[x * 3 + 0];
			frame[x * BYTES_PIXEL + iPixelAddr + 1] = read_line_buf[x * 3 + 1];
			frame[x * BYTES_PIXEL + iPixelAddr + 2] = read_line_buf[x * 3 + 2];
		}
		iPixelAddr -= stride;
	}
	f_close(&fil);
}
int main(void)
{
	int i;
	int Status;
	XAxiVdma_Config *vdmaConfig;
	FRESULT rc;
	/*
	 * Initialize an array of pointers to the 3 frame buffers
	 */
	for (i = 0; i < DISPLAY_NUM_FRAMES; i++)
	{
		pFrames[i] = frameBuf[i];
	}

	/*
	 * Initialize VDMA driver, get the hardware VDMA configurations
	 */
	vdmaConfig = XAxiVdma_LookupConfig(VGA_VDMA_ID);
	if (vdmaConfig == NULL)
	{
		xil_printf("No video DMA found for ID %d\r\n", VGA_VDMA_ID);
	}

	/*
	 * Use hardware VDMA configurations to initialize the driver
	 */
	Status = XAxiVdma_CfgInitialize(&vdma, vdmaConfig, vdmaConfig->BaseAddress);
	if (Status != XST_SUCCESS)
	{
		xil_printf("VDMA Configuration Initialization failed %d\r\n", Status);
	}

	/*
	 * Initialize the Display controller and start it
	 */

	VideoMode VMODE = VMODE_1920x1080;
	Status = DisplayInitialize(&dispCtrl, &vdma, DISP_VTC_ID, DYNCLK_BASEADDR, pFrames, DEMO_STRIDE, VMODE);

	if (Status != XST_SUCCESS)
	{
		xil_printf("Display Ctrl initialization failed during demo initialization%d\r\n", Status);
	}

	Status = DisplayStart(&dispCtrl);
	if (Status != XST_SUCCESS)
	{
		xil_printf("Couldn't start display during demo initialization%d\r\n", Status);
	}

	rc = f_mount(&fatfs, "0:/", 0);
		if (rc != FR_OK)
		{
			return 0 ;
		}
		bmp_read("shatan.bmp",dispCtrl.framePtr[dispCtrl.curFrame], DEMO_STRIDE);
		Xil_DCacheFlushRange((unsigned int) dispCtrl.framePtr[dispCtrl.curFrame], DEMO_MAX_FRAME);

	return 0;
}

main function:

First initialize pFrames (pointer to frame buffers)

 get the hardware VDMA configurations  :vdmaConfig

Initialize the driver

The display starts.

Install and open the file "shatan.bmp"

Finally, the display data is copied to the display buffer through the function bmp_read, and the image is displayed

End of program

After the program is compiled, copy the sample pictures in the routine folder to the SD card, and you can download and verify it on the development board.

Download verification

Connect the serial cable and download cable of the development board, and use the HDMI cable to connect the HDMI interface and the display. Insert the SD card with the sample pictures copied into the card slot. Click Run->Run Configuration in the menu bar to enter the programming setting page, and set the relevant settings as shown in the figure below.

After the setting is complete, click "Run" to burn the program, you can see the sample picture shown on the screen as shown in the figure below.

Here are the requirements for graphics files. The file name is: shatan.bmp, which is the name of the file opened in the program. If you change the name, you must modify the file name in the software and place it in the root directory. The file is a 1900x1600 24bits graphic file.

If you want to open files with other resolutions, VideoMode VMODE = VMODE_1920x1080; This must be changed. I did not try.

If you want to open a non-24-bit bmp picture, you need to understand the file structure and then modify the code of the software bmp_read. This is a bit difficult. It is recommended not to do this. You can change the picture to 24-bit.

That's it for the introduction.


 

Guess you like

Origin blog.csdn.net/leon_zeng0/article/details/113409581