Firefly开源社区

12
发表新贴

【技术分享】Lubuntu分辨率自适应

263

积分

22

威望

24

贡献

技术达人

Rank: 2

积分
263
QQ
发表于 2016-6-17 17:17:48     
本帖最后由 hongyin 于 2016-6-17 17:20 编辑

好久没发帖了,近期工作太忙,所以自适应(基于VGA)的整理迟迟没有更新,今天先来无事,所以把之前的研究成果拿出来供大家参考,如有问题,可以发我邮箱(iamphy@qq.com)进行交流,废话少说,谈正事。

首先,请先下载附件,该文件并非压缩包,下载后直接将后缀名改成.c即可,并将该文件cp到相应目录:kernel/drivers/video/rockchip/lcdc下,该文件修复了1440x900和1366x768两种分辨率的异常(兼容性有待考证),还有就是RGB颜色问题;准备工作做好之后,自行编译内核进行烧写;

然后,下面的代码便是自动适配分辨率的,这是一个单独的程序,需要各位网友自行cp进行编译,编译完成之后,只需要将执行路径添加到/etc/rc.local文件即可;若网友发现有问题,请邮件相互交流。

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4. #include <string.h>
  5. #include <unistd.h>
  6. #include <errno.h>
  7. #include <fcntl.h>
  8. #include <sys/ioctl.h>
  9. #include <linux/fb.h>

  10. #define NUM_BUFFERS                 2
  11. #define RK_FBIOSET_CLEAR_FB         0x4633

  12. #if 0
  13. #define DEBUG_P(format, ...) printf(format, ##__VA_ARGS__)
  14. #else
  15. #define DEBUG_P(format, ...)
  16. #endif

  17. int main(int argc, char *argv[])
  18. {
  19.         FILE *fp = fopen("/sys/class/graphics/fb0/screen_info", "r");
  20.         if(fp == NULL)
  21.         {
  22.                 perror("fopen err:");
  23.                 return -1;
  24.         }

  25.         int xres = 0;
  26.         int yres = 0;

  27.         char line1[64] = {0};
  28.         char line2[64] = {0};
  29.         fgets(line1, sizeof(line1), fp);
  30.         fgets(line2, sizeof(line2), fp);
  31.         sscanf(line1, "xres:%d\n", &xres);
  32.         sscanf(line2, "yres:%d\n", &yres);
  33.         fclose(fp);
  34.         DEBUG_P("read x:%d, y:%d\n", xres, yres);

  35.         int fd = open("/dev/fb0", O_RDWR, 0);
  36.         if (fd < 0)
  37.         {
  38.                 fprintf(stderr, "No fb devices found!\n");
  39.                 return -errno;
  40.         }

  41.         struct fb_fix_screeninfo finfo;
  42.         if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1)
  43.         {
  44.                 close(fd);
  45.                 return -errno;
  46.         }

  47.         struct fb_var_screeninfo info;
  48.         if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1)
  49.         {
  50.                 close(fd);
  51.                 return -errno;
  52.         }

  53.         info.reserved[0] = 0;
  54.         info.reserved[1] = 0;
  55.         info.reserved[2] = 0;
  56.         info.xoffset = 0;
  57.         info.yoffset = 0;
  58.         info.width = xres;
  59.         info.height = yres;
  60.         info.xres = xres;
  61.         info.yres = yres;
  62.         info.xres_virtual = info.xres;
  63.         info.yres_virtual = info.yres * NUM_BUFFERS;
  64.         info.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;

  65.         info.bits_per_pixel = 32;
  66.         info.red.offset     = 16;
  67.         info.red.length     = 8;
  68.         info.green.offset   = 8;
  69.         info.green.length   = 8;
  70.         info.blue.offset    = 0;
  71.         info.blue.length    = 8;
  72.         info.transp.offset  = 0;
  73.         info.transp.length  = 0;
  74.         info.grayscale            &= 0xff;
  75.         info.grayscale            |= (info.xres<<8) + (info.yres<<20);
  76.         info.nonstd             &= 0xffffff00;
  77.         info.nonstd             |= 2;//HAL_PIXEL_FORMAT_RGBX_8888;

  78.         ioctl(fd, RK_FBIOSET_CLEAR_FB, NULL);

  79.         if (ioctl(fd, FBIOPUT_VSCREENINFO, &info) == -1)
  80.         {
  81.                 perror("FBIOPUT_VSCREENINFO failed");
  82.                 close(fd);
  83.                 return -errno;
  84.         }

  85.         if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1)
  86.         {
  87.                 fprintf(stderr, "FBIOGET_VSCREENINFO failed.\n");
  88.                 close(fd);
  89.                 return -errno;
  90.         }

  91.         int refreshRate = 0;
  92.         if ( info.pixclock > 0 )
  93.         {
  94.                 refreshRate = 1000000000000000LLU / ((uint64_t)
  95.                         (info.upper_margin + info.lower_margin + info.yres + info.hsync_len ) *
  96.                         (info.left_margin  + info.right_margin + info.xres + info.vsync_len ) *
  97.                         info.pixclock);

  98.                 if (refreshRate == 0)
  99.                 {
  100.                         refreshRate = 60*1000;  // 60 Hz
  101.                 }
  102.         }

  103.         if ((int)(info.width) <= 0 || (int)(info.height) <= 0)
  104.         {
  105.                 // the driver doesn't return that information
  106.                 // default to 160 dpi
  107.                 info.width  = ((info.xres * 25.4f)/160.0f + 0.5f);
  108.                 info.height = ((info.yres * 25.4f)/160.0f + 0.5f);
  109.         }

  110.         float xdpi = (info.xres * 25.4f) / info.width;
  111.         float ydpi = (info.yres * 25.4f) / info.height;
  112.         float fps  = refreshRate / 1000.0f;

  113.         DEBUG_P("using (fd=%d)\n"
  114.              "id           = %s\n"
  115.              "xres         = %d px\n"
  116.              "yres         = %d px\n"
  117.              "xres_virtual = %d px\n"
  118.              "yres_virtual = %d px\n"
  119.              "bpp          = %d\n"
  120.              "r            = %2u:%u\n"
  121.              "g            = %2u:%u\n"
  122.              "b            = %2u:%u\n"
  123.              "format       = %d\n",
  124.              fd,
  125.              finfo.id,
  126.              info.xres,
  127.              info.yres,
  128.              info.xres_virtual,
  129.              info.yres_virtual,
  130.              info.bits_per_pixel,
  131.              info.red.offset, info.red.length,
  132.              info.green.offset, info.green.length,
  133.              info.blue.offset, info.blue.length,
  134.              info.nonstd);

  135.         DEBUG_P("width      = %d mm (%f dpi)\n"
  136.              "height       = %d mm (%f dpi)\n"
  137.              "refresh rate = %.2f Hz\n",
  138.              info.width,  xdpi,
  139.              info.height, ydpi,
  140.              fps);

  141.         int videodata[2];
  142.         videodata[1] = videodata[0] = finfo.smem_start;
  143.         ioctl(fd, 0x5002, videodata);

  144.         close(fd);
  145.         return 0;
  146. }
