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