天嵌 ARM开发社区

 找回密码
 注册
查看: 2241|回复: 1

LCD测试程序求解惑

[复制链接]
wang12zhedi 发表于 2012-12-17 09:00:32 | 显示全部楼层 |阅读模式
本帖最后由 wang12zhedi 于 2012-12-17 09:07 编辑

程序如下
    #include <unistd.h>
      #include <stdlib.h>
      #include <stdio.h>
    #include <fcntl.h>
    #include <linux/fb.h>
    #include <sys/mman.h>


        int main()
            {
             int fd,x=0,y=0,i=0;
                 unsigned long screensize;//这里需要定义成long 应为480*272已经非常大了
                 char *fbp=0;
                 struct fb_var_screeninfo varinfo;
                 fd=open("/dev/fb0",O_RDWR);
                 if(!fd)
                    {
                    printf("open /dev/fb0 fail \n");
                     exit(1);
                         }
                 if(ioctl(fd,FBIOGET_VSCREENINFO,&varinfo))
                         {
                           
                             printf("ERROR canot get var info");
                                exit(1);
                           
                         }
                 printf("varinfo.xres=%d \n",varinfo.xres);
                 printf("varinfo.yres=%d \n",varinfo.yres);
                 printf("varinfo.bits_per_pixel=%d \n",varinfo.bits_per_pixel);        
                 if(varinfo.bits_per_pixel!=16)
                        
                                {
                printf("Error: not supported bits_per_pixel, it only supports 16 bit color\n");
                exit(1);
               }
         screensize=varinfo.yres*varinfo.xres*varinfo.bits_per_pixel/8;
                        fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,
         fd, 0);//返回的fbp是显示缓冲区的开始地址  ?
       if ((int)fbp == -1)
                   {
          printf("Error: failed to map framebuffer device to memory.\n");
                  exit(1);
                 }
           printf("The framebuffer device was mapped to memory successfully.\n");



  for (i = 0; i < 3; i++) {
            for (y = i * (varinfo.yres / 3); y < (i + 1) * (varinfo.yres / 3); y++) {
                                for (x = 0; x < varinfo.xres; x++) {
                                        long location = x * varinfo.bits_per_pixel/8 + y *  varinfo.xres * varinfo.bits_per_pixel/8;
                                        int r = 0, g = 0, b = 0;
                                        unsigned short rgb;
                                       
                                                if (i == 0)
                                        // 实现位置与显示颜色挂钩,0<=r<=32
                                            r = ((x * 1.0) / varinfo.xres) * 32;//R G B 5 6 5     所以除以 32  64  32
                                           // r=155;
                                            if (i == 1)
                                            g = ((x * 1.0) / varinfo.xres) * 255;
                                                
                                          if (i == 2)
                                              b = ((x * 1.0) / varinfo.xres) * 32;
                        
                                                rgb = (r << 11) | (g << 5) | b;
                                                *((unsigned short*)(fbp + location)) = rgb;
                                        }
                    }
              }
          munmap(fbp, screensize);
          close(fd);
                  return 0;
                  


        }

程序排列很工整有序的,咋一复制粘贴过来就成这样啦 请原谅


我的问题是
// 实现位置与显示颜色挂钩,0<=r<=32
                                            r = ((x * 1.0) / varinfo.xres) * 32;//R G B 5 6 5     所以除以 32  64  32
                                           // r=155
这里为什么是乘以32,难道真是因为rgb=5:6:5吗?
这样r的范围只有0到32吧,但是当我给r赋值为255  155之类的也显示深浅不同的红颜色呀

embedsky_lhh 发表于 2012-12-17 12:05:48 | 显示全部楼层
你要看清楚这个程序的功能,这个是把LCD上对应的点的位置和这个点的像素联系起来,他只是这样测试而已,
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号 )

GMT+8, 2024-5-5 11:42 , Processed in 1.046875 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表