283
|
1 #if defined(__linux__)
|
|
2 #include <unistd.h>
|
|
3 #include <stdio.h>
|
|
4 #include <fcntl.h>
|
|
5 #include <linux/fb.h>
|
|
6 #include <linux/fs.h>
|
|
7 #include <sys/mman.h>
|
|
8 #include <sys/ioctl.h>
|
|
9 #include <stdlib.h>
|
|
10 #include <iostream>
|
|
11 using namespace std;
|
|
12
|
|
13 #define DEVICE_NAME "/dev/fb0"
|
|
14 #define DIV_BYTE 8
|
|
15
|
|
16 /* function prototype */
|
|
17 void send_current_error_msg(const char *ptr);
|
|
18 void send_current_information(const char *ptr);
|
|
19
|
|
20 int get_fbdev_addr(void)
|
|
21 {
|
|
22 int fd_framebuffer ;
|
|
23 struct fb_var_screeninfo vinfo;
|
|
24 struct fb_fix_screeninfo finfo;
|
|
25 long int screensize ;
|
|
26 //long int location;
|
|
27 char *fbptr ;
|
|
28 char tmp[DIV_BYTE*10];
|
|
29
|
|
30 //int x , y ;
|
|
31 int xres,yres,vbpp,line_len;
|
|
32 //unsigned short tcolor ;
|
|
33
|
298
|
34 /* 読み書き用にファイルを開く */
|
283
|
35 fd_framebuffer = open( DEVICE_NAME , O_RDWR);
|
|
36 if ( !fd_framebuffer ) {
|
|
37 send_current_error_msg("Framebuffer device open error !");
|
|
38 exit(1);
|
|
39 }
|
|
40 send_current_information("The framebuffer device was opened !");
|
|
41
|
298
|
42 /* 固定スクリーン情報取得 */
|
283
|
43 if ( ioctl( fd_framebuffer , FBIOGET_FSCREENINFO , &finfo ) ) {
|
|
44 send_current_error_msg("Fixed information not gotton !");
|
|
45 exit(2);
|
|
46 }
|
|
47
|
298
|
48 /* 変動スクリーン情報取得 */
|
283
|
49 if ( ioctl( fd_framebuffer , FBIOGET_VSCREENINFO , &vinfo ) ) {
|
|
50 send_current_error_msg("Variable information not gotton !");
|
|
51 exit(3);
|
|
52 }
|
|
53 xres = vinfo.xres ;
|
|
54 yres = vinfo.yres ;
|
|
55 vbpp = vinfo.bits_per_pixel ;
|
|
56 line_len = finfo.line_length ;
|
|
57 sprintf( tmp , "%d(pixel)x%d(line), %dbpp(bits per pixel)",xres,yres,vbpp);
|
|
58 send_current_information( tmp );
|
|
59
|
298
|
60 /* バイト単位でのスクリーンのサイズを計算 */
|
283
|
61 screensize = xres * yres * vbpp / DIV_BYTE ;
|
|
62
|
298
|
63 /* デバイスをメモリにマップする */
|
283
|
64 fbptr = (char *)mmap(0,screensize,PROT_READ | PROT_WRITE,MAP_SHARED,fd_framebuffer,0);
|
|
65 if ( (int)fbptr == -1 ) {
|
|
66 send_current_error_msg("Don't get framebuffer device to memory !");
|
|
67 exit(4);
|
|
68 }
|
|
69 send_current_information("The framebuffer device was mapped !");
|
|
70
|
|
71 printf("fb: 0x%x \n", (unsigned int)fbptr);
|
|
72 return (int)fbptr;
|
|
73 //munmap(fbptr,screensize);
|
|
74 //close(fd_framebuffer);
|
|
75 //return 0;
|
|
76 }
|
|
77
|
|
78 void send_current_error_msg(const char *ptr)
|
|
79 {
|
|
80 fprintf( stderr , "%s\n" , ptr );
|
|
81 }
|
|
82
|
|
83 void send_current_information(const char *ptr)
|
|
84 {
|
|
85 fprintf( stdout , "%s\n" , ptr );
|
|
86 }
|
|
87 #else /* !defined(__linux__) */
|
|
88 int get_fbdev_addr(void) {return 0;}
|
|
89 #endif /* defined(__linux__) */
|
|
90
|
|
91 extern int get_fbdev_addr(void);
|