📄 [转载]framebuffer驱动程序模型 - linux dev - 逍遥游.htm
字号:
fb_cmap <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>cmap<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">int</SPAN> kspc<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN><BR><SPAN
style="COLOR: rgb(0,0,255)">int</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>getcolreg<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">(</SPAN>u_int<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> u_int <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN><SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> u_int <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN><SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> u_int <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN><SPAN
style="COLOR: rgb(0,0,204)">,</SPAN>u_int <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN><SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
fb_info <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN><SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">,</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
fb_info <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>fb_info<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><BR><SPAN
style="COLOR: rgb(0,0,255)">extern</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">int</SPAN>
fb_set_cmap<SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
fb_cmap <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>cmap<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">int</SPAN> kspc<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN><BR>
<SPAN style="COLOR: rgb(0,0,255)">int</SPAN>
<SPAN style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>setcolreg<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">(</SPAN>u_int<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> u_int<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> u_int<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> u_int<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> u_int<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN><SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
fb_info <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN><SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">,</SPAN><BR>
<SPAN style="COLOR: rgb(0,0,255)">struct</SPAN>
fb_info <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>fb_info<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><BR><SPAN
style="COLOR: rgb(0,0,255)">extern</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
fb_cmap <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>fb_default_cmap<SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,255)">int</SPAN> len<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><BR><SPAN
style="COLOR: rgb(0,0,255)">extern</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">void</SPAN>
fb_invert_cmaps<SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,255)">void</SPAN><SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">;</SPAN></SPAN></CODE></P></TD></TR></TBODY></TABLE><BR><FONT
color=#993300>2.
通过文件解析</FONT><BR>在anakinfb.c文件中,cmap如图<BR><A
href="[转载]Framebuffer驱动程序模型 - linux Dev - 逍遥游.files/1_29132959.jpg"
target=_blank linkindex="20" set="yes"><IMG
height=497 alt=""
src="[转载]Framebuffer驱动程序模型 - linux Dev - 逍遥游.files/1_29132959.jpg"
width=538 border=0></A> <BR><A
href="[转载]Framebuffer驱动程序模型 - linux Dev - 逍遥游.files/1_29133042.jpg"
target=_blank linkindex="21" set="yes"><IMG
height=283 alt=""
src="[转载]Framebuffer驱动程序模型 - linux Dev - 逍遥游.files/1_29133042.jpg"
width=474 border=0></A> <BR>在stifb.c<BR><A
href="[转载]Framebuffer驱动程序模型 - linux Dev - 逍遥游.files/1_29133109.jpg"
target=_blank linkindex="22" set="yes"><IMG
height=284 alt=""
src="[转载]Framebuffer驱动程序模型 - linux Dev - 逍遥游.files/1_29133109.jpg"
width=467 border=0></A>
<P>本文介绍的设备是位于/video目录下面的anakinfb.c驱动程序。虽然我不清楚那个设备的特性,但是从对程序的分析中我们仍然知道如何编写一个frame
buffer设备驱动。</P>
<P>
本文是个标准的fb驱动。共221行,包含函数如下: </P>
<OL>
<LI>static int anakinfb_getcolreg(u_int
regno, u_int *red, u_int *green, u_int *blue,
u_int *transp, struct fb_info *info) 31行
<LI>static int anakinfb_setcolreg(u_int regno,
u_int red, u_int green, u_int blue,u_int transp,
struct fb_info *info) 45行
<LI>static int anakinfb_get_fix(struct
fb_fix_screeninfo *fix, int con, struct fb_info
*info) 57行
<LI>static int anakinfb_get_var(struct
fb_var_screeninfo *var, int con, struct fb_info
*info) 75行
<LI>static int anakinfb_set_var(struct
fb_var_screeninfo *var, int con, struct fb_info
*info) 111行
<LI>static int anakinfb_get_cmap(struct fb_cmap
*cmap, int kspc, int
con, struct fb_info
*info) 117行
<LI>static int anakinfb_set_cmap(struct fb_cmap
*cmap, int kspc, int
con, struct fb_info
*info) 130行
<LI>static int anakinfb_switch_con(int con,
struct fb_info *info) 147行
<LI>static int anakinfb_updatevar(int con,
struct fb_info *info) 155行
<LI>static void anakinfb_blank(int blank, struct
fb_info *info) 161行
<LI> int __init anakinfb_init(void)
178行</LI></OL>函数1,2是寄存器操作用。函数3,4,5,6,7是fb_ops函数。函数8用于切换控制台。函数9用于更新变量。函数10用于闪烁屏幕。函数11用于初始化设备。<BR>
很奇怪,对fb设备的读写函数怎么没有!值得说明的是open,release,read,write,ioctl,mmap等函数的实现是由
fbmem.c文件实现了。也就是说所有的fb设备在给定了fb_info后,所有的操作都是一样的。在明确的fb_info前提下,fbmem.c中的函数可以工作的很好。这样大家应该感到非常轻松了吧,只要完成上述的几个设备相关的函数,frame
buffer设备的驱动就写完了:) <BR>
系统的结构如图: <BR><A
href="http://www.dzkf.cn/upimg/allimg/0704/1_29133418.JPG"
target=_blank linkindex="23" set="yes"><IMG
style="WIDTH: 555px; HEIGHT: 233px" alt=""
src="[转载]Framebuffer驱动程序模型 - linux Dev - 逍遥游.files/1_29133418_lit.jpg"
border=0></A><BR><BR>
<P><STRONG>Stifb驱动模型<BR></STRONG>linux/drivers/video/stifb.c
- Generic frame buffer driver for HP *
workstations with STI (standard text interface)
video
firmware.<BR>这个驱动程序和前面的anakin设备完全不同,因为他不是采用标准的格式,而是根据
based on skeletonfb, which wasCreated 28 Dec 1997
by Geert Uytterhoeven也就是skeletonfb.c提供的框架完成的。</P>
<P>共230行,包含函数如下:</P>
<P><BR></P><BR>
<TABLE style="BORDER-COLLAPSE: collapse"
borderColor=#999999 cellSpacing=0 cellPadding=0
width="95%" bgColor=#f1f1f1 border=1>
<TBODY>
<TR>
<TD>
<P
style="MARGIN: 5px; LINE-HEIGHT: 150%"><CODE><SPAN
style="COLOR: rgb(0,0,0)"><SPAN
style="COLOR: rgb(0,0,204)"></SPAN><SPAN
style="COLOR: rgb(0,0,255)">static</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">int</SPAN>
sti_encode_fix<SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
fb_fix_screeninfo <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>fix<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">const</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">void</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>par<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
fb_info_gen <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>info<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN>
60行<BR><SPAN
style="COLOR: rgb(0,0,255)">static</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">int</SPAN>
sti_decode_var<SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,255)">const</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
fb_var_screeninfo <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>var<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN><SPAN
style="COLOR: rgb(0,0,255)">void</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>par<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
fb_info_gen <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>info<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN>
71行<BR><SPAN
style="COLOR: rgb(0,0,204)"></SPAN><SPAN
style="COLOR: rgb(0,0,255)">static</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">int</SPAN>
sti_encode_var<SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
fb_var_screeninfo <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>var<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">const</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">void</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>par<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> <SPAN
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -