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