I have a routine that draws pixels of variable colours on a 320X240 TFT SPI LCD. The library is ILI9341_due.
The original routine worked exactly as programmed though, because the logic didn't test the if the pixels had already been drawn, there was a lot of unintended overwriting of pixels.
The routine decided the co-ordinates of each pixel through complex decision making but (apart from the overwriting) the routine worked perfectly.
The routine decided where to draw each pixel and drew it, perfectly.
I decided to "readPixel" at the co-ordinate (x,y) to check the pixel was "empty" before I drew each pixel (to (x,y)) and the routine just stopped working altogether.
On debugging I found out the compiler inserted code that reset the values of integers "x" & "y" to their values at the "setup" stage.
I set "x = 319" and "y = 0" then manipulate x & y to be equal, for instance, to 310 & 9.
If I drawPixel at x & y it goes into (310,9) correctly.
If I, however, readPixel(x,y) first the "read" is correct but the compiler resets x & y back to their initial values of 319 & 0 and the following drawPixel goes into (319,0).
I declared x & y as volatile but that didn't change the compiler action, it still reset them to their initial values.
How do I tell the compiler to stop messing with my variables and leave them at the value they were recomputed to?
I have spent hours on this code but can't effect what the compiler does.