基于树莓派raspberry: 移植 2.4寸TFT显示屏以及源码分析

有了树莓派,但是没有hdmi显示器,这是个蛋疼的事,但是树莓派就是树莓派,他的GPIO管脚就是我们发挥想象力的地方.可以通过它的GPIO管脚来驱动一个显示屏.GOOGLE了一下,这个项目有个老外做好了,而且提供了patch文件,很容易就能移植到内核里面去.这里我就在这里记录一下移植这个TFT驱动的过程,然后试着分析这个老外提供的PATCH文件,希望能从中提高自己的能力,也能够熟悉一下内核的移植.

环境: ubuntu 13.10 (交叉编译按前面的文章设置)

TFT : 2.4寸 12864接口 ILI9325主控 (当时叉宝买来给AVR用的)

个人原创,转载请注明原文出处:

http://blog.csdn.net/embbnux/article/details/17394793

参考文章:

http://spritesmods.com/?art=rpi_arcade&page=2

http://www.blogjava.net/baicker/archive/2012/12/18/392829.html

首先上张图:

20131218163153734

一 首先是接线

用的是P1口:

raspberry_gpio

 

TFT与P1连线:

20131218155640953

这个上面的VCC接的是3.3v,因为我的屏幕接口是5v,所以我给改成5v了.

二 添加TFT驱动到内核

编译内核的环境,就按之前的文章设置,这里不再复述.

用的是spritesmods.com/?art=rpi_arcade&page=2提供的diff文件

原下载链接: ili9325_gpio_driver_rpi.diff

也可以到我的资源下载:

http://download.csdn.net/detail/canyue102/6735059

这个补丁是基于3.6内核的,不同版本的内核可能不一样,自己改一下就好了.

首先把 该diff文件放到内核根目录下,终端进去该目录:


    patch -p1 < ili9325_gpio_driver_rpi.diff
   

然后TFT内核源码就被添加到内核去了.

    make menuconfig
  

可以在device driver >> graphics support >> support for frame buffer 下看到ILI9325选项,Y选中它就把它添加进内核.另外的BCM2708 framebuffer support就是原来树莓派自带的HDMI和AV显示.


    make
  

就编译好了,把它按上一篇的方法放到SD卡上去运行,就可以了.

三 测试

进入ssh进入树莓派


    ls /dev/fb*

可以看到有fb0 和 fb1, fb1 就是我的TFT.

测试:

    cat /dev/urandom > /dev/fb1

如果屏幕出现花屏那就是成功了.

那要如何树莓派默认显示在tft上:

在make menuconfig里面把刚才说到的BCM2708 framebuffer support取消掉就可以了,不过就不支持HDMI了

三 源文件分析

查看该diff文件可以看出作者对内核做了四处改动

1 ) 在 arch/arm/mach-bcm2708/bcm2708.c文件中添加了ILI9325 平台定义


    static struct platform_device bcm2708_ili9325 = {
        .name = "ili9325",
        .id = 0,
    };
    /*************************/
    bcm_register_device(&bcm2708_ili9325);

2 ) 修改了 drivers/video/Kconfig 文件,添加:

    config FB_ILI9325
        tristate "ILI9325 connected to Raspberry Pi GPIO support"
        depends on FB
        select FB_SYS_FILLRECT
        select FB_SYS_COPYAREA
        select FB_SYS_IMAGEBLIT
        select FB_SYS_FOPS
        select FB_DEFERRED_IO
        help
          This driver implements a framebuffer on an LCD controlled by a
          ILI9325 (or compatible) controller connected to the GPIO of the
          Raspberry Pi.

只有在Kconfig 中声明定义该模块,在make menuconfig 中才看得到ILI9325选项

3 ) 在 drivers/video/Makefile 添加:


    obj-$(CONFIG_FB_ILI9325)          += ili9325.o

只有加了这句话,在make menuconfig选中该模块后,make时,该模块才会被编译

4) 在drivers/video/目录下新建了 ili9325.c文件

代码比较长,这里只看核心代码:


    static void ili9325_copy(struct ili9325 *item, unsigned int index)
    {
        unsigned short x;
        unsigned short y;
        unsigned short *buffer;
        unsigned short *oldbuffer;
        unsigned int len;
        unsigned int count;
        int sendNewPos=1;
        x = item->pages[index].x;
        y = item->pages[index].y;
        buffer = item->pages[index].buffer;
        oldbuffer = item->pages[index].oldbuffer;
        len = item->pages[index].len;
        dev_dbg(item->dev,
            "%s: page[%u]: x=%3hu y=%3hu buffer=0x%p len=%3hun",
            __func__, index, x, y, buffer, len);

        //Only update changed pixels in the page.
        for (count = 0; count < len; count++) {
            if (buffer[count]==oldbuffer[count]) {
                sendNewPos=1;
            } else {
                if (sendNewPos) {
                    ili9325_setptr(item, x, y);
                    sendNewPos=0;
                }
                ili9325_writeword(buffer[count], 1);
                oldbuffer[count]=buffer[count];
            }
            x++;
            if (x>=item->info->var.xres) {
                y++;
                x=0;
            }
        }
    }

前面还有一系列定义命令和初始化的函数,主要是得符合ILI9325的时序.和单片机上使用该TFT一样,这里的这个函数,主要用来显示,操作TFT上的每一个像素点.

四 有了显示屏那就做个摄像头显示的小项目

我正好有一个USB接口的UVC驱动的摄像头,树莓派兼容的,其他驱动芯片的驱动只要在make menuconfig里面找到相应选项就可以了.

插上usb摄像头,可以看到/dev下多了video0文件,这个就是摄像头了.

装个mplayer:


    sudo apt-get install mplayer

然后用mplayer 播放该摄像头

在tft上用鼠标点击终端图标,输入命令:


    mplayer tv:// -tv driver=v4l2:width=320:height=240:device=/dev/video0

然后就在tft上显示摄像头的图像:

20131218165510203

就到这里吧,有空再玩.

《基于树莓派raspberry: 移植 2.4寸TFT显示屏以及源码分析》上有3条评论

  1. 你好,我按照你的博客介绍,做到打补丁这一步出错,提示如下
    root@raspberrypi:/home/pi/work/raspberrypi_src/linux# dir
    arch config.gz crypto firmware include Kbuild lib mm REPORTING-BUGS security usr
    block COPYING Documentation fs init Kconfig MAINTAINERS net samples sound video
    certs CREDITS drivers ili9325_gpio_driver_rpi.diff ipc kernel Makefile README scripts tools virt
    root@raspberrypi:/home/pi/work/raspberrypi_src/linux# patch -p1 < ili9325_gpio_driver_rpi.diff
    patching file arch/arm/mach-bcm2708/bcm2708.c
    Hunk #1 FAILED at 296.
    Hunk #2 FAILED at 691.
    2 out of 2 hunks FAILED — saving rejects to file arch/arm/mach-bcm2708/bcm2708.c.rej
    patching file drivers/video/Kconfig
    Hunk #1 FAILED at 2303.
    1 out of 1 hunk FAILED — saving rejects to file drivers/video/Kconfig.rej
    patching file drivers/video/Makefile
    Hunk #1 FAILED at 144.
    1 out of 1 hunk FAILED — saving rejects to file drivers/video/Makefile.rej
    The next patch would create the file drivers/video/ili9325.c,
    which already exists! Assume -R? [n]
    Apply anyway? [n]
    Skipping patch.
    1 out of 1 hunk ignored

    求救!!

回复 禅猫 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Time limit is exhausted. Please reload the CAPTCHA.

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据