그림 재생기(2): 프레임 버퍼 기본 조작 코드
2072 단어 프로젝트 학습
fb.c//fb 파일Makefile
include############### fb.h
start.c//처음 파일
Makefile//기본 Makefile Makefile.build
fb.c
#include
#include
#include
#include
#include
#include
#include
#include
#include
//
unsigned int *pfb = NULL;
int fb_fd = -1;
int fb_open(void)
{
int ret = -1;
struct fb_fix_screeninfo finfo = {{0},};
struct fb_var_screeninfo vinfo = {{0},};
// 1 :
fb_fd = open(FBDEVICE, O_RDWR);
if (fb_fd < 0)
{
perror("open");
return -1;
}
printf("open %s success.
", FBDEVICE);
// 2 :
ret = ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo);
if (ret < 0)
{
perror("ioctl");
return -1;
}
printf("smem_start = 0x%lx, smem_len = %u.
", finfo.smem_start, finfo.smem_len);
ret = ioctl(fb_fd, FBIOGET_VSCREENINFO, &vinfo);
if (ret < 0)
{
perror("ioctl");
return -1;
}
printf("xres = %u, yres = %u.
", vinfo.xres, vinfo.yres);
printf("xres_virtual = %u, yres_virtual = %u.
", vinfo.xres_virtual, vinfo.yres_virtual);
printf("bpp = %u.
", vinfo.bits_per_pixel);
// 3 : mmap
unsigned long len = vinfo.xres_virtual * vinfo.yres_virtual * vinfo.bits_per_pixel / 8;
printf("len = %ld
", len);
pfb = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0);
if (NULL == pfb)
{
perror("mmap");
return -1;
}
printf("pfb = %p.
", pfb);
return 0;
}
void fb_close(void)
{
close(fb_fd);
}
void fb_draw_back(unsigned int width, unsigned int height, unsigned int color)
{
unsigned int x, y;
for (y=0; y