复制代码


rk3288_lcdc.tar

113.08 KB, 下载次数: 102, 下载积分: 灯泡 -1 , 经验 -1

回复

使用道具 举报

24

积分

0

威望

0

贡献

技术小白

积分
24
发表于 2016-6-21 10:37:13     
文件已经损坏了,可以重新上传吗,谢谢
回复

使用道具 举报

69

积分

0

威望

0

贡献

游客

积分
69
发表于 2016-6-22 10:53:34     
牛人,赞一个
回复

使用道具 举报

263

积分

22

威望

24

贡献

技术达人

Rank: 2

积分
263
QQ
发表于 2016-6-22 15:09:40     
blackholeII 发表于 2016-6-21 10:37
文件已经损坏了,可以重新上传吗,谢谢

附件并非压缩包,你下载后将后缀名改成.c就可以直接使用了
回复

使用道具 举报

发表于 2016-6-22 22:59:22     
好贴,已设置精华
暴走的创客!
回复

使用道具 举报

166

积分

0

威望

0

贡献

技术小白

积分
166
发表于 2016-9-22 15:08:47     
只能基于VGA?
回复

使用道具 举报

166

积分

0

威望

0

贡献

技术小白

积分
166
发表于 2016-9-22 15:38:42     
这个显示的问题可以帮忙看一下吗?
http://developer.t-firefly.com/thread-10933-1-1.html
回复

使用道具 举报

59

积分

0

威望

0

贡献

游客

积分
59
发表于 2016-10-13 19:44:11     
顶大神!!!!11
回复

使用道具 举报

13

积分

0

威望

0

贡献

游客

积分
13
发表于 2016-12-13 21:03:07     
这个帖子真是精华
回复

使用道具 举报

116

积分

0

威望

0

贡献

技术小白

积分
116
发表于 2017-7-19 22:50:51     
强烈的感谢楼主!这个帖子真是精华
回复

使用道具 举报

返回列表
12
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

友情链接 : 爱板网 电子发烧友论坛 云汉电子社区 粤ICP备14022046号-2
快速回复 返回顶部 返回列表