comparison old/simple_render/fb.cpp @ 507:735f76483bb2

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