1. DirectFB help needed
- Posted by jmduro Mar 27, 2019
- 1272 views
I'm trying to drive DirectFB directly from OEU instead of using a C library on a Raspberry Pi. I get stuck on one problem when poking into mapped memory.
I want to port this code:
// Map the device to memory fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); // Figure out where in memory to put the pixel for (y = 100; y < 300; y++) for (x = 100; x < 300; x++) { location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) + (y+vinfo.yoffset) * finfo.line_length; if (vinfo.bits_per_pixel == 32) { *(fbp + location) = 100; // Some blue *(fbp + location + 1) = 15+(x-100)/2; // A little green *(fbp + location + 2) = 200-(y-100)/5; // A lot of red *(fbp + location + 3) = 0; // No transparency } else { //assume 16bpp int b = 10; int g = (x-100)/6; // A little green int r = 31-(y-100)/16; // A lot of red unsigned short int t = r<<11 | g << 5 | b; *((unsigned short int*)(fbp + location)) = t; } } munmap(fbp, screensize);
I wrote this code:
fbp = mmap(0, screensize, or_bits(PROT_READ, PROT_WRITE), MAP_SHARED, fbfd, 0) -- Figure out where in memory to put the pixel atom xoffset = peek4u(vinfo+VSI_XOFFSET) atom yoffset = peek4u(vinfo+VSI_YOFFSET) atom line_length = peek4u(finfo+FSI_LINE_LENGTH) for y = 100 to 299 do for x = 100 to 299 do location = (x+xoffset) * (bits_per_pixel/8) + (y+yoffset) * line_length if bits_per_pixel = 32 then poke(fbp + location, { 100, -- Some blue trunc(15+(x-100)/2), -- A little green trunc(200-(y-100)/5), -- A lot of red 0}) -- No transparency else --assume 16bpp integer b = 10 integer g = trunc((x-100)/6) -- A little green integer r = trunc(31-(y-100)/16) -- A lot of red integer t = or_all({shift_bits(r,-11), shift_bits(g,-5), b}) poke2(fbp + location, t) end if end for end for munmap(fbp, screensize)
I get a machine level exception on poke(fbp + location, {. It seems I try to poke into a bad location but I can't locate the bug!
Can anyone help?
Jean-Marc
2. Re: DirectFB help needed
- Posted by ghaberek (admin) Mar 27, 2019
- 1281 views
I'm trying to drive DirectFB directly from OEU instead of using a C library on a Raspberry Pi. I get stuck on one problem when poking into mapped memory.
I get a machine level exception on poke(fbp + location, {. It seems I try to poke into a bad location but I can't locate the bug!
Can we see your define_c_func() entries and wrapper functions for mmap() and munmap()?
What are the values of screensize and fbp? How did you get vinfo and finfo?
Maybe post the entire code to Pastey or a Gist and that would help.
-Greg
3. Re: DirectFB help needed
- Posted by jmduro Mar 28, 2019
- 1252 views
All the code is here:
http://jean-marc.duro.pagesperso-orange.fr/eufb.tar.gz
Here is the output:
The framebuffer device was opened successfully. 1280x1024, 32bpp The framebuffer device was mapped to memory successfully. /home/pi/Data/Euphoria/eufb/test_fb3.ex:66 A machine-level exception occurred during execution of this statement (signal 11)
And here are the variable values:
/home/pi/Data/Euphoria/eufb/test_fb3.ex: screensize = 5242880 fbp = 1987805184 location = 3.35544324e+10 fbfd = 3 finfo = 34729984 vinfo = 34734080 xres = 1280 yres = 1024 bits_per_pixel = 32' ' xoffset = 0 yoffset = 0 line_length = 335544320 y = 100'd' x = 100'd' b = <no value> g = <no value> r = <no value> t = <no value>
location seems to be high but I don't see any difference between C and OEU code:
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) + (y+vinfo.yoffset) * finfo.line_length;
integer bits_per_pixel = peek4u(vinfo+VSI_BITS_PER_PIXEL) atom xoffset = peek4u(vinfo+VSI_XOFFSET) atom yoffset = peek4u(vinfo+VSI_YOFFSET) atom line_length = peek4u(finfo+FSI_LINE_LENGTH) location = (x+xoffset) * (bits_per_pixel/8) + (y+yoffset) * line_length
Jean-Marc
4. Re: DirectFB help needed
- Posted by jmduro Mar 28, 2019
- 1219 views
I ran the C code on Linux and made it print variable values.
The framebuffer device was opened successfully. 1920x1080, 32bpp The framebuffer device was mapped to memory successfully. vinfo.xoffset = 0 vinfo.yoffset = 0 vinfo.bits_per_pixel = 32 finfo.line_length = 7680 last location value = 2297516
line_length is much too high with OEU. Now I know where I must look for the bug.
Jean-Marc
5. Re: DirectFB help needed
- Posted by jmduro Mar 28, 2019
- 1238 views
I got it. There seems to be a bug in /usr/include/linux/fb.h in the declaration of struct fb_fix_screeninfo in following section:
__u16 xpanstep; /* zero if no hardware panning */ __u16 ypanstep; /* zero if no hardware panning */ __u16 ywrapstep; /* zero if no hardware ywrap */ __u32 line_length; /* length of a line in bytes */
If I insert following line before I wrap the code, it works correctly
__u16 xwrapstep; /* zero if no hardware xwrap */
Jean-Marc
6. Re: DirectFB help needed
- Posted by jmduro Mar 28, 2019
- 1244 views
There seems to be no xwrapstep element but a realignment problem so I put last modification line in comment.
Updated code is available here:
http://jean-marc.duro.pagesperso-orange.fr/eufb_v0.0.2_2019-03-28.tar.gz
Jean-Marc