Lib for ILI9486 - 3.5 inch 480x320 touch TFT for RPi

Working libraries, libraries being ported and related hardware
stevestrong
Posts: 1011
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Lib for ILI9486 - 3.5 inch 480x320 touch TFT for RPi

Postby stevestrong » Mon Dec 26, 2016 11:28 am

Hi all,

I was lately trying to improve some SPI functions (speed optimization). I mostly used the new SDfat beta and everything worked nicely.
But then I was told that my improvements have some problems on ILI9341-based displays so that I wanted to buy an SPI controlled display board.

In my searches for an appropriate board I realized that Arduino compatible 2.4 inch touch TFTs with SPI interface have almost the same price as 3.5 inch 480x320 touch TFT display modules for RPi. I decided to buy one of these.

As the board arrived, I had hard time by identifying the on-board controller as no register read functionality is available on the board, tried several init sequences from the net.
At the end I figured out it must be an ILI9486.
This board contains a serial->parallel conversion circuit, the ILI9486 is actually set up for 16 bit parallel write-only interface.

I decided to write an Adafruit-compatible library, and I took the ILI9341 lib from our repo as starting point.

And here it is a very first working version.

Using a graphic test sketch I could evaluate the performance of 16 bit writing at 36MHz SPI clock speed.

And this is the result:

Code: Select all

***** ILI9486 graphic Test *****

************************************************
Without DMA:
************************************************
Benchmark                Time (microseconds)
Screen fill              342137
Text                     49898
Lines                    544406
Horiz/Vert Lines         30606
Rectangles (outline)     19241
Rectangles (filled)      834795
Circles (filled)         298164
Circles (outline)        429518
Triangles (outline)      111944
Triangles (filled)       361198
Rounded rects (outline)  130705
Rounded rects (filled)   960236
Done!

************************************************
Now using DMA:
************************************************
Benchmark                Time (microseconds)
Screen fill              341513
Text                     52079
Lines                    613614
Horiz/Vert Lines         31325
Rectangles (outline)     20255
Rectangles (filled)      833456
Circles (filled)         352232
Circles (outline)        429516
Triangles (outline)      136594
Triangles (filled)       386043
Rounded rects (outline)  131725
Rounded rects (filled)   973679
Done!


Yes, the actual DMA-less SPI version is (mostly) faster than the DMA version!!!

SPI_16b_compare.jpg
SPI_16b_compare.jpg (56.2 KiB) Viewed 1106 times


The main reasons is that the DMA version has an overhead to initialize the DMA registers.
In addition, the DMA-less version is highly speed optimized so that there are no clock gaps between two consecutive data transfers.

This test only refers to the 16 bit transfer - which is used to transfer pixel data. I didn't compare yet the situation for 8 bit transfer (needs different setup), in which case the result, I assume, will look different.

I further plan to compare this lib to my 8 bit parallel lib and see which functions could i further improve (increase execution speed).
Any comment/suggestion is welcome.
Last edited by stevestrong on Tue Dec 27, 2016 10:35 am, edited 11 times in total.

User avatar
ahull
Posts: 1469
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: Lib for ILI9486 - 3.5 inch 480x320 touch TFT for RPi

Postby ahull » Mon Dec 26, 2016 12:01 pm

:D Nice.

There are a bunch of HVGA screens around, but I've never taken the plunge and actually bought one.
I was looking at this, but it is unclear what controller is on it, but I suspect that it too uses the LI9486.

Its interesting to see that the SPI only versions are actually relatively fast. I would have thought parallel would confer some major speed advantages, but evidently they are in the same general ball park. That SPI with DMA is no advantage until you to things like block fills makes some sense though.

Maybe I need to rename the $10 pig-o-scope as the £10 pig-o-scope and upgrade from QVGA to HVGA :) after all, I have tried a smaller 1.4" screen and that works, so why not go large.
Last edited by ahull on Mon Dec 26, 2016 12:10 pm, edited 1 time in total.
- Andy Hull -

stevestrong
Posts: 1011
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Lib for ILI9486 - 3.5 inch 480x320 touch TFT for RPi

Postby stevestrong » Mon Dec 26, 2016 12:10 pm

Your board looks slightly different, it may use the same controller, or alternatively the HX8375 lib from Adafruit.

michael_l
Posts: 318
Joined: Mon Aug 24, 2015 6:11 pm

Re: Lib for ILI9486 - 3.5 inch 480x320 touch TFT for RPi

Postby michael_l » Mon Dec 26, 2016 12:33 pm

stevestrong: nice work! Is this as fast as ILI9431_STM for STM32F1 with DMA or even faster?

I was wondering is the detection init sequence different for every chip?

stevestrong
Posts: 1011
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Lib for ILI9486 - 3.5 inch 480x320 touch TFT for RPi

