Linxu S3C2440 LCD驱动 测试程序

mingmingini 2011-09-02

主机:VM - RedHat 9.0

开发板:FL2440,linux-2.6.12

arm-linux-gcc:3.4.1

  1. #include <unistd.h>   
  2. #include <stdio.h>   
  3. #include <fcntl.h>   
  4. #include <linux/fb.h>   
  5. #include <sys/mman.h>   
  6.   
  7. #define RED_COLOR565    0x0F100   
  8. #define GREEN_COLOR565  0x007E0   
  9. #define BLUE_COLOR565   0x0001F   
  10.   
  11. int main(void)  
  12. {  
  13.     int fd_fb = 0;  
  14.     struct fb_var_screeninfo vinfo;  
  15.     struct fb_fix_screeninfo finfo;  
  16.     long int screen_size = 0;  
  17.     short *fbp565 = NULL;  
  18.   
  19.     int x = 0, y = 0;  
  20.   
  21.     fd_fb = open("/dev/fb0", O_RDWR);  
  22.     if (!fd_fb)  
  23.     {  
  24.         printf("Error: cannot open framebuffer device.\n");  
  25.         exit(1);  
  26.     }  
  27.   
  28.     // Get fixed screen info   
  29.     if (ioctl(fd_fb, FBIOGET_FSCREENINFO, &finfo))  
  30.     {  
  31.         printf("Error reading fixed information.\n");  
  32.         exit(2);  
  33.     }  
  34.   
  35.     // Get variable screen info   
  36.     if (ioctl(fd_fb, FBIOGET_VSCREENINFO, &vinfo))  
  37.     {  
  38.         printf("Error reading variable information.\n");  
  39.         exit(3);  
  40.     }  
  41.   
  42.     // the size of the screen in bytes   
  43.     screen_size = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;  
  44.   
  45.     printf("%dx%d, %dbpp, screen_size = %d\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel, screen_size );  
  46.   
  47.     // map framebuffer to user memory   
  48.     fbp565 = (short *)mmap(0, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_fb, 0);  
  49.   
  50.     if ((int)fbp565 == -1)  
  51.     {  
  52.         printf("Error: failed to map framebuffer device to memory.\n");  
  53.         exit(4);  
  54.     }  
  55.   
  56.     if(vinfo.bits_per_pixel == 16)  
  57.     {  
  58.         printf("16 bpp framebuffer\n");  
  59.   
  60.         // Red Screen   
  61.         printf("Red Screen\n");  
  62.         for(y = 0; y < vinfo.yres/3;  y++)  
  63.         {  
  64.             for(x = 0; x < vinfo.xres ; x++)  
  65.             {  
  66.                 *(fbp565 + y * vinfo.xres + x) = RED_COLOR565;  
  67.             }  
  68.         }  
  69.   
  70.         // Green Screen   
  71.         printf("Green Screen\n");  
  72.         for(y = vinfo.yres/3; y < (vinfo.yres*2)/3; y++)  
  73.         {  
  74.             for(x = 0; x < vinfo.xres; x++)  
  75.             {  
  76.                 *(fbp565 + y * vinfo.xres + x) =GREEN_COLOR565;  
  77.             }  
  78.         }  
  79.   
  80.         // Blue Screen   
  81.         printf("Blue Screen\n");  
  82.         for(y = (vinfo.yres*2)/3; y < vinfo.yres; y++)  
  83.         {  
  84.             for(x = 0; x < vinfo.xres; x++)  
  85.             {  
  86.                 *(fbp565 + y * vinfo.xres + x) = BLUE_COLOR565;  
  87.             }  
  88.         }  
  89.     }  
  90.       
  91.     else  
  92.     {  
  93.         printf("warnning: bpp is not 16\n");  
  94.     }  
  95.   
  96.     munmap(fbp565, screen_size);  
  97.     close(fd_fb);  
  98.     return 0;  
  99. }  
#include <unistd.h>#include <stdio.h>#include <fcntl.h>#include <linux/fb.h>#include <sys/mman.h>#define RED_COLOR565 0x0F100#define GREEN_COLOR565 0x007E0#define BLUE_COLOR565 0x0001Fint main(void){ int fd_fb = 0; struct fb_var_screeninfo vinfo; struct fb_fix_screeninfo finfo; long int screen_size = 0; short *fbp565 = NULL; int x = 0, y = 0; fd_fb = open("/dev/fb0", O_RDWR); if (!fd_fb) { printf("Error: cannot open framebuffer device.\n"); exit(1); } // Get fixed screen info if (ioctl(fd_fb, FBIOGET_FSCREENINFO, &finfo)) { printf("Error reading fixed information.\n"); exit(2); } // Get variable screen info if (ioctl(fd_fb, FBIOGET_VSCREENINFO, &vinfo)) { printf("Error reading variable information.\n"); exit(3); } // the size of the screen in bytes screen_size = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; printf("%dx%d, %dbpp, screen_size = %d\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel, screen_size ); // map framebuffer to user memory fbp565 = (short *)mmap(0, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_fb, 0); if ((int)fbp565 == -1) { printf("Error: failed to map framebuffer device to memory.\n"); exit(4); } if(vinfo.bits_per_pixel == 16) { printf("16 bpp framebuffer\n"); // Red Screen printf("Red Screen\n"); for(y = 0; y < vinfo.yres/3; y++) { for(x = 0; x < vinfo.xres ; x++) { *(fbp565 + y * vinfo.xres + x) = RED_COLOR565; } } // Green Screen printf("Green Screen\n"); for(y = vinfo.yres/3; y < (vinfo.yres*2)/3; y++) { for(x = 0; x < vinfo.xres; x++) { *(fbp565 + y * vinfo.xres + x) =GREEN_COLOR565; } } // Blue Screen printf("Blue Screen\n"); for(y = (vinfo.yres*2)/3; y < vinfo.yres; y++) { for(x = 0; x < vinfo.xres; x++) { *(fbp565 + y * vinfo.xres + x) = BLUE_COLOR565; } } } else { printf("warnning: bpp is not 16\n"); } munmap(fbp565, screen_size); close(fd_fb); return 0;}

测试结果,由上往下颜色分别为红、绿、蓝,图像有色差。

Linxu S3C2440 LCD驱动 测试程序

相关推荐

ganyouxianjava / 0评论 2012-05-31