juj
Posts: 26
Joined: Sat Nov 18, 2017 10:51 pm

Fast refresh rates up to 60fps with an SPI display (ILI9341)

Mon Nov 20, 2017 9:24 pm

Hi all,

if you're like me, you may have gotten excited about some DIY handheld games console projects packages out there when you first stumbled to that corner of the web, got the parts, and built the kit.

What they did not mention was that the display the kit came with was a SPI-based one, and as result you're getting 5fps or 10fps or at best 16fps or similar. I was there, and like the rest of you, disappointed by the fact that these displays even exist, and then readily ordered a $20 HDMI display to replace the $15 SPI one, and problem solved.

The slow as crap SPI display was then sitting without function in the corner of my work desk, such a shame, I thought. So I dug a bit deeper into the issue, and last weekend wrote my own display driver for the ILI9341 based display that I have.

You can check out the results of the project at Github: https://github.com/juj/fbcp-ili9341, and a video demo at YouTube: https://youtu.be/h1jhuR-oZm0.

This was a proof of concept project - even with the success, I wholeheartedly recommend people stick to HDMI, since using a generic purpose CPU to run the chore of a dedicated function GPU chip just takes away the precious CPU cycles elsewhere.

Although if you are running an SPI-based display for some reason over a HDMI based one, and are using a "framebuffer cloning" method to display its contents, I'd recommend posting a friendly message or a +1 in this GitHub issue https://github.com/raspberrypi/userland/issues/440 to give more weight to the issue if you think it's worth solving. If that gets resolved, then it's possible that stutter free high refresh rates on SPI-based displays could be developed to become quite power efficient on the Pi.

Hope you liked this!

Domarius
Posts: 28
Joined: Sat Oct 14, 2017 1:44 am

Re: Fast refresh rates up to 60fps with an SPI display (ILI9341)

Wed Nov 22, 2017 10:17 pm

Wow OK, are you saying that if I use a display that connects via HDMI, it will be offloading some work (scaling, maybe?) to the actual display, than if I connected directly via the GPIO pins?

What do you think about this display? Will it be better to use it's HDMI port rather than the GPIO pin connection?
https://raspberry.piaustralia.com.au/li ... -5-display

juj
Posts: 26
Joined: Sat Nov 18, 2017 10:51 pm

Re: Fast refresh rates up to 60fps with an SPI display (ILI9341)

Thu Nov 23, 2017 4:32 pm

That's exactly right - if a display is connected to the HDMI, then the VideoCore GPU uses its internal dedicated circuitry to schedule sending the image frames over to the HDMI attached display, and the main CPU does not have to take part in this. When the display is connected to the GPIO pins, then the pixels need to be uploaded by the main CPU and the associated BCM2835 peripheral chip. The BCM2835 chip can do most of the lowest level bit pushing, but it needs the main CPU to feed it periodically at a high rate, so that taxes the CPU of the Pi.

The linked display seems to connect to both HDMI and GPIO port at the same time, so I don't think there's a choice of which one to use. It looks like the HDMI port is used for the display data, and the GPIO pins are used only to receive touch input and to get power to the display. I don't think that display data will go through the GPIO pins, so that display should have better performance than GPIO (SPI) based one.

Domarius
Posts: 28
Joined: Sat Oct 14, 2017 1:44 am

Re: Fast refresh rates up to 60fps with an SPI display (ILI9341)

Fri Nov 24, 2017 3:16 am

I am so glad I talked to you. I was about to post a question last night about this display, but wasn't really sure what to ask actually (wasn't sure if I'd be using the GPIO pins or the HDMI, and it would affect my design) I just happened to open the thread because I'm generally interested in making sure I get a good frame rate on these emulated DOSBox and Amiga games I intend to be running. Decided instead to post here and wait and see what you said. Your two posts have been eye opening.

