June 2017
Intermediate to advanced
478 pages
13h 14m
English
As I mentioned in Chapter 9, Interfacing with Device Drivers, it is possible for a driver to allow its device node to be mmaped and share some of the device memory with an application. The exact implementation is dependent on the driver.
One example is the Linux framebuffer, /dev/fb0. The interface is defined in /usr/include/linux/fb.h, including an ioctl function to get the size of the display and the bits per pixel. You can then use mmap to ask the video driver to share the framebuffer with the application and read and write pixels:
int f; int fb_size; unsigned char *fb_mem; f = open("/dev/fb0", O_RDWR); /* Use ioctl FBIOGET_VSCREENINFO to find the display dimensions and calculate fb_size */ fb_mem ...Read now
Unlock full access