vindar
Well-known member
Hello,
I have been happily using (and abusing) user-contributed libraries for a few years now so I think it is time I try to give something back... So here is my SPI driver for the ubiquitous ILI9341 screen:
[github: ILI9341_T4]
I know there are already several good libraries for driving this screen (such as KurtE's ILI9341_t3n lib) but I think my library adds a few neat tricks that makes it unique.
First, a warning: the library's sole purpose is to push memory frame buffers to the screen as fast and as efficiently as possible. The library does not contain any drawing primitive of any kind. These are to be handled by a dedicated canvas library drawing on the memory frame buffer. Also, this library only works with Teensy 4/4.1. Using multi-buffers requires lots of RAM so it would not really make sense to adapt it to less powerful MCU...
Here are the library's main features:
In practice, the library makes it simple to achieve a high frame rate combined with a high quality display. But of course, there is no such thing as a free launch and the price to pay is large RAM consumption: around 320Kb when using double buffering.
The library is still in beta and there are certainly many bugs to be found but it already does the job quite nicely. The screen tearing prevention is really fun to observe: if you blit 2 colors alternatively fast enough, they will simply simply melt into one instead of making an awful mess... There is a demo of this in the example folder of the library [and you can check the code: the violet color displayed on the screen is never uploaded to the screen ^^].
I did not write a separate documentation for the library but the code itself is pretty well documented. Info about public methods can be found in the header file in front of their declarations.
I hope someone find this library useful !
Best,
I have been happily using (and abusing) user-contributed libraries for a few years now so I think it is time I try to give something back... So here is my SPI driver for the ubiquitous ILI9341 screen:
[github: ILI9341_T4]
I know there are already several good libraries for driving this screen (such as KurtE's ILI9341_t3n lib) but I think my library adds a few neat tricks that makes it unique.
First, a warning: the library's sole purpose is to push memory frame buffers to the screen as fast and as efficiently as possible. The library does not contain any drawing primitive of any kind. These are to be handled by a dedicated canvas library drawing on the memory frame buffer. Also, this library only works with Teensy 4/4.1. Using multi-buffers requires lots of RAM so it would not really make sense to adapt it to less powerful MCU...
Here are the library's main features:
- smart 'diff' redraw. The driver compares the frame buffer to be uploaded with the previous one (mirroring the current screen content) and uploads (almost) only the pixels that differ. It does so in a smart way to minimize SPI transaction / RAWRW commands. Uploading only part of the screen makes it possible to achieve extremely high frame rates when moderate changes occur between frames (hundreds of FPS for simple cases like UIs). Note here that diffs can be arbitrarily complex and are not restricted to rectangular regions...
- async. updates via DMA. Upload can be performed directly or done asynchronously using DMA (even in the case of complicated diff updates) which means that the MCU is free to do other tasks (like generating the next frame) during updates. DMA SPI transfer can be clocked up to 50Mhz and can use the bus at its full capacity when needed. There is almost no delay toggling between command and data packets (thanks to KurtE's DMA code . )
- adjustable framerate. The screen refresh rate can be adjusted and a fixed frame rate can be set within the driver. Uploads are then timed to meet the requested frame rate. Everything happens using timers and DMA so there is no "busy wait".
- vsync and screen tearing prevention. Now, this really is the best part The driver monitors the position of the current scan line being refreshed on the screen and orders the pixel updates so that they always trail behind this scan line. This makes it possible to completely suppress screen tearing provided the update can be done in less than two screen refresh periods ! In most cases, this makes it possible to reach a solid 50FPS without any screen tearing by setting the screen refresh rate to 100hz. And all this with modest SPI speeds...
- Multiple buffering methods. Support direct upload, double buffering and triple buffering configurations.
- driver for XPT2046 touchscreen. If present, the driver can manage the associated touchscreen on the same SPI bus. This simplifies the wiring since only 1 or 2 additional wires are needed in that case (for the touch cs pin and, possibly, the irq pin).
In practice, the library makes it simple to achieve a high frame rate combined with a high quality display. But of course, there is no such thing as a free launch and the price to pay is large RAM consumption: around 320Kb when using double buffering.
The library is still in beta and there are certainly many bugs to be found but it already does the job quite nicely. The screen tearing prevention is really fun to observe: if you blit 2 colors alternatively fast enough, they will simply simply melt into one instead of making an awful mess... There is a demo of this in the example folder of the library [and you can check the code: the violet color displayed on the screen is never uploaded to the screen ^^].
I did not write a separate documentation for the library but the code itself is pretty well documented. Info about public methods can be found in the header file in front of their declarations.
I hope someone find this library useful !
Best,