📄 slideshow.c
字号:
//// XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"// SOLELY FOR USE IN DEVELOPING PROGRAMS AND SOLUTIONS FOR// XILINX DEVICES. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION// AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION// OR STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS// IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,// AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE// FOR YOUR IMPLEMENTATION. XILINX EXPRESSLY DISCLAIMS ANY// WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE// IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR// REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF// INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS// FOR A PARTICULAR PURPOSE.// // (c) Copyright 2004 Xilinx, Inc.// All rights reserved.///* * Simple slideshow demo with read/write to Compact Flash * * Reads images from: "a:\\image01.bmp", "a:\\image02.bmp", "a:\\image03.bmp", ... * Stores images starting at IMAGE_BASEADDR, which by default is 0x0 **/#include <xparameters.h>#include <sysace_stdio.h>#include "xio.h"#include "sleep.h"//#include "util.h"// Demo Parameters#define IMAGE_BASEADDR 0x00000000#define IMAGE_MAXADDR 0x10000000/* structs for bitmaps */typedef struct { unsigned short int type; /* Magic identifier */ unsigned int size; /* File size in bytes */ unsigned short int reserved1, reserved2; unsigned int offset; /* Offset to image data, bytes */} HEADER;typedef struct { unsigned int size; /* Header size in bytes */ int width,height; /* Width and height of image */ unsigned short int planes; /* Number of color planes */ unsigned short int bits; /* Bits per pixel */ unsigned int compression; /* Compression type */ unsigned int imagesize; /* Image size in bytes */ int xresolution,yresolution; /* Pixels per meter */ unsigned int ncolors; /* Number of colors */ unsigned int importantcolors; /* Important colors */} INFOHEADER;/* structs for wave files */typedef struct { unsigned int chunkID; unsigned int chunkSize; unsigned int format;} RIFFCHUNK;typedef struct { unsigned int subchunkID; unsigned int subchunkSize; unsigned short int audioFormat; unsigned short int numChannels; unsigned int sampleRate; unsigned int byteRate; unsigned short int blockAlign; unsigned short int bitsPerSample; unsigned short int extraParamSize;} FMTCHUNK;typedef struct { unsigned int subchunkID; unsigned int subchunkSize;} DATACHUNK;/* reads two bytes from file */static unsigned short ReadUShort(SYSACE_FILE *fptr){ unsigned char b0, b1; int numread; char readBuffer[2]; numread = sysace_fread(readBuffer, 1, 2, fptr); b0 = readBuffer[0]; b1 = readBuffer[1]; return ((b1 << 8) | b0);}/* reads four bytes from file in little endian order */static unsigned int ReadUIntLil(SYSACE_FILE *fptr){ unsigned char b0, b1, b2, b3; int numread; char readBuffer[4]; numread = sysace_fread(readBuffer, 1, 4, fptr); b0 = readBuffer[0]; b1 = readBuffer[1]; b2 = readBuffer[2]; b3 = readBuffer[3]; return ((((((b3 << 8) | b2) << 8) | b1) << 8) | b0);}/* reads four bytes from file in big endian order */static unsigned int ReadUIntBig(SYSACE_FILE *fptr){ unsigned char b0, b1, b2, b3; int numread; char readBuffer[4]; numread = sysace_fread(readBuffer, 1, 4, fptr); b0 = readBuffer[0]; b1 = readBuffer[1]; b2 = readBuffer[2]; b3 = readBuffer[3]; return ((((((b0 << 8) | b1) << 8) | b2) << 8) | b3);}/* opens and reads from CF a 640x480 bitmap file, placing it in memory at baseaddr in a format for the tft */int read_image(char FileName[], int baseaddr){ unsigned char readBuffer[1920]; SYSACE_FILE *infile; int i, j, numread, temp, writeaddr; HEADER header; INFOHEADER infoheader; infile = sysace_fopen(FileName, "r"); if(infile) { xil_printf("Reading file : %s\n\r", FileName);// XromLCDPrintString ("Loading Slide: ", &FileName[3]); /* Read and check the header */ header.type = ReadUShort(infile); header.size = ReadUIntLil(infile); header.reserved1 = ReadUShort(infile); header.reserved2 = ReadUShort(infile); header.offset = ReadUIntLil(infile); infoheader.size = ReadUIntLil(infile); infoheader.width = ReadUIntLil(infile); infoheader.height = ReadUIntLil(infile); infoheader.planes = ReadUShort(infile); infoheader.bits = ReadUShort(infile); infoheader.compression = ReadUIntLil(infile); infoheader.imagesize = ReadUIntLil(infile); infoheader.xresolution = ReadUIntLil(infile); infoheader.yresolution = ReadUIntLil(infile); infoheader.ncolors = ReadUIntLil(infile); infoheader.importantcolors = ReadUIntLil(infile); /* xil_printf("ID is: %d, should be %d\n\r",header.type,'M'*256+'B'); xil_printf("File size is %d bytes\n\r",header.size); xil_printf("Offset to image data is %d bytes\n\r",header.offset); xil_printf("Image size = %d x %d\n\r",infoheader.width,infoheader.height); xil_printf("Number of color planes is %d\n\r",infoheader.planes); xil_printf("Bits per pixel is %d\n\r",infoheader.bits); xil_printf("Compression type is %d\n\r",infoheader.compression); xil_printf("Number of colors is %d\n\r",infoheader.ncolors); xil_printf("Number of required colors is %d\n\r",infoheader.importantcolors); */ /* Process the data */ for (j=infoheader.height-1;j>=0;j--) { numread = sysace_fread(readBuffer, 1, 1920, infile); for (i=0;i<infoheader.width;i++) { temp = ((((readBuffer[i*3+2] << 8) | readBuffer[(i*3)+1]) << 8) | readBuffer[(i*3)]); writeaddr = baseaddr+(j*1024+i)*4; XIo_Out32(writeaddr, temp); } } sysace_fclose(infile); return 1; } else { return 0; }}/* reads a series of images from CF: "image01.bmp", "image02.bmp", "image03.bmp", ... *//* stores each in memory on consecutive 2MB boundaries starting at IMAGE_BASEADDR up to IMAGE_MAXADDR */int get_images(){ char file[] = "a:\\image01.bmp"; int baseaddr = IMAGE_BASEADDR; int count = 0; while(baseaddr < IMAGE_MAXADDR && read_image(file, baseaddr)) { if (file[9] == '9') { file[8]++; file[9] -= 9; } else { file[9]++; } baseaddr += 0x200000; count++; } return count;}/* infinite loop */void step_images(Xuint32 baseaddr, Xuint32 count) { unsigned int i, j; unsigned int data, length, temp; unsigned int tftptr, volume; Xboolean button_n, button_e, button_s, button_w, button_c; Xboolean past_button_n, past_button_e, past_button_s, past_button_w, past_button_c; Xboolean paused = 0; length = XIo_In32(baseaddr); tftptr = baseaddr; /* Simple imaage loop */ print("Stepping through slides.\n\r"); while(1){ j= 0; //print("waiting\r\n"); usleep(5000000); if (tftptr == (IMAGE_BASEADDR) + (0x200000*(count-1)) ){ tftptr = IMAGE_BASEADDR; XIo_Out32(0xD0000040, tftptr); } else { //print("changing vga base address\n\r"); tftptr += 0x200000; XIo_Out32(0xD0000040, tftptr); } }}int main(){ int count = 0; print("\r\nTurning caches on"); XCache_EnableDCache(0xF000000F); XCache_EnableICache(0xF000000F); /* get images */ print("\r\nProgram running.\n\r"); count = get_images(); print("\n\rReads done\n\r"); /* set TFT pointer */ XIo_Out32(0xD0000040, IMAGE_BASEADDR); XIo_Out32(0xD0000044, 0x1); // turn on display step_images(IMAGE_BASEADDR, count); // infinite loop return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -