lcd设备驱动之全解析.docx
《lcd设备驱动之全解析.docx》由会员分享,可在线阅读,更多相关《lcd设备驱动之全解析.docx(61页珍藏版)》请在三一办公上搜索。
1、linux中LCD设备驱动(1)framebuffer(帧缓冲)1、framebuffer 帧缓冲 帧缓冲(framebuffer)是Linux 系统为显示设备提供的一个接口,它将显示缓冲区抽象,屏蔽图像硬件的底层差异,允许上层应用程序在图形模式下直接对显示缓冲区进行读写操作。用户不必关心物理显示缓冲区的具体位置及存放方式,这些都由帧缓冲设备驱动本身来完成。 framebuffer机制模仿显卡的功能,将显卡硬件结构抽象为一系列的数据结构,可以通过framebuffer的读写直接对显存进行操作。用户可以将framebuffer看成是显存的一个映像,将其映射到进程空间后,就可以直接进行读写操作,写
2、操作会直接反映在屏幕上。 framebuffer是个字符设备,主设备号为29,对应于/dev/fb%d 设备文件。通常,使用如下方式(前面的数字表示次设备号) 0 = /dev/fb0 第一个fb 设备 1 = /dev/fb1 第二个fb 设备 fb 也是一种普通的内存设备,可以读写其内容。例如,屏幕抓屏:cp /dev/fb0 myfilefb 虽然可以像内存设备(/dev/mem)一样,对其read,write,seek 以及mmap。但区别在于fb 使用的不是整个内存区,而是显存部分。2、fb与应用程序的交互对于用户程序而言,它和其他的设备并没有什么区别,用户可以把fb看成是一块内存,
3、既可以向内存中写数据,也可以读数据。fb的显示缓冲区位于内核空间,应用程序可以把此空间映射到自己的用户空间,在进行操作。在应用程序中,操作/dev/fbn的一般步骤如下:(1)打开/dev/fbn设备文件。(2)用ioctl()操作取得当前显示屏幕的参数,如屏幕分辨率、每个像素点的比特数。根据屏幕参数可计算屏幕缓冲区的大小。(3)用mmap()函数,将屏幕缓冲区映射到用户空间。(4)映射后就可以直接读/写屏幕缓冲区,进行绘图和图片显示了。3、fb的结构及其相关结构体在linux中,fb设备驱动的源码主要在Fb.h (linux2.6.28includelinux)和Fbmem.c (linux
4、2.6.28driversvideo)两个文件中,它们是fb设备驱动的中间层,为上层提供系统调用,为底层驱动提供接口。在fb.h文件中有fb驱动需要使用的很多结构,我们先对这些结构体进行说明:本章共介绍5个结构体:(1)、struct fb_info结构体(2)、struct fb_ops结构体(3)、struct fb_fix_screeninfo结构体(4)、struct fb_var_screeninfo结构体(5)、struct fb_cmap结构体(1)、struct fb_info结构体介绍一个帧缓冲区对应一个struct fb_info结构,它包括了帧缓冲设备的属性和操作的完整集
5、合,每个帧设备都有一个fb_info结构体。源码如下:struct fb_info int node;int flags;struct mutex lock;/* Lock for open/release/ioctl funcs */互斥锁struct fb_var_screeninfo var;/* Current var */当前缓冲区的可变参数struct fb_fix_screeninfo fix;/* Current fix */固定参数struct fb_monspecs monspecs;/* Current Monitor specs */当前显示器标志struct work
6、_struct queue;/* Framebuffer event queue */帧缓冲事件队列struct fb_pixmap pixmap;/* Image hardware mapper */图像硬件mapperstruct fb_pixmap sprite;/* Cursor hardware mapper */光标硬件mapperstruct fb_cmap cmap;/* Current cmap */当前的调色板struct list_head modelist; /* mode list */struct fb_videomode *mode;/* current mode
7、 */当前的视频模式#ifdef CONFIG_FB_BACKLIGHT如果配置了LCD支持背光灯/* assigned backlight device */* set before framebuffer registration, remove after unregister */背光调整struct backlight_device *bl_dev;/* Backlight level curve */struct mutex bl_curve_mutex;u8 bl_curveFB_BACKLIGHT_LEVELS;#endif#ifdef CONFIG_FB_DEFERRED_I
8、Ostruct delayed_work deferred_work;struct fb_deferred_io *fbdefio;#endifstruct fb_ops *fbops;帧缓冲操作函数集struct device *device;/* This is the parent */父设备struct device *dev;/* This is this fb device */fb设备int class_flag; /* private sysfs flags */私有的sysfs标志#ifdef CONFIG_FB_TILEBLITTINGstruct fb_tile_ops
9、*tileops; /* Tile Blitting */图块blitting#endifchar _iomem *screen_base;/* Virtual address */虚拟基地址unsigned long screen_size;/* Amount of ioremapped VRAM or 0 */ ioremap的虚拟内存大小void *pseudo_palette;/* Fake palette of 16 colors */ 伪16位调色板#define FBINFO_STATE_RUNNING 0#define FBINFO_STATE_SUSPENDED 1u32 s
10、tate; /* Hardware state i.e suspend */硬件的状态void *fbcon_par; /* fbcon use-only private area */* From here on everything is device dependent */void *par; ;(2)、struct fb_ops结构体介绍/*Frame buffer operations* LOCKING NOTE: those functions must _ALL_ be called with the console* semaphore held, this is the o
11、nly suitable locking mechanism we have* in 2.6. Some may be called at interrupt time at this point though.*/fb_ops结构体用来实现对帧缓冲设备的操作,这些函数需要驱动开发人员编写,struct fb_ops /* open/release and usage marking */struct module *owner;打开和释放int (*fb_open)(struct fb_info *info, int user);int (*fb_release)(struct fb_inf
12、o *info, int user);这两个函数对于非线性布局的/常规内存映射无法工作的帧缓冲设备需要/* For framebuffers with strange non linear layouts or that do not* work with normal memory mapped access*/ssize_t (*fb_read)(struct fb_info *info, char _user *buf, size_t count, loff_t *ppos);ssize_t (*fb_write)(struct fb_info *info, const char _us
13、er *buf, size_t count, loff_t *ppos);检测可变参数,并调整到支持的值/* checks var and eventually tweaks it to something supported,* DO NOT MODIFY PAR */int (*fb_check_var)(struct fb_var_screeninfo *var, struct fb_info *info);设置视频模式/* set the video mode according to info-var */int (*fb_set_par)(struct fb_info *info)
14、;设置color寄存器的值/* set color register */int (*fb_setcolreg)(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *info);批量设置color寄存器,设置颜色表/* set color registers in batch */int (*fb_setcmap)(struct fb_cmap *cmap, struct fb_info *info);显示空白/* blank display */int (*
15、fb_blank)(int blank, struct fb_info *info);pan显示/* pan display */int (*fb_pan_display)(struct fb_var_screeninfo *var, struct fb_info *info);填充矩形/* Draws a rectangle */void (*fb_fillrect) (struct fb_info *info, const struct fb_fillrect *rect);数据复制/* Copy data from area to another */void (*fb_copyarea
16、) (struct fb_info *info, const struct fb_copyarea *region);图形填充/* Draws a image to the display */void (*fb_imageblit) (struct fb_info *info, const struct fb_image *image);绘制光标/* Draws cursor */int (*fb_cursor) (struct fb_info *info, struct fb_cursor *cursor);旋转显示/* Rotates the display */void (*fb_ro
17、tate)(struct fb_info *info, int angle);等待blit空闲/* wait for blit idle, optional */int (*fb_sync)(struct fb_info *info);fb特定的ioctl操作/* perform fb specific ioctl (optional) */int (*fb_ioctl)(struct fb_info *info, unsigned int cmd,unsigned long arg);处理32兼容的ioctl操作/* Handle 32bit compat ioctl (optional)
18、*/int (*fb_compat_ioctl)(struct fb_info *info, unsigned cmd,unsigned long arg);fb特定的mmap操作/* perform fb specific mmap */int (*fb_mmap)(struct fb_info *info, struct vm_area_struct *vma);保存目前的硬件状态/* save current hardware state */void (*fb_save_state)(struct fb_info *info);恢复被保存的硬件状态/* restore saved st
19、ate */void (*fb_restore_state)(struct fb_info *info);通过fb_info获得framebuffer的能力/* get capability given var */void (*fb_get_caps)(struct fb_info *info, struct fb_blit_caps *caps, struct fb_var_screeninfo *var);(3)、struct fb_fix_screeninfo结构体接收fb_fix_screeninfo结构体中,记录了用户不能修改的固定显示控制器参数。这些固定的参数如缓冲区的物理地址、
20、缓冲区的长度等等。struct fb_fix_screeninfo char id16; /* identification string eg TT Builtin */字符串形式的标识符unsigned long smem_start;/* Start of frame buffer mem */* (physical address) */fb缓存的开始位置_u32 smem_len;/* Length of frame buffer mem */fb缓存的长度_u32 type; /* see FB_TYPE_* */FB_TYPE_*类型_u32 type_aux;/* Interl
21、eave for interleaved Planes */分界_u32 visual; /* see FB_VISUAL_* */屏幕使用的色彩模式_u16 xpanstep;/* zero if no hardware panning */如果没有硬件panning ,赋0_u16 ypanstep;/* zero if no hardware panning */_u16 ywrapstep;/* zero if no hardware ywrap */1行的字节数_u32 line_length;/* length of a line in bytes */内存映射I/O的开始位置un
22、signed long mmio_start;/* Start of Memory Mapped I/O */* (physical address) */内存映射I/O的长度_u32 mmio_len;/* Length of Memory Mapped I/O */_u32 accel; /* Indicate to driver which */* specific chip/card we have*/_u16 reserved3;/* Reserved for future compatibility */;(4)、struct fb_var_screeninfo结构体介绍fb_va
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- lcd 设备 驱动 解析
链接地址:https://www.31ppt.com/p-1937856.html