Mercurial > hg > Members > yutaka > manager
view ppe/fb.cc @ 5:39d405bc46b7
add fb
author | yutaka@localhost.localdomain |
---|---|
date | Sat, 10 Apr 2010 16:29:22 +0900 |
parents | |
children | febf899d0043 |
line wrap: on
line source
#include "fb.h" using namespace std; void send_current_error_msg(const char *ptr) { fprintf( stderr , "%s\n" , ptr ); } void send_current_information(const char *ptr) { fprintf( stdout , "%s\n" , ptr ); } fb_t get_fbdev_addr(void) { int fd_framebuffer ; struct fb_var_screeninfo vinfo; struct fb_fix_screeninfo finfo; long int screensize ; //long int location; char *fbptr ; char tmp[DIV_BYTE*10]; //int x , y ; int xres,yres,vbpp,line_len; //unsigned short tcolor ; /* 読み書き用にファイルを開く */ fd_framebuffer = open( DEVICE_NAME , O_RDWR); if ( !fd_framebuffer ) { send_current_error_msg("Framebuffer device open error !"); exit(1); } send_current_information("The framebuffer device was opened !"); /* 固定スクリーン情報取得 */ if ( ioctl( fd_framebuffer , FBIOGET_FSCREENINFO , &finfo ) ) { send_current_error_msg("Fixed information not gotton !"); exit(2); } /* 変動スクリーン情報取得 */ if ( ioctl( fd_framebuffer , FBIOGET_VSCREENINFO , &vinfo ) ) { send_current_error_msg("Variable information not gotton !"); exit(3); } xres = vinfo.xres ; yres = vinfo.yres ; vbpp = vinfo.bits_per_pixel ; line_len = finfo.line_length ; sprintf( tmp , "%d(pixel)x%d(line), %dbpp(bits per pixel)",xres,yres,vbpp); send_current_information( tmp ); /* バイト単位でのスクリーンのサイズを計算 */ screensize = xres * yres * vbpp / DIV_BYTE ; /* デバイスをメモリにマップする */ fbptr = (char *)mmap(0,screensize,PROT_READ | PROT_WRITE,MAP_SHARED,fd_framebuffer,0); if ( (int)fbptr == -1 ) { send_current_error_msg("Don't get framebuffer device to memory !"); exit(4); } send_current_information("The framebuffer device was mapped !"); printf("fb: 0x%x \n", (unsigned int)fbptr); fb_t fb; fb.pixels = fbptr; fb.size = screensize; fb.width = xres; fb.height = yres; fb.bpp = vbpp; fb.fd = fd_framebuffer; return fb; }