Also the people hosting the raspberry pi Australia site seem pretty useless at answering Pi questions (ironic seeing as they're touting themselves as the go-to for Pi hardware in Australia) so yeah, it's awesome to get a clear explanation. Never imagined I'd be using both the GPIO and the HDMI at the same time. Hmm this is going to make my design awkward if I want to retain access to the other ports externally to the case, but I'll come up with something I guess!

juj
Posts: 26
Joined: Sat Nov 18, 2017 10:51 pm

Re: Fast refresh rates up to 60fps with an SPI display (ILI9341)

Fri Dec 01, 2017 7:25 pm

Uploaded an updated version with better performance and a performance statistics overlay view. A new video can be found at https://www.youtube.com/watch?v=rKSH048XRjA.

User avatar
bitbank
Posts: 248
Joined: Sat Nov 07, 2015 8:01 am
Location: Sarasota, Florida
Contact: Website

Re: Fast refresh rates up to 60fps with an SPI display (ILI9341)

Sat Dec 02, 2017 2:43 pm

I've been working on this same problem and encountered many of the same issues. The solution that many people are looking for is one that will work well with the RPI0. The problem is that a single CPU core is going to spend most of its time communicating with the display and hold up the game emulator. My solution has been to write my own game emulators and integrate them with the code which talks to the display. By using a dirty tile system and no time wasted guessing when the display update is ready, it makes for a much better experience with no input or output lag. I haven't tried doing interlaced updates, but the idea sounds interesting. The other issue is the 2 step stretching and shrinking which occurs with the FBTFT+FBCP combination. This ends up distorting the pixels and wasting precious time.

Here's a sample of my Genesis emulator running on the ili9341:

https://www.youtube.com/watch?v=0ox6p5-im7c

It gets a framerate of 30-60fps, but keeps input and output lag to a minimum even during high CPU usage parts. The source code to my SPI LCD code is here:

https://github.com/bitbank2/SPI_LCD

I'll be releasing (some) of my game emulator code as open source shortly.

I also did an experiment to replace FBCP here:

https://github.com/bitbank2/BB-CP

It works well on a multi-core machine, but struggles with high CPU usage on the RPi0 because the SPI code (PIGPIO) is waiting to transmit each byte and doesn't yield the thread until it finishes the whole block.
The fastest code is none at all :)

Domarius
Posts: 28
Joined: Sat Oct 14, 2017 1:44 am

Re: Fast refresh rates up to 60fps with an SPI display (ILI9341)

Sat Dec 02, 2017 9:32 pm

Is there an advantage to using an SPI screen over an HDMI one, or is it just a technical challenge to get it running fast?

User avatar
bitbank
Posts: 248
Joined: Sat Nov 07, 2015 8:01 am
Location: Sarasota, Florida
Contact: Website

Re: Fast refresh rates up to 60fps with an SPI display (ILI9341)

Sat Dec 02, 2017 10:07 pm

Domarius wrote:
Sat Dec 02, 2017 9:32 pm
Is there an advantage to using an SPI screen over an HDMI one, or is it just a technical challenge to get it running fast?
It has to do with cost, power usage and availability. I haven't found any 320x240 2.8" HDMI screens. The small HDMI screens that are available cost a lot more and use a lot of power. A 2.8" ILI9341 without the prototyping PCB attached can cost as little as $4 retail (single piece). I've purchased several for $7.50 each shipped from China (with PCB and SD card slot).
The fastest code is none at all :)

Domarius
Posts: 28
Joined: Sat Oct 14, 2017 1:44 am

Re: Fast refresh rates up to 60fps with an SPI display (ILI9341)

Sat Dec 02, 2017 10:15 pm

Ah good point, yes it does seem all the cute tiny screens are GPIO only now that you mention it. Good luck with your endeavours guys. Having a super tiny arcade etc. was one of the projects that appealed to me a while back but isn't my current project. I actually bought a 2 inch "rear view camera" display that takes a standard video RCA, back when the original Pi was out (but never got round to the project). I suppose that would have worked but not as good video quality.

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 11 guests