Linux framebuffer的框架非常简单, 对于应用程序就是操作一块内存(俗称帧缓存), 当然也有可能是双缓存, 一般用于高帧率场景, 一块帧在填充数据时, 另一块在显示, 接着对调过来,

那通过设置哪里告知驱动层读取哪块帧数据呢? 答案是用vinfo.xoffset, vinfo.yoffset

  需要注意的是, 无论用write()、还是mmap()后直接操作内存都只是填充内存而已, 并不代表能够立马显示, 这得看驱动, 如果驱动实现了自刷新(不断从帧缓存拿数据刷到LCD上), 那填充数据到帧缓存就会立马显示出来,

如果驱动没有实现,那应用程序需要主动的调用 ioctl(fp, FBIOPAN_DISPLAY, &vinfo);, 告知驱动可以刷数据了, 如果这都没显示出来, 估计驱动没实现FBIOPAN_DISPLAY功能。

示例代码:(驱动实现自刷新, 应用依次显示黄、蓝、红,最后画线)

#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <string.h> #define RED 0xF800
#define YELLOW 0xFFE0
#define BLUE 0x001F
#define WHITE 0xFFFF
#define BLACK 0x0000 void fill_color16(short *fb_addr, short bit_map, int psize)
{
int i;
for(i=; i<psize; i++) {
*fb_addr = bit_map;
fb_addr++;
}
} int main ()
{
int fp=;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
long screensize=;
char *fbp = NULL, *test_fbp=NULL;
int x = , y = ;
long location = ;
int i;
int num = ;
int pix_size=; fp = open("/dev/graphics/fb0", O_RDWR); if(fp < ) {
printf("Error : Can not open framebuffer device/n");
exit();
} if(ioctl(fp, FBIOGET_FSCREENINFO, &finfo)){
printf("Error reading fixed information/n");
exit();
} if(ioctl(fp, FBIOGET_VSCREENINFO, &vinfo)){
printf("Error reading variable information/n");
exit();
} screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / ; printf("The phy mem = 0x%x, total size = %d(byte)\n", finfo.smem_start, finfo.smem_len);
printf("xres = %d, yres = %d, bits_per_pixel = %d\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
printf("So the screensize = %d(byte), using %d frame\n", screensize, finfo.smem_len/screensize);
printf("vinfo.xoffset = %d, vinfo.yoffset = %d\n", vinfo.xoffset, vinfo.yoffset);
printf("vinfo.vmode is :%d\n", vinfo.vmode);
printf("finfo.ypanstep is :%d\n", finfo.ypanstep);
printf("vinfo.red.offset=0x%x\n", vinfo.red.offset);
printf("vinfo.red.length=0x%x\n", vinfo.red.length);
printf("vinfo.green.offset=0x%x\n", vinfo.green.offset);
printf("vinfo.green.length=0x%x\n", vinfo.green.length);
printf("vinfo.blue.offset=0x%x\n", vinfo.blue.offset);
printf("vinfo.blue.length=0x%x\n", vinfo.blue.length);
printf("vinfo.transp.offset=0x%x\n", vinfo.transp.offset);
printf("vinfo.transp.length=0x%x\n", vinfo.transp.length); fbp =(char *)mmap(, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fp,);
if ((int)fbp == -)
{
printf ("Error: failed to map framebuffer device to memory./n");
exit ();
}
printf("Get virt mem = %p\n", fbp); pix_size = vinfo.xres * vinfo.yres;
/* using first frame, for FBIOPAN_DISPLAY
* 当刷新需要调用FBIOPAN_DISPLAY, 要告知驱动刷哪块帧, 用到下面两个参数
* 如果使用第二帧buffer -> vinfo.xoffset = 0; vinfo.yoffset = vinfo.yres;
*/
vinfo.xoffset = ;
vinfo.yoffset = ; /* show color loop */
while(num--) {
printf("\ndrawing YELLOW......\n");
fill_color16((short *)fbp, YELLOW, pix_size);
//ioctl(fp, FBIOPAN_DISPLAY, &vinfo);
sleep(); printf("\ndrawing BLUE......\n");
fill_color16((short *)fbp, BLUE, pix_size);
//ioctl(fp, FBIOPAN_DISPLAY, &vinfo);
sleep(); printf("\ndrawing RED......\n");
fill_color16((short *)fbp, RED, pix_size);
//ioctl(fp, FBIOPAN_DISPLAY, &vinfo);
sleep();
}
#if 1
/*这是你想画的点的位置坐标,(0,0)点在屏幕左上角*/
x = ;
y = ;
location = x * (vinfo.bits_per_pixel / ) + y * finfo.line_length;
test_fbp = fbp + location;
printf("draw line.......\n");
for(i = ; i < (vinfo.xres - x); i++)
*test_fbp++ = i+; //ioctl(fp, FBIOPAN_DISPLAY, &vinfo);
#endif munmap(fbp, screensize); /*解除映射*/ close (fp);
return ;
}

当然用read()/write(), 也可以, 就是效率非常低, 太多系统调用导致系统在用户态和kernel态切换, 而且每次还传输一个字节, 但作为例子可以参考一下:

#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <string.h> #define RED 0xF800
#define YELLOW 0xFFE0
#define BLUE 0x001F
#define WHITE 0xFFFF
#define BLACK 0x0000 int main ()
{
int fp=;
struct fb_var_screeninfo vinfo;
int i;
int pix_size=;
unsigned char color1, color2; fp = open("/dev/graphics/fb0", O_RDWR); if(fp < ) {
printf("Error : Can not open framebuffer device/n");
exit();
} if(ioctl(fp, FBIOGET_VSCREENINFO, &vinfo)){
printf("Error reading variable information/n");
exit();
} pix_size = vinfo.xres * vinfo.yres;
color1 = ;
color2 = 0xf8;
for(i=; i<pix_size; i++) {
write(fp, &color1, );
write(fp, &color2, );
} close (fp);
return ;
}

Linux framebuffer测试程序的更多相关文章

  1. Linux Framebuffer驱动剖析之一—软件需求

    嵌入式企鹅圈将以本文作为2015年的终结篇,以回应第一篇<Linux字符设备驱动剖析>.嵌入式企鹅圈一直专注于嵌入式Linux和物联网IOT两方面的原创技术分享,稍后会发布嵌入式企鹅圈的2 ...

  2. Linux Framebuffer save as picture

    /********************************************************************************* * Linux Framebuff ...

  3. Linux Framebuffer驱动剖析之中的一个—软件需求

    嵌入式企鹅圈将以本文作为2015年的终结篇,以回应第一篇<Linux字符设备驱动剖析>.嵌入式企鹅圈一直专注于嵌入式Linux和物联网IOT双方面的原创技术分享,稍后会公布嵌入式企鹅圈的2 ...

  4. Linux Framebuffer驱动框架之二软件架构(未完待续)【转】

    本文转载自:http://blog.csdn.net/gqb_driver/article/details/12918547 /************************************ ...

  5. Linux Framebuffer 驱动框架之一概念介绍及LCD硬件原理【转】

    本文转载自:http://blog.csdn.net/liuxd3000/article/details/17464779 一.基本概念 帧缓冲(Framebuffer)是Linux系统为显示设备提供 ...

  6. framebuffer测试程序

    /* framebuffer简单测试程序 网上转载 很多次 的程序 :-) */ #include <stdio.h> #include <stdlib.h> #include ...

  7. 【转】Linux Framebuffer

    全面的framebuffer详解 一.FrameBuffer的原理 FrameBuffer 是出现在 2.2.xx 内核当中的一种驱动程序接口. Linux是工作在保护模式下,所以用户态进程是无法象D ...

  8. Linux Framebuffer驱动剖析之二—驱动框架、接口实现和使用

    深入分析LinuxFramebuffer子系统的驱动框架.接口实现和使用. 一.LinuxFramebuffer的软件需求 上一篇文章详细阐述了LinuxFramebuffer的软件需求(请先理解第一 ...

  9. Linux framebuffer显示bmp图片【转】

    本文转载自:http://blog.csdn.net/luxiaoxun/article/details/7622988 framebuffer简介 帧缓冲(framebuffer)是Linux为显示 ...

随机推荐

  1. kmspico_setup.exe运行提示系统资源不足,无法完成请求的服务

    在使用KMSpico激活office时,windows下运行exe会提示系统资源不足,无法完成请求的服务. 我的解决方法是:卸载电脑上的wps...

  2. java 基础知识小结

    1. java 有三个求整的函数 math.floor ()  (floor 是地板的意思)  向下求整 math.ceil ()  (ceil 是天花板的意思 ) 向上求整 math.round() ...

  3. 基于SpringBoot从零构建博客网站 - 技术选型和整合开发环境

    技术选型和整合开发环境 1.技术选型 博客网站是基于SpringBoot整合其它模块而开发的,那么每个模块选择的技术如下: SpringBoot版本选择目前较新的2.1.1.RELEASE版本 持久化 ...

  4. ConcurrentDictionary并发字典知多少?

    背景 在上一篇文章你真的了解字典吗?一文中我介绍了Hash Function和字典的工作的基本原理. 有网友在文章底部评论,说我的Remove和Add方法没有考虑线程安全问题. https://doc ...

  5. 实例分析Vue.js中 computed和methods不同机制

    在vue.js中,有methods和computed两种方式来动态当作方法来用的 1.首先最明显的不同 就是调用的时候,methods要加上() 2.我们可以使用 methods 来替代 comput ...

  6. Android研发进阶之路

    前言 移动研发火热不停,越来越多人开始学习android开发.但很多人感觉入门容易成长很难,对未来比较迷茫,不知道自己技能该怎么提升,到达下一阶段需要补充哪些内容.市面上也多是谈论知识图谱,缺少体系和 ...

  7. ArcGIS JS 3.x使用webgl绘制热力图

        ArcGIS Js Api 3.x 热力图在数据量达到三万左右的时候,绘制速度不尽人意,数据量再大些,缩放时候就会很卡,非常影响客户体验.     参考了一下网上webgl热力图,能达到更流畅 ...

  8. Flutter 即学即用系列博客——07 RenderFlex overflowed 引发的思考

    背景 在进行 Flutter UI 开发的时候,控制台报出了下面错误: flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY >╞════════ ...

  9. 小程序后端项目【Springboot框架】部署到阿里云服务器【支持https访问】

    前言: 我的后端项目是Java写的,用的Springboot框架.在部署服务器并配置https访问过程中,因为做了一些令人窒息的操作(事后发现),所以老是不能成功. 不成功具体点说就是:域名地址可以正 ...

  10. PyCharm 如何远程连接服务器编写程序

    写在前面 我之前一直通过mstsc远程服务器桌面修改代码,或者本地修改后上传到远程服务器等,各种不爽,现在改用xshell,但有时候还是感觉不方便.于是乎,自己动手配置PyCharm远程连接服务器,这 ...