KurtE / ILI9341_t3n

Extended ILI9341_T3 library (Teensy) including all SPI buses, Frame buffer, plus
MIT License
51 stars 23 forks source link

Double buffering possible? #31

Closed cryham closed 4 years ago

cryham commented 4 years ago

Hi KurtE Firstly awesome library!

I am using Teensy 4.0 and ILI9341. Since 320x240 x 2bytes is 150 kB of 512 kB, I could be able to do double buffering. I mean: drawing in one buffer, when done set DMA transfer to update LCD from it, then switch to drawing in second buffer, and so on. I tried this in few ways but it is not working. Is it possible, am I doing something wrong? Here is my code:

uint16_t data[2][320 * 240];  // screen buffers
int buf = 0;

tft.setFrameBuffer(data[0]);
tft.useFrameBuffer(true);

tft.begin();
...

while(1)
{
    tft.setFrameBuffer(data[buf]);
    buf = 1-buf;

    ... drawing stuff ....

    tft.waitUpdateAsyncComplete();
    tft.updateScreenAsync();
}

Full code here single buffer, without that above.

KurtE commented 4 years ago

Sorry, not sure if this was sort of already answered on the forum or not?

Sometimes my github email gets eaten by my email providers spam system.

I just pushed up a change that maybe helps... That is the code to update the DMA buffers was not checking that I had cleared the DMA had been initialized, only that the whole field was not zero.

Let me know if this helps. Again I more likely to see things when posted up on forum.

Again Sorry I did not respond until now.

cryham commented 4 years ago

Thanks. I tested but your changes didn't fix it. This time I have black screen all the time and it crashes. Previously I saw few frames flickering with black screen and it crashed. It's bad for testing since I have to hold reset for 10sec or more after it crashes to get Teensy back. BTW. I am not using RST for tft (it has Vcc on pin) not sure if matters. I didn't know of the forum topic. Right, there is a way to do double buffering with memcpy, likely slower on page 13.

KurtE commented 4 years ago

I just pushed up a simple test sketch and code that switches back and forth between two buffers.

Let me know if this fixes the problem.

cryham commented 4 years ago

I tested your new doubleBuffer example in Arduino IDE on my setup. This is the output from Serial Monitor:

ILI9341 Test!
Delta time: 42885
Press any key to continue
Continued
Delta time: 42884
Press any key to continue
Continued
Delta time: 42974
Press any key to continue
Continued
Delta time: 42971
Press any key to continue
Continued
.
............

It did show screens with "Using FB1", I pressed enter then FB2, FB1A and FB2A. Then it started drawing green lines but stopped after about 12 (dots). So the display has top few lines green, rest is black and nothing happens. So I think I have some problem. Is this a hardware issue or software? This is exactly what happened before in my code it also just stopped after few frames swtiched. It looks for me like it was waiting infinitely in function updateScreenAsync(), but it doesn't show Timeout before. Any ideas?

KurtE commented 4 years ago

Sounds like the issue that I was having before I put the change in to the code.

I assume you picked up the new .cpp and .h files for the library as well as the sketch?

cryham commented 4 years ago

Right. I forgot to update the library. It works great now. I also checked in my code. Thanks for this update.

PS. There are 2 warnings in doubleBuffer.ino: tft.useFrameBuffer(fb2); this should be just true (not fb1 or fb2).