91
|
1 /*
|
|
2 * fbtst.c
|
|
3 * 2006.7.19 Kensuke Ooyu
|
|
4 */
|
90
|
5 #include <unistd.h>
|
91
|
6 #include <stdio.h>
|
|
7 #include <fcntl.h>
|
90
|
8 #include <linux/fb.h>
|
91
|
9 #include <linux/fs.h>
|
90
|
10 #include <sys/mman.h>
|
|
11 #include <sys/ioctl.h>
|
91
|
12 #include <stdlib.h>
|
|
13 #include <iostream>
|
90
|
14 using namespace std;
|
|
15
|
|
16 #define DEVICE_NAME "/dev/fb0"
|
|
17 #define DIV_BYTE 8
|
|
18
|
91
|
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 char *fbptr ;
|
|
43 char tmp[DIV_BYTE*10];
|
|
44
|
|
45 int xres,yres,vbpp,line_len;
|
90
|
46
|
91
|
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 }
|
90
|
60
|
91
|
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 );
|
90
|
72
|
91
|
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
|
96
|
84 printf("fb: %x \n",(unsigned int)fbptr);
|
91
|
85 return (int)fbptr;
|
|
86 //munmap(fbptr,screensize);
|
|
87 //close(fd_framebuffer);
|
|
88 //return 0;
|
90
|
89 }
|
|
90
|
91
|
91 void send_current_error_msg(char *ptr)
|
|
92 {
|
|
93 fprintf( stderr , "%s\n" , ptr );
|
|
94 }
|
90
|
95
|
91
|
96 void send_current_information(char *ptr)
|
|
97 {
|
|
98 fprintf( stdout , "%s\n" , ptr );
|
90
|
99 }
|