新的framebuff驱动核心思想是:直接操作显示区域,需要自己写的framebuff驱动里没有画点、画圆、显示字符、显示汉字等的具体操作。这些操作在framebuff驱动框架里已经实现,无需自己编写。下面记录下framebuff驱动的编写过程,lcd硬件部分仅保留修改lcd显示区的IO映射和数据写入即可。
手上这款lcd自带控制器,只能通过读写其提供寄存器和他交互数据,不能直接映射他的显示区域。所以我在驱动里申请了2个和lcd显示缓冲区一样大小的内存,一个用于模拟framebuff驱动需要的共享内存区域,另一个用来保存这个模拟共享区域的快照,用于比对共享区域的变化。当检测到共享内存区域的变化后,将这个变化通过lcd的寄存器写给lcd,这样就能实现共享区域的变化能被同步反映到lcd设备上。
在内核的drivers/video/目录下有很多fb设备的驱动,我找了个简单的dnfb.c作为参考,以他为蓝本实现我的驱动。首先修改drivers/video下Kconfig,添加:
config FB_DISPLAY
tristate“WHZYDZ lcd support”
depends on FB && ARM
select FB_CFB_FILLRECT
select FB_CFB_COPYAREA
select FB_CFB_IMAGEBLIT
接着修改Makefile,添加:
obj-$(CONFIG_FB_DISPLAY) += zydz_fb.o
我们在zydz_fb.c中来写驱动代码,首先要完成显示区域的变化如何写入到设备,这个虽不是framebuff驱动本身特有的,但其作为最基本的一环,必须先实现。原系统平台的相关驱动可以借鉴。原来的驱动代码是先定位到lcd显示缓冲的行首,然后一个字节一个字节的写,直到写完一行的数据,其中位置光标自动右移。但在我这,一行点位根本显示不全,我们用的是RA9935A,我怀疑它在控制自动移位方面可能存在问题。后来我改变写数据的方式:自己控制位置光标,然后写一个字节!这样能正常显示了。
接先来就是和MiniGUI联调,边调边修改我的驱动。MinGUI得使用shadow引擎才能支持8bpp以下的。重新编译minigui,configure 时加上--enable-newgal
--enable-videoshadow
--with-targetname=fbcon
MiniGUI.cfg配置文件修改如下:
[system]
# GAL engine and default options
gal_engine=shadow
defaultmode=320x240-1bpp
[shadow]
real_engine=fbcon
经过n次的测试,主要方法是在MinGUI中增加打印信息,根据输出信息判断出错的位置,然后修改驱动。最后跟到了src/newgal/video.c的int GAL_VideoModeOK (int width, int height, int bpp, Uint32 flags)函数,
里面有段注释和代码看了,让人心凉了一大节!
/* Currently 1 and 4 bpp are not supported */
if ( bpp 《 8 || bpp 》 32 ) {
return(0);
}
看来MinGUI1.6.10是不支持位深小于8的屏了。我尝试着注释掉了这段代码,以便让MinGUI能完成初始化的工作。接着出现下面的错误:
Linux_fbcon fb_fix.line_length=40
Linux_fbcon fbcon_info.yres=240
Linux_fbcon fbcon_info.fb_size=12288
Linux_fbcon fbcon_info.fb=40021000
Linux_fbcon fbcon_info.bpp=1
GAL_GetVideoMode 1
width=320
height=240
bpp=1
Unhandled fault: external abort on non-linefetch (0x008) at 0x40021000
Bus error
查看linux_fbcon.c:
fbcon_info.fb =
#ifdef _FXRM9200_IAL /* workaround for Fuxu RM9200 */
mmap (NULL, fbcon_info.fb_size, PROT_READ | PROT_WRITE, MAP_SHARED,
fbcon_info.fd_fb, 0);
#elif defined (__uClinux__)
mmap (NULL, fbcon_info.fb_size, PROT_READ | PROT_WRITE, 0,
fbcon_info.fd_fb, 0);
#else
mmap (NULL, fbcon_info.fb_size, PROT_READ | PROT_WRITE, MAP_SHARED,
fbcon_info.fd_fb, 0);
#endif
这个使用到了framebuff驱动的mmap调用,再查看drivers/video/Fbmem.c默认的fb_mmap函数:
/* frame buffer memory */
start = info-》fix.smem_start;
len = PAGE_ALIGN((start & ~PAGE_MASK) + info-》fix.smem_len);
他会将info-》fix.smem_start这个物理地址进行映射。好了,framebuff驱动里面我们可以使用virt_to_phys获取共享内存区域的物理地址!
自此,edit例程总算运行起来了!显示效果见下图:
显示效果不理想,MiniGUI还是用在8bpp以上屏上合适!,下面贴上主要的代码:
* linux/drivers/video/zyd***b.c -- ZYDZ graphics adaptor frame buffer device
*
* Created 16 Sep2011 by hongchang.yu(yu_hongchang@163.com)
* Based on dnfb.c
*
* History:
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive
* for more details.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define lcd_WIDTH 320
#define lcd_HEIGHT 240
#define DISPRAMBUFLSZ (lcd_WIDTH/8)
#define DISPRAMBUFSIZE (DISPRAMBUFLSZ*lcd_HEIGHT)
/* display_ video definitions */
static void __iomem *io_data=NULL;
static void __iomem *io_cmd=NULL;
static void __iomem *io_ctrl=NULL;
static unsigned long ioo_data=0;
static unsigned char *rambuf_org = NULL;
static unsigned char *rambuf_cur = NULL;
/* frame buffer operations */
// zyd***b_blank控制屏幕开关
static int zyd***b_blank(int blank, struct fb_info *info);
static struct fb_ops zyd***b_ops = {
.owner = THIS_MODULE,
//.fb_blank = zyd***b_blank,
.fb_fillrect = cfb_fillrect,
.fb_copyarea = cfb_copyarea,
.fb_imageblit = cfb_imageblit,
};
struct fb_var_screeninfo zyd***b_var __devinitdata = {
.xres = 320,//实际x轴分辨率
.yres = 240,//实际y轴分辨率
.xres_virtual = 320,//虚拟x轴分辨率
.yres_virtual = 240,//虚拟y轴分辨率
.bits_per_pixel= 1, //定义每个点用多少位表示
.height = -1,
.width = -1,
//.vmode = FB_VMODE_NONINTERLACED,
};
static struct fb_fix_screeninfo zyd***b_fix __devinitdata = {
.id = “zyd***b”,//设备名称
.type = FB_TYPE_PACKED_PIXELS,
.visual = FB_VISUAL_MONO01 ,/* Monochr. 1=Black 0=White */
.line_length = DISPRAMBUFLSZ,
};
/*
* Initialization
*/
static int __devinit zyd***b_probe(struct platform_device *dev)
{
struct fb_info *info;
int err = 0;
info = framebuffer_alloc(0, &dev-》dev);
if (!info)
return -ENOMEM;
info-》fbops = &zyd***b_ops;
info-》fix = zyd***b_fix;
info-》fix.smem_start = virt_to_phys(rambuf_cur);
info-》fix.smem_len = DISPRAMBUFSIZE;
info-》var = zyd***b_var;
/* Virtual address */
info-》screen_base = rambuf_cur;
info-》screen_size = DISPRAMBUFSIZE;
err = fb_alloc_cmap(&info-》cmap, 2, 0);
if (err 《 0) {
framebuffer_release(info);
return err;
}
err = register_framebuffer(info);
if (err 《 0) {
fb_dealloc_cmap(&info-》cmap);
framebuffer_release(info);
return err;
}
platform_set_drvdata(dev, info);
/* now we have registered we can safely setup the hardware */
printk(“display_ frame buffer alive and kicking ! ”);
retu
return err;
}
void disp_init( )
{
static int inited=0;
if(inited)return;
io_data=ioremap_nocache(lcd_DATA_PORT,32);
io_cmd=ioremap_nocache(lcd_CTRL_PORT,32);
io_ctrl=ioremap_nocache(lcd_PERH_PORT,32);
rambuf_org = kmalloc(DISPRAMBUFSIZE,GFP_KERNEL);
rambuf_cur = kmalloc(DISPRAMBUFSIZE,GFP_KERNEL);
lcd_reset();
inited=1;
}
unsigned char re_uc(unsigned char x)
{
x = (x&0x0f)《《4 |(x&0xf0)》》4;
x = (x&0x33)《《2 |(x&0xcc)》》2;
x = (x&0x55)《《1 |(x&0xaa)》》1;
return x;
}
static struct timer_list timer_key;
void fb_timer_func(unsigned long pa)
{
int i;
for(i=0;i
{
if(rambuf_org[i]!=rambuf_cur[i])
{
WritelcdCmd(SRCSET_CMD);
WritelcdData(i%0x100);
WritelcdData(i/0x100);
WritelcdCmd(MEMWRITE_CMD);
WritelcdData(re_uc(rambuf_cur[i]));
rambuf_org[i]=rambuf_cur[i];
}
}
mod_timer(&timer_key,jiffies+20);
}
static struct platform_driver zyd***b_driver = {
.probe = zyd***b_probe,
.driver = {
.name = “zyd***b”,
},
};
static struct platform_device zyd***b_device = {
.name = “zyd***b”,
};
int __init zyd***b_init(void)
{
int ret,i,j;
disp_init( );
ret = platform_driver_register(&zyd***b_driver);
if (!ret) {
ret = platform_device_register(&zyd***b_device);
if (ret)
platform_driver_unregister(&zyd***b_driver);
}
init_timer(&timer_key);
timer_key.function=&fb_timer_func;
timer_key.expires=jiffies+10;
timer_key.data = 0;
add_timer(&timer_key);
return ret;
}
static void __exit zyd***b_exit(void)
{
del_timer(&timer_key);
platform_device_unregister(&zyd***b_device);
platform_driver_unregister(&zyd***b_driver);
if (rambuf_org)
kfree(rambuf_org);
if (rambuf_cur)
kfree(rambuf_cur);
}
module_init(zyd***b_init);
module_exit(zyd***b_exit);
MODULE_LICENSE(“GPL”);
评论
查看更多