Implementation of an embedded Linux system GUI
0 Introduction
With the rapid development of the embedded Linux operating system, a simple human-computer interaction interface is urgently required. Therefore, this article introduces how to design your own embedded GUI based on FrameBuffer.
1. display principle
1.1 Color Representation
Color is the basis for all plotting operations. A 16-bit LCD screen generally needs two bytes. The 16-bit RGB format is generally divided into two formats: RGB565 and RGB5551. The RGB565 format is listed in Table 1, and the RGB5551 format is listed in Table 2. In the table, R is the red component, G is the green component, and B is the blue component.
Because the color adopts the RGB565 rule. Therefore. The red, green, and blue colors can be 0xf800, 0x07e0, or Ox001f according to RGB565 rules. It can be seen that it is inconvenient to directly represent the color in hexadecimal format. Currently, the 24-bit RGB color representation is generally accepted by software engineers. The R, G, and B components each occupy one byte in the range of 0 ~ 255. Therefore, an interface should be provided for the MIS software system to convert from 24-bit RGB to 16RGB. The specific implementation method of this interface using macros is as follows:
# Define RGB (r, g, B) (r> 3) <11 )? (G> 2) <5 )? (B> 3 ))
1.2 image point operations
The most basic operation of the graphic device interface is the painting point. Any other drawing function is based on the painting point. The principle is that the first pixel in the upper left corner of the screen is (0, 0), the right is the x axis, and the downward is the y axis to create a coordinate system, as long as the x, y, and color values of a certain point are provided, you can use a certain algorithm to find the address (x, y), and then replace the two bytes of the address with the specified color value. For example, if a 640x480x16 LCD has a first address of 0x40000000 pixels, the first address of the pixel is 1 in 2nd rows and 3rd columns.
If you want to change the pixels of 2nd rows and 3rd columns from the original white (0 xfff) to Black (0x0000 ). Then, you can find the address according to the following addressing method:
Final address = first address + y x 2 x screen width + x 2
The first address indicates the address corresponding to the 1st rows and 1st columns of pixels. From the above formula, the address of this point is 0x40000000 + 2x2x0x280 + 3x2 = 0x40000A06. The data corresponding to the 0x40000A06 address should be the low byte part of the sixteen-bit color, and the data corresponding to the 0x40000A07 address should be the high byte part of the sixteen-bit color.
For example, the image point function can be implemented using the following code:
M_pScreen_Addr is the first screen address, while m_nSereen_Width and m_nScreen_Height are the screen width and screen height respectively. In this way, various basic drawing operations can be extended based on the Bresenham algorithm, such as draw a straight line, draw a rectangle and draw a circle.
2 FrameBuffer Interface
FrameBuffer is a driver interface that appears in the 2.2.xx kernel. Linux abstracts the FrameBuffer device for user-State processes to directly write the screen. The FrameBuffer mechanism imitates the function of a video card. It abstracts the hardware structure of the video card, and then performs operations on the video memory through FrameBuffer read/write. Users can regard FrameBuffer as an image for displaying memory. After ing it to the process address space, you can perform read/write operations directly, and the write operations can also be immediately reflected on the screen. Such operations are abstract and unified. Users do not have to worry about the location of the physical display and page feed mechanism, and these can be driven by the FrameBuffer device.