Raspberry Pi raspberry: porting a 2.4-inch TFT display screen and source code analysis

Source: Internet
Author: User
With Raspberry Pi, but without an hdmi monitor, this is a pain point, but Raspberry Pi is Raspberry Pi, and his GPIO pin is where we can use our imagination. you can use its GPIO pins to drive a display. GOOGLE, this project has been prepared by a foreigner, and patch files are provided, which can be easily transplanted to the kernel. here I will record it here

With Raspberry Pi, but without an hdmi monitor, this is a pain point, but Raspberry Pi is Raspberry Pi, and his GPIO pin is where we can use our imagination. you can use its GPIO pins to drive a display. GOOGLE, this project has been prepared by a foreigner, and patch files are provided, which can be easily transplanted to the kernel. here I will record it here

With Raspberry Pi, but without an hdmi monitor, this is a pain point, but Raspberry Pi is Raspberry Pi, and his GPIO pin is where we can use our imagination. you can use its GPIO pins to drive a display. GOOGLE, this project has been prepared by a foreigner, and patch files are provided, which can be easily transplanted to the kernel. here I will record the process of porting this TFT driver, and then try to analyze the PATCH file provided by this foreigner, hoping to improve its own capabilities and be familiar with kernel porting.

Environment: ubuntu 13.10 (cross-compilation is set according to the previous article)

TFT: 2.4-inch 12864 interface ILI9325 master (purchased for AVR at that time)

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

The blogger has recently built his own blog and will use it more in the future. You are welcome to visit this blog. There are also many useful resources:

Http://www.embbnux.com/

References:

Http://spritesmods.com /? Art = rpi_arcade & page = 2

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

First, go to the image:


First, wiring

The P1 port is used:


TFT and P1 connections:

The above VCC is connected to 3.3 v, because my screen interface is 5 v, so I changed it to 5 v.

2. Add a TFT driver to the kernel

Compile the kernel environment as set in the previous article. I will not repeat it here.

Spritesmods.com /? Art = rpi_arcade & page = 2 diff files

Original download link: ili9325_gpio_driver_rpi.diff

You can also download it from my resources:

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

This patch is based on the 3.6 kernel. different versions of the kernel may be different. Just change it.

First, put the diff file under the kernel root directory, and the terminal enters the directory:

patch -p1 < ili9325_gpio_driver_rpi.diff

Then the source code of the TFT kernel is added to the kernel.

make menuconfig
You can see the ILI9325 option under device driver> graphics support> support for frame buffer, and select Y to add it to the kernel. in addition, BCM2708 framebuffer support is the original HDMI and AV display provided by Raspberry Pi.

make 
.

Test 3

Enter ssh to access Raspberry Pi

ls /dev/fb*

We can see fb0 and fb1. fb1 is my TFT.

Test:

cat /dev/urandom > /dev/fb1

If the screen displays a screen, it is successful.

How can Raspberry Pi be displayed on tft by default:

In make menuconfig, cancel the BCM2708 framebuffer support mentioned earlier, but it does not support HDMI.

3. Source File Analysis

View the diff file and we can see that the author has made four changes to the kernel.

1) added the ILI9325 platform definition in the arch/arm/mach-bcm2708/bcm2708.c File

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

2) modified the drivers/video/Kconfig file and added:

config FB_ILI9325tristate "ILI9325 connected to Raspberry Pi GPIO support"depends on FBselect FB_SYS_FILLRECTselect FB_SYS_COPYAREAselect FB_SYS_IMAGEBLITselect FB_SYS_FOPSselect FB_DEFERRED_IOhelp  This driver implements a framebuffer on an LCD controlled by a  ILI9325 (or compatible) controller connected to the GPIO of the   Raspberry Pi.

ILI9325 is available only when you declare and define this module in Kconfig in make menuconfig.

3) In drivers/video/Makefile, add:

obj-$(CONFIG_FB_ILI9325)  += ili9325.o

This module is compiled only when make menuconfig selects this module.


4) The ili9325.c file is created in the drivers/video/directory.

The code is long. Here we only look at the core code:

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 < 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;}}}

There are also a series of definition commands and initialization functions, mainly in line with the ILI9325 time series. like using the TFT on a single chip microcomputer, this function is mainly used to display and operate each pixel on the TFT.


4. With the display screen, make a small project of the camera display.

I have a USB-based UVC-driven camera, which is compatible with Raspberry Pi. for drivers of other driver chips, you only need to find the corresponding options in make menuconfig.

Plug in the usb camera and you can see that the video0 file is added under/dev. This is the camera.

Install mplayer:

sudo apt-get install mplayer

Then use mplayer to play the camera.

On the tft, click the terminal icon and enter the following command:

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

Then, the image of the camera is displayed on the tft:



This is the time to play.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.