When using a computer, do you know that you are using an operating system? Some people will say Microsoft's Windows, but do you know about Linux? Some people say that Linux is not as good as Windows, but this is because you do not understand Linux. This article introduces some Linux knowledge, such as the Linux Framebuffer programming problem. I hope this article will help you with Linux Framebuffer programming. The file name of the Linux framebuffer device is usually/dev/fb0, 1, 2, and so on.
The general steps for controlling the framebuffer device are as follows:
1) Open the device and map the framebuffer
2) prepare data according to hardware requirements
3) copy data to framebuffer
The example program is as follows:
1) Open the device and map the framebuffer
- static void *fbbuf;
- int openfb(char *devname)
- {
- int fd;
- fd = open(devname, O_RDWR);
- if (ioctl(fd, FBIOGET_VSCREENINFO, &fbvar) < 0)
- return -1;
- bpp = fbvar.bits_per_pixel;
- screen_size = fbvar.xres * fbvar.yres * bpp / 8;
- fbbuf = mmap(0, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
- return fd;
- }
2) data preparation. Assume that the LCD controller is initialized in the 565, 16-bit format.
- static inline int make_pixel(unsigned int a, unsigned int r, unsigned int g, unsigned int b)
- {
- return (unsigned int)(((r>>3)<<11)|((g>>2)<<5|(b>>3)));
- }
3) copy the data to be displayed to framebuffer. Assume that the framebuffer is filled in a color.
- static void fill_pixel(unsigned int pixel, int x0, int y0, int w, int h)
- {
- int i, j;
- unsigned short *pbuf = (unsigned short *)fbbuf;
- for (i = y0; i < h; i ++) {
- for (j = x0; j < w; j ++) {
- pbuf[i * screen_width + j] = pixel;
- }
- }
- }
The following program fills the LCD screen in blue
- fill_pixel(make_pixel(0, 0, 0,0xff), 0, 0, screen_width, screen_height);
The above is the process of Linux Framebuffer programming.
- Differences between soft and hard links in Linux
- Introduction to inode and soft-hardware links from Linux
- The Linux operating system no longer supports the anteng processor.
- Details about Linux recovery
- Describes how to install a wireless NIC Driver in Linux.