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