搜索
bottom↓
回复: 7

百为LPC1788开发板framebuffer测试程序

[复制链接]

出0入0汤圆

发表于 2013-11-21 13:06:52 | 显示全部楼层 |阅读模式
复制代码到目录下
root@xiliang-desktop:/home/bw-1788/framebuffer# cp /mnt/hgfs/share/framebuffer.c .

编译
root@xiliang-desktop:/home/bw-1788/framebuffer# /home/lpc1788/linux-cortexm-1.4.1/tools/arm-2010q1/bin/arm-uclinuxeabi-gcc -Os -mcpu=cortex-m3 -mthumb -o framebuffer framebuffer.c

把可执行文件复制到根文件系统下
root@xiliang-desktop:/home/bw-1788/framebuffer# cp framebuffer /home/bw-1788/rootfs/

在开发板上执行程序
# ./framebuffer

程序源码:
/* framebuffer.c */
  1.     #include <unistd.h>
  2.     #include <stdio.h>
  3.     #include <fcntl.h>
  4.     #include <linux/fb.h>
  5.     #include <sys/mman.h>

  6.     int main()
  7.     {
  8.         int fbfd = 0;
  9.         struct fb_var_screeninfo vinfo;
  10.         struct fb_fix_screeninfo finfo;
  11.         long int screensize = 0;
  12.         char *fbp = 0;
  13.         int x = 0, y = 0;
  14.         long int location = 0;

  15.         // Open the file for reading and writing
  16.         fbfd = open("/dev/fb0", O_RDWR);
  17.         if (!fbfd) {
  18.             printf("Error: cannot open framebuffer device.\n");
  19.             exit(1);
  20.         }
  21.         printf("The framebuffer device was opened successfully.\n");

  22.         // Get fixed screen information
  23.         if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
  24.             printf("Error reading fixed information.\n");
  25.             exit(2);
  26.         }

  27.         // Get variable screen information
  28.         if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
  29.             printf("Error reading variable information.\n");
  30.             exit(3);
  31.         }

  32.         printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);

  33.         // Figure out the size of the screen in bytes
  34.         screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;

  35.         // Map the device to memory
  36.         fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,
  37.                            fbfd, 0);
  38.         if ((int)fbp == -1) {
  39.             printf("Error: failed to map framebuffer device to memory.\n");
  40.             exit(4);
  41.         }
  42.         printf("The framebuffer device was mapped to memory successfully.\n");

  43.         x = 100; y = 100;       // Where we are going to put the pixel

  44.         // Figure out where in memory to put the pixel
  45.         for (y = 100; y < 300; y++)
  46.             for (x = 100; x < 300; x++) {

  47.                 location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
  48.                            (y+vinfo.yoffset) * finfo.line_length;

  49.                 if (vinfo.bits_per_pixel == 32) {
  50.                     *(fbp + location) = 100;        // Some blue
  51.                     *(fbp + location + 1) = 15+(x-100)/2;     // A little green
  52.                     *(fbp + location + 2) = 200-(y-100)/5;    // A lot of red
  53.                     *(fbp + location + 3) = 0;      // No transparency
  54.                 } else  { //assume 16bpp
  55.                     int b = 10;
  56.                     int g = (x-100)/6;     // A little green
  57.                     int r = 31-(y-100)/16;    // A lot of red
  58.                     unsigned short int t = r<<11 | g << 5 | b;
  59.                     *((unsigned short int*)(fbp + location)) = t;
  60.                 }

  61.             }
  62.         munmap(fbp, screensize);
  63.         close(fbfd);
  64.         return 0;
  65.     }
复制代码

阿莫论坛20周年了!感谢大家的支持与爱护!!

该献的血还是要献的。你不献他不献。难道让我去献? --- 出自坛友:lovejp1981

出0入0汤圆

发表于 2013-11-21 14:16:27 | 显示全部楼层
frame buffer 好高端,最好能科普下……

出0入0汤圆

 楼主| 发表于 2013-11-21 18:46:51 | 显示全部楼层
zenith1032 发表于 2013-11-21 14:16
frame buffer 好高端,最好能科普下……

其实就是在linux下测试LCD显示的一个程序。linux上的所有GUI都是从这里开始的,像QT,MINIGUI那些都是这样

出0入0汤圆

发表于 2013-11-22 10:02:07 | 显示全部楼层
framebuffer的详细介绍
http://bbs.chinaunix.net/thread-1932291-1-1.html

出0入0汤圆

 楼主| 发表于 2014-2-16 13:40:58 | 显示全部楼层
zuoyi001 发表于 2013-11-26 23:05
已经在LPC1788跑上linux了,厉害啊!

是没有MMU的linux,不过uclinux和linux的编程差别不太大,开发流程是一样的

出0入0汤圆

 楼主| 发表于 2014-6-6 12:22:10 | 显示全部楼层
科普一下,从linux2.6起,uclinux就已经合并到linux下面了,即nommu的linux

出0入0汤圆

 楼主| 发表于 2014-6-21 13:41:49 | 显示全部楼层
这个framebuffer程序其实就是linux上直接搬过来的,一行没改
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-9-1 18:14

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

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