当前位置: 技术问答>linux和unix
大虾帮我看看有关frame buffer的源程序?
来源: 互联网 发布时间:2014-12-15
本文导语: #include #include #include #include #include #include #include /* for mmap function call */ #include int open_file(const char *pathname,mode_t mode) { int retval; retval=open(pathname,O_WRONLY,mode); if(retva...
#include
#include
#include
#include
#include
#include
#include /* for mmap function call */
#include
int open_file(const char *pathname,mode_t mode)
{
int retval;
retval=open(pathname,O_WRONLY,mode);
if(retval==-1)
{
printf("rn sorry,open file failurenr");
printf("rn the error numer is %4dnr",error);
return(-1);
}
else return(retval);
}
int copytomem(void)
{
unsigned char *fb_mem;
int fb;
fb=open_file("/dev/fb0",S_IRWXU);
if(fb)
{
fb_mem=mmap(NULL,1024*768,PROT_READ|PROT_WRITE,MAP_SHARED,fb,0);
if(!fb_mem)
{
printf("n copy to mem errorn"); return -1 ;
}
else
{
printf("rn set memory valuenr");
memset(fb_mem,0,1024*768);
}
}
return 1;
}
int main(void)
{
copytomem();
return 2;
}
//它老说打不开设备文件/dev/fb0,还有在memset后就会出现segmemtion fault,当我打开的是一般文件时,文件倒是能打开,不过还是有segmention fault.
#include
#include
#include
#include
#include
#include /* for mmap function call */
#include
int open_file(const char *pathname,mode_t mode)
{
int retval;
retval=open(pathname,O_WRONLY,mode);
if(retval==-1)
{
printf("rn sorry,open file failurenr");
printf("rn the error numer is %4dnr",error);
return(-1);
}
else return(retval);
}
int copytomem(void)
{
unsigned char *fb_mem;
int fb;
fb=open_file("/dev/fb0",S_IRWXU);
if(fb)
{
fb_mem=mmap(NULL,1024*768,PROT_READ|PROT_WRITE,MAP_SHARED,fb,0);
if(!fb_mem)
{
printf("n copy to mem errorn"); return -1 ;
}
else
{
printf("rn set memory valuenr");
memset(fb_mem,0,1024*768);
}
}
return 1;
}
int main(void)
{
copytomem();
return 2;
}
//它老说打不开设备文件/dev/fb0,还有在memset后就会出现segmemtion fault,当我打开的是一般文件时,文件倒是能打开,不过还是有segmention fault.
|
1.直接用opne打开不用参数mode
2。你的mmap返回可能是错误的,你的判断是错误的。因该干成
if (fb_mem == MAP_FAILED)
{
}
else
2。你的mmap返回可能是错误的,你的判断是错误的。因该干成
if (fb_mem == MAP_FAILED)
{
}
else
|
不是这样用D
#include
#include
#include
#include
#include
#include
#include /* for mmap function call */
#include
#include
#include
#include
int open_file(const char *pathname)
{
int retval;
retval=open(pathname,O_WRONLY);
if(retval==-1)
{
printf("rn sorry,open file failurenr");
printf("rn the error numer is %4dnr",error);
return(-1);
}
else return(retval);
}
int copytomem(void)
{
int fb;
unsigned long fb_mem_offset;
unsigned long fb_mem;
struct fb_fix_screeninfo fb_fix;
struct fb_var_screeninfo fb_var;
fb=open_file("/dev/fb0");
if(fb)
{
if( -1 == ioctl(fb, FBIOGET_FSCREENINFO, &fb_fix))
{
printf("get fb fix screen info error");
exit(-1);
}
if(-1 == ioctl(fb, FBIOGET_VSCREENINFO, &fb_var))
{
printf("get fb visual screen info error");
exit(-1);
}
fb_mem_offset = (unsigned long) fb_fix.smem_start & (~PAGE_MASK);
fb_mem = mmap(NULL, fb_fix.smem_len + fb_mem_offset, PROT_READ|PROT_WRITE, MAP_SHARED, fb, 0);
if(-1L == (long) fb_mem)
{
printf("mmap error to mem errorn"); return -1 ;
}
else
{
printf("rn set memory valuenr");
memset(fb_mem, 0, fb_var.yres * fb_fix.line_length);
}
}
return 1;
}
int main(void)
{
copytomem();
return 2;
}
#include
#include
#include
#include
#include
#include
#include /* for mmap function call */
#include
#include
#include
#include
int open_file(const char *pathname)
{
int retval;
retval=open(pathname,O_WRONLY);
if(retval==-1)
{
printf("rn sorry,open file failurenr");
printf("rn the error numer is %4dnr",error);
return(-1);
}
else return(retval);
}
int copytomem(void)
{
int fb;
unsigned long fb_mem_offset;
unsigned long fb_mem;
struct fb_fix_screeninfo fb_fix;
struct fb_var_screeninfo fb_var;
fb=open_file("/dev/fb0");
if(fb)
{
if( -1 == ioctl(fb, FBIOGET_FSCREENINFO, &fb_fix))
{
printf("get fb fix screen info error");
exit(-1);
}
if(-1 == ioctl(fb, FBIOGET_VSCREENINFO, &fb_var))
{
printf("get fb visual screen info error");
exit(-1);
}
fb_mem_offset = (unsigned long) fb_fix.smem_start & (~PAGE_MASK);
fb_mem = mmap(NULL, fb_fix.smem_len + fb_mem_offset, PROT_READ|PROT_WRITE, MAP_SHARED, fb, 0);
if(-1L == (long) fb_mem)
{
printf("mmap error to mem errorn"); return -1 ;
}
else
{
printf("rn set memory valuenr");
memset(fb_mem, 0, fb_var.yres * fb_fix.line_length);
}
}
return 1;
}
int main(void)
{
copytomem();
return 2;
}
|
用之前先看看ls -l /dev/fb0这个设备在不在和它的属性
|
crw------- 1 root root 29, 0 aug 30 2001 /dev/fb0
只有root才有读写的权力,确认你的权限
只有root才有读写的权力,确认你的权限