00001 #if defined(__linux__)
00002 #include <unistd.h>
00003 #include <stdio.h>
00004 #include <fcntl.h>
00005 #include <linux/fb.h>
00006 #include <linux/fs.h>
00007 #include <sys/mman.h>
00008 #include <sys/ioctl.h>
00009 #include <stdlib.h>
00010 #include <iostream>
00011 using namespace std;
00012
00013 #define DEVICE_NAME "/dev/fb0"
00014 #define DIV_BYTE 8
00015
00016
00017 void send_current_error_msg(const char *ptr);
00018 void send_current_information(const char *ptr);
00019
00020 int get_fbdev_addr(void)
00021 {
00022 int fd_framebuffer ;
00023 struct fb_var_screeninfo vinfo;
00024 struct fb_fix_screeninfo finfo;
00025 long int screensize ;
00026
00027 char *fbptr ;
00028 char tmp[DIV_BYTE*10];
00029
00030
00031 int xres,yres,vbpp,line_len;
00032
00033
00034
00035 fd_framebuffer = open( DEVICE_NAME , O_RDWR);
00036 if ( !fd_framebuffer ) {
00037 send_current_error_msg("Framebuffer device open error !");
00038 exit(1);
00039 }
00040 send_current_information("The framebuffer device was opened !");
00041
00042
00043 if ( ioctl( fd_framebuffer , FBIOGET_FSCREENINFO , &finfo ) ) {
00044 send_current_error_msg("Fixed information not gotton !");
00045 exit(2);
00046 }
00047
00048
00049 if ( ioctl( fd_framebuffer , FBIOGET_VSCREENINFO , &vinfo ) ) {
00050 send_current_error_msg("Variable information not gotton !");
00051 exit(3);
00052 }
00053 xres = vinfo.xres ;
00054 yres = vinfo.yres ;
00055 vbpp = vinfo.bits_per_pixel ;
00056 line_len = finfo.line_length ;
00057 sprintf( tmp , "%d(pixel)x%d(line), %dbpp(bits per pixel)",xres,yres,vbpp);
00058 send_current_information( tmp );
00059
00060
00061 screensize = xres * yres * vbpp / DIV_BYTE ;
00062
00063
00064 fbptr = (char *)mmap(0,screensize,PROT_READ | PROT_WRITE,MAP_SHARED,fd_framebuffer,0);
00065 if ( (int)fbptr == -1 ) {
00066 send_current_error_msg("Don't get framebuffer device to memory !");
00067 exit(4);
00068 }
00069 send_current_information("The framebuffer device was mapped !");
00070
00071 printf("fb: 0x%x \n", (unsigned int)fbptr);
00072 return (int)fbptr;
00073
00074
00075
00076 }
00077
00078 void send_current_error_msg(const char *ptr)
00079 {
00080 fprintf( stderr , "%s\n" , ptr );
00081 }
00082
00083 void send_current_information(const char *ptr)
00084 {
00085 fprintf( stdout , "%s\n" , ptr );
00086 }
00087 #else
00088 int get_fbdev_addr(void) {return 0;}
00089 #endif
00090
00091 extern int get_fbdev_addr(void);