#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <string.h>
#include <stdlib.h> /*
可编程信息
struct fb_var_screeninfo {
__u32 xres; //x轴像素点数量
__u32 yres; //y轴像素点数量
__u32 xres_virtual; //虚拟屏x轴
__u32 yres_virtual; //虚拟屏y轴
__u32 xoffset;
__u32 yoffset;
__u32 bits_per_pixel; //色深
__u32 grayscale;
struct fb_bitfield red; //fb缓存的R\G\B位域
struct fb_bitfield green;
struct fb_bitfield blue;
struct fb_bitfield transp;
__u32 nonstd;
__u32 activate;
__u32 height; //屏幕的高度
__u32 width; //屏幕的宽度
__u32 accel_flags;
__u32 pixclock;
__u32 left_margin;
__u32 right_margin;
__u32 upper_margin;
__u32 lower_margin;
__u32 hsync_len;
__u32 vsync_len;
__u32 sync;
__u32 vmode;
__u32 rotate;
__u32 colorspace;
__u32 reserved[4];
}; 固定信息
struct fb_fix_screeninfo {
char id[16]; //标识符
unsigned long smem_start; //fb缓存的起始位置
__u32 smem_len; //fb缓存的大小
__u32 type;
__u32 type_aux;
__u32 visual;
__u16 xpanstep;
__u16 ypanstep;
__u16 ywrapstep;
__u32 line_length;
unsigned long mmio_start; //内存映射I/O的开始位置
__u32 mmio_len; //内存映射I/O的长度
__u32 accel;
__u16 capabilities;
__u16 reserved[2];
}
*/ char *fb_addr;
unsigned fb_size; void print_screen(char *buf,int width,int height); int main(int argc,char *argv[])
{
int fd=; struct fb_fix_screeninfo fb_fix;
struct fb_var_screeninfo fb_var; char *env=NULL; short *picture;
int ret;
env="/dev/graphics/fb0";
//env="/sys/class/graphics/fb0"; fd=open(env,O_RDWR);
printf("aplex test v2 \n");
printf("fd= %s\n",env); ioctl(fd,FBIOGET_FSCREENINFO,&fb_fix); printf("fb_fix.line_length=%u\n",fb_fix.line_length);
printf("fb_fix.accel=%u\n",fb_fix.accel); ioctl(fd,FBIOGET_VSCREENINFO,&fb_var); printf("fb_var.xres=%u\n",fb_var.xres);
printf("fb_var.yres=%u\n",fb_var.yres);
printf("fb_var.xres_virtual=%u\n",fb_var.xres_virtual);
printf("fb_var.yres_virtual=%u\n",fb_var.yres_virtual); fb_size=fb_var.yres*fb_fix.line_length; /*fb_addr的获取,是很核心的步骤,表示成功获得了framebuffer设备*/
fb_addr=(char *)mmap(NULL,fb_size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,); picture=(char *)malloc(fb_var.yres*fb_fix.line_length);
memset(picture,0xFF,fb_var.yres*fb_fix.line_length);
/*注意,这里对颜色的赋值只是一次赋一半值,也就是一个字节,8bit*/
/*而事实上,一个像素的颜色值是16bit*/
/*0xFFFF就是白色*/
/*介绍一下16bit的颜色的类型,颜色是由RGB组成,如果是565排列,
则依次为Red Green Blue
11111 111111 11111
*/ print_screen(picture,fb_var.xres,fb_var.yres); return ;
} void print_screen(char *buf,int width,int height)
{
short *t_data=(short *)buf; short *t_fb_addr=(short *)fb_addr; int bytew=width<<; /*像素数乘以2即是字节数,因为颜色深度是2个字节(16bit)*/ while(--height>=)
{
memcpy(t_fb_addr,t_data,bytew); /*一行的数据赋值*/
t_fb_addr += width;
t_data += width;
}
}
root@sabresd_6dq:/data # ./frameworkTest
aplex test v2
fd= /dev/graphics/fb0
fb_fix.line_length=
fb_fix.accel=
fb_var.xres=
fb_var.yres=
fb_var.xres_virtual=
fb_var.yres_virtual=
现象:
上半个屏幕显示为全白色