中级会员
- 积分
- 479
- 金钱
- 479
- 注册时间
- 2016-1-20
- 在线时间
- 48 小时
|
#include "stdio.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "stdlib.h"
#include "string.h"
#include "sys/mman.h"
#include "linux/fb.h"
#define WIDTH 480
#define HEIGHT 272
#define BYTE_PER_PIXEL 2
#define FB_DEVICE "/dev/fb0"
static unsigned char *fb_mem=NULL;
int init_framebuffer(void)
{
int fb;
struct fb_var_screeninfo vinfo;
fb=open(FB_DEVICE,O_RDWR);
ioctl(fb,FBIOGET_VSCREENINFO,&vinfo);
printf("x %d y %d bpp %d\r\n",vinfo.xres,vinfo.yres,vinfo.bits_per_pixel);
if(fb<0)
{
printf("cannot open frame buffer device\r\n");
}
else
{
printf("openning frame buffer succeeded\r\n");
}
fb_mem=mmap(NULL,WIDTH*HEIGHT*BYTE_PER_PIXEL,PROT_READ|PROT_WRITE,MAP_SHARED,fb,0);
if(fb_mem>0)
{
printf("map framebuffer succeeded\r\n");
}
memset(fb_mem,0,WIDTH*HEIGHT*BYTE_PER_PIXEL);
}
void putPixel(unsigned int x,unsigned int y,unsigned int color)
{
unsigned long offset;
if(x>=WIDTH)
{
x=WIDTH-1;
}
if(y>=HEIGHT)
{
y=WIDTH-1;
}
offset=(y*WIDTH*BYTE_PER_PIXEL)+(x*BYTE_PER_PIXEL);
*(unsigned short *)(fb_mem+offset)=color;
}
void main()
{
int i;
init_framebuffer();
for(i=0;i<100;i++)
{
putPixel(i,i,0xff00);
}
while(1)
{
}
} |
|