/* * Usage: * */ #include <unistd.h> #include <sys/mman.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> #include "s1d13521ioctl.h" #include <linux/fb.h> #define WF_MODE_INIT 0 #define WF_MODE_DU 1 #define WF_MODE_GC16 2 #define WF_MODE_GC4 3 int main(int argc,char*argv[]) { int fbdev, i, j; static unsignedshort *vram; unsigned short*pdata; unsigned short*pdata1; unsigned char clr; int choose = 0; int fd; int WIDTH = 600; int HEIGHT = 800; int PIC_WIDTH = 600; int PIC_HEIGHT= 800; unsigned char*data; struct stat sb; int xindex; int yindex; int retVal; int update_mode = 0; unsigned short mode; unsigned short cmd[10]; struct fb_var_screeninfo info; choose = atoi(argv[1]); update_mode = atoi(argv[2]); printf("choose = %d, update_mode = %d\n", choose, update_mode); /*read a grayscale file from external*/ fd = open(argv[3], O_RDONLY); if (fd < 0){ printf("Failed to open:%s\n", argv[3]); exit(-1); } if (fstat(fd,&sb) == -1){ printf("stat test_fb error!\n"); return -1; } printf("file size = %d!\n", sb.st_size); data = (unsignedchar *)malloc(sb.st_size+1); if (data == NULL){ printf("Failed to malloc\n"); exit(-1); } retVal = read(fd, data, sb.st_size); if (retVal< sb.st_size){ printf("read32read32: retVal < N, fd = %d ,retVal = %d\n", fd, retVal); return -1; } fbdev = open("/dev/graphics/fb0", O_RDWR); if ( fbdev< 0) { printf("Failed to open:fb"); exit(-1); } if (ioctl(fbdev, FBIOGET_VSCREENINFO,&info) == -1){ printf("FBIOGET_VSCREENINFO error\n"); exit(-1); } printf("yres = %d\n", info.yres); printf("xres = %d\n", info.xres); printf("yres_virtual = %d\n", info.yres_virtual); printf("xres_virtual = %d\n", info.xres_virtual); /* RGB16 */ vram = (unsignedshort *)mmap(NULL, info.xres_virtual* info.yres_virtual* 2, PROT_READ | PROT_WRITE, MAP_SHARED, fbdev,0); if(vram == MAP_FAILED){ printf("mmap OVERLAY2 error!\n"); goto out; } /*Clear the framebuffer, nor the screen*/ for(i = 0; i < info.yres_virtual; i++){ for(j = 0; j < info.xres_virtual; j++){ vram[i*info.xres_virtual+ j] = 0xFFFF; } } pdata = (unsignedshort *)data; xindex = 0; yindex = 0; for(i = 0; i < info.yres; i++){ xindex = 0; for(j = 0; j < info.xres; j++){ vram[i*info.xres+j] = pdata[i*info.xres+ j]; xindex++; if(xindex>= PIC_WIDTH) break; } yindex++; if (yindex>= PIC_HEIGHT) break; } info.yoffset = 0; info.activate = FB_ACTIVATE_VBL; ioctl(fbdev,FBIOPUT_VSCREENINFO,&info);/*control the first frame buffer*/ bzero(cmd,sizeof(cmd)); switch (choose){ case 1: cmd[0] = WF_MODE_DU; break; case 2: cmd[0] = WF_MODE_GC16; break; case 3: cmd[0] = WF_MODE_GC4; break; default: printf("%s:input mode error! choose = %d\n",__func__, choose); } cmd[1] = 0; cmd[2] = 0; switch (update_mode){ case 1: //UPD_FULL ioctl(fbdev,S1D13521_UPD_FULL, cmd); break; case 2://UPD_PART ioctl(fbdev,S1D13521_UPD_PART, cmd); break; case 3://UPD_FULL_AREA cmd[3] = 20; /*x*/ cmd[4] = 20; /*y*/ cmd[5] = 200;/*width*/ cmd[6] = 200;/*height*/ ioctl(fbdev,S1D13521_UPD_FULL_AREA, cmd); break; case 4: cmd[3] = 100;/*x*/ cmd[4] = 300;/*y*/ cmd[5] = 400;/*width*/ cmd[6] = 100;/*height*/ ioctl(fbdev,S1D13521_UPD_PART_AREA, cmd); break; case 5: for (i = 0; i < 600; i++){ cmd[3] = i + 50; cmd[4] = 300; cmd[5] = 10; cmd[6] = 10; usleep(1000* 10); ioctl(fbdev,S1D13521_UPD_PART_AREA, cmd); } break; default: for(i = 0; i < info.yres_virtual; i++){ for(j = 0; j < info.xres_virtual; j++){ vram[i*info.xres_virtual+ j] = 0xFFFF; } } cmd[0] = WF_MODE_GC16; cmd[1] = 0; cmd[2] = 0; ioctl(fbdev,S1D13521_UPD_FULL, cmd); printf("%s: input update_mode error! clear screen !\n",__func__); } void showbar(char*cmd) { int i = 0; for (i = 0; i < 600; i++){ cmd[3] = i + 10; cmd[4] = 300; cmd[5] = 10; cmd[6] = 10; usleep(1000* 10); } } out: munmap(vram, info.xres_virtual* info.yres_virtual* 2); close(fbdev); close(fd); free(data); printf("end\n"); } |