1 |
Hi all! |
2 |
|
3 |
I have a problem accessing the struct fb_cmap on my embedded board. |
4 |
I tried the code below, but without success. The thing, that goes wrong is |
5 |
|
6 |
if (ioctl(fbfd, FBIOGETCMAP, &cmap) == -1) { |
7 |
perror("Error get color map"); |
8 |
exit(1); |
9 |
} |
10 |
|
11 |
If I use a reference like above, I get |
12 |
Error get color map: Invalid argument |
13 |
|
14 |
If I use the struct itself, |
15 |
ioctl(fbfd, FBIOGETCMAP, &cmap) |
16 |
I get Error get color map: Bad address |
17 |
|
18 |
Could anyone please give me a hint, what to do? I spent hours with google, |
19 |
but without any success, |
20 |
|
21 |
Thanke in advance! |
22 |
Bye, |
23 |
Andy |
24 |
|
25 |
here is the hwole code I used: |
26 |
|
27 |
#include "stdlib.h" |
28 |
#include "unistd.h" |
29 |
#include "stdio.h" |
30 |
#include "fcntl.h" |
31 |
#include "linux/fb.h" |
32 |
#include "sys/mman.h" |
33 |
#include "sys/ioctl.h" |
34 |
|
35 |
int main() |
36 |
{ |
37 |
int fbfd = 0; |
38 |
struct fb_var_screeninfo vinfo; |
39 |
struct fb_fix_screeninfo finfo; |
40 |
struct fb_cmap cmap; |
41 |
long int screensize = 0; |
42 |
char *fbp = 0; |
43 |
int x = 0, y = 0; |
44 |
long int location = 0; |
45 |
|
46 |
// Open the file for reading and writing |
47 |
fbfd = open("/dev/fb0", O_RDWR); |
48 |
if (fbfd == -1) { |
49 |
perror("Error: cannot open framebuffer device"); |
50 |
exit(1); |
51 |
} |
52 |
printf("The framebuffer device was opened successfully.\n"); |
53 |
|
54 |
// Get fixed screen information |
55 |
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) { |
56 |
perror("Error reading fixed information"); |
57 |
exit(2); |
58 |
} |
59 |
|
60 |
// Get variable screen information |
61 |
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) { |
62 |
perror("Error reading variable information"); |
63 |
exit(3); |
64 |
} |
65 |
printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, |
66 |
vinfo.bits_per_pixel); |
67 |
|
68 |
// Figure out the size of the screen in bytes |
69 |
screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; |
70 |
|
71 |
// Check depth |
72 |
if (vinfo.bits_per_pixel != 8) { |
73 |
perror("Error: not 8 bits/pixel"); |
74 |
exit(1); |
75 |
} |
76 |
|
77 |
// Map the device to memory |
78 |
fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, |
79 |
fbfd, 0); |
80 |
if ((int)fbp == -1) { |
81 |
perror("Error: failed to map framebuffer device to memory"); |
82 |
exit(4); |
83 |
} |
84 |
printf("The framebuffer device was mapped to memory successfully.\n"); |
85 |
|
86 |
|
87 |
// Draw block |
88 |
for (y = 100; y < 300; y++) { |
89 |
for (x = 100; x < 300; x++) { |
90 |
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) + |
91 |
(y+vinfo.yoffset) * finfo.line_length; |
92 |
*((unsigned short int*)(fbp + location)) = 0; |
93 |
} |
94 |
} |
95 |
|
96 |
// Read color map |
97 |
if (ioctl(fbfd, FBIOGETCMAP, &cmap) == -1) { |
98 |
perror("Error get color map"); |
99 |
exit(1); |
100 |
} |
101 |
printf("Colormap %d %d", cmap.start, cmap.len); |
102 |
|
103 |
// Change color 0 |
104 |
cmap.red[cmap.start+0] = 0xFF; |
105 |
cmap.green[cmap.start+0] = 0xFF; |
106 |
cmap.blue[cmap.start+0] = 0xFF; |
107 |
|
108 |
if (ioctl(fbfd, FBIOPUTCMAP, &cmap) == -1) { |
109 |
perror("Error set color map"); |
110 |
exit(1); |
111 |
} |
112 |
printf("Colormap set"); |
113 |
|
114 |
munmap(fbp, screensize); |
115 |
close(fbfd); |
116 |
return 0; |
117 |
} |