framebuffer操作初识

#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <string.h>

#define FrameBufferDriverName "/dev/fb0" 

void fb_memclear (void *addr, int c, size_t len) 
{ 
    memset(addr, c, len); 
} 

int main () 
{
	 int fp=0;
	 struct fb_var_screeninfo vinfo;
	 struct fb_fix_screeninfo finfo;
	 long screensize1,screensize2;
	 char* fbp = 0;
	 int index = 0;
	 fp = open (FrameBufferDriverName,O_RDWR);


	 if (fp < 0)
	 {
		printf("Error : Can not open framebuffer device/n");
		exit(1);
	 }


	 if (ioctl(fp,FBIOGET_FSCREENINFO,&finfo))
	 {
		  printf("Error reading fixed information/n");
		  exit(2);
	 }
 
	 if (ioctl(fp,FBIOGET_VSCREENINFO,&vinfo))
	 {
		  printf("Error reading variable information/n");
		  exit(3);
	 }
	screensize2 = vinfo.yres_virtual * finfo.line_length;
	screensize1 = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; /*字节数*/

	/*这就是把fp所指的文件中从开始到screensize大小的内容给映射出来,得到一个指向这块空间的指针*/
	fbp =(char *) mmap (0, finfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fp,0);
	if ((long int)fbp == -1)
     {
        printf ("Error: failed to map framebuffer device to memory./n");
        exit (4);
     }
	 while(1)
	 { 
		 sleep(1);
		 if(index > 65535){
			 index == 0;
		 } 
	/*
		 printf("vinfo.xres value is %d\n",vinfo.xres);
		 printf("vinfo.yres value is %d\n",vinfo.yres);
		 printf("finfo.line_length value is %d\n",finfo.line_length);
		 printf("vinfo.bits_per_pixel value is %d\n",vinfo.bits_per_pixel);
		 printf("vinfo.yres_virtual value is %d\n",vinfo.yres_virtual);
		 printf("screensize1 value is %d\n",screensize1);
		 printf("screensize2 value is %d\n",screensize2);
		 printf("finfo.smem_len value is %d\n",finfo.smem_len);
		 printf("index value is %d\n",index);
	*/
		 //showImage(fbp,vinfo.xres,vinfo.yres,vinfo.bits_per_pixel);
		 fb_memclear((void *)fbp,index,finfo.smem_len);
		 index += 50;
	 }
	
	munmap ((void *)fbp,finfo.smem_len); /*解除映射*/
	close (fp);    /*关闭文件*/
	return 0;
  
}

    附上操作fb的两个主要结构体成员:(详情见<linux/fb.h>)

#if 0
struct fb_fix_screeninfo {
	char id[16]; /* identification string eg "TT Builtin" */ID
	unsigned long smem_start; /* Start of frame buffer mem */ 内存起始
	/* (physical address) */ 物理地址
	__u32 smem_len; /* Length of frame buffer mem */ 内存大小
	__u32 type; /* see FB_TYPE_* */ 
	__u32 type_aux; /* Interleave for interleaved Planes */插入区域
	__u32 visual; /* see FB_VISUAL_* */
	__u16 xpanstep; /* zero if no hardware panning */没有硬件设备就为零
	__u16 ypanstep; /* zero if no hardware panning */
	__u16 ywrapstep; /* zero if no hardware ywrap */
	__u32 line_length; /* length of a line in bytes */ 一行的字节表示
	unsigned long mmio_start; /* Start of Memory Mapped I/O */内存映射的I/O起始
	/* (physical address) */ 
	__u32 mmio_len; /* Length of Memory Mapped I/O */ I/O的大小
	__u32 accel; /* Type of acceleration available */ 可用的加速类型
	__u16 reserved[3]; /* Reserved for future compatibility */
};

struct fb_var_screeninfo
{
__u32 xres; /* visible resolution */   //可视区域
__u32 yres;
__u32 xres_virtual; /* virtual resolution */  //可视区域
__u32 yres_virtual;
__u32 xoffset; /* offset from virtual to visible resolution */ //可视区域的偏移
__u32 yoffset;

__u32 bits_per_pixel; /* guess what */  //每一象素的bit数
__u32 grayscale; /* != 0 Gray levels instead of colors *///等于零就成黑白

struct fb_bitfield red; /* bitfield in fb mem if true color, */真彩的bit机构
struct fb_bitfield green; /* else only length is significant */
struct fb_bitfield blue;   
struct fb_bitfield transp; /* transparency */  透明

__u32 nonstd; /* != 0 Non standard pixel format */ 不是标准格式

__u32 activate; /* see FB_ACTIVATE_* */

__u32 height; /* height of picture in mm */ 内存中的图像高度
__u32 width; /* width of picture in mm */ 内存中的图像宽度

__u32 accel_flags; /* acceleration flags (hints) */ 加速标志

/* Timing: All values in pixclocks, except pixclock (of course) */

时序-_-这些部分就是显示器的显示方法了,可以找相关的资料看看
__u32 pixclock; /* pixel clock in ps (pico seconds) */
__u32 left_margin; /* time from sync to picture */
__u32 right_margin; /* time from picture to sync */
__u32 upper_margin; /* time from sync to picture */
__u32 lower_margin;
__u32 hsync_len; /* length of horizontal sync */  水平可视区域
__u32 vsync_len; /* length of vertical sync */   垂直可视区域
__u32 sync; /* see FB_SYNC_* */
__u32 vmode; /* see FB_VMODE_* */
__u32 reserved[6]; /* Reserved for future compatibility */ 备用-以后开发
};
#endif



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值