Teensy 4.1 + ILI9341 - Strange tft.writeRect memory pointer blit quirk

Pensive

Well-known member
Hi all

Wondering if there might be any obvious reason for the following:

I'm using the t3 tft library
Code:
#include "SPI.h"
#include "ILI9341_t3.h"
#include "font_Arial.h"
#include <XPT2046_Touchscreen.h>
#include <USBHost_t36.h>

.
.
.
.


// TFT Screen
#define TFT_DC  9
#define TFT_CS 10
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);// Use hardware SPI (#13, #12, #11)

.
.
.
.
.
//Graphics includes
#include "joypadimage.c"
#include "unreallogo.c"
#include "carcinilogo.c"
#include "joypadTab.c"
#include "joypadTabIconBlue.c"
#include "joypadTabIconNoFocus.c"
#include "unrealTabIconBlue.c"
#include "unrealTabIconNoFocus.c"
#include "settingsfocus.c"
#include "settingsnofocus.c"
#include "homefocus.c"
#include "homenofocus.c"
#include "iofocus.c"
#include "ionofocus.c"
#include "terminalfocus.c"
#include "terminalnofocus.c"

And I'm repeatedly blitting the attached .C file to the screen - every time the xbox360 joystick settings change in any way (so yes -this is a lot of frames when you are using analogue).

I'm using absolute positioning coordinates - i added the setCursor in case that had something to do with it but it doesnt.

Code:
        tft.setCursor(0, 0);
    tft.writeRect(40, 70, 240, 161, (uint16_t*)joypad_Tab);

1) I've checked the resolution of the PNG image file - it's correct - 240x161
2) The export from this website always needs the last few pixels added on large files but I've fixed it that so we have the correct number of pixels.

THE PROBLEM:

It should look like this:
IMG_1697.jpg

But it flickers around and looks like this as the screen redraws - there doesnt seem to be any pattern to it that I can see:
IMG_1701.jpg
IMG_1698.jpg
Video here:

and it jitters around a lot as it updates. None of the other blitted images do this (although they are not blitte dto the screen quickly - they are written once when the tab changes.

I cant see what I've done wrong - it should be drawn in exactly the same place, the same way - every time. Anyone else had this? Is the pointer drifting somehow? The Y position is always fine it just seems to muddle up the X positioning. :-/ Anyone with a deeper understanding of the libraries have any insight?

Thanks

Jon
 

Attachments

  • joypadTab.c
    367.3 KB · Views: 22
Last edited:
Sorry, I am not sure with the information here, on what suggestions to tell you.

You might try the _t3n version of the library to see if it works any differently.

writeRect is more or less the same as fillRect, but instead of pushing out the same color it walks the array, by output color and increment to the next one.

Does the code do anything on interrupts and/or the like? Or more specifically does it do any outputs to the screen from an interrupt? And/or threads...
Likewise, anything with another SPI device while the writeRect is active?

I was pretty sure from what you said your image is correct as if it were not, it would always display wrong.
 
Sorry, I am not sure with the information here, on what suggestions to tell you.

You might try the _t3n version of the library to see if it works any differently.
I'll try this thank you
writeRect is more or less the same as fillRect, but instead of pushing out the same color it walks the array, by output color and increment to the next one.
Hmm interesting - im using drawRect and fillRect fairly extensivily without issue.

Does the code do anything on interrupts and/or the like? Or more specifically does it do any outputs to the screen from an interrupt? And/or threads... Likewise, anything with another SPI device while the writeRect is active?
None at all. I am only using the USBHost and the tft library plus the associated touchscreen library. So it could be the touchscreen library - but then I'm not touching the screen at all when its happening. I'm guessing it's the USBhost library messing with interrupts as I drag the analogue pots around.

I was pretty sure from what you said your image is correct as if it were not, it would always display wrong.

Yeah it can't be that can it..... - if I get the dimensions incorrect you get a very different overlap result.

I'll try that other library in case it improves things - if not - I'll use Metro to update the screen instead of update on every change - i need to reduce the flicker as it is. Failing that its page flipping time but I really dont need that for my project.....a little flicker is not an issue. Dont want to take my eyes off the ball.....
 
Well I reworked the screen update code so it runs through metro and only updates the screen at 30 fps; It's significantly improved. 95% of the time the image stays where it should be and when it does occur 5% of the time - the jitter is only minor - maybe 2 pixels to the right; It seems to occur when you are twiddling the POV anologue pots about or the analogue triggers - so I'm guessing a lot of interrupts fire when you move the analogue sticks.

It's not perfect - still a bit flickery - TBH it could with implementing an animation engine with page flipping now we have the power and the ram to do so......but thats far and above what I need so I'm going to call this fixed.
 
Back
Top