Operation notes: Linux Framebuffer Programming

Source: Internet
Author: User

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

 
 
  1. static void *fbbuf;  
  2. int openfb(char *devname)  
  3. {  
  4.     int fd;  
  5.     fd = open(devname, O_RDWR);  
  6.     if (ioctl(fd, FBIOGET_VSCREENINFO, &fbvar) < 0)  
  7.         return -1;  
  8.     bpp = fbvar.bits_per_pixel;  
  9.     screen_size = fbvar.xres * fbvar.yres * bpp / 8;  
  10.     fbbuf = mmap(0, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);  
  11.     return fd;  

2) data preparation. Assume that the LCD controller is initialized in the 565, 16-bit format.

 
 
  1. static inline int  make_pixel(unsigned int a, unsigned int r, unsigned int g, unsigned int b)  
  2. {  
  3.     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.

 
 
  1. static void fill_pixel(unsigned int pixel, int x0, int y0, int w, int h)  
  2. {  
  3.     int i, j;  
  4.     unsigned short *pbuf = (unsigned short *)fbbuf;  
  5.     for (i = y0; i < h; i ++) {  
  6.         for (j = x0; j < w; j ++) {  
  7.             pbuf[i * screen_width + j] = pixel;  
  8.         }  
  9.     }  

The following program fills the LCD screen in blue

 
 
  1. fill_pixel(make_pixel(0, 0, 0,0xff), 0, 0, screen_width, screen_height); 

The above is the process of Linux Framebuffer programming.

  1. Differences between soft and hard links in Linux
  2. Introduction to inode and soft-hardware links from Linux
  3. The Linux operating system no longer supports the anteng processor.
  4. Details about Linux recovery
  5. Describes how to install a wireless NIC Driver in Linux.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.