annotate old/simple_render/fb.h @ 1740:5a294d8e5643 draft

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