LCD & framebuffer development experience

  

frame buffer device belongs to the character device, using the "file layer - driver layer" interface mode. The driver layer interface defined by Linux for the frame buffer device is the struct fb_info structure. At the file level, Linux defines the following operation functions: struct file_operations

Software running process:

At the file level, the user calls the function operation of struct file_operations, in struct file_operations Indirectly call the function of struct fb_ops to operate the hardware. When registering the FB device with the kernel, it also registers the pointer of struct fb_ops. When opening the fb device, first call xxxfb_init() of fb_drivers[] to initialize the device;

1, development steps and framework

Files involved: fb.h, fbmem.c, xxxfb.c.

fb.h: defines some structures, variables and macros;

fbmem.c: Mainly implement device entry and initialization, such as struct file_operations;

entry point:

static struct {

const char *name;

int (*init)(void);

int (*setup)(char*);

} fb_drivers[] __initdata = {

#ifdef CONFIG_FB_YOURCARD

{ "driver_name", xxxfb_init, xxxfb_setup },

#endif

File Operations:

static struct file_operations fb_fops = {

owner: THIS_MODULE,

read: fb_read,

w Rite: fb_write,

ioctl: fb_ioctl,

mmap: fb_mmap,

open: fb_open,

release: fb_release,

#ifdef HAVE_ARCH_FB_UNMAPPED_AREA

get_unmapped_area: get_fb_unmapped_area,

#endif

};

xxxfb.c: Device driver files added by yourself, such as struct fb_info;

Implementation entry point function: xxxfb_init; xxxfb_setup;

static struct fb_ops xxxfb_ops = {

owner: THIS_MODULE,

fb_open: xxxfb_open, /* only If you need it to do something */

fb_release: xxxfb_release, /* only if you need it to do something */

fb_get_fix: fbgen_get_fix,

fb_get_var: fbgen_get_var ,

fb_set_var: fbgen_set_var,

fb_get_cmap: fbgen_get_cmap,

fb_set_cmap: fbgen_set_cmap,

fb_pan_display: fbgen_pan_display,

fb_ioctl: xxxfb_ioctl , /* optional */

};

2, what is a framebuffer device

framebuffer is a hardware device capable of extracting graphics, which is very good for users to enter the graphical interface. Interface. With framebuffer, the user's application can make good graphics without deep knowledge of the underlying drivers.

For the user, it is no different from other devices under /dev. Users can think of

framebuffer as a piece of memory, and can write data to this memory. Data can be read from this block of memory.

The first registered framebuffer has a minor equal to 0, the second registered framebuffer has a minor equal to 1, and so on.

3, framebuffer internal structure

Data structure: framebuffer device largely relies on the following four data structures. These three structures are declared in fb.h.

Struct fb_var_screeninfo

Struct fb_fix_screeninfo

Struct fb_info

The first structure is used to describe the characteristics of the graphics card. Usually set by the user. It includes the resolution of the display screen, the number of bits per pixel, and some timing variables. The variable xres defines the number of pixels occupied by one line of the screen, yres defines the number of pixels occupied by a column of the screen, and bits_per_pixel defines how many bits are used for each pixel.

The second structure defines the hardware characteristics of the graphics card and cannot be changed. If the graphics card is selected by the user, its hardware characteristics will be fixed. It contains the physical address and length of the screen buffer.

The third structure is the driver layer interface defined by Linux for framebuffer devices. It contains not only the underlying functions, but also the data that records the state of the device. Each frame buffer device corresponds to an fb_info structure. The member variable modename is the device name, fontname is the display font, and fbops is a pointer to the function of the underlying operation. Defines the independent state of the current graphics card framebuffer device. A graphics card may have two framebuffers. In this case, two fb_info structures are required. This structure is only visible in the kernel space.

4. Design your own framebuffer device driver

Users first need to add the following code to fbmem.c

static struct {

const char *name ;

int (*init)(void);

int (*setup)(char*);

} fb_drivers[] __initdata = {

#ifdef CONFIG_FB_YOURCARD

{ "driver_name", xxxfb_init, xxxfb_setup },

#endif

Secondly redistribute the memory size in xxfb.c according to your needs. For example:

#define VIDEOMEMSIZE (1*1024*1024) /* 1 MB */

Modify the corresponding var information again according to your hardware device. The main modification

xxfb_set_var(struct fb_var_screeninfo *var, int con, struct fb_info *info) function.

5, how to add framebuffer device driver

In the make menuconfig first enter the Character devices, select the Virtualterminal inside. If you want the console to output on the LCD, then select Support for console on virtual Terminal. (Msh (minix shell) is selected, and a sh < /dev/ttyS0 is placed in rc, and the key input output through the serial port can be displayed on the LCD.)

Return to In the upper layer interface, we can see the options of the Console device. After entering, place the cursor on the Framebuffer Support, press the Enter key to enter, and select the framebuffer device you need. The type of device driver that you have added (if you are in uclinux, you should select it with * instead of M), and the corresponding .o file will be generated at compile time.

You can configure bpp packed pixel support in Advanced low level, then select Selectcompiled-in fonts.

When the operating system
runs, it will see the fb device under /dev. Its major should be 29, and the first device's minor should be 0.

Copyright © Windows knowledge All Rights Reserved