Postby stevestrong » Mon Dec 26, 2016 2:45 pm

michael_l wrote:Is this as fast as ILI9431_STM for STM32F1?

i don't know, I don't have any other benchmark for a 480x320 resolution (ILI9341 or other) SPI driven TFT board.

michael_l wrote:I was wondering is the detection init sequence different for every chip?

Yes, although some controller ICs use same register addresses for basic settings, the rest of registers may be different.
Last edited by stevestrong on Mon Dec 26, 2016 9:32 pm, edited 1 time in total.

User avatar
RogerClark
Posts: 5589
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Lib for ILI9486 - 3.5 inch 480x320 touch TFT for RPi

Postby RogerClark » Mon Dec 26, 2016 8:04 pm

Thanks @stevestrong

I will download and test your latest code.

Its interesting that DMA is now slower in most cases. But we haver never been using DMA for its real purpose, which is allow the CPU to do something else while the transfer is running.

Ideally we should have non blocking DMA functions as well as blocking ( this could be done via an optional parameter)

Also, the nature of the ILI9341 SPI commands e.g to set individual pixels by sending address then value, is very inefficient, especially as the default Adafruit library does not buffer these transfers into one larger SPI transfer.

I think Paul rewrote huge chunks of the Adafruit code for use on the Teensy, and added buffering to achieve much higher speeds, but for most people what we currently have is adequate, hence no one needed to do the same thing with our version.

david.prentice
Posts: 75
Joined: Wed Nov 16, 2016 8:52 am

Re: Lib for ILI9486 - 3.5 inch 480x320 touch TFT for RPi

Postby david.prentice » Mon Dec 26, 2016 10:17 pm

It seems an incredibly complicated way of driving a Display.

Most TFT controllers can be configured for 8-bit SPI. The minimum write-cycle is marginally faster with 8080 parallel-interface. The minimum read-cycle is faster with SPI than parallel. OTOH, SPI is easily controlled with DMA.

You can calculate the "best" time for any graphics operation by the datasheet cycle times.
Of course most graphics require software calculations. The STM32 can calculate while the bus traffic is handled by DMA.

The STM32 requires "slowing down" when you use 8080-parallel interface. You cannot drive an 8080 interface with DMA. So you can't calculate and drive the bus at the same time.

Mind you, if the RPi display is converting SPI to 8080-16bit parallel in hardware, DMA should work just fine.

David.

stevestrong
Posts: 1011
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Lib for ILI9486 - 3.5 inch 480x320 touch TFT for RPi

Postby stevestrong » Mon Dec 26, 2016 10:30 pm

As far as I know, RPi drives the display as "frame buffer". It means, it has a complete image buffer in RAM and writes it as a whole frame always all over again with high speed to the display. So it does not need to change the window coordinates, no switch between command and data select. That's why it can really work with DMA.
But we cannot allow us this luxury, RAM is limited. So the biggest challange is how to optimize command and data selection.
I have some aproaches in my mind, the buffering could be implemented with not too much effort, have to check Paul's version.

User avatar
RogerClark
Posts: 5589
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Lib for ILI9486 - 3.5 inch 480x320 touch TFT for RPi

Postby RogerClark » Tue Dec 27, 2016 10:03 am

@stevestrong

I tested the latest SPI updates and they seem OK, but please check your repo is up to date, as it looks like the changes to boards.txt and possibly others have not been pulled from my master HEAD to your fork.

Thanks

Roger

stevestrong
Posts: 1011
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Lib for ILI9486 - 3.5 inch 480x320 touch TFT for RPi

Postby stevestrong » Tue Dec 27, 2016 10:59 am

Roger, I did update and sync my repo, so it should be ok now.

Btw, I further increased a bit the speed by reducing the window address setting part by 50% (from 18 us down to 8 us). I am now using entirely 16 bit accesses for register settings, too, without DMA.

Code: Select all

***** ILI9486 graphic Test *****

************************************************
Benchmark                Time (microseconds)
Screen fill              342102
Text                     42270
Lines                    456059
Horiz/Vert Lines         30056
Rectangles (outline)     18507
Rectangles (filled)      834569
Circles (filled)         259954
Circles (outline)        351849
Triangles (outline)      94697
Triangles (filled)       343390
Rounded rects (outline)  109572
Rounded rects (filled)   949488
Done!

The improvement is more significant on test which involve lot of single pixel writing.

My biggest problem is that the display is corrupted at 36MHz :( But works fine at 18 MHz.
It seems that the 10 cm wires from my blue pill to display board are too long, so I have to mount the pill onto or very close the display board somehow to reduce wire length.
Last edited by stevestrong on Thu Dec 29, 2016 10:41 pm, edited 1 time in total.


Return to “Libraries & Hardware”

Who is online

Users browsing this forum: No registered users and 1 guest