Linxu S3C2440 LCD驱动 测试程序

2024-06-13  

主机:VM - RedHat 9.0

开发板:FL2440,linux-2.6.12

arm-linux-gcc:3.4.1

对应的LCD设备驱动参见:http://www.linuxidc.com/Linux/2011-09/42076.htm

  1. #include    

  2. #include    

  3. #include    

  4. #include    

  5. #include    

  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 = %dn", 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 framebuffern");  

  59.   

  60.         // Red Screen   

  61.         printf("Red Screenn");  

  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 Screenn");  

  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 Screenn");  

  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 16n");  

  94.     }  

  95.   

  96.     munmap(fbp565, screen_size);  

  97.     close(fd_fb);  

  98.     return 0;  

  99. }  



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


文章来源于:电子工程世界    原文链接
本站所有转载文章系出于传递更多信息之目的,且明确注明来源,不希望被转载的媒体或个人可与我们联系,我们将立即进行删除处理。