Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-07 15:24:48
Original
1852 people have browsed it

有了树莓派,但是没有hdmi显示器,这是个蛋疼的事,但是树莓派就是树莓派,他的GPIO管脚就是我们发挥想象力的地方.可以通过它的GPIO管脚来驱动一个显示屏.GOOGLE了一下,这个项目有个老外做好了,而且提供了patch文件,很容易就能移植到内核里面去.这里我就在这里记

        有了树莓派,但是没有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://www.embbnux.com/

参考文章:

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

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

首先上张图:

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

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

一  首先是接线

      用的是P1口:

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

       TFT与P1连线:

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

    这个上面的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 <br>
      然后TFT内核源码就被添加到内核去了.  <br>

<p></p>
<pre class="brush:php;toolbar:false">make menuconfig
Copy after login
     可以在device driver >> graphics support >> support for frame buffer 下看到ILI9325选项,Y选中它就把它添加进内核.另外的BCM2708 framebuffer support就是原来树莓派自带的HDMI和AV显示.

make 
Copy after login
   .

三  测试

     进入ssh进入树莓派

   

ls /dev/fb*
Copy after login

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

测试:

cat /dev/urandom > /dev/fb1
Copy after login

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

 那要如何树莓派默认显示在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);
Copy after login

  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.
Copy after login

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

   3 ) 在 drivers/video/Makefile 添加:

 

obj-$(CONFIG_FB_ILI9325)		  += ili9325.o
Copy after login

    只有加了这句话,在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=%3hu\n",
		__func__, index, x, y, buffer, len);

	//Only update changed pixels in the page.
	for (count = 0; count =item->info->var.xres) {
			y++;
			x=0;
		}
	}
}
Copy after login

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


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

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

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

     装个mplayer:

   

sudo apt-get install mplayer
Copy after login

    然后用mplayer 播放该摄像头

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

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

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

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

     

就到这里吧,有空再玩.



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!